[176] Geknickter Schnitt: Abwicklung je Segment, Knicklinien, Werkzeug und Griffe für Knickpunkte
Kern plan/section/unfold.rs: jedes Segment schneidet mit eigener Ebene, Schnittflächen auf den u-Bereich, Projektion an den Winkelhalbierenden zugeschnitten, Teilbilder lückenlos (u = abgewickelte Länge), dünne Knicklinie je Knick; Öffnungen/Achsen/Bäume je Segment. Ohne bendPoints unverändert. Schnittlinien-Befehl: weitere Klicks = Knicke, Enter/Doppelklick beendet (Ansicht weiter zwei Klicks). Griffe: Anfang, Knicke, Ende (grips.rs sectionLineGrip).
This commit is contained in:
18 files changed
+748
-39
No files matched your search
@@ -13,7 +13,10 @@ function commitLine(p: Project, a: Vec2, b: Vec2, kind: "section" | "elevation")
|
||||
let s = sectionLineCommand.init();
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "option", id: kind }, ctx);
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: a }, ctx);
|
||||
const [, res] = sectionLineCommand.onInput(s, { kind: "point", point: b }, ctx);
|
||||
let res;
|
||||
[s, res] = sectionLineCommand.onInput(s, { kind: "point", point: b }, ctx);
|
||||
// [176] Schnitt: weitere Klicks wären Knicke, Enter beendet.
|
||||
if (!res.commit) [, res] = sectionLineCommand.onConfirm(s, ctx);
|
||||
const ops = res.commit!.toOps(p);
|
||||
return ops.length ? applyOps(p, ops) : p;
|
||||
}
|
||||
@@ -113,3 +116,30 @@ describe("sectionline — Name der neuen Ebene", () => {
|
||||
expect(nextLevelName(p1, "section")).toContain("B");
|
||||
});
|
||||
});
|
||||
|
||||
describe("sectionline — geknickter Schnitt [176]", () => {
|
||||
it("weitere Klicks werden Knickpunkte, Enter beendet; Doppelklick-Punkt zählt nicht doppelt", () => {
|
||||
const p = projectWith([{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }]);
|
||||
const ctx = { project: p, level: { id: "eg", kind: "floor" }, defaultCategoryCode: "20", activeWallTypeId: "", selection: { wallIds: [], drawingId: null } } as unknown as CommandContext;
|
||||
let s = sectionLineCommand.init();
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 0, y: 0 } }, ctx);
|
||||
let res;
|
||||
[s, res] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 0 } }, ctx);
|
||||
expect(res.commit).toBeUndefined();
|
||||
expect(sectionLineCommand.prompt(s)).toBe("cmd.sectionline.next");
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 10 } }, ctx);
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 10 } }, ctx);
|
||||
[, res] = sectionLineCommand.onConfirm(s, ctx);
|
||||
const out = applyOps(p, res.commit!.toOps(p));
|
||||
const lv = out.drawingLevels.at(-1)!;
|
||||
expect(lv.kind).toBe("section");
|
||||
expect(lv.linePoints).toEqual([{ x: 0, y: 0 }, { x: 6, y: 10 }]);
|
||||
expect(lv.bendPoints).toEqual([{ x: 6, y: 0 }]);
|
||||
});
|
||||
|
||||
it("Ansicht bleibt bei zwei Klicks", () => {
|
||||
const p = projectWith([{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }]);
|
||||
const out = commitLine(p, a, b, "elevation");
|
||||
expect(out.drawingLevels.at(-1)!.bendPoints).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,9 @@
|
||||
//
|
||||
// Schritte:
|
||||
// 1) „Schnitt-Startpunkt:" → Punkt
|
||||
// 2) „Schnitt-Endpunkt:" → Live-Linie + Richtungspfeil; Klick committet.
|
||||
// 2) „Schnitt-Endpunkt:" → Live-Linie + Richtungspfeil; Klick committet (Ansicht).
|
||||
// Schnitt ([176]): jeder weitere Klick setzt einen Knickpunkt (geknickter Schnitt), Enter/Doppelklick
|
||||
// beendet mit dem letzten Punkt als Ende (`bendPoints` = die Punkte dazwischen).
|
||||
//
|
||||
// Ziel-Ebene (im Commit bestimmt): existiert GENAU EINE Ebene der gewählten Art
|
||||
// OHNE gesetzte Linie (frisch angelegter Platzhalter), wird deren Linie gesetzt;
|
||||
@@ -41,12 +43,13 @@ const KIND_IDS = new Set(KIND_OPTIONS.map((o) => o.id));
|
||||
* Vorschau: Schnittlinie + Richtungspfeil (Kern, `cmd_solid.rs`: vom Mittelpunkt entlang der
|
||||
* Blicknormalen, zwei Flügel) + Länge im HUD.
|
||||
*/
|
||||
function lineDraft(ctx: CommandContext, a: Vec2, cursor: Vec2 | null): ToolDraft {
|
||||
if (!cursor) return { preview: [{ kind: "poly", pts: [a] }], vertices: [a] };
|
||||
const draft: ToolDraft = { preview: createPreview(ctx, { cmd: "sectionline" }, [a, cursor]).shapes, vertices: [a] };
|
||||
function lineDraft(ctx: CommandContext, pts: Vec2[], cursor: Vec2 | null): ToolDraft {
|
||||
if (!cursor) return { preview: [{ kind: "poly", pts }], vertices: pts };
|
||||
const last = pts[pts.length - 1];
|
||||
const draft: ToolDraft = { preview: createPreview(ctx, { cmd: "sectionline" }, [...pts, cursor]).shapes, vertices: pts };
|
||||
draft.hud = {
|
||||
at: cursor,
|
||||
text: `${Math.hypot(cursor.x - a.x, cursor.y - a.y).toFixed(2)} m`,
|
||||
text: `${Math.hypot(cursor.x - last.x, cursor.y - last.y).toFixed(2)} m`,
|
||||
};
|
||||
return draft;
|
||||
}
|
||||
@@ -55,9 +58,9 @@ function lineDraft(ctx: CommandContext, a: Vec2, cursor: Vec2 | null): ToolDraft
|
||||
* Commit (Kern): Linie [a, b] auf die EINE Ebene der Art ohne Linie, sonst eine neue Ebene (Name aus der
|
||||
* Vorlage, Buchstaben A, B, … nach Anzahl der Ebenen dieser Art); zu kurze Linien (< 0.1 m) → nichts.
|
||||
*/
|
||||
function lineMutation(ctx: CommandContext, a: Vec2, b: Vec2, kind: LineKind) {
|
||||
function lineMutation(ctx: CommandContext, a: Vec2, b: Vec2, kind: LineKind, bends: Vec2[] = []) {
|
||||
const key = kind === "section" ? "cmd.sectionline.newSection" : "cmd.sectionline.newElevation";
|
||||
return createMutation(ctx, { cmd: "sectionline", a, b, kind, name: t(key, { letter: "\u0001" }) });
|
||||
return createMutation(ctx, { cmd: "sectionline", a, b, kind, name: t(key, { letter: "\u0001" }), ...(bends.length ? { bends } : {}) });
|
||||
}
|
||||
|
||||
interface LineIdle extends CommandState {
|
||||
@@ -67,6 +70,8 @@ interface LineIdle extends CommandState {
|
||||
interface LineEnd extends CommandState {
|
||||
phase: "end";
|
||||
a: Vec2;
|
||||
/** [176] Weitere Klicks (Schnitt): Knickpunkte, der letzte wird beim Beenden das Ende. */
|
||||
pts: Vec2[];
|
||||
cursor: Vec2 | null;
|
||||
kind: LineKind;
|
||||
}
|
||||
@@ -85,7 +90,11 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
// auf freien Zeichnungsebenen nutzbar bleiben; die Prüfung übernimmt der
|
||||
// Grundriss-Kontext (keine harte Sperre nötig).
|
||||
floorOnly: true,
|
||||
prompt: (s) => ((s as LineState).phase === "end" ? "cmd.sectionline.end" : "cmd.sectionline.start"),
|
||||
prompt: (s) => {
|
||||
const st = s as LineState;
|
||||
if (st.phase !== "end") return "cmd.sectionline.start";
|
||||
return st.kind === "section" && st.pts.length > 0 ? "cmd.sectionline.next" : "cmd.sectionline.end";
|
||||
},
|
||||
accepts: () => ["point", "option"],
|
||||
options: () => KIND_OPTIONS,
|
||||
init: (): LineIdle => ({ phase: "start", kind: startKind, lastPoint: null }),
|
||||
@@ -95,28 +104,36 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
if (input.kind === "option" && KIND_IDS.has(input.id)) {
|
||||
const ns = { ...s, kind: input.id as LineKind } as LineState;
|
||||
const draft =
|
||||
ns.phase === "end" ? lineDraft(ctx, ns.a, ns.cursor) : null;
|
||||
ns.phase === "end" ? lineDraft(ctx, [ns.a, ...ns.pts], ns.cursor) : null;
|
||||
return [ns, { draft }];
|
||||
}
|
||||
if (input.kind !== "point") {
|
||||
return [
|
||||
s,
|
||||
{ draft: s.phase === "end" ? lineDraft(ctx, s.a, s.cursor) : null },
|
||||
{ draft: s.phase === "end" ? lineDraft(ctx, [s.a, ...s.pts], s.cursor) : null },
|
||||
];
|
||||
}
|
||||
if (s.phase !== "end") {
|
||||
const ns: LineEnd = {
|
||||
phase: "end",
|
||||
a: input.point,
|
||||
pts: [],
|
||||
cursor: input.point,
|
||||
kind: s.kind,
|
||||
lastPoint: input.point,
|
||||
};
|
||||
return [ns, { draft: lineDraft(ctx, input.point, input.point) }];
|
||||
return [ns, { draft: lineDraft(ctx, [input.point], input.point) }];
|
||||
}
|
||||
const a = s.a;
|
||||
const b = input.point;
|
||||
const kind = s.kind;
|
||||
if (kind === "section") {
|
||||
// [176] Schnitt: Punkt anhängen (Knick); derselbe Punkt nochmals (Doppelklick) ändert nichts.
|
||||
const last = s.pts.length ? s.pts[s.pts.length - 1] : a;
|
||||
if (Math.hypot(b.x - last.x, b.y - last.y) < 1e-6) return [s, { draft: lineDraft(ctx, [a, ...s.pts], s.cursor) }];
|
||||
const ns: LineEnd = { ...s, pts: [...s.pts, b], cursor: b, lastPoint: b };
|
||||
return [ns, { draft: lineDraft(ctx, [a, ...ns.pts], b) }];
|
||||
}
|
||||
return [
|
||||
{ phase: "start", kind, lastPoint: null } as LineIdle,
|
||||
{ draft: null, done: true, commit: lineMutation(ctx, a, b, kind) },
|
||||
@@ -127,10 +144,21 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
const s = state as LineState;
|
||||
if (s.phase !== "end") return [s, { draft: null }];
|
||||
const ns: LineEnd = { ...s, cursor: point };
|
||||
return [ns, { draft: lineDraft(ctx, s.a, point) }];
|
||||
return [ns, { draft: lineDraft(ctx, [s.a, ...s.pts], point) }];
|
||||
},
|
||||
|
||||
onConfirm: (state): [CommandState, CommandResult] => idle((state as LineState).kind),
|
||||
// [176] Enter/Doppelklick: geknickten Schnitt mit dem letzten Punkt als Ende setzen.
|
||||
onConfirm: (state, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as LineState;
|
||||
if (s.phase === "end" && s.pts.length > 0) {
|
||||
const b = s.pts[s.pts.length - 1];
|
||||
return [
|
||||
{ phase: "start", kind: s.kind, lastPoint: null } as LineIdle,
|
||||
{ draft: null, done: true, commit: lineMutation(ctx, s.a, b, s.kind, s.pts.slice(0, -1)) },
|
||||
];
|
||||
}
|
||||
return idle(s.kind);
|
||||
},
|
||||
onCancel: (state): [CommandState, CommandResult] => idle((state as LineState).kind),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ export type GripRequest =
|
||||
| { op: "roomStamp"; id: string; delta: P; pt?: P }
|
||||
| { op: "ceilingEdge" | "roomEdge"; id: string; a: number; b: number; delta: P }
|
||||
| { op: "excavationGrip"; id: string; index: number; pt: P }
|
||||
// [176] Schnittlinie: 0 = Anfang, dann `bendPoints`, zuletzt das Ende.
|
||||
| { op: "sectionLineGrip"; id: string; index: number; pt: P }
|
||||
// [151] Parameter-Griff einer Podesttreppe (Kern `grip_drag::stair_param_drag`).
|
||||
| { op: "stairParam"; id: string; index: number; pt: P }
|
||||
| { op: "excavationEdge"; id: string; a: number; b: number; delta: P }
|
||||
|
||||
@@ -1907,6 +1907,7 @@ export const de = {
|
||||
"cmd.sectionline.label": "Schnittlinie",
|
||||
"cmd.sectionline.start": "Schnitt-Startpunkt:",
|
||||
"cmd.sectionline.end": "Schnitt-Endpunkt:",
|
||||
"cmd.sectionline.next": "Knickpunkt oder Endpunkt (Enter/Doppelklick beendet):",
|
||||
"cmd.sectionline.kind.section": "Schnitt",
|
||||
"cmd.sectionline.kind.elevation": "Ansicht",
|
||||
"cmd.sectionline.newSection": "Schnitt {letter}",
|
||||
|
||||
@@ -1896,6 +1896,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"cmd.sectionline.label": "Section line",
|
||||
"cmd.sectionline.start": "Section start point:",
|
||||
"cmd.sectionline.end": "Section end point:",
|
||||
"cmd.sectionline.next": "Bend point or end point (Enter/double-click finishes):",
|
||||
"cmd.sectionline.kind.section": "Section",
|
||||
"cmd.sectionline.kind.elevation": "Elevation",
|
||||
"cmd.sectionline.newSection": "Section {letter}",
|
||||
|
||||
@@ -108,6 +108,8 @@ export function levelArg(level: DrawingLevel) {
|
||||
return {
|
||||
kind: level.kind,
|
||||
linePoints: level.linePoints,
|
||||
// [176] Knickpunkte (geknickter Schnitt, Abwicklung im Kern `plan/section/unfold.rs`).
|
||||
bendPoints: level.bendPoints,
|
||||
directionSign: level.directionSign,
|
||||
depth: level.depth,
|
||||
shadows: level.shadows,
|
||||
|
||||
@@ -386,6 +386,8 @@ export interface ProjectSlice {
|
||||
moveCeilingGrip: (ceilingId: string, index: number, pt: Vec2) => void;
|
||||
/** [68] Baugrube: Umriss-Ecke ziehen (Index = Ecke; Index = Eckenzahl: Sohlenhöhe). */
|
||||
moveExcavationGrip: (id: string, index: number, pt: Vec2) => void;
|
||||
/** [176] Griff einer Schnittlinie: 0 = Anfang, dann die Knickpunkte, zuletzt das Ende. */
|
||||
moveSectionLineGrip: (id: string, index: number, pt: Vec2) => void;
|
||||
moveExcavationEdge: (id: string, aIndex: number, bIndex: number, delta: Vec2) => void;
|
||||
/** Verschiebt eine Decke (ganzer Umriss) um `delta`. */
|
||||
moveCeilingBy: (ceilingId: string, delta: Vec2) => void;
|
||||
@@ -1240,6 +1242,7 @@ export function createProjectSlice(
|
||||
applyGrip({ op: "ceilingGrip", id: ceilingId, index, pt: gripPt(pt) }, `moveCeilingGrip:${ceilingId}:${index}`),
|
||||
|
||||
moveExcavationGrip: (id, index, pt) => applyGrip({ op: "excavationGrip", id, index, pt: gripPt(pt) }, `moveExcavationGrip:${id}:${index}`),
|
||||
moveSectionLineGrip: (id, index, pt) => applyGrip({ op: "sectionLineGrip", id, index, pt: gripPt(pt) }, `moveSectionLineGrip:${id}:${index}`),
|
||||
|
||||
moveExcavationEdge: (id, aIndex, bIndex, delta) =>
|
||||
applyGrip({ op: "excavationEdge", id, a: aIndex, b: bIndex, delta: gripPt(delta) }, `moveExcavationEdge:${id}:${aIndex}:${bIndex}`),
|
||||
|
||||
@@ -176,6 +176,13 @@ export function useGripEditing(opts: {
|
||||
// [149] Baum: Griff in der Stammmitte (verschieben) und am Kronenrand (Kronendurchmesser).
|
||||
const selectedTreeId = single(selection, "trees");
|
||||
const selectedTree = selectedTreeId ? (project.trees ?? []).find((x) => x.id === selectedTreeId) : undefined;
|
||||
// [176] Schnitt-/Ansichtslinie im Grundriss: Griffe an Anfang, Knickpunkten (`bendPoints`) und Ende.
|
||||
const selectedSectionLineId = single(selection, "sectionLines");
|
||||
const selectedSectionLine = modelEditable && selectedSectionLineId
|
||||
? project.drawingLevels.find((l) => l.id === selectedSectionLineId && l.linePoints)
|
||||
: undefined;
|
||||
const sectionLineGrips = (l: NonNullable<typeof selectedSectionLine>): Vec2[] =>
|
||||
l.linePoints ? [l.linePoints[0], ...(l.bendPoints ?? []), l.linePoints[1]] : [];
|
||||
// Mit gezeigter Beschriftung dazu ihr Griff (`labelOffset`, s. `treeGrips.ts`).
|
||||
const treeGrips = (tr: NonNullable<typeof selectedTree>): Vec2[] => treeGripPoints(tr, scaleDenominator);
|
||||
const selectedRoomId = single(selection, "rooms");
|
||||
@@ -315,6 +322,11 @@ export function useGripEditing(opts: {
|
||||
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
|
||||
return pts;
|
||||
}
|
||||
if (selectedSectionLine && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
const pts = sectionLineGrips(selectedSectionLine);
|
||||
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
|
||||
return pts;
|
||||
}
|
||||
// [68] Baugrube: Umriss-Ecken + Sohlen-Griff (Lage: Schwerpunkt, y um die Sohlenhöhe versetzt).
|
||||
if (modelEditable && selectedExcavation && !selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
const pts = excavationGripPoints(selectedExcavation);
|
||||
@@ -911,6 +923,11 @@ export function useGripEditing(opts: {
|
||||
storeState().applyChange((p) => patchItem(p, "trees", tr.id, patch), `treeGrip:${tr.id}:${index}`);
|
||||
return;
|
||||
}
|
||||
// [176] Schnittlinie: Endpunkt bzw. Knickpunkt live, ein Undo-Schritt je Zug (Kern `grips.rs`).
|
||||
if (selectedSectionLine && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
storeState().moveSectionLineGrip(selectedSectionLine.id, index, pt);
|
||||
return;
|
||||
}
|
||||
// [68] Baugrube: Sohlen-Griff sofort (Höhe), Ecken als Vorschau bis zum Setzen.
|
||||
if (selectedExcavation && !selectedCeilingId && !selectedRoomId) {
|
||||
if (index >= selectedExcavation.outline.length) moveExcavationGrip(selectedExcavation.id, index, pt);
|
||||
|
||||
Reference in new issue
Block a user