Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/autoforge/Helper/Export3MF.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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",
]
44 changes: 44 additions & 0 deletions tests/test_slicer_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading