diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3bf068b56..775114654 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -502,6 +502,14 @@ void GUI_App::get_installed_languages(wxArrayString & names, wxArrayLong & ident } } +Tab* GUI_App::get_tab(Preset::Type type) +{ + for (Tab* tab: tabs_list) + if (tab->type() == type) + return tab; + return nullptr; +} + ConfigMenuIDs GUI_App::get_view_mode() { if (!app_config->has("view_mode")) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 451b89147..55254ffd5 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -128,6 +128,7 @@ public: void save_language(); void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers); + Tab* get_tab(Preset::Type type); ConfigMenuIDs get_view_mode(); void update_mode(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 4dbaa9d09..ecd1ddea2 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -134,23 +134,6 @@ void MainFrame::init_tabpanel() // The following event is emited by Tab implementation on config value change. Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this); -// EVT_COMMAND($self, -1, $VALUE_CHANGE_EVENT, sub { -// my($self, $event) = @_; -// auto str = event->GetString; -// my($opt_key, $name) = ($str = ~/ (.*) (.*) / ); -// auto tab = Slic3r::GUI::get_preset_tab(name); -// auto config = tab->get_config(); -// if (m_plater) { -// m_plater->on_config_change(config); // propagate config change events to the plater -// if (opt_key == "extruders_count"){ -// auto value = event->GetInt(); -// m_plater->on_extruders_change(value); -// } -// } -// // don't save while loading for the first time -// if (Slic3r::GUI::autosave && m_loaded) -// m_config->save(Slic3r::GUI::autosave) ; -// }); // The following event is emited by Tab on preset selection, // or when the preset's "modified" status changes. @@ -174,22 +157,15 @@ void MainFrame::init_tabpanel() m_options_tabs[tab_name] = get_preset_tab(tab_name.c_str()); if (m_plater) { -// m_plater->on_select_preset(sub{ -// my($group, $name) = @_; -// $self->{options_tabs}{$group}->select_preset($name); -// }); // load initial config auto full_config = wxGetApp().preset_bundle->full_config(); -// m_plater->on_config_change(full_config); + m_plater->on_config_change(&full_config); // Show a correct number of filament fields. -// if (defined full_config->nozzle_diameter){ -// // nozzle_diameter is undefined when SLA printer is selected -// m_plater->on_extruders_change(int(@{$full_config->nozzle_diameter})); -// } - - // Show correct preset comboboxes according to the printer_technology -// m_plater->show_preset_comboboxes(full_config.printer_technology() == "FFF" ? 0 : 1); + // nozzle_diameter is undefined when SLA printer is selected + if (full_config.has("nozzle_diameter")){ + m_plater->on_extruders_change(full_config.option("nozzle_diameter")->values.size()); + } } } @@ -779,16 +755,32 @@ void MainFrame::on_presets_changed(SimpleEvent &event) else cur_tab->load_current_preset(); } - m_plater->sidebar().show_preset_comboboxes(static_cast(tab)->m_printer_technology == ptSLA); } // XXX: ? // m_plater->on_config_change(tab->get_config()); } } -void MainFrame::on_value_changed(wxCommandEvent&) +void MainFrame::on_value_changed(wxCommandEvent& event) { - ; + auto *tab = dynamic_cast(event.GetEventObject()); + wxASSERT(tab != nullptr); + if (tab == nullptr) + return; + + auto opt_key = event.GetString(); + auto config = tab->get_config(); + if (m_plater) { + m_plater->on_config_change(config); // propagate config change events to the plater + if (opt_key == "extruders_count"){ + auto value = event.GetInt(); + m_plater->on_extruders_change(value); + } + } + // don't save while loading for the first time + // #ys_FIXME ?autosave? +// if (wxGetApp().autosave && m_loaded) +// m_config->save(wxGetApp().autosave); } // Called after the Preferences dialog is closed and the program settings are saved. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 99395c826..e0101f54c 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "libslic3r/libslic3r.h" #include "libslic3r/PrintConfig.hpp" @@ -45,6 +46,7 @@ #include "BackgroundSlicingProcess.hpp" #include "ProgressStatusBar.hpp" #include "slic3r/Utils/ASCIIFolding.hpp" +#include "PrintConfig.hpp" #include // Needs to be last because reasons :-/ #include "WipeTowerDialog.hpp" @@ -189,6 +191,34 @@ PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) : evt.StopPropagation(); } }); + + if (preset_type == Slic3r::Preset::TYPE_FILAMENT) + { + Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &event) { + if (extruder_idx < 0 || event.GetLogicalPosition(wxClientDC(this)).x > 24) { + // Let the combo box process the mouse click. + event.Skip(); + return; + } + + // Swallow the mouse click and open the color picker. + auto data = new wxColourData(); + data->SetChooseFull(1); + auto dialog = new wxColourDialog(wxGetApp().mainframe, data); + if (dialog->ShowModal() == wxID_OK) { + DynamicPrintConfig cfg = *wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config(); + + auto colors = static_cast(wxGetApp().preset_bundle->full_config().option("extruder_colour")->clone()); + colors->values[extruder_idx] = dialog->GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX); + + cfg.set_key_value("extruder_colour", colors); + + wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg); + wxGetApp().preset_bundle->update_platter_filament_ui(extruder_idx, this); + } + dialog->Destroy(); + }); + } } PresetComboBox::~PresetComboBox() {} @@ -365,8 +395,29 @@ struct Sidebar::priv bool show_manifold_warning_icon = false; bool show_print_info = false; + + + void show_preset_comboboxes(); }; +void Sidebar::priv::show_preset_comboboxes() +{ + const bool showSLA = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA; + + wxWindowUpdateLocker noUpdates(wxGetApp().mainframe); + + for (size_t i = 0; i < 4; ++i) + sizer_presets->Show(i, !showSLA); + + sizer_presets->Show(4, showSLA); + sizer_presets->Show(5, showSLA); + + frequently_changed_parameters->get_sizer()->Show(!showSLA); + + wxGetApp().plater()->Layout(); + wxGetApp().mainframe->Layout(); +} + // Sidebar / public @@ -378,13 +429,12 @@ Sidebar::Sidebar(Plater *parent) // The preset chooser p->sizer_presets = new wxFlexGridSizer(4, 2, 1, 2); p->sizer_presets->AddGrowableCol(1, 1); - p->sizer_presets->SetFlexibleDirection(wxHORIZONTAL); + p->sizer_presets->SetFlexibleDirection(wxBOTH); p->sizer_filaments = new wxBoxSizer(wxVERTICAL); auto init_combo = [this](PresetComboBox **combo, wxString label, Preset::Type preset_type, bool filament) { auto *text = new wxStaticText(p->scrolled, wxID_ANY, label); text->SetFont(wxGetApp().small_font()); - // combo = new wxBitmapComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); *combo = new PresetComboBox(p->scrolled, preset_type); auto *sizer_presets = this->p->sizer_presets; @@ -394,6 +444,7 @@ Sidebar::Sidebar(Plater *parent) sizer_presets->Add(*combo, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxBOTTOM, 1); } else { sizer_filaments->Add(*combo, 1, wxEXPAND | wxBOTTOM, 1); + (*combo)->set_extruder_idx(0); sizer_presets->Add(sizer_filaments, 1, wxEXPAND); } }; @@ -469,6 +520,30 @@ Sidebar::Sidebar(Plater *parent) Sidebar::~Sidebar() {} +void Sidebar::init_filament_combo(PresetComboBox **combo, const int extr_idx) { + *combo = new PresetComboBox(p->scrolled, Slic3r::Preset::TYPE_FILAMENT); +// # copy icons from first choice +// $choice->SetItemBitmap($_, $choices->[0]->GetItemBitmap($_)) for 0..$#presets; + + (*combo)->set_extruder_idx(extr_idx); + + auto /***/sizer_filaments = this->p->sizer_filaments; + sizer_filaments->Add(*combo, 1, wxEXPAND | wxBOTTOM, 1); +} + +void Sidebar::remove_unused_filament_combos(const int current_extruder_count) +{ + if (current_extruder_count >= p->combos_filament.size()) + return; + auto sizer_filaments = this->p->sizer_filaments; + while (p->combos_filament.size() > current_extruder_count) { + const int last = p->combos_filament.size() - 1; + sizer_filaments->Remove(last); + (*p->combos_filament[last]).Destroy(); + p->combos_filament.pop_back(); + } +} + void Sidebar::update_presets(Preset::Type preset_type) { switch (preset_type) { @@ -503,6 +578,7 @@ void Sidebar::update_presets(Preset::Type preset_type) for (size_t i = 0; i < p->combos_filament.size(); i++) { wxGetApp().preset_bundle->update_platter_filament_ui(i, p->combos_filament[i]); } + p->show_preset_comboboxes(); break; default: break; @@ -512,22 +588,6 @@ void Sidebar::update_presets(Preset::Type preset_type) wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); } -void Sidebar::show_preset_comboboxes(bool showSLA) -{ -// wxWindowUpdateLocker noUpdates(wxGetApp().mainframe); - - for (size_t i = 0; i < 4; ++i) - p->sizer_presets->Show(i, !showSLA); - - p->sizer_presets->Show(4, showSLA); - p->sizer_presets->Show(5, showSLA); - - p->frequently_changed_parameters->get_sizer()->Show(!showSLA); - - wxGetApp().plater()->Layout(); - wxGetApp().mainframe->Layout(); -} - ObjectManipulation* Sidebar::obj_manipul() { return p->object_manipulation; @@ -591,6 +651,13 @@ bool Sidebar::is_multifilament() return p->combos_filament.size() > 0; } + +std::vector& Sidebar::combos_filament() +{ + return p->combos_filament; +} + + // Plater::Object struct PlaterObject @@ -704,9 +771,7 @@ struct Plater::priv void reload_from_disk(); void export_object_stl(); void fix_through_netfabb(); - void show_preset_comboboxes(); void item_changed_selection(); - void filament_color_box_lmouse_down(); void on_notebook_changed(wxBookCtrlEvent&); void on_select_preset(wxCommandEvent&); @@ -714,8 +779,6 @@ struct Plater::priv void on_update_print_preview(wxCommandEvent&); void on_process_completed(wxCommandEvent&); void on_layer_editing_toggled(bool enable); - void on_extruders_change(); - void on_config_change(); void on_action_add(SimpleEvent&); void on_action_arrange(SimpleEvent&); @@ -1417,22 +1480,11 @@ void Plater::priv::fix_through_netfabb() // TODO } -void Plater::priv::show_preset_comboboxes() -{ - // TODO -} - void Plater::priv::item_changed_selection() { // TODO } -void Plater::priv::filament_color_box_lmouse_down() -{ - // TODO -} - - void Plater::priv::on_notebook_changed(wxBookCtrlEvent&) { const auto current_id = notebook->GetCurrentPage()->GetId(); @@ -1454,9 +1506,9 @@ void Plater::priv::on_notebook_changed(wxBookCtrlEvent&) void Plater::priv::on_select_preset(wxCommandEvent &evt) { auto preset_type = static_cast(evt.GetInt()); - auto *combo = static_cast(evt.GetEventObject()); + auto *combo = static_cast(evt.GetEventObject()); - auto idx = 0;// evt.GetId(); + auto idx = combo->get_extruder_idx(); if (preset_type == Preset::TYPE_FILAMENT) { wxGetApp().preset_bundle->set_filament_preset(idx, combo->GetStringSelection().ToStdString()); @@ -1464,10 +1516,10 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) // TODO: ? if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { - // Only update the platter UI for the 2nd and other filaments. + // Only update the platter UI for the 2nd and other filaments. wxGetApp().preset_bundle->update_platter_filament_ui(idx, combo); - // } - } else { + } + else { for (Tab* tab : wxGetApp().tabs_list) { if (tab->type() == preset_type) { tab->select_preset(combo->GetStringSelection().ToStdString()); @@ -1509,16 +1561,6 @@ void Plater::priv::on_layer_editing_toggled(bool enable) canvas3D->Update(); } -void Plater::priv::on_extruders_change() -{ - // TODO -} - -void Plater::priv::on_config_change() -{ - // TODO -} - void Plater::priv::on_action_add(SimpleEvent&) { wxArrayString input_files; @@ -1775,6 +1817,34 @@ void Plater::send_gcode() p->send_gcode_file = export_gcode(); } +void Plater::on_extruders_change(int num_extruders) +{ + auto& choices = sidebar().combos_filament(); + + int i = choices.size(); + while ( i < num_extruders ) + { + PresetComboBox* choice/*{ nullptr }*/; + sidebar().init_filament_combo(&choice, i); + choices.push_back(choice); + + // initialize selection + wxGetApp().preset_bundle->update_platter_filament_ui(i, choice); + ++i; + } + + // remove unused choices if any + sidebar().remove_unused_filament_combos(num_extruders); + + sidebar().Layout(); + GetParent()->Layout(); +} + +void Plater::on_config_change(DynamicPrintConfig* config) +{ + // TODO +} + void Plater::changed_object_settings(int obj_idx) { if (obj_idx < 0) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 51291ee22..fd3c4e455 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -11,7 +11,7 @@ #include "Preset.hpp" class wxButton; - +class wxBoxSizer; namespace Slic3r { @@ -35,6 +35,8 @@ public: ~PresetComboBox(); void set_label_marker(int item); + void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; } + int get_extruder_idx() const { return extruder_idx; } private: typedef std::size_t Marker; @@ -42,6 +44,7 @@ private: Preset::Type preset_type; int last_selected; + int extruder_idx = -1; }; class Sidebar : public wxPanel @@ -54,8 +57,9 @@ public: Sidebar &operator=(const Sidebar &) = delete; ~Sidebar(); + void init_filament_combo(PresetComboBox **combo, const int extr_idx); + void remove_unused_filament_combos(const int current_extruder_count); void update_presets(Slic3r::Preset::Type preset_type); - void show_preset_comboboxes(bool showSLA); ObjectManipulation* obj_manipul(); ObjectList* obj_list(); @@ -69,6 +73,7 @@ public: void enable_buttons(bool enable); bool is_multifilament(); + std::vector& combos_filament(); private: struct priv; std::unique_ptr p; @@ -102,6 +107,9 @@ public: void reslice(); void changed_object_settings(int obj_idx); void send_gcode(); + + void on_extruders_change(int extruders_count); + void on_config_change(DynamicPrintConfig* config); private: struct priv; std::unique_ptr p; diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index cd3924dd0..8d4ab194a 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -3,6 +3,7 @@ #include "PresetBundle.hpp" #include "BitmapCache.hpp" +#include "Plater.hpp" #include #include @@ -1297,7 +1298,7 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out return true; } -void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitmapComboBox *ui) +void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui) { if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA) return; @@ -1320,7 +1321,7 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma std::map nonsys_presets; wxString selected_str = ""; if (!this->filaments().front().is_visible) - ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap); + ui->set_label_marker(ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap)); for (int i = this->filaments().front().is_visible ? 0 : 1; i < int(this->filaments().size()); ++i) { const Preset &preset = this->filaments.preset(i); bool selected = this->filament_presets[idx_extruder] == preset.name; @@ -1373,12 +1374,12 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma selected_str = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); } if (preset.is_default) - ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap); + ui->set_label_marker(ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap)); } if (!nonsys_presets.empty()) { - ui->Append("------- " + _(L("User presets")) + " -------", wxNullBitmap); + ui->set_label_marker(ui->Append("------- " + _(L("User presets")) + " -------", wxNullBitmap)); for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { ui->Append(it->first, *it->second); if (it->first == selected_str) diff --git a/src/slic3r/GUI/PresetBundle.hpp b/src/slic3r/GUI/PresetBundle.hpp index 3cd8df54b..e116b0ff9 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/slic3r/GUI/PresetBundle.hpp @@ -110,7 +110,7 @@ public: void export_configbundle(const std::string &path); // , const DynamicPrintConfig &settings); // Update a filament selection combo box on the platter for an idx_extruder. - void update_platter_filament_ui(unsigned int idx_extruder, wxBitmapComboBox *ui); + void update_platter_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui); // Enable / disable the "- default -" preset. void set_default_suppressed(bool default_suppressed);