object_range

This commit is contained in:
sunsets
2023-10-04 15:23:05 +08:00
parent f4f63b9a54
commit f713cb579a
2 changed files with 67 additions and 22 deletions

View File

@@ -1328,29 +1328,36 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// adds tag for processor // adds tag for processor
file.write_format(";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), gcode_extrusion_role_to_string(GCodeExtrusionRole::Custom).c_str()); file.write_format(";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), gcode_extrusion_role_to_string(GCodeExtrusionRole::Custom).c_str());
file.write(set_object_range(print));
//B14 //B14
std::string first_layer_print_min_x = this->placeholder_parser_process("start_gcode", "{first_layer_print_min[0]}", initial_extruder_id); //std::string first_layer_print_min_x = this->placeholder_parser_process("start_gcode", "{first_layer_print_min[0]}", initial_extruder_id);
std::string first_layer_print_min_y = this->placeholder_parser_process("start_gcode", "{first_layer_print_min[1]}", initial_extruder_id); //std::string first_layer_print_min_y = this->placeholder_parser_process("start_gcode", "{first_layer_print_min[1]}", initial_extruder_id);
std::string first_layer_print_max_x = this->placeholder_parser_process("start_gcode", "{first_layer_print_max[0]}", initial_extruder_id); //std::string first_layer_print_max_x = this->placeholder_parser_process("start_gcode", "{first_layer_print_max[0]}", initial_extruder_id);
std::string first_layer_print_max_y = this->placeholder_parser_process("start_gcode", "{first_layer_print_max[1]}", initial_extruder_id); //std::string first_layer_print_max_y = this->placeholder_parser_process("start_gcode", "{first_layer_print_max[1]}", initial_extruder_id);
std::string center_x = std ::to_string( //BOOST_LOG_TRIVIAL(error) << "bed_x:" << first_layer_print_min_x;
(atof(first_layer_print_min_x.c_str()) + //BOOST_LOG_TRIVIAL(error) << "bed_x:" << first_layer_print_max_x;
atof(first_layer_print_max_x.c_str())) / //std::string center_x = std ::to_string(
2); // (atof(first_layer_print_min_x.c_str()) +
std::string center_y = std ::to_string( // atof(first_layer_print_max_x.c_str())) /
(atof(first_layer_print_min_y.c_str()) + // 2);
atof(first_layer_print_max_y.c_str())) / //std::string center_y = std ::to_string(
2); // (atof(first_layer_print_min_y.c_str()) +
std::string min_x = std ::to_string(atof(first_layer_print_min_x.c_str()) -10); // atof(first_layer_print_max_y.c_str())) /
std::string min_y = std ::to_string(atof(first_layer_print_min_y.c_str()) - 10); // 2);
std::string max_x = std ::to_string(atof(first_layer_print_max_x.c_str()) + 10); //std::string min_x = std ::to_string(atof(first_layer_print_min_x.c_str()) -10);
std::string max_y = std ::to_string(atof(first_layer_print_max_y.c_str()) + 10); //std::string min_y = std ::to_string(atof(first_layer_print_min_y.c_str()) - 10);
std::string range_gcode = //std::string max_x = std ::to_string(atof(first_layer_print_max_x.c_str()) + 10);
"EXCLUDE_OBJECT_DEFINE NAME=stl_id_0_copy_0 CENTER=" + center_x + //std::string max_y = std ::to_string(atof(first_layer_print_max_y.c_str()) + 10);
"," + center_y + " POLYGON=[[" + min_x + "," + min_y + "],[" + min_x + //std::string range_gcode =
"," + max_y + "],[" + max_x + "," + max_y + "],[" + max_x + "," + // "EXCLUDE_OBJECT_DEFINE NAME=stl_id_0_copy_0 CENTER=" + center_x +
min_y + "],[" + min_x + "," + min_y + "]]"; // "," + center_y + " POLYGON=[[" + min_x + "," + min_y + "],[" + min_x +
file.writeln(range_gcode); // "," + max_y + "],[" + max_x + "," + max_y + "],[" + max_x + "," +
// min_y + "],[" + min_x + "," + min_y + "]]";
//file.writeln(range_gcode);
//B17 //B17
// adds tags for time estimators // adds tags for time estimators
if (print.config().remaining_times.value) if (print.config().remaining_times.value)
@@ -3529,6 +3536,41 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
return gcode; return gcode;
} }
//B41
std::string GCode::set_object_range(Print &print)
{
std::ostringstream gcode;
std::vector<std::pair<coordf_t, ObjectsLayerToPrint>> layers_to_print = collect_layers_to_print(print);
const std::pair<coordf_t, ObjectsLayerToPrint> & layer = layers_to_print[0];
std::vector<const PrintInstance *> print_object_instances_ordering;
print_object_instances_ordering = chain_print_object_instances(print);
std::vector<InstanceToPrint> instances_to_print = sort_print_object_instances(layer.second, &print_object_instances_ordering,
size_t(-1));
for (const InstanceToPrint& instance : instances_to_print) {
const PrintObject &print_object = instance.print_object;
auto bbox = print_object.bounding_box();
auto instances = print_object.instances();
for (PrintInstance &inst : instances) {
auto shift = inst.shift;
float min_x = round(bbox.min(0) + shift(0)) / 1000000.0 - 10;
float max_x = ((print_object.model_object()->name) == "pa_line.stl" or (print_object.model_object()->name) == "pa_pattern.stl") ?
round(bbox.max(0) + shift(0)) / 1000000.0 + 90 :
round(bbox.max(0) + shift(0)) / 1000000.0 + 10;
float min_y = round(bbox.min(1) + shift(1)) / 1000000.0 - 10;
float max_y = round(bbox.max(1) + shift(1)) / 1000000.0 + 10;
gcode << (std::string("EXCLUDE_OBJECT_DEFINE NAME =") + print_object.model_object()->name)
<< " CENTER=" << round(shift(0)) / 1000000.0 << "," << round(shift(1)) / 1000000.0 << " POLYGON=[[" << min_x << ","
<< min_y << "],[" << min_x << "," << max_y << "],[" << max_x << "," << max_y << "],[" << max_x << "," << min_y << "],["
<< min_x << "," << min_y << "]]"
<< "\n";
}
}
return gcode.str();
}
// convert a model-space scaled point into G-code coordinates // convert a model-space scaled point into G-code coordinates
Vec2d GCode::point_to_gcode(const Point &point) const Vec2d GCode::point_to_gcode(const Point &point) const
{ {

View File

@@ -330,6 +330,9 @@ private:
std::string unretract() { return m_writer.unlift() + m_writer.unretract(); } std::string unretract() { return m_writer.unlift() + m_writer.unretract(); }
std::string set_extruder(unsigned int extruder_id, double print_z); std::string set_extruder(unsigned int extruder_id, double print_z);
//B41
std::string set_object_range(Print &print);
// Cache for custom seam enforcers/blockers for each layer. // Cache for custom seam enforcers/blockers for each layer.
SeamPlacer m_seam_placer; SeamPlacer m_seam_placer;