SpinCtrsl inside Manipulation pane is replaced to TextCtrls

+ Added "proces_enter" mode for TextCtrl (The control will generate the event wxEVT_TEXT_ENTER)
This commit is contained in:
YuSanka 2018-11-14 12:33:48 +01:00
parent 86c1f5b417
commit 62aa34b444
7 changed files with 87 additions and 80 deletions

View File

@ -11,22 +11,21 @@
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
wxString double_to_string(double const value) wxString double_to_string(double const value, const int max_precision /*= 4*/)
{ {
if (value - int(value) == 0) if (value - int(value) == 0)
return wxString::Format(_T("%i"), int(value)); return wxString::Format(_T("%i"), int(value));
else {
int precision = 4; int precision = max_precision;
for (size_t p = 1; p < 4; p++) for (size_t p = 1; p < max_precision; p++)
{ {
double cur_val = pow(10, p)*value; double cur_val = pow(10, p)*value;
if (cur_val - int(cur_val) == 0) { if (cur_val - int(cur_val) == 0) {
precision = p; precision = p;
break; break;
}
} }
return wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None);
} }
return wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None);
} }
void Field::PostInitialize() void Field::PostInitialize()
@ -209,7 +208,8 @@ void TextCtrl::BUILD() {
break; break;
} }
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0)); const long style = m_opt.multiline ? wxTE_MULTILINE : 0 | m_process_enter ? wxTE_PROCESS_ENTER : 0;
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style);
temp->SetToolTip(get_tooltip_text(text_value)); temp->SetToolTip(get_tooltip_text(text_value));
@ -234,21 +234,26 @@ void TextCtrl::BUILD() {
}), temp->GetId()); }), temp->GetId());
#endif // __WXGTK__ #endif // __WXGTK__
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) if (m_process_enter) {
{ temp->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent& evt) { on_change_field(); }), temp->GetId());
}
else {
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt)
{
#ifdef __WXGTK__ #ifdef __WXGTK__
if (bChangedValueEvent) if (bChangedValueEvent)
#endif //__WXGTK__ #endif //__WXGTK__
on_change_field(); on_change_field();
}), temp->GetId()); }), temp->GetId());
#ifdef __WXGTK__ #ifdef __WXGTK__
// to correct value updating on GTK we should: // to correct value updating on GTK we should:
// call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT
// and prevent value updating on wxEVT_KEY_DOWN // and prevent value updating on wxEVT_KEY_DOWN
temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this);
temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this);
#endif //__WXGTK__ #endif //__WXGTK__
}
// select all text using Ctrl+A // select all text using Ctrl+A
temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event) temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event)

View File

@ -34,7 +34,7 @@ using t_kill_focus = std::function<void()>;
using t_change = std::function<void(t_config_option_key, const boost::any&)>; using t_change = std::function<void(t_config_option_key, const boost::any&)>;
using t_back_to_init = std::function<void(const std::string&)>; using t_back_to_init = std::function<void(const std::string&)>;
wxString double_to_string(double const value); wxString double_to_string(double const value, const int max_precision = 4);
class MyButton : public wxButton class MyButton : public wxButton
{ {
@ -139,9 +139,10 @@ public:
/// Factory method for generating new derived classes. /// Factory method for generating new derived classes.
template<class T> template<class T>
static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) // interface for creating shared objects static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id, const bool process_enter = false)// interface for creating shared objects
{ {
auto p = Slic3r::make_unique<T>(parent, opt, id); auto p = Slic3r::make_unique<T>(parent, opt, id);
p->m_process_enter = process_enter;
p->PostInitialize(); p->PostInitialize();
return std::move(p); //!p; return std::move(p); //!p;
} }
@ -221,6 +222,9 @@ protected:
// current value // current value
boost::any m_value; boost::any m_value;
//this variable shows a mode of a call of the on_change function
bool m_process_enter { false };
friend class OptionsGroup; friend class OptionsGroup;
}; };

View File

@ -1464,7 +1464,9 @@ void GLCanvas3D::Selection::translate(const Vec3d& displacement)
} }
#if !DISABLE_INSTANCES_SYNCH #if !DISABLE_INSTANCES_SYNCH
if (m_mode == Volume) if (m_mode == Instance)
_synchronize_unselected_instances();
else if (m_mode == Volume)
_synchronize_unselected_volumes(); _synchronize_unselected_volumes();
#endif // !DISABLE_INSTANCES_SYNCH #endif // !DISABLE_INSTANCES_SYNCH

View File

@ -20,7 +20,8 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
m_og->set_name(_(L("Object Manipulation"))); m_og->set_name(_(L("Object Manipulation")));
m_og->label_width = 100; m_og->label_width = 100;
m_og->set_grid_vgap(5); m_og->set_grid_vgap(5);
m_og->set_process_enter(); // We need to update new values only after press ENTER
m_og->m_on_change = [this](t_config_option_key opt_key, boost::any value) { m_og->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
if (opt_key == "scale_unit") { if (opt_key == "scale_unit") {
const wxString& selection = boost::any_cast<wxString>(value); const wxString& selection = boost::any_cast<wxString>(value);
@ -32,6 +33,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
m_is_percent_scale = selection == _("%"); m_is_percent_scale = selection == _("%");
update_scale_values(); update_scale_values();
return;
} }
}; };
@ -64,7 +66,6 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
auto add_og_to_object_settings = [](const std::string& option_name, const std::string& sidetext) auto add_og_to_object_settings = [](const std::string& option_name, const std::string& sidetext)
{ {
int def_value = 0;
Line line = { _(option_name), "" }; Line line = { _(option_name), "" };
if (option_name == "Scale") { if (option_name == "Scale") {
line.near_label_widget = [](wxWindow* parent) { line.near_label_widget = [](wxWindow* parent) {
@ -80,14 +81,12 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
} }
ConfigOptionDef def; ConfigOptionDef def;
def.type = coInt; def.type = coFloat;
def.default_value = new ConfigOptionInt(def_value); def.default_value = new ConfigOptionFloat(0.0);
def.width = 55; def.width = 55;
if (option_name == "Rotation") if (option_name == "Rotation")
def.min = -360; def.min = -360;
else
def.min = -1000;
const std::string lower_name = boost::algorithm::to_lower_copy(option_name); const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
@ -243,40 +242,40 @@ void ObjectManipulation::reset_settings_value()
void ObjectManipulation::reset_position_value() void ObjectManipulation::reset_position_value()
{ {
m_og->set_value("position_x", 0); m_og->set_value("position_x", "0");
m_og->set_value("position_y", 0); m_og->set_value("position_y", "0");
m_og->set_value("position_z", 0); m_og->set_value("position_z", "0");
} }
void ObjectManipulation::reset_rotation_value() void ObjectManipulation::reset_rotation_value()
{ {
m_og->set_value("rotation_x", 0); m_og->set_value("rotation_x", "0");
m_og->set_value("rotation_y", 0); m_og->set_value("rotation_y", "0");
m_og->set_value("rotation_z", 0); m_og->set_value("rotation_z", "0");
} }
void ObjectManipulation::reset_scale_value() void ObjectManipulation::reset_scale_value()
{ {
m_is_percent_scale = true; m_is_percent_scale = true;
m_og->set_value("scale_unit", _("%")); m_og->set_value("scale_unit", _("%"));
m_og->set_value("scale_x", 100); m_og->set_value("scale_x", "100");
m_og->set_value("scale_y", 100); m_og->set_value("scale_y", "100");
m_og->set_value("scale_z", 100); m_og->set_value("scale_z", "100");
} }
void ObjectManipulation::update_values() void ObjectManipulation::update_values()
{ {
int selection = ol_selection(); int selection = ol_selection();
if (selection < 0 || wxGetApp().mainframe->m_plater->model().objects.size() <= selection) { if (selection < 0 || wxGetApp().mainframe->m_plater->model().objects.size() <= selection) {
m_og->set_value("position_x", 0); m_og->set_value("position_x", "0");
m_og->set_value("position_y", 0); m_og->set_value("position_y", "0");
m_og->set_value("position_z", 0); m_og->set_value("position_z", "0");
m_og->set_value("scale_x", 0); m_og->set_value("scale_x", "0");
m_og->set_value("scale_y", 0); m_og->set_value("scale_y", "0");
m_og->set_value("scale_z", 0); m_og->set_value("scale_z", "0");
m_og->set_value("rotation_x", 0); m_og->set_value("rotation_x", "0");
m_og->set_value("rotation_y", 0); m_og->set_value("rotation_y", "0");
m_og->set_value("rotation_z", 0); m_og->set_value("rotation_z", "0");
m_og->disable(); m_og->disable();
return; return;
} }
@ -297,14 +296,14 @@ void ObjectManipulation::update_scale_values()
auto size = objects[selection]->instance_bounding_box(0).size(); auto size = objects[selection]->instance_bounding_box(0).size();
if (m_is_percent_scale) { if (m_is_percent_scale) {
m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100)); m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * 100, 2));
m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100)); m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * 100, 2));
m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * 100)); m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * 100, 2));
} }
else { else {
m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * size(0) + 0.5)); m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * size(0) + 0.5, 2));
m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5)); m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * size(1) + 0.5, 2));
m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5)); m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * size(2) + 0.5, 2));
} }
} }
@ -312,16 +311,16 @@ void ObjectManipulation::update_position_values()
{ {
auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front(); auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front();
m_og->set_value("position_x", int(instance->get_offset(X))); m_og->set_value("position_x", double_to_string(instance->get_offset(X), 2));
m_og->set_value("position_y", int(instance->get_offset(Y))); m_og->set_value("position_y", double_to_string(instance->get_offset(Y), 2));
m_og->set_value("position_z", int(instance->get_offset(Z))); m_og->set_value("position_z", double_to_string(instance->get_offset(Z), 2));
} }
void ObjectManipulation::update_position_value(const Vec3d& position) void ObjectManipulation::update_position_value(const Vec3d& position)
{ {
m_og->set_value("position_x", int(position(0))); m_og->set_value("position_x", double_to_string(position(0), 2));
m_og->set_value("position_y", int(position(1))); m_og->set_value("position_y", double_to_string(position(1), 2));
m_og->set_value("position_z", int(position(2))); m_og->set_value("position_z", double_to_string(position(2), 2));
} }
void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
@ -334,9 +333,9 @@ void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
m_og->set_value("scale_unit", _("%")); m_og->set_value("scale_unit", _("%"));
auto scale = scaling_factor * 100.0; auto scale = scaling_factor * 100.0;
m_og->set_value("scale_x", int(scale(0))); m_og->set_value("scale_x", double_to_string(scale(0), 2));
m_og->set_value("scale_y", int(scale(1))); m_og->set_value("scale_y", double_to_string(scale(1), 2));
m_og->set_value("scale_z", int(scale(2))); m_og->set_value("scale_z", double_to_string(scale(2), 2));
} }
void ObjectManipulation::update_rotation_values() void ObjectManipulation::update_rotation_values()
@ -364,18 +363,10 @@ void ObjectManipulation::update_rotation_value(double angle, Axis axis)
void ObjectManipulation::update_rotation_value(const Vec3d& rotation) void ObjectManipulation::update_rotation_value(const Vec3d& rotation)
{ {
m_og->set_value("rotation_x", int(round_nearest(Geometry::rad2deg(rotation(0)), 0))); m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(rotation(0)), 0), 2));
m_og->set_value("rotation_y", int(round_nearest(Geometry::rad2deg(rotation(1)), 0))); m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(rotation(1)), 0), 2));
m_og->set_value("rotation_z", int(round_nearest(Geometry::rad2deg(rotation(2)), 0))); m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(rotation(2)), 0), 2));
} }
void ObjectManipulation::show_object_name(bool show)
{
wxGridSizer* grid_sizer = m_og->get_grid_sizer();
grid_sizer->Show(static_cast<size_t>(0), show);
grid_sizer->Show(static_cast<size_t>(1), show);
}
} //namespace GUI } //namespace GUI
} //namespace Slic3r } //namespace Slic3r

View File

@ -48,8 +48,6 @@ public:
void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; }
void show_object_name(bool show);
}; };
}} }}

View File

@ -43,7 +43,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
case coPercents: case coPercents:
case coString: case coString:
case coStrings: case coStrings:
m_fields.emplace(id, std::move(TextCtrl::Create<TextCtrl>(parent(), opt, id))); m_fields.emplace(id, std::move(TextCtrl::Create<TextCtrl>(parent(), opt, id, process_enter)));
break; break;
case coBool: case coBool:
case coBools: case coBools:

View File

@ -94,6 +94,8 @@ public:
wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
int sidetext_width{ -1 }; int sidetext_width{ -1 };
bool process_enter { false };
/// Returns a copy of the pointer of the parent wxWindow. /// Returns a copy of the pointer of the parent wxWindow.
/// Accessor function is because users are not allowed to change the parent /// Accessor function is because users are not allowed to change the parent
/// but defining it as const means a lot of const_casts to deal with wx functions. /// but defining it as const means a lot of const_casts to deal with wx functions.
@ -148,8 +150,13 @@ public:
inline void disable() { for (auto& field : m_fields) field.second->disable(); } inline void disable() { for (auto& field : m_fields) field.second->disable(); }
void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); } void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); }
void set_show_modified_btns_val(bool show) { void set_show_modified_btns_val(bool show) {
m_show_modified_btns = show; m_show_modified_btns = show;
}
// The controls inside this option group will generate the event wxEVT_TEXT_ENTER
void set_process_enter() {
process_enter = true;
} }
OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false, OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false,