diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index e15c5808b5..d3330c3000 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2084,7 +2084,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato file.write_format("; EXECUTABLE_BLOCK_START\n"); // SoftFever - if( m_config.gcode_flavor.value == gcfKlipper && m_enable_exclude_object) + if( m_enable_exclude_object) file.write(set_object_info(&print)); // adds tags for time estimators @@ -4036,10 +4036,16 @@ LayerResult GCode::process_layer( std::string("; start printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n" + "M624 " + _encode_label_ids_to_base64({instance_to_print.label_object_id}) + "\n"); - } else if (print.config().gcode_flavor.value == gcfKlipper) { - m_writer.set_object_start_str(std::string("EXCLUDE_OBJECT_START NAME=") + - get_instance_name(&instance_to_print.print_object, inst.id) + - "\n"); + } else { + const auto gflavor = print.config().gcode_flavor.value; + if (gflavor == gcfKlipper) { + m_writer.set_object_start_str(std::string("EXCLUDE_OBJECT_START NAME=") + + get_instance_name(&instance_to_print.print_object, inst.id) + "\n"); + } + else if (gflavor == gcfMarlinLegacy || gflavor == gcfMarlinFirmware || gflavor == gcfRepRapFirmware) { + std::string str = std::string("M486 S") + std::to_string(inst.unique_id) + "\n"; + m_writer.set_object_start_str(str); + } } } @@ -4187,9 +4193,14 @@ LayerResult GCode::process_layer( m_writer.set_object_end_str(std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n" + "M625\n"); - } else if (print.config().gcode_flavor.value == gcfKlipper) { - m_writer.set_object_end_str(std::string("EXCLUDE_OBJECT_END NAME=") + - get_instance_name(&instance_to_print.print_object, inst.id) + "\n"); + } else { + const auto gflavor = print.config().gcode_flavor.value; + if (gflavor == gcfKlipper) { + m_writer.set_object_end_str(std::string("EXCLUDE_OBJECT_END NAME=") + + get_instance_name(&instance_to_print.print_object, inst.id) + "\n"); + } else if (gflavor == gcfMarlinLegacy || gflavor == gcfMarlinFirmware || gflavor == gcfRepRapFirmware) { + m_writer.set_object_end_str(std::string("M486 S-1\n")); + } } } } @@ -5803,6 +5814,9 @@ inline std::string polygon_to_string(const Polygon &polygon, Print *print, bool // this function iterator PrintObject and assign a seqential id to each object. // this id is used to generate unique object id for each object. std::string GCode::set_object_info(Print *print) { + const auto gflavor = print->config().gcode_flavor.value; + if (gflavor != gcfKlipper && gflavor != gcfMarlinLegacy && gflavor != gcfMarlinFirmware && gflavor != gcfRepRapFirmware) + return ""; std::ostringstream gcode; size_t object_id = 0; // Orca: check if we are in pa calib mode @@ -5818,18 +5832,27 @@ std::string GCode::set_object_info(Print *print) { << "Orca-PA-Calibration-Test" << " CENTER=" << 0 << "," << 0 << " POLYGON=" << polygon_to_string(polygon_bed, print, true) << "\n"; } else { - for (PrintObject *object : print->objects()) { + size_t unique_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() + for (PrintInstance& inst : object->instances()) { + inst.unique_id = unique_id++; + inst.id = inst_id++; + auto bbox = inst.get_bounding_box(); + auto center = print->translate_to_print_space(Vec2d(bbox.center().x(), bbox.center().y())); + auto inst_name = get_instance_name(object, inst); + if (gflavor == gcfKlipper) { + gcode << "EXCLUDE_OBJECT_DEFINE NAME=" << inst_name << " CENTER=" << center.x() << "," << center.y() << " POLYGON=" << polygon_to_string(inst.get_convex_hull_2d(), print) << "\n"; + } else if (gflavor == gcfMarlinLegacy || gflavor == gcfMarlinFirmware || gflavor == gcfRepRapFirmware) { + gcode << "M486 S" << std::to_string(inst.unique_id); + if (gflavor == gcfRepRapFirmware) + gcode << " A" + << "\"" << inst_name << "\""; + else + gcode << "\nM486 A" << inst_name; + gcode << "\nM486 S-1\n"; } } } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 440d72e05e..231761f957 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -204,6 +204,8 @@ struct PrintInstance // // instance id size_t id; + // Orca: unique id used by marlin/rrf cancel object feature + size_t unique_id; //BBS: instance_shift is too large because of multi-plate, apply without plate offset. Point shift_without_plate_offset() const;