From f5dd619c53c0784b4fc94a4bb3d53bf6de20bc7e Mon Sep 17 00:00:00 2001 From: remi durand Date: Tue, 8 Jun 2021 18:50:18 +0200 Subject: [PATCH] add complete_objects_one_brim * now takes into account per-object brim for auto-arrange & complete_object check * complete_objects_one_brim allow to print the brim first to remove it from the complete_object check & arrange --- resources/ui_layout/print.ui | 1 + src/libslic3r/Preset.cpp | 1 + src/libslic3r/Print.cpp | 8 +++++--- src/libslic3r/PrintConfig.cpp | 23 ++++++++++------------- src/libslic3r/PrintConfig.hpp | 2 ++ src/slic3r/GUI/ConfigManipulation.cpp | 2 +- src/slic3r/GUI/Jobs/ArrangeJob.cpp | 27 ++++++++++++++++++++++++--- src/slic3r/GUI/Plater.cpp | 1 + 8 files changed, 45 insertions(+), 20 deletions(-) diff --git a/resources/ui_layout/print.ui b/resources/ui_layout/print.ui index f126dea81..b430e7bd3 100644 --- a/resources/ui_layout/print.ui +++ b/resources/ui_layout/print.ui @@ -348,6 +348,7 @@ group:Plater group:Sequential printing setting:complete_objects setting:complete_objects_one_skirt + setting:complete_objects_one_brim setting:complete_objects_sort line:Extruder clearance (mm) setting:width$6:extruder_clearance_radius diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 83a34835f..676daa70a 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -531,6 +531,7 @@ const std::vector& Preset::print_options() , "support_material_buildplate_only", "dont_support_bridges", "notes", "complete_objects", "complete_objects_one_skirt", + "complete_objects_one_brim", "complete_objects_sort", "extruder_clearance_radius", "extruder_clearance_height", "gcode_comments", "gcode_label_objects", "output_filename_format", "post_process", "perimeter_extruder", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index ba868f95e..379123666 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -202,6 +202,7 @@ bool Print::invalidate_state_by_config_options(const std::vector map_model_object_to_convex_hull; + const double dist_grow = PrintConfig::min_object_distance(&print.default_region_config()); for (const PrintObject *print_object : print.objects()) { - double dist_grow = PrintConfig::min_object_distance(&print_object->config()); + const double object_grow = print.config().complete_objects_one_brim ? dist_grow : std::max(dist_grow, print_object->config().brim_width.value); assert(! print_object->model_object()->instances.empty()); assert(! print_object->instances().empty()); ObjectID model_object_id = print_object->model_object()->id(); @@ -1294,7 +1296,7 @@ static inline bool sequential_print_horizontal_clearance_valid(const Print &prin Geometry::assemble_transform(Vec3d::Zero(), model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())), // Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects // exactly by satisfying the extruder_clearance_radius, this test will not trigger collision. - float(scale_(0.5 * dist_grow - EPSILON)), + float(scale_(0.5 * object_grow - EPSILON)), jtRound, float(scale_(0.1))).front()); } // Make a copy, so it may be rotated for instances. @@ -1803,7 +1805,7 @@ void Print::process() const PrintObjectConfig &brim_config = obj_group.front()->config(); if (brim_config.brim_width > 0 || brim_config.brim_width_interior > 0) { this->set_status(88, L("Generating brim")); - if (config().complete_objects) { + if (config().complete_objects && !config().complete_objects_one_brim) { for (PrintObject *obj : obj_group) { //get flow std::vector set_extruders = this->object_extruders({ obj }); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 33d3cb808..b2a94e624 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -575,6 +575,14 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionBool(false)); + def = this->add("complete_objects_one_brim", coBool); + def->label = L("Print all brim at startup"); + def->category = OptionCategory::output; + def->tooltip = L("When using 'Complete individual objects', the default behavior is to draw the brim at the beginning of each object." + " if you prefer to have more place for you objects, you can print all the brims at the beginning, so ther is less problem with collision."); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionBool(false)); + def = this->add("complete_objects_sort", coEnum); def->label = L("Object sort"); def->category = OptionCategory::output; @@ -5381,6 +5389,7 @@ void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value, "brim_offset", "chamber_temperature", "complete_objects_one_skirt", +"complete_objects_one_brim", "complete_objects_sort", "top_fill_pattern", "solid_fill_pattern", @@ -5662,7 +5671,6 @@ double PrintConfig::min_object_distance(const ConfigBase *config, double ref_hei //std::cout << "START min_object_distance =>" << base_dist << "\n"; const ConfigOptionBool* co_opt = config->option("complete_objects"); if (co_opt && co_opt->value) { - double brim_dist = 0; double skirt_dist = 0; try { std::vector vals = dynamic_cast(config->option("nozzle_diameter"))->values; @@ -5677,18 +5685,7 @@ double PrintConfig::min_object_distance(const ConfigBase *config, double ref_hei base_dist = extruder_clearance_radius; } - //add brim width - // note: now brim can be per-object, so you have to get a different min_object_distance per object - // You should increase/reduce the size of the polygons that have a model-wide setting. const double first_layer_height = config->get_abs_value("first_layer_height"); - if (ref_height <= first_layer_height && ref_height != 0) { - if (config->option("brim_width")->getFloat() > 0) { - brim_dist += config->option("brim_width")->getFloat(); - } - } - else //if (config->option("brim_width")->getFloat() + 1 > base_dist) { - base_dist += config->option("brim_width")->getFloat(); - //} //add the skirt if (config->option("skirts")->getInt() > 0 && config->option("skirt_height")->getInt() >= 1 && !config->option("complete_objects_one_skirt")->getBool()) { if (ref_height == 0) { @@ -5721,7 +5718,7 @@ double PrintConfig::min_object_distance(const ConfigBase *config, double ref_hei catch (const std::exception & ex) { boost::nowide::cerr << ex.what() << std::endl; } - return base_dist + std::max(skirt_dist, brim_dist); + return base_dist + skirt_dist; } return base_dist; } diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index c11c5c8cb..10a7ec623 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1263,6 +1263,7 @@ public: ConfigOptionInts chamber_temperature; ConfigOptionBool complete_objects; ConfigOptionBool complete_objects_one_skirt; + ConfigOptionBool complete_objects_one_brim; ConfigOptionEnum complete_objects_sort; ConfigOptionFloats colorprint_heights; ConfigOptionBools cooling; @@ -1358,6 +1359,7 @@ protected: OPT_PTR(chamber_temperature); OPT_PTR(complete_objects); OPT_PTR(complete_objects_one_skirt); + OPT_PTR(complete_objects_one_brim); OPT_PTR(complete_objects_sort); OPT_PTR(colorprint_heights); OPT_PTR(cooling); diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 51f59cc47..48e2efa17 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -483,7 +483,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config) bool have_sequential_printing = config->opt_bool("complete_objects"); for (auto el : { /*"extruder_clearance_radius", "extruder_clearance_height",*/ "complete_objects_one_skirt", - "complete_objects_sort"}) + "complete_objects_sort", "complete_objects_one_brim"}) toggle_field(el, have_sequential_printing); bool have_ooze_prevention = config->opt_bool("ooze_prevention"); diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index d8f563da1..6b1a67908 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -69,17 +69,36 @@ void ArrangeJob::clear_input() m_unprintable.reserve(cunprint /* for optional wti */); } +void add_brim(arrangement::ArrangePolygon &ap, const ModelConfigObject &config, const Plater* plater) +{ + if (!plater->config()->option("complete_objects_one_brim")->getBool()) { + // object-brim increase the size of the object + // Should be using the "inflation" field but it's non-functional right now. + coord_t diff = scale_(plater->config()->option("brim_width")->getFloat() - plater->config()->option("extruder_clearance_radius")->getFloat() / 2); + if (config.option("brim_width")) + diff = scale_(config.option("brim_width")->getFloat() - plater->config()->option("extruder_clearance_radius")->getFloat() / 2); + if (diff > 0) { + ExPolygons brimmed = offset_ex(ap.poly, diff); + assert(brimmed.size() == 1); + ap.poly = brimmed[0]; + } + } +} + void ArrangeJob::prepare_all() { clear_input(); for (ModelObject *obj: m_plater->model().objects) for (ModelInstance *mi : obj->instances) { ArrangePolygons & cont = mi->printable ? m_selected : m_unprintable; - cont.emplace_back(get_arrange_poly(PtrWrapper{mi}, m_plater)); + arrangement::ArrangePolygon &&ap = get_arrange_poly(PtrWrapper{ mi }, m_plater); + add_brim(ap, obj->config, m_plater); + cont.emplace_back(std::move(ap)); } - if (auto wti = get_wipe_tower_arrangepoly(*m_plater)) + if (auto wti = get_wipe_tower_arrangepoly(*m_plater)) { m_selected.emplace_back(std::move(*wti)); + } } void ArrangeJob::prepare_selected() { @@ -114,7 +133,8 @@ void ArrangeJob::prepare_selected() { (inst_sel[i] ? m_selected : m_unselected) : m_unprintable; - + + add_brim(ap, model.objects[oidx]->config, m_plater); cont.emplace_back(std::move(ap)); } } @@ -124,6 +144,7 @@ void ArrangeJob::prepare_selected() { auto &cont = m_plater->get_selection().is_wipe_tower() ? m_selected : m_unselected; + cont.emplace_back(std::move(ap)); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 991c0f7e2..2cd015d4b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1978,6 +1978,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) "complete_objects", "complete_objects_sort", "complete_objects_one_skirt", + "complete_objects_one_brim", "duplicate_distance", "extruder_clearance_radius", "skirt_extrusion_width", "first_layer_extrusion_width",