Clean up and simplify

This commit is contained in:
thewildmage
2023-05-30 18:46:20 -06:00
parent 1a2334a6f9
commit 326e771c63
2 changed files with 23 additions and 21 deletions

View File

@@ -21,7 +21,7 @@ namespace Slic3r {
}
std::string convert_number_to_string(double num) {
auto sNumber = std::to_string(value);
auto sNumber = std::to_string(num);
sNumber.erase(sNumber.find_last_not_of('0') + 1, std::string::npos);
sNumber.erase(sNumber.find_last_not_of('.') + 1, std::string::npos);
@@ -33,7 +33,7 @@ namespace Slic3r {
std::stringstream gcode;
const double lw = 0.48;
Flow line_flow = Flow(lw, 0.2, m_nozzle_diameter);
const double len = m_digit_len;
const double len = m_digit_segment_len;
const double gap = lw / 2.0;
/*
@@ -280,8 +280,7 @@ namespace Slic3r {
std::string calib_pressure_advance_pattern::generate_test(double start_pa, double end_pa, double step_pa) {
BoundingBoxf bed_ext = get_extents(mp_gcodegen->config().printable_area.values);
bool is_delta = is_delta();
if (is_delta) {
if (is_delta()) {
delta_scale_bed_ext(bed_ext);
}
@@ -317,7 +316,7 @@ namespace Slic3r {
auto start_x = center_x - (object_size_x + pattern_shift) / 2;
auto start_y = center_y - object_size_y / 2;
if (is_delta) {
if (is_delta()) {
delta_modify_start(start_x, start_y, num_patterns);
}
@@ -348,36 +347,36 @@ namespace Slic3r {
line_width_anchor()
}
double max_numbering_height(double start_pa, double step_pa, int count) {
int max_length = 0;
double max_numbering_height(double start_pa, double step_pa, int num_patterns) {
int most_characters = 0;
for (int i = 0; i < count; i += 2) {
// note: only every other number is printed
for (int i = 0; i < num_patterns; i += 2) {
std::string sNumber = convert_number_to_string(start_pa + (i * step_pa));
if (sNumber.length > max_length) { max_length = sNumber.length; }
if (sNumber.length > most_characters) { most_characters = sNumber.length; }
}
max_length = std::min(max_characters, m_max_number_length);
most_characters = std::min(most_characters, m_max_number_length);
return (max_length * m_digit_len) + ((max_length - 1) * m_number_spacing);
return (most_characters * m_digit_segment_len) + ((most_characters - 1) * m_number_spacing);
}
double get_distance(double cur_x, double cur_y, double to_x, double to_y) {
return std::hypot((to_x - cur_x), (to_y - cur_y));
}
std::string draw_line(double to_x, double to_y, double line_width, double layer_height, std::string comment = std::string()) {
std::string draw_line(double to_x, double to_y, std::string comment = std::string()) {
std::stringstream gcode;
auto& config = mp_gcodegen.config();
auto& writer = mp_gcodegen.writer();
Flow line_flow = Flow(line_width, layer_height, m_nozzle_diameter);
Flow line_flow = Flow(line_width(), m_height_layer, m_nozzle_diameter);
const double filament_area = M_PI * std::pow(config.filament_diameter.value / 2, 2);
const double e_per_mm = line_flow.mm3_per_mm() / filament_area * config.print_flow_ratio;
const double e_per_mm = line_flow.mm3_per_mm() / filament_area * m_extrusion_multiplier;
Point last_pos = mp_gcodegen.last_pos();
const double length = get_distance(last_pos.x(), last_pos.y(), to_x, to_y);
auto dE = e_per_mm * length;
if (comment.empty()) {

View File

@@ -47,7 +47,7 @@ private:
void delta_modify_start(double start_x, double start_y, int count);
private:
GCode* mp_gcodegen;
double m_digit_len {2};
double m_digit_segment_len {2};
double m_nozzle_diameter;
int m_max_number_length {5};
double m_number_spacing {3.0};
@@ -85,27 +85,30 @@ class calib_pressure_advance_pattern: public calib_pressure_advance
std::string generate_test(double start_pa = 0, double end_pa = 0.08, double step_pa = 0.005);
double to_radians(double degrees) { return degrees * (M_PI / 180); }
double to_radians(double degrees) { return degrees * M_PI / 180; }
double line_width() { return m_nozzle_diameter * m_line_ratio / 100; };
double line_width_anchor() { return m_nozzle_diameter * m_anchor_layer_line_ratio / 100; };
// from slic3r documentation: spacing = extrusion_width - layer_height * (1 - PI/4)
double line_spacing() { return line_width() - mp_gcodegen->config().layer_height.value * (1 - M_PI / 4); };
double line_spacing_anchor() { return line_width_anchor() - mp_gcodegen->config().initial_layer_print_height.value * (1 - M_PI / 4); };
double line_spacing() { return line_width() - m_height_layer * (1 - M_PI / 4); };
double line_spacing_anchor() { return line_width_anchor() - m_height_first_layer * (1 - M_PI / 4); };
double line_spacing_angle() { return line_spacing() / std::sin(to_radians(m_corner_angle) / 2); };
double object_size_x(int num_patterns);
double object_size_y(double start_pa, double step_pa, int num_patterns);
double max_numbering_height();
double max_numbering_height(double start_pa, double step_pa, int num_patterns);
double get_distance(double cur_x, double cur_y, double to_x, double to_y);
std::string draw_line(double to_x, double to_y, double line_width, double layer_height, std::string comment = std::string());
std::string draw_line(double to_x, double to_y, std::string comment = std::string());
private:
int m_anchor_layer_line_ratio {140};
int m_anchor_perimeters {4};
int m_corner_angle {90};
double m_extrusion_multiplier {0.98};
double m_height_first_layer {0.25};
double m_height_layer {0.2};
double m_glyph_padding_horizontal {1};
double m_glyph_padding_vertical {1};
double m_line_ratio {112.5};