diff --git a/src/autoforge/Helper/Export3MF.py b/src/autoforge/Helper/Export3MF.py index 1e39bff..8f096bb 100644 --- a/src/autoforge/Helper/Export3MF.py +++ b/src/autoforge/Helper/Export3MF.py @@ -527,6 +527,8 @@ def complete(config: dict[str, Any], kind: str) -> dict[str, Any]: index = load_printer_index() fill_nil_values(config, set(index.get("nullable") or []), defaults, set(index.get("int_options") or [])) clamp_to_orca_ranges(config, index.get("option_ranges") or {}) + if printer["vendor"] == "BBL": + make_bambu_compatible(config) config["flush_volumes_matrix"] = flush_matrix(config, [s.color for s in slots]) config["flush_volumes_vector"] = ["140"] * (2 * len(slots)) @@ -827,6 +829,40 @@ def fill_nil_values(config: dict[str, Any], nullable: set[str], defaults: dict[s return changed +_PATTERN_KEYS = ( + "sparse_infill_pattern", "top_surface_pattern", "bottom_surface_pattern", + "internal_solid_infill_pattern", "ironing_pattern", "support_ironing_pattern", +) +# Bambu Studio has no "off" level, only its old on/off switch. +_BAMBU_VERTICAL_SHELL = {"none": "0", "ensure_critical_only": "0", "ensure_moderate": "0", "ensure_all": "1"} +_BAMBU_ARC_FITTING = {"disabled": "0", "enabled": "1"} + + +def make_bambu_compatible(config: dict[str, Any]) -> list[str]: + """Write the values Bambu Studio names differently from OrcaSlicer its + way. Bambu Studio swaps a value it doesn't know for its default: a 100 % + "rectilinear" infill became "cubic", which it refuses at that density, so + it dropped the project's settings and opened the stock 0.2 mm profile. + OrcaSlicer converts each of these back on load (handle_legacy), so the + project still opens there. Returns the keys changed.""" + changed = [] + + def convert(key: str, table: dict[str, str]) -> None: + value = config.get(key) + if value is None: + return + fixed = [table.get(str(v), v) for v in value] if isinstance(value, list) else table.get(str(value), value) + if fixed != value: + config[key] = fixed + changed.append(key) + + for key in _PATTERN_KEYS: + convert(key, {"rectilinear": "zig-zag"}) + convert("enable_arc_fitting", _BAMBU_ARC_FITTING) + convert("ensure_vertical_shell_thickness", _BAMBU_VERTICAL_SHELL) + return changed + + def clamp_to_orca_ranges(config: dict[str, Any], ranges: dict[str, Any]) -> list[str]: """Bring values into OrcaSlicer's allowed range for each option. @@ -1070,5 +1106,5 @@ def rows_done(n: int) -> None: __all__ = [ "Cancelled", "ProfileError", "Slot", "SwapPlan", "export_3mf", "printer_changes_filament", - "project_settings", "read_stl", "swap_plan", + "make_bambu_compatible", "project_settings", "read_stl", "swap_plan", ] diff --git a/tests/test_slicer_project.py b/tests/test_slicer_project.py index 8ba44a2..1068c98 100644 --- a/tests/test_slicer_project.py +++ b/tests/test_slicer_project.py @@ -757,3 +757,47 @@ def test_layer_limits_follow_autoforges_layer_height(acme, layer, base, min_expe cfg = E.project_settings(printer, _slots("PLA", "PLA"), layer, base, False, acme) assert cfg["layer_height"] == f"{layer:g}" and cfg["initial_layer_print_height"] == f"{base:g}" assert cfg["min_layer_height"] == min_expected and cfg["max_layer_height"] == max_expected + + +# ------------------------------------------------------- Bambu Studio values + +def test_bambu_printers_get_values_bambu_studio_reads(): + """Bambu Studio names some values differently from OrcaSlicer and swaps + a name it doesn't know for its default: sparse "rectilinear" became + "cubic", which it refuses at 100 % infill, so it dropped the project's + settings (0.04 mm layers opened as 0.2 mm). OrcaSlicer reads Bambu's + names as legacy values, so one file works in both.""" + cfg = { + "sparse_infill_pattern": "rectilinear", + "bottom_surface_pattern": "rectilinear", + "ironing_pattern": ["rectilinear"], + "top_surface_pattern": "monotonic", + "internal_solid_infill_pattern": "alignedrectilinear", + "enable_arc_fitting": "disabled", + "ensure_vertical_shell_thickness": "none", + } + changed = E.make_bambu_compatible(cfg) + assert cfg == { + "sparse_infill_pattern": "zig-zag", + "bottom_surface_pattern": "zig-zag", + "ironing_pattern": ["zig-zag"], + "top_surface_pattern": "monotonic", + "internal_solid_infill_pattern": "alignedrectilinear", + "enable_arc_fitting": "0", + "ensure_vertical_shell_thickness": "0", + } + assert set(changed) == { + "sparse_infill_pattern", "bottom_surface_pattern", "ironing_pattern", + "enable_arc_fitting", "ensure_vertical_shell_thickness", + } + assert E.make_bambu_compatible(cfg) == [] # already Bambu's + + +def test_ensure_vertical_shell_levels_map_to_bambus_old_switch(): + for orca, bambu in (("none", "0"), ("ensure_critical_only", "0"), ("ensure_moderate", "0"), ("ensure_all", "1")): + cfg = {"ensure_vertical_shell_thickness": orca} + E.make_bambu_compatible(cfg) + assert cfg["ensure_vertical_shell_thickness"] == bambu + cfg = {"enable_arc_fitting": "enabled"} + E.make_bambu_compatible(cfg) + assert cfg["enable_arc_fitting"] == "1"