Files
busbar-designer/static/scad.html
T
wenil 676d976937 holder + scad: SCAD source editor on /holder + new /scad universal renderer
Phase 2 — SCAD editor on /holder
================================
Some adjustments need more control than the parameter form gives
(e.g. tweaking the .scad logic itself). A collapsible CodeMirror-based
editor now slides up from the bottom of the viewport when you click
the "</> Source" button at the bottom-right.

- holder.html / holder.css: editor panel, toggle button, Reset and
  Close buttons. CodeMirror 5 loaded from cdnjs (single CSS + JS
  pair, clike mode for syntax highlighting since OpenSCAD is C-like).
- holder-app.js: lazy-initialises the editor on first show, fetches
  bundled source from /api/holder/source, tracks whether the editor
  content has been modified ("modified" tag in the panel title).
  When the editor is visible AND content differs from bundled,
  _doRender() switches from /api/holder/render -> /api/scad/render
  with {source, params}. Cell-count cap doesn't apply in that mode
  (the source may not even use the holder schema).

Phase 3 — Universal OpenSCAD playground at /scad
================================================
A standalone page for rendering arbitrary OpenSCAD. Paste code, click
Render (or Ctrl+Enter), see STL in the same Three.js viewer the
holder uses. Useful for prototyping new generators before wiring
them into a parameter form.

- New page: static/scad.html + scad.css + js/scad-app.js. Reuses
  holder-viewer.js (the Three.js scene module is generic enough).
- "Load example" populates a 6-hole rounded bracket so new users
  can verify the renderer works in two clicks.
- Same progress UI (elapsed timer + indeterminate bar + Cancel
  via AbortController) as /holder.
- Top nav now has Holder / Busbars / SCAD on every page.

Backend (shared by phase 2 & 3)
================================
- holder.py: split _run_openscad() out of render_stl(). New
  render_source(source, params=None) writes the source to a temp
  file and renders it; enforces MAX_SOURCE_BYTES (default 512 KB)
  and RENDER_TIMEOUT but skips the cell-count cap. New bundled_source()
  returns the hex_cell.scad text for editor pre-population.
- app.py: GET /api/holder/source returns the bundled .scad text.
  POST /api/scad/render takes {source, params?} and returns STL +
  X-Holder-Dimensions header. ValueError -> 400, RuntimeError -> 500.
  _stl_response() factored out so both render endpoints emit the same
  headers consistently.
2026-05-25 12:52:18 +03:00

75 lines
2.6 KiB
HTML

<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenSCAD playground</title>
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="holder.css" />
<link rel="stylesheet" href="scad.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/theme/dracula.min.css" />
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.165.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.165.0/examples/jsm/"
}
}
</script>
</head>
<body>
<header class="topbar">
<h1>OpenSCAD playground</h1>
<nav class="topbar-nav">
<a href="/holder">Holder</a>
<a href="/">Busbars</a>
<a href="/scad" class="active">SCAD</a>
</nav>
<span id="status" class="topbar-status">paste OpenSCAD code →</span>
<div class="actions">
<button id="btn-render" class="primary" title="Render the SCAD source as STL">Render</button>
<button id="btn-cancel" title="Cancel running render" hidden>Cancel</button>
<button id="btn-download-stl" title="Download the rendered STL">Download STL</button>
<span class="sep"></span>
<button id="btn-load-example" title="Load a small example to verify the renderer works">Load example</button>
</div>
</header>
<main class="scad-main">
<aside class="left scad-left">
<section class="panel" style="flex:1; display:flex; flex-direction:column;">
<h2>Source</h2>
<div id="scad-editor" style="flex:1;"></div>
</section>
<section class="panel">
<h2>Status</h2>
<p class="hint" id="render-status">idle</p>
<div id="render-progress" class="render-progress" hidden>
<div class="render-progress-bar"><div class="render-progress-fill"></div></div>
<span id="render-elapsed" class="render-elapsed">0.0s</span>
</div>
<p class="hint" id="warning"></p>
</section>
</aside>
<section class="right">
<div id="viewer3d" class="viewer3d"></div>
<div class="viewport-overlay">
<div id="hint-controls">left-drag: rotate · right-drag: pan · wheel: zoom</div>
</div>
</section>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/clike/clike.min.js"></script>
<script type="module" src="js/holder-viewer.js"></script>
<script type="module" src="js/scad-app.js"></script>
</body>
</html>