Skip to content

Commit

Permalink
1) fix layer id errors in gcodeviewer
Browse files Browse the repository at this point in the history
2) add preferences option for showing/hiding layer time & height
  • Loading branch information
supermerill committed Nov 14, 2023
1 parent 6b94f8f commit b3a2b6b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 24 deletions.
13 changes: 11 additions & 2 deletions src/libslic3r/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/GCode/GCodeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<float>(m_layer_id) //layer_duration: set later
static_cast<float>(m_layer_id), //layer_duration: set later
m_layer_id
);

// stores stop time placeholders for later use
Expand Down
6 changes: 4 additions & 2 deletions src/libslic3r/GCode/GCodeProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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; }
};
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 39 additions & 9 deletions src/slic3r/GUI/DoubleSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/slic3r/GUI/GCodeViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(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<double>(move.position.z()), { last_travel_s_id, move_id });
else
m_layers.get_endpoints().back().last = move_id;
// extruder ids
Expand Down
6 changes: 3 additions & 3 deletions src/slic3r/GUI/GUI_ObjectManipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 16 additions & 2 deletions src/slic3r/GUI/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit b3a2b6b

Please sign in to comment.