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

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

Inheritance diagram for Slic3r::CalibPressureAdvanceLine:
Collaboration diagram for Slic3r::CalibPressureAdvanceLine:

Public Member Functions

 CalibPressureAdvanceLine (GCode *gcodegen)
 ~CalibPressureAdvanceLine ()
BoundingBoxf print_extents (const BoundingBoxf &bed_ext) const
std::string generate_test (double start_pa=0, double step_pa=0.002, int count=50)
void set_speed (double fast=100.0, double slow=20.0)
const double & line_width ()
const double & height_layer ()
bool is_delta () const
bool & draw_numbers ()

Static Public Member Functions

static float find_optimal_PA_speed (const DynamicPrintConfig &config, double line_width, double layer_height, int extruder_id=0, int filament_idx=0)

Protected Types

enum class  DrawDigitMode { Left_To_Right , Bottom_To_Top }

Protected Member Functions

void delta_scale_bed_ext (BoundingBoxf &bed_ext) const
std::string move_to (Vec2d pt, GCodeWriter &writer, std::string comment=std::string(), double z=0, double layer_height=-1)
double e_per_mm (double line_width, double layer_height, float nozzle_diameter, float filament_diameter, float print_flow_ratio) const
double speed_adjust (int speed) const
std::string convert_number_to_string (double num, unsigned precision=0) const
double number_spacing () const
std::string draw_digit (double startx, double starty, char c, CalibPressureAdvance::DrawDigitMode mode, double line_width, double e_per_mm, GCodeWriter &writer)
std::string draw_number (double startx, double starty, double value, CalibPressureAdvance::DrawDigitMode mode, double line_width, double e_per_mm, double speed, GCodeWriter &writer)
std::string draw_line (GCodeWriter &writer, Vec2d to_pt, double line_width, double layer_height, double speed, const std::string &comment=std::string())
std::string draw_box (GCodeWriter &writer, double min_x, double min_y, double size_x, double size_y, DrawBoxOptArgs opt_args)
double to_radians (double degrees) const
double get_distance (Vec2d from, Vec2d to) const

Protected Attributes

Vec3d m_last_pos
DynamicPrintConfig m_config
const double m_encroachment {1. / 3.}
DrawDigitMode m_draw_digit_mode {DrawDigitMode::Left_To_Right}
const double m_digit_segment_len {2}
const double m_digit_gap_len {1}
const std::string::size_type m_max_number_len {5}
std::string::size_type m_number_len {m_max_number_len}

Private Member Functions

std::string print_pa_lines (double start_x, double start_y, double start_pa, double step_pa, int num)
void delta_modify_start (double &startx, double &starty, int count)

Private Attributes

GCode * mp_gcodegen
double m_nozzle_diameter
double m_slow_speed
double m_fast_speed
double m_height_layer {0.2}
double m_line_width {0.6}
double m_thin_line_width {0.44}
double m_number_line_width {0.48}
const double m_space_y {3.5}
double m_length_short {20.0}
double m_length_long {40.0}
bool m_draw_numbers {true}

Detailed Description

Member Enumeration Documentation

◆ DrawDigitMode

enum class Slic3r::CalibPressureAdvance::DrawDigitMode
strongprotectedinherited
Enumerator
Left_To_Right 
Bottom_To_Top 
213{ Left_To_Right, Bottom_To_Top };

Constructor & Destructor Documentation

◆ CalibPressureAdvanceLine()

Slic3r::CalibPressureAdvanceLine::CalibPressureAdvanceLine ( GCode * gcodegen)
474 : CalibPressureAdvance(gcodegen->config()), mp_gcodegen(gcodegen), m_nozzle_diameter(gcodegen->config().nozzle_diameter.get_at(0))
475{
477 m_height_layer = gcodegen->config().initial_layer_print_height;
479};
double m_nozzle_diameter
Definition calib.hpp:285
GCode * mp_gcodegen
Definition calib.hpp:283
double m_number_line_width
Definition calib.hpp:291
double m_line_width
Definition calib.hpp:289
double m_thin_line_width
Definition calib.hpp:290
double m_height_layer
Definition calib.hpp:288

References Slic3r::CalibPressureAdvance::CalibPressureAdvance(), Slic3r::GCode::config(), Slic3r::initial_layer_print_height(), m_height_layer, m_line_width, m_nozzle_diameter, m_number_line_width, m_thin_line_width, mp_gcodegen, and Slic3r::nozzle_diameter().

Here is the call graph for this function:

◆ ~CalibPressureAdvanceLine()

Slic3r::CalibPressureAdvanceLine::~CalibPressureAdvanceLine ( )
inline
261{};

Member Function Documentation

◆ convert_number_to_string()

std::string Slic3r::CalibPressureAdvance::convert_number_to_string ( double num,
unsigned precision = 0 ) const
protectedinherited
83{
84 std::ostringstream stream;
85
86 if (precision) {
87 /* if number is > 1000 then there are no way we'll fit fractional part into 5 glyphs, so
88 * in this case we keep full precision.
89 * Otherwise we reduce precision by 1 to accomodate decimal separator */
90 stream << std::setprecision(num >= 1000 ? precision : precision - 1);
91 }
92
93 stream << num;
94
95 return stream.str();
96}

Referenced by draw_number(), and Slic3r::CalibPressureAdvancePattern::max_numbering_length().

Here is the caller graph for this function:

◆ delta_modify_start()

void Slic3r::CalibPressureAdvanceLine::delta_modify_start ( double & startx,
double & starty,
int count )
private
610{
611 startx = -startx;
612 starty = -(count * m_space_y) / 2;
613}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
const double m_space_y
Definition calib.hpp:292

References count, and m_space_y.

◆ delta_scale_bed_ext()

void Slic3r::CalibPressureAdvance::delta_scale_bed_ext ( BoundingBoxf & bed_ext) const
inlineprotectedinherited
215{ bed_ext.scale(1.0f / 1.41421f); }

References Slic3r::BoundingBoxBase< PointType, APointsType >::scale().

Referenced by Slic3r::CalibPressureAdvanceLine::generate_test(), and Slic3r::CalibPressureAdvanceLine::print_extents().

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

◆ draw_box()

std::string Slic3r::CalibPressureAdvance::draw_box ( GCodeWriter & writer,
double min_x,
double min_y,
double size_x,
double size_y,
DrawBoxOptArgs opt_args )
protectedinherited
291{
292 std::stringstream gcode;
293
294 double x = min_x;
295 double y = min_y;
296 const double max_x = min_x + size_x;
297 const double max_y = min_y + size_y;
298
299 const double spacing = opt_args.line_width - opt_args.height * (1 - M_PI / 4);
300
301 // if number of perims exceeds size of box, reduce it to max
302 const int max_perimeters = std::min(
303 // this is the equivalent of number of perims for concentric fill
304 std::floor(size_x * std::sin(to_radians(45))) / (spacing / std::sin(to_radians(45))),
305 std::floor(size_y * std::sin(to_radians(45))) / (spacing / std::sin(to_radians(45))));
306
307 opt_args.num_perimeters = std::min(opt_args.num_perimeters, max_perimeters);
308
309 gcode << move_to(Vec2d(min_x, min_y), writer, "Move to box start");
310
311 // DrawLineOptArgs line_opt_args(*this);
312 auto line_arg_height = opt_args.height;
313 auto line_arg_line_width = opt_args.line_width;
314 auto line_arg_speed = opt_args.speed;
315 std::string comment = "";
316
317 for (int i = 0; i < opt_args.num_perimeters; ++i) {
318 if (i != 0) { // after first perimeter, step inwards to start next perimeter
319 x += spacing;
320 y += spacing;
321 gcode << move_to(Vec2d(x, y), writer, "Step inwards to print next perimeter");
322 }
323
324 y += size_y - i * spacing * 2;
325 comment = "Draw perimeter (up)";
326 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
327
328 x += size_x - i * spacing * 2;
329 comment = "Draw perimeter (right)";
330 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
331
332 y -= size_y - i * spacing * 2;
333 comment = "Draw perimeter (down)";
334 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
335
336 x -= size_x - i * spacing * 2;
337 comment = "Draw perimeter (left)";
338 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
339 }
340
341 if (!opt_args.is_filled) {
342 return gcode.str();
343 }
344
345 // create box infill
346 const double spacing_45 = spacing / std::sin(to_radians(45));
347
348 const double bound_modifier = (spacing * (opt_args.num_perimeters - 1)) + (opt_args.line_width * (1 - m_encroachment));
349 const double x_min_bound = min_x + bound_modifier;
350 const double x_max_bound = max_x - bound_modifier;
351 const double y_min_bound = min_y + bound_modifier;
352 const double y_max_bound = max_y - bound_modifier;
353 const int x_count = std::floor((x_max_bound - x_min_bound) / spacing_45);
354 const int y_count = std::floor((y_max_bound - y_min_bound) / spacing_45);
355
356 double x_remainder = std::fmod((x_max_bound - x_min_bound), spacing_45);
357 double y_remainder = std::fmod((y_max_bound - y_min_bound), spacing_45);
358
359 x = x_min_bound;
360 y = y_min_bound;
361
362 gcode << move_to(Vec2d(x, y), writer, "Move to fill start");
363
364 for (int i = 0; i < x_count + y_count + (x_remainder + y_remainder >= spacing_45 ? 1 : 0);
365 ++i) { // this isn't the most robust way, but less expensive than finding line intersections
366 if (i < std::min(x_count, y_count)) {
367 if (i % 2 == 0) {
368 x += spacing_45;
369 y = y_min_bound;
370 gcode << move_to(Vec2d(x, y), writer, "Fill: Step right");
371
372 y += x - x_min_bound;
373 x = x_min_bound;
374 comment = "Fill: Print up/left";
375 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
376 } else {
377 y += spacing_45;
378 x = x_min_bound;
379 gcode << move_to(Vec2d(x, y), writer, "Fill: Step up");
380
381 x += y - y_min_bound;
382 y = y_min_bound;
383 comment = "Fill: Print down/right";
384 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
385 }
386 } else if (i < std::max(x_count, y_count)) {
387 if (x_count > y_count) {
388 // box is wider than tall
389 if (i % 2 == 0) {
390 x += spacing_45;
391 y = y_min_bound;
392 gcode << move_to(Vec2d(x, y), writer, "Fill: Step right");
393
394 x -= y_max_bound - y_min_bound;
395 y = y_max_bound;
396 comment = "Fill: Print up/left";
397 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
398 } else {
399 if (i == y_count) {
400 x += spacing_45 - y_remainder;
401 y_remainder = 0;
402 } else {
403 x += spacing_45;
404 }
405 y = y_max_bound;
406 gcode << move_to(Vec2d(x, y), writer, "Fill: Step right");
407
408 x += y_max_bound - y_min_bound;
409 y = y_min_bound;
410 comment = "Fill: Print down/right";
411 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
412 }
413 } else {
414 // box is taller than wide
415 if (i % 2 == 0) {
416 x = x_max_bound;
417 if (i == x_count) {
418 y += spacing_45 - x_remainder;
419 x_remainder = 0;
420 } else {
421 y += spacing_45;
422 }
423 gcode << move_to(Vec2d(x, y), writer, "Fill: Step up");
424
425 x = x_min_bound;
426 y += x_max_bound - x_min_bound;
427 comment = "Fill: Print up/left";
428 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
429 } else {
430 x = x_min_bound;
431 y += spacing_45;
432 gcode << move_to(Vec2d(x, y), writer, "Fill: Step up");
433
434 x = x_max_bound;
435 y -= x_max_bound - x_min_bound;
436 comment = "Fill: Print down/right";
437 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
438 }
439 }
440 } else {
441 if (i % 2 == 0) {
442 x = x_max_bound;
443 if (i == x_count) {
444 y += spacing_45 - x_remainder;
445 } else {
446 y += spacing_45;
447 }
448 gcode << move_to(Vec2d(x, y), writer, "Fill: Step up");
449
450 x -= y_max_bound - y;
451 y = y_max_bound;
452 comment = "Fill: Print up/left";
453 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
454 } else {
455 if (i == y_count) {
456 x += spacing_45 - y_remainder;
457 } else {
458 x += spacing_45;
459 }
460 y = y_max_bound;
461 gcode << move_to(Vec2d(x, y), writer, "Fill: Step right");
462
463 y -= x_max_bound - x;
464 x = x_max_bound;
465 comment = "Fill: Print down/right";
466 gcode << draw_line(writer, Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
467 }
468 }
469 }
470
471 return gcode.str();
472}
#define M_PI
Definition ExtrusionSimulator.cpp:31
const double m_encroachment
Definition calib.hpp:249
double to_radians(double degrees) const
Definition calib.hpp:243
std::string move_to(Vec2d pt, GCodeWriter &writer, std::string comment=std::string(), double z=0, double layer_height=-1)
Definition calib.cpp:54
std::string draw_line(GCodeWriter &writer, Vec2d to_pt, double line_width, double layer_height, double speed, const std::string &comment=std::string())
Definition calib.cpp:269
@ gcode
Definition Time.hpp:14
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References draw_line(), Slic3r::DrawBoxOptArgs::height, Slic3r::DrawBoxOptArgs::is_filled, Slic3r::DrawBoxOptArgs::line_width, m_encroachment, M_PI, move_to(), Slic3r::DrawBoxOptArgs::num_perimeters, Slic3r::DrawBoxOptArgs::speed, and to_radians().

Referenced by Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

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

◆ draw_digit()

std::string Slic3r::CalibPressureAdvance::draw_digit ( double startx,
double starty,
char c,
CalibPressureAdvance::DrawDigitMode mode,
double line_width,
double e_per_mm,
GCodeWriter & writer )
protectedinherited
100{
101 const double len = m_digit_segment_len;
102 const double gap = line_width / 2.0;
103
104 const auto dE = e_per_mm * len;
105 const auto two_dE = dE * 2;
106
107 Vec2d p0, p1, p2, p3, p4, p5;
108 Vec2d p0_5, p4_5;
109 Vec2d gap_p0_toward_p3, gap_p2_toward_p3;
110 Vec2d dot_direction;
111
113 // 1-------2-------5
114 // | | |
115 // | | |
116 // 0-------3-------4
117 p0 = Vec2d(startx, starty);
118 p0_5 = Vec2d(startx, starty + len / 2);
119 p1 = Vec2d(startx, starty + len);
120 p2 = Vec2d(startx + len, starty + len);
121 p3 = Vec2d(startx + len, starty);
122 p4 = Vec2d(startx + len * 2, starty);
123 p4_5 = Vec2d(startx + len * 2, starty + len / 2);
124 p5 = Vec2d(startx + len * 2, starty + len);
125
126 gap_p0_toward_p3 = p0 + Vec2d(gap, 0);
127 gap_p2_toward_p3 = p2 + Vec2d(0, gap);
128
129 dot_direction = Vec2d(-len / 2, 0);
130 } else {
131 // 0-------1
132 // | |
133 // 3-------2
134 // | |
135 // 4-------5
136 p0 = Vec2d(startx, starty);
137 p0_5 = Vec2d(startx + len / 2, starty);
138 p1 = Vec2d(startx + len, starty);
139 p2 = Vec2d(startx + len, starty - len);
140 p3 = Vec2d(startx, starty - len);
141 p4 = Vec2d(startx, starty - len * 2);
142 p4_5 = Vec2d(startx + len / 2, starty - len * 2);
143 p5 = Vec2d(startx + len, starty - len * 2);
144
145 gap_p0_toward_p3 = p0 - Vec2d(0, gap);
146 gap_p2_toward_p3 = p2 - Vec2d(gap, 0);
147
148 dot_direction = Vec2d(0, len / 2);
149 }
150
151 std::stringstream gcode;
152
153 switch (c) {
154 case '0':
155 gcode << move_to(p0, writer, "Glyph: 0");
156 gcode << writer.extrude_to_xy(p1, dE);
157 gcode << writer.extrude_to_xy(p5, two_dE);
158 gcode << writer.extrude_to_xy(p4, dE);
159 gcode << writer.extrude_to_xy(gap_p0_toward_p3, two_dE);
160 break;
161 case '1':
162 gcode << move_to(p0_5, writer, "Glyph: 1");
163 gcode << writer.extrude_to_xy(p4_5, two_dE);
164 break;
165 case '2':
166 gcode << move_to(p0, writer, "Glyph: 2");
167 gcode << writer.extrude_to_xy(p1, dE);
168 gcode << writer.extrude_to_xy(p2, dE);
169 gcode << writer.extrude_to_xy(p3, dE);
170 gcode << writer.extrude_to_xy(p4, dE);
171 gcode << writer.extrude_to_xy(p5, dE);
172 break;
173 case '3':
174 gcode << move_to(p0, writer, "Glyph: 3");
175 gcode << writer.extrude_to_xy(p1, dE);
176 gcode << writer.extrude_to_xy(p5, two_dE);
177 gcode << writer.extrude_to_xy(p4, dE);
178 gcode << move_to(gap_p2_toward_p3, writer);
179 gcode << writer.extrude_to_xy(p3, dE);
180 break;
181 case '4':
182 gcode << move_to(p0, writer, "Glyph: 4");
183 gcode << writer.extrude_to_xy(p3, dE);
184 gcode << writer.extrude_to_xy(p2, dE);
185 gcode << move_to(p1, writer);
186 gcode << writer.extrude_to_xy(p5, two_dE);
187 break;
188 case '5':
189 gcode << move_to(p1, writer, "Glyph: 5");
190 gcode << writer.extrude_to_xy(p0, dE);
191 gcode << writer.extrude_to_xy(p3, dE);
192 gcode << writer.extrude_to_xy(p2, dE);
193 gcode << writer.extrude_to_xy(p5, dE);
194 gcode << writer.extrude_to_xy(p4, dE);
195 break;
196 case '6':
197 gcode << move_to(p1, writer, "Glyph: 6");
198 gcode << writer.extrude_to_xy(p0, dE);
199 gcode << writer.extrude_to_xy(p4, two_dE);
200 gcode << writer.extrude_to_xy(p5, dE);
201 gcode << writer.extrude_to_xy(p2, dE);
202 gcode << writer.extrude_to_xy(p3, dE);
203 break;
204 case '7':
205 gcode << move_to(p0, writer, "Glyph: 7");
206 gcode << writer.extrude_to_xy(p1, dE);
207 gcode << writer.extrude_to_xy(p5, two_dE);
208 break;
209 case '8':
210 gcode << move_to(p2, writer, "Glyph: 8");
211 gcode << writer.extrude_to_xy(p3, dE);
212 gcode << writer.extrude_to_xy(p4, dE);
213 gcode << writer.extrude_to_xy(p5, dE);
214 gcode << writer.extrude_to_xy(p1, two_dE);
215 gcode << writer.extrude_to_xy(p0, dE);
216 gcode << writer.extrude_to_xy(p3, dE);
217 break;
218 case '9':
219 gcode << move_to(p5, writer, "Glyph: 9");
220 gcode << writer.extrude_to_xy(p1, two_dE);
221 gcode << writer.extrude_to_xy(p0, dE);
222 gcode << writer.extrude_to_xy(p3, dE);
223 gcode << writer.extrude_to_xy(p2, dE);
224 break;
225 case '.':
226 gcode << move_to(p4_5, writer, "Glyph: .");
227 gcode << writer.extrude_to_xy(p4_5 + dot_direction, dE);
228 break;
229 default: break;
230 }
231
232 return gcode.str();
233}
const double m_digit_segment_len
Definition calib.hpp:251
@ Bottom_To_Top
Definition calib.hpp:213
double e_per_mm(double line_width, double layer_height, float nozzle_diameter, float filament_diameter, float print_flow_ratio) const
Definition calib.cpp:73

References Bottom_To_Top, e_per_mm(), Slic3r::GCodeWriter::extrude_to_xy(), m_digit_segment_len, and move_to().

Referenced by draw_number().

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

◆ draw_line()

std::string Slic3r::CalibPressureAdvance::draw_line ( GCodeWriter & writer,
Vec2d to_pt,
double line_width,
double layer_height,
double speed,
const std::string & comment = std::string() )
protectedinherited
271{
272 const double e_per_mm = CalibPressureAdvance::e_per_mm(line_width, layer_height,
273 m_config.option<ConfigOptionFloats>("nozzle_diameter")->get_at(0),
274 m_config.option<ConfigOptionFloats>("filament_diameter")->get_at(0),
275 m_config.option<ConfigOptionFloatsNullable>("filament_flow_ratio")->get_at(0));
276
277 const double length = get_distance(Vec2d(m_last_pos.x(), m_last_pos.y()), to_pt);
278 auto dE = e_per_mm * length;
279
280 std::stringstream gcode;
281
282 gcode << writer.set_speed(speed);
283 gcode << writer.extrude_to_xy(to_pt, dE, comment);
284
285 m_last_pos = Vec3d(to_pt.x(), to_pt.y(), 0);
286
287 return gcode.str();
288}
Vec3d m_last_pos
Definition calib.hpp:246
DynamicPrintConfig m_config
Definition calib.hpp:247
double get_distance(Vec2d from, Vec2d to) const
Definition calib.cpp:264
const double & get_at(size_t i) const
Definition Config.hpp:676
double length(const Points &pts)
Definition MultiPoint.hpp:181
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
layer_height((ConfigOptionInt, faded_layers))((ConfigOptionFloat
ConfigOptionFloatsTempl< true > ConfigOptionFloatsNullable
Definition Config.hpp:1016
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:1015

References e_per_mm(), Slic3r::GCodeWriter::extrude_to_xy(), get_distance(), Slic3r::layer_height(), Slic3r::length(), m_config, m_last_pos, and Slic3r::GCodeWriter::set_speed().

Referenced by draw_box(), and Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes().

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

◆ draw_number()

std::string Slic3r::CalibPressureAdvance::draw_number ( double startx,
double starty,
double value,
CalibPressureAdvance::DrawDigitMode mode,
double line_width,
double e_per_mm,
double speed,
GCodeWriter & writer )
protectedinherited
243{
244 auto sNumber = convert_number_to_string(value, m_number_len);
245 std::stringstream gcode;
246 gcode << writer.set_speed(speed);
247
248 for (std::string::size_type i = 0; i < sNumber.length(); ++i) {
249 if (i >= m_number_len) {
250 break;
251 }
252 switch (mode) {
254 gcode << draw_digit(startx, starty + i * number_spacing(), sNumber[i], mode, line_width, e_per_mm, writer);
255 break;
256 default: gcode << draw_digit(startx + i * number_spacing(), starty, sNumber[i], mode, line_width, e_per_mm, writer);
257 }
258 }
259
260 return gcode.str();
261}
std::string convert_number_to_string(double num, unsigned precision=0) const
Definition calib.cpp:82
std::string draw_digit(double startx, double starty, char c, CalibPressureAdvance::DrawDigitMode mode, double line_width, double e_per_mm, GCodeWriter &writer)
Definition calib.cpp:98
double number_spacing() const
Definition calib.hpp:222
std::string::size_type m_number_len
Definition calib.hpp:254

References Bottom_To_Top, convert_number_to_string(), draw_digit(), e_per_mm(), m_number_len, number_spacing(), and Slic3r::GCodeWriter::set_speed().

Referenced by Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

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

◆ draw_numbers()

bool & Slic3r::CalibPressureAdvanceLine::draw_numbers ( )
inline
276{ return m_draw_numbers; }
bool m_draw_numbers
Definition calib.hpp:295

References m_draw_numbers.

Referenced by Slic3r::GCode::_do_export().

Here is the caller graph for this function:

◆ e_per_mm()

double Slic3r::CalibPressureAdvance::e_per_mm ( double line_width,
double layer_height,
float nozzle_diameter,
float filament_diameter,
float print_flow_ratio ) const
protectedinherited
75{
76 const Flow line_flow = Flow(line_width, layer_height, nozzle_diameter);
77 const double filament_area = M_PI * std::pow(filament_diameter / 2, 2);
78
79 return line_flow.mm3_per_mm() * print_flow_ratio / filament_area ;
80}
zaa_minimize_perimeter_height nozzle_diameter((ConfigOptionBool, reduce_infill_retraction))((ConfigOptionBool
print_flow_ratio((ConfigOptionFloatOrPercent, seam_gap))((ConfigOptionBool

References Slic3r::layer_height(), M_PI, Slic3r::Flow::mm3_per_mm(), Slic3r::nozzle_diameter(), and Slic3r::print_flow_ratio().

Referenced by draw_digit(), draw_line(), draw_number(), Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

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

◆ find_optimal_PA_speed()

float Slic3r::CalibPressureAdvance::find_optimal_PA_speed ( const DynamicPrintConfig & config,
double line_width,
double layer_height,
int extruder_id = 0,
int filament_idx = 0 )
staticinherited
30{
31 const double general_suggested_min_speed = 100.0;
32 // Read defensively — CLI callers may hand us a config missing optional keys.
33 auto vector_at = [&config](const char *key, int idx) -> double {
34 if (const auto *o = config.option<ConfigOptionFloats>(key)) return o->get_at(idx);
35 const ConfigOptionDef *d = config.def() ? config.def()->get(key) : nullptr;
36 return (d && d->default_value) ? d->get_default_value<ConfigOptionFloats>()->get_at(idx) : 0.0;
37 };
38 auto nullable_at = [&config](const char *key, int idx) -> double {
39 if (const auto *o = config.option<ConfigOptionFloatsNullable>(key)) return o->get_at(idx);
40 const ConfigOptionDef *d = config.def() ? config.def()->get(key) : nullptr;
41 return (d && d->default_value) ? d->get_default_value<ConfigOptionFloatsNullable>()->get_at(idx) : 0.0;
42 };
43 double filament_max_volumetric_speed = vector_at("filament_max_volumetric_speed", filament_idx);
44 // todo multi_extruders:
45 const float nozzle_diameter = vector_at("nozzle_diameter", extruder_id);
46 if (line_width <= 0.) line_width = Flow::auto_extrusion_width(frPerimeter, nozzle_diameter);
47 Flow pattern_line = Flow(line_width, layer_height, nozzle_diameter);
48 auto pa_speed = std::min(std::max(general_suggested_min_speed, nullable_at("outer_wall_speed", extruder_id)),
49 filament_max_volumetric_speed / pattern_line.mm3_per_mm());
50
51 return std::floor(pa_speed);
52}
static float auto_extrusion_width(FlowRole role, float nozzle_diameter)
Definition Flow.cpp:27
@ frPerimeter
Definition Flow.hpp:20

References Slic3r::Flow::auto_extrusion_width(), Slic3r::DynamicPrintConfig::def(), Slic3r::ConfigOptionDef::default_value, Slic3r::frPerimeter, Slic3r::ConfigDef::get(), Slic3r::ConfigOptionDef::get_default_value(), Slic3r::layer_height(), Slic3r::Flow::mm3_per_mm(), Slic3r::nozzle_diameter(), and Slic3r::ConfigBase::option().

Referenced by Slic3r::GUI::Plater::_calib_pa_pattern(), Slic3r::GCode::_do_export(), Slic3r::GUI::CalibUtils::calib_pa_pattern(), and Slic3r::GUI::CalibUtils::set_for_auto_pa_model_and_config().

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

◆ generate_test()

std::string Slic3r::CalibPressureAdvanceLine::generate_test ( double start_pa = 0,
double step_pa = 0.002,
int count = 50 )
482{
483 BoundingBoxf bed_ext = get_extents(mp_gcodegen->config().printable_area.values);
484 if (is_delta()) {
486 }
487
488 auto bed_sizes = mp_gcodegen->config().printable_area.values;
489 const auto w = bed_ext.size().x();
490 const auto h = bed_ext.size().y();
491 count = std::min(count, int((h - 10) / m_space_y));
492
493 m_length_long = 40 + std::min(w - 120.0, 0.0);
494
495 auto startx = bed_ext.min.x() + (w - m_length_short * 2 - m_length_long - 20) / 2;
496 auto starty = bed_ext.min.y() + (h - count * m_space_y) / 2;
497
498 return print_pa_lines(startx, starty, start_pa, step_pa, count);
499}
bool is_delta() const
Definition calib.cpp:526
double m_length_short
Definition calib.hpp:294
double m_length_long
Definition calib.hpp:294
std::string print_pa_lines(double start_x, double start_y, double start_pa, double step_pa, int num)
Definition calib.cpp:528
void delta_scale_bed_ext(BoundingBoxf &bed_ext) const
Definition calib.hpp:215
BoundingBox get_extents(const ExPolygonsWithIds &e)
Definition Emboss.cpp:1374

References count, Slic3r::CalibPressureAdvance::delta_scale_bed_ext(), Slic3r::get_extents(), is_delta(), m_length_long, m_length_short, m_space_y, Slic3r::BoundingBoxBase< PointType, APointsType >::min, mp_gcodegen, print_pa_lines(), and Slic3r::BoundingBoxBase< PointType, APointsType >::size().

Referenced by Slic3r::GCode::_do_export().

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

◆ get_distance()

double Slic3r::CalibPressureAdvance::get_distance ( Vec2d from,
Vec2d to ) const
protectedinherited
265{
266 return std::hypot((to.x() - from.x()), (to.y() - from.y()));
267}

Referenced by draw_line().

Here is the caller graph for this function:

◆ height_layer()

const double & Slic3r::CalibPressureAdvanceLine::height_layer ( )
inline
274{ return m_height_layer; };

References m_height_layer.

Referenced by Slic3r::GCode::_do_export().

Here is the caller graph for this function:

◆ is_delta()

bool Slic3r::CalibPressureAdvanceLine::is_delta ( ) const
526{ return mp_gcodegen->config().printable_area.values.size() > 4; }

References mp_gcodegen.

Referenced by generate_test(), and print_extents().

Here is the caller graph for this function:

◆ line_width()

const double & Slic3r::CalibPressureAdvanceLine::line_width ( )
inline
273{ return m_line_width; };

References m_line_width.

Referenced by Slic3r::GCode::_do_export().

Here is the caller graph for this function:

◆ move_to()

std::string Slic3r::CalibPressureAdvance::move_to ( Vec2d pt,
GCodeWriter & writer,
std::string comment = std::string(),
double z = 0,
double layer_height = -1 )
protectedinherited
55{
56 std::stringstream gcode;
57
58 gcode << writer.retract(); // retract before z move or move
59 if(z > EPSILON && layer_height >= 0){
60 gcode << writer.travel_to_z(z, "Z-hop"); // Perform z hop
61 gcode << writer.travel_to_xy(pt, comment); // Travel with z move
62 gcode << writer.travel_to_z(layer_height, "undo Z-hop"); // Undo z hop
63 }else {
64 gcode << writer.travel_to_xy(pt, comment);
65 }
66 gcode << writer.unretract(); // unretract after z move is complete
67
68 m_last_pos = Vec3d(pt.x(), pt.y(), 0);
69
70 return gcode.str();
71}
#define EPSILON
Definition ColorUtils.cpp:64

References EPSILON, Slic3r::layer_height(), m_last_pos, Slic3r::GCodeWriter::retract(), Slic3r::GCodeWriter::travel_to_xy(), Slic3r::GCodeWriter::travel_to_z(), and Slic3r::GCodeWriter::unretract().

Referenced by draw_box(), draw_digit(), Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

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

◆ number_spacing()

double Slic3r::CalibPressureAdvance::number_spacing ( ) const
inlineprotectedinherited
const double m_digit_gap_len
Definition calib.hpp:252

References m_digit_gap_len, and m_digit_segment_len.

Referenced by draw_number(), Slic3r::CalibPressureAdvanceLine::print_extents(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

Here is the caller graph for this function:

◆ print_extents()

BoundingBoxf Slic3r::CalibPressureAdvanceLine::print_extents ( const BoundingBoxf & bed_ext) const
502{
503 BoundingBoxf adjusted_bed = bed_ext;
504 if (is_delta()) {
506 }
507
508 double bed_width = adjusted_bed.size().x();
509 // m_length_long adjusts for narrow beds – exactly as in generate_test()
510 double line_long = 40.0 + std::min(bed_width - 120.0, 0.0);
511 double total_line_len = m_length_short * 2 + line_long;
512 double start_x = adjusted_bed.min.x() + (bed_width - 2 * m_length_short - line_long - 20.0) / 2.0;
513 double box_width = m_draw_numbers ? (number_spacing() * 8) : 0.0; // 3.0 * 8 = 24 mm
514
515 BoundingBoxf extent;
516 extent.min.x() = start_x;
517 extent.max.x() = start_x + total_line_len + m_line_width + box_width;
518
519 // Y bounds are the full bed (the caller will inset them by -25)
520 extent.min.y() = adjusted_bed.min.y();
521 extent.max.y() = adjusted_bed.max.y();
522
523 return extent;
524}

References Slic3r::CalibPressureAdvance::delta_scale_bed_ext(), is_delta(), m_draw_numbers, m_length_short, m_line_width, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::CalibPressureAdvance::number_spacing(), and Slic3r::BoundingBoxBase< PointType, APointsType >::size().

Referenced by Slic3r::GCode::_do_export().

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

◆ print_pa_lines()

std::string Slic3r::CalibPressureAdvanceLine::print_pa_lines ( double start_x,
double start_y,
double start_pa,
double step_pa,
int num )
private
529{
530 auto &writer = mp_gcodegen->writer();
531 const auto &config = mp_gcodegen->config();
532
533 const auto filament_diameter = config.filament_diameter.get_at(0);
534 const auto print_flow_ratio = config.print_flow_ratio;
535 const auto z_offset = config.z_offset;
536
539 const double thin_e_per_mm = CalibPressureAdvance::e_per_mm(m_thin_line_width, m_height_layer, m_nozzle_diameter, filament_diameter,
541 const double number_e_per_mm = CalibPressureAdvance::e_per_mm(m_number_line_width, m_height_layer, m_nozzle_diameter, filament_diameter,
543
546 std::stringstream gcode;
547 gcode << mp_gcodegen->writer().travel_to_z(m_height_layer + z_offset);
549 double y_pos = start_y;
550 // Purge/first perimeter - acts as an anchor to the rest of the model
552 gcode << writer.set_pressure_advance(0.0);
553 auto prime_x = start_x;
554 gcode << move_to(Vec2d(prime_x, y_pos + (num) * m_space_y), writer);
555 gcode << writer.set_speed(slow);
556 gcode << writer.extrude_to_xy(Vec2d(prime_x, y_pos), e_per_mm * m_space_y * num * 1.2);
557
558 for (int i = 0; i < num; ++i) {
559 gcode << writer.set_pressure_advance(start_pa + i * step_pa);
560 gcode << move_to(Vec2d(start_x, y_pos + i * m_space_y), writer);
562 gcode << writer.set_speed(slow);
563 gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short, y_pos + i * m_space_y), e_per_mm * m_length_short);
565 gcode << writer.set_speed(fast);
566 gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short + m_length_long, y_pos + i * m_space_y), e_per_mm * m_length_long);
568 gcode << writer.set_speed(slow);
569 gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short + m_length_long + m_length_short, y_pos + i * m_space_y),
571
572 if (i == 0) {
573 // Print extra anchor line
574 gcode << writer.set_pressure_advance(0.0);
575 gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short + m_length_long + m_length_short, y_pos + (num) * m_space_y), e_per_mm * m_space_y * num * 1.2);
576 }
577 }
578 gcode << writer.set_pressure_advance(0.0);
579
580 if (m_draw_numbers) {
581
582 // Orca: skip drawing indicator lines
583 // gcode << writer.set_speed(fast);
584 // gcode << move_to(Vec2d(start_x + m_length_short, y_pos + (num - 1) * m_space_y + 2), writer);
585 // gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short, y_pos + (num - 1) * m_space_y + 7), thin_e_per_mm * 7);
586 // gcode << move_to(Vec2d(start_x + m_length_short + m_length_long, y_pos + (num - 1) * m_space_y + 7), writer);
587 // gcode << writer.extrude_to_xy(Vec2d(start_x + m_length_short + m_length_long, y_pos + (num - 1) * m_space_y + 2), thin_e_per_mm * 7);
588
589 const auto box_start_x = start_x + m_length_short + m_length_long + m_length_short + m_line_width;
590 DrawBoxOptArgs default_box_opt_args(2, m_height_layer, m_line_width, fast);
591 //Draw box
592 default_box_opt_args.is_filled = true;
593 gcode << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role) << "Bottom surface\n";
594 gcode << draw_box(writer, box_start_x, start_y - m_space_y,
595 number_spacing() * 8, (num + 1) * m_space_y, default_box_opt_args);
596 //Ensure numbers are shown on the next layer in gcode processor, as in reality
600 gcode << writer.travel_to_z(m_height_layer*2 + z_offset);
601 for (int i = 0; i < num; i += 2) {
602 gcode << draw_number(box_start_x + 3 + m_line_width, y_pos + i * m_space_y + m_space_y / 2, start_pa + i * step_pa, m_draw_digit_mode,
603 m_number_line_width, number_e_per_mm, 3600, writer);
604 }
605 }
606 return gcode.str();
607}
double m_fast_speed
Definition calib.hpp:286
double m_slow_speed
Definition calib.hpp:286
std::string draw_box(GCodeWriter &writer, double min_x, double min_y, double size_x, double size_y, DrawBoxOptArgs opt_args)
Definition calib.cpp:290
double speed_adjust(int speed) const
Definition calib.hpp:219
std::string draw_number(double startx, double starty, double value, CalibPressureAdvance::DrawDigitMode mode, double line_width, double e_per_mm, double speed, GCodeWriter &writer)
Definition calib.cpp:235
DrawDigitMode m_draw_digit_mode
Definition calib.hpp:250
static const std::string & reserved_tag(ETags tag)
Definition GCodeProcessor.hpp:636
@ Layer_Change
Definition GCodeProcessor.hpp:609
@ Role
Definition GCodeProcessor.hpp:604
@ Height
Definition GCodeProcessor.hpp:607

References Slic3r::CalibPressureAdvance::draw_box(), Slic3r::CalibPressureAdvance::draw_number(), Slic3r::CalibPressureAdvance::e_per_mm(), Slic3r::GCodeProcessor::Height, Slic3r::DrawBoxOptArgs::is_filled, Slic3r::GCodeProcessor::Layer_Change, Slic3r::CalibPressureAdvance::m_draw_digit_mode, m_draw_numbers, m_fast_speed, m_height_layer, m_length_long, m_length_short, m_line_width, m_nozzle_diameter, m_number_line_width, m_slow_speed, m_space_y, m_thin_line_width, Slic3r::CalibPressureAdvance::move_to(), mp_gcodegen, Slic3r::CalibPressureAdvance::number_spacing(), Slic3r::print_flow_ratio(), Slic3r::GCodeProcessor::reserved_tag(), Slic3r::GCodeProcessor::Role, and Slic3r::CalibPressureAdvance::speed_adjust().

Referenced by generate_test().

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

◆ set_speed()

void Slic3r::CalibPressureAdvanceLine::set_speed ( double fast = 100.0,
double slow = 20.0 )
inline
268 {
269 m_slow_speed = slow;
270 m_fast_speed = fast;
271 }

References m_fast_speed, and m_slow_speed.

Referenced by Slic3r::GCode::_do_export().

Here is the caller graph for this function:

◆ speed_adjust()

double Slic3r::CalibPressureAdvance::speed_adjust ( int speed) const
inlineprotectedinherited
219{ return speed * 60; };

Referenced by Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes(), and Slic3r::CalibPressureAdvanceLine::print_pa_lines().

Here is the caller graph for this function:

◆ to_radians()

double Slic3r::CalibPressureAdvance::to_radians ( double degrees) const
inlineprotectedinherited

Member Data Documentation

◆ m_config

◆ m_digit_gap_len

const double Slic3r::CalibPressureAdvance::m_digit_gap_len {1}
protectedinherited

◆ m_digit_segment_len

const double Slic3r::CalibPressureAdvance::m_digit_segment_len {2}
protectedinherited

◆ m_draw_digit_mode

◆ m_draw_numbers

bool Slic3r::CalibPressureAdvanceLine::m_draw_numbers {true}
private
295{true};

Referenced by draw_numbers(), print_extents(), and print_pa_lines().

◆ m_encroachment

const double Slic3r::CalibPressureAdvance::m_encroachment {1. / 3.}
protectedinherited

◆ m_fast_speed

double Slic3r::CalibPressureAdvanceLine::m_fast_speed
private

Referenced by print_pa_lines(), and set_speed().

◆ m_height_layer

double Slic3r::CalibPressureAdvanceLine::m_height_layer {0.2}
private

◆ m_last_pos

Vec3d Slic3r::CalibPressureAdvance::m_last_pos
protectedinherited

Referenced by draw_line(), and move_to().

◆ m_length_long

double Slic3r::CalibPressureAdvanceLine::m_length_long {40.0}
private
294{20.0}, m_length_long{40.0};

Referenced by generate_test(), and print_pa_lines().

◆ m_length_short

double Slic3r::CalibPressureAdvanceLine::m_length_short {20.0}
private
294{20.0}, m_length_long{40.0};

Referenced by generate_test(), print_extents(), and print_pa_lines().

◆ m_line_width

double Slic3r::CalibPressureAdvanceLine::m_line_width {0.6}
private

◆ m_max_number_len

const std::string::size_type Slic3r::CalibPressureAdvance::m_max_number_len {5}
protectedinherited

◆ m_nozzle_diameter

double Slic3r::CalibPressureAdvanceLine::m_nozzle_diameter
private

◆ m_number_len

std::string::size_type Slic3r::CalibPressureAdvance::m_number_len {m_max_number_len}
protectedinherited
254{m_max_number_len}; /* Current length of number labels */
const std::string::size_type m_max_number_len
Definition calib.hpp:253

Referenced by draw_number(), and Slic3r::CalibPressureAdvancePattern::generate_custom_gcodes().

◆ m_number_line_width

double Slic3r::CalibPressureAdvanceLine::m_number_line_width {0.48}
private
291{0.48};

Referenced by CalibPressureAdvanceLine(), and print_pa_lines().

◆ m_slow_speed

double Slic3r::CalibPressureAdvanceLine::m_slow_speed
private

Referenced by print_pa_lines(), and set_speed().

◆ m_space_y

const double Slic3r::CalibPressureAdvanceLine::m_space_y {3.5}
private
292{3.5};

Referenced by delta_modify_start(), generate_test(), and print_pa_lines().

◆ m_thin_line_width

double Slic3r::CalibPressureAdvanceLine::m_thin_line_width {0.44}
private
290{0.44};

Referenced by CalibPressureAdvanceLine(), and print_pa_lines().

◆ mp_gcodegen

GCode* Slic3r::CalibPressureAdvanceLine::mp_gcodegen
private

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