Merge remote-tracking branch 'origin/master' into ys_cp_improvements

This commit is contained in:
YuSanka 2020-01-16 14:02:19 +01:00
commit 099118d6f2
5 changed files with 77 additions and 13 deletions

View File

@ -1222,9 +1222,8 @@ void GCode::_do_export(Print& print, FILE* file)
} 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.
// If the tool ordering has been pre-calculated by Print class for wipe tower already, reuse it. // If the tool ordering has been pre-calculated by Print class for wipe tower already, reuse it.
tool_ordering = print.wipe_tower_data().tool_ordering.empty() ? tool_ordering = print.tool_ordering();
ToolOrdering(print, initial_extruder_id, false) : tool_ordering.assign_custom_gcodes(print);
print.wipe_tower_data().tool_ordering;
has_wipe_tower = print.has_wipe_tower() && tool_ordering.has_wipe_tower(); has_wipe_tower = print.has_wipe_tower() && tool_ordering.has_wipe_tower();
initial_extruder_id = (has_wipe_tower && ! print.config().single_extruder_multi_material_priming) ? initial_extruder_id = (has_wipe_tower && ! print.config().single_extruder_multi_material_priming) ?
// The priming towers will be skipped. // The priming towers will be skipped.

View File

@ -129,8 +129,12 @@ ToolOrdering::ToolOrdering(const Print &print, unsigned int first_extruder, bool
// Use the extruder switches from Model::custom_gcode_per_print_z to override the extruder to print the object. // Use the extruder switches from Model::custom_gcode_per_print_z to override the extruder to print the object.
// Do it only if all the objects were configured to be printed with a single extruder. // Do it only if all the objects were configured to be printed with a single extruder.
std::vector<std::pair<double, unsigned int>> per_layer_extruder_switches; std::vector<std::pair<double, unsigned int>> per_layer_extruder_switches;
if (print.object_extruders().size() == 1) if (auto num_extruders = unsigned(print.config().nozzle_diameter.size());
per_layer_extruder_switches = custom_tool_changes(print.model(), (unsigned int)print.config().nozzle_diameter.size()); num_extruders > 1 && print.object_extruders().size() == 1) {
// Printing a single extruder platter on a printer with more than 1 extruder (or single-extruder multi-material).
// There may be custom per-layer tool changes available at the model.
per_layer_extruder_switches = custom_tool_changes(print.model(), num_extruders);
}
// Collect extruders reuqired to print the layers. // Collect extruders reuqired to print the layers.
for (auto object : print.objects()) for (auto object : print.objects())
@ -460,6 +464,9 @@ void ToolOrdering::collect_extruder_statistics(bool prime_multi_material)
// If multiple events are planned over a span of a single layer, use the last one. // If multiple events are planned over a span of a single layer, use the last one.
void ToolOrdering::assign_custom_gcodes(const Print &print) void ToolOrdering::assign_custom_gcodes(const Print &print)
{ {
// Only valid for non-sequential print.
assert(! print.config().complete_objects.value);
const std::vector<Model::CustomGCode> &custom_gcode_per_print_z = print.model().custom_gcode_per_print_z; const std::vector<Model::CustomGCode> &custom_gcode_per_print_z = print.model().custom_gcode_per_print_z;
if (custom_gcode_per_print_z.empty()) if (custom_gcode_per_print_z.empty())
return; return;
@ -467,6 +474,8 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
unsigned int num_extruders = *std::max_element(m_all_printing_extruders.begin(), m_all_printing_extruders.end()) + 1; unsigned int num_extruders = *std::max_element(m_all_printing_extruders.begin(), m_all_printing_extruders.end()) + 1;
std::vector<unsigned char> extruder_printing_above(num_extruders, false); std::vector<unsigned char> extruder_printing_above(num_extruders, false);
auto custom_gcode_it = custom_gcode_per_print_z.rbegin(); auto custom_gcode_it = custom_gcode_per_print_z.rbegin();
// If printing on a single extruder machine, make the tool changes trigger color change (M600) events.
bool tool_changes_as_color_changes = num_extruders == 1;
// From the last layer to the first one: // From the last layer to the first one:
for (auto it_lt = m_layer_tools.rbegin(); it_lt != m_layer_tools.rend(); ++ it_lt) { for (auto it_lt = m_layer_tools.rbegin(); it_lt != m_layer_tools.rend(); ++ it_lt) {
LayerTools &lt = *it_lt; LayerTools &lt = *it_lt;
@ -486,7 +495,7 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
print_z_below = it_lt_below->print_z; print_z_below = it_lt_below->print_z;
if (custom_gcode.print_z > print_z_below + 0.5 * EPSILON) { if (custom_gcode.print_z > print_z_below + 0.5 * EPSILON) {
// The custom G-code applies to the current layer. // The custom G-code applies to the current layer.
if ( custom_gcode.gcode != ColorChangeCode || if ( tool_changes_as_color_changes || custom_gcode.gcode != ColorChangeCode ||
(custom_gcode.extruder <= num_extruders && extruder_printing_above[unsigned(custom_gcode.extruder - 1)])) (custom_gcode.extruder <= num_extruders && extruder_printing_above[unsigned(custom_gcode.extruder - 1)]))
// If it is color change, it will actually be useful as the exturder above will print. // If it is color change, it will actually be useful as the exturder above will print.
lt.custom_gcode = &custom_gcode; lt.custom_gcode = &custom_gcode;

View File

@ -143,6 +143,12 @@ public:
void clear() { m_layer_tools.clear(); } void clear() { m_layer_tools.clear(); }
// Only valid for non-sequential print:
// Assign a pointer to a custom G-code to the respective ToolOrdering::LayerTools.
// Ignore color changes, which are performed on a layer and for such an extruder, that the extruder will not be printing above that layer.
// If multiple events are planned over a span of a single layer, use the last one.
void assign_custom_gcodes(const Print &print);
// Get the first extruder printing, including the extruder priming areas, returns -1 if there is no layer printed. // Get the first extruder printing, including the extruder priming areas, returns -1 if there is no layer printed.
unsigned int first_extruder() const { return m_first_printing_extruder; } unsigned int first_extruder() const { return m_first_printing_extruder; }
@ -170,7 +176,6 @@ private:
void reorder_extruders(unsigned int last_extruder_id); void reorder_extruders(unsigned int last_extruder_id);
void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z); void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z);
void collect_extruder_statistics(bool prime_multi_material); void collect_extruder_statistics(bool prime_multi_material);
void assign_custom_gcodes(const Print &print);
std::vector<LayerTools> m_layer_tools; std::vector<LayerTools> m_layer_tools;
// First printing extruder, including the multi-material priming sequence. // First printing extruder, including the multi-material priming sequence.

View File

@ -478,7 +478,7 @@ static std::vector<PrintInstances> print_objects_from_model_object(const ModelOb
// Compare just the layer ranges and their layer heights, not the associated configs. // Compare just the layer ranges and their layer heights, not the associated configs.
// Ignore the layer heights if check_layer_heights is false. // Ignore the layer heights if check_layer_heights is false.
bool layer_height_ranges_equal(const t_layer_config_ranges &lr1, const t_layer_config_ranges &lr2, bool check_layer_height) static bool layer_height_ranges_equal(const t_layer_config_ranges &lr1, const t_layer_config_ranges &lr2, bool check_layer_height)
{ {
if (lr1.size() != lr2.size()) if (lr1.size() != lr2.size())
return false; return false;
@ -493,6 +493,37 @@ bool layer_height_ranges_equal(const t_layer_config_ranges &lr1, const t_layer_c
return true; return true;
} }
// Returns true if va == vb when all CustomGCode items that are not ExtruderChangeCode are ignored.
static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Model::CustomGCode> &va, const std::vector<Model::CustomGCode> &vb)
{
auto it_a = va.begin();
auto it_b = vb.begin();
while (it_a != va.end() && it_b != vb.end()) {
if (it_a != va.end() && it_a->gcode != ExtruderChangeCode) {
// Skip any CustomGCode items, which are not tool changes.
++ it_a;
continue;
}
if (it_b != vb.end() && it_b->gcode != ExtruderChangeCode) {
// Skip any CustomGCode items, which are not tool changes.
++ it_b;
continue;
}
if (it_a == va.end() || it_b == vb.end())
// va or vb contains more Tool Changes than the other.
return true;
assert(it_a->gcode == ExtruderChangeCode);
assert(it_b->gcode == ExtruderChangeCode);
if (*it_a != *it_b)
// The two Tool Changes differ.
return true;
++ it_a;
++ it_b;
}
// There is no change in custom Tool Changes.
return false;
}
// Collect diffs of configuration values at various containers, // Collect diffs of configuration values at various containers,
// resolve the filament rectract overrides of extruder retract values. // resolve the filament rectract overrides of extruder retract values.
void Print::config_diffs( void Print::config_diffs(
@ -692,8 +723,11 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
model_object_status.emplace(model_object->id(), ModelObjectStatus::New); model_object_status.emplace(model_object->id(), ModelObjectStatus::New);
} else { } else {
if (m_model.custom_gcode_per_print_z != model.custom_gcode_per_print_z) { if (m_model.custom_gcode_per_print_z != model.custom_gcode_per_print_z) {
// If custom gcode per layer height was changed, we should stop background processing. update_apply_status(custom_per_printz_gcodes_tool_changes_differ(m_model.custom_gcode_per_print_z, model.custom_gcode_per_print_z) ?
update_apply_status(this->invalidate_steps({ psWipeTower, psGCodeExport })); // The Tool Ordering and the Wipe Tower are no more valid.
this->invalidate_steps({ psWipeTower, psGCodeExport }) :
// There is no change in Tool Changes stored in custom_gcode_per_print_z, therefore there is no need to update Tool Ordering.
this->invalidate_step(psGCodeExport));
m_model.custom_gcode_per_print_z = model.custom_gcode_per_print_z; m_model.custom_gcode_per_print_z = model.custom_gcode_per_print_z;
} }
if (model_object_list_equal(m_model, model)) { if (model_object_list_equal(m_model, model)) {
@ -1521,9 +1555,13 @@ void Print::process()
obj->generate_support_material(); obj->generate_support_material();
if (this->set_started(psWipeTower)) { if (this->set_started(psWipeTower)) {
m_wipe_tower_data.clear(); m_wipe_tower_data.clear();
m_tool_ordering.clear();
if (this->has_wipe_tower()) { if (this->has_wipe_tower()) {
//this->set_status(95, L("Generating wipe tower")); //this->set_status(95, L("Generating wipe tower"));
this->_make_wipe_tower(); this->_make_wipe_tower();
} else if (! this->config().complete_objects.value) {
// Initialize the tool ordering, so it could be used by the G-code preview slider for planning tool changes and filament switches.
m_tool_ordering = ToolOrdering(*this, -1, false);
} }
this->set_done(psWipeTower); this->set_done(psWipeTower);
} }

View File

@ -27,8 +27,19 @@ class GCodePreviewData;
// Print step IDs for keeping track of the print state. // Print step IDs for keeping track of the print state.
enum PrintStep { enum PrintStep {
psSkirt, psBrim, psWipeTower, psGCodeExport, psCount, psSkirt,
psBrim,
// Synonym for the last step before the Wipe Tower / Tool Ordering, for the G-code preview slider to understand that
// all the extrusions are there for the layer slider to add color changes etc.
psExtrusionPaths = psBrim,
psWipeTower,
// psToolOrdering is a synonym to psWipeTower, as the Wipe Tower calculates and modifies the ToolOrdering,
// while if printing without the Wipe Tower, the ToolOrdering is calculated as well.
psToolOrdering = psWipeTower,
psGCodeExport,
psCount,
}; };
enum PrintObjectStep { enum PrintObjectStep {
posSlice, posPerimeters, posPrepareInfill, posSlice, posPerimeters, posPrepareInfill,
posInfill, posSupportMaterial, posCount, posInfill, posSupportMaterial, posCount,
@ -231,6 +242,7 @@ private:
struct WipeTowerData struct WipeTowerData
{ {
WipeTowerData(ToolOrdering &tool_ordering) : tool_ordering(tool_ordering) { clear(); }
// Following section will be consumed by the GCodeGenerator. // Following section will be consumed by the GCodeGenerator.
// Tool ordering of a non-sequential print has to be known to calculate the wipe tower. // Tool ordering of a non-sequential print has to be known to calculate the wipe tower.
// Cache it here, so it does not need to be recalculated during the G-code generation. // Cache it here, so it does not need to be recalculated during the G-code generation.
@ -247,7 +259,6 @@ struct WipeTowerData
float brim_width; float brim_width;
void clear() { void clear() {
tool_ordering.clear();
priming.reset(nullptr); priming.reset(nullptr);
tool_changes.clear(); tool_changes.clear();
final_purge.reset(nullptr); final_purge.reset(nullptr);
@ -377,6 +388,7 @@ public:
// Wipe tower support. // Wipe tower support.
bool has_wipe_tower() const; bool has_wipe_tower() const;
const WipeTowerData& wipe_tower_data(size_t extruders_cnt = 0, double first_layer_height = 0., double nozzle_diameter = 0.) const; const WipeTowerData& wipe_tower_data(size_t extruders_cnt = 0, double first_layer_height = 0., double nozzle_diameter = 0.) const;
const ToolOrdering& tool_ordering() const { return m_tool_ordering; }
std::string output_filename(const std::string &filename_base = std::string()) const override; std::string output_filename(const std::string &filename_base = std::string()) const override;
@ -421,7 +433,8 @@ private:
ExtrusionEntityCollection m_brim; ExtrusionEntityCollection m_brim;
// Following section will be consumed by the GCodeGenerator. // Following section will be consumed by the GCodeGenerator.
WipeTowerData m_wipe_tower_data; ToolOrdering m_tool_ordering;
WipeTowerData m_wipe_tower_data {m_tool_ordering};
// Estimated print time, filament consumed. // Estimated print time, filament consumed.
PrintStatistics m_print_statistics; PrintStatistics m_print_statistics;