diff --git a/include/ExtruderPlan.h b/include/ExtruderPlan.h index cfd2070975..e4d301969a 100644 --- a/include/ExtruderPlan.h +++ b/include/ExtruderPlan.h @@ -124,6 +124,11 @@ class ExtruderPlan */ void applyBackPressureCompensation(const Ratio back_pressure_compensation); + /*! + * Gets the mesh being printed first on this plan + */ + std::shared_ptr findFirstPrintedMesh() const; + private: LayerIndex layer_nr_{ 0 }; //!< The layer number at which we are currently printing. bool is_initial_layer_{ false }; //!< Whether this extruder plan is printed on the very first layer (which might be raft) diff --git a/include/LayerPlan.h b/include/LayerPlan.h index 387d1e9564..47cea1aa19 100644 --- a/include/LayerPlan.h +++ b/include/LayerPlan.h @@ -761,6 +761,11 @@ class LayerPlan : public NoCopy */ void applyGradualFlow(); + /*! + * Gets the mesh being printed first on this layer + */ + std::shared_ptr findFirstPrintedMesh() const; + private: /*! * \brief Compute the preferred or minimum combing boundary diff --git a/src/ExtruderPlan.cpp b/src/ExtruderPlan.cpp index b492abc23e..58a6bb3f86 100644 --- a/src/ExtruderPlan.cpp +++ b/src/ExtruderPlan.cpp @@ -70,4 +70,18 @@ void ExtruderPlan::applyBackPressureCompensation(const Ratio back_pressure_compe path.speed_back_pressure_factor = std::max(epsilon_speed_factor, 1.0 + (nominal_width_for_path / line_width_for_path - 1.0) * back_pressure_compensation); } } + +std::shared_ptr ExtruderPlan::findFirstPrintedMesh() const +{ + for (const GCodePath& path : paths_) + { + if (path.mesh) + { + return path.mesh; + } + } + + return nullptr; +} + } // namespace cura diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index f8fe3031f1..927e4357f7 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -3095,6 +3095,19 @@ void LayerPlan::applyGradualFlow() } } +std::shared_ptr LayerPlan::findFirstPrintedMesh() const +{ + for (const ExtruderPlan& extruder_plan : extruder_plans_) + { + if (std::shared_ptr mesh = extruder_plan.findFirstPrintedMesh()) + { + return mesh; + } + } + + return nullptr; +} + LayerIndex LayerPlan::getLayerNr() const { return layer_nr_; diff --git a/src/LayerPlanBuffer.cpp b/src/LayerPlanBuffer.cpp index 426c077055..4001f0837c 100644 --- a/src/LayerPlanBuffer.cpp +++ b/src/LayerPlanBuffer.cpp @@ -99,10 +99,21 @@ void LayerPlanBuffer::addConnectingTravelMove(LayerPlan* prev_layer, const Layer const Settings& mesh_group_settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings; const Settings& extruder_settings = Application::getInstance().current_slice_->scene.extruders[prev_layer->extruder_plans_.back().extruder_nr_].settings_; prev_layer->setIsInside(new_layer_destination_state->second); - const bool force_retract = extruder_settings.get("retract_at_layer_change") - || (mesh_group_settings.get("travel_retract_before_outer_wall") - && (mesh_group_settings.get("inset_direction") == InsetDirection::OUTSIDE_IN - || mesh_group_settings.get("wall_line_count") == 1)); // Moving towards an outer wall. + + const bool travel_retract_before_outer_wall = mesh_group_settings.get("travel_retract_before_outer_wall"); + const bool retract_at_layer_change = extruder_settings.get("retract_at_layer_change"); + bool next_mesh_retract_before_outer_wall = false; + std::shared_ptr first_printed_mesh = newest_layer->findFirstPrintedMesh(); + if (! retract_at_layer_change && first_printed_mesh && travel_retract_before_outer_wall) + { + // Check whether we are moving toving towards an outer wall and it should be retracted + const Settings& mesh_settings = first_printed_mesh->settings; + const InsetDirection inset_direction = mesh_settings.get("inset_direction"); + const size_t wall_line_count = mesh_settings.get("wall_line_count"); + + next_mesh_retract_before_outer_wall = inset_direction == InsetDirection::OUTSIDE_IN || wall_line_count == 1; + } + const bool force_retract = retract_at_layer_change || next_mesh_retract_before_outer_wall; prev_layer->final_travel_z_ = newest_layer->z_; GCodePath& path = prev_layer->addTravel(first_location_new_layer, force_retract); if (force_retract && ! path.retract)