Skip to content

Commit

Permalink
fix FanMover
Browse files Browse the repository at this point in the history
... and thus "fan speed-up time" and "fan kick-start time"

Squashed commit of the following:

commit 822c91b49cb718ac9bd42ff512e875f95b84d47f
Author: Thomas Scheiblauer <[email protected]>
Date:   Sat Dec 7 19:19:31 2024 +0100

    remove "only overhangs" option from FanMover

    ... which could never have worked in OrcaSlicer anyway because the required overhang markers are not written into the gcode.
    Its use is questionable anyway because compensating for a fan delay makes sense everywhere the fan is used.

commit 37f22971d36a384480861a31e3a12ca7274d9be7
Author: Thomas Scheiblauer <[email protected]>
Date:   Sat Dec 7 18:48:36 2024 +0100

    fix issue with FanMover modifying filament change g-code which resulted in poop chute fill ups

commit 6946218564d7aad3b6f90ad9298683abefd20c11
Author: Thomas Scheiblauer <[email protected]>
Date:   Fri Dec 6 21:11:51 2024 +0100

    fix danglin-else warning

commit 01144df3cef845a927990566dc2efe011649cccf
Author: supermerill <[email protected]>
Date:   Tue Feb 13 19:21:56 2024 +0100

    Fix fan mover kickstart
    supermerill/SuperSlicer#4113

commit 14506d7f8e077786298031e5fa3e7eacbd102591
Author: supermerill <[email protected]>
Date:   Mon Jan 29 19:54:49 2024 +0100

    Fix fan_mover/gcodeprocessor with G2/G3
    supermerill/SuperSlicer#4061
  • Loading branch information
shyblower committed Dec 9, 2024
1 parent 3caca22 commit 17ce5fa
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 323 deletions.
133 changes: 69 additions & 64 deletions src/libslic3r/GCode.cpp

Large diffs are not rendered by default.

283 changes: 154 additions & 129 deletions src/libslic3r/GCode/FanMover.cpp

Large diffs are not rendered by default.

31 changes: 22 additions & 9 deletions src/libslic3r/GCode/FanMover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ namespace Slic3r {

class BufferData {
public:
//raw string, contains end position
std::string raw;
// time to go from start to end
float time;
int16_t fan_speed;
bool is_kickstart;
// start position
float x = 0, y = 0, z = 0, e = 0;
// delta to go to end position
float dx = 0, dy = 0, dz = 0, de = 0;
BufferData(std::string line, float time = 0, int16_t fan_speed = 0, float is_kickstart = false) : raw(line), time(time), fan_speed(fan_speed), is_kickstart(is_kickstart){
//avoid double \n
Expand All @@ -31,11 +35,10 @@ class FanMover
{
private:
const std::regex regex_fan_speed;
const float nb_seconds_delay;
const float nb_seconds_delay; // in s
const bool with_D_option;
const bool relative_e;
const bool only_overhangs;
const float kickstart;
const float kickstart; // in s

GCodeReader m_parser{};
const GCodeWriter& m_writer;
Expand All @@ -61,19 +64,27 @@ class FanMover

public:
FanMover(const GCodeWriter& writer, const float nb_seconds_delay, const bool with_D_option, const bool relative_e,
const bool only_overhangs, const float kickstart)
: regex_fan_speed("S[0-9]+"),
const float kickstart)
: regex_fan_speed("S[0-9]+"),
nb_seconds_delay(nb_seconds_delay>0 ? std::max(0.01f,nb_seconds_delay) : 0),
with_D_option(with_D_option)
, relative_e(relative_e), only_overhangs(only_overhangs), kickstart(kickstart), m_writer(writer){}
, relative_e(relative_e), kickstart(kickstart), m_writer(writer){}

// Adds the gcode contained in the given string to the analysis and returns it after removing the workcodes
const std::string& process_gcode(const std::string& gcode, bool flush);

static const std::string& custom_gcode_start_marker;
static const std::string& custom_gcode_end_marker;

private:
BufferData& put_in_buffer(BufferData&& data) {
m_buffer_time_size += data.time;
m_buffer.emplace_back(data);
m_buffer_time_size += data.time;
if (data.fan_speed >= 0 && !m_buffer.empty() && m_buffer.back().fan_speed >= 0) {
// erase last item
m_buffer.back() = data;
} else {
m_buffer.emplace_back(data);
}
return m_buffer.back();
}
std::list<BufferData>::iterator remove_from_buffer(std::list<BufferData>::iterator data) {
Expand All @@ -83,13 +94,15 @@ class FanMover
// Processes the given gcode line
void _process_gcode_line(GCodeReader& reader, const GCodeReader::GCodeLine& line);
void _process_T(const std::string_view command);
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write);
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write, float max_time);
void _print_in_middle_G1(BufferData& line_to_split, float nb_sec, const std::string& line_to_write);
void _remove_slow_fan(int16_t min_speed, float past_sec);
void write_buffer_data();
std::string _set_fan(int16_t speed);
};

} // namespace Slic3r


#endif /* slic3r_GCode_FanMover_hpp_ */
;
10 changes: 5 additions & 5 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ static std::vector<std::string> s_Preset_print_options {
"detect_narrow_internal_solid_infill",
"gcode_add_line_number", "enable_arc_fitting", "precise_z_height", "infill_combination","infill_combination_max_layer_height", /*"adaptive_layer_height",*/
"support_bottom_interface_spacing", "enable_overhang_speed", "slowdown_for_curled_perimeters", "overhang_1_4_speed", "overhang_2_4_speed", "overhang_3_4_speed", "overhang_4_4_speed",
"initial_layer_infill_speed", "only_one_wall_top",
"initial_layer_infill_speed", "only_one_wall_top",
"timelapse_type",
"wall_generator", "wall_transition_length", "wall_transition_filter_deviation", "wall_transition_angle",
"wall_distribution_count", "min_feature_size", "min_bead_width", "post_process", "min_length_factor",
Expand All @@ -805,7 +805,7 @@ static std::vector<std::string> s_Preset_print_options {
"top_solid_infill_flow_ratio","bottom_solid_infill_flow_ratio","only_one_wall_first_layer", "print_flow_ratio", "seam_gap",
"role_based_wipe_speed", "wipe_speed", "accel_to_decel_enable", "accel_to_decel_factor", "wipe_on_loops", "wipe_before_external_loop",
"bridge_density", "precise_outer_wall", "overhang_speed_classic", "bridge_acceleration",
"sparse_infill_acceleration", "internal_solid_infill_acceleration", "tree_support_adaptive_layer_height", "tree_support_auto_brim",
"sparse_infill_acceleration", "internal_solid_infill_acceleration", "tree_support_adaptive_layer_height", "tree_support_auto_brim",
"tree_support_brim_width", "gcode_comments", "gcode_label_objects",
"initial_layer_travel_speed", "exclude_object", "slow_down_layers", "infill_anchor", "infill_anchor_max","initial_layer_min_bead_width",
"make_overhang_printable", "make_overhang_printable_angle", "make_overhang_printable_hole_size" ,"notes",
Expand Down Expand Up @@ -859,7 +859,7 @@ static std::vector<std::string> s_Preset_machine_limits_options {
static std::vector<std::string> s_Preset_printer_options {
"printer_technology",
"printable_area", "bed_exclude_area","bed_custom_texture", "bed_custom_model", "gcode_flavor",
"fan_kickstart", "fan_speedup_time", "fan_speedup_overhangs",
"fan_kickstart", "fan_speedup_time",
"single_extruder_multi_material", "manual_filament_change", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "printing_by_object_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode", "change_extrusion_role_gcode",
"printer_model", "printer_variant", "printable_height", "extruder_clearance_radius", "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod",
"nozzle_height",
Expand Down Expand Up @@ -2465,7 +2465,7 @@ const std::string& PresetCollection::get_preset_name_by_alias(const std::string&
it_preset->is_visible && (it_preset->is_compatible || size_t(it_preset - m_presets.begin()) == m_idx_selected))
return it_preset->name;
}

return alias;
}

Expand Down Expand Up @@ -3578,7 +3578,7 @@ namespace PresetUtils {
if (!boost::filesystem::exists(boost::filesystem::path(out)))
out = Slic3r::resources_dir() + "/profiles/" + preset.vendor->id + "/" + pm->hotend_model;
}

if (out.empty() ||!boost::filesystem::exists(boost::filesystem::path(out)))
out = Slic3r::resources_dir() + "/profiles/hotend.stl";
return out;
Expand Down
27 changes: 13 additions & 14 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"fan_cooling_layer_time",
"full_fan_speed_layer",
"fan_kickstart",
"fan_speedup_overhangs",
"fan_speedup_time",
"filament_colour",
"default_filament_colour",
Expand Down Expand Up @@ -154,7 +153,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"z_hop",
"travel_slope",
"retract_lift_above",
"retract_lift_below",
"retract_lift_below",
"retract_lift_enforce",
"retract_restart_extra",
"retract_restart_extra_toolchange",
Expand Down Expand Up @@ -188,7 +187,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"accel_to_decel_factor",
"wipe_on_loops",
"gcode_comments",
"gcode_label_objects",
"gcode_label_objects",
"exclude_object",
"support_material_interface_fan_speed",
"single_extruder_multi_material_priming",
Expand Down Expand Up @@ -280,7 +279,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
|| opt_key == "prime_tower_brim_width"
|| opt_key == "first_layer_print_sequence"
|| opt_key == "other_layers_print_sequence"
|| opt_key == "other_layers_print_sequence_nums"
|| opt_key == "other_layers_print_sequence_nums"
|| opt_key == "wipe_tower_bridging"
|| opt_key == "wipe_tower_extra_flow"
|| opt_key == "wipe_tower_no_sparse_layers"
Expand Down Expand Up @@ -1132,7 +1131,7 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*

Vec3d test =this->shrinkage_compensation();
const double shrinkage_compensation_z = this->shrinkage_compensation().z();

if (shrinkage_compensation_z != 1. && layers.back() > (this->config().printable_height / shrinkage_compensation_z + EPSILON)) {
// The object exceeds the maximum build volume height because of shrinkage compensation.
return StringObjectException{
Expand All @@ -1155,14 +1154,14 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*
}

// Some of the objects has variable layer height applied by painting or by a table.
bool has_custom_layering = std::find_if(m_objects.begin(), m_objects.end(),
[](const PrintObject *object) { return object->model_object()->has_custom_layering(); })
bool has_custom_layering = std::find_if(m_objects.begin(), m_objects.end(),
[](const PrintObject *object) { return object->model_object()->has_custom_layering(); })
!= m_objects.end();

// Custom layering is not allowed for tree supports as of now.
for (size_t print_object_idx = 0; print_object_idx < m_objects.size(); ++ print_object_idx)
if (const PrintObject &print_object = *m_objects[print_object_idx];
print_object.has_support_material() && is_tree(print_object.config().support_type.value) && (print_object.config().support_style.value == smsOrganic ||
print_object.has_support_material() && is_tree(print_object.config().support_type.value) && (print_object.config().support_style.value == smsOrganic ||
// Orca: use organic as default
print_object.config().support_style.value == smsDefault) &&
print_object.model_object()->has_custom_layering()) {
Expand Down Expand Up @@ -1193,7 +1192,7 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*

if (m_config.ooze_prevention && m_config.single_extruder_multi_material)
return {L("Ooze prevention is only supported with the wipe tower when 'single_extruder_multi_material' is off.")};

#if 0
if (m_config.gcode_flavor != gcfRepRapSprinter && m_config.gcode_flavor != gcfRepRapFirmware &&
m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlinLegacy && m_config.gcode_flavor != gcfMarlinFirmware)
Expand Down Expand Up @@ -1251,7 +1250,7 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*
if (has_custom_layering) {
std::vector<std::vector<coordf_t>> layer_z_series;
layer_z_series.assign(m_objects.size(), std::vector<coordf_t>());

for (size_t idx_object = 0; idx_object < m_objects.size(); ++idx_object) {
layer_z_series[idx_object] = generate_object_layers(m_objects[idx_object]->slicing_parameters(), layer_height_profiles[idx_object], m_objects[idx_object]->config().precise_z_height.value);
}
Expand Down Expand Up @@ -2455,7 +2454,7 @@ std::vector<Point> Print::first_layer_wipe_tower_corners(bool check_wipe_tower_e
double width = m_config.prime_tower_width + 2*m_wipe_tower_data.brim_width;
double depth = m_wipe_tower_data.depth + 2*m_wipe_tower_data.brim_width;
Vec2d pt0(-m_wipe_tower_data.brim_width, -m_wipe_tower_data.brim_width);

// First the corners.
std::vector<Vec2d> pts = { pt0,
Vec2d(pt0.x()+width, pt0.y()),
Expand Down Expand Up @@ -2601,9 +2600,9 @@ const WipeTowerData &Print::wipe_tower_data(size_t filaments_cnt) const
max_wipe_volumes.emplace_back(*std::max_element(v.begin(), v.end()));
float maximum = std::accumulate(max_wipe_volumes.begin(), max_wipe_volumes.end(), 0.f);
maximum = maximum * filaments_cnt / max_wipe_volumes.size();

// Orca: it's overshooting a bit, so let's reduce it a bit
maximum *= 0.6;
maximum *= 0.6;
const_cast<Print *>(this)->m_wipe_tower_data.depth = maximum / (layer_height * width);
} else {
double wipe_volume = m_config.prime_volume;
Expand Down Expand Up @@ -2956,7 +2955,7 @@ std::tuple<float, float> Print::object_skirt_offset(double margin_height) const
{
if (config().skirt_loops == 0 || config().skirt_type != stPerObject)
return std::make_tuple(0, 0);

float max_nozzle_diameter = *std::max_element(m_config.nozzle_diameter.values.begin(), m_config.nozzle_diameter.values.end());
float max_layer_height = *std::max_element(config().max_layer_height.values.begin(), config().max_layer_height.values.end());
float line_width = m_config.initial_layer_line_width.get_abs_value(max_nozzle_diameter);
Expand Down
Loading

0 comments on commit 17ce5fa

Please sign in to comment.