refactor exclude object

This commit is contained in:
SoftFever 2023-08-09 10:53:39 +08:00
parent f8c9c6bfc4
commit 36750c74e6
4 changed files with 70 additions and 66 deletions

View file

@ -79,7 +79,7 @@ namespace Slic3r {
static const float g_min_purge_volume = 100.f; static const float g_min_purge_volume = 100.f;
static const float g_purge_volume_one_time = 135.f; static const float g_purge_volume_one_time = 135.f;
static const int g_max_flush_count = 4; static const int g_max_flush_count = 4;
static const size_t g_max_label_object = 64; // static const size_t g_max_label_object = 64;
Vec2d travel_point_1; Vec2d travel_point_1;
Vec2d travel_point_2; Vec2d travel_point_2;
@ -1170,8 +1170,9 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
BOOST_LOG_TRIVIAL(info) << "Exporting G-code finished" << log_memory_info(); BOOST_LOG_TRIVIAL(info) << "Exporting G-code finished" << log_memory_info();
print->set_done(psGCodeExport); print->set_done(psGCodeExport);
// Used by BBL only
result->label_object_enabled = m_enable_label_object; if(is_BBL_Printer())
result->label_object_enabled = m_enable_exclude_object;
// Write the profiler measurements to file // Write the profiler measurements to file
PROFILE_UPDATE(); PROFILE_UPDATE();
@ -1548,15 +1549,17 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str()); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str());
//BBS: total layer number //BBS: total layer number
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Total_Layer_Number_Placeholder).c_str()); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Total_Layer_Number_Placeholder).c_str());
//BBS: judge whether support skipping, if yes, list all label_object_id with sorted order here m_enable_exclude_object = config().exclude_object;
if (print.extruders(true).size() == 1 && //Don't support multi-color //Orca: extra check for bbl printer
print.num_object_instances() <= g_max_label_object && //Don't support too many objects on one plate if (is_bbl_printers) {
print.calib_params().mode == CalibMode::Calib_None) { //Don't support skipping in cali mode if (print.extruders(true).size() == 1 && // Don't support multi-color
m_enable_label_object = true; print.calib_params().mode == CalibMode::Calib_None) { // Don't support skipping in cali mode
// list all label_object_id with sorted order here
m_enable_exclude_object = true;
m_label_objects_ids.clear(); m_label_objects_ids.clear();
m_label_objects_ids.reserve(print.num_object_instances()); m_label_objects_ids.reserve(print.num_object_instances());
for (const PrintObject* print_object : print.objects()) for (const PrintObject *print_object : print.objects())
for (const PrintInstance& print_instance : print_object->instances()) for (const PrintInstance &print_instance : print_object->instances())
m_label_objects_ids.push_back(print_instance.model_instance->get_labeled_id()); m_label_objects_ids.push_back(print_instance.model_instance->get_labeled_id());
std::sort(m_label_objects_ids.begin(), m_label_objects_ids.end()); std::sort(m_label_objects_ids.begin(), m_label_objects_ids.end());
@ -1565,11 +1568,11 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
for (auto it = m_label_objects_ids.begin(); it != m_label_objects_ids.end(); it++) for (auto it = m_label_objects_ids.begin(); it != m_label_objects_ids.end(); it++)
objects_id_list += (std::to_string(*it) + (it != m_label_objects_ids.end() - 1 ? "," : "\n")); objects_id_list += (std::to_string(*it) + (it != m_label_objects_ids.end() - 1 ? "," : "\n"));
file.writeln(objects_id_list); file.writeln(objects_id_list);
} } else {
else { m_enable_exclude_object = false;
m_enable_label_object = false;
m_label_objects_ids.clear(); m_label_objects_ids.clear();
} }
}
file.write_format("; HEADER_BLOCK_END\n\n"); file.write_format("; HEADER_BLOCK_END\n\n");
@ -3325,28 +3328,24 @@ GCode::LayerResult GCode::process_layer(
if (m_config.reduce_crossing_wall) if (m_config.reduce_crossing_wall)
m_avoid_crossing_perimeters.init_layer(*m_layer); m_avoid_crossing_perimeters.init_layer(*m_layer);
// Skip objects
if (m_enable_label_object) {
std::string start_str = std::string("; start printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n";
if (print.is_BBL_printer()) {
start_str += ("M624 " + _encode_label_ids_to_base64({ instance_to_print.label_object_id }));
start_str += "\n";
}
m_writer.set_object_start_str(start_str);
}
bool reset_e = false;
if (this->config().gcode_label_objects) { if (this->config().gcode_label_objects) {
gcode += std::string("; printing object ") + instance_to_print.print_object.model_object()->name + " id:" + std::to_string(instance_to_print.print_object.get_id()) + " copy " + std::to_string(inst.id) + "\n"; gcode += std::string("; printing object ") + instance_to_print.print_object.model_object()->name +
reset_e = true; " id:" + std::to_string(instance_to_print.print_object.get_id()) + " copy " +
std::to_string(inst.id) + "\n";
}
// exclude objects
if (m_enable_exclude_object) {
if (is_BBL_Printer()) {
m_writer.set_object_start_str(
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");
} }
if (this->config().exclude_object && print.config().gcode_flavor.value == gcfKlipper) {
gcode += std::string("EXCLUDE_OBJECT_START NAME=") +
get_instance_name(&instance_to_print.print_object, inst.id) + "\n";
reset_e = true;
} }
// ref to: https://github.com/SoftFever/OrcaSlicer/pull/205/commits/7f1fe0bd544077626080aa1a9a0576aa735da1a4#r1083470162
if (reset_e && !m_config.use_relative_e_distances)
gcode += m_writer.reset_e(true);
if (m_config.enable_overhang_speed && !m_config.overhang_speed_classic) if (m_config.enable_overhang_speed && !m_config.overhang_speed_classic)
m_extrusion_quality_estimator.set_current_object(&instance_to_print.print_object); m_extrusion_quality_estimator.set_current_object(&instance_to_print.print_object);
@ -3436,26 +3435,27 @@ GCode::LayerResult GCode::process_layer(
// ironing // ironing
gcode += this->extrude_infill(print,by_region_specific, true); gcode += this->extrude_infill(print,by_region_specific, true);
} }
// Don't set m_gcode_label_objects_end if you don't had to write the m_gcode_label_objects_start.
if (!m_writer.empty_object_start_str()) {
m_writer.set_object_start_str("");
} else if (m_enable_label_object) {
std::string end_str = std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n";
if (print.is_BBL_printer())
end_str += "M625\n";
m_writer.set_object_end_str(end_str);
}
if (this->config().gcode_label_objects) { if (this->config().gcode_label_objects) {
gcode += std::string("; stop printing object ") + instance_to_print.print_object.model_object()->name + " id:" + std::to_string(instance_to_print.print_object.get_id()) + " copy " + std::to_string(inst.id) + "\n"; gcode += std::string("; stop printing object ") +
reset_e = true; instance_to_print.print_object.model_object()->name +
" id:" + std::to_string(instance_to_print.print_object.get_id()) + " copy " +
std::to_string(inst.id) + "\n";
}
// exclude objects
// Don't set m_gcode_label_objects_end if you don't had to write the m_gcode_label_objects_start.
if (!m_writer.is_object_start_str_empty()) {
m_writer.set_object_start_str("");
} else if (m_enable_exclude_object) {
if (is_BBL_Printer()) {
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");
} }
if (this->config().exclude_object && print.config().gcode_flavor.value == gcfKlipper) {
gcode += std::string("EXCLUDE_OBJECT_END NAME=") +
get_instance_name(&instance_to_print.print_object, inst.id) + "\n";
reset_e = true;
} }
if (reset_e && !m_config.use_relative_e_distances)
gcode += m_writer.reset_e(true);
} }
} }
} }

View file

@ -445,8 +445,7 @@ private:
// Those comments are received and consumed (removed from the G-code) by the CoolingBuffer.pm Perl module. // Those comments are received and consumed (removed from the G-code) by the CoolingBuffer.pm Perl module.
bool m_enable_cooling_markers; bool m_enable_cooling_markers;
// for bbl printer bool m_enable_exclude_object;
bool m_enable_label_object;
std::vector<size_t> m_label_objects_ids; std::vector<size_t> m_label_objects_ids;
std::string _encode_label_ids_to_base64(std::vector<size_t> ids); std::string _encode_label_ids_to_base64(std::vector<size_t> ids);
// Orca // Orca

View file

@ -793,6 +793,11 @@ void GCodeWriter::add_object_end_labels(std::string& gcode)
if (!m_gcode_label_objects_end.empty()) { if (!m_gcode_label_objects_end.empty()) {
gcode += m_gcode_label_objects_end; gcode += m_gcode_label_objects_end;
m_gcode_label_objects_end = ""; m_gcode_label_objects_end = "";
// Orca: reset E so that e value remain correct after skipping the object
// ref to: https://github.com/SoftFever/OrcaSlicer/pull/205/commits/7f1fe0bd544077626080aa1a9a0576aa735da1a4#r1083470162
if (!this->config.use_relative_e_distances)
gcode += reset_e(true);
} }
} }

View file

@ -90,11 +90,11 @@ public:
static std::string set_additional_fan(unsigned int speed); static std::string set_additional_fan(unsigned int speed);
//BBS //BBS
void set_object_start_str(std::string start_string) { m_gcode_label_objects_start = start_string; } void set_object_start_str(std::string start_string) { m_gcode_label_objects_start = start_string; }
bool empty_object_start_str() { return m_gcode_label_objects_start.empty(); } bool is_object_start_str_empty() { return m_gcode_label_objects_start.empty(); }
void set_object_end_str(std::string end_string) { m_gcode_label_objects_end = end_string; } void set_object_end_str(std::string end_string) { m_gcode_label_objects_end = end_string; }
bool empty_object_end_str() { return m_gcode_label_objects_end.empty(); } bool is_object_end_str_empty() { return m_gcode_label_objects_end.empty(); }
void add_object_start_labels(std::string& gcode); void add_object_start_labels(std::string &gcode);
void add_object_end_labels(std::string& gcode); void add_object_end_labels(std::string &gcode);
void add_object_change_labels(std::string& gcode); void add_object_change_labels(std::string& gcode);
//BBS: //BBS:
@ -109,7 +109,7 @@ public:
const bool is_bbl_printers() const {return m_is_bbl_printers;} const bool is_bbl_printers() const {return m_is_bbl_printers;}
void set_is_first_layer(bool bval) { m_is_first_layer = bval; } void set_is_first_layer(bool bval) { m_is_first_layer = bval; }
private: private:
// Extruders are sorted by their ID, so that binary search is possible. // Extruders are sorted by their ID, so that binary search is possible.
std::vector<Extruder> m_extruders; std::vector<Extruder> m_extruders;
bool m_single_extruder_multi_material; bool m_single_extruder_multi_material;