From 8580ecacca32b2c6a5d22fdb17cc459236f04baa Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 15 Oct 2020 10:25:13 +0200 Subject: Added option to apply the sequential slider in preview to top layer only or to whole gcode toolpaths --- src/slic3r/GUI/GCodeViewer.cpp | 41 ++++++++++++++++++--------------- src/slic3r/GUI/GCodeViewer.hpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 2 ++ src/slic3r/GUI/GUI_Preview.cpp | 6 ++--- src/slic3r/GUI/Plater.cpp | 5 ++++ src/slic3r/GUI/Plater.hpp | 1 + src/slic3r/GUI/Preferences.cpp | 52 ++++++++++++++++++++++++++++++------------ src/slic3r/GUI/Preferences.hpp | 4 +++- 8 files changed, 75 insertions(+), 38 deletions(-) (limited to 'src/slic3r/GUI') diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 3b78a6223..6a5221c32 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -13,6 +13,7 @@ #include "Camera.hpp" #include "I18N.hpp" #include "GUI_Utils.hpp" +#include "GUI.hpp" #include "DoubleSlider.hpp" #include "GLCanvas3D.hpp" #include "GLToolbar.hpp" @@ -446,7 +447,7 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std: #endif // ENABLE_GCODE_VIEWER_STATISTICS // update buffers' render paths - refresh_render_paths(/*false,*/ false); + refresh_render_paths(false, false); log_memory_used("Refreshed G-code extrusion paths, "); } @@ -536,7 +537,7 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in m_sequential_view.current.last = new_last; m_sequential_view.last_current = m_sequential_view.current; - refresh_render_paths(/*true,*/ true); + refresh_render_paths(true, true); if (new_first != first || new_last != last) wxGetApp().plater()->update_preview_moves_slider(); @@ -595,10 +596,10 @@ void GCodeViewer::set_options_visibility_from_flags(unsigned int flags) void GCodeViewer::set_layers_z_range(const std::array& layers_z_range) { - /*bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0];*/ + bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0]; bool keep_sequential_current_last = layers_z_range[1] <= m_layers_z_range[1]; m_layers_z_range = layers_z_range; - refresh_render_paths(/*keep_sequential_current_first,*/ keep_sequential_current_last); + refresh_render_paths(keep_sequential_current_first, keep_sequential_current_last); wxGetApp().plater()->update_preview_moves_slider(); } @@ -1584,7 +1585,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) } } -void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ bool keep_sequential_current_last) const +void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const { #if ENABLE_GCODE_VIEWER_STATISTICS auto start_time = std::chrono::high_resolution_clock::now(); @@ -1647,9 +1648,11 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b m_statistics.render_paths_size = 0; #endif // ENABLE_GCODE_VIEWER_STATISTICS + bool top_layer_only = get_app_config()->get("seq_top_layer_only") == "1"; + SequentialView::Endpoints global_endpoints = { m_moves_count , 0 }; SequentialView::Endpoints top_layer_endpoints = global_endpoints; - /*if (!keep_sequential_current_first)*/ m_sequential_view.current.first = 0; + if (top_layer_only || !keep_sequential_current_first) m_sequential_view.current.first = 0; if (!keep_sequential_current_last) m_sequential_view.current.last = m_moves_count; // first pass: collect visible paths and update sequential view data @@ -1679,21 +1682,23 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b global_endpoints.first = std::min(global_endpoints.first, path.first.s_id); global_endpoints.last = std::max(global_endpoints.last, path.last.s_id); - if (path.type == EMoveType::Travel) { - if (is_travel_in_z_range(i, m_layers_z_range[1], m_layers_z_range[1])) { + if (top_layer_only) { + if (path.type == EMoveType::Travel) { + if (is_travel_in_z_range(i, m_layers_z_range[1], m_layers_z_range[1])) { + top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id); + top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id); + } + } + else if (is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) { top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id); top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id); } } - else if (is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) { - top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id); - top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id); - } } } // update current sequential position - m_sequential_view.current.first = /*keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, global_endpoints.first, global_endpoints.last) :*/ global_endpoints.first; + m_sequential_view.current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, global_endpoints.first, global_endpoints.last) : global_endpoints.first; m_sequential_view.current.last = keep_sequential_current_last ? std::clamp(m_sequential_view.current.last, global_endpoints.first, global_endpoints.last) : global_endpoints.last; // get the world position from gpu @@ -1741,7 +1746,7 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b switch (path.type) { case EMoveType::Extrude: { - if (m_sequential_view.current.last == global_endpoints.last || is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) + if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) color = extrusion_color(path); else color = { 0.25f, 0.25f, 0.25f }; @@ -1749,7 +1754,7 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b break; } case EMoveType::Travel: { - if (m_sequential_view.current.last == global_endpoints.last || is_travel_in_z_range(path_id, m_layers_z_range[1], m_layers_z_range[1])) + if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_travel_in_z_range(path_id, m_layers_z_range[1], m_layers_z_range[1])) color = (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path); else color = { 0.25f, 0.25f, 0.25f }; @@ -1790,8 +1795,8 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b } // set sequential data to their final value - m_sequential_view.endpoints = top_layer_endpoints; - m_sequential_view.current.first = /*keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, m_sequential_view.endpoints.first, m_sequential_view.endpoints.last) :*/ m_sequential_view.endpoints.first; + m_sequential_view.endpoints = top_layer_only ? top_layer_endpoints : global_endpoints; + m_sequential_view.current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, m_sequential_view.endpoints.first, m_sequential_view.endpoints.last) : m_sequential_view.endpoints.first; wxGetApp().plater()->enable_preview_moves_slider(!paths.empty()); @@ -2236,7 +2241,7 @@ void GCodeViewer::render_legend() const visible, times[i], percents[i], max_percent, offsets, [this, role, visible]() { m_extrusions.role_visibility_flags = visible ? m_extrusions.role_visibility_flags & ~(1 << role) : m_extrusions.role_visibility_flags | (1 << role); // update buffers' render paths - refresh_render_paths(/*false,*/ false); + refresh_render_paths(false, false); wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); wxGetApp().plater()->update_preview_bottom_toolbar(); } diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 783020925..c9fcabac3 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -458,7 +458,7 @@ public: private: void load_toolpaths(const GCodeProcessor::Result& gcode_result); void load_shells(const Print& print, bool initialized); - void refresh_render_paths(/*bool keep_sequential_current_first,*/ bool keep_sequential_current_last) const; + void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; void render_toolpaths() const; void render_shells() const; void render_legend() const; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index d11ca1f38..bbeb1aada 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1570,6 +1570,8 @@ void GUI_App::add_config_menu(wxMenuBar *menu) PreferencesDialog dlg(mainframe); dlg.ShowModal(); app_layout_changed = dlg.settings_layout_changed(); + if (dlg.seq_top_layer_only_changed()) + this->plater_->refresh_print(); } if (app_layout_changed) { // hide full main_sizer for mainFrame diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 5126b1789..b91105100 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -222,8 +222,7 @@ Preview::Preview( , m_volumes_cleanup_required(false) #endif // __linux__ { - if (init(parent, model)) - { + if (init(parent, model)) { #if !ENABLE_GCODE_VIEWER show_hide_ui_elements("none"); #endif // !ENABLE_GCODE_VIEWER @@ -349,7 +348,7 @@ bool Preview::init(wxWindow* parent, Model* model) right_sizer->Add(m_layers_slider_sizer, 1, wxEXPAND, 0); m_moves_slider = new DoubleSlider::Control(m_bottom_toolbar_panel, wxID_ANY, 0, 0, 0, 100, wxDefaultPosition, wxSize(-1, 3 * GetTextExtent("m").y), wxSL_HORIZONTAL); - m_moves_slider->set_lower_editable(false); + m_moves_slider->set_lower_editable(get_app_config()->get("seq_top_layer_only") == "0"); m_moves_slider->SetDrawMode(DoubleSlider::dmSequentialGCodeView); wxBoxSizer* bottom_toolbar_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -542,6 +541,7 @@ void Preview::refresh_print() return; load_print(true); + m_moves_slider->set_lower_editable(get_app_config()->get("seq_top_layer_only") == "0"); } void Preview::msw_rescale() diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ae6ebf912..585786bb1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4726,6 +4726,11 @@ void Plater::load_gcode(const wxString& filename) p->preview->reload_print(false); p->preview->get_canvas3d()->zoom_to_gcode(); } + +void Plater::refresh_print() +{ + p->preview->refresh_print(); +} #endif // ENABLE_GCODE_VIEWER std::vector Plater::load_files(const std::vector& input_files, bool load_model, bool load_config, bool imperial_units /*= false*/) { return p->load_files(input_files, load_model, load_config, imperial_units); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 9797a5060..b68b211a9 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -143,6 +143,7 @@ public: #if ENABLE_GCODE_VIEWER void load_gcode(); void load_gcode(const wxString& filename); + void refresh_print(); #endif // ENABLE_GCODE_VIEWER std::vector load_files(const std::vector& input_files, bool load_model = true, bool load_config = true, bool imperial_units = false); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 22d30a64a..f0be8b10d 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1,6 +1,7 @@ #include "Preferences.hpp" #include "OptionsGroup.hpp" #include "GUI_App.hpp" +#include "Plater.hpp" #include "I18N.hpp" #include "libslic3r/AppConfig.hpp" @@ -179,19 +180,19 @@ void PreferencesDialog::build() m_optgroup_camera->activate(); + m_optgroup_gui = std::make_shared(this, _L("GUI")); + m_optgroup_gui->label_width = 40; + m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; + if (opt_key == "use_custom_toolbar_size") { + m_icon_size_sizer->ShowItems(boost::any_cast(value)); + this->layout(); + } + }; + #if ENABLE_GCODE_VIEWER if (is_editor) { #endif // ENABLE_GCODE_VIEWER - m_optgroup_gui = std::make_shared(this, _L("GUI")); - m_optgroup_gui->label_width = 40; - m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) { - m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; - if (opt_key == "use_custom_toolbar_size") { - m_icon_size_sizer->ShowItems(boost::any_cast(value)); - this->layout(); - } - }; - def.label = L("Show sidebar collapse/expand button"); def.type = coBool; def.tooltip = L("If enabled, the button for the collapse sidebar will be appeared in top right corner of the 3D Scene"); @@ -205,14 +206,34 @@ void PreferencesDialog::build() def.set_default_value(new ConfigOptionBool{ app_config->get("use_custom_toolbar_size") == "1" }); option = Option(def, "use_custom_toolbar_size"); m_optgroup_gui->append_single_option_line(option); +#if ENABLE_GCODE_VIEWER + } +#endif // ENABLE_GCODE_VIEWER - m_optgroup_gui->activate(); + def.label = L("Sequential slider applied only to top layer"); + def.type = coBool; + def.tooltip = L("If enabled, changes made using the sequential slider, in preview, apply only to gcode top layer, " + "if disabled, changes made using the sequential slider, in preview, apply to the whole gcode."); + def.set_default_value(new ConfigOptionBool{ app_config->get("seq_top_layer_only") == "1" }); + option = Option(def, "seq_top_layer_only"); + m_optgroup_gui->append_single_option_line(option); + + m_optgroup_gui->activate(); +#if ENABLE_GCODE_VIEWER + if (is_editor) { +#endif // ENABLE_GCODE_VIEWER create_icon_size_slider(); m_icon_size_sizer->ShowItems(app_config->get("use_custom_toolbar_size") == "1"); create_settings_mode_widget(); +#if ENABLE_GCODE_VIEWER + } +#endif // ENABLE_GCODE_VIEWER +#if ENABLE_GCODE_VIEWER + if (is_editor) { +#endif // ENABLE_GCODE_VIEWER #if ENABLE_ENVIRONMENT_MAP m_optgroup_render = std::make_shared(this, _L("Render")); m_optgroup_render->label_width = 40; @@ -236,10 +257,7 @@ void PreferencesDialog::build() auto sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_optgroup_general->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); sizer->Add(m_optgroup_camera->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); -#if ENABLE_GCODE_VIEWER - if (m_optgroup_gui != nullptr) -#endif // ENABLE_GCODE_VIEWER - sizer->Add(m_optgroup_gui->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + sizer->Add(m_optgroup_gui->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); #if ENABLE_ENVIRONMENT_MAP #if ENABLE_GCODE_VIEWER if (m_optgroup_render != nullptr) @@ -266,6 +284,10 @@ void PreferencesDialog::accept() auto app_config = get_app_config(); + m_seq_top_layer_only_changed = false; + if (auto it = m_values.find("seq_top_layer_only"); it != m_values.end()) + m_seq_top_layer_only_changed = app_config->get("seq_top_layer_only") != it->second; + m_settings_layout_changed = false; for (const std::string& key : {"old_settings_layout_mode", "new_settings_layout_mode", diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index f61c4d932..68574fbcc 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -27,11 +27,13 @@ class PreferencesDialog : public DPIDialog wxRadioBox* m_layout_mode_box; bool isOSX {false}; bool m_settings_layout_changed {false}; + bool m_seq_top_layer_only_changed{ false }; public: PreferencesDialog(wxWindow* parent); ~PreferencesDialog() {} - bool settings_layout_changed() { return m_settings_layout_changed; } + bool settings_layout_changed() const { return m_settings_layout_changed; } + bool seq_top_layer_only_changed() const { return m_seq_top_layer_only_changed; } void build(); void accept(); -- cgit v1.2.3