Merge [272] Varianten (mit Umbau-Panel zusammengeführt, Import selectionRenovationIds aus state/renovationHook)
This commit is contained in:
73 files changed
+2979
-100
No files matched your search
@@ -0,0 +1,137 @@
|
||||
// [272] Varianten: Kombinationen lesen, Sätze/Varianten anlegen, Zuweisen/Kopieren/Übernehmen/Löschen über den Kern,
|
||||
// Grundriss/Schnitt/3D/Kennzahlen je Kombination am Varianten-Beispiel, Vergleich und CSV, CLI-Kombination.
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyOps } from "../core/ops";
|
||||
import {
|
||||
acceptDesignOptionOps, addDesignOptionOps, addDesignOptionSetOps, assignDesignOptionOps, combinationLabel, combinationSpec, combinationSuffix, commonDesignOption,
|
||||
compareDesignOptions, compareDesignOptionsCsv, copyToDesignOptionOps, deleteDesignOptionOps, levelCombination, nextOptionName, parseCombination, projectWithCombination,
|
||||
resolveCombination, setLevelCombinationOps, setPrimaryOptionOps, showsInCombination,
|
||||
} from "./designOptions";
|
||||
import { buildVariantenSampleProject } from "./sampleProjectVarianten";
|
||||
import { sampleProject } from "./sampleProject";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { computeKennzahlen } from "../analysis/kennzahlen";
|
||||
import { projectToModel3d, projectToModel3dParts } from "../plan/toWalls3d";
|
||||
import { withDocument } from "../core/document";
|
||||
import type { Project } from "./types";
|
||||
|
||||
const ALL = new Set(["20", "21", "30", "31", "40", "60"]);
|
||||
|
||||
/** Ids der Öffnungen/Dächer im Grundriss des OG bzw. EG einer Projekt-Fassung. */
|
||||
function planIds(p: Project, level: string): Set<string> {
|
||||
return withDocument(p, () => {
|
||||
const out = new Set<string>();
|
||||
for (const x of generatePlan(p, level, ALL).primitives) {
|
||||
const r = x as { openingId?: string; roofId?: string };
|
||||
if (r.openingId) out.add(r.openingId);
|
||||
if (r.roofId) out.add(r.roofId);
|
||||
}
|
||||
return out;
|
||||
});
|
||||
}
|
||||
|
||||
describe("[272] Varianten", () => {
|
||||
it("Kombination: Hauptvarianten, gespeicherte Wahl, Namen, Text", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
expect(resolveCombination(p)).toEqual({ dachform: "a", fassade: "a" });
|
||||
expect(resolveCombination(p, { dachform: "b", weg: "x" }, { fassade: "z" })).toEqual({ dachform: "b", fassade: "a" });
|
||||
expect(combinationLabel(p, { dachform: "b", fassade: "a" })).toBe("Dachform B Satteldach, Fassade A Lochfenster");
|
||||
expect(combinationSuffix(p, { dachform: "b", fassade: "a" })).toBe("Dachform B Satteldach");
|
||||
expect(combinationSuffix(p, {})).toBe("");
|
||||
expect(parseCombination(p, "dachform=b satteldach; Fassade = B Bandfenster, Unsinn")).toEqual({ dachform: "b", fassade: "b" });
|
||||
expect(combinationSpec(p, { dachform: "b" })).toBe("Dachform=B Satteldach");
|
||||
expect(showsInCombination({ dachform: "a" }, { set: "dachform", option: "b" })).toBe(false);
|
||||
expect(showsInCombination({ dachform: "a" }, undefined)).toBe(true);
|
||||
expect(showsInCombination({ dachform: "a" }, { set: "weg", option: "b" })).toBe(true);
|
||||
});
|
||||
|
||||
it("Sätze und Varianten anlegen, Hauptvariante, Kombination der Ebene (ohne Hauptvariante gespeichert)", () => {
|
||||
const { ops, id } = addDesignOptionSetOps(sampleProject, "Dachform");
|
||||
let p = applyOps(sampleProject, ops);
|
||||
expect(p.designOptionSets?.[0]).toMatchObject({ id, name: "Dachform", primary: "a" });
|
||||
p = applyOps(p, addDesignOptionOps(p, id));
|
||||
expect(p.designOptionSets?.[0].options.map((o) => o.name)).toEqual(["A", "B", "C"]);
|
||||
expect(nextOptionName(p.designOptionSets?.[0])).toBe("D");
|
||||
p = applyOps(p, setLevelCombinationOps(p, "eg", id, "b"));
|
||||
expect(p.drawingLevels.find((l) => l.id === "eg")?.designOptions).toEqual({ [id]: "b" });
|
||||
expect(levelCombination(p, p.drawingLevels.find((l) => l.id === "eg"))[id]).toBe("b");
|
||||
p = applyOps(p, setLevelCombinationOps(p, "eg", id, "a"));
|
||||
expect(p.drawingLevels.find((l) => l.id === "eg")).not.toHaveProperty("designOptions");
|
||||
p = applyOps(p, setPrimaryOptionOps(p, id, "b"));
|
||||
expect(p.designOptionSets?.[0].primary).toBe("b");
|
||||
expect(setPrimaryOptionOps(p, id, "zz")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("Grundriss je Kombination: Dächer und Fenster der anderen Variante fehlen", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
const a = planIds(p, "eg");
|
||||
expect(a.has("O2")).toBe(true);
|
||||
expect(a.has("O-band")).toBe(false);
|
||||
const q = applyOps(p, setLevelCombinationOps(p, "eg", "fassade", "b"));
|
||||
const b = planIds(q, "eg");
|
||||
expect(b.has("O2")).toBe(false);
|
||||
expect(b.has("O-band")).toBe(true);
|
||||
});
|
||||
|
||||
it("3D und Kennzahlen je Kombination; Teil-Cache aus bei Varianten", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
withDocument(p, () => {
|
||||
expect(projectToModel3dParts(p)).toBeNull();
|
||||
const roofs = (opts?: Record<string, string>) => JSON.stringify(projectToModel3d(p, opts ? { hide: { designOptions: opts } } : {}));
|
||||
expect(roofs()).not.toEqual(roofs({ dachform: "b" }));
|
||||
});
|
||||
const ka = withDocument(p, () => computeKennzahlen(p));
|
||||
const pb = projectWithCombination(p, { dachform: "b" });
|
||||
const kb = withDocument(pb, () => computeKennzahlen(pb));
|
||||
expect(ka.gv).not.toBeCloseTo(kb.gv, 3);
|
||||
});
|
||||
|
||||
it("Vergleich: alle Kombinationen, Hauptkombination zuerst, CSV mit Kopf", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
const rows = withDocument(p, () => compareDesignOptions(p));
|
||||
expect(rows).toHaveLength(4);
|
||||
expect(rows[0].primary).toBe(true);
|
||||
expect(rows[0].label).toBe("Dachform A Flachdach, Fassade A Lochfenster");
|
||||
expect(new Set(rows.map((r) => r.gv)).size).toBeGreaterThan(1);
|
||||
expect(rows.every((r) => Number.isFinite(r.cost) && r.cost > 0)).toBe(true);
|
||||
const csv = withDocument(p, () => compareDesignOptionsCsv(p, ["Kombination", "GF", "HNF", "GV", "Fussabdruck", "AZ", "ÜZ", "Kosten"]));
|
||||
expect(csv.split("\n")[0]).toBe("Kombination;GF;HNF;GV;Fussabdruck;AZ;ÜZ;Kosten");
|
||||
expect(csv.trim().split("\n")).toHaveLength(5);
|
||||
expect(compareDesignOptions(sampleProject)).toEqual([]);
|
||||
});
|
||||
|
||||
it("Zuweisen (Mehrfachauswahl, ein Schritt), gemeinsamer Wert, Kopieren, Übernehmen, Löschen", () => {
|
||||
const p = buildVariantenSampleProject();
|
||||
withDocument(p, () => {
|
||||
const ops = assignDesignOptionOps(p, ["W1", "W2", "nix"], { set: "fassade", option: "b" });
|
||||
expect(ops).toHaveLength(2);
|
||||
const q = applyOps(p, ops);
|
||||
expect(commonDesignOption(q, ["W1", "W2"])).toBe("fassade/b");
|
||||
expect(commonDesignOption(q, ["W1", "W3"])).toBe("mixed");
|
||||
expect(commonDesignOption(q, ["W3"])).toBe("");
|
||||
const copy = copyToDesignOptionOps(p, ["W3"], { set: "fassade", option: "b" }, "k");
|
||||
const c = applyOps(p, copy);
|
||||
const w = c.walls.find((x) => x.id.startsWith("k-"));
|
||||
expect(w?.designOption).toEqual({ set: "fassade", option: "b" });
|
||||
expect((c.openings ?? []).filter((o) => o.hostWallId === w?.id).length).toBeGreaterThan(0);
|
||||
});
|
||||
// Übernehmen: B Satteldach bleibt (ohne Variante), Flachdach weg, Satz weg.
|
||||
const acc = withDocument(p, () => applyOps(p, acceptDesignOptionOps(p, "dachform", "b")));
|
||||
expect(acc.roofs?.map((r) => r.id)).toEqual(["RF1"]);
|
||||
expect(acc.roofs?.[0]).not.toHaveProperty("designOption");
|
||||
expect(acc.designOptionSets?.map((s) => s.id)).toEqual(["fassade"]);
|
||||
// Satz löschen: alle Fenster beider Fassaden-Varianten weg.
|
||||
const del = withDocument(p, () => applyOps(p, deleteDesignOptionOps(p, "fassade")));
|
||||
expect((del.openings ?? []).some((o) => o.id === "O2" || o.id === "O-band")).toBe(false);
|
||||
});
|
||||
|
||||
it("CLI-Kombination: gewählte Varianten werden Hauptvarianten, gespeicherte Wahlen entfallen", () => {
|
||||
const p0 = buildVariantenSampleProject();
|
||||
const p = { ...p0, drawingLevels: p0.drawingLevels.map((l) => (l.id === "eg" ? { ...l, designOptions: { dachform: "a", fassade: "b" } } : l)) };
|
||||
const q = projectWithCombination(p, { dachform: "b" });
|
||||
expect(q.designOptionSets?.find((s) => s.id === "dachform")?.primary).toBe("b");
|
||||
expect(q.drawingLevels.find((l) => l.id === "eg")?.designOptions).toEqual({ fassade: "b" });
|
||||
expect(projectWithCombination(p, {})).toBe(p);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,301 @@
|
||||
// [272] Varianten (Archicad „Design Options“): Variantensätze mit Varianten, Elemente im Hauptmodell oder in genau einer
|
||||
// Variante, je Ebene/Ausschnitt/Viewport eine Kombination. Was sichtbar ist, entscheidet der Kern (`renovation.rs`, ein Ort
|
||||
// mit dem Umbaufilter; Modell und Ops in `design_options.rs`); hier nur, was die Oberfläche zum Lesen und Setzen braucht.
|
||||
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { documentFor } from "../core/document";
|
||||
import { patchItem, setField } from "../core/opsBuild";
|
||||
import type { DesignOption, DesignOptionRef, DesignOptionSet, DrawingLevel, Project } from "./types";
|
||||
|
||||
/** Listen, deren Elemente einer Variante angehören können (gleich wie `design_options::COLLECTIONS`). */
|
||||
export const DESIGN_OPTION_COLLECTIONS = ["walls", "openings", "ceilings", "roofs", "stairs", "columns", "extrudedSolids", "rooms", "drawings2d"] as const;
|
||||
export type DesignOptionCollection = (typeof DESIGN_OPTION_COLLECTIONS)[number];
|
||||
|
||||
/** Kombination: Satz-Id → Varianten-Id. */
|
||||
export type Combination = Record<string, string>;
|
||||
|
||||
/** Variantensätze des Projekts. */
|
||||
export function designOptionSets(project: Project): readonly DesignOptionSet[] {
|
||||
return project.designOptionSets ?? [];
|
||||
}
|
||||
|
||||
/** Hauptvariante eines Satzes (`primary`, sonst die erste). */
|
||||
export function primaryOption(s: DesignOptionSet): string | undefined {
|
||||
return s.primary && s.options.some((o) => o.id === s.primary) ? s.primary : s.options[0]?.id;
|
||||
}
|
||||
|
||||
/** Wirksame Kombination: Hauptvarianten, darüber die gespeicherten Wahlen (spätere gehen vor; unbekannte übergangen). */
|
||||
export function resolveCombination(project: Project, ...stored: (Combination | undefined | null)[]): Combination {
|
||||
const out: Combination = {};
|
||||
for (const s of designOptionSets(project)) {
|
||||
const p = primaryOption(s);
|
||||
if (p) out[s.id] = p;
|
||||
}
|
||||
for (const m of stored) {
|
||||
for (const [k, v] of Object.entries(m ?? {})) {
|
||||
const s = designOptionSets(project).find((x) => x.id === k);
|
||||
if (s?.options.some((o) => o.id === v)) out[k] = v;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Kombination einer Ebene (`DrawingLevel.designOptions` über den Hauptvarianten). */
|
||||
export function levelCombination(project: Project, level: DrawingLevel | undefined): Combination {
|
||||
return resolveCombination(project, level?.designOptions);
|
||||
}
|
||||
|
||||
/** Lesbarer Name „Dachform B, Fassade A“ (nur Sätze mit Varianten). */
|
||||
export function combinationLabel(project: Project, c: Combination): string {
|
||||
const parts: string[] = [];
|
||||
for (const s of designOptionSets(project)) {
|
||||
const o = s.options.find((x) => x.id === c[s.id]);
|
||||
if (o) parts.push(`${s.name} ${o.name}`.trim());
|
||||
}
|
||||
return parts.join(", ");
|
||||
}
|
||||
|
||||
/** Kurzname nur der Varianten, die von der Hauptvariante abweichen (Titelzusatz im Blatt); leer = Hauptkombination. */
|
||||
export function combinationSuffix(project: Project, c: Combination | undefined | null): string {
|
||||
if (!c) return "";
|
||||
const full = resolveCombination(project, c);
|
||||
const prim = resolveCombination(project);
|
||||
const diff: Combination = {};
|
||||
for (const [k, v] of Object.entries(full)) if (prim[k] !== v) diff[k] = v;
|
||||
return combinationLabel(project, diff);
|
||||
}
|
||||
|
||||
/** Text „Satz=Variante,…“ (Namen) einer Kombination — Format der CLI `--options`. */
|
||||
export function combinationSpec(project: Project, c: Combination): string {
|
||||
const parts: string[] = [];
|
||||
for (const s of designOptionSets(project)) {
|
||||
const o = s.options.find((x) => x.id === c[s.id]);
|
||||
if (o) parts.push(`${s.name}=${o.name}`);
|
||||
}
|
||||
return parts.join(",");
|
||||
}
|
||||
|
||||
/** Liest „Dachform=B,Fassade=A“ (Ids oder Namen, ohne Gross-/Kleinschreibung); Unbekanntes übergangen. */
|
||||
export function parseCombination(project: Project, spec: string): Combination {
|
||||
const out: Combination = {};
|
||||
for (const part of spec.split(/[,;]/)) {
|
||||
const i = part.indexOf("=");
|
||||
if (i <= 0) continue;
|
||||
const k = part.slice(0, i).trim().toLowerCase();
|
||||
const v = part.slice(i + 1).trim().toLowerCase();
|
||||
const s = designOptionSets(project).find((x) => x.id.toLowerCase() === k || x.name.trim().toLowerCase() === k);
|
||||
const o = s?.options.find((x) => x.id.toLowerCase() === v || x.name.trim().toLowerCase() === v);
|
||||
if (s && o) out[s.id] = o.id;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Erscheint ein Element mit dieser Zugehörigkeit in der Kombination? (Gleiche Regel wie `Combination::shows` im Kern.) */
|
||||
export function showsInCombination(c: Combination, r: DesignOptionRef | undefined | null): boolean {
|
||||
if (!r) return true;
|
||||
const chosen = c[r.set];
|
||||
return chosen === undefined || chosen === r.option;
|
||||
}
|
||||
|
||||
/** Name „Dachform: B“ einer Zugehörigkeit; leer = Hauptmodell. */
|
||||
export function designOptionLabel(project: Project, r: DesignOptionRef | undefined | null): string {
|
||||
if (!r) return "";
|
||||
const s = designOptionSets(project).find((x) => x.id === r.set);
|
||||
const o = s?.options.find((x) => x.id === r.option);
|
||||
return s && o ? `${s.name}: ${o.name}` : "";
|
||||
}
|
||||
|
||||
/** Auswahl je Liste (ids), wie der Kern sie für Zuweisen/Kopieren nimmt. */
|
||||
export function designOptionSelection(project: Project, ids: Iterable<string>): Record<string, string[]> {
|
||||
const set = new Set(ids);
|
||||
const out: Record<string, string[]> = {};
|
||||
for (const c of DESIGN_OPTION_COLLECTIONS) {
|
||||
const hit = ((project[c] ?? []) as { id: string }[]).filter((e) => set.has(e.id)).map((e) => e.id);
|
||||
if (hit.length) out[c] = hit;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Ids der Auswahl, die einer Variante angehören können. */
|
||||
export function designOptionIds(project: Project, ids: Iterable<string>): string[] {
|
||||
return Object.values(designOptionSelection(project, ids)).flat();
|
||||
}
|
||||
|
||||
/** Gemeinsame Zugehörigkeit der Elemente `ids` als `"set/option"` (`""` = Hauptmodell, `"mixed"`, `null` ohne Elemente). */
|
||||
export function commonDesignOption(project: Project, ids: Iterable<string>): string | "mixed" | null {
|
||||
const set = new Set(ids);
|
||||
let out: string | null = null;
|
||||
for (const c of DESIGN_OPTION_COLLECTIONS) {
|
||||
for (const e of (project[c] ?? []) as { id: string; designOption?: DesignOptionRef }[]) {
|
||||
if (!set.has(e.id)) continue;
|
||||
const k = e.designOption ? `${e.designOption.set}/${e.designOption.option}` : "";
|
||||
if (out === null) out = k;
|
||||
else if (out !== k) return "mixed";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Ziel aus `"set/option"` (`""` = Hauptmodell). */
|
||||
export function parseTarget(key: string): { set: string; option: string } | null {
|
||||
const i = key.indexOf("/");
|
||||
return i > 0 ? { set: key.slice(0, i), option: key.slice(i + 1) } : null;
|
||||
}
|
||||
|
||||
/** Alle Ziele „Satz: Variante“ für Auswahllisten (`key` = `"set/option"`). */
|
||||
export function designOptionTargets(project: Project): { key: string; label: string }[] {
|
||||
const out: { key: string; label: string }[] = [];
|
||||
for (const s of designOptionSets(project)) for (const o of s.options) out.push({ key: `${s.id}/${o.id}`, label: `${s.name}: ${o.name}` });
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── Ops ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Ops: Variante zuweisen (`null` = Hauptmodell) für die Auswahl (Kern `design_options::assign_ops`; ein Undo-Schritt). */
|
||||
export function assignDesignOptionOps(project: Project, ids: Iterable<string>, target: { set: string; option: string } | null): CoreOp[] {
|
||||
const sel = designOptionSelection(project, ids);
|
||||
if (!Object.keys(sel).length) return [];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("designOptionAssignOps", JSON.stringify({ ...(target ?? {}), sel }));
|
||||
}
|
||||
|
||||
/** Ops: Kopien der Auswahl in die Variante (`null` = Hauptmodell); Öffnungen gewählter Wände wandern mit. */
|
||||
export function copyToDesignOptionOps(project: Project, ids: Iterable<string>, target: { set: string; option: string } | null, stamp = `v${Date.now().toString(36)}`): CoreOp[] {
|
||||
const sel = designOptionSelection(project, ids);
|
||||
if (!Object.keys(sel).length) return [];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("designOptionCopyOps", JSON.stringify({ ...(target ?? {}), sel, stamp }));
|
||||
}
|
||||
|
||||
/** Ops: „Variante übernehmen“ — ihre Elemente ins Hauptmodell, die übrigen Varianten des Satzes gelöscht, Satz weg. */
|
||||
export function acceptDesignOptionOps(project: Project, set: string, option: string): CoreOp[] {
|
||||
return documentFor(project).queryRoot<CoreOp[]>("designOptionAcceptOps", JSON.stringify({ set, option }));
|
||||
}
|
||||
|
||||
/** Ops: Satz (ohne `option`) bzw. Variante löschen samt ihren Elementen. */
|
||||
export function deleteDesignOptionOps(project: Project, set: string, option?: string): CoreOp[] {
|
||||
return documentFor(project).queryRoot<CoreOp[]>("designOptionDeleteOps", JSON.stringify(option ? { set, option } : { set }));
|
||||
}
|
||||
|
||||
/** Nächste freie Id mit Präfix. */
|
||||
function freeId(used: Iterable<string>, prefix: string): string {
|
||||
const u = new Set(used);
|
||||
let i = u.size + 1;
|
||||
while (u.has(`${prefix}${i}`)) i++;
|
||||
return `${prefix}${i}`;
|
||||
}
|
||||
|
||||
/** Variantenname „A“, „B“, … (nächster freier Buchstabe). */
|
||||
export function nextOptionName(s: DesignOptionSet | undefined): string {
|
||||
const used = new Set((s?.options ?? []).map((o) => o.name.trim().toUpperCase()));
|
||||
for (let i = 0; i < 26; i++) {
|
||||
const n = String.fromCharCode(65 + i);
|
||||
if (!used.has(n)) return n;
|
||||
}
|
||||
return String((s?.options.length ?? 0) + 1);
|
||||
}
|
||||
|
||||
/** Ops: neuer Satz `name` mit den Varianten A und B (A = Hauptvariante). Gibt auch die neue Satz-Id zurück. */
|
||||
export function addDesignOptionSetOps(project: Project, name: string): { ops: CoreOp[]; id: string } {
|
||||
const sets = designOptionSets(project);
|
||||
const id = freeId(sets.map((s) => s.id), "satz-");
|
||||
const options: DesignOption[] = [
|
||||
{ id: "a", name: "A" },
|
||||
{ id: "b", name: "B" },
|
||||
];
|
||||
return { ops: [setField("designOptionSets", [...sets, { id, name: name.trim() || id, options, primary: "a" }])], id };
|
||||
}
|
||||
|
||||
/** Ops: weitere Variante im Satz (nächster Buchstabe). */
|
||||
export function addDesignOptionOps(project: Project, setId: string): CoreOp[] {
|
||||
const sets = designOptionSets(project);
|
||||
const s = sets.find((x) => x.id === setId);
|
||||
if (!s) return [];
|
||||
const name = nextOptionName(s);
|
||||
const id = freeId(s.options.map((o) => o.id), "v");
|
||||
return [setField("designOptionSets", sets.map((x) => (x.id === setId ? { ...x, options: [...x.options, { id, name }] } : x)))];
|
||||
}
|
||||
|
||||
/** Ops: Satz bzw. Variante umbenennen, Hauptvariante setzen. */
|
||||
export function renameDesignOptionSetOps(project: Project, setId: string, name: string): CoreOp[] {
|
||||
const sets = designOptionSets(project);
|
||||
if (!sets.some((s) => s.id === setId)) return [];
|
||||
return [setField("designOptionSets", sets.map((s) => (s.id === setId ? { ...s, name } : s)))];
|
||||
}
|
||||
|
||||
export function renameDesignOptionOps(project: Project, setId: string, optionId: string, name: string): CoreOp[] {
|
||||
const sets = designOptionSets(project);
|
||||
if (!sets.some((s) => s.id === setId && s.options.some((o) => o.id === optionId))) return [];
|
||||
return [setField("designOptionSets", sets.map((s) => (s.id === setId ? { ...s, options: s.options.map((o) => (o.id === optionId ? { ...o, name } : o)) } : s)))];
|
||||
}
|
||||
|
||||
export function setPrimaryOptionOps(project: Project, setId: string, optionId: string): CoreOp[] {
|
||||
const sets = designOptionSets(project);
|
||||
if (!sets.some((s) => s.id === setId && s.options.some((o) => o.id === optionId))) return [];
|
||||
return [setField("designOptionSets", sets.map((s) => (s.id === setId ? { ...s, primary: optionId } : s)))];
|
||||
}
|
||||
|
||||
/** Ops: Kombination der Ebene setzen (eine Variante je Satz; die Hauptvariante wird nicht gespeichert). */
|
||||
export function setLevelCombinationOps(project: Project, levelId: string, setId: string, optionId: string): CoreOp[] {
|
||||
const s = designOptionSets(project).find((x) => x.id === setId);
|
||||
if (!s || !s.options.some((o) => o.id === optionId)) return [];
|
||||
return patchItem(project, "drawingLevels", levelId, (l) => {
|
||||
const m: Combination = { ...(l.designOptions ?? {}) };
|
||||
if (primaryOption(s) === optionId) delete m[setId];
|
||||
else m[setId] = optionId;
|
||||
const next = { ...l, designOptions: m };
|
||||
if (!Object.keys(m).length) delete (next as { designOptions?: Combination }).designOptions;
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
// ── Vergleich ───────────────────────────────────────────────────────────────
|
||||
|
||||
/** Zeile der Vergleichstabelle (Kern `design_options::CompareRow`). */
|
||||
export interface DesignOptionCompareRow {
|
||||
choice: Combination;
|
||||
label: string;
|
||||
primary: boolean;
|
||||
gf: number;
|
||||
hnf: number;
|
||||
gv: number;
|
||||
footprint: number;
|
||||
az?: number | null;
|
||||
uez?: number | null;
|
||||
cost: number;
|
||||
}
|
||||
|
||||
/** Kennzahlen und Kosten je Kombination (Hauptkombination zuerst); `renovation`: Umbau-Zustand (Filter-Id). */
|
||||
export function compareDesignOptions(project: Project, renovation = ""): DesignOptionCompareRow[] {
|
||||
if (!designOptionSets(project).length) return [];
|
||||
return documentFor(project).query<DesignOptionCompareRow[]>("designOptionCompare", [], renovation ? JSON.stringify({ renovation }) : "");
|
||||
}
|
||||
|
||||
/** Vergleich als CSV (Semikolon) mit den Spaltenköpfen `head` (übersetzt). */
|
||||
export function compareDesignOptionsCsv(project: Project, head: readonly string[], renovation = ""): string {
|
||||
if (!designOptionSets(project).length) return "";
|
||||
return documentFor(project).query<string>("designOptionCompare", [], JSON.stringify(renovation ? { renovation, head } : { head }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Das Projekt so, dass die Kombination `c` überall gilt (CLI `--options`): die gewählten Varianten werden Hauptvarianten,
|
||||
* gespeicherte Wahlen dieser Sätze an Ebenen, Vorlagen, Ausschnitten und Viewports entfallen. Kein Op (Kopie für Exporte).
|
||||
*/
|
||||
export function projectWithCombination(project: Project, c: Combination): Project {
|
||||
const keys = Object.keys(c);
|
||||
if (!keys.length) return project;
|
||||
const strip = <T extends { designOptions?: Combination | null }>(x: T): T => {
|
||||
if (!x.designOptions || !keys.some((k) => k in x.designOptions!)) return x;
|
||||
const m = { ...x.designOptions };
|
||||
for (const k of keys) delete m[k];
|
||||
const next = { ...x, designOptions: m };
|
||||
if (!Object.keys(m).length) delete (next as { designOptions?: Combination | null }).designOptions;
|
||||
return next;
|
||||
};
|
||||
return {
|
||||
...project,
|
||||
designOptionSets: designOptionSets(project).map((s) => (c[s.id] && s.options.some((o) => o.id === c[s.id]) ? { ...s, primary: c[s.id] } : s)),
|
||||
drawingLevels: project.drawingLevels.map(strip),
|
||||
...(project.viewTemplates ? { viewTemplates: project.viewTemplates.map(strip) } : {}),
|
||||
...(project.viewSnapshots ? { viewSnapshots: project.viewSnapshots.map(strip) } : {}),
|
||||
...(project.layouts ? { layouts: project.layouts.map((l) => ({ ...l, viewports: l.viewports.map(strip) })) } : {}),
|
||||
};
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import type { Layout, LayoutOrientation, LayoutPaperFormat, MasterLayout, Projec
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { t } from "../i18n/translate";
|
||||
import { findSnapshot, resolveTitleBlock, resolveViewportScale, sheetSizeMm } from "./layoutModel";
|
||||
import { combinationSuffix } from "./designOptions";
|
||||
|
||||
export interface PosterTemplate {
|
||||
/** Schlüssel in `MasterLayout.template`. */
|
||||
@@ -113,5 +114,22 @@ export function viewportScaleLabel(
|
||||
if (!snap) return null;
|
||||
const n = scaleOverride ?? resolveViewportScale(vp, snap);
|
||||
const { sizeMm, dyMm } = scaleLabelMetrics(sheet);
|
||||
return { text: `1:${n}`, x: vp.xMm, y: vp.yMm + vp.heightMm + dyMm, sizeMm };
|
||||
// [272] Titelzusatz: Varianten, die von der Hauptkombination abweichen (Ausschnitt bzw. Viewport).
|
||||
const suffix = viewportVariantSuffix(project, vp);
|
||||
return { text: suffix ? `1:${n} · ${suffix}` : `1:${n}`, x: vp.xMm, y: vp.yMm + vp.heightMm + dyMm, sizeMm };
|
||||
}
|
||||
|
||||
/** [272] Varianten eines Viewports, die von der Hauptkombination abweichen („Dachform B Satteldach“); leer sonst. */
|
||||
export function viewportVariantSuffix(project: Project, vp: Layout["viewports"][number]): string {
|
||||
if (!project.designOptionSets?.length) return "";
|
||||
const snap = findSnapshot(project, vp.snapshotId);
|
||||
return combinationSuffix(project, { ...(snap?.designOptions ?? {}), ...(vp.designOptions ?? {}) });
|
||||
}
|
||||
|
||||
/** [272] Titelzusatz unter einem Viewport ohne Massstabsangaben des Masters: nur die Varianten; `null` ohne Abweichung. */
|
||||
export function viewportVariantLabel(project: Project, vp: Layout["viewports"][number], sheet: { w: number; h: number }): { text: string; x: number; y: number; sizeMm: number } | null {
|
||||
const suffix = viewportVariantSuffix(project, vp);
|
||||
if (!suffix) return null;
|
||||
const { sizeMm, dyMm } = scaleLabelMetrics(sheet);
|
||||
return { text: suffix, x: vp.xMm, y: vp.yMm + vp.heightMm + dyMm, sizeMm };
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// [272] „Beispiel Varianten": das Demo-Haus (sampleProject) mit zwei Variantensätzen — Vorlage für Tests, die Kurzanleitung
|
||||
// (Abschnitt Varianten) und die Prüfbilder (`doc/review-272`).
|
||||
//
|
||||
// Satz „Dachform": A Flachdach (Hauptvariante, neues Dach RF2), B Satteldach (das Dach RF1 des Demo-Hauses).
|
||||
// Satz „Fassade": A Lochfenster (Nordfenster O2 des Demo-Hauses, Hauptvariante), B Bandfenster (O-band, 3.6 m breit).
|
||||
// Alles Übrige gehört zum Hauptmodell. Ein eigenes Beispiel, damit die bestehenden Goldens unverändert bleiben.
|
||||
|
||||
import type { DesignOptionSet, Opening, Project, Roof } from "./types";
|
||||
import { sampleProject } from "./sampleProject";
|
||||
|
||||
export const VARIANTEN_SETS: DesignOptionSet[] = [
|
||||
{ id: "dachform", name: "Dachform", options: [{ id: "a", name: "A Flachdach" }, { id: "b", name: "B Satteldach" }], primary: "a" },
|
||||
{ id: "fassade", name: "Fassade", options: [{ id: "a", name: "A Lochfenster" }, { id: "b", name: "B Bandfenster" }], primary: "a" },
|
||||
];
|
||||
|
||||
/** Das Varianten-Beispiel (frische Kopie bei jedem Aufruf). */
|
||||
export function buildVariantenSampleProject(): Project {
|
||||
const base = structuredClone(sampleProject);
|
||||
const rf1 = (base.roofs ?? [])[0];
|
||||
const roofs: Roof[] = [
|
||||
{ ...rf1, designOption: { set: "dachform", option: "b" } },
|
||||
{ ...rf1, id: "RF2", shape: "flach", pitchDeg: 0, overhang: 0.15, thickness: 0.3, designOption: { set: "dachform", option: "a" } },
|
||||
];
|
||||
const openings: Opening[] = (base.openings ?? []).map((o) => (o.id === "O2" ? { ...o, designOption: { set: "fassade", option: "a" } } : o));
|
||||
const o2 = (base.openings ?? []).find((o) => o.id === "O2")!;
|
||||
openings.push({ ...o2, id: "O-band", position: 0.7, width: 3.6, height: 1.0, sillHeight: 1.1, designOption: { set: "fassade", option: "b" } });
|
||||
return {
|
||||
...base,
|
||||
id: "beispiel-varianten",
|
||||
name: "Beispiel Varianten",
|
||||
roofs,
|
||||
openings,
|
||||
designOptionSets: structuredClone(VARIANTEN_SETS),
|
||||
};
|
||||
}
|
||||
@@ -224,6 +224,10 @@ export type Ceiling = {
|
||||
bottom?: VerticalAnchor;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -331,6 +335,10 @@ export type Column = {
|
||||
hatchSource?: AttributeSource;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -667,6 +675,29 @@ export type CustomPalette = {
|
||||
visible?: boolean;
|
||||
};
|
||||
|
||||
/** [272] Eine Variante eines Satzes (z. B. „A Flachdach“). */
|
||||
export type DesignOption = { id: string; name: string };
|
||||
|
||||
/** [272] Zugehörigkeit eines Elements zu einer Variante (Archicad „Design Options“). */
|
||||
export type DesignOptionRef = {
|
||||
/** Id des Variantensatzes (`DesignOptionSet.id`). */
|
||||
set: string;
|
||||
/** Id der Variante im Satz (`DesignOption.id`). */
|
||||
option: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* [272] Ein Variantensatz (z. B. „Dachform“) mit seinen Varianten; je Darstellung ist genau eine Variante des
|
||||
* Satzes sichtbar (Vorgabe: die Hauptvariante).
|
||||
*/
|
||||
export type DesignOptionSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
options: Array<DesignOption>;
|
||||
/** Id der Hauptvariante. Fehlt/unbekannt ⇒ die erste Variante. */
|
||||
primary?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Detailgrad der Darstellung (≙ DOSSIER Einfach/Standard/Detail). Wirkt im
|
||||
* Grundriss auf Tür-/Fenstersymbole + Schraffuren/Linienfeinheit (siehe
|
||||
@@ -1010,6 +1041,10 @@ export type Drawing2D = {
|
||||
* Verhalten (ohne `hatchId` keine Schraffur).
|
||||
*/
|
||||
hatchSource?: AttributeSource;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/** Geometrie eines 2D-Zeichenelements (Tag `shape`). */
|
||||
@@ -1407,6 +1442,8 @@ export type DrawingLevel = {
|
||||
* noch, Abbruch späterer Etappen steht noch als Bestand. Fehlt ⇒ alle Etappen.
|
||||
*/
|
||||
renovationPhase?: string;
|
||||
/** [272] Variantenkombination: Satz-Id → Varianten-Id (fehlende Sätze ⇒ Hauptvariante). */
|
||||
designOptions?: { [key in string]: string };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1557,6 +1594,10 @@ export type ExtrudedSolid = {
|
||||
componentId?: string;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2161,6 +2202,10 @@ export type LayoutViewport = {
|
||||
* gleicher ±0.00 stehen und Kontext ausserhalb des Rahmens beschnitten wird.
|
||||
*/
|
||||
center?: Vec2;
|
||||
/**
|
||||
* [272] Variantenkombination des Viewports (über der des Ausschnitts): Satz-Id → Varianten-Id (fehlende Sätze ⇒ Hauptvariante).
|
||||
*/
|
||||
designOptions?: { [key in string]: string };
|
||||
};
|
||||
|
||||
/** Linienenden aller Striche im Plan/Schnitt/Ansicht und in den Exporten ([146]); fehlt = flach. */
|
||||
@@ -2799,6 +2844,10 @@ export type Opening = {
|
||||
* [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand wie die Wand (eine neue Öffnung in einer Bestandswand bricht die Wand dort ab, eine Öffnung „Abbruch“ wird zugemauert).
|
||||
*/
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -3255,6 +3304,11 @@ export type Project = {
|
||||
};
|
||||
/** [271] Umbau: Etappen, Farben je Status (SIA 400) und eigene Umbaufilter. */
|
||||
renovation?: RenovationSettings;
|
||||
/**
|
||||
* [272] Variantensätze (Archicad „Design Options“): Elemente mit `designOption` erscheinen nur in der
|
||||
* Kombination ihrer Variante.
|
||||
*/
|
||||
designOptionSets?: Array<DesignOptionSet>;
|
||||
};
|
||||
|
||||
/** Protokolleintrag einer Publikation ([79]): Datum, Blätter mit Revision, erzeugte Dateien. */
|
||||
@@ -3505,6 +3559,10 @@ export type Roof = {
|
||||
parapetComponentId?: string;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -3609,6 +3667,10 @@ export type Room = {
|
||||
* [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand (nur Sichtbarkeit und Flächen je Zustand, keine Umbau-Farbe: ein Raum ist kein Bauteil).
|
||||
*/
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -4019,6 +4081,10 @@ export type Stair = {
|
||||
postDepth?: number;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -4395,6 +4461,8 @@ export type ViewSnapshot = {
|
||||
* noch, Abbruch späterer Etappen steht noch als Bestand. Fehlt ⇒ alle Etappen.
|
||||
*/
|
||||
renovationPhase?: string;
|
||||
/** [272] Variantenkombination: Satz-Id → Varianten-Id (fehlende Sätze ⇒ Hauptvariante). */
|
||||
designOptions?: { [key in string]: string };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -4466,6 +4534,8 @@ export type ViewTemplate = {
|
||||
* noch, Abbruch späterer Etappen steht noch als Bestand. Fehlt ⇒ alle Etappen.
|
||||
*/
|
||||
renovationPhase?: string;
|
||||
/** [272] Variantenkombination: Satz-Id → Varianten-Id (fehlende Sätze ⇒ Hauptvariante). */
|
||||
designOptions?: { [key in string]: string };
|
||||
};
|
||||
|
||||
/** Ansichtstyp eines Geschosses (wie in App). */
|
||||
@@ -4624,6 +4694,10 @@ export type Wall = {
|
||||
surfacePatternOffset?: Vec2;
|
||||
/** [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe. Fehlt ⇒ Bestand. */
|
||||
renovation?: Renovation;
|
||||
/**
|
||||
* [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
*/
|
||||
designOption?: DesignOptionRef;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user