"""Floor plans: where the tables stand (plan step 6.8, owner decisions D-31). A zone (table group) can have several floor plans ("Ground floor", "Terrace"); a plan may also have no zone. A plan is a canvas `width` × `height` in plan units (1 unit = 1 px at 100%): - `outline`: the floor's shape as a polygon [[x, y], …] (irregular floors); empty = the whole rectangle; - `grid_on` / `grid_size`: with the grid on, the editor snaps positions and sizes to multiples of `grid_size` (the grid is a help for drawing, the stored positions are plain numbers); - `media_id`: a picture from the media library drawn under everything (e.g. a top-down photo), with `background_opacity`. `FloorItem`s are the things that aren't tables: walls, the bar, labels and areas, each a rectangle (x, y = its centre) with a rotation. A table's place is on the table itself (models/table.py: plan_id, floor_x/floor_y = its centre, width/height, rotation, shape). """ from sqlalchemy import JSON, Boolean, Column, Float, ForeignKey, Integer, String from sqlalchemy.orm import relationship from core.timeutil import UTCDateTime, utcnow from database import Base ITEM_KINDS = ("wall", "bar", "label", "area") TABLE_SHAPES = ("round", "square", "long") class FloorPlan(Base): __tablename__ = "floor_plans" id = Column(Integer, primary_key=True, index=True) name = Column(String, nullable=False) group_id = Column(Integer, ForeignKey("table_groups.id", ondelete="SET NULL"), nullable=True, index=True) sort_order = Column(Integer, nullable=False, default=0) width = Column(Integer, nullable=False, default=1200) height = Column(Integer, nullable=False, default=800) outline = Column(JSON, nullable=True) grid_on = Column(Boolean, nullable=False, default=False) grid_size = Column(Integer, nullable=False, default=40) media_id = Column(Integer, ForeignKey("media.id", ondelete="SET NULL"), nullable=True) background_opacity = Column(Float, nullable=False, default=0.6) created_at = Column(UTCDateTime, default=utcnow, nullable=False) media = relationship("Media") items = relationship("FloorItem", back_populates="plan", cascade="all, delete-orphan", order_by="FloorItem.id") class FloorItem(Base): __tablename__ = "floor_items" id = Column(Integer, primary_key=True, index=True) plan_id = Column(Integer, ForeignKey("floor_plans.id", ondelete="CASCADE"), nullable=False, index=True) kind = Column(String, nullable=False) x = Column(Float, nullable=False) y = Column(Float, nullable=False) width = Column(Float, nullable=False) height = Column(Float, nullable=False) rotation = Column(Float, nullable=False, default=0.0) text = Column(String, nullable=True) plan = relationship("FloorPlan", back_populates="items")