Attribute: Fuellart Keine/Vollflaeche/Schraffur fuer geschlossene 2D-Elemente

This commit is contained in:
karim committed 2026-10-20 21:11:38 +02:00
1 parent 4b2e02b37a
commit 6fbc8d4ff8
7 files changed
+111

No files matched your search

+4
View File
@@ -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",
+4
View File
@@ -352,6 +352,10 @@ export const en: Record<TranslationKey, string> = {
"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",
+27
View File
@@ -612,6 +612,33 @@ export function AttributesPanel() {
<>
<div className="attr-section-label">{t("attr.fill")}</div>
{/* 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 (
<>
<span className="attr-key">{t("attr.fillMode")}</span>
<span className="attr-val">
<Dropdown
value={mode}
disabled={!fillEditable}
onChange={(v) => 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") },
]}
/>
</span>
</>
);
})()}
{/* 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-
+6
View File
@@ -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`,
+30
View File
@@ -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");
});
});
+32
View File
@@ -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<string, unknown>;
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;
}
+8
View File
@@ -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) => ({