diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 9c9b5d348..80d34e821 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1441,6 +1441,24 @@ private: class ConfigOptionDef { public: + enum class GUIType { + undefined, + // Open enums, integer value could be one of the enumerated values or something else. + i_enum_open, + // Open enums, float value could be one of the enumerated values or something else. + f_enum_open, + // Color picker, string value. + color, + // ??? + select_open, + // Currently unused. + slider, + // Static text + legend, + // Vector value, but edited as a single string. + one_string, + }; + // Identifier of this option. It is stored here so that it is accessible through the by_serialization_key_ordinal map. t_config_option_key opt_key; // What type? bool, int, string etc. @@ -1524,7 +1542,7 @@ public: // Usually empty. // Special values - "i_enum_open", "f_enum_open" to provide combo box for int or float selection, // "select_open" - to open a selection dialog (currently only a serial port selection). - std::string gui_type; + GUIType gui_type { GUIType::undefined }; // Usually empty. Otherwise "serialized" or "show_value" // The flags may be combined. // "serialized" - vector valued option is entered in a single edit field. Values are separated by a semicolon. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 3aad02f91..f772f354f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -66,7 +66,7 @@ void PrintConfigDef::init_common_params() def->label = L("G-code thumbnails"); def->tooltip = L("Picture sizes to be stored into a .gcode and .sl1 files, in the following format: \"XxY, XxY, ...\""); def->mode = comExpert; - def->gui_type = "one_string"; + def->gui_type = ConfigOptionDef::GUIType::one_string; def->set_default_value(new ConfigOptionPoints()); def = this->add("layer_height", coFloat); @@ -116,7 +116,7 @@ void PrintConfigDef::init_common_params() def = this->add("printhost_port", coString); def->label = L("Printer"); def->tooltip = L("Name of the printer"); - def->gui_type = "select_open"; + def->gui_type = ConfigOptionDef::GUIType::select_open; def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); @@ -568,7 +568,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionBool(true)); def = this->add("extruder", coInt); - def->gui_type = "i_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::i_enum_open; def->label = L("Extruder"); def->category = L("Extruders"); def->tooltip = L("The extruder to use (unless more specific extruder settings are specified). " @@ -606,7 +606,7 @@ void PrintConfigDef::init_fff_params() def = this->add("extruder_colour", coStrings); def->label = L("Extruder Color"); def->tooltip = L("This is only used in the Slic3r interface as a visual help."); - def->gui_type = "color"; + def->gui_type = ConfigOptionDef::GUIType::color; // Empty string means no color assigned yet. def->set_default_value(new ConfigOptionStrings { "" }); @@ -668,7 +668,7 @@ void PrintConfigDef::init_fff_params() def = this->add("filament_colour", coStrings); def->label = L("Color"); def->tooltip = L("This is only used in the Slic3r interface as a visual help."); - def->gui_type = "color"; + def->gui_type = ConfigOptionDef::GUIType::color; def->set_default_value(new ConfigOptionStrings { "#29B2B2" }); def = this->add("filament_notes", coStrings); @@ -812,7 +812,7 @@ void PrintConfigDef::init_fff_params() def = this->add("filament_type", coStrings); def->label = L("Filament type"); def->tooltip = L("The filament material type for use in custom G-codes."); - def->gui_type = "f_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->gui_flags = "show_value"; def->enum_values.push_back("PLA"); def->enum_values.push_back("PET"); @@ -881,7 +881,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat(45)); def = this->add("fill_density", coPercent); - def->gui_type = "f_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->gui_flags = "show_value"; def->label = L("Fill density"); def->category = L("Infill"); @@ -1168,7 +1168,7 @@ void PrintConfigDef::init_fff_params() "Set this parameter to zero to disable anchoring perimeters connected to a single infill line."); def->sidetext = L("mm or %"); def->ratio_over = "infill_extrusion_width"; - def->gui_type = "f_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->enum_values.push_back("0"); def->enum_values.push_back("1"); def->enum_values.push_back("2"); @@ -1950,7 +1950,7 @@ void PrintConfigDef::init_fff_params() #if 0 def = this->add("seam_preferred_direction", coFloat); -// def->gui_type = "slider"; +// def->gui_type = ConfigOptionDef::GUIType::slider; def->label = L("Direction"); def->sidetext = L("°"); def->full_label = L("Preferred direction of the seam"); @@ -1960,7 +1960,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat(0)); def = this->add("seam_preferred_direction_jitter", coFloat); -// def->gui_type = "slider"; +// def->gui_type = ConfigOptionDef::GUIType::slider; def->label = L("Jitter"); def->sidetext = L("°"); def->full_label = L("Seam preferred direction jitter"); @@ -2234,7 +2234,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionBool(false)); def = this->add("support_material_contact_distance", coFloat); - def->gui_type = "f_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->label = L("Top contact Z distance"); def->category = L("Support material"); def->tooltip = L("The vertical distance between object and support material interface. " @@ -2252,7 +2252,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat(0.2)); def = this->add("support_material_bottom_contact_distance", coFloat); - def->gui_type = "f_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->label = L("Bottom contact Z distance"); def->category = L("Support material"); def->tooltip = L("The vertical distance between the object top surface and the support material interface. " @@ -2318,7 +2318,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionInt(1)); auto support_material_interface_layers = def = this->add("support_material_interface_layers", coInt); - def->gui_type = "i_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::i_enum_open; def->label = L("Top interface layers"); def->category = L("Support material"); def->tooltip = L("Number of interface layers to insert between the object(s) and support material."); @@ -2336,7 +2336,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionInt(3)); def = this->add("support_material_bottom_interface_layers", coInt); - def->gui_type = "i_enum_open"; + def->gui_type = ConfigOptionDef::GUIType::i_enum_open; def->label = L("Bottom interface layers"); def->category = L("Support material"); def->tooltip = L("Number of interface layers to insert between the object(s) and support material. " @@ -2873,7 +2873,7 @@ void PrintConfigDef::init_sla_params() def = this->add("material_type", coString); def->label = L("SLA material type"); def->tooltip = L("SLA material type"); - def->gui_type = "f_enum_open"; // TODO: ??? + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; // TODO: ??? def->gui_flags = "show_value"; def->enum_values.push_back("Tough"); def->enum_values.push_back("Flexible"); diff --git a/src/libslic3r/SupportMaterial.cpp b/src/libslic3r/SupportMaterial.cpp index 8dc939aed..9caac5769 100644 --- a/src/libslic3r/SupportMaterial.cpp +++ b/src/libslic3r/SupportMaterial.cpp @@ -2760,7 +2760,7 @@ std::pair -1) { + if (num_interface_layers_top > 0) { // Top Z coordinate of a slab, over which we are collecting the top / bottom contact surfaces coordf_t top_z = intermediate_layers[std::min(num_intermediate - 1, idx_intermediate_layer + num_interface_layers_top - 1)]->print_z; coordf_t top_inteface_z = std::numeric_limits::max(); @@ -2781,7 +2781,7 @@ std::pair top_inteface_z ? polygons_top_contact_projected_base : polygons_top_contact_projected_interface, top_contact_layer.polygons); } } - if (num_interface_layers_bottom > -1) { + if (num_interface_layers_bottom > 0) { // Bottom Z coordinate of a slab, over which we are collecting the top / bottom contact surfaces coordf_t bottom_z = intermediate_layers[std::max(0, idx_intermediate_layer - num_interface_layers_bottom + 1)]->bottom_z; coordf_t bottom_interface_z = - std::numeric_limits::max(); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 02ef87775..5af658a21 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -902,7 +902,7 @@ void Choice::BUILD() { if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); choice_ctrl* temp; - if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) { + if (m_opt.gui_type != undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open) { m_is_editable = true; temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size); } @@ -1237,7 +1237,7 @@ boost::any& Choice::get_value() else if (m_opt_id == "brim_type") m_value = static_cast(ret_enum); } - else if (m_opt.gui_type == "f_enum_open") { + else if (m_opt.gui_type == ConfigOptionDef::GUIType::f_enum_open || m_opt.gui_type == ConfigOptionDef::GUIType::i_enum_open) { const int ret_enum = field->GetSelection(); if (ret_enum < 0 || m_opt.enum_values.empty() || m_opt.type == coStrings || (ret_str != m_opt.enum_values[ret_enum] && ret_str != _(m_opt.enum_labels[ret_enum]))) @@ -1245,6 +1245,8 @@ boost::any& Choice::get_value() get_value_by_opt_type(ret_str); else if (m_opt.type == coFloatOrPercent) m_value = m_opt.enum_values[ret_enum]; + else if (m_opt.type == coInt) + m_value = atoi(m_opt.enum_values[ret_enum].c_str()); else m_value = atof(m_opt.enum_values[ret_enum].c_str()); } diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 6433bf2d1..aba3404e7 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -91,7 +91,7 @@ void OG_CustomCtrl::init_ctrl_lines() height = m_bmp_blinking_sz.GetHeight() + m_v_gap; ctrl_lines.emplace_back(CtrlLine(height, this, line, true)); } - else if (opt_group->label_width != 0 && (!line.label.IsEmpty() || option_set.front().opt.gui_type == "legend") ) + else if (opt_group->label_width != 0 && (!line.label.IsEmpty() || option_set.front().opt.gui_type == ConfigOptionDef::GUIType::legend) ) { wxSize label_sz = GetTextExtent(line.label); height = label_sz.y * (label_sz.GetWidth() > int(opt_group->label_width * m_em_unit) ? 2 : 1) + m_v_gap; @@ -186,11 +186,11 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/) #endif //__WXMSW__ h_pos += label_w + 1 + m_h_gap; } - h_pos += (opt.opt.gui_type == "legend" ? 1 : 3) * blinking_button_width; + h_pos += (opt.opt.gui_type == ConfigOptionDef::GUIType::legend ? 1 : 3) * blinking_button_width; if (field == field_in) break; - if (opt.opt.gui_type == "legend") + if (opt.opt.gui_type == ConfigOptionDef::GUIType::legend) h_pos += 2 * blinking_button_width; h_pos += field->getWindow()->GetSize().x; @@ -580,7 +580,7 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos) wxBitmap bmp = create_scaled_bitmap(bmp_name, ctrl, wxOSX ? 10 : 12); wxCoord y_draw = v_pos + lround((height - get_bitmap_size(bmp).GetHeight()) / 2); - if (og_line.get_options().front().opt.gui_type != "legend") + if (og_line.get_options().front().opt.gui_type != ConfigOptionDef::GUIType::legend) dc.DrawBitmap(bmp, 0, y_draw); return get_bitmap_size(bmp).GetWidth() + ctrl->m_h_gap; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index b87e2047d..c81f4c644 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -25,23 +25,27 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id) { const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) { // Check the gui_type field first, fall through // is the normal type. - if (opt.gui_type == "select") { - } else if (opt.gui_type == "select_open") { + switch (opt.gui_type) { + case ConfigOptionDef::GUIType::select_open: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); - } else if (opt.gui_type == "color") { + break; + case ConfigOptionDef::GUIType::color: m_fields.emplace(id, ColourPicker::Create(this->ctrl_parent(), opt, id)); - } else if (opt.gui_type == "f_enum_open" || - opt.gui_type == "i_enum_open" || - opt.gui_type == "i_enum_closed") { + break; + case ConfigOptionDef::GUIType::f_enum_open: + case ConfigOptionDef::GUIType::i_enum_open: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); - } else if (opt.gui_type == "slider") { + break; + case ConfigOptionDef::GUIType::slider: m_fields.emplace(id, SliderCtrl::Create(this->ctrl_parent(), opt, id)); - } else if (opt.gui_type == "i_spin") { // Spinctrl - } else if (opt.gui_type == "legend") { // StaticText + break; + case ConfigOptionDef::GUIType::legend: // StaticText m_fields.emplace(id, StaticText::Create(this->ctrl_parent(), opt, id)); - } else if (opt.gui_type == "one_string") { + break; + case ConfigOptionDef::GUIType::one_string: m_fields.emplace(id, TextCtrl::Create(this->ctrl_parent(), opt, id)); - } else { + break; + default: switch (opt.type) { case coFloatOrPercent: case coFloat: @@ -122,7 +126,7 @@ bool OptionsGroup::is_legend_line() { if (m_lines.size() == 1) { const std::vector