From 6de5b343123da3aaa2be2a157a405019cebea4e1 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 23 May 2019 12:39:55 +0200 Subject: [PATCH] Set current filament color to the ColorPicker --- src/slic3r/GUI/Plater.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f3ad9c55d..f2220b3ea 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -274,22 +274,30 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * } // Swallow the mouse click and open the color picker. + + // get current color + DynamicPrintConfig* cfg = wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config(); + auto colors = static_cast(cfg->option("extruder_colour")->clone()); + wxColour clr(colors->values[extruder_idx]); + if (!clr.IsOk()) + clr = wxTransparentColour; + auto data = new wxColourData(); data->SetChooseFull(1); - auto dialog = new wxColourDialog(/* wxGetApp().mainframe */this, data); - dialog->CenterOnParent(); - if (dialog->ShowModal() == wxID_OK) { - DynamicPrintConfig cfg = *wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config(); + data->SetColour(clr); - //FIXME this is too expensive to call full_config to get just the extruder color! - auto colors = static_cast(wxGetApp().preset_bundle->full_config().option("extruder_colour")->clone()); + auto dialog = new wxColourDialog(this, data); + dialog->CenterOnParent(); + if (dialog->ShowModal() == wxID_OK) + { colors->values[extruder_idx] = dialog->GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX); - cfg.set_key_value("extruder_colour", colors); + DynamicPrintConfig cfg_new = *cfg; + cfg_new.set_key_value("extruder_colour", colors); - wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg); + wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg_new); wxGetApp().preset_bundle->update_platter_filament_ui(extruder_idx, this); - wxGetApp().plater()->on_config_change(cfg); + wxGetApp().plater()->on_config_change(cfg_new); } dialog->Destroy(); });