diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 625335de62..ee4bc4e463 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1011,8 +1011,10 @@ public: // What type? bool, int, string etc. ConfigOptionType type = coNone; // Default value of this option. The default value object is owned by ConfigDef, it is released in its destructor. - Slic3r::clonable_ptr default_value = nullptr; + Slic3r::clonable_ptr default_value; void set_default_value(const ConfigOption* ptr) { this->default_value = Slic3r::clonable_ptr(ptr); } + template + const T* get_default_value() const { return static_cast(this->default_value.get()); } // Usually empty. // Special values - "i_enum_open", "f_enum_open" to provide combo box for int or float selection, diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index bd45104c4c..4fbaa45637 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -544,14 +544,12 @@ PageDiameters::PageDiameters(ConfigWizard *parent) { spin_nozzle->SetDigits(2); spin_nozzle->SetIncrement(0.1); - const auto &def_nozzle = *print_config_def.get("nozzle_diameter"); - auto *default_nozzle = dynamic_cast(def_nozzle.default_value.get()); + auto *default_nozzle = print_config_def.get("nozzle_diameter")->get_default_value(); spin_nozzle->SetValue(default_nozzle != nullptr && default_nozzle->size() > 0 ? default_nozzle->get_at(0) : 0.5); spin_filam->SetDigits(2); spin_filam->SetIncrement(0.25); - const auto &def_filam = *print_config_def.get("filament_diameter"); - auto *default_filam = dynamic_cast(def_filam.default_value.get()); + auto *default_filam = print_config_def.get("filament_diameter")->get_default_value(); spin_filam->SetValue(default_filam != nullptr && default_filam->size() > 0 ? default_filam->get_at(0) : 3.0); append_text(_(L("Enter the diameter of your printer's hot end nozzle."))); @@ -596,13 +594,13 @@ PageTemperatures::PageTemperatures(ConfigWizard *parent) spin_extr->SetIncrement(5.0); const auto &def_extr = *print_config_def.get("temperature"); spin_extr->SetRange(def_extr.min, def_extr.max); - auto *default_extr = dynamic_cast(def_extr.default_value.get()); + auto *default_extr = def_extr.get_default_value(); spin_extr->SetValue(default_extr != nullptr && default_extr->size() > 0 ? default_extr->get_at(0) : 200); spin_bed->SetIncrement(5.0); const auto &def_bed = *print_config_def.get("bed_temperature"); spin_bed->SetRange(def_bed.min, def_bed.max); - auto *default_bed = dynamic_cast(def_bed.default_value.get()); + auto *default_bed = def_bed.get_default_value(); spin_bed->SetValue(default_bed != nullptr && default_bed->size() > 0 ? default_bed->get_at(0) : 0); append_text(_(L("Enter the temperature needed for extruding your filament."))); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 02f58667c3..5e06efa29e 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -203,7 +203,7 @@ void TextCtrl::BUILD() { case coFloatOrPercent: { text_value = double_to_string(m_opt.default_value->getFloat()); - if (static_cast(m_opt.default_value.get())->percent) + if (m_opt.get_default_value()->percent) text_value += "%"; break; } @@ -218,19 +218,19 @@ void TextCtrl::BUILD() { case coFloat: { double val = m_opt.type == coFloats ? - static_cast(m_opt.default_value.get())->get_at(m_opt_idx) : + m_opt.get_default_value()->get_at(m_opt_idx) : m_opt.type == coFloat ? m_opt.default_value->getFloat() : - static_cast(m_opt.default_value.get())->get_at(m_opt_idx); + m_opt.get_default_value()->get_at(m_opt_idx); text_value = double_to_string(val); break; } case coString: - text_value = static_cast(m_opt.default_value.get())->value; + text_value = m_opt.get_default_value()->value; break; case coStrings: { - const ConfigOptionStrings *vec = static_cast(m_opt.default_value.get()); + const ConfigOptionStrings *vec = m_opt.get_default_value(); if (vec == nullptr || vec->empty()) break; //for the case of empty default value text_value = vec->get_at(m_opt_idx); break; @@ -373,8 +373,8 @@ void CheckBox::BUILD() { bool check_value = m_opt.type == coBool ? m_opt.default_value->getBool() : m_opt.type == coBools ? - static_cast(m_opt.default_value.get())->get_at(m_opt_idx) : - false; + m_opt.get_default_value()->get_at(m_opt_idx) : + false; // Set Label as a string of at least one space simbol to correct system scaling of a CheckBox auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(" "), wxDefaultPosition, size); @@ -427,7 +427,7 @@ void SpinCtrl::BUILD() { break; case coInts: { - const ConfigOptionInts *vec = static_cast(m_opt.default_value.get()); + const ConfigOptionInts *vec = m_opt.get_default_value(); if (vec == nullptr || vec->empty()) break; for (size_t id = 0; id < vec->size(); ++id) { @@ -629,7 +629,7 @@ void Choice::set_selection() break; } case coEnum:{ - int id_value = static_cast*>(m_opt.default_value.get())->value; //!! + int id_value = m_opt.get_default_value>()->value; //!! field->SetSelection(id_value); break; } @@ -649,7 +649,7 @@ void Choice::set_selection() break; } case coStrings:{ - text_value = static_cast(m_opt.default_value.get())->get_at(m_opt_idx); + text_value = m_opt.get_default_value()->get_at(m_opt_idx); size_t idx = 0; for (auto el : m_opt.enum_values) @@ -886,7 +886,7 @@ void ColourPicker::BUILD() if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); // Validate the color - wxString clr_str(static_cast(m_opt.default_value.get())->get_at(m_opt_idx)); + wxString clr_str(m_opt.get_default_value()->get_at(m_opt_idx)); wxColour clr(clr_str); if (! clr.IsOk()) { clr = wxTransparentColour; @@ -920,7 +920,7 @@ void PointCtrl::BUILD() const wxSize field_size(4 * m_em_unit, -1); - auto default_pt = static_cast(m_opt.default_value.get())->values.at(0); + auto default_pt = m_opt.get_default_value()->values.at(0); double val = default_pt(0); wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); val = default_pt(1); @@ -1019,7 +1019,7 @@ void StaticText::BUILD() if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); - const wxString legend(static_cast(m_opt.default_value.get())->value); + const wxString legend(m_opt.get_default_value()->value); auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); temp->SetBackgroundStyle(wxBG_STYLE_PAINT); @@ -1054,7 +1054,7 @@ void SliderCtrl::BUILD() auto temp = new wxBoxSizer(wxHORIZONTAL); - auto def_val = static_cast(m_opt.default_value.get())->value; + auto def_val = m_opt.get_default_value()->value; auto min = m_opt.min == INT_MIN ? 0 : m_opt.min; auto max = m_opt.max == INT_MAX ? 100 : m_opt.max;