"on_change" function call correctly work now. Start adding of Tab::update().

It's need to think about config->set_key_value(...): at cpp side it's non-trivial.
This commit is contained in:
YuSanka 2018-01-05 15:11:33 +01:00
parent f8a48f5c13
commit e62c17bddf
9 changed files with 617 additions and 262 deletions

View file

@ -15,13 +15,13 @@ namespace Slic3r { namespace GUI {
event.Skip(1);
// call the registered function if it is available
//! if (on_kill_focus)
//! on_kill_focus(opt_id);
if (on_kill_focus)
on_kill_focus(m_opt_id);
}
void Field::_on_change(wxCommandEvent& event) {
std::cerr << "calling Field::_on_change \n";
//! if (on_change != nullptr && !disable_change_event)
//! on_change(opt_id, "A");
void Field::on_change_field(wxCommandEvent& event) {
// std::cerr << "calling Field::_on_change \n";
if (m_on_change != nullptr && !m_disable_change_event)
m_on_change(m_opt_id, get_value());
}
@ -33,32 +33,32 @@ namespace Slic3r { namespace GUI {
void TextCtrl::BUILD() {
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
wxString text_value = wxString("");
switch (opt.type) {
switch (m_opt.type) {
case coFloatOrPercent:
{
if (static_cast<const ConfigOptionFloatOrPercent*>(opt.default_value)->percent)
if (static_cast<const ConfigOptionFloatOrPercent*>(m_opt.default_value)->percent)
{
text_value = wxString::Format(_T("%i"), int(opt.default_value->getFloat()));
text_value = wxString::Format(_T("%i"), int(m_opt.default_value->getFloat()));
text_value += "%";
}
else
wxNumberFormatter::ToString(opt.default_value->getFloat(), 2);
wxNumberFormatter::ToString(m_opt.default_value->getFloat(), 2);
break;
}
case coPercent:
{
text_value = wxString::Format(_T("%i"), int(opt.default_value->getFloat()));
text_value = wxString::Format(_T("%i"), int(m_opt.default_value->getFloat()));
text_value += "%";
break;
}
case coPercents:
{
const ConfigOptionPercents *vec = static_cast<const ConfigOptionPercents*>(opt.default_value);
const ConfigOptionPercents *vec = static_cast<const ConfigOptionPercents*>(m_opt.default_value);
if (vec == nullptr || vec->empty()) break;
if (vec->size() > 1)
break;
@ -68,13 +68,13 @@ namespace Slic3r { namespace GUI {
}
case coFloat:
{
double val = opt.default_value->getFloat();
double val = m_opt.default_value->getFloat();
text_value = (val - int(val)) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2);
break;
}
case coFloats:
{
const ConfigOptionFloats *vec = static_cast<const ConfigOptionFloats*>(opt.default_value);
const ConfigOptionFloats *vec = static_cast<const ConfigOptionFloats*>(m_opt.default_value);
if (vec == nullptr || vec->empty()) break;
if (vec->size() > 1)
break;
@ -83,11 +83,11 @@ namespace Slic3r { namespace GUI {
break;
}
case coString:
text_value = static_cast<const ConfigOptionString*>(opt.default_value)->value;
text_value = static_cast<const ConfigOptionString*>(m_opt.default_value)->value;
break;
case coStrings:
{
const ConfigOptionStrings *vec = static_cast<const ConfigOptionStrings*>(opt.default_value);
const ConfigOptionStrings *vec = static_cast<const ConfigOptionStrings*>(m_opt.default_value);
if (vec == nullptr || vec->empty()) break;
if (vec->size() > 1)
break;
@ -98,11 +98,11 @@ namespace Slic3r { namespace GUI {
break;
}
auto temp = new wxTextCtrl(parent, wxID_ANY, text_value, wxDefaultPosition, size, (opt.multiline ? wxTE_MULTILINE : 0));
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0));
if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); }
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { _on_change(e); }), temp->GetId());
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());
// recast as a wxWindow to fit the calling convention
@ -116,21 +116,21 @@ namespace Slic3r { namespace GUI {
void CheckBox::BUILD() {
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
bool check_value = opt.type == coBool ?
opt.default_value->getBool() : opt.type == coBools ?
static_cast<ConfigOptionBools*>(opt.default_value)->values.at(0) :
bool check_value = m_opt.type == coBool ?
m_opt.default_value->getBool() : m_opt.type == coBools ?
static_cast<ConfigOptionBools*>(m_opt.default_value)->values.at(0) :
false;
auto temp = new wxCheckBox(parent, wxID_ANY, wxString(""), wxDefaultPosition, size);
auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size);
temp->SetValue(check_value);
if (opt.readonly) temp->Disable();
if (m_opt.readonly) temp->Disable();
temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { _on_change(e); }), temp->GetId());
temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); }
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
// recast as a wxWindow to fit the calling convention
window = dynamic_cast<wxWindow*>(temp);
@ -140,20 +140,20 @@ int undef_spin_val = -9999; //! Probably, It's not necessary
void SpinCtrl::BUILD() {
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
wxString text_value = wxString("");
int default_value = 0;
switch (opt.type) {
switch (m_opt.type) {
case coInt:
default_value = opt.default_value->getInt();
default_value = m_opt.default_value->getInt();
text_value = wxString::Format(_T("%i"), default_value);
break;
case coInts:
{
const ConfigOptionInts *vec = static_cast<const ConfigOptionInts*>(opt.default_value);
const ConfigOptionInts *vec = static_cast<const ConfigOptionInts*>(m_opt.default_value);
if (vec == nullptr || vec->empty()) break;
for (size_t id = 0; id < vec->size(); ++id)
{
@ -166,10 +166,10 @@ void SpinCtrl::BUILD() {
break;
}
auto temp = new wxSpinCtrl(parent, wxID_ANY, text_value, wxDefaultPosition, size,
0, opt.min >0 ? opt.min : 0, opt.max < 2147483647 ? opt.max : 2147483647, default_value);
auto temp = new wxSpinCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size,
0, m_opt.min >0 ? m_opt.min : 0, m_opt.max < 2147483647 ? m_opt.max : 2147483647, default_value);
temp->Bind(wxEVT_SPINCTRL, ([=](wxCommandEvent e) { tmp_value = undef_spin_val; _on_change(e); }), temp->GetId());
temp->Bind(wxEVT_SPINCTRL, ([=](wxCommandEvent e) { tmp_value = undef_spin_val; on_change_field(e); }), temp->GetId());
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxFocusEvent e) { tmp_value = undef_spin_val; _on_kill_focus(e); }), temp->GetId());
temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e)
{
@ -181,14 +181,14 @@ void SpinCtrl::BUILD() {
std::string value = e.GetString();
if (is_matched(value, "^\d+$"))
tmp_value = std::stoi(value);
_on_change(e);
on_change_field(e);
// # We don't reset tmp_value here because _on_change might put callbacks
// # in the CallAfter queue, and we want the tmp value to be available from
// # them as well.
}), temp->GetId());
if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); }
if (m_opt.tooltip.length() > 0) { temp->SetToolTip(m_opt.tooltip); }
// recast as a wxWindow to fit the calling convention
window = dynamic_cast<wxWindow*>(temp);
@ -196,66 +196,66 @@ void SpinCtrl::BUILD() {
void Choice::BUILD() {
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
auto temp = new wxComboBox(parent, wxID_ANY, wxString(""), wxDefaultPosition, size);
if (opt.gui_type.compare("select_open") != 0)
auto temp = new wxComboBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size);
if (m_opt.gui_type.compare("select_open") != 0)
temp->SetExtraStyle(wxCB_READONLY);
// recast as a wxWindow to fit the calling convention
window = dynamic_cast<wxWindow*>(temp);
if (opt.enum_labels.empty() && opt.enum_values.empty()){
if (m_opt.enum_labels.empty() && m_opt.enum_values.empty()){
}
else{
for (auto el : opt.enum_labels.empty() ? opt.enum_values : opt.enum_labels)
for (auto el : m_opt.enum_labels.empty() ? m_opt.enum_values : m_opt.enum_labels)
temp->Append(wxString(el));
set_selection();
}
temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { _on_change(e); }), temp->GetId());
temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { _on_change(e); }), temp->GetId());
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 (opt.tooltip.length() > 0) temp->SetToolTip(opt.tooltip);
if (m_opt.tooltip.length() > 0) temp->SetToolTip(m_opt.tooltip);
}
void Choice::set_selection()
{
wxString text_value = wxString("");
switch (opt.type){
switch (m_opt.type){
case coFloat:
case coPercent: {
double val = opt.default_value->getFloat();
double val = m_opt.default_value->getFloat();
text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 1);
auto idx = 0;
for (auto el : opt.enum_values)
for (auto el : m_opt.enum_values)
{
if (el.compare(text_value) == 0)
break;
++idx;
}
if (opt.type == coPercent) text_value += "%";
idx == opt.enum_values.size() ?
if (m_opt.type == coPercent) text_value += "%";
idx == m_opt.enum_values.size() ?
dynamic_cast<wxComboBox*>(window)->SetValue(text_value) :
dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
break;
}
case coEnum:{
int id_value = static_cast<const ConfigOptionEnum<SeamPosition>*>(opt.default_value)->value; //!!
int id_value = static_cast<const ConfigOptionEnum<SeamPosition>*>(m_opt.default_value)->value; //!!
dynamic_cast<wxComboBox*>(window)->SetSelection(id_value);
break;
}
case coInt:{
int val = opt.default_value->getInt(); //!!
int val = m_opt.default_value->getInt(); //!!
text_value = wxString::Format(_T("%i"), int(val));
auto idx = 0;
for (auto el : opt.enum_values)
for (auto el : m_opt.enum_values)
{
if (el.compare(text_value) == 0)
break;
++idx;
}
idx == opt.enum_values.size() ?
idx == m_opt.enum_values.size() ?
dynamic_cast<wxComboBox*>(window)->SetValue(text_value) :
dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
break;
@ -276,16 +276,16 @@ void Choice::set_selection()
// break;
// }
case coStrings:{
text_value = static_cast<const ConfigOptionStrings*>(opt.default_value)->values.at(0);
text_value = static_cast<const ConfigOptionStrings*>(m_opt.default_value)->values.at(0);
auto idx = 0;
for (auto el : opt.enum_values)
for (auto el : m_opt.enum_values)
{
if (el.compare(text_value) == 0)
break;
++idx;
}
idx == opt.enum_values.size() ?
idx == m_opt.enum_values.size() ?
dynamic_cast<wxComboBox*>(window)->SetValue(text_value) :
dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
break;
@ -295,27 +295,29 @@ void Choice::set_selection()
void Choice::set_value(const std::string value) //! Redundant?
{
disable_change_event = true;
m_disable_change_event = true;
auto idx=0;
for (auto el : opt.enum_values)
for (auto el : m_opt.enum_values)
{
if (el.compare(value) == 0)
break;
++idx;
}
idx == opt.enum_values.size() ?
idx == m_opt.enum_values.size() ?
dynamic_cast<wxComboBox*>(window)->SetValue(value) :
dynamic_cast<wxComboBox*>(window)->SetSelection(idx);
disable_change_event = false;
m_disable_change_event = false;
}
//! it's needed for _update_serial_ports()
void Choice::set_values(const std::vector<std::string> values)
{
disable_change_event = true;
if (values.empty())
return;
m_disable_change_event = true;
// # it looks that Clear() also clears the text field in recent wxWidgets versions,
// # but we want to preserve it
@ -326,75 +328,75 @@ void Choice::set_values(const std::vector<std::string> values)
ww->Append(wxString(el));
ww->SetValue(value);
disable_change_event = false;
m_disable_change_event = false;
}
void ColourPicker::BUILD()
{
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
wxString clr(static_cast<ConfigOptionStrings*>(opt.default_value)->values.at(0));
auto temp = new wxColourPickerCtrl(parent, wxID_ANY, clr, wxDefaultPosition, size);
wxString clr(static_cast<ConfigOptionStrings*>(m_opt.default_value)->values.at(0));
auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size);
// // recast as a wxWindow to fit the calling convention
window = dynamic_cast<wxWindow*>(temp);
temp->Bind(wxEVT_COLOURPICKER_CHANGED, ([=](wxCommandEvent e) { _on_change(e); }), temp->GetId());
temp->Bind(wxEVT_COLOURPICKER_CHANGED, ([=](wxCommandEvent e) { on_change_field(e); }), temp->GetId());
if (opt.tooltip.length() > 0) temp->SetToolTip(opt.tooltip);
if (m_opt.tooltip.length() > 0) temp->SetToolTip(m_opt.tooltip);
}
void Point::BUILD()
{
auto size = wxSize(wxDefaultSize);
if (opt.height >= 0) size.SetHeight(opt.height);
if (opt.width >= 0) size.SetWidth(opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
auto temp = new wxBoxSizer(wxHORIZONTAL);
// $self->wxSizer($sizer);
//
wxSize field_size(40, -1);
auto default_pt = static_cast<ConfigOptionPoints*>(opt.default_value)->values.at(0);
auto default_pt = static_cast<ConfigOptionPoints*>(m_opt.default_value)->values.at(0);
double val = default_pt.x;
wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2);
val = default_pt.y;
wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2);
x_textctrl = new wxTextCtrl(parent, wxID_ANY, X, wxDefaultPosition, field_size);
y_textctrl = new wxTextCtrl(parent, wxID_ANY, Y, wxDefaultPosition, field_size);
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(parent, wxID_ANY, "x:")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
temp->Add(new wxStaticText(m_parent, wxID_ANY, "x:")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
temp->Add(x_textctrl);
temp->Add(new wxStaticText(parent, wxID_ANY, "y:")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
temp->Add(new wxStaticText(m_parent, wxID_ANY, "y:")/*, 0, wxALIGN_CENTER_VERTICAL, 0*/);
temp->Add(y_textctrl);
x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { _on_change(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { _on_change(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
// // recast as a wxWindow to fit the calling convention
sizer = dynamic_cast<wxSizer*>(temp);
if (opt.tooltip.length() > 0)
if (m_opt.tooltip.length() > 0)
{
x_textctrl->SetToolTip(opt.tooltip);
y_textctrl->SetToolTip(opt.tooltip);
x_textctrl->SetToolTip(m_opt.tooltip);
y_textctrl->SetToolTip(m_opt.tooltip);
}
}
void Point::set_value(const Pointf value)
{
disable_change_event = true;
m_disable_change_event = true;
double val = value.x;
x_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2));
val = value.y;
y_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2));
disable_change_event = false;
m_disable_change_event = false;
}
boost::any Point::get_value()