mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 23:25:59 +08:00
OptionsGroup : Refactoring
* Don't use "m_"prefix for public members * Move change_opt_value() function from GUI to OptionsGroup
This commit is contained in:
parent
bbbeedf1ce
commit
9926181008
@ -266,7 +266,7 @@ ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& tit
|
||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Settings"));
|
||||
|
||||
optgroup->label_width = 10;
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
update_shape();
|
||||
};
|
||||
|
||||
@ -290,7 +290,7 @@ wxPanel* BedShapePanel::init_texture_panel()
|
||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Texture"));
|
||||
|
||||
optgroup->label_width = 10;
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
update_shape();
|
||||
};
|
||||
|
||||
@ -363,7 +363,7 @@ wxPanel* BedShapePanel::init_model_panel()
|
||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Model"));
|
||||
|
||||
optgroup->label_width = 10;
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
update_shape();
|
||||
};
|
||||
|
||||
|
@ -107,128 +107,6 @@ const std::string& shortkey_alt_prefix()
|
||||
return str;
|
||||
}
|
||||
|
||||
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
|
||||
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
||||
{
|
||||
try{
|
||||
|
||||
if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) {
|
||||
ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) };
|
||||
config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
const ConfigOptionDef *opt_def = config.def()->get(opt_key);
|
||||
switch (opt_def->type) {
|
||||
case coFloatOrPercent:{
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
bool percent = false;
|
||||
if (str.back() == '%') {
|
||||
str.pop_back();
|
||||
percent = true;
|
||||
}
|
||||
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
|
||||
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
|
||||
break;}
|
||||
case coPercent:
|
||||
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
|
||||
break;
|
||||
case coFloat:{
|
||||
double& val = config.opt_float(opt_key);
|
||||
val = boost::any_cast<double>(value);
|
||||
break;
|
||||
}
|
||||
case coFloatsOrPercents:{
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
bool percent = false;
|
||||
if (str.back() == '%') {
|
||||
str.pop_back();
|
||||
percent = true;
|
||||
}
|
||||
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
|
||||
ConfigOptionFloatsOrPercents* vec_new = new ConfigOptionFloatsOrPercents({ {val, percent} });
|
||||
config.option<ConfigOptionFloatsOrPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coPercents:{
|
||||
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) };
|
||||
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coFloats:{
|
||||
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) };
|
||||
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coString:
|
||||
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
||||
break;
|
||||
case coStrings:{
|
||||
if (opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "gcode_substitutions") {
|
||||
config.option<ConfigOptionStrings>(opt_key)->values =
|
||||
boost::any_cast<std::vector<std::string>>(value);
|
||||
}
|
||||
else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) {
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
std::vector<std::string> values {};
|
||||
if (!str.empty()) {
|
||||
if (str.back() == ';') str.pop_back();
|
||||
// Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values.
|
||||
// Currently used for the post_process config value only.
|
||||
boost::split(values, str, boost::is_any_of(";"));
|
||||
if (values.size() == 1 && values[0] == "")
|
||||
values.resize(0);
|
||||
}
|
||||
config.option<ConfigOptionStrings>(opt_key)->values = values;
|
||||
}
|
||||
else{
|
||||
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) };
|
||||
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case coBool:
|
||||
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
||||
break;
|
||||
case coBools:{
|
||||
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 };
|
||||
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
break;}
|
||||
case coInt:
|
||||
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
|
||||
break;
|
||||
case coInts:{
|
||||
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) };
|
||||
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
break;
|
||||
case coEnum:{
|
||||
auto *opt = opt_def->default_value.get()->clone();
|
||||
opt->setInt(boost::any_cast<int>(value));
|
||||
config.set_key_value(opt_key, opt);
|
||||
}
|
||||
break;
|
||||
case coPoints:{
|
||||
if (opt_key == "bed_shape") {
|
||||
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
|
||||
break;
|
||||
}
|
||||
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) };
|
||||
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
break;
|
||||
case coNone:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
wxLogError(format_wxstr("Internal error when changing value for %1%: %2%", opt_key, e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void show_error(wxWindow* parent, const wxString& message, bool monospaced_font)
|
||||
{
|
||||
ErrorDialog msg(parent, message, monospaced_font);
|
||||
|
@ -42,9 +42,6 @@ extern AppConfig* get_app_config();
|
||||
|
||||
extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_language_change);
|
||||
|
||||
// Change option value in config
|
||||
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0);
|
||||
|
||||
// If monospaced_font is true, the error message is displayed using html <code><pre></pre></code> tags,
|
||||
// so that the code formatting will be preserved. This is useful for reporting errors from the placeholder parser.
|
||||
void show_error(wxWindow* parent, const wxString& message, bool monospaced_font = false);
|
||||
|
@ -127,7 +127,7 @@ bool ObjectSettings::update_settings_list()
|
||||
optgroup->label_width = 15;
|
||||
optgroup->sidetext_width = 5;
|
||||
|
||||
optgroup->m_on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) {
|
||||
optgroup->on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) {
|
||||
this->update_config_values(config);
|
||||
wxGetApp().obj_list()->changed_object(); };
|
||||
|
||||
|
@ -138,6 +138,128 @@ OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title,
|
||||
{
|
||||
}
|
||||
|
||||
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
|
||||
void OptionsGroup::change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
||||
{
|
||||
try {
|
||||
|
||||
if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) {
|
||||
ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) };
|
||||
config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
const ConfigOptionDef* opt_def = config.def()->get(opt_key);
|
||||
switch (opt_def->type) {
|
||||
case coFloatOrPercent: {
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
bool percent = false;
|
||||
if (str.back() == '%') {
|
||||
str.pop_back();
|
||||
percent = true;
|
||||
}
|
||||
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
|
||||
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
|
||||
break; }
|
||||
case coPercent:
|
||||
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
|
||||
break;
|
||||
case coFloat: {
|
||||
double& val = config.opt_float(opt_key);
|
||||
val = boost::any_cast<double>(value);
|
||||
break;
|
||||
}
|
||||
case coFloatsOrPercents: {
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
bool percent = false;
|
||||
if (str.back() == '%') {
|
||||
str.pop_back();
|
||||
percent = true;
|
||||
}
|
||||
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
|
||||
ConfigOptionFloatsOrPercents* vec_new = new ConfigOptionFloatsOrPercents({ {val, percent} });
|
||||
config.option<ConfigOptionFloatsOrPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coPercents: {
|
||||
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) };
|
||||
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coFloats: {
|
||||
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) };
|
||||
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
||||
break;
|
||||
}
|
||||
case coString:
|
||||
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
||||
break;
|
||||
case coStrings: {
|
||||
if (opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "gcode_substitutions") {
|
||||
config.option<ConfigOptionStrings>(opt_key)->values =
|
||||
boost::any_cast<std::vector<std::string>>(value);
|
||||
}
|
||||
else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) {
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
std::vector<std::string> values{};
|
||||
if (!str.empty()) {
|
||||
if (str.back() == ';') str.pop_back();
|
||||
// Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values.
|
||||
// Currently used for the post_process config value only.
|
||||
boost::split(values, str, boost::is_any_of(";"));
|
||||
if (values.size() == 1 && values[0] == "")
|
||||
values.resize(0);
|
||||
}
|
||||
config.option<ConfigOptionStrings>(opt_key)->values = values;
|
||||
}
|
||||
else {
|
||||
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) };
|
||||
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case coBool:
|
||||
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
||||
break;
|
||||
case coBools: {
|
||||
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 };
|
||||
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
break; }
|
||||
case coInt:
|
||||
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
|
||||
break;
|
||||
case coInts: {
|
||||
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) };
|
||||
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
break;
|
||||
case coEnum: {
|
||||
auto* opt = opt_def->default_value.get()->clone();
|
||||
opt->setInt(boost::any_cast<int>(value));
|
||||
config.set_key_value(opt_key, opt);
|
||||
}
|
||||
break;
|
||||
case coPoints: {
|
||||
if (opt_key == "bed_shape") {
|
||||
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
|
||||
break;
|
||||
}
|
||||
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) };
|
||||
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
break;
|
||||
case coNone:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
wxLogError(format_wxstr("Internal error when changing value for %1%: %2%", opt_key, e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
Option::Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), opt_id(id)
|
||||
{
|
||||
if (!opt.tooltip.empty()) {
|
||||
@ -571,8 +693,8 @@ void OptionsGroup::clear_fields_except_of(const std::vector<std::string> left_fi
|
||||
}
|
||||
|
||||
void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) {
|
||||
if (m_on_change != nullptr)
|
||||
m_on_change(opt_id, value);
|
||||
if (on_change != nullptr)
|
||||
on_change(opt_id, value);
|
||||
}
|
||||
|
||||
Option ConfigOptionsGroup::get_option(const std::string& opt_key, int opt_index /*= -1*/)
|
||||
@ -614,18 +736,18 @@ void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const b
|
||||
|
||||
void ConfigOptionsGroup::back_to_initial_value(const std::string& opt_key)
|
||||
{
|
||||
if (m_get_initial_config == nullptr)
|
||||
if (get_initial_config == nullptr)
|
||||
return;
|
||||
back_to_config_value(m_get_initial_config(), opt_key);
|
||||
back_to_config_value(get_initial_config(), opt_key);
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::back_to_sys_value(const std::string& opt_key)
|
||||
{
|
||||
if (m_get_sys_config == nullptr)
|
||||
if (get_sys_config == nullptr)
|
||||
return;
|
||||
if (!have_sys_config())
|
||||
return;
|
||||
back_to_config_value(m_get_sys_config(), opt_key);
|
||||
back_to_config_value(get_sys_config(), opt_key);
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key)
|
||||
@ -663,8 +785,8 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config,
|
||||
|
||||
void ConfigOptionsGroup::on_kill_focus(const std::string& opt_key)
|
||||
{
|
||||
if (m_fill_empty_value)
|
||||
m_fill_empty_value(opt_key);
|
||||
if (fill_empty_value)
|
||||
fill_empty_value(opt_key);
|
||||
else
|
||||
reload_config();
|
||||
}
|
||||
@ -1012,7 +1134,7 @@ std::pair<OG_CustomCtrl*, bool*> ConfigOptionsGroup::get_custom_ctrl_with_blinki
|
||||
void ConfigOptionsGroup::change_opt_value(const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
||||
|
||||
{
|
||||
Slic3r::GUI::change_opt_value(const_cast<DynamicPrintConfig&>(*m_config), opt_key, value, opt_index);
|
||||
OptionsGroup::change_opt_value(const_cast<DynamicPrintConfig&>(*m_config), opt_key, value, opt_index);
|
||||
if (m_modelconfig)
|
||||
m_modelconfig->touch();
|
||||
}
|
||||
|
@ -122,13 +122,14 @@ public:
|
||||
OG_CustomCtrl* custom_ctrl{ nullptr };
|
||||
int ctrl_horiz_alignment{ wxALIGN_LEFT};
|
||||
column_t extra_column {nullptr};
|
||||
t_change m_on_change { nullptr };
|
||||
t_change on_change { nullptr };
|
||||
// To be called when the field loses focus, to assign a new initial value to the field.
|
||||
// Used by the relative position / rotation / scale manipulation fields of the Object Manipulation UI.
|
||||
t_kill_focus m_fill_empty_value { nullptr };
|
||||
std::function<DynamicPrintConfig()> m_get_initial_config{ nullptr };
|
||||
std::function<DynamicPrintConfig()> m_get_sys_config{ nullptr };
|
||||
std::function<bool()> have_sys_config{ nullptr };
|
||||
t_kill_focus fill_empty_value { nullptr };
|
||||
|
||||
std::function<DynamicPrintConfig()> get_initial_config{ nullptr };
|
||||
std::function<DynamicPrintConfig()> get_sys_config { nullptr };
|
||||
std::function<bool()> have_sys_config { nullptr };
|
||||
|
||||
std::function<void(wxWindow* win)> rescale_extra_column_item { nullptr };
|
||||
std::function<void(wxWindow* win)> rescale_near_label_widget { nullptr };
|
||||
@ -258,6 +259,9 @@ public:
|
||||
static wxString get_url(const std::string& path_end);
|
||||
static bool launch_browser(const std::string& path_end);
|
||||
static bool is_option_without_field(const std::string& opt_key);
|
||||
|
||||
// Change option value in config
|
||||
static void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0);
|
||||
};
|
||||
|
||||
class ConfigOptionsGroup: public OptionsGroup {
|
||||
|
@ -281,7 +281,7 @@ void PhysicalPrinterDialog::update_printers()
|
||||
|
||||
void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup)
|
||||
{
|
||||
m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (opt_key == "host_type" || opt_key == "printhost_authorization_type")
|
||||
this->update();
|
||||
if (opt_key == "print_host")
|
||||
|
@ -403,7 +403,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
|
||||
m_og->set_config(config);
|
||||
m_og->hide_labels();
|
||||
|
||||
m_og->m_on_change = [config, this](t_config_option_key opt_key, boost::any value) {
|
||||
m_og->on_change = [config, this](t_config_option_key opt_key, boost::any value) {
|
||||
Tab* tab_print = wxGetApp().get_tab(Preset::TYPE_PRINT);
|
||||
if (!tab_print) return;
|
||||
|
||||
@ -559,7 +559,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
|
||||
DynamicPrintConfig* config_sla = &wxGetApp().preset_bundle->sla_prints.get_edited_preset().config;
|
||||
m_og_sla->set_config(config_sla);
|
||||
|
||||
m_og_sla->m_on_change = [config_sla](t_config_option_key opt_key, boost::any value) {
|
||||
m_og_sla->on_change = [config_sla](t_config_option_key opt_key, boost::any value) {
|
||||
Tab* tab = wxGetApp().get_tab(Preset::TYPE_SLA_PRINT);
|
||||
if (!tab) return;
|
||||
|
||||
|
@ -272,7 +272,7 @@ void PreferencesDialog::build()
|
||||
|
||||
// Add "General" tab
|
||||
m_optgroup_general = create_options_tab(L("General"), tabs);
|
||||
m_optgroup_general->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_general->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (auto it = m_values.find(opt_key); it != m_values.end()) {
|
||||
m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected
|
||||
return;
|
||||
@ -456,7 +456,7 @@ void PreferencesDialog::build()
|
||||
|
||||
// Add "Camera" tab
|
||||
m_optgroup_camera = create_options_tab(L("Camera"), tabs);
|
||||
m_optgroup_camera->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_camera->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (auto it = m_values.find(opt_key);it != m_values.end()) {
|
||||
m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected
|
||||
return;
|
||||
@ -483,7 +483,7 @@ void PreferencesDialog::build()
|
||||
|
||||
// Add "GUI" tab
|
||||
m_optgroup_gui = create_options_tab(L("GUI"), tabs);
|
||||
m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_gui->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (opt_key == "notify_release") {
|
||||
int val_int = boost::any_cast<int>(value);
|
||||
for (const auto& item : s_keys_map_NotifyReleaseMode) {
|
||||
@ -615,7 +615,7 @@ void PreferencesDialog::build()
|
||||
create_settings_mode_color_widget();
|
||||
|
||||
m_optgroup_other = create_options_tab(_L("Other"), tabs);
|
||||
m_optgroup_other->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_other->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
|
||||
if (auto it = m_values.find(opt_key); it != m_values.end() && opt_key != "url_downloader_dest") {
|
||||
m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected
|
||||
@ -649,7 +649,7 @@ void PreferencesDialog::build()
|
||||
#if ENABLE_ENVIRONMENT_MAP
|
||||
// Add "Render" tab
|
||||
m_optgroup_render = create_options_tab(L("Render"), tabs);
|
||||
m_optgroup_render->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_render->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (auto it = m_values.find(opt_key); it != m_values.end()) {
|
||||
m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected
|
||||
return;
|
||||
@ -669,7 +669,7 @@ void PreferencesDialog::build()
|
||||
#ifdef _WIN32
|
||||
// Add "Dark Mode" tab
|
||||
m_optgroup_dark_mode = create_options_tab(_L("Dark mode"), tabs);
|
||||
m_optgroup_dark_mode->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
m_optgroup_dark_mode->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
if (auto it = m_values.find(opt_key); it != m_values.end()) {
|
||||
m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected
|
||||
return;
|
||||
|
@ -1070,7 +1070,7 @@ void Tab::toggle_option(const std::string& opt_key, bool toggle, int opt_index/*
|
||||
// and value can be some random value because in this case it will not been used
|
||||
void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value /*= false*/)
|
||||
{
|
||||
if (!saved_value) change_opt_value(*m_config, opt_key, value);
|
||||
if (!saved_value) OptionsGroup::change_opt_value(*m_config, opt_key, value);
|
||||
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
||||
if (opt_key == "compatible_printers" || opt_key == "compatible_prints") {
|
||||
// Don't select another profile if this profile happens to become incompatible.
|
||||
@ -1713,7 +1713,7 @@ void TabPrint::build()
|
||||
optgroup->append_single_option_line(option);
|
||||
optgroup->append_single_option_line("gcode_binary");
|
||||
|
||||
optgroup->m_on_change = [this](const t_config_option_key& opt_key, boost::any value)
|
||||
optgroup->on_change = [this](const t_config_option_key& opt_key, boost::any value)
|
||||
{
|
||||
if (opt_key == "gcode_binary") {
|
||||
const bool is_binary = m_config->opt_bool("gcode_binary");
|
||||
@ -2198,7 +2198,7 @@ void TabFilament::build()
|
||||
optgroup->append_single_option_line("filament_cost");
|
||||
optgroup->append_single_option_line("filament_spool_weight");
|
||||
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value)
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value)
|
||||
{
|
||||
update_dirty();
|
||||
if (opt_key == "filament_spool_weight") {
|
||||
@ -2327,7 +2327,7 @@ void TabFilament::build()
|
||||
|
||||
page = add_options_page(L("Custom G-code"), "cog");
|
||||
optgroup = page->new_optgroup(L("Start G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2338,7 +2338,7 @@ void TabFilament::build()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("End G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2660,7 +2660,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
optgroup->append_single_option_line("single_extruder_multi_material");
|
||||
|
||||
optgroup->m_on_change = [this, optgroup_wk = ConfigOptionsGroupWkp(optgroup)](t_config_option_key opt_key, boost::any value) {
|
||||
optgroup->on_change = [this, optgroup_wk = ConfigOptionsGroupWkp(optgroup)](t_config_option_key opt_key, boost::any value) {
|
||||
auto optgroup_sh = optgroup_wk.lock();
|
||||
if (!optgroup_sh)
|
||||
return;
|
||||
@ -2734,7 +2734,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line("silent_mode");
|
||||
optgroup->append_single_option_line("remaining_times");
|
||||
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
wxTheApp->CallAfter([this, opt_key, value]() {
|
||||
if (opt_key == "thumbnails" && m_config->has("thumbnails_format")) {
|
||||
// to backward compatibility we need to update "thumbnails_format" from new "thumbnails"
|
||||
@ -2824,7 +2824,7 @@ void TabPrinter::build_fff()
|
||||
const int notes_field_height = 25; // 250
|
||||
page = add_options_page(L("Custom G-code"), "cog");
|
||||
optgroup = page->new_optgroup(L("Start G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2838,7 +2838,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line("autoemit_temperature_commands");
|
||||
|
||||
optgroup = page->new_optgroup(L("End G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2849,7 +2849,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Before layer change G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2860,7 +2860,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("After layer change G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2871,7 +2871,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Tool change G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2882,7 +2882,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Between objects G-code (for sequential printing)"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2893,7 +2893,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Color Change G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2903,7 +2903,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Pause Print G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -2913,7 +2913,7 @@ void TabPrinter::build_fff()
|
||||
optgroup->append_single_option_line(option);
|
||||
|
||||
optgroup = page->new_optgroup(L("Template Custom G-code"), 0);
|
||||
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
|
||||
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
|
||||
};
|
||||
optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
|
||||
@ -3070,7 +3070,7 @@ PageShp TabPrinter::build_kinematics_page()
|
||||
optgroup->append_line(line);
|
||||
}
|
||||
|
||||
optgroup->m_on_change = [this](const t_config_option_key& opt_key, boost::any value)
|
||||
optgroup->on_change = [this](const t_config_option_key& opt_key, boost::any value)
|
||||
{
|
||||
if (opt_key == "machine_limits_usage" &&
|
||||
static_cast<MachineLimitsUsage>(boost::any_cast<int>(value)) == MachineLimitsUsage::EmitToGCode &&
|
||||
@ -3164,7 +3164,7 @@ void TabPrinter::build_extruder_pages(size_t n_before_extruders)
|
||||
auto optgroup = page->new_optgroup(L("Size"));
|
||||
optgroup->append_single_option_line("nozzle_diameter", "", extruder_idx);
|
||||
|
||||
optgroup->m_on_change = [this, extruder_idx](const t_config_option_key&opt_key, boost::any value)
|
||||
optgroup->on_change = [this, extruder_idx](const t_config_option_key&opt_key, boost::any value)
|
||||
{
|
||||
const bool is_single_extruder_MM = m_config->opt_bool("single_extruder_multi_material");
|
||||
const bool is_nozzle_diameter_changed = opt_key.find_first_of("nozzle_diameter") != std::string::npos;
|
||||
@ -5254,33 +5254,27 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la
|
||||
optgroup->label_width = noncommon_label_width;
|
||||
|
||||
#ifdef __WXOSX__
|
||||
auto tab = parent()->GetParent()->GetParent();// GetParent()->GetParent();
|
||||
Tab* tab = static_cast<Tab*>(parent()->GetParent()->GetParent());
|
||||
#else
|
||||
auto tab = parent()->GetParent();// GetParent();
|
||||
Tab* tab = static_cast<Tab*>(parent()->GetParent());
|
||||
#endif
|
||||
optgroup->set_config_category_and_type(m_title, static_cast<Tab*>(tab)->type());
|
||||
optgroup->m_on_change = [tab](t_config_option_key opt_key, boost::any value) {
|
||||
//! This function will be called from OptionGroup.
|
||||
//! Using of CallAfter is redundant.
|
||||
//! And in some cases it causes update() function to be recalled again
|
||||
//! wxTheApp->CallAfter([this, opt_key, value]() {
|
||||
static_cast<Tab*>(tab)->update_dirty();
|
||||
static_cast<Tab*>(tab)->on_value_change(opt_key, value);
|
||||
//! });
|
||||
optgroup->on_change = [tab](t_config_option_key opt_key, boost::any value) {
|
||||
// This function will be called from OptionGroup.
|
||||
tab->update_dirty();
|
||||
tab->on_value_change(opt_key, value);
|
||||
};
|
||||
|
||||
optgroup->m_get_initial_config = [tab]() {
|
||||
DynamicPrintConfig config = static_cast<Tab*>(tab)->m_presets->get_selected_preset().config;
|
||||
return config;
|
||||
optgroup->get_initial_config = [tab]() {
|
||||
return tab->m_presets->get_selected_preset().config;
|
||||
};
|
||||
|
||||
optgroup->m_get_sys_config = [tab]() {
|
||||
DynamicPrintConfig config = static_cast<Tab*>(tab)->m_presets->get_selected_preset_parent()->config;
|
||||
return config;
|
||||
optgroup->get_sys_config = [tab]() {
|
||||
return tab->m_presets->get_selected_preset_parent()->config;
|
||||
};
|
||||
|
||||
optgroup->have_sys_config = [tab]() {
|
||||
return static_cast<Tab*>(tab)->m_presets->get_selected_preset_parent() != nullptr;
|
||||
return tab->m_presets->get_selected_preset_parent() != nullptr;
|
||||
};
|
||||
|
||||
optgroup->rescale_extra_column_item = [](wxWindow* win) {
|
||||
@ -5320,7 +5314,7 @@ void TabSLAMaterial::build()
|
||||
optgroup->append_single_option_line("bottle_weight");
|
||||
optgroup->append_single_option_line("material_density");
|
||||
|
||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value)
|
||||
optgroup->on_change = [this](t_config_option_key opt_key, boost::any value)
|
||||
{
|
||||
if (opt_key == "material_colour") {
|
||||
update_dirty();
|
||||
|
Loading…
x
Reference in New Issue
Block a user