diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 83f4e4464f..94c192ec66 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -3643,6 +3643,36 @@ bool ModelInstance::intersects_bed_exclude_region(const BedExcludeRegion ®ion return intersects; } +bool ModelInstance::intersects_bed_exclude_regions( + const std::vector ®ions, + indexed_triangle_set *intersection_mesh) const +{ + if (intersection_mesh != nullptr) + intersection_mesh->clear(); + if (regions.empty()) + return false; + + const Polygon hull = const_cast(this)->convex_hull_2d(); + bool intersects = false; + for (const BedExcludeRegion ®ion : regions) { + if (intersection(Polygons{ region.polygon }, Polygons{ hull }).empty()) + continue; + + if (intersection_mesh == nullptr) { + if (intersects_bed_exclude_region(region)) + return true; + continue; + } + + indexed_triangle_set region_intersection; + if (intersects_bed_exclude_region(region, ®ion_intersection) && !region_intersection.empty()) { + intersects = true; + its_merge(*intersection_mesh, region_intersection); + } + } + return intersects; +} + //BBS: invalidate instance's convex_hull_2d void ModelInstance::invalidate_convex_hull_2d() { diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 2af1150e30..525eb820f1 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1367,6 +1367,7 @@ public: // BBS Polygon convex_hull_2d(); bool intersects_bed_exclude_region(const BedExcludeRegion ®ion, indexed_triangle_set *intersection_mesh = nullptr) const; + bool intersects_bed_exclude_regions(const std::vector ®ions, indexed_triangle_set *intersection_mesh = nullptr) const; void invalidate_convex_hull_2d(); // Getting the input polygon for arrange diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 0f5b30fb59..e98e459162 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1440,7 +1440,7 @@ static std::vector s_Preset_machine_limits_options { static std::vector s_Preset_printer_options { "printer_technology", "printable_area", "extruder_printable_area", "support_parallel_printheads", "parallel_printheads_count", "parallel_printheads_bed_exclude_areas", - "bed_exclude_area", "bed_custom_texture", "bed_custom_model", "gcode_flavor", + "bed_exclude_area_mode", "bed_exclude_area", "extruder_bed_exclude_area", "bed_custom_texture", "bed_custom_model", "gcode_flavor", "gcode_skip_config_block", "fan_kickstart", "part_cooling_fan_min_pwm", "fan_speedup_time", "fan_speedup_overhangs", "single_extruder_multi_material", "manual_filament_change", "file_start_gcode", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "printing_by_object_gcode", "layer_change_gcode", "time_lapse_gcode", "wrapping_detection_gcode", "change_filament_gcode", "change_extrusion_role_gcode", "printer_model", "printer_variant", "printer_extruder_id", "printer_extruder_variant", "extruder_variant_list", "default_nozzle_volume_type", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index bd953f1929..d4a421303f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -77,21 +78,42 @@ static std::vector translated_bed_exclusion_volumes(const Prin return regions; } -static bool intersects_bed_exclusion_volume(const ModelInstance &instance, const std::vector ®ions) +static std::vector> translated_bed_exclusion_volumes_by_extruder(const Print &print) { - if (regions.empty()) - return false; + std::vector> regions_by_extruder = get_bed_excluded_regions_by_extruder(print.config()); + const Point print_origin(scale_(print.get_plate_origin().x()), scale_(print.get_plate_origin().y())); + for (std::vector ®ions : regions_by_extruder) + for (BedExcludeRegion ®ion : regions) + region.polygon.translate(print_origin); + return regions_by_extruder; +} - Polygon hull = const_cast(instance).convex_hull_2d(); - for (const BedExcludeRegion ®ion : regions) { - if (intersection(Polygons{ region.polygon }, Polygons{ hull }).empty()) - continue; +static std::optional colliding_bed_exclusion_extruder( + const Print &print, + const PrintObject &print_object, + const ModelInstance &instance, + const std::vector> ®ions_by_extruder) +{ + if (regions_by_extruder.empty()) + return std::nullopt; - if (instance.intersects_bed_exclude_region(region)) - return true; + if (is_auto_filament_map_mode(print.get_filament_map_mode())) { + std::optional first_collision; + for (size_t extruder_id = 0; extruder_id < regions_by_extruder.size(); ++extruder_id) { + if (!instance.intersects_bed_exclude_regions(regions_by_extruder[extruder_id])) + return std::nullopt; + if (!first_collision.has_value()) + first_collision = extruder_id; + } + return first_collision; } - return false; + for (const unsigned int filament_id : print_object.printing_extruders()) { + const size_t extruder_id = std::min(print.get_extruder_id(filament_id), regions_by_extruder.size() - 1); + if (instance.intersects_bed_exclude_regions(regions_by_extruder[extruder_id])) + return extruder_id; + } + return std::nullopt; } static Polygons full_height_bed_exclusion_polygons(const std::vector ®ions) @@ -154,7 +176,10 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "max_travel_detour_distance", "printable_area", //BBS: add bed_exclude_area + "bed_exclude_area_mode", "bed_exclude_area", + "extruder_bed_exclude_area", + "extruder_offset", "thumbnail_size", "before_layer_change_gcode", "enable_pressure_advance", @@ -686,7 +711,7 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print StringObjectException single_object_exception; const auto& print_config = print.config(); const Vec3d print_origin = print.get_plate_origin(); - const std::vector exclusion_volumes = translated_bed_exclusion_volumes(print); + const std::vector> exclusion_volumes = translated_bed_exclusion_volumes_by_extruder(print); struct print_instance_info { @@ -737,15 +762,20 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print // Convert the shift from the PrintObject's coordinates into ModelObject's coordinates by removing the centering offset. convex_hull.translate(instance.shift - print_object->center_offset()); } - if (intersects_bed_exclusion_volume(*instance.model_instance, exclusion_volumes)) { + const std::optional collision_extruder = colliding_bed_exclusion_extruder( + print, *print_object, *instance.model_instance, exclusion_volumes); + if (collision_extruder.has_value()) { + const std::string collision_message = is_auto_filament_map_mode(print.get_filament_map_mode()) ? + (boost::format(L("%1% intersects exclusion volumes for every available extruder.")) % instance.model_instance->get_object()->name).str() : + (boost::format(L("%1% intersects an exclusion volume for extruder %2%.")) % instance.model_instance->get_object()->name % (*collision_extruder + 1)).str(); if (single_object_exception.string.empty()) { - single_object_exception.string = (boost::format(L("%1% is too close to exclusion volume, there may be collisions when printing.")) %instance.model_instance->get_object()->name).str(); + single_object_exception.string = collision_message; // single_object_exception.object = instance.model_instance->get_object(); //ORCA: Pass ModelInstance instead of ModelObject single_object_exception.object = instance.model_instance; } else { - single_object_exception.string += "\n" + (boost::format(L("%1% is too close to exclusion volume, there may be collisions when printing.")) % instance.model_instance->get_object()->name).str(); + single_object_exception.string += "\n" + collision_message; single_object_exception.object = nullptr; } } @@ -1001,8 +1031,8 @@ static StringObjectException layered_print_cleareance_valid(const Print &print, const auto& print_config = print.config(); const Vec3d print_origin = print.get_plate_origin(); - const std::vector exclusion_volumes = translated_bed_exclusion_volumes(print); - const Polygons prime_tower_exclude_polys = full_height_bed_exclusion_polygons(exclusion_volumes); + const std::vector> exclusion_volumes = translated_bed_exclusion_volumes_by_extruder(print); + const Polygons prime_tower_exclude_polys = full_height_bed_exclusion_polygons(translated_bed_exclusion_volumes(print)); Pointfs wrapping_detection_area = print_config.wrapping_exclude_area.values; Polygon wrapping_poly; @@ -1031,8 +1061,13 @@ static StringObjectException layered_print_cleareance_valid(const Print &print, } current_instance_hulls.emplace_back(volume_hull); } - if (intersects_bed_exclusion_volume(*inst->model_instance, exclusion_volumes)) - return {inst->model_instance->get_object()->name + L(" is too close to exclusion volume, there may be collisions when printing.") + "\n", inst->model_instance}; + if (const std::optional collision_extruder = colliding_bed_exclusion_extruder( + print, *inst->print_object, *inst->model_instance, exclusion_volumes); collision_extruder.has_value()) { + const std::string message = is_auto_filament_map_mode(print.get_filament_map_mode()) ? + (boost::format(L("%1% intersects exclusion volumes for every available extruder.")) % inst->model_instance->get_object()->name).str() : + (boost::format(L("%1% intersects an exclusion volume for extruder %2%.")) % inst->model_instance->get_object()->name % (*collision_extruder + 1)).str(); + return {message + "\n", inst->model_instance}; + } if (!intersection(convex_hulls_other, current_instance_hulls).empty()) { if (warning) { diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 9822c5520c..4d01e64580 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -460,6 +460,7 @@ public: // returns 0-based indices of extruders used to print the object (without brim, support and other helper extrusions) std::vector object_extruders() const; + std::vector printing_extruders() const; // Called by make_perimeters() void slice(); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index be7bbac24e..039efbae04 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -9,6 +9,7 @@ #include "GCode/Thumbnails.hpp" #include +#include #include #include #include @@ -640,6 +641,13 @@ static const t_config_enum_values s_keys_map_FilamentMapMode = { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(FilamentMapMode) +static const t_config_enum_values s_keys_map_BedExcludeAreaMode = { + { "shared", int(BedExcludeAreaMode::Shared) }, + { "toolhead_offset", int(BedExcludeAreaMode::ToolheadOffset) }, + { "per_extruder", int(BedExcludeAreaMode::PerExtruder) } +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedExcludeAreaMode) + // PrimeVolumeMode. Serialized string keys must stay stable; they round-trip through .3mf. static const t_config_enum_values s_keys_map_PrimeVolumeMode = { { "Default", pvmDefault }, @@ -874,6 +882,15 @@ void PrintConfigDef::init_common_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionStrings()); + def = this->add("bed_exclude_area_mode", coEnum); + def->label = L("Exclusion volume behaviour"); + def->tooltip = L("Choose whether all nozzles use the same exclusion volumes, derive toolhead-relative volumes from each nozzle's XY offset, or configure independent volumes for every extruder."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values = { "shared", "toolhead_offset", "per_extruder" }; + def->enum_labels = { L("Shared"), L("Toolhead-relative (nozzle offsets)"), L("Individual per extruder") }; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionEnum(BedExcludeAreaMode::Shared)); + //BBS: add "bed_exclude_area" def = this->add("bed_exclude_area", coPoints); def->label = L("Excluded bed area"); @@ -885,6 +902,13 @@ void PrintConfigDef::init_common_params() def->gui_type = ConfigOptionDef::GUIType::one_string; def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) }); + def = this->add("extruder_bed_exclude_area", coStrings); + def->label = L("Extruder exclusion volumes"); + def->tooltip = L("Exclusion volumes used only by this extruder in individual mode. Use the same polygon and optional Z-range format as the shared excluded bed area. Leave empty for no exclusion volumes on this extruder."); + def->mode = comAdvanced; + def->gui_type = ConfigOptionDef::GUIType::one_string; + def->set_default_value(new ConfigOptionStrings{ "" }); + def = this->add("bed_custom_texture", coString); def->label = L("Bed custom texture"); def->mode = comAdvanced; @@ -8212,6 +8236,7 @@ void PrintConfigDef::init_extruder_option_keys() "default_filament_profile", "default_nozzle_volume_type", "deretraction_speed", + "extruder_bed_exclude_area", "extruder_colour", "extruder_offset", "extruder_printable_height", @@ -9382,6 +9407,7 @@ std::set printer_extruder_options = { "nozzle_diameter", "default_nozzle_volume_type", "extruder_printable_area", + "extruder_bed_exclude_area", "extruder_printable_height", "min_layer_height", "max_layer_height", @@ -11550,6 +11576,23 @@ std::map validate(const FullPrintConfig &cfg, bool und break; } + if (cfg.bed_exclude_area_mode.value == BedExcludeAreaMode::ToolheadOffset && + cfg.extruder_offset.size() < cfg.nozzle_diameter.size()) { + error_message.emplace("extruder_offset", L("A nozzle offset is required for every extruder when toolhead-relative exclusion volumes are enabled.")); + } + if (cfg.bed_exclude_area_mode.value == BedExcludeAreaMode::PerExtruder) { + if (cfg.extruder_bed_exclude_area.size() < cfg.nozzle_diameter.size()) { + error_message.emplace("extruder_bed_exclude_area", L("An exclusion-volume entry is required for every extruder. An entry may be empty when that extruder has no exclusion volumes.")); + } else { + for (const std::string &entry : cfg.extruder_bed_exclude_area.values) { + if (!is_valid_bed_exclude_area_string(entry, cfg.printable_height.value)) { + error_message.emplace("extruder_bed_exclude_area", L("Invalid per-extruder exclusion volume definition.")); + break; + } + } + } + } + // --perimeters if (cfg.wall_loops.value < 0) { error_message.emplace("wall_loops", L("invalid value ") + std::to_string(cfg.wall_loops.value)); @@ -12894,30 +12937,155 @@ static std::vector get_bed_excluded_regions_impl( return regions; } -} // namespace - -std::vector get_bed_excluded_regions(const DynamicPrintConfig& cfg) +static std::vector parse_master_bed_excluded_regions( + const ConfigOptionPoints *option, + const double printable_height) { - const ConfigOptionPoints *legacy = cfg.opt("bed_exclude_area"); - const ConfigOptionFloat *height = cfg.opt("printable_height"); - const std::string bed_exclude_area = legacy != nullptr ? legacy->serialize() : std::string{}; - const bool volume_syntax = is_bed_exclusion_volume_syntax(bed_exclude_area); + if (option == nullptr) + return {}; + const std::string serialized = option->serialize(); + const bool volume_syntax = is_bed_exclusion_volume_syntax(serialized); return get_bed_excluded_regions_impl( - volume_syntax || legacy == nullptr ? Pointfs{} : legacy->values, - volume_syntax ? bed_exclude_area : std::string{}, - height != nullptr ? height->value : 0.0); + volume_syntax ? Pointfs{} : option->values, + volume_syntax ? serialized : std::string{}, + printable_height); } -std::vector get_bed_excluded_regions(const PrintConfig& cfg) +static std::vector resolve_bed_excluded_regions( + const std::vector &master_regions, + const BedExcludeAreaMode mode, + const std::vector &per_extruder_specs, + const std::vector &extruder_offsets, + const size_t reference_extruder, + const size_t extruder_id, + const double printable_height) { - const std::string bed_exclude_area = cfg.bed_exclude_area.serialize(); - const bool volume_syntax = is_bed_exclusion_volume_syntax(bed_exclude_area); + if (mode == BedExcludeAreaMode::Shared) + return master_regions; - return get_bed_excluded_regions_impl( - volume_syntax ? Pointfs{} : cfg.bed_exclude_area.values, - volume_syntax ? bed_exclude_area : std::string{}, - cfg.printable_height.value); + if (mode == BedExcludeAreaMode::PerExtruder) { + if (extruder_id >= per_extruder_specs.size() || per_extruder_specs[extruder_id].empty()) + return {}; + + std::vector regions; + append_bed_exclusion_volume_regions(regions, per_extruder_specs[extruder_id], std::max(0.0, printable_height)); + return regions; + } + + std::vector regions = master_regions; + if (extruder_id >= extruder_offsets.size() || extruder_offsets.empty()) + return regions; + + const size_t clamped_reference = std::min(reference_extruder, extruder_offsets.size() - 1); + // A model-space point is emitted as model_position - extruder_offset. Therefore a + // carriage/toolhead obstacle described through the reference nozzle appears in another + // nozzle's model space translated by (other_offset - reference_offset). + const Vec2d delta = extruder_offsets[extruder_id] - extruder_offsets[clamped_reference]; + const Point translation(scale_(delta.x()), scale_(delta.y())); + for (BedExcludeRegion ®ion : regions) + region.polygon.translate(translation); + return regions; +} + +static size_t bed_exclusion_extruder_count( + const size_t nozzle_count, + const size_t offset_count, + const size_t per_extruder_count) +{ + return std::max(1, std::max({ nozzle_count, offset_count, per_extruder_count })); +} + +static std::vector flatten_bed_excluded_regions( + const BedExcludeAreaMode mode, + std::vector> regions_by_extruder) +{ + if (regions_by_extruder.empty()) + return {}; + if (mode == BedExcludeAreaMode::Shared) + return std::move(regions_by_extruder.front()); + + size_t total = 0; + for (const std::vector ®ions : regions_by_extruder) + total += regions.size(); + + std::vector flattened; + flattened.reserve(total); + for (std::vector ®ions : regions_by_extruder) + flattened.insert(flattened.end(), std::make_move_iterator(regions.begin()), std::make_move_iterator(regions.end())); + return flattened; +} + +} // namespace + +std::vector> get_bed_excluded_regions_by_extruder(const DynamicPrintConfig &cfg) +{ + const ConfigOptionFloat *height_option = cfg.opt("printable_height"); + const double printable_height = height_option != nullptr ? height_option->value : 0.0; + const std::vector master_regions = parse_master_bed_excluded_regions( + cfg.opt("bed_exclude_area"), printable_height); + + const ConfigOptionEnum *mode_option = cfg.opt>("bed_exclude_area_mode"); + const BedExcludeAreaMode mode = mode_option != nullptr ? mode_option->value : BedExcludeAreaMode::Shared; + const ConfigOptionStrings *per_extruder_option = cfg.opt("extruder_bed_exclude_area"); + const ConfigOptionPoints *offset_option = cfg.opt("extruder_offset"); + const ConfigOptionFloats *nozzle_option = cfg.opt("nozzle_diameter"); + const ConfigOptionInt *reference_option = cfg.opt("master_extruder_id"); + + const std::vector per_extruder_specs = per_extruder_option != nullptr ? per_extruder_option->values : std::vector{}; + const std::vector offsets = offset_option != nullptr ? offset_option->values : std::vector{}; + const size_t count = bed_exclusion_extruder_count( + nozzle_option != nullptr ? nozzle_option->size() : 0, + offsets.size(), per_extruder_specs.size()); + const size_t reference = reference_option != nullptr && reference_option->value > 0 ? size_t(reference_option->value - 1) : 0; + + std::vector> result; + result.reserve(count); + for (size_t extruder_id = 0; extruder_id < count; ++extruder_id) + result.emplace_back(resolve_bed_excluded_regions(master_regions, mode, per_extruder_specs, offsets, reference, extruder_id, printable_height)); + return result; +} + +std::vector> get_bed_excluded_regions_by_extruder(const PrintConfig &cfg) +{ + const double printable_height = cfg.printable_height.value; + const std::vector master_regions = parse_master_bed_excluded_regions(&cfg.bed_exclude_area, printable_height); + const size_t count = bed_exclusion_extruder_count( + cfg.nozzle_diameter.size(), cfg.extruder_offset.size(), cfg.extruder_bed_exclude_area.size()); + const size_t reference = cfg.master_extruder_id.value > 0 ? size_t(cfg.master_extruder_id.value - 1) : 0; + + std::vector> result; + result.reserve(count); + for (size_t extruder_id = 0; extruder_id < count; ++extruder_id) { + result.emplace_back(resolve_bed_excluded_regions( + master_regions, cfg.bed_exclude_area_mode.value, cfg.extruder_bed_exclude_area.values, + cfg.extruder_offset.values, reference, extruder_id, printable_height)); + } + return result; +} + +std::vector get_bed_excluded_regions(const DynamicPrintConfig &cfg, const size_t extruder_id) +{ + std::vector> regions = get_bed_excluded_regions_by_extruder(cfg); + return extruder_id < regions.size() ? std::move(regions[extruder_id]) : std::vector{}; +} + +std::vector get_bed_excluded_regions(const PrintConfig &cfg, const size_t extruder_id) +{ + std::vector> regions = get_bed_excluded_regions_by_extruder(cfg); + return extruder_id < regions.size() ? std::move(regions[extruder_id]) : std::vector{}; +} + +std::vector get_bed_excluded_regions(const DynamicPrintConfig &cfg) +{ + const ConfigOptionEnum *mode_option = cfg.opt>("bed_exclude_area_mode"); + const BedExcludeAreaMode mode = mode_option != nullptr ? mode_option->value : BedExcludeAreaMode::Shared; + return flatten_bed_excluded_regions(mode, get_bed_excluded_regions_by_extruder(cfg)); +} + +std::vector get_bed_excluded_regions(const PrintConfig &cfg) +{ + return flatten_bed_excluded_regions(cfg.bed_exclude_area_mode.value, get_bed_excluded_regions_by_extruder(cfg)); } bool has_bed_exclusion_volume_syntax(const ConfigOptionPoints& bed_exclude_area) @@ -12925,6 +13093,27 @@ bool has_bed_exclusion_volume_syntax(const ConfigOptionPoints& bed_exclude_area) return is_bed_exclusion_volume_syntax(bed_exclude_area.serialize()); } +bool is_valid_bed_exclude_area_string(const std::string &value, const double printable_height) +{ + if (value.empty()) + return true; + + std::vector specs; + boost::split(specs, value, boost::is_any_of("|\n")); + bool found_nonempty = false; + for (std::string spec : specs) { + boost::trim(spec); + if (spec.empty()) + continue; + found_nonempty = true; + std::vector parsed; + append_bed_exclusion_volume_regions(parsed, spec, std::max(0.0, printable_height)); + if (parsed.size() != 1) + return false; + } + return found_nonempty; +} + Polygons get_bed_excluded_area(const PrintConfig& cfg) { const std::vector regions = get_bed_excluded_regions(cfg); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 2a1a8063de..758399af31 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -530,6 +530,14 @@ enum FilamentMapMode { fmmDefault }; +// Defines how bed exclusion volumes are resolved for printers with multiple +// independently positioned nozzles/toolheads. +enum class BedExcludeAreaMode { + Shared = 0, + ToolheadOffset, + PerExtruder +}; + // All auto modes are ordered before fmmManual (see the enum ordering note above). inline bool is_auto_filament_map_mode(FilamentMapMode mode) { return mode < fmmManual; @@ -1757,7 +1765,9 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionInt, parallel_printheads_count)) ((ConfigOptionStrings, parallel_printheads_bed_exclude_areas)) //BBS: add bed_exclude_area + ((ConfigOptionEnum, bed_exclude_area_mode)) ((ConfigOptionPoints, bed_exclude_area)) + ((ConfigOptionStrings, extruder_bed_exclude_area)) ((ConfigOptionPoints, head_wrap_detect_zone)) // BBS ((ConfigOptionString, bed_custom_texture)) @@ -2312,7 +2322,12 @@ struct BedExcludeRegion { }; std::vector get_bed_excluded_regions(const DynamicPrintConfig& cfg); std::vector get_bed_excluded_regions(const PrintConfig& cfg); +std::vector get_bed_excluded_regions(const DynamicPrintConfig &cfg, size_t extruder_id); +std::vector get_bed_excluded_regions(const PrintConfig &cfg, size_t extruder_id); +std::vector> get_bed_excluded_regions_by_extruder(const DynamicPrintConfig &cfg); +std::vector> get_bed_excluded_regions_by_extruder(const PrintConfig &cfg); bool has_bed_exclusion_volume_syntax(const ConfigOptionPoints& bed_exclude_area); +bool is_valid_bed_exclude_area_string(const std::string &value, double printable_height); Slic3r::Polygons get_bed_excluded_area(const PrintConfig& cfg); Slic3r::Polygon get_bed_shape_with_excluded_area(const PrintConfig& cfg, bool use_share = false); bool has_skirt(const DynamicPrintConfig& cfg); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 54378b3b16..8d94eae593 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -308,6 +308,23 @@ std::vector> PrintObject::detect_extruder_geometric_unprintables() std::vector> geometric_unprintables(extruder_size); // the container to return + std::vector> exclusion_regions = get_bed_excluded_regions_by_extruder(m_print->config()); + exclusion_regions.resize(extruder_size); + const Point plate_origin(scale_(m_print->get_plate_origin().x()), scale_(m_print->get_plate_origin().y())); + for (std::vector ®ions : exclusion_regions) + for (BedExcludeRegion ®ion : regions) + region.polygon.translate(plate_origin); + + const std::vector used_filaments = printing_extruders(); + for (size_t extruder_id = 0; extruder_id < exclusion_regions.size(); ++extruder_id) { + const bool collision = std::any_of(m_instances.begin(), m_instances.end(), [&](const PrintInstance &instance) { + return instance.model_instance != nullptr && + instance.model_instance->intersects_bed_exclude_regions(exclusion_regions[extruder_id]); + }); + if (collision) + geometric_unprintables[extruder_id].insert(used_filaments.begin(), used_filaments.end()); + } + std::vector printable_height_per_extruder = m_print->config().extruder_printable_height.values; assert(printable_height_per_extruder.size() == extruder_size); @@ -4042,6 +4059,24 @@ std::vector PrintObject::object_extruders() const return extruders; } +std::vector PrintObject::printing_extruders() const +{ + std::vector extruders = object_extruders(); + 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 (extruders.empty()) + extruders.emplace_back(0); + sort_remove_duplicates(extruders); + return extruders; +} + bool PrintObject::update_layer_height_profile(const ModelObject &model_object, const SlicingParameters &slicing_parameters, std::vector &layer_height_profile) { bool updated = false; diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 412df19091..c9255da2b2 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -2637,7 +2637,8 @@ ConfigWizard::ConfigWizard(wxWindow *parent) p->load_vendors(); //BBS: add bed exclude areas p->custom_config.reset(DynamicPrintConfig::new_from_defaults_keys({ - "gcode_flavor", "printable_area", "bed_exclude_area", "bed_custom_texture", "bed_custom_model", "nozzle_diameter", "filament_diameter", "thumbnails" + "gcode_flavor", "printable_area", "bed_exclude_area_mode", "bed_exclude_area", "extruder_bed_exclude_area", + "bed_custom_texture", "bed_custom_model", "nozzle_diameter", "filament_diameter", "thumbnails" //, "nozzle_temperature", "bed_temperature" })); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 68a4b87ddd..a4146f33a0 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -683,6 +684,14 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true m_value = into_u8(str); } break; + } else if (m_opt.opt_key == "extruder_bed_exclude_area") { + const std::string definition = into_u8(str); + if (!is_valid_bed_exclude_area_string(definition, std::numeric_limits::max())) { + show_error(m_parent, _L("Invalid exclusion volume format. Use XxY, XxY, ... or ZMIN..ZMAX;XxY, XxY, ... and separate multiple volumes with |.")); + const std::string old_value = m_value.empty() ? std::string{} : boost::any_cast(m_value); + set_value(from_u8(old_value), true); + break; + } } else if (m_opt.opt_key == "extra_solid_infills") { string ustr(str.utf8_string()); // New rule: accept either interval form (N or N#K) or explicit list (e.g. 1,7,9), with optional quotes. diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 363bf982df..404352747c 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1213,14 +1213,31 @@ void PartPlate::update_exclusion_volume_preview_models() m_exclusion_volume_preview_cache_key.clear(); m_exclusion_volume_floor_triangles.reset(); m_exclusion_volume_border_triangles.reset(); + m_extruder_exclusion_volume_borders.clear(); m_active_exclusion_volume_prisms.reset(); m_exclusion_volume_intersection_triangles.reset(); m_exclusion_volume_intersections_cleared = false; return; } + const std::vector> regions_by_extruder = get_bed_excluded_regions_by_extruder(*config); std::vector regions = get_bed_excluded_regions(*config); - const std::string cache_key = exclusion_volume_preview_cache_key(regions); + const BedExcludeAreaMode mode = config->opt_enum("bed_exclude_area_mode"); + std::ostringstream grouped_key; + grouped_key << exclusion_volume_preview_cache_key(regions) << "mode:" << int(mode) << ";groups:"; + for (const std::vector &group : regions_by_extruder) + grouped_key << group.size() << ','; + const std::vector filament_colors = m_plater->get_extruder_colors_from_plater_config(); + std::vector preview_colors(regions_by_extruder.size()); + const ConfigOptionInts *filament_map = wxGetApp().preset_bundle->project_config.opt("filament_map"); + for (size_t filament_id = 0; filament_id < filament_colors.size(); ++filament_id) { + const int mapped_extruder = filament_map != nullptr && filament_id < filament_map->size() ? filament_map->values[filament_id] - 1 : int(filament_id); + if (mapped_extruder >= 0 && size_t(mapped_extruder) < preview_colors.size() && preview_colors[mapped_extruder].empty()) + preview_colors[mapped_extruder] = filament_colors[filament_id]; + } + for (const std::string &color : preview_colors) + grouped_key << color << ','; + const std::string cache_key = grouped_key.str(); if (cache_key == m_exclusion_volume_preview_cache_key && !m_exclusion_volume_intersections_cleared) return; m_exclusion_volume_preview_cache_key = cache_key; @@ -1228,6 +1245,7 @@ void PartPlate::update_exclusion_volume_preview_models() m_exclusion_volume_floor_triangles.reset(); m_exclusion_volume_border_triangles.reset(); + m_extruder_exclusion_volume_borders.clear(); m_active_exclusion_volume_prisms.reset(); m_exclusion_volume_intersection_triangles.reset(); @@ -1239,6 +1257,37 @@ void PartPlate::update_exclusion_volume_preview_models() Polygons preview_footprints; std::vector active_prisms; + if (mode != BedExcludeAreaMode::Shared) { + static const std::array fallback_colors = { + ColorRGBA{ .18f, .52f, .95f, .92f }, ColorRGBA{ .95f, .35f, .22f, .92f }, + ColorRGBA{ .25f, .72f, .38f, .92f }, ColorRGBA{ .72f, .34f, .88f, .92f }, + ColorRGBA{ .95f, .68f, .16f, .92f }, ColorRGBA{ .18f, .76f, .78f, .92f } + }; + const coord_t tool_border_width = scale_(0.55); + for (size_t extruder_id = 0; extruder_id < regions_by_extruder.size(); ++extruder_id) { + ColorRGBA color = fallback_colors[extruder_id % fallback_colors.size()]; + if (extruder_id < preview_colors.size()) { + ColorRGBA decoded; + if (decode_color(preview_colors[extruder_id], decoded)) { + color = decoded; + color.a(0.92f); + } + } + + for (const BedExcludeRegion ®ion_src : regions_by_extruder[extruder_id]) { + Polygon footprint = region_src.polygon; + footprint.translate(plate_offset); + footprint.make_counter_clockwise(); + const Polygons inner = offset(Polygons{ footprint }, -tool_border_width, jtMiter, 2.0); + const ExPolygons border = inner.empty() ? ExPolygons{ expolygon_from_polygon(footprint) } : diff_ex(Polygons{ footprint }, inner); + auto model = std::make_unique(); + const float border_z = static_cast(std::max(GROUND_Z + 0.026, region_src.has_z_range ? region_src.z_min + 0.026 : GROUND_Z + 0.026)); + if (init_model_from_expolygons(*model, border, border_z) && model->is_initialized()) + m_extruder_exclusion_volume_borders.emplace_back(std::move(model), color); + } + } + } + for (const BedExcludeRegion ®ion_src : regions) { Polygon region = region_src.polygon; region.translate(plate_offset); @@ -1336,6 +1385,11 @@ void PartPlate::render_exclusion_volume_previews(bool force_default_color) m_exclusion_volume_border_triangles.set_color(ribbon_color); m_exclusion_volume_border_triangles.render(); + for (auto &colored_border : m_extruder_exclusion_volume_borders) { + colored_border.first->set_color(colored_border.second); + colored_border.first->render(); + } + m_active_exclusion_volume_prisms.set_color(prism_color); m_active_exclusion_volume_prisms.render(); diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index a533191860..28fae20668 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "libslic3r/ObjectID.hpp" #include "libslic3r/GCode/GCodeProcessor.hpp" @@ -136,6 +137,7 @@ private: GLModel m_wrapping_detection_triangles; GLModel m_exclusion_volume_floor_triangles; GLModel m_exclusion_volume_border_triangles; + std::vector, ColorRGBA>> m_extruder_exclusion_volume_borders; GLModel m_active_exclusion_volume_prisms; GLModel m_exclusion_volume_intersection_triangles; std::string m_exclusion_volume_preview_cache_key; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e1fa2b5004..02565296fe 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7331,7 +7331,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) , main_frame(main_frame) //BBS: add bed_exclude_area , config(Slic3r::DynamicPrintConfig::new_from_defaults_keys({ - "printable_area", "bed_exclude_area", "wrapping_exclude_area", "extruder_printable_area", "bed_custom_texture", "bed_custom_model", "print_sequence", + "printable_area", "bed_exclude_area_mode", "bed_exclude_area", "extruder_bed_exclude_area", "extruder_offset", + "wrapping_exclude_area", "extruder_printable_area", "bed_custom_texture", "bed_custom_model", "print_sequence", "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", @@ -20090,7 +20091,8 @@ void Plater::on_config_change(const DynamicPrintConfig &config) p->partplate_list.invalid_all_slice_result(); } //BBS: add bed_exclude_area - else if (opt_key == "printable_area" || opt_key == "bed_exclude_area" + else if (opt_key == "printable_area" || opt_key == "bed_exclude_area_mode" || opt_key == "bed_exclude_area" + || opt_key == "extruder_bed_exclude_area" || opt_key == "extruder_offset" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model" || opt_key == "extruder_clearance_height_to_lid" || opt_key == "extruder_clearance_height_to_rod") { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 914e4cc7bb..fdaadda0fd 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -32,6 +32,7 @@ #include "wxExtensions.hpp" #include "PresetComboBoxes.hpp" #include +#include #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" @@ -1826,6 +1827,26 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) printer_tab->on_gcode_flavor_changed(); } + if (opt_key == "bed_exclude_area_mode" && m_type == Preset::TYPE_PRINTER && + m_config->opt_enum("bed_exclude_area_mode") == BedExcludeAreaMode::PerExtruder) { + auto *per_extruder = m_config->option("extruder_bed_exclude_area"); + const auto *shared = m_config->option("bed_exclude_area"); + const size_t extruder_count = m_config->option("nozzle_diameter")->size(); + const bool definitions_empty = per_extruder == nullptr || + std::all_of(per_extruder->values.begin(), per_extruder->values.end(), [](const std::string &entry) { return entry.empty(); }); + + if (definitions_empty && shared != nullptr && extruder_count > 0) { + const std::string serialized = shared->serialize(); + const bool valid_shared_definition = shared->values.size() >= 3 || + (has_bed_exclusion_volume_syntax(*shared) && + is_valid_bed_exclude_area_string(serialized, std::numeric_limits::max())); + DynamicPrintConfig new_conf = *m_config; + new_conf.set_key_value("extruder_bed_exclude_area", + new ConfigOptionStrings(std::vector(extruder_count, valid_shared_definition ? serialized : std::string{}))); + m_config_manipulation.apply(m_config, &new_conf); + } + } + if (opt_key == "compatible_prints") this->compatible_widget_reload(m_compatible_prints); if (opt_key == "compatible_printers") @@ -5002,6 +5023,7 @@ void TabPrinter::build_fff() return create_bed_shape_widget(parent); }); optgroup->append_single_option_line("parallel_printheads_count"); + optgroup->append_single_option_line("bed_exclude_area_mode"); Option option = optgroup->get_option("bed_exclude_area"); option.opt.full_width = true; optgroup->append_single_option_line(option, "printer_basic_information_printable_space#excluded-bed-area"); @@ -5638,6 +5660,10 @@ if (is_marlin_flavor) option.opt.full_width = true; optgroup->append_single_option_line(option, "printer_extruder_basic_information#extruder-offset-position"); + Option exclusion_option = optgroup->get_option("extruder_bed_exclude_area", extruder_idx); + exclusion_option.opt.full_width = true; + optgroup->append_single_option_line(exclusion_option, "printer_basic_information_printable_space#excluded-bed-area"); + optgroup->m_on_change = [this, extruder_idx](const t_config_option_key& opt_key, boost::any value) { bool is_SEMM = m_config->opt_bool("single_extruder_multi_material"); @@ -6065,6 +6091,11 @@ void TabPrinter::toggle_options() const bool support_parallel_printheads = printer_cfg.opt_bool("support_parallel_printheads"); toggle_line("parallel_printheads_count", support_parallel_printheads); + const size_t exclusion_extruder_count = m_preset_bundle->get_printer_extruder_count(); + const BedExcludeAreaMode exclusion_mode = m_config->opt_enum("bed_exclude_area_mode"); + toggle_line("bed_exclude_area_mode", exclusion_extruder_count > 1); + toggle_line("bed_exclude_area", exclusion_extruder_count <= 1 || exclusion_mode != BedExcludeAreaMode::PerExtruder); + toggle_line("fan_direction", m_config->opt_bool("auxiliary_fan")); // The cooling filter and air filtration are alternative accessories: show only the one the printer supports. @@ -6122,6 +6153,8 @@ void TabPrinter::toggle_options() toggle_option("extruder_printable_area", false, i); // disable toggle_line("extruder_printable_area", m_preset_bundle->get_printer_extruder_count() == 2, i); //hide + const bool per_extruder_exclusions = m_config->opt_enum("bed_exclude_area_mode") == BedExcludeAreaMode::PerExtruder; + toggle_line("extruder_bed_exclude_area", m_preset_bundle->get_printer_extruder_count() > 1 && per_extruder_exclusions, i); toggle_option("extruder_printable_height", false, i); toggle_line("extruder_printable_height", m_preset_bundle->get_printer_extruder_count() == 2, i); diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index 6bff945fc3..9ef63dff02 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -119,6 +119,23 @@ size_t count_opt_key(const std::vector& warnings, const s [&](const StringObjectException& w) { return w.opt_key == key; }); } +DynamicPrintConfig dual_extruder_exclusion_config(FilamentMapMode map_mode, int mapped_extruder) +{ + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_num_extruders(2); + config.set_key_value("nozzle_diameter", new ConfigOptionFloats{ 0.4, 0.4 }); + config.set_key_value("extruder_offset", new ConfigOptionPoints{ Vec2d::Zero(), Vec2d(20.0, 0.0) }); + config.set_key_value("extruder_printable_height", new ConfigOptionFloatsNullable{ 256.0, 256.0 }); + config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::PerExtruder)); + config.set_key_value("extruder_bed_exclude_area", new ConfigOptionStrings{ + "0..256;-100x-100,300x-100,300x300,-100x300", + "" + }); + config.set_key_value("filament_map_mode", new ConfigOptionEnum(map_mode)); + config.set_key_value("filament_map", new ConfigOptionInts{ mapped_extruder }); + return config; +} + // Make `default_acceleration` exceed the machine's extruding-acceleration limit. void trigger_acceleration_warning(DynamicPrintConfig& c) { @@ -145,6 +162,26 @@ void trigger_precise_wall_warning(DynamicPrintConfig& c) } // namespace +TEST_CASE("Print validation applies exclusion volumes to the relevant extruder", "[Print][BedExclude][MultiNozzle]") +{ + std::vector warnings; + + SECTION("manual mapping rejects the colliding extruder") { + const StringObjectException error = validate_cubes(dual_extruder_exclusion_config(fmmManual, 1), warnings); + CHECK(error.string.find("extruder 1") != std::string::npos); + } + + SECTION("manual mapping accepts a clear extruder") { + const StringObjectException error = validate_cubes(dual_extruder_exclusion_config(fmmManual, 2), warnings); + CHECK(error.string.empty()); + } + + SECTION("automatic mapping remains valid when at least one extruder is clear") { + const StringObjectException error = validate_cubes(dual_extruder_exclusion_config(fmmAutoForMatch, 1), warnings); + CHECK(error.string.empty()); + } +} + // --------------------------------------------------------------------------- // {first_object_name} filename placeholder // --------------------------------------------------------------------------- diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt index 2f859f46fe..187bb8e019 100644 --- a/tests/libslic3r/CMakeLists.txt +++ b/tests/libslic3r/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(${_TEST_NAME}_tests test_arrange.cpp test_bambu_networking.cpp test_buildvolume.cpp + test_bed_exclude_regions.cpp test_calib.cpp test_clipper_offset.cpp test_clipper_utils.cpp diff --git a/tests/libslic3r/test_bed_exclude_regions.cpp b/tests/libslic3r/test_bed_exclude_regions.cpp new file mode 100644 index 0000000000..ff61f404d4 --- /dev/null +++ b/tests/libslic3r/test_bed_exclude_regions.cpp @@ -0,0 +1,93 @@ +#include + +#include "libslic3r/PrintConfig.hpp" + +using namespace Slic3r; + +namespace { + +DynamicPrintConfig two_extruder_config() +{ + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_key_value("nozzle_diameter", new ConfigOptionFloats{ 0.4, 0.4 }); + config.set_key_value("extruder_offset", new ConfigOptionPoints{ Vec2d(0.0, 0.0), Vec2d(20.0, 5.0) }); + config.set_key_value("master_extruder_id", new ConfigOptionInt(1)); + config.set_key_value("printable_height", new ConfigOptionFloat(200.0)); + config.set_deserialize_strict("bed_exclude_area", "10..30;0x0,10x0,10x10,0x10"); + return config; +} + +BoundingBox region_bounds(const BedExcludeRegion ®ion) +{ + return get_extents(region.polygon); +} + +} // namespace + +TEST_CASE("Shared exclusion volumes resolve identically for every extruder", "[PrintConfig][BedExclude]") +{ + DynamicPrintConfig config = two_extruder_config(); + config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::Shared)); + + const auto groups = get_bed_excluded_regions_by_extruder(config); + REQUIRE(groups.size() == 2); + REQUIRE(groups[0].size() == 1); + REQUIRE(groups[1].size() == 1); + CHECK(groups[0][0].polygon.points == groups[1][0].polygon.points); + CHECK(groups[0][0].z_min == Catch::Approx(10.0)); + CHECK(groups[0][0].z_max == Catch::Approx(30.0)); + + // The global compatibility view returns a shared definition only once. + CHECK(get_bed_excluded_regions(config).size() == 1); +} + +TEST_CASE("Toolhead-relative exclusion volumes follow nozzle offset deltas", "[PrintConfig][BedExclude]") +{ + DynamicPrintConfig config = two_extruder_config(); + config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::ToolheadOffset)); + + const auto groups = get_bed_excluded_regions_by_extruder(config); + REQUIRE(groups.size() == 2); + REQUIRE(groups[0].size() == 1); + REQUIRE(groups[1].size() == 1); + + const BoundingBox reference = region_bounds(groups[0][0]); + const BoundingBox offset = region_bounds(groups[1][0]); + CHECK(unscale(offset.min.x() - reference.min.x()) == Catch::Approx(20.0)); + CHECK(unscale(offset.min.y() - reference.min.y()) == Catch::Approx(5.0)); + CHECK(groups[1][0].z_min == Catch::Approx(groups[0][0].z_min)); + CHECK(groups[1][0].z_max == Catch::Approx(groups[0][0].z_max)); +} + +TEST_CASE("Individual exclusion volumes are authoritative per extruder", "[PrintConfig][BedExclude]") +{ + DynamicPrintConfig config = two_extruder_config(); + config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::PerExtruder)); + config.set_key_value("extruder_bed_exclude_area", new ConfigOptionStrings{ + "0..25;0x0,8x0,8x8,0x8|40..60;20x20,30x20,30x30,20x30", + "" + }); + + const auto groups = get_bed_excluded_regions_by_extruder(config); + REQUIRE(groups.size() == 2); + CHECK(groups[0].size() == 2); + CHECK(groups[1].empty()); + CHECK(groups[0][0].z_min == Catch::Approx(0.0)); + CHECK(groups[0][0].z_max == Catch::Approx(25.0)); + CHECK(groups[0][1].z_min == Catch::Approx(40.0)); + CHECK(groups[0][1].z_max == Catch::Approx(60.0)); +} + +TEST_CASE("Offset mode honours a non-zero reference extruder", "[PrintConfig][BedExclude]") +{ + DynamicPrintConfig config = two_extruder_config(); + config.set_key_value("master_extruder_id", new ConfigOptionInt(2)); + config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::ToolheadOffset)); + + const auto groups = get_bed_excluded_regions_by_extruder(config); + REQUIRE(groups.size() == 2); + const BoundingBox first = region_bounds(groups[0][0]); + const BoundingBox reference = region_bounds(groups[1][0]); + CHECK(unscale(first.min.x() - reference.min.x()) == Catch::Approx(-20.0)); + CHECK(unscale(first.min.y() - reference.min.y()) == Catch::Approx(-5.0)); +}