- Floor editor: one toolbar over the map and the panels (grid on / off, grid resolution Ultra high ... Very low, edit the shape, Fit width / Whole plan, undo, save), panels top-aligned and sticky. - The floor's shape: a '+' on the edge under the pointer, press to add a corner (and drag it); resting on a corner shows a bubble to remove it (never below 3). - Areas: resize handles on the sides and corners, a colour (pastel, see-through; floor_items.color, migration 0041), the name repeated in the corner when tables cover it (live maps too). - Labels can be clicked again after they're placed (transparent fill, not none). - Management -> Tables: <Page> with the tabs above (?tab=), the list as a container, toolbar buttons one height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.8 KiB
Python
60 lines
2.8 KiB
Python
"""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)
|
||
color = Column(String, nullable=True) # an area's colour, "#rrggbb" (drawn see-through; 2026-11-20)
|
||
|
||
plan = relationship("FloorPlan", back_populates="items")
|