From b3a2b6b5ad23d2a4231dcd950427d33419de6320 Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 13 Nov 2023 19:08:52 +0100 Subject: [PATCH] 1) fix layer id errors in gcodeviewer 2) add preferences option for showing/hiding layer time & height --- src/libslic3r/AppConfig.cpp | 13 +++++- src/libslic3r/GCode/GCodeProcessor.cpp | 4 +- src/libslic3r/GCode/GCodeProcessor.hpp | 6 ++- src/slic3r/GUI/DoubleSlider.cpp | 48 ++++++++++++++++++----- src/slic3r/GUI/GCodeViewer.cpp | 8 ++-- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 6 +-- src/slic3r/GUI/Preferences.cpp | 18 ++++++++- 7 files changed, 79 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index e7c81f8230f..5151a0871d0 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -439,8 +439,11 @@ void AppConfig::set_defaults() if (get("default_action_delete_all").empty()) set("default_action_delete_all", "1"); - if (get("color_mapinulation_panel").empty()) - set("color_mapinulation_panel", "0"); + // change names, remove this if after 2024 + if (get("color_manipulation_panel").empty() && !get("color_mapinulation_panel").empty()) + set("color_manipulation_panel", get("color_mapinulation_panel")); + if (get("color_manipulation_panel").empty()) + set("color_manipulation_panel", "0"); if (get("order_volumes").empty()) set("order_volumes", "1"); @@ -454,6 +457,12 @@ void AppConfig::set_defaults() if (get("hide_slice_tooltip").empty()) set("hide_slice_tooltip", "0"); + if (get("show_layer_height_doubleslider").empty()) + set("show_layer_height_doubleslider", "1"); + + if (get("show_layer_time_doubleslider").empty()) + set("show_layer_time_doubleslider", "0"); + } else { #ifdef _WIN32 if (get("associate_gcode").empty()) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index c80c5179d3d..7830d820f9f 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -3606,6 +3606,7 @@ void GCodeProcessor::store_move_vertex(EMoveType type) m_line_id + 1 : ((type == EMoveType::Seam) ? m_last_line_id : m_line_id); assert(type != EMoveType::Noop); + m_result.moves.emplace_back( m_last_line_id, type, @@ -3629,7 +3630,8 @@ void GCodeProcessor::store_move_vertex(EMoveType type) m_fan_speed, m_extruder_temps[m_extruder_id], m_time_processor.machines[0].time, //time: set later - static_cast(m_layer_id) //layer_duration: set later + static_cast(m_layer_id), //layer_duration: set later + m_layer_id ); // stores stop time placeholders for later use diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 6bc96ebf064..472ed3e5dab 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -97,11 +97,11 @@ namespace Slic3r { MoveVertex() {} MoveVertex(uint32_t gcode_id, EMoveType type, ExtrusionRole extrusion_role, uint8_t extruder_id, uint8_t cp_color_id, Vec3f position, float delta_extruder, float feedrate, float width, float height, - float mm3_per_mm, float fan_speed, float temperature, float time, float layer_duration) : + float mm3_per_mm, float fan_speed, float temperature, float time, float layer_duration, uint16_t layer_id) : gcode_id(gcode_id), type(type), extrusion_role(extrusion_role), extruder_id(extruder_id), cp_color_id(cp_color_id), position(position), delta_extruder(delta_extruder), feedrate(feedrate), width(width), height(height), mm3_per_mm(mm3_per_mm), fan_speed(fan_speed), - temperature(temperature), time(time), layer_duration(layer_duration) { + temperature(temperature), time(time), layer_duration(layer_duration), layer_id(layer_id) { } uint32_t gcode_id{ 0 }; @@ -119,6 +119,7 @@ namespace Slic3r { float temperature{ 0.0f }; // Celsius degrees float time{ 0.0f }; // s float layer_duration{ 0.0f }; // s (layer id before finalize) + uint16_t layer_id{ 0 }; float volumetric_rate() const { return feedrate * mm3_per_mm; } }; @@ -562,6 +563,7 @@ namespace Slic3r { float m_first_layer_height; // mm bool m_processing_start_custom_gcode; unsigned int m_g1_line_id; + unsigned int m_last_layer_id; unsigned int m_layer_id; CpColor m_cp_color; float m_temperature; diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index afa2c49cf35..942433f759d 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -782,16 +782,46 @@ wxString Control::get_label(int tick, LabelType label_type/* = ltHeightWithLayer if (label_type == ltHeight) return str; if (label_type == ltHeightWithLayer) { - size_t layer_number = m_is_wipe_tower ? get_layer_number(value, label_type) + 1 : (m_values.empty() ? value : value + 1); - wxString layer_time_wstr = value < m_layers_times.size() ? short_and_splitted_time(get_time_dhms(m_layers_times[value] - (value > 0 ? m_layers_times[value - 1] : 0))) : ""; - if (layer_number >= m_values.size()) { - assert(layer_number == m_values.size()); - double layer_height = m_values.empty() ? m_label_koef : m_values[m_values.size() - 1] - (m_values.size() > 1 ? m_values[m_values.size() - 2] : 0); - return format_wxstr("\n%1%\n(%2%,\n%3%,\n%4%)", str, wxString::Format("%.*f", 2, layer_height), layer_time_wstr, layer_number); - } else { - double layer_height = m_values.empty() ? m_label_koef : m_values[layer_number - 1] - (layer_number > 1 ? m_values[layer_number - 2] : 0); - return format_wxstr("%1%\n(%2%,\n%3%,\n%4%)", str, wxString::Format("%.*f", 2, layer_height), layer_time_wstr, layer_number); + size_t layer_number = m_is_wipe_tower ? get_layer_number(value, label_type) /**/ + 1 : (m_values.empty() ? value : value /* + 1 */ ); + bool show_lheight = GUI::wxGetApp().app_config->get("show_layer_height_doubleslider") == "1"; + bool show_ltime = GUI::wxGetApp().app_config->get("show_layer_time_doubleslider") == "1"; + int nb_lines = 2; // to move things down if the slider is on top + wxString comma = "\n("; + if (show_lheight) { + nb_lines++; + double layer_height = 0; + if (layer_number >= m_values.size()) { + assert(layer_number == m_values.size()); + layer_height = m_values.empty() ? m_label_koef : m_values[m_values.size() - 1] - (m_values.size() > 1 ? m_values[m_values.size() - 2] : 0); + } else if (layer_number == 0) { + layer_height = m_values.empty() ? m_label_koef : m_values[layer_number]; + }else { + layer_height = m_values.empty() ? m_label_koef : m_values[layer_number] - (layer_number > 1 ? m_values[layer_number - 1] : 0); + } + str = str + comma + wxString::Format("%.*f", 2, layer_height); + comma = ",\n"; + } + if (show_ltime && !m_layers_times.empty()) { + if (m_layers_times.size() +1 >= m_values.size()) { + size_t layer_idx_time = layer_number; + if (m_values.size() > m_layers_times.size()) { + layer_idx_time--; + } + if (layer_idx_time < m_layers_times.size()) { + nb_lines++; + double previous_time = (layer_idx_time > 0 ? m_layers_times[layer_idx_time - 1] : 0); + wxString layer_time_wstr = short_and_splitted_time(get_time_dhms(m_layers_times[layer_idx_time] - previous_time)); + str = str + comma + layer_time_wstr; + comma = ",\n"; + } + } + } + int nb_step_down = layer_number - m_values.size() + nb_lines - 1; + while (nb_step_down > 0) { + str = "\n" + str; + nb_step_down--; } + return format_wxstr("%1%%2%%3%)", str, comma, layer_number); } } diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index bc7a2a16c30..6a18b8ea446 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2124,11 +2124,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) size_t move_id = i - seams_count; if (move.type == EMoveType::Extrude) { - // layers zs - const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back(); - const double z = static_cast(move.position.z()); - if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z) - m_layers.append(z, { last_travel_s_id, move_id }); + // detect new layers + if (m_layers.empty() || move.layer_id >= m_layers.size()) + m_layers.append(static_cast(move.position.z()), { last_travel_s_id, move_id }); else m_layers.get_endpoints().back().last = move_id; // extruder ids diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index bce81f6c426..4d97aba7a6e 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -105,7 +105,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : OG_Settings(parent, true) { m_imperial_units = wxGetApp().app_config->get("use_inches") == "1"; - m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1"; + m_use_colors = wxGetApp().app_config->get("color_manipulation_panel") == "1"; m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation"); @@ -493,9 +493,9 @@ void ObjectManipulation::update_ui_from_settings() } m_check_inch->SetValue(m_imperial_units); - if (m_use_colors != (wxGetApp().app_config->get("color_mapinulation_panel") == "1")) + if (m_use_colors != (wxGetApp().app_config->get("color_manipulation_panel") == "1")) { - m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1"; + m_use_colors = wxGetApp().app_config->get("color_manipulation_panel") == "1"; // update colors for edit-boxes int axis_id = 0; for (ManipulationEditor* editor : m_editors) { diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index ffc600b0ea1..f01bcab146a 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -527,8 +527,8 @@ void PreferencesDialog::build(size_t selected_tab) def.type = coBool; def.tooltip = L("If enabled, the axes names and axes values will be colorized according to the axes colors. " "If disabled, old UI will be used."); - def.set_default_value(new ConfigOptionBool{ app_config->get("color_mapinulation_panel") == "1" }); - option = Option(def, "color_mapinulation_panel"); + def.set_default_value(new ConfigOptionBool{ app_config->get("color_manipulation_panel") == "1" }); + option = Option(def, "color_manipulation_panel"); m_optgroups_gui.back()->append_single_option_line(option); def.label = L("Order object volumes by types"); @@ -636,6 +636,20 @@ void PreferencesDialog::build(size_t selected_tab) option = Option(def, "hide_slice_tooltip"); m_optgroups_gui.back()->append_single_option_line(option); m_values_need_restart.push_back("hide_slice_tooltip"); + + def.label = L("Show layer height on the scroll bar"); + def.type = coBool; + def.tooltip = L("Add the layer height (first number in parentheses) next to a widget of the layer double-scrollbar."); + def.set_default_value(new ConfigOptionBool{ app_config->get("show_layer_height_doubleslider") == "1" }); + option = Option(def, "show_layer_height_doubleslider"); + m_optgroups_gui.back()->append_single_option_line(option); + + def.label = L("Show layer time on the scroll bar"); + def.type = coBool; + def.tooltip = L("Add the layer height (before the layer count in parentheses) next to a widget of the layer double-scrollbar."); + def.set_default_value(new ConfigOptionBool{ app_config->get("show_layer_time_doubleslider") == "1" }); + option = Option(def, "show_layer_time_doubleslider"); + m_optgroups_gui.back()->append_single_option_line(option); }