Skip to content

Commit

Permalink
Cache extruder settings (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
rburema authored Sep 12, 2023
2 parents 115f286 + 9d11fd2 commit 9b40dcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/gcodeExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class GCodeExport : public NoCopy
double last_e_value_after_wipe; //!< The current material amount extruded since last wipe

unsigned fan_number; // nozzle print cooling fan number
Point nozzle_offset; //!< Cache of setting machine_nozzle_offset_[xy]
bool machine_firmware_retract; //!< Cache of setting machine_firmware_retract

std::deque<double> extruded_volume_at_previous_n_retractions; // in mm^3

Expand Down
32 changes: 16 additions & 16 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ void GCodeExport::preSetup(const size_t start_extruder)
extruder_attr[extruder_nr].last_retraction_prime_speed
= train.settings.get<Velocity>("retraction_prime_speed"); // the alternative would be switch_extruder_prime_speed, but dual extrusion might not even be configured...
extruder_attr[extruder_nr].fan_number = train.settings.get<size_t>("machine_extruder_cooling_fan_number");

// Cache some settings that we use frequently.
const Settings& extruder_settings = Application::getInstance().current_slice->scene.extruders[extruder_nr].settings;
if (use_extruder_offset_to_offset_coords)
{
extruder_attr[extruder_nr].nozzle_offset = Point(extruder_settings.get<coord_t>("machine_nozzle_offset_x"), extruder_settings.get<coord_t>("machine_nozzle_offset_y"));
}
else
{
extruder_attr[extruder_nr].nozzle_offset = Point(0, 0);
}
extruder_attr[extruder_nr].machine_firmware_retract = extruder_settings.get<bool>("machine_firmware_retract");
}

machine_name = mesh_group->settings.get<std::string>("machine_name");
Expand Down Expand Up @@ -323,18 +335,9 @@ bool GCodeExport::getExtruderIsUsed(const int extruder_nr) const

Point GCodeExport::getGcodePos(const coord_t x, const coord_t y, const int extruder_train) const
{
if (use_extruder_offset_to_offset_coords)
{
const Settings& extruder_settings = Application::getInstance().current_slice->scene.extruders[extruder_train].settings;
return Point(x - extruder_settings.get<coord_t>("machine_nozzle_offset_x"), y - extruder_settings.get<coord_t>("machine_nozzle_offset_y"));
}
else
{
return Point(x, y);
}
return Point(x, y) - extruder_attr[extruder_train].nozzle_offset;
}


void GCodeExport::setFlavor(EGCodeFlavor flavor)
{
this->flavor = flavor;
Expand Down Expand Up @@ -412,8 +415,7 @@ void GCodeExport::setFilamentDiameter(const size_t extruder, const coord_t diame
double GCodeExport::getCurrentExtrudedVolume() const
{
double extrusion_amount = current_e_value;
const Settings& extruder_settings = Application::getInstance().current_slice->scene.extruders[current_extruder].settings;
if (! extruder_settings.get<bool>("machine_firmware_retract"))
if (! extruder_attr[current_extruder].machine_firmware_retract)
{ // no E values are changed to perform a retraction
extrusion_amount
-= extruder_attr[current_extruder].retraction_e_amount_at_e_start; // subtract the increment in E which was used for the first unretraction instead of extrusion
Expand Down Expand Up @@ -1057,8 +1059,7 @@ void GCodeExport::writeUnretractionAndPrime()
current_e_value += prime_volume_e;
if (extruder_attr[current_extruder].retraction_e_amount_current)
{
const Settings& extruder_settings = Application::getInstance().current_slice->scene.extruders[current_extruder].settings;
if (extruder_settings.get<bool>("machine_firmware_retract"))
if (extruder_attr[current_extruder].machine_firmware_retract)
{ // note that BFB is handled differently
*output_stream << "G11" << new_line;
// Assume default UM2 retraction settings.
Expand Down Expand Up @@ -1163,8 +1164,7 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
}
}

const Settings& extruder_settings = Application::getInstance().current_slice->scene.extruders[current_extruder].settings;
if (extruder_settings.get<bool>("machine_firmware_retract"))
if (extruder_attr[current_extruder].machine_firmware_retract)
{
if (extruder_switch && extr_attr.retraction_e_amount_current)
{
Expand Down

0 comments on commit 9b40dcd

Please sign in to comment.