diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 5bbade3561..743644f82e 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -122,7 +122,7 @@ using namespace Slic3r; static Pointfs legacy_bed_exclude_area_points(const DynamicPrintConfig &config) { const ConfigOptionPoints *option = config.option("bed_exclude_area"); - return option != nullptr && !has_bed_exclusion_volume_syntax(*option) ? option->values : Pointfs{}; + return option != nullptr && !has_bed_exclude_volumes(config) ? option->values : Pointfs{}; } std::map cli_errors = { diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 4129b7838c..e4c3f4d1b0 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1547,34 +1547,14 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoints(*this); } ConfigOptionPoints& operator= (const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoints &rhs) const throw() { return this->values == rhs.values && m_serialized_override == rhs.m_serialized_override; } - bool operator==(const ConfigOption &rhs) const override - { - if (rhs.type() != this->type()) - throw ConfigurationError("ConfigOptionPoints: Comparing incompatible types"); - assert(dynamic_cast(&rhs)); - const ConfigOptionPoints *other = static_cast(&rhs); - return this->values == other->values && m_serialized_override == other->m_serialized_override; - } + using ConfigOptionVector::operator==; + bool operator==(const ConfigOptionPoints &rhs) const throw() { return this->values == rhs.values; } bool operator< (const ConfigOptionPoints &rhs) const throw() { return std::lexicographical_compare(this->values.begin(), this->values.end(), rhs.values.begin(), rhs.values.end(), [](const auto &l, const auto &r){ return l < r; }); } bool is_nil(size_t) const override { return false; } - void set(const ConfigOption *rhs) override - { - if (rhs->type() != this->type()) - throw ConfigurationError("ConfigOptionPoints: Assigning an incompatible type"); - assert(dynamic_cast(rhs)); - const ConfigOptionPoints *other = static_cast(rhs); - this->values = other->values; - m_serialized_override = other->m_serialized_override; - } - std::string serialize() const override { - if (! m_serialized_override.empty()) - return m_serialized_override; - std::ostringstream ss; for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) { if (it - this->values.begin() != 0) ss << ","; @@ -1587,9 +1567,6 @@ public: std::vector vserialize() const override { - if (! m_serialized_override.empty()) - return { m_serialized_override }; - std::vector vv; for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) { std::ostringstream ss; @@ -1605,24 +1582,13 @@ public: bool deserialize(const std::string &str, bool append = false) override { - if (! append) { - this->values.clear(); - m_serialized_override.clear(); - } - - const bool has_extended_bed_exclusion_syntax = str.find('|') != std::string::npos || (str.find("..") != std::string::npos && str.find(';') != std::string::npos); - if (has_extended_bed_exclusion_syntax && append) + // Extended exclusion-volume syntax belongs to the dedicated string option. + // Rejecting it here also makes --bed-exclude-area fail instead of silently + // turning a volume definition into malformed legacy points. + if (str.find('|') != std::string::npos || str.find(';') != std::string::npos || str.find("..") != std::string::npos) return false; - - if (has_extended_bed_exclusion_syntax) { - m_serialized_override = str; - // Multiple independent polygons have no valid representation in - // the legacy flat point array. Keep the serialized definition as - // the sole source of truth so old consumers cannot mistake their - // concatenated vertices for one polygon. - return true; - } - + if (! append) + this->values.clear(); std::istringstream is(str); std::string point_str; while (std::getline(is, point_str, ',')) { @@ -1640,45 +1606,21 @@ public: return true; } - size_t hash() const throw() override - { - size_t seed = 0; - std::hash point_hasher; - std::hash string_hasher; - for (const Vec2d &point : this->values) - boost::hash_combine(seed, point_hasher(point)); - boost::hash_combine(seed, string_hasher(m_serialized_override)); - return seed; - } - private: - std::string m_serialized_override; - friend class cereal::access; - template void save(Archive& archive, const std::uint32_t /* version */) const { + template void save(Archive& archive) const { size_t cnt = this->values.size(); archive(cnt); archive.saveBinary((const char*)this->values.data(), sizeof(Vec2d) * cnt); - archive(m_serialized_override); } - template void load(Archive& archive, const std::uint32_t version) { + template void load(Archive& archive) { size_t cnt; archive(cnt); this->values.assign(cnt, Vec2d()); archive.loadBinary((char*)this->values.data(), sizeof(Vec2d) * cnt); - if (version >= 1) - archive(m_serialized_override); - else - m_serialized_override.clear(); } }; -} // namespace Slic3r - -CEREAL_CLASS_VERSION(Slic3r::ConfigOptionPoints, 1); - -namespace Slic3r { - class ConfigOptionPoint3 : public ConfigOptionSingle { public: diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fbdef80299..b084000e5d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -294,10 +294,7 @@ static std::vector get_path_of_change_filament(const Print& print) Vec2d end_point = points[1]; // the cutter area size(18, 28) - if (has_bed_exclusion_volume_syntax(print.config().bed_exclude_area)) - return out_points; - - Pointfs excluse_area = print.config().bed_exclude_area.values; + Pointfs excluse_area = has_bed_exclude_volumes(print.config()) ? Pointfs{} : print.config().bed_exclude_area.values; if (excluse_area.size() != 4) return out_points; diff --git a/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp b/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp index f2f3bb9cbe..c795c5808c 100644 --- a/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp +++ b/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp @@ -114,7 +114,10 @@ void ExclusionVolumePathChecker::configure(const PrintConfig &config) std::vector &prepared = m_regions_by_extruder[extruder_id]; prepared.reserve(regions[extruder_id].size()); for (const BedExcludeRegion ®ion : regions[extruder_id]) { - if (region.polygon.points.size() < 3 || region.z_max < region.z_min) + // Legacy excluded areas are material keep-outs. Some stock profiles + // deliberately move the nozzle into them (for example, a cutter), so + // only explicitly configured collision volumes constrain motion. + if (!region.is_collision_volume() || region.polygon.points.size() < 3 || region.z_max < region.z_min) continue; PreparedRegion item; diff --git a/src/libslic3r/GCode/ExclusionVolumeTravelAvoidance.cpp b/src/libslic3r/GCode/ExclusionVolumeTravelAvoidance.cpp index 5fb7ca6b8b..3b001a12d7 100644 --- a/src/libslic3r/GCode/ExclusionVolumeTravelAvoidance.cpp +++ b/src/libslic3r/GCode/ExclusionVolumeTravelAvoidance.cpp @@ -410,6 +410,8 @@ void ExclusionVolumeTravelAvoidance::init(const PrintConfig &config, const Vec3d for (size_t extruder_id = 0; extruder_id < regions_by_extruder.size(); ++extruder_id) { RoutingSpace &space = m_spaces[extruder_id]; space.regions = std::move(regions_by_extruder[extruder_id]); + space.regions.erase(std::remove_if(space.regions.begin(), space.regions.end(), + [](const BedExcludeRegion ®ion) { return !region.is_collision_volume(); }), space.regions.end()); const Vec2d extruder_offset = extruder_id < config.extruder_offset.values.size() ? config.extruder_offset.values[extruder_id] : Vec2d::Zero(); diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index eb05146892..e2dbcb99b6 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include #include #include @@ -3176,7 +3178,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) //BBS: add bed_exclude_area const ConfigOptionPoints* bed_exclude_area = config.option("bed_exclude_area"); - if (bed_exclude_area != nullptr && !has_bed_exclusion_volume_syntax(*bed_exclude_area)) + if (bed_exclude_area != nullptr && !has_bed_exclude_volumes(config)) m_result.bed_exclude_area = bed_exclude_area->values; const ConfigOptionPoints* wrapping_exclude_area = config.option("wrapping_exclude_area"); @@ -6115,22 +6117,56 @@ void GCodeProcessor::process_G23(const GCodeReader::GCodeLine& line) store_move_vertex(EMoveType::Unretract); } +static std::array g28_homed_axes(const GCodeReader::GCodeLine &line) +{ + std::array homed { false, false, false }; + std::string_view raw = line.raw(); + const size_t command_end = raw.find_first_of(" \t;"); + size_t pos = command_end == std::string_view::npos ? raw.size() : command_end; + + while (pos < raw.size()) { + pos = raw.find_first_not_of(" \t", pos); + if (pos == std::string_view::npos || raw[pos] == ';') + break; + const size_t end = raw.find_first_of(" \t;", pos); + const std::string_view word = raw.substr(pos, end == std::string_view::npos ? raw.size() - pos : end - pos); + + const bool compact_axes = !word.empty() && std::all_of(word.begin(), word.end(), [](const char c) { + const char upper = static_cast(std::toupper(static_cast(c))); + return upper == 'X' || upper == 'Y' || upper == 'Z'; + }); + if (compact_axes) { + for (const char c : word) + homed[static_cast(std::toupper(static_cast(c)) - 'X')] = true; + } else if (!word.empty()) { + const char axis = static_cast(std::toupper(static_cast(word.front()))); + const bool numeric_axis_word = word.size() > 1 && + (std::isdigit(static_cast(word[1])) || word[1] == '+' || word[1] == '-' || word[1] == '.'); + if (axis >= 'X' && axis <= 'Z' && numeric_axis_word) + homed[static_cast(axis - 'X')] = true; + } + + if (end == std::string_view::npos || raw[end] == ';') + break; + pos = end; + } + return homed; +} + void GCodeProcessor::process_G28(const GCodeReader::GCodeLine& line) { std::string_view cmd = line.cmd(); std::string new_line_raw = { cmd.data(), cmd.size() }; - bool found = false; - if (line.has('X')) { + const std::array homed = g28_homed_axes(line); + const bool found = std::any_of(homed.begin(), homed.end(), [](const bool value) { return value; }); + if (homed[X]) { new_line_raw += " X0"; - found = true; } - if (line.has('Y')) { + if (homed[Y]) { new_line_raw += " Y0"; - found = true; } - if (line.has('Z')) { + if (homed[Z]) { new_line_raw += " Z0"; - found = true; } if (!found) new_line_raw += " X0 Y0 Z0"; @@ -6146,7 +6182,7 @@ void GCodeProcessor::process_G28(const GCodeReader::GCodeLine& line) // zero. Wait for a subsequent explicit absolute coordinate before checking // a path from any homed axis. for (unsigned char axis = X; axis <= Z; ++axis) { - if (!found || line.has(static_cast(axis))) { + if (!found || homed[axis]) { m_axis_position_known[axis] = false; m_axis_origin_known[axis] = true; } diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 9c9dbd76e3..b0d96428d9 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -3105,7 +3105,7 @@ void Model::setPrintSpeedTable(const DynamicPrintConfig& config, const PrintConf //auto print_config = print.config(); //printSpeedMap.bed_poly.points = get_bed_shape(*(wxGetApp().plater()->config())); printSpeedMap.bed_poly.points = get_bed_shape(config); - Pointfs excluse_area_points = has_bed_exclusion_volume_syntax(print_config.bed_exclude_area) ? Pointfs{} : print_config.bed_exclude_area.values; + Pointfs excluse_area_points = has_bed_exclude_volumes(print_config) ? Pointfs{} : print_config.bed_exclude_area.values; Polygons exclude_polys; Polygon exclude_poly; for (int i = 0; i < excluse_area_points.size(); i++) { diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index e98e459162..e578a3e840 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_mode", "bed_exclude_area", "extruder_bed_exclude_area", "bed_custom_texture", "bed_custom_model", "gcode_flavor", + "bed_exclude_area", "bed_exclude_volumes", "bed_exclude_volume_mode", "extruder_bed_exclude_volumes", "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 cb6b28eebc..d11defb03b 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -187,11 +187,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "reduce_crossing_wall", "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", @@ -215,7 +210,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "extruder_clearance_radius", "nozzle_height", "extruder_colour", - "extruder_offset", "filament_flow_ratio", "reduce_fan_stop_start_freq", "dont_slow_down_outer_wall", @@ -337,13 +331,27 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n }; static std::unordered_set steps_ignore; + static const std::unordered_set steps_exclusion_geometry = { + "bed_exclude_area", + "bed_exclude_volumes", + "bed_exclude_volume_mode", + "extruder_bed_exclude_volumes", + "extruder_offset" + }; std::vector steps; std::vector osteps; bool invalidated = false; for (const t_config_option_key &opt_key : opt_keys) { - if (steps_gcode.find(opt_key) != steps_gcode.end()) { + if (steps_exclusion_geometry.find(opt_key) != steps_exclusion_geometry.end()) { + // Exclusions are consumed while generating brims, support, tree + // support and wipe-tower geometry, not only during final export. + steps.emplace_back(psWipeTower); + steps.emplace_back(psSkirtBrim); + osteps.emplace_back(posSupportMaterial); + osteps.emplace_back(posSimplifySupportPath); + } else if (steps_gcode.find(opt_key) != steps_gcode.end()) { // These options only affect G-code export or they are just notes without influence on the generated G-code, // so there is nothing to invalidate. steps.emplace_back(psGCodeExport); @@ -3298,7 +3306,7 @@ void Print::_make_skirt() brim_exclusion_regions.begin(), brim_exclusion_regions.end(), [](const std::vector ®ions) { return !regions.empty(); }); const bool has_nozzle_specific_brim_exclusions = has_brim_exclusions && - m_config.bed_exclude_area_mode.value != BedExcludeAreaMode::Shared; + active_bed_exclude_volume_mode(m_config) != BedExcludeVolumeMode::Shared; auto make_brims_for_skirt_brim_group = [this, &brim_exclusion_regions, has_nozzle_specific_brim_exclusions] diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index a5a8076a1a..a4ab2e0127 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -9,6 +9,8 @@ #include "GCode/Thumbnails.hpp" #include +#include +#include #include #include #include @@ -641,12 +643,12 @@ 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) } +static const t_config_enum_values s_keys_map_BedExcludeVolumeMode = { + { "shared", int(BedExcludeVolumeMode::Shared) }, + { "toolhead_offset", int(BedExcludeVolumeMode::ToolheadOffset) }, + { "per_extruder", int(BedExcludeVolumeMode::PerExtruder) } }; -CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedExcludeAreaMode) +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedExcludeVolumeMode) // PrimeVolumeMode. Serialized string keys must stay stable; they round-trip through .3mf. static const t_config_enum_values s_keys_map_PrimeVolumeMode = { @@ -882,29 +884,37 @@ 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"); + def->label = L("Excluded bed area (legacy)"); def->tooltip = L("Unprintable area in XY plane. For example, X1 Series printers use the front left corner to cut filament during filament change. " - "The area is expressed as polygon by points in following format: \"XxY, XxY, ...\". " - "Use \"ZMIN..ZMAX;XxY, XxY, ...\" for a 3D Z-limited exclusion volume. " - "Separate multiple areas or volumes with \"|\". "); + "The area is expressed as a polygon in the format \"XxY, XxY, ...\". Legacy areas keep generated material and models out, " + "but do not check or reroute machine travel. Configure exclusion volumes below for full collision checking."); def->mode = comAdvanced; 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 = this->add("bed_exclude_volumes", coString); + def->label = L("Exclusion volumes"); + def->tooltip = L("Collision volumes used for model and generated-material exclusion, G-code checking, and travel avoidance. " + "Use \"XxY, XxY, ...\" for a full-height polygon or \"ZMIN..ZMAX;XxY, XxY, ...\" for a Z-limited volume. " + "Separate multiple volumes with \"|\". When configured, these volumes take precedence over the legacy excluded bed area."); + def->mode = comAdvanced; + def->gui_type = ConfigOptionDef::GUIType::one_string; + def->set_default_value(new ConfigOptionString()); + + def = this->add("bed_exclude_volume_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(BedExcludeVolumeMode::Shared)); + + def = this->add("extruder_bed_exclude_volumes", 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->tooltip = L("Collision volumes used only by this extruder in individual mode. Use the same polygon and optional Z-range format as the shared exclusion volumes. 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{ "" }); @@ -8236,7 +8246,7 @@ void PrintConfigDef::init_extruder_option_keys() "default_filament_profile", "default_nozzle_volume_type", "deretraction_speed", - "extruder_bed_exclude_area", + "extruder_bed_exclude_volumes", "extruder_colour", "extruder_offset", "extruder_printable_height", @@ -9407,7 +9417,7 @@ std::set printer_extruder_options = { "nozzle_diameter", "default_nozzle_volume_type", "extruder_printable_area", - "extruder_bed_exclude_area", + "extruder_bed_exclude_volumes", "extruder_printable_height", "min_layer_height", "max_layer_height", @@ -11576,17 +11586,23 @@ std::map validate(const FullPrintConfig &cfg, bool und break; } - if (cfg.bed_exclude_area_mode.value == BedExcludeAreaMode::ToolheadOffset && + const bool collision_volumes_enabled = has_bed_exclude_volumes(cfg); + if (cfg.bed_exclude_volume_mode.value != BedExcludeVolumeMode::PerExtruder && + !cfg.bed_exclude_volumes.value.empty() && + !is_valid_bed_exclude_volumes_string(cfg.bed_exclude_volumes.value, cfg.printable_height.value)) { + error_message.emplace("bed_exclude_volumes", L("Invalid exclusion volume definition.")); + } + if (collision_volumes_enabled && cfg.bed_exclude_volume_mode.value == BedExcludeVolumeMode::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.")); + if (collision_volumes_enabled && cfg.bed_exclude_volume_mode.value == BedExcludeVolumeMode::PerExtruder) { + if (cfg.extruder_bed_exclude_volumes.size() < cfg.nozzle_diameter.size()) { + error_message.emplace("extruder_bed_exclude_volumes", 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.")); + for (const std::string &entry : cfg.extruder_bed_exclude_volumes.values) { + if (!is_valid_bed_exclude_volumes_string(entry, cfg.printable_height.value)) { + error_message.emplace("extruder_bed_exclude_volumes", L("Invalid per-extruder exclusion volume definition.")); break; } } @@ -12775,7 +12791,7 @@ Points get_bed_shape(const SLAPrinterConfig &cfg) { return to_points(make_counte namespace { -static bool is_bed_exclusion_volume_syntax(const std::string &value) +static bool looks_like_bed_exclusion_volume_syntax(const std::string &value) { return value.find('|') != std::string::npos || (value.find("..") != std::string::npos && value.find(';') != std::string::npos); } @@ -12832,14 +12848,33 @@ static bool parse_z_range_token( static std::optional parse_exclude_polygon_points(const std::string &points_str) { - ConfigOptionPoints points; - if (! points.deserialize(points_str) || points.values.size() < 3) + Pointfs points; + std::vector point_tokens; + boost::split(point_tokens, points_str, boost::is_any_of(",")); + points.reserve(point_tokens.size()); + for (std::string point_token : point_tokens) { + boost::trim(point_token); + const size_t separator = point_token.find('x'); + if (separator == std::string::npos || point_token.find('x', separator + 1) != std::string::npos) + return std::nullopt; + + double x = 0.0; + double y = 0.0; + if (!parse_double_token(point_token.substr(0, separator), x) || + !parse_double_token(point_token.substr(separator + 1), y) || + !std::isfinite(x) || !std::isfinite(y)) + return std::nullopt; + points.emplace_back(x, y); + } + if (points.size() < 3) return std::nullopt; Polygon polygon; - polygon.points.reserve(points.values.size()); - for (const Vec2d &pt : points.values) + polygon.points.reserve(points.size()); + for (const Vec2d &pt : points) polygon.points.emplace_back(scale_(pt.x()), scale_(pt.y())); + if (polygon.area() == 0.0) + return std::nullopt; polygon.make_counter_clockwise(); return polygon; } @@ -12858,7 +12893,8 @@ static void append_legacy_bed_exclude_regions( polygon.points.emplace_back(scale_(pt.x()), scale_(pt.y())); polygon.make_counter_clockwise(); - out.push_back({ std::move(polygon), 0.0, printable_height, false, false }); + out.push_back({ std::move(polygon), 0.0, printable_height, + BedExcludeRegion::Purpose::MaterialKeepout, false }); } static void append_bed_exclusion_volume_regions( @@ -12921,50 +12957,54 @@ static void append_bed_exclusion_volume_regions( if (! polygon) continue; - out.push_back({ std::move(*polygon), z_min, z_max, true, has_z_range }); + out.push_back({ std::move(*polygon), z_min, z_max, + BedExcludeRegion::Purpose::CollisionVolume, has_z_range }); } } -static std::vector get_bed_excluded_regions_impl( +static bool has_nonempty_string(const std::string &value) +{ + return std::any_of(value.begin(), value.end(), [](const char c) { return !std::isspace(static_cast(c)); }); +} + +static bool collision_volumes_configured( + const std::string &shared_specs, + const BedExcludeVolumeMode mode, + const std::vector &per_extruder_specs) +{ + if (mode == BedExcludeVolumeMode::PerExtruder) + return std::any_of(per_extruder_specs.begin(), per_extruder_specs.end(), has_nonempty_string); + return has_nonempty_string(shared_specs); +} + +static std::vector parse_master_bed_excluded_regions( const Pointfs &legacy_points, - const std::string ®ion_specs, + const std::string &shared_specs, + const bool use_collision_volumes, const double printable_height) { std::vector regions; const double height = std::max(0.0, printable_height); - append_legacy_bed_exclude_regions(regions, legacy_points, height); - append_bed_exclusion_volume_regions(regions, region_specs, height); + if (use_collision_volumes) + append_bed_exclusion_volume_regions(regions, shared_specs, height); + else + append_legacy_bed_exclude_regions(regions, legacy_points, height); return regions; } -static std::vector parse_master_bed_excluded_regions( - const ConfigOptionPoints *option, - const double printable_height) -{ - 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 ? Pointfs{} : option->values, - volume_syntax ? serialized : std::string{}, - printable_height); -} - static std::vector resolve_bed_excluded_regions( const std::vector &master_regions, - const BedExcludeAreaMode mode, + const BedExcludeVolumeMode 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) { - if (mode == BedExcludeAreaMode::Shared) + if (mode == BedExcludeVolumeMode::Shared) return master_regions; - if (mode == BedExcludeAreaMode::PerExtruder) { + if (mode == BedExcludeVolumeMode::PerExtruder) { if (extruder_id >= per_extruder_specs.size() || per_extruder_specs[extruder_id].empty()) return {}; @@ -12997,12 +13037,12 @@ static size_t bed_exclusion_extruder_count( } static std::vector flatten_bed_excluded_regions( - const BedExcludeAreaMode mode, + const BedExcludeVolumeMode mode, std::vector> regions_by_extruder) { if (regions_by_extruder.empty()) return {}; - if (mode == BedExcludeAreaMode::Shared) + if (mode == BedExcludeVolumeMode::Shared) return std::move(regions_by_extruder.front()); size_t total = 0; @@ -13046,17 +13086,22 @@ std::vector> get_bed_excluded_regions_by_extruder( { 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 BedExcludeAreaMode mode = cfg.has("bed_exclude_area_mode") ? - cfg.opt_enum("bed_exclude_area_mode") : BedExcludeAreaMode::Shared; - const ConfigOptionStrings *per_extruder_option = cfg.opt("extruder_bed_exclude_area"); + const ConfigOptionPoints *legacy_option = cfg.opt("bed_exclude_area"); + const ConfigOptionString *shared_option = cfg.opt("bed_exclude_volumes"); + const BedExcludeVolumeMode configured_mode = cfg.has("bed_exclude_volume_mode") ? + cfg.opt_enum("bed_exclude_volume_mode") : BedExcludeVolumeMode::Shared; + const ConfigOptionStrings *per_extruder_option = cfg.opt("extruder_bed_exclude_volumes"); 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 Pointfs legacy_points = legacy_option != nullptr ? legacy_option->values : Pointfs{}; + const std::string shared_specs = shared_option != nullptr ? shared_option->value : std::string{}; const std::vector per_extruder_specs = per_extruder_option != nullptr ? per_extruder_option->values : std::vector{}; + const bool use_collision_volumes = collision_volumes_configured(shared_specs, configured_mode, per_extruder_specs); + const BedExcludeVolumeMode active_mode = use_collision_volumes ? configured_mode : BedExcludeVolumeMode::Shared; + const std::vector master_regions = parse_master_bed_excluded_regions( + legacy_points, shared_specs, use_collision_volumes, printable_height); 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, @@ -13066,23 +13111,29 @@ std::vector> get_bed_excluded_regions_by_extruder( 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)); + result.emplace_back(resolve_bed_excluded_regions(master_regions, active_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 bool use_collision_volumes = collision_volumes_configured( + cfg.bed_exclude_volumes.value, cfg.bed_exclude_volume_mode.value, + cfg.extruder_bed_exclude_volumes.values); + const BedExcludeVolumeMode active_mode = use_collision_volumes ? + cfg.bed_exclude_volume_mode.value : BedExcludeVolumeMode::Shared; + const std::vector master_regions = parse_master_bed_excluded_regions( + cfg.bed_exclude_area.values, cfg.bed_exclude_volumes.value, use_collision_volumes, printable_height); const size_t count = bed_exclusion_extruder_count( - cfg.nozzle_diameter.size(), cfg.extruder_offset.size(), cfg.extruder_bed_exclude_area.size()); + cfg.nozzle_diameter.size(), cfg.extruder_offset.size(), cfg.extruder_bed_exclude_volumes.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, + master_regions, active_mode, cfg.extruder_bed_exclude_volumes.values, cfg.extruder_offset.values, reference, extruder_id, printable_height)); } return result; @@ -13102,22 +13153,20 @@ std::vector get_bed_excluded_regions(const PrintConfig &cfg, c std::vector get_bed_excluded_regions(const DynamicPrintConfig &cfg) { - const BedExcludeAreaMode mode = cfg.has("bed_exclude_area_mode") ? - cfg.opt_enum("bed_exclude_area_mode") : BedExcludeAreaMode::Shared; - return flatten_bed_excluded_regions(mode, get_bed_excluded_regions_by_extruder(cfg)); + return flatten_bed_excluded_regions(active_bed_exclude_volume_mode(cfg), 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)); + return flatten_bed_excluded_regions(active_bed_exclude_volume_mode(cfg), get_bed_excluded_regions_by_extruder(cfg)); } -bool has_bed_exclusion_volume_syntax(const ConfigOptionPoints& bed_exclude_area) +bool is_bed_exclusion_volume_syntax(const std::string &value) { - return is_bed_exclusion_volume_syntax(bed_exclude_area.serialize()); + return looks_like_bed_exclusion_volume_syntax(value); } -bool is_valid_bed_exclude_area_string(const std::string &value, const double printable_height) +bool is_valid_bed_exclude_volumes_string(const std::string &value, const double printable_height) { if (value.empty()) return true; @@ -13138,6 +13187,36 @@ bool is_valid_bed_exclude_area_string(const std::string &value, const double pri return found_nonempty; } +bool has_bed_exclude_volumes(const DynamicPrintConfig &cfg) +{ + const ConfigOptionString *shared = cfg.opt("bed_exclude_volumes"); + const ConfigOptionStrings *per_extruder = cfg.opt("extruder_bed_exclude_volumes"); + const BedExcludeVolumeMode mode = cfg.has("bed_exclude_volume_mode") ? + cfg.opt_enum("bed_exclude_volume_mode") : BedExcludeVolumeMode::Shared; + return collision_volumes_configured( + shared != nullptr ? shared->value : std::string{}, mode, + per_extruder != nullptr ? per_extruder->values : std::vector{}); +} + +bool has_bed_exclude_volumes(const PrintConfig &cfg) +{ + return collision_volumes_configured( + cfg.bed_exclude_volumes.value, cfg.bed_exclude_volume_mode.value, + cfg.extruder_bed_exclude_volumes.values); +} + +BedExcludeVolumeMode active_bed_exclude_volume_mode(const DynamicPrintConfig &cfg) +{ + if (!has_bed_exclude_volumes(cfg) || !cfg.has("bed_exclude_volume_mode")) + return BedExcludeVolumeMode::Shared; + return cfg.opt_enum("bed_exclude_volume_mode"); +} + +BedExcludeVolumeMode active_bed_exclude_volume_mode(const PrintConfig &cfg) +{ + return has_bed_exclude_volumes(cfg) ? cfg.bed_exclude_volume_mode.value : BedExcludeVolumeMode::Shared; +} + 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 109d1544ad..fd2fcf692e 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -532,7 +532,7 @@ enum FilamentMapMode { // Defines how bed exclusion volumes are resolved for printers with multiple // independently positioned nozzles/toolheads. -enum class BedExcludeAreaMode { +enum class BedExcludeVolumeMode { Shared = 0, ToolheadOffset, PerExtruder @@ -1765,9 +1765,10 @@ 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)) + ((ConfigOptionString, bed_exclude_volumes)) + ((ConfigOptionEnum, bed_exclude_volume_mode)) + ((ConfigOptionStrings, extruder_bed_exclude_volumes)) ((ConfigOptionPoints, head_wrap_detect_zone)) // BBS ((ConfigOptionString, bed_custom_texture)) @@ -2314,11 +2315,18 @@ Points get_bed_shape(const DynamicPrintConfig &cfg, bool use_share = true); Points get_bed_shape(const PrintConfig &cfg, bool use_share = false); Points get_bed_shape(const SLAPrinterConfig &cfg); struct BedExcludeRegion { + enum class Purpose { + MaterialKeepout, + CollisionVolume + }; + Polygon polygon; double z_min { 0.0 }; double z_max { 0.0 }; - bool from_3d_config { false }; + Purpose purpose { Purpose::MaterialKeepout }; bool has_z_range { false }; + + bool is_collision_volume() const { return purpose == Purpose::CollisionVolume; } }; std::vector get_bed_excluded_regions(const DynamicPrintConfig& cfg); std::vector get_bed_excluded_regions(const PrintConfig& cfg); @@ -2332,8 +2340,12 @@ std::vector> get_bed_excluded_regions_by_extruder( int bed_exclusion_extruder_for_filament(size_t filament_id, const std::vector &configured_map, FilamentMapMode map_mode, bool is_bambu, bool automatic_map_resolved, size_t extruder_count); -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); +bool is_bed_exclusion_volume_syntax(const std::string &value); +bool is_valid_bed_exclude_volumes_string(const std::string &value, double printable_height); +bool has_bed_exclude_volumes(const DynamicPrintConfig &cfg); +bool has_bed_exclude_volumes(const PrintConfig &cfg); +BedExcludeVolumeMode active_bed_exclude_volume_mode(const DynamicPrintConfig &cfg); +BedExcludeVolumeMode active_bed_exclude_volume_mode(const PrintConfig &cfg); 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/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index c9255da2b2..4ada874c41 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -2637,7 +2637,7 @@ 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_mode", "bed_exclude_area", "extruder_bed_exclude_area", + "gcode_flavor", "printable_area", "bed_exclude_area", "bed_exclude_volumes", "bed_exclude_volume_mode", "extruder_bed_exclude_volumes", "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 a4146f33a0..6282dee392 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -684,9 +684,9 @@ 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") { + } else if (m_opt.opt_key == "bed_exclude_volumes" || m_opt.opt_key == "extruder_bed_exclude_volumes") { const std::string definition = into_u8(str); - if (!is_valid_bed_exclude_area_string(definition, std::numeric_limits::max())) { + if (!is_valid_bed_exclude_volumes_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); @@ -784,7 +784,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true if (!m_value.empty() && boost::any_cast>(&m_value) != nullptr) text_value = get_thumbnails_string(boost::any_cast>(m_value)); set_value(text_value, true); - show_error(m_parent, format_wxstr(_L("Invalid format. Expected vector format: \"%1%\""), m_opt_id == "bed_exclude_area" ? "XxY, XxY, ... or ZMIN..ZMAX;XxY, XxY, ..." : "XxY, XxY, ...")); + show_error(m_parent, format_wxstr(_L("Invalid format. Expected vector format: \"%1%\""), "XxY, XxY, ...")); } } diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index df11be8563..4c0c1c0694 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -25,7 +25,7 @@ void set_arrange_polygon_bed_exclusion_extruders(ArrangePolygon &polygon, const const PartPlate &plate, const DynamicPrintConfig &config) { polygon.bed_exclusion_extruder_ids.clear(); - if (config.opt_enum("bed_exclude_area_mode") == BedExcludeAreaMode::Shared) + if (active_bed_exclude_volume_mode(config) == BedExcludeVolumeMode::Shared) return; const ConfigOptionFloats *nozzle_diameters = config.opt("nozzle_diameter"); @@ -57,7 +57,7 @@ static void set_arrange_polygon_bed_exclusion_extruders_for_all_plates(ArrangePo const DynamicPrintConfig &config) { polygon.bed_exclusion_extruder_ids.clear(); - if (config.opt_enum("bed_exclude_area_mode") == BedExcludeAreaMode::Shared) + if (active_bed_exclude_volume_mode(config) == BedExcludeVolumeMode::Shared) return; std::set extruder_ids; diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index c45c8e6e4c..719d7ac92a 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1093,7 +1093,7 @@ void PartPlate::render_exclude_area(bool force_default_color) { // the other extruders' regions hollow. const DynamicPrintConfig *config = m_plater != nullptr ? m_plater->config() : nullptr; if (config != nullptr && - config->opt_enum("bed_exclude_area_mode") != BedExcludeAreaMode::Shared) + active_bed_exclude_volume_mode(*config) != BedExcludeVolumeMode::Shared) return; ColorRGBA select_color{ .9f, .86f, .82f, .7f }; // ORCA @@ -1164,7 +1164,7 @@ std::string PartPlate::exclusion_volume_preview_cache_key(const std::vector regions; for (const std::vector &extruder_regions : regions_by_extruder) regions.insert(regions.end(), extruder_regions.begin(), extruder_regions.end()); - const BedExcludeAreaMode mode = config->opt_enum("bed_exclude_area_mode"); + const BedExcludeVolumeMode mode = active_bed_exclude_volume_mode(*config); // A coloured border communicates which physical nozzle owns a footprint. // With only one nozzle the exclusion applies to every filament, so using // the first filament colour would incorrectly imply material ownership. const bool show_nozzle_ownership = - regions_by_extruder.size() > 1 && mode != BedExcludeAreaMode::Shared; + regions_by_extruder.size() > 1 && mode != BedExcludeVolumeMode::Shared; std::ostringstream grouped_key; grouped_key << exclusion_volume_preview_cache_key(regions) << "mode:" << int(mode) << ";groups:"; for (const std::vector &group : regions_by_extruder) @@ -1345,7 +1345,7 @@ void PartPlate::update_exclusion_volume_preview_models() for (size_t extruder_id = 0; extruder_id < regions_by_extruder.size(); ++extruder_id) { // Shared regions are identical for every nozzle. Keeping one copy // avoids duplicate floor, prism and intersection geometry. - if (mode == BedExcludeAreaMode::Shared && extruder_id > 0) + if (mode == BedExcludeVolumeMode::Shared && extruder_id > 0) break; for (const BedExcludeRegion ®ion_src : regions_by_extruder[extruder_id]) { @@ -1360,7 +1360,7 @@ void PartPlate::update_exclusion_volume_preview_models() // In non-shared modes these resolved regions are the authoritative bed // preview, including legacy master polygons duplicated by nozzle offset. // Shared legacy polygons continue to use m_exclude_triangles above. - if (region_src.from_3d_config || mode != BedExcludeAreaMode::Shared) { + if (region_src.is_collision_volume() || mode != BedExcludeVolumeMode::Shared) { if (!region_src.has_z_range || region_src.z_min <= EPSILON) { floor_regions.emplace_back(region); } else { @@ -1400,7 +1400,7 @@ void PartPlate::update_exclusion_volume_preview_models() continue; std::set relevant_extruders; - if (mode != BedExcludeAreaMode::Shared) { + if (mode != BedExcludeVolumeMode::Shared) { for (const auto &mapping : get_object_filament_extruders( *object, project_config, regions_by_extruder.size())) relevant_extruders.emplace(mapping.second); @@ -1409,7 +1409,7 @@ void PartPlate::update_exclusion_volume_preview_models() Polygon hull = instance->convex_hull_2d(); const BoundingBoxf3 instance_box = object->instance_convex_hull_bounding_box(instance_id); for (const PreviewRegion &preview_region : preview_regions) { - if (mode != BedExcludeAreaMode::Shared && + if (mode != BedExcludeVolumeMode::Shared && relevant_extruders.find(preview_region.extruder_id) == relevant_extruders.end()) continue; @@ -3457,16 +3457,16 @@ bool PartPlate::check_outside(int obj_id, int instance_id, BoundingBoxf3* boundi if (config != nullptr) { const std::vector> regions_by_extruder = get_bed_excluded_regions_by_extruder(*config); - const BedExcludeAreaMode mode = config->opt_enum("bed_exclude_area_mode"); + const BedExcludeVolumeMode mode = active_bed_exclude_volume_mode(*config); // The legacy outside flag has no filament/nozzle context. Keep it // authoritative for the shared mode, but let the newer per-extruder // placement pipeline handle offset/individual modes so a collision // belonging to an unused nozzle does not block the whole plate. - checked_config_regions = mode != BedExcludeAreaMode::Shared; + checked_config_regions = mode != BedExcludeVolumeMode::Shared; const Point plate_offset(scale_(m_origin.x()), scale_(m_origin.y())); Polygon hull = instance->convex_hull_2d(); - const size_t groups_to_check = mode == BedExcludeAreaMode::Shared && !regions_by_extruder.empty() ? 1 : 0; + const size_t groups_to_check = mode == BedExcludeVolumeMode::Shared && !regions_by_extruder.empty() ? 1 : 0; for (size_t group_id = 0; group_id < groups_to_check; ++group_id) { const std::vector &extruder_regions = regions_by_extruder[group_id]; checked_config_regions = checked_config_regions || !extruder_regions.empty(); @@ -6492,15 +6492,13 @@ bool PartPlateList::preprocess_exclude_areas(arrangement::ArrangePolygons &unsel } added = true; } - const BedExcludeAreaMode mode = config.opt_enum("bed_exclude_area_mode"); - const ConfigOptionPoints *configured_areas = config.opt("bed_exclude_area"); - const bool use_resolved_regions = mode != BedExcludeAreaMode::Shared || - (configured_areas != nullptr && has_bed_exclusion_volume_syntax(*configured_areas)); + const BedExcludeVolumeMode mode = active_bed_exclude_volume_mode(config); + const bool use_resolved_regions = has_bed_exclude_volumes(config); if (use_resolved_regions) { const std::vector> regions_by_extruder = get_bed_excluded_regions_by_extruder(config); - const size_t extruder_count = mode == BedExcludeAreaMode::Shared ? + const size_t extruder_count = mode == BedExcludeVolumeMode::Shared ? std::min(1, regions_by_extruder.size()) : regions_by_extruder.size(); for (size_t extruder_id = 0; extruder_id < extruder_count; ++extruder_id) { @@ -6517,7 +6515,7 @@ bool PartPlateList::preprocess_exclude_areas(arrangement::ArrangePolygons &unsel blocker.rotation = 0.0; blocker.is_virt_object = true; blocker.is_bed_exclusion = true; - blocker.bed_exclusion_extruder_id = mode == BedExcludeAreaMode::Shared ? -1 : int(extruder_id); + blocker.bed_exclusion_extruder_id = mode == BedExcludeVolumeMode::Shared ? -1 : int(extruder_id); blocker.bed_idx = plate_idx; blocker.height = std::max(0.0, region.z_max - region.z_min); blocker.z_min = region.z_min; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7c52c7f81c..7fbc77193b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7331,7 +7331,7 @@ 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_mode", "bed_exclude_area", "extruder_bed_exclude_area", "extruder_offset", + "printable_area", "bed_exclude_area", "bed_exclude_volumes", "bed_exclude_volume_mode", "extruder_bed_exclude_volumes", "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", @@ -20082,8 +20082,8 @@ void Plater::on_config_change(const DynamicPrintConfig &config) } p->config->set_key_value(opt_key, config.option(opt_key)->clone()); - if (opt_key == "bed_exclude_area_mode" || opt_key == "bed_exclude_area" || - opt_key == "extruder_bed_exclude_area" || opt_key == "extruder_offset" || + if (opt_key == "bed_exclude_volume_mode" || opt_key == "bed_exclude_area" || + opt_key == "bed_exclude_volumes" || opt_key == "extruder_bed_exclude_volumes" || opt_key == "extruder_offset" || opt_key == "master_extruder_id" || opt_key == "nozzle_diameter" || opt_key == "printable_height" || opt_key == "extruder_colour") exclusion_preview_changed = true; @@ -20099,8 +20099,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_mode" || opt_key == "bed_exclude_area" - || opt_key == "extruder_bed_exclude_area" || opt_key == "extruder_offset" + else if (opt_key == "printable_area" || opt_key == "bed_exclude_volume_mode" || opt_key == "bed_exclude_area" + || opt_key == "bed_exclude_volumes" || opt_key == "extruder_bed_exclude_volumes" || 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") { @@ -20239,7 +20239,7 @@ void Plater::set_bed_shape() const const ConfigOptionPoints *bed_exclude_area = p->config->option("bed_exclude_area"); set_bed_shape(p->config->option("printable_area")->values, //BBS: add bed exclude areas - has_bed_exclusion_volume_syntax(*bed_exclude_area) ? Pointfs{} : bed_exclude_area->values, + has_bed_exclude_volumes(*p->config) ? Pointfs{} : bed_exclude_area->values, p->config->option("wrapping_exclude_area")->values, p->config->option("printable_height")->value, p->config->option("extruder_printable_area")->values, diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index fdaadda0fd..25bf93efea 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1805,6 +1805,54 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) return; } + // A legacy point option cannot represent multiple or Z-limited regions. If + // that syntax is pasted into the legacy field, offer an explicit, atomic + // conversion rather than silently changing its meaning based on syntax. + if (opt_key == "bed_exclude_area" && m_type == Preset::TYPE_PRINTER) { + const std::string *definition = boost::any_cast(&value); + if (definition != nullptr && is_bed_exclusion_volume_syntax(*definition)) { + const double printable_height = m_config->opt_float("printable_height"); + if (!is_valid_bed_exclude_volumes_string(*definition, printable_height)) { + show_error(wxGetApp().plater(), _L("Invalid exclusion volume format. Use XxY, XxY, ... or ZMIN..ZMAX;XxY, XxY, ... and separate multiple volumes with |.")); + reload_config(); + return; + } + + MessageDialog dialog( + wxGetApp().plater(), + _L("This definition contains collision-volume syntax. Convert it to exclusion volumes and enable G-code checking and travel avoidance?"), + _L("Convert exclusion volumes"), wxICON_QUESTION | wxYES | wxNO); + if (dialog.ShowModal() == wxID_YES) { + DynamicPrintConfig converted = *m_config; + converted.set_key_value("bed_exclude_volumes", new ConfigOptionString(*definition)); + converted.set_key_value("bed_exclude_volume_mode", + new ConfigOptionEnum(BedExcludeVolumeMode::Shared)); + converted.set_key_value("bed_exclude_area", new ConfigOptionPoints()); + load_config(converted); + on_presets_changed(); + wxGetApp().plater()->update(); + } else { + reload_config(); + } + return; + } + } + + // Editing the dedicated collision-volume fields is an explicit opt-in to + // the new behaviour. Keep presets unambiguous by removing any legacy area; + // the resolver still gives volumes precedence when externally authored + // profiles contain both keys. + if (m_type == Preset::TYPE_PRINTER && + (opt_key == "bed_exclude_volumes" || opt_key.rfind("extruder_bed_exclude_volumes#", 0) == 0)) { + const std::string *definition = boost::any_cast(&value); + const ConfigOptionPoints *legacy = m_config->option("bed_exclude_area"); + if (definition != nullptr && !definition->empty() && legacy != nullptr && !legacy->values.empty()) { + DynamicPrintConfig converted = *m_config; + converted.set_key_value("bed_exclude_area", new ConfigOptionPoints()); + m_config_manipulation.apply(m_config, &converted); + } + } + // Keep this preset's "plugins" manifest in sync when a plugin picker changes, so full_config() and // save_to_json() always find resolved "name;uuid;capability" references and rebuild it nowhere else. // Also drop any plugin config override entries for a capability the change just stopped @@ -1827,21 +1875,20 @@ 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"); + if (opt_key == "bed_exclude_volume_mode" && m_type == Preset::TYPE_PRINTER && + m_config->opt_enum("bed_exclude_volume_mode") == BedExcludeVolumeMode::PerExtruder) { + auto *per_extruder = m_config->option("extruder_bed_exclude_volumes"); + const auto *shared = m_config->option("bed_exclude_volumes"); 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())); + const std::string serialized = shared->value; + const bool valid_shared_definition = + is_valid_bed_exclude_volumes_string(serialized, std::numeric_limits::max()); DynamicPrintConfig new_conf = *m_config; - new_conf.set_key_value("extruder_bed_exclude_area", + new_conf.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings(std::vector(extruder_count, valid_shared_definition ? serialized : std::string{}))); m_config_manipulation.apply(m_config, &new_conf); } @@ -5023,10 +5070,44 @@ 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"); + Line convert_exclusion_line = Line{ L("Collision checking"), L("Convert the legacy excluded bed area into a collision volume so Orca can check G-code moves and reroute travel around it.") }; + convert_exclusion_line.widget = [this](wxWindow *parent) { + Button *button = new Button(parent, _L("Convert area to collision volume")); + button->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { + const ConfigOptionPoints *legacy = m_config->option("bed_exclude_area"); + if (legacy == nullptr || legacy->values.size() < 3) { + show_error(wxGetApp().plater(), _L("Configure a valid excluded bed area before converting it.")); + return; + } + + const std::string definition = legacy->serialize(); + MessageDialog dialog( + wxGetApp().plater(), + _L("Convert this legacy excluded bed area into a full-height collision volume? This enables G-code checking and travel avoidance."), + _L("Convert exclusion volume"), wxICON_QUESTION | wxYES | wxNO); + if (dialog.ShowModal() != wxID_YES) + return; + + DynamicPrintConfig converted = *m_config; + converted.set_key_value("bed_exclude_volumes", new ConfigOptionString(definition)); + converted.set_key_value("bed_exclude_volume_mode", + new ConfigOptionEnum(BedExcludeVolumeMode::Shared)); + converted.set_key_value("bed_exclude_area", new ConfigOptionPoints()); + load_config(converted); + on_presets_changed(); + wxGetApp().plater()->update(); + }); + return button; + }; + optgroup->append_line(convert_exclusion_line); + + Option volume_option = optgroup->get_option("bed_exclude_volumes"); + volume_option.opt.full_width = true; + optgroup->append_single_option_line(volume_option); + optgroup->append_single_option_line("bed_exclude_volume_mode"); // optgroup->append_single_option_line("printable_area"); optgroup->append_single_option_line("printable_height", "printer_basic_information_printable_space#printable-height"); optgroup->append_single_option_line("support_multi_bed_types","printer_basic_information_printable_space#support-multi-bed-types"); @@ -5660,7 +5741,7 @@ 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); + Option exclusion_option = optgroup->get_option("extruder_bed_exclude_volumes", extruder_idx); exclusion_option.opt.full_width = true; optgroup->append_single_option_line(exclusion_option, "printer_basic_information_printable_space#excluded-bed-area"); @@ -6092,9 +6173,11 @@ void TabPrinter::toggle_options() 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); + const bool collision_volumes_enabled = has_bed_exclude_volumes(*m_config); + const BedExcludeVolumeMode exclusion_mode = active_bed_exclude_volume_mode(*m_config); + toggle_option("bed_exclude_area", !collision_volumes_enabled); + toggle_line("bed_exclude_volume_mode", collision_volumes_enabled && exclusion_extruder_count > 1); + toggle_line("bed_exclude_volumes", exclusion_extruder_count <= 1 || exclusion_mode != BedExcludeVolumeMode::PerExtruder); toggle_line("fan_direction", m_config->opt_bool("auxiliary_fan")); @@ -6153,8 +6236,9 @@ 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); + const bool per_extruder_exclusions = has_bed_exclude_volumes(*m_config) && + active_bed_exclude_volume_mode(*m_config) == BedExcludeVolumeMode::PerExtruder; + toggle_line("extruder_bed_exclude_volumes", 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_exclusion_volumes.cpp b/tests/fff_print/test_exclusion_volumes.cpp index 981eeea6c4..83f43fe6b8 100644 --- a/tests/fff_print/test_exclusion_volumes.cpp +++ b/tests/fff_print/test_exclusion_volumes.cpp @@ -24,7 +24,7 @@ using Catch::Matchers::WithinAbs; namespace { DynamicPrintConfig exclusion_config( - BedExcludeAreaMode mode = BedExcludeAreaMode::Shared, + BedExcludeVolumeMode mode = BedExcludeVolumeMode::Shared, const std::string &shared = "0..10;40x40,60x40,60x60,40x60", const std::vector &per_extruder = {}) { @@ -38,10 +38,18 @@ DynamicPrintConfig exclusion_config( config.set_key_value("printable_area", new ConfigOptionPoints{ Vec2d(0.0, 0.0), Vec2d(100.0, 0.0), Vec2d(100.0, 100.0), Vec2d(0.0, 100.0), }); - config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(mode)); - config.set_deserialize_strict("bed_exclude_area", shared); + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(mode)); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString(shared)); if (!per_extruder.empty()) - config.set_key_value("extruder_bed_exclude_area", new ConfigOptionStrings(per_extruder)); + config.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings(per_extruder)); + return config; +} + +DynamicPrintConfig legacy_exclusion_config() +{ + DynamicPrintConfig config = exclusion_config(); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString()); + config.set_deserialize_strict("bed_exclude_area", "40x40,60x40,60x60,40x60"); return config; } @@ -227,7 +235,7 @@ struct BrimRun BrimRun generate_brim(const std::string &exclusion_definition) { - DynamicPrintConfig config = exclusion_config(BedExcludeAreaMode::Shared, exclusion_definition); + DynamicPrintConfig config = exclusion_config(BedExcludeVolumeMode::Shared, exclusion_definition); config.set_deserialize_strict({ {"skirt_loops", "0"}, {"brim_type", "outer_only"}, @@ -260,7 +268,7 @@ BrimRun generate_brim(const std::string &exclusion_definition) DynamicPrintConfig support_config(int support_filament, int interface_filament) { DynamicPrintConfig config = exclusion_config( - BedExcludeAreaMode::PerExtruder, "", + BedExcludeVolumeMode::PerExtruder, "", {"0..10;4x4,12x4,12x12,4x12", "0..10;22x4,30x4,30x12,22x12"}); // PrintObject clamps support role ids against the number of logical // filaments, represented by filament_diameter in the static config. @@ -322,6 +330,23 @@ TEST_CASE("Path checker ignores clear motions and motions outside the active Z s } } +TEST_CASE("Legacy excluded areas do not constrain machine motion", "[ExclusionVolume][GCode][Compatibility]") +{ + const FullPrintConfig config = static_config(legacy_exclusion_config()); + const Polyline direct = travel({Vec2d(20.0, 50.0), Vec2d(80.0, 50.0)}); + + auto checker = configured_checker(config); + check_motion(checker, Vec3d(20.0, 50.0, 5.0), Vec3d(80.0, 50.0, 5.0)); + CHECK_FALSE(checker.result().has_any_conflict); + + ExclusionVolumeTravelAvoidance router; + router.init(config, Vec3d::Zero()); + const auto route = router.route(direct, 5.0, 5.0, 0); + CHECK(route.status == ExclusionVolumeTravelAvoidance::Status::Unchanged); + CHECK(route.detail == ExclusionVolumeTravelAvoidance::Detail::NoActiveObstacles); + CHECK(route.path.points == direct.points); +} + TEST_CASE("Path checker detects crossing inside and boundary motions", "[ExclusionVolume][GCode]") { const FullPrintConfig config = static_config(exclusion_config()); @@ -386,7 +411,7 @@ TEST_CASE("Path checker handles unknown coordinates conservatively without inven TEST_CASE("Path checker selects the active nozzle and applies its XY offset", "[ExclusionVolume][GCode][MultiNozzle]") { DynamicPrintConfig dynamic = exclusion_config( - BedExcludeAreaMode::PerExtruder, "", {"", "0..10;40x40,60x40,60x60,40x60"}); + BedExcludeVolumeMode::PerExtruder, "", {"", "0..10;40x40,60x40,60x60,40x60"}); dynamic.set_key_value("extruder_offset", new ConfigOptionPoints{Vec2d::Zero(), Vec2d(20.0, 0.0)}); const FullPrintConfig config = static_config(dynamic); @@ -482,7 +507,7 @@ TEST_CASE("Travel router reports unsafe endpoints unknown tools and blocked beds SECTION("obstacle separates the bed") { ExclusionVolumeTravelAvoidance router; router.init(static_config(exclusion_config( - BedExcludeAreaMode::Shared, "0..10;45x0,55x0,55x100,45x100")), Vec3d::Zero()); + BedExcludeVolumeMode::Shared, "0..10;45x0,55x0,55x100,45x100")), Vec3d::Zero()); const auto result = router.route(travel({Vec2d(20.0, 50.0), Vec2d(80.0, 50.0)}), 5.0, 5.0, 0); CHECK(result.status == ExclusionVolumeTravelAvoidance::Status::Failed); } @@ -491,7 +516,7 @@ TEST_CASE("Travel router reports unsafe endpoints unknown tools and blocked beds TEST_CASE("Travel router uses only the active nozzle exclusion set", "[ExclusionVolume][TravelRouting][MultiNozzle]") { const FullPrintConfig config = static_config(exclusion_config( - BedExcludeAreaMode::PerExtruder, "", {"0..10;40x40,60x40,60x60,40x60", ""})); + BedExcludeVolumeMode::PerExtruder, "", {"0..10;40x40,60x40,60x60,40x60", ""})); ExclusionVolumeTravelAvoidance router; router.init(config, Vec3d::Zero()); const Polyline direct = travel({Vec2d(20.0, 50.0), Vec2d(80.0, 50.0)}); @@ -539,6 +564,17 @@ TEST_CASE("G-code processor tracks absolute relative and reset coordinate state" const ProcessorExclusionResult result = run_processor(config, "G28\nG1 X80 Y50 Z5\n"); CHECK_FALSE(result.conflict); } + + SECTION("all supported homing-axis spellings make the homed position unknown") { + const std::string homing = GENERATE( + std::string("G28"), std::string("G28 X"), std::string("G28 X Y"), + std::string("G28 XY"), std::string("G28 X0 Y0"), std::string("G28 XYZ"), + std::string("G28 Z P0"), std::string("G28 Z Z_OFFSET -0.07"), + std::string("G28 W")); + const ProcessorExclusionResult result = run_processor( + config, "G90\nG1 X20 Y50 Z5\n" + homing + "\nG1 X80 Y50 Z5\n"); + CHECK_FALSE(result.conflict); + } } TEST_CASE("G-code processor classifies extrusion conflicts", "[ExclusionVolume][GCodeProcessor]") @@ -555,7 +591,7 @@ TEST_CASE("G-code processor classifies extrusion conflicts", "[ExclusionVolume][ TEST_CASE("G-code processor changes the active physical nozzle at tool selection", "[ExclusionVolume][GCodeProcessor][MultiNozzle]") { const FullPrintConfig config = static_config(exclusion_config( - BedExcludeAreaMode::PerExtruder, "", {"", "0..10;40x40,60x40,60x60,40x60"})); + BedExcludeVolumeMode::PerExtruder, "", {"", "0..10;40x40,60x40,60x60,40x60"})); const ProcessorExclusionResult first_tool = run_processor(config, "G90\nT0\nG1 X20 Y50 Z5\nG1 X80 Y50\n"); CHECK_FALSE(first_tool.conflict); diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index 3bc027ebb5..b87fce5f95 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -120,7 +120,7 @@ size_t count_opt_key(const std::vector& warnings, const s } DynamicPrintConfig dual_extruder_exclusion_config( - BedExcludeAreaMode mode, + BedExcludeVolumeMode mode, const std::vector &per_extruder, const std::vector &filament_map = {1}) { @@ -129,8 +129,8 @@ DynamicPrintConfig dual_extruder_exclusion_config( 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(mode)); - config.set_key_value("extruder_bed_exclude_area", new ConfigOptionStrings(per_extruder)); + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(mode)); + config.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings(per_extruder)); config.set_key_value("filament_map_mode", new ConfigOptionEnum(fmmManual)); config.set_key_value("filament_map", new ConfigOptionInts(filament_map)); return config; @@ -185,21 +185,21 @@ TEST_CASE("Print validation applies individual exclusion volumes to the mapped p SECTION("mapped colliding extruder is rejected") { const DynamicPrintConfig config = dual_extruder_exclusion_config( - BedExcludeAreaMode::PerExtruder, {colliding, ""}, {1}); + BedExcludeVolumeMode::PerExtruder, {colliding, ""}, {1}); const StringObjectException error = validate_cubes(config, warnings); CHECK(error.string.find("extruder 1") != std::string::npos); } SECTION("mapped clear extruder is accepted") { const DynamicPrintConfig config = dual_extruder_exclusion_config( - BedExcludeAreaMode::PerExtruder, {colliding, ""}, {2}); + BedExcludeVolumeMode::PerExtruder, {colliding, ""}, {2}); const StringObjectException error = validate_cubes(config, warnings); CHECK(error.string.empty()); } SECTION("an unrelated nozzle exclusion does not reject the object") { const DynamicPrintConfig config = dual_extruder_exclusion_config( - BedExcludeAreaMode::PerExtruder, {"", colliding}, {1}); + BedExcludeVolumeMode::PerExtruder, {"", colliding}, {1}); const StringObjectException error = validate_cubes(config, warnings); CHECK(error.string.empty()); } @@ -210,25 +210,36 @@ TEST_CASE("Print validation applies shared exclusions and ignores volumes above std::vector warnings; SECTION("shared volume intersects") { - DynamicPrintConfig config = dual_extruder_exclusion_config(BedExcludeAreaMode::Shared, {"", ""}, {2}); - config.set_deserialize_strict("bed_exclude_area", "0..30;-100x-100,300x-100,300x300,-100x300"); + DynamicPrintConfig config = dual_extruder_exclusion_config(BedExcludeVolumeMode::Shared, {"", ""}, {2}); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString("0..30;-100x-100,300x-100,300x300,-100x300")); const StringObjectException error = validate_cubes(config, warnings); CHECK(error.string.find("extruder 2") != std::string::npos); } SECTION("elevated shared volume clears a 20mm cube") { - DynamicPrintConfig config = dual_extruder_exclusion_config(BedExcludeAreaMode::Shared, {"", ""}, {1}); - config.set_deserialize_strict("bed_exclude_area", "30..50;-100x-100,300x-100,300x300,-100x300"); + DynamicPrintConfig config = dual_extruder_exclusion_config(BedExcludeVolumeMode::Shared, {"", ""}, {1}); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString("30..50;-100x-100,300x-100,300x300,-100x300")); const StringObjectException error = validate_cubes(config, warnings); CHECK(error.string.empty()); } } +TEST_CASE("Legacy excluded areas retain object placement validation", "[Print][ExclusionVolume][Compatibility]") +{ + DynamicPrintConfig config = dual_extruder_exclusion_config( + BedExcludeVolumeMode::Shared, {"", ""}, {1}); + config.set_deserialize_strict("bed_exclude_area", "-100x-100,300x-100,300x300,-100x300"); + + std::vector warnings; + const StringObjectException error = validate_cubes(config, warnings); + CHECK_FALSE(error.string.empty()); +} + TEST_CASE("Print validation checks every nozzle used by a multimaterial object", "[Print][ExclusionVolume][MultiNozzle]") { const std::string colliding = "0..256;-100x-100,300x-100,300x300,-100x300"; const DynamicPrintConfig config = dual_extruder_exclusion_config( - BedExcludeAreaMode::PerExtruder, {"", colliding}, {1, 2}); + BedExcludeVolumeMode::PerExtruder, {"", colliding}, {1, 2}); const StringObjectException error = validate_multimaterial_cube(config); CHECK(error.string.find("extruder 2") != std::string::npos); diff --git a/tests/libslic3r/test_3mf.cpp b/tests/libslic3r/test_3mf.cpp index f1fc5c0bf5..85ce5dc00a 100644 --- a/tests/libslic3r/test_3mf.cpp +++ b/tests/libslic3r/test_3mf.cpp @@ -159,10 +159,11 @@ TEST_CASE("Volumetric per-extruder exclusions survive a 3MF round-trip", "[3mf][ // exclusion settings and should not depend on unrelated printer-profile // defaults surviving the project archive round-trip. DynamicPrintConfig source; - source.set_key_value("bed_exclude_area_mode", - new ConfigOptionEnum(BedExcludeAreaMode::PerExtruder)); + source.set_key_value("bed_exclude_volume_mode", + new ConfigOptionEnum(BedExcludeVolumeMode::PerExtruder)); source.set_deserialize_strict("bed_exclude_area", "0x0,10x0,10x10,0x10"); - source.set_key_value("extruder_bed_exclude_area", new ConfigOptionStrings{ + source.set_key_value("bed_exclude_volumes", new ConfigOptionString("0..10;1x1,2x1,2x2,1x2")); + source.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings{ "0..25;5x5,15x5,15x15,5x15", "30..80;40x40,55x40,55x55,40x55|0..5;70x10,80x10,80x20,70x20", }); @@ -197,14 +198,18 @@ TEST_CASE("Volumetric per-extruder exclusions survive a 3MF round-trip", "[3mf][ release_PlateData_list(reloaded_plates); REQUIRE(loaded); - REQUIRE(reloaded.option>("bed_exclude_area_mode") != nullptr); - CHECK(reloaded.option>("bed_exclude_area_mode")->value == - BedExcludeAreaMode::PerExtruder); + REQUIRE(reloaded.option>("bed_exclude_volume_mode") != nullptr); + CHECK(reloaded.option>("bed_exclude_volume_mode")->value == + BedExcludeVolumeMode::PerExtruder); - const auto *areas = reloaded.option("extruder_bed_exclude_area"); + const auto *areas = reloaded.option("extruder_bed_exclude_volumes"); REQUIRE(areas != nullptr); REQUIRE(areas->values.size() == 2); - CHECK(areas->values == source.option("extruder_bed_exclude_area")->values); + CHECK(areas->values == source.option("extruder_bed_exclude_volumes")->values); + + const auto *shared_volumes = reloaded.option("bed_exclude_volumes"); + REQUIRE(shared_volumes != nullptr); + CHECK(shared_volumes->value == source.opt_string("bed_exclude_volumes")); const auto *legacy = reloaded.option("bed_exclude_area"); REQUIRE(legacy != nullptr); diff --git a/tests/libslic3r/test_exclusion_volumes.cpp b/tests/libslic3r/test_exclusion_volumes.cpp index db0f425506..e5ad6b5fff 100644 --- a/tests/libslic3r/test_exclusion_volumes.cpp +++ b/tests/libslic3r/test_exclusion_volumes.cpp @@ -30,7 +30,8 @@ Polygon rectangle(double min_x, double min_y, double max_x, double max_y) BedExcludeRegion region(double min_x, double min_y, double max_x, double max_y, double z_min, double z_max, bool has_z_range = true) { - return {rectangle(min_x, min_y, max_x, max_y), z_min, z_max, true, has_z_range}; + return {rectangle(min_x, min_y, max_x, max_y), z_min, z_max, + BedExcludeRegion::Purpose::CollisionVolume, has_z_range}; } DynamicPrintConfig two_extruder_config() @@ -42,7 +43,7 @@ DynamicPrintConfig two_extruder_config() config.set_key_value("extruder_printable_height", new ConfigOptionFloatsNullable{200.0, 200.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"); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString("10..30;0x0,10x0,10x10,0x10")); return config; } @@ -86,27 +87,16 @@ TEST_CASE("Legacy exclusion polygons keep their point representation", "[Exclusi REQUIRE(option.deserialize("0x0,10x0,10x10,0x10")); REQUIRE(option.values.size() == 4); CHECK(option.serialize() == "0x0,10x0,10x10,0x10"); - CHECK_FALSE(has_bed_exclusion_volume_syntax(option)); + CHECK_FALSE(is_bed_exclusion_volume_syntax(option.serialize())); } -TEST_CASE("Extended exclusion definitions retain their serialized representation", "[ExclusionVolume][PrintConfig]") +TEST_CASE("Legacy point options reject collision-volume syntax", "[ExclusionVolume][PrintConfig]") { const std::string definition = "0..10;0x0,10x0,10x10,0x10|20x20,30x20,30x30,20x30"; ConfigOptionPoints option; - REQUIRE(option.deserialize(definition)); + CHECK_FALSE(option.deserialize(definition)); CHECK(option.values.empty()); - CHECK(option.serialize() == definition); - CHECK(option.vserialize() == std::vector{definition}); - CHECK(has_bed_exclusion_volume_syntax(option)); - - std::unique_ptr cloned(option.clone()); - REQUIRE(cloned != nullptr); - CHECK(*cloned == option); - CHECK(cloned->hash() == option.hash()); - - ConfigOptionPoints assigned; - assigned.set(&option); - CHECK(assigned == option); + CHECK(is_bed_exclusion_volume_syntax(definition)); } TEST_CASE("Exclusion syntax validation accepts supported forms and rejects malformed regions", "[ExclusionVolume][PrintConfig]") @@ -126,7 +116,7 @@ TEST_CASE("Exclusion syntax validation accepts supported forms and rejects malfo })); DYNAMIC_SECTION(definition) { - CHECK(is_valid_bed_exclude_area_string(definition, 200.0) == valid); + CHECK(is_valid_bed_exclude_volumes_string(definition, 200.0) == valid); } } @@ -134,9 +124,8 @@ TEST_CASE("Extended exclusion Z ranges are defaulted and clamped to printable he { DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); config.set_key_value("printable_height", new ConfigOptionFloat(100.0)); - config.set_deserialize_strict( - "bed_exclude_area", - "-20..25;0x0,10x0,10x10,0x10|75..150;20x0,30x0,30x10,20x10|..;40x0,50x0,50x10,40x10"); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString( + "-20..25;0x0,10x0,10x10,0x10|75..150;20x0,30x0,30x10,20x10|..;40x0,50x0,50x10,40x10")); const std::vector regions = get_bed_excluded_regions(config); REQUIRE(regions.size() == 3); @@ -148,10 +137,88 @@ TEST_CASE("Extended exclusion Z ranges are defaulted and clamped to printable he CHECK_THAT(regions[2].z_max, WithinAbs(100.0, 1e-9)); } +TEST_CASE("CLI keeps legacy areas and collision volumes on separate options", "[ExclusionVolume][PrintConfig][CLI]") +{ + const char *legacy_area_argv[] = { + "orca-slicer", "--bed-exclude-area", "0x0,10x0,10x10,0x10" + }; + DynamicPrintAndCLIConfig legacy_area_config; + t_config_option_keys extra; + t_config_option_keys keys; + REQUIRE(legacy_area_config.read_cli(3, legacy_area_argv, &extra, &keys)); + REQUIRE(legacy_area_config.opt("bed_exclude_area") != nullptr); + CHECK(legacy_area_config.opt("bed_exclude_area")->values.size() == 4); + + const char *volume_argv[] = { + "orca-slicer", "--bed-exclude-volumes", "0..10;0x0,10x0,10x10,0x10" + }; + DynamicPrintAndCLIConfig volume_config; + extra.clear(); + keys.clear(); + REQUIRE(volume_config.read_cli(3, volume_argv, &extra, &keys)); + CHECK(volume_config.opt_string("bed_exclude_volumes") == volume_argv[2]); + + const char *legacy_argv[] = { + "orca-slicer", "--bed-exclude-area", "0..10;0x0,10x0,10x10,0x10" + }; + DynamicPrintAndCLIConfig legacy_config; + extra.clear(); + keys.clear(); + CHECK_FALSE(legacy_config.read_cli(3, legacy_argv, &extra, &keys)); +} + +TEST_CASE("Legacy areas remain material keep-outs until collision volumes are configured", "[ExclusionVolume][PrintConfig]") +{ + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_key_value("printable_height", new ConfigOptionFloat(100.0)); + config.set_deserialize_strict("bed_exclude_area", "0x0,10x0,10x10,0x10"); + + auto regions = get_bed_excluded_regions(config); + REQUIRE(regions.size() == 1); + CHECK_FALSE(regions.front().is_collision_volume()); + CHECK_FALSE(has_bed_exclude_volumes(config)); + + config.set_key_value("bed_exclude_volumes", new ConfigOptionString("20x20,30x20,30x30,20x30")); + regions = get_bed_excluded_regions(config); + REQUIRE(regions.size() == 1); + CHECK(regions.front().is_collision_volume()); + CHECK(regions.front().polygon.contains(Point::new_scale(25.0, 25.0))); + CHECK_FALSE(regions.front().polygon.contains(Point::new_scale(5.0, 5.0))); +} + +TEST_CASE("A nonempty invalid collision-volume definition never falls back to the legacy area", "[ExclusionVolume][PrintConfig]") +{ + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_deserialize_strict("bed_exclude_area", "0x0,10x0,10x10,0x10"); + config.set_key_value("bed_exclude_volumes", new ConfigOptionString("not a polygon")); + + CHECK(has_bed_exclude_volumes(config)); + CHECK(get_bed_excluded_regions(config).empty()); + CHECK_FALSE(is_valid_bed_exclude_volumes_string(config.opt_string("bed_exclude_volumes"), 100.0)); +} + +TEST_CASE("An empty collision-volume configuration falls back to the legacy area", "[ExclusionVolume][PrintConfig]") +{ + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_num_extruders(2); + config.set_deserialize_strict("bed_exclude_area", "0x0,10x0,10x10,0x10"); + config.set_key_value("bed_exclude_volume_mode", + new ConfigOptionEnum(BedExcludeVolumeMode::PerExtruder)); + config.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings{"", ""}); + + CHECK_FALSE(has_bed_exclude_volumes(config)); + CHECK(active_bed_exclude_volume_mode(config) == BedExcludeVolumeMode::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_FALSE(groups[0][0].is_collision_volume()); +} + TEST_CASE("Shared exclusion volumes resolve identically for every extruder", "[ExclusionVolume][PrintConfig][MultiNozzle]") { DynamicPrintConfig config = two_extruder_config(); - config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::Shared)); + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(BedExcludeVolumeMode::Shared)); const auto groups = get_bed_excluded_regions_by_extruder(config); REQUIRE(groups.size() == 2); @@ -168,7 +235,7 @@ TEST_CASE("Shared exclusion volumes resolve identically for every extruder", "[E TEST_CASE("Toolhead-relative exclusion volumes follow nozzle offset deltas", "[ExclusionVolume][PrintConfig][MultiNozzle]") { DynamicPrintConfig config = two_extruder_config(); - config.set_key_value("bed_exclude_area_mode", new ConfigOptionEnum(BedExcludeAreaMode::ToolheadOffset)); + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(BedExcludeVolumeMode::ToolheadOffset)); const auto groups = get_bed_excluded_regions_by_extruder(config); REQUIRE(groups.size() == 2); @@ -184,7 +251,7 @@ TEST_CASE("Toolhead-relative exclusions honour a non-default reference extruder" { 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)); + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(BedExcludeVolumeMode::ToolheadOffset)); const auto groups = get_bed_excluded_regions_by_extruder(config); REQUIRE(groups.size() == 2); @@ -197,8 +264,8 @@ TEST_CASE("Toolhead-relative exclusions honour a non-default reference extruder" TEST_CASE("Individual exclusion volumes remain authoritative per extruder", "[ExclusionVolume][PrintConfig][MultiNozzle]") { 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{ + config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum(BedExcludeVolumeMode::PerExtruder)); + config.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings{ "0..25;0x0,8x0,8x8,0x8|40..60;20x20,30x20,30x30,20x30", "", }); @@ -214,9 +281,8 @@ TEST_CASE("Legacy bed helpers include only regions touching the first layer", "[ { DynamicPrintConfig dynamic = DynamicPrintConfig::full_print_config(); dynamic.set_key_value("printable_height", new ConfigOptionFloat(100.0)); - dynamic.set_deserialize_strict( - "bed_exclude_area", - "0..5;0x0,10x0,10x10,0x10|20..30;20x0,30x0,30x10,20x10"); + dynamic.set_key_value("bed_exclude_volumes", new ConfigOptionString( + "0..5;0x0,10x0,10x10,0x10|20..30;20x0,30x0,30x10,20x10")); PrintConfig config; config.apply(dynamic, true);