ConfigOptions: GUI type as enum, not string.

Fixing compilation error in the new Platform code.
Fixing one issue in FDM support after splitting the top/bottom
interface layers.
This commit is contained in:
Vojtech Bubnik 2021-03-11 15:01:24 +01:00
parent 051ba0e6f4
commit a9c3d270e6
10 changed files with 66 additions and 55 deletions

View File

@ -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.

View File

@ -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");

View File

@ -2760,7 +2760,7 @@ std::pair<PrintObjectSupportMaterial::MyLayersPtr, PrintObjectSupportMaterial::M
Polygons polygons_top_contact_projected_base;
Polygons polygons_bottom_contact_projected_interface;
Polygons polygons_bottom_contact_projected_base;
if (num_interface_layers_top > -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<coordf_t>::max();
@ -2781,7 +2781,7 @@ std::pair<PrintObjectSupportMaterial::MyLayersPtr, PrintObjectSupportMaterial::M
polygons_append(top_contact_layer.bottom_z - EPSILON > 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<coordf_t>::max();

View File

@ -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<BrimType>(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());
}

View File

@ -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;

View File

@ -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<Choice>(this->ctrl_parent(), opt, id));
} else if (opt.gui_type == "color") {
break;
case ConfigOptionDef::GUIType::color:
m_fields.emplace(id, ColourPicker::Create<ColourPicker>(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<Choice>(this->ctrl_parent(), opt, id));
} else if (opt.gui_type == "slider") {
break;
case ConfigOptionDef::GUIType::slider:
m_fields.emplace(id, SliderCtrl::Create<SliderCtrl>(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<StaticText>(this->ctrl_parent(), opt, id));
} else if (opt.gui_type == "one_string") {
break;
case ConfigOptionDef::GUIType::one_string:
m_fields.emplace(id, TextCtrl::Create<TextCtrl>(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<Option>& option_set = m_lines.front().get_options();
return !option_set.empty() && option_set.front().opt.gui_type == "legend";
return !option_set.empty() && option_set.front().opt.gui_type == ConfigOptionDef::GUIType::legend;
}
return false;
}
@ -213,7 +217,7 @@ void OptionsGroup::activate_line(Line& line)
}
auto option_set = line.get_options();
bool is_legend_line = option_set.front().opt.gui_type == "legend";
bool is_legend_line = option_set.front().opt.gui_type == ConfigOptionDef::GUIType::legend;
if (!custom_ctrl && m_use_custom_ctrl) {
custom_ctrl = new OG_CustomCtrl(is_legend_line || !staticbox ? this->parent() : static_cast<wxWindow*>(this->stb), this);

View File

@ -357,7 +357,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
ConfigOptionDef support_def;
support_def.label = L("Supports");
support_def.type = coStrings;
support_def.gui_type = "select_open";
support_def.gui_type = ConfigOptionDef::GUIType::select_open;
support_def.tooltip = L("Select what kind of support do you need");
support_def.enum_labels.push_back(L("None"));
support_def.enum_labels.push_back(L("Support on build plate only"));
@ -397,7 +397,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
def.label = L("Brim");
def.type = coBool;
def.tooltip = L("This flag enables the brim that will be printed around each object on the first layer.");
def.gui_type = "";
def.gui_type = ConfigOptionDef::GUIType::undefined;
def.set_default_value(new ConfigOptionBool{ m_brim_width > 0.0 ? true : false });
option = Option(def, "brim");
option.opt.sidetext = "";
@ -500,7 +500,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
ConfigOptionDef pad_def;
pad_def.label = L("Pad");
pad_def.type = coStrings;
pad_def.gui_type = "select_open";
pad_def.gui_type = ConfigOptionDef::GUIType::select_open;
pad_def.tooltip = L("Select what kind of pad do you need");
pad_def.enum_labels.push_back(L("None"));
pad_def.enum_labels.push_back(L("Below object"));

View File

@ -2531,7 +2531,7 @@ PageShp TabPrinter::build_kinematics_page()
ConfigOptionDef def;
def.type = coString;
def.width = Field::def_width();
def.gui_type = "legend";
def.gui_type = ConfigOptionDef::GUIType::legend;
def.mode = comAdvanced;
def.tooltip = L("Values in this column are for Normal mode");
def.set_default_value(new ConfigOptionString{ _(L("Normal")).ToUTF8().data() });

View File

@ -30,7 +30,7 @@ void detect_platform()
char buf[4096];
// Read the 1st line.
if (::fgets(buf, 4096, f) && strstr(buf, "Chromium OS") != nullptr)
s_platform_flavor = LinuxOnChromium;
s_platform_flavor = PlatformFlavor::LinuxOnChromium;
::fclose(f);
}
}

View File

@ -170,19 +170,6 @@ print_config_def()
throw "Unknown option type";
}
(void)hv_stores( hv, "type", newSVpv(opt_type, 0) );
(void)hv_stores( hv, "gui_type", newSVpvn(optdef->gui_type.c_str(), optdef->gui_type.length()) );
(void)hv_stores( hv, "gui_flags", newSVpvn(optdef->gui_flags.c_str(), optdef->gui_flags.length()) );
(void)hv_stores( hv, "label", newSVpvn_utf8(optdef->label.c_str(), optdef->label.length(), true) );
if (!optdef->full_label.empty())
(void)hv_stores( hv, "full_label", newSVpvn_utf8(optdef->full_label.c_str(), optdef->full_label.length(), true) );
(void)hv_stores( hv, "category", newSVpvn_utf8(optdef->category.c_str(), optdef->category.length(), true) );
(void)hv_stores( hv, "tooltip", newSVpvn_utf8(optdef->tooltip.c_str(), optdef->tooltip.length(), true) );
(void)hv_stores( hv, "sidetext", newSVpvn_utf8(optdef->sidetext.c_str(), optdef->sidetext.length(), true) );
(void)hv_stores( hv, "cli", newSVpvn(optdef->cli.c_str(), optdef->cli.length()) );
(void)hv_stores( hv, "ratio_over", newSVpvn(optdef->ratio_over.c_str(), optdef->ratio_over.length()) );
(void)hv_stores( hv, "multiline", newSViv(optdef->multiline ? 1 : 0) );
(void)hv_stores( hv, "full_width", newSViv(optdef->full_width ? 1 : 0) );
(void)hv_stores( hv, "readonly", newSViv(optdef->readonly ? 1 : 0) );
(void)hv_stores( hv, "height", newSViv(optdef->height) );
(void)hv_stores( hv, "width", newSViv(optdef->width) );
(void)hv_stores( hv, "min", newSViv(optdef->min) );