[T7] Rotationskörper und Loft als Befehle (Profil, Achse, Winkel / mehrere Profile)

This commit is contained in:
Claude committed 2026-10-30 08:06:44 +00:00
1 parent 0048c37126
commit ded5aa1332
13 files changed
+530 -7

No files matched your search

+4 -4
View File
@@ -32,25 +32,25 @@ let lastTaper = 0;
// ── Profil (Kern, `cmd_create.rs`): geschlossene polyline/rect/circle → Punktliste ─
/** Profil eines extrudierbaren 2D-Elements (Kreis: 48-Eck + Mittelpunkt/Radius). */
interface Profile {
export interface Profile {
pts: Vec2[];
circle?: { center: Vec2; r: number };
}
type ProfileHit = { id: string } & Profile;
export type ProfileHit = { id: string } & Profile;
function profileQuery(project: Project, req: { q: string } & Record<string, unknown>): ProfileHit | null {
return createQuery<{ hit: (ProfileHit & { circle: Profile["circle"] | null }) | null }>(project, req).hit ?? null;
}
/** Genau EIN geeignetes Profil vorgewählt (sonst null). */
function singleSelectedProfile(project: Project, sel: CommandSelection): ProfileHit | null {
export function singleSelectedProfile(project: Project, sel: CommandSelection): ProfileHit | null {
if (!sel.drawingId || sel.wallIds.length > 0) return null;
return profileQuery(project, { q: "profile", id: sel.drawingId });
}
/** Nächstes Profil der Ebene am Klickpunkt (Kanten-Abstand < 0.25 m). */
const pickProfileAt = (project: Project, levelId: string, pt: Vec2): ProfileHit | null =>
export const pickProfileAt = (project: Project, levelId: string, pt: Vec2): ProfileHit | null =>
profileQuery(project, { q: "pickProfile", level: levelId, pt: xy(pt) });
/** Commit (Kern): Quelle entfernen, Körper (Punkte + Höhe + Verjüngung) anlegen. */
+71
View File
@@ -0,0 +1,71 @@
// Loft ([T7]): ≥ 2 geschlossene Plan-Profile nacheinander anklicken (erstes = unten), Enter, dann die
// Gesamthöhe. Die Profile werden gleichmässig über die Höhe verteilt (Kern `cmd_solid.rs`: gleiche
// Punktzahl durch Kantenteilung, Drehsinn angeglichen) und zu einem truck-`loft`-B-Rep-Körper
// (`ExtrudedSolid.brep`) verbunden; die Quellprofile entfallen wie beim Extrudieren.
import type { Command, CommandContext, CommandResult, CommandState, Vec2 } from "../types";
import { createMutation } from "../createCore";
import { pickProfileAt, type ProfileHit } from "./extrude";
let lastHeight = 3;
interface LoftState extends CommandState {
phase: "pick" | "height" | "done";
picks: ProfileHit[];
}
const draft = (s: LoftState, cursor: Vec2 | null): CommandResult["draft"] => ({
preview: s.picks.map((p) => ({ kind: "poly" as const, pts: p.pts, closed: true })),
vertices: [],
hud: cursor ? { at: cursor, text: s.phase === "height" ? `${lastHeight.toFixed(2)} m` : `${s.picks.length}` } : undefined,
});
const finished = (): LoftState => ({ phase: "done", picks: [], lastPoint: null });
const done = (): [CommandState, CommandResult] => [finished(), { draft: null, done: true }];
function commit(s: LoftState, height: number, ctx: CommandContext): [CommandState, CommandResult] {
lastHeight = height;
return [
finished(),
{ draft: null, done: true, commit: createMutation(ctx, { cmd: "loft", sources: s.picks.map((p) => p.id), height }) },
];
}
export const loftCommand: Command = {
name: "loft",
labelKey: "cmd.loft.label",
prompt: (st) => ((st as LoftState).phase === "height" ? "cmd.loft.height" : (st as LoftState).picks.length < 2 ? "cmd.loft.pick" : "cmd.loft.pickMore"),
accepts: (st) => ((st as LoftState).phase === "height" ? ["number"] : ["point"]),
options: () => [],
floorOnly: true,
init: (): LoftState => ({ phase: "pick", picks: [], lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as LoftState;
if (s.phase === "done") return done();
if (s.phase === "pick") {
if (input.kind !== "point") return [s, { draft: draft(s, null) }];
const hit = pickProfileAt(ctx.project, ctx.level.id, input.point);
if (!hit || s.picks.some((p) => p.id === hit.id)) return [s, { draft: draft(s, null) }];
const ns: LoftState = { ...s, picks: [...s.picks, hit] };
return [ns, { draft: draft(ns, input.point) }];
}
if (input.kind !== "number" || !(input.value > 0)) return [s, { draft: draft(s, null) }];
return commit(s, input.value, ctx);
},
onMove: (state, point): [CommandState, CommandResult] => [state, { draft: draft(state as LoftState, point) }],
// Enter: mit ≥ 2 Profilen zur Höhe; bei der Höhe die zuletzt benutzte übernehmen.
onConfirm: (state, ctx): [CommandState, CommandResult] => {
const s = state as LoftState;
if (s.phase === "pick") {
if (s.picks.length < 2) return [s, { draft: draft(s, null) }];
const ns: LoftState = { ...s, phase: "height" };
return [ns, { draft: draft(ns, null) }];
}
return s.phase === "height" ? commit(s, lastHeight, ctx) : done();
},
onCancel: () => done(),
};
+98
View File
@@ -0,0 +1,98 @@
// Rotationskörper ([T7]): geschlossenes Plan-Profil + Drehachse (2 Punkte im Plan) + Winkel → truck-
// `revolve` als B-Rep-Körper (`ExtrudedSolid.brep`, Kern `cmd_solid.rs`). Das Profil muss ganz auf einer
// Seite der Achse liegen; die Achse liegt waagrecht auf Höhe des grössten Profilabstands, ein voller
// Körper steht also auf der Geschoss-UK. Die Quelle (Profil) wird ersetzt wie beim Extrudieren.
//
// Schritte: Profil wählen (oder vorselektiert) → Achse Anfang → Achse Ende → Winkel (Zahl oder Enter = zuletzt, 360).
import type { Command, CommandContext, CommandResult, CommandState, Vec2 } from "../types";
import { createMutation } from "../createCore";
import { pickProfileAt, singleSelectedProfile, type Profile } from "./extrude";
let lastAngle = 360;
interface RevState extends CommandState {
phase: "pick" | "axisA" | "axisB" | "angle" | "done";
profile: Profile | null;
sourceId: string | null;
a: Vec2 | null;
b: Vec2 | null;
cursor: Vec2 | null;
}
const draft = (s: RevState, cursor: Vec2 | null): CommandResult["draft"] => {
const preview: NonNullable<CommandResult["draft"]>["preview"] = [];
if (s.profile) preview.push({ kind: "poly", pts: s.profile.pts, closed: true });
const end = s.b ?? cursor;
if (s.a && end) preview.push({ kind: "line", a: s.a, b: end });
return { preview, vertices: s.a ? [s.a] : [], hud: cursor && s.phase === "angle" ? { at: cursor, text: `${lastAngle}°` } : undefined };
};
const finished = (): RevState => ({ phase: "done", profile: null, sourceId: null, a: null, b: null, cursor: null, lastPoint: null });
const done = (): [CommandState, CommandResult] => [finished(), { draft: null, done: true }];
function commit(s: RevState, angle: number, ctx: CommandContext): [CommandState, CommandResult] {
lastAngle = angle;
return [
finished(),
{ draft: null, done: true, commit: createMutation(ctx, { cmd: "revolve", source: s.sourceId, a: s.a, b: s.b, angle }) },
];
}
export const revolveCommand: Command = {
name: "revolve",
labelKey: "cmd.revolve.label",
prompt: (st) => {
const p = (st as RevState).phase;
return p === "axisA" ? "cmd.revolve.axisA" : p === "axisB" ? "cmd.revolve.axisB" : p === "angle" ? "cmd.revolve.angle" : "cmd.revolve.pick";
},
accepts: (st) => ((st as RevState).phase === "angle" ? ["number"] : ["point"]),
options: () => [],
floorOnly: true,
init: (): RevState => ({ phase: "pick", profile: null, sourceId: null, a: null, b: null, cursor: null, lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
let s = state as RevState;
if (s.phase === "done") return done();
if (s.phase === "pick") {
if (input.kind !== "point") return [s, { draft: null }];
// Vorselektiertes Profil: der erste Punkt ist gleich der Achsenanfang.
const pre = singleSelectedProfile(ctx.project, ctx.selection);
if (pre) {
s = { ...s, phase: "axisA", profile: pre, sourceId: pre.id };
} else {
const hit = pickProfileAt(ctx.project, ctx.level.id, input.point);
if (!hit) return [s, { draft: null }];
const ns: RevState = { ...s, phase: "axisA", profile: hit, sourceId: hit.id };
return [ns, { draft: draft(ns, null) }];
}
}
if (s.phase === "axisA") {
if (input.kind !== "point") return [s, { draft: draft(s, s.cursor) }];
const ns: RevState = { ...s, phase: "axisB", a: input.point, lastPoint: input.point };
return [ns, { draft: draft(ns, input.point) }];
}
if (s.phase === "axisB") {
if (input.kind !== "point" || !s.a || Math.hypot(input.point.x - s.a.x, input.point.y - s.a.y) < 1e-6) return [s, { draft: draft(s, s.cursor) }];
const ns: RevState = { ...s, phase: "angle", b: input.point, lastPoint: input.point };
return [ns, { draft: draft(ns, input.point) }];
}
// angle
if (input.kind !== "number" || !(input.value > 0)) return [s, { draft: draft(s, s.cursor) }];
return commit(s, Math.min(360, input.value), ctx);
},
onMove: (state, point): [CommandState, CommandResult] => {
const s = { ...(state as RevState), cursor: point };
return [s, { draft: draft(s, point) }];
},
// Enter beim Winkel: zuletzt benutzten Winkel übernehmen.
onConfirm: (state, ctx): [CommandState, CommandResult] => {
const s = state as RevState;
return s.phase === "angle" ? commit(s, lastAngle, ctx) : done();
},
onCancel: () => done(),
};
+102
View File
@@ -0,0 +1,102 @@
/**
* [T7] `revolveCommand` (Profil + Achse + Winkel) und `loftCommand` (≥ 2 Profile + Höhe): beide legen
* einen B-Rep-Körper (`ExtrudedSolid.brep`) an und entfernen die Quellprofile.
*/
import { describe, it, expect } from "vitest";
import { revolveCommand } from "./revolve";
import { loftCommand } from "./loft";
import type { CommandContext, CmdInput, Project } from "../types";
const rect = (id: string, x: number, y: number, w: number, h: number) => ({
id,
type: "drawing2d" as const,
levelId: "eg",
categoryCode: "20",
geom: { shape: "rect" as const, min: { x, y }, max: { x: x + w, y: y + h } },
});
function project(): Project {
return {
id: "t",
name: "T",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 }],
layers: [{ code: "20", name: "Zeichnung", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
walls: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [rect("A", 0, 1, 2, 1), rect("B", 10, 0, 1, 1)],
extrudedSolids: [],
context: [],
} as unknown as Project;
}
function makeCtx(p: Project, drawingId: string | null = null): CommandContext {
return {
project: p,
level: p.drawingLevels[0],
defaultCategoryCode: "20",
activeLineStyleId: "solid",
activeWallTypeId: "aw",
lastPoint: null,
selection: { wallIds: [], drawingId },
} as CommandContext;
}
/** Spielt Eingaben ab; liefert das Projekt nach dem Commit (oder null). */
function run(cmd: typeof revolveCommand, p: Project, inputs: Array<CmdInput | "confirm">, selected: string | null = null) {
const ctx = makeCtx(p, selected);
let state = cmd.init();
let commit: ((p: Project) => Project) | undefined;
for (const i of inputs) {
const [ns, res] = i === "confirm" ? cmd.onConfirm(state, ctx) : cmd.onInput(state, i, ctx);
state = ns;
if (res.commit) commit = res.commit as typeof commit;
}
return commit ? commit(p) : null;
}
const pt = (x: number, y: number): CmdInput => ({ kind: "point", point: { x, y } });
describe("revolveCommand", () => {
it("Profil wählen, Achse (2 Punkte), Winkel → Rotationskörper, Quelle entfernt", () => {
const next = run(revolveCommand, project(), [pt(1, 1), pt(-1, 0), pt(5, 0), { kind: "number", value: 180 }])!;
expect(next.drawings2d.map((d) => d.id)).toEqual(["B"]);
const s = next.extrudedSolids![0];
expect(s.brep!.spec).toMatchObject({ kind: "transform", solid: { kind: "revolve", angleDeg: 180 } });
expect(s.height).toBeCloseTo(4, 9); // Profil 1 … 2 m neben der Achse y=0 → r_max = 2
});
it("Enter beim Winkel übernimmt den zuletzt benutzten; vorgewähltes Profil überspringt die Wahl", () => {
run(revolveCommand, project(), [pt(1, 1), pt(-1, 0), pt(5, 0), { kind: "number", value: 90 }]);
const next = run(revolveCommand, project(), [pt(-1, 0), pt(5, 0), "confirm"], "A")!;
expect(next.extrudedSolids![0].brep!.spec).toMatchObject({ solid: { angleDeg: 90 } });
});
it("Profil, das die Achse überquert, ergibt keinen Körper", () => {
const next = run(revolveCommand, project(), [pt(1, 1), pt(-1, 1.5), pt(5, 1.5), "confirm"]);
expect(next?.extrudedSolids ?? []).toHaveLength(0);
});
});
describe("loftCommand", () => {
it("zwei Profile wählen, Enter, Höhe → Loft-Körper, Quellen entfernt", () => {
const next = run(loftCommand, project(), [pt(1, 1), pt(10.5, 0), "confirm", { kind: "number", value: 3 }])!;
expect(next.drawings2d).toHaveLength(0);
const s = next.extrudedSolids![0];
expect(s.height).toBe(3);
expect(s.brep!.spec).toMatchObject({ kind: "loft" });
expect((s.brep!.spec as { sections: unknown[] }).sections).toHaveLength(2);
});
it("mit nur einem Profil bleibt Enter wirkungslos", () => {
const next = run(loftCommand, project(), [pt(1, 1), "confirm", { kind: "number", value: 3 }]);
expect(next?.extrudedSolids ?? []).toHaveLength(0);
});
});
+7
View File
@@ -53,6 +53,8 @@ import { copyCommand } from "./cmds/copy";
import { arrayCommand } from "./cmds/array";
import { offsetCommand } from "./cmds/offset";
import { extrudeCommand } from "./cmds/extrude";
import { revolveCommand } from "./cmds/revolve";
import { loftCommand } from "./cmds/loft";
import { trimCommand } from "./cmds/trim";
import { breakCommand } from "./cmds/break";
import { extendCommand } from "./cmds/extend";
@@ -120,6 +122,8 @@ export const COMMANDS: Record<string, Command> = {
array: arrayCommand,
offset: offsetCommand,
extrude: extrudeCommand,
revolve: revolveCommand,
loft: loftCommand,
trim: trimCommand,
break: breakCommand,
extend: extendCommand,
@@ -244,6 +248,9 @@ export const ALIASES: Record<string, string> = {
feld: "array",
o: "offset",
ex: "extrude",
rev: "revolve",
rotation: "revolve",
lf: "loft",
tr: "trim",
br: "break",
unterbrechen: "break",
+11
View File
@@ -1839,6 +1839,17 @@ export const de = {
"cmd.offset.label": "Versatz",
"cmd.offset.pick": "Kurve wählen:",
"cmd.offset.side": "Seite oder Distanz:",
"cmd.revolve.label": "Rotationskörper",
"cmd.revolve.pick": "Geschlossenes Profil wählen:",
"cmd.revolve.axisA": "Drehachse: Anfangspunkt:",
"cmd.revolve.axisB": "Drehachse: Endpunkt:",
"cmd.revolve.angle": "Drehwinkel (°, Enter = zuletzt):",
"cmd.loft.label": "Loft",
"cmd.loft.pick": "Profile der Reihe nach wählen (unten zuerst):",
"cmd.loft.pickMore": "Weiteres Profil wählen oder Enter:",
"cmd.loft.height": "Gesamthöhe:",
"history.cmd.revolve": "Rotationskörper",
"history.cmd.loft": "Loft",
"cmd.extrude.label": "Extrudieren",
"cmd.extrude.pick": "Geschlossenes Profil wählen:",
"cmd.extrude.height": "Höhe:",
+11
View File
@@ -1827,6 +1827,17 @@ export const en: Record<TranslationKey, string> = {
"cmd.offset.label": "Offset",
"cmd.offset.pick": "Select curve:",
"cmd.offset.side": "Side or distance:",
"cmd.revolve.label": "Revolve",
"cmd.revolve.pick": "Select closed profile:",
"cmd.revolve.axisA": "Revolve axis: start point:",
"cmd.revolve.axisB": "Revolve axis: end point:",
"cmd.revolve.angle": "Revolve angle (°, Enter = last):",
"cmd.loft.label": "Loft",
"cmd.loft.pick": "Select profiles in order (bottom first):",
"cmd.loft.pickMore": "Select another profile or Enter:",
"cmd.loft.height": "Total height:",
"history.cmd.revolve": "Revolve",
"history.cmd.loft": "Loft",
"cmd.extrude.label": "Extrude",
"cmd.extrude.pick": "Select closed profile:",
"cmd.extrude.height": "Height:",
+1 -1
View File
@@ -355,7 +355,7 @@ const TOOLS_2D: ToolId[] = [
"image",
];
const TOOLS_3D: ToolId[] = ["wall", "ceiling", "window", "door", "stair", "room"];
const COMMANDS_3D = ["column", "ceilingopening", "roof", "roofhole", "roofwindow", "dormer", "extrude", "solid", "solidbool", "sectionline", "viewline", "autodim"];
const COMMANDS_3D = ["column", "ceilingopening", "roof", "roofhole", "roofwindow", "dormer", "extrude", "revolve", "loft", "solid", "solidbool", "sectionline", "viewline", "autodim"];
const COMMANDS_EDIT = ["move", "copy", "array", "rotate", "mirror", "offset", "multiline", "trim", "break", "extend", "fillet", "chamfer", "join", "defblock", "measure"];
type ToolsView = "list" | "icons";
+18
View File
@@ -225,6 +225,24 @@ export function CommandIcon({ name }: { name: string }) {
<path d="M9.5 12.5 L12.5 9.5 L12.5 4.5" />
</svg>
);
case "revolve":
// Rotationskörper: Profil neben einer Achse, Drehbogen.
return (
<svg {...common}>
<path d="M8 2.5 V13.5" strokeDasharray="1.4 1.2" />
<path d="M9.5 4.5 H13 V11.5 H9.5 Z" />
<path d="M6.5 4.5 H3 V11.5 H6.5" />
</svg>
);
case "loft":
// Loft: grosses Profil unten, kleines oben, verbunden.
return (
<svg {...common}>
<rect x="2.5" y="9.5" width="11" height="3" />
<rect x="5.5" y="3.5" width="5" height="2" />
<path d="M2.5 9.5 L5.5 5.5 M13.5 9.5 L10.5 5.5" />
</svg>
);
case "voidbox":
// Durchbruch: Wand mit gestricheltem, durchkreuztem Ausschnitt.
return (