Skip to content

Commit d9a2afc

Browse files
authored
Cura 12275 retract before outer wall only works on the initial layer (#2172)
2 parents f32cb0f + 57f8e1d commit d9a2afc

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

include/ExtruderPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class ExtruderPlan
124124
*/
125125
void applyBackPressureCompensation(const Ratio back_pressure_compensation);
126126

127+
/*!
128+
* Gets the mesh being printed first on this plan
129+
*/
130+
std::shared_ptr<const SliceMeshStorage> findFirstPrintedMesh() const;
131+
127132
private:
128133
LayerIndex layer_nr_{ 0 }; //!< The layer number at which we are currently printing.
129134
bool is_initial_layer_{ false }; //!< Whether this extruder plan is printed on the very first layer (which might be raft)

include/LayerPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,11 @@ class LayerPlan : public NoCopy
761761
*/
762762
void applyGradualFlow();
763763

764+
/*!
765+
* Gets the mesh being printed first on this layer
766+
*/
767+
std::shared_ptr<const SliceMeshStorage> findFirstPrintedMesh() const;
768+
764769
private:
765770
/*!
766771
* \brief Compute the preferred or minimum combing boundary

src/ExtruderPlan.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,18 @@ void ExtruderPlan::applyBackPressureCompensation(const Ratio back_pressure_compe
7070
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);
7171
}
7272
}
73+
74+
std::shared_ptr<const SliceMeshStorage> ExtruderPlan::findFirstPrintedMesh() const
75+
{
76+
for (const GCodePath& path : paths_)
77+
{
78+
if (path.mesh)
79+
{
80+
return path.mesh;
81+
}
82+
}
83+
84+
return nullptr;
85+
}
86+
7387
} // namespace cura

src/LayerPlan.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,6 +3095,19 @@ void LayerPlan::applyGradualFlow()
30953095
}
30963096
}
30973097

3098+
std::shared_ptr<const SliceMeshStorage> LayerPlan::findFirstPrintedMesh() const
3099+
{
3100+
for (const ExtruderPlan& extruder_plan : extruder_plans_)
3101+
{
3102+
if (std::shared_ptr<const SliceMeshStorage> mesh = extruder_plan.findFirstPrintedMesh())
3103+
{
3104+
return mesh;
3105+
}
3106+
}
3107+
3108+
return nullptr;
3109+
}
3110+
30983111
LayerIndex LayerPlan::getLayerNr() const
30993112
{
31003113
return layer_nr_;

src/LayerPlanBuffer.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,21 @@ void LayerPlanBuffer::addConnectingTravelMove(LayerPlan* prev_layer, const Layer
9999
const Settings& mesh_group_settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings;
100100
const Settings& extruder_settings = Application::getInstance().current_slice_->scene.extruders[prev_layer->extruder_plans_.back().extruder_nr_].settings_;
101101
prev_layer->setIsInside(new_layer_destination_state->second);
102-
const bool force_retract = extruder_settings.get<bool>("retract_at_layer_change")
103-
|| (mesh_group_settings.get<bool>("travel_retract_before_outer_wall")
104-
&& (mesh_group_settings.get<InsetDirection>("inset_direction") == InsetDirection::OUTSIDE_IN
105-
|| mesh_group_settings.get<size_t>("wall_line_count") == 1)); // Moving towards an outer wall.
102+
103+
const bool travel_retract_before_outer_wall = mesh_group_settings.get<bool>("travel_retract_before_outer_wall");
104+
const bool retract_at_layer_change = extruder_settings.get<bool>("retract_at_layer_change");
105+
bool next_mesh_retract_before_outer_wall = false;
106+
std::shared_ptr<const SliceMeshStorage> first_printed_mesh = newest_layer->findFirstPrintedMesh();
107+
if (! retract_at_layer_change && first_printed_mesh && travel_retract_before_outer_wall)
108+
{
109+
// Check whether we are moving toving towards an outer wall and it should be retracted
110+
const Settings& mesh_settings = first_printed_mesh->settings;
111+
const InsetDirection inset_direction = mesh_settings.get<InsetDirection>("inset_direction");
112+
const size_t wall_line_count = mesh_settings.get<size_t>("wall_line_count");
113+
114+
next_mesh_retract_before_outer_wall = inset_direction == InsetDirection::OUTSIDE_IN || wall_line_count == 1;
115+
}
116+
const bool force_retract = retract_at_layer_change || next_mesh_retract_before_outer_wall;
106117
prev_layer->final_travel_z_ = newest_layer->z_;
107118
GCodePath& path = prev_layer->addTravel(first_location_new_layer, force_retract);
108119
if (force_retract && ! path.retract)

0 commit comments

Comments
 (0)