[222] Volumenstudie → Bauteile: Körper in Aussenwände je Geschoss, Decken und Flachdach umwandeln
Neuer Befehl solidtoparts (koerperinbauteile): gewählter Körper oder Klick; ein Undo-Schritt. Kern cmd_massing.rs: bestehende Geschosse nutzen, fehlende obenauf anlegen; Wände mit Aussenfläche auf der Körperkante (Referenz left), Decken/Dach wie beim Zeichnen (ceiling_item/roof_item aus cmd_create.rs), Körper entfällt. Nicht abgedeckte Körper (verjüngt, Kugel/Kegel, verrundet, Abzugskörper, selbstschneidend, UK zwischen Geschossen) werden mit Meldung abgelehnt. Tests: Rust, vitest, e2e [222] statt fixme.
This commit is contained in:
15 files changed
+817
-27
No files matched your search
@@ -29,7 +29,7 @@ Ribbon-Befehle sie erreichen: `src/state/useToolInput.ts`.
|
||||
| Gruppe | Module |
|
||||
|---|---|
|
||||
| Bauteile | `wall.ts`, `opening.ts`, `ceiling.ts`, `ceilingOpening.ts`, `roof.ts`, `roofHole.ts`, `roofWindow.ts`, `dormer.ts`, `stair.ts`, `column.ts`, `room.ts`, `grid.ts`, `tree.ts`, `terrain.ts`, `excavation.ts` |
|
||||
| Körper | `solid.ts`, `solidbool.ts`, `voidbox.ts`, `extrude.ts`, `revolve.ts`, `loft.ts` |
|
||||
| Körper | `solid.ts`, `solidbool.ts`, `solidToParts.ts` (Körper → Bauteile, [222]), `voidbox.ts`, `extrude.ts`, `revolve.ts`, `loft.ts` |
|
||||
| 2D zeichnen | `line.ts`, `xline.ts`, `ray.ts`, `polyline.ts`, `polygon.ts`, `rect.ts`, `circle.ts`, `arc.ts`, `ellipse.ts`, `bezier.ts`, `spline.ts`, `multiline.ts`, `revcloud.ts`, `wipeout.ts`, `block.ts`, `defblock.ts` |
|
||||
| Beschriften | `text.ts`, `textbox.ts`, `textpath.ts`, `leader.ts`, `dimension.ts`, `dimround.ts`, `dimdetach.ts`, `autodim.ts`, `kote.ts`, `detailref.ts`, `pointmarker.ts`, `scalebar.ts`, `sectionline.ts` |
|
||||
| Bearbeiten | `transform.ts` (Bewegen, Drehen, Spiegeln), `copy.ts`, `scale.ts`, `array.ts`, `align.ts`, `offset.ts`, `trim.ts`, `extend.ts`, `fillet.ts`, `chamfer.ts`, `cornerHit.ts`, `break.ts`, `split.ts`, `join.ts`, `explode.ts` |
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* [222] „Körper in Bauteile umwandeln": gewählter Körper → Aussenwände je Geschoss, Decken, Flachdach (ein Commit),
|
||||
* fehlende Geschosse obenauf; Unsinn (verjüngt, UK zwischen Geschossen) mit Meldung abgelehnt; ohne Auswahl Klick.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { solidToPartsCommand } from "./solidToParts";
|
||||
import { resolveCommand } from "../registry";
|
||||
import type { CommandContext, Project } from "../types";
|
||||
import type { ExtrudedSolid } from "../../model/types";
|
||||
|
||||
/** L-förmiger Körper (konkav) 10 × 8 m, Höhe `h`, auf dem EG. */
|
||||
const solid = (h: number, extra: Partial<ExtrudedSolid> = {}): ExtrudedSolid => ({
|
||||
id: "K",
|
||||
type: "extrudedSolid",
|
||||
levelId: "eg",
|
||||
categoryCode: "90",
|
||||
points: [{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 4 }, { x: 4, y: 4 }, { x: 4, y: 8 }, { x: 0, y: 8 }],
|
||||
height: h,
|
||||
...extra,
|
||||
});
|
||||
|
||||
function project(s: ExtrudedSolid): Project {
|
||||
return {
|
||||
id: "t",
|
||||
name: "T",
|
||||
lineStyles: [],
|
||||
hatches: [],
|
||||
components: [{ id: "c", name: "Beton", color: "#999999" }] as Project["components"],
|
||||
wallTypes: [{ id: "aw", name: "Aussenwand", layers: [{ componentId: "c", thickness: 0.3 }] }],
|
||||
ceilingTypes: [{ id: "ct", name: "Decke", layers: [{ componentId: "c", thickness: 0.25 }] }],
|
||||
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 3, cutHeight: 1.0, baseElevation: 0 }],
|
||||
layers: [
|
||||
{ code: "20", name: "Wände", color: "#000000", lw: 0.5, visible: true, locked: false },
|
||||
{ code: "90", name: "Körper", color: "#000000", lw: 0.25, visible: true, locked: false },
|
||||
],
|
||||
walls: [],
|
||||
openings: [],
|
||||
ceilings: [],
|
||||
stairs: [],
|
||||
rooms: [],
|
||||
drawings2d: [],
|
||||
context: [],
|
||||
extrudedSolids: [s],
|
||||
} as Project;
|
||||
}
|
||||
|
||||
const ctxOf = (p: Project, solidId: string | null): CommandContext =>
|
||||
({
|
||||
project: p,
|
||||
level: p.drawingLevels[0],
|
||||
defaultCategoryCode: "90",
|
||||
activeLineStyleId: "solid",
|
||||
activeWallTypeId: "aw",
|
||||
lastPoint: null,
|
||||
selection: { wallIds: [], drawingId: null, drawingIds: [], extrudedSolidId: solidId },
|
||||
}) as CommandContext;
|
||||
|
||||
describe("solidToPartsCommand", () => {
|
||||
it("Name und Kürzel", () => {
|
||||
expect(resolveCommand("solidtoparts")?.name).toBe("solidtoparts");
|
||||
expect(resolveCommand("koerperinbauteile")?.name).toBe("solidtoparts");
|
||||
});
|
||||
|
||||
it("gewählter Körper 9 m: drei Geschosse (zwei neu), 6 Wände je Geschoss, 2 Decken, Flachdach, Körper weg", () => {
|
||||
const p = project(solid(9));
|
||||
const r = solidToPartsCommand.autoRun!(ctxOf(p, "K"));
|
||||
expect(r.done).toBe(true);
|
||||
expect(r.notice).toMatchObject({ key: "cmd.solidtoparts.done", params: { stories: 3, newFloors: 2, walls: 18, ceilings: 2 } });
|
||||
const next = r.commit!(p);
|
||||
expect(next.extrudedSolids ?? []).toHaveLength(0);
|
||||
const floors = next.drawingLevels.filter((l) => l.kind === "floor");
|
||||
expect(floors.map((f) => [f.name, f.baseElevation, f.floorHeight])).toEqual([
|
||||
["EG", 0, 3],
|
||||
["Geschoss 2", 3, 3],
|
||||
["Geschoss 3", 6, 3],
|
||||
]);
|
||||
expect(next.walls).toHaveLength(18);
|
||||
expect(next.walls.every((w) => w.wallTypeId === "aw" && w.height === 3 && w.referenceLine === "left" && w.isExternal)).toBe(true);
|
||||
expect(next.walls.filter((w) => w.floorId === "eg")).toHaveLength(6);
|
||||
expect((next.ceilings ?? []).map((c) => c.ceilingTypeId)).toEqual(["ct", "ct"]);
|
||||
expect(next.roofs).toHaveLength(1);
|
||||
expect(next.roofs![0]).toMatchObject({ shape: "flach", overhang: 0, floorId: floors[2].id });
|
||||
});
|
||||
|
||||
it("lehnt verjüngte Körper und Körper zwischen Geschossen mit Meldung ab (kein Commit)", () => {
|
||||
const tapered = solidToPartsCommand.autoRun!(ctxOf(project(solid(6, { taper: 0.4 })), "K"));
|
||||
expect(tapered).toMatchObject({ done: true, notice: { key: "cmd.solidtoparts.reject.tapered", kind: "warning" } });
|
||||
expect(tapered.commit).toBeUndefined();
|
||||
const floating = solidToPartsCommand.autoRun!(ctxOf(project(solid(6, { baseOffset: 1.3 })), "K"));
|
||||
expect(floating.notice?.key).toBe("cmd.solidtoparts.reject.base");
|
||||
expect(floating.commit).toBeUndefined();
|
||||
});
|
||||
|
||||
it("ohne Auswahl: Klick in den Körper wandelt um, Klick daneben meldet", () => {
|
||||
const p = project(solid(3));
|
||||
const ctx = ctxOf(p, null);
|
||||
expect(solidToPartsCommand.autoRun!(ctx).done).toBeFalsy();
|
||||
const [, miss] = solidToPartsCommand.onInput(solidToPartsCommand.init(), { kind: "point", point: { x: 8, y: 7 } }, ctx);
|
||||
expect(miss.commit).toBeUndefined();
|
||||
expect(miss.notice?.key).toBe("cmd.solidtoparts.noSolid");
|
||||
const [, hit] = solidToPartsCommand.onInput(solidToPartsCommand.init(), { kind: "point", point: { x: 1, y: 1 } }, ctx);
|
||||
const next = hit.commit!(p);
|
||||
expect(next.walls).toHaveLength(6);
|
||||
expect(next.ceilings).toHaveLength(0);
|
||||
expect(next.roofs).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
// [222] Volumenstudie → Bauteile: ein gewählter Körper (Massenmodell) wird zu Aussenwänden je Geschoss, Decken
|
||||
// und Flachdach; fehlende Geschosse legt der Kern obenauf an, der Körper entfällt. Ein Undo-Schritt.
|
||||
// Ist ein Körper gewählt, läuft der Befehl sofort; sonst „Körper wählen“ (Klick in seine Grundfläche).
|
||||
// Rechnung und Prüfung im Kern (`cmd_massing.rs`); was er nicht abdeckt (geneigt, Kugel/Kegel/Torus, verrundet, Abzugskörper,
|
||||
// selbstschneidend, UK zwischen Geschossen), lehnt der Befehl mit einer Meldung ab.
|
||||
|
||||
import type { Command, CommandContext, CommandResult, CommandState } from "../types";
|
||||
import { createMutation, createQuery, xy } from "../createCore";
|
||||
import { t, type TranslationKey } from "../../i18n";
|
||||
|
||||
/** Ergebnis der Prüfung im Kern (`cmd_massing::check`). */
|
||||
export interface SolidToPartsCheck {
|
||||
ok: boolean;
|
||||
reason: string | null;
|
||||
stories?: number;
|
||||
newFloors?: number;
|
||||
walls?: number;
|
||||
ceilings?: number;
|
||||
}
|
||||
|
||||
/** Namensmuster neuer Geschosse („Geschoss {n}“, der Kern setzt die Nummer ein). */
|
||||
const floorName = (): string => t("default.floorName");
|
||||
|
||||
export function checkSolidToParts(ctx: CommandContext, id: string): SolidToPartsCheck {
|
||||
return createQuery<SolidToPartsCheck>(ctx.project, { q: "solidToParts", id, floorName: floorName() });
|
||||
}
|
||||
|
||||
/** Umwandeln (Commit + Meldung) oder ablehnen (nur Meldung). */
|
||||
function convert(ctx: CommandContext, id: string): CommandResult {
|
||||
const c = checkSolidToParts(ctx, id);
|
||||
if (!c.ok) {
|
||||
return { draft: null, done: true, notice: { key: `cmd.solidtoparts.reject.${c.reason ?? "none"}` as TranslationKey, kind: "warning" } };
|
||||
}
|
||||
return {
|
||||
draft: null,
|
||||
done: true,
|
||||
commit: createMutation(ctx, { cmd: "solidToParts", id, floorName: floorName() }),
|
||||
notice: { key: "cmd.solidtoparts.done", params: { stories: c.stories ?? 0, newFloors: c.newFloors ?? 0, walls: c.walls ?? 0, ceilings: c.ceilings ?? 0 }, kind: "info" },
|
||||
};
|
||||
}
|
||||
|
||||
const idle = (): CommandState => ({ phase: "pick", lastPoint: null });
|
||||
|
||||
export const solidToPartsCommand: Command = {
|
||||
name: "solidtoparts",
|
||||
labelKey: "cmd.solidtoparts.label",
|
||||
floorOnly: true,
|
||||
prompt: () => "cmd.solidtoparts.pick",
|
||||
accepts: () => ["point"],
|
||||
options: () => [],
|
||||
init: idle,
|
||||
|
||||
autoRun: (ctx): CommandResult => {
|
||||
const id = ctx.selection.extrudedSolidId;
|
||||
return id ? convert(ctx, id) : { draft: null };
|
||||
},
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
if (input.kind !== "point") return [state, { draft: null }];
|
||||
const hit = createQuery<{ hit: string | null }>(ctx.project, { q: "pickSolid", level: ctx.level.id, pt: xy(input.point) }).hit;
|
||||
if (!hit) return [state, { draft: null, notice: { key: "cmd.solidtoparts.noSolid", kind: "info" } }];
|
||||
return [idle(), convert(ctx, hit)];
|
||||
},
|
||||
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
|
||||
onConfirm: (): [CommandState, CommandResult] => [idle(), { draft: null, done: true }],
|
||||
onCancel: (): [CommandState, CommandResult] => [idle(), { draft: null, done: true }],
|
||||
};
|
||||
@@ -17,6 +17,7 @@ import { circlesToTreesCommand, treeCommand } from "./cmds/tree";
|
||||
import { roofCommand } from "./cmds/roof";
|
||||
import { solidCommand } from "./cmds/solid";
|
||||
import { solidBoolCommand } from "./cmds/solidbool";
|
||||
import { solidToPartsCommand } from "./cmds/solidToParts";
|
||||
import { voidBoxCommand } from "./cmds/voidbox";
|
||||
import { ceilingOpeningCommand } from "./cmds/ceilingOpening";
|
||||
import { roofWindowCommand } from "./cmds/roofWindow";
|
||||
@@ -93,6 +94,7 @@ export const COMMANDS: Record<string, Command> = {
|
||||
roof: roofCommand,
|
||||
solid: solidCommand,
|
||||
solidbool: solidBoolCommand,
|
||||
solidtoparts: solidToPartsCommand,
|
||||
voidbox: voidBoxCommand,
|
||||
ceilingopening: ceilingOpeningCommand,
|
||||
roofwindow: roofWindowCommand,
|
||||
@@ -186,6 +188,8 @@ export const ALIASES: Record<string, string> = {
|
||||
stütze: "column",
|
||||
baum: "tree",
|
||||
kreiseinbaeume: "circlestotrees",
|
||||
koerperinbauteile: "solidtoparts",
|
||||
volumenzubauteilen: "solidtoparts",
|
||||
dach: "roof",
|
||||
koerper: "solid",
|
||||
durchbruch: "voidbox",
|
||||
|
||||
Reference in new issue
Block a user