Skip to content

Commit

Permalink
fixes, parallel_object_step now works with part instances
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jan 16, 2024
2 parents b6d41ca + 41d775d commit 8f26e8f
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 106 deletions.
8 changes: 4 additions & 4 deletions resources/ui_layout/default/print.ui
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,22 @@ group:Extrusion width
line:perimeter
setting:sidetext_width$10:label$width:perimeter_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:perimeter_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:perimeter_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:perimeter_extrusion_change_odd_layers
end_line
line:external perimeter
setting:sidetext_width$10:label$width:external_perimeter_extrusion_width
setting:sidetext_width$10:label_width$15:label$width&spacing combo:external_perimeter_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:external_perimeter_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:external_perimeter_extrusion_change_odd_layers
end_line
line:infill
setting:sidetext_width$10:label$width:infill_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:infill_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:infill_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:infill_extrusion_change_odd_layers
end_line
line:solid infill
setting:sidetext_width$10:label$width:solid_infill_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:solid_infill_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:solid_infill_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:solid_infill_extrusion_change_odd_layers
end_line
line:top infill
setting:sidetext_width$10:label$width:top_infill_extrusion_width
Expand Down
8 changes: 4 additions & 4 deletions resources/ui_layout/example/print.ui
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,22 @@ group:Extrusion width
line:perimeter
setting:sidetext_width$10:label$width:perimeter_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:perimeter_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:perimeter_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:perimeter_extrusion_change_odd_layers
end_line
line:external perimeter
setting:sidetext_width$10:label$width:external_perimeter_extrusion_width
setting:sidetext_width$10:label_width$15:label$width&spacing combo:external_perimeter_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:external_perimeter_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:external_perimeter_extrusion_change_odd_layers
end_line
line:infill
setting:sidetext_width$10:label$width:infill_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:infill_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:infill_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:infill_extrusion_change_odd_layers
end_line
line:solid infill
setting:sidetext_width$10:label$width:solid_infill_extrusion_width
setting:sidetext_width$10:label_width$15:label$spacing:solid_infill_extrusion_spacing
setting:sidetext_width$10:label_width$15:label$odd layers:solid_infill_extrusion_change_odd_layers
setting:sidetext_width$10:label_width$15:label$even layers:solid_infill_extrusion_change_odd_layers
end_line
line:top infill
setting:sidetext_width$10:label$width:top_infill_extrusion_width
Expand Down
30 changes: 29 additions & 1 deletion src/libslic3r/Fill/Fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,45 @@ struct SurfaceFillParams : FillParams
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, connection);
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_adjust);

RETURN_COMPARE_NON_EQUAL(anchor_length); RETURN_COMPARE_NON_EQUAL(fill_exactly);
RETURN_COMPARE_NON_EQUAL(anchor_length);
RETURN_COMPARE_NON_EQUAL(fill_exactly);
RETURN_COMPARE_NON_EQUAL(flow.width());
RETURN_COMPARE_NON_EQUAL(flow.height());
RETURN_COMPARE_NON_EQUAL(flow.nozzle_diameter());
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, flow.bridge());
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, role);
RETURN_COMPARE_NON_EQUAL_TYPED(int32_t, priority);
assert(this->config != nullptr);
assert(rhs.config != nullptr);
if (config != nullptr && rhs.config != nullptr) {
RETURN_COMPARE_NON_EQUAL(config->infill_speed);
RETURN_COMPARE_NON_EQUAL(config->solid_infill_speed);
RETURN_COMPARE_NON_EQUAL(config->top_solid_infill_speed);
RETURN_COMPARE_NON_EQUAL(config->ironing_speed);
RETURN_COMPARE_NON_EQUAL(config->default_speed);
RETURN_COMPARE_NON_EQUAL(config->bridge_speed);
RETURN_COMPARE_NON_EQUAL(config->bridge_speed_internal);
RETURN_COMPARE_NON_EQUAL(config->gap_fill_speed);
}
assert(*this == rhs);
return false;
}

bool operator==(const SurfaceFillParams &rhs) const {
// first check speed via config
if ((config != nullptr) != (rhs.config != nullptr))
return false;
if(config != nullptr && (
config->infill_speed != rhs.config->infill_speed
|| config->solid_infill_speed != rhs.config->solid_infill_speed
|| config->top_solid_infill_speed != rhs.config->top_solid_infill_speed
|| config->ironing_speed != rhs.config->ironing_speed
|| config->default_speed != rhs.config->default_speed
|| config->bridge_speed != rhs.config->bridge_speed
|| config->bridge_speed_internal != rhs.config->bridge_speed_internal
|| config->gap_fill_speed != rhs.config->gap_fill_speed))
return false;
// then check params
return this->extruder == rhs.extruder &&
this->pattern == rhs.pattern &&
this->spacing == rhs.spacing &&
Expand Down
122 changes: 60 additions & 62 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ void GCode::_do_export(Print& print_mod, GCodeOutputStream &file, ThumbnailsGene
}
}
}
if (print.config().complete_objects.value) {
if (print.config().complete_objects.value || print.config().parallel_objects_step.value > 0) {
// Order object instances for sequential print.
if(print.config().complete_objects_sort.value == cosObject)
print_object_instances_ordering = sort_object_instances_by_model_order(print);
Expand Down Expand Up @@ -1848,24 +1848,7 @@ void GCode::_do_export(Print& print_mod, GCodeOutputStream &file, ThumbnailsGene
print.throw_if_canceled();
this->set_origin(unscale((*print_object_instance_sequential_active)->shift));
if (finished_objects > 0) {
// Move to the origin position for the copy we're going to print.
// This happens before Z goes down to layer 0 again, so that no collision happens hopefully.
m_enable_cooling_markers = false; // we're not filtering these moves through CoolingBuffer
m_avoid_crossing_perimeters.use_external_mp_once();
set_extra_lift(m_last_layer_z, 0, print.config(), m_writer, initial_extruder_id);
file.write(this->retract());
std::string gcode;
//go to origin of the next object (it's 0,0 because we shifted the origin to it)
Polyline polyline = this->travel_to(gcode, Point(0, 0), erTravel);
this->write_travel_to(gcode, polyline, "move to origin position for next object");
file.write(gcode);
m_enable_cooling_markers = true;
// Disable motion planner when traveling to first object point.
m_avoid_crossing_perimeters.disable_once();
// Ff we are printing the bottom layer of an object, and we have already finished
// another one, set first layer temperatures. This happens before the Z move
// is triggered, so machine has more time to reach such temperatures.
m_placeholder_parser.set("current_object_idx", int(finished_objects));
_move_to_print_object(file, print, finished_objects, initial_extruder_id);
std::string between_objects_gcode = this->placeholder_parser_process("between_objects_gcode", print.config().between_objects_gcode.value, initial_extruder_id);
// Set first layer bed and extruder temperatures, don't wait for it to reach the temperature.
this->_print_first_layer_bed_temperature(file, print, between_objects_gcode, initial_extruder_id, false);
Expand Down Expand Up @@ -1894,57 +1877,50 @@ void GCode::_do_export(Print& print_mod, GCodeOutputStream &file, ThumbnailsGene
} else {
/////////////////////////////////////////////// begin parallel_objects_step
if (print.config().parallel_objects_step > 0 && !has_wipe_tower) {

float range = print.config().parallel_objects_step + EPSILON;
print_object_instances_ordering = sort_object_instances_by_model_order(print);
std::vector<const PrintInstance*>::const_iterator prev_object = print_object_instances_ordering.begin();

bool first_layer = true;
proceed_layers:
double range = std::min(print.config().parallel_objects_step, print.config().extruder_clearance_height) + EPSILON;
print_object_instances_ordering = chain_print_object_instances(print);
bool first_layers = true;

for (coordf_t Rstart = 0, Rend = range;; Rstart += range, Rend += range) {
proceed_layers:
bool is_layers = false;
print_object_instance_sequential_active = print_object_instances_ordering.begin();

for (size_t i = 0; i < print.objects().size(); ++i, ++print_object_instance_sequential_active) {
std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> layers_to_print_range;
{
std::vector<LayerToPrint> object_layers = collect_layers_to_print(*print.objects()[i], status_monitor);
int layer_num = 0;
for (LayerToPrint& ltp : object_layers) {
layer_num++;
if (!first_layer && layer_num == 1)
continue;

if (ltp.print_z() >= Rstart && ltp.print_z() < Rend) {
std::pair<coordf_t, std::vector<LayerToPrint>> merged;
merged.first = ltp.print_z();
merged.second.push_back(std::move(ltp));
layers_to_print_range.emplace_back(merged);
if (first_layer)
break;
}
}
for (auto it_print_object_instance = print_object_instances_ordering.begin();
it_print_object_instance != print_object_instances_ordering.end();
++it_print_object_instance) {
std::vector<LayerToPrint> layers_to_print_range;
const PrintObject & object = *(*it_print_object_instance)->print_object;
std::vector<LayerToPrint> object_layers = collect_layers_to_print(object, status_monitor);

for (const LayerToPrint &ltp : object_layers) {
if (ltp.print_z() < Rstart || ltp.print_z() >= Rend)
continue;

if (!first_layers && ltp.layer()->id() == 0)
continue;

layers_to_print_range.push_back(ltp);
if (first_layers)
break;
}

if (!layers_to_print_range.empty())
{
if (print_object_instance_sequential_active != prev_object) {
this->set_origin(unscale((*print_object_instance_sequential_active)->shift));
std::string gcode;
//go to origin of the next object (it's 0,0 because we shifted the origin to it)
Polyline polyline = this->travel_to(gcode, Point(0, 0), erTravel);
this->write_travel_to(gcode, polyline, "move to origin position for next object");
file.write(gcode);
}
this->process_layers(print, status_monitor, tool_ordering, print_object_instances_ordering,
layers_to_print_range, file);
prev_object = print_object_instance_sequential_active;
if (!layers_to_print_range.empty()) {
this->set_origin(unscale((*it_print_object_instance)->shift));

size_t finished_objects = 1 + (it_print_object_instance -
print_object_instances_ordering.begin());
if (finished_objects > 1)
_move_to_print_object(file, print, finished_objects, initial_extruder_id);

assert(!object.instances().empty());
assert(*it_print_object_instance >= &*object.instances().begin() &&
*it_print_object_instance <= &*(object.instances().end()-1));
this->process_layers(print, status_monitor, tool_ordering, layers_to_print_range,
*it_print_object_instance - object.instances().data(), file);
is_layers = true;
}
}
if (first_layer) {
first_layer = false;
if (first_layers) {
first_layers = false;
goto proceed_layers;
}
if (!is_layers) {
Expand Down Expand Up @@ -2107,6 +2083,28 @@ void GCode::_do_export(Print& print_mod, GCodeOutputStream &file, ThumbnailsGene
print.throw_if_canceled();
}

void GCode::_move_to_print_object(GCodeOutputStream& file, const Print& print, size_t finished_objects, uint16_t initial_extruder_id)
{
// Move to the origin position for the copy we're going to print.
// This happens before Z goes down to layer 0 again, so that no collision happens hopefully.
m_enable_cooling_markers = false; // we're not filtering these moves through CoolingBuffer
m_avoid_crossing_perimeters.use_external_mp_once();
set_extra_lift(m_last_layer_z, 0, print.config(), m_writer, initial_extruder_id);
file.write(this->retract());
std::string gcode;
//go to origin of the next object (it's 0,0 because we shifted the origin to it)
Polyline polyline = this->travel_to(gcode, Point(0, 0), erTravel);
this->write_travel_to(gcode, polyline, "move to origin position for next object");
file.write(gcode);
m_enable_cooling_markers = true;
// Disable motion planner when traveling to first object point.
m_avoid_crossing_perimeters.disable_once();
// Ff we are printing the bottom layer of an object, and we have already finished
// another one, set first layer temperatures. This happens before the Z move
// is triggered, so machine has more time to reach such temperatures.
m_placeholder_parser.set("current_object_idx", int(finished_objects));
}

// For unknown reasons and in sporadic cases when GCode export is processing, some participating thread
// in tbb::parallel_pipeline has not set locales to "C", probably because this thread is newly spawned.
// So in this class method on_scheduler_entry is called for every thread before it starts participating
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class GCode : ExtrusionVisitorConst {
GCode &m_gcodegen;
};
void _do_export(Print &print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb);

void _move_to_print_object(GCodeOutputStream& file, const Print& print, size_t finished_objects, uint16_t initial_extruder_id);
void _init_multiextruders(const Print& print, GCodeOutputStream& file, GCodeWriter& writer, const ToolOrdering& tool_ordering, const std::string& custom_gcode);

static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object, Print::StatusMonitor &status_monitor);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ ProcessSurfaceResult PerimeterGenerator::process_arachne(int& loop_number, const
// svg.draw(to_polylines(last), "brown");
// svg.Close();
//}
loop_number = 0;
loop_number--;
} else {
// Give up the outer shell because we don't have any meaningful top surface
out_shell.clear();
Expand Down
Loading

0 comments on commit 8f26e8f

Please sign in to comment.