Files
maziggy 02e39b18b9 Configure Orca Cloud filaments with their own filament ID (#3216)
OrcaSlicer's Sync filaments finds a slot's preset by the slot's filament
ID alone. The Configure dialog looked up an Orca profile's ID in the
browser and quietly sent the generic for the material when that came back
empty, so Orca custom filaments reached the slicer as Generic and the log
showed nothing. configure now resolves the ID on the server from
orca_profile_id, follows inherits to the parent profile or the Bambu
filament it was copied from, logs the outcome and reports a fallback,
which the dialog shows as a warning.

Slot presets also store the filament ID they were written with, so the
slot card and the Configure dialog stop showing a preset once the slot is
changed from OrcaSlicer's Device tab or the printer.

Re-configuring a slot for another filament no longer carries over the old
filament's active K-profile, which switched the slot back to the old
filament.
2026-10-02 08:32:57 +02:00

42 lines
1.9 KiB
Python

"""Model for storing AMS slot to filament preset mappings.
This stores the user's preferred filament preset for each AMS slot,
similar to how Bambu Studio remembers preset selections.
"""
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from backend.app.core.database import Base
class SlotPresetMapping(Base):
"""Maps an AMS slot to a cloud filament preset."""
__tablename__ = "slot_preset_mappings"
__table_args__ = (UniqueConstraint("printer_id", "ams_id", "tray_id", name="uq_slot_preset"),)
id: Mapped[int] = mapped_column(primary_key=True)
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"))
ams_id: Mapped[int] = mapped_column(Integer) # AMS unit ID (0, 1, 2, 3)
tray_id: Mapped[int] = mapped_column(Integer) # Tray ID within AMS (0-3)
preset_id: Mapped[str] = mapped_column(String(100)) # Cloud preset setting_id
preset_name: Mapped[str] = mapped_column(String(200)) # Preset name for display
preset_source: Mapped[str] = mapped_column(String(20), default="cloud") # cloud or local
# The filament id the slot was configured with alongside this preset. When
# the printer later reports a different one, something else (the slicer's
# Device tab, the printer screen) re-configured the slot and this row no
# longer describes it (#3216). None for rows written before it was recorded
# and by callers that do not know it.
tray_info_idx: Mapped[str | None] = mapped_column(String(32), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
# Relationship
printer: Mapped["Printer"] = relationship()
from backend.app.models.printer import Printer # noqa: E402