From 433bd46bee72d2ed41a31fe3d14929e0a01aee1c Mon Sep 17 00:00:00 2001 From: supermerill Date: Wed, 15 Jan 2020 03:03:58 +0100 Subject: [PATCH] Expended option for settings ui files: widths, sidetext, simple/advanced/export mode support for lines. --- resources/ui_layout/Readme.md | 46 +++++---- resources/ui_layout/print.ui | 76 ++++++++------ src/libslic3r/Config.hpp | 4 +- src/libslic3r/PrintConfig.cpp | 4 +- src/slic3r/GUI/BedShapeDialog.cpp | 6 +- src/slic3r/GUI/Field.cpp | 3 + src/slic3r/GUI/GUI_ObjectSettings.cpp | 2 +- src/slic3r/GUI/LambdaObjectDialog.cpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 138 ++++++++++++++++++-------- src/slic3r/GUI/OptionsGroup.hpp | 16 +-- src/slic3r/GUI/Preferences.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 38 +++++-- src/slic3r/GUI/Tab.hpp | 2 +- 13 files changed, 217 insertions(+), 122 deletions(-) diff --git a/resources/ui_layout/Readme.md b/resources/ui_layout/Readme.md index 599e6a6a9..e20a5555c 100644 --- a/resources/ui_layout/Readme.md +++ b/resources/ui_layout/Readme.md @@ -26,33 +26,39 @@ each parameter is separated by ':' page:STR:STR * first STR is for the label and the second for the icon, with or without the .svg / .png * Group: - group[:nolabel][:label_width$INT][:EVENT]:STR + group[:nolabel][:title_width$INT][:label_width$INT][:sidetext_width$INT][:EVENT]:STR * EVENT can be extruders_count_event if the group contains extruders_count and is a printer tab ; silent_mode_event if the group contains silent_mode and is a printer tab ; material_density_event if the group contains material_density. - * label_width$INT is used to set the size of the left column, where labels are draw. + * title_width$INT is used to set the size of the left column, where labels are draw. + * label_width$INT is used to set the size of the labels on lines. + * sidetext_width$INT is used to set the size of the suffix label (see sidetext in setting). + * EVENT can be extruders_count_event (TabPrinter only), silent_mode_event (TabPrinter only), material_density_event. * nolabel is used to remove the left column, where labels are draw. * Line: line:STR * setting: - setting[label$STR][:full_label][:full_width][:simple|advanced|expert][:width$INT][:width$INT][:id$INT]:STR + setting[label$STR][label_width$INT][:full_label][:full_width][:sidetext$STR][sidetext_width$INT][:simple|advanced|expert][:width$INT][:height$INT][:id$INT]:STR * STR, the last parameter: the id name of the setting. - * label$STR : to override the label by this new one - * full_label: to override the label by the "full one" - * full_width: to tell to create a field that span the full width - * simple|advanced|expert: add one of these to modify the mode in which this setting appear. If it's inside a lien, the first setting of the line decide for all the line. - * width$INT: change the width of the field. Don't works (yet) with every type of setting. - * height$INT: change the height of the field. Don't works (yet) with every type of setting. + * label$STR : to override the label by this new one (if it ends with '_' it won't have a ':' ; if empty it won't have a length). + * label_width$INT: change the width of the label. Only works if it's in a line. Override the group one. 0 for auto. + * full_label: to override the label by the "full one". + * full_width: to tell to create a field that span the full width. + * sidetext$STR: the suffix at the right of the widget (like 'mm'). + * sidetext_width$INT: the suffix label length (override the group one). 0 for auto. + * simple|advanced|expert: add one of these to modify the mode in which this setting appear. + * width$INT: change the width of the field. Shouod work on most type of settings. + * height$INT: change the height of the field. Don't works with every type of setting. * id $INT : for setting only a single value of a setting array. -* recommended_thin_wall_thickness_description: create a text widget to explain recommended thin wall thickness (only in a fff print tab) -* parent_preset_description: create a text widget to explain parent preset -* cooling_description: create a text widget to explain cooling (only in a filament tab) -* volumetric_speed_description: create a text widget to explain volumetric speed (only in a filament tab) -* filament_ramming_parameters: create a widget for filament ramming -* filament_overrides_page: create a page for overrides (only in a filament tab) -* unregular_pages: create needed special pages for a fff printer tab -* printhost: create printhost settings for the group (only in a printer tab) -* bed_shape: create bed shape widget (only in a printer tab) -* extruders_count: create extruders_count setting (only in a fff printer tab) -* logs: activated logs +* recommended_thin_wall_thickness_description: create a text widget to explain recommended thin wall thickness (only in a fff print tab). +* parent_preset_description: create a text widget to explain parent preset. +* cooling_description: create a text widget to explain cooling (only in a filament tab). +* volumetric_speed_description: create a text widget to explain volumetric speed (only in a filament tab). +* filament_ramming_parameters: create a widget for filament ramming. +* filament_overrides_page: create a page for overrides (only in a filament tab). +* unregular_pages: create needed special pages for a fff printer tab. +* printhost: create printhost settings for the group (only in a printer tab). +* bed_shape: create bed shape widget (only in a printer tab). +* extruders_count: create extruders_count setting (only in a fff printer tab). +* logs: activated logs. ### ui file syntax trailing & leading tabs & spaces are removed, so you can indent as you want. If the first character is '#', then this line is ignored diff --git a/resources/ui_layout/print.ui b/resources/ui_layout/print.ui index 9013c30e0..445e921b4 100644 --- a/resources/ui_layout/print.ui +++ b/resources/ui_layout/print.ui @@ -1,7 +1,7 @@ #logs page:Perimeters & Shell:shell group:Vertical shells - setting:label$perimeters:perimeters + setting:width$6:perimeters setting:spiral_vase recommended_thin_wall_thickness_description group:Horizontal shells @@ -55,32 +55,38 @@ group:Filtering setting:resolution setting:model_precision setting:slice_closing_radius -group:Modifying slices +group:label_width$8:Modifying slices line:Curve smoothing setting:width$6:curve_smoothing_precision setting:width$6:curve_smoothing_angle_convex setting:width$6:curve_smoothing_angle_concave setting:width$6:curve_smoothing_cutoff_dist end_line + setting:hole_to_polyhole line:XY compensation setting:width$6:xy_size_compensation setting:width$6:elefant_foot_compensation setting:width$6:hole_size_compensation end_line - setting:hole_to_polyhole group:Other setting:clip_multipart_objects page:Infill:infill group:Infill - setting:fill_density - setting:fill_pattern - line:External patterns - setting:top_fill_pattern - setting:bottom_fill_pattern + line:Fill density + setting:label_width$5:label$_:fill_density + end_line + line:Pattern + setting:label_width$5:label$_:fill_pattern + setting:label$don't connect:infill_not_connected + end_line + line:External patterns + setting:label_width$5:top_fill_pattern + setting:label_width$5:bottom_fill_pattern + end_line + line:Solid pattern + setting:label_width$5:label$_:solid_fill_pattern end_line - setting:solid_fill_pattern - setting:infill_not_connected group:Reducing printing time setting:infill_every_layers setting:infill_only_where_needed @@ -88,23 +94,23 @@ group:Reducing printing time setting:infill_dense setting:infill_dense_algo end_line -group:Advanced +group:sidetext_width$3:Advanced setting:solid_infill_every_layers setting:solid_infill_below_area line:Angle - setting:fill_angle - setting:bridge_angle + setting:label_width$6:width$5:fill_angle + setting:label_width$6:width$5:bridge_angle end_line line:Anchor solid infill by X mm - setting:external_infill_margin - setting:bridged_infill_margin + setting:label_width$6:width$5:external_infill_margin + setting:label_width$6:width$5:bridged_infill_margin end_line setting:only_retract_when_crossing_perimeters setting:infill_first group:Advanced Infill line:Ironing tuning - setting:fill_smooth_width - setting:fill_smooth_distribution + setting:label_width$6:width$5:fill_smooth_width + setting:label_width$9:width$5:fill_smooth_distribution end_line page:Skirt & Brim:skirt+brim @@ -119,7 +125,7 @@ group:Brim setting:brim_width_interior line:Brim ears setting:brim_ears - setting:brim_ears_max_angle + setting:width$3:brim_ears_max_angle end_line page:Support material:support @@ -152,29 +158,33 @@ group:Options for support material interface setting:support_material_interface_contact_loops page:Speed:time -group:Speed for print moves +group:label_width$8:Speed for print moves line:Perimeter speed - setting:perimeter_speed - setting:external_perimeter_speed - setting:small_perimeter_speed + setting:width$4:perimeter_speed + setting:width$4:external_perimeter_speed + setting:width$4:small_perimeter_speed end_line line:Infill speed - setting:infill_speed - setting:solid_infill_speed - setting:top_solid_infill_speed + setting:width$4:infill_speed + setting:width$4:solid_infill_speed + setting:width$4:top_solid_infill_speed end_line line:Support speed - setting:support_material_speed - setting:support_material_interface_speed + setting:width$4:support_material_speed + setting:width$4:support_material_interface_speed + end_line + line:Bridge speed + setting:label$_:width$4:bridge_speed + end_line + line:Gap fill speed + setting:label$_:width$4:gap_fill_speed end_line - setting:bridge_speed - setting:gap_fill_speed group:Speed for non-print moves setting:travel_speed group:Modifiers line:First layer speed - setting:first_layer_speed - setting:first_layer_infill_speed + setting:label_width$8:width$4:first_layer_speed + setting:label_width$8:width$4:first_layer_infill_speed end_line group:Acceleration control (advanced) setting:perimeter_acceleration @@ -219,8 +229,8 @@ group:Ooze prevention group:Wipe tower setting:wipe_tower line:Wipe tower position - setting:wipe_tower_x - setting:wipe_tower_y + setting:label_width$3:width$5:sidetext$mm:wipe_tower_x + setting:label_width$3:width$5:sidetext$mm:wipe_tower_y end_line setting:wipe_tower_width setting:wipe_tower_rotation_angle diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index c73ae3a02..dce7dd0a4 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1475,8 +1475,10 @@ public: int height = -1; // Optional width of an input field. int width = -1; - // Optional label width of an input field (if in a line). + // Optional label width of the label (if in a line). int label_width = -1; + // Optional label width of the sidetext (if in a line). + int sidetext_width = -1; // limit of a numeric input. // If not set, the is set to // By setting min=0, only nonnegative input is allowed. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index daaeb3776..ac5484353 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -296,7 +296,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat(0)); def = this->add("brim_ears", coBool); - def->label = L(" "); + def->label = L(""); def->full_label = L("Brim ears"); def->category = OptionCategory::skirtBrim; def->tooltip = L("Only draw brim over the sharp edges of the model."); @@ -669,7 +669,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionBool(false)); def = this->add("perimeter_loop", coBool); - def->label = L(" "); + def->label = L(""); def->full_label = L("Perimeters loop"); def->category = OptionCategory::perimeter; def->tooltip = L("Join the perimeters to create only one continuous extrusion without any z-hop." diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 44f5e6021..0ec03cdc5 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -154,7 +154,7 @@ ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& tit wxPanel* panel = new wxPanel(m_shape_options_book); ConfigOptionsGroupShp optgroup = std::make_shared(panel, _(L("Settings"))); - optgroup->label_width = 10; + optgroup->title_width = 10; optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; @@ -171,7 +171,7 @@ wxPanel* BedShapePanel::init_texture_panel() wxPanel* panel = new wxPanel(this); ConfigOptionsGroupShp optgroup = std::make_shared(panel, _(L("Texture"))); - optgroup->label_width = 10; + optgroup->title_width = 10; optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; @@ -250,7 +250,7 @@ wxPanel* BedShapePanel::init_model_panel() wxPanel* panel = new wxPanel(this); ConfigOptionsGroupShp optgroup = std::make_shared(panel, _(L("Model"))); - optgroup->label_width = 10; + optgroup->title_width = 10; optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 634747589..64d2eaf6d 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -693,6 +693,9 @@ void SpinCtrl::propagate_value() void SpinCtrl::msw_rescale() { Field::msw_rescale(); + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit); wxSpinCtrl* field = dynamic_cast(window); field->SetMinSize(wxSize(-1, int(1.9f*field->GetFont().GetPixelSize().y))); diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp index a537ab994..d9b8ac176 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.cpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp @@ -121,7 +121,7 @@ bool ObjectSettings::update_settings_list() categories.push_back(cat.first); auto optgroup = std::make_shared(m_og->ctrl_parent(), _(toString(cat.first)), config, false, extra_column); - optgroup->label_width = 15; + optgroup->title_width = 15; optgroup->sidetext_width = 5; optgroup->m_on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) { diff --git a/src/slic3r/GUI/LambdaObjectDialog.cpp b/src/slic3r/GUI/LambdaObjectDialog.cpp index 63c8d329c..4913e412b 100644 --- a/src/slic3r/GUI/LambdaObjectDialog.cpp +++ b/src/slic3r/GUI/LambdaObjectDialog.cpp @@ -181,7 +181,7 @@ ConfigOptionsGroupShp LambdaObjectDialog::init_modificator_options_page(const wx ConfigOptionsGroupShp optgroup; optgroup = std::make_shared(panel, _(L("Add")) + " " +title + " " +dots); - optgroup->label_width = 100; + optgroup->title_width = 100; m_optgroups.push_back(optgroup); diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index f9b8aeb59..55eb4d416 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -100,16 +100,21 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co return field; } -void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field) +void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field, std::vector* widget_idx_in_sizer) { - if (!m_show_modified_btns) { + if (!m_show_modified_btns) { field->m_Undo_btn->set_as_hidden(); - field->m_Undo_to_sys_btn->set_as_hidden(); - return; - } + field->m_Undo_to_sys_btn->set_as_hidden(); + return; + } - sizer->Add(field->m_Undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); - sizer->Add(field->m_Undo_btn, 0, wxALIGN_CENTER_VERTICAL); + if(widget_idx_in_sizer) + widget_idx_in_sizer->push_back(sizer->GetItemCount()); + sizer->Add(field->m_Undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); + + if (widget_idx_in_sizer) + widget_idx_in_sizer->push_back(sizer->GetItemCount()); + sizer->Add(field->m_Undo_btn, 0, wxALIGN_CENTER_VERTICAL); } void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = nullptr*/) { @@ -129,11 +134,14 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n m_options.emplace(opt.opt_id, opt); // add mode value for current line to m_options_mode - if (!option_set.empty()) - m_options_mode.push_back(option_set[0].opt.mode); + m_options_mode.emplace_back(); + m_line_sizer.emplace_back(); + if (!option_set.empty()) { + m_options_mode.back()[option_set[0].opt.mode].push_back(-1); + } // if we have a single option with no label, no sidetext just add it directly to sizer - if (option_set.size() == 1 && label_width == 0 && option_set.front().opt.full_width && + if (option_set.size() == 1 && title_width == 0 && option_set.front().opt.full_width && option_set.front().opt.label.empty() && option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0) { @@ -174,7 +182,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n // Build a label if we have it wxStaticText* label=nullptr; - if (label_width != 0) { + if (title_width != 0) { if (! line.near_label_widget || ! line.label.IsEmpty()) { // Only create the label if it is going to be displayed. long label_style = staticbox ? 0 : wxALIGN_RIGHT; @@ -185,10 +193,10 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n label_style |= staticbox ? 0 : wxST_ELLIPSIZE_END; #endif /* __WXGTK__ */ label = new wxStaticText(this->ctrl_parent(), wxID_ANY, line.label + (line.label.IsEmpty() ? "" : ": "), - wxDefaultPosition, wxSize(label_width*wxGetApp().em_unit(), -1), label_style); + wxDefaultPosition, wxSize(title_width*wxGetApp().em_unit(), -1), label_style); label->SetBackgroundStyle(wxBG_STYLE_PAINT); label->SetFont(wxGetApp().normal_font()); - label->Wrap(label_width*wxGetApp().em_unit()); // avoid a Linux/GTK bug + label->Wrap(title_width*wxGetApp().em_unit()); // avoid a Linux/GTK bug } if (!line.near_label_widget) grid_sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) | wxALIGN_CENTER_VERTICAL, line.label.IsEmpty() ? 0 : 5); @@ -240,56 +248,75 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n return; } - for (auto opt : option_set) { + m_line_sizer.back() = sizer; + wxSizer* sizer_tmp = sizer; + for (auto opt : option_set) { ConfigOptionDef option = opt.opt; - wxSizer* sizer_tmp = sizer; // add label if any - if (option.label != "") { + if (!option.label.empty()) { //! To correct translation by context have to use wxGETTEXT_IN_CONTEXT macro from wxWidget 3.1.1 - wxString str_label = (option.label == L_CONTEXT("Top", "Layers") || option.label == L_CONTEXT("Bottom", "Layers")) ? - _CTX(option.label, "Layers") : - _(option.label); - label = new wxStaticText(this->ctrl_parent(), wxID_ANY, str_label + ":", wxDefaultPosition, wxDefaultSize); + std::string opt_label = (option.label.at(option.label.size() - 1) != '_') ? option.label : option.label.substr(0, option.label.size() - 1); + wxString str_label = (opt_label == L_CONTEXT("Top", "Layers") || opt_label == L_CONTEXT("Bottom", "Layers")) ? + _CTX(opt_label, "Layers") : + _(opt_label); + label = new wxStaticText(this->ctrl_parent(), wxID_ANY, + (str_label.empty() ? "" : (str_label + ":")), wxDefaultPosition, //wxDefaultSize); + (option.label_width >= 0) ? ((option.label_width != 0) ? wxSize(option.label_width*wxGetApp().em_unit(), -1) : wxDefaultSize) : + ((label_width > 0) ? wxSize(label_width * wxGetApp().em_unit(), -1) : (wxDefaultSize)) + , wxALIGN_RIGHT); label->SetBackgroundStyle(wxBG_STYLE_PAINT); - label->SetFont(wxGetApp().normal_font()); + label->SetFont(wxGetApp().normal_font()); + if (option.label_width > 0 || label_width >0) { + label->Wrap((option.label_width > 0 ? option.label_width : label_width)* wxGetApp().em_unit()); // avoid a Linux/GTK bug + } + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); sizer_tmp->Add(label, 0, /*wxALIGN_RIGHT |*/ wxALIGN_CENTER_VERTICAL, 0); } // add field const Option& opt_ref = opt; auto& field = build_field(opt_ref, label); - add_undo_buttuns_to_sizer(sizer_tmp, field); + add_undo_buttuns_to_sizer(sizer_tmp, field, &(m_options_mode.back()[opt.opt.mode])); if (option_set.size() == 1 && option_set.front().opt.full_width) { const auto v_sizer = new wxBoxSizer(wxVERTICAL); + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); sizer_tmp->Add(v_sizer, 1, wxEXPAND); - is_sizer_field(field) ? + is_sizer_field(field) ? v_sizer->Add(field->getSizer(), 0, wxEXPAND) : v_sizer->Add(field->getWindow(), 0, wxEXPAND); break;//return; } + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); is_sizer_field(field) ? sizer_tmp->Add(field->getSizer(), 0, wxALIGN_CENTER_VERTICAL, 0) : sizer_tmp->Add(field->getWindow(), 0, wxALIGN_CENTER_VERTICAL, 0); // add sidetext if any if (option.sidetext != "") { - auto sidetext = new wxStaticText( this->ctrl_parent(), wxID_ANY, _(option.sidetext), wxDefaultPosition, - wxSize(sidetext_width != -1 ? sidetext_width*wxGetApp().em_unit() : -1, -1) /*wxDefaultSize*/, wxALIGN_LEFT); + auto sidetext = new wxStaticText( this->ctrl_parent(), wxID_ANY, + ((option.sidetext.at(option.sidetext.size() - 1) != '_') ? _(option.sidetext) : option.sidetext.substr(0, option.sidetext.size() - 1)), + wxDefaultPosition, + wxSize( ( option.sidetext_width >= 0 ? (option.sidetext_width != 0 ? option.sidetext_width * wxGetApp().em_unit() : -1) : + (sidetext_width > 0 ? sidetext_width * wxGetApp().em_unit() : -1) ), -1) + /*wxDefaultSize*/, wxALIGN_LEFT); sidetext->SetBackgroundStyle(wxBG_STYLE_PAINT); - sidetext->SetFont(wxGetApp().normal_font()); + sidetext->SetFont(wxGetApp().normal_font()); + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); field->set_side_text_ptr(sidetext); } // add side widget if any if (opt.side_widget != nullptr) { + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); sizer_tmp->Add(opt.side_widget(this->ctrl_parent())/*!.target()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); //! requires verification } if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back()) { + m_options_mode.back()[opt.opt.mode].push_back(sizer_tmp->GetItemCount()); sizer_tmp->AddSpacer(6); } } @@ -454,28 +481,57 @@ void ConfigOptionsGroup::Show(const bool show) #endif /* __WXGTK__ */ } +std::vector get_visible_idx(const std::map>& map, ConfigOptionMode mode) { + std::vector ret; + for (const auto& entry : map) { + if (entry.first <= mode) + ret.insert(ret.end(), entry.second.begin(), entry.second.end()); + } + return ret; +} +std::vector get_invisible_idx(const std::map>& map, ConfigOptionMode mode) { + std::vector ret; + for (const auto& entry : map) { + if (entry.first > mode) + ret.insert(ret.end(), entry.second.begin(), entry.second.end()); + } + return ret; +} + bool ConfigOptionsGroup::update_visibility(ConfigOptionMode mode) { if (m_options_mode.empty()) return true; - int opt_mode_size = m_options_mode.size(); + const int opt_mode_size = m_options_mode.size(); if (m_grid_sizer->GetEffectiveRowsCount() != opt_mode_size && - opt_mode_size == 1) - return m_options_mode[0] <= mode; + opt_mode_size == 1 && m_options_mode[0].size() == 1 && m_options_mode[0].begin()->second.size() == 1) + return get_invisible_idx(m_options_mode[0], mode).empty(); Show(true); - int coef = 0; + ConfigOptionMode best_mode = ConfigOptionMode::comExpert; + for (const auto& map : m_options_mode) + for (const auto& entry : map) + if (entry.first <= best_mode) + best_mode = entry.first; + + int idx_item = 0; int hidden_row_cnt = 0; const int cols = m_grid_sizer->GetCols(); - for (auto opt_mode : m_options_mode) { - const bool show = opt_mode <= mode; - if (!show) { + assert(opt_mode_size == m_line_sizer.size()); + for (int i = 0; i < opt_mode_size; i++) { + if ((m_options_mode[i].size() == 1 + && m_options_mode[i].begin()->second.size() == 1 + && m_options_mode[i].begin()->second[0] == (size_t)-1 + && m_options_mode[i].begin()->first > mode) + || get_visible_idx(m_options_mode[i], mode).empty()) { hidden_row_cnt++; - for (int i = 0; i < cols; ++i) - m_grid_sizer->Show(coef + i, show); - } - coef+= cols; - } + for (size_t idx =0; idx < cols; idx++) + m_grid_sizer->Show(idx_item + idx, false); + }else + for (size_t idx : get_invisible_idx(m_options_mode[i], mode)) + if(idx != (size_t)-1) m_line_sizer[i]->Show(idx, false); + idx_item += cols; + } if (hidden_row_cnt == opt_mode_size) { sizer->ShowItems(false); @@ -503,7 +559,7 @@ void ConfigOptionsGroup::msw_rescale() const int em = em_unit(parent()); // rescale width of label column - if (!m_options_mode.empty() && label_width > 1) + if (!m_options_mode.empty() && title_width > 1) { const int cols = m_grid_sizer->GetCols(); const int rows = m_grid_sizer->GetEffectiveRowsCount(); @@ -516,7 +572,7 @@ void ConfigOptionsGroup::msw_rescale() { auto label = dynamic_cast(label_item->GetWindow()); if (label != nullptr) { - label->SetMinSize(wxSize(label_width*em, -1)); + label->SetMinSize(wxSize(title_width*em, -1)); } } else if (label_item->IsSizer()) // case when we have near_label_widget @@ -526,7 +582,7 @@ void ConfigOptionsGroup::msw_rescale() { auto label = dynamic_cast(l_item->GetWindow()); if (label != nullptr) { - label->SetMinSize(wxSize(label_width*em, -1)); + label->SetMinSize(wxSize(title_width*em, -1)); } } } diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 6089e18f5..d34ab82d8 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -79,7 +79,7 @@ class OptionsGroup { public: const bool staticbox {true}; const wxString title {wxString("")}; - size_t label_width = 20 ;// {200}; + size_t title_width = 20;// {200}; wxSizer* sizer {nullptr}; column_t extra_column {nullptr}; t_change m_on_change { nullptr }; @@ -96,7 +96,8 @@ public: wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; - int sidetext_width{ -1 }; + int sidetext_width{ -1 }; + int label_width{ -1 }; /// Returns a copy of the pointer of the parent wxWindow. /// Accessor function is because users are not allowed to change the parent @@ -163,7 +164,7 @@ public: void clear_fields_except_of(const std::vector left_fields); void hide_labels() { - label_width = 0; + title_width = 0; m_grid_sizer->SetCols(m_grid_sizer->GetEffectiveColsCount()-1); static_cast(m_grid_sizer)->AddGrowableCol(!extra_column ? 0 : 1); } @@ -181,11 +182,11 @@ public: stb = nullptr; sizer = (staticbox ? new wxStaticBoxSizer(stb, wxVERTICAL) : new wxBoxSizer(wxVERTICAL)); auto num_columns = 1U; - if (label_width != 0) num_columns++; + if (title_width != 0) num_columns++; if (extra_column != nullptr) num_columns++; m_grid_sizer = new wxFlexGridSizer(0, num_columns, 1,0); static_cast(m_grid_sizer)->SetFlexibleDirection(wxBOTH/*wxHORIZONTAL*/); - static_cast(m_grid_sizer)->AddGrowableCol(label_width == 0 ? 0 : !extra_column ? 1 : 2 ); + static_cast(m_grid_sizer)->AddGrowableCol(title_width == 0 ? 0 : !extra_column ? 1 : 2 ); #if 0//#ifdef __WXGTK__ m_panel = new wxPanel( _parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); sizer->Fit(m_panel); @@ -200,7 +201,8 @@ public: protected: std::map m_options; wxWindow* m_parent {nullptr}; - std::vector m_options_mode; + std::vector>> m_options_mode; + std::vector m_line_sizer; std::vector m_extra_column_item_ptrs; std::vector m_near_label_widget_ptrs; @@ -226,7 +228,7 @@ protected: const t_field& build_field(const t_config_option_key& id, const ConfigOptionDef& opt, wxStaticText* label = nullptr); const t_field& build_field(const t_config_option_key& id, wxStaticText* label = nullptr); const t_field& build_field(const Option& opt, wxStaticText* label = nullptr); - void add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field); + void add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field, std::vector *widget_idx_in_sizer = nullptr); virtual void on_kill_focus(const std::string& opt_key) {}; virtual void on_set_focus(const std::string& opt_key); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 956997442..3676b7f23 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -20,7 +20,7 @@ void PreferencesDialog::build() { auto app_config = get_app_config(); m_optgroup = std::make_shared(this, _(L("General"))); - m_optgroup->label_width = 40; + m_optgroup->title_width = 40; m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 024ceae0b..e37076667 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1114,9 +1114,17 @@ bool Tab::create_pages(std::string setting_type_name) current_group = current_page->new_optgroup(_(L(params.back())), nolabel?0:-1); for (int i = 1; i < params.size() - 1; i++) { - if (boost::starts_with(params[i], "label_width$")) { + if (boost::starts_with(params[i], "title_width$")) { + current_group->title_width = atoi(params[i].substr(12, params[i].size() - 12).c_str()); + } + else if (params[i].find("label_width$") != std::string::npos) + { current_group->label_width = atoi(params[i].substr(12, params[i].size() - 12).c_str()); } + else if (params[i].find("sidetext_width$") != std::string::npos) + { + current_group->sidetext_width = atoi(params[i].substr(15, params[i].size() - 15).c_str()); + } else if (params[i] == "extruders_count_event") { TabPrinter* tab = nullptr; if ((tab = dynamic_cast(this)) == nullptr) continue; @@ -1314,15 +1322,23 @@ bool Tab::create_pages(std::string setting_type_name) { option.opt.label = params[i].substr(6, params[i].size() - 6); } + else if (boost::starts_with(params[i], "label_width$")) { + option.opt.label_width = atoi(params[i].substr(12, params[i].size() - 12).c_str()); + } + else if (params[i].find("sidetext$") != std::string::npos) + { + option.opt.sidetext = params[i].substr(9, params[i].size() - 9); + } + else if (params[i].find("sidetext_width$") != std::string::npos) + { + option.opt.sidetext_width = atoi(params[i].substr(15, params[i].size() - 15).c_str()); + } else if (params[i] == "full_width") { option.opt.full_width = true; } else if (boost::starts_with(params[i], "width$")) { option.opt.width = atoi(params[i].substr(6, params[i].size() - 6).c_str()); } - else if (boost::starts_with(params[i], "label_width$")) { - option.opt.label_width = atoi(params[i].substr(12, params[i].size() - 12).c_str()); - } else if (boost::starts_with(params[i], "height$")) { option.opt.height = atoi(params[i].substr(7, params[i].size() - 7).c_str()); } @@ -2087,7 +2103,7 @@ void TabFilament::build() page = add_options_page(_(L("Notes")), "note.png"); optgroup = page->new_optgroup(_(L("Notes")), 0); - optgroup->label_width = 0; + optgroup->title_width = 0; option = optgroup->get_option("filament_notes"); option.opt.full_width = true; option.opt.height = notes_field_height;// 250; @@ -2746,7 +2762,7 @@ PageShp TabPrinter::build_kinematics_page() // Legend for OptionsGroups auto optgroup = page->new_optgroup(""); optgroup->set_show_modified_btns_val(false); - optgroup->label_width = 23;// 230; + optgroup->title_width = 23;// 230; auto line = Line{ "", "" }; ConfigOptionDef def; @@ -3904,7 +3920,7 @@ bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value } // package Slic3r::GUI::Tab::Page; -ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/) +ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_title_width /*= -1*/) { auto extra_column = [this](wxWindow* parent, const Line& line) { @@ -3922,8 +3938,8 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la //! config_ have to be "right" ConfigOptionsGroupShp optgroup = std::make_shared(this, title, m_config, true, extra_column); - if (noncommon_label_width >= 0) - optgroup->label_width = noncommon_label_width; + if (noncommon_title_width >= 0) + optgroup->title_width = noncommon_title_width; #ifdef __WXOSX__ auto tab = GetParent()->GetParent(); @@ -4078,7 +4094,7 @@ void TabSLAMaterial::build() optgroup->append_single_option_line("initial_exposure_time"); optgroup = page->new_optgroup(_(L("Corrections"))); - optgroup->label_width = 19;//190; + optgroup->title_width = 19;//190; std::vector corrections = {"material_correction"}; // std::vector axes{ "X", "Y", "Z" }; std::vector axes{ "XY", "Z" }; @@ -4097,7 +4113,7 @@ void TabSLAMaterial::build() page = add_options_page(_(L("Notes")), "note"); optgroup = page->new_optgroup(_(L("Notes")), 0); - optgroup->label_width = 0; + optgroup->title_width = 0; Option option = optgroup->get_option("material_notes"); option.opt.full_width = true; option.opt.height = 25;//250; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 68696f0c5..98bf1120d 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -83,7 +83,7 @@ public: void msw_rescale(); Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; bool set_value(const t_config_option_key& opt_key, const boost::any& value); - ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1); + ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_title_width = -1); bool set_item_colour(const wxColour *clr) { if (m_item_color != clr) {