[26] Ecke einfügen/löschen an Umrissen: Dach (Umriss + Höfe), Decke, Raum, Baugrube, geschlossene Polylinie; Einfüge-Raute, Kontextmenü, Aufräumen

This commit is contained in:
Claude committed 2026-11-11 06:26:43 +00:00
1 parent abdd251fc9
commit 52e2b4efe0
15 files changed
+628 -15

No files matched your search

+1 -1
View File
@@ -73,7 +73,7 @@ export type { GroupMembership, MemberKind } from "../model/groups";
export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from "../geometry/grips";
export { verticalExtents } from "../geometry/grips";
export type { VerticalExtent } from "../geometry/grips";
export type { GripRequest } from "../geometry/grips";
export type { GripRequest, RingKind } from "../geometry/grips";
export { clampInside, coincidentGripPoints, excavationGripPoints, gripArcWallRadius, gripArcWallResize, gripArcWallTarget, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingTypedPosition, sheetHeightDrag, stairMoveHandle, stairParamPoints, wallGripPoints } from "../geometry/gripDrag";
export type { EdgeDrive, GripLocks, SheetHeightKind } from "../geometry/gripDrag";
export { openingPreviewProject, openingPreviewSvgs } from "../plan/openingPreview";
+7
View File
@@ -17,6 +17,9 @@ import { textFrameCorners } from "../text/textFrame";
/** Punkt als `[x, y]` (Anfragen an den Kern). */
type P = [number, number];
/** Elemente mit Umriss-Ring, an denen sich Ecken einfügen/löschen lassen (geschlossene Polylinie eingeschlossen). */
export type RingKind = "roof" | "ceiling" | "room" | "excavation" | "polyline";
/** Eine Griff-Änderung für den Kern (`grips.rs::run`); Zahlen dürfen NaN/±∞ sein (Marken). */
export type GripRequest =
| { op: "moveGrip"; drawingId: string | null; wallId: string | null; index: number; pt: P; scale: number; free?: boolean; arcLength?: number }
@@ -37,6 +40,10 @@ export type GripRequest =
| { op: "sectionBendInsert"; id: string; seg: number; pt: P }
| { op: "sectionBendDelete"; id: string; index: number }
| { op: "sectionLineTidy"; id: string; tol?: number }
// [26] Ecke an Umriss-Ringen einfügen (hinter Kante `seg`), löschen, aufräumen (Kern `ring_edit`); Dach: flacher Index.
| { op: "ringInsert"; kind: RingKind; id: string; seg: number; pt: P }
| { op: "ringDelete"; kind: RingKind; id: string; index: number }
| { op: "ringTidy"; kind: RingKind; id: string; index: number; tol?: number }
// [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 }
+3
View File
@@ -1044,6 +1044,9 @@ export const de = {
"ctx.deletePoint": "Punkt löschen",
"ctx.insertBend": "Knick einfügen",
"ctx.deleteBend": "Knick löschen",
"ctx.insertCorner": "Ecke einfügen",
"ctx.deleteCorner": "Ecke löschen",
"ctx.deleteCorner.min": "Mindestens drei Ecken bleiben.",
"ctx.vertexType.corner": "Eckpunkt",
"ctx.vertexType.arc": "Bogenpunkt",
"ctx.vertexType.spline": "Splinepunkt",
+3
View File
@@ -1039,6 +1039,9 @@ export const en: Record<TranslationKey, string> = {
"ctx.deletePoint": "Delete point",
"ctx.insertBend": "Insert bend",
"ctx.deleteBend": "Delete bend",
"ctx.insertCorner": "Insert corner",
"ctx.deleteCorner": "Delete corner",
"ctx.deleteCorner.min": "At least three corners remain.",
"ctx.vertexType.corner": "Corner point",
"ctx.vertexType.arc": "Arc point",
"ctx.vertexType.spline": "Spline point",
+22
View File
@@ -7,6 +7,7 @@
import type { RefObject } from "react";
import { useStore } from "../state/appStore";
import { ContextMenu } from "../ui/ContextMenu";
import type { Vec2 } from "../model/types";
import type { PlanViewHandle } from "../views/plan/PlanView";
import { countClosedAreas, differenceDrawings, intersectionDrawings, unionDrawings } from "../editors/booleanOps";
import { categoryNames } from "../state/selectionLayers";
@@ -59,6 +60,8 @@ export function AppContextMenu(props: {
insertDrawingPoint,
insertSectionBend,
deleteSectionBend,
insertRingVertex,
deleteRingVertex,
deleteDrawingPoint,
setPolylineVertexType,
reorderDrawingLevels,
@@ -149,6 +152,25 @@ export function AppContextMenu(props: {
})(),
insertSectionBend,
deleteSectionBend,
// [26] Umriss-Ecken: genau ein Element mit Umriss gewählt (sonst kein Bezug für den Klick).
selectedRing: (() => {
const total = Object.values(selection).reduce((n, v) => n + (Array.isArray(v) ? v.length : 0), 0);
if (total !== 1) return null;
const roof = selection.roofs.length === 1 ? (project.roofs ?? []).find((x) => x.id === selection.roofs[0]) : undefined;
if (roof && !roof.locked) {
return { kind: "roof" as const, id: roof.id, rings: [roof.outline, ...(roof.holes ?? [])].reduce<{ pts: Vec2[]; off: number }[]>(
(acc, pts) => [...acc, { pts, off: acc.reduce((n, r) => n + r.pts.length, 0) }], []) };
}
const ceiling = selection.ceilings.length === 1 ? (project.ceilings ?? []).find((x) => x.id === selection.ceilings[0]) : undefined;
if (ceiling && !ceiling.locked) return { kind: "ceiling" as const, id: ceiling.id, rings: [{ pts: ceiling.outline, off: 0 }] };
const room = selection.rooms.length === 1 ? (project.rooms ?? []).find((x) => x.id === selection.rooms[0]) : undefined;
if (room && !room.locked) return { kind: "room" as const, id: room.id, rings: [{ pts: room.boundary, off: 0 }] };
const ctx = selection.contextObjects.length === 1 ? (project.context ?? []).find((x) => x.id === selection.contextObjects[0]) : undefined;
if (ctx && ctx.type === "excavation") return { kind: "excavation" as const, id: ctx.id, rings: [{ pts: ctx.outline, off: 0 }] };
return null;
})(),
insertRingVertex,
deleteRingVertex,
insertPolylinePoint: insertDrawingPoint,
deletePolylinePoint: deleteDrawingPoint,
setPolylineVertexType,
+32 -1
View File
@@ -8,7 +8,7 @@
// Kommentare deutsch (CONVENTIONS.md).
import { t } from "../i18n";
import { canSetVertexType, vertexTypeOf, type PolylineVertexType } from "../core";
import { canSetVertexType, vertexTypeOf, type PolylineVertexType, type RingKind } from "../core";
import { nearestPolylineTarget, toleranceFor } from "../core";
import type { LayerCategory, Project, Vec2 } from "../model/types";
import { flattenCategories } from "../model/types";
@@ -89,6 +89,10 @@ export interface MenuActions {
/** [176] Einzeln gewählte Schnittlinie: Anfang, Knickpunkte, Ende (für „Knick einfügen/löschen"). */
selectedSectionLine?: { id: string; pts: Vec2[] } | null;
insertSectionBend?: (id: string, seg: number, pt: Vec2) => void;
/** [26] Einzeln gewähltes Element mit Umriss (Dach samt Höfen, Decke, Raum, Baugrube): Ringe mit Start-Index im flachen Ecken-Index. */
selectedRing?: { kind: RingKind; id: string; rings: { pts: Vec2[]; off: number }[] } | null;
insertRingVertex?: (kind: RingKind, id: string, seg: number, pt: Vec2) => void;
deleteRingVertex?: (kind: RingKind, id: string, index: number) => void;
deleteSectionBend?: (id: string, index: number) => void;
/** Ob eine Element-Stil-Zwischenablage gefüllt ist (aktiviert „Einfügen"). */
hasDrawingStyleClipboard: boolean;
@@ -336,6 +340,33 @@ function planMenuItems(
onClick: () => a.deleteSectionBend?.(sec.id, secTarget.index),
});
}
// [26] Umriss-Element: Ecke am Klick einfügen bzw. die getroffene Ecke löschen (mindestens drei bleiben).
const ring = a.selectedRing;
if (ring) {
for (const { pts, off } of ring.rings) {
const geom = { pts, closed: true };
const hit = nearestPolylineTarget(geom, model, toleranceFor(geom));
if (!hit) continue;
if (hit.kind === "segment" && a.insertRingVertex) {
pointItems.push({
label: t("ctx.insertCorner"),
icon: <MenuIcon name="add_circle" />,
onClick: () => a.insertRingVertex?.(ring.kind, ring.id, off + hit.segIndex, hit.at),
});
}
if (hit.kind === "vertex" && a.deleteRingVertex) {
const enabled = pts.length > 3;
pointItems.push({
label: t("ctx.deleteCorner"),
icon: <MenuIcon name="do_not_disturb_on" />,
disabled: !enabled,
title: enabled ? undefined : t("ctx.deleteCorner.min"),
onClick: () => a.deleteRingVertex?.(ring.kind, ring.id, off + hit.index),
});
}
break;
}
}
// Eigenschaften übertragen — dasselbe Muster wie im Ebenen-Menü, nur für
// 2D-Elemente. Kopieren ab einem gewählten Element, Einfügen sobald etwas
// in der Zwischenablage liegt.
+25 -1
View File
@@ -63,7 +63,7 @@ import { reorderByIds } from "../model/reorder";
import { transformMutation } from "../tools/transform";
import type { CopyMode, TransformOp, TransformSelection } from "../tools/transform";
import { uniqueId } from "../tools/types";
import { gripPt, type GripRequest } from "../core";
import { gripPt, type GripRequest, type RingKind } from "../core";
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
import { DEFAULT_PRESETS, type TextStylePreset } from "../text/richText";
import { t } from "../i18n";
@@ -394,6 +394,14 @@ export interface ProjectSlice {
deleteSectionBend: (id: string, index: number) => void;
/** [176] Nach dem Ziehen: Knicke auf einem Nachbarpunkt oder auf der Geraden entfernen. */
tidySectionLine: (id: string, coalesceKey?: string, tol?: number) => void;
/** [26] Ecke von Dach/Decke/Raum/Baugrube/geschlossener Polylinie ziehen (Kern wählt den Op je `kind`); `coalesceKey` fasst Einfügen + Zug zusammen. */
moveRingVertex: (kind: RingKind, id: string, index: number, pt: Vec2, coalesceKey?: string) => void;
/** [26] Ecke hinter Ecke `seg` (Dach: flacher Index) einfügen; Kanten-Eigenschaften erbt die neue Kante. */
insertRingVertex: (kind: RingKind, id: string, seg: number, pt: Vec2, coalesceKey?: string) => void;
/** [26] Ecke löschen (mind. 3 bleiben); ein Undo-Schritt. */
deleteRingVertex: (kind: RingKind, id: string, index: number) => void;
/** [26] Nach dem Ziehen: Ecke auf Nachbar bzw. Gerade zwischen den Nachbarn entfällt. */
tidyRingVertex: (kind: RingKind, id: string, index: number, coalesceKey?: string, tol?: number) => void;
moveExcavationEdge: (id: string, aIndex: number, bIndex: number, delta: Vec2) => void;
/** Verschiebt eine Decke (ganzer Umriss) um `delta`. */
moveCeilingBy: (ceilingId: string, delta: Vec2) => void;
@@ -1256,6 +1264,22 @@ export function createProjectSlice(
applyGrip({ op: "sectionLineGrip", id, index, pt: gripPt(pt) }, coalesceKey ?? `moveSectionLineGrip:${id}:${index}`),
insertSectionBend: (id, seg, pt, coalesceKey) => applyGrip({ op: "sectionBendInsert", id, seg, pt: gripPt(pt) }, coalesceKey),
deleteSectionBend: (id, index) => applyGrip({ op: "sectionBendDelete", id, index }),
moveRingVertex: (kind, id, index, pt, coalesceKey) => {
const p = gripPt(pt);
const req: GripRequest =
kind === "roof" ? { op: "roofVertex", id, index, pt: p }
: kind === "ceiling" ? { op: "ceilingGrip", id, index, pt: p }
: kind === "room" ? { op: "roomGrip", id, index, pt: p }
: kind === "excavation" ? { op: "excavationGrip", id, index, pt: p }
: { op: "moveGrip", drawingId: id, wallId: null, index, pt: p, scale: DEFAULT_SCALE_DENOMINATOR };
applyGrip(req, coalesceKey ?? `moveRingVertex:${kind}:${id}:${index}`);
},
insertRingVertex: (kind, id, seg, pt, coalesceKey) =>
applyGrip(kind === "polyline" ? { op: "insertPoint", id, seg, pt: gripPt(pt) } : { op: "ringInsert", kind, id, seg, pt: gripPt(pt) }, coalesceKey),
deleteRingVertex: (kind, id, index) =>
applyGrip(kind === "polyline" ? { op: "deletePoint", id, index } : { op: "ringDelete", kind, id, index }),
tidyRingVertex: (kind, id, index, coalesceKey, tol) =>
applyGrip({ op: "ringTidy", kind, id, index, ...(tol != null ? { tol } : {}) }, coalesceKey),
tidySectionLine: (id, coalesceKey, tol) => applyGrip({ op: "sectionLineTidy", id, ...(tol != null ? { tol } : {}) }, coalesceKey),
moveExcavationEdge: (id, aIndex, bIndex, delta) =>
+125
View File
@@ -0,0 +1,125 @@
// [26] Ecke einfügen/löschen an Umriss-Ringen (Dach samt Hof, Decke, geschlossene Polylinie) über den Store:
// ein Undo-Schritt je Aktion, Einfügen + Zug + Aufräumen mit gleichem Schlüssel ebenso; Kanten-Neigung des Dachs läuft mit.
import { beforeEach, describe, expect, it } from "vitest";
import { getState, setState } from "./appStore";
import type { Project, Roof } from "../model/types";
const roof: Roof = {
id: "RF1",
type: "roof",
floorId: "eg",
categoryCode: "31",
outline: [
{ x: 0, y: 0 },
{ x: 12, y: 0 },
{ x: 12, y: 8 },
{ x: 0, y: 8 },
],
holes: [
[
{ x: 4, y: 2 },
{ x: 4, y: 6 },
{ x: 8, y: 6 },
],
],
edgePitchDeg: [30, null, 40, 50, 20, 21, 22],
shape: "walm",
pitchDeg: 35,
overhang: 0,
ridgeAxis: "x",
thickness: 0.2,
};
const baseProject = {
id: "p",
name: "T",
layers: [],
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, baseElevation: 0 }],
walls: [],
drawings2d: [
{
id: "pl",
type: "drawing2d",
levelId: "eg",
categoryCode: "20",
geom: { shape: "polyline", closed: true, pts: [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 4 }, { x: 0, y: 4 }] },
},
],
roofs: [roof],
} as unknown as Project;
const current = (): Roof => getState().project.roofs![0];
const poly = () => {
const g = getState().project.drawings2d.find((d) => d.id === "pl")!.geom;
if (g.shape !== "polyline") throw new Error("keine Polylinie");
return g;
};
beforeEach(() => {
setState({ project: JSON.parse(JSON.stringify(baseProject)), undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false });
getState().clearHistory();
});
describe("Ecken am Dach", () => {
it("Einfügen erbt die geteilte Kante, ein Undo-Schritt", () => {
getState().insertRingVertex("roof", "RF1", 1, { x: 13, y: 4 });
expect(current().outline).toHaveLength(5);
expect(current().outline[2]).toEqual({ x: 13, y: 4 });
expect(current().edgePitchDeg).toEqual([30, null, null, 40, 50, 20, 21, 22]);
expect(getState().undoDepth).toBe(1);
getState().undo();
expect(current().outline).toHaveLength(4);
expect(current().edgePitchDeg).toEqual([30, null, 40, 50, 20, 21, 22]);
});
it("Einfügen, Ziehen und Aufräumen mit gleichem Schlüssel sind ein Schritt; auf die Gerade zurück entfällt die Ecke", () => {
const key = "ringInsert:RF1:1";
getState().insertRingVertex("roof", "RF1", 0, { x: 6, y: 1 }, key);
getState().moveRingVertex("roof", "RF1", 1, { x: 6, y: 3 }, key);
getState().moveRingVertex("roof", "RF1", 1, { x: 6, y: 0.001 }, key);
getState().tidyRingVertex("roof", "RF1", 1, key, 0.01);
expect(current().outline).toHaveLength(4);
expect(current().edgePitchDeg).toEqual([30, null, 40, 50, 20, 21, 22]);
getState().undo();
expect(current().outline).toHaveLength(4);
expect(getState().canUndo).toBe(false);
});
it("gezogene Ecke bleibt, solange sie nicht auf der Geraden liegt (ein Undo-Schritt)", () => {
const key = "ringInsert:RF1:2";
getState().insertRingVertex("roof", "RF1", 0, { x: 6, y: 1 }, key);
getState().moveRingVertex("roof", "RF1", 1, { x: 6, y: -2 }, key);
getState().tidyRingVertex("roof", "RF1", 1, key, 0.01);
expect(current().outline).toHaveLength(5);
expect(current().outline[1]).toEqual({ x: 6, y: -2 });
expect(getState().undoDepth).toBe(1);
});
it("Löschen: Hof-Ecke geht nicht unter drei, Umriss-Ecke schon, Kanten-Eintrag entfällt", () => {
getState().deleteRingVertex("roof", "RF1", 4); // Hof hat 3 Ecken
expect(current().holes![0]).toHaveLength(3);
expect(getState().canUndo).toBe(false);
getState().deleteRingVertex("roof", "RF1", 2);
expect(current().outline).toHaveLength(3);
expect(current().edgePitchDeg).toEqual([30, null, 50, 20, 21, 22]);
expect(getState().undoDepth).toBe(1);
});
});
describe("Ecken an der geschlossenen Polylinie", () => {
it("Einfügen, Aufräumen auf der Geraden, Löschen", () => {
const key = "ringInsert:pl:1";
getState().insertRingVertex("polyline", "pl", 0, { x: 2, y: 1 }, key);
expect(poly().pts).toHaveLength(5);
getState().moveRingVertex("polyline", "pl", 1, { x: 2, y: 0.002 }, key);
getState().tidyRingVertex("polyline", "pl", 1, key, 0.01);
expect(poly().pts).toHaveLength(4);
expect(getState().undoDepth).toBe(1);
getState().deleteRingVertex("polyline", "pl", 2);
expect(poly().pts).toHaveLength(3);
// Mindestens drei Ecken bleiben.
getState().deleteRingVertex("polyline", "pl", 0);
expect(poly().pts).toHaveLength(3);
});
});
+75 -1
View File
@@ -8,6 +8,7 @@
import { useRef, useState, type RefObject } from "react";
import { useEventBundle, useSameData } from "./useEvent";
import { leftNormal, normalize, scale, sub, wallCorners } from "../model/geometry";
import type { RingKind } from "../core";
import type { Ceiling, Drawing2D, EdgeGrip, Excavation, Project, Roof, Room, Vec2, Wall } from "../model/types";
import { wallTypeThickness } from "../model/types";
import { bulgeArcPoints, drawingVertices, surfaceOpeningGripPatch, surfaceOpeningGrips, surfaceOpeningInfo, wallArcBand } from "../core";
@@ -199,6 +200,8 @@ export function useGripEditing(opts: {
/** Pixel je Meter beim letzten Zug (Aufräum-Toleranz). */
const sectionPxRef = useRef(0);
const sectionDragRef = useRef<{ id: string; key: string; midIndex: number; bendIndex: number } | null>(null);
/** [26] Laufender Zug an einer Einfüge-Raute: gemeinsamer Undo-Schlüssel, Raute-Index und Index der eingefügten Ecke. */
const ringDragRef = useRef<{ kind: RingKind; id: string; key: string; midIndex: number; vertex: number } | null>(null);
// 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");
@@ -220,6 +223,9 @@ export function useGripEditing(opts: {
drawingId?: string;
wallId?: string;
localIndex: number;
/** [26] Einfüge-Griff (Raute) in Kante `insertSeg` des Umriss-Rings `ring` (Dach: flacher Index). */
insertSeg?: number;
ring?: { kind: RingKind; id: string };
}
const gripOwners: GripOwner[] = [];
// [ersterFlachIndex, letzterFlachIndex] DESSELBEN Elements — für die Anker-
@@ -310,6 +316,32 @@ export function useGripEditing(opts: {
return [];
})();
const MAX_INSERT_GRIP_POINTS = 100; // Kataster-Umrisse mit tausenden Punkten: keine Rauten
/** Anteil entlang der Kante, an dem der Einfüge-Griff sitzt (neben dem Kanten-Anfasser in der Mitte). */
const INSERT_AT = 0.25;
/**
* [26] Einfüge-Griffe (Rauten) je Kante der Ringe hinter die Ecken-Griffe in `out` hängen: Ziehen fügt dort eine
* Ecke ein. `rings` mit Start-Index im flachen Ecken-Index (Dach: Umriss, dann Höfe).
*/
const pushInsertGrips = (
out: Vec2[],
rings: { pts: Vec2[]; off: number }[],
ring: { kind: RingKind; id: string },
owner: { drawingId?: string } = {},
keep?: (seg: number) => boolean,
) => {
const start = out.length;
for (const { pts, off } of rings) {
pts.forEach((a, i) => {
if (keep && !keep(off + i)) return;
const b = pts[(i + 1) % pts.length];
out.push({ x: a.x + (b.x - a.x) * INSERT_AT, y: a.y + (b.y - a.y) * INSERT_AT, insert: true } as Vec2);
gripOwners.push({ ...owner, localIndex: -1, insertSeg: off + i, ring });
});
}
for (let i = start; i < out.length; i++) gripOwnerRange.push([start, out.length - 1]);
};
const grips: Vec2[] = (() => {
// Öffnung (Fenster/Tür): EIN Mittelpunkt-Griff auf der Wandachse. Ziehen
// verschiebt die Öffnung entlang der Wirts-Wand (siehe applyGrip →
@@ -364,12 +396,14 @@ export function useGripEditing(opts: {
for (const { pts, off } of roofRings(selectedRoof)) {
pts.forEach((q, i) => { out.push(q); gripOwners.push({ localIndex: off + i }); gripOwnerRange.push([off, off + pts.length - 1]); });
}
pushInsertGrips(out, roofRings(selectedRoof), { kind: "roof", id: selectedRoof.id });
return out;
}
// [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);
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
pushInsertGrips(pts, [{ pts: selectedExcavation.outline, off: 0 }], { kind: "excavation", id: selectedExcavation.id });
return pts;
}
// Decke: die Umriss-Vertices als Griffe (nur bei genau einer gewählten Decke,
@@ -377,6 +411,7 @@ export function useGripEditing(opts: {
if (modelEditable && selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
const pts = [...selectedCeiling.outline];
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
if (!selectedCeiling.locked) pushInsertGrips(pts, [{ pts: selectedCeiling.outline, off: 0 }], { kind: "ceiling", id: selectedCeiling.id });
return pts;
}
// Raum: die Umriss-Vertices als Griffe (nur bei genau einem gewählten Raum).
@@ -389,6 +424,7 @@ export function useGripEditing(opts: {
) {
const pts = [...selectedRoom.boundary];
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
if (!selectedRoom.locked) pushInsertGrips(pts, [{ pts: selectedRoom.boundary, off: 0 }], { kind: "room", id: selectedRoom.id });
return pts;
}
// Mehrfachauswahl (Regel- UND Standardfall): je gewähltem 2D-Element bzw.
@@ -425,6 +461,10 @@ export function useGripEditing(opts: {
? (i: number) => i < g.pts.length || Math.abs(g.bulge?.[i - g.pts.length] ?? 0) > 1e-9
: undefined;
pushGroup(drawingVertices(d, scaleDenominator), { drawingId: id }, keep);
// [26] Geschlossene Polylinie: Einfüge-Raute auf jedem geraden Segment (Bogen-Segmente haben ihren Mitten-Griff).
if (g.shape === "polyline" && g.closed && !d.locked && g.pts.length >= 3 && g.pts.length <= MAX_INSERT_GRIP_POINTS) {
pushInsertGrips(out, [{ pts: g.pts, off: 0 }], { kind: "polyline", id }, { drawingId: id }, (seg) => Math.abs(g.bulge?.[seg] ?? 0) < 1e-9);
}
}
if (modelEditable && effectiveDrawingIds.length === 0) {
for (const id of selectedWallIds) {
@@ -716,6 +756,7 @@ export function useGripEditing(opts: {
// Wand/Öffnung/Treppe haben keine Polygon-Nachbarn → null.
const resolvePolygonRing = (index: number): { pts: Vec2[]; index: number; closed: boolean } | null => {
const owner = gripOwners[index];
if (owner?.insertSeg != null) return null;
if (roofGripsOn && selectedRoof && !owner?.drawingId && !owner?.wallId) {
const ring = roofRings(selectedRoof).find((rg) => index >= rg.off && index < rg.off + rg.pts.length);
return ring ? { pts: ring.pts, index: index - ring.off, closed: true } : null;
@@ -935,6 +976,20 @@ export function useGripEditing(opts: {
// Editier-Dispatch: bei gewählter Decke auf die Decken-Aktionen umleiten, sonst
// auf die Wand/2D-Aktionen. So teilen Plan- UND 3D-Griffe denselben Pfad.
const applyGrip = (index: number, pt: Vec2, arcLength?: number) => {
// [26] Einfüge-Raute am Umriss (Dach, Decke, Raum, Baugrube, geschlossene Polylinie): der erste Zug fügt die Ecke
// ein, danach folgt sie dem Zeiger; Einfügen, Zug und Aufräumen sind ein Undo-Schritt (gleicher Schlüssel).
const rd = ringDragRef.current;
if (rd && rd.midIndex === index) {
storeState().moveRingVertex(rd.kind, rd.id, rd.vertex, pt, rd.key);
return;
}
const ins = gripOwners[index];
if (modelEditable && ins?.insertSeg != null && ins.ring) {
const key = `ringInsert:${ins.ring.id}:${Date.now()}`;
ringDragRef.current = { ...ins.ring, key, midIndex: index, vertex: ins.insertSeg + 1 };
storeState().insertRingVertex(ins.ring.kind, ins.ring.id, ins.insertSeg, pt, key);
return;
}
// Öffnung: den gezogenen Punkt auf die Wandachse projizieren → neue
// `position` (Abstand des ersten Pfostens vom Wand-Start), sodass die
// Öffnung entlang der Wand gleitet. Griff sitzt in der Öffnungsmitte, daher
@@ -1112,13 +1167,18 @@ export function useGripEditing(opts: {
else if (pa.kind === "excavation") moveExcavationGrip(pa.id, pa.index, pa.pt);
else if (pa.kind === "roof") opts.moveRoofVertex?.(pa.id, pa.index, pa.pt);
else moveCeilingGrip(pa.id, pa.index, pa.pt);
// [26] Ecke auf einem Nachbarn bzw. auf der Geraden zwischen den Nachbarn entfällt (im selben Undo-Schritt).
storeState().tidyRingVertex(pa.kind, pa.id, pa.index, undefined, ringTidyTol());
}
const pw = pendingWallGripRef.current;
pendingWallGripRef.current = null;
if (pw) moveGripOf(null, pw.wallId, pw.localIndex, pw.pt, scaleDenominator, undefined, pw.arcLength);
const pend = pendingGripRef.current;
pendingGripRef.current = null;
if (pend) moveGripOf(pend.drawingId, null, pend.localIndex, pend.pt, scaleDenominator);
if (pend) {
moveGripOf(pend.drawingId, null, pend.localIndex, pend.pt, scaleDenominator);
storeState().tidyRingVertex("polyline", pend.drawingId, pend.localIndex, undefined, ringTidyTol());
}
};
/** Polylinien-Element (nicht gesperrt), dessen Änderung aufgeschoben werden darf. */
@@ -1254,8 +1314,16 @@ export function useGripEditing(opts: {
// Zeiger-Genauigkeit: ca. 6 Pixel der Ansicht.
if (drag) storeState().tidySectionLine(drag.id, drag.key, sectionPxRef.current > 0 ? 6 / sectionPxRef.current : undefined);
};
/** Aufräum-Abstand (m) der Ecken: ca. 6 Pixel der Ansicht (unbekannt = Kern-Vorgabe). */
const ringTidyTol = (): number | undefined => (sectionPxRef.current > 0 ? 6 / sectionPxRef.current : undefined);
/** [26] Nach einem Zug an einer Einfüge-Raute: die eingefügte Ecke entfällt, wenn sie auf der Geraden liegt. */
const tidyRingDrag = () => {
const rd = ringDragRef.current;
if (rd) storeState().tidyRingVertex(rd.kind, rd.id, rd.vertex, rd.key, ringTidyTol());
};
const endEditing = () => {
sectionDragRef.current = null;
ringDragRef.current = null;
setDraft(null);
edgeAppliedDeltaRef.current = null; // Kanten-Drag beendet → Anker zurücksetzen
moveCoincidentRef.current = null; // Körper-Koinzidenz-Gruppe verwerfen
@@ -1377,6 +1445,7 @@ export function useGripEditing(opts: {
// verankern (s. Kommentar an gripOriginRef).
if (gripDragInfoRef.current === null) {
sectionDragRef.current = null; // [176] neuer Zug: eigener Undo-Schlüssel, kein eingefügter Knick
ringDragRef.current = null; // [26] dito für eingefügte Ecken
gripOriginRef.current = grips[index];
const op0 = selectedOpeningId ? (project.openings ?? []).find((o) => o.id === selectedOpeningId) : undefined;
const dir0 = op0 ? openingWallDir() : null;
@@ -1609,6 +1678,7 @@ export function useGripEditing(opts: {
commitPendingGrip();
commitPendingBody();
tidySectionDrag();
tidyRingDrag();
endEditing();
},
// Bewaffneten Punkt-Griff verwerfen (Escape): exakt auf `origin`
@@ -1625,6 +1695,10 @@ export function useGripEditing(opts: {
} else if (sectionDragRef.current) {
applyGrip(index, origin);
tidySectionDrag();
} else if (ringDragRef.current) {
// Eingefügte Ecke zurück auf die Kante: das Aufräumen entfernt sie wieder.
applyGrip(index, origin);
tidyRingDrag();
} else if (!selectedSectionLine) applyGrip(index, origin);
endEditing();
},
+4
View File
@@ -128,6 +128,8 @@ export function useProjectActions(
const insertDrawingPoint = useStore((s) => s.insertDrawingPoint);
const insertSectionBend = useStore((s) => s.insertSectionBend);
const deleteSectionBend = useStore((s) => s.deleteSectionBend);
const insertRingVertex = useStore((s) => s.insertRingVertex);
const deleteRingVertex = useStore((s) => s.deleteRingVertex);
const deleteDrawingPoint = useStore((s) => s.deleteDrawingPoint);
const setPolylineVertexType = useStore((s) => s.setPolylineVertexType);
// Wandstile: immutable Patch eines Wandtyps (z. B. Schichtfugen-Stile). Kein
@@ -448,6 +450,8 @@ export function useProjectActions(
insertDrawingPoint,
insertSectionBend,
deleteSectionBend,
insertRingVertex,
deleteRingVertex,
deleteDrawingPoint,
setPolylineVertexType,
patchWallType,