[K4] Stiftsätze im Kern: Standardpalette, Neu-Backen der Stift-Farben, Stift löschen mit Verweisen (pens.rs)
Wurzel-Abfragen (run_root, doc_query_root, ProjectDocument.queryRoot) liefern Ops; model/penSets.ts ist Fassade, TS-Rechnung (Palette, rebakePenOps, clearCategoryPenRefs in projectSlice) gelöscht.
This commit is contained in:
14 files changed
+583
-256
No files matched your search
@@ -15,6 +15,9 @@ export type LoadFileResult =
|
||||
| { ok: true; project: Project; warnings: string[]; migratedFrom: number | null }
|
||||
| { ok: false; error: string };
|
||||
|
||||
/** Wurzel-Abfragen des Kerns (`queries.rs::run_root`). */
|
||||
export type RootQueryName = "penRebakeOps" | "penDeleteOps" | "penSeedOps";
|
||||
|
||||
/** Abfragen des Kerns (`queries.rs`). */
|
||||
export type QueryName =
|
||||
| "kennzahlen"
|
||||
@@ -124,6 +127,17 @@ export class ProjectDocument {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abfrage auf dem rohen Projekt-JSON des Kerns (`queries.rs::run_root`): rechnet verlustfrei auf dem
|
||||
* Baum (unbekannte Felder, Schlüsselreihenfolge) und liefert meist Ops. `text`: Argument (Text/JSON).
|
||||
*/
|
||||
queryRoot<T>(name: RootQueryName, text = ""): T {
|
||||
if (!this.handle) throw new Error(`Kern-Abfrage „${name}": Dokument nicht offen`);
|
||||
const out = core().doc_query_root(this.handle, name, text);
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
return JSON.parse(out) as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abfrage mit binärer Antwort (`queries.rs::run_bin`, z. B. `planDomains` als Plan-Puffer v2,
|
||||
* s. `plan/planBuf.ts`). Fehler kommen als Fehlerpuffer (`decodePlanBuf` wirft die Meldung).
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
resolvePenColor,
|
||||
resolvePenWeight,
|
||||
rebakePenOps,
|
||||
generateStandardPenPalette,
|
||||
freeColorPalette,
|
||||
deletePenOps,
|
||||
seedStandardPenSetOps,
|
||||
PEN_FALLBACK_COLOR,
|
||||
PEN_FALLBACK_WEIGHT,
|
||||
@@ -146,7 +147,7 @@ describe("rebakePenColors — Ebenen (Farbe UND Strichstärke, inkl. verschachte
|
||||
expect(out.layers[0].lw).toBe(0.7);
|
||||
});
|
||||
|
||||
it("bäckt eine verschachtelte Kategorie (children) und lässt Geschwister ohne Stift unverändert", () => {
|
||||
it("bäckt eine verschachtelte Kategorie (children) und lässt Geschwister ohne Stift inhaltlich unverändert", () => {
|
||||
const child = cat({ code: "21", colorPenId: "2" });
|
||||
const untouchedChild = cat({ code: "22", color: "#untouched" });
|
||||
const parent = cat({ code: "20", children: [child, untouchedChild] });
|
||||
@@ -157,7 +158,7 @@ describe("rebakePenColors — Ebenen (Farbe UND Strichstärke, inkl. verschachte
|
||||
});
|
||||
const out = rebakePenColors(p);
|
||||
expect(out.layers[0].children?.[0].color).toBe("#00ff00");
|
||||
expect(out.layers[0].children?.[1]).toBe(untouchedChild); // referenzgleich, unangetastet
|
||||
expect(out.layers[0].children?.[1]).toEqual(untouchedChild);
|
||||
});
|
||||
|
||||
it("lässt eine Kategorie OHNE Stift-Verweis referenzgleich", () => {
|
||||
@@ -298,8 +299,10 @@ describe("rebakePenColors — Elemente OHNE Strichstärke-Feld (Raum), Robusthei
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateStandardPenPalette", () => {
|
||||
const { pens, styles } = generateStandardPenPalette();
|
||||
describe("Standardpalette (Kern)", () => {
|
||||
const seeded = seedStandardPenSet(baseProject());
|
||||
const pens = seeded.pens!;
|
||||
const styles = seeded.penSets![0].pens;
|
||||
|
||||
it("liefert genau 255 Stifte mit IDs '1'..'255', je Farbe+Strichstärke", () => {
|
||||
expect(pens.length).toBe(255);
|
||||
@@ -353,3 +356,32 @@ describe("seedStandardPenSet", () => {
|
||||
expect(out.components[0].color).toBe("#00ff00");
|
||||
});
|
||||
});
|
||||
|
||||
describe("freeColorPalette", () => {
|
||||
it("liefert 8 Graustufen und 8 × 5 Farbtöne als #rrggbb", () => {
|
||||
const pal = freeColorPalette();
|
||||
expect(pal).toHaveLength(48);
|
||||
expect(pal[0]).toBe("#000000");
|
||||
expect(pal[7]).toBe("#ffffff");
|
||||
for (const c of pal) expect(c).toMatch(/^#[0-9a-f]{6}$/);
|
||||
expect(freeColorPalette()).toBe(pal);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deletePenOps", () => {
|
||||
it("entfernt Stift, Satz-Einträge und alle Verweise (Bauteile, verschachtelte Kategorien)", () => {
|
||||
const p = baseProject({
|
||||
pens: [{ id: "1", name: "a" }, { id: "2", name: "b" }],
|
||||
penSets: [{ id: "s", name: "S", pens: { "1": ps("#111111"), "2": ps("#222222") } }],
|
||||
components: [comp({ colorPenId: "1", foregroundPenId: "2" })],
|
||||
layers: [{ code: "20", name: "x", color: "#000", visible: true, lw: 1, children: [{ code: "21", name: "y", color: "#000", visible: true, lw: 1, colorPenId: "1" }] } as LayerCategory],
|
||||
});
|
||||
const out = applyOps(p, deletePenOps(p, "1"));
|
||||
expect(out.pens!.map((x) => x.id)).toEqual(["2"]);
|
||||
expect(Object.keys(out.penSets![0].pens)).toEqual(["2"]);
|
||||
expect(out.components[0].colorPenId).toBeUndefined();
|
||||
expect(out.components[0].foregroundPenId).toBe("2");
|
||||
expect(out.layers[0].children![0].colorPenId).toBeUndefined();
|
||||
expect(deletePenOps(out, "1")).toEqual([]);
|
||||
});
|
||||
});
|
||||
+45
-216
@@ -1,139 +1,50 @@
|
||||
// Stiftsatz-Auflösung (ArchiCAD-Stiftsatz-Muster) — reine Funktionen, keine
|
||||
// Modell-Mutation. Der Trick, der jeden bestehenden Farb-/Strichstärke-Leser
|
||||
// (2D-Plan, beide 3D-Renderer, DXF-Export, Vorschau-Swatches) UNVERÄNDERT
|
||||
// lässt: `Component.color`/`.foreground`/`.background`, `LayerCategory.color`/
|
||||
// `.lw` bzw. die Element-Felder (`color`/`strokeWeight`/`weightMm`) bleiben
|
||||
// IMMER die eine gültige, aufgelöste Farbe/Strichstärke. Ein Stift-Verweis
|
||||
// (`xxxPenId`) schreibt diese Felder nur bei Gelegenheit (Stiftsatz-Wechsel,
|
||||
// Stift-Änderung, neue Zuweisung) per `rebakePenColors` aus dem aktiven
|
||||
// Stiftsatz NEU — kein Leser muss je einen Stift auflösen.
|
||||
// Stiftsatz-Auflösung (ArchiCAD-Stiftsatz-Muster) im Rust-Kern ([K4] S3, `src-tauri/core/src/pens.rs`).
|
||||
// Der Trick, der jeden bestehenden Farb-/Strichstärke-Leser (2D-Plan, beide 3D-Renderer, DXF-Export,
|
||||
// Vorschau-Swatches) UNVERÄNDERT lässt: `Component.color`/`.foreground`/`.background`,
|
||||
// `LayerCategory.color`/`.lw` bzw. die Element-Felder (`color`/`strokeWeight`/`weightMm`) bleiben
|
||||
// IMMER die eine gültige, aufgelöste Farbe/Strichstärke. Ein Stift-Verweis (`xxxPenId`) schreibt diese
|
||||
// Felder nur bei Gelegenheit (Stiftsatz-Wechsel, Stift-Änderung, neue Zuweisung) per `rebakePenOps` aus
|
||||
// dem aktiven Stiftsatz NEU — kein Leser muss je einen Stift auflösen.
|
||||
//
|
||||
// Ein Stift (`PenStyle`) trägt Farbe UND Strichstärke zusammen (wie ein
|
||||
// echter ArchiCAD-/AutoCAD-Stift) — beide wandern gemeinsam, wenn ein
|
||||
// Element/eine Ebene auf „Stift" statt „Frei" gestellt wird.
|
||||
// Ein Stift (`PenStyle`) trägt Farbe UND Strichstärke zusammen (wie ein echter ArchiCAD-/AutoCAD-Stift).
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
// Im Kern: Standardpalette (255 Stifte, rein prozedural per HSL, keine externe Bibliothek, Stifte 1–9 und
|
||||
// 250–255 wie `ACI_PALETTE` in `export/exportDxf.ts`), Freie-Farbe-Palette, Neu-Backen und das Entfernen
|
||||
// von Stift-Verweisen. Hier bleiben nur die Lese-Auflösung einzelner Stifte (O(1), je Swatch im Render) und
|
||||
// dünne Fassaden, die die Ops des Kerns liefern (`documentFor(project)`: das Kern-Dokument folgt dem Projekt).
|
||||
//
|
||||
// Bewusst NICHT abgedeckt: Layout-Annotationen (`Layout.annotations[]`) und `Tür`/`ExtrudedSolid`/Kontext-
|
||||
// Objekte — kein `colorPenId`-Feld dort (Scope-Entscheid, s. PENDENZEN.md).
|
||||
|
||||
import type { ColorPen, Component, LayerCategory, PenSet, PenStyle, Project } from "./types";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { PenStyle, Project } from "./types";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { addItems, fieldOps, patchItems, setFieldIfChanged } from "../core/opsBuild";
|
||||
import { documentFor } from "../core/document";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
/** Farbe eines Stifts, der im aktiven Stiftsatz (noch) keinen Eintrag hat. */
|
||||
export const PEN_FALLBACK_COLOR = "#9aa0a6";
|
||||
/** Strichstärke (mm) eines Stifts, der im aktiven Stiftsatz (noch) keinen Eintrag hat. */
|
||||
export const PEN_FALLBACK_WEIGHT = 0.18;
|
||||
|
||||
/** HSL (h in Grad 0..360, s/l in 0..1) → "#rrggbb". Reine Konvertierung, keine Bibliothek nötig. */
|
||||
export function hslToHex(h: number, s: number, l: number): string {
|
||||
const c = (1 - Math.abs(2 * l - 1)) * s;
|
||||
const hp = (((h % 360) + 360) % 360) / 60;
|
||||
const x = c * (1 - Math.abs((hp % 2) - 1));
|
||||
const [r1, g1, b1] =
|
||||
hp < 1 ? [c, x, 0] : hp < 2 ? [x, c, 0] : hp < 3 ? [0, c, x] : hp < 4 ? [0, x, c] : hp < 5 ? [x, 0, c] : [c, 0, x];
|
||||
const m = l - c / 2;
|
||||
const toHex = (v: number) => Math.round((v + m) * 255).toString(16).padStart(2, "0");
|
||||
return `#${toHex(r1)}${toHex(g1)}${toHex(b1)}`;
|
||||
let freePalette: string[] | null = null;
|
||||
|
||||
/**
|
||||
* Feste Freie-Farbe-Palette für den Palette-Popover (`ui/PenColorField.tsx`): 8 Graustufen (Schwarz→Weiss)
|
||||
* + 8 Farbtöne × 5 Helligkeitsstufen = 48 Swatches. Aus dem Kern (erst nach `initCore()` lesbar, daher
|
||||
* eine Funktion, kein Modul-Wert); jeder Aufruf liefert dieselbe Liste.
|
||||
*/
|
||||
export function freeColorPalette(): string[] {
|
||||
if (!freePalette) freePalette = JSON.parse(core().pens_call("freePalette", "")) as string[];
|
||||
return freePalette;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feste Freie-Farbe-Palette für den Palette-Popover (`ui/PenColorField.tsx`):
|
||||
* 8 Graustufen (Schwarz→Weiss) + 8 Farbtöne × 5 Helligkeitsstufen = 48
|
||||
* Swatches. Rein prozedural (HSL), dieselbe Begründung wie
|
||||
* `generateStandardPenPalette` — kein externes Farbschema.
|
||||
*/
|
||||
export const FREE_COLOR_PALETTE: string[] = (() => {
|
||||
const out: string[] = [];
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const v = Math.round((i / 7) * 255);
|
||||
out.push(`#${v.toString(16).padStart(2, "0").repeat(3)}`);
|
||||
}
|
||||
for (let hue = 0; hue < 8; hue++) {
|
||||
for (let level = 0; level < 5; level++) {
|
||||
out.push(hslToHex(hue * 45, 0.75, 0.75 - level * 0.14));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
|
||||
/**
|
||||
* Generiert 255 Stifte + einen passenden Stiftsatz nach klassischer CAD-
|
||||
* Nummerierungs-Konvention (AutoCAD Color Index / ArchiCAD-Stiftsätze): Stifte
|
||||
* 1–9 die Grundfarben (Rot/Gelb/Grün/Cyan/Blau/Magenta/Schwarz/zwei Grautöne —
|
||||
* dieselben Werte wie die bestehende `ACI_PALETTE` in `export/exportDxf.ts`,
|
||||
* damit beide Stellen konsistent bleiben), 10–249 24 Farbtöne × 10 Helligkeits-/
|
||||
* Sättigungsstufen (prozedural per HSL erzeugt), 250–255 ein Graustufen-Keil
|
||||
* (identische Werte wie `ACI_PALETTE`s 250–255). **Keine externe Bibliothek
|
||||
* oder ein konkretes lizenziertes Farbschema** — reine Mathematik (HSL-Kreis),
|
||||
* daher lizenzfrei; strukturell an die altbekannte 255-Stift-Konvention aus
|
||||
* AutoCAD/ArchiCAD angelehnt, nicht Pixel-für-Pixel identisch mit deren
|
||||
* (proprietärer) Originaltabelle. Strichstärke einheitlich `PEN_FALLBACK_WEIGHT`
|
||||
* (0.18 mm) — im Stiftsatz-Tab pro Stift frei änderbar.
|
||||
*/
|
||||
export function generateStandardPenPalette(): { pens: ColorPen[]; styles: Record<string, PenStyle> } {
|
||||
const pens: ColorPen[] = [];
|
||||
const styles: Record<string, PenStyle> = {};
|
||||
const add = (id: number, name: string, color: string) => {
|
||||
pens.push({ id: String(id), name });
|
||||
styles[String(id)] = { color, weight: PEN_FALLBACK_WEIGHT };
|
||||
};
|
||||
|
||||
// 1–9: Grundfarben (wie ACI_PALETTE in exportDxf.ts).
|
||||
add(1, "Rot", "#ff0000");
|
||||
add(2, "Gelb", "#ffff00");
|
||||
add(3, "Grün", "#00ff00");
|
||||
add(4, "Cyan", "#00ffff");
|
||||
add(5, "Blau", "#0000ff");
|
||||
add(6, "Magenta", "#ff00ff");
|
||||
add(7, "Schwarz", "#000000");
|
||||
add(8, "Dunkelgrau", "#414141");
|
||||
add(9, "Grau", "#808080");
|
||||
|
||||
// 10–249: 24 Farbtöne (15°-Schritte) × 10 Stufen (5 gesättigt hell→dunkel,
|
||||
// 5 entsättigt hell→dunkel) — 240 Stifte.
|
||||
let id = 10;
|
||||
for (let hue = 0; hue < 24; hue++) {
|
||||
const h = hue * 15;
|
||||
for (let step = 0; step < 10; step++) {
|
||||
const saturated = step < 5;
|
||||
const level = step % 5; // 0..4
|
||||
const l = 0.75 - level * 0.14; // 0.75 → 0.19
|
||||
const s = saturated ? 0.85 : 0.4;
|
||||
add(id, `Stift ${id}`, hslToHex(h, s, l));
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
// 250–255: Graustufen-Keil (wie ACI_PALETTE).
|
||||
const greys: [number, string][] = [
|
||||
[250, "#333333"],
|
||||
[251, "#5b5b5b"],
|
||||
[252, "#848484"],
|
||||
[253, "#adadad"],
|
||||
[254, "#d6d6d6"],
|
||||
[255, "#ffffff"],
|
||||
];
|
||||
for (const [gid, color] of greys) add(gid, `Grau ${gid}`, color);
|
||||
|
||||
return { pens, styles };
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt `Project.pens`/`penSets` auf die generierte 255er-Standardpalette
|
||||
* (s. {@link generateStandardPenPalette}) — ERSETZT bestehende `pens`/den neu
|
||||
* angelegten Satz vollständig (kein Merge), gedacht für den Erststart, bevor
|
||||
* eigene Stifte/Sätze existieren. Der neue Satz wird aktiv, wenn noch KEIN
|
||||
* Stiftsatz aktiv war (dieselbe Konvention wie `addPenSet`).
|
||||
* Setzt `Project.pens`/`penSets` auf die generierte 255er-Standardpalette — ERSETZT bestehende `pens`
|
||||
* vollständig (kein Merge), gedacht für den Erststart. Der neue Satz wird aktiv, wenn noch KEIN Stiftsatz
|
||||
* aktiv war.
|
||||
*/
|
||||
export function seedStandardPenSetOps(project: Project): CoreOp[] {
|
||||
const { pens, styles } = generateStandardPenPalette();
|
||||
const penSet: PenSet = { id: `penset-${Date.now()}`, name: "Standard (CAD-Palette)", pens: styles };
|
||||
const stateOps = [
|
||||
...fieldOps(project, "pens", pens),
|
||||
...addItems("penSets", [penSet]),
|
||||
...setFieldIfChanged(project, "activePenSetId", project.activePenSetId ?? penSet.id),
|
||||
];
|
||||
return [...stateOps, ...rebakePenOps(applyOps(project, stateOps))];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("penSeedOps", JSON.stringify({ id: `penset-${Date.now()}`, name: "Standard (CAD-Palette)" }));
|
||||
}
|
||||
|
||||
/** Der aktuell aktive Stiftsatz, oder `undefined` (kein Stiftsatz angelegt/aktiviert). */
|
||||
@@ -156,102 +67,20 @@ export function resolvePenWeight(project: Project, penId: string): number {
|
||||
return resolvePenStyle(project, penId)?.weight ?? PEN_FALLBACK_WEIGHT;
|
||||
}
|
||||
|
||||
/** Bäckt die Stift-Farbe(n) EINES Bauteils neu (reine Funktion, unverändert wenn kein Stift gesetzt). */
|
||||
function bakeComponent(project: Project, c: Component): Component {
|
||||
if (!c.colorPenId && !c.foregroundPenId && !c.backgroundPenId) return c;
|
||||
return {
|
||||
...c,
|
||||
...(c.colorPenId ? { color: resolvePenColor(project, c.colorPenId) } : {}),
|
||||
...(c.foregroundPenId ? { foreground: resolvePenColor(project, c.foregroundPenId) } : {}),
|
||||
...(c.backgroundPenId ? { background: resolvePenColor(project, c.backgroundPenId) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Bäckt Farbe UND Strichstärke (`.lw`) EINER Ebenen-Kategorie neu (rekursiv über `children`). */
|
||||
function bakeCategory(project: Project, cat: LayerCategory): LayerCategory {
|
||||
const next: LayerCategory = cat.colorPenId
|
||||
? { ...cat, color: resolvePenColor(project, cat.colorPenId), lw: resolvePenWeight(project, cat.colorPenId) }
|
||||
: cat;
|
||||
if (!cat.children) return next;
|
||||
const children = cat.children.map((c) => bakeCategory(project, c));
|
||||
return children === cat.children ? next : { ...next, children };
|
||||
}
|
||||
|
||||
/**
|
||||
* Bäckt die eigene `color`-Stift-Kopplung EINES Modell-Elements neu (nur
|
||||
* Farbe — für Elementarten ohne eigenes Strichstärke-Override-Feld: Dach,
|
||||
* Öffnung, Treppe, Raum). Unverändert (referenzgleich), wenn kein Stift
|
||||
* gesetzt ist.
|
||||
*/
|
||||
function bakeElementColor<T extends { colorPenId?: string; color?: string }>(
|
||||
project: Project,
|
||||
x: T,
|
||||
): T {
|
||||
return x.colorPenId ? { ...x, color: resolvePenColor(project, x.colorPenId) } : x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie {@link bakeElementColor}, zusätzlich (a) die Strichstärke unter
|
||||
* `weightKey` (Wand/Decke/Stütze: `strokeWeight`; Drawing2D: `weightMm`) —
|
||||
* nur über `colorPenId` gekoppelt (ein Stift trägt Farbe UND Strichstärke
|
||||
* zusammen; Vordergrund/Hintergrund sind reine Musterfarben ohne
|
||||
* Strichstärke-Aspekt) — und (b) die Attribut-Override-Farben `foreground`/
|
||||
* `background` DIESER Element-Instanz, unabhängig über `foregroundPenId`/
|
||||
* `backgroundPenId` (analog `Component.foregroundPenId`/`backgroundPenId`,
|
||||
* nur eben am Element statt am Bauteil). Für Elementarten MIT eigenem
|
||||
* Strichstärke- UND Vordergrund/Hintergrund-Override-Feld (Wand/Decke/
|
||||
* Stütze/Drawing2D — exakt dieselben vier wie bei der Strichstärke).
|
||||
*/
|
||||
function bakeElementColorAndWeight<
|
||||
T extends {
|
||||
colorPenId?: string;
|
||||
color?: string;
|
||||
foregroundPenId?: string;
|
||||
foreground?: string;
|
||||
backgroundPenId?: string;
|
||||
background?: string;
|
||||
},
|
||||
K extends string,
|
||||
>(project: Project, x: T & Partial<Record<K, number>>, weightKey: K): T {
|
||||
if (!x.colorPenId && !x.foregroundPenId && !x.backgroundPenId) return x;
|
||||
return {
|
||||
...x,
|
||||
...(x.colorPenId
|
||||
? { color: resolvePenColor(project, x.colorPenId), [weightKey]: resolvePenWeight(project, x.colorPenId) }
|
||||
: {}),
|
||||
...(x.foregroundPenId ? { foreground: resolvePenColor(project, x.foregroundPenId) } : {}),
|
||||
...(x.backgroundPenId ? { background: resolvePenColor(project, x.backgroundPenId) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Schreibt für JEDES Bauteil/JEDE Ebenen-Kategorie/JEDES Modell-Element mit
|
||||
* gesetztem Stift die Farbe (+ ggf. Strichstärke) des AKTIVEN Stiftsatzes in
|
||||
* `color`/`foreground`/`background`/`lw`/`strokeWeight`/`weightMm` — reine
|
||||
* Funktion, liefert ein neues `Project` (unveränderte Teile bleiben
|
||||
* referenzgleich). Aufzurufen nach: Stiftsatz-Wechsel, Änderung EINES Stifts
|
||||
* im aktiven Satz, oder Neuzuweisung eines Stifts an ein Bauteil/eine Ebene
|
||||
* (dort reicht meist ein direkter Patch, s. `resolvePenColor`/
|
||||
* `resolvePenWeight` — diese Funktion ist für die FLÄCHIGEN Fälle, die viele
|
||||
* Objekte auf einmal betreffen).
|
||||
*
|
||||
* Bewusst NICHT abgedeckt: Layout-Annotationen (`Layout.annotations[]`,
|
||||
* verschachtelt in `Project.layouts`) und `Tür`/`ExtrudedSolid`/Kontext-
|
||||
* Objekte — kein `colorPenId`-Feld dort (Scope-Entscheid, s. PENDENZEN.md).
|
||||
* Ops, die für JEDES Bauteil/JEDE Ebenen-Kategorie/JEDES Modell-Element mit gesetztem Stift die Farbe
|
||||
* (+ ggf. Strichstärke) des AKTIVEN Stiftsatzes in `color`/`foreground`/`background`/`lw`/`strokeWeight`/
|
||||
* `weightMm` schreiben; nur wirklich geänderte Elemente. Aufzurufen nach: Stiftsatz-Wechsel, Änderung EINES
|
||||
* Stifts im aktiven Satz oder Neuzuweisung eines Stifts (dort reicht meist ein direkter Patch).
|
||||
*/
|
||||
export function rebakePenOps(project: Project): CoreOp[] {
|
||||
const all = () => true;
|
||||
const layers = project.layers.map((cat) => bakeCategory(project, cat));
|
||||
return [
|
||||
...patchItems(project, "components", all, (c) => bakeComponent(project, c)),
|
||||
...(layers.every((c, i) => c === project.layers[i]) ? [] : fieldOps(project, "layers", layers)),
|
||||
...patchItems(project, "walls", all, (w) => bakeElementColorAndWeight(project, w, "strokeWeight")),
|
||||
...patchItems(project, "drawings2d", all, (d) => bakeElementColorAndWeight(project, d, "weightMm")),
|
||||
...patchItems(project, "ceilings", all, (c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
...patchItems(project, "columns", all, (c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
...patchItems(project, "roofs", all, (r) => bakeElementColor(project, r)),
|
||||
...patchItems(project, "openings", all, (o) => bakeElementColor(project, o)),
|
||||
...patchItems(project, "stairs", all, (s) => bakeElementColor(project, s)),
|
||||
...patchItems(project, "rooms", all, (r) => bakeElementColor(project, r)),
|
||||
];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("penRebakeOps");
|
||||
}
|
||||
|
||||
/**
|
||||
* Ops zum Löschen des Stifts `penId`: aus `pens` und allen Stiftsätzen entfernen und die Verweise
|
||||
* (`colorPenId`/`foregroundPenId`/`backgroundPenId`) in Bauteilen und im Kategorien-Baum löschen.
|
||||
*/
|
||||
export function deletePenOps(project: Project, penId: string): CoreOp[] {
|
||||
return documentFor(project).queryRoot<CoreOp[]>("penDeleteOps", penId);
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import type {
|
||||
} from "../model/types";
|
||||
import {
|
||||
activePenSet,
|
||||
deletePenOps,
|
||||
rebakePenOps,
|
||||
seedStandardPenSetOps,
|
||||
PEN_FALLBACK_COLOR,
|
||||
@@ -920,31 +921,7 @@ export function createProjectSlice(
|
||||
|
||||
renamePen: (id, name) => applyChange((p) => patchItem(p, "pens", id, { name })),
|
||||
|
||||
deletePen: (id) =>
|
||||
applyChange((p) => {
|
||||
const clearPenRefs = <T extends { colorPenId?: string; foregroundPenId?: string; backgroundPenId?: string }>(x: T): T =>
|
||||
x.colorPenId === id || x.foregroundPenId === id || x.backgroundPenId === id
|
||||
? {
|
||||
...x,
|
||||
colorPenId: x.colorPenId === id ? undefined : x.colorPenId,
|
||||
foregroundPenId: x.foregroundPenId === id ? undefined : x.foregroundPenId,
|
||||
backgroundPenId: x.backgroundPenId === id ? undefined : x.backgroundPenId,
|
||||
}
|
||||
: x;
|
||||
const clearCategoryPenRefs = (cat: LayerCategory): LayerCategory => ({
|
||||
...(cat.colorPenId === id ? { ...cat, colorPenId: undefined } : cat),
|
||||
...(cat.children ? { children: cat.children.map(clearCategoryPenRefs) } : {}),
|
||||
});
|
||||
return [
|
||||
...removeItems(p, "pens", [id]),
|
||||
...patchItems(p, "penSets", () => true, (s) => {
|
||||
const { [id]: _removed, ...rest } = s.pens;
|
||||
return { ...s, pens: rest };
|
||||
}),
|
||||
...patchItems(p, "components", () => true, clearPenRefs),
|
||||
...fieldOps(p, "layers", p.layers.map(clearCategoryPenRefs)),
|
||||
];
|
||||
}),
|
||||
deletePen: (id) => applyChange((p) => deletePenOps(p, id)),
|
||||
|
||||
addPenSet: () =>
|
||||
applyChange((p) => {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// Manager läuft auch als eigenes natives Fenster ohne gemeinsamen Store.
|
||||
|
||||
import { useState } from "react";
|
||||
import { FREE_COLOR_PALETTE } from "../model/penSets";
|
||||
import { freeColorPalette } from "../model/penSets";
|
||||
import { MATERIAL_PALETTE, RAL_CLASSIC, TANGO_PALETTE } from "../model/color";
|
||||
import type { BuiltinPaletteBanks, CustomPalette } from "../model/types";
|
||||
import { Swatch } from "./ColorSwatchCell";
|
||||
@@ -59,7 +59,7 @@ export function FreeColorPicker({
|
||||
banks.push({
|
||||
id: "simple",
|
||||
label: t("pen.paletteSimple"),
|
||||
entries: FREE_COLOR_PALETTE.map((hex) => ({ hex, title: hex })),
|
||||
entries: freeColorPalette().map((hex) => ({ hex, title: hex })),
|
||||
});
|
||||
}
|
||||
if (builtinBanks?.tango !== false) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { useState } from "react";
|
||||
import type { BuiltinPaletteBank, Project } from "../../model/types";
|
||||
import { MATERIAL_PALETTE, RAL_CLASSIC, TANGO_PALETTE } from "../../model/color";
|
||||
import { FREE_COLOR_PALETTE } from "../../model/penSets";
|
||||
import { freeColorPalette } from "../../model/penSets";
|
||||
import { t } from "../../i18n";
|
||||
import { DeleteButton, EmptyState, FieldRow, TextField } from "./fields";
|
||||
|
||||
@@ -20,15 +20,16 @@ import { DeleteButton, EmptyState, FieldRow, TextField } from "./fields";
|
||||
* Die vier mitgelieferten Bänke. `labelKey` statt fertigem Label, damit `t()`
|
||||
* erst zur RENDERZEIT läuft (Sprachwechsel wirkt sonst nicht — gleiche
|
||||
* Konvention wie `PATTERN_OPTIONS` in `HatchesTab.tsx`); Eigennamen
|
||||
* (Tango/Material/RAL) stehen direkt in `label`.
|
||||
* (Tango/Material/RAL) stehen direkt in `label`. Eine Funktion, weil die Freie-Farbe-Palette aus dem
|
||||
* Kern kommt (erst nach `initCore()` lesbar).
|
||||
*/
|
||||
const BUILTIN_BANKS: {
|
||||
const builtinBanks = (): {
|
||||
id: BuiltinPaletteBank;
|
||||
label?: string;
|
||||
labelKey?: string;
|
||||
preview: string[];
|
||||
}[] = [
|
||||
{ id: "simple", labelKey: "pen.paletteSimple", preview: FREE_COLOR_PALETTE },
|
||||
}[] => [
|
||||
{ id: "simple", labelKey: "pen.paletteSimple", preview: freeColorPalette() },
|
||||
{ id: "tango", label: "Tango", preview: TANGO_PALETTE.map((c) => c.hex) },
|
||||
{ id: "material", label: "Material", preview: MATERIAL_PALETTE.map((c) => c.hex) },
|
||||
{ id: "ral", label: "RAL Classic", preview: RAL_CLASSIC.map((c) => c.hex) },
|
||||
@@ -73,7 +74,7 @@ export function PalettesTab({
|
||||
{/* Mitgelieferte Bänke: nur ein/aus — Inhalt ist fest. */}
|
||||
<div className="res-fields">
|
||||
<div className="res-section-label">{t("resources.palettes.builtin")}</div>
|
||||
{BUILTIN_BANKS.map((bank) => (
|
||||
{builtinBanks().map((bank) => (
|
||||
<FieldRow
|
||||
key={bank.id}
|
||||
label={bank.label ?? t(bank.labelKey!)}
|
||||
|
||||
Reference in new issue
Block a user