ENH: save filament sequences in gcode result

jira: NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I79c2eb4002c72568d487df417c914ab0b8a14a67
(cherry picked from commit a289370b19e78693698db388d4057e25ba285d6b)
This commit is contained in:
xun.zhang
2024-10-25 11:13:31 +08:00
committed by Noisyfox
parent 53745a5767
commit d7af75359f
4 changed files with 51 additions and 3 deletions

View File

@@ -2155,7 +2155,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
print_object_instance_sequential_active = print_object_instances_ordering.begin();
for (; print_object_instance_sequential_active != print_object_instances_ordering.end(); ++ print_object_instance_sequential_active) {
tool_ordering = ToolOrdering(*(*print_object_instance_sequential_active)->print_object, initial_extruder_id);
{ //save the flush statitics stored in tool ordering by object
{
// save the flush statitics stored in tool ordering by object
print.m_statistics_by_extruder_count.stats_by_single_extruder += tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::SingleExt);
print.m_statistics_by_extruder_count.stats_by_multi_extruder_auto += tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::MultiExtAuto);
print.m_statistics_by_extruder_count.stats_by_multi_extruder_manual += tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::MultiExtManual);
@@ -2200,7 +2201,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// 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.
tool_ordering = print.tool_ordering();
{ //save the flush statitics stored in tool ordering
{
//save the flush statitics stored in tool ordering
print.m_statistics_by_extruder_count.stats_by_single_extruder = tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::SingleExt);
print.m_statistics_by_extruder_count.stats_by_multi_extruder_auto = tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::MultiExtAuto);
print.m_statistics_by_extruder_count.stats_by_multi_extruder_manual = tool_ordering.get_filament_change_stats(ToolOrdering::FilamentChangeMode::MultiExtManual);
@@ -2636,6 +2638,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// Generate G-code, run the filters (vase mode, cooling buffer), run the G-code analyser
// and export G-code into file.
this->process_layers(print, tool_ordering, collect_layers_to_print(object), *print_object_instance_sequential_active - object.instances().data(), file, prime_extruder);
// save sorted filament sequences
const auto& layer_tools = tool_ordering.layer_tools();
for (const auto& lt : layer_tools)
m_sorted_layer_filaments.emplace_back(lt.extruders);
//BBS: close powerlost recovery
{
if (is_bbl_printers && m_second_layer_things_done) {
@@ -2700,6 +2706,11 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// Generate G-code, run the filters (vase mode, cooling buffer), run the G-code analyser
// and export G-code into file.
this->process_layers(print, tool_ordering, print_object_instances_ordering, layers_to_print, file);
// save sorted filament sequences
const auto& layer_tools = tool_ordering.layer_tools();
for (const auto& lt : layer_tools)
m_sorted_layer_filaments.emplace_back(lt.extruders);
//BBS: close powerlost recovery
{
if (is_bbl_printers && m_second_layer_things_done) {
@@ -2824,6 +2835,30 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
print.throw_if_canceled();
}
void GCode::export_layer_filaments(GCodeProcessorResult* result)
{
if (result == nullptr)
return;
result->layer_filaments.clear();
for (size_t idx = 0; idx < m_sorted_layer_filaments.size(); ++idx) {
// now we do not need sorted data, so we sort the filaments in id order
auto& layer_filaments = m_sorted_layer_filaments[idx];
std::sort(layer_filaments.begin(), layer_filaments.end());
auto iter = result->layer_filaments.find(layer_filaments);
if (iter == result->layer_filaments.end()) {
result->layer_filaments[layer_filaments].emplace_back(idx, idx);
}
else {
// if layer id is sequential, expand the range
if (iter->second.back().second == idx - 1)
iter->second.back().second = idx;
else
iter->second.emplace_back(idx, idx);
}
}
}
//BBS
void GCode::check_placeholder_parser_failed()
{