[K4] S2: typisiertes Rust-Modell (generiert aus TS-Typen), Document::project(), Kennzahlen rechnen auf dem Dokument; TS-Sammler entfernt
This commit is contained in:
1 parent
8a120329ee
commit
8d4952e5d0
16 files changed
+3700
-119
No files matched your search
@@ -6,14 +6,14 @@
|
||||
// • Ausnützungs-/Überbauungsziffer nur mit `project.parcelArea` oder der Parzellengrenze (`siteRules`).
|
||||
// • Raumprogramm (`project.roomProgram`, Soll) gegen die gezeichneten Räume.
|
||||
// Exakt für Prismen/Kegelstümpfe/Kreise, Näherung sonst (Fasen/Rundungen). Raumflächen je
|
||||
// Geschoss und Kategorie, Volumen und Parzellenfläche rechnet der Rust-Kern
|
||||
// (`src-tauri/core/src/kennzahlen.rs`); die Zusammenfassung nach SIA 416 (NF/NGF/GF) bleibt bei
|
||||
// `geometry/roomArea.ts::balance`, die auch Raumstempel, Bilanz, Raumliste und IFC nutzen.
|
||||
// Geschoss und Kategorie, Volumen, Parzellenfläche und die SIA-416-Zusammenfassung rechnet der
|
||||
// Rust-Kern auf dem Projekt-Dokument (`src-tauri/core/src/kennzahlen.rs`).
|
||||
|
||||
import type { ExtrudedSolid, Project } from "../model/types";
|
||||
import { SIA_CATEGORIES, balance, polygonArea } from "../geometry/roomArea";
|
||||
import { polygonArea } from "../geometry/roomArea";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { FlatWriter } from "../geometry/coreFlat";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
export interface LevelKennzahlen {
|
||||
levelId: string;
|
||||
@@ -46,56 +46,12 @@ export function solidVolume(s: ExtrudedSolid): number {
|
||||
|
||||
const finite = (n: number): number => (Number.isFinite(n) ? n : 0);
|
||||
|
||||
/** Körper flach (`web/kennzahlen.rs`). */
|
||||
function encodeSolids(solids: ExtrudedSolid[]): Float64Array {
|
||||
const w = new FlatWriter().num(solids.length);
|
||||
for (const s of solids) {
|
||||
w.num(s.operation === "subtract" ? 1 : 0, s.circle ? s.circle.r : Number.NaN, s.height, s.taper ?? 0).ring(s.circle ? [] : s.points);
|
||||
}
|
||||
return w.done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flächen je Geschoss (SIA 416), Gebäudevolumen, Ausnützungs- und Überbauungsziffer. Rechnet der
|
||||
* Kern auf dem Projekt-Dokument (`kennzahlen.rs`, [K4] S2).
|
||||
*/
|
||||
export function computeKennzahlen(project: Project): Kennzahlen {
|
||||
const floors = project.drawingLevels
|
||||
.filter((l) => l.kind === "floor")
|
||||
.slice()
|
||||
.sort((a, b) => (a.baseElevation ?? 0) - (b.baseElevation ?? 0));
|
||||
const levelIndex = new Map<string, number>();
|
||||
floors.forEach((l, i) => levelIndex.has(l.id) || levelIndex.set(l.id, i));
|
||||
const rooms = (project.rooms ?? []).filter((r) => levelIndex.has(r.floorId));
|
||||
const rw = new FlatWriter().num(rooms.length);
|
||||
for (const r of rooms) {
|
||||
const k = SIA_CATEGORIES.indexOf(r.siaCategory);
|
||||
// Unbekannte Kategorie → Index ausserhalb, zählt im Kern nicht.
|
||||
rw.num(levelIndex.get(r.floorId)!, k < 0 ? SIA_CATEGORIES.length : k).ring(r.boundary);
|
||||
}
|
||||
const parcelRing = project.siteRules?.parcel ?? [];
|
||||
const sums = core().kz_area_sums(
|
||||
floors.length,
|
||||
rw.done(),
|
||||
encodeSolids(project.extrudedSolids ?? []),
|
||||
project.parcelArea ?? Number.NaN,
|
||||
new FlatWriter().pts(Array.isArray(parcelRing) ? parcelRing : []).done(),
|
||||
);
|
||||
const gv = sums[0];
|
||||
const parcel = Number.isNaN(sums[1]) ? null : sums[1];
|
||||
const levels: LevelKennzahlen[] = floors.map((l, i) => {
|
||||
// Kategorie-Summen als Einträge der SIA-416-Bilanz → GF und NGF.
|
||||
const b = balance(SIA_CATEGORIES.map((category, k) => ({ category, area: sums[2 + i * SIA_CATEGORIES.length + k] })));
|
||||
return { levelId: l.id, name: l.name, gf: b.byKey.GF, agf: b.byKey.NGF, rooms: rooms.filter((r) => r.floorId === l.id).length };
|
||||
});
|
||||
const gf = levels.reduce((s, l) => s + l.gf, 0);
|
||||
const agf = levels.reduce((s, l) => s + l.agf, 0);
|
||||
const footprint = levels.find((l) => l.gf > 0)?.gf ?? 0;
|
||||
return {
|
||||
levels,
|
||||
gf,
|
||||
agf,
|
||||
gv,
|
||||
footprint,
|
||||
az: parcel ? agf / parcel : null,
|
||||
uez: parcel ? footprint / parcel : null,
|
||||
};
|
||||
return documentFor(project).kennzahlen();
|
||||
}
|
||||
|
||||
export type ProgramStatus = "ok" | "zu klein" | "zu gross" | "fehlt" | "zu wenige" | "zu viele";
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import type { Project } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { diffToOps } from "./ops";
|
||||
import type { Kennzahlen } from "../analysis/kennzahlen";
|
||||
|
||||
export class ProjectDocument {
|
||||
private handle = 0;
|
||||
@@ -45,6 +46,13 @@ export class ProjectDocument {
|
||||
}
|
||||
}
|
||||
|
||||
/** Kennzahlen aus dem Kern (`kennzahlen.rs`). */
|
||||
kennzahlen(): Kennzahlen {
|
||||
const text = this.handle ? core().doc_kennzahlen(this.handle) : "";
|
||||
if (!text) throw new Error("Kennzahlen: Projekt passt nicht zum Kern-Modell");
|
||||
return JSON.parse(text) as Kennzahlen;
|
||||
}
|
||||
|
||||
/** Das Dokument als JSON-Text (Test, Export). */
|
||||
json(): string {
|
||||
return this.handle ? core().doc_json(this.handle) : "";
|
||||
@@ -55,3 +63,16 @@ export class ProjectDocument {
|
||||
this.handle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
let shared: ProjectDocument | null = null;
|
||||
|
||||
/**
|
||||
* Das gemeinsame Kern-Dokument, auf den Stand von `project` gebracht. Der Abgleich läuft über die
|
||||
* Differenz zum zuletzt gesehenen Projekt (Referenzvergleich, unveränderte Teile kosten nichts);
|
||||
* wechselt ein Aufrufer zwischen sehr verschiedenen Projekten, ist es nur langsamer, nie falsch.
|
||||
*/
|
||||
export function documentFor(project: Project): ProjectDocument {
|
||||
if (!shared) shared = new ProjectDocument(project);
|
||||
else shared.sync(project);
|
||||
return shared;
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { createStore } from "./store";
|
||||
import { ProjectDocument } from "../core/document";
|
||||
import type { StoreApi } from "./store";
|
||||
import { createProjectSlice } from "./projectSlice";
|
||||
import type { ProjectSlice } from "./projectSlice";
|
||||
@@ -65,24 +64,3 @@ export const useStore = store.useStore;
|
||||
export const getState = store.getState;
|
||||
export const setState = store.setState;
|
||||
|
||||
// Kern-Dokument ([K4] S1): spiegelt jede Änderung von `project` (Setzen, Laden, Undo/Redo) als Ops
|
||||
// in den Rust-Kern. Ohne geladenen Kern (Start, manche Tests) bleibt es aus und holt sich beim
|
||||
// nächsten Zugriff den vollen Stand.
|
||||
let coreDoc: ProjectDocument | null = null;
|
||||
|
||||
/** Das Rust-Dokument zum aktuellen Projekt (synchron nachgezogen); `null`, solange der Kern fehlt. */
|
||||
export function projectDocument(): ProjectDocument | null {
|
||||
try {
|
||||
const p = store.getState().project;
|
||||
if (!coreDoc) coreDoc = new ProjectDocument(p);
|
||||
else coreDoc.sync(p);
|
||||
return coreDoc;
|
||||
} catch {
|
||||
coreDoc = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
store.subscribe(() => {
|
||||
void projectDocument();
|
||||
});
|
||||
Reference in new issue
Block a user