From 7cbf4b6d5fbae286d309806daf98b22c1a10f84e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 14 Jun 2018 23:16:30 -0500 Subject: [PATCH] stubbed out preset editor changes. --- src/GUI/Dialogs/PresetEditor.cpp | 13 ++++++ src/GUI/Dialogs/PrintEditor.cpp | 5 +++ src/GUI/GUI.cpp | 3 -- src/GUI/GUI.hpp | 2 +- src/GUI/MainFrame.cpp | 4 +- src/GUI/MainFrame.hpp | 4 +- src/GUI/Plater.cpp | 74 ++++++++++++++++++++++++++++++++ src/GUI/Plater.hpp | 9 +++- src/GUI/Preset.hpp | 3 +- 9 files changed, 108 insertions(+), 9 deletions(-) diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index 8fb363283..08f389f70 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -76,6 +76,11 @@ void PresetEditor::_on_value_change(std::string opt_key) { } ); } +// TODO +void PresetEditor::_on_select_preset(bool force) { +} + + void PresetEditor::select_preset(int id, bool force) { this->_presets_choice->SetSelection(id); this->_on_select_preset(force); @@ -117,4 +122,12 @@ void PresetEditor::reload_config() { void PresetEditor::reload_preset() { } +// TODO +void PresetEditor::_update_tree() { +} + +// TODO +void PresetEditor::load_presets() { +} + }} // namespace Slic3r::GUI diff --git a/src/GUI/Dialogs/PrintEditor.cpp b/src/GUI/Dialogs/PrintEditor.cpp index 2ddb26c73..e675cc74a 100644 --- a/src/GUI/Dialogs/PrintEditor.cpp +++ b/src/GUI/Dialogs/PrintEditor.cpp @@ -14,6 +14,11 @@ PrintEditor::PrintEditor(wxWindow* parent, t_config_option_keys options) : void PrintEditor::_update(const std::string& opt_key) { } + +// TODO +void PrintEditor::_on_preset_loaded() { +} + void PrintEditor::_build() { } }} // namespace Slic3r::GUI diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index 3a2bb3c11..bafcaeb83 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -23,8 +23,6 @@ namespace Slic3r { namespace GUI { bool App::OnInit() { this->SetAppName("Slic3r"); - // TODO: Call a logging function with channel GUI, severity info - this->notifier = std::unique_ptr(); datadir = decode_path(wxStandardPaths::Get().GetUserDataDir()); @@ -46,7 +44,6 @@ bool App::OnInit() } } - // TODO: Call a logging function with channel GUI, severity info for datadir path Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); ui_settings = Settings::init_settings(); diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index e18e073ff..11b497852 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -50,7 +50,7 @@ private: /// Quick reference to this app with its cast applied. -#define SLIC3RAPP dynamic_cast(wxTheApp) +#define SLIC3RAPP (dynamic_cast(wxTheApp)) }} // namespace Slic3r::GUI diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index dfad27820..80d949b85 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -14,7 +14,7 @@ wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) + tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) { this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); @@ -95,7 +95,7 @@ void MainFrame::init_tabpanel() panel->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, ([=](wxAuiNotebookEvent& e) { if (typeid(panel) == typeid(Slic3r::GUI::PresetEditor)) { - wxDELETE(this->preset_editor_tabs[panel->GetId()]); + wxDELETE(this->preset_editor_tabs[dynamic_cast(panel)->type()]); } wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); }), panel->GetId()); diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 54f0bfdc9..1d8272231 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -33,6 +33,9 @@ public: bool has_plater_menu() { return this->plater_menu != nullptr; } wxMenu* plater_select_menu {nullptr}; + wxAuiNotebook* tabs() { return tabpanel; } + + std::map preset_editor_tabs; private: wxDECLARE_EVENT_TABLE(); @@ -49,7 +52,6 @@ private: wxMenu* plater_menu {nullptr}; - std::map preset_editor_tabs; void on_plater_object_list_changed(bool force) {}; void on_plater_selection_changed(bool force) {}; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index bbf8d10a2..301917f46 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -1196,6 +1196,80 @@ void Plater::_on_change_combobox(preset_t preset, wxBitmapComboBox* choice) { */ } +void Plater::show_preset_editor(preset_t preset, unsigned int idx) { + + std::function cbfunc { + [this, preset, idx]() { + auto presets { this->selected_presets(preset) }; + auto* mainframe {this->GetFrame()}; + auto* tabpanel {mainframe->tabs()}; + if (mainframe->preset_editor_tabs[preset] != nullptr) { + // editor is already open + tabpanel->SetSelection(tabpanel->GetPageIndex(mainframe->preset_editor_tabs[preset])); + return; + } else if (ui_settings->preset_editor_tabs) { + // open a tab + PresetEditor* tab {nullptr}; + switch (preset) { + case preset_t::Print: + tab = new PrintEditor(this); + break; + /* + case preset_t::Material: + tab = new MaterialEditor(this); + break; + case preset_t::Printer: + tab = new PrinterEditor(this); + break; + */ + default: // do nothing + return; + } + tabpanel->AddPage(tab, wxString(tab->name()) + wxString(" Settings")); + + } else { + // pop a dialog + switch (preset) { + case preset_t::Print: + break; + case preset_t::Material: + break; + case preset_t::Printer: + break; + default:; // do nothing + return; + } + } + + } + }; + SLIC3RAPP->CallAfter(cbfunc); + +} + +Preset* Plater::selected_presets(preset_t preset) { + auto& preset_list {SLIC3RAPP->presets.at(static_cast(preset))}; + auto sel = this->preset_choosers.at(static_cast(preset))->GetSelection(); + if (sel == -1) sel = 0; + + // Retrieve the string associated with this + auto preset_name {this->preset_choosers.at(static_cast(preset))->GetString(sel)}; + auto iter = std::find(preset_list.begin(), preset_list.end(), preset_name); + if (iter == preset_list.end()) { + Slic3r::Log::warn(LogChannel, LOG_WSTRING(preset_name + LOG_WSTRING(" not found in Presets list."))); + iter = preset_list.begin(); // get the first one if not found for some reason. + } + return &(*iter); +} + +std::vector Plater::selected_presets() { + std::vector tmp(static_cast(preset_t::Last)); // preallocate + for (uint8_t i = 0; i < static_cast(preset_t::Last); i++) { + tmp[i] = selected_presets(static_cast(i)); + } + return tmp; +} + void Plater::load_presets() { for (auto group : {preset_t::Printer, preset_t::Material, preset_t::Print}) { diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index f4cd4dbdf..a88c2999e 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -98,6 +98,8 @@ public: /// Create menu for object. wxMenu* object_menu(); + + /// Retrieve the identifier for the currently selected preset. void undo() {}; void redo() {}; @@ -109,6 +111,11 @@ public: void export_amf() {}; void export_tmf() {}; void export_stl() {}; + + /// Return a reference to the currently selected preset for a group. + Preset* selected_presets(preset_t preset); + /// Return a reference to all currently selected presets. + std::vector selected_presets(); private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; @@ -253,7 +260,7 @@ private: std::vector preset_choosers {preset_types, nullptr}; void _on_change_combobox(preset_t preset, wxBitmapComboBox* choice); - void show_preset_editor(preset_t preset, unsigned int idx) { }; + void show_preset_editor(preset_t preset, unsigned int idx); void _on_select_preset(preset_t preset) {}; void load_presets(); diff --git a/src/GUI/Preset.hpp b/src/GUI/Preset.hpp index fe28f430d..7d3ece2a4 100644 --- a/src/GUI/Preset.hpp +++ b/src/GUI/Preset.hpp @@ -6,7 +6,8 @@ namespace Slic3r { namespace GUI { -/// Preset types list. We assign numbers to permit static_casts and use as preset tab indices +/// Preset types list. We assign numbers to permit static_casts and use as preset tab indices. +/// Don't skip numbers in the enumeration, we use this as an index into vectors (instead of using std::map). enum class preset_t : uint8_t { Print = 0, Material, Printer, Last // This MUST be the last enumeration. Don't use it for anything.