[193] Gelände & Co.: Höhen-Befehle im Kern, Maus-Ziehen für Kontext-Elemente, Höhenlinien-Punkte als Griffe, Entf auf Ansichts-Schlagschatten
This commit is contained in:
24 files changed
+530
-71
No files matched your search
@@ -18,7 +18,7 @@ import { textFrameCorners } from "../text/textFrame";
|
||||
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";
|
||||
export type RingKind = "roof" | "ceiling" | "room" | "excavation" | "polyline" | "contours";
|
||||
|
||||
/** Eine Griff-Änderung für den Kern (`grips.rs::run`); Zahlen dürfen NaN/±∞ sein (Marken). */
|
||||
export type GripRequest =
|
||||
@@ -32,6 +32,9 @@ 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 }
|
||||
// [193] Höhenlinien-Satz: Punkt (flacher Index über alle Linien) ziehen bzw. hinter Punkt `seg` einfügen (Kern `contour_edit`).
|
||||
| { op: "contourGrip"; id: string; index: number; pt: P }
|
||||
| { op: "contourInsert"; id: string; seg: number; pt: P }
|
||||
// [26] Dach: Ecke bzw. Kante von Umriss/Hof, flacher Index (erst `outline`, dann `holes` Ring für Ring).
|
||||
| { op: "roofVertex"; id: string; index: number; pt: P }
|
||||
| { op: "roofEdge"; id: string; a: number; b: number; delta: P }
|
||||
|
||||
@@ -12,7 +12,6 @@ import type { ContextObject } from "../model/types";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import { resmoothGridTerrain } from "../model/terrain";
|
||||
import { useMemo, useState } from "react";
|
||||
import { contourHeightPatch, heightOffsetPatch } from "../state/contextHeight";
|
||||
import type { ExcavationQuantity } from "../core";
|
||||
|
||||
/** Zahl-Eingabe für ein Feld eines Kontext-Objekts (leer = Standard, ungültig = keine Änderung). */
|
||||
@@ -68,12 +67,12 @@ const RESMOOTH_PASSES = [1, 2, 4] as const;
|
||||
|
||||
/** [193] Höhenversatz (alle Höhen um dz) und, bei Höhenlinien, die Höhe je Linie. */
|
||||
function HeightFields({ obj }: { obj: ContextObject }) {
|
||||
const host = usePanelHost();
|
||||
const offsetContextHeight = useStore((s) => s.offsetContextHeight);
|
||||
const setContourHeight = useStore((s) => s.setContourHeight);
|
||||
const [dz, setDz] = useState("");
|
||||
if (obj.type === "image") return null;
|
||||
const apply = () => {
|
||||
const patch = dz.trim() === "" ? null : heightOffsetPatch(obj, Number(dz.replace(",", ".")));
|
||||
if (patch) host.onPatchContextObject(obj.id, patch);
|
||||
if (dz.trim() !== "") offsetContextHeight(obj.id, Number(dz.replace(",", ".")));
|
||||
setDz("");
|
||||
};
|
||||
return (
|
||||
@@ -104,8 +103,7 @@ function HeightFields({ obj }: { obj: ContextObject }) {
|
||||
data-testid={`contour-z-${i}`}
|
||||
value={c.z}
|
||||
onChange={(e) => {
|
||||
const patch = e.target.value.trim() === "" ? null : contourHeightPatch(obj, i, Number(e.target.value));
|
||||
if (patch) host.onPatchContextObject(obj.id, patch, `site-${obj.id}-contourZ-${i}`);
|
||||
if (e.target.value.trim() !== "") setContourHeight(obj.id, i, Number(e.target.value), `site-${obj.id}-contourZ-${i}`);
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// [193] Maus-Ziehen von Gelände-/Umgebungs-Elementen im Plan: Bezugspunkt für den Fang.
|
||||
// Das Verschieben selbst (Ops) und die Vorschau stammen aus dem Kern (`cmd_transform.rs`).
|
||||
|
||||
import type { Project, Vec2 } from "../model/types";
|
||||
|
||||
/** Ein Punkt des Elements (erste Ecke / erster Punkt / Rahmen-Ecke), der beim Ziehen am Fang teilnimmt. */
|
||||
export function contextAnchor(project: Project, id: string): Vec2 | null {
|
||||
const o = (project.context ?? []).find((c) => c.id === id);
|
||||
if (!o) return null;
|
||||
switch (o.type) {
|
||||
case "excavation":
|
||||
return o.outline[0] ?? null;
|
||||
case "contourSet":
|
||||
return o.contours.find((c) => c.pts.length > 0)?.pts[0] ?? null;
|
||||
case "terrainMesh":
|
||||
case "importedMesh":
|
||||
return o.positions.length >= 2 ? { x: o.positions[0], y: o.positions[1] } : null;
|
||||
case "image":
|
||||
return o.min;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// [193] Gelände & Co.: Höhenversatz/Höhe je Höhenlinie (Kern `cmd_context.rs`), Punkte einer Höhenlinie per Griff
|
||||
// (Kern `grips.rs::contour_edit`), Verschieben über den Kern, Bezugspunkt für den Fang beim Ziehen im Plan.
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { documentFor } from "../core/document";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { ContextObject, ContourSet, Excavation, Project } from "../model/types";
|
||||
import { contextAnchor } from "./contextDrag";
|
||||
import { transformOps } from "../tools/transform";
|
||||
|
||||
const hl = {
|
||||
id: "hl",
|
||||
type: "contourSet",
|
||||
categoryCode: "02",
|
||||
name: "Höhenlinien",
|
||||
contours: [
|
||||
{ z: 500, closed: false, pts: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 4, y: 0 }] },
|
||||
{ z: 501, closed: true, pts: [{ x: 0, y: 1 }, { x: 2, y: 1 }, { x: 2, y: 3 }] },
|
||||
],
|
||||
} as ContourSet;
|
||||
const pit = { id: "bg", type: "excavation", categoryCode: "07", name: "Baugrube", outline: [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 4 }], bottom: -2 } as Excavation;
|
||||
const project = (): Project => ({ ...sampleProject, context: [hl, pit] as ContextObject[] });
|
||||
|
||||
function commit<T extends ContextObject>(base: Project, req: object, id: string): T {
|
||||
const r = documentFor(base).commitGrip(base, req, undefined, 1);
|
||||
if ("problems" in r) throw new Error(r.problems.join(";"));
|
||||
return r.project.context!.find((c) => c.id === id) as T;
|
||||
}
|
||||
|
||||
describe("Höhen über den Kern", () => {
|
||||
it("Höhenversatz und Höhe je Linie als Ops", () => {
|
||||
const p = project();
|
||||
expect(documentFor(p).cmdOps({ cmd: "contextOffset", id: "bg", dz: 1.5 })).toHaveLength(1);
|
||||
expect(documentFor(p).cmdOps({ cmd: "contextOffset", id: "bg", dz: 0 })).toEqual([]);
|
||||
const z = documentFor(p).cmdOps({ cmd: "contourZ", id: "hl", index: 1, z: 510 });
|
||||
expect(JSON.stringify(z)).toContain("510");
|
||||
expect(documentFor(p).cmdOps({ cmd: "contourZ", id: "hl", index: 1, z: 501 })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Höhenlinien: Punkte per Griff", () => {
|
||||
it("Punkt ziehen (flacher Index über alle Linien) und Punkt einfügen", () => {
|
||||
const p = project();
|
||||
expect(commit<ContourSet>(p, { op: "contourGrip", id: "hl", index: 4, pt: [9, 9] }, "hl").contours[1].pts[1]).toEqual({ x: 9, y: 9 });
|
||||
const ins = commit<ContourSet>(p, { op: "contourInsert", id: "hl", seg: 1, pt: [3, 1] }, "hl");
|
||||
expect(ins.contours[0].pts).toHaveLength(4);
|
||||
expect(ins.contours[0].pts[2]).toEqual({ x: 3, y: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kontext verschieben (Maus-Ziehen im Plan)", () => {
|
||||
it("ein Op-Satz verschiebt alle gewählten Elemente; Bezugspunkt je Art", () => {
|
||||
const p = project();
|
||||
const ops = transformOps(p, { wallIds: [], drawingId: null, contextIds: ["bg", "hl"] }, "move", [{ x: 0, y: 0 }, { x: 3, y: -1 }], "move", 1);
|
||||
expect(ops).toHaveLength(2);
|
||||
expect(contextAnchor(p, "bg")).toEqual({ x: 0, y: 0 });
|
||||
expect(contextAnchor(p, "hl")).toEqual({ x: 0, y: 0 });
|
||||
expect(contextAnchor(p, "nix")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { contourHeightPatch, heightOffsetPatch } from "./contextHeight";
|
||||
import type { ContextObject } from "../model/types";
|
||||
|
||||
const base = { id: "a", name: "A", categoryCode: "02" };
|
||||
const set = { ...base, type: "contourSet", contours: [{ z: 500, pts: [], closed: false }, { z: 501, pts: [], closed: false }] } as ContextObject;
|
||||
|
||||
describe("Höhe von Gelände-Elementen", () => {
|
||||
it("Netz: nur z wird versetzt", () => {
|
||||
const o = { ...base, type: "terrainMesh", positions: [0, 0, 5, 1, 0, 6, 0, 1, 7], indices: [0, 1, 2] } as ContextObject;
|
||||
expect(heightOffsetPatch(o, -1.5)).toEqual({ positions: [0, 0, 3.5, 1, 0, 4.5, 0, 1, 5.5] });
|
||||
});
|
||||
it("Höhenlinien und Baugrube", () => {
|
||||
expect(heightOffsetPatch(set, 2)).toEqual({ contours: [{ z: 502, pts: [], closed: false }, { z: 503, pts: [], closed: false }] });
|
||||
expect(heightOffsetPatch({ ...base, type: "excavation", outline: [], bottom: -3 } as ContextObject, 0.5)).toEqual({ bottom: -2.5 });
|
||||
});
|
||||
it("keine Änderung bei 0/NaN; Höhe einer Linie", () => {
|
||||
expect(heightOffsetPatch(set, 0)).toBeNull();
|
||||
expect(heightOffsetPatch(set, NaN)).toBeNull();
|
||||
expect(contourHeightPatch(set, 1, 510)).toEqual({ contours: [{ z: 500, pts: [], closed: false }, { z: 510, pts: [], closed: false }] });
|
||||
expect(contourHeightPatch(set, 1, 501)).toBeNull();
|
||||
expect(contourHeightPatch(set, 7, 1)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
// [193] Höhe von Gelände-/Umgebungs-Elementen ändern: Höhenversatz (alle z um dz) und die Höhe einer einzelnen
|
||||
// Höhenlinie. Liefert Feld-Patches für `patchContextObject`; `null` = Art ohne Höhe (Luftbild) oder keine Änderung.
|
||||
|
||||
import type { ContextObject, Contour } from "../model/types";
|
||||
|
||||
/** Alle Höhen des Elements um `dz` Meter versetzen: Netz-z, Höhenlinien-z, Baugruben-Sohle. */
|
||||
export function heightOffsetPatch(obj: ContextObject, dz: number): Record<string, unknown> | null {
|
||||
if (!Number.isFinite(dz) || dz === 0) return null;
|
||||
switch (obj.type) {
|
||||
case "terrainMesh":
|
||||
case "importedMesh": {
|
||||
const pos = obj.positions.slice();
|
||||
for (let i = 2; i < pos.length; i += 3) pos[i] += dz;
|
||||
return { positions: pos };
|
||||
}
|
||||
case "contourSet":
|
||||
return { contours: obj.contours.map((c): Contour => ({ ...c, z: c.z + dz })) };
|
||||
case "excavation":
|
||||
return { bottom: obj.bottom + dz };
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Höhe der Höhenlinie `index` eines Höhenlinien-Satzes setzen. */
|
||||
export function contourHeightPatch(obj: ContextObject, index: number, z: number): Record<string, unknown> | null {
|
||||
if (obj.type !== "contourSet" || !Number.isFinite(z) || !obj.contours[index] || obj.contours[index].z === z) return null;
|
||||
return { contours: obj.contours.map((c, i): Contour => (i === index ? { ...c, z } : c)) };
|
||||
}
|
||||
@@ -1274,13 +1274,14 @@ export function createProjectSlice(
|
||||
: kind === "ceiling" ? { op: "ceilingGrip", id, index, pt: p }
|
||||
: kind === "room" ? { op: "roomGrip", id, index, pt: p }
|
||||
: kind === "excavation" ? { op: "excavationGrip", id, index, pt: p }
|
||||
: kind === "contours" ? { op: "contourGrip", 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),
|
||||
applyGrip(kind === "contours" ? { op: "contourInsert", id, seg, pt: gripPt(pt) } : 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 }),
|
||||
kind === "contours" ? undefined : 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),
|
||||
|
||||
@@ -49,4 +49,10 @@ describe("selectAllIds", () => {
|
||||
const ogWall = p.walls.find((w) => w.floorId === "og")!;
|
||||
expect(ids.walls).not.toContain(ogWall.id);
|
||||
});
|
||||
|
||||
it("wählt den Schlagschatten einer Ansicht mit (Entf schaltet ihn ab), solange er eingeschaltet ist", () => {
|
||||
expect(selectAllIds(p, "ansicht-sued").site).toEqual(["viewShadows"]);
|
||||
const off = { ...p, drawingLevels: p.drawingLevels.map((l) => (l.id === "ansicht-sued" ? { ...l, shadows: false } : l)) };
|
||||
expect(selectAllIds(off, "ansicht-sued").site).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -38,7 +38,8 @@ export function selectAllIds(project: Project, levelId: string): Partial<Selecti
|
||||
}
|
||||
// Schattenfläche der Sonnenstudie: abgeleitet, aber angeklickt wählbar ([137]) — also auch hier; Entf blendet sie aus.
|
||||
const level = project.drawingLevels.find((l) => l.id === levelId);
|
||||
const site = project.sunStudy?.show && level?.kind === "floor" ? ["sunStudy"] : [];
|
||||
// [193] dito der Schlagschatten der Ansicht (`DrawingLevel.shadows`), nur in einer Ansicht.
|
||||
const site = project.sunStudy?.show && level?.kind === "floor" ? ["sunStudy"] : level?.kind === "elevation" && level.shadows ? ["viewShadows"] : [];
|
||||
return {
|
||||
site,
|
||||
walls: wallIds,
|
||||
|
||||
+25
-1
@@ -9,7 +9,9 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { generateTerrainFromContours, resmoothGridTerrain, type TerrainOptions } from "../model/terrain";
|
||||
import type { ContextObject, Project } from "../model/types";
|
||||
import type { ContextObject, Project, Vec2 } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { transformOps } from "../tools/transform";
|
||||
import { addItems, fieldOps, patchItem, removeItems } from "../core/opsBuild";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { ensureContextCategories } from "../model/contextCategories";
|
||||
@@ -32,6 +34,12 @@ export interface SiteSlice {
|
||||
* null, wenn der ContourSet nicht existiert / kein Mesh entsteht.
|
||||
*/
|
||||
generateTerrain: (contourSetId: string, opts?: TerrainOptions) => string | null;
|
||||
/** [193] Alle Höhen eines Elements um `dz` Meter versetzen (Netz-z, Höhenlinien-z, Baugruben-Sohle; Kern `cmd_context.rs`). */
|
||||
offsetContextHeight: (id: string, dz: number) => void;
|
||||
/** [193] Höhe der Höhenlinie `index` eines Höhenlinien-Satzes setzen (Kern `cmd_context.rs`); `coalesceKey` für Tippen. */
|
||||
setContourHeight: (id: string, index: number, z: number, coalesceKey?: string) => void;
|
||||
/** [193] Kontext-Elemente um `delta` verschieben (Maus-Ziehen im Plan; Kern `cmd_transform.rs`), ein Undo-Schritt. */
|
||||
moveContextBy: (ids: string[], delta: Vec2) => void;
|
||||
/** [T6]/[68] Ändert Felder eines Kontext-Objekts (Gelände, Baugrube) in einem Schritt; `coalesceKey` für Tippen. */
|
||||
patchContextObject: (id: string, patch: Record<string, unknown>, coalesceKey?: string) => void;
|
||||
/**
|
||||
@@ -93,6 +101,22 @@ export function createSiteSlice(
|
||||
get().applyChange((p) => removeItems(p, "context", ids));
|
||||
},
|
||||
|
||||
offsetContextHeight: (id, dz) => {
|
||||
const ops = documentFor(get().project).cmdOps({ cmd: "contextOffset", id, dz });
|
||||
if (ops.length) get().applyChange(ops);
|
||||
},
|
||||
|
||||
setContourHeight: (id, index, z, coalesceKey) => {
|
||||
const ops = documentFor(get().project).cmdOps({ cmd: "contourZ", id, index, z });
|
||||
if (ops.length) get().applyChange(ops, coalesceKey);
|
||||
},
|
||||
|
||||
moveContextBy: (ids, delta) => {
|
||||
if (ids.length === 0 || (delta.x === 0 && delta.y === 0)) return;
|
||||
const ops = transformOps(get().project, { wallIds: [], drawingId: null, contextIds: ids }, "move", [{ x: 0, y: 0 }, delta], "move", 1);
|
||||
if (ops.length) get().applyChange(ops);
|
||||
},
|
||||
|
||||
patchContextObject: (id, patch, coalesceKey) =>
|
||||
get().applyChange((p) => patchItem(p, "context", id, (o) => ({ ...o, ...patch }) as ContextObject), coalesceKey),
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ declare global {
|
||||
modelView: () => string | undefined;
|
||||
/** [173] Schnitt der aktiven Ebene (1:50, Detailgrad der Anzeige): Zahl der Wand-Schnittflächen und ihre Fläche (m²). */
|
||||
sectionWalls: () => Promise<{ n: number; area: number }>;
|
||||
/** [193] Gelände-/Umgebungs-Elemente (Art, Id, bei der Baugrube die erste Umrissecke). */
|
||||
/** [193] Gelände-/Umgebungs-Elemente (Art, Id, bei der Baugrube die erste Umrissecke, bei Höhenlinien der erste Punkt). */
|
||||
context: () => { id: string; type: string; first?: { x: number; y: number } }[];
|
||||
/** [193] Gefüllte Flächen (Füllfarbe gesetzt) im Grundriss der aktiven Ebene (alle Kategorien, 1:100); bei 0 ist nichts Gefülltes mehr zu sehen. */
|
||||
planFills: () => number;
|
||||
@@ -95,7 +95,7 @@ export function installTestHooks(): void {
|
||||
return generatePlan(s.project, s.activeLevelId, codes, undefined, s.detail, false, false, true, 50).primitives.filter((q) => q.kind === "line" && q.cls === cls).length;
|
||||
},
|
||||
context: () =>
|
||||
(getState().project.context ?? []).map((c) => ({ id: c.id, type: c.type, first: c.type === "excavation" ? c.outline[0] : undefined })),
|
||||
(getState().project.context ?? []).map((c) => ({ id: c.id, type: c.type, first: c.type === "excavation" ? c.outline[0] : c.type === "contourSet" ? c.contours[0]?.pts[0] : undefined })),
|
||||
planFills: () => {
|
||||
const s = getState();
|
||||
const codes = new Set<string>();
|
||||
|
||||
@@ -33,7 +33,8 @@ import {
|
||||
wallGripPoints,
|
||||
type GripLocks,
|
||||
} from "../core";
|
||||
import { areaMovePreview, drawingMovePreview } from "../tools/transform";
|
||||
import { areaMovePreview, drawingMovePreview, transformPreview } from "../tools/transform";
|
||||
import { contextAnchor } from "./contextDrag";
|
||||
import type { DraftShape, SnapResult, SnapSettings, ToolDraft, ToolMods } from "../tools/types";
|
||||
import { computeSnap } from "../tools/snapping";
|
||||
import { useCommandTabShortcut } from "./useKeyboardShortcuts";
|
||||
@@ -181,6 +182,14 @@ export function useGripEditing(opts: {
|
||||
const selectedOpeningId = single(selection, "openings");
|
||||
const selectedStairId = single(selection, "stairs");
|
||||
// [149] Baum: Griff in der Stammmitte (verschieben) und am Kronenrand (Kronendurchmesser).
|
||||
// [193] Einzeln gewählter Höhenlinien-Satz: Punkte als Griffe (Kern `grips.rs::contour_edit`).
|
||||
const selectedContourSetId = modelEditable && selection.contextObjects.length === 1 ? selection.contextObjects[0] : null;
|
||||
const selectedContourSet = selectedContourSetId
|
||||
? (() => {
|
||||
const o = (project.context ?? []).find((c) => c.id === selectedContourSetId);
|
||||
return o && o.type === "contourSet" ? o : null;
|
||||
})()
|
||||
: null;
|
||||
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.
|
||||
@@ -317,6 +326,7 @@ export function useGripEditing(opts: {
|
||||
})();
|
||||
|
||||
const MAX_INSERT_GRIP_POINTS = 100; // Kataster-Umrisse mit tausenden Punkten: keine Rauten
|
||||
const MAX_CONTOUR_GRIPS = 600; // Höhenlinien-Sätze mit tausenden Punkten: gar keine Punkt-Griffe
|
||||
/** Anteil entlang der Kante, an dem der Einfüge-Griff sitzt (neben dem Kanten-Anfasser in der Mitte). */
|
||||
const INSERT_AT = 0.25;
|
||||
/**
|
||||
@@ -399,6 +409,28 @@ export function useGripEditing(opts: {
|
||||
pushInsertGrips(out, roofRings(selectedRoof), { kind: "roof", id: selectedRoof.id });
|
||||
return out;
|
||||
}
|
||||
// [193] Höhenlinien: jeder Punkt ein Griff (flacher Index über alle Linien), dazu je Segment eine Einfüge-Raute.
|
||||
// Kataster-grosse Sätze (hunderte Punkte) bekommen keine Griffe bzw. keine Rauten.
|
||||
if (selectedContourSet && !selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
const lines = selectedContourSet.contours;
|
||||
const pts: Vec2[] = lines.flatMap((c) => c.pts);
|
||||
if (pts.length > MAX_CONTOUR_GRIPS) return [];
|
||||
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
|
||||
if (pts.length <= MAX_INSERT_GRIP_POINTS) {
|
||||
let off = 0;
|
||||
const rings: { pts: Vec2[]; off: number }[] = [];
|
||||
const noSeg = new Set<number>();
|
||||
for (const c of lines) {
|
||||
if (c.pts.length >= 2) {
|
||||
rings.push({ pts: c.pts, off });
|
||||
if (!c.closed) noSeg.add(off + c.pts.length - 1);
|
||||
}
|
||||
off += c.pts.length;
|
||||
}
|
||||
pushInsertGrips(pts, rings, { kind: "contours", id: selectedContourSet.id }, {}, (seg) => !noSeg.has(seg));
|
||||
}
|
||||
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);
|
||||
@@ -669,6 +701,10 @@ export function useGripEditing(opts: {
|
||||
const pendingAreaGripRef = useRef<{ kind: "room" | "ceiling" | "excavation" | "roof"; id: string; index: number; flat: number; pt: Vec2 } | null>(null);
|
||||
const pendingAreaMoveRef = useRef<{ kind: "ceiling" | "room" | "stair"; id: string; total: Vec2 } | null>(null);
|
||||
const pendingWallMoveRef = useRef<{ wallId: string; total: Vec2 } | null>(null);
|
||||
/** [193] Aufgeschobenes Ziehen von Gelände-/Umgebungs-Elementen: ungefangenes und gefangenes Gesamt-Delta. */
|
||||
const pendingContextMoveRef = useRef<{ ids: string[]; raw: Vec2; total: Vec2; anchor: Vec2 | null } | null>(null);
|
||||
/** [193] Zug an einem Höhenlinien-Punkt (bzw. einer Einfüge-Raute: `insertSeg`): Vorschau bis zum Setzen, dann EIN Undo-Schritt. */
|
||||
const pendingContourRef = useRef<{ id: string; index: number; pt: Vec2; insertSeg?: number } | null>(null);
|
||||
/** Aufgeschobene Öffnungs-Verschiebung im Schnitt/in der Ansicht (neue `position`). */
|
||||
const pendingOpeningMoveRef = useRef<{ id: string; position: number } | null>(null);
|
||||
/** Aufgeschobene Höhen-Änderung im Schnitt (Wand `height` bzw. Öffnung `height`/`sillHeight`). */
|
||||
@@ -976,6 +1012,14 @@ 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) => {
|
||||
// [193] Höhenlinien-Punkt bzw. Einfüge-Raute: nur Vorschau, das Projekt ändert sich beim Setzen (ein Undo-Schritt).
|
||||
if (selectedContourSet) {
|
||||
const ins = gripOwners[index];
|
||||
pendingContourRef.current = ins?.insertSeg != null
|
||||
? { id: selectedContourSet.id, index: ins.insertSeg + 1, pt, insertSeg: ins.insertSeg }
|
||||
: { id: selectedContourSet.id, index, pt };
|
||||
return;
|
||||
}
|
||||
// [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;
|
||||
@@ -1099,6 +1143,23 @@ export function useGripEditing(opts: {
|
||||
|
||||
/** Vorschau-Form des ausstehenden Eckpunkt-Zugs (leer, wenn keiner läuft). */
|
||||
const gripPreviewShapes = (): DraftShape[] => {
|
||||
const pc = pendingContourRef.current;
|
||||
if (pc && selectedContourSet?.id === pc.id) {
|
||||
// Die betroffene Höhenlinie mit dem gezogenen (bzw. eingefügten) Punkt als Linienzug.
|
||||
let off = 0;
|
||||
for (const c of selectedContourSet.contours) {
|
||||
if (pc.index >= off && pc.index < off + c.pts.length + (pc.insertSeg != null ? 1 : 0) && (pc.insertSeg == null || pc.insertSeg >= off)) {
|
||||
const local = pc.index - off;
|
||||
const pts = pc.insertSeg != null ? [...c.pts.slice(0, local), pc.pt, ...c.pts.slice(local)] : c.pts.map((q, i) => (i === local ? pc.pt : q));
|
||||
const out: DraftShape[] = [];
|
||||
for (let i = 0; i + 1 < pts.length; i++) out.push({ kind: "line", a: pts[i], b: pts[i + 1] });
|
||||
if (c.closed && pts.length > 2) out.push({ kind: "line", a: pts[pts.length - 1], b: pts[0] });
|
||||
return out;
|
||||
}
|
||||
off += c.pts.length;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
const pa = pendingAreaGripRef.current;
|
||||
if (pa?.kind === "roof" && selectedRoof) {
|
||||
return roofRings(selectedRoof).map(({ pts, off }) => ({
|
||||
@@ -1160,6 +1221,12 @@ export function useGripEditing(opts: {
|
||||
if (ph.kind === "wall") updateWall(ph.id, ph.patch as Partial<import("../model/types").Wall>);
|
||||
else updateOpening(ph.id, ph.patch);
|
||||
}
|
||||
const pc = pendingContourRef.current;
|
||||
pendingContourRef.current = null;
|
||||
if (pc) {
|
||||
if (pc.insertSeg != null) storeState().insertRingVertex("contours", pc.id, pc.insertSeg, pc.pt);
|
||||
else storeState().moveRingVertex("contours", pc.id, pc.index, pc.pt);
|
||||
}
|
||||
const pa = pendingAreaGripRef.current;
|
||||
pendingAreaGripRef.current = null;
|
||||
if (pa) {
|
||||
@@ -1226,6 +1293,9 @@ export function useGripEditing(opts: {
|
||||
const pom = pendingOpeningMoveRef.current;
|
||||
pendingOpeningMoveRef.current = null;
|
||||
if (pom) slideOpening(pom.id, { position: pom.position });
|
||||
const pcm = pendingContextMoveRef.current;
|
||||
pendingContextMoveRef.current = null;
|
||||
if (pcm) storeState().moveContextBy(pcm.ids, pcm.total);
|
||||
const pa = pendingAreaMoveRef.current;
|
||||
pendingAreaMoveRef.current = null;
|
||||
if (pa && (pa.total.x !== 0 || pa.total.y !== 0)) {
|
||||
@@ -1324,6 +1394,8 @@ export function useGripEditing(opts: {
|
||||
const endEditing = () => {
|
||||
sectionDragRef.current = null;
|
||||
ringDragRef.current = null;
|
||||
pendingContourRef.current = null;
|
||||
pendingContextMoveRef.current = null;
|
||||
setDraft(null);
|
||||
edgeAppliedDeltaRef.current = null; // Kanten-Drag beendet → Anker zurücksetzen
|
||||
moveCoincidentRef.current = null; // Körper-Koinzidenz-Gruppe verwerfen
|
||||
@@ -1536,7 +1608,31 @@ export function useGripEditing(opts: {
|
||||
delta: Vec2,
|
||||
target?: BodyTarget,
|
||||
mods?: ToolMods,
|
||||
pxPerMeter?: number,
|
||||
) => {
|
||||
// [193] Gelände-/Umgebungs-Elemente: Gesamt-Delta (mit Fang des Bezugspunkts) + Vorschau, Projekt erst beim Loslassen.
|
||||
if (target?.contextIds && modelEditable) {
|
||||
const prev = pendingContextMoveRef.current;
|
||||
const same = prev && prev.ids.join("\n") === target.contextIds.join("\n");
|
||||
const anchor = same ? prev!.anchor : contextAnchor(project, target.contextIds[0]);
|
||||
let raw = same ? { x: prev!.raw.x + delta.x, y: prev!.raw.y + delta.y } : delta;
|
||||
if (mods?.shift) {
|
||||
raw = Math.abs(raw.x) >= Math.abs(raw.y) ? { x: raw.x, y: 0 } : { x: 0, y: raw.y };
|
||||
}
|
||||
let total = raw;
|
||||
let hit: SnapResult | null = null;
|
||||
if (anchor && pxPerMeter && !mods?.shift) {
|
||||
hit = snapFor({ x: anchor.x + raw.x, y: anchor.y + raw.y }, pxPerMeter, mods ?? { shift: false, ctrl: false, alt: false });
|
||||
if (hit?.point) total = { x: hit.point.x - anchor.x, y: hit.point.y - anchor.y };
|
||||
}
|
||||
pendingContextMoveRef.current = { ids: target.contextIds, raw, total, anchor };
|
||||
setDraft({
|
||||
preview: transformPreview(project, { wallIds: [], drawingId: null, contextIds: target.contextIds }, "move", [{ x: 0, y: 0 }, total], "move", 1),
|
||||
vertices: [],
|
||||
snap: hit,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Shift = Ortho: das Delta auf die dominante Achse (H/V) zwingen —
|
||||
// dieselbe Regel wie beim freien Kanten-Zug (onEdgeMove) und beim
|
||||
// Vertex-Griff (onGripMove). Bisher wirkte Shift beim Körper-Verschieben
|
||||
@@ -1688,7 +1784,8 @@ export function useGripEditing(opts: {
|
||||
// Ausstehender Zug: einfach verwerfen (das Projekt wurde nie verändert).
|
||||
if (pendingSheetHeightRef.current) {
|
||||
pendingSheetHeightRef.current = null;
|
||||
} else if (pendingGripRef.current || pendingWallGripRef.current || pendingAreaGripRef.current) {
|
||||
} else if (pendingGripRef.current || pendingWallGripRef.current || pendingAreaGripRef.current || pendingContourRef.current) {
|
||||
pendingContourRef.current = null;
|
||||
pendingGripRef.current = null;
|
||||
pendingWallGripRef.current = null;
|
||||
pendingAreaGripRef.current = null;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { useMemo } from "react";
|
||||
import type { Drawing2D, DrawingLevel, Project, Vec2 } from "../model/types";
|
||||
import type { Selection } from "./selection";
|
||||
import { addItems, cmdMutation, opsMutation, patchItems, removeItems } from "../core";
|
||||
import { addItems, cmdMutation, fieldOps, opsMutation, patchItem, patchItems, removeItems } from "../core";
|
||||
import type { ToolId } from "../tools/types";
|
||||
import type { DrawingStyle } from "../editors/matchProps";
|
||||
import { applyDrawingStyleOps, readDrawingStyle } from "../editors/matchProps";
|
||||
@@ -155,6 +155,10 @@ export function useSelectionCommands(opts: {
|
||||
const siteHide: ReturnType<typeof fieldOps> = [];
|
||||
if (selection.site.includes("sunStudy") && project.sunStudy?.show) siteHide.push(...fieldOps(project, "sunStudy", { ...project.sunStudy, show: false }));
|
||||
if (selection.site.includes("siteRules") && project.siteRules && project.siteRules.show !== false) siteHide.push(...fieldOps(project, "siteRules", { ...project.siteRules, show: false }));
|
||||
// Schlagschatten der Ansicht (`viewShadows`): schaltet `shadows` der aktiven Ansicht aus.
|
||||
if (selection.site.includes("viewShadows") && project.drawingLevels.find((l) => l.id === activeLevel.id)?.shadows) {
|
||||
siteHide.push(...patchItem(project, "drawingLevels", activeLevel.id, { shadows: false }));
|
||||
}
|
||||
setProject(
|
||||
opsMutation((p) => [
|
||||
...siteHide,
|
||||
|
||||
@@ -321,6 +321,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
selectedCeilingIds,
|
||||
selectedStairIds,
|
||||
selectedWallIds,
|
||||
selectedContextObjectIds,
|
||||
selectedDrawingIds,
|
||||
selectedDrawingId,
|
||||
getUnderlayIds,
|
||||
|
||||
@@ -430,6 +430,8 @@ export interface BodyTarget {
|
||||
ceilingId?: string;
|
||||
/** Nur im Schnitt/in der Ansicht (`sheetBodies`). */
|
||||
stairId?: string;
|
||||
/** [193] Gelände-/Umgebungs-Elemente (alle gewählten, das gegriffene liegt darunter). */
|
||||
contextIds?: string[];
|
||||
}
|
||||
|
||||
export interface GripHandlers {
|
||||
@@ -445,6 +447,7 @@ export interface GripHandlers {
|
||||
delta: Vec2,
|
||||
target?: BodyTarget,
|
||||
mods?: ToolMods,
|
||||
pxPerMeter?: number,
|
||||
): void;
|
||||
/**
|
||||
* Eine SEITE (Kante) ziehen: verschiebt beide Vertices der Kante senkrecht
|
||||
|
||||
@@ -34,6 +34,7 @@ export interface UsePlanPickingArgs {
|
||||
selectedCeilingIds: string[];
|
||||
selectedStairIds: string[];
|
||||
selectedWallIds: string[];
|
||||
selectedContextObjectIds: string[];
|
||||
selectedDrawingIds: string[];
|
||||
selectedDrawingId: string | null;
|
||||
getUnderlayIds: () => Map<string, UnderlayGroup> | null;
|
||||
@@ -58,6 +59,7 @@ export function usePlanPicking(inp: UsePlanPickingArgs) {
|
||||
selectedCeilingIds,
|
||||
selectedStairIds,
|
||||
selectedWallIds,
|
||||
selectedContextObjectIds,
|
||||
selectedDrawingIds,
|
||||
selectedDrawingId,
|
||||
getUnderlayIds,
|
||||
@@ -375,6 +377,11 @@ export function usePlanPicking(inp: UsePlanPickingArgs) {
|
||||
const id = pickDrawing(clientX, clientY);
|
||||
if (id && selDraws.has(id)) return { drawingId: id };
|
||||
}
|
||||
// [193] Gewähltes Gelände-/Umgebungs-Element unter dem Cursor: alle gewählten Kontext-Elemente ziehen mit.
|
||||
if (selectedContextObjectIds.length) {
|
||||
const sel = new Set(selectedContextObjectIds);
|
||||
if (contextIdsAt(clientX, clientY).some((id) => sel.has(id))) return { contextIds: selectedContextObjectIds };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
@@ -474,7 +474,7 @@ export function usePlanPointer(inp: UsePlanPointerArgs) {
|
||||
if (md && md.pointerId === p.pointerId) {
|
||||
const delta = { x: raw.x - md.last.x, y: raw.y - md.last.y };
|
||||
if (delta.x !== 0 || delta.y !== 0) {
|
||||
gripHandlers!.onMoveBody(delta, md.target, mods);
|
||||
gripHandlers!.onMoveBody(delta, md.target, mods, currentPxPerMeter());
|
||||
md.last = raw;
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user