From 40dd3acd0fc8d8723a9f6608c87e1ca1c569a78e Mon Sep 17 00:00:00 2001 From: vovodroid Date: Sat, 20 Jul 2024 18:31:34 +0300 Subject: [PATCH] Refactor wall direction --- src/libslic3r/GCode.cpp | 7 ++++-- src/libslic3r/PerimeterGenerator.cpp | 32 ++++++++++++++------------- src/libslic3r/PrintConfig.cpp | 8 +++---- src/libslic3r/PrintConfig.hpp | 1 - src/slic3r/GUI/ConfigManipulation.cpp | 7 +----- src/slic3r/GUI/PartPlate.cpp | 1 - 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 171d68b9480..7b8e7f8d42d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -4561,7 +4561,10 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou if (m_config.spiral_mode && !is_hole) { // if spiral vase, we have to ensure that all contour are in the same orientation. - loop.make_counter_clockwise(); + if (m_config.wall_direction == WallDirection::CounterClockwise) + loop.make_counter_clockwise(); + else + loop.make_clockwise(); } if (loop.loop_role() == elrSkirt && (this->m_layer->id() % 2 == 1)) loop.reverse(); @@ -4622,7 +4625,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou // 1 - the currently printed external perimeter and 2 - the neighbouring internal perimeter. if (m_config.wipe_before_external_loop.value && !paths.empty() && paths.front().size() > 1 && paths.back().size() > 1 && paths.front().role() == erExternalPerimeter && region_perimeters.size() > 1) { const bool is_full_loop_ccw = loop.polygon().is_counter_clockwise(); - bool is_hole_loop = (loop.loop_role() & ExtrusionLoopRole::elrHole) != 0; // loop.make_counter_clockwise(); + bool is_hole_loop = (loop.loop_role() & ExtrusionLoopRole::elrHole) != 0; const double nozzle_diam = nozzle_diameter; // note: previous & next are inverted to extrude "in the opposite direction, and we are "rewinding" diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index a1123361756..cab5f5a767a 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -663,7 +663,10 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime ExtrusionLoop *eloop = static_cast(coll.entities[idx.first]); coll.entities[idx.first] = nullptr; - eloop->make_counter_clockwise(); + if (perimeter_generator.config->wall_direction == WallDirection::CounterClockwise) + eloop->make_counter_clockwise(); + else + eloop->make_clockwise(); eloop->inset_idx = loop.depth; if (loop.is_contour) { out.append(std::move(children.entities)); @@ -1046,7 +1049,10 @@ static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& p if (!paths.empty()) { if (extrusion->is_closed) { ExtrusionLoop extrusion_loop(std::move(paths), pg_extrusion.is_contour ? elrDefault : elrHole); - extrusion_loop.make_counter_clockwise(); + if (perimeter_generator.config->wall_direction == WallDirection::CounterClockwise) + extrusion_loop.make_counter_clockwise(); + else + extrusion_loop.make_clockwise(); // TODO: it seems in practice that ExtrusionLoops occasionally have significantly disconnected paths, // triggering the asserts below. Is this a problem? for (auto it = std::next(extrusion_loop.paths.begin()); it != extrusion_loop.paths.end(); ++it) { @@ -1635,7 +1641,7 @@ static void reorient_perimeters(ExtrusionEntityCollection &entities, bool steep_ } if (need_reverse && !isExternal) { - eloop->make_clockwise(); + eloop->reverse(); } } } @@ -1947,18 +1953,17 @@ void PerimeterGenerator::process_classic() // at this point, all loops should be in contours[0] bool steep_overhang_contour = false; bool steep_overhang_hole = false; - const WallDirection wall_direction = config->wall_direction; - if (wall_direction != WallDirection::Auto) { - // Skip steep overhang detection if wall direction is specified + if (!config->overhang_reverse) { + // Skip steep overhang detection no reverse is specified steep_overhang_contour = true; steep_overhang_hole = true; } ExtrusionEntityCollection entities = traverse_loops(*this, contours.front(), thin_walls, steep_overhang_contour, steep_overhang_hole); // All walls are counter-clockwise initially, so we don't need to reorient it if that's what we want - if (wall_direction != WallDirection::CounterClockwise) { + if (config->overhang_reverse) { reorient_perimeters(entities, steep_overhang_contour, steep_overhang_hole, // Reverse internal only if the wall direction is auto - this->config->overhang_reverse_internal_only && wall_direction == WallDirection::Auto); + this->config->overhang_reverse_internal_only); } // if brim will be printed, reverse the order of perimeters so that @@ -2987,18 +2992,15 @@ void PerimeterGenerator::process_arachne() bool steep_overhang_contour = false; bool steep_overhang_hole = false; - const WallDirection wall_direction = config->wall_direction; - if (wall_direction != WallDirection::Auto) { - // Skip steep overhang detection if wall direction is specified + if (!config->overhang_reverse) { + // Skip steep overhang detection no reverse is specified steep_overhang_contour = true; steep_overhang_hole = true; } if (ExtrusionEntityCollection extrusion_coll = traverse_extrusions(*this, ordered_extrusions, steep_overhang_contour, steep_overhang_hole); !extrusion_coll.empty()) { - // All walls are counter-clockwise initially, so we don't need to reorient it if that's what we want - if (wall_direction != WallDirection::CounterClockwise) { + if (config->overhang_reverse) { reorient_perimeters(extrusion_coll, steep_overhang_contour, steep_overhang_hole, - // Reverse internal only if the wall direction is auto - this->config->overhang_reverse_internal_only && wall_direction == WallDirection::Auto); + this->config->overhang_reverse_internal_only); } this->loops->append(extrusion_coll); } diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 42465046c6c..945f3d689f5 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -176,7 +176,6 @@ CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(WallSequence) //Orca static t_config_enum_values s_keys_map_WallDirection{ - { "auto", int(WallDirection::Auto) }, { "ccw", int(WallDirection::CounterClockwise) }, { "cw", int(WallDirection::Clockwise)}, }; @@ -1563,14 +1562,12 @@ void PrintConfigDef::init_fff_params() def->category = L("Quality"); def->tooltip = L("The direction which the wall loops are extruded when looking down from the top.\n\nBy default all walls are extruded in counter-clockwise, unless Reverse on odd is enabled. Set this to any option other than Auto will force the wall direction regardless of the Reverse on odd.\n\nThis option will be disabled if spiral vase mode is enabled."); def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); - def->enum_values.push_back("auto"); def->enum_values.push_back("ccw"); def->enum_values.push_back("cw"); - def->enum_labels.push_back(L("Auto")); def->enum_labels.push_back(L("Counter clockwise")); def->enum_labels.push_back(L("Clockwise")); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionEnum(WallDirection::Auto)); + def->set_default_value(new ConfigOptionEnum(WallDirection::CounterClockwise)); def = this->add("extruder", coInt); def->gui_type = ConfigOptionDef::GUIType::i_enum_open; @@ -6202,6 +6199,9 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va else if(opt_key == "counterbole_hole_bridging") { opt_key = "counterbore_hole_bridging"; } + else if (opt_key == "wall_direction" && value == "auto") { + value = "ccw"; + } else if (opt_key == "draft_shield" && value == "limited") { value = "disabled"; } else if (opt_key == "overhang_speed_classic") { diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 9c6f147586e..9102877615b 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -85,7 +85,6 @@ enum class WallSequence { // Orca enum class WallDirection { - Auto, CounterClockwise, Clockwise, Count, diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 803ba6f943a..06a6529bb0c 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -293,7 +293,6 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con config->opt_int("enforce_support_layers") == 0 && ! config->opt_bool("detect_thin_wall") && ! config->opt_bool("overhang_reverse") && - config->opt_enum("wall_direction") == WallDirection::Auto && config->opt_enum("timelapse_type") == TimelapseType::tlTraditional)) { DynamicPrintConfig new_conf = *config; @@ -307,7 +306,6 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con new_conf.set_key_value("enforce_support_layers", new ConfigOptionInt(0)); new_conf.set_key_value("detect_thin_wall", new ConfigOptionBool(false)); new_conf.set_key_value("overhang_reverse", new ConfigOptionBool(false)); - new_conf.set_key_value("wall_direction", new ConfigOptionEnum(WallDirection::Auto)); new_conf.set_key_value("timelapse_type", new ConfigOptionEnum(tlTraditional)); sparse_infill_density = 0; timelapse_type = TimelapseType::tlTraditional; @@ -540,8 +538,6 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co toggle_field("top_shell_thickness", ! has_spiral_vase && has_top_solid_infill); toggle_field("bottom_shell_thickness", ! has_spiral_vase && has_bottom_solid_infill); - toggle_field("wall_direction", !has_spiral_vase); - // Gap fill is newly allowed in between perimeter lines even for empty infill (see GH #1476). toggle_field("gap_infill_speed", have_perimeters); @@ -734,8 +730,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co bool has_detect_overhang_wall = config->opt_bool("detect_overhang_wall"); bool has_overhang_reverse = config->opt_bool("overhang_reverse"); - bool force_wall_direction = config->opt_enum("wall_direction") != WallDirection::Auto; - bool allow_overhang_reverse = has_detect_overhang_wall && !has_spiral_vase && !force_wall_direction; + bool allow_overhang_reverse = has_detect_overhang_wall && !has_spiral_vase; toggle_field("overhang_reverse", allow_overhang_reverse); toggle_line("overhang_reverse_threshold", allow_overhang_reverse && has_overhang_reverse); toggle_line("overhang_reverse_internal_only", allow_overhang_reverse && has_overhang_reverse); diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index f99db5445c8..c3d810f831e 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -2385,7 +2385,6 @@ void PartPlate::set_vase_mode_related_object_config(int obj_id) { new_conf.set_key_value("detect_thin_wall", new ConfigOptionBool(false)); new_conf.set_key_value("timelapse_type", new ConfigOptionEnum(tlTraditional)); new_conf.set_key_value("overhang_reverse", new ConfigOptionBool(false)); - new_conf.set_key_value("wall_direction", new ConfigOptionEnum(WallDirection::Auto)); auto applying_keys = global_config->diff(new_conf); for (ModelObject* object : obj_ptrs) {