From cddfc8b690ad87d40320d9ea557ed8244543ffd8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 14 Sep 2021 10:32:17 +0200 Subject: [PATCH] Tech ENABLE_PREVIEW_LAYOUT - A few fixes in the new legend layout --- src/slic3r/GUI/GCodeViewer.cpp | 33 +++++++++++++++++++-------------- src/slic3r/GUI/GUI_Preview.cpp | 16 ++++++++++++---- src/slic3r/GUI/GUI_Preview.hpp | 4 ++++ src/slic3r/GUI/Plater.cpp | 6 ++++++ src/slic3r/GUI/Plater.hpp | 4 ++++ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index d60935978d..ac47494598 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3346,21 +3346,26 @@ void GCodeViewer::render_legend(float& legend_height) #if ENABLE_PREVIEW_LAYOUT // selection section - bool selection_changed = false; - int view_type = static_cast(get_view_type()); - int old_view_type = view_type; - if (imgui.combo("", { _u8L("Feature type"), - _u8L("Height (mm)"), - _u8L("Width (mm)"), - _u8L("Speed (mm/s)"), - _u8L("Fan speed (%)"), - _u8L("Temperature (°C)"), - _u8L("Volumetric flow rate (mm³/s)"), - _u8L("Tool"), - _u8L("Color Print") }, view_type)) { + bool view_type_changed = false; + int old_view_type = static_cast(get_view_type()); + int view_type = old_view_type; + ImGuiStyle& style = ImGui::GetStyle(); + ImGui::PushItemWidth(ImGui::GetWindowWidth() - style.ItemSpacing.x - 2.0f * style.FramePadding.x); + imgui.combo("", { _u8L("Feature type"), + _u8L("Height (mm)"), + _u8L("Width (mm)"), + _u8L("Speed (mm/s)"), + _u8L("Fan speed (%)"), + _u8L("Temperature (°C)"), + _u8L("Volumetric flow rate (mm³/s)"), + _u8L("Tool"), + _u8L("Color Print") }, view_type); + + if (old_view_type != view_type) { set_view_type(static_cast(view_type)); + wxGetApp().plater()->set_keep_current_preview_type(true); wxGetApp().plater()->refresh_print(); - selection_changed = old_view_type != view_type; + view_type_changed = true; } // extrusion paths section -> title @@ -3394,7 +3399,7 @@ void GCodeViewer::render_legend(float& legend_height) #endif // ENABLE_PREVIEW_LAYOUT #if ENABLE_PREVIEW_LAYOUT - if (!selection_changed) { + if (!view_type_changed) { #endif // ENABLE_PREVIEW_LAYOUT // extrusion paths section -> items switch (m_view_type) diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 3375702e38..65bcf212d9 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -993,13 +993,21 @@ void Preview::load_print_as_fff(bool keep_z_range) std::vector gcodes = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_canvas->get_custom_gcode_per_print_z(); +#if ENABLE_PREVIEW_LAYOUT + const GCodeViewer::EViewType choice = !gcodes.empty() ? + GCodeViewer::EViewType::ColorPrint : + (number_extruders > 1) ? GCodeViewer::EViewType::Tool : GCodeViewer::EViewType::FeatureType; + if (choice != gcode_view_type) { + m_canvas->set_gcode_view_preview_type(choice); + if (wxGetApp().is_gcode_viewer()) { + m_keep_current_preview_type = true; + refresh_print(); + } + } +#else const wxString choice = !gcodes.empty() ? _L("Color Print") : (number_extruders > 1) ? _L("Tool") : _L("Feature type"); - -#if ENABLE_PREVIEW_LAYOUT - GCodeViewer::EViewType view_type = m_canvas->get_gcode_view_type(); -#else int type = m_choice_view_type->FindString(choice); if (m_choice_view_type->GetSelection() != type) { if (0 <= type && type < static_cast(GCodeViewer::EViewType::Count)) { diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 91d126e344..bf3db0915e 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -164,6 +164,10 @@ public: void move_moves_slider(wxKeyEvent& evt); void hide_layers_slider(); +#if ENABLE_PREVIEW_LAYOUT + void set_keep_current_preview_type(bool value) { m_keep_current_preview_type = value; } +#endif // ENABLE_PREVIEW_LAYOUT + private: bool init(wxWindow* parent, Model* model); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7d344c389b..6506cb2c1b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6606,6 +6606,12 @@ bool Plater::is_render_statistic_dialog_visible() const return p->show_render_statistic_dialog; } +#if ENABLE_PREVIEW_LAYOUT +void Plater::set_keep_current_preview_type(bool value) +{ + p->preview->set_keep_current_preview_type(value); +} +#endif // ENABLE_PREVIEW_LAYOUT Plater::TakeSnapshot::TakeSnapshot(Plater *plater, const std::string &snapshot_name) : TakeSnapshot(plater, from_u8(snapshot_name)) {} diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 4a98797e5d..dffb2451f3 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -403,6 +403,10 @@ public: void toggle_render_statistic_dialog(); bool is_render_statistic_dialog_visible() const; +#if ENABLE_PREVIEW_LAYOUT + void set_keep_current_preview_type(bool value); +#endif // ENABLE_PREVIEW_LAYOUT + // Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu. bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition); bool PopupMenu(wxMenu *menu, int x, int y) { return this->PopupMenu(menu, wxPoint(x, y)); }