From 63566a92b3a666d0030942c390dc409f29cf455e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 28 Jun 2021 15:26:47 +0200 Subject: [PATCH 1/5] Merged psSkirt and psBrim --- src/libslic3r/Print.cpp | 17 ++++++----------- src/libslic3r/Print.hpp | 5 ++--- src/libslic3r/PrintApply.cpp | 2 +- src/libslic3r/PrintObject.cpp | 10 +++++----- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index c719a232f0..975c9d57ea 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -157,7 +157,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n || opt_key == "wipe_tower_x" || opt_key == "wipe_tower_y" || opt_key == "wipe_tower_rotation_angle") { - steps.emplace_back(psSkirt); + steps.emplace_back(psSkirtBrim); } else if ( opt_key == "nozzle_diameter" || opt_key == "resolution" @@ -201,7 +201,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n || opt_key == "first_layer_speed" || opt_key == "z_offset") { steps.emplace_back(psWipeTower); - steps.emplace_back(psSkirt); + steps.emplace_back(psSkirtBrim); } else if (opt_key == "filament_soluble") { steps.emplace_back(psWipeTower); // Soluble support interface / non-soluble base interface produces non-soluble interface layers below soluble interface layers. @@ -215,8 +215,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n osteps.emplace_back(posPerimeters); osteps.emplace_back(posInfill); osteps.emplace_back(posSupportMaterial); - steps.emplace_back(psSkirt); - steps.emplace_back(psBrim); + steps.emplace_back(psSkirtBrim); } else { // for legacy, if we can't handle this option let's invalidate all steps //FIXME invalidate all steps of all objects as well? @@ -239,8 +238,6 @@ bool Print::invalidate_step(PrintStep step) { bool invalidated = Inherited::invalidate_step(step); // Propagate to dependent steps. - if (step == psSkirt) - invalidated |= Inherited::invalidate_step(psBrim); if (step != psGCodeExport) invalidated |= Inherited::invalidate_step(psGCodeExport); return invalidated; @@ -861,7 +858,7 @@ void Print::process() } this->set_done(psWipeTower); } - if (this->set_started(psSkirt)) { + if (this->set_started(psSkirtBrim)) { m_skirt.clear(); m_skirt_convex_hull.clear(); m_first_layer_convex_hull.points.clear(); @@ -869,9 +866,7 @@ void Print::process() this->set_status(88, L("Generating skirt")); this->_make_skirt(); } - this->set_done(psSkirt); - } - if (this->set_started(psBrim)) { + m_brim.clear(); m_first_layer_convex_hull.points.clear(); if (this->has_brim()) { @@ -884,7 +879,7 @@ void Print::process() // Brim depends on skirt (brim lines are trimmed by the skirt lines), therefore if // the skirt gets invalidated, brim gets invalidated as well and the following line is called. this->finalize_first_layer_convex_hull(); - this->set_done(psBrim); + this->set_done(psSkirtBrim); } BOOST_LOG_TRIVIAL(info) << "Slicing process finished." << log_memory_info(); } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index e486b2bc65..672546d86a 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -45,11 +45,10 @@ enum PrintStep { // psToolOrdering is a synonym to psWipeTower, as the Wipe Tower calculates and modifies the ToolOrdering, // while if printing without the Wipe Tower, the ToolOrdering is calculated as well. psToolOrdering = psWipeTower, - psSkirt, - psBrim, + psSkirtBrim, // Last step before G-code export, after this step is finished, the initial extrusion path preview // should be refreshed. - psSlicingFinished = psBrim, + psSlicingFinished = psSkirtBrim, psGCodeExport, psCount, }; diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index a3b96bfe14..5772204234 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -1240,7 +1240,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ deleted_objects = true; } if (new_objects || deleted_objects) - update_apply_status(this->invalidate_steps({ psSkirt, psBrim, psWipeTower, psGCodeExport })); + update_apply_status(this->invalidate_steps({ psSkirtBrim, psWipeTower, psGCodeExport })); if (new_objects) update_apply_status(false); print_regions_reshuffled = true; diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index d2cfc5e4e3..e1d4096bf9 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -91,7 +91,7 @@ PrintBase::ApplyStatus PrintObject::set_instances(PrintInstances &&instances) [](const PrintInstance& lhs, const PrintInstance& rhs) { return lhs.model_instance == rhs.model_instance && lhs.shift == rhs.shift; }); if (! equal) { status = PrintBase::APPLY_STATUS_CHANGED; - if (m_print->invalidate_steps({ psSkirt, psBrim, psGCodeExport }) || + if (m_print->invalidate_steps({ psSkirtBrim, psGCodeExport }) || (! equal_length && m_print->invalidate_step(psWipeTower))) status = PrintBase::APPLY_STATUS_INVALIDATED; m_instances = std::move(instances); @@ -674,18 +674,18 @@ bool PrintObject::invalidate_step(PrintObjectStep step) // propagate to dependent steps if (step == posPerimeters) { invalidated |= this->invalidate_steps({ posPrepareInfill, posInfill, posIroning }); - invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); + invalidated |= m_print->invalidate_steps({ psSkirtBrim }); } else if (step == posPrepareInfill) { invalidated |= this->invalidate_steps({ posInfill, posIroning }); } else if (step == posInfill) { invalidated |= this->invalidate_steps({ posIroning }); - invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); + invalidated |= m_print->invalidate_steps({ psSkirtBrim }); } else if (step == posSlice) { invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportMaterial }); - invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); + invalidated |= m_print->invalidate_steps({ psSkirtBrim }); m_slicing_params.valid = false; } else if (step == posSupportMaterial) { - invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); + invalidated |= m_print->invalidate_steps({ psSkirtBrim }); m_slicing_params.valid = false; } diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ba99444835..56010555ed 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5704,7 +5704,7 @@ void GLCanvas3D::_load_print_toolpaths() if (print == nullptr) return; - if (!print->is_step_done(psSkirt) || !print->is_step_done(psBrim)) + if (! print->is_step_done(psSkirtBrim)) return; if (!print->has_skirt() && !print->has_brim()) From cf17d164811297e99edae613db87cb2b3ffdda4b Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 30 Jun 2021 12:24:09 +0200 Subject: [PATCH 2/5] Fixed Perl bindings --- xs/xsp/Print.xsp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 8aef9e7a3b..bffdd933fb 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -17,8 +17,7 @@ _constant() STEP_PREPARE_INFILL = posPrepareInfill STEP_INFILL = posInfill STEP_SUPPORTMATERIAL = posSupportMaterial - STEP_SKIRT = psSkirt - STEP_BRIM = psBrim + STEP_SKIRTBRIM = psSkirtBrim STEP_WIPE_TOWER = psWipeTower PROTOTYPE: CODE: From 6eeedf2bc6c62884d2f95e2ee95d1109f2c7a194 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 29 Jun 2021 17:00:18 +0200 Subject: [PATCH 3/5] Skirt is now generated around brims, unless 'draft shield' is checked --- src/libslic3r/Brim.cpp | 6 +++++- src/libslic3r/Print.cpp | 27 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index 29ec60c46a..49f6a9c837 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -402,9 +402,13 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance const BrimType &bt = object->config().brim_type; return (bt == btOuterOnly || bt == btOuterAndInner) && print.config().skirt_distance.value < object->config().brim_width; }); + + const bool draft_shield = print.config().draft_shield; + + // If there is a possibility that brim intersects skirt, go through loops and split those extrusions // The result is either the original Polygon or a list of Polylines - if (! print.skirt().empty() && could_brim_intersects_skirt) + if (draft_shield && ! print.skirt().empty() && could_brim_intersects_skirt) { // Find the bounding polygons of the skirt const Polygons skirt_inners = offset(dynamic_cast(print.skirt().entities.back())->polygon(), diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 975c9d57ea..22b10315c5 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -859,25 +859,36 @@ void Print::process() this->set_done(psWipeTower); } if (this->set_started(psSkirtBrim)) { + this->set_status(88, L("Generating skirt and brim")); + m_skirt.clear(); m_skirt_convex_hull.clear(); m_first_layer_convex_hull.points.clear(); - if (this->has_skirt()) { - this->set_status(88, L("Generating skirt")); - this->_make_skirt(); + const bool draft_shield = config().draft_shield; + + if (this->has_skirt() && draft_shield) { + // In case that draft shield is active, generate skirt first so brim + // can be trimmed to make room for it. + _make_skirt(); } m_brim.clear(); m_first_layer_convex_hull.points.clear(); if (this->has_brim()) { - this->set_status(88, L("Generating brim")); Polygons islands_area; m_brim = make_brim(*this, this->make_try_cancel(), islands_area); for (Polygon &poly : union_(this->first_layer_islands(), islands_area)) append(m_first_layer_convex_hull.points, std::move(poly.points)); } - // Brim depends on skirt (brim lines are trimmed by the skirt lines), therefore if - // the skirt gets invalidated, brim gets invalidated as well and the following line is called. + + + if (has_skirt() && ! draft_shield) { + // In case that draft shield is NOT active, generate skirt now. + // It will be placed around the brim, so brim has to be ready. + assert(m_skirt.empty()); + _make_skirt(); + } + this->finalize_first_layer_convex_hull(); this->set_done(psSkirtBrim); } @@ -959,6 +970,10 @@ void Print::_make_skirt() // Include the wipe tower. append(points, this->first_layer_wipe_tower_corners()); + // Unless draft shield is enabled, include all brims as well. + if (! config().draft_shield) + append(points, m_first_layer_convex_hull.points); + if (points.size() < 3) // At least three points required for a convex hull. return; From b466f18326c473c9d1111427de127c73db593814 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 30 Jun 2021 11:58:01 +0200 Subject: [PATCH 4/5] Draft shield option is now an enum (Disabled/Limited/Enabled) --- src/libslic3r/Brim.cpp | 2 +- src/libslic3r/Print.cpp | 8 +++---- src/libslic3r/PrintConfig.cpp | 30 ++++++++++++++++++++------- src/libslic3r/PrintConfig.hpp | 7 ++++++- src/slic3r/GUI/ConfigManipulation.cpp | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index 49f6a9c837..853c5e22e9 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -403,7 +403,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance return (bt == btOuterOnly || bt == btOuterAndInner) && print.config().skirt_distance.value < object->config().brim_width; }); - const bool draft_shield = print.config().draft_shield; + const bool draft_shield = print.config().draft_shield != dsDisabled; // If there is a possibility that brim intersects skirt, go through loops and split those extrusions diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 22b10315c5..e0946523bb 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -339,12 +339,12 @@ std::vector Print::print_object_ids() const bool Print::has_infinite_skirt() const { - return (m_config.draft_shield && m_config.skirts > 0) || (m_config.ooze_prevention && this->extruders().size() > 1); + return (m_config.draft_shield == dsEnabled && m_config.skirts > 0) || (m_config.ooze_prevention && this->extruders().size() > 1); } bool Print::has_skirt() const { - return (m_config.skirt_height > 0 && m_config.skirts > 0) || this->has_infinite_skirt(); + return (m_config.skirt_height > 0 && m_config.skirts > 0) || m_config.draft_shield != dsDisabled; } bool Print::has_brim() const @@ -864,7 +864,7 @@ void Print::process() m_skirt.clear(); m_skirt_convex_hull.clear(); m_first_layer_convex_hull.points.clear(); - const bool draft_shield = config().draft_shield; + const bool draft_shield = config().draft_shield != dsDisabled; if (this->has_skirt() && draft_shield) { // In case that draft shield is active, generate skirt first so brim @@ -971,7 +971,7 @@ void Print::_make_skirt() append(points, this->first_layer_wipe_tower_corners()); // Unless draft shield is enabled, include all brims as well. - if (! config().draft_shield) + if (config().draft_shield == dsDisabled) append(points, m_first_layer_convex_hull.points); if (points.size() < 3) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 76dbac263b..d0569ea119 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -173,6 +173,13 @@ static const t_config_enum_values s_keys_map_BrimType = { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BrimType) +static const t_config_enum_values s_keys_map_DraftShield = { + { "disabled", dsDisabled }, + { "limited", dsLimited }, + { "enabled", dsEnabled } +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(DraftShield) + static const t_config_enum_values s_keys_map_ForwardCompatibilitySubstitutionRule = { { "disable", ForwardCompatibilitySubstitutionRule::Disable }, { "enable", ForwardCompatibilitySubstitutionRule::Enable }, @@ -2147,27 +2154,34 @@ void PrintConfigDef::init_fff_params() #endif def = this->add("skirt_distance", coFloat); - def->label = L("Distance from object"); - def->tooltip = L("Distance between skirt and object(s). Set this to zero to attach the skirt " - "to the object(s) and get a brim for better adhesion."); + def->label = L("Distance from brim/object"); + def->tooltip = L("Distance between skirt and brim (when draft shield is not used) or objects."); def->sidetext = L("mm"); def->min = 0; def->set_default_value(new ConfigOptionFloat(6)); def = this->add("skirt_height", coInt); def->label = L("Skirt height"); - def->tooltip = L("Height of skirt expressed in layers. Set this to a tall value to use skirt " - "as a shield against drafts."); + def->tooltip = L("Height of skirt expressed in layers."); def->sidetext = L("layers"); def->mode = comAdvanced; def->set_default_value(new ConfigOptionInt(1)); - def = this->add("draft_shield", coBool); + def = this->add("draft_shield", coEnum); def->label = L("Draft shield"); - def->tooltip = L("If enabled, the skirt will be as tall as a highest printed object. " + def->tooltip = L("With draft shield active, the skirt will be printed skirt_distance from the object, possibly intersecting brim.\n" + "Enabled = skirt is as tall as the highest printed object.\n" + "Limited = skirt is as tall as specified by skirt_height.\n" "This is useful to protect an ABS or ASA print from warping and detaching from print bed due to wind draft."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("disabled"); + def->enum_values.push_back("limited"); + def->enum_values.push_back("enabled"); + def->enum_labels.push_back(L("Disabled")); + def->enum_labels.push_back(L("Limited")); + def->enum_labels.push_back(L("Enabled")); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionBool(false)); + def->set_default_value(new ConfigOptionEnum(dsDisabled)); def = this->add("skirts", coInt); def->label = L("Loops (minimum)"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index efe71822b1..b15651ba70 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -121,6 +121,10 @@ enum BrimType { btOuterAndInner, }; +enum DraftShield { + dsDisabled, dsLimited, dsEnabled +}; + #define CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(NAME) \ template<> const t_config_enum_names& ConfigOptionEnum::get_enum_names(); \ template<> const t_config_enum_values& ConfigOptionEnum::get_enum_values(); @@ -141,6 +145,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SeamPosition) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SLADisplayOrientation) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SLAPillarConnectionMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(BrimType) +CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(DraftShield) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ForwardCompatibilitySubstitutionRule) #undef CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS @@ -689,6 +694,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionBools, cooling)) ((ConfigOptionFloat, default_acceleration)) ((ConfigOptionInts, disable_fan_first_layers)) + ((ConfigOptionEnum, draft_shield)) ((ConfigOptionFloat, duplicate_distance)) ((ConfigOptionFloat, extruder_clearance_height)) ((ConfigOptionFloat, extruder_clearance_radius)) @@ -728,7 +734,6 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionBools, retract_layer_change)) ((ConfigOptionFloat, skirt_distance)) ((ConfigOptionInt, skirt_height)) - ((ConfigOptionBool, draft_shield)) ((ConfigOptionInt, skirts)) ((ConfigOptionInts, slowdown_below_layer_time)) ((ConfigOptionBool, spiral_vase)) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 5596bb6339..47d2831778 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -276,7 +276,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config) toggle_field(el, have_default_acceleration); bool have_skirt = config->opt_int("skirts") > 0; - toggle_field("skirt_height", have_skirt && !config->opt_bool("draft_shield")); + toggle_field("skirt_height", have_skirt && config->opt_enum("draft_shield") != dsEnabled); for (auto el : { "skirt_distance", "draft_shield", "min_skirt_length" }) toggle_field(el, have_skirt); From 49ae88583444bec7c930b9db16f028e6584d8f59 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Jul 2021 09:15:08 +0200 Subject: [PATCH 5/5] Correctly convert legacy bool 'draft_shield' to enum --- src/libslic3r/PrintConfig.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index d0569ea119..d91770d77f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3666,9 +3666,12 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va value = "rectilinear"; } else if (opt_key == "skirt_height" && value == "-1") { // PrusaSlicer no more accepts skirt_height == -1 to print a draft shield to the top of the highest object. - // A new "draft_shield" boolean config value is used instead. + // A new "draft_shield" enum config value is used instead. opt_key = "draft_shield"; - value = "1"; + value = "enabled"; + } else if (opt_key == "draft_shield" && (value == "1" || value == "0")) { + // draft_shield used to be a bool, it was turned into an enum in PrusaSlicer 2.4.0. + value = value == "1" ? "enabled" : "disabled"; } else if (opt_key == "octoprint_host") { opt_key = "print_host"; } else if (opt_key == "octoprint_cafile") {