From 040f1fedff1f4caa310622c54adbc3d5d5b97aab Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 3 Jul 2019 14:52:39 +0200 Subject: [PATCH] Added UI-prototype for FilamentSettings->Overrides page --- src/slic3r/GUI/OptionsGroup.cpp | 2 +- src/slic3r/GUI/OptionsGroup.hpp | 3 ++ src/slic3r/GUI/Tab.cpp | 91 ++++++++++++++++++++++++++++++++- src/slic3r/GUI/Tab.hpp | 2 + 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 014932900..2b70dfb4c 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -202,7 +202,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n // so we need a horizontal sizer to arrange these things auto sizer = new wxBoxSizer(wxHORIZONTAL); grid_sizer->Add(sizer, 0, wxEXPAND | (staticbox ? wxALL : wxBOTTOM | wxTOP | wxLEFT), staticbox ? 0 : 1); - sizer->Add(m_near_label_widget_ptrs.back(), 0, wxRIGHT, 7); + sizer->Add(m_near_label_widget_ptrs.back(), 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 7); sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) | wxALIGN_CENTER_VERTICAL, 5); } } diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 73b2c5110..f7b536e9c 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -244,6 +244,9 @@ public: Option option = get_option(title, idx); return OptionsGroup::create_single_option_line(option); } + Line create_single_option_line(const Option& option) const { + return OptionsGroup::create_single_option_line(option); + } void append_single_option_line(const Option& option) { OptionsGroup::append_single_option_line(option); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 6e8b8a471..f45b6017a 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1492,6 +1492,91 @@ void TabPrint::OnActivate() Tab::OnActivate(); } +void TabFilament::add_overrides_page() +{ + PageShp page = add_options_page(_(L("Overrides")), "wrench"); + + const DynamicPrintConfig& printer_cfg = wxGetApp().preset_bundle->printers.default_preset().config; + + ConfigOptionsGroupShp optgroup = page->new_optgroup(_(L("Retraction"/*Overrides"*/))); + + auto append_single_option_line = [printer_cfg, optgroup, this](const std::string& opt_key, int opt_index) + { + const std::string opt_id = opt_index == -1 ? opt_key : opt_key + "#" + std::to_string(opt_index); + const Option& option = Option(*printer_cfg.def()->get(opt_key), opt_id); + + Line line = optgroup->create_single_option_line(option); + + line.near_label_widget = [optgroup, opt_id](wxWindow* parent) { + wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, ""); + + check_box->Bind(wxEVT_CHECKBOX, [optgroup, opt_id](wxCommandEvent& evt) + { + Field* field = optgroup->get_field(opt_id); + if (field != nullptr) + field->toggle(evt.IsChecked()); + }, check_box->GetId()); + return check_box; + }; + + optgroup->append_line(line); + + Field* field = optgroup->get_field(opt_id); + if (field != nullptr) + field->toggle(false); + }; + + int extruder_idx = 0; // #ys_FIXME + + append_single_option_line("retract_length", extruder_idx); + append_single_option_line("retract_lift", extruder_idx); + + Line line = { _(L("Only lift Z")), "" }; + + std::vector opt_ids; + opt_ids.reserve(2); + for (const std::string& opt_key : { "retract_lift_above", "retract_lift_below" }) + { + const std::string opt_id = extruder_idx == -1 ? opt_key : opt_key + "#" + std::to_string(extruder_idx); + opt_ids.push_back(opt_id); + const Option& option = Option(*printer_cfg.def()->get(opt_key), opt_id); + + line.append_option(option); + } + + line.near_label_widget = [optgroup, opt_ids](wxWindow* parent) { + wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, ""); + + check_box->Bind(wxEVT_CHECKBOX, [optgroup, opt_ids](wxCommandEvent& evt) + { + Field* field = nullptr; + for (const std::string& opt_id : opt_ids) { + field = optgroup->get_field(opt_id); + if (field != nullptr) + field->toggle(evt.IsChecked()); + } + }, check_box->GetId()); + return check_box; + }; + + optgroup->append_line(line); + + Field* field = nullptr; + for (const std::string& opt_id : opt_ids) { + field = optgroup->get_field(opt_id); + if (field != nullptr) + field->toggle(false); + } + + append_single_option_line("retract_speed", extruder_idx); + append_single_option_line("deretract_speed", extruder_idx); + append_single_option_line("retract_restart_extra", extruder_idx); + append_single_option_line("retract_before_travel", extruder_idx); + append_single_option_line("retract_layer_change", extruder_idx); + append_single_option_line("wipe", extruder_idx); + append_single_option_line("retract_before_wipe", extruder_idx); +} + void TabFilament::build() { m_presets = &m_preset_bundle->filaments; @@ -1587,10 +1672,14 @@ void TabFilament::build() }; optgroup->append_line(line); + + add_overrides_page(); + + const int gcode_field_height = 15; // 150 const int notes_field_height = 25; // 250 - page = add_options_page(_(L("Custom G-code")), "cog"); + page = add_options_page(_(L("Custom G-code")), "cog"); optgroup = page->new_optgroup(_(L("Start G-code")), 0); Option option = optgroup->get_option("start_filament_gcode"); option.opt.full_width = true; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 6bbe15f7f..abe6a0344 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -331,6 +331,8 @@ class TabFilament : public Tab { ogStaticText* m_volumetric_speed_description_line; ogStaticText* m_cooling_description_line; + + void add_overrides_page(); public: TabFilament(wxNotebook* parent) : // Tab(parent, _(L("Filament Settings")), L("filament")) {}