diff --git a/src/plan/generatePlan.ts b/src/plan/generatePlan.ts index dab66fa2..db5bb436 100644 --- a/src/plan/generatePlan.ts +++ b/src/plan/generatePlan.ts @@ -248,18 +248,24 @@ export function materializeUnderlay(plan: Plan): Plan { const below: Primitive[] = []; const above: Primitive[] = []; const belowGreyed: Array<[number, number]> = []; + const aboveGreyed: Array<[number, number]> = []; for (const g of groups) { const target = g.above ? above : below; const from = target.length; for (const pr of g.build(g.drawings)) target.push(pr); - if (!g.above && g.tint && target.length > from) belowGreyed.push([from, target.length]); + if (g.tint && target.length > from) (g.above ? aboveGreyed : belowGreyed).push([from, target.length]); } const primitives: Primitive[] = []; for (const pr of below) primitives.push(pr); for (const pr of plan.primitives) primitives.push(pr); for (const pr of above) primitives.push(pr); const shifted = (plan.greyedRanges ?? []).map(([a, b]): [number, number] => [a + below.length, b + below.length]); - const ranges = [...belowGreyed, ...shifted]; + const aboveShift = below.length + plan.primitives.length; + const ranges = [ + ...belowGreyed, + ...shifted, + ...aboveGreyed.map(([a, b]): [number, number] => [a + aboveShift, b + aboveShift]), + ]; return { ...plan, primitives, diff --git a/src/state/groupActions.test.ts b/src/state/groupActions.test.ts index ad2e549d..14e9fe4b 100644 --- a/src/state/groupActions.test.ts +++ b/src/state/groupActions.test.ts @@ -9,6 +9,7 @@ import { describe, it, expect } from "vitest"; import { addNewElementsToActiveGroup, applyGroupDimming, + applyGroupDimmingToPlan, containingGroupId, expandToGroups, groupSelection, @@ -18,7 +19,8 @@ import { ungroup, } from "./groupActions"; import type { Primitive } from "../plan/generatePlan/shared"; -import type { Group, Project } from "../model/types"; +import { materializeUnderlay, type Plan } from "../plan/generatePlan"; +import type { Drawing2D, Group, Project } from "../model/types"; const EMPTY_MEM = { wallIds: [] as string[], @@ -186,6 +188,35 @@ describe("applyGroupDimming", () => { }); }); +describe("applyGroupDimmingToPlan", () => { + const g1: Group = { id: "g1", wallIds: [], drawingIds: ["din"], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] }; + const p = project([g1]); + const din = { id: "din" } as unknown as Drawing2D; + const dout = { id: "dout" } as unknown as Drawing2D; + const mkLine = (d: Drawing2D) => ({ kind: "line", drawingId: d.id }) as unknown as Primitive; + const underlay = [{ drawings: [din, dout], catGreyed: false, tint: false, above: true, ctx: [], build: (ds: Drawing2D[]) => ds.map(mkLine) }]; + const plan = { primitives: [], underlay } as unknown as Plan; + + it("ohne Isolation unverändert", () => { + expect(applyGroupDimmingToPlan(plan, p, [])).toBe(plan); + }); + + it("Unterlage bleibt kompakt: Zeichnungen ausserhalb in gedimmte Untergruppe", () => { + const out = applyGroupDimmingToPlan(plan, p, ["g1"]); + expect(out.underlay).toHaveLength(2); + expect(out.underlay![0].drawings).toEqual([din]); + expect(out.underlay![0].tint).toBe(false); + expect(out.underlay![1].drawings).toEqual([dout]); + expect(out.underlay![1].tint).toBe(true); + }); + + it("materializeUnderlay markiert gedimmte obere Gruppen als greyedRange", () => { + const m = materializeUnderlay(applyGroupDimmingToPlan(plan, p, ["g1"])); + expect(m.primitives).toHaveLength(2); + expect(m.greyedRanges).toEqual([[1, 2]]); + }); +}); + describe("addNewElementsToActiveGroup", () => { const g1: Group = { id: "g1", wallIds: ["w1"], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] }; const line = (id: string) => diff --git a/src/state/groupActions.ts b/src/state/groupActions.ts index e59aaebb..a2dafb7d 100644 --- a/src/state/groupActions.ts +++ b/src/state/groupActions.ts @@ -5,7 +5,8 @@ // // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). -import type { Group, Project } from "../model/types"; +import type { Drawing2D, Group, Project } from "../model/types"; +import type { Plan, UnderlayGroup } from "../plan/generatePlan"; import { uniqueId } from "../tools/types"; import type { Primitive } from "../plan/generatePlan/shared"; @@ -227,6 +228,29 @@ export function applyGroupDimming( }); } +/** + * Wie `applyGroupDimming`, aber auf einem ganzen Plan: die kompakte Linien- + * Unterlage (`plan.underlay`, bei Kataster-Importen Millionen Linien) bleibt + * kompakt — ihre Zeichnungen ausserhalb der aktiven Gruppe wandern in eine + * zusätzlich gedimmte Untergruppe (`tint`), statt dass alle Linien zu einzelnen + * Primitiven materialisiert und geklont werden. + */ +export function applyGroupDimmingToPlan(plan: Plan, project: Project, groupPath: string[]): Plan { + if (groupPath.length === 0) return plan; + const primitives = applyGroupDimming(plan.primitives, project, groupPath); + if (!plan.underlay || plan.underlay.length === 0) return { ...plan, primitives }; + const inside = new Set(transitiveMembership(project, groupPath[groupPath.length - 1]).drawingIds); + const underlay: UnderlayGroup[] = []; + for (const g of plan.underlay) { + const inn: Drawing2D[] = []; + const out: Drawing2D[] = []; + for (const d of g.drawings) (inside.has(d.id) ? inn : out).push(d); + if (inn.length) underlay.push(out.length ? { ...g, drawings: inn } : g); + if (out.length) underlay.push({ ...g, drawings: out, tint: true }); + } + return { ...plan, primitives, underlay }; +} + /** IDs, die in `after` neu hinzugekommen sind (in `before` noch nicht vorhanden). */ function newIds(before: { id: string }[], after: { id: string }[]): string[] { const beforeIds = new Set(before.map((x) => x.id)); diff --git a/src/views/viewportContent.tsx b/src/views/viewportContent.tsx index a18fcac1..35560eae 100644 --- a/src/views/viewportContent.tsx +++ b/src/views/viewportContent.tsx @@ -21,7 +21,7 @@ import type { } from "../model/types"; import { categoryNameForPick } from "../plan/pickLabels"; import type { PickKind } from "../plan/PlanView"; -import { generatePlan, generateSectionPlan, generateVisibleLevelsPlan, materializeUnderlay } from "../plan/generatePlan"; +import { generatePlan, generateSectionPlan, generateVisibleLevelsPlan } from "../plan/generatePlan"; import type { CategoryDisplayResolver, Primitive } from "../plan/generatePlan"; import type { RichTextDoc } from "../text/richText"; import { computeSection } from "../plan/toSection"; @@ -29,7 +29,7 @@ import type { SectionOutput } from "../plan/toSection"; import { generateElevationPlan } from "../plan/toElevation"; import { pushNativeScene, pushNativeWalls } from "../plan/nativeSync"; import { selectionHighlightLines } from "../plan/toWalls3d"; -import { applyGroupDimming } from "../state/groupActions"; +import { applyGroupDimmingToPlan } from "../state/groupActions"; import { PlanView } from "../plan/PlanView"; import type { GripHandlers, @@ -835,14 +835,9 @@ function LevelPlanView({ ? p : { ...p, primitives: [...p.primitives, ...overlayPrimitives] }; // Gruppen-Isolation ("Gruppe betreten"): alles ausserhalb der aktiven - // Gruppe gedimmt, s. state/groupActions.ts::applyGroupDimming. - // applyGroupDimming arbeitet auf Primitiven → Unterlage vorher materialisieren. - return groupPath.length === 0 - ? withOverlay - : (() => { - const full = materializeUnderlay(withOverlay); - return { ...full, primitives: applyGroupDimming(full.primitives, project, groupPath) }; - })(); + // Gruppe gedimmt, s. state/groupActions.ts::applyGroupDimmingToPlan (die + // kompakte Linien-Unterlage bleibt dabei kompakt). + return applyGroupDimmingToPlan(withOverlay, project, groupPath); }, [ project, level.id, @@ -1145,7 +1140,7 @@ function SectionPlanView({ const plan = useMemo( () => withOverlay && groupPath.length > 0 - ? { ...withOverlay, primitives: applyGroupDimming(withOverlay.primitives, project, groupPath) } + ? applyGroupDimmingToPlan(withOverlay, project, groupPath) : withOverlay, [withOverlay, project, groupPath], );