diff --git a/src/i18n/de.ts b/src/i18n/de.ts index ff6c19e..afe3995 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -354,6 +354,10 @@ export const de = { "attr.weight": "Strichstärke (mm)", "attr.opacity": "Deckkraft", "attr.fillTransparency": "Füllungs-Transparenz", + "attr.fillMode": "Füllart", + "attr.fillMode.none": "Keine Füllung", + "attr.fillMode.solid": "Vollfläche", + "attr.fillMode.hatch": "Schraffur", "attr.hatch.none": "Keine Schraffur", "attr.saturation": "Sättigung", "attr.brightness": "Helligkeit", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index d630813..4a0b7c5 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -352,6 +352,10 @@ export const en: Record = { "attr.weight": "Line weight (mm)", "attr.opacity": "Opacity", "attr.fillTransparency": "Fill transparency", + "attr.fillMode": "Fill type", + "attr.fillMode.none": "No fill", + "attr.fillMode.solid": "Solid", + "attr.fillMode.hatch": "Hatch", "attr.hatch.none": "No hatch", "attr.saturation": "Saturation", "attr.brightness": "Brightness", diff --git a/src/panels/AttributesPanel.tsx b/src/panels/AttributesPanel.tsx index a282ab9..aa273a3 100644 --- a/src/panels/AttributesPanel.tsx +++ b/src/panels/AttributesPanel.tsx @@ -612,6 +612,33 @@ export function AttributesPanel() { <>
{t("attr.fill")}
+ {/* Füllart: Keine / Vollfläche / Schraffur — die drei klaren Zustände einer + Fläche, statt sie nur indirekt über Hintergrundfarbe + Schraffur-Liste + zu erraten. Erkennung wie der Renderer (`addDrawing2D`: background → + Ebenenfarbe bei Quelle „Ebene" → fillColor). */} + {isDrawing && sel.closed === true && (() => { + const hatchActive = !!sel.effectiveHatchId && !hatchPatternIsNone; + const hasFill = !!(sel.background || sel.fillColor || sel.backgroundSource === "layer"); + const mode = hatchActive ? "hatch" : hasFill ? "solid" : "none"; + return ( + <> + {t("attr.fillMode")} + + host.onSetSelectionFillMode(v as "none" | "solid" | "hatch")} + options={[ + { value: "none", label: t("attr.fillMode.none") }, + { value: "solid", label: t("attr.fillMode.solid") }, + { value: "hatch", label: t("attr.fillMode.hatch") }, + ]} + /> + + + ); + })()} + {/* Swatch — IMMER sichtbar (zeigt den effektiven Wert, welche Ebene/Bauteil/Override auch immer gerade liefert), aber nur bei „eigener Wert" editierbar (`disabled`). Trägt wie die Strich- diff --git a/src/panels/host.ts b/src/panels/host.ts index 3d5f6f6..583b0b9 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -224,6 +224,12 @@ export interface PanelHostValue { * 0..1, 1 = deckend); der Umriss bleibt deckend. Wirkt nur auf 2D-Elemente. */ onSetSelectionFillOpacity: (opacity: number) => void; + /** + * Füllart eines geschlossenen 2D-Elements: "none" = keine Füllung (weder Farbe + * noch Schraffur), "solid" = Vollfläche in der Füllfarbe (ohne Schraffur), + * "hatch" = Schraffur (Füllfarbe bleibt als Grund erhalten). + */ + onSetSelectionFillMode: (mode: "none" | "solid" | "hatch") => void; /** * Setzt eine oder mehrere Bildkorrektur-Werte (Sättigung/Helligkeit/ * Kontrast/Graustufen) — wirkt NUR auf Kontext-Objekt-Bilder (`ContextImage`, diff --git a/src/state/fillMode.test.ts b/src/state/fillMode.test.ts new file mode 100644 index 0000000..1d54055 --- /dev/null +++ b/src/state/fillMode.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; +import type { Drawing2D, HatchStyle } from "../model/types"; +import { DEFAULT_SOLID_FILL, applyFillMode } from "./fillMode"; + +const hatches = [ + { id: "none", name: "Ohne", pattern: "none" }, + { id: "diag", name: "Diagonal", pattern: "diagonal" }, +] as unknown as HatchStyle[]; +const base = { id: "d", type: "drawing2d", levelId: "L", categoryCode: "60" } as unknown as Drawing2D; + +describe("applyFillMode", () => { + it("none: entfernt Farbe und Schraffur, Quellen auf eigenen Wert", () => { + const d = applyFillMode({ ...base, background: "#fff", fillColor: "#eee", hatchId: "diag" } as Drawing2D, hatches, "none"); + expect(d.background).toBeUndefined(); + expect(d.fillColor).toBeUndefined(); + expect(d.hatchId).toBeUndefined(); + expect(d.backgroundSource).toBe("object"); + }); + it("solid: behält vorhandene Füllfarbe, sonst Vorgabe; ohne Schraffur", () => { + expect(applyFillMode({ ...base, fillColor: "#123456" } as Drawing2D, hatches, "solid").background).toBe("#123456"); + expect(applyFillMode(base, hatches, "solid").background).toBe(DEFAULT_SOLID_FILL); + expect(applyFillMode({ ...base, hatchId: "diag" } as Drawing2D, hatches, "solid").hatchId).toBeUndefined(); + }); + it("hatch: wählt die erste echte Schraffur (nie 'Ohne'), behält die Füllfarbe", () => { + const d = applyFillMode({ ...base, background: "#abcdef" } as Drawing2D, hatches, "hatch"); + expect(d.hatchId).toBe("diag"); + expect(d.background).toBe("#abcdef"); + expect(applyFillMode({ ...base, hatchId: "none" } as Drawing2D, hatches, "hatch").hatchId).toBe("diag"); + }); +}); diff --git a/src/state/fillMode.ts b/src/state/fillMode.ts new file mode 100644 index 0000000..5843895 --- /dev/null +++ b/src/state/fillMode.ts @@ -0,0 +1,32 @@ +// Füllart eines geschlossenen 2D-Elements: Keine / Vollfläche / Schraffur. +// Reine Umrechnung auf die vorhandenen Felder (`background`, `fillColor`, `hatchId` +// samt Quellen) — der Renderer (`addDrawing2D`) braucht kein neues Feld. + +import type { Drawing2D, HatchStyle } from "../model/types"; + +export type FillMode = "none" | "solid" | "hatch"; + +/** Vorgabe-Füllfarbe, wenn "Vollfläche" gewählt wird und noch keine gesetzt ist. */ +export const DEFAULT_SOLID_FILL = "#d9dde2"; + +export function applyFillMode(d: Drawing2D, hatches: readonly HatchStyle[], mode: FillMode): Drawing2D { + const next = { ...d } as Drawing2D & Record; + if (mode === "none") { + delete next.background; + delete next.fillColor; + delete next.hatchId; + next.backgroundSource = "object"; + next.hatchSource = "object"; + } else if (mode === "solid") { + next.background = d.background ?? d.fillColor ?? DEFAULT_SOLID_FILL; + next.backgroundSource = "object"; + delete next.hatchId; + next.hatchSource = "object"; + } else { + const current = hatches.find((h) => h.id === d.hatchId); + const keep = current && current.pattern !== "none" ? current.id : hatches.find((h) => h.pattern !== "none")?.id; + if (keep) next.hatchId = keep; + next.hatchSource = "object"; + } + return next as Drawing2D; +} diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index 72ff341..4dac133 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -7,6 +7,7 @@ // // Extrahiert aus App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). +import { applyFillMode } from "./fillMode"; import { useMemo, type RefObject } from "react"; import type { DrawingLevel, Layout, Project } from "../model/types"; import { resolvePenColor } from "../model/penSets"; @@ -470,6 +471,13 @@ export function usePanelHostBase(opts: { if (selection?.kind === "drawing2d") setElementFillColor(selection.id, color); }, + onSetSelectionFillMode: (mode) => { + if (selection?.kind !== "drawing2d") return; + setProject((p) => ({ + ...p, + drawings2d: p.drawings2d.map((d) => (d.id === selection.id ? applyFillMode(d, p.hatches, mode) : d)), + })); + }, onSetSelectionFillOpacity: (opacity) => { if (selection?.kind === "drawing2d") setProject((p) => ({