Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cura 11099 nozzle switch duration #1981

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 16 additions & 10 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

#include "gcodeExport.h"

#include <assert.h>
#include <cmath>
#include <iomanip>
#include <stdarg.h>

#include <spdlog/spdlog.h>

#include "Application.h" //To send layer view data.
#include "ExtruderTrain.h"
#include "PrintFeature.h"
Expand All @@ -14,13 +21,6 @@
#include "utils/Date.h"
#include "utils/string.h" // MMtoStream, PrecisionedDouble

#include <spdlog/spdlog.h>

#include <assert.h>
#include <cmath>
#include <iomanip>
#include <stdarg.h>

namespace cura
{

Expand Down Expand Up @@ -1254,8 +1254,8 @@ void GCodeExport::startExtruder(const size_t 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 std::string start_code = Application::getInstance().current_slice->scene.extruders[new_extruder].settings.get<std::string>("machine_extruder_start_code");

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 @@ -1271,6 +1271,9 @@ void GCodeExport::startExtruder(const size_t new_extruder)
}
}

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

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

Expand Down Expand Up @@ -1302,7 +1305,7 @@ void GCodeExport::switchExtruder(size_t new_extruder, const RetractionConfig& re

resetExtrusionValue(); // zero the E value on the old extruder, so that the current_e_value is registered on the old extruder

const std::string end_code = old_extruder_settings.get<std::string>("machine_extruder_end_code");
const auto end_code = old_extruder_settings.get<std::string>("machine_extruder_end_code");

if (! end_code.empty())
{
Expand All @@ -1319,6 +1322,9 @@ void GCodeExport::switchExtruder(size_t new_extruder, const RetractionConfig& re
}
}

const auto end_code_duration = old_extruder_settings.get<Duration>("machine_extruder_end_code_duration");
estimateCalculator.addTime(end_code_duration);

startExtruder(new_extruder);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/GCodeExportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,21 @@ TEST_F(GCodeExportTest, SwitchExtruderSimple)

scene.extruders.emplace_back(0, nullptr);
ExtruderTrain& train1 = scene.extruders.back();

train1.settings.add("machine_extruder_start_code", ";FIRST EXTRUDER START G-CODE!");
train1.settings.add("machine_extruder_end_code", ";FIRST EXTRUDER END G-CODE!");
train1.settings.add("machine_extruder_start_code_duration", "0.0");
train1.settings.add("machine_extruder_end_code_duration", "0.0");
train1.settings.add("machine_firmware_retract", "True");
train1.settings.add("retraction_enable", "True");

scene.extruders.emplace_back(1, nullptr);
ExtruderTrain& train2 = scene.extruders.back();

train2.settings.add("machine_extruder_start_code", ";SECOND EXTRUDER START G-CODE!");
train2.settings.add("machine_extruder_end_code", ";SECOND EXTRUDER END G-CODE!");
train2.settings.add("machine_extruder_start_code_duration", "0.0");
train2.settings.add("machine_extruder_end_code_duration", "0.0");
train2.settings.add("machine_firmware_retract", "True");
train2.settings.add("retraction_enable", "True");

Expand Down
Loading