Skip to content

Commit

Permalink
add: min length before zlift, show layer time
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Nov 13, 2023
2 parents a0f34b1 + ef77820 commit 6551379
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 58 deletions.
5 changes: 4 additions & 1 deletion resources/ui_layout/default/extruder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ group:Retraction
setting:idx:label$Deretraction:deretract_speed
end_line
setting:idx:retract_restart_extra
setting:idx:retract_before_travel
line:Minimum travel after
setting:idx:label$Retraction:retract_before_travel
setting:idx:label$Lift:retract_lift_before_travel
end_line
setting:idx:retract_layer_change
group:Retraction wipe
setting:idx:wipe
Expand Down
5 changes: 4 additions & 1 deletion resources/ui_layout/example/extruder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ group:Retraction
setting:idx:label$Deretraction:deretract_speed
end_line
setting:idx:retract_restart_extra
setting:idx:retract_before_travel
line:Minimum travel after
setting:idx:label$Retraction:retract_before_travel
setting:idx:label$Lift:retract_lift_before_travel
end_line
setting:idx:retract_layer_change
group:Retraction wipe
setting:idx:wipe
Expand Down
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
42 changes: 23 additions & 19 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5837,7 +5837,10 @@ Polyline GCode::travel_to(std::string &gcode, const Point &point, ExtrusionRole
}

Point last_post_before_retract = this->last_pos();
gcode += this->retract();

bool no_lift_on_retract = travel.length() <= scale_(EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_before_travel, 0));
gcode += this->retract(false, no_lift_on_retract);

// When "Wipe while retracting" is enabled, then extruder moves to another position, and travel from this position can cross perimeters.
bool updated_first_pos = false;
if (last_post_before_retract != this->last_pos() && can_avoid_cross_peri) {
Expand Down Expand Up @@ -6010,7 +6013,7 @@ bool GCode::can_cross_perimeter(const Polyline& travel, bool offset)
return true;
}

std::string GCode::retract(bool toolchange)
std::string GCode::retract(bool toolchange, bool inhibit_lift)
{
std::string gcode;

Expand All @@ -6033,24 +6036,25 @@ std::string GCode::retract(bool toolchange)
length is honored in case wipe path was too short. */
gcode += toolchange ? m_writer.retract_for_toolchange() : m_writer.retract();

//check if need to lift
bool need_lift = !m_writer.tool_is_extruder() || toolchange
|| (BOOL_EXTRUDER_CONFIG(retract_lift_first_layer) && m_config.print_retract_lift.value != 0 && this->m_layer_index == 0)
|| this->m_writer.get_extra_lift() > 0;
bool last_fill_extusion_role_top_infill = (this->m_last_extrusion_role == ExtrusionRole::erTopSolidInfill || this->m_last_extrusion_role == ExtrusionRole::erIroning);
if(this->m_last_extrusion_role == ExtrusionRole::erGapFill)
last_fill_extusion_role_top_infill = (this->m_last_notgapfill_extrusion_role == ExtrusionRole::erTopSolidInfill || this->m_last_notgapfill_extrusion_role == ExtrusionRole::erIroning);
if (!need_lift && m_config.print_retract_lift.value != 0) {
if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Not on top")
need_lift = !last_fill_extusion_role_top_infill;
else if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Only on top")
need_lift = last_fill_extusion_role_top_infill;
else
need_lift = true;
if (!inhibit_lift) {
// check if need to lift
bool need_lift = !m_writer.tool_is_extruder() || toolchange
|| (BOOL_EXTRUDER_CONFIG(retract_lift_first_layer) && m_config.print_retract_lift.value != 0 && this->m_layer_index == 0)
|| this->m_writer.get_extra_lift() > 0;
bool last_fill_extusion_role_top_infill = (this->m_last_extrusion_role == ExtrusionRole::erTopSolidInfill || this->m_last_extrusion_role == ExtrusionRole::erIroning);
if (this->m_last_extrusion_role == ExtrusionRole::erGapFill)
last_fill_extusion_role_top_infill = (this->m_last_notgapfill_extrusion_role == ExtrusionRole::erTopSolidInfill || this->m_last_notgapfill_extrusion_role == ExtrusionRole::erIroning);
if (!need_lift && m_config.print_retract_lift.value != 0) {
if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Not on top")
need_lift = !last_fill_extusion_role_top_infill;
else if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Only on top")
need_lift = last_fill_extusion_role_top_infill;
else
need_lift = true;
}
if (need_lift)
gcode += m_writer.lift(this->m_layer_index);
}
if (need_lift)
gcode += m_writer.lift(this->m_layer_index);

return gcode;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class GCode : ExtrusionVisitorConst {
void write_travel_to(std::string& gcode, const Polyline& travel, std::string comment);
bool can_cross_perimeter(const Polyline& travel, bool offset);
bool needs_retraction(const Polyline& travel, ExtrusionRole role = erNone, coordf_t max_min_dist = 0);
std::string retract(bool toolchange = false);
std::string retract(bool toolchange = false, bool inhibit_lift = false);
std::string unretract() { return m_writer.unlift() + m_writer.unretract(); }
std::string set_extruder(uint16_t extruder_id, double print_z, bool no_toolchange = false);
std::string toolchange(uint16_t extruder_id, double print_z);
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
4 changes: 3 additions & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ static std::vector<std::string> s_Preset_filament_options {
"start_filament_gcode", "end_filament_gcode",
"external_perimeter_fan_speed",
// Retract overrides
"filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra", "filament_retract_before_travel",
"filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below",
"filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra",
"filament_retract_before_travel", "filament_retract_lift_before_travel",
"filament_retract_layer_change", "filament_retract_before_wipe",
"filament_seam_gap",
"filament_wipe", "filament_wipe_only_crossing", "filament_wipe_extra_perimeter", "filament_wipe_speed",
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver& /* ne
"retract_lift_below",
"retract_lift_first_layer",
"retract_lift_top",
"retract_lift_before_travel",
"retract_restart_extra",
"retract_restart_extra_toolchange",
"retract_speed",
Expand Down
26 changes: 22 additions & 4 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,16 @@ void PrintConfigDef::init_fff_params()
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionFloats { 2. });

def = this->add("retract_lift_before_travel", coFloats);
def->label = L("Minimum travel after z lift");
def->category = OptionCategory::extruders;
def->tooltip = L("Z lift is not triggered when travel moves are shorter than this length.");
def->sidetext = L("mm");
def->mode = comAdvancedE | comPrusa;
def->min = 0;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionFloats { 2. });

def = this->add("retract_before_wipe", coPercents);
def->label = L("Retract amount before wipe");
def->category = OptionCategory::extruders;
Expand Down Expand Up @@ -6283,7 +6293,8 @@ void PrintConfigDef::init_fff_params()
// Declare retract values for filament profile, overriding the printer's extruder profile.
for (const char *opt_key : {
// floats
"retract_length", "retract_lift", "retract_lift_above", "retract_lift_below", "retract_speed", "deretract_speed", "retract_restart_extra", "retract_before_travel",
"retract_length", "retract_lift", "retract_lift_above", "retract_lift_below", "retract_speed",
"deretract_speed", "retract_restart_extra", "retract_before_travel", "retract_lift_before_travel",
"wipe_extra_perimeter", "wipe_speed",
"wipe_inside_depth", "wipe_inside_end", "wipe_inside_start",
// bools
Expand Down Expand Up @@ -6314,12 +6325,12 @@ void PrintConfigDef::init_extruder_option_keys()
{
// ConfigOptionFloats, ConfigOptionPercents, ConfigOptionBools, ConfigOptionStrings
m_extruder_option_keys = {
"default_filament_profile",
"deretract_speed",
"extruder_colour",
"extruder_offset",
"extruder_fan_offset",
"extruder_offset",
"extruder_temperature_offset",
"default_filament_profile",
"deretract_speed",
"max_layer_height",
"min_layer_height",
"nozzle_diameter",
Expand All @@ -6330,6 +6341,7 @@ void PrintConfigDef::init_extruder_option_keys()
"retract_length_toolchange",
"retract_lift",
"retract_lift_above",
"retract_lift_before_travel",
"retract_lift_below",
"retract_lift_first_layer",
"retract_lift_top",
Expand All @@ -6347,6 +6359,7 @@ void PrintConfigDef::init_extruder_option_keys()
"wipe_only_crossing",
"wipe_speed",
};
assert(std::is_sorted(m_extruder_option_keys.begin(), m_extruder_option_keys.end()));

m_extruder_retract_keys = {
"deretract_speed",
Expand All @@ -6356,10 +6369,14 @@ void PrintConfigDef::init_extruder_option_keys()
"retract_length",
"retract_lift",
"retract_lift_above",
"retract_lift_before_travel",
"retract_lift_below",
"retract_lift_first_layer",
"retract_lift_top",
"retract_restart_extra",
"retract_speed",
"seam_gap",
"seam_gap_external",
"wipe",
"wipe_extra_perimeter",
"wipe_inside_depth",
Expand Down Expand Up @@ -7748,6 +7765,7 @@ std::unordered_set<std::string> prusa_export_to_remove_keys = {
"remaining_times_type",
"retract_lift_first_layer",
"retract_lift_top",
"retract_lift_before_travel",
"seam_angle_cost",
"seam_gap",
"seam_gap_external",
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloats, retract_lift_below))
((ConfigOptionBools, retract_lift_first_layer))
((ConfigOptionStrings, retract_lift_top))
((ConfigOptionFloats, retract_lift_before_travel))
((ConfigOptionFloats, retract_restart_extra))
((ConfigOptionFloats, retract_restart_extra_toolchange))
((ConfigOptionFloats, retract_speed))
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/ConfigManipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
}
}

//note: printer options are toogled in TabPrinter::toggle_options()

void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config)
{
bool have_perimeters = config->opt_int("perimeters") > 0;
Expand Down
45 changes: 38 additions & 7 deletions src/slic3r/GUI/DoubleSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,45 @@ 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);
if (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%)", str, wxString::Format("%.*f", 2, layer_height), 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%)", str, wxString::Format("%.*f", 2, layer_height), 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()){
size_t layer_idx_time = layer_number;
if (m_values.size() > m_layers_times.size()) {
assert(m_layers_times.size() +1 == m_values.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
Loading

0 comments on commit 6551379

Please sign in to comment.