Skip to content

Commit

Permalink
Merge commit '5642f26347d04dcd879d9b41b25494ceb0e14264' into supersli…
Browse files Browse the repository at this point in the history
…cer_variant
  • Loading branch information
supermerill committed Feb 16, 2025
2 parents 3f13bbc + 5642f26 commit 944f5cb
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 53 deletions.
2 changes: 1 addition & 1 deletion resources/ui_layout/default/printer_fff.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ group:silent_mode_event:filename_format_event:Firmware
end_line
line:Processing limit
setting:max_gcode_per_second
setting:gcode_command_buffer
# setting:gcode_command_buffer
end_line
line:G2/G3 generation
setting:arc_fitting
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ void AppConfig::set_defaults()
if (get("font_size").empty())
set("font_size", "0");

if (get("side_panel_width").empty())
set("side_panel_width", "42");

if (get("gcodeviewer_decimals").empty())
set("gcodeviewer_decimals", "2");

Expand Down
84 changes: 61 additions & 23 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5177,7 +5177,7 @@ std::string GCodeGenerator::extrude_loop(const ExtrusionLoop &original_loop, con
}
assert(polys.front().closest_point(pt_inside) != nullptr &&
std::abs(polys.front().closest_point(pt_inside)->distance_to_square(pt_inside) -
best_dist_sqr) < SCALED_EPSILON);
best_dist_sqr) < SCALED_EPSILON * SCALED_EPSILON);
} else {
polys = { original_polygon };
}
Expand Down Expand Up @@ -5528,7 +5528,7 @@ std::string GCodeGenerator::extrude_path(const ExtrusionPath &path, const std::s
}

// if the path is too small to be printed, put in the queue to be merge with the next one.
const coordf_t scaled_min_length = this->config().gcode_min_length.is_enabled() ?
const distf_t scaled_min_length = this->config().gcode_min_length.is_enabled() ?
scale_d(this->config().gcode_min_length.get_abs_value(m_current_perimeter_extrusion_width)) :
0;
if (scaled_min_length > 0 && simplifed_path.length() < scaled_min_length) {
Expand All @@ -5542,31 +5542,69 @@ std::string GCodeGenerator::extrude_path(const ExtrusionPath &path, const std::s
// simplify with gcode_resolution (not used yet). Simplify by junction deviation before the g1/sec count, to be able to use that decimation to reduce max_gcode_per_second triggers.
// But as it can be visible on cylinders, should only be called if a max_gcode_per_second trigger may come.
const coordf_t scaled_min_resolution = scale_d(this->config().gcode_min_resolution.get_abs_value(m_current_perimeter_extrusion_width));
const int32_t max_gcode_per_second = (false /*disabled*/&& this->config().max_gcode_per_second.is_enabled()) ?
const int32_t max_gcode_per_second = (this->config().max_gcode_per_second.is_enabled()) ?
this->config().max_gcode_per_second.value :
0;
double fan_speed;
if (max_gcode_per_second > 0) {
// if (broken) max_gcode_per_second is used, simplify the segment with it
const int32_t gcode_buffer_window = this->config().gcode_command_buffer.value;
double speed = _compute_speed_mm_per_sec(path, speed_mm_per_sec, fan_speed, nullptr);
coordf_t scaled_mean_length = scale_d(speed / max_gcode_per_second);
//if (max_gcode_per_second > 0) {
// // if (broken) max_gcode_per_second is used, simplify the segment with it
// const int32_t gcode_buffer_window = this->config().gcode_command_buffer.value;
// double speed = _compute_speed_mm_per_sec(path, speed_mm_per_sec, fan_speed, nullptr);
// coordf_t scaled_mean_length = scale_d(speed / max_gcode_per_second);

// // set at least 2 buffer space, to not over-erase first lines.
// if (gcode_buffer_window > 2 && gcode_buffer_window - m_last_command_buffer_used < 2) {
// m_last_command_buffer_used = gcode_buffer_window - 2;
// }

// set at least 2 buffer space, to not over-erase first lines.
if (gcode_buffer_window > 2 && gcode_buffer_window - m_last_command_buffer_used < 2) {
m_last_command_buffer_used = gcode_buffer_window - 2;
// // simplify
// m_last_command_buffer_used = simplifed_path.polyline.simplify_straits(scaled_min_resolution,
// scaled_min_length,
// scaled_mean_length,
// gcode_buffer_window,
// m_last_command_buffer_used);
//} else if (scaled_min_length > 0) {
// // else, simplify with the simple algo only
// simplifed_path.polyline.simplify_straits(scaled_min_resolution, scaled_min_length);
//}
// old 2.5 way
distf_t current_scaled_min_length = scaled_min_length;
if (max_gcode_per_second > 0) {
current_scaled_min_length = std::max(current_scaled_min_length, scale_d(_compute_speed_mm_per_sec(path, speed_mm_per_sec, fan_speed, nullptr)) / max_gcode_per_second);
}
if (current_scaled_min_length > 0 && !simplifed_path.polyline.has_arc() && !config().spiral_vase) {
// it's an alternative to simplifed_path.simplify(scale_(this->config().min_length)); with more enphasis on
// the segment length that on the feature detail. because tolerance = min_length /10, douglas_peucker will
// erase more points if angles are shallower than 6° and then the '_plus' will kick in to keep a bit more. if
// angles are all bigger than 6°, then the douglas_peucker will do all the work.
// NOTE: okay to use set_points() as i have checked against the absence of arc.
bool can_simplify = true;
if (simplifed_path.polyline.size() < 3) {
can_simplify = false;
}
if (simplifed_path.polyline.size() < 4 &&
simplifed_path.polyline.front().coincides_with_epsilon(simplifed_path.polyline.back())) {
// polygon
can_simplify = false;
}
for (int i = 1; i < simplifed_path.polyline.size(); ++i)
assert(!simplifed_path.polyline.get_point(i - 1).coincides_with_epsilon(
simplifed_path.polyline.get_point(i)));
if (can_simplify) {
ExtrusionPath old_path = simplifed_path;
simplifed_path.polyline = ArcPolyline(
MultiPoint::_douglas_peucker_plus(simplifed_path.polyline.to_polyline().points,
std::max(scaled_min_resolution, current_scaled_min_length / 20),
current_scaled_min_length));
for (int i = 1; i < simplifed_path.polyline.size(); ++i)
assert(!simplifed_path.polyline.get_point(i - 1).coincides_with_epsilon(
simplifed_path.polyline.get_point(i)));
if (simplifed_path.size() <= 1) {
simplifed_path = old_path;
}
}

// simplify
m_last_command_buffer_used = simplifed_path.polyline.simplify_straits(scaled_min_resolution,
scaled_min_length,
scaled_mean_length,
gcode_buffer_window,
m_last_command_buffer_used);
} else if (scaled_min_length > 0) {
// else, simplify with the simple algo only
simplifed_path.polyline.simplify_straits(scaled_min_resolution, scaled_min_length);
}
// end old 2.5 way

for(int i=1;i<simplifed_path.polyline.size();++i)
assert(!simplifed_path.polyline.get_point(i - 1).coincides_with_epsilon(simplifed_path.polyline.get_point(i)));
Expand Down Expand Up @@ -6247,7 +6285,7 @@ std::string GCodeGenerator::_extrude(const ExtrusionPath &path, const std::strin
return gcode;
}

double_t GCodeGenerator::_compute_speed_mm_per_sec(const ExtrusionPath& path, const double set_speed, double &fan_speed, std::string *comment) {
double_t GCodeGenerator::_compute_speed_mm_per_sec(const ExtrusionPath& path, const double set_speed, double &fan_speed, std::string *comment) const {

float factor = 1;
double speed = set_speed;
Expand Down Expand Up @@ -7936,7 +7974,7 @@ std::string GCodeGenerator::toolchange(uint16_t extruder_id, double print_z) {
if (toolchange_gcode.empty() && m_writer.multiple_extruders) { // !custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id) && !no_toolchange)
gcode += toolchange_command;
} else {
// user provided his own toolchange gcode, no need to do anything
// user provided his own toolchange gcode, no need to write anything
}
if (m_enable_cooling_markers) {
gcode += ";_TOOLCHANGE " + std::to_string(extruder_id) + "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class GCodeGenerator : ExtrusionVisitorConst {
void _extrude_line(std::string& gcode_str, const Line& line, const double e_per_mm, const std::string_view comment, ExtrusionRole role);
void _extrude_line_cut_corner(std::string& gcode_str, const Line& line, const double e_per_mm, const std::string_view comment, Point& last_pos, const double path_width);
std::string _before_extrude(const ExtrusionPath &path, const std::string_view description, double speed = -1);
double_t _compute_speed_mm_per_sec(const ExtrusionPath &path_attrs, const double speed, double &fan_speed, std::string *comment);
double_t _compute_speed_mm_per_sec(const ExtrusionPath &path_attrs, const double speed, double &fan_speed, std::string *comment) const;
std::pair<double, double> _compute_acceleration(const ExtrusionPath &path);
std::string _after_extrude(const ExtrusionPath &path);
void print_machine_envelope(GCodeOutputStream &file, const Print &print);
Expand Down
19 changes: 11 additions & 8 deletions src/libslic3r/GCode/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ std::string GCodeWriter::set_pressure_advance(double pa) const {
std::string gcode;
if (FLAVOR_IS(gcfKlipper)) {
gcode = std::string("SET_PRESSURE_ADVANCE ADVANCE=") + to_string_nozero(pa, 4);
if (tool_id >= 0) {
if (tool_id >= 0 && !this->config.single_extruder_multi_material.value) {
if (this->config.tool_name.size() > tool_id && !this->config.tool_name.get_at(tool_id).empty()) {
gcode += std::string(" EXTRUDER=") + this->config.tool_name.get_at(tool_id);
} else {
Expand Down Expand Up @@ -508,10 +508,10 @@ std::string GCodeWriter::update_progress(uint32_t num, uint32_t tot, bool allow_

std::string GCodeWriter::toolchange_prefix() const
{
return FLAVOR_IS(gcfMakerWare) ? "M135 T" :
FLAVOR_IS(gcfSailfish) ? "M108 T" :
FLAVOR_IS(gcfKlipper) ? "ACTIVATE_EXTRUDER EXTRUDER=" :
"T";
return FLAVOR_IS(gcfMakerWare) ? "M135 T" :
FLAVOR_IS(gcfSailfish) ? "M108 T" :
FLAVOR_IS(gcfKlipper) && !this->config.single_extruder_multi_material.value ? "ACTIVATE_EXTRUDER EXTRUDER=" :
"T";
}

std::string GCodeWriter::toolchange(uint16_t tool_id)
Expand Down Expand Up @@ -540,9 +540,11 @@ std::string GCodeWriter::toolchange(uint16_t tool_id)

// return the toolchange command
// if we are running a single-extruder setup, just set the extruder and return nothing
// no, still output TX to let the firmware know to change the filament
std::ostringstream gcode;
if (this->multiple_extruders) {
if (FLAVOR_IS(gcfKlipper)) {
// if klipper and not in single_extruder_multi_material, then you need to select the extruder by name.
if (FLAVOR_IS(gcfKlipper) && !this->config.single_extruder_multi_material.value) {
//check if we can use the tool_name field or not
if (tool_id > 0 && tool_id < this->config.tool_name.size() && !this->config.tool_name.get_at(tool_id).empty()
// NOTE: this will probably break if there's more than 10 tools, as it's relying on the
Expand All @@ -551,14 +553,15 @@ std::string GCodeWriter::toolchange(uint16_t tool_id)
gcode << this->toolchange_prefix() << this->config.tool_name.get_at(tool_id);
} else {
gcode << this->toolchange_prefix() << "extruder";
if (tool_id > 0)
if (tool_id > 0) {
gcode << tool_id;
}
}
} else {
gcode << this->toolchange_prefix() << tool_id;
}
if (this->config.gcode_comments)
gcode << " ; change extruder";
gcode << (this->config.single_extruder_multi_material.value ? " ; change filament" : " ; change extruder");
gcode << "\n";
gcode << this->reset_e(true);
}
Expand Down
19 changes: 10 additions & 9 deletions src/libslic3r/GCode/WipeTower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class WipeTowerWriter
float e_speed = e / (((len == 0.f) ? std::abs(e) : len) / f * 60.f);
f /= std::max(1.f, e_speed / m_filpar[m_current_tool].max_e_speed);
if (len > 0 && m_filpar[m_current_tool].max_speed > 0) {
f = std::min(f, m_filpar[m_current_tool].max_speed);
// don't forget to go from speed (mm/s) to Feedrate (mm/min)
f = std::min(f, m_filpar[m_current_tool].max_speed * 60.f);
}
}
gcode += set_format_F(f);
Expand Down Expand Up @@ -1345,12 +1346,12 @@ void WipeTower::toolchange_Wipe(
if (this->m_config->filament_max_speed.get_at(this->m_current_tool) > 0) {
max_speed = float(this->m_config->filament_max_speed.get_at(this->m_current_tool));
}
float target_speed = m_speed;
float target_speed = m_speed; //mm/s
if (is_first_layer() && m_first_layer_speed > 0)
target_speed = m_first_layer_speed;
if (target_speed <= 0)
target_speed = m_infill_speed;
target_speed = std::min(max_speed, target_speed * 60.f);
target_speed = std::min(max_speed, target_speed);
float wipe_speed = std::min(max_speed, float(m_config->wipe_tower_wipe_starting_speed.get_abs_value(target_speed)));
if (wipe_speed <= 0) {
wipe_speed = target_speed;
Expand Down Expand Up @@ -1422,14 +1423,14 @@ WipeTower::ToolChangeResult WipeTower::finish_layer()

// Slow down on the 1st layer.
bool first_layer = is_first_layer();
float speed_factor = 1.f;
float feedrate = m_speed;
float speed_factor = 60.f;
float print_speed = m_speed;
if (first_layer && m_first_layer_speed > 0)
feedrate = m_first_layer_speed;
if (feedrate <= 0)
feedrate = m_infill_speed;
feedrate *= 60.f;
print_speed = m_first_layer_speed;
if (print_speed <= 0)
print_speed = m_infill_speed;
speed_factor *= get_speed_reduction();
float feedrate = m_speed * speed_factor;
float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth();
box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)),
m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width);
Expand Down
Loading

0 comments on commit 944f5cb

Please sign in to comment.