[272] Varianten: Auge/Stift, grau einfärben und sperren wie Archicad
Panel „Varianten“: je Variante Auge (Kombination der aktiven Ansicht, Op mit Undo; ersetzt die Selects) und Stift (Bearbeitungsvariante, ersetzt „Neue Elemente zeichnen in …“; Stift impliziert Auge; Hauptmodell-Stift beendet). Chip „Bearbeite: …“. Häkchen „ausserhalb grau einfärben“ (nur Bildschirm: Anfrage-Feld designOptionEdit → renovation::View::editing → ghost_style in Resolved.styled, Grundriss/Schnitt/Ansicht/ Axo/3D) und „ausserhalb sperren“ (selectionSlice filtert die Auswahl). Stift und Häkchen sind Sitzungszustand. Goldens unverändert. Tests: Kern design_options_tests (+3), vitest designOptions (+5), e2e designOptions272 (+1, 2× grün Port 5195), renderCount grün.
This commit is contained in:
36 files changed
+910
-81
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
resolveCombination, setLevelCombinationOps, setPrimaryOptionOps, showsInCombination,
|
||||
addCombinationOps, assignCombinationOps, combinationChoice, deleteCombinationOps, designOptionCombinations, levelCombinationState, renameCombinationOps, setCombinationChoiceOps,
|
||||
storedChoice,
|
||||
DESIGN_OPTION_GHOST_FILL, designOptionEditArg, designOptionLocked, eyeClick, penClick, unlockedSelection, visibleOption,
|
||||
} from "./designOptions";
|
||||
import { viewportDesignOptions } from "../plan/viewportPlan";
|
||||
import { viewportVariantSuffix } from "./posterTemplates";
|
||||
@@ -233,3 +234,74 @@ describe("[272] Benannte Variantenkombinationen", () => {
|
||||
expect(q2.drawingLevels.find((l) => l.id === "eg")?.designOptions).toEqual({ fassade: "b" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("[272] Varianten bearbeiten wie Archicad (Auge, Stift, grau, sperren)", () => {
|
||||
const dach = (option: string) => ({ set: "dachform", option });
|
||||
|
||||
it("Bearbeitungsvariante der Bildschirm-Anfrage: nur mit Stift und bekannter Variante", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
expect(designOptionEditArg(p, null, true)).toBeNull();
|
||||
expect(designOptionEditArg(p, { set: "dachform", option: "zz" }, true)).toBeNull();
|
||||
expect(designOptionEditArg(p, dach("b"), true)).toEqual({ set: "dachform", option: "b", grey: true });
|
||||
expect(designOptionEditArg(p, dach("b"), false)).toEqual({ set: "dachform", option: "b", grey: false });
|
||||
});
|
||||
|
||||
it("Auge: sichtbare Variante je Satz (Stift geht vor); Klick schaltet die Ebene um, im Stift-Satz endet die Bearbeitung", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
const eg = p.drawingLevels.find((l) => l.id === "eg");
|
||||
expect(visibleOption(p, eg, null, "dachform")).toBe("a");
|
||||
expect(visibleOption(p, eg, dach("b"), "dachform")).toBe("b");
|
||||
expect(visibleOption(p, eg, dach("b"), "fassade")).toBe(levelCombination(p, eg).fassade);
|
||||
// Auge in einem anderen Satz: Ebene wechselt, Stift bleibt.
|
||||
const other = eyeClick(p, "eg", dach("b"), "fassade", "b");
|
||||
expect(other.draw).toEqual(dach("b"));
|
||||
const q = applyOps(p, other.ops);
|
||||
expect(levelCombination(q, q.drawingLevels.find((l) => l.id === "eg")).fassade).toBe("b");
|
||||
// Auge im Satz des Stifts auf eine andere Variante: Bearbeitung endet (Stift impliziert Auge).
|
||||
const same = eyeClick(p, "eg", dach("b"), "dachform", "a");
|
||||
expect(same.draw).toBeNull();
|
||||
// Auge auf die bearbeitete Variante: nichts zu tun.
|
||||
expect(eyeClick(p, "eg", dach("b"), "dachform", "b")).toEqual({ draw: dach("b"), ops: [] });
|
||||
});
|
||||
|
||||
it("Stift: setzt die Bearbeitungsvariante, zweiter Klick zurück aufs Hauptmodell (kein Undo-Schritt)", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
expect(penClick(p, null, "dachform", "b")).toEqual(dach("b"));
|
||||
expect(penClick(p, dach("b"), "dachform", "b")).toBeNull();
|
||||
expect(penClick(p, dach("b"), "fassade", "a")).toEqual({ set: "fassade", option: "a" });
|
||||
expect(penClick(p, null, "dachform", "zz")).toBeNull();
|
||||
});
|
||||
|
||||
it("Sperren: ausserhalb der Bearbeitungsvariante nicht wählbar (Öffnung folgt ihrer Wand), ohne Stift nichts gesperrt", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
const main = p.walls.find((w) => !w.designOption)!;
|
||||
const roofB = (p.roofs ?? []).find((r) => r.designOption?.option === "b" && r.designOption.set === "dachform")!;
|
||||
const roofA = (p.roofs ?? []).find((r) => r.designOption?.option === "a" && r.designOption.set === "dachform")!;
|
||||
expect(designOptionLocked(p, dach("b"), "walls", main.id)).toBe(true);
|
||||
expect(designOptionLocked(p, dach("b"), "roofs", roofB.id)).toBe(false);
|
||||
expect(designOptionLocked(p, dach("b"), "roofs", roofA.id)).toBe(true);
|
||||
expect(designOptionLocked(p, null, "walls", main.id)).toBe(false);
|
||||
// Öffnung ohne eigene Variante in einer Wand der Variante: frei.
|
||||
const q: Project = { ...p, walls: p.walls.map((w) => (w.id === main.id ? { ...w, designOption: dach("b") } : w)) };
|
||||
const o = (q.openings ?? []).find((x) => x.hostWallId === main.id && !x.designOption);
|
||||
expect(o).toBeDefined();
|
||||
expect(designOptionLocked(q, dach("b"), "openings", o!.id)).toBe(false);
|
||||
expect(designOptionLocked(p, dach("b"), "openings", o!.id)).toBe(true);
|
||||
// Schnittlinien und Gruppen bleiben wählbar; Auswahl gefiltert.
|
||||
expect(designOptionLocked(p, dach("b"), "sectionLines", "schnitt-a")).toBe(false);
|
||||
expect(unlockedSelection(p, dach("b"), { walls: [main.id], roofs: [roofB.id, roofA.id] })).toEqual({ walls: [], roofs: [roofB.id] });
|
||||
expect(unlockedSelection(p, null, { walls: [main.id] })).toEqual({ walls: [main.id] });
|
||||
});
|
||||
|
||||
it("Grau nur in der Bildschirm-Anfrage: Hauptmodell grau, bearbeitete Variante nicht, Druck unverändert", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
const fills = (edit: ReturnType<typeof designOptionEditArg>) =>
|
||||
withDocument(p, () => {
|
||||
const plan = generatePlan(p, "eg", ALL, undefined, "mittel", false, false, true, 100, false, false, null, null, edit);
|
||||
return plan.primitives.filter((x) => x.kind === "polygon" && (x as { wallId?: string }).wallId).map((x) => (x as { fill: string }).fill);
|
||||
});
|
||||
expect(fills(null)).not.toContain(DESIGN_OPTION_GHOST_FILL);
|
||||
expect(fills(designOptionEditArg(p, dach("b"), true))).toContain(DESIGN_OPTION_GHOST_FILL);
|
||||
expect(fills(designOptionEditArg(p, dach("b"), false))).not.toContain(DESIGN_OPTION_GHOST_FILL);
|
||||
});
|
||||
});
|
||||
@@ -424,3 +424,101 @@ export function projectWithCombination(project: Project, c: Combination): Projec
|
||||
...(project.layouts ? { layouts: project.layouts.map((l) => ({ ...l, viewports: l.viewports.map(strip) })) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// ── Bearbeiten wie im Archicad-Manager (Nachtrag 17.11.): Auge, Stift, grau einfärben, sperren ─────────────────────
|
||||
//
|
||||
// Stift = Bearbeitungsvariante (`drawDesignOption` im Store, Zustand der Sitzung wie in Archicad die Einstellungen des
|
||||
// Managers, kein Undo-Schritt): neue Elemente der Zeichenbefehle gehören ihr (Kern `design_options::stamp_ops`), die
|
||||
// Bildschirm-Ansichten zeigen sie (Stift impliziert Auge) und färben mit „grau“ alles ausserhalb grau (Kern
|
||||
// `design_options::Edit`, `renovation::View::editing` — der eine Sichtbarkeits-Ort; Druck/PDF/Exporte fragen nie damit).
|
||||
|
||||
/** Variante als Ziel (Satz-Id, Varianten-Id). */
|
||||
export type DesignOptionTarget = { set: string; option: string };
|
||||
|
||||
/** Anfrage-Feld `designOptionEdit` der Bildschirm-Ansichten (Grundriss, Schnitt, Ansicht, Axo, 3D). */
|
||||
export interface DesignOptionEditArg {
|
||||
set: string;
|
||||
option: string;
|
||||
/** Häkchen „Elemente ausserhalb der Variante grau einfärben“. */
|
||||
grey: boolean;
|
||||
}
|
||||
|
||||
/** Füllfarbe des Graus ausserhalb der Bearbeitungsvariante (gleich wie `renovation::ghost_style` im Kern). */
|
||||
export const DESIGN_OPTION_GHOST_FILL = "#e3e3e3";
|
||||
|
||||
function knownTarget(project: Project, t: DesignOptionTarget | null | undefined): t is DesignOptionTarget {
|
||||
return !!t && designOptionSets(project).some((s) => s.id === t.set && s.options.some((o) => o.id === t.option));
|
||||
}
|
||||
|
||||
/** Bearbeitungsvariante für Bildschirm-Anfragen; `null` ohne Stift oder bei unbekannter Variante. */
|
||||
export function designOptionEditArg(project: Project, draw: DesignOptionTarget | null | undefined, grey: boolean): DesignOptionEditArg | null {
|
||||
return knownTarget(project, draw) ? { set: draw.set, option: draw.option, grey } : null;
|
||||
}
|
||||
|
||||
/** Auge: die in der aktiven Ansicht sichtbare Variante des Satzes (der Stift geht vor, sonst die Kombination der Ebene). */
|
||||
export function visibleOption(project: Project, level: DrawingLevel | undefined, draw: DesignOptionTarget | null | undefined, setId: string): string | undefined {
|
||||
if (knownTarget(project, draw) && draw.set === setId) return draw.option;
|
||||
return levelCombination(project, level)[setId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Klick aufs Auge einer Variante: die Ebene zeigt sie (Ops, ein Undo-Schritt). Im Satz des Stifts endet damit die Bearbeitung
|
||||
* (Stift impliziert Auge, eine andere Variante dieses Satzes sichtbar zu machen heisst, den Stift abzugeben).
|
||||
*/
|
||||
export function eyeClick(project: Project, levelId: string, draw: DesignOptionTarget | null, setId: string, optionId: string): { draw: DesignOptionTarget | null; ops: CoreOp[] } {
|
||||
if (draw && draw.set === setId && draw.option === optionId) return { draw, ops: [] };
|
||||
const level = project.drawingLevels.find((l) => l.id === levelId);
|
||||
const ops = levelCombination(project, level)[setId] === optionId ? [] : setLevelCombinationOps(project, levelId, setId, optionId);
|
||||
return { draw: draw && draw.set === setId ? null : draw, ops };
|
||||
}
|
||||
|
||||
/** Klick auf den Stift einer Variante: sie wird Bearbeitungsvariante; der Stift der bearbeiteten Variante gibt zurück ans Hauptmodell. */
|
||||
export function penClick(project: Project, draw: DesignOptionTarget | null, setId: string, optionId: string): DesignOptionTarget | null {
|
||||
if (draw && draw.set === setId && draw.option === optionId) return null;
|
||||
const t = { set: setId, option: optionId };
|
||||
return knownTarget(project, t) ? t : null;
|
||||
}
|
||||
|
||||
/** Auswahl-Art → Liste im Projekt (nur Arten, deren Elemente einer Variante angehören können). */
|
||||
const KIND_COLLECTION: Record<string, DesignOptionCollection> = {
|
||||
walls: "walls",
|
||||
openings: "openings",
|
||||
ceilings: "ceilings",
|
||||
roofs: "roofs",
|
||||
stairs: "stairs",
|
||||
columns: "columns",
|
||||
solids: "extrudedSolids",
|
||||
rooms: "rooms",
|
||||
drawings: "drawings2d",
|
||||
};
|
||||
|
||||
/** Modell-Arten ohne Variante (immer ausserhalb einer Bearbeitungsvariante). */
|
||||
const OUTSIDE_KINDS = new Set(["trees", "cameras", "contextObjects"]);
|
||||
|
||||
/**
|
||||
* Häkchen „Elemente ausserhalb der Variante sperren“: ist das Element (Auswahl-Art, Id) bei Bearbeitungsvariante `edit` gesperrt?
|
||||
* Gesperrt ist alles ausserhalb der Variante (Hauptmodell, andere Varianten, Bäume, Kameras, Kontext); eine Öffnung ohne eigene
|
||||
* Variante folgt ihrer Wand. Schnittlinien, Lage-Darstellung und Gruppen bleiben wählbar. Ohne `edit` nichts gesperrt.
|
||||
*/
|
||||
export function designOptionLocked(project: Project, edit: DesignOptionTarget | null | undefined, kind: string, id: string): boolean {
|
||||
if (!edit) return false;
|
||||
if (OUTSIDE_KINDS.has(kind)) return true;
|
||||
const coll = KIND_COLLECTION[kind];
|
||||
if (!coll) return false;
|
||||
const e = ((project[coll] ?? []) as { id: string; designOption?: DesignOptionRef; hostWallId?: string }[]).find((x) => x.id === id);
|
||||
if (!e) return false;
|
||||
const r = e.designOption ?? (coll === "openings" ? project.walls.find((w) => w.id === e.hostWallId)?.designOption : undefined);
|
||||
return !(r && r.set === edit.set && r.option === edit.option);
|
||||
}
|
||||
|
||||
/** Auswahl ohne gesperrte Elemente ({@link designOptionLocked}); unveränderte Listen behalten ihre Referenz. */
|
||||
export function unlockedSelection<T extends Record<string, string[] | undefined>>(project: Project, edit: DesignOptionTarget | null | undefined, sel: T): T {
|
||||
if (!edit) return sel;
|
||||
const out = { ...sel } as Record<string, string[] | undefined>;
|
||||
for (const [k, ids] of Object.entries(sel)) {
|
||||
if (!ids?.length) continue;
|
||||
const keep = ids.filter((id) => !designOptionLocked(project, edit, k, id));
|
||||
if (keep.length !== ids.length) out[k] = keep;
|
||||
}
|
||||
return out as T;
|
||||
}
|
||||
Reference in new issue
Block a user