Added additional checkbox to enable zero elevation

This commit is contained in:
tamasmeszaros 2019-08-06 16:51:32 +02:00
parent b43f7c3880
commit 3c09473f2a
5 changed files with 2626 additions and 2568 deletions

View File

@ -85,8 +85,8 @@ void PrintConfigDef::init_common_params()
"The gap closing operation may reduce the final print resolution, therefore it is advisable to keep the value reasonably low."); "The gap closing operation may reduce the final print resolution, therefore it is advisable to keep the value reasonably low.");
def->sidetext = L("mm"); def->sidetext = L("mm");
def->min = 0; def->min = 0;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.049)); def->set_default_value(new ConfigOptionFloat(0.049));
def = this->add("print_host", coString); def = this->add("print_host", coString);
def->label = L("Hostname, IP or URL"); def->label = L("Hostname, IP or URL");
@ -117,9 +117,9 @@ void PrintConfigDef::init_fff_params()
// Maximum extruder temperature, bumped to 1500 to support printing of glass. // Maximum extruder temperature, bumped to 1500 to support printing of glass.
const int max_temp = 1500; const int max_temp = 1500;
def = this->add("avoid_crossing_perimeters", coBool); def = this->add("avoid_crossing_perimeters", coBool);
def->label = L("Avoid crossing perimeters"); def->label = L("Avoid crossing perimeters");
def->tooltip = L("Optimize travel moves in order to minimize the crossing of perimeters. " def->tooltip = L("Optimize travel moves in order to minimize the crossing of perimeters. "
"This is mostly useful with Bowden extruders which suffer from oozing. " "This is mostly useful with Bowden extruders which suffer from oozing. "
"This feature slows down both the print and the G-code generation."); "This feature slows down both the print and the G-code generation.");
def->mode = comExpert; def->mode = comExpert;
@ -178,7 +178,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Bridging angle override. If left to zero, the bridging angle will be calculated " def->tooltip = L("Bridging angle override. If left to zero, the bridging angle will be calculated "
"automatically. Otherwise the provided angle will be used for all bridges. " "automatically. Otherwise the provided angle will be used for all bridges. "
"Use 180° for zero angle."); "Use 180° for zero angle.");
def->sidetext = L("°"); def->sidetext = L("°");
def->min = 0; def->min = 0;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.)); def->set_default_value(new ConfigOptionFloat(0.));
@ -200,9 +200,9 @@ void PrintConfigDef::init_fff_params()
"although default settings are usually good and you should experiment " "although default settings are usually good and you should experiment "
"with cooling (use a fan) before tweaking this."); "with cooling (use a fan) before tweaking this.");
def->min = 0; def->min = 0;
def->max = 2; def->max = 2;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(1)); def->set_default_value(new ConfigOptionFloat(1));
def = this->add("bridge_speed", coFloat); def = this->add("bridge_speed", coFloat);
def->label = L("Bridges"); def->label = L("Bridges");
@ -678,7 +678,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("This string is edited by RammingDialog and contains ramming specific parameters."); def->tooltip = L("This string is edited by RammingDialog and contains ramming specific parameters.");
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionStrings { "120 100 6.6 6.8 7.2 7.6 7.9 8.2 8.7 9.4 9.9 10.0|" def->set_default_value(new ConfigOptionStrings { "120 100 6.6 6.8 7.2 7.6 7.9 8.2 8.7 9.4 9.9 10.0|"
" 0.05 6.6 0.45 6.8 0.95 7.8 1.45 8.3 1.95 9.7 2.45 10 2.95 7.6 3.45 7.6 3.95 7.6 4.45 7.6 4.95 7.6" }); " 0.05 6.6 0.45 6.8 0.95 7.8 1.45 8.3 1.95 9.7 2.45 10 2.95 7.6 3.45 7.6 3.95 7.6 4.45 7.6 4.95 7.6" });
def = this->add("filament_unload_time", coFloats); def = this->add("filament_unload_time", coFloats);
def->label = L("Filament unload time"); def->label = L("Filament unload time");
@ -1073,85 +1073,85 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(false)); def->set_default_value(new ConfigOptionBool(false));
def = this->add("silent_mode", coBool); def = this->add("silent_mode", coBool);
def->label = L("Supports stealth mode"); def->label = L("Supports stealth mode");
def->tooltip = L("The firmware supports stealth mode"); def->tooltip = L("The firmware supports stealth mode");
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(true)); def->set_default_value(new ConfigOptionBool(true));
const int machine_limits_opt_width = 7; const int machine_limits_opt_width = 7;
{ {
struct AxisDefault { struct AxisDefault {
std::string name; std::string name;
std::vector<double> max_feedrate; std::vector<double> max_feedrate;
std::vector<double> max_acceleration; std::vector<double> max_acceleration;
std::vector<double> max_jerk; std::vector<double> max_jerk;
}; };
std::vector<AxisDefault> axes { std::vector<AxisDefault> axes {
// name, max_feedrate, max_acceleration, max_jerk // name, max_feedrate, max_acceleration, max_jerk
{ "x", { 500., 200. }, { 9000., 1000. }, { 10. , 10. } }, { "x", { 500., 200. }, { 9000., 1000. }, { 10. , 10. } },
{ "y", { 500., 200. }, { 9000., 1000. }, { 10. , 10. } }, { "y", { 500., 200. }, { 9000., 1000. }, { 10. , 10. } },
{ "z", { 12., 12. }, { 500., 200. }, { 0.2, 0.4 } }, { "z", { 12., 12. }, { 500., 200. }, { 0.2, 0.4 } },
{ "e", { 120., 120. }, { 10000., 5000. }, { 2.5, 2.5 } } { "e", { 120., 120. }, { 10000., 5000. }, { 2.5, 2.5 } }
}; };
for (const AxisDefault &axis : axes) { for (const AxisDefault &axis : axes) {
std::string axis_upper = boost::to_upper_copy<std::string>(axis.name); std::string axis_upper = boost::to_upper_copy<std::string>(axis.name);
// Add the machine feedrate limits for XYZE axes. (M203) // Add the machine feedrate limits for XYZE axes. (M203)
def = this->add("machine_max_feedrate_" + axis.name, coFloats); def = this->add("machine_max_feedrate_" + axis.name, coFloats);
def->full_label = (boost::format("Maximum feedrate %1%") % axis_upper).str(); def->full_label = (boost::format("Maximum feedrate %1%") % axis_upper).str();
(void)L("Maximum feedrate X"); (void)L("Maximum feedrate X");
(void)L("Maximum feedrate Y"); (void)L("Maximum feedrate Y");
(void)L("Maximum feedrate Z"); (void)L("Maximum feedrate Z");
(void)L("Maximum feedrate E"); (void)L("Maximum feedrate E");
def->category = L("Machine limits"); def->category = L("Machine limits");
def->tooltip = (boost::format("Maximum feedrate of the %1% axis") % axis_upper).str(); def->tooltip = (boost::format("Maximum feedrate of the %1% axis") % axis_upper).str();
(void)L("Maximum feedrate of the X axis"); (void)L("Maximum feedrate of the X axis");
(void)L("Maximum feedrate of the Y axis"); (void)L("Maximum feedrate of the Y axis");
(void)L("Maximum feedrate of the Z axis"); (void)L("Maximum feedrate of the Z axis");
(void)L("Maximum feedrate of the E axis"); (void)L("Maximum feedrate of the E axis");
def->sidetext = L("mm/s"); def->sidetext = L("mm/s");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_feedrate)); def->set_default_value(new ConfigOptionFloats(axis.max_feedrate));
// Add the machine acceleration limits for XYZE axes (M201) // Add the machine acceleration limits for XYZE axes (M201)
def = this->add("machine_max_acceleration_" + axis.name, coFloats); def = this->add("machine_max_acceleration_" + axis.name, coFloats);
def->full_label = (boost::format("Maximum acceleration %1%") % axis_upper).str(); def->full_label = (boost::format("Maximum acceleration %1%") % axis_upper).str();
(void)L("Maximum acceleration X"); (void)L("Maximum acceleration X");
(void)L("Maximum acceleration Y"); (void)L("Maximum acceleration Y");
(void)L("Maximum acceleration Z"); (void)L("Maximum acceleration Z");
(void)L("Maximum acceleration E"); (void)L("Maximum acceleration E");
def->category = L("Machine limits"); def->category = L("Machine limits");
def->tooltip = (boost::format("Maximum acceleration of the %1% axis") % axis_upper).str(); def->tooltip = (boost::format("Maximum acceleration of the %1% axis") % axis_upper).str();
(void)L("Maximum acceleration of the X axis"); (void)L("Maximum acceleration of the X axis");
(void)L("Maximum acceleration of the Y axis"); (void)L("Maximum acceleration of the Y axis");
(void)L("Maximum acceleration of the Z axis"); (void)L("Maximum acceleration of the Z axis");
(void)L("Maximum acceleration of the E axis"); (void)L("Maximum acceleration of the E axis");
def->sidetext = L("mm/s²"); def->sidetext = L("mm/s²");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_acceleration)); def->set_default_value(new ConfigOptionFloats(axis.max_acceleration));
// Add the machine jerk limits for XYZE axes (M205) // Add the machine jerk limits for XYZE axes (M205)
def = this->add("machine_max_jerk_" + axis.name, coFloats); def = this->add("machine_max_jerk_" + axis.name, coFloats);
def->full_label = (boost::format("Maximum jerk %1%") % axis_upper).str(); def->full_label = (boost::format("Maximum jerk %1%") % axis_upper).str();
(void)L("Maximum jerk X"); (void)L("Maximum jerk X");
(void)L("Maximum jerk Y"); (void)L("Maximum jerk Y");
(void)L("Maximum jerk Z"); (void)L("Maximum jerk Z");
(void)L("Maximum jerk E"); (void)L("Maximum jerk E");
def->category = L("Machine limits"); def->category = L("Machine limits");
def->tooltip = (boost::format("Maximum jerk of the %1% axis") % axis_upper).str(); def->tooltip = (boost::format("Maximum jerk of the %1% axis") % axis_upper).str();
(void)L("Maximum jerk of the X axis"); (void)L("Maximum jerk of the X axis");
(void)L("Maximum jerk of the Y axis"); (void)L("Maximum jerk of the Y axis");
(void)L("Maximum jerk of the Z axis"); (void)L("Maximum jerk of the Z axis");
(void)L("Maximum jerk of the E axis"); (void)L("Maximum jerk of the E axis");
def->sidetext = L("mm/s"); def->sidetext = L("mm/s");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_jerk)); def->set_default_value(new ConfigOptionFloats(axis.max_jerk));
} }
} }
// M205 S... [mm/sec] // M205 S... [mm/sec]
def = this->add("machine_min_extruding_rate", coFloats); def = this->add("machine_min_extruding_rate", coFloats);
@ -1160,9 +1160,9 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Minimum feedrate when extruding (M205 S)"); def->tooltip = L("Minimum feedrate when extruding (M205 S)");
def->sidetext = L("mm/s"); def->sidetext = L("mm/s");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 0., 0. }); def->set_default_value(new ConfigOptionFloats{ 0., 0. });
// M205 T... [mm/sec] // M205 T... [mm/sec]
def = this->add("machine_min_travel_rate", coFloats); def = this->add("machine_min_travel_rate", coFloats);
@ -1171,9 +1171,9 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Minimum travel feedrate (M205 T)"); def->tooltip = L("Minimum travel feedrate (M205 T)");
def->sidetext = L("mm/s"); def->sidetext = L("mm/s");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 0., 0. }); def->set_default_value(new ConfigOptionFloats{ 0., 0. });
// M204 S... [mm/sec^2] // M204 S... [mm/sec^2]
def = this->add("machine_max_acceleration_extruding", coFloats); def = this->add("machine_max_acceleration_extruding", coFloats);
@ -1182,7 +1182,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Maximum acceleration when extruding (M204 S)"); def->tooltip = L("Maximum acceleration when extruding (M204 S)");
def->sidetext = L("mm/s²"); def->sidetext = L("mm/s²");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); def->set_default_value(new ConfigOptionFloats{ 1500., 1250. });
@ -1193,7 +1193,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Maximum acceleration when retracting (M204 T)"); def->tooltip = L("Maximum acceleration when retracting (M204 T)");
def->sidetext = L("mm/s²"); def->sidetext = L("mm/s²");
def->min = 0; def->min = 0;
def->width = machine_limits_opt_width; def->width = machine_limits_opt_width;
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); def->set_default_value(new ConfigOptionFloats{ 1500., 1250. });
@ -1437,9 +1437,9 @@ void PrintConfigDef::init_fff_params()
def->gui_flags = "serialized"; def->gui_flags = "serialized";
def->multiline = true; def->multiline = true;
def->full_width = true; def->full_width = true;
def->height = 6; def->height = 6;
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionStrings()); def->set_default_value(new ConfigOptionStrings());
def = this->add("printer_model", coString); def = this->add("printer_model", coString);
def->label = L("Printer type"); def->label = L("Printer type");
@ -1775,7 +1775,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Temperature variation"); def->label = L("Temperature variation");
def->tooltip = L("Temperature difference to be applied when an extruder is not active. " def->tooltip = L("Temperature difference to be applied when an extruder is not active. "
"Enables a full-height \"sacrificial\" skirt on which the nozzles are periodically wiped."); "Enables a full-height \"sacrificial\" skirt on which the nozzles are periodically wiped.");
def->sidetext = "∆°C"; def->sidetext = "∆°C";
def->min = -max_temp; def->min = -max_temp;
def->max = max_temp; def->max = max_temp;
def->mode = comExpert; def->mode = comExpert;
@ -1817,7 +1817,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Single Extruder Multi Material"); def->label = L("Single Extruder Multi Material");
def->tooltip = L("The printer multiplexes filaments into a single hot end."); def->tooltip = L("The printer multiplexes filaments into a single hot end.");
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(false)); def->set_default_value(new ConfigOptionBool(false));
def = this->add("single_extruder_multi_material_priming", coBool); def = this->add("single_extruder_multi_material_priming", coBool);
def->label = L("Prime all printing extruders"); def->label = L("Prime all printing extruders");
@ -1879,8 +1879,8 @@ void PrintConfigDef::init_fff_params()
// def->min = 0; // def->min = 0;
def->enum_values.push_back("0"); def->enum_values.push_back("0");
def->enum_values.push_back("0.2"); def->enum_values.push_back("0.2");
def->enum_labels.push_back(L("0 (soluble)")); def->enum_labels.push_back(L("0 (soluble)"));
def->enum_labels.push_back(L("0.2 (detachable)")); def->enum_labels.push_back(L("0.2 (detachable)"));
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.2)); def->set_default_value(new ConfigOptionFloat(0.2));
@ -1969,7 +1969,7 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("rectilinear"); def->enum_values.push_back("rectilinear");
def->enum_values.push_back("rectilinear-grid"); def->enum_values.push_back("rectilinear-grid");
def->enum_values.push_back("honeycomb"); def->enum_values.push_back("honeycomb");
def->enum_labels.push_back(L("Rectilinear")); def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Rectilinear grid")); def->enum_labels.push_back(L("Rectilinear grid"));
def->enum_labels.push_back(L("Honeycomb")); def->enum_labels.push_back(L("Honeycomb"));
def->mode = comAdvanced; def->mode = comAdvanced;
@ -2243,45 +2243,45 @@ void PrintConfigDef::init_fff_params()
// Declare retract values for filament profile, overriding the printer's extruder profile. // Declare retract values for filament profile, overriding the printer's extruder profile.
for (const char *opt_key : { for (const char *opt_key : {
// floats // floats
"retract_length", "retract_lift", "retract_lift_above", "retract_lift_below", "retract_speed", "deretract_speed", "retract_restart_extra", "retract_before_travel", "retract_length", "retract_lift", "retract_lift_above", "retract_lift_below", "retract_speed", "deretract_speed", "retract_restart_extra", "retract_before_travel",
// bools // bools
"retract_layer_change", "wipe", "retract_layer_change", "wipe",
// percents // percents
"retract_before_wipe"}) { "retract_before_wipe"}) {
auto it_opt = options.find(opt_key); auto it_opt = options.find(opt_key);
assert(it_opt != options.end()); assert(it_opt != options.end());
def = this->add_nullable(std::string("filament_") + opt_key, it_opt->second.type); def = this->add_nullable(std::string("filament_") + opt_key, it_opt->second.type);
def->label = it_opt->second.label; def->label = it_opt->second.label;
def->full_label = it_opt->second.full_label; def->full_label = it_opt->second.full_label;
def->tooltip = it_opt->second.tooltip; def->tooltip = it_opt->second.tooltip;
def->sidetext = it_opt->second.sidetext; def->sidetext = it_opt->second.sidetext;
def->mode = it_opt->second.mode; def->mode = it_opt->second.mode;
switch (def->type) { switch (def->type) {
case coFloats : def->set_default_value(new ConfigOptionFloatsNullable (static_cast<const ConfigOptionFloats* >(it_opt->second.default_value.get())->values)); break; case coFloats : def->set_default_value(new ConfigOptionFloatsNullable (static_cast<const ConfigOptionFloats* >(it_opt->second.default_value.get())->values)); break;
case coPercents : def->set_default_value(new ConfigOptionPercentsNullable(static_cast<const ConfigOptionPercents*>(it_opt->second.default_value.get())->values)); break; case coPercents : def->set_default_value(new ConfigOptionPercentsNullable(static_cast<const ConfigOptionPercents*>(it_opt->second.default_value.get())->values)); break;
case coBools : def->set_default_value(new ConfigOptionBoolsNullable (static_cast<const ConfigOptionBools* >(it_opt->second.default_value.get())->values)); break; case coBools : def->set_default_value(new ConfigOptionBoolsNullable (static_cast<const ConfigOptionBools* >(it_opt->second.default_value.get())->values)); break;
default: assert(false); default: assert(false);
} }
} }
} }
void PrintConfigDef::init_extruder_retract_keys() void PrintConfigDef::init_extruder_retract_keys()
{ {
m_extruder_retract_keys = { m_extruder_retract_keys = {
"deretract_speed", "deretract_speed",
"retract_before_travel", "retract_before_travel",
"retract_before_wipe", "retract_before_wipe",
"retract_layer_change", "retract_layer_change",
"retract_length", "retract_length",
"retract_lift", "retract_lift",
"retract_lift_above", "retract_lift_above",
"retract_lift_below", "retract_lift_below",
"retract_restart_extra", "retract_restart_extra",
"retract_speed", "retract_speed",
"wipe" "wipe"
}; };
assert(std::is_sorted(m_extruder_retract_keys.begin(), m_extruder_retract_keys.end())); assert(std::is_sorted(m_extruder_retract_keys.begin(), m_extruder_retract_keys.end()));
} }
void PrintConfigDef::init_sla_params() void PrintConfigDef::init_sla_params()
@ -2676,14 +2676,14 @@ void PrintConfigDef::init_sla_params()
def->set_default_value(new ConfigOptionFloat(50.0)); def->set_default_value(new ConfigOptionFloat(50.0));
// This is disabled on the UI. I hope it will never be enabled. // This is disabled on the UI. I hope it will never be enabled.
def = this->add("pad_edge_radius", coFloat); // def = this->add("pad_edge_radius", coFloat);
def->label = L("Pad edge radius"); // def->label = L("Pad edge radius");
def->category = L("Pad"); // def->category = L("Pad");
// def->tooltip = L(""); //// def->tooltip = L("");
def->sidetext = L("mm"); // def->sidetext = L("mm");
def->min = 0; // def->min = 0;
def->mode = comAdvanced; // def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(1.0)); // def->set_default_value(new ConfigOptionFloat(1.0));
def = this->add("pad_wall_slope", coFloat); def = this->add("pad_wall_slope", coFloat);
def->label = L("Pad wall slope"); def->label = L("Pad wall slope");
@ -2696,6 +2696,13 @@ void PrintConfigDef::init_sla_params()
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(45.0)); def->set_default_value(new ConfigOptionFloat(45.0));
def = this->add("pad_zero_elevation", coBool);
def->label = L("Pad around object");
def->category = L("Pad");
def->tooltip = L("Create pad around object and ignore the support elevation");
def->mode = comSimple;
def->set_default_value(new ConfigOptionBool(false));
def = this->add("pad_object_gap", coFloat); def = this->add("pad_object_gap", coFloat);
def->label = L("Pad object gap"); def->label = L("Pad object gap");
def->category = L("Pad"); def->category = L("Pad");
@ -2866,8 +2873,8 @@ void DynamicPrintConfig::normalize()
std::string DynamicPrintConfig::validate() std::string DynamicPrintConfig::validate()
{ {
// Full print config is initialized from the defaults. // Full print config is initialized from the defaults.
const ConfigOption *opt = this->option("printer_technology", false); const ConfigOption *opt = this->option("printer_technology", false);
auto printer_technology = (opt == nullptr) ? ptFFF : static_cast<PrinterTechnology>(dynamic_cast<const ConfigOptionEnumGeneric*>(opt)->value); auto printer_technology = (opt == nullptr) ? ptFFF : static_cast<PrinterTechnology>(dynamic_cast<const ConfigOptionEnumGeneric*>(opt)->value);
switch (printer_technology) { switch (printer_technology) {
case ptFFF: case ptFFF:
{ {
@ -3299,11 +3306,11 @@ DynamicPrintAndCLIConfig::PrintAndCLIConfigDef DynamicPrintAndCLIConfig::s_def;
void DynamicPrintAndCLIConfig::handle_legacy(t_config_option_key &opt_key, std::string &value) const void DynamicPrintAndCLIConfig::handle_legacy(t_config_option_key &opt_key, std::string &value) const
{ {
if (cli_actions_config_def .options.find(opt_key) == cli_actions_config_def .options.end() && if (cli_actions_config_def .options.find(opt_key) == cli_actions_config_def .options.end() &&
cli_transform_config_def.options.find(opt_key) == cli_transform_config_def.options.end() && cli_transform_config_def.options.find(opt_key) == cli_transform_config_def.options.end() &&
cli_misc_config_def .options.find(opt_key) == cli_misc_config_def .options.end()) { cli_misc_config_def .options.find(opt_key) == cli_misc_config_def .options.end()) {
PrintConfigDef::handle_legacy(opt_key, value); PrintConfigDef::handle_legacy(opt_key, value);
} }
} }
} }

View File

@ -740,7 +740,7 @@ protected:
class PrintConfig : public MachineEnvelopeConfig, public GCodeConfig class PrintConfig : public MachineEnvelopeConfig, public GCodeConfig
{ {
STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig) STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig)
PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); } PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); }
public: public:
double min_object_distance() const; double min_object_distance() const;
static double min_object_distance(const ConfigBase *config); static double min_object_distance(const ConfigBase *config);
@ -812,7 +812,7 @@ public:
ConfigOptionFloat z_offset; ConfigOptionFloat z_offset;
protected: protected:
PrintConfig(int) : MachineEnvelopeConfig(1), GCodeConfig(1) {} PrintConfig(int) : MachineEnvelopeConfig(1), GCodeConfig(1) {}
void initialize(StaticCacheBase &cache, const char *base_ptr) void initialize(StaticCacheBase &cache, const char *base_ptr)
{ {
this->MachineEnvelopeConfig::initialize(cache, base_ptr); this->MachineEnvelopeConfig::initialize(cache, base_ptr);
@ -1028,7 +1028,7 @@ public:
ConfigOptionFloat pad_max_merge_distance /*= 50*/; ConfigOptionFloat pad_max_merge_distance /*= 50*/;
// The smoothing radius of the pad edges // The smoothing radius of the pad edges
ConfigOptionFloat pad_edge_radius /*= 1*/; // ConfigOptionFloat pad_edge_radius /*= 1*/;
// The slope of the pad wall... // The slope of the pad wall...
ConfigOptionFloat pad_wall_slope; ConfigOptionFloat pad_wall_slope;
@ -1041,6 +1041,9 @@ public:
// - The two pads will be connected with tiny connector sticks // - The two pads will be connected with tiny connector sticks
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
// Disable the elevation (ignore its value) and use the zero elevation mode
ConfigOptionBool pad_zero_elevation;
// This is the gap between the object bottom and the generated pad // This is the gap between the object bottom and the generated pad
ConfigOptionFloat pad_object_gap; ConfigOptionFloat pad_object_gap;
@ -1080,8 +1083,9 @@ protected:
OPT_PTR(pad_wall_thickness); OPT_PTR(pad_wall_thickness);
OPT_PTR(pad_wall_height); OPT_PTR(pad_wall_height);
OPT_PTR(pad_max_merge_distance); OPT_PTR(pad_max_merge_distance);
OPT_PTR(pad_edge_radius); // OPT_PTR(pad_edge_radius);
OPT_PTR(pad_wall_slope); OPT_PTR(pad_wall_slope);
OPT_PTR(pad_zero_elevation);
OPT_PTR(pad_object_gap); OPT_PTR(pad_object_gap);
OPT_PTR(pad_object_connector_stride); OPT_PTR(pad_object_connector_stride);
OPT_PTR(pad_object_connector_width); OPT_PTR(pad_object_connector_width);
@ -1205,8 +1209,8 @@ extern const CLIMiscConfigDef cli_misc_config_def;
class DynamicPrintAndCLIConfig : public DynamicPrintConfig class DynamicPrintAndCLIConfig : public DynamicPrintConfig
{ {
public: public:
DynamicPrintAndCLIConfig() {} DynamicPrintAndCLIConfig() {}
DynamicPrintAndCLIConfig(const DynamicPrintAndCLIConfig &other) : DynamicPrintConfig(other) {} DynamicPrintAndCLIConfig(const DynamicPrintAndCLIConfig &other) : DynamicPrintConfig(other) {}
// Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here. // Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here.
const ConfigDef* def() const override { return &s_def; } const ConfigDef* def() const override { return &s_def; }
@ -1227,7 +1231,7 @@ private:
this->options.insert(cli_transform_config_def.options.begin(), cli_transform_config_def.options.end()); this->options.insert(cli_transform_config_def.options.begin(), cli_transform_config_def.options.end());
this->options.insert(cli_misc_config_def.options.begin(), cli_misc_config_def.options.end()); this->options.insert(cli_misc_config_def.options.begin(), cli_misc_config_def.options.end());
for (const auto &kvp : this->options) for (const auto &kvp : this->options)
this->by_serialization_key_ordinal[kvp.second.serialization_key_ordinal] = &kvp.second; this->by_serialization_key_ordinal[kvp.second.serialization_key_ordinal] = &kvp.second;
} }
// Do not release the default values, they are handled by print_config_def & cli_actions_config_def / cli_transform_config_def / cli_misc_config_def. // Do not release the default values, they are handled by print_config_def & cli_actions_config_def / cli_transform_config_def / cli_misc_config_def.
~PrintAndCLIConfigDef() { this->options.clear(); } ~PrintAndCLIConfigDef() { this->options.clear(); }
@ -1239,36 +1243,36 @@ private:
// Serialization through the Cereal library // Serialization through the Cereal library
namespace cereal { namespace cereal {
// Let cereal know that there are load / save non-member functions declared for DynamicPrintConfig, ignore serialize / load / save from parent class DynamicConfig. // Let cereal know that there are load / save non-member functions declared for DynamicPrintConfig, ignore serialize / load / save from parent class DynamicConfig.
template <class Archive> struct specialize<Archive, Slic3r::DynamicPrintConfig, cereal::specialization::non_member_load_save> {}; template <class Archive> struct specialize<Archive, Slic3r::DynamicPrintConfig, cereal::specialization::non_member_load_save> {};
template<class Archive> void load(Archive& archive, Slic3r::DynamicPrintConfig &config) template<class Archive> void load(Archive& archive, Slic3r::DynamicPrintConfig &config)
{ {
size_t cnt; size_t cnt;
archive(cnt); archive(cnt);
config.clear(); config.clear();
for (size_t i = 0; i < cnt; ++ i) { for (size_t i = 0; i < cnt; ++ i) {
size_t serialization_key_ordinal; size_t serialization_key_ordinal;
archive(serialization_key_ordinal); archive(serialization_key_ordinal);
assert(serialization_key_ordinal > 0); assert(serialization_key_ordinal > 0);
auto it = Slic3r::print_config_def.by_serialization_key_ordinal.find(serialization_key_ordinal); auto it = Slic3r::print_config_def.by_serialization_key_ordinal.find(serialization_key_ordinal);
assert(it != Slic3r::print_config_def.by_serialization_key_ordinal.end()); assert(it != Slic3r::print_config_def.by_serialization_key_ordinal.end());
config.set_key_value(it->second->opt_key, it->second->load_option_from_archive(archive)); config.set_key_value(it->second->opt_key, it->second->load_option_from_archive(archive));
} }
} }
template<class Archive> void save(Archive& archive, const Slic3r::DynamicPrintConfig &config) template<class Archive> void save(Archive& archive, const Slic3r::DynamicPrintConfig &config)
{ {
size_t cnt = config.size(); size_t cnt = config.size();
archive(cnt); archive(cnt);
for (auto it = config.cbegin(); it != config.cend(); ++it) { for (auto it = config.cbegin(); it != config.cend(); ++it) {
const Slic3r::ConfigOptionDef* optdef = Slic3r::print_config_def.get(it->first); const Slic3r::ConfigOptionDef* optdef = Slic3r::print_config_def.get(it->first);
assert(optdef != nullptr); assert(optdef != nullptr);
assert(optdef->serialization_key_ordinal > 0); assert(optdef->serialization_key_ordinal > 0);
archive(optdef->serialization_key_ordinal); archive(optdef->serialization_key_ordinal);
optdef->save_option_to_archive(archive, it->second.get()); optdef->save_option_to_archive(archive, it->second.get());
} }
} }
} }
#endif #endif

View File

@ -365,7 +365,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
// Synchronize Object's config. // Synchronize Object's config.
bool object_config_changed = model_object.config != model_object_new.config; bool object_config_changed = model_object.config != model_object_new.config;
if (object_config_changed) if (object_config_changed)
static_cast<DynamicPrintConfig&>(model_object.config) = static_cast<const DynamicPrintConfig&>(model_object_new.config); static_cast<DynamicPrintConfig&>(model_object.config) = static_cast<const DynamicPrintConfig&>(model_object_new.config);
if (! object_diff.empty() || object_config_changed) { if (! object_diff.empty() || object_config_changed) {
SLAPrintObjectConfig new_config = m_default_object_config; SLAPrintObjectConfig new_config = m_default_object_config;
normalize_and_apply_config(new_config, model_object.config); normalize_and_apply_config(new_config, model_object.config);
@ -425,9 +425,9 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
print_object->set_instances(std::move(new_instances)); print_object->set_instances(std::move(new_instances));
SLAPrintObjectConfig new_config = m_default_object_config; SLAPrintObjectConfig new_config = m_default_object_config;
normalize_and_apply_config(new_config, model_object.config); normalize_and_apply_config(new_config, model_object.config);
print_object->config_apply(new_config, true); print_object->config_apply(new_config, true);
print_objects_new.emplace_back(print_object); print_objects_new.emplace_back(print_object);
new_objects = true; new_objects = true;
} }
@ -569,6 +569,16 @@ std::string SLAPrint::output_filename(const std::string &filename_base) const
} }
namespace { namespace {
bool is_zero_elevation(const SLAPrintObjectConfig &c) {
bool en_implicit = c.support_object_elevation.getFloat() <= EPSILON &&
c.pad_enable.getBool() && c.supports_enable.getBool();
bool en_explicit = c.pad_zero_elevation.getBool() &&
c.supports_enable.getBool();
return en_implicit || en_explicit;
}
// Compile the argument for support creation from the static print config. // Compile the argument for support creation from the static print config.
sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) { sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) {
sla::SupportConfig scfg; sla::SupportConfig scfg;
@ -577,7 +587,8 @@ sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) {
scfg.head_back_radius_mm = 0.5*c.support_pillar_diameter.getFloat(); scfg.head_back_radius_mm = 0.5*c.support_pillar_diameter.getFloat();
scfg.head_penetration_mm = c.support_head_penetration.getFloat(); scfg.head_penetration_mm = c.support_head_penetration.getFloat();
scfg.head_width_mm = c.support_head_width.getFloat(); scfg.head_width_mm = c.support_head_width.getFloat();
scfg.object_elevation_mm = c.support_object_elevation.getFloat(); scfg.object_elevation_mm = is_zero_elevation(c) ?
0. : c.support_object_elevation.getFloat();
scfg.bridge_slope = c.support_critical_angle.getFloat() * PI / 180.0 ; scfg.bridge_slope = c.support_critical_angle.getFloat() * PI / 180.0 ;
scfg.max_bridge_length_mm = c.support_max_bridge_length.getFloat(); scfg.max_bridge_length_mm = c.support_max_bridge_length.getFloat();
scfg.max_pillar_link_distance_mm = c.support_max_pillar_link_distance.getFloat(); scfg.max_pillar_link_distance_mm = c.support_max_pillar_link_distance.getFloat();
@ -603,8 +614,7 @@ sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) {
sla::PoolConfig::EmbedObject builtin_pad_cfg(const SLAPrintObjectConfig& c) { sla::PoolConfig::EmbedObject builtin_pad_cfg(const SLAPrintObjectConfig& c) {
sla::PoolConfig::EmbedObject ret; sla::PoolConfig::EmbedObject ret;
ret.enabled = c.support_object_elevation.getFloat() <= EPSILON && ret.enabled = is_zero_elevation(c);
c.pad_enable.getBool() && c.supports_enable.getBool();
if(ret.enabled) { if(ret.enabled) {
ret.object_gap_mm = c.pad_object_gap.getFloat(); ret.object_gap_mm = c.pad_object_gap.getFloat();
@ -661,7 +671,9 @@ std::string SLAPrint::validate() const
double elv = cfg.object_elevation_mm; double elv = cfg.object_elevation_mm;
if(supports_en && elv > EPSILON && elv < pinhead_width ) if(supports_en && elv > EPSILON && elv < pinhead_width )
return L("Elevation is too low for object."); return L(
"Elevation is too low for object. Use the \"Pad around "
"obect\" feature to print the object without elevation.");
sla::PoolConfig::EmbedObject builtinpad = builtin_pad_cfg(po->config()); sla::PoolConfig::EmbedObject builtinpad = builtin_pad_cfg(po->config());
if(supports_en && builtinpad.enabled && if(supports_en && builtinpad.enabled &&
@ -879,7 +891,7 @@ void SLAPrint::process()
// If the zero elevation mode is engaged, we have to filter out all the // If the zero elevation mode is engaged, we have to filter out all the
// points that are on the bottom of the object // points that are on the bottom of the object
if (po.config().support_object_elevation.getFloat() <= EPSILON) { if (is_zero_elevation(po.config())) {
double gnd = po.m_supportdata->emesh.ground_level(); double gnd = po.m_supportdata->emesh.ground_level();
auto & pts = po.m_supportdata->support_points; auto & pts = po.m_supportdata->support_points;
double tolerance = po.config().pad_enable.getBool() double tolerance = po.config().pad_enable.getBool()
@ -1647,6 +1659,7 @@ bool SLAPrintObject::invalidate_state_by_config_options(const std::vector<t_conf
|| opt_key == "pad_wall_thickness" || opt_key == "pad_wall_thickness"
|| opt_key == "supports_enable" || opt_key == "supports_enable"
|| opt_key == "support_object_elevation" || opt_key == "support_object_elevation"
|| opt_key == "pad_zero_elevation"
|| opt_key == "slice_closing_radius") { || opt_key == "slice_closing_radius") {
steps.emplace_back(slaposObjectSlice); steps.emplace_back(slaposObjectSlice);
} else if ( } else if (
@ -1719,7 +1732,10 @@ bool SLAPrintObject::invalidate_all_steps()
} }
double SLAPrintObject::get_elevation() const { double SLAPrintObject::get_elevation() const {
bool en = m_config.supports_enable.getBool(); if (is_zero_elevation(m_config)) return 0.;
bool en = m_config.supports_enable.getBool();
double ret = en ? m_config.support_object_elevation.getFloat() : 0.; double ret = en ? m_config.support_object_elevation.getFloat() : 0.;
if(m_config.pad_enable.getBool()) { if(m_config.pad_enable.getBool()) {
@ -1736,8 +1752,10 @@ double SLAPrintObject::get_elevation() const {
double SLAPrintObject::get_current_elevation() const double SLAPrintObject::get_current_elevation() const
{ {
if (is_zero_elevation(m_config)) return 0.;
bool has_supports = is_step_done(slaposSupportTree); bool has_supports = is_step_done(slaposSupportTree);
bool has_pad = is_step_done(slaposBasePool); bool has_pad = is_step_done(slaposBasePool);
if(!has_supports && !has_pad) if(!has_supports && !has_pad)
return 0; return 0;

View File

@ -162,11 +162,11 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
if (from_pre_map != pre_family_model_map.end()) { model.family = from_pre_map->second; } if (from_pre_map != pre_family_model_map.end()) { model.family = from_pre_map->second; }
} }
#if 0 #if 0
// Remove SLA printers from the initial alpha. // Remove SLA printers from the initial alpha.
if (model.technology == ptSLA) if (model.technology == ptSLA)
continue; continue;
#endif #endif
section.second.get<std::string>("variants", ""); section.second.get<std::string>("variants", "");
const auto variants_field = section.second.get<std::string>("variants", ""); const auto variants_field = section.second.get<std::string>("variants", "");
std::vector<std::string> variants; std::vector<std::string> variants;
if (Slic3r::unescape_strings_cstyle(variants_field, variants)) { if (Slic3r::unescape_strings_cstyle(variants_field, variants)) {
@ -209,7 +209,7 @@ const std::string& Preset::suffix_modified()
void Preset::update_suffix_modified() void Preset::update_suffix_modified()
{ {
g_suffix_modified = (" (" + _(L("modified")) + ")").ToUTF8().data(); g_suffix_modified = (" (" + _(L("modified")) + ")").ToUTF8().data();
} }
// Remove an optional "(modified)" suffix from a name. // Remove an optional "(modified)" suffix from a name.
// This converts a UI name to a unique preset identifier. // This converts a UI name to a unique preset identifier.
@ -224,8 +224,8 @@ void Preset::set_num_extruders(DynamicPrintConfig &config, unsigned int num_extr
{ {
const auto &defaults = FullPrintConfig::defaults(); const auto &defaults = FullPrintConfig::defaults();
for (const std::string &key : Preset::nozzle_options()) { for (const std::string &key : Preset::nozzle_options()) {
if (key == "default_filament_profile") if (key == "default_filament_profile")
continue; continue;
auto *opt = config.option(key, false); auto *opt = config.option(key, false);
assert(opt != nullptr); assert(opt != nullptr);
assert(opt->is_vector()); assert(opt->is_vector());
@ -247,8 +247,8 @@ void Preset::normalize(DynamicPrintConfig &config)
size_t n = (nozzle_diameter == nullptr) ? 1 : nozzle_diameter->values.size(); size_t n = (nozzle_diameter == nullptr) ? 1 : nozzle_diameter->values.size();
const auto &defaults = FullPrintConfig::defaults(); const auto &defaults = FullPrintConfig::defaults();
for (const std::string &key : Preset::filament_options()) { for (const std::string &key : Preset::filament_options()) {
if (key == "compatible_prints" || key == "compatible_printers") if (key == "compatible_prints" || key == "compatible_printers")
continue; continue;
auto *opt = config.option(key, false); auto *opt = config.option(key, false);
/*assert(opt != nullptr); /*assert(opt != nullptr);
assert(opt->is_vector());*/ assert(opt->is_vector());*/
@ -334,9 +334,9 @@ bool Preset::is_compatible_with_printer(const Preset &active_printer) const
{ {
DynamicPrintConfig config; DynamicPrintConfig config;
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name)); config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
const ConfigOption *opt = active_printer.config.option("nozzle_diameter"); const ConfigOption *opt = active_printer.config.option("nozzle_diameter");
if (opt) if (opt)
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size())); config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
return this->is_compatible_with_printer(active_printer, &config); return this->is_compatible_with_printer(active_printer, &config);
} }
@ -401,9 +401,9 @@ const std::vector<std::string>& Preset::filament_options()
"max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed", "max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed",
"start_filament_gcode", "end_filament_gcode", "start_filament_gcode", "end_filament_gcode",
// Retract overrides // Retract overrides
"filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra", "filament_retract_before_travel", "filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra", "filament_retract_before_travel",
"filament_retract_layer_change", "filament_wipe", "filament_retract_before_wipe", "filament_retract_layer_change", "filament_wipe", "filament_retract_before_wipe",
// Profile compatibility // Profile compatibility
"compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits" "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits"
}; };
return s_opts; return s_opts;
@ -423,10 +423,10 @@ const std::vector<std::string>& Preset::printer_options()
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height", "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height",
"default_print_profile", "inherits", "default_print_profile", "inherits",
"remaining_times", "silent_mode", "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", "remaining_times", "silent_mode", "machine_max_acceleration_extruding", "machine_max_acceleration_retracting",
"machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e", "machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e",
"machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e", "machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e",
"machine_min_extruding_rate", "machine_min_travel_rate", "machine_min_extruding_rate", "machine_min_travel_rate",
"machine_max_jerk_x", "machine_max_jerk_y", "machine_max_jerk_z", "machine_max_jerk_e" "machine_max_jerk_x", "machine_max_jerk_y", "machine_max_jerk_z", "machine_max_jerk_e"
}; };
s_opts.insert(s_opts.end(), Preset::nozzle_options().begin(), Preset::nozzle_options().end()); s_opts.insert(s_opts.end(), Preset::nozzle_options().begin(), Preset::nozzle_options().end());
} }
@ -477,9 +477,10 @@ const std::vector<std::string>& Preset::sla_print_options()
"pad_wall_thickness", "pad_wall_thickness",
"pad_wall_height", "pad_wall_height",
"pad_max_merge_distance", "pad_max_merge_distance",
"pad_edge_radius", // "pad_edge_radius",
"pad_wall_slope", "pad_wall_slope",
"pad_object_gap", "pad_object_gap",
"pad_zero_elevation",
"pad_object_connector_stride", "pad_object_connector_stride",
"pad_object_connector_width", "pad_object_connector_width",
"pad_object_connector_penetration", "pad_object_connector_penetration",
@ -539,7 +540,7 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::str
m_idx_selected(0), m_idx_selected(0),
m_bitmap_main_frame(new wxBitmap), m_bitmap_main_frame(new wxBitmap),
m_bitmap_add(new wxBitmap), m_bitmap_add(new wxBitmap),
m_bitmap_cache(new GUI::BitmapCache) m_bitmap_cache(new GUI::BitmapCache)
{ {
// Insert just the default preset. // Insert just the default preset.
this->add_default_preset(keys, defaults, default_name); this->add_default_preset(keys, defaults, default_name);
@ -552,8 +553,8 @@ PresetCollection::~PresetCollection()
m_bitmap_main_frame = nullptr; m_bitmap_main_frame = nullptr;
delete m_bitmap_add; delete m_bitmap_add;
m_bitmap_add = nullptr; m_bitmap_add = nullptr;
delete m_bitmap_cache; delete m_bitmap_cache;
m_bitmap_cache = nullptr; m_bitmap_cache = nullptr;
} }
void PresetCollection::reset(bool delete_files) void PresetCollection::reset(bool delete_files)
@ -575,8 +576,8 @@ void PresetCollection::add_default_preset(const std::vector<std::string> &keys,
{ {
// Insert just the default preset. // Insert just the default preset.
m_presets.emplace_back(Preset(this->type(), preset_name, true)); m_presets.emplace_back(Preset(this->type(), preset_name, true));
m_presets.back().config.apply_only(defaults, keys.empty() ? defaults.keys() : keys); m_presets.back().config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
m_presets.back().loaded = true; m_presets.back().loaded = true;
++ m_num_default_presets; ++ m_num_default_presets;
} }
@ -584,13 +585,13 @@ void PresetCollection::add_default_preset(const std::vector<std::string> &keys,
// Throws an exception on error. // Throws an exception on error.
void PresetCollection::load_presets(const std::string &dir_path, const std::string &subdir) void PresetCollection::load_presets(const std::string &dir_path, const std::string &subdir)
{ {
boost::filesystem::path dir = boost::filesystem::canonical(boost::filesystem::path(dir_path) / subdir).make_preferred(); boost::filesystem::path dir = boost::filesystem::canonical(boost::filesystem::path(dir_path) / subdir).make_preferred();
m_dir_path = dir.string(); m_dir_path = dir.string();
std::string errors_cummulative; std::string errors_cummulative;
// Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken. // Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
// (see the "Preset already present, not loading" message). // (see the "Preset already present, not loading" message).
std::deque<Preset> presets_loaded; std::deque<Preset> presets_loaded;
for (auto &dir_entry : boost::filesystem::directory_iterator(dir)) for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
if (Slic3r::is_ini_file(dir_entry)) { if (Slic3r::is_ini_file(dir_entry)) {
std::string name = dir_entry.path().filename().string(); std::string name = dir_entry.path().filename().string();
// Remove the .ini suffix. // Remove the .ini suffix.
@ -609,28 +610,28 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
DynamicPrintConfig config; DynamicPrintConfig config;
config.load_from_ini(preset.file); config.load_from_ini(preset.file);
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field. // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
const Preset &default_preset = this->default_preset_for(config); const Preset &default_preset = this->default_preset_for(config);
preset.config = default_preset.config; preset.config = default_preset.config;
preset.config.apply(std::move(config)); preset.config.apply(std::move(config));
Preset::normalize(preset.config); Preset::normalize(preset.config);
// Report configuration fields, which are misplaced into a wrong group. // Report configuration fields, which are misplaced into a wrong group.
std::string incorrect_keys = Preset::remove_invalid_keys(config, default_preset.config); std::string incorrect_keys = Preset::remove_invalid_keys(config, default_preset.config);
if (! incorrect_keys.empty()) if (! incorrect_keys.empty())
BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" << BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed"; preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
preset.loaded = true; preset.loaded = true;
} catch (const std::ifstream::failure &err) { } catch (const std::ifstream::failure &err) {
throw std::runtime_error(std::string("The selected preset cannot be loaded: ") + preset.file + "\n\tReason: " + err.what()); throw std::runtime_error(std::string("The selected preset cannot be loaded: ") + preset.file + "\n\tReason: " + err.what());
} catch (const std::runtime_error &err) { } catch (const std::runtime_error &err) {
throw std::runtime_error(std::string("Failed loading the preset file: ") + preset.file + "\n\tReason: " + err.what()); throw std::runtime_error(std::string("Failed loading the preset file: ") + preset.file + "\n\tReason: " + err.what());
} }
presets_loaded.emplace_back(preset); presets_loaded.emplace_back(preset);
} catch (const std::runtime_error &err) { } catch (const std::runtime_error &err) {
errors_cummulative += err.what(); errors_cummulative += err.what();
errors_cummulative += "\n"; errors_cummulative += "\n";
} }
} }
m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end())); m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
std::sort(m_presets.begin() + m_num_default_presets, m_presets.end()); std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
this->select_preset(first_visible_idx()); this->select_preset(first_visible_idx());
if (! errors_cummulative.empty()) if (! errors_cummulative.empty())
@ -681,7 +682,7 @@ Preset& PresetCollection::load_external_preset(
cfg.apply_only(config, cfg.keys(), true); cfg.apply_only(config, cfg.keys(), true);
// Is there a preset already loaded with the name stored inside the config? // Is there a preset already loaded with the name stored inside the config?
std::deque<Preset>::iterator it = this->find_preset_internal(original_name); std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
bool found = it != m_presets.end() && it->name == original_name; bool found = it != m_presets.end() && it->name == original_name;
if (found && profile_print_params_same(it->config, cfg)) { if (found && profile_print_params_same(it->config, cfg)) {
// The preset exists and it matches the values stored inside config. // The preset exists and it matches the values stored inside config.
if (select) if (select)
@ -751,8 +752,8 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
void PresetCollection::save_current_preset(const std::string &new_name) void PresetCollection::save_current_preset(const std::string &new_name)
{ {
// 1) Find the preset with a new_name or create a new one, // 1) Find the preset with a new_name or create a new one,
// initialize it with the edited config. // initialize it with the edited config.
auto it = this->find_preset_internal(new_name); auto it = this->find_preset_internal(new_name);
if (it != m_presets.end() && it->name == new_name) { if (it != m_presets.end() && it->name == new_name) {
// Preset with the same name found. // Preset with the same name found.
@ -762,15 +763,15 @@ void PresetCollection::save_current_preset(const std::string &new_name)
return; return;
// Overwriting an existing preset. // Overwriting an existing preset.
preset.config = std::move(m_edited_preset.config); preset.config = std::move(m_edited_preset.config);
// The newly saved preset will be activated -> make it visible. // The newly saved preset will be activated -> make it visible.
preset.is_visible = true; preset.is_visible = true;
} else { } else {
// Creating a new preset. // Creating a new preset.
Preset &preset = *m_presets.insert(it, m_edited_preset); Preset &preset = *m_presets.insert(it, m_edited_preset);
std::string &inherits = preset.inherits(); std::string &inherits = preset.inherits();
std::string old_name = preset.name; std::string old_name = preset.name;
preset.name = new_name; preset.name = new_name;
preset.file = this->path_from_name(new_name); preset.file = this->path_from_name(new_name);
preset.vendor = nullptr; preset.vendor = nullptr;
if (preset.is_system) { if (preset.is_system) {
// Inheriting from a system preset. // Inheriting from a system preset.
@ -785,24 +786,24 @@ void PresetCollection::save_current_preset(const std::string &new_name)
preset.is_default = false; preset.is_default = false;
preset.is_system = false; preset.is_system = false;
preset.is_external = false; preset.is_external = false;
// The newly saved preset will be activated -> make it visible. // The newly saved preset will be activated -> make it visible.
preset.is_visible = true; preset.is_visible = true;
} }
// 2) Activate the saved preset. // 2) Activate the saved preset.
this->select_preset_by_name(new_name, true); this->select_preset_by_name(new_name, true);
// 2) Store the active preset to disk. // 2) Store the active preset to disk.
this->get_selected_preset().save(); this->get_selected_preset().save();
} }
bool PresetCollection::delete_current_preset() bool PresetCollection::delete_current_preset()
{ {
const Preset &selected = this->get_selected_preset(); const Preset &selected = this->get_selected_preset();
if (selected.is_default) if (selected.is_default)
return false; return false;
if (! selected.is_external && ! selected.is_system) { if (! selected.is_external && ! selected.is_system) {
// Erase the preset file. // Erase the preset file.
boost::nowide::remove(selected.file.c_str()); boost::nowide::remove(selected.file.c_str());
} }
// Remove the preset from the list. // Remove the preset from the list.
m_presets.erase(m_presets.begin() + m_idx_selected); m_presets.erase(m_presets.begin() + m_idx_selected);
// Find the next visible preset. // Find the next visible preset.
@ -810,9 +811,9 @@ bool PresetCollection::delete_current_preset()
if (new_selected_idx < m_presets.size()) if (new_selected_idx < m_presets.size())
for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ; for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ;
if (new_selected_idx == m_presets.size()) if (new_selected_idx == m_presets.size())
for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx); for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx);
this->select_preset(new_selected_idx); this->select_preset(new_selected_idx);
return true; return true;
} }
void PresetCollection::load_bitmap_default(wxWindow *window, const std::string &file_name) void PresetCollection::load_bitmap_default(wxWindow *window, const std::string &file_name)
@ -841,7 +842,7 @@ const Preset* PresetCollection::get_selected_preset_parent() const
std::string inherits = this->get_edited_preset().inherits(); std::string inherits = this->get_edited_preset().inherits();
if (inherits.empty()) if (inherits.empty())
{ {
if (this->get_selected_preset().is_system || this->get_selected_preset().is_default) if (this->get_selected_preset().is_system || this->get_selected_preset().is_default)
return &this->get_selected_preset(); return &this->get_selected_preset();
if (this->get_selected_preset().is_external) if (this->get_selected_preset().is_external)
return nullptr; return nullptr;
@ -860,13 +861,13 @@ const Preset* PresetCollection::get_preset_parent(const Preset& child) const
const std::string &inherits = child.inherits(); const std::string &inherits = child.inherits();
if (inherits.empty()) if (inherits.empty())
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr; // return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
return nullptr; return nullptr;
const Preset* preset = this->find_preset(inherits, false); const Preset* preset = this->find_preset(inherits, false);
return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset; return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset;
} }
const std::string& PresetCollection::get_suffix_modified() { const std::string& PresetCollection::get_suffix_modified() {
return g_suffix_modified; return g_suffix_modified;
} }
// Return a preset by its name. If the preset is active, a temporary copy is returned. // Return a preset by its name. If the preset is active, a temporary copy is returned.
@ -896,9 +897,9 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
{ {
if (m_default_suppressed != default_suppressed) { if (m_default_suppressed != default_suppressed) {
m_default_suppressed = default_suppressed; m_default_suppressed = default_suppressed;
bool default_visible = ! default_suppressed || m_idx_selected < m_num_default_presets; bool default_visible = ! default_suppressed || m_idx_selected < m_num_default_presets;
for (size_t i = 0; i < m_num_default_presets; ++ i) for (size_t i = 0; i < m_num_default_presets; ++ i)
m_presets[i].is_visible = default_visible; m_presets[i].is_visible = default_visible;
} }
} }
@ -940,12 +941,12 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
// Otherwise fill in the list from scratch. // Otherwise fill in the list from scratch.
ui->Freeze(); ui->Freeze();
ui->Clear(); ui->Clear();
size_t selected_preset_item = 0; size_t selected_preset_item = 0;
const Preset &selected_preset = this->get_selected_preset(); const Preset &selected_preset = this->get_selected_preset();
// Show wide icons if the currently selected preset is not compatible with the current printer, // Show wide icons if the currently selected preset is not compatible with the current printer,
// and draw a red flag in front of the selected preset. // and draw a red flag in front of the selected preset.
bool wide_icons = ! selected_preset.is_compatible && m_bitmap_incompatible != nullptr; bool wide_icons = ! selected_preset.is_compatible && m_bitmap_incompatible != nullptr;
/* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display.
* So set sizes for solid_colored icons used for filament preset * So set sizes for solid_colored icons used for filament preset
@ -957,87 +958,87 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
const int thin_space_icon_width = 4 * scale_f + 0.5f; const int thin_space_icon_width = 4 * scale_f + 0.5f;
const int wide_space_icon_width = 6 * scale_f + 0.5f; const int wide_space_icon_width = 6 * scale_f + 0.5f;
std::map<wxString, wxBitmap*> nonsys_presets; std::map<wxString, wxBitmap*> nonsys_presets;
wxString selected = ""; wxString selected = "";
if (!this->m_presets.front().is_visible) if (!this->m_presets.front().is_visible)
ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap));
for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++ i) { for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++ i) {
const Preset &preset = this->m_presets[i]; const Preset &preset = this->m_presets[i];
if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected)) if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected))
continue; continue;
std::string bitmap_key = ""; std::string bitmap_key = "";
// If the filament preset is not compatible and there is a "red flag" icon loaded, show it left // If the filament preset is not compatible and there is a "red flag" icon loaded, show it left
// to the filament color image. // to the filament color image.
if (wide_icons) if (wide_icons)
bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt";
bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst";
wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); wxBitmap *bmp = m_bitmap_cache->find(bitmap_key);
if (bmp == nullptr) { if (bmp == nullptr) {
// Create the bitmap with color bars. // Create the bitmap with color bars.
std::vector<wxBitmap> bmps; std::vector<wxBitmap> bmps;
if (wide_icons) if (wide_icons)
// Paint a red flag for incompatible presets. // Paint a red flag for incompatible presets.
bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(icon_width, icon_height) : *m_bitmap_incompatible); bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(icon_width, icon_height) : *m_bitmap_incompatible);
// Paint the color bars. // Paint the color bars.
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
bmps.emplace_back(*m_bitmap_main_frame); bmps.emplace_back(*m_bitmap_main_frame);
// Paint a lock at the system presets. // Paint a lock at the system presets.
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height));
bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height)); bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height));
bmp = m_bitmap_cache->insert(bitmap_key, bmps); bmp = m_bitmap_cache->insert(bitmap_key, bmps);
} }
if (preset.is_default || preset.is_system) { if (preset.is_default || preset.is_system) {
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
if (i == m_idx_selected) if (i == m_idx_selected)
selected_preset_item = ui->GetCount() - 1; selected_preset_item = ui->GetCount() - 1;
} }
else else
{ {
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/); nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/);
if (i == m_idx_selected) if (i == m_idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str());
} }
if (i + 1 == m_num_default_presets) if (i + 1 == m_num_default_presets)
ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap));
} }
if (!nonsys_presets.empty()) if (!nonsys_presets.empty())
{ {
ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap)); ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap));
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
ui->Append(it->first, *it->second); ui->Append(it->first, *it->second);
if (it->first == selected) if (it->first == selected)
selected_preset_item = ui->GetCount() - 1; selected_preset_item = ui->GetCount() - 1;
} }
} }
if (m_type == Preset::TYPE_PRINTER) { if (m_type == Preset::TYPE_PRINTER) {
std::string bitmap_key = ""; std::string bitmap_key = "";
// If the filament preset is not compatible and there is a "red flag" icon loaded, show it left // If the filament preset is not compatible and there is a "red flag" icon loaded, show it left
// to the filament color image. // to the filament color image.
if (wide_icons) if (wide_icons)
bitmap_key += "wide,"; bitmap_key += "wide,";
bitmap_key += "add_printer"; bitmap_key += "add_printer";
wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); wxBitmap *bmp = m_bitmap_cache->find(bitmap_key);
if (bmp == nullptr) { if (bmp == nullptr) {
// Create the bitmap with color bars. // Create the bitmap with color bars.
std::vector<wxBitmap> bmps; std::vector<wxBitmap> bmps;
if (wide_icons) if (wide_icons)
// Paint a red flag for incompatible presets. // Paint a red flag for incompatible presets.
bmps.emplace_back(m_bitmap_cache->mkclear(icon_width, icon_height)); bmps.emplace_back(m_bitmap_cache->mkclear(icon_width, icon_height));
// Paint the color bars. // Paint the color bars.
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
bmps.emplace_back(*m_bitmap_main_frame); bmps.emplace_back(*m_bitmap_main_frame);
// Paint a lock at the system presets. // Paint a lock at the system presets.
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height));
bmps.emplace_back(m_bitmap_add ? *m_bitmap_add : wxNullBitmap); bmps.emplace_back(m_bitmap_add ? *m_bitmap_add : wxNullBitmap);
bmp = m_bitmap_cache->insert(bitmap_key, bmps); bmp = m_bitmap_cache->insert(bitmap_key, bmps);
} }
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add a new printer")), *bmp), GUI::PresetComboBox::LABEL_ITEM_CONFIG_WIZARD); ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add a new printer")), *bmp), GUI::PresetComboBox::LABEL_ITEM_CONFIG_WIZARD);
} }
ui->SetSelection(selected_preset_item); ui->SetSelection(selected_preset_item);
ui->SetToolTip(ui->GetString(selected_preset_item)); ui->SetToolTip(ui->GetString(selected_preset_item));
ui->check_selection(); ui->check_selection();
ui->Thaw(); ui->Thaw();
@ -1052,7 +1053,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
return 0; return 0;
ui->Freeze(); ui->Freeze();
ui->Clear(); ui->Clear();
size_t selected_preset_item = 0; size_t selected_preset_item = 0;
/* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display.
* So set sizes for solid_colored(empty) icons used for preset * So set sizes for solid_colored(empty) icons used for preset
@ -1062,52 +1063,52 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
const int icon_height = 16 * scale_f + 0.5f; const int icon_height = 16 * scale_f + 0.5f;
const int icon_width = 16 * scale_f + 0.5f; const int icon_width = 16 * scale_f + 0.5f;
std::map<wxString, wxBitmap*> nonsys_presets; std::map<wxString, wxBitmap*> nonsys_presets;
wxString selected = ""; wxString selected = "";
if (!this->m_presets.front().is_visible) if (!this->m_presets.front().is_visible)
ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap); ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap);
for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) { for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
const Preset &preset = this->m_presets[i]; const Preset &preset = this->m_presets[i];
if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected)) if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected))
continue; continue;
std::string bitmap_key = "tab"; std::string bitmap_key = "tab";
bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt";
bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst";
wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); wxBitmap *bmp = m_bitmap_cache->find(bitmap_key);
if (bmp == nullptr) { if (bmp == nullptr) {
// Create the bitmap with color bars. // Create the bitmap with color bars.
std::vector<wxBitmap> bmps; std::vector<wxBitmap> bmps;
const wxBitmap* tmp_bmp = preset.is_compatible ? m_bitmap_compatible : m_bitmap_incompatible; const wxBitmap* tmp_bmp = preset.is_compatible ? m_bitmap_compatible : m_bitmap_incompatible;
bmps.emplace_back((tmp_bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *tmp_bmp); bmps.emplace_back((tmp_bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *tmp_bmp);
// Paint a lock at the system presets. // Paint a lock at the system presets.
bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height)); bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height));
bmp = m_bitmap_cache->insert(bitmap_key, bmps); bmp = m_bitmap_cache->insert(bitmap_key, bmps);
} }
if (preset.is_default || preset.is_system) { if (preset.is_default || preset.is_system) {
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
if (i == m_idx_selected) if (i == m_idx_selected)
selected_preset_item = ui->GetCount() - 1; selected_preset_item = ui->GetCount() - 1;
} }
else else
{ {
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/); nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/);
if (i == m_idx_selected) if (i == m_idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str());
} }
if (i + 1 == m_num_default_presets) if (i + 1 == m_num_default_presets)
ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap); ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap);
}
if (!nonsys_presets.empty())
{
ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap);
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
ui->Append(it->first, *it->second);
if (it->first == selected)
selected_preset_item = ui->GetCount() - 1;
}
} }
if (!nonsys_presets.empty())
{
ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap);
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
ui->Append(it->first, *it->second);
if (it->first == selected)
selected_preset_item = ui->GetCount() - 1;
}
}
if (m_type == Preset::TYPE_PRINTER) { if (m_type == Preset::TYPE_PRINTER) {
wxBitmap *bmp = m_bitmap_cache->find("add_printer_tab"); wxBitmap *bmp = m_bitmap_cache->find("add_printer_tab");
if (bmp == nullptr) { if (bmp == nullptr) {
@ -1119,10 +1120,10 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
} }
ui->Append(PresetCollection::separator("Add a new printer"), *bmp); ui->Append(PresetCollection::separator("Add a new printer"), *bmp);
} }
ui->SetSelection(selected_preset_item); ui->SetSelection(selected_preset_item);
ui->SetToolTip(ui->GetString(selected_preset_item)); ui->SetToolTip(ui->GetString(selected_preset_item));
ui->Thaw(); ui->Thaw();
return selected_preset_item; return selected_preset_item;
} }
// Update a dirty floag of the current preset, update the labels of the UI component accordingly. // Update a dirty floag of the current preset, update the labels of the UI component accordingly.
@ -1142,11 +1143,11 @@ bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui)
const Preset *preset = this->find_preset(preset_name, false); const Preset *preset = this->find_preset(preset_name, false);
// The old_label could be the "----- system presets ------" or the "------- user presets --------" separator. // The old_label could be the "----- system presets ------" or the "------- user presets --------" separator.
// assert(preset != nullptr); // assert(preset != nullptr);
if (preset != nullptr) { if (preset != nullptr) {
std::string new_label = preset->is_dirty ? preset->name + g_suffix_modified : preset->name; std::string new_label = preset->is_dirty ? preset->name + g_suffix_modified : preset->name;
if (old_label != new_label) if (old_label != new_label)
ui->SetString(ui_id, wxString::FromUTF8(new_label.c_str())); ui->SetString(ui_id, wxString::FromUTF8(new_label.c_str()));
} }
} }
#ifdef __APPLE__ #ifdef __APPLE__
// wxWidgets on OSX do not upload the text of the combo box line automatically. // wxWidgets on OSX do not upload the text of the combo box line automatically.
@ -1159,15 +1160,15 @@ bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui)
template<class T> template<class T>
void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys& vec, const ConfigBase &other, const ConfigBase &this_c) void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys& vec, const ConfigBase &other, const ConfigBase &this_c)
{ {
const T* opt_init = static_cast<const T*>(other.option(opt_key)); const T* opt_init = static_cast<const T*>(other.option(opt_key));
const T* opt_cur = static_cast<const T*>(this_c.option(opt_key)); const T* opt_cur = static_cast<const T*>(this_c.option(opt_key));
int opt_init_max_id = opt_init->values.size() - 1; int opt_init_max_id = opt_init->values.size() - 1;
for (int i = 0; i < opt_cur->values.size(); i++) for (int i = 0; i < opt_cur->values.size(); i++)
{ {
int init_id = i <= opt_init_max_id ? i : 0; int init_id = i <= opt_init_max_id ? i : 0;
if (opt_cur->values[i] != opt_init->values[init_id]) if (opt_cur->values[i] != opt_init->values[init_id])
vec.emplace_back(opt_key + "#" + std::to_string(i)); vec.emplace_back(opt_key + "#" + std::to_string(i));
} }
} }
// Use deep_diff to correct return of changed options, considering individual options for each extruder. // Use deep_diff to correct return of changed options, considering individual options for each extruder.
@ -1201,10 +1202,10 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
std::vector<std::string> PresetCollection::dirty_options(const Preset *edited, const Preset *reference, const bool deep_compare /*= false*/) std::vector<std::string> PresetCollection::dirty_options(const Preset *edited, const Preset *reference, const bool deep_compare /*= false*/)
{ {
std::vector<std::string> changed; std::vector<std::string> changed;
if (edited != nullptr && reference != nullptr) { if (edited != nullptr && reference != nullptr) {
changed = deep_compare ? changed = deep_compare ?
deep_diff(edited->config, reference->config) : deep_diff(edited->config, reference->config) :
reference->config.diff(edited->config); reference->config.diff(edited->config);
// The "compatible_printers" option key is handled differently from the others: // The "compatible_printers" option key is handled differently from the others:
// It is not mandatory. If the key is missing, it means it is compatible with any printer. // It is not mandatory. If the key is missing, it means it is compatible with any printer.
// If the key exists and it is empty, it means it is compatible with no printer. // If the key exists and it is empty, it means it is compatible with no printer.
@ -1227,9 +1228,9 @@ Preset& PresetCollection::select_preset(size_t idx)
idx = first_visible_idx(); idx = first_visible_idx();
m_idx_selected = idx; m_idx_selected = idx;
m_edited_preset = m_presets[idx]; m_edited_preset = m_presets[idx];
bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets; bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets;
for (size_t i = 0; i < m_num_default_presets; ++i) for (size_t i = 0; i < m_num_default_presets; ++i)
m_presets[i].is_visible = default_visible; m_presets[i].is_visible = default_visible;
return m_presets[idx]; return m_presets[idx];
} }
@ -1239,7 +1240,7 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
// 1) Try to find the preset by its name. // 1) Try to find the preset by its name.
auto it = this->find_preset_internal(name); auto it = this->find_preset_internal(name);
size_t idx = 0; size_t idx = 0;
if (it != m_presets.end() && it->name == name && it->is_visible) if (it != m_presets.end() && it->name == name && it->is_visible)
// Preset found by its name and it is visible. // Preset found by its name and it is visible.
idx = it - m_presets.begin(); idx = it - m_presets.begin();
else { else {
@ -1266,7 +1267,7 @@ bool PresetCollection::select_preset_by_name_strict(const std::string &name)
// 1) Try to find the preset by its name. // 1) Try to find the preset by its name.
auto it = this->find_preset_internal(name); auto it = this->find_preset_internal(name);
size_t idx = (size_t)-1; size_t idx = (size_t)-1;
if (it != m_presets.end() && it->name == name && it->is_visible) if (it != m_presets.end() && it->name == name && it->is_visible)
// Preset found by its name. // Preset found by its name.
idx = it - m_presets.begin(); idx = it - m_presets.begin();
// 2) Select the new preset. // 2) Select the new preset.
@ -1333,9 +1334,9 @@ std::vector<std::string> PresetCollection::system_preset_names() const
++ num; ++ num;
std::vector<std::string> out; std::vector<std::string> out;
out.reserve(num); out.reserve(num);
for (const Preset &preset : m_presets) for (const Preset &preset : m_presets)
if (preset.is_system) if (preset.is_system)
out.emplace_back(preset.name); out.emplace_back(preset.name);
std::sort(out.begin(), out.end()); std::sort(out.begin(), out.end());
return out; return out;
} }
@ -1343,7 +1344,7 @@ std::vector<std::string> PresetCollection::system_preset_names() const
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing. // Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
std::string PresetCollection::path_from_name(const std::string &new_name) const std::string PresetCollection::path_from_name(const std::string &new_name) const
{ {
std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini"); std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
} }
@ -1354,13 +1355,13 @@ void PresetCollection::clear_bitmap_cache()
wxString PresetCollection::separator(const std::string &label) wxString PresetCollection::separator(const std::string &label)
{ {
return wxString::FromUTF8(PresetCollection::separator_head()) + _(label) + wxString::FromUTF8(PresetCollection::separator_tail()); return wxString::FromUTF8(PresetCollection::separator_head()) + _(label) + wxString::FromUTF8(PresetCollection::separator_tail());
} }
const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConfig &config) const const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConfig &config) const
{ {
const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology"); const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology");
return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1); return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
} }
const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model_id) const const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model_id) const

File diff suppressed because it is too large Load Diff