From 4454c3437f2e031ea54af77ed40cc445ca00d596 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 21 Jun 2018 16:15:56 +0200 Subject: [PATCH] "Machine limits" page is completed --- xs/src/libslic3r/PrintConfig.cpp | 34 ++++++---- xs/src/slic3r/GUI/Field.cpp | 16 +++++ xs/src/slic3r/GUI/Field.hpp | 28 ++++++++ xs/src/slic3r/GUI/OptionsGroup.cpp | 4 +- xs/src/slic3r/GUI/OptionsGroup.hpp | 8 ++- xs/src/slic3r/GUI/Tab.cpp | 104 +++++++++++++---------------- 6 files changed, 120 insertions(+), 74 deletions(-) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 54aa3b424b..68fc2da244 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -856,6 +856,12 @@ PrintConfigDef::PrintConfigDef() def->min = 0; def->default_value = new ConfigOptionFloat(0.3); + def = this->add("silent_mode", coBool); + def->label = L("Support silent mode"); + def->tooltip = L("Set silent mode for the G-code flavor"); + def->default_value = new ConfigOptionBool(true); + + const int machine_linits_opt_width = 70; { struct AxisDefault { std::string name; @@ -874,65 +880,72 @@ PrintConfigDef::PrintConfigDef() std::string axis_upper = boost::to_upper_copy(axis.name); // Add the machine feedrate limits for XYZE axes. (M203) def = this->add("machine_max_feedrate_" + axis.name, coFloats); - def->label = (boost::format(L("Maximum feedrate %1%")) % axis_upper).str(); + def->full_label = (boost::format(L("Maximum feedrate %1%")) % axis_upper).str(); def->category = L("Machine limits"); def->tooltip = (boost::format(L("Maximum feedrate of the %1% axis")) % axis_upper).str(); def->sidetext = L("mm/s"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats(axis.max_feedrate); // Add the machine acceleration limits for XYZE axes (M201) def = this->add("machine_max_acceleration_" + axis.name, coFloats); - def->label = (boost::format(L("Maximum acceleration %1%")) % axis_upper).str(); + def->full_label = (boost::format(L("Maximum acceleration %1%")) % axis_upper).str(); def->category = L("Machine limits"); def->tooltip = (boost::format(L("Maximum acceleration of the %1% axis")) % axis_upper).str(); def->sidetext = L("mm/s²"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats(axis.max_acceleration); // Add the machine jerk limits for XYZE axes (M205) def = this->add("machine_max_jerk_" + axis.name, coFloats); - def->label = (boost::format(L("Maximum jerk %1%")) % axis_upper).str(); + def->full_label = (boost::format(L("Maximum jerk %1%")) % axis_upper).str(); def->category = L("Machine limits"); def->tooltip = (boost::format(L("Maximum jerk of the %1% axis")) % axis_upper).str(); def->sidetext = L("mm/s"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats(axis.max_jerk); } } // M205 S... [mm/sec] def = this->add("machine_min_extruding_rate", coFloats); - def->label = L("Minimum feedrate when extruding"); + def->full_label = L("Minimum feedrate when extruding"); def->category = L("Machine limits"); def->tooltip = L("Minimum feedrate when extruding") + " (M205 S)"; def->sidetext = L("mm/s"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats{ 0., 0. }; // M205 T... [mm/sec] def = this->add("machine_min_travel_rate", coFloats); - def->label = L("Minimum travel feedrate"); + def->full_label = L("Minimum travel feedrate"); def->category = L("Machine limits"); def->tooltip = L("Minimum travel feedrate") + " (M205 T)"; def->sidetext = L("mm/s"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats{ 0., 0. }; // M204 S... [mm/sec^2] def = this->add("machine_max_acceleration_extruding", coFloats); - def->label = L("Maximum acceleration when extruding"); + def->full_label = L("Maximum acceleration when extruding"); def->category = L("Machine limits"); def->tooltip = L("Maximum acceleration when extruding") + " (M204 S)"; def->sidetext = L("mm/s²"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats(1250., 1250.); // M204 T... [mm/sec^2] def = this->add("machine_max_acceleration_retracting", coFloats); - def->label = L("Maximum acceleration when retracting"); + def->full_label = L("Maximum acceleration when retracting"); def->category = L("Machine limits"); def->tooltip = L("Maximum acceleration when retracting") + " (M204 T)"; def->sidetext = L("mm/s²"); def->min = 0; + def->width = machine_linits_opt_width; def->default_value = new ConfigOptionFloats(1250., 1250.); def = this->add("max_fan_speed", coInts); @@ -1565,13 +1578,6 @@ PrintConfigDef::PrintConfigDef() def->cli = "single-extruder-multi-material!"; def->default_value = new ConfigOptionBool(false); - // -- ! Kinematics options - def = this->add("silent_mode", coBool); - def->label = L("Silent mode"); - def->tooltip = L("Set silent mode for the G-code flavor"); - def->default_value = new ConfigOptionBool(true); - // -- ! - def = this->add("support_material", coBool); def->label = L("Generate support material"); def->category = L("Support material"); diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 43c9e7db9e..46b04d959b 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -665,6 +665,22 @@ boost::any& PointCtrl::get_value() return m_value = ret_point; } +void StaticText::BUILD() +{ + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + wxString legend(static_cast(m_opt.default_value)->value); + auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size); + temp->SetFont(bold_font()); + + // // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); + + temp->SetToolTip(get_tooltip_text(legend)); +} + } // GUI } // Slic3r diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index 948178d3ee..fb6116b79c 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -384,6 +384,34 @@ public: wxSizer* getSizer() override { return sizer; } }; +class StaticText : public Field { + using Field::Field; +public: + StaticText(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + StaticText(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~StaticText() {} + + wxWindow* window{ nullptr }; + void BUILD() override; + + void set_value(const std::string& value, bool change_event = false) { + m_disable_change_event = !change_event; + dynamic_cast(window)->SetLabel(value); + m_disable_change_event = false; + } + void set_value(const boost::any& value, bool change_event = false) { + m_disable_change_event = !change_event; + dynamic_cast(window)->SetLabel(boost::any_cast(value)); + m_disable_change_event = false; + } + + boost::any& get_value()override { return m_value; } + + void enable() override { dynamic_cast(window)->Enable(); }; + void disable() override{ dynamic_cast(window)->Disable(); }; + wxWindow* getWindow() override { return window; } +}; + } // GUI } // Slic3r diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 57659d03dd..053293ee60 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -31,6 +31,8 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co m_fields.emplace(id, STDMOVE(Choice::Create(parent(), opt, id))); } else if (opt.gui_type.compare("slider") == 0) { } else if (opt.gui_type.compare("i_spin") == 0) { // Spinctrl + } else if (opt.gui_type.compare("legend") == 0) { // StaticText + m_fields.emplace(id, STDMOVE(StaticText::Create(parent(), opt, id))); } else { switch (opt.type) { case coFloatOrPercent: @@ -86,7 +88,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co if (!this->m_disabled) this->back_to_sys_value(opt_id); }; - if (!m_is_tab_opt) { + if (!m_show_modified_btns) { field->m_Undo_btn->Hide(); field->m_Undo_to_sys_btn->Hide(); } diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index f351476423..422e1afd9e 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -127,8 +127,12 @@ public: inline void enable() { for (auto& field : m_fields) field.second->enable(); } inline void disable() { for (auto& field : m_fields) field.second->disable(); } + void set_show_modified_btns_val(bool show) { + m_show_modified_btns = show; + } + 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!="") { + m_parent(_parent), title(title), m_show_modified_btns(is_tab_opt), staticbox(title!="") { auto stb = new wxStaticBox(_parent, wxID_ANY, title); stb->SetFont(bold_font()); sizer = (staticbox ? new wxStaticBoxSizer(stb/*new wxStaticBox(_parent, wxID_ANY, title)*/, wxVERTICAL) : new wxBoxSizer(wxVERTICAL)); @@ -158,7 +162,7 @@ protected: bool m_disabled {false}; wxGridSizer* m_grid_sizer {nullptr}; // "true" if option is created in preset tabs - bool m_is_tab_opt{ false }; + bool m_show_modified_btns{ false }; // This panel is needed for correct showing of the ToolTips for Button, StaticText and CheckBox // Tooltips on GTK doesn't work inside wxStaticBoxSizer unless you insert a panel diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 33636c7098..583773c1e7 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -1718,73 +1718,63 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){ on_value_change("extruders_count", extruders_count); } +void append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key) +{ + auto option = optgroup->get_option(opt_key, 0); + auto line = Line{ option.opt.full_label, "" }; + line.append_option(option); + line.append_option(optgroup->get_option(opt_key, 1)); + optgroup->append_line(line); +} + PageShp TabPrinter::create_kinematics_page() { auto page = add_options_page(_(L("Machine limits")), "cog.png", true); - auto optgroup = page->new_optgroup(_(L("Maximum accelerations"))); - auto line = Line{ _(L("Standard/Silent mode")), "" }; - line.append_option(optgroup->get_option("machine_max_acceleration_x", 0)); - line.append_option(optgroup->get_option("machine_max_acceleration_x", 1)); + + // Legend for OptionsGroups + auto optgroup = page->new_optgroup(_(L(""))); + optgroup->set_show_modified_btns_val(false); + optgroup->label_width = 230; + auto line = Line{ "", "" }; + + ConfigOptionDef def; + def.type = coString; + def.width = 150; + def.gui_type = "legend"; + def.tooltip = L("Values in this column are for Full Power mode"); + def.default_value = new ConfigOptionString{ L("Full Power")}; + + auto option = Option(def, "full_power_legend"); + line.append_option(option); + + def.tooltip = L("Values in this column are for Silent mode"); + def.default_value = new ConfigOptionString{ L("Silent") }; + option = Option(def, "silent_legend"); + line.append_option(option); + optgroup->append_line(line); - line = Line{ "", "" }; - line.append_option(optgroup->get_option("machine_max_acceleration_y", 0)); - line.append_option(optgroup->get_option("machine_max_acceleration_y", 1)); - optgroup->append_line(line); - line = Line{ _(L("Standard/Silent mode")), "" }; - line.append_option(optgroup->get_option("machine_max_acceleration_z", 0)); - line.append_option(optgroup->get_option("machine_max_acceleration_z", 1)); - optgroup->append_line(line); - line = Line{ _(L("Standard/Silent mode")), "" }; - line.append_option(optgroup->get_option("machine_max_acceleration_e", 0)); - line.append_option(optgroup->get_option("machine_max_acceleration_e", 1)); - optgroup->append_line(line); -// optgroup->append_single_option_line("machine_max_acceleration_x", 0); -// optgroup->append_single_option_line("machine_max_acceleration_y", 0); -// optgroup->append_single_option_line("machine_max_acceleration_z", 0); -// optgroup->append_single_option_line("machine_max_acceleration_e", 0); + + std::vector axes{ "x", "y", "z", "e" }; + optgroup = page->new_optgroup(_(L("Maximum accelerations"))); + for (const std::string &axis : axes) { + append_option_line(optgroup, "machine_max_acceleration_" + axis); + } optgroup = page->new_optgroup(_(L("Maximum feedrates"))); - optgroup->append_single_option_line("machine_max_feedrate_x", 0); - optgroup->append_single_option_line("machine_max_feedrate_y", 0); - optgroup->append_single_option_line("machine_max_feedrate_z", 0); - optgroup->append_single_option_line("machine_max_feedrate_e", 0); + for (const std::string &axis : axes) { + append_option_line(optgroup, "machine_max_feedrate_" + axis); + } optgroup = page->new_optgroup(_(L("Starting Acceleration"))); - optgroup->append_single_option_line("machine_max_acceleration_extruding", 0); - optgroup->append_single_option_line("machine_max_acceleration_retracting", 0); + append_option_line(optgroup, "machine_max_acceleration_extruding"); + append_option_line(optgroup, "machine_max_acceleration_retracting"); optgroup = page->new_optgroup(_(L("Advanced"))); - optgroup->append_single_option_line("machine_min_extruding_rate", 0); - optgroup->append_single_option_line("machine_min_travel_rate", 0); - optgroup->append_single_option_line("machine_max_jerk_x", 0); - optgroup->append_single_option_line("machine_max_jerk_y", 0); - optgroup->append_single_option_line("machine_max_jerk_z", 0); - optgroup->append_single_option_line("machine_max_jerk_e", 0); - - //for silent mode -// optgroup = page->new_optgroup(_(L("Maximum accelerations"))); -// optgroup->append_single_option_line("machine_max_acceleration_x", 1); -// optgroup->append_single_option_line("machine_max_acceleration_y", 1); -// optgroup->append_single_option_line("machine_max_acceleration_z", 1); -// optgroup->append_single_option_line("machine_max_acceleration_e", 1); - - optgroup = page->new_optgroup(_(L("Maximum feedrates (Silent mode)"))); - optgroup->append_single_option_line("machine_max_feedrate_x", 1); - optgroup->append_single_option_line("machine_max_feedrate_y", 1); - optgroup->append_single_option_line("machine_max_feedrate_z", 1); - optgroup->append_single_option_line("machine_max_feedrate_e", 1); - - optgroup = page->new_optgroup(_(L("Starting Acceleration (Silent mode)"))); - optgroup->append_single_option_line("machine_max_acceleration_extruding", 1); - optgroup->append_single_option_line("machine_max_acceleration_retracting", 1); - - optgroup = page->new_optgroup(_(L("Advanced (Silent mode)"))); - optgroup->append_single_option_line("machine_min_extruding_rate", 1); - optgroup->append_single_option_line("machine_min_travel_rate", 1); - optgroup->append_single_option_line("machine_max_jerk_x", 1); - optgroup->append_single_option_line("machine_max_jerk_y", 1); - optgroup->append_single_option_line("machine_max_jerk_z", 1); - optgroup->append_single_option_line("machine_max_jerk_e", 1); + append_option_line(optgroup, "machine_min_extruding_rate"); + append_option_line(optgroup, "machine_min_travel_rate"); + for (const std::string &axis : axes) { + append_option_line(optgroup, "machine_max_jerk_" + axis); + } return page; }