erste Fassung von Client und Server rein
This commit is contained in:
26
server/catalog/symbols.json
Normal file
26
server/catalog/symbols.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"symbols": [
|
||||
{
|
||||
"id": "weiche_links_r300",
|
||||
"label": "Weiche links R300",
|
||||
"type": "weiche",
|
||||
"radius": 300,
|
||||
"direction": "left",
|
||||
"svg_path": "M 0,0 L 100,0 Q 150,0 200,50",
|
||||
"snap_points": [[0,0], [100,0], [200,50]],
|
||||
"ports": ["in", "out_gerade", "out_abzweig"]
|
||||
},
|
||||
{
|
||||
"id": "kreisel_standard",
|
||||
"label": "Kreisel",
|
||||
"type": "kreisel",
|
||||
"geometry": {
|
||||
"circle_top_r": 40,
|
||||
"circle_bottom_r": 40,
|
||||
"straight_length": 80
|
||||
},
|
||||
"svg_path": "M -40,0 A 40,40 0 1,1 40,0 A 40,40 0 1,1 -40,0 M -40,160 A 40,40 0 1,1 40,160 A 40,40 0 1,1 -40,160 M -40,0 L -40,160 M 40,0 L 40,160",
|
||||
"snap_points": [[0,0], [0,160]]
|
||||
}
|
||||
]
|
||||
}
|
||||
66
server/main.py
Normal file
66
server/main.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
PlantPlan FastAPI Backend
|
||||
- Symbolbibliothek ausliefern
|
||||
- Koordinaten normalisieren
|
||||
- JSON/SVG Export
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI(title="PlantPlan API")
|
||||
|
||||
# CORS: Erlaubt Zugriff vom lokalen Frontend Dev-Server
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:5173"],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
CATALOG_DIR = Path(__file__).parent / "catalog"
|
||||
|
||||
|
||||
# --- Models ---
|
||||
|
||||
class SketchPayload(BaseModel):
|
||||
shapes: list[dict]
|
||||
grid_size: int = 10
|
||||
|
||||
|
||||
# --- Endpoints ---
|
||||
|
||||
@app.get("/symbols")
|
||||
async def get_symbols():
|
||||
"""Symbolbibliothek als JSON ausliefern."""
|
||||
catalog_file = CATALOG_DIR / "symbols.json"
|
||||
with open(catalog_file, encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
@app.post("/normalize")
|
||||
async def normalize(payload: SketchPayload):
|
||||
"""Koordinaten auf Grid snappen und SVG-Pfade normalisieren."""
|
||||
cleaned = []
|
||||
for shape in payload.shapes:
|
||||
s = dict(shape)
|
||||
if "x" in s:
|
||||
s["x"] = round(s["x"] / payload.grid_size) * payload.grid_size
|
||||
if "y" in s:
|
||||
s["y"] = round(s["y"] / payload.grid_size) * payload.grid_size
|
||||
cleaned.append(s)
|
||||
return {"shapes": cleaned}
|
||||
|
||||
|
||||
@app.post("/export")
|
||||
async def export_sketch(payload: SketchPayload):
|
||||
"""Finales Projektfile als JSON exportieren."""
|
||||
return {
|
||||
"json": {
|
||||
"version": "1.0",
|
||||
"shapes": payload.shapes,
|
||||
}
|
||||
}
|
||||
3
server/requirements.txt
Normal file
3
server/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
fastapi>=0.115.0
|
||||
uvicorn[standard]>=0.34.0
|
||||
pydantic>=2.0.0
|
||||
Reference in New Issue
Block a user