bim-twin-viewer/backend/app/models/element.py
warnason 5cb6f1403b Initial project scaffold: FastAPI backend + Vue.js frontend
- FastAPI with async SQLAlchemy models for IFC elements
- IFC file upload and parsing via IfcOpenShell
- REST API for projects, elements, and properties
- Vue.js 3 frontend shell with Three.js dependency
- Docker Compose for full-stack local development
- PostgreSQL 16 as database
- CI pipeline for Forgejo Actions
- Project documentation and API overview
2026-04-20 18:01:12 +02:00

55 lines
1.9 KiB
Python

"""SQLAlchemy models for IFC building elements."""
import uuid
from sqlalchemy import Column, Float, ForeignKey, String, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.models.database import Base
class Project(Base):
"""An uploaded IFC project / building model."""
__tablename__ = "projects"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String(255), nullable=False)
filename = Column(String(255), nullable=False)
description = Column(Text, default="")
ifc_schema = Column(String(50), default="")
elements = relationship("Element", back_populates="project", cascade="all, delete-orphan")
class Element(Base):
"""A single IFC building element (wall, door, slab, etc.)."""
__tablename__ = "elements"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
project_id = Column(UUID(as_uuid=True), ForeignKey("projects.id"), nullable=False)
global_id = Column(String(64), nullable=False, index=True)
ifc_type = Column(String(100), nullable=False, index=True)
name = Column(String(255), default="")
description = Column(Text, default="")
storey = Column(String(255), default="")
project = relationship("Project", back_populates="elements")
properties = relationship("Property", back_populates="element", cascade="all, delete-orphan")
class Property(Base):
"""A property (key-value pair) attached to an IFC element."""
__tablename__ = "properties"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
element_id = Column(UUID(as_uuid=True), ForeignKey("elements.id"), nullable=False)
pset_name = Column(String(255), default="")
name = Column(String(255), nullable=False)
value = Column(Text, default="")
element = relationship("Element", back_populates="properties")