Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/TheSin-/CuraEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
nallath committed Oct 10, 2024
2 parents 662f20e + 2960fd6 commit 82a4986
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ bool GCodeExport::initializeExtruderTrains(const SliceDataStorage& storage, cons

writeComment("Generated with Cura_SteamEngine " CURA_ENGINE_VERSION);

if (mesh_group_settings.get<bool>("machine_start_gcode_first"))
{
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());
}

if (getFlavor() == EGCodeFlavor::GRIFFIN)
{
std::ostringstream tmp;
Expand All @@ -693,8 +698,11 @@ bool GCodeExport::initializeExtruderTrains(const SliceDataStorage& storage, cons
processInitialLayerTemperature(storage, start_extruder_nr);
}

if (!mesh_group_settings.get<bool>("machine_start_gcode_first"))
{
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());
}
writeExtrusionMode(false); // ensure absolute extrusion mode is set before the start gcode
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());

// in case of shared nozzle assume that the machine-start gcode reset the extruders as per machine description
if (Application::getInstance().current_slice_->scene.settings.get<bool>("machine_extruders_share_nozzle"))
Expand Down Expand Up @@ -819,8 +827,9 @@ void GCodeExport::processInitialLayerExtrudersTemperatures(const SliceDataStorag
void GCodeExport::processInitialLayerTemperature(const SliceDataStorage& storage, const size_t start_extruder_nr)
{
Scene& scene = Application::getInstance().current_slice_->scene;
const size_t num_extruders = scene.extruders.size();
bool wait_start_extruder = false;
std::vector<bool> extruders_used = storage.getExtrudersUsed();
size_t used_extruders = std::count(extruders_used.begin(), extruders_used.end(), true);

switch (getFlavor())
{
Expand All @@ -830,7 +839,7 @@ void GCodeExport::processInitialLayerTemperature(const SliceDataStorage& storage
wait_start_extruder = true;
break;
default:
if (num_extruders > 1 || getFlavor() == EGCodeFlavor::REPRAP)
if (used_extruders > 1 || getFlavor() == EGCodeFlavor::REPRAP)
{
std::ostringstream tmp;
tmp << "T" << start_extruder_nr;
Expand Down Expand Up @@ -1279,6 +1288,29 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/)

void GCodeExport::startExtruder(const size_t new_extruder)
{
const auto extruder_settings = Application::getInstance().current_slice_->scene.extruders[new_extruder].settings_;
const auto prestart_code = extruder_settings.get<std::string>("machine_extruder_prestart_code");
const auto start_code = extruder_settings.get<std::string>("machine_extruder_start_code");
const auto start_code_duration = extruder_settings.get<Duration>("machine_extruder_start_code_duration");
const auto extruder_change_duration = extruder_settings.get<Duration>("machine_extruder_change_duration");

// Be nice to be able to calculate the extruder change time verses time
// to heat and run this so it's run before the change call. **Future note**
if (! prestart_code.empty())
{
if (relative_extrusion_)
{
writeExtrusionMode(false); // ensure absolute extrusion mode is set before the prestart gcode
}

writeCode(prestart_code.c_str());

if (relative_extrusion_)
{
writeExtrusionMode(true); // restore relative extrusion mode
}
}

extruder_attr_[new_extruder].is_used_ = true;
if (new_extruder != current_extruder_) // wouldn't be the case on the very first extruder start if it's extruder 0
{
Expand All @@ -1290,15 +1322,16 @@ void GCodeExport::startExtruder(const size_t new_extruder)
{
*output_stream_ << "T" << new_extruder << new_line_;
}
// Only add time is we are actually changing extruders
estimate_calculator_.addTime(extruder_change_duration);
}

estimate_calculator_.addTime(start_code_duration);
current_extruder_ = new_extruder;

assert(getCurrentExtrudedVolume() == 0.0 && "Just after an extruder switch we haven't extruded anything yet!");
resetExtrusionValue(); // zero the E value on the new extruder, just to be sure

const auto extruder_settings = Application::getInstance().current_slice_->scene.extruders[new_extruder].settings_;
const auto start_code = extruder_settings.get<std::string>("machine_extruder_start_code");
if (! start_code.empty())
{
if (relative_extrusion_)
Expand All @@ -1314,9 +1347,6 @@ void GCodeExport::startExtruder(const size_t new_extruder)
}
}

const auto start_code_duration = extruder_settings.get<Duration>("machine_extruder_start_code_duration");
estimate_calculator_.addTime(start_code_duration);

Application::getInstance().communication_->setExtruderForSend(Application::getInstance().current_slice_->scene.extruders[new_extruder]);
Application::getInstance().communication_->sendCurrentPosition(getPositionXY());

Expand Down
6 changes: 6 additions & 0 deletions src/sliceDataStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ std::vector<bool> SliceDataStorage::getExtrudersUsed() const
std::vector<bool> ret;
ret.resize(Application::getInstance().current_slice_->scene.extruders.size(), false);

// set all the false to start, we set them to true if used
for (size_t extruder_nr = 0; extruder_nr < Application::getInstance().current_slice_->scene.extruders.size(); extruder_nr++)
{
ret[extruder_nr] = false;
}

const Settings& mesh_group_settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings;
const EPlatformAdhesion adhesion_type = mesh_group_settings.get<EPlatformAdhesion>("adhesion_type");
if (adhesion_type == EPlatformAdhesion::SKIRT || adhesion_type == EPlatformAdhesion::BRIM)
Expand Down

0 comments on commit 82a4986

Please sign in to comment.