diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 3f42471b4..a65c31eb1 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -2072,6 +2072,7 @@ int CLI::run(int argc, char **argv) for (ModelObject* model_object : model.objects) for (ModelInstance *i : model_object->instances) { + i->use_loaded_id_for_label = true; if (skip_maps.find(i->loaded_id) != skip_maps.end()) { skip_maps[i->loaded_id] = true; i->printable = false; @@ -2178,6 +2179,22 @@ int CLI::run(int argc, char **argv) } } #endif + //check whether it is bbl printer + std::string& printer_model_string = new_print_config.opt_string("printer_model", true); + bool is_bbl_vendor_preset = false; + + if (!printer_model_string.empty()) { + is_bbl_vendor_preset = (printer_model_string.compare(0, 9, "Bambu Lab") == 0); + BOOST_LOG_TRIVIAL(info) << boost::format("printer_model_string: %1%, is_bbl_vendor_preset %2%")%printer_model_string %is_bbl_vendor_preset; + } + else { + if (!new_printer_name.empty()) + is_bbl_vendor_preset = (new_printer_name.compare(0, 9, "Bambu Lab") == 0); + else if (!current_printer_system_name.empty()) + is_bbl_vendor_preset = (current_printer_system_name.compare(0, 9, "Bambu Lab") == 0); + BOOST_LOG_TRIVIAL(info) << boost::format("new_printer_name: %1%, current_printer_system_name %2%, is_bbl_vendor_preset %3%")%new_printer_name %current_printer_system_name %is_bbl_vendor_preset; + } + (dynamic_cast(print))->set_BBL_Printer(is_bbl_vendor_preset); if (load_slicedata) { std::string plate_dir = load_slice_data_dir+"/"+std::to_string(index+1); int ret = print->load_cached_data(plate_dir); @@ -2217,7 +2234,7 @@ int CLI::run(int argc, char **argv) part_plate->set_tmp_gcode_path(outfile); } BOOST_LOG_TRIVIAL(info) << "process finished, will export gcode temporily to " << outfile << std::endl; - outfile = (dynamic_cast(print))->export_gcode(outfile, gcode_result, nullptr, true); + outfile = (dynamic_cast(print))->export_gcode(outfile, gcode_result, nullptr); //outfile_final = (dynamic_cast(print))->print_statistics().finalize_output_path(outfile); //m_fff_print->export_gcode(m_temp_output_path, m_gcode_result, [this](const ThumbnailsParams& params) { return this->render_thumbnails(params); }); }/* else { diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index e3b81353f..41358c832 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1048,7 +1048,7 @@ bool GCode::is_BBL_Printer() return false; } -void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb, bool using_identify_id) +void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb) { PROFILE_CLEAR(); @@ -1108,7 +1108,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu try { m_placeholder_parser_failed_templates.clear(); - this->_do_export(*print, file, thumbnail_cb, using_identify_id); + this->_do_export(*print, file, thumbnail_cb); file.flush(); if (file.is_error()) { file.close(); @@ -1437,7 +1437,7 @@ static BambuBedType to_bambu_bed_type(BedType type) return bambu_bed_type; } -void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb, bool using_identify_id) +void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb) { PROFILE_FUNC(); @@ -1530,14 +1530,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato m_label_objects_ids.reserve(print.num_object_instances()); for (const PrintObject* print_object : print.objects()) for (const PrintInstance& print_instance : print_object->instances()) - { - size_t instance_identify_id; - if (using_identify_id && print_instance.model_instance->loaded_id > 0) - instance_identify_id = print_instance.model_instance->loaded_id; - else - instance_identify_id = print_instance.model_instance->id().id; - m_label_objects_ids.push_back(instance_identify_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::string objects_id_list = "; model label id: "; @@ -2473,7 +2467,7 @@ std::vector GCode::sort_print_object_instances( const PrintObject *print_object = layers[layer_id].original_object; //const PrintObject *print_object = layers[layer_id].object(); if (print_object) - out.emplace_back(object_by_extruder, layer_id, *print_object, single_object_instance_idx, print_object->instances()[single_object_instance_idx].model_instance->id().id); + out.emplace_back(object_by_extruder, layer_id, *print_object, single_object_instance_idx, print_object->instances()[single_object_instance_idx].model_instance->get_labeled_id()); } } else { // Create mapping from PrintObject* to ObjectByExtruder*. @@ -2501,7 +2495,7 @@ std::vector GCode::sort_print_object_instances( auto it = std::lower_bound(sorted.begin(), sorted.end(), key); if (it != sorted.end() && it->first == &print_object) // ObjectByExtruder for this PrintObject was found. - out.emplace_back(*it->second, it->second - objects_by_extruder.data(), print_object, instance - print_object.instances().data(), instance->model_instance->id().id); + out.emplace_back(*it->second, it->second - objects_by_extruder.data(), print_object, instance - print_object.instances().data(), instance->model_instance->get_labeled_id()); } } } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 79141dd8c..5f7b00154 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -167,7 +167,7 @@ public: // throws std::runtime_exception on error, // throws CanceledException through print->throw_if_canceled(). - void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr, bool using_identify_id = false); + void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); //BBS: set offset for gcode writer void set_gcode_offset(double x, double y) { m_writer.set_xy_offset(x, y); m_processor.set_xy_offset(x, y);} @@ -277,7 +277,7 @@ private: FILE *f = nullptr; GCodeProcessor &m_processor; }; - void _do_export(Print &print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb, bool using_identify_id = false); + void _do_export(Print &print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb); static std::vector collect_layers_to_print(const PrintObject &object); static std::vector>> collect_layers_to_print(const Print &print); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 2b71c2749..1560dfc80 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -257,7 +257,7 @@ namespace Slic3r { }; static const std::string& reserved_tag(ETags tag) { return Reserved_Tags[static_cast(tag)]; } - // checks the given gcode for reserved tags and returns true when finding the 1st (which is returned into found_tag) + // checks the given gcode for reserved tags and returns true when finding the 1st (which is returned into found_tag) static bool contains_reserved_tag(const std::string& gcode, std::string& found_tag); // checks the given gcode for reserved tags and returns true when finding any // (the first max_count found tags are returned into found_tag) @@ -365,7 +365,7 @@ namespace Slic3r { AxisCoords axis_feedrate; // mm/s AxisCoords abs_axis_feedrate; // mm/s - //BBS: unit vector of enter speed and exit speed in x-y-z space. + //BBS: unit vector of enter speed and exit speed in x-y-z space. //For line move, there are same. For arc move, there are different. Vec3f enter_direction; Vec3f exit_direction; diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index a6ccc6ca1..d3efbaa19 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1227,9 +1227,18 @@ public: ModelInstanceEPrintVolumeState print_volume_state; // Whether or not this instance is printable bool printable; + bool use_loaded_id_for_label {false}; int arrange_order = 0; // BBS size_t loaded_id = 0; // BBS + size_t get_labeled_id() const + { + if (use_loaded_id_for_label && (loaded_id > 0)) + return loaded_id; + else + return id().id; + } + ModelObject* get_object() const { return this->object; } const Geometry::Transformation& get_transformation() const { return m_transformation; } diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index b9fb80ace..76a5a9390 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1754,7 +1754,7 @@ void Print::process(bool use_cache) // The export_gcode may die for various reasons (fails to process filename_format, // write error into the G-code, cannot execute post-processing scripts). // It is up to the caller to show an error message. -std::string Print::export_gcode(const std::string& path_template, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb, bool using_identify_id) +std::string Print::export_gcode(const std::string& path_template, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb) { // output everything to a G-code file // The following call may die if the filename_format template substitution fails. @@ -1774,7 +1774,7 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor //BBS: compute plate offset for gcode-generator const Vec3d origin = this->get_plate_origin(); gcode.set_gcode_offset(origin(0), origin(1)); - gcode.do_export(this, path.c_str(), result, thumbnail_cb, using_identify_id); + gcode.do_export(this, path.c_str(), result, thumbnail_cb); //BBS result->conflict_result = m_conflict_result; return path.c_str(); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 624c49c05..51a5b0dbc 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -699,7 +699,7 @@ public: void process(bool use_cache = false) override; // Exports G-code into a file name based on the path_template, returns the file path of the generated G-code file. // If preview_data is not null, the preview_data is filled in for the G-code visualization (not used by the command line Slic3r). - std::string export_gcode(const std::string& path_template, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb = nullptr, bool using_identify_id = false); + std::string export_gcode(const std::string& path_template, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); //return 0 means successful int export_cached_data(const std::string& dir_path, bool with_space=false); int load_cached_data(const std::string& directory);