[109][110] Merge origin/master (Fenster/Türen [105]/[106], Manifold [107], Schraffur-Strichskala); Kurven-Schraffuren im DXF mit hatch_dash

This commit is contained in:
Claude committed 2026-10-30 02:10:15 +00:00
commit d042fc9270
68 files changed
+4480 -1089

No files matched your search

+12 -4
View File
@@ -139,10 +139,18 @@ describe("generatePlan — Dächer (Dachaufsicht)", () => {
],
roofTypes: [{ id: "rt1", name: "Dach", layers: [{ componentId: "tile", thickness: 0.05 }] }],
};
const polys = generatePlan(p, "eg", visible).primitives.filter(
(pr): pr is Extract<typeof pr, { kind: "polygon" }> =>
pr.kind === "polygon" && (pr as { roofId?: string }).roofId === "R9",
);
const roofPolys = (proj: Project) =>
generatePlan(proj, "eg", visible).primitives.filter(
(pr): pr is Extract<typeof pr, { kind: "polygon" }> =>
pr.kind === "polygon" && (pr as { roofId?: string }).roofId === "R9",
);
// Dach über der Schnittebene (Schnitt 1 m, Traufe 2.6 m): nicht von oben gesehen → ohne Schraffur.
const over = roofPolys(p);
expect(over.length).toBe(1);
expect(over[0].hatch.pattern).toBe("none");
// Schnitt über dem First: Dachaufsicht mit Ansichtsschraffur.
const seen = { ...p, drawingLevels: p.drawingLevels.map((l) => (l.id === "eg" ? { ...l, cutHeight: 20 } : l)) };
const polys = roofPolys(seen);
expect(polys.length).toBe(1);
expect(polys[0].hatch.pattern).toBe("diagonal");
+26
View File
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { sampleProject } from "../model/sampleProject";
import type { Project } from "../model/types";
import { openingPreviewProject, openingPreviewSvgs } from "./openingPreview";
describe("openingPreview ([105]/[106])", () => {
it("baut ein Vorschau-Projekt mit nur der Öffnung", () => {
const mini = openingPreviewProject(sampleProject, "D1");
expect(mini?.walls).toHaveLength(1);
expect(mini?.openings?.map((o) => o.id)).toEqual(["D1"]);
expect(openingPreviewProject(sampleProject, "fehlt")).toBeNull();
});
it("liefert Grundriss, Schnitt und Ansicht als SVG; Schichteinzug ändert den Grundriss", async () => {
const svgs = await openingPreviewSvgs(sampleProject, "D1");
expect(svgs?.plan).toContain("<svg");
expect(svgs?.section).toContain("<polygon");
expect(svgs?.elevation).toContain("<polygon");
const withReveal: Project = {
...sampleProject,
openings: sampleProject.openings!.map((o) => (o.id === "D1" ? { ...o, layerReveals: [{ layer: -1, mode: "zurueck", amount: 0.05 }] } : o)),
};
const other = await openingPreviewSvgs(withReveal, "D1");
expect(other?.plan).not.toEqual(svgs?.plan);
});
});
+58
View File
@@ -0,0 +1,58 @@
// Live-Vorschau einer Öffnung für den Fenster-/Tür-Dialog ([105]/[106]): Der Kern baut ein kleines
// Projekt (Abfrage `openingPreview`, `src-tauri/core/src/opening_preview.rs`: Wirtswand mit nur dieser
// Öffnung, Schnitt quer durch die Mitte, Ansicht von aussen); Grundriss, Schnitt und Ansicht rechnen die
// gewöhnlichen Kern-Fassaden, als SVG-Text (`planToSvgString`).
import type { DetailLevel, Project } from "../model/types";
import { documentFor } from "../core/document";
import { generatePlan } from "./generatePlan";
import { computeSection, generateSectionPlan } from "./toSection";
import { generateElevationPlan } from "./toElevation";
import { planToSvgString } from "../export/planToSvgString";
export interface OpeningPreviewSvgs {
plan: string;
section: string | null;
elevation: string | null;
}
/** Vorschau-Projekt (oder `null`, wenn Öffnung/Wand fehlen). */
export function openingPreviewProject(project: Project, openingId: string): Project | null {
return documentFor(project).query<Project | null>("openingPreview", [], openingId);
}
/** Grundriss (Detailgrad `detail`), Schnitt und Ansicht der Öffnung als SVG-Text, Massstab 1:`scale`. */
export async function openingPreviewSvgs(project: Project, openingId: string, detail: DetailLevel = "fein", scale = 20): Promise<OpeningPreviewSvgs | null> {
const mini = openingPreviewProject(project, openingId);
if (!mini) return null;
const codes = new Set<string>(["", ...collectCodes(mini)]);
const opts = { scaleDenominator: scale, marginM: 0.15 };
const plan = planToSvgString(generatePlan(mini, "preview-floor", codes, undefined, detail, false, false, false, scale), opts);
const secLevel = mini.drawingLevels.find((l) => l.id === "preview-section");
const elevLevel = mini.drawingLevels.find((l) => l.id === "preview-elevation");
let section: string | null = null;
if (secLevel) {
const out = await computeSection(mini, secLevel);
if (out) section = planToSvgString(generateSectionPlan(out, false, { visibleCodes: codes, openings: true }), opts);
}
let elevation: string | null = null;
if (elevLevel) {
const p = generateElevationPlan(mini, elevLevel, { visibleCodes: codes });
if (p) elevation = planToSvgString(p, opts);
}
return { plan, section, elevation };
}
function collectCodes(p: Project): string[] {
const out: string[] = [];
for (const w of p.walls) out.push(w.categoryCode);
for (const o of p.openings ?? []) out.push(o.categoryCode);
const walk = (cats: Project["layers"]) => {
for (const c of cats) {
out.push(c.code);
walk((c as { children?: Project["layers"] }).children ?? []);
}
};
walk(p.layers);
return out;
}
+30
View File
@@ -0,0 +1,30 @@
import { describe, it, expect } from "vitest";
import { dashArrayCss, fitDashToPeriod, hatchDashVb, lineDashVb } from "./dashVb";
import { PX_PER_M } from "./geometry";
describe("Strichmuster im Modell-Raum (SVG-Pfad)", () => {
it("Linientyp: Papier-mm im Plot-Massstab, unabhängig vom Zoom = Druck-SVG", () => {
// 6 mm bei 1:50 = 0.3 m Modell — wie sceneToPrintSvg (mm auf dem Blatt bei 1:50).
const vb = lineDashVb([6, 2], 50);
expect(vb[0] / PX_PER_M).toBeCloseTo(0.3, 9);
// Unter non-scaling-stroke: Bildschirm-px = vb · meet (CSS-Variable), bei zwei Zoomstufen
// dieselbe Modell-Länge.
for (const meet of [0.5, 7]) {
const px = parseFloat(dashArrayCss(vb, true)!.match(/\* ([\d.]+)px/)![1]) * meet;
expect(px / meet / PX_PER_M).toBeCloseTo(0.3, 4);
}
expect(dashArrayCss(vb, false)).toBe("27 9");
});
it("Schraffur-Strich skaliert mit der Musterskala (wie hatch::hatch_dash)", () => {
const a = hatchDashVb([1, 0.7], 0.35);
expect(a[0]).toBeCloseTo((0.35 / 0.13), 9);
expect(hatchDashVb([1], 0.35, true)[0]).toBeCloseTo(1 / 0.13, 9);
});
it("Kachel-Anpassung: ganze Perioden je Kachel", () => {
const f = fitDashToPeriod([3, 2], 8);
expect(f[0] + f[1]).toBeCloseTo(8 / 2, 9);
expect(fitDashToPeriod([], 8)).toEqual([]);
});
});
+46
View File
@@ -0,0 +1,46 @@
// Strichmuster des SVG-Plan-Pfads in viewBox-Einheiten (Modell-Raum) — wie die Engines: Linientypen in
// Papier-mm im PLOT-Massstab (render2d `ortho::dash_scale`), Schraffur-Striche gekoppelt an die
// Musterskala (Kern `hatch::hatch_dash` × `DASH_MM_TO_M`). So bleibt der Rhythmus beim Zoomen fest und
// gleicht der Druckansicht.
import { PX_PER_M } from "./geometry";
import { DASH_MM_TO_M } from "../glPlan/glPlanHatch";
/** CSS-Variable am Plan-SVG: CSS-px je viewBox-Einheit (meet), für Muster unter `non-scaling-stroke`. */
export const PLAN_DASH_VAR = "--plan-dash-k";
const clean = (v: number): number => (Number.isFinite(v) ? Math.max(0, v) : 0);
/** Linienmuster (Papier-mm) → viewBox-Einheiten im Plot-Massstab 1:`plotN` (ohne gültiges N: 1:100). */
export function lineDashVb(dash: readonly number[], plotN: number): number[] {
const n = Number.isFinite(plotN) && plotN > 0 ? plotN : 100;
return dash.map((mm) => ((clean(mm) * n) / 1000) * PX_PER_M);
}
/** Schraffur-Strichmuster (Papier-mm des Linienstils) → viewBox-Einheiten im Musterraum. */
export function hatchDashVb(dash: readonly number[], scale: number, random = false): number[] {
const k = !random && Number.isFinite(scale) && scale > 0 ? scale : 1;
return dash.map((mm) => clean(mm) * k * DASH_MM_TO_M * PX_PER_M);
}
/**
* Muster so strecken, dass eine ganze Zahl Perioden in `period` passt (SVG-`<pattern>`-Kachel: das
* Muster beginnt in jeder Kachel neu). Leeres/entartetes Muster bleibt unverändert.
*/
export function fitDashToPeriod(vb: readonly number[], period: number): number[] {
const cycle = (vb.length % 2 ? 2 : 1) * vb.reduce((s, v) => s + v, 0);
if (!(cycle > 1e-9) || !(period > 1e-9)) return [...vb];
const k = Math.max(1, Math.round(period / cycle));
const f = period / (k * cycle);
return vb.map((v) => v * f);
}
/**
* `stroke-dasharray` als CSS-Wert. Unter `non-scaling-stroke` gilt das Muster in Bildschirm-px — dann
* über die meet-Variable am SVG zurück in den Modell-Raum (`calc(var(--plan-dash-k) * Xpx)`).
*/
export function dashArrayCss(vb: readonly number[], nonScaling: boolean): string | undefined {
if (!vb.length) return undefined;
const r = (v: number) => Math.round(v * 1e4) / 1e4;
return vb.map((v) => (nonScaling ? `calc(var(${PLAN_DASH_VAR}, 1) * ${r(v)}px)` : `${r(v)}`)).join(" ");
}
+8
View File
@@ -71,6 +71,14 @@ export function emitDrawingLineVerts(project: Project): Float32Array {
return documentFor(project).drawingLineVerts();
}
/**
* Ansichtsschraffur ([100]) auf den Flächen als Linien für render3d (`set_pattern_lines`): je Linie
* `ax ay az bx by bz r g b maske` (Welt-Meter); die Maske wählt die Ausdünnung nach Abstand.
*/
export function emitSurfacePatternLines(project: Project): Float32Array {
return documentFor(project).surfacePatternLines();
}
/**
* Nur die Wände (Rückwärts-Kompatibilität / bestehende Aufrufer). Zerlegt Wände mit Öffnungen in
* Teilquader bzw. (layered) in Schicht-Bänder. Rechnet der Kern auf dem Projekt-Dokument