diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b096683b..686cc3c2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -207,6 +207,10 @@ IF(wxWidgets_FOUND) add_library(slic3r_gui STATIC ${GUI_LIBDIR}/Dialogs/AboutDialog.cpp + ${GUI_LIBDIR}/Dialogs/PresetEditor.cpp + ${GUI_LIBDIR}/Dialogs/PrintEditor.cpp + ${GUI_LIBDIR}/Dialogs/PrinterEditor.cpp + ${GUI_LIBDIR}/Dialogs/MaterialEditor.cpp ${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/Plater.cpp diff --git a/src/GUI/Dialogs/MaterialEditor.cpp b/src/GUI/Dialogs/MaterialEditor.cpp new file mode 100644 index 000000000..9ec877753 --- /dev/null +++ b/src/GUI/Dialogs/MaterialEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +MaterialEditor::MaterialEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void MaterialEditor::_update() { +} + +void MaterialEditor::_build() { +} +}} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PresetEditor.hpp b/src/GUI/Dialogs/PresetEditor.hpp index 03cb86d6d..2c6544d92 100644 --- a/src/GUI/Dialogs/PresetEditor.hpp +++ b/src/GUI/Dialogs/PresetEditor.hpp @@ -1,8 +1,22 @@ #ifndef PRESETEDITOR_HPP #define PRESETEDITOR_HPP +// stdlib #include +#include + +// Libslic3r #include "libslic3r.h" +#include "ConfigBase.hpp" +#include "Config.hpp" + +// GUI +#include "misc_ui.hpp" + +// Wx +#include +#include +#include #if SLIC3R_CPPVER==11 #define st(A) (std::string(#A)) @@ -16,16 +30,66 @@ namespace Slic3r { namespace GUI { class PresetEditor : public wxPanel { +public: /// Member function to retrieve a list of options /// that this preset governs. Subclasses should /// call their own static method. virtual t_config_option_keys my_options() = 0; static t_config_option_keys options() { return t_config_option_keys {}; } + + wxSizer* sizer() { return _sizer; }; + PresetEditor(wxWindow* parent, t_config_option_keys options = {}); + PresetEditor() : PresetEditor(nullptr, {}) {}; + + bool prompt_unsaved_changes(); + void select_preset_by_name(const wxString& name, bool force = false); + + /// suppress the callback when the tree selection is changed. + bool disable_tree_sel_changed_event {false}; + + void save_preset(); + std::function on_save_preset {}; + std::function on_value_change {}; + + config_ptr config; + + virtual wxString title() = 0; + virtual std::string name() = 0; +protected: + // Main sizer + wxSizer* _sizer {nullptr}; + wxString presets; + wxImageList* _icons {nullptr}; + wxTreeCtrl* _treectrl {nullptr}; + wxBitmapButton* _btn_save_preset {nullptr}; + wxBitmapButton* _btn_delete_preset {nullptr}; + wxChoice* _presets_choice {nullptr}; + int _iconcount {-1}; + + std::vector _pages {}; + + const unsigned int left_col_width {150}; + void _update_tree(); + void load_presets(); + + virtual void _build() = 0; + virtual void _update() = 0; + virtual void _on_preset_loaded() = 0; + void set_tooltips() { + this->_btn_save_preset->SetToolTip(wxString(_("Save current ")) + this->title()); + this->_btn_delete_preset->SetToolTip(_("Delete this preset.")); + } }; class PrintEditor : public PresetEditor { public: + PrintEditor(wxWindow* parent, t_config_option_keys options = {}); + PrintEditor() : PrintEditor(nullptr, {}) {}; + + wxString title() override { return _("Print Settings"); } + std::string name() override { return st("print"); } + /// Static method to retrieve list of options that this preset governs. static t_config_option_keys options() { return t_config_option_keys @@ -73,10 +137,20 @@ public: } t_config_option_keys my_options() override { return PrintEditor::options(); } + +protected: + void _update() override; + void _build() override; }; class MaterialEditor : public PresetEditor { - +public: + + wxString title() override { return _("Material Settings"); } + std::string name() override { return st("material"); } + MaterialEditor(wxWindow* parent, t_config_option_keys options = {}); + MaterialEditor() : MaterialEditor(nullptr, {}) {}; + static t_config_option_keys options() { return t_config_option_keys { @@ -91,9 +165,18 @@ class MaterialEditor : public PresetEditor { } t_config_option_keys my_options() override { return MaterialEditor::options(); } +protected: + void _update() override; + void _build() override; }; class PrinterEditor : public PresetEditor { +public: + PrinterEditor(wxWindow* parent, t_config_option_keys options = {}); + PrinterEditor() : PrinterEditor(nullptr, {}) {}; + + wxString title() override { return _("Printer Settings"); } + std::string name() override { return st("printer"); } static t_config_option_keys options() { return t_config_option_keys @@ -115,6 +198,9 @@ class PrinterEditor : public PresetEditor { } t_config_option_keys my_options() override { return PrinterEditor::options(); } +protected: + void _update() override; + void _build() override; }; diff --git a/src/GUI/Dialogs/PrintEditor.cpp b/src/GUI/Dialogs/PrintEditor.cpp new file mode 100644 index 000000000..7a121c9fb --- /dev/null +++ b/src/GUI/Dialogs/PrintEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +PrintEditor::PrintEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void PrintEditor::_update() { +} + +void PrintEditor::_build() { +} +}} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PrinterEditor.cpp b/src/GUI/Dialogs/PrinterEditor.cpp new file mode 100644 index 000000000..8143e9b26 --- /dev/null +++ b/src/GUI/Dialogs/PrinterEditor.cpp @@ -0,0 +1,19 @@ +#include "Dialogs/PresetEditor.hpp" +namespace Slic3r { namespace GUI { + +PrinterEditor::PrinterEditor(wxWindow* parent, t_config_option_keys options) : + PresetEditor(parent, options) { + + this->config = Slic3r::Config::new_from_defaults(this->my_options()); + this->_update_tree(); + this->load_presets(); + this->_update(); + this->_build(); + } + +void PrinterEditor::_update() { +} + +void PrinterEditor::_build() { +} +}} // namespace Slic3r::GUI