Skip to content

Commit

Permalink
Fix config rework (modifiers)
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Dec 27, 2023
2 parents 6e6e99b + fff51ad commit 5e44696
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 176 deletions.
4 changes: 2 additions & 2 deletions src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ int CLI::run(int argc, char **argv)

// The default bed shape should reflect the default display parameters
// and not the fff defaults.
double w = sla_print_config.display_width.get_float();
double h = sla_print_config.display_height.get_float();
double w = sla_print_config.display_width.get_float();
double h = sla_print_config.display_height.get_float();
sla_print_config.bed_shape.values = { Vec2d(0, 0), Vec2d(w, 0), Vec2d(w, h), Vec2d(0, h) };

sla_print_config.apply(m_print_config, true);
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ double ConfigBase::get_computed_value(const t_config_option_key &opt_key, int ex
if (extruder_id < 0) {
const ConfigOption* opt_extruder_id = nullptr;
if ((opt_extruder_id = this->option("extruder")) == nullptr)
if ((opt_extruder_id = this->option("current_extruder")) == nullptr ||
opt_extruder_id->get_int() < 0 || opt_extruder_id->get_int() >= vector_opt->size()) {
if ((opt_extruder_id = this->option("current_extruder")) == nullptr
|| opt_extruder_id->get_int() < 0 || opt_extruder_id->get_int() >= vector_opt->size()) {
std::stringstream ss; ss << "ConfigBase::get_abs_value(): " << opt_key << " need to has the extuder id to get the right value, but it's not available";
throw ConfigurationError(ss.str());
}
Expand Down
173 changes: 76 additions & 97 deletions src/libslic3r/Config.hpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/libslic3r/PlaceholderParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ namespace client
case coFloat: output.set_d(opt.opt->get_float()); break;
case coInt: output.set_i(opt.opt->get_int()); break;
case coString: output.set_s(static_cast<const ConfigOptionString*>(opt.opt)->value); break;
case coPercent: output.set_d(opt.opt->get_float()); break;
case coPercent: output.set_d(opt.opt->get_float()); break;
case coPoint: output.set_s(opt.opt->serialize()); break;
case coBool: output.set_b(opt.opt->get_bool()); break;
case coFloatOrPercent:
Expand Down Expand Up @@ -969,7 +969,7 @@ namespace client
v *= val;
break;
// if (opt_parent->type() == coFloat || opt_parent->type() == coFloatOrPercent) {
// v *= opt_parent->getFloat();
// v *= opt_parent->get_float();
// if (opt_parent->type() == coFloat || ! static_cast<const ConfigOptionFloatOrPercent*>(opt_parent)->percent)
// break;
// v *= 0.01; // percent to ratio
Expand All @@ -985,15 +985,15 @@ namespace client
case coInts:
opt_def = print_config_def.get(opt_key);
if (opt_def->is_vector_extruder) {
output.set_i(int(((ConfigOptionVectorBase *) opt.opt)->get_float(int(ctx->current_extruder_id))));
output.set_i(int(((ConfigOptionVectorBase*)opt.opt)->get_float(int(ctx->current_extruder_id))));
break;
} else
ctx->throw_exception("Unknown scalar variable type", opt.it_range);
case coFloats:
case coPercents:
vector_opt = static_cast<const ConfigOptionVectorBase*>(opt.opt);
if (vector_opt->is_extruder_size()) {
output.set_d(((ConfigOptionVectorBase *) opt.opt)->get_float(int(ctx->current_extruder_id)));
output.set_d(((ConfigOptionVectorBase*)opt.opt)->get_float(int(ctx->current_extruder_id)));
break;
} else
ctx->throw_exception("Unknown scalar variable type", opt.it_range);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static inline void layer_height_ranges_copy_configs(t_layer_config_ranges &lr_ds
assert(std::abs(kvp_dst.first.first - kvp_src.first.first ) <= EPSILON);
assert(std::abs(kvp_dst.first.second - kvp_src.first.second) <= EPSILON);
// Layer heights are allowed do differ in case the layer height table is being overriden by the smooth profile.
// assert(std::abs(kvp_dst.second.option("layer_height")->getFloat() - kvp_src.second.option("layer_height")->getFloat()) <= EPSILON);
// assert(std::abs(kvp_dst.second.option("layer_height")->get_float() - kvp_src.second.option("layer_height")->get_float()) <= EPSILON);
kvp_dst.second = kvp_src.second;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libslic3r/PrintBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ std::string PrintBase::output_filename(const std::string &format, const std::str
cfg.set_key_value("input_filename_base", new ConfigOptionString(filename_base));
}
try {
uint16_t extruder_initial = config_override->option("initial_extruder") != nullptr &&
config_override->option("initial_extruder")->type() == coInt ? config_override->option("initial_extruder")->get_int() : 0;
uint16_t extruder_initial = config_override->option("initial_extruder") != nullptr && config_override->option("initial_extruder")->type() == coInt ? config_override->option("initial_extruder")->get_int() : 0;
boost::filesystem::path filepath = format.empty() ?
cfg.opt_string("input_filename_base") + default_ext :
this->placeholder_parser().process(format, extruder_initial, &cfg);
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6467,14 +6467,14 @@ void PrintConfigDef::init_fff_params()
}
case coPercents: {
ConfigOptionPercentsNullable *opt = new ConfigOptionPercentsNullable(it_opt->second.default_value.get()->get_float());
opt->set_any(ConfigOptionFloatsNullable::create_nil(), 0);
opt->set_any(ConfigOptionPercentsNullable::create_nil(), 0);
def->set_default_value(opt);
break;
}
case coFloatsOrPercents: {
ConfigOptionFloatsOrPercentsNullable*opt = new ConfigOptionFloatsOrPercentsNullable(
static_cast<const ConfigOptionFloatsOrPercents*>(it_opt->second.default_value.get())->get_at(0));
opt->set_at(ConfigOptionFloatsOrPercentsNullable::NIL_VALUE(), 0);
opt->set_any(ConfigOptionFloatsOrPercentsNullable::create_nil(), 0);
def->set_default_value(opt);
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2541,12 +2541,13 @@ static constexpr const std::initializer_list<const std::string_view> keys_extrud
// 2) Copy the rest of the values.
for (auto it = in.cbegin(); it != in.cend(); ++it)
if (it->first != key_extruder)
if (ConfigOptionInt *my_opt = out.option<ConfigOptionInt>(it->first, false); my_opt != nullptr) {
if (ConfigOption* my_opt = out.option(it->first, false); my_opt != nullptr) {
if (one_of(it->first, keys_extruders)) {
assert(dynamic_cast<ConfigOptionInt*>(my_opt));
// Ignore "default" extruders.
int extruder = it->second->get_int();
int extruder = static_cast<const ConfigOptionInt*>(it->second.get())->value;
if (extruder > 0)
my_opt->value = (extruder);
static_cast<ConfigOptionInt *>(my_opt)->value = (extruder);
} else
my_opt->set(it->second.get());
}
Expand Down
12 changes: 5 additions & 7 deletions src/slic3r/GUI/BedShapeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para
t_config_option_key key;
switch (param) {
case Parameter::RectSize:
def.type = coPoint;
def.type = coPoints;
def.set_default_value(new ConfigOptionPoints{ Vec2d(200, 200) });
def.min = 0;
def.max = 100000;
Expand All @@ -51,7 +51,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para
key = "rect_size";
break;
case Parameter::RectOrigin:
def.type = coPoint;
def.type = coPoints;
def.set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });
def.min = -100000;
def.max = 100000;
Expand Down Expand Up @@ -120,14 +120,12 @@ void BedShape::apply_optgroup_values(ConfigOptionsGroupShp optgroup)
{
switch (m_build_volume.type()) {
case BuildVolume::Type::Circle:
optgroup->set_value("diameter", 2. * unscaled<double>(m_build_volume.circle().radius));
optgroup->set_value("diameter", double_to_string(2. * unscaled<double>(m_build_volume.circle().radius)));
break;
default:
// rectangle, convex, concave...
optgroup->set_value("rect_size", Vec2d(m_build_volume.bounding_volume().size().x(),
m_build_volume.bounding_volume().size().y()));
optgroup->set_value("rect_origin", Vec2d(-m_build_volume.bounding_volume().min.x(),
-m_build_volume.bounding_volume().min.y()));
optgroup->set_value("rect_size" , new ConfigOptionPoints{ to_2d(m_build_volume.bounding_volume().size()) });
optgroup->set_value("rect_origin" , new ConfigOptionPoints{ - to_2d(m_build_volume.bounding_volume().min) });
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/slic3r/GUI/CalibrationOverBridgeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ void CalibrationOverBridgeDialog::create_geometry(bool over_bridge) {
DynamicPrintConfig new_print_config = *print_config; //make a copy
new_print_config.set_key_value("complete_objects", new ConfigOptionBool(true));
//if skirt, use only one
if (print_config->option<ConfigOptionInt>("skirts")->get_int() > 0 &&
print_config->option<ConfigOptionInt>("skirt_height")->get_int() > 0) {
if (print_config->option<ConfigOptionInt>("skirts")->get_int() > 0 && print_config->option<ConfigOptionInt>("skirt_height")->get_int() > 0) {
new_print_config.set_key_value("complete_objects_one_skirt", new ConfigOptionBool(true));
}

Expand Down
44 changes: 20 additions & 24 deletions src/slic3r/GUI/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ std::pair<bool, bool> get_strings_points(const wxString &str, double min, double
return {invalid_val, out_of_range_val};
}


Field::~Field()
{
if (m_on_kill_focus)
Expand Down Expand Up @@ -430,8 +429,7 @@ std::pair<wxString, bool> any_to_wxstring(const boost::any &value, const ConfigO
deserialize(ConfigOptionFloatsOrPercents{});
break;
}
if (opt.nullable &&
boost::any_cast<FloatOrPercent>(value) == ConfigOptionFloatsOrPercentsNullable::NIL_VALUE()) {
if (opt.nullable && ConfigOptionFloatsOrPercentsNullable::is_nil(value)) {
text_value = na_value();
has_nil = true;
break;
Expand Down Expand Up @@ -732,15 +730,15 @@ void TextField::get_value_by_opt_type(wxString &str, const bool check_value /* =
str.Replace("m", "", true);

if (m_opt.nullable && str == NIL_STR_VALUE) {
m_value = ConfigOptionFloatsOrPercentsNullable::NIL_VALUE();
m_value = ConfigOptionFloatsOrPercentsNullable::create_nil();
break;
} else if (!str.ToDouble(&val)) {
if (!check_value) {
m_value.clear();
break;
}
show_error(m_parent, _(L("Invalid numeric input.")));
set_value(FloatOrPercent{val, is_percent}, true);
set_any_value(FloatOrPercent{val, is_percent}, true);
} else {
//convert m_value into str to compare
FloatOrPercent val_from_m_value = m_value.empty() ? FloatOrPercent{0, false} :
Expand All @@ -758,7 +756,7 @@ void TextField::get_value_by_opt_type(wxString &str, const bool check_value /* =
show_error(m_parent, _(L("Input value is out of range")));
if (m_opt.min > val)
val = m_opt.min;
set_value(FloatOrPercent{val, is_percent}, true);
set_any_value(FloatOrPercent{val, is_percent}, true);
} else if (m_value.empty() || str != str_from_m_value) {
// empty of not equal -> need check
bool not_ok = (m_opt.sidetext.rfind("mm/s") != std::string::npos && val > m_opt.max);
Expand Down Expand Up @@ -806,10 +804,10 @@ void TextField::get_value_by_opt_type(wxString &str, const bool check_value /* =
str += "%";
is_percent = true;
m_last_validated_value = str;
set_value(FloatOrPercent{val, is_percent}, false /*true*/);
set_any_value(FloatOrPercent{val, is_percent}, false /*true*/);
str = m_last_validated_value;
} else
set_value(FloatOrPercent{val, is_percent}, false); // it's no needed but can be helpful, when inputted value
set_any_value(FloatOrPercent{val, is_percent}, false); // it's no needed but can be helpful, when inputted value
// contained "," instead of "."
m_last_validated_value = str;
}
Expand Down Expand Up @@ -919,7 +917,7 @@ void TextCtrl::BUILD() {
assert(m_opt.default_value->is_vector());
m_last_meaningful_value = any_to_wxstring(static_cast<const ConfigOptionVectorBase*>(m_opt.default_value.get())->get_default_value(), m_opt, m_opt_idx).first;
} else {
m_last_meaningful_value = text_value;
m_last_meaningful_value = text_value;
}
assert(m_last_meaningful_value != na_value());

Expand Down Expand Up @@ -1034,7 +1032,7 @@ bool TextCtrl::value_was_changed()
double old_val = boost::any_cast<double>(val);
if ((std::isnan(new_val) || ConfigOptionFloats::is_nil(m_value)) &&
(std::isnan(old_val) || ConfigOptionFloats::is_nil(val)))
return false;
return false;
}
case coPercent:
case coFloat: {
Expand All @@ -1053,10 +1051,7 @@ bool TextCtrl::value_was_changed()
boost::any_cast<std::vector<FloatOrPercent>>(val);
}
if (m_opt.nullable) {
FloatOrPercent new_val = boost::any_cast<FloatOrPercent>(m_value);
FloatOrPercent old_val = boost::any_cast<FloatOrPercent>(val);
if ((std::isnan(new_val.value) || new_val == ConfigOptionFloatsOrPercents::NIL_VALUE()) &&
(std::isnan(old_val.value) || old_val == ConfigOptionFloatsOrPercents::NIL_VALUE()))
if (ConfigOptionFloatsOrPercents::is_nil(m_value) &&ConfigOptionFloatsOrPercents::is_nil(val))
return false;
}
case coFloatOrPercent:
Expand Down Expand Up @@ -1102,7 +1097,7 @@ void TextCtrl::propagate_value()
m_last_meaningful_value = dynamic_cast<wxTextCtrl *>(window)->GetValue();
}

void TextCtrl::set_value(const boost::any& value, bool change_event/* = false*/) {
void TextCtrl::set_any_value(const boost::any& value, bool change_event/* = false*/) {
//can be:
//case coFloat:
//case coFloats:
Expand Down Expand Up @@ -1232,7 +1227,7 @@ void CheckBox::BUILD() {

//set value (need the window for the set_value)
if (m_opt.is_script && !m_opt.default_script_value.empty())
set_value(m_opt.default_script_value, false);
set_any_value(m_opt.default_script_value, false);
else
set_widget_value(check_value);

Expand Down Expand Up @@ -1261,7 +1256,7 @@ void CheckBox::set_widget_value(bool new_val)
#endif
}

void CheckBox::set_value(const boost::any &value, bool change_event)
void CheckBox::set_any_value(const boost::any &value, bool change_event)
{
//can be coBool and coBools (with idx)
m_disable_change_event = !change_event;
Expand Down Expand Up @@ -1322,7 +1317,7 @@ boost::any& CheckBox::get_value()
if (m_opt.type == coBool)
m_value = static_cast<bool>(value);
else
m_value = m_is_na_val ? ConfigOptionBoolsNullable::NIL_VALUE() : static_cast<unsigned char>(value);
m_value = m_is_na_val ? ConfigOptionBoolsNullable::NIL_VALUE() : static_cast<unsigned char>(value);
return m_value;
}

Expand Down Expand Up @@ -1738,7 +1733,7 @@ int32_t Choice::idx_from_enum_value(int32_t val) {
return 0;
}

void Choice::set_value(const boost::any &value, bool change_event)
void Choice::set_any_value(const boost::any &value, bool change_event)
{
// can be
// GUIType::select_open
Expand All @@ -1758,7 +1753,7 @@ void Choice::set_value(const boost::any &value, bool change_event)
case coPercent:
case coFloatOrPercent:
case coString:
case coStrings: {
case coStrings: {
auto [/*wxString*/ text_value, /*bool*/ has_nil] = any_to_wxstring(value, m_opt, m_opt_idx);

size_t idx = 0;
Expand Down Expand Up @@ -2009,7 +2004,7 @@ void ColourPicker::set_undef_value(wxColourPickerCtrl* field)
btn->SetBitmapLabel(bmp);
}

void ColourPicker::set_value(const boost::any &value, bool change_event)
void ColourPicker::set_any_value(const boost::any &value, bool change_event)
{
// can be ConfigOptionDef::GUIType::color
m_disable_change_event = !change_event;
Expand Down Expand Up @@ -2184,7 +2179,7 @@ void PointCtrl::set_vec2d_value(const Vec2d& value, bool change_event)
m_disable_change_event = false;
}

void PointCtrl::set_value(const boost::any &value, bool change_event)
void PointCtrl::set_any_value(const boost::any &value, bool change_event)
{
// can be coPoint and coPoints (with idx)
assert(m_opt.type == coPoint || (m_opt.type == coPoints && m_opt_idx >= 0));
Expand All @@ -2198,7 +2193,7 @@ boost::any& PointCtrl::get_value()
if (!x_textctrl->GetValue().ToDouble(&x) ||
!y_textctrl->GetValue().ToDouble(&y))
{
set_value(m_value.empty() ? Vec2d(0.0, 0.0) : m_value, true);
set_any_value(m_value.empty() ? Vec2d(0.0, 0.0) : m_value, true);
show_error(m_parent, _L("Invalid numeric input."));
}
else
Expand Down Expand Up @@ -2301,7 +2296,7 @@ void SliderCtrl::BUILD()
m_sizer = dynamic_cast<wxSizer*>(temp);
}

void SliderCtrl::set_value(const boost::any &value, bool change_event)
void SliderCtrl::set_any_value(const boost::any &value, bool change_event)
{
// only with ConfigOptionDef::GUIType::slider: & coFloat or coInt
assert(m_opt.gui_type == ConfigOptionDef::GUIType::slider && (m_opt.type == coFloat || m_opt.type == coInt));
Expand Down Expand Up @@ -2332,5 +2327,6 @@ boost::any &SliderCtrl::get_value()
return m_value;
}


} // GUI
} // Slic3r
Loading

0 comments on commit 5e44696

Please sign in to comment.