mirror of
https://git.mirrors.martin98.com/https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 17:24:23 +08:00
support adaptive bed mesh for PA calib
This commit is contained in:
parent
6a767a5f67
commit
15d96e1f6d
@ -1,3 +1,5 @@
|
|||||||
|
#include "BoundingBox.hpp"
|
||||||
|
#include "Polygon.hpp"
|
||||||
#include "PrintConfig.hpp"
|
#include "PrintConfig.hpp"
|
||||||
#include "libslic3r.h"
|
#include "libslic3r.h"
|
||||||
#include "I18N.hpp"
|
#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));
|
m_placeholder_parser.set("is_extruder_used", new ConfigOptionBools(is_extruder_used));
|
||||||
|
|
||||||
{
|
{
|
||||||
BoundingBoxf bbox(print.config().printable_area.values);
|
BoundingBoxf bbox_bed(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_min", new ConfigOptionFloats({ bbox_bed.min.x(), bbox_bed.min.y()}));
|
||||||
m_placeholder_parser.set("print_bed_max", new ConfigOptionFloats({ bbox.max.x(), bbox.max.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.size().x(), bbox.size().y() }));
|
m_placeholder_parser.set("print_bed_size", new ConfigOptionFloats({ bbox_bed.size().x(), bbox_bed.size().y() }));
|
||||||
}
|
|
||||||
{
|
BoundingBoxf bbox;
|
||||||
// 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.
|
|
||||||
auto pts = std::make_unique<ConfigOptionPoints>();
|
auto pts = std::make_unique<ConfigOptionPoints>();
|
||||||
pts->values.reserve(print.first_layer_convex_hull().size());
|
if (print.calib_mode() == CalibMode::Calib_PA_Line || print.calib_mode() == CalibMode::Calib_PA_Pattern) {
|
||||||
for (const Point& pt : print.first_layer_convex_hull().points)
|
bbox = bbox_bed;
|
||||||
pts->values.emplace_back(print.translate_to_print_space(pt));
|
bbox.offset(-5.0);
|
||||||
BoundingBoxf bbox(pts->values);
|
// 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_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_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()}));
|
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;
|
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;
|
std::ostringstream gcode;
|
||||||
gcode << "[";
|
gcode << "[";
|
||||||
for (const Point &p : polygon.points) {
|
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() << "],";
|
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 << "[" << first_v.x() << "," << first_v.y() << "]";
|
||||||
gcode << "]";
|
gcode << "]";
|
||||||
return gcode.str();
|
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::string GCode::set_object_info(Print *print) {
|
||||||
std::ostringstream gcode;
|
std::ostringstream gcode;
|
||||||
size_t object_id = 0;
|
size_t object_id = 0;
|
||||||
for (PrintObject *object : print->objects()) {
|
// Orca: check if we are in pa calib mode
|
||||||
object->set_id(object_id++);
|
if (print->calib_mode() == CalibMode::Calib_PA_Line || print->calib_mode() == CalibMode::Calib_PA_Pattern) {
|
||||||
size_t inst_id = 0;
|
BoundingBoxf bbox_bed(print->config().printable_area.values);
|
||||||
for (PrintInstance &inst : object->instances()) {
|
bbox_bed.offset(-5.0);
|
||||||
inst.id = inst_id++;
|
Polygon polygon_bed;
|
||||||
if (this->config().exclude_object && print->config().gcode_flavor.value == gcfKlipper) {
|
polygon_bed.append(Point(bbox_bed.min.x(), bbox_bed.min.y()));
|
||||||
auto bbox = inst.get_bounding_box();
|
polygon_bed.append(Point(bbox_bed.max.x(), bbox_bed.min.y()));
|
||||||
auto center = print->translate_to_print_space(Vec2d(bbox.center().x(), bbox.center().y()));
|
polygon_bed.append(Point(bbox_bed.max.x(), bbox_bed.max.y()));
|
||||||
gcode << "EXCLUDE_OBJECT_DEFINE NAME=" << get_instance_name(object, inst) << " CENTER=" << center.x()
|
polygon_bed.append(Point(bbox_bed.min.x(), bbox_bed.max.y()));
|
||||||
<< "," << center.y() << " POLYGON=" << polygon_to_string(inst.get_convex_hull_2d(), print)
|
gcode << "EXCLUDE_OBJECT_DEFINE NAME="
|
||||||
<< "\n";
|
<< "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();
|
return gcode.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user