[267] Ansichten aller Seiten: Befehl ansichten und Menü Ansicht legen Nord/Ost/Süd/West um das Gebäude an (Hauptrichtung aus minimalem Hüllrechteck, vorhandene Seiten ausgelassen, ein Undo-Schritt)
This commit is contained in:
21 files changed
+646
-9
No files matched your search
@@ -0,0 +1,59 @@
|
||||
// [267] Befehl `ansichten`: Ansichten Nord/Ost/Süd/West um das Gebäude in einem Schritt. Geometrie (Hauptrichtung,
|
||||
// gedrehtes Haus, L-Form) prüft der Kern (`elevation_set.rs`); hier der Weg über Befehl, Meldung und Ops.
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { elevationsCommand } from "./elevations";
|
||||
import { emptyProject, sampleProject } from "../../model/sampleProject";
|
||||
import type { Project } from "../../model/types";
|
||||
import type { CommandContext } from "../types";
|
||||
import { applyOps } from "../../core/ops";
|
||||
import { getCommand } from "../registry";
|
||||
|
||||
const ctxOf = (p: Project) => ({ project: p, level: { id: "eg", kind: "floor" }, defaultCategoryCode: "20", activeWallTypeId: "", selection: { wallIds: [], drawingId: null } }) as unknown as CommandContext;
|
||||
|
||||
const run = (p: Project) => elevationsCommand.autoRun!(ctxOf(p));
|
||||
const apply = (p: Project) => {
|
||||
const res = run(p);
|
||||
return { res, project: res.commit ? applyOps(p, res.commit.toOps(p)) : p };
|
||||
};
|
||||
const elevations = (p: Project) => p.drawingLevels.filter((l) => l.kind === "elevation");
|
||||
|
||||
describe("ansichten", () => {
|
||||
it("ist als Befehl und Alias registriert", () => {
|
||||
expect(getCommand("ansichten")).toBe(elevationsCommand);
|
||||
});
|
||||
|
||||
it("Musterhaus: legt Nord, Ost, West an; die vorhandene Süd-Ansicht bleibt", () => {
|
||||
const before = elevations(sampleProject);
|
||||
expect(before.map((l) => l.name)).toEqual(["Ansicht Süd"]);
|
||||
const { res, project } = apply(sampleProject);
|
||||
expect(res.done).toBe(true);
|
||||
expect(res.notice?.key).toBe("elevations.doneSkipped");
|
||||
expect(res.notice?.params).toMatchObject({ n: 3 });
|
||||
const names = elevations(project).map((l) => l.name);
|
||||
expect(names).toEqual(["Ansicht Süd", "Ansicht Nord", "Ansicht Ost", "Ansicht West"]);
|
||||
for (const l of elevations(project)) {
|
||||
expect(l.linePoints).toHaveLength(2);
|
||||
expect(l.directionSign).toBe(1);
|
||||
}
|
||||
// Nord blickt nach −y (Linie nördlich des Hauses, von rechts nach links), Ost nach −x.
|
||||
const nord = elevations(project).find((l) => l.name === "Ansicht Nord")!.linePoints!;
|
||||
expect(nord[1].x).toBeLessThan(nord[0].x);
|
||||
expect(nord[0].y).toBeGreaterThan(4);
|
||||
});
|
||||
|
||||
it("zweiter Lauf: nichts mehr zu tun, keine Änderung", () => {
|
||||
const { project } = apply(sampleProject);
|
||||
const again = apply(project);
|
||||
expect(again.res.commit).toBeUndefined();
|
||||
expect(again.res.notice?.key).toBe("elevations.allExist");
|
||||
expect(elevations(again.project)).toHaveLength(4);
|
||||
});
|
||||
|
||||
it("leeres Projekt: Meldung, keine Ebenen", () => {
|
||||
const { res, project } = apply(emptyProject);
|
||||
expect(res.commit).toBeUndefined();
|
||||
expect(res.notice).toMatchObject({ key: "elevations.empty", kind: "warning" });
|
||||
expect(elevations(project)).toHaveLength(elevations(emptyProject).length);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
// [267] Ansichten aller Seiten — legt die Ansichten Nord/Ost/Süd/West um das Gebäude an und endet sofort
|
||||
// (Null-Schritt-Befehl wie `terrain`). Rechnung im Kern (`elevation_set.rs`), Brücke in `commands/elevationSetFor.ts`.
|
||||
|
||||
import { elevationSetFor } from "../elevationSetFor";
|
||||
import type { Command, CommandContext, CommandResult, CommandState } from "../types";
|
||||
|
||||
const IDLE: CommandState = { phase: "idle", lastPoint: null };
|
||||
|
||||
const run = (ctx: CommandContext): CommandResult => {
|
||||
const { commit, notice } = elevationSetFor(ctx.project);
|
||||
return { draft: null, done: true, ...(commit ? { commit } : {}), notice };
|
||||
};
|
||||
|
||||
export const elevationsCommand: Command = {
|
||||
name: "ansichten",
|
||||
labelKey: "cmd.elevations.label",
|
||||
prompt: () => "cmd.elevations.prompt",
|
||||
accepts: () => [],
|
||||
options: () => [],
|
||||
init: () => ({ ...IDLE }),
|
||||
autoRun: run,
|
||||
onInput: (_s, _i, ctx): [CommandState, CommandResult] => [{ ...IDLE }, run(ctx)],
|
||||
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
|
||||
onConfirm: (_s, ctx): [CommandState, CommandResult] => [{ ...IDLE }, run(ctx)],
|
||||
onCancel: (): [CommandState, CommandResult] => [{ ...IDLE }, { draft: null, done: true }],
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
// [267] Ansichten Nord/Ost/Süd/West in einem Schritt: der Kern (`elevation_set.rs`) legt um das Gebaute vier
|
||||
// Ansichtslinien an und lässt Seiten mit vorhandener Ansicht aus. Hier nur die Brücke: Namen (t()), Abfrage vorab
|
||||
// für die Meldung, Mutation. Gebraucht vom Befehl `ansichten` und vom Menü (`state/elevationSet.ts`); ohne Store, damit der Befehl keinen Importzyklus über die Registry bildet.
|
||||
|
||||
import { cmdMutation, documentFor } from "../core/document";
|
||||
import type { ProjectMutation } from "../core";
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { uniqueStamp } from "../tools/types";
|
||||
|
||||
type Side = "north" | "east" | "south" | "west";
|
||||
|
||||
const NAME_KEY: Record<Side, TranslationKey> = {
|
||||
north: "elevations.name.north",
|
||||
east: "elevations.name.east",
|
||||
south: "elevations.name.south",
|
||||
west: "elevations.name.west",
|
||||
};
|
||||
|
||||
interface Plan {
|
||||
empty: boolean;
|
||||
create: Side[];
|
||||
existing: Side[];
|
||||
}
|
||||
|
||||
/** Meldung (i18n-Key + Platzhalter + Art) zum Ergebnis. */
|
||||
export interface ElevationSetNotice {
|
||||
key: TranslationKey;
|
||||
params?: Record<string, string | number>;
|
||||
kind: "info" | "warning";
|
||||
}
|
||||
|
||||
const names = (sides: Side[]): string => sides.map((s) => t(NAME_KEY[s])).join(", ");
|
||||
|
||||
/** Mutation (nur wenn etwas entsteht) und Meldung für `project`. */
|
||||
export function elevationSetFor(project: Project): { commit?: ProjectMutation; notice: ElevationSetNotice } {
|
||||
const plan = documentFor(project).createQuery<Plan>({ q: "elevationsPlan" });
|
||||
if (plan.empty) return { notice: { key: "elevations.empty", kind: "warning" } };
|
||||
if (plan.create.length === 0) return { notice: { key: "elevations.allExist", kind: "info" } };
|
||||
const commit = cmdMutation({
|
||||
cmd: "elevations",
|
||||
names: { north: t(NAME_KEY.north), east: t(NAME_KEY.east), south: t(NAME_KEY.south), west: t(NAME_KEY.west) },
|
||||
stamp: uniqueStamp(),
|
||||
});
|
||||
const done = { n: plan.create.length, names: names(plan.create) };
|
||||
const notice: ElevationSetNotice = plan.existing.length
|
||||
? { key: "elevations.doneSkipped", params: { ...done, existing: names(plan.existing) }, kind: "info" }
|
||||
: { key: "elevations.done", params: done, kind: "info" };
|
||||
return { commit, notice };
|
||||
}
|
||||
@@ -72,6 +72,7 @@ import { excavationCommand } from "./cmds/excavation";
|
||||
import { meshCropCommand } from "./cmds/meshcrop";
|
||||
import { measureCommand } from "./cmds/measure";
|
||||
import { sectionLineCommand, viewLineCommand } from "./cmds/sectionline";
|
||||
import { elevationsCommand } from "./cmds/elevations";
|
||||
import { georefCommand } from "./cmds/georef";
|
||||
import { blockCommand } from "./cmds/block";
|
||||
import { defblockCommand } from "./cmds/defblock";
|
||||
@@ -162,6 +163,7 @@ export const COMMANDS: Record<string, Command> = {
|
||||
measure: measureCommand,
|
||||
sectionline: sectionLineCommand,
|
||||
viewline: viewLineCommand,
|
||||
ansichten: elevationsCommand,
|
||||
georef: georefCommand,
|
||||
block: blockCommand,
|
||||
defblock: defblockCommand,
|
||||
@@ -326,6 +328,8 @@ export const ALIASES: Record<string, string> = {
|
||||
netzzuschnitt: "meshcrop",
|
||||
schnittlinie: "sectionline",
|
||||
ansichtslinie: "viewline",
|
||||
elevations: "ansichten",
|
||||
fassaden: "ansichten",
|
||||
bezugspunkt: "georef",
|
||||
nullpunkt: "georef",
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user