Files
FreeCADWasmDev/web/teaching/index.html

288 lines
20 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>FreeCAD Web 官方案例验收 · 初学者教学手册</title>
<style>
:root{
--bg:#0d1319; --panel:#151d25; --panel2:#1b252f; --line:#2a3742;
--text:#e7edf3; --muted:#93a7b4; --accent:#4fb3c8; --ok:#7fdc9f; --warn:#f2c46d; --bad:#ff9e9e;
--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--text);font:16px/1.75 -apple-system,"Segoe UI","Noto Sans SC",system-ui,sans-serif}
header{position:sticky;top:0;z-index:10;background:rgba(13,19,25,.94);backdrop-filter:blur(8px);border-bottom:1px solid var(--line)}
.bar{max-width:1080px;margin:0 auto;padding:14px 22px;display:flex;align-items:center;gap:14px}
.brand{background:var(--accent);color:#071219;font-weight:800;border-radius:6px;padding:5px 9px}
.bar h1{font-size:17px;margin:0;font-weight:600}
.bar nav{margin-left:auto;display:flex;gap:16px;flex-wrap:wrap}
.bar nav a{color:var(--muted);text-decoration:none;font-size:14px}
.bar nav a:hover{color:var(--accent)}
main{max-width:1080px;margin:0 auto;padding:32px 22px 96px}
h2{font-size:26px;margin:56px 0 8px;padding-top:8px}
h3{font-size:19px;margin:32px 0 6px;color:#cfe0ea}
p{color:#cfdae2}
.lead{font-size:18px;color:#b9cbd7}
.muted{color:var(--muted)}
.card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:20px 22px;margin:18px 0}
.grid{display:grid;gap:16px}
.grid.two{grid-template-columns:repeat(auto-fit,minmax(280px,1fr))}
.grid.three{grid-template-columns:repeat(auto-fit,minmax(210px,1fr))}
.stat{background:var(--panel2);border:1px solid var(--line);border-radius:10px;padding:16px 18px}
.stat b{display:block;font-size:30px;line-height:1.1;color:var(--accent)}
.stat span{font-size:13px;color:var(--muted)}
figure{margin:20px 0}
figure img{width:100%;border-radius:10px;border:1px solid var(--line);display:block}
figcaption{font-size:13px;color:var(--muted);margin-top:8px}
code,kbd{font-family:var(--mono);font-size:13.5px;background:#0a1016;border:1px solid var(--line);border-radius:4px;padding:1px 5px}
pre{background:#0a1016;border:1px solid var(--line);border-radius:10px;padding:14px 16px;overflow:auto;font-size:13.5px;line-height:1.6}
pre code{background:none;border:0;padding:0}
ol.steps{counter-reset:step;list-style:none;padding:0;margin:18px 0}
ol.steps>li{counter-increment:step;position:relative;padding:18px 20px 18px 66px;background:var(--panel);border:1px solid var(--line);border-radius:12px;margin-bottom:14px}
ol.steps>li::before{content:counter(step);position:absolute;left:18px;top:16px;width:32px;height:32px;border-radius:50%;background:var(--accent);color:#071219;font-weight:800;display:grid;place-items:center}
ol.steps>li h4{margin:0 0 6px;font-size:17px}
table{border-collapse:collapse;width:100%;max-width:100%;font-size:14.5px;margin:14px 0;table-layout:fixed}
td,th{overflow-wrap:anywhere;word-break:break-word}
td code,th code{overflow-wrap:anywhere;white-space:normal}
th,td{border-bottom:1px solid var(--line);padding:9px 10px;text-align:left;vertical-align:top}
th{color:var(--muted);font-weight:600;font-size:13px;letter-spacing:.04em}
.pill{display:inline-block;font-size:12px;border-radius:999px;padding:2px 10px;border:1px solid var(--line);color:var(--muted)}
.pill.ok{color:var(--ok);border-color:#2f6b45;background:#12281c}
.pill.warn{color:var(--warn);border-color:#6b5526;background:#2a2312}
.cta{display:inline-block;background:var(--accent);color:#071219;font-weight:700;text-decoration:none;padding:11px 20px;border-radius:8px;margin:6px 8px 6px 0}
.cta.secondary{background:transparent;color:var(--accent);border:1px solid var(--accent)}
.note{border-left:3px solid var(--accent);padding-left:14px;color:#b9cbd7}
.toc{columns:2;column-gap:32px;font-size:15px}
.toc a{color:#b9cbd7;text-decoration:none;display:block;padding:3px 0}
.toc a:hover{color:var(--accent)}
@media(max-width:640px){
.toc{columns:1}
main{padding:24px 14px 80px}
table{font-size:13px}
th,td{padding:7px 6px}
pre{font-size:12px;white-space:pre-wrap}
ol.steps>li{padding:16px 14px 16px 56px}
ol.steps>li::before{left:12px;width:28px;height:28px;font-size:13px}
}
footer{border-top:1px solid var(--line);color:var(--muted);font-size:13px;padding:24px 22px;text-align:center}
</style>
</head>
<body>
<header>
<div class="bar">
<span class="brand">FreeCAD Web</span>
<h1>官方案例验收 · 初学者教学手册</h1>
<nav>
<a href="#overview">概览</a>
<a href="#pipeline">验收流程</a>
<a href="#walkthrough">动手演示</a>
<a href="#glossary">术语</a>
<a href="features.html">功能列表</a>
<a href="runner.html">可视化执行 →</a>
</nav>
</div>
</header>
<main>
<section id="overview">
<p class="lead">这本手册面向第一次接触本项目的同学。它讲清楚一件事:<strong>为什么我们要在浏览器里,把 FreeCAD 桌面版的官方测试逐条重新跑一遍,并且怎么亲手跑。</strong></p>
<div class="grid three" id="stats">
<div class="stat"><b id="stat-total">278</b><span>已通过验收的官方案例</span></div>
<div class="stat"><b id="stat-exec">95</b><span>可一键可视化执行</span></div>
<div class="stat"><b id="stat-img">72</b><span>带现场截图证据</span></div>
</div>
<h2>这个项目在做什么</h2>
<p>FreeCAD 是一个开源的三维 CAD 软件,正常情况下它运行在桌面上,底层是 C++,界面用 Qt。本项目要把它移植成一份<strong>纯浏览器版本</strong>:C++ 内核编译成 WebAssembly,界面用 React 重写。移植最大的风险不是"能不能打开",而是<strong>"行为和桌面版是否一致"</strong>。</p>
<p>所以我们的验收方法是:把 FreeCAD 自带的官方测试用例(比如 <code>Mod/PartDesign/PartDesignTests/TestPad.py</code>)当作"考卷",在 Web 版里用真实的运行链路把它跑一遍,再和桌面版的结果逐项对比。每条通过验收的考卷,就是账本(ledger)里的一条 <code>passed</code> 记录。目前 324 条候选里有 <strong>278 条</strong>已经通过。</p>
<div class="card">
<h3 style="margin-top:0">一句话记住三条线</h3>
<table>
<tr><th>线</th><th>在哪</th><th>作用</th></tr>
<tr><td>桌面依据</td><td><code>freecad-source/src/Mod/...</code></td><td>官方的 Python 测试代码,是我们唯一的"正确答案"</td></tr>
<tr><td>Web owner</td><td><code>web/src/...</code> + <code>freecad-source/src/WebAssembly/...</code></td><td>用 React 和 WASM 实现同样的能力,并由它对外提供命令入口</td></tr>
<tr><td>证据与账本</td><td><code>docs/current/business-evidence/</code> 与 <code>web/docs/current/freecad-official-case-ledger.json</code></td><td>把每次验证的现场(截图、JSON 结果)和结论固化下来</td></tr>
</table>
</div>
</section>
<section id="pipeline">
<h2>一次验收要经过什么</h2>
<p>这是本项目约定的统一顺序。初学者最容易犯的错是:页面一打开就急着断言"产品坏了",其实大多数时候是<strong>前置条件没准备好</strong>。</p>
<figure>
<svg viewBox="0 0 980 250" role="img" aria-label="验收管线:从桌面依据到账本记账" style="width:100%;height:auto;background:#0a1016;border:1px solid #2a3742;border-radius:10px">
<defs><marker id="arw" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 z" fill="#4fb3c8"/></marker></defs>
<g font-family="ui-monospace,monospace" font-size="13" fill="#e7edf3">
<g fill="#151d25" stroke="#2a3742">
<rect x="14" y="60" width="150" height="70" rx="8"/><rect x="184" y="60" width="150" height="70" rx="8"/>
<rect x="354" y="60" width="150" height="70" rx="8"/><rect x="524" y="60" width="150" height="70" rx="8"/>
<rect x="694" y="60" width="130" height="70" rx="8"/><rect x="844" y="60" width="122" height="70" rx="8"/>
</g>
<g fill="#4fb3c8"><text x="30" y="88">① 桌面依据</text><text x="200" y="88">② Web owner</text><text x="370" y="88">③ host / server</text><text x="540" y="88">④ fixture</text><text x="706" y="88">⑤ Worker/WASM</text><text x="860" y="88">⑥ 断言</text></g>
<g fill="#93a7b4" font-size="11.5">
<text x="30" y="108">官方测试代码</text><text x="30" y="122">是唯一正确答案</text>
<text x="200" y="108">React + C++ owner</text><text x="200" y="122">提供命令实现</text>
<text x="370" y="108">页面能被打开</text><text x="370" y="122">端口 / 视图就绪</text>
<text x="540" y="108">文档与对象</text><text x="540" y="122">准备好再跑</text>
<text x="706" y="108">原生内核</text><text x="706" y="122">真正算出结果</text>
<text x="860" y="108">执行并对比</text><text x="860" y="122">桌面 vs Web</text>
</g>
<g stroke="#4fb3c8" stroke-width="1.5" marker-end="url(#arw)">
<line x1="164" y1="95" x2="182" y2="95"/><line x1="334" y1="95" x2="352" y2="95"/><line x1="504" y1="95" x2="522" y2="95"/><line x1="674" y1="95" x2="692" y2="95"/><line x1="824" y1="95" x2="842" y2="95"/>
</g>
<g fill="#93a7b4" font-size="12">
<text x="14" y="170">⑦ 双视口(1440×900 桌面 / 390×844 移动)→ 页面无横向溢出、无 pageErrors</text>
<text x="14" y="192">⑧ 产品行为与保存回开 → 改参数、重算、存盘、重开,对象与属性一致</text>
<text x="14" y="214">⑨ 证据落盘 → docs/current/business-evidence/&lt;case&gt;/ 下的截图与 JSON</text>
<text x="14" y="236" fill="#7fdc9f">⑩ 64 项工作台审计 + 账本记账 → status=passed,acceptancePassed=true</text>
</g>
</g>
</svg>
<figcaption>图 1 验收管线的十个环节。前面任何一步不满足,都不能跳到⑥断言,更不能把前置失败记成产品回归。</figcaption>
</figure>
<h3>为什么要分"前置失败"和"产品回归"</h3>
<p>项目里出过真实教训:某个脚本因为工作目录不对,报 <code>MODULE_NOT_FOUND</code>,被误判为"产品失败"。后来定下铁律:日志很小且含 <code>Cannot find module</code>、<code>No such file or directory</code> 时,一律记为<strong>前置失败</strong>,先补前置,不得据此记账。</p>
<div class="note">初学者记忆法:<strong>先问"我准备好了吗",再问"软件做对了吗"。</strong></div>
</section>
<section id="checks">
<h2>一条案例要过哪七道关</h2>
<table id="checks-table">
<tr><th>关卡</th><th>含义</th><th>怎么算通过</th></tr>
<tr><td>前置条件 <code>preflightPassed</code></td><td>入口、fixture、Worker、端口都就绪</td><td>缺任何一项先补,不算产品失败</td></tr>
<tr><td>native 结果 <code>nativeResultVerified</code></td><td>WASM 内算出的数值与桌面一致</td><td>体积、坐标、对象数等按类型比较</td></tr>
<tr><td>保存回开 <code>saveReopenVerified</code></td><td>存盘后重新打开,数据不变</td><td>对象与属性逐项对比</td></tr>
<tr><td>桌面视口 <code>desktopViewportVerified</code></td><td>1440×900 下界面正常</td><td>无溢出、无 pageErrors、在视口内</td></tr>
<tr><td>移动视口 <code>mobileViewportVerified</code></td><td>390×844 下界面正常</td><td>同上</td></tr>
<tr><td>64 项审计 <code>audit64Passed</code></td><td>32 个模块 × 2 个视口</td><td>64 条记录全部通过</td></tr>
<tr><td>总验收 <code>acceptancePassed</code></td><td>以上全部满足</td><td>账本行记为 <code>passed</code></td></tr>
</table>
</section>
<section id="walkthrough">
<h2>动手演示:跑通一条案例</h2>
<p>下面这条案例是 <code>real.Inspection:inspection.createRecompute</code>,它在 Web 端创建 Inspection 对象并做一次重算。跟着做一遍,你就掌握了整个验收动作。</p>
<ol class="steps">
<li>
<h4>确认服务已经开着</h4>
<p>Web 应用运行在 <code>http://127.0.0.1:5180</code>。打开终端先探一下:</p>
<pre><code>curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:5180/
# 期望输出:200</code></pre>
<p class="muted">如果不是 200,先启动 Web 服务,再继续。这就是"前置条件"。</p>
</li>
<li>
<h4>打开工作台并选中命令</h4>
<p>直接访问带参数的地址,页面会自动选中 Inspection 模块和该命令:</p>
<pre><code>http://127.0.0.1:5180/workbench.html?module=Inspection&amp;command=inspection.createRecompute</code></pre>
<p>页面左侧是模块列表,中间是命令参数 JSON,右侧是执行结果。</p>
</li>
<li>
<h4>检查参数与状态</h4>
<p>参数框里应该已经有官方 fixture(<code>PAYLOADS</code> 注册的默认参数)。如果没有,就手动填 <code>{}</code>。注意页面 URL 上的 <code>module</code> 和 <code>command</code> 只有命中注册表才会生效。</p>
</li>
<li>
<h4>点击"执行选中命令"</h4>
<p>按钮会真正把请求发进 Worker,由 WASM 内核执行,再把结果回传给页面。稍等一两秒,右侧出现 JSON 结果:</p>
<pre><code>{
"schema": "freecad-web-inspection/create-recompute/v1",
"inspection": { "distanceCount": 8, "rms": 0, "hasError": 0 },
"recompute": { "count": 1, "hasError": 0 },
"resourcesReleased": true
}</code></pre>
</li>
<li>
<h4>核对数值与状态</h4>
<p>和桌面结果比对。注意按<strong>真实类型</strong>比较:数值带容差,字符串用前缀或子串,Vector 用 <code>isEqual</code>,对象按标识比较。</p>
</li>
<li>
<h4>截屏并记录证据</h4>
<p>截图存到 <code>docs/current/business-evidence/&lt;case&gt;/</code>,并把结果 JSON 一起写入。这一步是"证据"。可视化执行页已经帮你自动截图并写入 <code>docs/current/teaching-runs/</code>。</p>
</li>
<li>
<h4>记账</h4>
<p>七道关全过之后,才更新账本行。项目提供了统一入口,不要手工改 JSON:</p>
<pre><code>node tools/close-official-case.mjs \
--case &lt;caseId&gt; \
--evidence &lt;repo-relative-path&gt; \
--note "一句话说明"</code></pre>
</li>
</ol>
<p><a class="cta" href="runner.html">打开可视化执行页</a><a class="cta secondary" href="features.html">查看 32 个模块的功能列表</a><a class="cta" href="cases/engine-block.html">案例教学:4 缸发动机缸体</a><a class="cta secondary" href="cases/t1-replica.html">案例教学:照 t1.stp 复刻零件</a><a class="cta secondary" href="cases/secondary-reducer.html">案例教学:二级齿轮减速器(界面操作)</a><a class="cta" href="cases/assembly-tolerance.html">案例教学:装配公差分析(初学者)</a><a class="cta" href="cases/cam-teaching.html">案例教学:三轴 CAM(初学者)</a><a class="cta" href="cases/carrier.html">案例教学:航空母舰(含培训视频)</a><a class="cta" href="cases/fem-cantilever.html">案例教学:FEM 悬臂梁(应力云图)</a><a class="cta" href="cases/production-line.html">案例教学:三维产线(有头界面 + MCP)</a><a class="cta" href="cases/abb120-line.html">案例教学:ABB IRB 120 产线(MCP)</a><a class="cta" href="cases/production-line-course.html">视频课程:27 件 GLB 产线建模(18 集)</a><a class="cta secondary" href="z-up-verification.html">Three.js Z-up 验证报告</a><a class="cta" href="http://127.0.0.1:5180/bim-workshop.html">BIM 厂房车间(30×18m)</a><a class="cta secondary" href="bim-workshop-tutorial.html">BIM 厂房教程</a><a class="cta secondary" href="bim-workshop-manual.html">BIM 厂房初学者手册(视频)</a><a class="cta secondary" href="http://127.0.0.1:5180/workbench.html?module=Inspection&amp;command=inspection.createRecompute" target="_blank" rel="noopener">直接打开这条案例</a></p>
</section>
<section id="gallery">
<h2>验收现场长什么样</h2>
<p>下面是从真实证据目录里挑出的截图。它们记录了浏览器中的实际结果,而不是示意图。</p>
<div class="grid two" id="gallery-grid"></div>
<h3>教学目录自身的实景</h3>
<p class="muted">下面两张截图来自本手册页面与执行页在真实 Chrome 中的运行结果(1440×900)。</p>
<div class="grid two">
<figure style="margin:0">
<img src="/evidence/current/teaching-manual-20261104/manual-desktop-top.png" alt="教学手册首页实景" />
<figcaption>手册首页:概览、统计与管线示意</figcaption>
</figure>
<figure style="margin:0">
<img src="/evidence/current/teaching-manual-20261104/runner-desktop.png" alt="可视化执行页实景" />
<figcaption>执行页:278 条案例列表与详情</figcaption>
</figure>
</div>
</section>
<section id="glossary">
<h2>术语小词典</h2>
<table>
<tr><th>词</th><th>用大白话解释</th></tr>
<tr><td>WASM / WebAssembly</td><td>一种能在浏览器里高速运行的二进制格式。我们把 FreeCAD 的 C++ 内核编译成它。</td></tr>
<tr><td>Worker</td><td>浏览器里的后台线程。内核在 Worker 里跑,避免卡住界面。</td></tr>
<tr><td>Probe(探针)</td><td>一个专门用来"问内核问题"的小程序。比如 Test 探针负责跑 Python 语法检查。</td></tr>
<tr><td>fixture</td><td>测试用的固定输入。比如一个已经画好盒子的文档。</td></tr>
<tr><td>owner</td><td>某项能力的"负责人"代码。Web 端用 React/TS 实现界面语义,用 C++ 实现内核能力。</td></tr>
<tr><td>ledger(账本)</td><td><code>freecad-official-case-ledger.json</code>,记录每条案例的状态和证据。</td></tr>
<tr><td>preflight(前置)</td><td>跑产品断言之前必须准备好的条件。</td></tr>
<tr><td>viewport(视口)</td><td>浏览器可见区域大小。我们固定测桌面和移动两种。</td></tr>
</table>
</section>
<section id="toc">
<h2>按模块浏览</h2>
<div class="toc" id="module-toc"></div>
</section>
</main>
<footer>FreeCAD Web 教学目录 · 数据来自 <code>web/teaching/data/cases.json</code>(由账本自动生成)· 由可视化执行页可逐条运行</footer>
<script type="module">
const data = await fetch("./data/cases.json").then(r => r.json()).catch(() => null);
if (data) {
document.getElementById("stat-total").textContent = data.total;
document.getElementById("stat-exec").textContent = data.executable;
document.getElementById("stat-img").textContent = data.withImage;
const toc = document.getElementById("module-toc");
const counts = new Map();
for (const item of data.cases) {
const key = item.module || "(未分类)";
counts.set(key, (counts.get(key) || 0) + 1);
}
toc.innerHTML = [...counts.entries()].sort((a, b) => b[1] - a[1])
.map(([name, count]) => `<a href="runner.html#module-${encodeURIComponent(name)}">${name} <span class="muted">(${count})</span></a>`).join("");
const gallery = document.getElementById("gallery-grid");
const withImages = data.cases.filter(item => item.hasImage).slice(0, 4);
gallery.innerHTML = withImages.map(item => {
const shot = item.evidence.find(e => e.kind === "image" && e.exists);
return `<figure style="margin:0"><img loading="eager" src="${shot.url}" alt="${item.title} 验收截图"><figcaption>${item.module} · ${item.command || item.title}</figcaption></figure>`;
}).join("");
}
</script>
</body>
</html>