Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/gcode_export/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,13 +2027,30 @@ void GCodeExport::finalize(const std::string& end_code, PrintInformation& print_

template_resolver_->prepareForResolving(print_info.initial_extruder_nr.value_or(0), extra_global_settings);

std::shared_ptr<Communication> communication = Application::getInstance().communication_;
{
// Prepend the header to the first gcode part, so that they become a single unsplittable part
const std::string header = getFileHeader(is_extruder_used_bool, filaments_volumes, materials_ids);

// Since the gcode is stored in a stream, we cannot prepend data to it, so create a new part with the assembled strings
auto header_part = std::make_shared<FixedGCodePart>();
header_part->stream() << header;

communication->sendGCodePart(getFileHeader(is_extruder_used_bool, filaments_volumes, materials_ids));
std::shared_ptr<GCodePart> first_gcode_part = gcode_parts_.front();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCode-parts can't be empty here right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I don't think in practice it could happen, because even if the print is somehow empty, you always have some init gcode.

if (const auto fixed_first_gcode_part = std::dynamic_pointer_cast<FixedGCodePart>(first_gcode_part))
{
header_part->stream() << fixed_first_gcode_part->str();
gcode_parts_.front() = header_part;
}
else
{
// First GCode part is a resolvable part, which should not happen, but in case it does, just prepend the header as a fixed part
gcode_parts_.insert(gcode_parts_.begin(), header_part);
}
}

sendFinalGCode();

communication->sendPrintInformation(total_print_times_, print_info);
Application::getInstance().communication_->sendPrintInformation(total_print_times_, print_info);
}

void GCodeExport::finalizeExtruder(const std::string& extruder_end_code)
Expand Down
Loading