diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index cb0c6c4..a55bb76 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1328,29 +1328,36 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato // 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(set_object_range(print)); + //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_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_y = this->placeholder_parser_process("start_gcode", "{first_layer_print_max[1]}", initial_extruder_id); - std::string center_x = std ::to_string( - (atof(first_layer_print_min_x.c_str()) + - atof(first_layer_print_max_x.c_str())) / - 2); - std::string center_y = std ::to_string( - (atof(first_layer_print_min_y.c_str()) + - atof(first_layer_print_max_y.c_str())) / - 2); - std::string min_x = std ::to_string(atof(first_layer_print_min_x.c_str()) -10); - std::string min_y = std ::to_string(atof(first_layer_print_min_y.c_str()) - 10); - std::string max_x = std ::to_string(atof(first_layer_print_max_x.c_str()) + 10); - std::string max_y = std ::to_string(atof(first_layer_print_max_y.c_str()) + 10); - std::string range_gcode = - "EXCLUDE_OBJECT_DEFINE NAME=stl_id_0_copy_0 CENTER=" + center_x + - "," + center_y + " POLYGON=[[" + min_x + "," + min_y + "],[" + min_x + - "," + max_y + "],[" + max_x + "," + max_y + "],[" + max_x + "," + - min_y + "],[" + min_x + "," + min_y + "]]"; - file.writeln(range_gcode); + //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_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); + //BOOST_LOG_TRIVIAL(error) << "bed_x:" << first_layer_print_min_x; + //BOOST_LOG_TRIVIAL(error) << "bed_x:" << first_layer_print_max_x; + //std::string center_x = std ::to_string( + // (atof(first_layer_print_min_x.c_str()) + + // atof(first_layer_print_max_x.c_str())) / + // 2); + //std::string center_y = std ::to_string( + // (atof(first_layer_print_min_y.c_str()) + + // atof(first_layer_print_max_y.c_str())) / + // 2); + //std::string min_x = std ::to_string(atof(first_layer_print_min_x.c_str()) -10); + //std::string min_y = std ::to_string(atof(first_layer_print_min_y.c_str()) - 10); + //std::string max_x = std ::to_string(atof(first_layer_print_max_x.c_str()) + 10); + //std::string max_y = std ::to_string(atof(first_layer_print_max_y.c_str()) + 10); + //std::string range_gcode = + // "EXCLUDE_OBJECT_DEFINE NAME=stl_id_0_copy_0 CENTER=" + center_x + + // "," + center_y + " POLYGON=[[" + min_x + "," + min_y + "],[" + min_x + + // "," + max_y + "],[" + max_x + "," + max_y + "],[" + max_x + "," + + // min_y + "],[" + min_x + "," + min_y + "]]"; + //file.writeln(range_gcode); //B17 // adds tags for time estimators if (print.config().remaining_times.value) @@ -3529,6 +3536,41 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z) return gcode; } +//B41 +std::string GCode::set_object_range(Print &print) +{ + std::ostringstream gcode; + + std::vector> layers_to_print = collect_layers_to_print(print); + const std::pair & layer = layers_to_print[0]; + + std::vector print_object_instances_ordering; + print_object_instances_ordering = chain_print_object_instances(print); + std::vector 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 Vec2d GCode::point_to_gcode(const Point &point) const { diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 22fe8fe..9bc399d 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -330,6 +330,9 @@ private: std::string unretract() { return m_writer.unlift() + m_writer.unretract(); } 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. SeamPlacer m_seam_placer;