From 4b2e02b37a1b917f00d44e006faed31e36dd75a6 Mon Sep 17 00:00:00 2001 From: karim Date: Tue, 20 Oct 2026 19:43:57 +0200 Subject: [PATCH] =?UTF-8?q?Attribute:=20F=C3=BCllungs-Transparenz=20(nur?= =?UTF-8?q?=20Fl=C3=A4che),=20Schraffur-Auswahl=20ohne=20doppeltes=20'Ohne?= =?UTF-8?q?',=20Platzierung=20nur=20bei=20sichtbarer=20Schraffur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/de.ts | 2 + src/i18n/en.ts | 2 + src/model/types.ts | 6 +++ src/panels/AttributesPanel.tsx | 38 ++++++++++++-- src/panels/host.ts | 5 ++ src/plan/generatePlan.fillOpacity.test.ts | 61 +++++++++++++++++++++++ src/plan/generatePlan/drawing2d.ts | 10 ++++ src/state/usePanelHostBase.ts | 11 ++++ 8 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 src/plan/generatePlan.fillOpacity.test.ts diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 134dc411..ff6c19e5 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -353,6 +353,8 @@ export const de = { "attr.color": "Farbe", "attr.weight": "Strichstärke (mm)", "attr.opacity": "Deckkraft", + "attr.fillTransparency": "Füllungs-Transparenz", + "attr.hatch.none": "Keine Schraffur", "attr.saturation": "Sättigung", "attr.brightness": "Helligkeit", "attr.contrast": "Kontrast", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 47761e14..d6308134 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -351,6 +351,8 @@ export const en: Record = { "attr.color": "Color", "attr.weight": "Line weight (mm)", "attr.opacity": "Opacity", + "attr.fillTransparency": "Fill transparency", + "attr.hatch.none": "No hatch", "attr.saturation": "Saturation", "attr.brightness": "Brightness", "attr.contrast": "Contrast", diff --git a/src/model/types.ts b/src/model/types.ts index 9e19584c..c4569e9f 100644 --- a/src/model/types.ts +++ b/src/model/types.ts @@ -2068,6 +2068,12 @@ export interface Drawing2D { * Flächen). Der DXF-Export trägt sie nicht mit (bewusst, s. PENDENZEN.md). */ opacity?: number; + /** + * Transparenz NUR der Füllung/Schraffurfläche 0..1 (Default 1 = deckend) — + * zusätzlich zu `opacity` (das Strich UND Füllung trifft). Der Umriss bleibt + * dabei deckend (z. B. durchscheinende Fläche mit kräftiger Kontur). + */ + fillOpacity?: number; /** * Linienenden an OFFENEN Formen (Linie, offene Polylinie, Bogen, Spline, * Bezier) sowie an der Hinweislinie eines Textes. `start`/`end` beziehen diff --git a/src/panels/AttributesPanel.tsx b/src/panels/AttributesPanel.tsx index 1cda9973..a282ab9d 100644 --- a/src/panels/AttributesPanel.tsx +++ b/src/panels/AttributesPanel.tsx @@ -237,6 +237,9 @@ export function AttributesPanel() { if (next === "custom") host.onSetSelectionWeight(sel.weightMm); else host.onSetSelectionStrokeWeightSource(next); }; + // Die Ressource „Ohne" (Muster none) zeigt wie „Keine Schraffur" nichts an. + const hatchPatternIsNone = + project.hatches.find((h) => h.id === sel.effectiveHatchId)?.pattern === "none"; const onHatchSourceChange = (next: UiSource) => { if (next === "custom") { host.onSetSelectionFill(sel.effectiveHatchId ?? project.hatches[0]?.id ?? null); @@ -659,22 +662,49 @@ export function AttributesPanel() { hatchUi, onHatchSourceChange, host.onSetSelectionFill(v || null)} options={[ - { value: "", label: t("attr.none") }, - ...project.hatches.map((h) => ({ value: h.id, label: h.name })), + { value: "", label: t("attr.hatch.none") }, + // Die Ressource „Ohne" (Muster none) wäre dasselbe wie „Keine Schraffur". + ...project.hatches + .filter((h) => h.pattern !== "none") + .map((h) => ({ value: h.id, label: h.name })), ]} />, )} + {/* Transparenz NUR der Füllung/Schraffurfläche (Umriss bleibt deckend); + in Prozent: 0 % = deckend, 100 % = unsichtbar. */} + {isDrawing && ( + <> + {t("attr.fillTransparency")} + + { + const pct = Number(e.target.value); + if (Number.isFinite(pct)) host.onSetSelectionFillOpacity(1 - Math.max(0, Math.min(100, pct)) / 100); + }} + /> + % + + + )} + {/* Schraffur-Platzierung an DIESEM Objekt (direkt unter der Schraffur-Auswahl): Winkel ersetzt den der Ressource, Massstab multipliziert sie, der Anker verschiebt das Musterraster (leer = Modellursprung, damit benachbarte Flächen dieselbe Phase teilen). Nur sinnvoll, wenn das Element überhaupt eine Schraffur zeigt. */} - {isDrawing && sel.effectiveHatchId && ( + {isDrawing && sel.effectiveHatchId && !hatchPatternIsNone && ( <> {t("attr.hatch.angle")} diff --git a/src/panels/host.ts b/src/panels/host.ts index 2ae47b49..3d5f6f64 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -219,6 +219,11 @@ export interface PanelHostValue { * `type:"image"`), sonst No-op. */ onSetSelectionOpacity: (opacity: number) => void; + /** + * Setzt die Transparenz NUR der Füllung/Schraffur (`Drawing2D.fillOpacity`, + * 0..1, 1 = deckend); der Umriss bleibt deckend. Wirkt nur auf 2D-Elemente. + */ + onSetSelectionFillOpacity: (opacity: number) => void; /** * Setzt eine oder mehrere Bildkorrektur-Werte (Sättigung/Helligkeit/ * Kontrast/Graustufen) — wirkt NUR auf Kontext-Objekt-Bilder (`ContextImage`, diff --git a/src/plan/generatePlan.fillOpacity.test.ts b/src/plan/generatePlan.fillOpacity.test.ts new file mode 100644 index 00000000..ec9384cf --- /dev/null +++ b/src/plan/generatePlan.fillOpacity.test.ts @@ -0,0 +1,61 @@ +// Füllungs-Transparenz (Drawing2D.fillOpacity): trifft NUR die Flächen-Primitive, +// Umriss-Linien bleiben deckend; zusammen mit `opacity` multiplizieren sich beide. + +import { describe, it, expect } from "vitest"; +import { generatePlan } from "./generatePlan"; +import type { Drawing2D, Project } from "../model/types"; + +const closed = (over: Partial): Drawing2D => + ({ + id: "D", + type: "drawing2d", + levelId: "eg", + categoryCode: "60", + fillColor: "#336699", + geom: { shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }, { x: 0, y: 2 }], closed: true }, + ...over, + }) as unknown as Drawing2D; + +const project = (d: Drawing2D): Project => + ({ + id: "t", + name: "T", + lineStyles: [], + hatches: [{ id: "none", name: "Ohne", pattern: "none", scale: 1, angle: 0, color: "#111" }], + components: [], + wallTypes: [], + drawingLevels: [ + { id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 }, + ], + layers: [{ code: "60", name: "Zeichnung", color: "#0a0a0a", lw: 0.25, visible: true, locked: false }], + walls: [], doors: [], openings: [], ceilings: [], stairs: [], rooms: [], + drawings2d: [d], + context: [], + }) as unknown as Project; + +const prims = (d: Drawing2D) => generatePlan(project(d), "eg", new Set(["60"])).primitives; + +describe("Füllungs-Transparenz", () => { + it("macht nur das Polygon transparent, die Linien bleiben deckend", () => { + const p = prims(closed({ fillOpacity: 0.4 })); + const polys = p.filter((x) => x.kind === "polygon"); + const lines = p.filter((x) => x.kind === "line"); + expect(polys.length).toBeGreaterThan(0); + expect(lines.length).toBeGreaterThan(0); + expect(polys.every((x) => (x as { opacity?: number }).opacity === 0.4)).toBe(true); + expect(lines.every((x) => (x as { opacity?: number }).opacity === undefined)).toBe(true); + }); + + it("ohne fillOpacity bleibt alles unverändert", () => { + const p = prims(closed({})); + expect(p.filter((x) => x.kind === "polygon").every((x) => (x as { opacity?: number }).opacity === undefined)).toBe(true); + }); + + it("multipliziert sich mit der Objekt-Deckkraft", () => { + const p = prims(closed({ opacity: 0.5, fillOpacity: 0.5 })); + const polys = p.filter((x) => x.kind === "polygon"); + expect(polys.every((x) => Math.abs(((x as { opacity?: number }).opacity ?? 1) - 0.25) < 1e-9)).toBe(true); + const lines = p.filter((x) => x.kind === "line"); + expect(lines.every((x) => (x as { opacity?: number }).opacity === 0.5)).toBe(true); + }); +}); diff --git a/src/plan/generatePlan/drawing2d.ts b/src/plan/generatePlan/drawing2d.ts index c08a19af..e6838ebc 100644 --- a/src/plan/generatePlan/drawing2d.ts +++ b/src/plan/generatePlan/drawing2d.ts @@ -208,6 +208,16 @@ export function addDrawing2D( : { ...p, opacity: (p.opacity ?? 1) * clamped }; } } + // Nur die FLÄCHE transparenter machen (Umriss/Linien bleiben deckend): die + // Füllungs-Primitive sind die Polygone. + const fo = d.fillOpacity; + if (fo !== undefined && fo < 1) { + const clampedFo = Math.max(0, fo); + for (let i = start; i < out.length; i++) { + const p = out[i]; + if (p.kind === "polygon") out[i] = { ...p, opacity: (p.opacity ?? 1) * clampedFo }; + } + } if (cacheable) { drawingPrimCache.set(d, { lineStyles: project.lineStyles, diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index b752d1eb..72ff3413 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -470,6 +470,17 @@ export function usePanelHostBase(opts: { if (selection?.kind === "drawing2d") setElementFillColor(selection.id, color); }, + onSetSelectionFillOpacity: (opacity) => { + if (selection?.kind === "drawing2d") + setProject((p) => ({ + ...p, + drawings2d: p.drawings2d.map((d) => { + if (d.id !== selection.id) return d; + const { fillOpacity: _old, ...rest } = d; + return opacity >= 1 ? rest : { ...rest, fillOpacity: Math.max(0, opacity) }; + }), + })); + }, onSetSelectionOpacity: (opacity) => { // Deckkraft eines 2D-Elements. Bei BILDERN bleibt es die Deckkraft der // Bildgeometrie (bestehendes Verhalten, eigenes Feld); bei allen