[332] Höhenlinie: gezeichnete Linien mit getippter Höhe zu Gelände-Höhenlinien (Befehl hl, Knopf im Panel Gelände)
check / check (push) Canceled after 0s
check / licenses (push) Canceled after 0s
check / e2e (push) Canceled after 0s
macos / native (push) Canceled after 0s

This commit is contained in:
Claude committed 2026-11-25 11:09:39 +00:00
1 parent 6c4ea8a2eb
commit 48ce1d5ce6
13 files changed
+537 -1

No files matched your search

+104
View File
@@ -0,0 +1,104 @@
/**
* [332] `contourLineCommand` — gezeichnete Linie anklicken + Höhe tippen → Gelände-Höhenlinie; der Befehl wartet auf die
* nächste Linie und schlägt letzte Höhe + Äquidistanz vor; aus den Höhenlinien entsteht mit „Gelände" ein Netz.
*/
import { beforeEach, describe, expect, it } from "vitest";
import { contourLineCommand, resetContourLineDefaults, suggestedZ } from "./contourLine";
import { terrainCommand } from "./terrain";
import type { CommandContext, CommandState, Project } from "../types";
const line = (id: string, y: number, x0 = 0, x1 = 20) => ({
id,
type: "drawing2d" as const,
levelId: "eg",
categoryCode: "20",
geom: { shape: "spline" as const, pts: [{ x: x0, y }, { x: (x0 + x1) / 2, y: y + 0.5 }, { x: x1, y }], closed: false },
});
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: "14", name: "Höhenlinien", color: "#888888", lw: 0.1, visible: true, locked: false },
{ code: "20", name: "Zeichnung", color: "#0a0a0a", lw: 0.5, visible: true, locked: false },
],
walls: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [line("a", 0), line("b", 5), line("c", 10)],
context: [],
} as Project;
}
const ctxOf = (p: Project, drawingIds: string[] = []): CommandContext => ({
project: p,
level: p.drawingLevels[0],
defaultCategoryCode: "20",
activeLineStyleId: "solid",
activeWallTypeId: "aw",
lastPoint: null,
selection: { wallIds: [], drawingId: drawingIds[0] ?? null, drawingIds },
});
const contours = (p: Project) => (p.context ?? []).flatMap((o) => (o.type === "contourSet" ? o.contours : []));
describe("contourLineCommand", () => {
beforeEach(() => resetContourLineDefaults());
it("Linie anklicken, Höhe tippen → Höhenlinie; nächste Linie mit Vorschlag (Enter); dann Gelände", () => {
let p = project();
const cmd = contourLineCommand;
let s: CommandState = cmd.init();
// Daneben geklickt: Hinweis, kein Wechsel.
let [ns, r] = cmd.onInput(s, { kind: "point", point: { x: 10, y: 2.5 } }, ctxOf(p));
expect(ns.phase).toBe("pick");
expect(r.notice?.key).toBe("cmd.contourLine.noLine");
// Erste Linie (y = 0) mit 450.
[s] = cmd.onInput(s, { kind: "point", point: { x: 0.05, y: 0 } }, ctxOf(p));
expect(s.phase).toBe("height");
[s, r] = cmd.onInput(s, { kind: "number", value: 450 }, ctxOf(p));
p = r.commit!(p);
expect(s.phase).toBe("pick");
expect(contours(p).map((c) => c.z)).toEqual([450]);
expect(p.drawings2d.map((d) => d.id)).toEqual(["b", "c"]);
// Zweite mit 451 → Äquidistanz 1; dritte per Enter: Vorschlag 452.
[s] = cmd.onInput(s, { kind: "point", point: { x: 0.05, y: 5 } }, ctxOf(p));
[s, r] = cmd.onInput(s, { kind: "number", value: 451 }, ctxOf(p));
p = r.commit!(p);
expect(suggestedZ(p)).toBe(452);
[s] = cmd.onInput(s, { kind: "point", point: { x: 0.05, y: 10 } }, ctxOf(p));
[s, r] = cmd.onConfirm(s, ctxOf(p));
p = r.commit!(p);
expect(contours(p).map((c) => c.z)).toEqual([450, 451, 452]);
expect(p.drawings2d).toEqual([]);
// Ein Satz der Klasse „14".
const sets = (p.context ?? []).filter((o) => o.type === "contourSet");
expect(sets.map((o) => o.categoryCode)).toEqual(["14"]);
// Enter beim Wählen: fertig, mit Hinweis.
[, r] = cmd.onConfirm(s, ctxOf(p));
expect(r.done).toBe(true);
expect(r.notice?.key).toBe("cmd.contourLine.done");
// Gelände aus den gezeichneten Höhenlinien.
const t = terrainCommand.autoRun!(ctxOf(p));
const withTerrain = t.commit!(p);
const mesh = (withTerrain.context ?? []).find((o) => o.type === "terrainMesh");
expect(mesh && mesh.type === "terrainMesh" ? mesh.indices.length : 0).toBeGreaterThan(0);
});
it("vorgewählte Linie: getippte Zahl ist gleich ihre Höhe", () => {
const p = project();
const [, r] = contourLineCommand.onInput(contourLineCommand.init(), { kind: "number", value: 3.5 }, ctxOf(p, ["b"]));
const next = r.commit!(p);
expect(contours(next).map((c) => c.z)).toEqual([3.5]);
expect(next.drawings2d.map((d) => d.id)).toEqual(["a", "c"]);
});
});
+122
View File
@@ -0,0 +1,122 @@
// [332] Höhenlinie — eigene Gelände-Höhenlinien aus gezeichneten Linien (Linie, Polylinie, Spline, Bogen, Kreis,
// Ellipse, Rechteck). Ablauf wie beim Extrudieren:
// 1) Linie anklicken (oder eine vorgewählte nehmen),
// 2) „Höhe:" → Zahl tippen, Enter übernimmt den Vorschlag (letzte Höhe + Äquidistanz).
// Die Linie wird zur Höhenlinie (Kern `contour_draw.rs`, ein Undo-Schritt je Linie) und der Befehl wartet auf die
// nächste Linie; Enter/Esc beim Wählen beendet ihn. Daraus erzeugt „Gelände“ das Geländemodell.
import type { Command, CommandContext, CommandResult, CommandState, Project, Vec2 } from "../types";
import { createMutation, createQuery, xy } from "../createCore";
/** Getroffene Linie (Kern): Id, Linienzug, geschlossen? */
export interface LineHit {
id: string;
pts: Vec2[];
closed: boolean;
}
/** Zuletzt getippte Höhe und Äquidistanz (Abstand der letzten beiden Höhen) über Aufrufe hinweg. */
let lastZ: number | null = null;
let step = 1;
/** Nur für Tests: Vorschlag zurücksetzen. */
export function resetContourLineDefaults(): void {
lastZ = null;
step = 1;
}
const query = (project: Project, req: { q: string } & Record<string, unknown>): LineHit | null =>
createQuery<{ hit: LineHit | null }>(project, req).hit ?? null;
/** Höchste vorhandene Höhenlinie (alle Sätze der Kontext-Schicht), sonst null. */
function topContour(project: Project): number | null {
let top: number | null = null;
for (const o of project.context ?? []) {
if (o.type !== "contourSet") continue;
for (const c of o.contours) if (Number.isFinite(c.z) && (top === null || c.z > top)) top = c.z;
}
return top;
}
/** Vorschlag für die nächste Höhe: letzte + Äquidistanz, sonst über der höchsten vorhandenen, sonst 0. */
export function suggestedZ(project: Project): number {
if (lastZ !== null) return lastZ + step;
const top = topContour(project);
return top === null ? 0 : top + step;
}
interface ClPick extends CommandState {
phase: "pick";
}
interface ClHeight extends CommandState {
phase: "height";
hit: LineHit;
}
type ClState = ClPick | ClHeight;
const PICK: ClPick = { phase: "pick", lastPoint: null };
/** Genau eine vorgewählte Linie (sonst null). */
function preselected(ctx: CommandContext): LineHit | null {
const ids = ctx.selection.drawingIds ?? (ctx.selection.drawingId ? [ctx.selection.drawingId] : []);
if (ids.length !== 1 || ctx.selection.wallIds.length > 0) return null;
return query(ctx.project, { q: "contourLine", id: ids[0] });
}
const draftOf = (hit: LineHit, at: Vec2 | null, project: Project): CommandResult => ({
draft: {
preview: [{ kind: "poly", pts: hit.pts, closed: hit.closed }],
vertices: [],
...(at ? { hud: { at, text: `${suggestedZ(project).toFixed(2)} m` } } : {}),
},
});
/** Höhe übernehmen: Höhenlinie anlegen, Vorschlag nachführen, nächste Linie wählen. */
function commit(hit: LineHit, z: number, ctx: CommandContext): [CommandState, CommandResult] {
if (lastZ !== null && Math.abs(z - lastZ) > 1e-9) step = z - lastZ;
lastZ = z;
return [{ ...PICK }, { draft: null, commit: createMutation(ctx, { cmd: "contourLine", source: hit.id, z }) }];
}
export const contourLineCommand: Command = {
name: "contourline",
labelKey: "cmd.contourLine.label",
prompt: (s) => ((s as ClState).phase === "height" ? "cmd.contourLine.height" : "cmd.contourLine.pick"),
// Auch beim Wählen eine Zahl: mit vorgewählter Linie gilt sie sofort als deren Höhe.
accepts: () => ["point", "number"],
options: () => [],
floorOnly: true,
init: (): ClState => ({ ...PICK }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as ClState;
if (s.phase === "pick") {
// Vorgewählte Linie: getippte Zahl ist gleich ihre Höhe (wie beim Extrudieren).
if (input.kind === "number" && Number.isFinite(input.value)) {
const pre = preselected(ctx);
return pre ? commit(pre, input.value, ctx) : [s, { draft: null }];
}
if (input.kind !== "point") return [s, { draft: null }];
const hit = query(ctx.project, { q: "pickContourLine", level: ctx.level.id, pt: xy(input.point) });
if (!hit) return [s, { draft: null, notice: { key: "cmd.contourLine.noLine", kind: "warning" } }];
return [{ phase: "height", hit, lastPoint: null } as ClHeight, draftOf(hit, input.point, ctx.project)];
}
if (input.kind === "number" && Number.isFinite(input.value)) return commit(s.hit, input.value, ctx);
return [s, { draft: null }];
},
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
const s = state as ClState;
if (s.phase === "height") return [s, draftOf(s.hit, point, ctx.project)];
return [s, { draft: null }];
},
// Enter/Rechtsklick: beim Höhen-Schritt den Vorschlag übernehmen; beim Wählen beenden.
onConfirm: (state, ctx): [CommandState, CommandResult] => {
const s = state as ClState;
if (s.phase === "height") return commit(s.hit, suggestedZ(ctx.project), ctx);
return [{ ...PICK }, { draft: null, done: true, notice: { key: "cmd.contourLine.done", kind: "info" } }];
},
onCancel: (): [CommandState, CommandResult] => [{ ...PICK }, { draft: null, done: true }],
};
+5
View File
@@ -62,6 +62,7 @@ import { copyCommand } from "./cmds/copy";
import { arrayCommand } from "./cmds/array";
import { offsetCommand } from "./cmds/offset";
import { extrudeCommand } from "./cmds/extrude";
import { contourLineCommand } from "./cmds/contourLine";
import { revolveCommand } from "./cmds/revolve";
import { loftCommand } from "./cmds/loft";
import { trimCommand } from "./cmds/trim";
@@ -155,6 +156,7 @@ export const COMMANDS: Record<string, Command> = {
array: arrayCommand,
offset: offsetCommand,
extrude: extrudeCommand,
contourline: contourLineCommand,
revolve: revolveCommand,
loft: loftCommand,
trim: trimCommand,
@@ -344,6 +346,9 @@ export const ALIASES: Record<string, string> = {
parallel: "multiline",
imp: "import",
ter: "terrain",
hl: "contourline",
hoehenlinie: "contourline",
höhenlinie: "contourline",
baugrube: "excavation",
aushub: "excavation",
netzzuschnitt: "meshcrop",
+7
View File
@@ -2708,6 +2708,11 @@ export const de = {
"cmd.extrude.pick": "Geschlossenes Profil wählen:",
"cmd.extrude.height": "Höhe:",
"cmd.extrude.taper": "Verjüngung (0–1, 1=Spitze):",
"cmd.contourLine.label": "Höhenlinie",
"cmd.contourLine.pick": "Linie für die Höhenlinie wählen (Enter: fertig):",
"cmd.contourLine.height": "Höhe (m ü. M. bzw. Projekthöhe, Enter: Vorschlag):",
"cmd.contourLine.noLine": "Hier liegt keine Linie (Linie, Polylinie, Spline, Bogen, Kreis, Ellipse oder Rechteck anklicken)",
"cmd.contourLine.done": "Höhenlinien übernommen — „Gelände“ erzeugt daraus das Geländemodell",
// Trim (Quick-Trim): auf den wegzuschneidenden Abschnitt klicken; wiederholend.
"cmd.trim.label": "Stutzen",
"cmd.trim.pick": "Abschnitt zum Wegschneiden anklicken (Esc beendet):",
@@ -2851,6 +2856,8 @@ export const de = {
"site.smooth.hint": "Höhenlinien als Bruchkanten, flache Dreiecke behoben, Fläche ohne Überschwingen geglättet",
"site.excavation.draw": "Baugrube zeichnen",
"site.excavation.hint": "Umriss der Sohle zeichnen; Böschungen schneiden das Gelände",
"site.contourLine.draw": "Höhenlinien zeichnen",
"site.contourLine.hint": "Gezeichnete Linien (Linie, Polylinie, Spline, Kreis …) anklicken und ihre Höhe tippen; danach „Gelände erzeugen“",
"site.contourInterval": "Äquidistanz",
"site.contourIndexEvery": "Zähllinie jede",
"site.smoothShading": "Glatt schattieren",
+7
View File
@@ -2696,6 +2696,11 @@ export const en: Record<TranslationKey, string> = {
"cmd.extrude.pick": "Select closed profile:",
"cmd.extrude.height": "Height:",
"cmd.extrude.taper": "Taper (0–1, 1=point):",
"cmd.contourLine.label": "Contour line",
"cmd.contourLine.pick": "Select line for the contour (Enter: done):",
"cmd.contourLine.height": "Elevation (m a.s.l. or project height, Enter: suggestion):",
"cmd.contourLine.noLine": "No line here (click a line, polyline, spline, arc, circle, ellipse or rectangle)",
"cmd.contourLine.done": "Contours added — “Terrain” builds the terrain model from them",
// Trim (quick-trim): click the part to cut away; repeats until Esc.
"cmd.trim.label": "Trim",
"cmd.trim.pick": "Click the part to trim away (Esc to finish):",
@@ -2839,6 +2844,8 @@ export const en: Record<TranslationKey, string> = {
"site.smooth.hint": "Contours as breaklines, flat triangles fixed, surface smoothed without overshoot",
"site.excavation.draw": "Draw excavation",
"site.excavation.hint": "Draw the outline of the pit bottom; slopes cut the terrain",
"site.contourLine.draw": "Draw contours",
"site.contourLine.hint": "Click drawn lines (line, polyline, spline, circle …) and type their elevation; then “Generate terrain”",
"site.contourInterval": "Interval",
"site.contourIndexEvery": "Index contour every",
"site.smoothShading": "Smooth shading",
+3
View File
@@ -82,6 +82,9 @@ export function SitePanel() {
>
{t("site.setGeoref")}
</button>
<button type="button" className="site-btn" title={t("site.contourLine.hint")} onClick={() => host.onStartContourLine()}>
{t("site.contourLine.draw")}
</button>
</div>
{ctxImportOpen && (
+2
View File
@@ -638,6 +638,8 @@ export interface PanelHostValue {
onPatchContextObject: (id: string, patch: Record<string, unknown>, coalesceKey?: string) => void;
/** [68] Startet den Befehl „Baugrube" (Umriss zeichnen). */
onStartExcavation: () => void;
/** [332] Startet den Befehl „Höhenlinie" (gezeichnete Linien mit Höhe zu Gelände-Höhenlinien). */
onStartContourLine: () => void;
/**
* Setzt/ersetzt den Georeferenzierungs-Bezug (`Project.geoAnchor`) — welcher
* Modell-Punkt welcher realen LV95-Koordinate entspricht. `undefined` löscht
+1
View File
@@ -19,6 +19,7 @@ export function buildSiteHost(c: FlatHostOpts) {
onGenerateTerrain: generateTerrain,
onPatchContextObject: patchContextObject,
onStartExcavation: () => onRunCommand("excavation"),
onStartContourLine: () => onRunCommand("contourline"),
onSetGeoAnchor: (anchor) => {
applyChange((p) => setFieldIfChanged(p, "geoAnchor", anchor));
},