diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index f7a8701428..9833ea1ff8 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1,3 +1,5 @@ +#include "BoundingBox.hpp" +#include "Polygon.hpp" #include "PrintConfig.hpp" #include "libslic3r.h" #include "I18N.hpp" @@ -1796,22 +1798,35 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato m_placeholder_parser.set("is_extruder_used", new ConfigOptionBools(is_extruder_used)); { - BoundingBoxf bbox(print.config().printable_area.values); - m_placeholder_parser.set("print_bed_min", new ConfigOptionFloats({ bbox.min.x(), bbox.min.y()})); - m_placeholder_parser.set("print_bed_max", new ConfigOptionFloats({ bbox.max.x(), bbox.max.y()})); - m_placeholder_parser.set("print_bed_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() })); - } - { - // Convex hull of the 1st layer extrusions, for bed leveling and placing the initial purge line. - // It encompasses the object extrusions, support extrusions, skirt, brim, wipe tower. - // It does NOT encompass user extrusions generated by custom G-code, - // therefore it does NOT encompass the initial purge line. - // It does NOT encompass MMU/MMU2 starting (wipe) areas. + BoundingBoxf bbox_bed(print.config().printable_area.values); + m_placeholder_parser.set("print_bed_min", new ConfigOptionFloats({ bbox_bed.min.x(), bbox_bed.min.y()})); + m_placeholder_parser.set("print_bed_max", new ConfigOptionFloats({ bbox_bed.max.x(), bbox_bed.max.y()})); + m_placeholder_parser.set("print_bed_size", new ConfigOptionFloats({ bbox_bed.size().x(), bbox_bed.size().y() })); + + BoundingBoxf bbox; auto pts = std::make_unique(); - pts->values.reserve(print.first_layer_convex_hull().size()); - for (const Point& pt : print.first_layer_convex_hull().points) - pts->values.emplace_back(print.translate_to_print_space(pt)); - BoundingBoxf bbox(pts->values); + if (print.calib_mode() == CalibMode::Calib_PA_Line || print.calib_mode() == CalibMode::Calib_PA_Pattern) { + bbox = bbox_bed; + bbox.offset(-5.0); + // add 4 corner points of bbox into pts + pts->values.reserve(4); + pts->values.emplace_back(bbox.min.x(), bbox.min.y()); + pts->values.emplace_back(bbox.max.x(), bbox.min.y()); + pts->values.emplace_back(bbox.max.x(), bbox.max.y()); + pts->values.emplace_back(bbox.min.x(), bbox.max.y()); + + } else { + // Convex hull of the 1st layer extrusions, for bed leveling and placing the initial purge line. + // It encompasses the object extrusions, support extrusions, skirt, brim, wipe tower. + // It does NOT encompass user extrusions generated by custom G-code, + // therefore it does NOT encompass the initial purge line. + // It does NOT encompass MMU/MMU2 starting (wipe) areas. + pts->values.reserve(print.first_layer_convex_hull().size()); + for (const Point &pt : print.first_layer_convex_hull().points) + pts->values.emplace_back(print.translate_to_print_space(pt)); + bbox = BoundingBoxf((pts->values)); + } + m_placeholder_parser.set("first_layer_print_convex_hull", pts.release()); m_placeholder_parser.set("first_layer_print_min", new ConfigOptionFloats({bbox.min.x(), bbox.min.y()})); m_placeholder_parser.set("first_layer_print_max", new ConfigOptionFloats({bbox.max.x(), bbox.max.y()})); @@ -4921,14 +4936,15 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z) return gcode; } -inline std::string polygon_to_string(const Polygon &polygon, Print *print) { +inline std::string polygon_to_string(const Polygon &polygon, Print *print, bool is_print_space = false) { std::ostringstream gcode; gcode << "["; for (const Point &p : polygon.points) { - const auto v = print->translate_to_print_space(p); + const auto v = is_print_space ? Vec2d(p.x(), p.y()) : print->translate_to_print_space(p); gcode << "[" << v.x() << "," << v.y() << "],"; } - const auto first_v = print->translate_to_print_space(polygon.points.front()); + const auto first_v = is_print_space ? Vec2d(polygon.points.front().x(), polygon.points.front().y()) + : print->translate_to_print_space(polygon.points.front()); gcode << "[" << first_v.x() << "," << first_v.y() << "]"; gcode << "]"; return gcode.str(); @@ -4938,20 +4954,36 @@ inline std::string polygon_to_string(const Polygon &polygon, Print *print) { std::string GCode::set_object_info(Print *print) { std::ostringstream gcode; size_t object_id = 0; - for (PrintObject *object : print->objects()) { - object->set_id(object_id++); - size_t inst_id = 0; - for (PrintInstance &inst : object->instances()) { - inst.id = inst_id++; - if (this->config().exclude_object && print->config().gcode_flavor.value == gcfKlipper) { - auto bbox = inst.get_bounding_box(); - auto center = print->translate_to_print_space(Vec2d(bbox.center().x(), bbox.center().y())); - gcode << "EXCLUDE_OBJECT_DEFINE NAME=" << get_instance_name(object, inst) << " CENTER=" << center.x() - << "," << center.y() << " POLYGON=" << polygon_to_string(inst.get_convex_hull_2d(), print) - << "\n"; + // Orca: check if we are in pa calib mode + if (print->calib_mode() == CalibMode::Calib_PA_Line || print->calib_mode() == CalibMode::Calib_PA_Pattern) { + BoundingBoxf bbox_bed(print->config().printable_area.values); + bbox_bed.offset(-5.0); + Polygon polygon_bed; + polygon_bed.append(Point(bbox_bed.min.x(), bbox_bed.min.y())); + polygon_bed.append(Point(bbox_bed.max.x(), bbox_bed.min.y())); + polygon_bed.append(Point(bbox_bed.max.x(), bbox_bed.max.y())); + polygon_bed.append(Point(bbox_bed.min.x(), bbox_bed.max.y())); + gcode << "EXCLUDE_OBJECT_DEFINE NAME=" + << "Orca-PA-Calibration-Test" + << " CENTER=" << 0 << "," << 0 << " POLYGON=" << polygon_to_string(polygon_bed, print, true) << "\n"; + } else { + for (PrintObject *object : print->objects()) { + object->set_id(object_id++); + size_t inst_id = 0; + for (PrintInstance &inst : object->instances()) { + inst.id = inst_id++; + if (this->config().exclude_object && print->config().gcode_flavor.value == gcfKlipper) { + auto bbox = inst.get_bounding_box(); + auto center = print->translate_to_print_space(Vec2d(bbox.center().x(), bbox.center().y())); + + gcode << "EXCLUDE_OBJECT_DEFINE NAME=" << get_instance_name(object, inst) + << " CENTER=" << center.x() << "," << center.y() + << " POLYGON=" << polygon_to_string(inst.get_convex_hull_2d(), print) << "\n"; + } } } } + return gcode.str(); }