[317] Anwählen in Schnitt/Ansicht: Stütze/Träger im Schnitt und Treppe in der Ansicht tragen ihre eigene Pick-Id, Rahmen wählt Stützen/Dächer/Fenster/Körper; e2e + Pick-Id-Test
This commit is contained in:
15 files changed
+399
-16
No files matched your search
@@ -0,0 +1,66 @@
|
||||
// [317] Pick-Ids in Schnitt und Ansicht: jede Id, die ein Plan-Primitiv trägt, muss zur Art passen — `ceilingId` eine
|
||||
// Decke, `stairId` eine Treppe, `columnId` eine Stütze oder ein Träger usw. Sonst wählt der Klick ein Element, das
|
||||
// es nicht gibt (Treppe in der Ansicht, Stütze/Träger im Schnitt liefen früher als `ceilingId`).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { computeSection, generateElevationPlan, generateSectionPlan } from "../core";
|
||||
import type { Project } from "../model/types";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { buildUmbauSampleProject } from "../model/sampleProjectUmbau";
|
||||
import { buildWettbewerbSampleProject } from "../model/sampleProjectWettbewerb";
|
||||
|
||||
type Lists = Record<string, { id: string }[] | undefined>;
|
||||
const LIST: Record<string, string[]> = {
|
||||
wallId: ["walls"],
|
||||
ceilingId: ["ceilings"],
|
||||
openingId: ["openings"],
|
||||
stairId: ["stairs"],
|
||||
roofId: ["roofs"],
|
||||
columnId: ["columns", "beams"],
|
||||
extrudedSolidId: ["extrudedSolids"],
|
||||
drawingId: ["drawings2d"],
|
||||
roomId: ["rooms"],
|
||||
};
|
||||
|
||||
function badIds(p: Project, prims: readonly unknown[]): string[] {
|
||||
const lists = p as unknown as Lists;
|
||||
const bad = new Set<string>();
|
||||
for (const pr of prims as Record<string, unknown>[]) {
|
||||
for (const [key, names] of Object.entries(LIST)) {
|
||||
const id = pr[key];
|
||||
if (typeof id === "string" && !names.some((n) => (lists[n] ?? []).some((e) => e.id === id))) bad.add(`${key}=${id}`);
|
||||
}
|
||||
}
|
||||
return [...bad];
|
||||
}
|
||||
|
||||
const PROJECTS: [string, () => Project][] = [
|
||||
["Muster", () => sampleProject],
|
||||
["komplex", buildComplexSampleProject],
|
||||
["Wettbewerb", buildWettbewerbSampleProject],
|
||||
["Umbau", buildUmbauSampleProject],
|
||||
];
|
||||
|
||||
describe("Pick-Ids in Schnitt und Ansicht gehören zur richtigen Art", () => {
|
||||
for (const [name, make] of PROJECTS) {
|
||||
it(name, async () => {
|
||||
const p = make();
|
||||
let stairIds = 0;
|
||||
let columnIds = 0;
|
||||
for (const l of p.drawingLevels.filter((x) => x.kind === "section" || x.kind === "elevation")) {
|
||||
const plan =
|
||||
l.kind === "section"
|
||||
? generateSectionPlan((await computeSection(p, l))!, false, { openings: true, scaleDenominator: 100 })
|
||||
: generateElevationPlan(p, l, { scaleDenominator: 100 })!;
|
||||
expect(badIds(p, plan.primitives), `${name} ${l.id}`).toEqual([]);
|
||||
for (const pr of plan.primitives as unknown as Record<string, unknown>[]) {
|
||||
if (pr.stairId) stairIds++;
|
||||
if (pr.columnId) columnIds++;
|
||||
}
|
||||
}
|
||||
// Die Beispiele zeigen Treppen bzw. Stützen/Träger tatsächlich (sonst prüft der Test nichts).
|
||||
if (name === "Muster" || name === "Umbau") expect(stairIds).toBeGreaterThan(0);
|
||||
if (name === "komplex") expect(columnIds).toBeGreaterThan(0);
|
||||
}, 120_000);
|
||||
}
|
||||
});
|
||||
@@ -191,7 +191,7 @@ export class PlanPickIndex {
|
||||
* Rahmen-Auswahl über Polygone mit Id im Feld `field` (CAD-Konvention): `crossing` = ein Band
|
||||
* berührt das Rechteck, sonst liegen alle Bänder ganz darin. Ids in Auftreten-Reihenfolge.
|
||||
*/
|
||||
marquee(field: "wallId" | "ceilingId" | "roomId" | "stairId" | "columnId" | "roofId" | "contextObjectId", rect: ModelRect, crossing: boolean): string[] {
|
||||
marquee(field: "wallId" | "ceilingId" | "roomId" | "stairId" | "columnId" | "roofId" | "openingId" | "extrudedSolidId" | "contextObjectId", rect: ModelRect, crossing: boolean): string[] {
|
||||
const r = Float64Array.of(rect.minX, rect.minY, rect.maxX, rect.maxY);
|
||||
return splitIds(core().pick_marquee_polygons(this.ix(), KIND[field], r, crossing));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { BUILTIN_PANEL_IDS } from "../panels/builtinPanels";
|
||||
import { hiddenFloorIds, itemDisplay } from "../panels/displayMode";
|
||||
import { renderJob } from "./renderJob";
|
||||
import { CyclesCancelled } from "../core";
|
||||
import type { Plan } from "../core";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -49,6 +50,10 @@ declare global {
|
||||
contours: { id: string; zs: number[] }[];
|
||||
excavations: { id: string; bottom: number }[];
|
||||
};
|
||||
/** [317] Klickpunkte der Bauteile des gezeigten Plans (Schnitt/Ansicht): je Pick-Id ein Modellpunkt, an dem nur dieses Bauteil liegt. */
|
||||
viewPickPoints: () => { key: string; id: string; x: number; y: number; covered: boolean; /** Gibt es das Element mit dieser Id im Projekt? */ known: boolean }[];
|
||||
/** [317] Pick-Polygone des gezeigten Plans an einem Modellpunkt (Index in `primitives`, Art, Id), unterste zuerst. */
|
||||
viewPolysAt: (x: number, y: number) => string[];
|
||||
/** [144] Auswahl setzen (wie ein Klick), z. B. `{ openings: ["D1"] }`. */
|
||||
select: (patch: Record<string, string[]>) => void;
|
||||
/** [144] Punkte einer Bemassung (Kette) — folgt sie der Öffnung? */
|
||||
@@ -115,7 +120,77 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
// [317] Der Plan, den die Plan-Ansicht gerade zeigt (`PlanView` meldet ihn über `__dossierPlanProbe`).
|
||||
let lastPlan: Plan | null = null;
|
||||
|
||||
const PICK_KEYS = ["wallId", "ceilingId", "openingId", "stairId", "roofId", "columnId", "extrudedSolidId", "drawingId", "roomId"] as const;
|
||||
|
||||
/** [317] Pro Pick-Id ein Punkt in der Fläche, den kein anderes Bauteil-Polygon (mit Id) überdeckt. */
|
||||
const KEY_LIST: Record<string, string> = { wallId: "walls", ceilingId: "ceilings", openingId: "openings", stairId: "stairs", roofId: "roofs", columnId: "columns", extrudedSolidId: "extrudedSolids", drawingId: "drawings2d", roomId: "rooms", treeId: "trees", railingId: "railings", contextObjectId: "context" };
|
||||
|
||||
function pickPoints(plan: Plan): { key: string; id: string; x: number; y: number; covered: boolean; known: boolean }[] {
|
||||
type Poly = { key: string; id: string; pts: { x: number; y: number }[] };
|
||||
const project = getState().project as unknown as Record<string, { id: string }[] | undefined>;
|
||||
const known = (key: string, id: string): boolean => {
|
||||
const list = project[KEY_LIST[key]] ?? [];
|
||||
return list.some((e) => e.id === id) || (key === "columnId" && (project.beams ?? []).some((e) => e.id === id)) || (key === "contextObjectId" && id.startsWith("@"));
|
||||
};
|
||||
const polys: Poly[] = [];
|
||||
for (const pr of plan.primitives) {
|
||||
if (pr.kind !== "polygon" || pr.pts.length < 3) continue;
|
||||
const o = pr as unknown as Record<string, string | undefined>;
|
||||
let key: string | null = null;
|
||||
let id: string | undefined;
|
||||
for (const k of PICK_KEYS) if (o[k]) { key = k; id = o[k]; break; }
|
||||
const c = o.contextObjectId;
|
||||
if (!key && c) { key = c.startsWith("@tree:") ? "treeId" : c.startsWith("@railing:") ? "railingId" : c.startsWith("@") ? null : "contextObjectId"; id = c.replace(/^@(tree|railing):/, ""); }
|
||||
if (key && id) polys.push({ key, id, pts: pr.pts });
|
||||
}
|
||||
const inside = (q: { x: number; y: number }, pts: { x: number; y: number }[]) => {
|
||||
let r = false;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
|
||||
if (pts[i].y > q.y !== pts[j].y > q.y && q.x < ((pts[j].x - pts[i].x) * (q.y - pts[i].y)) / (pts[j].y - pts[i].y) + pts[i].x) r = !r;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
const out = new Map<string, { key: string; id: string; x: number; y: number; covered: boolean; known: boolean }>();
|
||||
for (const [pi, pg] of polys.entries()) {
|
||||
const k = `${pg.key}:${pg.id}`;
|
||||
if (out.get(k) && !out.get(k)!.covered) continue;
|
||||
const xs = pg.pts.map((q) => q.x), ys = pg.pts.map((q) => q.y);
|
||||
const [x0, x1, y0, y1] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)];
|
||||
let found: { x: number; y: number } | null = null;
|
||||
let any: { x: number; y: number } | null = null;
|
||||
let foundD = -1;
|
||||
let anyD = -1;
|
||||
// Rand-Abstand: der Punkt mit dem grössten Abstand zur Umrisslinie (Bildschirm-Rundung soll ihn nicht kippen).
|
||||
const edgeDist = (q: { x: number; y: number }) => {
|
||||
let d = Infinity;
|
||||
for (let i = 0, j = pg.pts.length - 1; i < pg.pts.length; j = i++) {
|
||||
const a = pg.pts[j], b = pg.pts[i];
|
||||
const dx = b.x - a.x, dy = b.y - a.y;
|
||||
const l2 = dx * dx + dy * dy;
|
||||
const t = l2 === 0 ? 0 : Math.max(0, Math.min(1, ((q.x - a.x) * dx + (q.y - a.y) * dy) / l2));
|
||||
d = Math.min(d, Math.hypot(q.x - (a.x + t * dx), q.y - (a.y + t * dy)));
|
||||
}
|
||||
return d;
|
||||
};
|
||||
const N = 13;
|
||||
for (let i = 1; i < N; i++) for (let j = 1; j < N; j++) {
|
||||
const q = { x: x0 + ((x1 - x0) * i) / N, y: y0 + ((y1 - y0) * j) / N };
|
||||
if (!inside(q, pg.pts)) continue;
|
||||
const d = edgeDist(q);
|
||||
if (d > anyD) { any = q; anyD = d; }
|
||||
if (d > foundD && !polys.some((o2, oi) => oi > pi && (o2.key !== pg.key || o2.id !== pg.id) && o2.key !== "contextObjectId" && inside(q, o2.pts))) { found = q; foundD = d; }
|
||||
}
|
||||
if (found) out.set(k, { key: pg.key, id: pg.id, ...found, covered: false, known: known(pg.key, pg.id) });
|
||||
else if (any && !out.has(k)) out.set(k, { key: pg.key, id: pg.id, ...any, covered: true, known: known(pg.key, pg.id) });
|
||||
}
|
||||
return [...out.values()];
|
||||
}
|
||||
|
||||
export function installTestHooks(): void {
|
||||
(window as unknown as { __dossierPlanProbe?: (p: Plan) => void }).__dossierPlanProbe = (p) => { lastPlan = p; };
|
||||
window.__dossierTest = {
|
||||
corePanic: () => {
|
||||
try {
|
||||
@@ -158,6 +233,24 @@ export function installTestHooks(): void {
|
||||
selectionAction: (id) => runSelectionAction(id),
|
||||
walls: () => getState().project.walls.map((w) => ({ id: w.id, start: { ...w.start }, end: { ...w.end } })),
|
||||
select: (patch) => getState().setSelection(patch),
|
||||
viewPickPoints: () => (lastPlan ? pickPoints(lastPlan) : []),
|
||||
viewPolysAt: (x, y) => {
|
||||
if (!lastPlan) return [];
|
||||
const q = { x, y };
|
||||
const inside = (pts: { x: number; y: number }[]) => {
|
||||
let r = false;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) if (pts[i].y > q.y !== pts[j].y > q.y && q.x < ((pts[j].x - pts[i].x) * (q.y - pts[i].y)) / (pts[j].y - pts[i].y) + pts[i].x) r = !r;
|
||||
return r;
|
||||
};
|
||||
const out: string[] = [];
|
||||
lastPlan.primitives.forEach((pr, i) => {
|
||||
if (pr.kind !== "polygon" || !inside(pr.pts)) return;
|
||||
const o = pr as unknown as Record<string, string | undefined>;
|
||||
const key = [...PICK_KEYS, "contextObjectId"].find((k) => o[k]);
|
||||
out.push(`${i}:${key ?? "-"}:${key ? o[key] : ""}`);
|
||||
});
|
||||
return out;
|
||||
},
|
||||
dimPts: (id) => {
|
||||
const g = getState().project.drawings2d.find((d) => d.id === id)?.geom;
|
||||
return g?.shape === "dimension" ? g.pts.map((p) => ({ x: p.x, y: p.y })) : [];
|
||||
|
||||
@@ -331,9 +331,9 @@ export function useMouseSelectionHandlers(opts: {
|
||||
ceilingIds: sel.ceilingIds ?? [],
|
||||
roomIds: sel.roomIds ?? [],
|
||||
stairIds: sel.stairIds ?? [],
|
||||
columnIds: [],
|
||||
roofIds: [],
|
||||
openingIds: [],
|
||||
columnIds: sel.columnIds ?? [],
|
||||
roofIds: sel.roofIds ?? [],
|
||||
openingIds: sel.openingIds ?? [],
|
||||
treeIds: sel.treeIds ?? [],
|
||||
cameraIds: sel.cameraIds ?? [],
|
||||
railingIds: sel.railingIds ?? [],
|
||||
@@ -349,9 +349,9 @@ export function useMouseSelectionHandlers(opts: {
|
||||
ceilingIds: raw.ceilingIds.filter((id) => isInsideActiveGroup(project, "ceilingIds", id, groupPath)),
|
||||
roomIds: raw.roomIds.filter((id) => isInsideActiveGroup(project, "roomIds", id, groupPath)),
|
||||
stairIds: raw.stairIds.filter((id) => isInsideActiveGroup(project, "stairIds", id, groupPath)),
|
||||
columnIds: [],
|
||||
roofIds: [],
|
||||
openingIds: [],
|
||||
columnIds: raw.columnIds.filter((id) => isInsideActiveGroup(project, "columnIds", id, groupPath)),
|
||||
roofIds: raw.roofIds.filter((id) => isInsideActiveGroup(project, "roofIds", id, groupPath)),
|
||||
openingIds: raw.openingIds.filter((id) => isInsideActiveGroup(project, "openingIds", id, groupPath)),
|
||||
treeIds: raw.treeIds.filter((id) => isInsideActiveGroup(project, "treeIds", id, groupPath)),
|
||||
cameraIds: raw.cameraIds.filter((id) => isInsideActiveGroup(project, "cameraIds", id, groupPath)),
|
||||
railingIds: raw.railingIds.filter((id) => isInsideActiveGroup(project, "railingIds", id, groupPath)),
|
||||
@@ -359,12 +359,14 @@ export function useMouseSelectionHandlers(opts: {
|
||||
// Gruppen-Erweiterung: jedes getroffene Element, das zu einer sichtbaren
|
||||
// Gruppe gehört, zieht deren ganze (transitive) Mitgliedschaft nach.
|
||||
const { expanded, groupIds } = expandToGroups(project, filtered, groupPath);
|
||||
// Öffnungen/Extrusionen/Stützen/Dächer/Kontext-Objekte sind (noch) nicht
|
||||
// Teil des Marquee (Nutzer-Report betraf nur Decken/Räume/Treppen; Stütze/
|
||||
// Dach liessen sich mit derselben `marqueeHitByField`-Mechanik ergänzen,
|
||||
// falls gewünscht) → beim Aufziehen abwählen.
|
||||
// Stützen/Dächer/Öffnungen/Körper nur im Schnitt und in der Ansicht ([317], `sheetBodies`); im Grundriss
|
||||
// (Dach deckt die ganze Traufe, Fenster hängen an ihrer Wand) bleiben sie ausserhalb des Rahmens.
|
||||
setSelection({
|
||||
...clearKinds(),
|
||||
columns: expanded.columnIds,
|
||||
roofs: expanded.roofIds,
|
||||
openings: expanded.openingIds,
|
||||
solids: sel.solidIds ?? [],
|
||||
walls: expanded.wallIds,
|
||||
drawings: expanded.drawingIds,
|
||||
ceilings: expanded.ceilingIds,
|
||||
|
||||
@@ -278,6 +278,10 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
startViewRef, // [204] Papier-Massstab folgt der Startansicht
|
||||
resetKey: viewKey, // Papier-Massstab folgt dem Einpassen
|
||||
});
|
||||
// [317] Test-Naht: der gezeigte Plan für die e2e-Prüfung der Anwahl (nur mit `?dossierTest`, sonst fehlt die Funktion).
|
||||
useEffect(() => {
|
||||
(window as unknown as { __dossierPlanProbe?: (p: typeof plan) => void }).__dossierPlanProbe?.(plan);
|
||||
}, [plan]);
|
||||
// [165] Steuerhandle, Zieh-Zustände, Koordinaten-Umrechnung und Griff-Treffer.
|
||||
const {
|
||||
drag,
|
||||
@@ -515,6 +519,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
toolMods,
|
||||
marquee,
|
||||
onMarquee,
|
||||
sheetBodies,
|
||||
marqueeHitAll,
|
||||
setMarqueeRect,
|
||||
drag,
|
||||
|
||||
@@ -191,6 +191,11 @@ export interface MarqueeSelection {
|
||||
treeIds?: string[];
|
||||
/** [279] Getroffene Geländer (Pick-Flächen um die Achse, gleiche Konvention). */
|
||||
railingIds?: string[];
|
||||
/** [317] Nur im Schnitt/in der Ansicht (`sheetBodies`): Stützen/Träger, Dächer, Öffnungen, Körper (gleiche Konvention). */
|
||||
columnIds?: string[];
|
||||
roofIds?: string[];
|
||||
openingIds?: string[];
|
||||
solidIds?: string[];
|
||||
/** [213] Getroffene Kameras (Pick-Flächen von Gehäuse und Sichtgrenzen, gleiche Konvention). */
|
||||
cameraIds?: string[];
|
||||
/**
|
||||
|
||||
@@ -71,6 +71,8 @@ export interface UsePlanPickCycleArgs {
|
||||
toolMods: (e: React.PointerEvent | React.MouseEvent) => { shift: boolean; ctrl: boolean; alt: boolean; };
|
||||
marquee: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: Vec2; moved: boolean; } | null>;
|
||||
onMarquee: ((selection: MarqueeSelection) => void) | undefined;
|
||||
/** [317] Schnitt/Ansicht: Rahmen wählt auch Stützen, Dächer, Öffnungen und Körper. */
|
||||
sheetBodies?: boolean;
|
||||
marqueeHitAll: (rect: ModelRect, crossing: boolean) => string[];
|
||||
setMarqueeRect: React.Dispatch<React.SetStateAction<{ x: number; y: number; w: number; h: number; crossing: boolean; } | null>>;
|
||||
drag: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: ViewBox; } | null>;
|
||||
@@ -127,6 +129,7 @@ export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
|
||||
toolMods,
|
||||
marquee,
|
||||
onMarquee,
|
||||
sheetBodies,
|
||||
marqueeHitAll,
|
||||
setMarqueeRect,
|
||||
drag,
|
||||
@@ -572,6 +575,15 @@ export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
|
||||
.map((id) => id.slice(CAMERA_PICK.length)),
|
||||
),
|
||||
],
|
||||
// [317] Schnitt/Ansicht: auch Stützen/Träger, Dächer, Fenster/Türen und Körper per Rahmen.
|
||||
...(sheetBodies
|
||||
? {
|
||||
columnIds: getPick().marquee("columnId", rect, crossing),
|
||||
roofIds: getPick().marquee("roofId", rect, crossing),
|
||||
openingIds: getPick().marquee("openingId", rect, crossing),
|
||||
solidIds: getPick().marquee("extrudedSolidId", rect, crossing),
|
||||
}
|
||||
: {}),
|
||||
crossing,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user