Eliminated the g-code pop up text description.
Fixed correct writing of TextCtrl values.
This commit is contained in:
parent
6ef5e6bd3d
commit
8c7a56d4ea
@ -5,6 +5,7 @@
|
||||
#include <regex>
|
||||
#include <wx/numformatter.h>
|
||||
#include "PrintConfig.hpp"
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
@ -24,6 +25,13 @@ namespace Slic3r { namespace GUI {
|
||||
m_on_change(m_opt_id, get_value());
|
||||
}
|
||||
|
||||
wxString Field::get_tooltip_text(const wxString& default_string)
|
||||
{
|
||||
wxString tooltip_text("");
|
||||
if (m_opt.tooltip.length() > 0)
|
||||
tooltip_text = m_opt.tooltip + "(default: " + default_string + ")";
|
||||
return tooltip_text;
|
||||
}
|
||||
|
||||
bool Field::is_matched(std::string string, std::string pattern)
|
||||
{
|
||||
@ -135,7 +143,7 @@ namespace Slic3r { namespace GUI {
|
||||
|
||||
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0));
|
||||
|
||||
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
|
||||
temp->SetToolTip(get_tooltip_text(text_value));
|
||||
|
||||
temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
|
||||
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxFocusEvent e) { _on_kill_focus(e); }), temp->GetId());
|
||||
@ -154,7 +162,15 @@ namespace Slic3r { namespace GUI {
|
||||
|
||||
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) { }
|
||||
wxString TextCtrl::get_tooltip_text(const wxString& default_string)
|
||||
{
|
||||
wxString tooltip_text("");
|
||||
if (m_opt.tooltip.length() > 0)
|
||||
tooltip_text = boost::iends_with(m_opt_id, "_gcode") ?
|
||||
m_opt.tooltip : // eliminating the g-code pop up text description
|
||||
m_opt.tooltip + "(default: " + default_string + ")";
|
||||
return tooltip_text;
|
||||
}
|
||||
|
||||
void CheckBox::BUILD() {
|
||||
auto size = wxSize(wxDefaultSize);
|
||||
@ -172,7 +188,7 @@ void CheckBox::BUILD() {
|
||||
|
||||
temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
|
||||
|
||||
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
|
||||
temp->SetToolTip(get_tooltip_text(check_value ? "true" : "false"));
|
||||
|
||||
// recast as a wxWindow to fit the calling convention
|
||||
window = dynamic_cast<wxWindow*>(temp);
|
||||
@ -228,9 +244,8 @@ void SpinCtrl::BUILD() {
|
||||
// # in the CallAfter queue, and we want the tmp value to be available from
|
||||
// # them as well.
|
||||
}), temp->GetId());
|
||||
|
||||
|
||||
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
|
||||
|
||||
temp->SetToolTip(get_tooltip_text(text_value));
|
||||
|
||||
// recast as a wxWindow to fit the calling convention
|
||||
window = dynamic_cast<wxWindow*>(temp);
|
||||
@ -260,7 +275,7 @@ void Choice::BUILD() {
|
||||
temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
|
||||
temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
|
||||
|
||||
if (m_opt.tooltip.length() > 0) temp->SetToolTip(m_opt.tooltip);
|
||||
temp->SetToolTip(get_tooltip_text(temp->GetValue()));
|
||||
}
|
||||
|
||||
void Choice::set_selection()
|
||||
@ -443,8 +458,7 @@ void ColourPicker::BUILD()
|
||||
|
||||
temp->Bind(wxEVT_COLOURPICKER_CHANGED, ([=](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
|
||||
|
||||
if (m_opt.tooltip.length() > 0) temp->SetToolTip(m_opt.tooltip);
|
||||
|
||||
temp->SetToolTip(get_tooltip_text(clr));
|
||||
}
|
||||
|
||||
void PointCtrl::BUILD()
|
||||
@ -467,9 +481,9 @@ void PointCtrl::BUILD()
|
||||
x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size);
|
||||
y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size);
|
||||
|
||||
temp->Add(new wxStaticText(m_parent, wxID_ANY, "x : ")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
|
||||
temp->Add(new wxStaticText(m_parent, wxID_ANY, "x : "));
|
||||
temp->Add(x_textctrl);
|
||||
temp->Add(new wxStaticText(m_parent, wxID_ANY, " y : ")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
|
||||
temp->Add(new wxStaticText(m_parent, wxID_ANY, " y : "));
|
||||
temp->Add(y_textctrl);
|
||||
|
||||
x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
|
||||
@ -478,11 +492,8 @@ void PointCtrl::BUILD()
|
||||
// // recast as a wxWindow to fit the calling convention
|
||||
sizer = dynamic_cast<wxSizer*>(temp);
|
||||
|
||||
if (m_opt.tooltip.length() > 0)
|
||||
{
|
||||
x_textctrl->SetToolTip(m_opt.tooltip);
|
||||
y_textctrl->SetToolTip(m_opt.tooltip);
|
||||
}
|
||||
x_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
||||
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
||||
}
|
||||
|
||||
void PointCtrl::set_value(const Pointf value)
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
/// Fires the enable or disable function, based on the input.
|
||||
inline void toggle(bool en) { en ? enable() : disable(); }
|
||||
|
||||
virtual void set_tooltip(const wxString& tip) = 0;
|
||||
virtual wxString get_tooltip_text(const wxString& default_string);
|
||||
|
||||
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) {};
|
||||
@ -123,7 +123,7 @@ public:
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
virtual wxWindow* getWindow() { return window; }
|
||||
void set_tooltip(const wxString& tip);
|
||||
wxString get_tooltip_text(const wxString& default_string) override;
|
||||
|
||||
};
|
||||
|
||||
@ -148,7 +148,6 @@ public:
|
||||
|
||||
void enable() override { dynamic_cast<wxCheckBox*>(window)->Enable(); }
|
||||
void disable() override { dynamic_cast<wxCheckBox*>(window)->Disable(); }
|
||||
void set_tooltip(const wxString& tip) override {};
|
||||
wxWindow* getWindow() override { return window; }
|
||||
};
|
||||
|
||||
@ -176,7 +175,6 @@ public:
|
||||
void enable() override { dynamic_cast<wxSpinCtrl*>(window)->Enable(); }
|
||||
void disable() override { dynamic_cast<wxSpinCtrl*>(window)->Disable(); }
|
||||
wxWindow* getWindow() override { return window; }
|
||||
void set_tooltip(const wxString& tip) override{};
|
||||
};
|
||||
|
||||
class Choice : public Field {
|
||||
@ -197,7 +195,6 @@ public:
|
||||
void enable() override { dynamic_cast<wxComboBox*>(window)->Enable(); };
|
||||
void disable() override{ dynamic_cast<wxComboBox*>(window)->Disable(); };
|
||||
wxWindow* getWindow() override { return window; }
|
||||
void set_tooltip(const wxString& tip) override {}; //! Redundant
|
||||
};
|
||||
|
||||
class ColourPicker : public Field {
|
||||
@ -223,7 +220,6 @@ public:
|
||||
void enable() override { dynamic_cast<wxColourPickerCtrl*>(window)->Enable(); };
|
||||
void disable() override{ dynamic_cast<wxColourPickerCtrl*>(window)->Disable(); };
|
||||
wxWindow* getWindow() override { return window; }
|
||||
void set_tooltip(const wxString& tip) override {}; //! Redundant
|
||||
};
|
||||
|
||||
class PointCtrl : public Field {
|
||||
@ -249,7 +245,6 @@ public:
|
||||
x_textctrl->Disable();
|
||||
y_textctrl->Disable(); };
|
||||
wxSizer* getSizer() override { return sizer; }
|
||||
void set_tooltip(const wxString& tip) override {}; //! Redundant
|
||||
};
|
||||
|
||||
|
||||
|
@ -283,6 +283,15 @@ boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index,
|
||||
}
|
||||
}
|
||||
|
||||
wxString double_to_string(double const value)
|
||||
{
|
||||
return value - int(value) == 0 ?
|
||||
wxString::Format(_T("%i"), int(value)) :
|
||||
10 * value - int(10 * value) == 0 ?
|
||||
wxNumberFormatter::ToString(value, 1) :
|
||||
wxNumberFormatter::ToString(value, 2);
|
||||
}
|
||||
|
||||
boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std::string opt_key, int opt_index/* = -1*/)
|
||||
{
|
||||
size_t idx = opt_index == -1 ? 0 : opt_index;
|
||||
@ -299,7 +308,7 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std:
|
||||
text_value += "%";
|
||||
}
|
||||
else
|
||||
text_value = wxNumberFormatter::ToString(value.value, 2);
|
||||
text_value = double_to_string(value.value);
|
||||
ret = text_value;
|
||||
break;
|
||||
}
|
||||
@ -310,18 +319,15 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std:
|
||||
}
|
||||
break;
|
||||
case coPercents:
|
||||
case coFloats:{
|
||||
case coFloats:
|
||||
case coFloat:{
|
||||
double val = opt->type == coFloats ?
|
||||
config.opt_float(opt_key, idx/*0opt_index*/) :
|
||||
config.option<ConfigOptionPercents>(opt_key)->values.at(idx/*0*/);
|
||||
ret = val - int(val) == 0 ?
|
||||
wxString::Format(_T("%i"), int(val)) :
|
||||
wxNumberFormatter::ToString(val, 2);
|
||||
opt->type == coFloat ? config.opt_float(opt_key) :
|
||||
config.option<ConfigOptionPercents>(opt_key)->values.at(idx/*0*/);
|
||||
ret = double_to_string(val);
|
||||
}
|
||||
break;
|
||||
case coFloat:
|
||||
ret = wxNumberFormatter::ToString(config.opt_float(opt_key), 2);
|
||||
break;
|
||||
case coString:
|
||||
ret = static_cast<wxString>(config.opt_string(opt_key));
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user