From 142499871e7b82e69b459d509d6a4ff4b5d495da Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 21 Aug 2023 13:08:32 +0800 Subject: [PATCH] NEW: add best_object_pos for auto-arranging For i3 printers, best object position may not be the bed center, we need to align objects to the specified best_object_pos. Jira: STUDIO-4133 Change-Id: I06e31e597d2dd8288eb24a52d836cc8a134a4111 --- .../BBL/machine/Bambu Lab P1P 0.4 nozzle.json | 1 - .../BBL/machine/Bambu Lab P1S 0.4 nozzle.json | 1 - .../BBL/machine/Bambu Lab X1 0.4 nozzle.json | 1 - .../BBL/machine/fdm_bbl_3dp_001_common.json | 2 ++ .../include/libnest2d/placers/nfpplacer.hpp | 10 ++++++- src/libslic3r/Arrange.cpp | 28 ++++++++++++------- src/libslic3r/Arrange.hpp | 1 + src/libslic3r/Preset.cpp | 1 + src/libslic3r/PrintConfig.cpp | 8 +++++- src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/Jobs/ArrangeJob.cpp | 10 ++++--- src/slic3r/GUI/Plater.cpp | 3 +- src/slic3r/GUI/Tab.cpp | 1 + 13 files changed, 48 insertions(+), 20 deletions(-) diff --git a/resources/profiles/BBL/machine/Bambu Lab P1P 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab P1P 0.4 nozzle.json index db2835791..e2c2d68b1 100644 --- a/resources/profiles/BBL/machine/Bambu Lab P1P 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab P1P 0.4 nozzle.json @@ -33,7 +33,6 @@ "z_hop": [ "0.2" ], - "printer_structure": "corexy", "upward_compatible_machine": [ "Bambu Lab P1S 0.4 nozzle", "Bambu Lab X1 0.4 nozzle", diff --git a/resources/profiles/BBL/machine/Bambu Lab P1S 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab P1S 0.4 nozzle.json index f6ff88c3a..59b1d8e8d 100644 --- a/resources/profiles/BBL/machine/Bambu Lab P1S 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab P1S 0.4 nozzle.json @@ -32,7 +32,6 @@ "z_hop": [ "0.2" ], - "printer_structure": "corexy", "upward_compatible_machine": [ "Bambu Lab P1P 0.4 nozzle", "Bambu Lab X1 0.4 nozzle", diff --git a/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json index 857269ad5..cfdd6bd70 100644 --- a/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json @@ -32,7 +32,6 @@ "z_hop": [ "0.2" ], - "printer_structure": "corexy", "upward_compatible_machine": [ "Bambu Lab P1P 0.4 nozzle", "Bambu Lab P1S 0.4 nozzle", diff --git a/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json b/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json index 7a4f799ec..08bfd2a0c 100644 --- a/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json +++ b/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json @@ -118,6 +118,8 @@ "printer_settings_id": "", "printer_technology": "FFF", "printer_variant": "0.4", + "printer_structure": "corexy", + "best_object_pos":"0.5x0.5", "retraction_minimum_travel": [ "1" ], diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index e1e6fba22..c722d0374 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -37,8 +37,9 @@ struct NfpPConfig { BOTTOM_RIGHT, TOP_LEFT, TOP_RIGHT, - DONT_ALIGN //!> Warning: parts may end up outside the bin with the + DONT_ALIGN, //!> Warning: parts may end up outside the bin with the //! default object function. + USER_DEFINED }; /// Which angles to try out for better results. @@ -50,6 +51,8 @@ struct NfpPConfig { /// Where to start putting objects in the bin. Alignment starting_point; + TPoint best_object_pos; + /** * @brief A function object representing the fitting function in the * placement optimization process. (Optional) @@ -1100,6 +1103,11 @@ private: cb = bbin.maxCorner(); break; } + case Config::Alignment::USER_DEFINED: { + ci = bb.center(); + cb = config_.best_object_pos; + break; + } default: ; // DONT_ALIGN } diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index e23648bbb..8d1b3d12a 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -244,16 +244,16 @@ Points get_shrink_bedpts(const DynamicPrintConfig* print_cfg, const ArrangeParam // Slic3r. template void fill_config(PConf& pcfg, const ArrangeParams ¶ms) { - - if (params.is_seq_print) { - // Start placing the items from the center of the print bed - pcfg.starting_point = PConf::Alignment::BOTTOM_LEFT; - } - else { - // Start placing the items from the center of the print bed - pcfg.starting_point = PConf::Alignment::TOP_RIGHT; - } - + + if (params.is_seq_print) { + // Start placing the items from the center of the print bed + pcfg.starting_point = PConf::Alignment::BOTTOM_LEFT; + } + else { + // Start placing the items from the center of the print bed + pcfg.starting_point = PConf::Alignment::TOP_RIGHT; + } + if (params.do_final_align) { // Align the arranged pile into the center of the bin pcfg.alignment = PConf::Alignment::CENTER; @@ -655,6 +655,14 @@ public: m_norm = std::sqrt(m_bin_area); fill_config(m_pconf, params); this->params = params; + + // if best object center is not bed center, specify starting point here + if (std::abs(this->params.align_center.x() - 0.5) > 0.001 || std::abs(this->params.align_center.y() - 0.5) > 0.001) { + auto binbb = sl::boundingBox(m_bin); + m_pconf.best_object_pos = binbb.minCorner() + Point{ binbb.width() * this->params.align_center.x(), binbb.height() * this->params.align_center.y() }; + m_pconf.alignment = PConfig::Alignment::USER_DEFINED; + } + for (auto& region : m_pconf.m_excluded_regions) { Box bb = region.boundingBox(); m_excluded_and_extruCali_regions.emplace_back(bb); diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 523e8baa7..1b1300084 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -128,6 +128,7 @@ struct ArrangeParams { float clearance_height_to_lid = 0; float cleareance_radius = 0; float printable_height = 256.0; + Vec2d align_center{ 0.5,0.5 }; ArrangePolygons excluded_regions; // regions cant't be used ArrangePolygons nonprefered_regions; // regions can be used but not prefered diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index e36a4cc9f..e49ac3f35 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -853,6 +853,7 @@ static std::vector s_Preset_printer_options { // BBS "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode", "nozzle_type","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types","support_chamber_temp_control","support_air_filtration","printer_structure", + "best_object_pos", //OrcaSlicer "host_type", "print_host", "printhost_apikey", "print_host_webui", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 19de34712..3e72d6df0 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -502,7 +502,7 @@ void PrintConfigDef::init_common_params() def->mode = comAdvanced; def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionEnum(atKeyPassword)); - + // temporary workaround for compatibility with older Slicer { def = this->add("preset_name", coString); @@ -1765,6 +1765,12 @@ void PrintConfigDef::init_fff_params() def->mode = comDevelop; def->set_default_value(new ConfigOptionEnum(psUndefine)); + def = this->add("best_object_pos", coPoint); + def->label = L("Best object position"); + def->tooltip = L("Best auto arranging position in range [0,1] w.r.t. bed shape."); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionPoint(Vec2d(0.5, 0.5))); + def = this->add("auxiliary_fan", coBool); def->label = L("Auxiliary part cooling fan"); def->tooltip = L("Enable this option if machine has auxiliary part cooling fan"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 3b42cf24c..e0ad6744e 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -957,6 +957,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionInts, fan_min_speed)) ((ConfigOptionFloats, min_layer_height)) ((ConfigOptionFloat, printable_height)) + ((ConfigOptionPoint, best_object_pos)) ((ConfigOptionFloats, slow_down_min_speed)) ((ConfigOptionFloats, nozzle_diameter)) ((ConfigOptionBool, reduce_infill_retraction)) diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 4aa1e4860..76fd36c8d 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -745,11 +745,13 @@ arrangement::ArrangeParams init_arrange_params(Plater *p) arrangement::ArrangeParams params; const GLCanvas3D::ArrangeSettings &settings = static_cast(p->canvas3D())->get_arrange_settings(); auto & print = wxGetApp().plater()->get_partplate_list().get_current_fff_print(); + const PrintConfig& print_config = print.config(); - params.clearance_height_to_rod = print.config().extruder_clearance_height_to_rod.value; - params.clearance_height_to_lid = print.config().extruder_clearance_height_to_lid.value; - params.cleareance_radius = print.config().extruder_clearance_max_radius.value; - params.printable_height = print.config().printable_height.value; + params.clearance_height_to_rod = print_config.extruder_clearance_height_to_rod.value; + params.clearance_height_to_lid = print_config.extruder_clearance_height_to_lid.value; + params.cleareance_radius = print_config.extruder_clearance_max_radius.value; + params.printable_height = print_config.printable_height.value; + params.align_center = print_config.best_object_pos.value; params.allow_rotations = settings.enable_rotation; params.allow_multi_materials_on_same_plate = settings.allow_multi_materials_on_same_plate; params.avoid_extrusion_cali_region = settings.avoid_extrusion_cali_region; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5d32d3b8c..4bf4f5aca 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2452,7 +2452,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) "layer_height", "initial_layer_print_height", "min_layer_height", "max_layer_height", "brim_width", "wall_loops", "wall_filament", "sparse_infill_density", "sparse_infill_filament", "top_shell_layers", "enable_support", "support_filament", "support_interface_filament", - "support_top_z_distance", "support_bottom_z_distance", "raft_layers" + "support_top_z_distance", "support_bottom_z_distance", "raft_layers", + "best_object_pos" })) , sidebar(new Sidebar(q)) , notification_manager(std::make_unique(q)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index b5e7d6b2d..2631f6a6c 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2997,6 +2997,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup->append_single_option_line("printable_height"); optgroup->append_single_option_line("nozzle_volume"); + optgroup->append_single_option_line("best_object_pos"); // BBS #if 0 //optgroup->append_single_option_line("z_offset");