Extended "get_value" to Choice & TextCtrl fields.
Extended "change_opt_value".
This commit is contained in:
parent
59432d50ff
commit
129bd898cd
5 changed files with 93 additions and 40 deletions
|
@ -31,6 +31,41 @@ namespace Slic3r { namespace GUI {
|
|||
return std::regex_match(string, regex_pattern);
|
||||
}
|
||||
|
||||
boost::any Field::get_value_by_opt_type(wxString str, ConfigOptionType type)
|
||||
{
|
||||
boost::any ret_val;
|
||||
switch (m_opt.type){
|
||||
case coInt:
|
||||
case coPercent:
|
||||
if (m_opt.type == coPercent) str.RemoveLast();
|
||||
ret_val = wxAtoi(str);
|
||||
break;
|
||||
case coPercents:
|
||||
case coFloats:
|
||||
case coFloat:{
|
||||
double val;
|
||||
str.ToCDouble(&val);
|
||||
ret_val = val;
|
||||
break; }
|
||||
case coString:
|
||||
case coStrings:
|
||||
ret_val = str.ToStdString();
|
||||
break;
|
||||
case coFloatOrPercent:{
|
||||
if (str.Last() == '%')
|
||||
str.RemoveLast();
|
||||
double val;
|
||||
str.ToCDouble(&val);
|
||||
ret_val = val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void TextCtrl::BUILD() {
|
||||
auto size = wxSize(wxDefaultSize);
|
||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
|
||||
|
@ -107,10 +142,17 @@ namespace Slic3r { namespace GUI {
|
|||
|
||||
// recast as a wxWindow to fit the calling convention
|
||||
window = dynamic_cast<wxWindow*>(temp);
|
||||
}
|
||||
|
||||
}
|
||||
boost::any TextCtrl::get_value()
|
||||
{
|
||||
wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue();
|
||||
boost::any ret_val = get_value_by_opt_type(ret_str, m_opt.type);
|
||||
|
||||
void TextCtrl::enable() { dynamic_cast<wxTextCtrl*>(window)->Enable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(true); }
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void TextCtrl::enable() { dynamic_cast<wxTextCtrl*>(window)->Enable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(true); }
|
||||
void TextCtrl::disable() { dynamic_cast<wxTextCtrl*>(window)->Disable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(false); }
|
||||
void TextCtrl::set_tooltip(const wxString& tip) { }
|
||||
|
||||
|
@ -260,21 +302,6 @@ void Choice::set_selection()
|
|||
dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
|
||||
break;
|
||||
}
|
||||
// case coString:{
|
||||
// text_value = static_cast<const ConfigOptionString*>(opt.default_value)->value;
|
||||
//
|
||||
// auto idx = 0;
|
||||
// for (auto el : opt.enum_values)
|
||||
// {
|
||||
// if (el.compare(text_value) == 0)
|
||||
// break;
|
||||
// ++idx;
|
||||
// }
|
||||
// idx == opt.enum_values.size() ?
|
||||
// dynamic_cast<wxComboBox*>(window)->SetValue(text_value) :
|
||||
// dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
|
||||
// break;
|
||||
// }
|
||||
case coStrings:{
|
||||
text_value = static_cast<const ConfigOptionStrings*>(m_opt.default_value)->values.at(0);
|
||||
|
||||
|
@ -361,6 +388,18 @@ void Choice::set_values(const std::vector<std::string> values)
|
|||
m_disable_change_event = false;
|
||||
}
|
||||
|
||||
boost::any Choice::get_value()
|
||||
{
|
||||
boost::any ret_val;
|
||||
wxString ret_str = static_cast<wxComboBox*>(window)->GetValue();
|
||||
|
||||
ret_val = m_opt.type == coEnum ?
|
||||
static_cast<wxComboBox*>(window)->GetSelection() :
|
||||
get_value_by_opt_type(ret_str, m_opt.type);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void ColourPicker::BUILD()
|
||||
{
|
||||
auto size = wxSize(wxDefaultSize);
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
virtual wxWindow* getWindow() { return nullptr; }
|
||||
|
||||
bool is_matched(std::string string, std::string pattern);
|
||||
boost::any get_value_by_opt_type(wxString str, ConfigOptionType type);
|
||||
|
||||
/// Factory method for generating new derived classes.
|
||||
template<class T>
|
||||
|
@ -110,19 +111,19 @@ public:
|
|||
void BUILD();
|
||||
wxWindow* window {nullptr};
|
||||
|
||||
virtual void set_value(std::string value) {
|
||||
virtual void set_value(std::string value) {
|
||||
dynamic_cast<wxTextCtrl*>(window)->SetValue(wxString(value));
|
||||
}
|
||||
virtual void set_value(boost::any value) {
|
||||
virtual void set_value(boost::any value) {
|
||||
dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(value));
|
||||
}
|
||||
|
||||
boost::any get_value() override { return boost::any(dynamic_cast<wxTextCtrl*>(window)->GetValue()); }
|
||||
boost::any get_value() override;
|
||||
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
virtual wxWindow* getWindow() { return window; }
|
||||
void set_tooltip(const wxString& tip);
|
||||
void set_tooltip(const wxString& tip);
|
||||
|
||||
};
|
||||
|
||||
|
@ -191,9 +192,7 @@ public:
|
|||
void set_value(const std::string value);
|
||||
void set_value(boost::any value);
|
||||
void set_values(const std::vector<std::string> values);
|
||||
boost::any get_value() override {
|
||||
return boost::any(dynamic_cast<wxComboBox*>(window)->GetValue());
|
||||
}
|
||||
boost::any get_value() override;
|
||||
|
||||
void enable() override { dynamic_cast<wxComboBox*>(window)->Enable(); };
|
||||
void disable() override{ dynamic_cast<wxComboBox*>(window)->Disable(); };
|
||||
|
@ -210,14 +209,13 @@ public:
|
|||
wxWindow* window{ nullptr };
|
||||
void BUILD() override;
|
||||
|
||||
// void set_selection();
|
||||
void set_value(const std::string value) {
|
||||
dynamic_cast<wxColourPickerCtrl*>(window)->SetColour(value);
|
||||
}
|
||||
void set_value(boost::any value) {
|
||||
dynamic_cast<wxColourPickerCtrl*>(window)->SetColour(boost::any_cast<std::string>(value));
|
||||
}
|
||||
// void set_values(const std::vector<std::string> values);
|
||||
|
||||
boost::any get_value() override {
|
||||
return boost::any(dynamic_cast<wxColourPickerCtrl*>(window)->GetColour());
|
||||
}
|
||||
|
|
|
@ -196,27 +196,36 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||
{
|
||||
try{
|
||||
switch (config.def()->get(opt_key)->type){
|
||||
case coFloatOrPercent:
|
||||
case coFloatOrPercent:{
|
||||
const auto &val = *config.option<ConfigOptionFloatOrPercent>(opt_key);
|
||||
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(boost::any_cast</*ConfigOptionFloatOrPercent*/double>(value), val.percent));
|
||||
break;}
|
||||
case coPercent:
|
||||
case coFloat:
|
||||
{
|
||||
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast</*ConfigOptionPercent*/double>(value)));
|
||||
break;
|
||||
case coFloat:{
|
||||
double& val = config.opt_float(opt_key);
|
||||
val = boost::any_cast<double>(value);
|
||||
break;
|
||||
}
|
||||
// case coPercents:
|
||||
// case coFloats:
|
||||
case coPercents:
|
||||
case coFloats:{
|
||||
double& val = config.opt_float(opt_key, 0);
|
||||
val = boost::any_cast<double>(value);
|
||||
break;
|
||||
}
|
||||
case coString:
|
||||
// opt = new ConfigOptionString(config.opt_string(opt_key));
|
||||
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
||||
break;
|
||||
case coStrings:
|
||||
break;
|
||||
case coBool:
|
||||
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
||||
break;
|
||||
case coBools:
|
||||
// opt = new ConfigOptionBools(0, config.opt_bool(opt_key)); //! 0?
|
||||
break;
|
||||
case coBools:{
|
||||
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<bool>(value) };
|
||||
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, 0, 0);
|
||||
break;}
|
||||
case coInt:
|
||||
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
|
||||
break;
|
||||
|
@ -234,7 +243,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
||||
int i = 0;//no reason, just experiment
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
|
|
@ -231,7 +231,9 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val
|
|||
}
|
||||
else {
|
||||
if (opt_index == -1) {
|
||||
change_opt_value(*m_config, opt_key, field_value);
|
||||
// change_opt_value(*m_config, opt_key, field_value);
|
||||
//!? why field_value?? in this case changed value will be lose! No?
|
||||
change_opt_value(*m_config, opt_key, value);
|
||||
}
|
||||
else {
|
||||
// auto value = m_config->get($opt_key);
|
||||
|
|
|
@ -150,7 +150,11 @@ void Tab::load_config(DynamicPrintConfig config)
|
|||
for(auto opt_key : m_config.diff(config)) {
|
||||
switch ( config.def()->get(opt_key)->type ){
|
||||
case coFloatOrPercent:
|
||||
change_opt_value(m_config, opt_key, config.option<ConfigOptionFloatOrPercent>(opt_key)->value);
|
||||
break;
|
||||
case coPercent:
|
||||
change_opt_value(m_config, opt_key, config.option<ConfigOptionPercent>(opt_key)->value);
|
||||
break;
|
||||
case coFloat:
|
||||
change_opt_value(m_config, opt_key, config.opt_float(opt_key));
|
||||
break;
|
||||
|
@ -422,7 +426,8 @@ void TabPrint::update()
|
|||
Freeze();
|
||||
|
||||
if ( m_config.opt_bool("spiral_vase") &&
|
||||
!(m_config.opt_int("perimeters") == 1 && m_config.opt_int("top_solid_layers") == 0 && m_config.opt_float("fill_density") == 0)) {
|
||||
!(m_config.opt_int("perimeters") == 1 && m_config.opt_int("top_solid_layers") == 0 && /*m_config.opt_float("fill_density") == 0*/
|
||||
m_config.option<ConfigOptionPercent>("fill_density")->value == 0)) {
|
||||
std::string msg_text = "The Spiral Vase mode requires:\n"
|
||||
"- one perimeter\n"
|
||||
"- no top solid layers\n"
|
||||
|
|
Loading…
Reference in a new issue