Add hex holder designer page (/holder)

Server-side OpenSCAD renders STL from bundled hex_cell.scad with parameter
overrides via -D. Frontend is a Three.js viewer with auto-form generated
from /api/holder/params. 'Design busbars →' button posts the computed
cell coordinates to /api/projects and redirects to the busbar editor with
the holder cells pre-loaded.

  - holder.py:                openscad subprocess wrapper + compute_cells()
                              (Python mirror of get_hex_center_points_*)
  - scad/hex_cell.scad:       verbatim copy of Addy/Hex-Cell-Holder source
  - app.py:                   /holder route + /api/holder/{params,render,cells}
  - static/holder.html etc:   parameter form + Three.js STL viewer
  - Dockerfile / install.sh:  apt install openscad
  - static/index.html:        nav link Holder ↔ Busbars in topbar
This commit is contained in:
wenil
2026-05-24 19:27:50 +03:00
parent d8cb0dc06d
commit 6bc922cabf
13 changed files with 2371 additions and 9 deletions
+44 -1
View File
@@ -18,6 +18,7 @@ from flask import Flask, Response, jsonify, request, send_from_directory
from busbar_export import WRITERS
import storage
import holder
APP_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_DIR = os.path.join(APP_DIR, "static")
@@ -37,9 +38,51 @@ def index():
return send_from_directory(STATIC_DIR, "index.html")
@app.get("/holder")
def holder_page():
return send_from_directory(STATIC_DIR, "holder.html")
@app.get("/api/health")
def health():
return jsonify({"status": "ok"})
return jsonify({"status": "ok", "openscad": holder.openscad_available()})
# ---------------------------------------------------------------------------
# Hex holder designer (OpenSCAD-backed)
# ---------------------------------------------------------------------------
@app.get("/api/holder/params")
def holder_params():
"""Schema for the parameter form + their defaults."""
return jsonify({"params": holder.schema_dict(), "defaults": holder.default_params()})
@app.post("/api/holder/render")
def holder_render():
"""Render STL for the supplied parameter overrides."""
body = request.get_json(silent=True) or {}
try:
data = holder.render_stl(body.get("params", {}))
except (FileNotFoundError, RuntimeError) as e:
return jsonify({"error": str(e)}), 500
return Response(
data,
mimetype="model/stl",
headers={"Content-Disposition": 'attachment; filename="hex_holder.stl"'},
)
@app.post("/api/holder/cells")
def holder_cells():
"""Cell-center coordinates for the supplied parameters (no OpenSCAD needed)."""
body = request.get_json(silent=True) or {}
try:
cells = holder.compute_cells(body.get("params", {}))
except ValueError as e:
return jsonify({"error": str(e)}), 400
return jsonify({"cells": cells, "count": len(cells)})
# ---------------------------------------------------------------------------