Files
FreeCADWasmDev/web/tools/cad-ui-rebuild/lib/driver.mjs
wangdequan 87b2a6cb8a feat(carrier): 航空母舰 PartDesign 有头创建工具包与初学者教学
- 新数据链 web/teaching/cases/carrier-partdesign:20 件零件(spec.json 唯一来源)、
  内核建造器 parts/*.mjs、traces/FCStd/replay 全量产物;装配 20 插入 + 19 关节。
- 工具包 tools/carrier:catalog / preflight / create-part / create-assembly /
  create-all / list / self-test / README,按零件与装配拆分为独立工具。
- 共享驱动扩展 web/tools/cad-ui-rebuild:Loft/Pipe/Hole/Fillet/Chamfer/Mirrored/
  LinearPattern 交互,Reversed 复选框补齐;装配 saveAssemblyBundle 先 Accept 再保存。
- 教学:lessons.mjs 新增 carrier 组(环境课 + 20 件 + 装配),suite-runner 增加
  carrier-part/carrier-assembly,生成 carrier-toolkit.html 并接入 index 与控制台证据。

验证:20 件 210 步全部有头通过(P05 修复后 39640 m³;P06 回归 8/8);
装配 20/20 插入、19/19 关节、20 组件 0 畸形、0 mismatch;check:carrier、
check:reducer、check-console --live 全绿。

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-25 18:46:27 +08:00

582 lines
29 KiB
JavaScript

// Drive the real Web FreeCAD UI to rebuild one part, step by step.
//
// Target page is `partdesign.html` (the standalone PartDesign workspace): it is
// the only surface that renders the sketch editor AND the profile features.
// The embedded PartDesign panel on project.html has no sketch controls at all
// (they only appear when the Workbench select is set to Sketcher), so driving it
// would need a workbench round-trip for every sketch.
//
// This exists to PROVE the generated instructions are true: every step in
// out/ui-steps is performed through the same controls a learner would use, and
// the finished volume is compared against the replay's. If the UI cannot express
// a step this driver fails loudly rather than the manual describing an
// impossible operation.
export const PAGE = "partdesign.html";
export async function waitForWorkspace(page) {
await page.waitForSelector('[aria-label="Native PartDesign view"]', { timeout: 180000 });
await page.waitForTimeout(1200);
}
/** Start a fresh document and body, so each part is built in isolation. */
export async function newDocumentWithBody(page) {
await page.locator('button[aria-label="新建文档"]').first().click();
await page.waitForTimeout(1500);
await page.locator('button[aria-label="新建 Body"]').first().click();
await page.waitForTimeout(1500);
}
async function fillVector(page, label, values) {
for (const [index, axis] of ["X", "Y", "Z"].entries()) {
const input = page.locator(`input[aria-label="${label} ${axis}"]`).first();
await input.fill(String(values?.[index] ?? 0));
await input.press("Enter");
}
}
async function fillGeometryRow(page, index, geometry) {
const n = index + 1;
const typeSelect = page.locator(`select[aria-label="Geometry ${n} type"]`);
await typeSelect.selectOption(geometry.type);
await page.waitForTimeout(150);
if (geometry.type === "line") {
await fillVector(page, `Geometry ${n} start`, geometry.start);
await fillVector(page, `Geometry ${n} end`, geometry.end);
} else if (geometry.type === "circle" || geometry.type === "arc") {
await fillVector(page, `Geometry ${n} center`, geometry.center);
await page.locator(`input[aria-label="Geometry ${n} radius"]`).fill(String(geometry.radius));
if (geometry.type === "arc") {
await page.locator(`input[aria-label="Geometry ${n} startAngle"]`).fill(String(geometry.startAngle));
await page.locator(`input[aria-label="Geometry ${n} endAngle"]`).fill(String(geometry.endAngle));
}
} else if (geometry.type === "ellipse") {
await fillVector(page, `Geometry ${n} center`, geometry.center);
await page.locator(`input[aria-label="Geometry ${n} majorRadius"]`).fill(String(geometry.majorRadius));
await page.locator(`input[aria-label="Geometry ${n} minorRadius"]`).fill(String(geometry.minorRadius));
} else if (geometry.type === "point") {
await fillVector(page, `Geometry ${n} point`, geometry.point);
}
}
async function fillConstraintRow(page, index, constraint) {
const n = index + 1;
await page.locator(`select[aria-label="Constraint ${n} type"]`).selectOption(constraint.type);
await page.waitForTimeout(150);
for (const slot of ["first", "second", "third"]) {
if (constraint[slot] === undefined) continue;
const select = page.locator(`select[aria-label="Constraint ${n} ${slot}"]`).first();
if (await select.count()) await select.selectOption(String(constraint[slot]));
}
for (const slot of ["firstPos", "secondPos", "thirdPos"]) {
if (!constraint[slot]) continue;
const select = page.locator(`select[aria-label="Constraint ${n} ${slot}"]`).first();
if (await select.count()) await select.selectOption(constraint[slot]);
}
if (constraint.value !== undefined) {
const input = page.locator(`input[aria-label="Constraint ${n} value"]`).first();
if (await input.count()) await input.fill(String(constraint.value));
}
}
/**
* Create a sketch from a geometry+constraint list.
*
* The editor opens with a four-line rectangle preset, so the row count has to be
* driven to the target shape: delete the surplus rows, then append and fill.
*/
export async function createSketch(page, step) {
const group = page.locator('[role="group"][aria-label="Profile type"]').first();
const label = step.profileType === "Circle" ? "圆形" : "几何与约束";
await group.getByRole("button", { name: label }).first().click();
await page.waitForTimeout(400);
if (step.profileType === "Circle") {
const radius = step.geometries?.[0]?.radius ?? step.parameters?.Radius;
if (radius !== undefined) await page.locator('input[aria-label="Sketch Radius"]').first().fill(String(radius));
} else {
const countGeometryRows = () => page.locator('select[aria-label^="Geometry "][aria-label$=" type"]').count();
let rows = await countGeometryRows();
while (rows > step.geometries.length) {
await page.locator(`button[aria-label="Remove geometry ${rows}"]`).first().click();
await page.waitForTimeout(100);
rows = await countGeometryRows();
}
while (rows < step.geometries.length) {
await page.locator('button[aria-label="Add sketch geometry"]').first().click();
await page.waitForTimeout(100);
rows = await countGeometryRows();
}
for (const [index, geometry] of step.geometries.entries()) await fillGeometryRow(page, index, geometry);
const countConstraintRows = () => page.locator('select[aria-label^="Constraint "][aria-label$=" type"]').count();
let constraints = await countConstraintRows();
while (constraints > step.constraints.length) {
await page.locator(`button[aria-label="Remove constraint ${constraints}"]`).first().click();
await page.waitForTimeout(100);
constraints = await countConstraintRows();
}
while (constraints < step.constraints.length) {
await page.locator('button[aria-label="Add sketch constraint"]').first().click();
await page.waitForTimeout(100);
constraints = await countConstraintRows();
}
for (const [index, constraint] of step.constraints.entries()) await fillConstraintRow(page, index, constraint);
}
await fillVector(page, "Sketch", step.position ?? [0, 0, 0]);
// A sketch is not always parallel to XY. Pick the plane whose quaternion the
// kernel snapshot reported; the "Custom" branch types the raw quaternion when
// the support is not one of the three axis-aligned planes.
const plane = await page.locator('select[aria-label="Sketch plane"]').first();
if (await plane.count()) {
const rotation = step.placementRotation ?? [0, 0, 0, 1];
const identity = rotation[0] === 0 && rotation[1] === 0 && rotation[2] === 0;
if (identity) await plane.selectOption("XY");
else {
await plane.selectOption("Custom");
const axes = ["W", "X", "Y", "Z"];
for (const [index, axis] of axes.entries()) {
const input = page.locator(`input[aria-label="Sketch rotation ${axis}"]`).first();
if (await input.count()) { await input.fill(String(rotation[index])); await input.press("Enter"); }
}
}
await page.waitForTimeout(200);
}
await page.locator('button[data-create-sketch]').first().click();
await page.waitForTimeout(2200);
}
/** The workspace names objects itself (Sketch1, Pad1 ...), so map as we go. */
export async function lastProfileName(page) {
await page.locator('[role="group"][aria-label="Profile feature"] button[data-feature-type="Pad"]').first().click().catch(() => {});
await page.waitForTimeout(250);
const values = await page.evaluate(() => {
const select = document.querySelector('select[aria-label="Feature Profile"]');
return select ? [...select.options].map(option => option.value).filter(Boolean) : [];
});
return values.at(-1) ?? null;
}
/** Select several options by value and notify React, as the panel does. */
async function selectMulti(page, locator, values) {
const picked = await locator.evaluate((node, wanted) => {
const found = [...node.options].filter(option => wanted.includes(option.value)).map(option => option.value);
if (!found.length) return [];
for (const option of node.options) option.selected = found.includes(option.value);
node.dispatchEvent(new Event("change", { bubbles: true }));
return found;
}, values);
await page.waitForTimeout(300);
return picked;
}
/** Open a collapsed `<details>` task group by the words in its summary. */
async function openDesignGroup(page, pattern) {
await page.evaluate(source => {
const wanted = new RegExp(source, "i");
for (const details of document.querySelectorAll("details.design-task-group")) {
const summary = details.querySelector("summary");
if (summary && wanted.test(summary.textContent ?? "")) details.open = true;
}
}, pattern);
await page.waitForTimeout(300);
}
async function fillNumber(page, label, value) {
if (value === null || value === undefined) return;
const input = page.locator(`input[aria-label="${label}"]`).first();
if (await input.count()) { await input.fill(String(value)); await input.press("Enter"); }
}
async function setCheckbox(page, label, checked) {
const box = page.locator(`input[type="checkbox"][aria-label="${label}"]`).first();
if (await box.count()) await box.setChecked(Boolean(checked)).catch(() => {});
}
/** Pick one option whose value is a JSON [object, subelement] reference. */
async function selectReference(page, locator, wanted) {
if (!wanted) return;
const object = typeof wanted === "string" ? wanted : wanted.object;
const sub = typeof wanted === "string" ? null : wanted.subelements?.[0] ?? wanted.subelement ?? null;
const match = await locator.evaluate((node, ref) => {
for (const option of node.options) {
try {
const parsed = JSON.parse(option.value);
const sameObject = parsed[0] === ref.object || `${parsed[0]}_${parsed[1]}` === ref.object;
if (sameObject && (!ref.sub || parsed[1] === ref.sub)) return option.value;
} catch { /* placeholder option text has no JSON value */ }
}
return null;
}, { object, sub });
if (!match) throw new Error(`no reference option for ${object}${sub ? "·" + sub : ""}`);
await locator.selectOption(match);
await page.waitForTimeout(300);
}
/** Apply Pad / Pocket / Revolution / Hole / Loft / Pipe through the profile group. */
export async function createFeature(page, step) {
await page.locator(`[role="group"][aria-label="Profile feature"] button[data-feature-type="${step.featureType}"]`).first().click();
await page.waitForTimeout(500);
// Select by the name the UI actually gave the sketch, not the kernel's name.
// A missing name must fail: picking "the last option" silently builds the
// wrong solid once a body holds more than one profile.
const profileName = step.uiProfile ?? step.profile;
if (profileName) {
const select = page.locator('select[aria-label="Feature Profile"]').first();
const values = await select.evaluate(node => [...node.options].map(option => option.value));
if (!values.includes(profileName)) throw new Error(`profile ${profileName} is not in the feature list`);
await select.selectOption(profileName);
await page.waitForTimeout(350);
}
if (step.length !== null && step.length !== undefined) {
const input = page.locator('input[aria-label="Feature Length"]').first();
if (await input.count()) { await input.fill(String(step.length)); await input.press("Enter"); }
}
if (step.featureType === "Revolution" && step.angle != null) {
const input = page.locator('input[aria-label="Feature Angle"]').first();
if (await input.count()) { await input.fill(String(step.angle)); await input.press("Enter"); }
}
// A Revolution without an axis spins the profile about an axis the form picked,
// which produces a completely different solid (shafts came out 16x too large).
// The axis select's values are JSON ["objectName","subelement"] pairs, so the
// kernel's single axis name has to be matched against the first element.
if (step.featureType === "Revolution") {
const axisSelect = page.locator('select[aria-label="Feature Axis"]').first();
if (await axisSelect.count()) {
const wanted = step.axis ?? "X_Axis";
const match = await axisSelect.evaluate((node, name) => {
for (const option of node.options) {
try {
const [object, sub] = JSON.parse(option.value);
if (object === name || `${object}_${sub}` === name || object === `${name}`.replace("_Axis", "")) return option.value;
} catch { /* placeholder option */ }
}
// Fall back to matching the visible label, which reads "X-axis · ".
const byLabel = [...node.options].find(option => option.textContent.trim().startsWith(name.replace("_", "-")));
return byLabel ? byLabel.value : null;
}, wanted);
if (match) { await axisSelect.selectOption(match); await page.waitForTimeout(300); }
else throw new Error(`no axis option for ${wanted}`);
}
}
// Midplane has no checkbox: it is the Sides select's "Symmetric" option. That
// select carries no aria-label and its options have no value attribute, so it
// has to be found by the label text ("Sides") rather than by a value filter.
const sides = page.locator('label:has(> select)').filter({ hasText: /^\s*Sides/ }).locator("select").first();
const mode = step.midplane ? "Symmetric" : "One side";
if (await sides.count()) {
await sides.selectOption({ label: mode });
await page.waitForTimeout(300);
}
// "Reversed" flips the extrusion direction of every profile feature the form
// draws it for. Hole carries its own copy inside fillFeatureExtras. Without
// this the flag was silently dropped and a pocket authored to cut upwards
// still cut downwards, so the built solid disagreed with the recorded
// reference while every step still "succeeded" (P05 CarrierHangar).
if (step.reversed !== undefined && ["Pad", "Pocket", "Revolution", "Groove"].includes(step.featureType)) {
await setCheckbox(page, "Reversed", step.reversed === true);
}
await fillFeatureExtras(page, step);
await page.locator('button[data-create-feature]').first().click();
await page.waitForTimeout(2500);
}
/** Fields that only exist for one feature type (Loft, Pipe, Hole). */
async function fillFeatureExtras(page, step) {
if (step.featureType === "Loft" || step.featureType === "SubtractiveLoft") {
const sections = (step.sections ?? []).map(section => (typeof section === "string" ? section : section?.object)).filter(Boolean);
if (sections.length) {
const picked = await selectMulti(page, page.locator('select[aria-label="Loft Sections"]').first(), sections);
if (picked.length !== sections.length) throw new Error(`loft sections missing: wanted ${sections.join(",")} got ${picked.join(",") || "none"}`);
}
await setCheckbox(page, "Loft Ruled", step.ruled === true);
await setCheckbox(page, "Loft Closed", step.closed === true);
return;
}
if (step.featureType === "Pipe" || step.featureType === "SubtractivePipe") {
const spine = step.spine ?? step.spineEdges?.[0] ?? null;
if (spine) {
const spineObject = typeof spine === "string" ? spine : spine.object;
const spineSelect = page.locator('select[aria-label="Pipe Spine"]').first();
if (await spineSelect.count()) {
const values = await spineSelect.evaluate(node => [...node.options].map(option => option.value));
const byValue = values.find(value => value === spineObject);
const byLabel = await spineSelect.evaluate((node, name) => {
const option = [...node.options].find(item => item.textContent.trim() === name
|| item.textContent.trim().startsWith(`${name} `));
return option ? option.value : null;
}, spineObject);
const chosen = byValue ?? byLabel;
if (chosen) await spineSelect.selectOption(chosen);
else throw new Error(`no pipe spine option for ${spineObject}`);
await page.waitForTimeout(300);
}
}
if (step.orientation) {
const orientation = page.locator('select[aria-label="Pipe Orientation"]').first();
if (await orientation.count()) await orientation.selectOption(step.orientation).catch(() => {});
}
if (step.transition) {
const transition = page.locator('select[aria-label="Pipe Transition"]').first();
if (await transition.count()) await transition.selectOption(step.transition).catch(() => {});
}
return;
}
if (step.featureType === "Hole") {
await fillNumber(page, "Hole Diameter", step.diameter);
if (step.depthType) {
const depthType = page.locator('select[aria-label="Hole Depth Type"]').first();
if (await depthType.count()) await depthType.selectOption(step.depthType).catch(() => {});
await page.waitForTimeout(200);
}
if (step.depthType !== "ThroughAll") await fillNumber(page, "Hole Depth", step.depth);
await setCheckbox(page, "Reversed", step.reversed === true);
}
}
/** Fillet / Chamfer through the dress-up group (inside a collapsed details). */
export async function createDressUp(page, step) {
await openDesignGroup(page, "厚度|布尔与边缘|Dress");
await page.locator(`[role="group"][aria-label="Dress-up feature"] button[data-dressup-type="${step.dressUpType}"]`).first().click();
await page.waitForTimeout(400);
if (step.base) {
const base = page.locator('select[aria-label="Dress-up Base"]').first();
if (await base.count()) {
const values = await base.evaluate(node => [...node.options].map(option => option.value));
if (!values.includes(step.base)) throw new Error(`dress-up base ${step.base} is not in the list`);
await base.selectOption(step.base);
await page.waitForTimeout(300);
}
}
await fillNumber(page, "Dress-up Size", step.size);
if (step.dressUpType === "Chamfer") {
if (step.chamferType) {
const type = page.locator('select[aria-label="Chamfer type"]').first();
if (await type.count()) await type.selectOption(step.chamferType).catch(() => {});
}
await fillNumber(page, "Chamfer second distance", step.size2);
await fillNumber(page, "Chamfer angle", step.angle);
await setCheckbox(page, "Chamfer Flip direction", step.flipDirection === true);
}
if (step.useAllEdges) await setCheckbox(page, "Use all edges", true);
else {
// Edge checkboxes are numbered EdgeN inside the native references group.
for (const edge of step.edges ?? []) {
const name = typeof edge === "string" ? edge : `Edge${edge.index ?? edge}`;
const box = page.locator(`input[type="checkbox"][aria-label="${name}"]`).first();
if (!(await box.count())) throw new Error(`no edge checkbox ${name}`);
await box.setChecked(true);
}
}
await page.waitForTimeout(300);
await page.locator('button[data-create-dressup]').first().click();
await page.waitForTimeout(2500);
}
/** Additive sphere primitive (bearing balls). */
export async function createPrimitive(page, step) {
const operation = page.locator('select[aria-label="Design primitive operation"]').first();
await operation.selectOption("Additive");
await page.locator('select[aria-label="Design primitive type"]').first().selectOption("Sphere");
await page.waitForTimeout(300);
if (step.parameters?.Radius != null) {
const radius = page.locator('input[aria-label="Design primitive Radius"]').first();
if (await radius.count()) await radius.fill(String(step.parameters.Radius));
}
for (const [index, axis] of ["X", "Y", "Z"].entries()) {
const input = page.locator(`input[aria-label="Design primitive position ${axis}"]`).first();
if (await input.count()) await input.fill(String(step.position?.[index] ?? 0));
}
await page.locator('button[aria-label="Create design primitive"]').first().click();
await page.waitForTimeout(2500);
}
/** Polar pattern (bearing balls). */
export async function createPolarPattern(page, step) {
// The transformation fieldset is inside a <details> that starts collapsed, so
// its controls exist in the DOM but cannot be clicked until the group opens.
await page.evaluate(() => {
for (const details of document.querySelectorAll("details.design-task-group")) {
const summary = details.querySelector("summary");
if (summary && /Transformation/i.test(summary.textContent ?? "")) details.open = true;
}
});
await page.waitForTimeout(300);
const originals = page.locator('select[aria-label="PolarPattern Originals"]').first();
const names = step.originals ?? [];
if (names.length) {
// Select by `value`, not by visible text: the option label is the object's
// display label, which need not equal the object name. A multi-select whose
// value never lands leaves the form invalid, so the commit button stays
// disabled and a blind click only times out.
const values = await originals.evaluate((node, wanted) => {
const picked = [...node.options].filter(option => wanted.includes(option.value)).map(option => option.value);
return picked.length ? picked : [...node.options].map(option => option.value).filter(Boolean);
}, names);
if (values.length) await originals.evaluate((node, picked) => {
for (const option of node.options) option.selected = picked.includes(option.value);
node.dispatchEvent(new Event("change", { bubbles: true }));
}, values);
await page.waitForTimeout(300);
}
if (step.angle != null) {
const angle = page.locator('input[aria-label="PolarPattern Angle"]').first();
if (await angle.count()) await angle.fill(String(step.angle));
}
// Without an axis the form keeps "Create PolarPattern" disabled, and a blind
// click then waits 30 s and reports a generic failure. The select's values are
// JSON ["object","subelement"] pairs, so match on the object name.
const wantedAxis = step.rotationAxis?.object;
if (wantedAxis) {
const axisSelect = page.locator('select[aria-label="PolarPattern Axis"]').first();
if (await axisSelect.count()) {
const match = await axisSelect.evaluate((node, name) => {
for (const option of node.options) {
try { if (JSON.parse(option.value)[0] === name) return option.value; } catch { /* placeholder */ }
}
return null;
}, wantedAxis);
if (match) { await axisSelect.selectOption(match); await page.waitForTimeout(300); }
else throw new Error(`no polar axis option for ${wantedAxis}`);
}
}
if (step.occurrences != null) {
const occurrences = page.locator('input[aria-label="PolarPattern Occurrences"]').first();
if (await occurrences.count()) await occurrences.fill(String(step.occurrences));
}
await page.locator('button[aria-label="Create PolarPattern"]').first().click();
await page.waitForTimeout(2500);
}
/**
* Volume of the body's current tip.
*
* The standalone page has no global object array; the property pane renders the
* selected feature's volume as text ("体积33600.000000"). Read that, and fall
* back to the tree's tip row when nothing is selected.
*/
export async function tipVolume(page) {
return page.evaluate(() => {
const pane = document.querySelector("aside.property-pane")?.textContent ?? "";
const match = /体积\s*(-?[\d.]+(?:[eE][-+]?\d+)?)/.exec(pane);
return match ? Number(match[1]) : null;
});
}
/** Try every feature tab until the property pane reports a volume. */
export async function selectTip(page) {
const rows = await page.locator('[role="treeitem"] .fc-tree-col-label').allTextContents();
for (const name of rows.reverse()) {
await page.locator(`[role="treeitem"] .fc-tree-col-label:text-is("${name}")`).first().click().catch(() => {});
await page.waitForTimeout(400);
if (await tipVolume(page) != null) return name;
}
return null;
}
/**
* Involute gear / sprocket. The Gear / Sprocket fieldset lives on the same
* `partdesign.html` page as the sketch editor, so no page hop is needed; the
* fields are `Gear <parameterName>` and the commit button has no data hook, so
* it is found by its visible label.
*/
export async function createGear(page, step) {
// The gear fieldset lives inside a collapsed <details> task group, so the
// select exists in the DOM but is not interactable until the group is opened.
await page.evaluate(() => {
for (const details of document.querySelectorAll("details.design-task-group")) {
const summary = details.querySelector("summary");
if (summary && /Gear/i.test(summary.textContent ?? "")) details.open = true;
}
});
await page.waitForTimeout(300);
const kind = step.gearType === "Sprocket" ? "Sprocket" : "InvoluteGear";
await page.locator('select[aria-label="Gear type"]').first().selectOption(kind);
await page.waitForTimeout(400);
for (const [key, value] of Object.entries(step.gearParameters ?? {})) {
if (typeof value === "boolean") {
const box = page.locator(`input[type="checkbox"][aria-label="Gear ${key}"]`).first();
if (await box.count()) await box.setChecked(value).catch(() => {});
continue;
}
if (typeof value !== "number") continue;
const input = page.locator(`input[aria-label="Gear ${key}"]`).first();
if (await input.count()) { await input.fill(String(value)); await input.press("Enter"); }
}
// Position and orientation: a gear body sits at an axial offset and often
// faces along Y, so the placement is part of the operation, not a nicety.
for (const [index, axis] of ["X", "Y", "Z"].entries()) {
const input = page.locator(`input[aria-label="Gear position ${axis}"]`).first();
if (await input.count()) { await input.fill(String(step.position?.[index] ?? 0)); await input.press("Enter"); }
}
const gearPlane = page.locator('select[aria-label="Gear plane"]').first();
if (await gearPlane.count()) {
const rotation = step.placementRotation ?? [0, 0, 0, 1];
const identity = rotation[0] === 0 && rotation[1] === 0 && rotation[2] === 0;
if (identity) await gearPlane.selectOption("XY");
else {
await gearPlane.selectOption("Custom");
for (const [index, axis] of ["W", "X", "Y", "Z"].entries()) {
const input = page.locator(`input[aria-label="Gear rotation ${axis}"]`).first();
if (await input.count()) { await input.fill(String(rotation[index])); await input.press("Enter"); }
}
}
await page.waitForTimeout(200);
}
const commit = page.getByRole("button", { name: /^Create gear$/ }).first();
await commit.click();
await page.waitForTimeout(2500);
}
/** Mirrored: originals + plane, then "Create Mirrored". */
export async function createMirrored(page, step) {
await openDesignGroup(page, "Transformation");
const originals = page.locator('select[aria-label="Mirrored Originals"]').first();
const names = step.originals ?? [];
if (names.length) {
const picked = await selectMulti(page, originals, names);
if (!picked.length) throw new Error(`mirrored originals missing: ${names.join(",")}`);
}
await selectReference(page, page.locator('select[aria-label="Mirrored Plane"]').first(), step.mirrorPlane);
const commit = page.locator('button[aria-label="Create Mirrored"]').first();
await commit.waitFor({ state: "visible", timeout: 15000 });
await commit.click();
await page.waitForTimeout(2500);
}
/** LinearPattern: originals + direction + length + occurrences. */
export async function createLinearPattern(page, step) {
await openDesignGroup(page, "Transformation");
const originals = page.locator('select[aria-label="LinearPattern Originals"]').first();
const names = step.originals ?? [];
if (names.length) {
const picked = await selectMulti(page, originals, names);
if (!picked.length) throw new Error(`linear pattern originals missing: ${names.join(",")}`);
}
await selectReference(page, page.locator('select[aria-label="LinearPattern Direction"]').first(), step.direction);
await fillNumber(page, "LinearPattern Length", step.length);
await fillNumber(page, "LinearPattern Occurrences", step.occurrences);
await setCheckbox(page, "LinearPattern Reversed", step.reversed === true);
const occurrences = page.locator('input[aria-label="LinearPattern Occurrences"]').first();
if (await occurrences.count()) await occurrences.press("Enter");
await page.locator('button[aria-label="Create LinearPattern"]').first().click();
await page.waitForTimeout(2500);
}
export async function createTransform(page, step) {
if (step.transformType === "Mirrored") return createMirrored(page, step);
if (step.transformType === "LinearPattern") return createLinearPattern(page, step);
return createPolarPattern(page, step);
}
export async function runStep(page, step) {
if (step.kind === "sketch") return createSketch(page, step);
if (step.kind === "gear") return createGear(page, step);
if (step.kind === "feature") return createFeature(page, step);
if (step.kind === "primitive") return createPrimitive(page, step);
if (step.kind === "transform") return createTransform(page, step);
if (step.kind === "dressup") return createDressUp(page, step);
throw new Error(`ui-driver cannot perform kind "${step.kind}" (${step.label})`);
}