Add 27-model production-line Web FreeCAD course tooling and pages

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 04:16:04 +08:00
parent 789e18ca3e
commit 4eff6110e7
447 changed files with 29820 additions and 71 deletions

View File

@@ -0,0 +1,81 @@
// Shared project-page actions for the production-line course drivers.
import fs from "node:fs";
import { fileURLToPath } from "node:url";
export const REFERENCE_DIR = "/home/mes123456/FreeCADWasmDev/working/GLTFmodel";
export const footerStatus = page => page.locator('footer [role="status"]').textContent().catch(() => "");
export const treeLabels = page => page.locator(".fc-tree-text").allTextContents();
export async function newDocument(page) {
await page.locator('nav[aria-label="Application menus"] details').filter({ hasText: "File" }).locator("summary").click();
await page.getByRole("button", { name: "新建 Document" }).click();
await page.waitForTimeout(2000);
// The File details menu stays open otherwise and covers the tree/toolbar in
// every subsequent still; close it after creating the document.
await page.evaluate(() => {
for (const details of document.querySelectorAll('nav[aria-label="Application menus"] details[open]')) details.open = false;
});
await page.waitForTimeout(250);
}
export async function openFiles(page) {
await page.evaluate(() => {
const details = document.querySelector(".file-tools");
if (details) details.open = true;
});
await page.waitForTimeout(300);
}
export async function importReference(page, file, timeoutSeconds = 180) {
await openFiles(page);
await page.locator('input[aria-label="Import SCAD, CSG, JT, PLMXML, STEPZ, 3MF or shape files"]').setInputFiles(file);
let status = "";
for (let attempt = 0; attempt < timeoutSeconds; attempt++) {
await page.waitForTimeout(1000);
status = await footerStatus(page);
if (/Imported|failed|error|requires|cancel/i.test(status ?? "")) break;
}
return status;
}
export async function orbit(page, dx, dy) {
const view = page.locator('[aria-label="Imported native 3D view"]').first();
const box = await view.boundingBox();
if (!box) return false;
const x = box.x + box.width / 2; const y = box.y + box.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + dx, y + dy, { steps: 18 });
await page.mouse.up();
await page.waitForTimeout(400);
return true;
}
export const spec = () => JSON.parse(fs.readFileSync(
fileURLToPath(new URL("../line-spec.json", import.meta.url)), "utf8"));
export const modelParts = name => {
const model = spec().models.find(item => item.name === name);
if (!model) throw new Error(`line-spec has no model ${name}`);
return model.parts;
};
export async function openLineReference(page) {
await page.getByRole("button", { name: "Toggle line reference viewer" }).click();
const panel = page.getByRole("complementary", { name: "Line reference viewer" });
await panel.waitFor({ state: "visible", timeout: 30000 });
return panel;
}
export async function selectReferenceModel(panel, page, label, expected = /个网格/) {
const select = panel.locator('select[aria-label="Reference model"]');
await select.selectOption({ label });
let footer = "";
for (let attempt = 0; attempt < 100; attempt++) {
await page.waitForTimeout(500);
footer = await panel.locator("footer").textContent().catch(() => "");
if (expected.test(footer ?? "")) return footer;
}
return footer;
}