[38][112] Achsraster (rechtwinklig/radial, Blasen, Fang, Schnitt/Ansicht, DXF, Griffe), Bemassung an Rasterachsen, Bogenwänden, Treppen; Radius-/Durchmesser-/Bogenlängen-Mass; Autodim für nicht mittige Wände
This commit is contained in:
41 files changed
+2351
-72
No files matched your search
@@ -0,0 +1,60 @@
|
||||
// Radius-, Durchmesser- und Bogenlängen-Bemassung ([38]): Klick auf den Rand eines Kreises, Bogens oder
|
||||
// einer Bogenwand (Fläche oder Achse). Der Kern (`cmd_draw.rs`, `dim_assoc::round_dimension`) findet den
|
||||
// Kreis, setzt Mittelpunkt und Randpunkte und hängt sie daran (Bezug `center`/`rim`): Verschieben oder
|
||||
// Vergrössern des Kreises, Strecken der Bogenwand führt das Mass nach. Radius und Durchmesser: ein Klick;
|
||||
// Bogenlänge: Anfang, Ende (gegen den Uhrzeigersinn), dann Lage der Masslinie.
|
||||
|
||||
import type { Command, CommandContext, CommandResult, CommandState, ToolDraft, Vec2 } from "../types";
|
||||
import { createMutation, createPreview, xy } from "../createCore";
|
||||
|
||||
export type RoundKind = "radius" | "diameter" | "arc";
|
||||
|
||||
interface RoundState extends CommandState {
|
||||
phase: "first" | "second" | "offset";
|
||||
pts: Vec2[];
|
||||
}
|
||||
|
||||
const fresh = (): RoundState => ({ phase: "first", lastPoint: null, pts: [] });
|
||||
const idle = (): [CommandState, CommandResult] => [fresh(), { draft: null, done: true }];
|
||||
|
||||
/** Fangtoleranz auf dem Rand (Modell-Meter). */
|
||||
const TOL = 0.2;
|
||||
|
||||
function draft(ctx: CommandContext, kind: RoundKind, pts: Vec2[], cursor: Vec2 | null): ToolDraft | null {
|
||||
const all = cursor ? [...pts, cursor] : pts;
|
||||
if (all.length === 0) return null;
|
||||
const pv = createPreview(ctx, { cmd: "dimround", kind, tol: TOL }, all);
|
||||
return { preview: pv.shapes, vertices: pts };
|
||||
}
|
||||
|
||||
function make(kind: RoundKind, name: string): Command {
|
||||
const keyOf = (s: RoundState) => (s.phase === "first" ? `cmd.${name}.first` : s.phase === "second" ? `cmd.${name}.second` : `cmd.${name}.offset`);
|
||||
return {
|
||||
name,
|
||||
labelKey: `cmd.${name}.label` as never,
|
||||
prompt: (s) => keyOf(s as RoundState) as never,
|
||||
accepts: () => ["point"],
|
||||
options: () => [],
|
||||
init: fresh,
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as RoundState;
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const pts = [...s.pts, input.point];
|
||||
if (kind !== "arc" || s.phase === "offset") {
|
||||
const commit = createMutation(ctx, { cmd: "dimround", kind, tol: TOL, pts: pts.slice(0, kind === "arc" ? 2 : 1).map(xy), side: kind === "arc" ? xy(input.point) : null });
|
||||
return [fresh(), { draft: null, done: true, commit }];
|
||||
}
|
||||
const ns: RoundState = { phase: pts.length >= 2 ? "offset" : "second", pts, lastPoint: input.point };
|
||||
return [ns, { draft: draft(ctx, kind, pts, null) }];
|
||||
},
|
||||
|
||||
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => [state, { draft: draft(ctx, kind, (state as RoundState).pts, point) }],
|
||||
onConfirm: () => idle(),
|
||||
onCancel: () => idle(),
|
||||
};
|
||||
}
|
||||
|
||||
export const radiusDimCommand = make("radius", "dimradius");
|
||||
export const diameterDimCommand = make("diameter", "dimdiameter");
|
||||
export const arcDimCommand = make("arc", "dimarc");
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* `gridCommand` ([112]) und die Rundmass-Befehle ([38]): Eingabe → Zeichnung im Kern. Die Nachführung der
|
||||
* Bezüge im Store prüft `src/state/gridAssoc.test.ts`.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { gridCommand } from "./grid";
|
||||
import { arcDimCommand, diameterDimCommand, radiusDimCommand } from "./dimround";
|
||||
import type { CommandContext, Project } from "../types";
|
||||
import type { Drawing2D } from "../../model/types";
|
||||
|
||||
function project(extra: Drawing2D[] = []): 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: "20", name: "Zeichnung", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
|
||||
walls: [],
|
||||
openings: [],
|
||||
ceilings: [],
|
||||
stairs: [],
|
||||
rooms: [],
|
||||
drawings2d: extra,
|
||||
context: [],
|
||||
};
|
||||
}
|
||||
|
||||
function ctxOf(p: Project): CommandContext {
|
||||
return { project: p, level: p.drawingLevels[0], defaultCategoryCode: "20", activeLineStyleId: "solid", activeWallTypeId: "aw", lastPoint: null, selection: { wallIds: [], drawingId: null } };
|
||||
}
|
||||
|
||||
describe("gridCommand", () => {
|
||||
it("Ursprung + Feldweiten → Achsraster mit Beschriftung 1, 2, 3 / A, B", () => {
|
||||
const p = project();
|
||||
const ctx = ctxOf(p);
|
||||
let [s] = gridCommand.onInput(gridCommand.init(), { kind: "point", point: { x: 2, y: 1 } }, ctx);
|
||||
[s] = gridCommand.onInput(s, { kind: "text", text: "6 4.5 3x5" }, ctx);
|
||||
const [, r] = gridCommand.onInput(s, { kind: "text", text: "5 5" }, ctx);
|
||||
expect(r.done).toBe(true);
|
||||
const g = r.commit!(p).drawings2d[0].geom;
|
||||
expect(g.shape).toBe("grid");
|
||||
if (g.shape !== "grid") return;
|
||||
expect(g.origin).toEqual({ x: 2, y: 1 });
|
||||
expect(g.a.map((x) => [x.label, x.pos])).toEqual([["1", 0], ["2", 6], ["3", 10.5], ["4", 15.5], ["5", 20.5], ["6", 25.5]]);
|
||||
expect(g.b.map((x) => [x.label, x.pos])).toEqual([["A", 0], ["B", 5], ["C", 10]]);
|
||||
});
|
||||
|
||||
it("radial: Option umschalten, Strahlen und Ringe; Enter übernimmt die Vorgaben", () => {
|
||||
const p = project();
|
||||
const ctx = ctxOf(p);
|
||||
let [s] = gridCommand.onInput(gridCommand.init(), { kind: "option", id: "radial" }, ctx);
|
||||
[s] = gridCommand.onInput(s, { kind: "point", point: { x: 0, y: 0 } }, ctx);
|
||||
[s] = gridCommand.onInput(s, { kind: "text", text: "2x45" }, ctx);
|
||||
const [, r] = gridCommand.onInput(s, { kind: "text", text: "3 3" }, ctx);
|
||||
const g = r.commit!(p).drawings2d[0].geom;
|
||||
expect(g.shape === "grid" && g.radial).toBe(true);
|
||||
if (g.shape === "grid") {
|
||||
expect(g.a.map((x) => x.pos)).toEqual([0, 45, 90]);
|
||||
expect(g.b.map((x) => x.pos)).toEqual([3, 6]);
|
||||
}
|
||||
// Vorgaben (Enter, Enter) im rechtwinkligen Raster: 6 6 6 / 6 6.
|
||||
let [t] = gridCommand.onInput(gridCommand.init(), { kind: "point", point: { x: 0, y: 0 } }, ctx);
|
||||
[t] = gridCommand.onConfirm(t, ctx);
|
||||
const [, e] = gridCommand.onConfirm(t, ctx);
|
||||
const d = e.commit!(p).drawings2d[0].geom;
|
||||
expect(d.shape === "grid" && [d.a.length, d.b.length]).toEqual([4, 3]);
|
||||
});
|
||||
|
||||
it("unlesbare Feldweiten legen nichts an; Vorschau am Cursor liefert Achsen", () => {
|
||||
const p = project();
|
||||
const ctx = ctxOf(p);
|
||||
let [s] = gridCommand.onInput(gridCommand.init(), { kind: "point", point: { x: 0, y: 0 } }, ctx);
|
||||
[s] = gridCommand.onInput(s, { kind: "text", text: "abc" }, ctx);
|
||||
const [, r] = gridCommand.onInput(s, { kind: "text", text: "5" }, ctx);
|
||||
expect(r.commit!(p).drawings2d.length).toBe(0);
|
||||
const [, mv] = gridCommand.onMove(gridCommand.init(), { x: 1, y: 1 }, null, ctx);
|
||||
expect(mv.draft?.preview.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Rundmass-Befehle", () => {
|
||||
const circle = { id: "K", type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "circle", center: { x: 5, y: 5 }, r: 2 } } as Drawing2D;
|
||||
|
||||
it("Radius/Durchmesser: ein Klick auf den Rand → Mass mit Bezug", () => {
|
||||
for (const [cmd, kind] of [[radiusDimCommand, "radius"], [diameterDimCommand, "diameter"]] as const) {
|
||||
const p = project([circle]);
|
||||
const [, r] = cmd.onInput(cmd.init(), { kind: "point", point: { x: 7, y: 5.02 } }, ctxOf(p));
|
||||
const g = r.commit!(p).drawings2d[1].geom;
|
||||
expect(g.shape === "dimension" && g.kind).toBe(kind);
|
||||
expect(g.shape === "dimension" && g.refs?.map((x) => x?.feature)).toEqual(["center", "rim"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("Bogenlänge: Anfang, Ende, Lage → drei Punkte; Klick ins Leere legt nichts an", () => {
|
||||
const p = project([circle]);
|
||||
const ctx = ctxOf(p);
|
||||
let [s] = arcDimCommand.onInput(arcDimCommand.init(), { kind: "point", point: { x: 7, y: 5 } }, ctx);
|
||||
[s] = arcDimCommand.onInput(s, { kind: "point", point: { x: 5, y: 7 } }, ctx);
|
||||
const [, r] = arcDimCommand.onInput(s, { kind: "point", point: { x: 5, y: 8 } }, ctx);
|
||||
const dim = r.commit!(p).drawings2d[1];
|
||||
expect(dim.geom.shape === "dimension" && dim.geom.pts.length).toBe(3);
|
||||
expect(dim.geom.shape === "dimension" && dim.geom.offset).toBeCloseTo(1, 6);
|
||||
const [, none] = radiusDimCommand.onInput(radiusDimCommand.init(), { kind: "point", point: { x: 50, y: 50 } }, ctx);
|
||||
expect(none.commit!(p).drawings2d.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
// Achsraster ([112]): Ursprung klicken, dann die Feldweiten als Text (`6 4.5 3x5`: Zahlen, `N x W` =
|
||||
// N Felder zu W). Rechtwinklig: erst die Richtung 1, 2, 3 …, dann A, B, C …; radial: Strahlwinkel in
|
||||
// Grad und Ringabstände. Das Raster ist eine 2D-Zeichnung (Kern, `grid.rs`): Achsen mit Blasen in
|
||||
// allen Plänen, Schnitten und Ansichten, Fang auf Achsen und Schnittpunkte, Griffe je Achse.
|
||||
|
||||
import type { Command, CommandContext, CommandResult, CommandState, CmdOption, ToolDraft, Vec2 } from "../types";
|
||||
import { createMutation, createPreview, xy } from "../createCore";
|
||||
|
||||
type Phase = "origin" | "xs" | "ys";
|
||||
|
||||
interface GridState extends CommandState {
|
||||
phase: Phase;
|
||||
origin: Vec2 | null;
|
||||
radial: boolean;
|
||||
xs: string;
|
||||
ys: string;
|
||||
}
|
||||
|
||||
const DEFAULTS = {
|
||||
ortho: { xs: "6 6 6", ys: "6 6" },
|
||||
radial: { xs: "4x45", ys: "3 3 3" },
|
||||
};
|
||||
|
||||
const RADIAL: CmdOption = { id: "radial", labelKey: "cmd.grid.radial" };
|
||||
|
||||
const start = (radial = false): GridState => ({
|
||||
phase: "origin",
|
||||
lastPoint: null,
|
||||
origin: null,
|
||||
radial,
|
||||
xs: radial ? DEFAULTS.radial.xs : DEFAULTS.ortho.xs,
|
||||
ys: radial ? DEFAULTS.radial.ys : DEFAULTS.ortho.ys,
|
||||
});
|
||||
|
||||
const idle = (): [CommandState, CommandResult] => [start(), { draft: null, done: true }];
|
||||
|
||||
/** Vorschau (Kern): die Achsen des Rasters am Cursor. */
|
||||
function draft(ctx: CommandContext, s: GridState, at: Vec2): ToolDraft {
|
||||
const pv = createPreview(ctx, { cmd: "grid", xs: s.xs, ys: s.ys, radial: s.radial, angle: 0 }, [at]);
|
||||
return { preview: pv.shapes, vertices: [at] };
|
||||
}
|
||||
|
||||
const commit = (ctx: CommandContext, s: GridState, ys: string) =>
|
||||
createMutation(ctx, { cmd: "grid", at: xy(s.origin as Vec2), xs: s.xs, ys, radial: s.radial, angle: 0 });
|
||||
|
||||
export const gridCommand: Command = {
|
||||
name: "grid",
|
||||
labelKey: "cmd.grid.label",
|
||||
prompt: (state) => {
|
||||
const s = state as GridState;
|
||||
if (s.phase === "origin") return "cmd.grid.origin";
|
||||
if (s.phase === "xs") return s.radial ? "cmd.grid.xsRadial" : "cmd.grid.xs";
|
||||
return s.radial ? "cmd.grid.ysRadial" : "cmd.grid.ys";
|
||||
},
|
||||
accepts: (state) => ((state as GridState).phase === "origin" ? ["point", "option"] : ["text"]),
|
||||
options: (state): CmdOption[] => ((state as GridState).phase === "origin" ? [{ ...RADIAL, value: (state as GridState).radial ? "ja" : "nein" }] : []),
|
||||
floorOnly: false,
|
||||
init: () => start(),
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as GridState;
|
||||
if (s.phase === "origin") {
|
||||
if (input.kind === "option" && input.id === "radial") return [start(!s.radial), { draft: null }];
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const ns: GridState = { ...s, phase: "xs", origin: input.point, lastPoint: input.point };
|
||||
return [ns, { draft: draft(ctx, ns, input.point) }];
|
||||
}
|
||||
if (input.kind !== "text") return [s, { draft: null }];
|
||||
const text = input.text.trim();
|
||||
if (s.phase === "xs") {
|
||||
const ns: GridState = { ...s, phase: "ys", xs: text === "" ? s.xs : text };
|
||||
return [ns, { draft: s.origin ? draft(ctx, ns, s.origin) : null }];
|
||||
}
|
||||
const ys = text === "" && !s.radial ? s.ys : text;
|
||||
return [start(), { draft: null, done: true, commit: commit(ctx, s, ys) }];
|
||||
},
|
||||
|
||||
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as GridState;
|
||||
if (s.phase !== "origin") return [s, { draft: s.origin ? draft(ctx, s, s.origin) : null }];
|
||||
return [s, { draft: draft(ctx, s, point) }];
|
||||
},
|
||||
|
||||
// Enter: Vorgabe-Feldweiten übernehmen.
|
||||
onConfirm: (state, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as GridState;
|
||||
if (s.phase === "origin") return idle();
|
||||
if (s.phase === "xs") {
|
||||
const ns: GridState = { ...s, phase: "ys" };
|
||||
return [ns, { draft: s.origin ? draft(ctx, ns, s.origin) : null }];
|
||||
}
|
||||
return [start(), { draft: null, done: true, commit: commit(ctx, s, s.ys) }];
|
||||
},
|
||||
onCancel: () => idle(),
|
||||
};
|
||||
Reference in new issue
Block a user