diff --git a/docs/HLSD/filament-for-features.md b/docs/HLSD/filament-for-features.md new file mode 100644 index 0000000000..05d6b3b5e8 --- /dev/null +++ b/docs/HLSD/filament-for-features.md @@ -0,0 +1,151 @@ +# Filament for features + +## Purpose and scope + +On a multi-material printer, each feature of an object can print with its own +filament: walls in a colour, infill in a cheaper filament, a brim in a soluble +one. The Multimaterial page groups these selectors under *Filament for +Features*. The support selectors work the same way but sit in their own group +on the Support page. + +Every selector holds a 1-based filament number, and 0 shows as "Default". The +keys live in three config classes, according to the scope of the feature: + +| Key | Config | Mixed slots | +| --- | --- | --- | +| `outer_wall_filament_id`, `inner_wall_filament_id`, `sparse_infill_filament_id`, `internal_solid_filament_id`, `top_surface_filament_id`, `bottom_surface_filament_id` | `PrintRegionConfig` | allowed | +| `brim_filament_id`, `support_filament`, `support_interface_filament` | `PrintObjectConfig` | physical only | +| `wipe_tower_filament` | `PrintConfig` | physical only | + +The region keys can be set on the process, an object, a part, a modifier or a +height range, and painting overrides them. The object keys can be set on the +process or an object. A region key may name a mixed-colour slot because tool +ordering resolves those per layer (`resolve_mixed_filaments()`). The other keys +are consumed directly by the brim, support and wipe tower code, so the GUI +offers them only physical filaments and resets a mixed value +(`ConfigManipulation`, `physical_only_keys`), and `Print::validate()` rejects a +mixed brim or wipe tower filament that arrives from a project or the CLI. + +## What "Default" means + +Region keys never reach the engine as 0. `region_config_from_model_volume()` +applies each scope in turn: the process, the object, the part, its material and +the height range. An explicit filament at any scope sets that feature. A 0 marks +the feature as following the part's own filament (`extruder`), which every scope +that carries one applies to the features nobody set explicitly. What is still +unset becomes filament 1. A painted region then sets all six keys to the painted +filament (`PrintApply.cpp`). From there on every `PrintRegion` names a concrete +filament for every feature. + +Object and print keys keep 0 into the engine, and each gives it its own meaning: + +- Support and support interface: no tool change; the support prints with + whichever filament is active. +- Brim: the brim prints in the pass of the first filament that reaches the + object on the first layer, see [Brim](#brim). +- Wipe tower: any filament, preferring a non-soluble one. + +## Which filament prints an extrusion + +`region_filament()` in `ToolOrdering.cpp` maps an island's extrusion collection +to a region key. Tool ordering and G-code export both go through it +(`LayerTools::extruder()`), so the tools planned for a layer are exactly the +tools the export asks for. + +- Sparse infill uses the sparse infill filament. +- Solid infill uses the top surface filament for top surfaces and ironing, the + bottom surface filament for bottom surfaces, and the internal solid filament + otherwise. Gap fill among infill follows the surface it fills. +- Gap fill between walls uses the inner wall filament when the region has more + than one wall, and the outer wall filament otherwise. +- A wall collection made only of inner walls uses the inner wall filament; + anything else uses the outer wall filament. + +A per-layer tool change from custom G-code (`extruder_override`) replaces all +region filaments on its layers. + +## Tool ordering + +`ToolOrdering::collect_extruders()` builds each layer's filament set from what +is actually printed there: the filaments of the regions' walls and fills, the +support filaments of support layers, the chosen brim filament on the object's +first layer, and the brim filament on every layer that carries a belt brim band. +The brim filament is added even when nothing else uses it, so a filament can be +loaded only for the brim. + +## Brim + +**Planning.** `getObjectExtruderMap()` gives each object one brim filament: the +chosen `brim_filament_id`, otherwise the lowest outer wall filament of the +object's first layer. `make_brim()` generates the brims in passes over the +first-layer filaments, and each brim records that filament +(`SkirtBrimGroup::Brim::filament_id`) for the nozzle-specific bed exclusions. +The brim line width uses the nozzle of the first object's chosen brim filament, +or of the first region's outer wall filament. + +**Combining.** *Combine brims* merges a brim with a chosen filament only with +brims that chose the same filament, so each merged brim still has a single +filament. Brims left on Default combine as before. + +**Emission.** A Default brim prints at the first visit of any of its instances, +in whichever filament's pass gets there first. This keeps the established +order, in which the brim usually goes with the outer wall filament because tool +ordering starts the first layer with it. Only nozzle-specific bed exclusions +make a Default brim wait for its recorded filament. A brim with a chosen +filament prints at the start of that filament's pass on the first layer, +before the pass visits any object (`GCode::process_layer()`), and the first +visits of other passes skip it. That filament may print nothing else on the +object, so the brim cannot rely on an object visit in its pass. + +**Belt printers.** They never print the plate brim. Belt brim bands print with +`PrintObject::belt_brim_filament()`: the chosen brim filament, or the lowest +outer wall filament of the object. + +**Invalidation.** On a flat bed the brim filament affects only the brim, the +tool ordering and the export, so changing it reruns those steps and keeps the +sliced object and its supports. The belt brim is generated with the supports +and takes its line width from the brim filament's nozzle, so on a belt printer +the change reruns the supports as well. + +## Predicting the used filaments + +Several places need the set of filaments a print or plate will use before, or +without, building the tool ordering. Each one derives it from the config with +the same rules: a feature filament counts only while its feature prints, such +as walls or a brim for the wall filaments, support for the support filaments, +and a brim for the brim filament. + +- `Print::extruders()`: the G-code writer's filament list for by-object export, + and validation. +- `PrintObject::printing_extruders()`: bed exclusion collisions and automatic + filament grouping. +- `PartPlate::get_extruders()` and `get_extruders_under_cli()`: the plate's + filament list for AMS mapping and filament checks. +- `PartPlate::get_object_filament_extruders()`: the bed exclusion preview. +- `project_used_filament_slots()` in `PublishSettingsDialog.cpp`: the filament + slots a published project uses. + +A filament missing from these lists can still be printed by the tool ordering +but is unknown to the consumer; in by-object export that means the writer has +no extruder for it. + +## Filament count changes + +When the filament count shrinks, `PresetBundle::full_fff_config()` resets +out-of-range region and brim keys to Default and clamps the support and wipe +tower keys, and `PrintObject::object_config_from_model_object()` does the same +for object overrides. Deleting a filament renumbers the support and brim keys of +objects, parts and the plater config (`ObjectList`, `Plater`). + +## Compatibility + +Older keys are renamed on load in `handle_legacy()`: `infill_extruder` and +`sparse_infill_filament`, `solid_infill_extruder` and `solid_infill_filament`, +`top_solid_infill_filament`, `bottom_solid_infill_filament`, +`perimeter_extruder`, `wall_filament`, `wall_filament_id`, +`inner_wall_filament` and `outer_wall_filament`. Their old value 1 meant "the +active filament" and maps to 0, Default; other values stay explicit. +`wipe_tower_extruder` and `support_material_extruder` are renamed as they are. +A part's `extruder` fills the region keys that are still 0 +(`DynamicPrintConfig::normalize_fdm()`). Every key defaults to 0, so a project +or profile without a key keeps its behaviour. diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 09890f570f..de9057ee18 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -6091,8 +6091,9 @@ std::string GCode::generate_object_brim( if (!first_layer) return {}; - const bool wait_for_owner_filament = has_bed_exclude_volumes(m_config) && - active_bed_exclude_volume_mode(m_config) != BedExcludeVolumeMode::Shared; + // A chosen brim filament also waits for its own pass, see process_layer(). + const bool wait_for_owner_filament = object.config().brim_filament_id.value > 0 || + (has_bed_exclude_volumes(m_config) && active_bed_exclude_volume_mode(m_config) != BedExcludeVolumeMode::Shared); auto emit_brim = [this, extruder_id, wait_for_owner_filament](const ExtrusionEntityCollection& brim, const std::vector& instances, const unsigned int brim_filament_id) { @@ -7623,6 +7624,21 @@ LayerResult GCode::process_layer( this->set_origin(saved_origin); } + // A chosen brim filament may print nothing else on its objects, so their brims go down at the start of its pass. + if (first_layer) { + const Vec2d saved_origin = m_origin; + for (const LayerToPrint <p : layers) { + const PrintObject *object = ltp.original_object; + if (object == nullptr || object->config().brim_filament_id.value <= 0 || object->has_belt_brim()) + continue; + const size_t i_begin = single_object_instance_idx == size_t(-1) ? 0 : single_object_instance_idx; + const size_t i_end = single_object_instance_idx == size_t(-1) ? object->instances().size() : single_object_instance_idx + 1; + for (size_t i = i_begin; i < i_end && i < object->instances().size(); ++i) + gcode += generate_object_brim(print, *object, i, first_layer, extruder_id, ltp.object_layer); + } + this->set_origin(saved_origin); + } + auto &filament_plan = filament_to_print_instances[extruder_id]; std::vector &instances_to_print = filament_plan.first; const std::vector &instance_visits = filament_plan.second; diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 6f7cdce70f..b574b3f7ed 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -957,6 +957,11 @@ void ToolOrdering::collect_extruders(const PrintObject &object, const std::vecto sort_remove_duplicates(firstLayerExtruders); const_cast(object).object_first_layer_wall_extruders = firstLayerExtruders; + // A chosen brim filament prints the plate brim on the object's first layer. + if (object.config().brim_filament_id.value > 0 && object.has_brim() && !object.print()->config().belt_printer.value && + !object.layers().empty()) + this->tools_for_layer(object.layers().front()->print_z).extruders.push_back(object.config().brim_filament_id.value); + // Collect the support extruders. for (auto support_layer : object.support_layers()) { LayerTools &layer_tools = this->tools_for_layer(support_layer->print_z); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 82f89d160c..1b54f24a93 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1310,6 +1310,7 @@ static std::vector s_Preset_print_options{ "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id", + "brim_filament_id", "support_filament", "support_interface_filament", "support_interface_not_for_body", diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index a6ea1347bb..a1e1483ec1 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -5832,7 +5832,7 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::optio static const char* keys_with_default[] = { "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_filament_id", - "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id" + "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id", "brim_filament_id" }; for (size_t i = 0; i < sizeof(keys_with_default) / sizeof(keys_with_default[0]); ++ i) { std::string key = std::string(keys_with_default[i]); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 415d59b27c..8976986627 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -778,6 +778,10 @@ std::vector Print::extruders(bool conside_custom_gcode) const { std::vector extruders = this->object_extruders(); append(extruders, this->support_material_extruders()); + for (const PrintObject *object : m_objects) + if (object->config().brim_filament_id.value > 0 && + ((object->has_brim() && !m_config.belt_printer.value) || object->has_belt_brim())) + extruders.push_back(object->config().brim_filament_id.value - 1); if (conside_custom_gcode) this->append_tool_change_extruders(extruders); @@ -1960,6 +1964,8 @@ StringObjectException Print::check_multi_filament_valid(const Print& print) if (print_object->config().support_interface_filament >= 1 && (unsigned int)print_object->config().support_interface_filament < num_extruders + 1) obj_used_extruder_ids.insert((unsigned int) print_object->config().support_interface_filament - 1); } + if (print_object->has_brim() && print_object->config().brim_filament_id.value > 0) + obj_used_extruder_ids.insert(print_object->config().brim_filament_id.value - 1); std::vector filament_types; std::vector nozzle_temperatures; std::vector nozzle_temperature_range_lows; @@ -2642,6 +2648,12 @@ StringObjectException Print::validate(std::vector *warnin return {_u8L("Variable layer height is not supported with Organic supports.") }; } + // The brim filament is a physical tool. The GUI hides mixed slots from the option; this guards loaded projects and the CLI. + for (const PrintObject *object : m_objects) + if (const int brim_filament = object->config().brim_filament_id.value; brim_filament > 0 && + size_t(brim_filament - 1) < m_config.filament_is_mixed.values.size() && m_config.filament_is_mixed.values[brim_filament - 1]) + return { L("The brim filament cannot be a mixed filament."), object, "brim_filament_id" }; + if ((this->has_wipe_tower() || this->has_belt_purge_tower()) && ! m_objects.empty()) { // Orca: wipe_tower_filament (issue #10971) is inserted into the tool order after // resolve_mixed_filaments has expanded every mixed (virtual) slot, so a mixed slot here @@ -3233,11 +3245,12 @@ Flow Print::brim_flow() const extruders and take the one with, say, the smallest index. The same logic should be applied to the code that selects the extruder during G-code generation as well. */ + const int brim_filament = m_objects.front()->config().brim_filament_id.value; return Flow::new_from_config_width( frPerimeter, // Flow::new_from_config_width takes care of the percent to value substitution width, - (float)nozzle_diameter_for_filament(m_config, m_print_regions.front()->config().outer_wall_filament_id, this->is_BBL_printer()), + (float)nozzle_diameter_for_filament(m_config, brim_filament > 0 ? brim_filament : m_print_regions.front()->config().outer_wall_filament_id.value, this->is_BBL_printer()), (float)this->skirt_first_layer_height()); } @@ -3397,8 +3410,11 @@ BoundingBox PrintObject::get_first_layer_bbox(float& a, float& layer_height, std std::map getObjectExtruderMap(const Print& print) { std::map objectExtruderMap; for (const PrintObject* object : print.objects()) { + if (object->config().brim_filament_id.value > 0) { + objectExtruderMap.insert(std::make_pair(object->id(), (unsigned int)object->config().brim_filament_id.value)); + } // BBS - if (object->object_first_layer_wall_extruders.empty()){ + else if (object->object_first_layer_wall_extruders.empty()){ unsigned int objectFirstLayerFirstExtruder = print.config().filament_diameter.size(); auto firstLayerRegions = object->layers().front()->regions(); if (!firstLayerRegions.empty()) { @@ -4493,6 +4509,11 @@ void Print::_make_skirt() auto compatible_brim_nozzles = [this, &brim_filament, &brim_exclusion_regions, has_nozzle_specific_brim_exclusions] (const ObjectInstanceID& first, const ObjectInstanceID& second) { + // A brim with a chosen filament is only combined with brims chosen the same. + const int first_chosen = get_object(first.object_id)->config().brim_filament_id.value; + const int second_chosen = get_object(second.object_id)->config().brim_filament_id.value; + if (first_chosen > 0 || second_chosen > 0) + return first_chosen == second_chosen; if (!has_nozzle_specific_brim_exclusions) return true; const std::optional first_filament = brim_filament(first); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index e7545739d9..2d49e491dd 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -436,8 +436,8 @@ public: // Brim filament for this object's belt brim, returned in the 1-based domain of // PrintRegion::outer_wall_filament_id and the raw values pushed into // LayerTools::extruders in ToolOrdering::collect_extruders (ToolOrdering reindexes - // the whole list to 0-based afterwards). Lowest positive outer_wall_filament_id - // over the printing regions, 1 if none is explicitly set. + // the whole list to 0-based afterwards). brim_filament_id when set, else the lowest + // positive outer_wall_filament_id over the printing regions, 1 if none is explicitly set. unsigned int belt_brim_filament() const; const std::vector& belt_brim_by_layer() const { return m_belt_brim_by_layer; } const std::vector& belt_brim_prologue() const { return m_belt_brim_prologue; } diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 59b700c121..b6b8e8afa0 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2180,6 +2180,15 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionBool(false)); + def = this->add("brim_filament_id", coInt); + def->gui_type = ConfigOptionDef::GUIType::i_enum_open; + def->label = L("Brim"); + def->category = L("Extruders"); + def->tooltip = L("Filament to print the brim.\n\"Default\" prints it with the first filament that prints the object on the first layer."); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionInt(0)); + def = this->add("brim_ears", coBool); def->label = L("Brim ears"); def->category = L("Support"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index e6fba1c46a..45aa2f5d41 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1316,6 +1316,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, brim_object_gap)) ((ConfigOptionFloat, brim_flow_ratio)) + ((ConfigOptionInt, brim_filament_id)) ((ConfigOptionBool, brim_use_efc_outline)) ((ConfigOptionEnum, brim_type)) ((ConfigOptionFloat, brim_width)) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 221fa73454..32157bc9ba 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1418,8 +1418,10 @@ unsigned int PrintObject::belt_brim_filament() const { // 1-based, matching PrintRegion::outer_wall_filament_id and the raw values pushed // into LayerTools::extruders in ToolOrdering::collect_extruders (the whole list is - // reindexed to 0-based later). Lowest positive outer-wall filament over the - // printing regions; 1 when none is explicitly set. + // reindexed to 0-based later). The chosen brim filament, else the lowest positive + // outer-wall filament over the printing regions; 1 when none is explicitly set. + if (m_config.brim_filament_id.value > 0) + return (unsigned int)m_config.brim_filament_id.value; unsigned int brim_filament = 0; for (size_t i = 0; i < this->num_printing_regions(); ++ i) { const unsigned int f = this->printing_region(i).config().outer_wall_filament_id.value; @@ -1886,6 +1888,12 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "spiral_starting_flow_ratio" || opt_key == "spiral_finishing_flow_ratio") { invalidated |= m_print->invalidate_step(psGCodeExport); + } else if (opt_key == "brim_filament_id") { + // The belt brim is built with the supports and takes its line width from the brim filament's nozzle. + if (m_print->config().belt_printer.value) + steps.emplace_back(posSupportMaterial); + else + invalidated |= m_print->invalidate_steps({ psSkirtBrim, psWipeTower, psGCodeExport }); } else if ( opt_key == "flush_into_infill" || opt_key == "flush_into_objects" @@ -4332,6 +4340,8 @@ PrintObjectConfig PrintObject::object_config_from_model_object(const PrintObject // Clamp invalid extruders to the default extruder (with index 1). clamp_exturder_to_default(config.support_filament, num_extruders); clamp_exturder_to_default(config.support_interface_filament, num_extruders); + if (config.brim_filament_id.value > (int)num_extruders) + config.brim_filament_id.value = 0; return config; } @@ -4626,15 +4636,17 @@ std::vector PrintObject::object_extruders() const std::vector PrintObject::printing_extruders() const { std::vector extruders = object_extruders(); + const size_t filament_count = print()->config().filament_diameter.size(); + auto append_fixed_filament = [&](const int filament_id) { + if (filament_id > 0) + extruders.emplace_back(std::min(size_t(filament_id - 1), filament_count > 0 ? filament_count - 1 : 0)); + }; if (has_support_material()) { - const size_t filament_count = print()->config().filament_diameter.size(); - auto append_fixed_filament = [&](const int filament_id) { - if (filament_id > 0) - extruders.emplace_back(std::min(size_t(filament_id - 1), filament_count > 0 ? filament_count - 1 : 0)); - }; append_fixed_filament(config().support_filament.value); append_fixed_filament(config().support_interface_filament.value); } + if ((has_brim() && !print()->config().belt_printer.value) || has_belt_brim()) + append_fixed_filament(config().brim_filament_id.value); if (extruders.empty()) extruders.emplace_back(0); sort_remove_duplicates(extruders); diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 86e974f11c..5ec0d31f7b 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -634,10 +634,10 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con } // BBS - // Reset filament overrides pointing at a slot that no longer exists. Support and the wipe + // Reset filament overrides pointing at a slot that no longer exists. Support, brim and the wipe // tower additionally reject mixed slots: the engine consumes those keys directly, so a virtual // slot would reach the G-code unresolved, while the per-feature keys are resolved per layer. - static const char* physical_only_keys[] = { "support_filament", "support_interface_filament", "wipe_tower_filament" }; + static const char* physical_only_keys[] = { "support_filament", "support_interface_filament", "brim_filament_id", "wipe_tower_filament" }; static const char* feature_keys[] = { "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_filament_id", "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id" }; @@ -1031,6 +1031,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, in // configured width, so the width field has to stay live for them too. toggle_field("brim_width", have_brim_width || (have_brim && is_belt_tilted), -1, _L("Select a brim type with an editable width, or enable a brim on a tilted belt printer.")); toggle_field("brim_flow_ratio", have_brim, -1, brim_reason); + toggle_field("brim_filament_id", have_brim, -1, brim_reason); // Paired toggle_line + toggle_field: cb_toggle_line is null in the per-object // override panel, so the row cannot be hidden there and greying out is the // fallback. Both extras are belt-only: one extends the brim ahead along the belt, diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 9fab82cda3..6ab2deb03d 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -782,7 +782,7 @@ void ObjectList::update_filament_values_for_items(const size_t filaments_count) } m_objects_model->SetExtruder(extruder, item); - static const char *keys[] = {"support_filament", "support_interface_filament"}; + static const char *keys[] = {"support_filament", "support_interface_filament", "brim_filament_id"}; for (auto key : keys) if (object->config.has(key) && object->config.opt_int(key) > filaments_count) object->config.erase(key); @@ -840,7 +840,7 @@ void ObjectList::update_filament_values_for_items_when_delete_filament(const siz } m_objects_model->SetExtruder(extruder, item); - static const char *keys[] = {"support_filament", "support_interface_filament"}; + static const char *keys[] = {"support_filament", "support_interface_filament", "brim_filament_id"}; for (auto key : keys) { if (object->config.has(key)) { if(object->config.opt_int(key) == filament_id + 1) diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 35c38e4820..53f41ac073 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -3027,6 +3027,8 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam int glb_internal_solid_extr = glb_config.opt_int("internal_solid_filament_id"); int glb_top_surface_extr = glb_config.opt_int("top_surface_filament_id"); int glb_bottom_surface_extr = glb_config.opt_int("bottom_surface_filament_id"); + const int glb_brim_extr = glb_config.opt_int("brim_filament_id"); + const bool glb_brim = glb_config.option("brim_type")->getInt() != int(BrimType::btNoBrim); bool glb_support = glb_config.opt_bool("enable_support"); glb_support |= glb_config.opt_int("raft_layers") > 0; @@ -3137,6 +3139,12 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam else if (glb_bottom_surface_extr != 0) plate_extruders.push_back(glb_bottom_surface_extr); + const ConfigOption* brim_type_opt = mo->config.option("brim_type"); + if (brim_type_opt != nullptr ? brim_type_opt->getInt() != int(BrimType::btNoBrim) : glb_brim) { + const ConfigOption* brim_opt = mo->config.option("brim_filament_id"); + if (const int brim_extr = brim_opt != nullptr ? brim_opt->getInt() : glb_brim_extr; brim_extr != 0) + plate_extruders.push_back(brim_extr); + } } if (conside_custom_gcode) { @@ -3192,6 +3200,9 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D int glb_internal_solid_extr = full_config.opt_int("internal_solid_filament_id"); int glb_top_surface_extr = full_config.opt_int("top_surface_filament_id"); int glb_bottom_surface_extr = full_config.opt_int("bottom_surface_filament_id"); + const ConfigOption* glb_brim_opt = full_config.option("brim_filament_id"); + const int glb_brim_extr = glb_brim_opt != nullptr ? glb_brim_opt->getInt() : 0; + const bool glb_brim = full_config.option("brim_type")->getInt() != int(BrimType::btNoBrim); bool glb_support = full_config.opt_bool("enable_support"); glb_support |= full_config.opt_int("raft_layers") > 0; @@ -3308,6 +3319,13 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D plate_extruders.push_back(obj_bottom_surface_extr); else if (glb_bottom_surface_extr != 0) plate_extruders.push_back(glb_bottom_surface_extr); + + const ConfigOption* brim_type_opt = object->config.option("brim_type"); + if (brim_type_opt != nullptr ? brim_type_opt->getInt() != int(BrimType::btNoBrim) : glb_brim) { + const ConfigOption* brim_opt = object->config.option("brim_filament_id"); + if (const int brim_extr = brim_opt != nullptr ? brim_opt->getInt() : glb_brim_extr; brim_extr != 0) + plate_extruders.push_back(brim_extr); + } } } @@ -3545,6 +3563,9 @@ std::map PartPlate::get_object_filament_extruders( filament_ids.emplace(process_config.opt_int(key)); } + if (has_brim && effective_int("brim_filament_id") > 0) + filament_ids.emplace(effective_int("brim_filament_id")); + const bool has_support = effective_bool("enable_support") || effective_int("raft_layers") > 0; if (has_support) { const int support_filament = effective_int("support_filament"); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 05c2695176..cece79df58 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1429,7 +1429,7 @@ static bool has_junction_deviation(const DynamicPrintConfig* printer_config) } static DynamicFilamentList dynamic_filament_list; // every slot, mixed included (per-feature *_filament_id keys) -static DynamicFilamentList dynamic_physical_filament_list(true); // physical slots only (support_*, wipe_tower_filament) +static DynamicFilamentList dynamic_physical_filament_list(true); // physical slots only (support_*, brim_filament_id, wipe_tower_filament) class AMSCountPopupWindow : public PopupWindow { @@ -2795,6 +2795,7 @@ Sidebar::Sidebar(Plater *parent) Choice::register_dynamic_list("internal_solid_filament_id", &dynamic_filament_list); Choice::register_dynamic_list("top_surface_filament_id", &dynamic_filament_list); Choice::register_dynamic_list("bottom_surface_filament_id", &dynamic_filament_list); + Choice::register_dynamic_list("brim_filament_id", &dynamic_physical_filament_list); Choice::register_dynamic_list("wipe_tower_filament", &dynamic_physical_filament_list); p->scrolled = new wxPanel(this); @@ -7905,7 +7906,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) "extruder_clearance_radius", "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod", "nozzle_height", "skirt_type", "skirt_loops", "skirt_speed","min_skirt_length", "skirt_distance", "skirt_start_angle", - "brim_width", "brim_object_gap", "brim_flow_ratio", "brim_use_efc_outline", "combine_brims", "brim_type", "nozzle_diameter", "single_extruder_multi_material", "preferred_orientation", + "brim_width", "brim_object_gap", "brim_flow_ratio", "brim_use_efc_outline", "combine_brims", "brim_type", "brim_filament_id", "nozzle_diameter", "single_extruder_multi_material", "preferred_orientation", "enable_prime_tower", "wipe_tower_x", "wipe_tower_y", "prime_tower_width", "prime_tower_brim_width", "prime_tower_skip_points", "prime_tower_enable_framework", "prime_tower_infill_gap", "prime_volume", "extruder_colour", "filament_colour", "filament_type", "filament_is_support", "material_colour", "printable_height", "extruder_printable_height", "printer_model", "printer_technology", @@ -21976,8 +21977,8 @@ void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id, int r // update_objects_list_filament_column() that clips extruders above total count. sidebar().obj_list()->update_objects_list_filament_column_when_delete_filament(filament_id, num_filaments, replace_filament_id); - // update global support filament - static const char *keys[] = {"support_filament", "support_interface_filament"}; + // update global support and brim filament + static const char *keys[] = {"support_filament", "support_interface_filament", "brim_filament_id"}; for (auto key : keys) if (p->config->has(key)) { if(p->config->opt_int(key) == filament_id + 1) @@ -22172,6 +22173,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config) opt_key == "outer_wall_filament_id" || opt_key == "inner_wall_filament_id" || opt_key == "sparse_infill_filament_id" || opt_key == "internal_solid_filament_id" || opt_key == "top_surface_filament_id" || opt_key == "bottom_surface_filament_id" || + opt_key == "brim_filament_id" || opt_key == "enable_support" || opt_key == "raft_layers" || opt_key == "wall_loops" || opt_key == "sparse_infill_density" || opt_key == "top_shell_layers" || opt_key == "bottom_shell_layers" || opt_key == "brim_type" || opt_key == "brim_width") { diff --git a/src/slic3r/GUI/PublishSettingsDialog.cpp b/src/slic3r/GUI/PublishSettingsDialog.cpp index 740f6edff6..c5013aef0e 100644 --- a/src/slic3r/GUI/PublishSettingsDialog.cpp +++ b/src/slic3r/GUI/PublishSettingsDialog.cpp @@ -400,6 +400,8 @@ std::set project_used_filament_slots(const PresetBundle& bundle, const D const int glb_internal_solid = print_cfg.opt_int("internal_solid_filament_id"); const int glb_top_surface = print_cfg.opt_int("top_surface_filament_id"); const int glb_bottom_surface = print_cfg.opt_int("bottom_surface_filament_id"); + const int glb_brim = print_cfg.opt_int("brim_filament_id"); + const bool glb_brim_on = print_cfg.option("brim_type")->getInt() != int(BrimType::btNoBrim); const bool glb_support_on = print_cfg.opt_bool("enable_support") || print_cfg.opt_int("raft_layers") > 0; for (ModelObject* mo : model.objects) { @@ -459,6 +461,10 @@ std::set project_used_filament_slots(const PresetBundle& bundle, const D if (obj_bottom == 0) obj_bottom = obj_internal_solid; add_1based(obj_bottom != 0 ? obj_bottom : glb_bottom_surface); + + const ConfigOption* brim_type_opt = mo->config.option("brim_type"); + if (brim_type_opt != nullptr ? brim_type_opt->getInt() != int(BrimType::btNoBrim) : glb_brim_on) + add_1based(mo->config.has("brim_filament_id") ? obj_id("brim_filament_id") : glb_brim); } for (const auto& plate_entry : model.plates_custom_gcodes) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e657d7fadc..6453bf61a8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3444,6 +3444,7 @@ void TabPrint::build() optgroup->append_single_option_line("internal_solid_filament_id", "multimaterial_settings_filament_for_features#internal-solid-infill"); optgroup->append_single_option_line("top_surface_filament_id", "multimaterial_settings_filament_for_features#top-surface"); optgroup->append_single_option_line("bottom_surface_filament_id", "multimaterial_settings_filament_for_features#bottom-surface"); + optgroup->append_single_option_line("brim_filament_id", "multimaterial_settings_filament_for_features#brim"); optgroup->append_single_option_line("wipe_tower_filament", "multimaterial_settings_filament_for_features#wipe-tower"); optgroup = page->new_optgroup(L("Ooze prevention"), L"param_ooze_prevention"); diff --git a/tests/fff_print/test_multifilament.cpp b/tests/fff_print/test_multifilament.cpp index 6f98ca423d..7fe71a6348 100644 --- a/tests/fff_print/test_multifilament.cpp +++ b/tests/fff_print/test_multifilament.cpp @@ -350,6 +350,78 @@ TEST_CASE("Per-object wall filament override is honored", "[MultiFilament]") CHECK(tools_for_role(gcode, "infill") == std::set{ 0 }); // infill not overridden: stays on F1 } +// Filament 3 prints nothing but the brim, so the brim still needs a pass of its own. +TEST_CASE("Brim prints with its assigned filament", "[MultiFilament]") +{ + const int brim_filament = GENERATE(2, 3); + const char *print_sequence = GENERATE("by layer", "by object"); + DYNAMIC_SECTION("brim filament " << brim_filament << ", " << print_sequence) { + const std::string gcode = slice({ cube(20) }, + multifilament_config(3, { + { "outer_wall_filament_id", 2 }, + { "inner_wall_filament_id", 2 }, + { "brim_filament_id", brim_filament }, + { "skirt_loops", 0 }, + { "brim_type", "outer_only" }, + { "brim_width", 5 }, + { "print_sequence", print_sequence }, + })); + CHECK(tools_for_role(gcode, "brim") == std::set{ brim_filament - 1 }); + CHECK(tools_for_role(gcode, "perimeter") == std::set{ 1 }); + } +} + +// Only the brim and the tool ordering depend on the brim filament on a flat bed. +TEST_CASE("Changing the brim filament keeps the sliced object", "[MultiFilament]") +{ + DynamicPrintConfig config = multifilament_config(3, { + { "outer_wall_filament_id", 2 }, + { "inner_wall_filament_id", 2 }, + { "brim_filament_id", 2 }, + { "skirt_loops", 0 }, + { "brim_type", "outer_only" }, + { "brim_width", 5 }, + }); + // init_print sets this on its own copy; set it here too so the re-apply below differs in the brim filament only. + config.set_key_value("gcode_comments", new ConfigOptionBool(true)); + + Print print; + Model model; + init_print(std::vector{ cube(20) }, print, model, config); + REQUIRE(tools_for_role(gcode(print), "brim") == std::set{ 1 }); + + config.set_deserialize_strict({ { "brim_filament_id", 3 } }); + DynamicPrintConfig changed = DynamicPrintConfig::full_print_config(); + changed.apply(config); + print.apply(model, changed); + CHECK(print.objects().front()->is_step_done(posSupportMaterial)); + CHECK_FALSE(print.is_step_done(psSkirtBrim)); + CHECK(tools_for_role(gcode(print), "brim") == std::set{ 2 }); +} + +// The wall filament prints the first layer first; a brim left on Default goes with it, +// a brim assigned to the infill filament waits for that filament's pass. +TEST_CASE("Brim waits for its assigned filament when another prints first", "[MultiFilament]") +{ + auto [brim_filament, brim_tool] = GENERATE(table({ { 0, 0 }, { 2, 1 } })); + DYNAMIC_SECTION("brim filament " << brim_filament) { + const std::string gcode = slice({ cube(20) }, + multifilament_config(2, { + { "outer_wall_filament_id", 1 }, + { "inner_wall_filament_id", 1 }, + { "sparse_infill_filament_id", 2 }, + { "internal_solid_filament_id", 2 }, + { "top_surface_filament_id", 2 }, + { "bottom_surface_filament_id", 2 }, + { "brim_filament_id", brim_filament }, + { "skirt_loops", 0 }, + { "brim_type", "outer_only" }, + { "brim_width", 5 }, + })); + CHECK(tools_for_role(gcode, "brim") == std::set{ brim_tool }); + } +} + // 0-based tool indices extruding under the ";TYPE:" marker of `feature`. static std::set tools_for_feature(const std::string& gcode, std::string_view feature) { diff --git a/tests/fff_print/test_skirt_brim.cpp b/tests/fff_print/test_skirt_brim.cpp index 76c22bbb74..c03daa74d0 100644 --- a/tests/fff_print/test_skirt_brim.cpp +++ b/tests/fff_print/test_skirt_brim.cpp @@ -193,6 +193,38 @@ TEST_CASE("Combine brims merges touching brims", "[SkirtBrim]") } } +TEST_CASE("Combine brims keeps brims of different chosen filaments apart", "[SkirtBrim]") +{ + auto [first_filament, second_filament, expected_brims] = GENERATE(table({ + { 1, 2, 2 }, // different chosen filaments -> separate + { 2, 2, 1 }, // same chosen filament -> merged + { 0, 2, 2 }, // default and chosen -> separate + })); + DYNAMIC_SECTION("brim filaments " << first_filament << " and " << second_filament) { + TriangleMesh a = cube(20); + a.translate(80, 80, 0); + TriangleMesh b = cube(20); + b.translate(80 + 20 + 5, 80, 0); // 5 mm apart, so the 5 mm brims touch + std::vector meshes; + meshes.push_back(std::move(a)); + meshes.push_back(std::move(b)); + const std::vector> overrides { + { { "brim_filament_id", first_filament } }, + { { "brim_filament_id", second_filament } }, + }; + Print print; + Model model; + init_print(std::move(meshes), print, model, multifilament_config(2, { + { "skirt_loops", 0 }, + { "brim_type", "outer_only" }, + { "brim_width", 5 }, + { "combine_brims", 1 }, + }), &overrides, /*arrange=*/false); + print.process(); + CHECK(brim_count(print) == expected_brims); + } +} + TEST_CASE("Object brims are generated per instance", "[SkirtBrim]") { Print print;