From c5e21c1fbf6ca637e869e58be1cd16f9b3780f92 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 5 Dec 2017 15:54:01 +0100 Subject: [PATCH 01/59] First steps --- lib/Slic3r/GUI/MainFrame.pm | 2 +- xs/src/slic3r/GUI/GUI.cpp | 18 +-- xs/src/slic3r/GUI/OptionsGroup.cpp | 124 ++++++++++++++++ xs/src/slic3r/GUI/OptionsGroup.hpp | 109 ++++++++++++++ xs/src/slic3r/GUI/OptionsGroup/Field.cpp | 36 +++++ xs/src/slic3r/GUI/OptionsGroup/Field.hpp | 95 +++++++++++++ xs/src/slic3r/GUI/Tab.cpp | 173 +++++++++++++++++++++++ xs/src/slic3r/GUI/Tab.h | 109 ++++++++++++++ xs/src/slic3r/GUI/Widget.hpp | 12 ++ xs/src/slic3r/GUI/wxinit.h | 25 ++++ 10 files changed, 694 insertions(+), 9 deletions(-) create mode 100644 xs/src/slic3r/GUI/OptionsGroup.cpp create mode 100644 xs/src/slic3r/GUI/OptionsGroup.hpp create mode 100644 xs/src/slic3r/GUI/OptionsGroup/Field.cpp create mode 100644 xs/src/slic3r/GUI/OptionsGroup/Field.hpp create mode 100644 xs/src/slic3r/GUI/Tab.cpp create mode 100644 xs/src/slic3r/GUI/Tab.h create mode 100644 xs/src/slic3r/GUI/Widget.hpp create mode 100644 xs/src/slic3r/GUI/wxinit.h diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index c91c59ea7..9712329c2 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -152,7 +152,7 @@ sub _init_tabpanel { } #TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view. -# Slic3r::GUI::create_preset_tab("print"); + Slic3r::GUI::create_preset_tab("print"); if ($self->{plater}) { $self->{plater}->on_select_preset(sub { diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 8db0508f1..cbd84f6db 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -21,6 +21,13 @@ #include #include +#include "Tab.h" + +//#include +//#include +//#include +//#include + namespace Slic3r { namespace GUI { #if __APPLE__ @@ -171,16 +178,11 @@ void add_debug_menu(wxMenuBar *menu) #endif } +// void create_preset_tab(const char *name) { - auto *panel = new wxPanel(g_wxTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); - // Vertical sizer to hold the choice menu and the rest of the page. - auto *sizer = new wxBoxSizer(wxVERTICAL); - sizer->SetSizeHints(panel); - panel->SetSizer(sizer); - auto *button = new wxButton(panel, wxID_ANY, "Hello World", wxDefaultPosition, wxDefaultSize, 0); - sizer->Add(button, 0, 0, 0); - g_wxTabPanel->AddPage(panel, name); + CTabPrint* panel = new CTabPrint(g_wxTabPanel, name/*, someParams*/); + g_wxTabPanel->AddPage(panel, name); } } } diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp new file mode 100644 index 000000000..6dd278913 --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -0,0 +1,124 @@ +#include "OptionsGroup.hpp" +#include "OptionsGroup/Field.hpp" +#include "Config.hpp" + +// Translate the ifdef +#ifdef __WXOSX__ + #define wxOSX true +#else + #define wxOSX false +#endif + +#define BORDER(a, b) ((wxOSX ? a : b)) + +namespace Slic3r { namespace GUI { + + +void OptionsGroup::BUILD() { + if (staticbox) { + wxStaticBox* box = new wxStaticBox(_parent, -1, title); + _sizer = new wxStaticBoxSizer(box, wxVERTICAL); + } else { + _sizer = new wxBoxSizer(wxVERTICAL); + } + size_t num_columns = 1; + if (label_width != 0) ++num_columns; + if (extra_column != 0) ++num_columns; + + _grid_sizer = new wxFlexGridSizer(0, num_columns, 0, 0); + _grid_sizer->SetFlexibleDirection(wxHORIZONTAL); + _grid_sizer->AddGrowableCol(label_width > 0); + _sizer->Add(_grid_sizer, 0, wxEXPAND | wxALL, BORDER(0,5)); +} + +void OptionsGroup::append_line(const Line& line) { + if (line.has_sizer() || (line.has_widget() && line.full_width)) { + wxASSERT(line.sizer() != nullptr); + _sizer->Add( (line.has_sizer() ? line.sizer() : line.widget().sizer()), 0, wxEXPAND | wxALL, BORDER(0, 15)); + return; + } + wxSizer* grid_sizer = _grid_sizer; + // If we have an extra column, build it. + // If there's a label, build it. + if (label_width != 0) { + wxStaticText* label = new wxStaticText(_parent, -1, (line.label) + ":", wxDefaultPosition); + label->Wrap(label_width); + if (wxIsEmpty(line.tooltip())) { label->SetToolTip(line.tooltip()); } + grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL, 0); + } + // If we have a widget, add it to the sizer + if (line.has_widget()) { + grid_sizer->Add(line.widget().sizer(), 0, wxEXPAND | wxALL, BORDER(0,15)); + return; + } + // If we have a single option with no sidetext just add it directly to the grid sizer + if (line.options().size() == 1) { + const ConfigOptionDef& opt = line.options()[0]; + if (line.extra_widgets().size() && !wxIsEmpty(opt.sidetext) && line.extra_widgets().size() == 0) { + Field* field = _build_field(opt); + if (field != nullptr) { + if (field->has_sizer()) { + grid_sizer->Add(field->sizer(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + } else if (field->has_window()) { + grid_sizer->Add(field->window(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + } + } + } + } + // Otherwise, there's more than one option or a single option with sidetext -- make + // a horizontal sizer to arrange things. + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + grid_sizer->Add(sizer, 0, 0, 0); + for (auto& option : line.options()) { + // add label if any + if (!wxIsEmpty(option.label)) { + wxStaticText* field_label = new wxStaticText(_parent, -1, __(option.label) + ":", wxDefaultPosition, wxDefaultSize); + sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL,0); + } + + // add field + Field* field = _build_field(option); + if (field != nullptr) { + if (field->has_sizer()) { + sizer->Add(field->sizer(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + } else if (field->has_window()) { + sizer->Add(field->window(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + } + } + + if (!wxIsEmpty(option.sidetext)) { + } + // !!! side_widget !!! find out the purpose +// if (option.side_widget.valid()) { +// sizer->Add(option.side_widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); +// } + if (&option != &line.options().back()) { + sizer->AddSpacer(4); + } + + // add side text if any + // add side widget if any + } + // Append extra sizers + for (auto& widget : line.extra_widgets()) { + _sizer->Add(widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); + } +} + +Field* OptionsGroup::_build_field(const ConfigOptionDef& opt) { + Field* built_field = nullptr; + switch (opt.type) { + case coString: + { + printf("Making new textctrl\n"); + TextCtrl* temp = new TextCtrl(_parent, opt); + printf("recasting textctrl\n"); + built_field = dynamic_cast(temp); + } + break; + default: + break; + } + return built_field; +} +} } diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp new file mode 100644 index 000000000..f2db0304e --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -0,0 +1,109 @@ +#ifndef OPTIONSGROUP_HPP +#define OPTIONSGROUP_HPP + +#include +#include +#include "wxinit.h" +#include "Widget.hpp" +#include "OptionsGroup/Field.hpp" +#include "Config.hpp" +namespace Slic3r { +class ConfigOptionDef; +namespace GUI { + + +/// Enumeration class to provide flags for these GUI hints. +/// they resolve to hex numbers to permit boolean masking. +enum class GUI_Type { + i_enum_open = 0x1, + f_enum_open = 0x2, + select_open = 0x4 +}; + +// Map these flags +/*constexpr */std::mapgui_type_map = + { { "i_enum_open", GUI_Type::i_enum_open }, + { "f_enum_open", GUI_Type::f_enum_open }, + { "select_open", GUI_Type::select_open } + }; + +// Abstraction cribbed from Slic3r::ConfigOptionDefGroup::Line +// Unsure if templated class or function overloading is the appropriate thing here. +class Line { +private: + std::vector _options; + std::vector _extra_widgets; + Widget _widget; + wxSizer* _sizer; + wxString _tooltip; +public: + wxString label; + bool full_width; + wxSizer* sizer() const { return _sizer; } + Line() : label(wxT("")), _tooltip(wxT("")), _sizer(nullptr), full_width(false), _widget(Widget()) { } + Line(const ConfigOptionDef& z) : label(z.label), _tooltip(z.tooltip), _sizer(nullptr), full_width(false), _widget(Widget()) { append_option(z); } + Line(const wxString& label, const wxString& tooltip) : label(label), _tooltip(tooltip), _sizer(nullptr), full_width(false), _widget(Widget()) { } + inline void append_option(const ConfigOptionDef& z) { _options.push_back(z); }; + void append_widget(const Widget& wid) { _extra_widgets.push_back(wid); } + std::vector options() const { return _options; } + const std::vector extra_widgets() const { return _extra_widgets; } + bool has_sizer() const { return _sizer != nullptr; } + bool has_widget() const { return _widget.valid(); } + Widget widget() const { return _widget; } + const wxString tooltip() const { return _tooltip; } +}; + + +// OptionsGroup building class, cribbed from Slic3r::OptionGroup +// Usage: Instantitate, add individual items to it, and add its sizer to another wxWidgets sizer. +class OptionsGroup { + private: + bool _disabled; + wxFlexGridSizer* _grid_sizer; + wxSizer* _sizer; + void BUILD(); + const bool staticbox; + wxFrame* _parent; + std::map fields; + Field* _build_field(const ConfigOptionDef& opt); + public: + const wxString title; + + size_t label_width; + wxFont label_font; + wxFont sidetext_font; + bool extra_column; + + OptionsGroup() : _parent(nullptr), title(wxT("")), staticbox(1), fields(std::map()){}; + OptionsGroup(wxFrame* parent, std::string title) : + _parent(parent), + title(title.c_str()), + staticbox(1), + extra_column(false), + label_width(0), + fields(std::map()) + { BUILD(); } + + OptionsGroup(wxFrame* parent, std::string, size_t label_width) : + _parent(parent), + title(title.c_str()), + staticbox(1), + extra_column(false), + fields(std::map()), + label_width(label_width) { BUILD(); } + + void append_line(const Line& line); + Line create_single_option_line(const ConfigOptionDef& opt) { Line a = Line(opt); append_line(a); return a; } + void append_single_option_line(const Line& line); + + wxSizer* sizer() { return _sizer; } + void disable() { for (auto& f: fields) f.second->disable(); } + void enable() { for (auto& f: fields) f.second->enable(); } +}; + + + + +} } + +#endif diff --git a/xs/src/slic3r/GUI/OptionsGroup/Field.cpp b/xs/src/slic3r/GUI/OptionsGroup/Field.cpp new file mode 100644 index 000000000..a512a4685 --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup/Field.cpp @@ -0,0 +1,36 @@ +#include "Field.hpp" + +namespace Slic3r { namespace GUI { + +void TextCtrl::BUILD() { + wxString default_value = ""; + // Empty wxString object fails cast, default to "" if + // the recast fails from boost::any. + try { + if (opt.default_value != nullptr) { + default_value = boost::any_cast(*(opt.default_value)); + } + } catch (const boost::bad_any_cast& e) { + //TODO log error + } + auto size = wxSize(opt.height,opt.width); + if (opt.height == 0 || opt.width == 0) { size = wxDefaultSize; } + + wxTextCtrl* temp = new wxTextCtrl(_parent, wxID_ANY, default_value, wxDefaultPosition, size, (opt.multiline ? wxTE_MULTILINE : 0)); + + _on_change = [=](wxCommandEvent& a) { this->__on_change(a);}; + + // This replaces the generic EVT_TEXT call to set the table up, it works with function objects. + temp->Bind(wxEVT_TEXT, _on_change, temp->GetId()); + if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); } + + // recast as a wxWindow to fit the calling convention + _window = dynamic_cast(temp); +} + +// Fixed (temporary) function. We can (and probably should) use lambdas instead. +void TextCtrl::__on_change(wxCommandEvent& a) { + printf("Calling _on_change for %d.\n", opt.label); +} + +} } diff --git a/xs/src/slic3r/GUI/OptionsGroup/Field.hpp b/xs/src/slic3r/GUI/OptionsGroup/Field.hpp new file mode 100644 index 000000000..e60d3bc32 --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup/Field.hpp @@ -0,0 +1,95 @@ +#ifndef FIELD_HPP +#define FIELD_HPP + +#include "../wxinit.h" + +#include +#include +#include + +// ConfigOptionDef definition +#include "Config.hpp" + +namespace Slic3r { +class ConfigOptionDef; +namespace GUI { + + + +/// Interface class for fields +/// +class Field { +protected: + wxSizer* _sizer; + wxWindow* _window; + wxWindow* _parent; + + /// Instantiate the underlying wxWidgets control/window. + /// This function is expected to be called by the constructor. + virtual void BUILD() = 0; + + /// Reference to underlying ConfigOptionDef this Field is + /// implementing. + /// TODO: This may not be necessary. + const ConfigOptionDef& opt; + std::string type; + +public: + std::function _on_change; + std::function _on_kill_focus; + // used if we need to know which ConfigOptionDef this corresponds. + Field() : opt(ConfigOptionDef()), _on_change(nullptr), _on_kill_focus(nullptr){} + Field(const ConfigOptionDef& opt) : opt(opt), type(opt.gui_type) { } + Field(wxFrame* parent, const ConfigOptionDef& opt) : opt(opt), _parent(parent) { } + wxSizer* sizer() { return _sizer; } + wxWindow* window() { return _window; } + + // + bool has_sizer() { return _sizer != nullptr; } + bool has_window() { return _window != nullptr; } + + /// Return the wxWidgets ID for this object. + /// + wxWindowID get_id() { if (this->has_window()) return _window->GetId(); } + + /// Sets a value for this control. + /// subclasses should overload with a specific version + virtual void set_value(boost::any value) = 0; + + /// Gets a boost::any representing this control. + /// subclasses should overload with a specific version + virtual boost::any get_value() = 0; + + /// subclasses should overload with a specific version + virtual void enable() = 0; + virtual void disable() = 0; + +}; + +class TextCtrl : public Field { +protected: + void BUILD(); +public: + TextCtrl(); + TextCtrl(wxFrame* parent, const ConfigOptionDef& opt) : Field(parent, opt) { BUILD(); }; + + void set_value(std::string value) { + dynamic_cast(_window)->SetValue(wxString(value)); + } + void set_value(boost::any value) { + try { + dynamic_cast(_window)->SetValue(boost::any_cast(value)); + } catch (boost::bad_any_cast) { + // TODO Log error and do nothing + } + } + boost::any get_value() { return boost::any(dynamic_cast(_window)->GetValue()); } + + void enable() { dynamic_cast(_window)->Enable(); dynamic_cast(_window)->SetEditable(1); } + void disable() { dynamic_cast(_window)->Disable(); dynamic_cast(_window)->SetEditable(0); } + void __on_change(wxCommandEvent&); + +}; + +} } +#endif diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp new file mode 100644 index 000000000..b6af3d998 --- /dev/null +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -0,0 +1,173 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "Tab.h" + +namespace Slic3r { +namespace GUI { + +// Declare some IDs. +/*const int BUTTON1 = 100; + +// Attach the event handlers. Put this after Slis3rFrame declaration. +BEGIN_EVENT_TABLE(MyFrame, wxFrame) +EVT_BUTTON(BUTTON1, MyFrame::OnButton1) +END_EVENT_TABLE() +*/ + +// sub new +void CTab::create_preset_tab() +{ + // Vertical sizer to hold the choice menu and the rest of the page. + CTab *panel = this; + auto *sizer = new wxBoxSizer(wxVERTICAL); + sizer->SetSizeHints(panel); + (panel)->SetSizer(sizer); + panel->SetSizer(sizer); + + // preset chooser + // choice menu for Experiments + wxString choices[] = + { + _T("Washington"), + _T("Adams"), + _T("Jefferson"), + _T("Madison"), + _T("Lincoln"), + _T("One"), + _T("Two"), + _T("Three"), + _T("Four") + }; + int nCntEl = 9; + + presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), nCntEl, choices, wxCB_READONLY); + + //buttons + wxBitmap bmpMenu; + bmpMenu = wxBitmap(wxT("var\\disk.png"), wxBITMAP_TYPE_PNG); + auto *btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + bmpMenu = wxBitmap(wxT("var\\delete.png"), wxBITMAP_TYPE_PNG); + auto *btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + + // $self->{show_incompatible_presets} = 0; // !!! + + bmp_show_incompatible_presets = new wxBitmap(wxT("var\\flag-red-icon.png"), wxBITMAP_TYPE_PNG); + bmp_hide_incompatible_presets = new wxBitmap(wxT("var\\flag-green-icon.png"), wxBITMAP_TYPE_PNG); + btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, *bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + + wxString stTitle = _T("Save current ") + wxString(_title);//. lc($self->title) + btn_save_preset->SetToolTip(stTitle); + btn_delete_preset->SetToolTip(_T("Delete this preset")); + btn_delete_preset->Disable(); + + hsizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(hsizer, 0, wxBOTTOM, 3); + hsizer->Add(presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); + hsizer->AddSpacer(4); + hsizer->Add(btn_save_preset, 0, wxALIGN_CENTER_VERTICAL); + hsizer->AddSpacer(4); + hsizer->Add(btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL); + hsizer->AddSpacer(16); + hsizer->Add(btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL); + + //Horizontal sizer to hold the tree and the selected page. + hsizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(hsizer, 1, wxEXPAND, 0); + + //left vertical sizer + left_sizer = new wxBoxSizer(wxVERTICAL); + hsizer->Add(left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3); + + // tree + auto *treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(185, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); + left_sizer->Add(treectrl, 1, wxEXPAND); + icons = new wxImageList(16, 16, 1); + // Map from an icon file name to its index in $self->{icons}. + // $self->{icon_index} = {}; + // Index of the last icon inserted into $self->{icons}. + icon_count = -1; + treectrl->AssignImageList(icons); + treectrl->AddRoot("root"); + // $self->{pages} = []; + treectrl->SetIndent(0); + disable_tree_sel_changed_event = 0; + + /* EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub { + return if $self->{disable_tree_sel_changed_event}; + my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}} + or return; + $_->Hide for @{$self->{pages}}; + $page->Show; + $self->{hsizer}->Layout; + $self->Refresh; + }); + EVT_KEY_DOWN($self->{treectrl}, sub { + my ($treectrl, $event) = @_; + if ($event->GetKeyCode == WXK_TAB) { + $treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward); + } else { + $event->Skip; + } + }); + + EVT_COMBOBOX($parent, $self->{presets_choice}, sub { + $self->select_preset($self->{presets_choice}->GetStringSelection); + }); + + EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset }); + EVT_BUTTON($self, $self->{btn_delete_preset}, sub { $self->delete_preset }); + EVT_BUTTON($self, $self->{btn_hide_incompatible_presets}, sub { $self->_toggle_show_hide_incompatible }); +*/ + // Initialize the DynamicPrintConfig by default keys/values. + // Possible %params keys: no_controller +// build(/*%params*/); +// rebuild_page_tree(); +// _update(); + + + return;//$self; +} + +void CTab::OnTreeSelChange(wxCommandEvent& event) +{ + if (disable_tree_sel_changed_event) return; + CPage* page = nullptr; + for (auto& el : pages) + if (el.title() == treectrl->GetSelection()) + { + page = ⪙ + break; + } + if (page == nullptr) return; + + for (auto& el : pages) + el.Hide(); + page->Show(); + hsizer->Layout(); + this->Refresh(); +}; + +void CTab::OnKeyDown(wxKeyEvent& event) +{ + event.GetKeyCode() == WXK_TAB ? + treectrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward) : + event.Skip(); +}; + +void CTab::save_preset(wxCommandEvent &event){}; +void CTab::delete_preset(wxCommandEvent &event){}; +void CTab::_toggle_show_hide_incompatible(wxCommandEvent &event){}; + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/Tab.h b/xs/src/slic3r/GUI/Tab.h new file mode 100644 index 000000000..2c60dd556 --- /dev/null +++ b/xs/src/slic3r/GUI/Tab.h @@ -0,0 +1,109 @@ +// The "Expert" tab at the right of the main tabbed window. +// +// This file implements following packages: +// Slic3r::GUI::Tab; +// Slic3r::GUI::Tab::Print; +// Slic3r::GUI::Tab::Filament; +// Slic3r::GUI::Tab::Printer; +// Slic3r::GUI::Tab::Page +// - Option page: For example, the Slic3r::GUI::Tab::Print has option pages "Layers and perimeters", "Infill", "Skirt and brim" ... +// Slic3r::GUI::SavePresetWindow +// - Dialog to select a new preset name to store the configuration. +// Slic3r::GUI::Tab::Preset; +// - Single preset item: name, file is default or external. + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Slic3r { +namespace GUI { + +// Single Tab page containing a{ vsizer } of{ optgroups } +// package Slic3r::GUI::Tab::Page; +class CPage : public wxScrolledWindow +{ + const char* _title; + wxWindow* _parent; + wxBoxSizer* _vsizer; + size_t _iconID; +// const OptionsGroup opt; // $self->{optgroups} = []; +public: + CPage(){}; + CPage(wxWindow* parent, const char* title, int iconID) : + _parent(parent), + _title(title), + _iconID(iconID) + { + Create(_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + this->SetScrollbars(1, 1, 1, 1); + _vsizer = new wxBoxSizer(wxVERTICAL); + this->SetSizer(_vsizer); + } + ~CPage(){}; + wxBoxSizer * vsizer(){ return this->_vsizer; } + wxString title(){ return wxString(_title); } +}; + +// Slic3r::GUI::Tab; +class CTab: public wxPanel +{ +protected: + const char* _title; + wxBitmapComboBox* presets_choice; + wxBitmap* bmp_show_incompatible_presets; + wxBitmap* bmp_hide_incompatible_presets; + wxBitmapButton* btn_hide_incompatible_presets; + wxBoxSizer* hsizer; + wxBoxSizer* left_sizer; + wxTreeCtrl* treectrl; + wxImageList* icons; + int icon_count; +// std::map icon_index; + std::vector pages; + bool disable_tree_sel_changed_event; +public: + CTab(){}; + CTab(wxNotebook* parent, const char *title/*, someParams*/){} + ~CTab(){}; + + void create_preset_tab(); + void OnTreeSelChange(wxCommandEvent& event); + void OnKeyDown(wxKeyEvent& event); + void OnComboBox(wxCommandEvent& event){ /*$self->select_preset(presets_choice->GetStringSelection)*/ }; + void save_preset(wxCommandEvent &event); + void delete_preset(wxCommandEvent &event); + void _toggle_show_hide_incompatible(wxCommandEvent &event); + +// virtual void build(/*%params*/); +// virtual void rebuild_page_tree(); +// virtual void _update(); +private: +// DECLARE_EVENT_TABLE() +}; + +//Slic3r::GUI::Tab::Print; +class CTabPrint : public CTab +{ +public: + CTabPrint() {}; + CTabPrint(wxNotebook* parent, const char *title/*, someParams*/) + { + _title = title; + Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); + create_preset_tab(); + } + ~CTabPrint(){}; +// void build(/*%params*/){}; +}; + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/Widget.hpp b/xs/src/slic3r/GUI/Widget.hpp new file mode 100644 index 000000000..6c3da1393 --- /dev/null +++ b/xs/src/slic3r/GUI/Widget.hpp @@ -0,0 +1,12 @@ +#ifndef WIDGET_HPP +#define WIDGET_HPP +#include "wxinit.h" +class Widget { +protected: + wxSizer* _sizer; +public: + Widget(): _sizer(nullptr) { } + bool valid() const { return _sizer != nullptr; } + wxSizer* sizer() const { return _sizer; } +}; +#endif diff --git a/xs/src/slic3r/GUI/wxinit.h b/xs/src/slic3r/GUI/wxinit.h new file mode 100644 index 000000000..b55681b92 --- /dev/null +++ b/xs/src/slic3r/GUI/wxinit.h @@ -0,0 +1,25 @@ +#ifndef slic3r_wxinit_hpp_ +#define slic3r_wxinit_hpp_ + +#include +#include +#include + +// Perl redefines a _ macro, so we undef this one +#undef _ + +// We do want to use translation however, so define it as __ so we can do a find/replace +// later when we no longer need to undef _ +#define __(s) wxGetTranslation((s)) + +// legacy macros +// https://wiki.wxwidgets.org/EventTypes_and_Event-Table_Macros +#ifndef wxEVT_BUTTON +#define wxEVT_BUTTON wxEVT_COMMAND_BUTTON_CLICKED +#endif + +#ifndef wxEVT_HTML_LINK_CLICKED +#define wxEVT_HTML_LINK_CLICKED wxEVT_COMMAND_HTML_LINK_CLICKED +#endif + +#endif From d60fac42d69a8bfc74d35d62970f3360c2f7585c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 13 Dec 2017 14:45:10 +0100 Subject: [PATCH 02/59] Start filling the Print's Tab, using @lordofhyphens's Optionsgroup --- xs/src/slic3r/GUI/ConfigExceptions.hpp | 15 + xs/src/slic3r/GUI/Field.cpp | 42 ++ xs/src/slic3r/GUI/Field.hpp | 137 ++++++ xs/src/slic3r/GUI/GUI.cpp | 29 +- xs/src/slic3r/GUI/OptionsGroup.cpp | 207 ++++----- xs/src/slic3r/GUI/OptionsGroup.hpp | 235 ++++++---- xs/src/slic3r/GUI/OptionsGroup/Field.cpp | 36 -- xs/src/slic3r/GUI/OptionsGroup/Field.hpp | 95 ---- xs/src/slic3r/GUI/Tab.cpp | 545 +++++++++++++++++++---- xs/src/slic3r/GUI/Tab.h | 135 +++--- xs/src/slic3r/GUI/Widget.hpp | 6 +- 11 files changed, 1000 insertions(+), 482 deletions(-) create mode 100644 xs/src/slic3r/GUI/ConfigExceptions.hpp create mode 100644 xs/src/slic3r/GUI/Field.cpp create mode 100644 xs/src/slic3r/GUI/Field.hpp delete mode 100644 xs/src/slic3r/GUI/OptionsGroup/Field.cpp delete mode 100644 xs/src/slic3r/GUI/OptionsGroup/Field.hpp diff --git a/xs/src/slic3r/GUI/ConfigExceptions.hpp b/xs/src/slic3r/GUI/ConfigExceptions.hpp new file mode 100644 index 000000000..9038d3445 --- /dev/null +++ b/xs/src/slic3r/GUI/ConfigExceptions.hpp @@ -0,0 +1,15 @@ +#include +namespace Slic3r { + +class ConfigError : public std::runtime_error { +using std::runtime_error::runtime_error; +}; + +namespace GUI { + +class ConfigGUITypeError : public ConfigError { +using ConfigError::ConfigError; +}; +} + +} diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp new file mode 100644 index 000000000..af89b01b1 --- /dev/null +++ b/xs/src/slic3r/GUI/Field.cpp @@ -0,0 +1,42 @@ +#include "GUI.hpp"//"slic3r_gui.hpp" +#include "Field.hpp" + +namespace Slic3r { namespace GUI { + + void Field::_on_kill_focus(wxFocusEvent& event) { + // Without this, there will be nasty focus bugs on Windows. + // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all + // non-command events to allow the default handling to take place." + event.Skip(1); + + // call the registered function if it is available +//! if (on_kill_focus) +//! on_kill_focus(opt_id); + } + void Field::_on_change(wxCommandEvent& event) { + std::cerr << "calling Field::_on_change \n"; +//! if (on_change != nullptr && !disable_change_event) +//! on_change(opt_id, "A"); + } + void TextCtrl::BUILD() { + auto size = wxSize(wxDefaultSize); + if (opt.height >= 0) size.SetHeight(opt.height); + if (opt.width >= 0) size.SetWidth(opt.width); + + auto temp = new wxTextCtrl(parent, wxID_ANY, wxString(""), wxDefaultPosition, size, (opt.multiline ? wxTE_MULTILINE : 0)); //! new wxTextCtrl(parent, wxID_ANY, wxString(opt.default_value->getString()), wxDefaultPosition, size, (opt.multiline ? wxTE_MULTILINE : 0)); + + if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); } + + temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { _on_change(e); }), temp->GetId()); + temp->Bind(wxEVT_KILL_FOCUS, ([this](wxFocusEvent e) { _on_kill_focus(e); }), temp->GetId()); + + // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); + + } + + void TextCtrl::enable() { (dynamic_cast(window))->Enable(); (dynamic_cast(window))->SetEditable(1); } + void TextCtrl::disable() { dynamic_cast(window)->Disable(); dynamic_cast(window)->SetEditable(0); } + void TextCtrl::set_tooltip(const wxString& tip) { } +}} + diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp new file mode 100644 index 000000000..c5bf74256 --- /dev/null +++ b/xs/src/slic3r/GUI/Field.hpp @@ -0,0 +1,137 @@ +#ifndef SLIC3R_GUI_FIELD_HPP +#define SLIC3R_GUI_FIELD_HPP + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include +#include +#include + +#include "../../libslic3r/libslic3r.h" +#include "../../libslic3r/Config.hpp" + +//#include "slic3r_gui.hpp" +#include "GUI.hpp" + +#if SLIC3R_CPPVER==11 + // C++14 has make_unique, C++11 doesn't. This is really useful so we're going to steal it. + template + std::unique_ptr make_unique(Args&&... args) + { + std::unique_ptr ret (new T(std::forward(args)...)); + return ret; + } +#endif + +namespace Slic3r { namespace GUI { + +class Field; +using t_field = std::unique_ptr; + +class Field { + protected: + // factory function to defer and enforce creation of derived type. + virtual void PostInitialize() { BUILD(); } + + /// Finish constructing the Field's wxWidget-related properties, including setting its own sizer, etc. + virtual void BUILD() = 0; + + /// Call the attached on_kill_focus method. + void _on_kill_focus(wxFocusEvent& event); + /// Call the attached on_change method. + void _on_change(wxCommandEvent& event); + + public: + + /// parent wx item, opportunity to refactor (probably not necessary - data duplication) + wxWindow* parent {nullptr}; + + /// Function object to store callback passed in from owning object. +//! t_kill_focus on_kill_focus {nullptr}; + + /// Function object to store callback passed in from owning object. +//! t_change on_change {nullptr}; + + bool disable_change_event {false}; + + /// Copy of ConfigOption for deduction purposes + const ConfigOptionDef opt {ConfigOptionDef()}; + const t_config_option_key opt_id;//! {""}; + + /// Sets a value for this control. + /// subclasses should overload with a specific version + /// Postcondition: Method does not fire the on_change event. + virtual void set_value(boost::any value) = 0; + + /// Gets a boost::any representing this control. + /// subclasses should overload with a specific version + virtual boost::any get_value() = 0; + + virtual void enable() = 0; + virtual void disable() = 0; + + /// Fires the enable or disable function, based on the input. + inline void toggle(bool en) { en ? enable() : disable(); } + + virtual void set_tooltip(const wxString& tip) = 0; + + + Field(const ConfigOptionDef& opt, const t_config_option_key& id) : opt(opt), opt_id(id) {}; + Field(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : parent(parent), opt(opt), opt_id(id) {}; + + /// If you don't know what you are getting back, check both methods for nullptr. + virtual wxSizer* getSizer() { return nullptr; } + virtual wxWindow* getWindow() { return nullptr; } + + + /// Factory method for generating new derived classes. + template + static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) // interface for creating shared objects + { + auto p = std::make_unique(parent, opt, id); + p->PostInitialize(); + return p; + } + +}; + +/// Convenience function, accepts a const reference to t_field and checks to see whether +/// or not both wx pointers are null. +inline bool is_bad_field(const t_field& obj) { return obj->getSizer() == nullptr && obj->getWindow() == nullptr; } + +/// Covenience function to determine whether this field is a valid window field. +inline bool is_window_field(const t_field& obj) { return !is_bad_field(obj) && obj->getWindow() != nullptr; } + +/// Covenience function to determine whether this field is a valid sizer field. +inline bool is_sizer_field(const t_field& obj) { return !is_bad_field(obj) && obj->getSizer() != nullptr; } + +class TextCtrl : public Field { + using Field::Field; +public: + void BUILD(); + wxWindow* window {nullptr}; + + + virtual void set_value(std::string value) { + dynamic_cast(window)->SetValue(wxString(value)); + } + virtual void set_value(boost::any value) { + dynamic_cast(window)->SetValue(boost::any_cast(value)); + } + + boost::any get_value() { return boost::any(dynamic_cast(window)->GetValue()); } + + virtual void enable(); + virtual void disable(); + virtual wxWindow* getWindow() { return window; } + void set_tooltip(const wxString& tip); + +}; + + +#endif +}} + diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index cbd84f6db..e1292bd3a 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -9,6 +9,15 @@ #import #elif _WIN32 #include +// Undefine min/max macros incompatible with the standard library +// For example, std::numeric_limits::max() +// produces some weird errors +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif #include "boost/nowide/convert.hpp" #pragma comment(lib, "user32.lib") #endif @@ -20,6 +29,7 @@ #include #include #include +#include #include "Tab.h" @@ -181,8 +191,25 @@ void add_debug_menu(wxMenuBar *menu) // void create_preset_tab(const char *name) { - CTabPrint* panel = new CTabPrint(g_wxTabPanel, name/*, someParams*/); + CTabPrint* panel = new CTabPrint(g_wxTabPanel, name); + panel->create_preset_tab(); g_wxTabPanel->AddPage(panel, name); + + //!------------Exp + // parse all command line options into a DynamicConfig +/* + DynamicPrintConfig print_config; +//! const DynamicPrintConfig &print_config = preset_bundle.prints .get_edited_preset().config; + + auto vsizer = new wxBoxSizer(wxVERTICAL); + this->SetSizer(vsizer); + auto optgroup = GUI::ConfigOptionsGroup(this, "Custom GCode", &print_config); + optgroup.on_change = ON_CHANGE(= , {}); + vsizer->Add(optgroup.sizer, 0, wxEXPAND | wxALL, 10); + + optgroup.append_single_option_line(GUI::Option(*(config.def->get("before_layer_gcode")), "before_layer_gcode")); +*/ //!------------Exp + } } } diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 6dd278913..1c7124710 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -1,124 +1,125 @@ #include "OptionsGroup.hpp" -#include "OptionsGroup/Field.hpp" -#include "Config.hpp" +#include "ConfigExceptions.hpp" -// Translate the ifdef -#ifdef __WXOSX__ - #define wxOSX true -#else - #define wxOSX false -#endif - -#define BORDER(a, b) ((wxOSX ? a : b)) +#include +#include namespace Slic3r { namespace GUI { +const t_field& OptionsGroup::build_field(const Option& opt) { + return build_field(opt.opt_id, opt.opt); +} +const t_field& OptionsGroup::build_field(const t_config_option_key& id) { + const ConfigOptionDef& opt = options.at(id); + return build_field(id, opt); +} -void OptionsGroup::BUILD() { - if (staticbox) { - wxStaticBox* box = new wxStaticBox(_parent, -1, title); - _sizer = new wxStaticBoxSizer(box, wxVERTICAL); - } else { - _sizer = new wxBoxSizer(wxVERTICAL); +const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) { + // Check the gui_type field first, fall through + // is the normal type. + if (opt.gui_type.compare("select") == 0) { + } else if (opt.gui_type.compare("select_open") == 0) { + } else if (opt.gui_type.compare("color") == 0) { + } else if (opt.gui_type.compare("f_enum_open") == 0 || + opt.gui_type.compare("i_enum_open") == 0 || + opt.gui_type.compare("i_enum_closed") == 0) { + } else if (opt.gui_type.compare("slider") == 0) { + } else if (opt.gui_type.compare("i_spin") == 0) { // Spinctrl + } else { + switch (opt.type) { + case coFloatOrPercent: + case coPercent: + case coFloat: + case coString: +//! fields.emplace(id, STDMOVE(TextCtrl::Create(_parent, opt,id))); + break; + case coNone: break; + default: + break;//! throw ConfigGUITypeError(""); break; + } } - size_t num_columns = 1; - if (label_width != 0) ++num_columns; - if (extra_column != 0) ++num_columns; - - _grid_sizer = new wxFlexGridSizer(0, num_columns, 0, 0); - _grid_sizer->SetFlexibleDirection(wxHORIZONTAL); - _grid_sizer->AddGrowableCol(label_width > 0); - _sizer->Add(_grid_sizer, 0, wxEXPAND | wxALL, BORDER(0,5)); + // Grab a reference to fields for convenience + const t_field& field = fields[id]; +//! field->on_change = [this](std::string id, boost::any val) { }; + field->parent = parent(); + // assign function objects for callbacks, etc. + return field; } void OptionsGroup::append_line(const Line& line) { - if (line.has_sizer() || (line.has_widget() && line.full_width)) { - wxASSERT(line.sizer() != nullptr); - _sizer->Add( (line.has_sizer() ? line.sizer() : line.widget().sizer()), 0, wxEXPAND | wxALL, BORDER(0, 15)); - return; + if (line.sizer != nullptr || (line.widget != nullptr && line.full_width > 0)){ + if (line.sizer != nullptr) { + sizer->Add(line.sizer, 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); + return; + } + if (line.widget != nullptr) { + sizer->Add(line.widget(_parent), 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); + return; + } } - wxSizer* grid_sizer = _grid_sizer; - // If we have an extra column, build it. - // If there's a label, build it. + + auto grid_sizer = _grid_sizer; + + // Build a label if we have it if (label_width != 0) { - wxStaticText* label = new wxStaticText(_parent, -1, (line.label) + ":", wxDefaultPosition); - label->Wrap(label_width); - if (wxIsEmpty(line.tooltip())) { label->SetToolTip(line.tooltip()); } - grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL, 0); + auto label = new wxStaticText(parent(), wxID_ANY, line.label , wxDefaultPosition, wxSize(label_width, -1)); + label->SetFont(label_font); + label->Wrap(label_width); // avoid a Linux/GTK bug + grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL,0); + if (line.label_tooltip.compare("") != 0) + label->SetToolTip(line.label_tooltip); } - // If we have a widget, add it to the sizer - if (line.has_widget()) { - grid_sizer->Add(line.widget().sizer(), 0, wxEXPAND | wxALL, BORDER(0,15)); + + // If there's a widget, build it and add the result to the sizer. + if (line.widget != nullptr) { + auto wgt = line.widget(parent()); + grid_sizer->Add(wgt, 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); return; } - // If we have a single option with no sidetext just add it directly to the grid sizer - if (line.options().size() == 1) { - const ConfigOptionDef& opt = line.options()[0]; - if (line.extra_widgets().size() && !wxIsEmpty(opt.sidetext) && line.extra_widgets().size() == 0) { - Field* field = _build_field(opt); - if (field != nullptr) { - if (field->has_sizer()) { - grid_sizer->Add(field->sizer(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); - } else if (field->has_window()) { - grid_sizer->Add(field->window(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); - } - } - } + + + // if we have a single option with no sidetext just add it directly to the grid sizer + auto option_set = line.get_options(); + if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 && + option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0) { + const auto& option = option_set.front(); + const auto& field = build_field(option); + std::cerr << "single option, no sidetext.\n"; + std::cerr << "field parent is not null?: " << (field->parent != nullptr) << "\n"; + + if (is_window_field(field)) + grid_sizer->Add(field->getWindow(), 0, (option.opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + if (is_sizer_field(field)) + grid_sizer->Add(field->getSizer(), 0, (option.opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + return; } - // Otherwise, there's more than one option or a single option with sidetext -- make - // a horizontal sizer to arrange things. - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + + // if we're here, we have more than one option or a single option with sidetext + // so we need a horizontal sizer to arrange these things + auto sizer = new wxBoxSizer(wxHORIZONTAL); grid_sizer->Add(sizer, 0, 0, 0); - for (auto& option : line.options()) { - // add label if any - if (!wxIsEmpty(option.label)) { - wxStaticText* field_label = new wxStaticText(_parent, -1, __(option.label) + ":", wxDefaultPosition, wxDefaultSize); - sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL,0); - } - - // add field - Field* field = _build_field(option); - if (field != nullptr) { - if (field->has_sizer()) { - sizer->Add(field->sizer(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); - } else if (field->has_window()) { - sizer->Add(field->window(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); - } - } - - if (!wxIsEmpty(option.sidetext)) { - } - // !!! side_widget !!! find out the purpose -// if (option.side_widget.valid()) { -// sizer->Add(option.side_widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); -// } - if (&option != &line.options().back()) { - sizer->AddSpacer(4); - } - - // add side text if any - // add side widget if any - } - // Append extra sizers - for (auto& widget : line.extra_widgets()) { - _sizer->Add(widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); + for (auto opt : option_set) { + } + + +} +Line OptionsGroup::create_single_option_line(const Option& option) const { + Line retval {option.opt.label, option.opt.tooltip}; + Option tmp(option); + tmp.opt.label = std::string(""); + retval.append_option(tmp); + return retval; } -Field* OptionsGroup::_build_field(const ConfigOptionDef& opt) { - Field* built_field = nullptr; - switch (opt.type) { - case coString: - { - printf("Making new textctrl\n"); - TextCtrl* temp = new TextCtrl(_parent, opt); - printf("recasting textctrl\n"); - built_field = dynamic_cast(temp); - } - break; - default: - break; - } - return built_field; +//! void OptionsGroup::_on_change(t_config_option_key id, config_value value) { +//! if (on_change != nullptr) +//! on_change(id, value); +//! } + +void OptionsGroup::_on_kill_focus (t_config_option_key id) { + // do nothing. } -} } + + +}} diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index f2db0304e..328f721d8 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -1,109 +1,148 @@ -#ifndef OPTIONSGROUP_HPP -#define OPTIONSGROUP_HPP +#include +#include +#include +//#include -#include #include -#include "wxinit.h" -#include "Widget.hpp" -#include "OptionsGroup/Field.hpp" -#include "Config.hpp" -namespace Slic3r { -class ConfigOptionDef; -namespace GUI { +#include +#include "libslic3r/Config.hpp" +#include "libslic3r/PrintConfig.hpp" +#include "libslic3r/libslic3r.h" -/// Enumeration class to provide flags for these GUI hints. -/// they resolve to hex numbers to permit boolean masking. -enum class GUI_Type { - i_enum_open = 0x1, - f_enum_open = 0x2, - select_open = 0x4 +#include "Field.hpp" +//#include "slic3r_gui.hpp" +#include "GUI.hpp" + +// Translate the ifdef +#ifdef __WXOSX__ + #define wxOSX true +#else + #define wxOSX false +#endif + +#define BORDER(a, b) ((wxOSX ? a : b)) + +namespace Slic3r { namespace GUI { + +/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window). +using widget_t = std::function; +using column_t = std::function; + +class StaticText; + +/// Wraps a ConfigOptionDef and adds function object for creating a side_widget. +struct Option { + ConfigOptionDef opt {ConfigOptionDef()}; + t_config_option_key opt_id;//! {""}; + widget_t side_widget {nullptr}; + bool readonly {false}; + + Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), opt_id(id) {}; +}; +using t_option = std::unique_ptr