Cleaned code
This commit is contained in:
parent
d82505984a
commit
120c1978ae
8 changed files with 120 additions and 136 deletions
|
@ -75,13 +75,13 @@ namespace Slic3r { namespace GUI {
|
|||
return tooltip_text;
|
||||
}
|
||||
|
||||
bool Field::is_matched(std::string string, std::string pattern)
|
||||
bool Field::is_matched(const std::string& string, const std::string& pattern)
|
||||
{
|
||||
std::regex regex_pattern(pattern, std::regex_constants::icase); // use ::icase to make the matching case insensitive like /i in perl
|
||||
return std::regex_match(string, regex_pattern);
|
||||
}
|
||||
|
||||
boost::any Field::get_value_by_opt_type(wxString str)
|
||||
boost::any Field::get_value_by_opt_type(wxString& str)
|
||||
{
|
||||
boost::any ret_val;
|
||||
switch (m_opt.type){
|
||||
|
@ -377,7 +377,7 @@ void Choice::set_selection()
|
|||
}
|
||||
}
|
||||
|
||||
void Choice::set_value(const std::string value, bool change_event) //! Redundant?
|
||||
void Choice::set_value(const std::string& value, bool change_event) //! Redundant?
|
||||
{
|
||||
m_disable_change_event = !change_event;
|
||||
|
||||
|
@ -396,7 +396,7 @@ void Choice::set_value(const std::string value, bool change_event) //! Redundan
|
|||
m_disable_change_event = false;
|
||||
}
|
||||
|
||||
void Choice::set_value(boost::any value, bool change_event)
|
||||
void Choice::set_value(const boost::any& value, bool change_event)
|
||||
{
|
||||
m_disable_change_event = !change_event;
|
||||
|
||||
|
@ -435,7 +435,7 @@ void Choice::set_value(boost::any value, bool change_event)
|
|||
}
|
||||
|
||||
//! it's needed for _update_serial_ports()
|
||||
void Choice::set_values(const std::vector<std::string> values)
|
||||
void Choice::set_values(const std::vector<std::string>& values)
|
||||
{
|
||||
if (values.empty())
|
||||
return;
|
||||
|
@ -554,7 +554,7 @@ void PointCtrl::BUILD()
|
|||
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
||||
}
|
||||
|
||||
void PointCtrl::set_value(const Pointf value, bool change_event)
|
||||
void PointCtrl::set_value(const Pointf& value, bool change_event)
|
||||
{
|
||||
m_disable_change_event = !change_event;
|
||||
|
||||
|
@ -566,10 +566,10 @@ void PointCtrl::set_value(const Pointf value, bool change_event)
|
|||
m_disable_change_event = false;
|
||||
}
|
||||
|
||||
void PointCtrl::set_value(boost::any value, bool change_event)
|
||||
void PointCtrl::set_value(const boost::any& value, bool change_event)
|
||||
{
|
||||
Pointf pt;
|
||||
Pointf *ptf = boost::any_cast<Pointf>(&value);
|
||||
const Pointf *ptf = boost::any_cast<Pointf>(&value);
|
||||
if (!ptf)
|
||||
{
|
||||
ConfigOptionPoints* pts = boost::any_cast<ConfigOptionPoints*>(value);
|
||||
|
@ -577,21 +577,6 @@ void PointCtrl::set_value(boost::any value, bool change_event)
|
|||
}
|
||||
else
|
||||
pt = *ptf;
|
||||
// try
|
||||
// {
|
||||
// pt = boost::any_cast<ConfigOptionPoints*>(value)->values.at(0);
|
||||
// }
|
||||
// catch (const std::exception &e)
|
||||
// {
|
||||
// try{
|
||||
// pt = boost::any_cast<Pointf>(value);
|
||||
// }
|
||||
// catch (const std::exception &e)
|
||||
// {
|
||||
// std::cerr << "Error! Can't cast PointCtrl value" << m_opt_id << "\n";
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
set_value(pt, change_event);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace Slic3r { namespace GUI {
|
|||
class Field;
|
||||
using t_field = std::unique_ptr<Field>;
|
||||
using t_kill_focus = std::function<void()>;
|
||||
using t_change = std::function<void(t_config_option_key, boost::any)>;
|
||||
using t_back_to_init = std::function<void(std::string)>;
|
||||
using t_change = std::function<void(t_config_option_key, const boost::any&)>;
|
||||
using t_back_to_init = std::function<void(const std::string&)>;
|
||||
|
||||
wxString double_to_string(double const value);
|
||||
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
/// Sets a value for this control.
|
||||
/// subclasses should overload with a specific version
|
||||
/// Postcondition: Method does not fire the on_change event.
|
||||
virtual void set_value(boost::any value, bool change_event) = 0;
|
||||
virtual void set_value(const boost::any& value, bool change_event) = 0;
|
||||
|
||||
/// Gets a boost::any representing this control.
|
||||
/// subclasses should overload with a specific version
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
virtual wxString get_tooltip_text(const wxString& default_string);
|
||||
|
||||
// set icon to "UndoToSystemValue" button according to an inheritance of preset
|
||||
void set_nonsys_btn_icon(const std::string& icon);
|
||||
void set_nonsys_btn_icon(const std::string& icon);
|
||||
|
||||
Field(const ConfigOptionDef& opt, const t_config_option_key& id) : m_opt(opt), m_opt_id(id) {};
|
||||
Field(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : m_parent(parent), m_opt(opt), m_opt_id(id) {};
|
||||
|
@ -109,8 +109,8 @@ public:
|
|||
virtual wxSizer* getSizer() { return nullptr; }
|
||||
virtual wxWindow* getWindow() { return nullptr; }
|
||||
|
||||
bool is_matched(std::string string, std::string pattern);
|
||||
boost::any get_value_by_opt_type(wxString str);
|
||||
bool is_matched(const std::string& string, const std::string& pattern);
|
||||
boost::any get_value_by_opt_type(wxString& str);
|
||||
|
||||
/// Factory method for generating new derived classes.
|
||||
template<class T>
|
||||
|
@ -137,16 +137,17 @@ class TextCtrl : public Field {
|
|||
public:
|
||||
TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
TextCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
|
||||
~TextCtrl() {}
|
||||
|
||||
void BUILD();
|
||||
wxWindow* window {nullptr};
|
||||
|
||||
virtual void set_value(std::string value, bool change_event = false) {
|
||||
virtual void set_value(const std::string& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxTextCtrl*>(window)->SetValue(wxString(value));
|
||||
m_disable_change_event = false;
|
||||
}
|
||||
virtual void set_value(boost::any value, bool change_event = false) {
|
||||
virtual void set_value(const boost::any& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(value));
|
||||
m_disable_change_event = false;
|
||||
|
@ -164,6 +165,7 @@ class CheckBox : public Field {
|
|||
public:
|
||||
CheckBox(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
CheckBox(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
|
||||
~CheckBox() {}
|
||||
|
||||
wxWindow* window{ nullptr };
|
||||
void BUILD() override;
|
||||
|
@ -173,7 +175,7 @@ public:
|
|||
dynamic_cast<wxCheckBox*>(window)->SetValue(value);
|
||||
m_disable_change_event = false;
|
||||
}
|
||||
void set_value(boost::any value, bool change_event = false) {
|
||||
void set_value(const boost::any& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<bool>(value));
|
||||
m_disable_change_event = false;
|
||||
|
@ -190,21 +192,22 @@ class SpinCtrl : public Field {
|
|||
public:
|
||||
SpinCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id), tmp_value(-9999) {}
|
||||
SpinCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id), tmp_value(-9999) {}
|
||||
~SpinCtrl() {}
|
||||
|
||||
int tmp_value;
|
||||
|
||||
wxWindow* window{ nullptr };
|
||||
void BUILD() override;
|
||||
|
||||
void set_value(const std::string value, bool change_event = false) {
|
||||
void set_value(const std::string& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxSpinCtrl*>(window)->SetValue(value);
|
||||
m_disable_change_event = false;
|
||||
}
|
||||
void set_value(boost::any value, bool change_event = false) {
|
||||
void set_value(const boost::any& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
tmp_value = boost::any_cast<int>(value);
|
||||
dynamic_cast<wxSpinCtrl*>(window)->SetValue(tmp_value/*boost::any_cast<int>(value)*/);
|
||||
dynamic_cast<wxSpinCtrl*>(window)->SetValue(tmp_value);
|
||||
m_disable_change_event = false;
|
||||
}
|
||||
boost::any get_value() override {
|
||||
|
@ -221,14 +224,15 @@ class Choice : public Field {
|
|||
public:
|
||||
Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
|
||||
~Choice() {}
|
||||
|
||||
wxWindow* window{ nullptr };
|
||||
void BUILD() override;
|
||||
|
||||
void set_selection();
|
||||
void set_value(const std::string value, bool change_event = false);
|
||||
void set_value(boost::any value, bool change_event = false);
|
||||
void set_values(const std::vector<std::string> values);
|
||||
void set_value(const std::string& value, bool change_event = false);
|
||||
void set_value(const boost::any& value, bool change_event = false);
|
||||
void set_values(const std::vector<std::string> &values);
|
||||
boost::any get_value() override;
|
||||
|
||||
void enable() override { dynamic_cast<wxComboBox*>(window)->Enable(); };
|
||||
|
@ -241,16 +245,17 @@ class ColourPicker : public Field {
|
|||
public:
|
||||
ColourPicker(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
ColourPicker(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
|
||||
~ColourPicker() {}
|
||||
|
||||
wxWindow* window{ nullptr };
|
||||
void BUILD() override;
|
||||
|
||||
void set_value(const std::string value, bool change_event = false) {
|
||||
void set_value(const std::string& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxColourPickerCtrl*>(window)->SetColour(value);
|
||||
m_disable_change_event = false;
|
||||
}
|
||||
void set_value(boost::any value, bool change_event = false) {
|
||||
void set_value(const boost::any& value, bool change_event = false) {
|
||||
m_disable_change_event = !change_event;
|
||||
dynamic_cast<wxColourPickerCtrl*>(window)->SetColour(boost::any_cast<wxString>(value));
|
||||
m_disable_change_event = false;
|
||||
|
@ -268,23 +273,24 @@ class PointCtrl : public Field {
|
|||
public:
|
||||
PointCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
PointCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
|
||||
~PointCtrl() {}
|
||||
|
||||
wxSizer* sizer{ nullptr };
|
||||
wxTextCtrl* x_textctrl;
|
||||
wxTextCtrl* y_textctrl;
|
||||
wxTextCtrl* x_textctrl{ nullptr };
|
||||
wxTextCtrl* y_textctrl{ nullptr };
|
||||
|
||||
void BUILD() override;
|
||||
|
||||
void set_value(const Pointf value, bool change_event = false);
|
||||
void set_value(boost::any value, bool change_event = false);
|
||||
void set_value(const Pointf& value, bool change_event = false);
|
||||
void set_value(const boost::any& value, bool change_event = false);
|
||||
boost::any get_value() override;
|
||||
|
||||
void enable() override {
|
||||
x_textctrl->Enable();
|
||||
y_textctrl->Enable(); };
|
||||
y_textctrl->Enable(); }
|
||||
void disable() override{
|
||||
x_textctrl->Disable();
|
||||
y_textctrl->Disable(); };
|
||||
y_textctrl->Disable(); }
|
||||
wxSizer* getSizer() override { return sizer; }
|
||||
};
|
||||
|
||||
|
|
|
@ -403,7 +403,7 @@ TabIface* get_preset_tab_iface(char *name)
|
|||
}
|
||||
|
||||
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
|
||||
void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index /*= 0*/)
|
||||
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
||||
{
|
||||
try{
|
||||
switch (config.def()->get(opt_key)->type){
|
||||
|
@ -439,11 +439,18 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
||||
break;
|
||||
case coStrings:{
|
||||
if (opt_key.compare("compatible_printers") == 0 ||
|
||||
config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){
|
||||
config.option<ConfigOptionStrings>(opt_key)->values.resize(0);
|
||||
std::vector<std::string> values = boost::any_cast<std::vector<std::string>>(value);
|
||||
if (values.size() == 1 && values[0] == "")
|
||||
if (opt_key.compare("compatible_printers") == 0) {
|
||||
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);
|
||||
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.
|
||||
std::vector<std::string> values;
|
||||
boost::split(values, str, boost::is_any_of(";"));
|
||||
if (values.size() == 1 && values[0] == "")
|
||||
break;
|
||||
config.option<ConfigOptionStrings>(opt_key)->values = values;
|
||||
}
|
||||
|
@ -510,17 +517,17 @@ void add_created_tab(Tab* panel)
|
|||
g_wxTabPanel->AddPage(panel, panel->title());
|
||||
}
|
||||
|
||||
void show_error(wxWindow* parent, wxString message){
|
||||
void show_error(wxWindow* parent, const wxString& message){
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, _(L("Error")), wxOK | wxICON_ERROR);
|
||||
msg_wingow->ShowModal();
|
||||
}
|
||||
|
||||
void show_info(wxWindow* parent, wxString message, wxString title){
|
||||
void show_info(wxWindow* parent, const wxString& message, const wxString& title){
|
||||
auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _(L("Notice")) : title, wxOK | wxICON_INFORMATION);
|
||||
msg_wingow->ShowModal();
|
||||
}
|
||||
|
||||
void warning_catcher(wxWindow* parent, wxString message){
|
||||
void warning_catcher(wxWindow* parent, const wxString& message){
|
||||
if (message == _(L("GLUquadricObjPtr | Attempt to free unreferenced scalar")) )
|
||||
return;
|
||||
auto msg = new wxMessageDialog(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
||||
|
|
|
@ -96,11 +96,11 @@ TabIface* get_preset_tab_iface(char *name);
|
|||
// add it at the end of the tab panel.
|
||||
void add_created_tab(Tab* panel);
|
||||
// Change option value in config
|
||||
void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index = 0);
|
||||
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0);
|
||||
|
||||
void show_error(wxWindow* parent, wxString message);
|
||||
void show_info(wxWindow* parent, wxString message, wxString title);
|
||||
void warning_catcher(wxWindow* parent, wxString message);
|
||||
void show_error(wxWindow* parent, const wxString& message);
|
||||
void show_info(wxWindow* parent, const wxString& message, const wxString& title);
|
||||
void warning_catcher(wxWindow* parent, const wxString& message);
|
||||
|
||||
// load language saved at application config
|
||||
bool load_language();
|
||||
|
|
|
@ -227,12 +227,12 @@ Line OptionsGroup::create_single_option_line(const Option& option) const {
|
|||
return retval;
|
||||
}
|
||||
|
||||
void OptionsGroup::on_change_OG(t_config_option_key id, /*config_value*/boost::any value) {
|
||||
void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) {
|
||||
if (m_on_change != nullptr)
|
||||
m_on_change(id, value);
|
||||
m_on_change(opt_id, value);
|
||||
}
|
||||
|
||||
Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index /*= -1*/)
|
||||
Option ConfigOptionsGroup::get_option(const std::string& opt_key, int opt_index /*= -1*/)
|
||||
{
|
||||
if (!m_config->has(opt_key)) {
|
||||
std::cerr << "No " << opt_key << " in ConfigOptionsGroup config.";
|
||||
|
@ -245,7 +245,7 @@ Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index /
|
|||
return Option(*m_config->def()->get(opt_key), opt_id);
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any value)
|
||||
void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value)
|
||||
{
|
||||
if (!m_opt_map.empty())
|
||||
{
|
||||
|
@ -268,16 +268,7 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val
|
|||
if (opt_index != -1){
|
||||
// die "Can't set serialized option indexed value" ;
|
||||
}
|
||||
// # 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.
|
||||
// my @values = split / ; / , $field_value;
|
||||
// $self->config->set($opt_key, \@values);
|
||||
std::string str = boost::any_cast<std::string>(value);
|
||||
if (str.back() == ';')
|
||||
str.pop_back();
|
||||
std::vector<std::string> values;
|
||||
boost::split(values, str, boost::is_any_of(";"));
|
||||
change_opt_value(*m_config, opt_key, values);
|
||||
change_opt_value(*m_config, opt_key, value);
|
||||
}
|
||||
else {
|
||||
if (opt_index == -1) {
|
||||
|
@ -297,14 +288,14 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val
|
|||
OptionsGroup::on_change_OG(opt_id, value); //!? Why doing this
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::back_to_initial_value(const std::string opt_key)
|
||||
void ConfigOptionsGroup::back_to_initial_value(const std::string& opt_key)
|
||||
{
|
||||
if (m_get_initial_config == nullptr)
|
||||
return;
|
||||
back_to_config_value(m_get_initial_config(), opt_key);
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::back_to_sys_value(const std::string opt_key)
|
||||
void ConfigOptionsGroup::back_to_sys_value(const std::string& opt_key)
|
||||
{
|
||||
if (m_get_sys_config == nullptr)
|
||||
return;
|
||||
|
@ -313,7 +304,7 @@ void ConfigOptionsGroup::back_to_sys_value(const std::string opt_key)
|
|||
back_to_config_value(m_get_sys_config(), opt_key);
|
||||
}
|
||||
|
||||
void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string opt_key)
|
||||
void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key)
|
||||
{
|
||||
boost::any value;
|
||||
if (opt_key == "extruders_count"){
|
||||
|
@ -348,7 +339,7 @@ void ConfigOptionsGroup::reload_config(){
|
|||
|
||||
}
|
||||
|
||||
boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index, bool deserialize){
|
||||
boost::any ConfigOptionsGroup::config_value(const std::string& opt_key, int opt_index, bool deserialize){
|
||||
|
||||
if (deserialize) {
|
||||
// Want to edit a vector value(currently only multi - strings) in a single edit box.
|
||||
|
@ -365,7 +356,7 @@ boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index,
|
|||
}
|
||||
}
|
||||
|
||||
boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config, std::string opt_key, int opt_index /*= -1*/)
|
||||
boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index /*= -1*/)
|
||||
{
|
||||
size_t idx = opt_index == -1 ? 0 : opt_index;
|
||||
|
||||
|
@ -457,7 +448,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
|
|||
return ret;
|
||||
}
|
||||
|
||||
Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index){
|
||||
Field* ConfigOptionsGroup::get_fieldc(const t_config_option_key& opt_key, int opt_index){
|
||||
Field* field = get_field(opt_key);
|
||||
if (field != nullptr)
|
||||
return field;
|
||||
|
@ -471,7 +462,7 @@ Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index
|
|||
return opt_id.empty() ? nullptr : get_field(opt_id);
|
||||
}
|
||||
|
||||
void ogStaticText::SetText(wxString value)
|
||||
void ogStaticText::SetText(const wxString& value)
|
||||
{
|
||||
SetLabel(value);
|
||||
Wrap(400);
|
||||
|
|
|
@ -98,16 +98,16 @@ public:
|
|||
void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
||||
|
||||
// return a non-owning pointer reference
|
||||
inline Field* get_field(t_config_option_key id) const{
|
||||
inline Field* get_field(const t_config_option_key& id) const{
|
||||
if (m_fields.find(id) == m_fields.end()) return nullptr;
|
||||
return m_fields.at(id).get();
|
||||
}
|
||||
bool set_value(t_config_option_key id, boost::any value, bool change_event = false) {
|
||||
bool set_value(const t_config_option_key& id, const boost::any& value, bool change_event = false) {
|
||||
if (m_fields.find(id) == m_fields.end()) return false;
|
||||
m_fields.at(id)->set_value(value, change_event);
|
||||
return true;
|
||||
}
|
||||
boost::any get_value(t_config_option_key id) {
|
||||
boost::any get_value(const t_config_option_key& id) {
|
||||
boost::any out;
|
||||
if (m_fields.find(id) == m_fields.end()) ;
|
||||
else
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
||||
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
||||
|
||||
OptionsGroup(wxWindow* _parent, wxString title, bool is_tab_opt=false) :
|
||||
OptionsGroup(wxWindow* _parent, const wxString& title, bool is_tab_opt=false) :
|
||||
m_parent(_parent), title(title), m_is_tab_opt(is_tab_opt), staticbox(title!="") {
|
||||
sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
||||
auto num_columns = 1U;
|
||||
|
@ -152,14 +152,14 @@ protected:
|
|||
const t_field& build_field(const Option& opt, wxStaticText* label = nullptr);
|
||||
|
||||
virtual void on_kill_focus (){};
|
||||
virtual void on_change_OG(t_config_option_key opt_id, boost::any value);
|
||||
virtual void back_to_initial_value(const std::string opt_key){};
|
||||
virtual void back_to_sys_value(const std::string opt_key){};
|
||||
virtual void on_change_OG(const t_config_option_key& opt_id, const boost::any& value);
|
||||
virtual void back_to_initial_value(const std::string& opt_key){}
|
||||
virtual void back_to_sys_value(const std::string& opt_key){}
|
||||
};
|
||||
|
||||
class ConfigOptionsGroup: public OptionsGroup {
|
||||
public:
|
||||
ConfigOptionsGroup(wxWindow* parent, wxString title, DynamicPrintConfig* _config = nullptr, bool is_tab_opt = false) :
|
||||
ConfigOptionsGroup(wxWindow* parent, const wxString& title, DynamicPrintConfig* _config = nullptr, bool is_tab_opt = false) :
|
||||
OptionsGroup(parent, title, is_tab_opt), m_config(_config) {}
|
||||
|
||||
/// reference to libslic3r config, non-owning pointer (?).
|
||||
|
@ -167,8 +167,8 @@ public:
|
|||
bool m_full_labels {0};
|
||||
t_opt_map m_opt_map;
|
||||
|
||||
Option get_option(const std::string opt_key, int opt_index = -1);
|
||||
Line create_single_option_line(const std::string title, int idx = -1) /*const*/{
|
||||
Option get_option(const std::string& opt_key, int opt_index = -1);
|
||||
Line create_single_option_line(const std::string& title, int idx = -1) /*const*/{
|
||||
Option option = get_option(title, idx);
|
||||
return OptionsGroup::create_single_option_line(option);
|
||||
}
|
||||
|
@ -181,16 +181,16 @@ public:
|
|||
append_single_option_line(option);
|
||||
}
|
||||
|
||||
void on_change_OG(t_config_option_key opt_id, boost::any value) override;
|
||||
void back_to_initial_value(const std::string opt_key) override;
|
||||
void back_to_sys_value(const std::string opt_key) override;
|
||||
void back_to_config_value(const DynamicPrintConfig& config, const std::string opt_key);
|
||||
void on_change_OG(const t_config_option_key& opt_id, const boost::any& value) override;
|
||||
void back_to_initial_value(const std::string& opt_key) override;
|
||||
void back_to_sys_value(const std::string& opt_key) override;
|
||||
void back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key);
|
||||
void on_kill_focus() override{ reload_config();}
|
||||
void reload_config();
|
||||
boost::any config_value(std::string opt_key, int opt_index, bool deserialize);
|
||||
boost::any config_value(const std::string& opt_key, int opt_index, bool deserialize);
|
||||
// return option value from config
|
||||
boost::any get_config_value(const DynamicPrintConfig& config, std::string opt_key, int opt_index = -1);
|
||||
Field* get_fieldc(t_config_option_key opt_key, int opt_index);
|
||||
boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1);
|
||||
Field* get_fieldc(const t_config_option_key& opt_key, int opt_index);
|
||||
};
|
||||
|
||||
// Static text shown among the options.
|
||||
|
@ -200,7 +200,7 @@ public:
|
|||
ogStaticText(wxWindow* parent, const char *text) : wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize){}
|
||||
~ogStaticText(){}
|
||||
|
||||
void SetText(wxString value);
|
||||
void SetText(const wxString& value);
|
||||
};
|
||||
|
||||
}}
|
||||
|
|
|
@ -203,11 +203,10 @@ void Tab::load_initial_data()
|
|||
{
|
||||
m_config = &m_presets->get_edited_preset().config;
|
||||
m_nonsys_btn_icon = m_presets->get_selected_preset_parent() == nullptr ?
|
||||
"bullet_white.png" : "sys_unlock.png";
|
||||
// wxMSW ? "sys_unlock.png" : "lock_open.png";
|
||||
"bullet_white.png" : "sys_unlock.png";
|
||||
}
|
||||
|
||||
PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder_pages/* = false*/)
|
||||
PageShp Tab::add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages/* = false*/)
|
||||
{
|
||||
// Index of icon in an icon list $self->{icons}.
|
||||
auto icon_idx = 0;
|
||||
|
@ -332,8 +331,8 @@ void Tab::update_changed_ui()
|
|||
{
|
||||
bool is_nonsys_value = false;
|
||||
bool is_modified_value = true;
|
||||
std::string sys_icon = /*wxMSW ? */"sys_lock.png"/* : "lock.png"*/;
|
||||
std::string icon = /*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/;
|
||||
std::string sys_icon = "sys_lock.png";
|
||||
std::string icon = "action_undo.png";
|
||||
wxColour color = get_sys_label_clr();
|
||||
if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) {
|
||||
is_nonsys_value = true;
|
||||
|
@ -478,10 +477,8 @@ void Tab::update_changed_tree_ui()
|
|||
|
||||
void Tab::update_undo_buttons()
|
||||
{
|
||||
const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" :
|
||||
/*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/;
|
||||
const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon :
|
||||
/*wxMSW ? */"sys_lock.png"/* : "lock.png"*/;
|
||||
const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" : "action_undo.png";
|
||||
const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon : "sys_lock.png";
|
||||
|
||||
m_undo_btn->SetBitmap(wxBitmap(from_u8(var(undo_icon)), wxBITMAP_TYPE_PNG));
|
||||
m_undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(undo_to_sys_icon)), wxBITMAP_TYPE_PNG));
|
||||
|
@ -559,7 +556,7 @@ void Tab::update_tab_ui()
|
|||
|
||||
// Load a provied DynamicConfig into the tab, modifying the active preset.
|
||||
// This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view.
|
||||
void Tab::load_config(DynamicPrintConfig config)
|
||||
void Tab::load_config(const DynamicPrintConfig& config)
|
||||
{
|
||||
bool modified = 0;
|
||||
for(auto opt_key : m_config->diff(config)) {
|
||||
|
@ -582,7 +579,7 @@ void Tab::reload_config(){
|
|||
Thaw();
|
||||
}
|
||||
|
||||
Field* Tab::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const
|
||||
Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const
|
||||
{
|
||||
Field* field = nullptr;
|
||||
for (auto page : m_pages){
|
||||
|
@ -596,7 +593,7 @@ Field* Tab::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const
|
|||
// Set a key/value pair on this page. Return true if the value has been modified.
|
||||
// Currently used for distributing extruders_count over preset pages of Slic3r::GUI::Tab::Printer
|
||||
// after a preset is loaded.
|
||||
bool Tab::set_value(t_config_option_key opt_key, boost::any value){
|
||||
bool Tab::set_value(const t_config_option_key& opt_key, const boost::any& value){
|
||||
bool changed = false;
|
||||
for(auto page: m_pages) {
|
||||
if (page->set_value(opt_key, value))
|
||||
|
@ -607,7 +604,7 @@ bool Tab::set_value(t_config_option_key opt_key, boost::any value){
|
|||
|
||||
// To be called by custom widgets, load a value into a config,
|
||||
// update the preset selection boxes (the dirty flags)
|
||||
void Tab::load_key_value(std::string opt_key, boost::any value)
|
||||
void Tab::load_key_value(const std::string& opt_key, const boost::any& value)
|
||||
{
|
||||
change_opt_value(*m_config, opt_key, value);
|
||||
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
||||
|
@ -621,7 +618,7 @@ void Tab::load_key_value(std::string opt_key, boost::any value)
|
|||
|
||||
extern wxFrame *g_wxMainFrame;
|
||||
|
||||
void Tab::on_value_change(std::string opt_key, boost::any value)
|
||||
void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
|
||||
{
|
||||
if (m_event_value_change > 0) {
|
||||
wxCommandEvent event(m_event_value_change);
|
||||
|
@ -636,8 +633,8 @@ void Tab::on_value_change(std::string opt_key, boost::any value)
|
|||
}
|
||||
if (opt_key == "fill_density")
|
||||
{
|
||||
value = get_optgroup()->get_config_value(*m_config, opt_key);
|
||||
get_optgroup()->set_value(opt_key, value);
|
||||
boost::any val = get_optgroup()->get_config_value(*m_config, opt_key);
|
||||
get_optgroup()->set_value(opt_key, val);
|
||||
}
|
||||
if (opt_key == "support_material" || opt_key == "support_material_buildplate_only")
|
||||
{
|
||||
|
@ -1785,9 +1782,7 @@ void Tab::load_current_preset()
|
|||
// Reload preset pages with the new configuration values.
|
||||
reload_config();
|
||||
const Preset* parent = m_presets->get_selected_preset_parent();
|
||||
m_nonsys_btn_icon = parent == nullptr ?
|
||||
"bullet_white.png" :
|
||||
/*wxMSW ? */"sys_unlock.png"/* : "lock_open.png"*/;
|
||||
m_nonsys_btn_icon = parent == nullptr ? "bullet_white.png" : "sys_unlock.png";
|
||||
|
||||
// use CallAfter because some field triggers schedule on_change calls using CallAfter,
|
||||
// and we don't want them to be called after this update_dirty() as they would mark the
|
||||
|
@ -1844,7 +1839,7 @@ void Tab::rebuild_page_tree()
|
|||
// Called by the UI combo box when the user switches profiles.
|
||||
// Select a preset by a name.If !defined(name), then the default preset is selected.
|
||||
// If the current profile is modified, user is asked to save the changes.
|
||||
void Tab::select_preset(std::string preset_name /*= ""*/)
|
||||
void Tab::select_preset(const std::string& preset_name /*= ""*/)
|
||||
{
|
||||
std::string name = preset_name;
|
||||
auto force = false;
|
||||
|
@ -1911,7 +1906,7 @@ void Tab::select_preset(std::string preset_name /*= ""*/)
|
|||
|
||||
// If the current preset is dirty, the user is asked whether the changes may be discarded.
|
||||
// if the current preset was not dirty, or the user agreed to discard the changes, 1 is returned.
|
||||
bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr*/, std::string new_printer_name /*= ""*/)
|
||||
bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr*/, const std::string& new_printer_name /*= ""*/)
|
||||
{
|
||||
if (presets == nullptr) presets = m_presets;
|
||||
// Display a dialog showing the dirty options in a human readable form.
|
||||
|
@ -2339,7 +2334,7 @@ void Page::reload_config()
|
|||
group->reload_config();
|
||||
}
|
||||
|
||||
Field* Page::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const
|
||||
Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const
|
||||
{
|
||||
Field* field = nullptr;
|
||||
for (auto opt : m_optgroups){
|
||||
|
@ -2350,7 +2345,7 @@ Field* Page::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) cons
|
|||
return field;
|
||||
}
|
||||
|
||||
bool Page::set_value(t_config_option_key opt_key, boost::any value){
|
||||
bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value){
|
||||
bool changed = false;
|
||||
for(auto optgroup: m_optgroups) {
|
||||
if (optgroup->set_value(opt_key, value))
|
||||
|
@ -2360,7 +2355,7 @@ bool Page::set_value(t_config_option_key opt_key, boost::any value){
|
|||
}
|
||||
|
||||
// package Slic3r::GUI::Tab::Page;
|
||||
ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_width /*= -1*/)
|
||||
ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/)
|
||||
{
|
||||
//! config_ have to be "right"
|
||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config, true);
|
||||
|
@ -2401,7 +2396,7 @@ ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_wid
|
|||
return optgroup;
|
||||
}
|
||||
|
||||
void SavePresetWindow::build(wxString title, std::string default_name, std::vector<std::string> &values)
|
||||
void SavePresetWindow::build(const wxString& title, const std::string& default_name, std::vector<std::string> &values)
|
||||
{
|
||||
auto text = new wxStaticText(this, wxID_ANY, _(L("Save ")) + title + _(L(" as:")),
|
||||
wxDefaultPosition, wxDefaultSize);
|
||||
|
|
|
@ -68,9 +68,9 @@ public:
|
|||
size_t iconID() const { return m_iconID; }
|
||||
void set_config(DynamicPrintConfig* config_in) { m_config = config_in; }
|
||||
void reload_config();
|
||||
Field* get_field(t_config_option_key opt_key, int opt_index = -1) const;
|
||||
bool set_value(t_config_option_key opt_key, boost::any value);
|
||||
ConfigOptionsGroupShp new_optgroup(wxString title, int noncommon_label_width = -1);
|
||||
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
|
||||
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
|
||||
ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1);
|
||||
};
|
||||
|
||||
// Slic3r::GUI::Tab;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
|
||||
public:
|
||||
Tab() {}
|
||||
Tab(wxNotebook* parent, wxString title, const char* name, bool no_controller) :
|
||||
Tab(wxNotebook* parent, const wxString& title, const char* name, bool no_controller) :
|
||||
m_parent(parent), m_title(title), m_name(name), m_no_controller(no_controller) {
|
||||
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
|
||||
get_tabs_list().push_back(this);
|
||||
|
@ -147,12 +147,12 @@ public:
|
|||
void create_preset_tab(PresetBundle *preset_bundle);
|
||||
void load_current_preset();
|
||||
void rebuild_page_tree();
|
||||
void select_preset(std::string preset_name = "");
|
||||
bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, std::string new_printer_name = "");
|
||||
void select_preset(const std::string& preset_name = "");
|
||||
bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = "");
|
||||
wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn);
|
||||
|
||||
void update_presetsctrl(wxDataViewTreeCtrl* ui, bool show_incompatible);
|
||||
void load_key_value(std::string opt_key, boost::any value);
|
||||
void load_key_value(const std::string& opt_key, const boost::any& value);
|
||||
void reload_compatible_printers_widget();
|
||||
|
||||
void OnTreeSelChange(wxTreeEvent& event);
|
||||
|
@ -172,7 +172,7 @@ public:
|
|||
void on_back_to_initial_value();
|
||||
void on_back_to_sys_value();
|
||||
|
||||
PageShp add_options_page(wxString title, std::string icon, bool is_extruder_pages = false);
|
||||
PageShp add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages = false);
|
||||
|
||||
virtual void OnActivate(){}
|
||||
virtual void on_preset_loaded(){}
|
||||
|
@ -181,10 +181,10 @@ public:
|
|||
void load_initial_data();
|
||||
void update_dirty();
|
||||
void update_tab_ui();
|
||||
void load_config(DynamicPrintConfig config);
|
||||
void load_config(const DynamicPrintConfig& config);
|
||||
virtual void reload_config();
|
||||
Field* get_field(t_config_option_key opt_key, int opt_index = -1) const;
|
||||
bool set_value(t_config_option_key opt_key, boost::any value);
|
||||
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
|
||||
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
|
||||
wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText);
|
||||
bool current_preset_is_dirty();
|
||||
DynamicPrintConfig* get_config() { return m_config; }
|
||||
|
@ -194,7 +194,7 @@ public:
|
|||
}
|
||||
std::vector<std::string> get_dependent_tabs() { return m_reload_dependent_tabs; }
|
||||
|
||||
void on_value_change(std::string opt_key, boost::any value);
|
||||
void on_value_change(const std::string& opt_key, const boost::any& value);
|
||||
|
||||
protected:
|
||||
void on_presets_changed();
|
||||
|
@ -270,7 +270,7 @@ public:
|
|||
std::string m_chosen_name;
|
||||
wxComboBox* m_combo;
|
||||
|
||||
void build(wxString title, std::string default_name, std::vector<std::string> &values);
|
||||
void build(const wxString& title, const std::string& default_name, std::vector<std::string> &values);
|
||||
void accept();
|
||||
std::string get_name() { return m_chosen_name; }
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue