Fixed tool ordering for sequential prints.

This commit is contained in:
bubnikv 2017-05-17 19:25:36 +02:00
parent 34747b2015
commit fdff937cb2
3 changed files with 33 additions and 21 deletions

View file

@ -297,21 +297,28 @@ bool GCode::do_export(FILE *file, Print &print)
// For a print by objects, find the 1st printing object. // For a print by objects, find the 1st printing object.
std::vector<ToolOrdering::LayerTools> tool_ordering; std::vector<ToolOrdering::LayerTools> tool_ordering;
unsigned int initial_extruder_id = (unsigned int)-1; unsigned int initial_extruder_id = (unsigned int)-1;
unsigned int final_extruder_id = (unsigned int)-1;
size_t initial_print_object_id = 0; size_t initial_print_object_id = 0;
if (print.config.complete_objects.value) { if (print.config.complete_objects.value) {
// Find the 1st printing object, find its tool ordering and the initial extruder ID. // Find the 1st printing object, find its tool ordering and the initial extruder ID.
for (; initial_print_object_id < print.objects.size() && initial_extruder_id == (unsigned int)-1; ++initial_print_object_id) { for (; initial_print_object_id < print.objects.size(); ++initial_print_object_id) {
tool_ordering = ToolOrdering::tool_ordering(*print.objects[initial_print_object_id], initial_extruder_id); tool_ordering = ToolOrdering::tool_ordering(*print.objects[initial_print_object_id], initial_extruder_id);
initial_extruder_id = ToolOrdering::first_extruder(tool_ordering); if ((initial_extruder_id = ToolOrdering::first_extruder(tool_ordering)) != (unsigned int)-1)
break;
} }
} else { } else {
// Find tool ordering for all the objects at once, and the initial extruder ID. // Find tool ordering for all the objects at once, and the initial extruder ID.
tool_ordering = ToolOrdering::tool_ordering(print, initial_extruder_id); tool_ordering = ToolOrdering::tool_ordering(print, initial_extruder_id);
initial_extruder_id = ToolOrdering::first_extruder(tool_ordering); initial_extruder_id = ToolOrdering::first_extruder(tool_ordering);
} }
if (initial_extruder_id == (unsigned int)-1) if (initial_extruder_id == (unsigned int)-1) {
// Nothing to print! // Nothing to print!
initial_extruder_id = 0; initial_extruder_id = 0;
final_extruder_id = 0;
} else {
final_extruder_id = ToolOrdering::last_extruder(tool_ordering);
assert(final_extruder_id != (unsigned int)-1);
}
// Set extruder(s) temperature before and after start G-code. // Set extruder(s) temperature before and after start G-code.
this->_print_first_layer_extruder_temperatures(file, print, initial_extruder_id, false); this->_print_first_layer_extruder_temperatures(file, print, initial_extruder_id, false);
@ -392,12 +399,14 @@ bool GCode::do_export(FILE *file, Print &print)
// Get optimal tool ordering to minimize tool switches of a multi-exruder print. // Get optimal tool ordering to minimize tool switches of a multi-exruder print.
if (object_id != initial_print_object_id || &copy != object._shifted_copies.data()) { if (object_id != initial_print_object_id || &copy != object._shifted_copies.data()) {
// Don't initialize for the first object and first copy. // Don't initialize for the first object and first copy.
tool_ordering = ToolOrdering::tool_ordering(object, initial_extruder_id); tool_ordering = ToolOrdering::tool_ordering(object, final_extruder_id);
unsigned int new_extruder_id = ToolOrdering::first_extruder(tool_ordering); unsigned int new_extruder_id = ToolOrdering::first_extruder(tool_ordering);
if (new_extruder_id == (unsigned int)-1) if (new_extruder_id == (unsigned int)-1)
// Skip this object. // Skip this object.
continue; continue;
initial_extruder_id = new_extruder_id; initial_extruder_id = new_extruder_id;
final_extruder_id = ToolOrdering::last_extruder(tool_ordering);
assert(final_extruder_id != (unsigned int)-1);
} }
this->set_origin(unscale(copy.x), unscale(copy.y)); this->set_origin(unscale(copy.x), unscale(copy.y));
if (finished_objects > 0) { if (finished_objects > 0) {

View file

@ -208,7 +208,7 @@ unsigned int first_extruder(const std::vector<LayerTools> &layer_tools)
unsigned int last_extruder(const std::vector<LayerTools> &layer_tools) unsigned int last_extruder(const std::vector<LayerTools> &layer_tools)
{ {
for (auto lt_it = layer_tools.rend(); lt_it != layer_tools.rbegin(); ++ lt_it) for (auto lt_it = layer_tools.rbegin(); lt_it != layer_tools.rend(); ++ lt_it)
if (! lt_it->extruders.empty()) if (! lt_it->extruders.empty())
return lt_it->extruders.back(); return lt_it->extruders.back();
return (unsigned int)-1; return (unsigned int)-1;

View file

@ -211,6 +211,8 @@ convex_hull(Points points)
int n = points.size(), k = 0; int n = points.size(), k = 0;
Polygon hull; Polygon hull;
if (n >= 3) {
hull.points.resize(2*n); hull.points.resize(2*n);
// Build lower hull // Build lower hull
@ -229,6 +231,7 @@ convex_hull(Points points)
assert( hull.points.front().coincides_with(hull.points.back()) ); assert( hull.points.front().coincides_with(hull.points.back()) );
hull.points.pop_back(); hull.points.pop_back();
}
return hull; return hull;
} }