Skip to content

Commit

Permalink
[CURA-10783] Better management of extruder change during raft printing (
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo authored Oct 30, 2023
2 parents 247b438 + ba8d5c2 commit 1d88e6c
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
const size_t base_extruder_nr = mesh_group_settings.get<ExtruderTrain&>("raft_base_extruder_nr").extruder_nr;
const size_t interface_extruder_nr = mesh_group_settings.get<ExtruderTrain&>("raft_interface_extruder_nr").extruder_nr;
const size_t surface_extruder_nr = mesh_group_settings.get<ExtruderTrain&>("raft_surface_extruder_nr").extruder_nr;
const size_t prime_tower_extruder_nr = storage.primeTower.extruder_order.front();

coord_t z = 0;
const LayerIndex initial_raft_layer_nr = -Raft::getTotalExtraLayers();
Expand Down Expand Up @@ -598,8 +599,6 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
= *new LayerPlan(storage, layer_nr, z, layer_height, base_extruder_nr, fan_speed_layer_time_settings_per_extruder_raft_base, comb_offset, line_width, avoid_distance);
gcode_layer.setIsInside(true);

gcode_layer.setExtruder(base_extruder_nr);

Application::getInstance().communication->sendLayerComplete(layer_nr, z, layer_height);

Polygons raftLines;
Expand Down Expand Up @@ -718,6 +717,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)

for (LayerIndex raft_interface_layer = 1; static_cast<size_t>(raft_interface_layer) <= num_interface_layers; ++raft_interface_layer)
{ // raft interface layer
bool prime_tower_added_on_this_layer = ! storage.primeTower.enabled;
const LayerIndex layer_nr = initial_raft_layer_nr + raft_interface_layer;
z += interface_layer_height;

Expand All @@ -741,10 +741,19 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
comb_offset,
interface_line_width,
interface_avoid_distance);
gcode_layer.setIsInside(true);

current_extruder_nr = interface_extruder_nr;
gcode_layer.setExtruder(current_extruder_nr);
if (! prime_tower_added_on_this_layer && current_extruder_nr == prime_tower_extruder_nr)
{
addPrimeTower(storage, gcode_layer, current_extruder_nr);
prime_tower_added_on_this_layer = true;
}

gcode_layer.setIsInside(true);
if (interface_extruder_nr != current_extruder_nr)
{
setExtruder_addPrime(storage, gcode_layer, interface_extruder_nr);
current_extruder_nr = interface_extruder_nr;
}

Application::getInstance().communication->sendLayerComplete(layer_nr, z, interface_layer_height);

Expand Down Expand Up @@ -806,7 +815,11 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
raft_polygons.clear();
raft_lines.clear();

setExtruder_addPrime(storage, gcode_layer, storage.primeTower.extruder_order.front());
if (! prime_tower_added_on_this_layer)
{
setExtruder_addPrime(storage, gcode_layer, prime_tower_extruder_nr);
current_extruder_nr = prime_tower_extruder_nr;
}

layer_plan_buffer.handle(gcode_layer, gcode);
last_planned_position = gcode_layer.getLastPlannedPositionOrStartingPosition();
Expand All @@ -822,6 +835,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)

for (LayerIndex raft_surface_layer = 1; static_cast<size_t>(raft_surface_layer) <= num_surface_layers; raft_surface_layer++)
{ // raft surface layers
bool prime_tower_added_on_this_layer = ! storage.primeTower.enabled;
const LayerIndex layer_nr = initial_raft_layer_nr + 1 + num_interface_layers + raft_surface_layer - 1; // +1: 1 base layer
z += surface_layer_height;

Expand All @@ -845,11 +859,21 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
comb_offset,
surface_line_width,
surface_avoid_distance);

if (! prime_tower_added_on_this_layer && current_extruder_nr == prime_tower_extruder_nr)
{
addPrimeTower(storage, gcode_layer, current_extruder_nr);
prime_tower_added_on_this_layer = true;
}

gcode_layer.setIsInside(true);

// make sure that we are using the correct extruder to print raft
current_extruder_nr = surface_extruder_nr;
gcode_layer.setExtruder(current_extruder_nr);
if (current_extruder_nr != surface_extruder_nr)
{
setExtruder_addPrime(storage, gcode_layer, surface_extruder_nr);
current_extruder_nr = surface_extruder_nr;
}
Application::getInstance().communication->sendLayerComplete(layer_nr, z, surface_layer_height);

Polygons raft_outline_path;
Expand Down Expand Up @@ -911,7 +935,11 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
raft_polygons.clear();
raft_lines.clear();

setExtruder_addPrime(storage, gcode_layer, storage.primeTower.extruder_order.front());
if (! prime_tower_added_on_this_layer)
{
setExtruder_addPrime(storage, gcode_layer, prime_tower_extruder_nr);
current_extruder_nr = prime_tower_extruder_nr;
}

layer_plan_buffer.handle(gcode_layer, gcode);
}
Expand Down Expand Up @@ -3655,8 +3683,6 @@ bool FffGcodeWriter::addSupportBottomsToGCode(const SliceDataStorage& storage, L

void FffGcodeWriter::setExtruder_addPrime(const SliceDataStorage& storage, LayerPlan& gcode_layer, const size_t extruder_nr) const
{
const size_t outermost_prime_tower_extruder = storage.primeTower.extruder_order[0];

const size_t previous_extruder = gcode_layer.getExtruder();
const bool extruder_changed = gcode_layer.setExtruder(extruder_nr);

Expand Down

0 comments on commit 1d88e6c

Please sign in to comment.