From 93b1a335d203992bf8d19f66a7c51b1755a6dadc Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Wed, 14 Dec 2022 15:05:01 +0800 Subject: [PATCH] ENH: allow generate wipe tower when print ByObject allow generate wipe tower when print ByObject if there is only one object Change-Id: I199e9cab7bd7c963edf58e829c663bb91c12f4f8 (cherry picked from commit 7153c30800022f3afb9811c67f88ba28c9b25d20) --- src/libslic3r/GCode.cpp | 9 ++++++--- src/libslic3r/PrintApply.cpp | 4 ++-- src/libslic3r/PrintConfig.cpp | 4 ++-- src/libslic3r/PrintConfig.hpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 6 +++++- src/slic3r/GUI/PartPlate.cpp | 20 ++++++++++++++++++++ src/slic3r/GUI/PartPlate.hpp | 2 ++ 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 6a649d28fd..995df84587 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1409,6 +1409,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato // We don't allow switching of extruders per layer by Model::custom_gcode_per_print_z in sequential mode. // Use the extruder IDs collected from Regions. this->set_extruders(print.extruders()); + + has_wipe_tower = print.has_wipe_tower() && tool_ordering.has_wipe_tower(); } else { // Find tool ordering for all the objects at once, and the initial extruder ID. // If the tool ordering has been pre-calculated by Print class for wipe tower already, reuse it. @@ -1582,7 +1584,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato file.write("M981 S1 P20000 ;open spaghetti detector\n"); // Do all objects for each layer. - if (print.config().print_sequence == PrintSequence::ByObject) { + if (print.config().print_sequence == PrintSequence::ByObject && !has_wipe_tower) { size_t finished_objects = 0; const PrintObject *prev_object = (*print_object_instance_sequential_active)->print_object; for (; print_object_instance_sequential_active != print_object_instances_ordering.end(); ++ print_object_instance_sequential_active) { @@ -2752,8 +2754,9 @@ GCode::LayerResult GCode::process_layer( // BBS: ordering instances by extruder std::vector instances_to_print; bool has_prime_tower = print.config().enable_prime_tower - && print.config().print_sequence == PrintSequence::ByLayer - && print.extruders().size() > 1; + && print.extruders().size() > 1 + && (print.config().print_sequence == PrintSequence::ByLayer + || (print.config().print_sequence == PrintSequence::ByObject && print.objects().size() == 1)); if (has_prime_tower) { int plate_idx = print.get_plate_index(); Point wt_pos(print.config().wipe_tower_x.get_at(plate_idx), print.config().wipe_tower_y.get_at(plate_idx)); diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index ea5f1f281b..c1ab2c8046 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -1024,7 +1024,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ //new_full_config.normalize_fdm(used_filaments); new_full_config.normalize_fdm_1(); - t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(used_filaments); + t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(objects().size(), used_filaments); if (changed_keys.size() > 0) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got changed_keys, size=%1%")%changed_keys.size(); for (int i = 0; i < changed_keys.size(); i++) @@ -1415,7 +1415,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ //BBS: check the config again int new_used_filaments = this->extruders(true).size(); - t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(new_used_filaments); + t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(objects().size(), new_used_filaments); if (new_changed_keys.size() > 0) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got new_changed_keys, size=%1%")%new_changed_keys.size(); for (int i = 0; i < new_changed_keys.size(); i++) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 8777882c02..7443ccbea2 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -4035,7 +4035,7 @@ void DynamicPrintConfig::normalize_fdm_1() return; } -t_config_option_keys DynamicPrintConfig::normalize_fdm_2(int used_filaments) +t_config_option_keys DynamicPrintConfig::normalize_fdm_2(int num_objects, int used_filaments) { t_config_option_keys changed_keys; ConfigOptionBool* ept_opt = this->option("enable_prime_tower"); @@ -4046,7 +4046,7 @@ t_config_option_keys DynamicPrintConfig::normalize_fdm_2(int used_filaments) ConfigOptionEnum* timelapse_opt = this->option>("timelapse_type"); bool is_smooth_timelapse = timelapse_opt != nullptr && timelapse_opt->value == TimelapseType::tlSmooth; - if (!is_smooth_timelapse && (used_filaments == 1 || ps_opt->value == PrintSequence::ByObject)) { + if (!is_smooth_timelapse && (used_filaments == 1 || (ps_opt->value == PrintSequence::ByObject && num_objects > 1))) { if (ept_opt->value) { ept_opt->value = false; changed_keys.push_back("enable_prime_tower"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index b9569b7589..399deb617b 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -361,7 +361,7 @@ public: void normalize_fdm(int used_filaments = 0); void normalize_fdm_1(); //return the changed param set - t_config_option_keys normalize_fdm_2(int used_filaments = 0); + t_config_option_keys normalize_fdm_2(int num_objects, int used_filaments = 0); void set_num_extruders(unsigned int num_extruders); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0cc647ebe6..6ac14e9ee7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2521,8 +2521,12 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re auto timelapse_type = dconfig.option>("timelapse_type"); bool timelapse_enabled = timelapse_type ? (timelapse_type->value == TimelapseType::tlSmooth) : false; - if ((timelapse_enabled && wt) || (filaments_count > 1 && wt && co != nullptr && co->value != PrintSequence::ByObject)) { + if (wt && (timelapse_enabled || filaments_count > 1)) { for (int plate_id = 0; plate_id < n_plates; plate_id++) { + // If print ByObject and there is only one object in the plate, the wipe tower is allowed to be generated. + if (co != nullptr && co->value == PrintSequence::ByObject && ppl.get_plate(plate_id)->printable_instance_size() != 1) + continue; + DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; float x = dynamic_cast(proj_cfg.option("wipe_tower_x"))->get_at(plate_id); float y = dynamic_cast(proj_cfg.option("wipe_tower_y"))->get_at(plate_id); diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index ce35bded2b..5947259aaa 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1729,6 +1729,26 @@ void PartPlate::update_object_index(int obj_idx_removed, int obj_idx_max) } +int PartPlate::printable_instance_size() +{ + int size = 0; + for (std::set>::iterator it = obj_to_instance_set.begin(); it != obj_to_instance_set.end(); ++it) { + int obj_id = it->first; + int instance_id = it->second; + + if (obj_id >= m_model->objects.size()) + continue; + + ModelObject * object = m_model->objects[obj_id]; + ModelInstance *instance = object->instances[instance_id]; + + if ((instance->printable) && (instance_outside_set.find(std::pair(obj_id, instance_id)) == instance_outside_set.end())) { + size++; + } + } + return size; +} + //whether it is has printable instances bool PartPlate::has_printable_instances() { diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 327df2aac8..6e37c52579 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -292,6 +292,8 @@ public: //whether it is empty bool empty() { return obj_to_instance_set.empty(); } + int printable_instance_size(); + //whether it is has printable instances bool has_printable_instances();