OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Extruder Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Extruder.hpp>

Collaboration diagram for Slic3r::Extruder:

Public Member Functions

 Extruder (unsigned int id, GCodeConfig *config, bool share_extruder)
virtual ~Extruder ()
void reset ()
unsigned int id () const
int config_index () const
void set_config_index (int idx)
unsigned int extruder_id () const
double extrude (double dE)
double retract (double length, double restart_extra)
double unretract ()
double E () const
double E_to_emit (bool high_precision, double extra=0.)
void reset_E ()
double e_per_mm (double mm3_per_mm) const
double e_per_mm3 () const
double extruded_volume () const
double used_filament () const
double position () const
double retracted () const
double restart_extra () const
bool is_share_extruder () const
double get_single_retracted_length () const
double get_share_retracted_length () const
void set_position (double e)
void set_retracted (double retracted, double restart_extra)
double filament_diameter () const
double filament_crossection () const
double filament_density () const
double filament_cost () const
double filament_flow_ratio () const
double retract_before_wipe () const
double retract_after_wipe () const
double retraction_length () const
double retract_lift () const
int retract_speed () const
int deretract_speed () const
double retract_restart_extra () const
double retract_length_toolchange () const
double retract_restart_extra_toolchange () const
double travel_slope () const
bool use_firmware_retraction () const

Private Member Functions

 Extruder (unsigned int id)

Private Attributes

GCodeConfig * m_config
unsigned int m_id
int m_config_index {0}
double m_E
double m_absolute_E
double m_retracted
double m_restart_extra
double m_E_rounding_carry { 0. }
double m_e_per_mm3
bool m_share_extruder

Static Private Attributes

static std::vector< double > m_share_E = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0)
static std::vector< double > m_share_retracted = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0)

Detailed Description

Constructor & Destructor Documentation

◆ Extruder() [1/2]

Slic3r::Extruder::Extruder ( unsigned int id,
GCodeConfig * config,
bool share_extruder )
18 :
19 m_id(id),
20 m_config(config),
21 m_share_extruder(share_extruder)
22{
23 reset();
24
25 m_config_index = int(m_id);
26 // cache values that are going to be called often
29}
void reset()
Definition Extruder.hpp:17
double m_e_per_mm3
Definition Extruder.hpp:114
double filament_flow_ratio() const
Definition Extruder.cpp:197
bool m_share_extruder
Definition Extruder.hpp:118
double filament_crossection() const
Definition Extruder.hpp:76
unsigned int m_id
Definition Extruder.hpp:101
GCodeConfig * m_config
Definition Extruder.hpp:99
int m_config_index
Definition Extruder.hpp:103

References filament_crossection(), filament_flow_ratio(), Slic3r::GCodeConfig, id(), m_config, m_config_index, m_e_per_mm3, m_id, m_share_extruder, and reset().

Here is the call graph for this function:

◆ ~Extruder()

virtual Slic3r::Extruder::~Extruder ( )
inlinevirtual
15{}

◆ Extruder() [2/2]

Slic3r::Extruder::Extruder ( unsigned int id)
inlineprivate
96: m_id(id) {}

References id(), and m_id.

Here is the call graph for this function:

Member Function Documentation

◆ config_index()

int Slic3r::Extruder::config_index ( ) const
inline
36{ return m_config_index; }

References m_config_index.

◆ deretract_speed()

int Slic3r::Extruder::deretract_speed ( ) const
236{
237 int speed = int(floor(m_config->deretraction_speed.get_at(m_config_index)+0.5));
238 return (speed > 0) ? speed : this->retract_speed();
239}
int retract_speed() const
Definition Extruder.cpp:225

References m_config, m_config_index, and retract_speed().

Here is the call graph for this function:

◆ E()

double Slic3r::Extruder::E ( ) const
inline
unsigned int extruder_id() const
Definition Extruder.cpp:39
double m_E
Definition Extruder.hpp:105
static std::vector< double > m_share_E
Definition Extruder.hpp:119

References extruder_id(), m_E, m_share_E, and m_share_extruder.

Referenced by E_to_emit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ e_per_mm()

double Slic3r::Extruder::e_per_mm ( double mm3_per_mm) const
inline
50{ return mm3_per_mm * m_e_per_mm3; }

References m_e_per_mm3.

Referenced by Slic3r::Print::_make_skirt().

Here is the caller graph for this function:

◆ e_per_mm3()

double Slic3r::Extruder::e_per_mm3 ( ) const
inline
52{ return m_e_per_mm3; }

References m_e_per_mm3.

◆ E_to_emit()

double Slic3r::Extruder::E_to_emit ( bool high_precision,
double extra = 0. )
71{
72 const double e = this->E() + extra;
73 if (! m_config->use_relative_e_distances.value || ! high_precision)
74 return e;
75 // Rounding each relative move on its own biases the flow when short moves of about the same length all round
76 // the same way. Carrying the rounding error into the next move keeps the written E within half of the last
77 // decimal of the extruded length, as with absolute E distances. Moves written with the standard precision
78 // (supports) are rounded on their own, as without high precision G-code, and keep the carry for the next move
79 // written with high precision.
80 const double carried = e + m_E_rounding_carry;
81 const double emitted = GCodeFormatter::quantize_e(carried, true);
82 m_E_rounding_carry = carried - emitted;
83 return emitted;
84}
double E() const
Definition Extruder.hpp:44
double m_E_rounding_carry
Definition Extruder.hpp:113
static double quantize_e(double v, bool high_precision)
Definition GCodeWriter.hpp:343

References E(), m_config, m_E_rounding_carry, and Slic3r::GCodeFormatter::quantize_e().

Here is the call graph for this function:

◆ extrude()

double Slic3r::Extruder::extrude ( double dE)
49{
50 // BBS
51 if (m_share_extruder) {
52 if (m_config->use_relative_e_distances)
53 m_share_E[extruder_id()] = 0.;
54 m_share_E[extruder_id()] += dE;
55 m_absolute_E += dE;
56 if (dE < 0.)
58 } else {
59 // in case of relative E distances we always reset to 0 before any output
60 if (m_config->use_relative_e_distances)
61 m_E = 0.;
62 m_E += dE;
63 m_absolute_E += dE;
64 if (dE < 0.)
65 m_retracted -= dE;
66 }
67 return dE;
68}
double m_retracted
Definition Extruder.hpp:109
double m_absolute_E
Definition Extruder.hpp:107
static std::vector< double > m_share_retracted
Definition Extruder.hpp:120

References extruder_id(), m_absolute_E, m_config, m_E, m_retracted, m_share_E, m_share_extruder, and m_share_retracted.

Referenced by Slic3r::GCodeWriter::extrude_arc_to_xy(), Slic3r::GCodeWriter::extrude_to_xy(), Slic3r::GCodeWriter::extrude_to_xyz(), and unretract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extruded_volume()

double Slic3r::Extruder::extruded_volume ( ) const
160{
161 // BBS
162 if (m_share_extruder) {
163 // FIXME: need to count m_retracted for share extruder machine
164 return this->used_filament() * this->filament_crossection();
165 } else {
166 return this->used_filament() * this->filament_crossection();
167 }
168}
double used_filament() const
Definition Extruder.cpp:171

References filament_crossection(), m_share_extruder, and used_filament().

Here is the call graph for this function:

◆ extruder_id()

unsigned int Slic3r::Extruder::extruder_id ( ) const
40{
41 assert(m_config);
43 return m_config->filament_map.get_at(m_id) - 1;
44 }
45 return 0;
46}
zaa_minimize_perimeter_height filament_map((ConfigOptionInts, filament_volume_map))((ConfigOptionInts

References Slic3r::filament_map(), m_config, and m_id.

Referenced by Slic3r::WipeTowerIntegration::append_tcr(), E(), Slic3r::GCodeWriter::eager_lift(), extrude(), get_share_retracted_length(), Slic3r::GCodeWriter::lazy_lift(), reset_E(), retract(), travel_slope(), and unretract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filament_cost()

double Slic3r::Extruder::filament_cost ( ) const
193{
194 return m_config->filament_cost.get_at(m_id);
195}

References m_config, and m_id.

◆ filament_crossection()

double Slic3r::Extruder::filament_crossection ( ) const
inline
76{ return this->filament_diameter() * this->filament_diameter() * 0.25 * PI; }
double filament_diameter() const
Definition Extruder.cpp:182
static constexpr double PI
Definition libslic3r.h:81

References filament_diameter(), and PI.

Referenced by Extruder(), extruded_volume(), and set_config_index().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filament_density()

double Slic3r::Extruder::filament_density ( ) const
188{
189 return m_config->filament_density.get_at(m_id);
190}

References m_config, and m_id.

◆ filament_diameter()

double Slic3r::Extruder::filament_diameter ( ) const
183{
184 return m_config->filament_diameter.get_at(m_id);
185}

References m_config, and m_id.

Referenced by filament_crossection().

Here is the caller graph for this function:

◆ filament_flow_ratio()

double Slic3r::Extruder::filament_flow_ratio ( ) const
198{
199 return m_config->filament_flow_ratio.get_at(m_config_index);
200}

References m_config, and m_config_index.

Referenced by Extruder(), and set_config_index().

Here is the caller graph for this function:

◆ get_share_retracted_length()

double Slic3r::Extruder::get_share_retracted_length ( ) const
inline
68{ return m_share_retracted[extruder_id()]; }

References extruder_id(), and m_share_retracted.

Here is the call graph for this function:

◆ get_single_retracted_length()

double Slic3r::Extruder::get_single_retracted_length ( ) const
inline
67{ return m_retracted; }

References m_retracted.

◆ id()

◆ is_share_extruder()

bool Slic3r::Extruder::is_share_extruder ( ) const
inline
66{ return m_share_extruder; }

References m_share_extruder.

◆ position()

double Slic3r::Extruder::position ( ) const
inline
60{ return m_E; }

References m_E.

◆ reset()

void Slic3r::Extruder::reset ( )
inline
17 {
18 // BBS
19 if (m_share_extruder) {
20 m_share_E = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0);
21 m_share_retracted = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0);
22 } else {
23 m_E = 0;
24 m_retracted = 0;
25 }
27 m_absolute_E = 0;
29 }
double m_restart_extra
Definition Extruder.hpp:111
static constexpr size_t MAXIMUM_EXTRUDER_NUMBER
Definition libslic3r.h:70

References m_absolute_E, m_E, m_E_rounding_carry, m_restart_extra, m_retracted, m_share_E, m_share_extruder, m_share_retracted, and MAXIMUM_EXTRUDER_NUMBER.

Referenced by Extruder().

Here is the caller graph for this function:

◆ reset_E()

void Slic3r::Extruder::reset_E ( )
inline
48{ m_E = 0.; m_share_E[extruder_id()] = 0.; }

References extruder_id(), m_E, and m_share_E.

Here is the call graph for this function:

◆ restart_extra()

double Slic3r::Extruder::restart_extra ( ) const
inline
64{ return m_restart_extra; }

References m_restart_extra.

Referenced by retract(), and set_retracted().

Here is the caller graph for this function:

◆ retract()

double Slic3r::Extruder::retract ( double length,
double restart_extra )
94{
95 // BBS
96 if (m_share_extruder) {
97 if (m_config->use_relative_e_distances)
98 m_share_E[extruder_id()] = 0.;
99 double to_retract = std::max(0., length - m_share_retracted[extruder_id()]);
101 if (to_retract > 0.) {
102 m_share_E[extruder_id()] -= to_retract;
103 m_absolute_E -= to_retract;
104 m_share_retracted[extruder_id()] += to_retract;
105 }
106 return to_retract;
107 } else {
108 // in case of relative E distances we always reset to 0 before any output
109 if (m_config->use_relative_e_distances)
110 m_E = 0.;
111 double to_retract = std::max(0., length - m_retracted);
113 if (to_retract > 0.) {
114 m_E -= to_retract;
115 m_absolute_E -= to_retract;
116 m_retracted += to_retract;
117 }
118 return to_retract;
119 }
120}
double restart_extra() const
Definition Extruder.hpp:64
double length(const Points &pts)
Definition MultiPoint.hpp:181

References extruder_id(), Slic3r::length(), m_absolute_E, m_config, m_E, m_restart_extra, m_retracted, m_share_E, m_share_extruder, m_share_retracted, and restart_extra().

Here is the call graph for this function:

◆ retract_after_wipe()

double Slic3r::Extruder::retract_after_wipe ( ) const
211{
212 return std::min(std::clamp(m_config->retract_after_wipe.get_at(m_config_index) * 0.01, 0., 1.), 1. - retract_before_wipe());
213}
double retract_before_wipe() const
Definition Extruder.cpp:203

References m_config, m_config_index, and retract_before_wipe().

Here is the call graph for this function:

◆ retract_before_wipe()

double Slic3r::Extruder::retract_before_wipe ( ) const
204{
205 return std::clamp(m_config->retract_before_wipe.get_at(m_config_index) * 0.01, 0., 1.);
206}

References m_config, and m_config_index.

Referenced by Slic3r::GCodeWriter::retract(), retract_after_wipe(), and Slic3r::GCodeWriter::retract_for_toolchange().

Here is the caller graph for this function:

◆ retract_length_toolchange()

double Slic3r::Extruder::retract_length_toolchange ( ) const
247{
248 return m_config->retract_length_toolchange.get_at(m_config_index);
249}

References m_config, and m_config_index.

◆ retract_lift()

double Slic3r::Extruder::retract_lift ( ) const
221{
222 return m_config->z_hop.get_at(m_config_index);
223}

References m_config, and m_config_index.

◆ retract_restart_extra()

double Slic3r::Extruder::retract_restart_extra ( ) const
242{
243 return m_config->retract_restart_extra.get_at(m_config_index);
244}

References m_config, and m_config_index.

◆ retract_restart_extra_toolchange()

double Slic3r::Extruder::retract_restart_extra_toolchange ( ) const
252{
253 return m_config->retract_restart_extra_toolchange.get_at(m_config_index);
254}

References m_config, and m_config_index.

◆ retract_speed()

int Slic3r::Extruder::retract_speed ( ) const
226{
227 return int(floor(m_config->retraction_speed.get_at(m_config_index)+0.5));
228}

References m_config, and m_config_index.

Referenced by deretract_speed().

Here is the caller graph for this function:

◆ retracted()

double Slic3r::Extruder::retracted ( ) const
inline
62{ return m_retracted; }

References m_retracted.

Referenced by set_retracted().

Here is the caller graph for this function:

◆ retraction_length()

double Slic3r::Extruder::retraction_length ( ) const
216{
217 return m_config->retraction_length.get_at(m_config_index);
218}

References m_config, and m_config_index.

◆ set_config_index()

void Slic3r::Extruder::set_config_index ( int idx)
32{
33 m_config_index = idx < 0 ? int(m_id) : idx;
34 // keep the cached flow term reading the same column as the getters
37}

References filament_crossection(), filament_flow_ratio(), m_config_index, m_e_per_mm3, and m_id.

Here is the call graph for this function:

◆ set_position()

void Slic3r::Extruder::set_position ( double e)
inline
71{ m_E = e; }

References m_E.

◆ set_retracted()

void Slic3r::Extruder::set_retracted ( double retracted,
double restart_extra )
143{
144 if (retracted < - EPSILON)
145 throw Slic3r::RuntimeError(_u8L("Custom G-code reports negative z_retracted."));
146 if (restart_extra < - EPSILON)
147 throw Slic3r::RuntimeError(_u8L("Custom G-code reports negative z_restart_extra."));
148
149 if (retracted > EPSILON) {
152 } else {
153 m_retracted = 0;
154 m_restart_extra = 0;
155 }
156}
#define EPSILON
Definition ColorUtils.cpp:64
double retracted() const
Definition Extruder.hpp:62
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, EPSILON, m_restart_extra, m_retracted, restart_extra(), and retracted().

Here is the call graph for this function:

◆ travel_slope()

double Slic3r::Extruder::travel_slope ( ) const
257{
258 // Orca: deliberately keyed by the physical extruder, not the filament column — this read
259 // predates the per-variant merge and switching it would change existing multi-extruder output.
260 return m_config->travel_slope.get_at(extruder_id()) * PI / 180;
261}

References extruder_id(), m_config, and PI.

Here is the call graph for this function:

◆ unretract()

double Slic3r::Extruder::unretract ( )
123{
124 // BBS
125 if (m_share_extruder) {
127 this->extrude(dE);
129 m_restart_extra = 0.;
130 return dE;
131 } else {
132 double dE = m_retracted + m_restart_extra;
133 this->extrude(dE);
134 m_retracted = 0.;
135 m_restart_extra = 0.;
136 return dE;
137 }
138}
double extrude(double dE)
Definition Extruder.cpp:48

References extrude(), extruder_id(), m_restart_extra, m_retracted, m_share_extruder, and m_share_retracted.

Here is the call graph for this function:

◆ use_firmware_retraction()

bool Slic3r::Extruder::use_firmware_retraction ( ) const
231{
232 return m_config->use_firmware_retraction;
233}

References m_config.

◆ used_filament()

double Slic3r::Extruder::used_filament ( ) const
172{
173 // BBS
174 if (m_share_extruder) {
175 // FIXME: need to count retracted length for share-extruder machine
176 return m_absolute_E;
177 } else {
178 return m_absolute_E + m_retracted;
179 }
180}

References m_absolute_E, m_retracted, and m_share_extruder.

Referenced by extruded_volume().

Here is the caller graph for this function:

Member Data Documentation

◆ m_absolute_E

double Slic3r::Extruder::m_absolute_E
private

Referenced by extrude(), reset(), retract(), and used_filament().

◆ m_config

◆ m_config_index

◆ m_E

double Slic3r::Extruder::m_E
private

◆ m_e_per_mm3

double Slic3r::Extruder::m_e_per_mm3
private

◆ m_E_rounding_carry

double Slic3r::Extruder::m_E_rounding_carry { 0. }
private
113{ 0. };

Referenced by E_to_emit(), and reset().

◆ m_id

unsigned int Slic3r::Extruder::m_id
private

◆ m_restart_extra

double Slic3r::Extruder::m_restart_extra
private

◆ m_retracted

double Slic3r::Extruder::m_retracted
private

◆ m_share_E

std::vector< double > Slic3r::Extruder::m_share_E = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0)
staticprivate

Referenced by E(), extrude(), reset(), reset_E(), and retract().

◆ m_share_extruder

bool Slic3r::Extruder::m_share_extruder
private

◆ m_share_retracted

std::vector< double > Slic3r::Extruder::m_share_retracted = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0)
staticprivate

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Extruder.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Extruder.cpp