mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
ENH: skip_objects: optimize the label_id logic in ModelInstance
Change-Id: Id20fe9b084426036d6cf4f54859655579bec7197 (cherry picked from commit ebb5343eef6aea9e54d11f3d6b98cf11ff941aa5)
This commit is contained in:
parent
8620e3ff85
commit
d385384907
7 changed files with 41 additions and 21 deletions
|
@ -2072,6 +2072,7 @@ int CLI::run(int argc, char **argv)
|
||||||
for (ModelObject* model_object : model.objects)
|
for (ModelObject* model_object : model.objects)
|
||||||
for (ModelInstance *i : model_object->instances)
|
for (ModelInstance *i : model_object->instances)
|
||||||
{
|
{
|
||||||
|
i->use_loaded_id_for_label = true;
|
||||||
if (skip_maps.find(i->loaded_id) != skip_maps.end()) {
|
if (skip_maps.find(i->loaded_id) != skip_maps.end()) {
|
||||||
skip_maps[i->loaded_id] = true;
|
skip_maps[i->loaded_id] = true;
|
||||||
i->printable = false;
|
i->printable = false;
|
||||||
|
@ -2178,6 +2179,22 @@ int CLI::run(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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*>(print))->set_BBL_Printer(is_bbl_vendor_preset);
|
||||||
if (load_slicedata) {
|
if (load_slicedata) {
|
||||||
std::string plate_dir = load_slice_data_dir+"/"+std::to_string(index+1);
|
std::string plate_dir = load_slice_data_dir+"/"+std::to_string(index+1);
|
||||||
int ret = print->load_cached_data(plate_dir);
|
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);
|
part_plate->set_tmp_gcode_path(outfile);
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "process finished, will export gcode temporily to " << outfile << std::endl;
|
BOOST_LOG_TRIVIAL(info) << "process finished, will export gcode temporily to " << outfile << std::endl;
|
||||||
outfile = (dynamic_cast<Print*>(print))->export_gcode(outfile, gcode_result, nullptr, true);
|
outfile = (dynamic_cast<Print*>(print))->export_gcode(outfile, gcode_result, nullptr);
|
||||||
//outfile_final = (dynamic_cast<Print*>(print))->print_statistics().finalize_output_path(outfile);
|
//outfile_final = (dynamic_cast<Print*>(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); });
|
//m_fff_print->export_gcode(m_temp_output_path, m_gcode_result, [this](const ThumbnailsParams& params) { return this->render_thumbnails(params); });
|
||||||
}/* else {
|
}/* else {
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ bool GCode::is_BBL_Printer()
|
||||||
return false;
|
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();
|
PROFILE_CLEAR();
|
||||||
|
|
||||||
|
@ -1108,7 +1108,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_placeholder_parser_failed_templates.clear();
|
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();
|
file.flush();
|
||||||
if (file.is_error()) {
|
if (file.is_error()) {
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -1437,7 +1437,7 @@ static BambuBedType to_bambu_bed_type(BedType type)
|
||||||
return bambu_bed_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();
|
PROFILE_FUNC();
|
||||||
|
|
||||||
|
@ -1530,14 +1530,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
||||||
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());
|
||||||
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);
|
|
||||||
}
|
|
||||||
std::sort(m_label_objects_ids.begin(), m_label_objects_ids.end());
|
std::sort(m_label_objects_ids.begin(), m_label_objects_ids.end());
|
||||||
|
|
||||||
std::string objects_id_list = "; model label id: ";
|
std::string objects_id_list = "; model label id: ";
|
||||||
|
@ -2473,7 +2467,7 @@ std::vector<GCode::InstanceToPrint> GCode::sort_print_object_instances(
|
||||||
const PrintObject *print_object = layers[layer_id].original_object;
|
const PrintObject *print_object = layers[layer_id].original_object;
|
||||||
//const PrintObject *print_object = layers[layer_id].object();
|
//const PrintObject *print_object = layers[layer_id].object();
|
||||||
if (print_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 {
|
} else {
|
||||||
// Create mapping from PrintObject* to ObjectByExtruder*.
|
// Create mapping from PrintObject* to ObjectByExtruder*.
|
||||||
|
@ -2501,7 +2495,7 @@ std::vector<GCode::InstanceToPrint> GCode::sort_print_object_instances(
|
||||||
auto it = std::lower_bound(sorted.begin(), sorted.end(), key);
|
auto it = std::lower_bound(sorted.begin(), sorted.end(), key);
|
||||||
if (it != sorted.end() && it->first == &print_object)
|
if (it != sorted.end() && it->first == &print_object)
|
||||||
// ObjectByExtruder for this PrintObject was found.
|
// 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ public:
|
||||||
|
|
||||||
// throws std::runtime_exception on error,
|
// throws std::runtime_exception on error,
|
||||||
// throws CanceledException through print->throw_if_canceled().
|
// 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
|
//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);}
|
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;
|
FILE *f = nullptr;
|
||||||
GCodeProcessor &m_processor;
|
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<LayerToPrint> collect_layers_to_print(const PrintObject &object);
|
static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object);
|
||||||
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print);
|
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print);
|
||||||
|
|
|
@ -1227,9 +1227,18 @@ public:
|
||||||
ModelInstanceEPrintVolumeState print_volume_state;
|
ModelInstanceEPrintVolumeState print_volume_state;
|
||||||
// Whether or not this instance is printable
|
// Whether or not this instance is printable
|
||||||
bool printable;
|
bool printable;
|
||||||
|
bool use_loaded_id_for_label {false};
|
||||||
int arrange_order = 0; // BBS
|
int arrange_order = 0; // BBS
|
||||||
size_t loaded_id = 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; }
|
ModelObject* get_object() const { return this->object; }
|
||||||
|
|
||||||
const Geometry::Transformation& get_transformation() const { return m_transformation; }
|
const Geometry::Transformation& get_transformation() const { return m_transformation; }
|
||||||
|
|
|
@ -1754,7 +1754,7 @@ void Print::process(bool use_cache)
|
||||||
// The export_gcode may die for various reasons (fails to process filename_format,
|
// The export_gcode may die for various reasons (fails to process filename_format,
|
||||||
// write error into the G-code, cannot execute post-processing scripts).
|
// write error into the G-code, cannot execute post-processing scripts).
|
||||||
// It is up to the caller to show an error message.
|
// 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
|
// output everything to a G-code file
|
||||||
// The following call may die if the filename_format template substitution fails.
|
// 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
|
//BBS: compute plate offset for gcode-generator
|
||||||
const Vec3d origin = this->get_plate_origin();
|
const Vec3d origin = this->get_plate_origin();
|
||||||
gcode.set_gcode_offset(origin(0), origin(1));
|
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
|
//BBS
|
||||||
result->conflict_result = m_conflict_result;
|
result->conflict_result = m_conflict_result;
|
||||||
return path.c_str();
|
return path.c_str();
|
||||||
|
|
|
@ -699,7 +699,7 @@ public:
|
||||||
void process(bool use_cache = false) override;
|
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.
|
// 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).
|
// 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
|
//return 0 means successful
|
||||||
int export_cached_data(const std::string& dir_path, bool with_space=false);
|
int export_cached_data(const std::string& dir_path, bool with_space=false);
|
||||||
int load_cached_data(const std::string& directory);
|
int load_cached_data(const std::string& directory);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue