This repository has been archived on 2026-10-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
HiNC-2025-win-desktop-Deploy/App/wwwroot/HiAPI-docsite/anatomy/util/mech-builder.html
T
2026-09-11 03:46:11 +08:00

223 lines
17 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mechanism Builder Page | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Mechanism Builder Page | HiAPI-C# 2025 ">
<link rel="icon" href="../../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../../public/docfx.min.css">
<link rel="stylesheet" href="../../public/main.css">
<meta name="docfx:navrel" content="../../toc.html">
<meta name="docfx:tocrel" content="toc.html">
<meta name="docfx:rel" content="../../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../../index.html">
<img id="logo" class="svg" src="../../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="Anatomy-MechBuilderPage">
<h1 id="mechanism-builder-page">Mechanism Builder Page</h1>
<p>The Mechanism Builder page edits a standalone <a class="xref" href="../../api/Hi.Mech.GeneralMechanism.html">GeneralMechanism</a> — its anchor topology, per-branch <code>ITransformer</code>, and per-anchor optional geometry inside a <code>Solid</code>. Unlike the project-scoped editors (Fixture / Workpiece / ToolHouse / Spindle Capability), this page is <strong>user-scoped</strong> — no project needs to be loaded.</p>
<ul>
<li>Key Model: <a class="xref" href="../../api/Hi.Mech.GeneralMechanism.html">GeneralMechanism</a></li>
<li>Related Model:
<ul>
<li><a class="xref" href="../../api/Hi.Numerical.Xyzabc.GeneralXyzabcChain.html">GeneralXyzabcChain</a> + <a class="xref" href="../../api/Hi.NcMech.Xyzabc.GeneralXyzabcMachineTool.html">GeneralXyzabcMachineTool</a> (used by &ldquo;Save As Machine Tool&rdquo;)</li>
</ul>
</li>
</ul>
<h2 id="layout">Layout</h2>
<ul>
<li>Mechanism Builder Page
<ul>
<li>Three Fixed Columns — equal width, separated by 1px borders, none of them draggable. Every column keeps its header pinned; the graph and the editor cards scroll inside their own region below it.</li>
<li>Column 1: Graph
<ul>
<li>Title + File Menu + Add Anchor Button.
<ul>
<li>File Menu
<ul>
<li>New — discards the current mechanism and starts an empty one with a root anchor.</li>
<li>Load… — opens the server file picker (Admin / Project / Resource) filtered to <code>*.GeneralMechanism</code> / <code>*.xml</code>; the backend parses the picked file in place and records its directory so ReLoad can re-read it. <strong>That filter matches none of the shipped mechanisms</strong>, which are named <code>.general-mech</code> beside the machine tool they belong to; the dialog's appended All Files entry is what reaches them, and the backend parses whatever is picked.</li>
<li>ReLoad — re-parses the file last loaded (disabled until a file has been loaded). The entry is spelled <code>ReLoad</code>, with the second capital.</li>
<li>Save As General Mechanism — writes a <code>.GeneralMechanism</code> XML to the picked server location and retargets ReLoad at it.</li>
<li>Save As Machine Tool — wraps the mechanism in a <a class="xref" href="../../api/Hi.NcMech.Xyzabc.GeneralXyzabcMachineTool.html">GeneralXyzabcMachineTool</a> and writes a <code>.MachineTool</code> XML to the picked server location, leaving the open-mechanism pointer where it is. The envelope is the Xyzabc machine tool; the menu entry names neither that nor the file type.</li>
</ul>
</li>
<li>Add Anchor — creates a standalone anchor, connected to nothing, and selects it.</li>
</ul>
</li>
<li>File Line — the loaded file's relative path, or an &ldquo;unsaved&rdquo; caption while the mechanism has no file.</li>
<li>Graph — mermaid diagram of anchors (nodes) + branches (edges), scrolling inside its own region; node / edge click selects. The selected anchor is filled green and the selected branch's edge is stroked green.</li>
</ul>
</li>
<li>Column 2: Selected Item Editor — content depends on selection:
<ul>
<li><strong>Anchor selected:</strong> header with a Root badge on the root anchor, an Extend button, and a delete button (double-click; absent on the root).
<ul>
<li>Identity Card — the anchor's Guid, an inline name field (debounced), and an &ldquo;Add Branch&rdquo; select that connects this anchor to the picked one.</li>
<li>Geometry Card — a Geometry checkbox attaches or removes the anchor's <code>Solid</code>, and a badge shows the current geometry type. While attached the card carries a display-colour control and mounts the geometry editor over five kinds: <code>Box3d</code>, <code>Cylindroid</code>, <code>StlFile</code>, <a class="xref" href="../../api/Hi.Geom.TransformationGeom.html">TransformationGeom</a> and <code>GeomCombination</code>. <code>CubeTreeFile</code> and <code>ExtendedCylinder</code> are absent because the backend's <code>create-geom</code> does not construct them. <code>TransformationGeom</code> still exposes its own inner geometry and inner transformer through the nested editor.</li>
</ul>
</li>
<li><strong>Branch selected:</strong> header with a delete button (double-click).
<ul>
<li>Identity Card — the branch's Guid, an inline name field (debounced), and the fletch → arrow anchor chips naming the two anchors it joins.</li>
<li>Transformer Card — <a class="xref" href="../geom/transformer-panel.html">Transformer Select Panel</a> (7 transformer kinds).</li>
</ul>
</li>
</ul>
</li>
<li>Column 3: Display — <a class="xref" href="../widget/renderingcanvas-tool-bar.html">RenderingCanvas Tool Bar</a>, a rendering / disconnected badge, and <code>RenderingCanvas</code> bound to <code>DelegateFuncDisplayee(() =&gt; MechService.GeneralMechanism as IDisplayee)</code>.</li>
<li>Server File Picker — one <code>FileExplorerDialog</code> shared by Load and both Save As actions.</li>
</ul>
</li>
</ul>
<h2 id="behavior">Behavior</h2>
<ul>
<li><strong>New-anchor auto-naming.</strong> Newly-created anchors receive placeholder names (<code>NewAnchor-001</code>, <code>NewAnchor-002</code>, …) — the first <code>NewAnchor-{i:000}</code> no descendant anchor already carries. Inline rename is debounced 400 ms.</li>
<li><strong>Extend.</strong> The anchor editor's Extend button creates a new anchor <em>and</em> the branch from the selected one to it in a single call, then selects the new anchor. This is the normal way a chain grows; Add Anchor leaves the new anchor unconnected.</li>
<li><strong>Branch add filter.</strong> The &ldquo;Add Branch&rdquo; select inside the anchor editor filters out the selected anchor itself and anchors already directly connected, in either direction. A new branch starts on <code>NoTransform</code>.</li>
<li><strong>Root protection.</strong> The root anchor cannot be deleted; double-click delete on any other anchor works.</li>
<li><strong>Branch transformer swap.</strong> <code>TransformerSelectPanel</code> uses a parent-aware <code>onCreate</code> hook that calls <code>POST /branch/{id}/update-transformer</code>, so the new transformer takes effect on the next frame without a re-init round-trip. Same idiom as <a class="xref" href="../general-setup/fixture.html">Fixture Page</a>.</li>
<li><strong>Geometry cache invalidation.</strong> Geometry edits POST to <code>anchor/{id}/refresh-geom-cache</code>, which triggers the same <code>Solid.ClearCache()</code> pattern used across the project.</li>
<li><strong>Anchor display colour.</strong> The colour input authors an <code>#rrggbb</code> that persists inside the mechanism's <code>&lt;Solid&gt;</code> element, so every consumer of the file shows the same colour; a reset button drops the authored value and an &ldquo;auto&rdquo; badge marks the stable Guid-seeded fallback the 3D view otherwise renders with. <code>Solid.Display</code> reads the colour per frame, so the canvas follows without a cache refresh.</li>
<li><strong>DelegateFuncDisplayee.</strong> The <code>RenderingCanvas</code> is wired through a delegate so edits render next frame without IndexService churn.</li>
</ul>
<h2 id="source-code-path">Source Code Path</h2>
<p>See <a class="xref" href="../index.html">HiNC App Anatomy</a> for git repository links.</p>
<p>HiNC-2025-webservice (Quasar CLI SPA):</p>
<ul>
<li><code>wwwroot-src/src/pages/MechBuilderPage.vue</code> — routed page at <code>/util/mech-builder</code>: File menu, the three columns, the anchor / branch editors, the display-colour control, the picker wiring and the canvas.</li>
<li><code>wwwroot-src/src/components/mech/MechBuilderGraph.vue</code> — lazy mermaid loader + click-proxy onto mermaid node / edge DOM. Mermaid is dynamic-imported so the first bundle stays slim (~1 MB raw split into its own chunk); labels are emitted quoted, which the parser requires for CJK text.</li>
<li><code>wwwroot-src/src/components/widgets/FileExplorerDialog.vue</code> — the server file picker behind Load and both Save As actions.</li>
<li><code>wwwroot-src/src/components/geom/GeometryEditor.vue</code> — the geometry switchboard the anchor's Geometry card mounts.</li>
<li><code>wwwroot-src/src/components/topo/TransformerSelectPanel.vue</code> — the branch transformer switchboard.</li>
<li><code>wwwroot-src/src/api/generalMechanism.ts</code> — typed wrapper over <code>/api/general-mechanism/*</code>, including the three server-file operations and the anchor colour endpoints.</li>
<li><code>wwwroot-src/src/api/transformer.ts</code> — the seven transformer kinds and their <code>New</code> endpoints.</li>
<li><code>wwwroot-src/src/api/geometry.ts</code> — <code>GeometryKind</code>, the union the anchor's allowed kinds are drawn from.</li>
<li><code>wwwroot-src/src/utils/path.ts</code> — <code>stripDefaultMarker</code>, which sheds the <code>.default</code> ownership marker from the name offered on save.</li>
<li><code>wwwroot-src/src/router/routes.ts</code> — <code>/util/mech-builder</code> entry (route name <code>util-mech-builder</code>).</li>
<li><code>wwwroot-src/src/components/AppMenuBar.vue</code> — <code>Page → Mechanism Builder</code> entry.</li>
<li><code>Mech/MechBuilder/GeneralMechanismService.cs</code> — DI singleton that holds the current mechanism + last <code>BaseDirectory</code> + <code>RelFile</code>.</li>
<li><code>Mech/MechBuilder/GeneralMechanismController.cs</code> — <code>/api/general-mechanism/*</code> CRUD over anchors / branches / per-anchor geometry and colour; server-side Load, Reload and XML Save As for both <code>GeneralMechanism</code> and <code>GeneralXyzabcMachineTool</code> envelopes.</li>
<li><code>Mech/MechBuilder/GeneralMechanismDisplayController.cs</code> — <code>/api/general-mechanism/display/*</code> view init and the isometric reset-view.</li>
<li><code>Common/NamedRootResolver.cs</code> — resolves the three named roots the picker offers.</li>
<li><code>Program.cs</code> — registers <code>GeneralMechanismService</code> as a DI singleton.</li>
</ul>
<h2 id="indexservice-keys">IndexService Keys</h2>
<p>The mechanism state is persistent across pages (unlike Fixture which re-initialises on mount), so mechanism keys are <strong>not</strong> registered with <code>useCleanupHub</code>. Stale keys are harmless; they are re-pointed on the next <code>index-transformer</code> / <code>index-geom</code> call.</p>
<ul>
<li><code>general-mechanism.current</code> — the mechanism itself (informational; <code>DelegateFuncDisplayee</code> bypasses IndexService at render time).</li>
<li><code>general-mechanism.branch.{guid:N}.transformer</code> — stable per-branch transformer key used by <code>TransformerSelectPanel</code>.</li>
<li><code>general-mechanism.anchor.{guid:N}.geom</code> — stable per-anchor key for whatever geometry the anchor's <code>Solid</code> holds, used by <code>GeometryEditor</code>. <code>index-geom</code> indexes that geometry without replacing it, so re-selecting an anchor leaves a non-<code>TransformationGeom</code> geometry intact.</li>
</ul>
<h2 id="file-io">File IO</h2>
<p>Load and both Save As actions go through one server file picker — the File Explorer's dialog wrapper — over the three named roots <code>AdminDirectory</code> / <code>ProjectDirectory</code> / <code>ResourceDir</code>. The XML is read and written by the backend at the picked path; nothing travels through the browser. The picker opens on the root and folder of the last successful operation, starting at <code>ResourceDir</code>, where the shipped mechanism templates live, and a save offers the current file's name with the <code>.default</code> ownership marker stripped and the target extension forced (<code>.GeneralMechanism</code> or <code>.MachineTool</code>).</p>
<p>The File menu has New / Load… / ReLoad plus the two Save As entries; there is no plain &ldquo;Save&rdquo; that overwrites the last path. Saving a General Mechanism retargets ReLoad at the new file; saving a Machine Tool deliberately does not, because it is a separate file type that does not replace the open mechanism pointer.</p>
<h2 id="see-also">See Also</h2>
<ul>
<li><a class="xref" href="../general-setup/fixture.html">Fixture Page</a> — parent-aware <code>onCreate</code> transformer rebind pattern reused for Branch.</li>
<li><a class="xref" href="../geom/transformer-panel.html">Transformers</a> — the shared 7-transformer switchboard.</li>
<li><a class="xref" href="../geom/geometry-editor.html">Geometry Management Control</a> — embedded under the anchor editor.</li>
<li><a class="xref" href="../general-setup/machine-tool.html">Machine Tool</a> — where a project's chain is loaded, replaced and previewed, next to this user-scoped builder.</li>
<li><a href="file-explorer.html">File Explorer</a> — the server-side browser this page's Load and Save As dialogs are built on.</li>
<li><a class="xref" href="../general-setup/spindle-capability.html">Spindle Capability Page</a> — the project-scoped editor with the same Load / Reload / Save As pattern.</li>
<li><a href="../../manual/utilities/mech-builder.html">Mechanism Builder (manual)</a> — the end-user task: driving this editor, and what a machine chain built in it must be named.</li>
</ul>
</article>
<div class="contribution d-print-none">
</div>
<div class="next-article d-print-none border-top" id="nextArticle"></div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>