Pass model into generate_gcodes to improve consistency

This commit is contained in:
thewildmage
2023-07-10 18:14:55 -06:00
parent ecc3002ffd
commit b8728e7921
5 changed files with 76 additions and 63 deletions

View File

@@ -72,6 +72,12 @@ Model& Model::assign_copy(const Model &rhs)
this->plates_custom_gcodes = rhs.plates_custom_gcodes;
this->curr_plate_index = rhs.curr_plate_index;
if (rhs.calib_pa_pattern) {
this->calib_pa_pattern = std::make_unique<CalibPressureAdvancePattern>(
CalibPressureAdvancePattern(*rhs.calib_pa_pattern)
);
}
// BBS: for design info
this->design_info = rhs.design_info;
this->model_info = rhs.model_info;
@@ -100,6 +106,7 @@ Model& Model::assign_copy(Model &&rhs)
// BBS
this->plates_custom_gcodes = std::move(rhs.plates_custom_gcodes);
this->curr_plate_index = rhs.curr_plate_index;
this->calib_pa_pattern = std::move(rhs.calib_pa_pattern);
//BBS: add auxiliary path logic
// BBS: backup, all in one temp dir

View File

@@ -362,31 +362,25 @@ PatternSettings::PatternSettings(const CalibPressureAdvancePattern& cpap) :
CalibPressureAdvancePattern::CalibPressureAdvancePattern(
const Calib_Params& params,
Model& model,
DynamicPrintConfig& config,
const bool& is_bbl_machine,
const Vec3d& origin
) :
CalibPressureAdvance(),
m_params(params),
m_model(model),
m_initial_config(config),
m_is_bbl_machine(is_bbl_machine),
m_origin(origin)
{
this->m_nozzle_diameter = pattern_config().option<ConfigOptionFloats>("nozzle_diameter")->values[0];
this->m_height_layer = 0.2;
this->m_draw_digit_mode = DrawDigitMode::Bottom_To_Top;
this->m_line_width = line_width();
this->m_pattern_settings = PatternSettings(*this);
};
void CalibPressureAdvancePattern::starting_point(Vec3d pt)
void CalibPressureAdvancePattern::starting_point(Vec3d pt, Model& model)
{
m_starting_point = pt;
if (is_delta()) {
if (is_delta(model)) {
m_starting_point.x() *= -1;
m_starting_point.y() -= (frame_size_y() / 2);
}
@@ -400,13 +394,13 @@ void CalibPressureAdvancePattern::translate_starting_point(const Vec3d displacem
m_last_pos = m_starting_point;
};
CustomGCode::Info CalibPressureAdvancePattern::generate_gcodes()
void CalibPressureAdvancePattern::generate_gcodes(Model& model)
{
std::stringstream gcode;
gcode << "; start pressure advance pattern for layer\n";
GCodeWriter writer = pattern_writer();
GCodeWriter writer = pattern_writer(model);
gcode << move_to(Vec2d(m_starting_point.x(), m_starting_point.y()), writer, "Move to start XY position");
gcode << writer.travel_to_z(m_height_first_layer, "Move to start Z position");
@@ -420,7 +414,8 @@ CustomGCode::Info CalibPressureAdvancePattern::generate_gcodes()
m_starting_point.y(),
print_size_x(),
frame_size_y(),
default_box_opt_args
default_box_opt_args,
model
);
// create tab for numbers
@@ -432,7 +427,8 @@ CustomGCode::Info CalibPressureAdvancePattern::generate_gcodes()
m_starting_point.y() + frame_size_y() + line_spacing_anchor(),
glyph_tab_max_x() - m_starting_point.x(),
max_numbering_height() + line_spacing_anchor() + m_glyph_padding_vertical * 2,
draw_box_opt_args
draw_box_opt_args,
model
);
std::vector<CustomGCode::Item> gcode_items;
@@ -513,12 +509,12 @@ CustomGCode::Info CalibPressureAdvancePattern::generate_gcodes()
draw_line_opt_args.height = i == 0 ? m_height_first_layer : m_height_layer;
draw_line_opt_args.speed = i == 0 ? speed_adjust(m_speed_first_layer) : speed_adjust(m_speed_perimeter);
draw_line_opt_args.comment = "Print pattern wall";
gcode << draw_line(Vec2d(to_x, to_y), draw_line_opt_args);
gcode << draw_line(Vec2d(to_x, to_y), draw_line_opt_args, model);
to_x -= std::cos(to_radians(m_corner_angle) / 2) * side_length;
to_y += std::sin(to_radians(m_corner_angle) / 2) * side_length;
gcode << draw_line(Vec2d(to_x, to_y), draw_line_opt_args);
gcode << draw_line(Vec2d(to_x, to_y), draw_line_opt_args, model);
to_y = initial_y;
if (k != m_wall_count - 1) {
@@ -553,21 +549,26 @@ CustomGCode::Info CalibPressureAdvancePattern::generate_gcodes()
info.mode = CustomGCode::Mode::SingleExtruder;
info.gcodes = gcode_items;
return info;
model.plates_custom_gcodes[model.curr_plate_index] = info;
}
DynamicPrintConfig CalibPressureAdvancePattern::pattern_config() const
DynamicPrintConfig CalibPressureAdvancePattern::pattern_config(const Model& model)
{
DynamicPrintConfig updated_config(m_initial_config);
updated_config.apply(m_model.objects[0]->volumes[0]->config.get(), true);
updated_config.apply(model.objects.front()->config.get(), true);
updated_config.apply(model.objects.front()->volumes.front()->config.get(), true);
m_nozzle_diameter = updated_config.option<ConfigOptionFloats>("nozzle_diameter")->values[0];
m_line_width = line_width();
m_pattern_settings = PatternSettings(*this);
return updated_config;
}
GCodeWriter CalibPressureAdvancePattern::pattern_writer() const
GCodeWriter CalibPressureAdvancePattern::pattern_writer(const Model& model)
{
PrintConfig print_config;
print_config.apply(pattern_config(), true);
print_config.apply(pattern_config(model), true);
GCodeWriter writer;
writer.apply_print_config(print_config);
@@ -576,16 +577,20 @@ GCodeWriter CalibPressureAdvancePattern::pattern_writer() const
writer.set_is_bbl_machine(m_is_bbl_machine);
const unsigned int extruder_id = m_model.objects.front()->volumes.front()->extruder_id();
const unsigned int extruder_id = model.objects.front()->volumes.front()->extruder_id();
writer.set_extruders({ extruder_id });
writer.set_extruder(extruder_id);
return writer;
}
std::string CalibPressureAdvancePattern::draw_line(Vec2d to_pt, DrawLineOptArgs opt_args)
std::string CalibPressureAdvancePattern::draw_line(
Vec2d to_pt,
DrawLineOptArgs opt_args,
Model& model
)
{
const DynamicPrintConfig& config = pattern_config();
const DynamicPrintConfig& config = pattern_config(model);
const double e_per_mm = CalibPressureAdvance::e_per_mm(
opt_args.line_width,
@@ -599,14 +604,21 @@ std::string CalibPressureAdvancePattern::draw_line(Vec2d to_pt, DrawLineOptArgs
std::stringstream gcode;
gcode << pattern_writer().extrude_to_xy(to_pt, dE, opt_args.comment);
gcode << pattern_writer(model).extrude_to_xy(to_pt, dE, opt_args.comment);
m_last_pos = Vec3d(to_pt.x(), to_pt.y(), 0);
return gcode.str();
}
std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, double size_x, double size_y, DrawBoxOptArgs opt_args)
std::string CalibPressureAdvancePattern::draw_box(
double min_x,
double min_y,
double size_x,
double size_y,
DrawBoxOptArgs opt_args,
Model& model
)
{
std::stringstream gcode;
@@ -628,7 +640,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
opt_args.num_perimeters = std::min(opt_args.num_perimeters, max_perimeters);
const GCodeWriter& writer = pattern_writer();
const GCodeWriter& writer = pattern_writer(model);
gcode << move_to(Vec2d(min_x, min_y), writer, "Move to box start");
@@ -646,19 +658,19 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
y += size_y - i * spacing * 2;
line_opt_args.comment = "Draw perimeter (up)";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
x += size_x - i * spacing * 2;
line_opt_args.comment = "Draw perimeter (right)";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
y -= size_y - i * spacing * 2;
line_opt_args.comment = "Draw perimeter (down)";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
x -= size_x - i * spacing * 2;
line_opt_args.comment = "Draw perimeter (left)";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
}
if (!opt_args.is_filled) {
@@ -697,7 +709,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
y += x - x_min_bound;
x = x_min_bound;
line_opt_args.comment = "Fill: Print up/left";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
} else {
y += spacing_45;
x = x_min_bound;
@@ -706,7 +718,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x += y - y_min_bound;
y = y_min_bound;
line_opt_args.comment = "Fill: Print down/right";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
}
} else if (i < std::max(x_count, y_count)) {
if (x_count > y_count) {
@@ -719,7 +731,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x -= y_max_bound - y_min_bound;
y = y_max_bound;
line_opt_args.comment = "Fill: Print up/left";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
} else {
if (i == y_count) {
x += spacing_45 - y_remainder;
@@ -733,7 +745,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x += y_max_bound - y_min_bound;
y = y_min_bound;
line_opt_args.comment = "Fill: Print down/right";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
}
} else {
// box is taller than wide
@@ -750,7 +762,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x = x_min_bound;
y += x_max_bound - x_min_bound;
line_opt_args.comment = "Fill: Print up/left";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
} else {
x = x_min_bound;
y += spacing_45;
@@ -759,7 +771,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x = x_max_bound;
y -= x_max_bound - x_min_bound;
line_opt_args.comment = "Fill: Print down/right";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
}
}
} else {
@@ -775,7 +787,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
x -= y_max_bound - y;
y = y_max_bound;
line_opt_args.comment = "Fill: Print up/left";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
} else {
if (i == y_count) {
x += spacing_45 - y_remainder;
@@ -788,7 +800,7 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
y -= x_max_bound - x;
x = x_max_bound;
line_opt_args.comment = "Fill: Print down/right";
gcode << draw_line(Vec2d(x, y), line_opt_args);
gcode << draw_line(Vec2d(x, y), line_opt_args, model);
}
}
}

View File

@@ -36,7 +36,6 @@ protected:
Bottom_To_Top
};
virtual bool is_delta() const =0;
void delta_scale_bed_ext(BoundingBoxf& bed_ext) const { bed_ext.scale(1.0f / 1.41421f); }
std::string move_to(Vec2d pt, GCodeWriter writer, std::string comment = std::string());
@@ -122,8 +121,6 @@ private:
PatternSettings() { };
PatternSettings(const CalibPressureAdvancePattern& cpap);
PatternSettings& operator= (const PatternSettings& rhs) =default;
double anchor_line_width;
int anchor_perimeters;
double encroachment;
@@ -171,27 +168,20 @@ friend struct PatternSettings;
public:
CalibPressureAdvancePattern(
const Calib_Params& params,
Model& model,
DynamicPrintConfig& config,
const bool& is_bbl_machine,
const Vec3d& origin
);
bool is_delta() const
{
return pattern_config().option<ConfigOptionPoints>("printable_area")->values.size() > 4;
}
double handle_xy_size() const { return m_handle_xy_size; };
double height_first_layer() const { return m_height_first_layer; };
double height_layer() const { return m_height_layer; };
double max_layer_z() const { return m_height_first_layer + ((m_num_layers - 1) * m_height_layer); };
void starting_point(Vec3d pt);
void starting_point(Vec3d pt, Model& model);
void translate_starting_point(Vec3d displacement);
CustomGCode::Info generate_gcodes();
void generate_gcodes(Model& model);
protected:
double line_width() const { return m_nozzle_diameter * m_line_ratio / 100; };
double line_width_anchor() const { return m_nozzle_diameter * m_anchor_layer_line_ratio / 100; };
@@ -201,16 +191,28 @@ protected:
int anchor_perimeters() const { return m_anchor_perimeters; };
double encroachment() const { return m_encroachment; };
private:
DynamicPrintConfig pattern_config() const;
GCodeWriter pattern_writer() const; // travel_to and extrude_to require a non-const GCodeWriter
bool is_delta(Model& model)
{
return pattern_config(model).option<ConfigOptionPoints>("printable_area")->values.size() > 4;
}
DynamicPrintConfig pattern_config(const Model& model);
GCodeWriter pattern_writer(const Model& model); // travel_to and extrude_to require a non-const GCodeWriter
const int get_num_patterns() const
{
return std::ceil((m_params.end - m_params.start) / m_params.step + 1);
}
std::string draw_line(Vec2d to_pt, DrawLineOptArgs opt_args);
std::string draw_box(double min_x, double min_y, double size_x, double size_y, DrawBoxOptArgs opt_args);
std::string draw_line(Vec2d to_pt, DrawLineOptArgs opt_args, Model& model);
std::string draw_box(
double min_x,
double min_y,
double size_x,
double size_y,
DrawBoxOptArgs opt_args,
Model& model
);
double to_radians(double degrees) const { return degrees * M_PI / 180; };
double get_distance(Vec2d from, Vec2d to) const;
@@ -240,7 +242,6 @@ private:
const Calib_Params& m_params;
const DynamicPrintConfig m_initial_config;
Model& m_model;
const bool& m_is_bbl_machine;
const Vec3d& m_origin;

View File

@@ -8135,7 +8135,6 @@ void Plater::_calib_pa_pattern(const Calib_Params& params)
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
CalibPressureAdvancePattern pa_pattern(
params,
model(),
full_config,
preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(preset_bundle),
fff_print().get_plate_origin()
@@ -8162,7 +8161,7 @@ void Plater::_calib_pa_pattern(const Calib_Params& params)
bbox.merge(obj->instance_bounding_box(i, false));
}
}
pa_pattern.starting_point(Vec3d(bbox.min.x(), bbox.max.y(), 0));
pa_pattern.starting_point(Vec3d(bbox.min.x(), bbox.max.y(), 0), model());
DynamicPrintConfig* print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config;
DynamicPrintConfig* printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
@@ -8185,9 +8184,7 @@ void Plater::_calib_pa_pattern(const Calib_Params& params)
wxGetApp().get_tab(Preset::TYPE_PRINT)->reload_config();
wxGetApp().get_tab(Preset::TYPE_FILAMENT)->reload_config();
model().plates_custom_gcodes[model().curr_plate_index] =
pa_pattern.generate_gcodes()
;
pa_pattern.generate_gcodes(model());
model().calib_pa_pattern = std::make_unique<CalibPressureAdvancePattern>(pa_pattern);
}

View File

@@ -918,10 +918,6 @@ void Selection::translate(const Vec3d& displacement, bool local)
if (m_model->calib_pa_pattern) {
m_model->calib_pa_pattern->translate_starting_point(displacement);
m_model->plates_custom_gcodes[m_model->curr_plate_index] =
m_model->calib_pa_pattern->generate_gcodes()
;
}
ensure_not_below_bed();