[K4] Zeichenbefehle im Kern: Elemente, Vorschauen, Gruppen-Zuordnung
Alle Erzeuge-Befehle bauen ihre Elemente im Kern: cmd_create.rs (Wand, Decke, Raum, Treppe, Öffnung, Dach, Stütze, Extrusion), cmd_draw.rs (2D-Formen, Texte, Bemassung, autodim), cmd_solid.rs (solid, solidbool, voidbox, terrain, Deckenöffnung, Dachhof, Schnittlinie). Vorschauen über doc_create_preview(_again) ohne JSON je Mausschritt, Abfragen über doc_create_query; Gruppen-Zuordnung als `group` im Request ersetzt activeGroupOps. TS hält nur die Zustandsautomaten (commands/createCore.ts). Ersetzte TS-Geometrie und alte Werkzeug-Commits in tools/tools.ts gelöscht. Gleichheit alt/neu mit zeitweiligen Zufallstests geprüft (s. TODO.md). Die drei Gruppen hängen über den gemeinsamen Dispatcher zusammen und sind deshalb ein Commit.
This commit is contained in:
92 files changed
+4169
-4744
No files matched your search
@@ -7,7 +7,6 @@
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
activeGroupOps,
|
||||
applyGroupDimming,
|
||||
applyGroupDimmingToPlan,
|
||||
containingGroupId,
|
||||
@@ -22,7 +21,7 @@ import { materializeUnderlay, type Plan } from "../plan/generatePlan";
|
||||
import type { Drawing2D, Group, Project } from "../model/types";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { addItems, replaceItem } from "../core/opsBuild";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
const EMPTY_MEM = {
|
||||
wallIds: [] as string[],
|
||||
@@ -214,45 +213,48 @@ describe("applyGroupDimmingToPlan", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("activeGroupOps ([K4] S3: neue Elemente in die aktive Gruppe, als Ops)", () => {
|
||||
describe("Zeichnen in der aktiven Gruppe ([K4] S3: Gruppen-Zuordnung im Kern, `cmd_create::group_ops`)", () => {
|
||||
const g1: Group = { id: "g1", wallIds: ["w1"], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] };
|
||||
const line = (id: string) =>
|
||||
({ id, type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 1, y: 0 } } }) as Project["drawings2d"][number];
|
||||
/** Wendet `ops` plus die Gruppen-Ops an (wie `EngineHost.commit` in App.tsx). */
|
||||
const commit = (before: Project, ops: CoreOp[], path: string[]) => applyOps(before, [...ops, ...activeGroupOps(before, ops, path)]);
|
||||
const ctx = { level: "eg", cat: "20" };
|
||||
/** Befehl im Kern rechnen (mit `group` wie `EngineHost.commit` in App.tsx) und anwenden. */
|
||||
const ops = (before: Project, req: object, group?: string): CoreOp[] =>
|
||||
documentFor(before).cmdOps({ ...req, ctx, stamp: "t", ...(group ? { group } : {}) });
|
||||
const commit = (before: Project, req: object, group?: string) => applyOps(before, ops(before, req, group));
|
||||
const lineReq = { cmd: "line", a: [0, 0], b: [2, 0] };
|
||||
|
||||
it("neu gezeichnetes Element wird Mitglied der aktiven (innersten) Gruppe", () => {
|
||||
const result = commit(project([g1]), addItems("drawings2d", [line("d1")]), ["g1"]);
|
||||
const result = commit(project([g1]), lineReq, "g1");
|
||||
const g = result.groups!.find((x) => x.id === "g1")!;
|
||||
expect(g.drawingIds).toEqual(["d1"]);
|
||||
expect(g.drawingIds).toEqual(["dr2d-t-1"]);
|
||||
expect(g.wallIds).toEqual(["w1"]); // bestehende Mitgliedschaft bleibt
|
||||
});
|
||||
|
||||
it("ohne aktive Gruppe (groupPath leer) keine zusätzlichen Ops", () => {
|
||||
expect(activeGroupOps(project([g1]), addItems("drawings2d", [line("d1")]), [])).toEqual([]);
|
||||
it("ohne aktive Gruppe keine zusätzlichen Ops", () => {
|
||||
expect(ops(project([g1]), lineReq)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("ohne neue Elemente (nur Ersetzen) keine zusätzlichen Ops", () => {
|
||||
const p: Project = { ...project([g1]), drawings2d: [line("d0")] };
|
||||
expect(activeGroupOps(p, [replaceItem("drawings2d", { ...line("d0"), color: "#f00" })], ["g1"])).toEqual([]);
|
||||
expect(activeGroupOps(p, [], ["g1"])).toEqual([]);
|
||||
const move = { cmd: "transform", sel: { drawingIds: ["d0"] }, op: "move", pts: [[0, 0], [1, 0]], mode: "move", count: 1 };
|
||||
expect(ops(p, move, "g1").map((o) => o.kind)).toEqual(["replace"]);
|
||||
});
|
||||
|
||||
it("unbekannte aktive Gruppe: keine zusätzlichen Ops", () => {
|
||||
expect(activeGroupOps(project([g1]), addItems("drawings2d", [line("d1")]), ["gx"])).toEqual([]);
|
||||
expect(ops(project([g1]), lineReq, "gx")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("mehrere neue Elemente auf einmal (z. B. Feld/Array) werden alle Mitglied", () => {
|
||||
const result = commit(project([g1]), addItems("drawings2d", [line("d1"), line("d2"), line("d3")]), ["g1"]);
|
||||
const g = result.groups!.find((x) => x.id === "g1")!;
|
||||
expect(g.drawingIds.sort()).toEqual(["d1", "d2", "d3"]);
|
||||
it("mehrere neue Elemente auf einmal (Mehrfachlinie) werden alle Mitglied", () => {
|
||||
const result = commit(project([g1]), { cmd: "multiline", a: [0, 0], b: [4, 0], spacing: 0.3, sign: 1, count: 3 }, "g1");
|
||||
expect(result.groups!.find((x) => x.id === "g1")!.drawingIds).toEqual(["dr2d-t-1", "dr2d-t-2", "dr2d-t-3"]);
|
||||
});
|
||||
|
||||
it("verschachtelt: neues Element landet in der INNERSTEN (aktiven) Gruppe, nicht der äusseren", () => {
|
||||
const inner: Group = { id: "g1", wallIds: [], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] };
|
||||
const outer: Group = { id: "g2", wallIds: [], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: ["g1"] };
|
||||
const result = commit(project([inner, outer]), addItems("drawings2d", [line("d1")]), ["g2", "g1"]);
|
||||
expect(result.groups!.find((x) => x.id === "g1")!.drawingIds).toEqual(["d1"]);
|
||||
const result = commit(project([inner, outer]), lineReq, "g1");
|
||||
expect(result.groups!.find((x) => x.id === "g1")!.drawingIds).toEqual(["dr2d-t-1"]);
|
||||
expect(result.groups!.find((x) => x.id === "g2")!.drawingIds).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,11 +9,9 @@ import type { Drawing2D, Group, Project } from "../model/types";
|
||||
import type { Plan, UnderlayGroup } from "../core";
|
||||
import { uniqueId } from "../tools/types";
|
||||
import type { Primitive } from "../core";
|
||||
import { applyOps } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import { addItems, itemsOf, patchItem, removeItems } from "../core";
|
||||
import type { EntityCollection } from "../core";
|
||||
import { EMPTY_MEMBERSHIP, transitiveMembership } from "../core";
|
||||
import { addItems, removeItems } from "../core";
|
||||
import { transitiveMembership } from "../core";
|
||||
import type { GroupMembership, MemberKind } from "../core";
|
||||
|
||||
export type { GroupMembership, MemberKind } from "../core";
|
||||
@@ -113,58 +111,6 @@ export function applyGroupDimmingToPlan(plan: Plan, project: Project, groupPath:
|
||||
return { ...plan, primitives, underlay };
|
||||
}
|
||||
|
||||
/** Liste je Mitgliedsart. */
|
||||
const COLLECTION_OF: Record<MemberKind, EntityCollection> = {
|
||||
wallIds: "walls",
|
||||
drawingIds: "drawings2d",
|
||||
ceilingIds: "ceilings",
|
||||
roomIds: "rooms",
|
||||
stairIds: "stairs",
|
||||
columnIds: "columns",
|
||||
roofIds: "roofs",
|
||||
openingIds: "openings",
|
||||
};
|
||||
|
||||
/**
|
||||
* Zeichnet man WÄHREND man eine Gruppe betreten hat (Isolation) ein neues Element, wird es
|
||||
* automatisch Mitglied dieser (innersten) Gruppe — man zeichnet ja SICHTLICH „in" ihr
|
||||
* (Nutzer-Wunsch, Vectorworks-Verhalten). Für eine Änderung als Ops ([K4] S3): die zusätzlichen
|
||||
* Ops, die die neu eingefügten Elemente (`add`-Ops) der aktiven Gruppe zuschlagen. Leer ohne
|
||||
* aktive Gruppe oder ohne neue Elemente.
|
||||
*/
|
||||
export function activeGroupOps(before: Project, ops: readonly CoreOp[], groupPath: string[]): CoreOp[] {
|
||||
if (groupPath.length === 0) return [];
|
||||
const addedIds = new Set<string>();
|
||||
const touched = new Set<string>();
|
||||
for (const op of ops) {
|
||||
if (op.kind !== "add") continue;
|
||||
touched.add(op.collection);
|
||||
for (const e of op.items) addedIds.add(e.id);
|
||||
}
|
||||
if (addedIds.size === 0) return [];
|
||||
const after = applyOps(before, ops);
|
||||
const activeId = groupPath[groupPath.length - 1];
|
||||
const g = (after.groups ?? []).find((x) => x.id === activeId);
|
||||
if (!g) return [];
|
||||
const added = { ...EMPTY_MEMBERSHIP };
|
||||
for (const k of KEYS) {
|
||||
const coll = COLLECTION_OF[k];
|
||||
if (!touched.has(coll)) continue;
|
||||
// Reihenfolge wie in der Liste (wie `newIds`); vorher vorhandene ids sind nie neu.
|
||||
const existed = new Set<string>();
|
||||
for (const e of itemsOf(before, coll)) {
|
||||
const id = (e as { id: string }).id;
|
||||
if (addedIds.has(id)) existed.add(id);
|
||||
}
|
||||
added[k] = itemsOf(after, coll)
|
||||
.map((e) => (e as { id: string }).id)
|
||||
.filter((id) => addedIds.has(id) && !existed.has(id));
|
||||
}
|
||||
if (KEYS.every((k) => added[k].length === 0)) return [];
|
||||
const merged: Group = { ...g, ...mergeMembership(g, added) };
|
||||
return patchItem(after, "groups", activeId, () => merged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Gruppe aus einer Mengen-Auswahl (+ optional bereits
|
||||
* gewählte Gruppen, die dabei als Untergruppen verschachtelt werden — „zwei
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import type { Project, Roof } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofGeometry, setRoofEdge } from "../core";
|
||||
import { removeRoofHole, roofGeometry, setRoofEdge } from "../core";
|
||||
import { parseProjectFile, serializeProject } from "../io/projectFormat";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
|
||||
@@ -81,7 +81,7 @@ describe("Kantenneigung über Ops", () => {
|
||||
|
||||
describe("Innenhöfe über Ops", () => {
|
||||
it("Hof hinzufügen und entfernen: je ein Undo-Schritt, Dach spart den Hof aus", () => {
|
||||
getState().updateRoof("RF1", addRoofHole(current(), court));
|
||||
getState().updateRoof("RF1", { holes: [...(current().holes ?? []), court] });
|
||||
expect(current().holes).toEqual([court]);
|
||||
expect(roofGeometry(current(), 0).eavesHoles).toHaveLength(1);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
|
||||
Reference in new issue
Block a user