Files
DOSSIER/src/commands/cmds/kote.ts
T
karim 2dc57d01a5 2D: Höhenkoten-Werkzeug + Masskette bleibt gerade + Punkt-Notation
Neues Werkzeug "Höhenkote" (SIA 400 B.5.4, Figur 18): Dreieck-Symbol +
Höhenwert an einem Punkt. Vier Varianten (OK/UK × fertig/roh) bestimmen
Dreieck-Richtung und Füllung, per Option umschaltbar. Die Norm ordnet
Zahlen UNTERHALB einer Masslinie explizit Höhenmassen zu — das war der
eigentliche Grund, warum ein separater Typ statt einer Bemassungs-Variante
nötig war.

Bemassungs-Korrektur: eine Masskette bleibt beim Zeichnen immer eine
GERADE Linie (Klicks ab dem dritten Punkt werden auf die durch Punkt 1/2
festgelegte Gerade projiziert), auch wenn die Bedienung wie eine Polylinie
funktioniert — vorher konnte man versehentlich einen Zickzack-Pfad
erzeugen.

Ausserdem: Masszahlen nutzen jetzt Punkt- statt Komma-Notation ("3.96"
statt "3,96") — die tatsächlich gezeichneten Beispiele in der Norm
(Figur 13/14/18) verwenden durchgängig den Punkt, nicht das Komma aus der
abstrakten B.5.2-Beispielliste.
2026-08-22 02:32:11 +02:00

112 lines
4.0 KiB
TypeScript

// Höhenkote (SIA 400 B.5.4, Figur 18) — Dreieck-Symbol + Höhenwert an einem
// Punkt. Schritte:
// 1) „Punkt:" → Punkt (Dreieck-Spitze)
// 2) „Höhenwert ( Art ):" → Zahl (Meter, z. B. 3.25 oder -0.1) →
// commit. „Art" (Option, zyklisch: OK fertig/UK fertig/OK roh/UK roh)
// wechselt VOR dem Tippen die Dreieck-Variante (Default OK fertig).
import type { Drawing2D } from "../../model/types";
import { uniqueId } from "../../tools/types";
import type {
Command,
CommandContext,
CommandResult,
CommandState,
CmdOption,
DraftShape,
Project,
ToolDraft,
Vec2,
} from "../types";
import type { TranslationKey } from "../../i18n";
type KoteKind = "okFertig" | "ukFertig" | "okRoh" | "ukRoh";
const KIND_ORDER: KoteKind[] = ["okFertig", "ukFertig", "okRoh", "ukRoh"];
const nextKind = (k: KoteKind): KoteKind => KIND_ORDER[(KIND_ORDER.indexOf(k) + 1) % KIND_ORDER.length];
const KIND_LABEL: Record<KoteKind, TranslationKey> = {
okFertig: "cmd.kote.kind.okFertig",
ukFertig: "cmd.kote.kind.ukFertig",
okRoh: "cmd.kote.kind.okRoh",
ukRoh: "cmd.kote.kind.ukRoh",
};
const TRI_SIZE = 0.15; // Modell-Meter, Vorschau-Grösse (Rendering: DIM_… in drawing2d.ts)
const HALF_W = TRI_SIZE * 0.6;
/** Dreieck-Punkte für die Vorschau: `at` = Spitze; OK zeigt nach unten, UK nach oben. */
function triPts(at: Vec2, kind: KoteKind): Vec2[] {
const up = kind === "okFertig" || kind === "okRoh" ? 1 : -1; // Basis liegt in +up-Richtung von `at`
return [
at,
{ x: at.x - HALF_W, y: at.y + up * TRI_SIZE },
{ x: at.x + HALF_W, y: at.y + up * TRI_SIZE },
];
}
interface KotePoint extends CommandState {
phase: "point";
}
interface KoteValue extends CommandState {
phase: "value";
at: Vec2;
kind: KoteKind;
}
type KoteState = KotePoint | KoteValue;
function kindOption(kind: KoteKind): CmdOption {
return { id: "kind", labelKey: KIND_LABEL[kind], value: kind };
}
function valueDraft(at: Vec2, kind: KoteKind): ToolDraft {
const preview: DraftShape[] = [{ kind: "poly", pts: triPts(at, kind), closed: true }];
return { preview, vertices: [at] };
}
function appendKote(p: Project, at: Vec2, value: number, kind: KoteKind, ctx: CommandContext): Project {
const d: Drawing2D = {
id: uniqueId("dr2d"),
type: "drawing2d",
levelId: ctx.level.id,
categoryCode: ctx.defaultCategoryCode,
geom: { shape: "kote", at, value, kind, rotation: 0 },
};
return { ...p, drawings2d: [...p.drawings2d, d] };
}
const idle = (): [CommandState, CommandResult] => [
{ phase: "point", lastPoint: null },
{ draft: null, done: true },
];
export const koteCommand: Command = {
name: "kote",
labelKey: "cmd.kote.label",
prompt: (s) => ((s as KoteState).phase === "value" ? "cmd.kote.value" : "cmd.kote.point"),
accepts: (s) => ((s as KoteState).phase === "value" ? ["number", "option"] : ["point"]),
options: (s) => ((s as KoteState).phase === "value" ? [kindOption((s as KoteValue).kind)] : []),
init: (): KotePoint => ({ phase: "point", lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as KoteState;
if (s.phase === "point") {
if (input.kind !== "point") return [s, { draft: null }];
const ns: KoteValue = { phase: "value", at: input.point, kind: "okFertig", lastPoint: input.point };
return [ns, { draft: valueDraft(input.point, "okFertig") }];
}
if (input.kind === "option" && input.id === "kind") {
const ns: KoteValue = { ...s, kind: nextKind(s.kind) };
return [ns, { draft: valueDraft(s.at, ns.kind) }];
}
if (input.kind !== "number") return [s, { draft: valueDraft(s.at, s.kind) }];
const { at, kind } = s;
return [
{ phase: "point", lastPoint: null },
{ draft: null, done: true, commit: (p) => appendKote(p, at, input.value, kind, ctx) },
];
},
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
onConfirm: (): [CommandState, CommandResult] => idle(),
onCancel: (): [CommandState, CommandResult] => idle(),
};