Remove OpenSCAD from the web port
Web FreeCAD does not implement OpenSCAD. Drop the module end to end instead of keeping a blocked or placeholder shell: - delete the parity-matrix row and regenerate the module registry (31 modules, OpenSCAD absent) - remove the OpenSCAD-only frontend modules (worker, facades, slice, mesh backend, desktop/preferences tasks) and strip the OpenSCAD branches from the dispatchers, shells, storage and router - neutralise the two shared owners that outlived the module: openscad-desktop-view -> scene-viewport (SceneViewport) and openscad-desktop-adapter -> scene-document (SceneDocument), so Part, Mesh and the other consumers keep working - drop the FreeCADWebOpenSCADRuntimeProbe target and FREECAD_WEB_ENABLE_OPENSCAD option from the kernel CMake; BUILD_OPENSCAD stays in the forced-off list - delete web/openscad.html, its Vite input, the kernel artifacts and the 17 OpenSCAD tool entry points AGENTS.md records the removal rule. tsc --noEmit is clean and grep -ri openscad web/src is empty. Also carry the Boost pthread guard: under Emscripten a plain -lpthread implies -sUSE_PTHREADS=1 and therewith --shared-memory, which the non-atomics VTK archives cannot link against. Validation NOT_RUN / PARTIAL_FAILED, Acceptance NOT_CLAIMED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
165
tools/part-section-cut-opacity-cases.mjs
Normal file
165
tools/part-section-cut-opacity-cases.mjs
Normal file
@@ -0,0 +1,165 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
import { playwright } from "./part-primitive-business-cases.mjs";
|
||||
|
||||
export async function runSectionCutOpacityCases(ids) {
|
||||
const capabilityId = "Part:desktop:Part_SectionCut";
|
||||
if (!ids.includes(capabilityId)) return [];
|
||||
const directory = path.resolve("docs/current/part-section-cut-opacity", new Date().toISOString().replace(/[:.]/g, "-"));
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
const result = { capabilityId, status: "failed", cases: [], evidenceFiles: {},
|
||||
deferredCases: ["runLegacySectionCutCases", "runSectionCutEmptySourcesCases", "runSectionCutFragmentsCases"],
|
||||
remaining: ["Automatic cut-face coloring and color controls", "Independent cut-face and fragment appearance/transparency"] };
|
||||
const record = (input, actual, name) => {
|
||||
result.cases.push({ input, actual, assertions: [{ name, passed: true }] });
|
||||
fs.writeFileSync(path.join(directory, "result.json"), JSON.stringify(result, null, 2) + "\n");
|
||||
};
|
||||
const session = state => state.objects.find(item => item.sectionCutSession)?.sectionCutSession;
|
||||
const objects = state => Object.fromEntries(state.objects.map(item => [item.name, item]));
|
||||
const signature = state => ({ objects: objects(state), undoCount: state.undoCount, redoCount: state.redoCount });
|
||||
const near = (a, b) => assert.ok(Number.isFinite(a) && Math.abs(a - b) < 1e-6, `${a} != ${b}`);
|
||||
const check = (state, transparency, volume = 800) => {
|
||||
const cut = state.objects.find(item => item.name === session(state).result);
|
||||
assert.equal(session(state).resultTransparency, transparency);
|
||||
near(cut.displayOpacity, 1 - transparency / 100); near(cut.volume, volume);
|
||||
assert.equal(cut.topology.valid, true); assert.ok(cut.mesh.triangleCount > 0);
|
||||
for (const name of session(state).sources) assert.equal(state.objects.find(item => item.name === name).displayOpacity, undefined);
|
||||
return cut;
|
||||
};
|
||||
let browser;
|
||||
try {
|
||||
for (const file of ["tools/part-section-cut-opacity-cases.mjs", "tools/part-section-cut-business-cases.mjs",
|
||||
"web/src/part-section-cut-task.tsx", "web/src/part-desktop-adapter.ts", "web/src/part-document-facade.ts",
|
||||
"web/src/workbench-shell.tsx", "web/src/scene-viewport.tsx", "web/src/scene-document.ts",
|
||||
"freecad-source/src/WebAssembly/FreeCADCoreProbe/PartSectionCutDocument.h",
|
||||
"freecad-source/src/WebAssembly/FreeCADCoreProbe/DocumentProbe.cpp",
|
||||
...["js", "wasm", "worker.js"].map(ext => `web/public/kernel/FreeCADWebDocumentProbe.${ext}`)])
|
||||
result.evidenceFiles[file] = createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
||||
browser = await playwright().chromium.launch({ executablePath: process.env.FREECAD_CHROME ?? "/usr/bin/google-chrome",
|
||||
headless: process.env.HEADLESS !== "0", args: ["--no-sandbox", "--disable-dev-shm-usage"] });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
|
||||
const errors = []; page.on("pageerror", error => errors.push(String(error)));
|
||||
const documentId = "SectionCutOpacity";
|
||||
await page.goto(`${process.env.FREECAD_BROWSER_ORIGIN ?? "http://127.0.0.1:5180"}/workbench.html?module=Part&command=part.document&document=${documentId}`);
|
||||
const run = async (args, expectError = false) => {
|
||||
await page.locator("aside > button.command").filter({ has: page.locator("span", { hasText: /^part.document$/ }) }).click();
|
||||
await page.locator("#payload-editor").fill(JSON.stringify({ schema: "freecad-web-part/document/v1", module: "Part",
|
||||
document: documentId, builderInfo: true, includeMesh: true, ...args }));
|
||||
await page.evaluate(() => { if (window.__freecadWorkbenchState) window.__freecadWorkbenchState.response = null; });
|
||||
await page.getByRole("button", { name: "执行选中命令", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__freecadWorkbenchState?.response && !document.querySelector("button.run")?.disabled);
|
||||
const reply = await page.evaluate(() => window.__freecadWorkbenchState.response);
|
||||
assert.equal(reply.kind, expectError ? "error" : "result", JSON.stringify(reply)); return expectError ? reply.error : reply.result;
|
||||
};
|
||||
const snapshot = () => run({ action: "snapshot" });
|
||||
await run({ action: "create" }); await run({ action: "setBox", object: "A", dimensions: [10, 10, 10] });
|
||||
await run({ action: "setBox", object: "B", dimensions: [10, 10, 10] });
|
||||
await run({ action: "setPosition", object: "B", position: [5, 0, 0] });
|
||||
const other = await run({ action: "create", document: "OpacityOther" }); await snapshot();
|
||||
await page.locator(".matrix-list button").filter({ has: page.locator("span", { hasText: /^Part_SectionCut$/ }) }).click();
|
||||
const panel = page.getByRole("region", { name: "Section cutting", exact: true });
|
||||
const ready = () => page.waitForFunction(() => {
|
||||
const fieldset = document.querySelector('section[aria-label="Section cutting"] fieldset'); return fieldset && !fieldset.disabled;
|
||||
});
|
||||
const click = async name => {
|
||||
await panel.getByRole("button", { name, exact: true }).click(); if (name === "Close section cutting") return;
|
||||
await ready(); assert.deepEqual(await panel.getByRole("status").allTextContents(), []);
|
||||
};
|
||||
const transparency = panel.getByRole("spinbutton", { name: "Result surface transparency", exact: true });
|
||||
const apply = panel.getByRole("button", { name: "Apply section cut", exact: true });
|
||||
const canvas = panel.locator('[aria-label="Section cut geometry"] canvas');
|
||||
const pixels = async name => {
|
||||
const png = await canvas.screenshot();
|
||||
const metrics = await page.evaluate(async base64 => {
|
||||
const image = new Image(); image.src = `data:image/png;base64,${base64}`; await image.decode();
|
||||
const canvas = document.createElement("canvas"); canvas.width = image.width; canvas.height = image.height;
|
||||
const ctx = canvas.getContext("2d"); ctx.drawImage(image, 0, 0);
|
||||
const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data; let contrast = 0;
|
||||
for (let i = 0; i < data.length; i += 4) contrast += Math.abs(data[i] - 241) + Math.abs(data[i+1] - 243) + Math.abs(data[i+2] - 245);
|
||||
return { contrast, width: canvas.width, height: canvas.height };
|
||||
}, png.toString("base64"));
|
||||
const file = path.join(directory, `${name}.png`); fs.writeFileSync(file, png);
|
||||
result.evidenceFiles[path.relative(process.cwd(), file)] = createHash("sha256").update(png).digest("hex");
|
||||
return metrics;
|
||||
};
|
||||
await ready(); await panel.getByRole("checkbox", { name: "Cut X", exact: true }).check();
|
||||
await panel.getByRole("spinbutton", { name: "Cut X position", exact: true }).fill("8");
|
||||
await panel.getByRole("checkbox", { name: "Intersecting objects", exact: true }).check();
|
||||
await click("Apply section cut"); const opaque = await snapshot(); check(opaque, 0);
|
||||
const opaquePixels = await pixels("opaque");
|
||||
await transparency.fill("65"); await click("Apply section cut"); const partial = await snapshot(); check(partial, 65);
|
||||
const partialPixels = await pixels("partial");
|
||||
assert.ok(partialPixels.contrast < opaquePixels.contrast * .85, JSON.stringify({ opaquePixels, partialPixels }));
|
||||
await click("Section cut undo"); assert.equal(await transparency.inputValue(), "0");
|
||||
assert.deepEqual(objects(await snapshot()), objects(opaque));
|
||||
await click("Section cut redo"); assert.equal(await transparency.inputValue(), "65");
|
||||
assert.deepEqual(objects(await snapshot()), objects(partial));
|
||||
await transparency.fill("100"); await click("Apply section cut"); check(await snapshot(), 100);
|
||||
const clearPixels = await pixels("clear");
|
||||
assert.ok(clearPixels.contrast < opaquePixels.contrast * .3, JSON.stringify({ opaquePixels, clearPixels }));
|
||||
assert.ok(partialPixels.contrast > clearPixels.contrast * 1.5);
|
||||
await click("Section cut undo"); check(await snapshot(), 65);
|
||||
record({ values: [0, 65, 100], intersecting: true }, { opaquePixels, partialPixels, clearPixels },
|
||||
"Native opacity changes surface pixels while preserving topology, source appearance, and reversible session state");
|
||||
|
||||
const stable = await snapshot();
|
||||
for (const invalid of [-1, 101, 2.5, "65", null, true]) {
|
||||
const error = await run({ action: "sectionCut", sectionCut: { operation: "apply", axes: session(stable).axes, resultTransparency: invalid } }, true);
|
||||
assert.match(error.message, /Result transparency must be an integer in 0\.\.100/);
|
||||
assert.deepEqual(signature(await snapshot()), signature(stable));
|
||||
}
|
||||
for (const invalid of ["-1", "101", "2.5", ""]) {
|
||||
await transparency.fill(invalid); assert.equal(await apply.isDisabled(), true);
|
||||
assert.deepEqual(signature(await snapshot()), signature(stable));
|
||||
}
|
||||
await click("Refresh section cut"); assert.equal(await transparency.inputValue(), "65");
|
||||
await run({ action: "sectionCut", sectionCut: { operation: "apply", axes: session(stable).axes.map((axis, i) => i ? axis : { ...axis, position: 100 }), resultTransparency: 5 } }, true);
|
||||
assert.deepEqual(signature(await snapshot()), signature(stable));
|
||||
record({ invalidValues: [-1, 101, 2.5, "65", null, true], failedRebuildTransparency: 5 }, { retained: 65 },
|
||||
"Native invalid opacity and geometry failures roll back appearance and history; invalid UI input cannot apply");
|
||||
|
||||
await run({ action: "save", path: "/tmp/SectionCutOpacity.FCStd" }); await run({ action: "close" });
|
||||
const reopened = await run({ action: "open", path: "/tmp/SectionCutOpacity.FCStd" });
|
||||
assert.deepEqual(objects(reopened), objects(stable)); check(reopened, 65);
|
||||
await click("Refresh section cut"); assert.equal(await transparency.inputValue(), "65");
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
const mobilePartial = await pixels("mobile-partial");
|
||||
await transparency.fill("0"); await click("Apply section cut"); const mobileOpaque = await pixels("mobile-opaque");
|
||||
assert.ok(mobilePartial.contrast < mobileOpaque.contrast * .85);
|
||||
await click("Section cut undo"); assert.equal(await transparency.inputValue(), "65"); check(await snapshot(), 65);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
|
||||
record({ operation: "FCStd restore and mobile rendering", viewport: [390, 844] }, { mobilePartial, mobileOpaque },
|
||||
"Saved native opacity restores the control and actual transparent surface on mobile without overflow");
|
||||
|
||||
const edited = await run({ action: "setBox", object: "B", dimensions: [10, 10, 20] }); check(edited, 65, 1100);
|
||||
await click("Refresh cut sources"); check(await snapshot(), 65, 1100);
|
||||
await run({ action: "remove", object: "B" }); check(await snapshot(), 65);
|
||||
await click("Refresh section cut"); assert.equal(await transparency.inputValue(), "65");
|
||||
await run({ action: "remove", object: "A" });
|
||||
const empty = await snapshot(); assert.equal(session(empty).resultTransparency, 65);
|
||||
await run({ action: "setBox", object: "Replacement", dimensions: [10, 10, 10] });
|
||||
await click("Refresh cut sources"); check(await snapshot(), 65);
|
||||
await run({ action: "setBox", object: "Small", dimensions: [1, 1, 1] });
|
||||
await click("Refresh cut sources"); check(await snapshot(), 65);
|
||||
await transparency.fill("25"); await click("Apply section cut");
|
||||
await click("Section cut undo"); const deletionGuard = await snapshot(); check(deletionGuard, 65);
|
||||
assert.ok(deletionGuard.redoCount > 0);
|
||||
const rejectedRemoval = await run({ action: "remove", object: "Replacement" }, true);
|
||||
assert.match(rejectedRemoval.message, /outside source bounds/);
|
||||
assert.deepEqual(signature(await snapshot()), signature(deletionGuard));
|
||||
await click("Section cut redo"); check(await snapshot(), 25);
|
||||
await click("Section cut undo"); check(await snapshot(), 65);
|
||||
await click("Close section cutting"); await panel.waitFor({ state: "detached" });
|
||||
await page.locator(".matrix-list button").filter({ has: page.locator("span", { hasText: /^Part_SectionCut$/ }) }).click();
|
||||
await ready(); assert.equal(await transparency.inputValue(), "65");
|
||||
assert.deepEqual(signature(await run({ action: "snapshot", document: "OpacityOther" })), signature(other));
|
||||
assert.deepEqual(errors, []);
|
||||
record({ operation: "edit source, recollect, fall back to compound, empty session, recover, reject out-of-bounds source removal and reenter" }, { transparency: 65, volume: 800, redoPreserved: true },
|
||||
"Source lifecycle retains result opacity in both modes; failed source removal preserves the executable redo branch and other documents");
|
||||
result.status = "not_implemented";
|
||||
} catch (error) { result.error = String(error.stack ?? error); process.stderr.write(result.error + "\n"); }
|
||||
finally { await browser?.close(); }
|
||||
fs.writeFileSync(path.join(directory, "result.json"), JSON.stringify(result, null, 2) + "\n"); return [result];
|
||||
}
|
||||
Reference in New Issue
Block a user