[K4] Projekt-Verschiebung und Auswahl-Export im Kern: translateProject/translateOps, filterProjectToSelection (geo_translate.rs, selection_filter.rs)
Wurzel-Abfragen translatePatch/translateOps/selectionFilterPatch; TS-Rechnung in geoRebase.ts und exportScope.ts gelöscht.
This commit is contained in:
8 files changed
+397
-174
No files matched your search
+11
-149
@@ -12,48 +12,14 @@
|
||||
// (Column.rotation, Text-/Bild-Rotation, Tür-Schwenk) müssten bei einer Drehung
|
||||
// mitgeführt werden — eine Rotation ist ein eigener, grösserer Schritt.
|
||||
//
|
||||
// Die Rechnung liegt im Rust-Kern ([K4] S3, `src-tauri/core/src/geo_translate.rs`, Wurzel-Abfragen
|
||||
// `translatePatch`/`translateOps`); hier bleiben die Fassaden und der Ursprung aus dem Geo-Anker.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { replaceItem, setField } from "../core/opsBuild";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import type {
|
||||
ContextObject,
|
||||
Contour,
|
||||
Project,
|
||||
Vec2,
|
||||
} from "./types";
|
||||
|
||||
const shift = (p: Vec2, dx: number, dy: number): Vec2 => ({ x: p.x + dx, y: p.y + dy });
|
||||
const shiftAll = (pts: Vec2[], dx: number, dy: number): Vec2[] => pts.map((p) => shift(p, dx, dy));
|
||||
|
||||
/** Kontur (Höhenlinie): Punkte + optionale Kreis-/Bogen-Mitte verschieben. */
|
||||
function shiftContour(c: Contour, dx: number, dy: number): Contour {
|
||||
return {
|
||||
...c,
|
||||
pts: shiftAll(c.pts, dx, dy),
|
||||
curve: c.curve ? { ...c.curve, cx: c.curve.cx + dx, cy: c.curve.cy + dy } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontext-Objekt (importiertes Mesh/Terrain/Konturen-Satz) verschieben.
|
||||
* `positions` ist ein flaches [x,y,z=Höhe, …]-Array — nur x/y (Grundriss)
|
||||
* verschieben, die Höhe (z) bleibt unverändert.
|
||||
*/
|
||||
function shiftContextObject(obj: ContextObject, dx: number, dy: number): ContextObject {
|
||||
if (obj.type === "contourSet") {
|
||||
return { ...obj, contours: obj.contours.map((c) => shiftContour(c, dx, dy)) };
|
||||
}
|
||||
if (obj.type === "image") {
|
||||
return { ...obj, min: shift(obj.min, dx, dy), max: shift(obj.max, dx, dy) };
|
||||
}
|
||||
const positions = obj.positions.slice();
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) {
|
||||
positions[i] += dx;
|
||||
positions[i + 1] += dy;
|
||||
}
|
||||
return { ...obj, positions };
|
||||
}
|
||||
import { documentFor } from "../core/document";
|
||||
import type { Project } from "./types";
|
||||
|
||||
/**
|
||||
* Verschiebt SÄMTLICHE Modell-Koordinaten eines Projekts um den festen Vektor
|
||||
@@ -62,127 +28,23 @@ function shiftContextObject(obj: ContextObject, dx: number, dy: number): Context
|
||||
* (Import/Terrain/Konturen), Schnitt-/Ansichtslinien sowie den Geo-Anker
|
||||
* (`geoAnchor.model`, damit der LV95-Bezug exakt erhalten bleibt). Richtungs-
|
||||
* Vektoren (z. B. `Stair.dir`) und Winkel-Felder bleiben unangetastet — eine
|
||||
* reine Translation ändert keine Orientierung.
|
||||
* reine Translation ändert keine Orientierung. Unveränderte Teile behalten ihre Identität;
|
||||
* (0,0) liefert das Projekt selbst.
|
||||
*/
|
||||
export function translateProject(project: Project, dx: number, dy: number): Project {
|
||||
if (dx === 0 && dy === 0) return project;
|
||||
return {
|
||||
...project,
|
||||
walls: project.walls.map((w) => ({
|
||||
...w,
|
||||
start: shift(w.start, dx, dy),
|
||||
end: shift(w.end, dx, dy),
|
||||
})),
|
||||
ceilings: project.ceilings?.map((c) => ({
|
||||
...c,
|
||||
outline: shiftAll(c.outline, dx, dy),
|
||||
openings: c.openings?.map((h) => shiftAll(h, dx, dy)),
|
||||
})),
|
||||
roofs: project.roofs?.map((r) => ({
|
||||
...r,
|
||||
outline: shiftAll(r.outline, dx, dy),
|
||||
...(r.holes ? { holes: r.holes.map((h) => shiftAll(h, dx, dy)) } : {}),
|
||||
})),
|
||||
stairs: project.stairs?.map((s) => ({
|
||||
...s,
|
||||
start: shift(s.start, dx, dy),
|
||||
center: s.center ? shift(s.center, dx, dy) : undefined,
|
||||
})),
|
||||
rooms: project.rooms?.map((r) => ({
|
||||
...r,
|
||||
boundary: shiftAll(r.boundary, dx, dy),
|
||||
stampAnchor: r.stampAnchor ? shift(r.stampAnchor, dx, dy) : undefined,
|
||||
})),
|
||||
columns: project.columns?.map((c) => ({ ...c, position: shift(c.position, dx, dy) })),
|
||||
extrudedSolids: project.extrudedSolids?.map((s) => ({
|
||||
...s,
|
||||
points: shiftAll(s.points, dx, dy),
|
||||
circle: s.circle ? { ...s.circle, center: shift(s.circle.center, dx, dy) } : undefined,
|
||||
})),
|
||||
drawings2d: project.drawings2d.map((d) => {
|
||||
const g = d.geom;
|
||||
switch (g.shape) {
|
||||
case "line":
|
||||
case "xline":
|
||||
case "ray":
|
||||
return { ...d, geom: { ...g, a: shift(g.a, dx, dy), b: shift(g.b, dx, dy) } };
|
||||
case "polyline":
|
||||
return { ...d, geom: { ...g, pts: shiftAll(g.pts, dx, dy) } };
|
||||
case "rect":
|
||||
return { ...d, geom: { ...g, min: shift(g.min, dx, dy), max: shift(g.max, dx, dy) } };
|
||||
case "circle":
|
||||
return { ...d, geom: { ...g, center: shift(g.center, dx, dy) } };
|
||||
case "arc":
|
||||
return { ...d, geom: { ...g, center: shift(g.center, dx, dy) } };
|
||||
case "ellipse":
|
||||
return { ...d, geom: { ...g, center: shift(g.center, dx, dy) } };
|
||||
case "bezier":
|
||||
return { ...d, geom: { ...g, pts: shiftAll(g.pts, dx, dy) } };
|
||||
case "spline":
|
||||
return { ...d, geom: { ...g, pts: shiftAll(g.pts, dx, dy) } };
|
||||
case "dimension":
|
||||
return { ...d, geom: { ...g, pts: shiftAll(g.pts, dx, dy) } };
|
||||
case "kote":
|
||||
return { ...d, geom: { ...g, at: shift(g.at, dx, dy) } };
|
||||
case "detailref":
|
||||
return { ...d, geom: { ...g, at: shift(g.at, dx, dy) } };
|
||||
case "scalebar":
|
||||
return { ...d, geom: { ...g, at: shift(g.at, dx, dy) } };
|
||||
case "pointmarker":
|
||||
return { ...d, geom: { ...g, at: shift(g.at, dx, dy) } };
|
||||
case "text":
|
||||
return {
|
||||
...d,
|
||||
geom: {
|
||||
...g,
|
||||
at: shift(g.at, dx, dy),
|
||||
...(g.leaderTarget ? { leaderTarget: shift(g.leaderTarget, dx, dy) } : {}),
|
||||
...(g.leaderBendPoints ? { leaderBendPoints: shiftAll(g.leaderBendPoints, dx, dy) } : {}),
|
||||
...(g.pathPts ? { pathPts: shiftAll(g.pathPts, dx, dy) } : {}),
|
||||
},
|
||||
};
|
||||
case "block":
|
||||
return { ...d, geom: { ...g, at: shift(g.at, dx, dy) } };
|
||||
case "image":
|
||||
return { ...d, geom: { ...g, min: shift(g.min, dx, dy), max: shift(g.max, dx, dy) } };
|
||||
}
|
||||
}),
|
||||
context: project.context?.map((o) => shiftContextObject(o, dx, dy)),
|
||||
drawingLevels: project.drawingLevels.map((lvl) =>
|
||||
lvl.linePoints
|
||||
? { ...lvl, linePoints: [shift(lvl.linePoints[0], dx, dy), shift(lvl.linePoints[1], dx, dy)] }
|
||||
: lvl,
|
||||
),
|
||||
geoAnchor: project.geoAnchor
|
||||
? { ...project.geoAnchor, model: shift(project.geoAnchor.model, dx, dy) }
|
||||
: undefined,
|
||||
};
|
||||
const patch = documentFor(project).queryRoot<Partial<Project>>("translatePatch", JSON.stringify([dx, dy]));
|
||||
return { ...project, ...patch };
|
||||
}
|
||||
|
||||
/** Projekt-Listen, die {@link translateProject} verschiebt (jedes Element hat eine `id`). */
|
||||
const TRANSLATED_LISTS = [
|
||||
"walls", "ceilings", "roofs", "stairs", "rooms", "columns", "extrudedSolids", "drawings2d", "context", "drawingLevels",
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Ops für {@link translateProject}: je geändertem Element ein `replace` (Reihenfolge und Identität
|
||||
* unveränderter Elemente bleiben), `geoAnchor` als Feld. Das Ergebnis von `applyOps` ist gleich
|
||||
* `translateProject(project, dx, dy)`.
|
||||
*/
|
||||
export function translateOps(project: Project, dx: number, dy: number): CoreOp[] {
|
||||
const next = translateProject(project, dx, dy);
|
||||
if (next === project) return [];
|
||||
const ops: CoreOp[] = [];
|
||||
for (const key of TRANSLATED_LISTS) {
|
||||
const before = project[key] as readonly { id: string }[] | undefined;
|
||||
const after = next[key] as readonly { id: string }[] | undefined;
|
||||
if (!before || !after) continue;
|
||||
after.forEach((e, i) => {
|
||||
if (e !== before[i]) ops.push(replaceItem(key, e as never));
|
||||
});
|
||||
}
|
||||
if (next.geoAnchor !== project.geoAnchor) ops.push(setField("geoAnchor", next.geoAnchor));
|
||||
return ops;
|
||||
if (dx === 0 && dy === 0) return [];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("translateOps", JSON.stringify([dx, dy]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user