[K4] Merge: Griffe und Objekt-Info im Kern (grips.rs, selection_info.rs), 3D-Griffhöhen
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
46 files changed
+3352
-2427
No files matched your search
@@ -615,6 +615,67 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern
|
||||
(5) `model/wall.ts` (vertikale Ausdehnungen, Aufrufer in `toSection`/`voids`/Viewport — fallen mit dem Plan-Port);
|
||||
(6) `model/geometry.ts` (`wallBand`/`wallCorners`/`clippedBand`, Aufrufer in Werkzeugen/Fang), `model/color.ts`
|
||||
(Farbraum-Umrechnung der UI), `state/viewSnapshots.ts`/`visibilitySets.ts` (UI-Zustand, localStorage).
|
||||
**Griffe im Kern (29.10.)** — erledigt damit (3) und aus (2) die Dicken: `grips.rs` (vorher ~800 Zeilen in `projectSlice.ts`
|
||||
und `state/edgeGrips.ts`): Eckpunkt-Griff (`moveGrip`: Wand, alle 2D-Formen inkl. Bogen-Mitten-Griff der Polylinie,
|
||||
Masslinien-Offset und Masszahl mit Einrasten, Textpfad/Hinweislinie/Spaltenbreite, Kreis↔Ellipse), Verschieben, Kante
|
||||
winkeltreu (`movePolygonEdge`), Grösse um einen Anker (`resizeGeom`), Decke/Dach/Treppe/Raum (Griff, Verschieben, Kante,
|
||||
Stempel), Polylinien-Punkt einfügen/löschen, Dicke einschichtiger Wände/Decken (id und Name eines neuen Typs gibt die
|
||||
Hülle mit: `Date.now()`, `t()`). Rechnung auf der rohen Wurzel (unbekannte Felder, Schlüsselreihenfolge bleiben). Die
|
||||
Store-Aktionen behalten ihre Signatur; je Mausschritt EIN Kern-Aufruf `doc_grip_commit` (rechnen, prüfen, Verlauf —
|
||||
`ProjectDocument.commitGrip`), TS führt die Leseansicht mit den gelieferten Ops nach (NaN-Marken werden wieder Zahlen,
|
||||
`fromMarkedJson`); die Wurzel-Abfrage `gripOps` rechnet ohne Anwenden. Griff-Listen (`drawingVertices`, `ringEdges`/
|
||||
`openEdges`/`polylineEdgeGrips`) über die Fassade `geometry/grips.ts` (Polylinie als flacher Puffer, sonst Element-JSON);
|
||||
die Rahmen-Ecken einer Textspalte bleiben in TS (Schrift-Metrik, `textFrameCorners`). Gelöscht: die TS-Rechnung,
|
||||
`state/edgeGrips.ts`, `dimTextFrame`/`dimTextPos`/`dimTextOffsetFromPoint`/`mmToModel`/`modelToMm` (`model/dimension.ts` hält
|
||||
nur noch die Konstanten) und die Bindung `dim_text_frame`. Gleichheit (einmalig, Test gelöscht): 790 000 Zufalls-Änderungen
|
||||
über 15 000 Projekte (alle Formen, entartete Geometrie, NaN/±∞ in den Eingaben, Bögen, LV95) — Ops zeichengleich zur alten
|
||||
Fassung; 19 800 Griff-Listen samt Kanten-Griffen bitgleich; 11 000 Store-Schritte (Leseansicht, Undo-Tiefe, Kern ==
|
||||
Leseansicht). Abweichungen (gewollt): ein Griff-Index ohne Punkt (negativ, gebrochen, zu gross) ändert nichts (TS warf beim
|
||||
Lesen von `undefined`, 38 000 der Zufallsfälle); gerechnet wird auf dem Dokument — ein dort als `null` gespeichertes NaN
|
||||
rechnet wie `null` in JS (0) und kommt als `null` in die Leseansicht (vorher blieb dort NaN); Griff-Listen liefern −0 als 0.
|
||||
Messung (vitest, Store, 3000 Wände + 2000 Polylinien, alt/neu abwechselnd, kleinster Wert aus drei Läufen, Container unter
|
||||
Last; Stand nach dem Nachtrag unten): Wand-Griff an Position 10/1500/2990 32/150/315 µs → 28/116/262 µs (dominiert von der
|
||||
linearen id-Suche), Polylinien-Griff 78 → 58 µs, Polylinien-Kante 72 → 57 µs, Wand verschieben 131 → 115 µs, Griff an einer
|
||||
5000-Punkte-Polylinie 13,7 → 9,1 ms; Griff-Liste der 5000-Punkte-Polylinie 2,7 → 1,1 ms (kleine Polylinie 2 µs, gleich).
|
||||
Nicht in der Tauri-App geprüft (vitest/Linux, e2e im Browser). Offen: `setPolylineVertexType`
|
||||
(rechnet in `geometry/polylineVertexType.ts`), die lineare id-Suche je Mausschritt (im Kern beim Rechnen und beim Commit,
|
||||
in TS in `applyOps`) und der Commit grosser Polylinien (~9 ms bei 5000 Punkten: Verlauf/Prüfung in `document.rs`/`ops.rs`).
|
||||
**Objekt-Info im Kern (29.10.)** — erledigt damit (4): `selection_info.rs` (vorher `deriveSelection` in `state/selectionInfo.ts`,
|
||||
~800 Zeilen Rechnung) liefert als Wurzel-Abfrage `selectionInfo` den Kontrakt `Selection` für das erste gewählte Element
|
||||
(Vorrang wie bisher): effektive Farbe/Strichstärke/Schraffur/Vorder-/Hintergrund (Element → Linienstil → Ebene → Bauteil),
|
||||
bbox, Wand (Referenzlinie, Fugen der Schichten, Typ-Liste mit `wallTypeLabel`, Geschosse, Geschoss darüber, UK/OK, Länge,
|
||||
Brutto-/Öffnungs-/Nettovolumen), Decke (Typ, Fläche, Volumen, Aussparungen), Dach (Firsthöhe aus `roof.rs`, Kantenliste
|
||||
`roofEdgeList`, Höfe), Öffnung (Lücke `opening_geom`, UK/OK), Treppe (`stair.rs`), Raum, Extrusion, Stütze, Kontext-Objekt
|
||||
(LV95-Mitte), Detailverweis; `geomBBox` (auch für Ausrichten/Verteilen: Abfrage `drawingBBoxes`, `editors/align.ts`). Rechnung
|
||||
auf der rohen Wurzel (verlustfrei, Schlüsselreihenfolge wie die früheren Objekt-Literale, keine typisierte Sicht des ganzen
|
||||
Projekts); nur Dach/Treppe/Stütze werden für die schon typisierte Geometrie einzeln gelesen. Die Antwort wird direkt als Text
|
||||
geschrieben; Felder kleiner Objekte linear gesucht statt über den SipHash der `IndexMap` (`grips::field`, auch in den Griffen);
|
||||
die Fassade gibt die Lage des Elements aus der Leseansicht mit (spart dem Kern die lineare Suche). `state/selectionInfo.ts`
|
||||
hält den Kontrakt (Typen) und die Fassade; die B-Rep-Beschreibung einer Extrusion (`spec`, truck) setzt sie aus
|
||||
`extrudedSolidSpec`. `js_fmt::to_fixed` hat einen Schnellweg (nur exakte Halbwerte gehen den langen, genauen Weg; Test
|
||||
gegen den genauen Weg über 1,6 Mio. Werte). Gelöscht: die TS-Rechnung, `geomBBox`. Gleichheit (einmalig, Test gelöscht):
|
||||
174 360 Auswahlen über 10 000 Zufallsprojekte (alle Bauteilarten, fehlende/null-Felder, Bindungen UK/OK, unbekannte
|
||||
Typen/Bauteile, LV95, mehrere Arten gleichzeitig) zeichengleich zur alten Fassung (JSON mit NaN-Marken), 20 489 Fälle mit
|
||||
derselben Fehlermeldung; Beispielprojekt alle Elemente; 24 000 Ausrichten/Verteilen-Fälle gleich. Abweichung (gewollt): ein
|
||||
Element, das das Kern-Modell nicht lesen kann (Dach/Treppe/Stütze mit kaputten Pflichtfeldern), ergibt `null` mit Warnung
|
||||
statt eines Werts. Messung (vitest, Store mit 3000 Wänden und 20 000 Zeichnungen, Container unter Last): Wand 36–67 →
|
||||
96–138 µs, Zeichnung (Position 10 000) 150–300 → 160–390 µs, Dach 5 → 30–60 µs (TS merkte sich die Dachgeometrie je
|
||||
Objekt; im Kern ist sie für die letzten 16 Dächer gemerkt, der Rest ist die JSON-Übergabe), Griff-Schritt samt Objekt-Info
|
||||
1,6–2,6 ms → 1,5–2,4 ms; je Darstellung also ~0,05 ms mehr. Nicht in der Tauri-App geprüft.
|
||||
**Höhen und Wand-Bänder (29.10.)** — zu (5)/(6): die 3D-Griffe (`Wasm3DViewport`: Griff-Lagen, Arbeitsebene beim Ziehen)
|
||||
holen UK/OK von Wänden und Decken über die Wurzel-Abfrage `verticalExtents` (`selection_info.rs`, dieselbe Rechnung wie die
|
||||
Objekt-Info; Fassade `verticalExtents` in `geometry/grips.ts`, ganze Elemente, auch gerade gezogene Fassungen). Gleichheit
|
||||
(einmalig, Test gelöscht): 480 000 Höhen über 20 000 Zufallsfälle (Bindungen UK/OK, fehlende Geschosse/Typen, NaN/±∞/null
|
||||
in den Elementen) gleich `wallVerticalExtent`/`ceilingVerticalExtent` (−0 kommt als 0). Gelöscht, weil ohne Aufrufer:
|
||||
`lineIntersect`/`clippedBand`/`Line`/`wallBand` (`model/geometry.ts`, `wallCorners` rechnet das Band selbst),
|
||||
`stairVerticalExtent`/`nextFloorAbove` (`model/wall.ts`), `openingGapQuad`, `roofBBox`, `stairBBox` samt Bindung
|
||||
`stair_bbox_flat`, `outlineBBox`, `localToLv95`, `roofEdgeList` (Kantenliste nur noch im Kern; Test über `deriveSelection`;
|
||||
`setRoofEdge` zählt die Kanten direkt). Bleibt in TS: `wallVerticalExtent`/`ceilingVerticalExtent`/`columnVerticalExtent`/
|
||||
`openingVerticalExtent` nur noch für die Plan-Ableitung (`toSection`, `voids`, `sectionOpenings`, `toElevation` — fallen mit
|
||||
deren Port; im Kern gibt es die Regeln doppelt: roh in `selection_info.rs`, typisiert in `model/helpers.rs`, beim Plan-Port
|
||||
zusammenlegen); `wallCorners` (Plan-Treffer `planHitTest`, Werkzeug-Vorschau, Griff-Vorschau, `voids`, STEP-Export — ein
|
||||
Kern-Aufruf je Wand wäre teurer als die vier Punkte) und `wallReferenceOffset` (Fang, `geometry/opening.ts`). Nicht in
|
||||
der Tauri-App geprüft (3D-Griffe nur über e2e im Browser).
|
||||
- ◐ **S4 Typen aus Rust**: `types.ts` wird aus den Rust-Strukturen erzeugt (ts-rs); Datei-I/O (`projectFormat`, Migration, IFC/DXF/
|
||||
STEP-Ex- und -Import) im Kern.
|
||||
**Typen (28.10.):** Das Rust-Modell (`core/src/model/generated.rs`, `manual.rs`) ist die Quelle; ts-rs 12 (MIT, nur
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -15,6 +15,30 @@ pub fn to_fixed(x: f64, d: usize) -> String {
|
||||
if ax >= 1e21 {
|
||||
return format!("{}{}", if neg { "-" } else { "" }, ax);
|
||||
}
|
||||
// Schnellweg: Rust rundet `{:.N}` korrekt (zum geraden Nachbarn nur bei exakten Halbwerten); ohne
|
||||
// exakten Halbwert ist das Ergebnis dasselbe wie in JS, nur ohne die teure lange Formatierung.
|
||||
if !exact_half(ax, d) {
|
||||
let s = format!("{:.*}", d, ax);
|
||||
return if neg { format!("-{s}") } else { s };
|
||||
}
|
||||
to_fixed_wide(ax, d, neg)
|
||||
}
|
||||
|
||||
/// Ob `ax` (endlich, ≥ 0) bei `d` Nachkommastellen genau auf der Mitte zwischen zwei Ergebnissen liegt:
|
||||
/// `ax · 10^d · 2` ist eine ungerade ganze Zahl, d. h. das niedrigste gesetzte Bit von `ax` ist 2^-(d+1).
|
||||
fn exact_half(ax: f64, d: usize) -> bool {
|
||||
if ax == 0.0 {
|
||||
return false;
|
||||
}
|
||||
let bits = ax.to_bits();
|
||||
let exp = ((bits >> 52) & 0x7ff) as i64;
|
||||
let frac = bits & ((1u64 << 52) - 1);
|
||||
let (m, e) = if exp == 0 { (frac, -1074) } else { (frac | (1u64 << 52), exp - 1075) };
|
||||
e + m.trailing_zeros() as i64 + d as i64 + 1 == 0
|
||||
}
|
||||
|
||||
/// Langsamer, exakter Weg (für exakte Halbwerte): Ziffern mit 25 Stellen Reserve, dann aufrunden.
|
||||
fn to_fixed_wide(ax: f64, d: usize, neg: bool) -> String {
|
||||
// 25 Stellen mehr als nötig: ein exakter Halbwert zeigt sich als '5' gefolgt von Nullen.
|
||||
let wide = format!("{:.*}", d + 25, ax);
|
||||
let (int_part, frac) = wide.split_once('.').expect("Nachkommastellen");
|
||||
@@ -119,5 +143,30 @@ mod tests {
|
||||
assert_eq!(to_fixed(123.456, 2), "123.46");
|
||||
assert_eq!(to_fixed(2.675, 2), "2.67"); // 2.675 ist binär 2.67499999… — JS: "2.67"
|
||||
assert_eq!(to_fixed(1e-9, 6), "0.000000");
|
||||
assert_eq!(to_fixed(0.25, 1), "0.3");
|
||||
assert_eq!(to_fixed(-0.25, 1), "-0.3");
|
||||
assert_eq!(to_fixed(-0.0, 2), "0.00");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schnellweg_gleich_dem_genauen_weg() {
|
||||
let mut x: u64 = 0x2545_f491_4f6c_dd1d;
|
||||
for i in 0..200_000 {
|
||||
x ^= x << 13;
|
||||
x ^= x >> 7;
|
||||
x ^= x << 17;
|
||||
let v = match i % 4 {
|
||||
0 => (x % 1_000_000) as f64 / 1000.0,
|
||||
1 => f64::from_bits(x) % 1e6,
|
||||
2 => (x % 4096) as f64 / 64.0,
|
||||
_ => (x as f64 / u64::MAX as f64 - 0.5) * 100.0,
|
||||
};
|
||||
if !v.is_finite() {
|
||||
continue;
|
||||
}
|
||||
for d in 0..8 {
|
||||
assert_eq!(to_fixed(v, d), to_fixed_wide(v.abs(), d, v < 0.0), "{v} {d}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,8 @@ pub mod ugrid;
|
||||
pub mod wasm_alloc;
|
||||
pub mod text_layout;
|
||||
pub mod plan_text;
|
||||
pub mod grips;
|
||||
pub mod selection_info;
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
@@ -98,6 +98,27 @@ pub fn run_root(root: &serde_json::Map<String, serde_json::Value>, name: &str, t
|
||||
let m: crate::groups::Membership = serde_json::from_str(text).map_err(|e| format!("selectionFilterPatch: {e}"))?;
|
||||
json(&crate::selection_filter::filter_patch(root, &m))
|
||||
}
|
||||
// Griff-Änderungen ([K4] S3, `grips.rs`): `text` = JSON der Anfrage; Antwort `{ops, notice}` (ohne Commit).
|
||||
"gripOps" => {
|
||||
let req: crate::grips::Request = serde_json::from_str(text).map_err(|e| format!("gripOps: {e}"))?;
|
||||
Ok(crate::grips::result_json(&crate::grips::run(root, &req)?))
|
||||
}
|
||||
// Objekt-Info der Auswahl ([K4] S3, `selection_info.rs`): `text` = JSON der gewählten ids je Art; Antwort
|
||||
// `Selection` (TS) oder null, Zahlen mit Nicht-endlich-Marken.
|
||||
"selectionInfo" => {
|
||||
let a: crate::selection_info::SelArgs = serde_json::from_str(text).map_err(|e| format!("selectionInfo: {e}"))?;
|
||||
crate::selection_info::derive(root, &a).map(crate::selection_info::J::into_string)
|
||||
}
|
||||
// Bounding-Boxen von Zeichnungen (Ausrichten/Verteilen): `text` = JSON der ids.
|
||||
"drawingBBoxes" => {
|
||||
let ids: Vec<String> = serde_json::from_str(text).map_err(|e| format!("drawingBBoxes: {e}"))?;
|
||||
Ok(crate::selection_info::drawing_bboxes(root, &ids).into_string())
|
||||
}
|
||||
// UK/OK von Wänden und Decken (3D-Griffe): `text` = `{walls: […], ceilings: […]}` (ganze Elemente).
|
||||
"verticalExtents" => {
|
||||
let a: crate::selection_info::ExtentArgs = serde_json::from_str(text).map_err(|e| format!("verticalExtents: {e}"))?;
|
||||
Ok(crate::selection_info::vertical_extents(root, &a).into_string())
|
||||
}
|
||||
_ => Err(format!("Unbekannte Wurzel-Abfrage: {name}")),
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,16 +0,0 @@
|
||||
//! Bindungen der 2D-Zeichnungen im Grundriss (`crate::plan::drawings`). Die Plan-Primitive selbst
|
||||
//! kommen über die Dokument-Abfragen (`planDomains`, `drawingPrims`, `drawingLines`).
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Lage der Masszahl eines Mass-Segments `[baseX, baseY, readX, readY, upX, upY, angle]`
|
||||
/// (`dimTextFrame`, geteilt von Plan und Masszahl-Griff); leer bei NaN/∞.
|
||||
#[wasm_bindgen]
|
||||
pub fn dim_text_frame(ax: f64, ay: f64, bx: f64, by: f64, offset: f64, text_height: f64) -> Vec<f64> {
|
||||
if ![ax, ay, bx, by, offset, text_height].iter().all(|v| v.is_finite()) {
|
||||
return Vec::new();
|
||||
}
|
||||
let v = |x, y| crate::model::Vec2 { x, y };
|
||||
let (base, read, up, angle) = crate::plan::drawings::dim_text_frame(v(ax, ay), v(bx, by), offset, text_height);
|
||||
vec![base.x, base.y, read.x, read.y, up.x, up.y, angle]
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//! Bindungen der Griff-Geometrie (`crate::grips`): Griff-Änderung im Dokument rechnen und gleich als
|
||||
//! Benutzer-Änderung anwenden (ein Aufruf je Mausschritt, keine Op-Übergabe hin und zurück), Griff-
|
||||
//! und Kanten-Listen für die Anzeige als flache Puffer.
|
||||
|
||||
use super::document::with_doc;
|
||||
use serde_json::{json, Value};
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Griff-Änderung `req_json` (s. `crate::grips::run`) auf dem Dokument `h` rechnen und mit Verlauf
|
||||
/// anwenden (`key` = coalesceKey, `now_ms` = Zeit für das Koaleszenz-Fenster, wie `doc_commit`).
|
||||
/// Antwort: `{"ops":[…],"notice":…}` (angewendet; leer = nichts zu tun) oder `{"problems":[…]}`
|
||||
/// (zurückgewiesen, Dokument unverändert); Fehler als Text mit vorangestelltem `\u{1}`.
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_grip_commit(h: u32, req_json: &str, key: &str, now_ms: f64) -> String {
|
||||
let req: crate::grips::Request = match serde_json::from_str(req_json) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return format!("\u{1}Griff-Anfrage: {e}"),
|
||||
};
|
||||
let key = (!key.is_empty()).then_some(key);
|
||||
let now = if now_ms.is_finite() { now_ms } else { 0.0 };
|
||||
let out = with_doc(h, |d| -> Result<String, String> {
|
||||
let res = crate::grips::run(d.root(), &req)?;
|
||||
let text = crate::grips::result_json(&res);
|
||||
if res.ops.is_empty() {
|
||||
return Ok(text);
|
||||
}
|
||||
// Nicht endliche Ergebnisse stehen als Marken in den Ops (die Prüfung weist sie zurück).
|
||||
let marks = text.contains("\\u0001");
|
||||
match d.commit(res.ops, key, now, marks) {
|
||||
Ok(()) => Ok(text),
|
||||
Err(problems) => Ok(json!({ "problems": problems }).to_string()),
|
||||
}
|
||||
});
|
||||
match out {
|
||||
Some(Ok(t)) => t,
|
||||
Some(Err(e)) => format!("\u{1}{e}"),
|
||||
None => "\u{1}Dokument nicht offen".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Editier-Griffe einer 2D-Zeichnung (JSON) beim Massstab 1:`scale`: `[n, x0, y0, …]`; `[-1]` = Textspalte
|
||||
/// (Rahmen-Ecken rechnet die Hülle mit der Schrift-Metrik), `[]` bei kaputtem JSON.
|
||||
#[wasm_bindgen]
|
||||
pub fn grip_vertices(drawing_json: &str, scale: f64) -> Vec<f64> {
|
||||
let Ok(d) = serde_json::from_str::<Value>(drawing_json) else { return vec![] };
|
||||
let g = d.get("geom").unwrap_or(&d);
|
||||
match crate::grips::drawing_vertices(g, scale) {
|
||||
None => vec![-1.0],
|
||||
Some(v) => {
|
||||
let mut out = Vec::with_capacity(1 + 2 * v.len());
|
||||
out.push(v.len() as f64);
|
||||
for p in v {
|
||||
out.push(p.0);
|
||||
out.push(p.1);
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Editier-Griffe einer Polylinie aus flachen Puffern (grosse Kataster-Umrisse ohne JSON): `pts = [x0, y0, …]`,
|
||||
/// `bulge` je Segment (fehlend/NaN = gerade) → `[x0, y0, …]` (Eckpunkte, dann je Segment die Bogen-Mitte).
|
||||
#[wasm_bindgen]
|
||||
pub fn grip_vertices_polyline(pts: &[f64], bulge: &[f64], closed: bool) -> Vec<f64> {
|
||||
let verts: Vec<(f64, f64)> = pts.chunks_exact(2).map(|c| (c[0], c[1])).collect();
|
||||
crate::grips::polyline_vertices(verts, closed, |i| bulge.get(i).copied().unwrap_or(0.0)).into_iter().flat_map(|p| [p.0, p.1]).collect()
|
||||
}
|
||||
|
||||
/// Kanten-Griffe eines Rings (`closed`) bzw. einer Kette aus `pts = [x0, y0, …]`; `bulge` je Segment
|
||||
/// nur bei `use_bulge` (Polylinie: Bogen-Segmente ohne Kanten-Griff). Antwort je Kante
|
||||
/// `[a, b, mitteX, mitteY, normaleX, normaleY]`.
|
||||
#[wasm_bindgen]
|
||||
pub fn edge_grips(pts: &[f64], closed: bool, bulge: &[f64], use_bulge: bool) -> Vec<f64> {
|
||||
let verts: Vec<(f64, f64)> = pts.chunks_exact(2).map(|c| (c[0], c[1])).collect();
|
||||
let edges = crate::grips::edge_grips(&verts, closed, use_bulge.then_some(bulge));
|
||||
let mut out = Vec::with_capacity(6 * edges.len());
|
||||
for (a, b, m, n) in edges {
|
||||
out.extend([a as f64, b as f64, m.0, m.1, n.0, n.1]);
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -32,13 +32,13 @@ mod snap;
|
||||
mod plan_svg;
|
||||
mod plan_dxf;
|
||||
mod plan_print_svg;
|
||||
mod drawings;
|
||||
mod layers;
|
||||
mod pens;
|
||||
mod layout_model;
|
||||
mod parametric_walls;
|
||||
mod reorder;
|
||||
mod text_layout;
|
||||
mod grips;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
|
||||
@@ -21,12 +21,6 @@ pub fn stair_cut_flat(geometry: &[f64], cut_rise: f64) -> Vec<f64> {
|
||||
s::cut(geometry, cut_rise)
|
||||
}
|
||||
|
||||
/// `[minX, minY, maxX, maxY]` aller Tritte + Podest.
|
||||
#[wasm_bindgen]
|
||||
pub fn stair_bbox_flat(geometry: &[f64]) -> Vec<f64> {
|
||||
s::bbox(geometry)
|
||||
}
|
||||
|
||||
/// Vorgabe-Stufenzahl aus Steighöhe und Lauflänge.
|
||||
#[wasm_bindgen]
|
||||
pub fn stair_default_step_count(total_rise: f64, run_length: f64) -> u32 {
|
||||
|
||||
+1
-1
@@ -1254,7 +1254,7 @@ export default function App() {
|
||||
for (const id of selectedSectionLineIds) patchLevel(id, { linePoints: undefined });
|
||||
}
|
||||
// Objekt-Sperre: gesperrte Elemente aus der Löschung ausnehmen (s.
|
||||
// `moveGrip`/`moveElementBy` in projectSlice.ts für dieselbe Prüfung
|
||||
// `moveGrip`/`moveElementBy` im Kern, `grips.rs`, für dieselbe Prüfung
|
||||
// beim Ziehen). ExtrudedSolid/Kontext-Objekte haben kein `locked`-Feld
|
||||
// (s. deren Typdefinitionen) — bleiben ungefiltert.
|
||||
const notLocked = (kind: MemberKind, ids: string[]) =>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// • Achse (gedreht): Zentrum + Hauptachse + Nebenachse — beliebig gedrehte
|
||||
// Ellipse. `rotation` existiert im Modell seit Langem (Rendering +
|
||||
// Griff-Editieren lesen es bereits, s. `plan/drawings.rs` im Kern
|
||||
// Z. 448 bzw. `projectSlice.ts` `drawingVertices`), nur die Erzeugung
|
||||
// Z. 448 bzw. `grips.rs` `drawing_vertices`), nur die Erzeugung
|
||||
// setzte es bisher immer auf 0.
|
||||
// 1) „Zentrum:" → Punkt
|
||||
// 2) „Hauptachse:" → Punkt (Richtung + rx = Abstand zum Zentrum)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import type { Project } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { applyOps, opsToJson } from "./ops";
|
||||
import { fromMarkedJson, toMarkedJson } from "./ops";
|
||||
import type { CoreOp } from "./ops";
|
||||
import { fieldOps } from "./opsBuild";
|
||||
|
||||
@@ -238,6 +239,44 @@ export class ProjectDocument {
|
||||
return { project };
|
||||
}
|
||||
|
||||
/**
|
||||
* Griff-Änderung ([K4] S3, `grips.rs`): der Kern rechnet `req` (s. `GripRequest`) auf seinem Stand
|
||||
* von `base` und wendet das Ergebnis wie {@link commit} an — ein Aufruf je Mausschritt. Ergebnis:
|
||||
* neues Projekt und die angewendeten Ops (leer = nichts zu tun, dann `project === base`), ein
|
||||
* Hinweis-Schlüssel (i18n) oder die Meldungen der Prüfung (dann bleibt alles unverändert).
|
||||
*/
|
||||
commitGrip(base: Project, req: object, coalesceKey: string | undefined, now: number): { project: Project; ops: CoreOp[]; notice?: string } | { problems: string[] } {
|
||||
this.ensure(base);
|
||||
if (!this.handle) return { problems: ["Projekt-Dokument im Kern nicht offen."] };
|
||||
const out = core().doc_grip_commit(this.handle, gripJson(req), coalesceKey ?? "", now);
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
const r = fromMarkedJson<{ ops: CoreOp[]; notice?: string } | { problems: string[] }>(out);
|
||||
if ("problems" in r) return r;
|
||||
if (r.ops.length === 0) return { project: base, ops: r.ops, notice: r.notice };
|
||||
const project = applyOps(base, r.ops);
|
||||
this.mirror = project;
|
||||
return { project, ops: r.ops, notice: r.notice };
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie {@link queryRoot} für Abfragen, deren Antwort nicht endliche Zahlen als Marken trägt
|
||||
* (`selectionInfo`, `drawingBBoxes`); die Marken werden wieder Zahlen.
|
||||
*/
|
||||
queryRootMarked<T>(name: "selectionInfo" | "drawingBBoxes" | "verticalExtents", 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 fromMarkedJson<T>(out);
|
||||
}
|
||||
|
||||
/** Wie {@link commitGrip}, aber nur rechnen (ohne Anwenden): die Ops und ggf. der Hinweis. */
|
||||
gripOps(req: object): { ops: CoreOp[]; notice?: string } {
|
||||
if (!this.handle) throw new Error("Kern-Abfrage „gripOps“: Dokument nicht offen");
|
||||
const out = core().doc_query_root(this.handle, "gripOps", gripJson(req));
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
return fromMarkedJson(out);
|
||||
}
|
||||
|
||||
/** Einen Schritt zurück auf `base` (= aktuelles Projekt); `null` = nichts rückgängig zu machen. */
|
||||
undo(base: Project): Project | null {
|
||||
return this.jump(base, "doc_undo");
|
||||
@@ -295,6 +334,15 @@ export class ProjectDocument {
|
||||
}
|
||||
}
|
||||
|
||||
/** Griff-Anfrage als JSON; Marken nur bei nicht endlichen Zahlen (der Ersetzer kostet je Wert einen Aufruf). */
|
||||
function gripJson(req: object): string {
|
||||
for (const v of Object.values(req)) {
|
||||
const bad = typeof v === "number" ? !Number.isFinite(v) : Array.isArray(v) && v.some((x) => typeof x === "number" && !Number.isFinite(x));
|
||||
if (bad) return toMarkedJson(req);
|
||||
}
|
||||
return JSON.stringify(req);
|
||||
}
|
||||
|
||||
let shared: ProjectDocument | null = null;
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,3 +53,7 @@ export { addItems, fieldOps, findItem, itemsOf, opsMutation, patchItem, patchIte
|
||||
export type { EntityCollection, EntityOf, ProjectMutation } from "./opsBuild";
|
||||
export { EMPTY_MEMBERSHIP, containingGroupId, expandToGroups, isInsideActiveGroup, transitiveMembership } from "../model/groups";
|
||||
export type { GroupMembership, MemberKind } from "../model/groups";
|
||||
export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from "../geometry/grips";
|
||||
export { verticalExtents } from "../geometry/grips";
|
||||
export type { VerticalExtent } from "../geometry/grips";
|
||||
export type { GripRequest } from "../geometry/grips";
|
||||
@@ -20,7 +20,6 @@ export {
|
||||
export {
|
||||
ceilingArea,
|
||||
normalizeOutline,
|
||||
outlineBBox,
|
||||
pointInOutline,
|
||||
} from "../geometry/ceiling";
|
||||
|
||||
@@ -98,7 +97,6 @@ export {
|
||||
} from "../geometry/lineSegments";
|
||||
|
||||
export {
|
||||
openingGapQuad,
|
||||
openingVerticalExtent,
|
||||
} from "../geometry/opening";
|
||||
export { autoExteriorDimensions } from "../geometry/autoDimensions";
|
||||
@@ -122,7 +120,6 @@ export {
|
||||
} from "../geometry/revisionCloud";
|
||||
|
||||
export {
|
||||
roofBBox,
|
||||
roofBaseElevation,
|
||||
roofGeometry,
|
||||
} from "../geometry/roof";
|
||||
@@ -130,7 +127,6 @@ export {
|
||||
export {
|
||||
addRoofHole,
|
||||
removeRoofHole,
|
||||
roofEdgeList,
|
||||
roofHoleWorks,
|
||||
setRoofEdge,
|
||||
} from "../geometry/roofEdges";
|
||||
@@ -155,7 +151,6 @@ export {
|
||||
IDEAL_TREAD,
|
||||
MIN_STEPS,
|
||||
defaultStepCount,
|
||||
stairBBox,
|
||||
stairGeometry,
|
||||
stairOutline,
|
||||
} from "../geometry/stair";
|
||||
|
||||
@@ -154,6 +154,23 @@ export function opsToJson(ops: readonly CoreOp[]): string {
|
||||
return JSON.stringify(ops, markNonFinite);
|
||||
}
|
||||
|
||||
/** Wert als JSON mit Nicht-endlich-Marken (wie {@link opsToJson}), z. B. Anfragen an den Kern. */
|
||||
export function toMarkedJson(v: unknown): string {
|
||||
return JSON.stringify(v, markNonFinite);
|
||||
}
|
||||
|
||||
/** Nicht-endlich-Marken des Kerns (`"\u0001NaN"` …) zurück in Zahlen. */
|
||||
function reviveNonFinite(_key: string, v: unknown): unknown {
|
||||
if (typeof v !== "string" || v.charCodeAt(0) !== 1) return v;
|
||||
const t = v.slice(1);
|
||||
return t === "NaN" ? NaN : t === "Infinity" ? Infinity : t === "-Infinity" ? -Infinity : v;
|
||||
}
|
||||
|
||||
/** JSON des Kerns lesen; Nicht-endlich-Marken werden wieder Zahlen (nur wenn welche vorkommen). */
|
||||
export function fromMarkedJson<T>(text: string): T {
|
||||
return (text.includes("\\u0001") ? JSON.parse(text, reviveNonFinite) : JSON.parse(text)) as T;
|
||||
}
|
||||
|
||||
// ── Validierung ([7]) — im Kern (`ops.rs`) ───────────────────────────────────
|
||||
|
||||
function problemsOf(json: string): string[] {
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// `editors/explode.ts`), damit sie ohne UI testbar bleiben.
|
||||
//
|
||||
// Beides arbeitet auf den BOUNDING-BOXEN der Elemente (dieselbe Herleitung wie
|
||||
// im Attribut-Panel, s. `geomBBox`) und verschiebt sie anschliessend als
|
||||
// im Attribut-Panel: Kern `selection_info.rs::geom_bbox`, Abfrage `drawingBBoxes`) und verschiebt sie anschliessend als
|
||||
// Ganzes. Die Form selbst bleibt unangetastet — es wird nur verschoben, nie
|
||||
// skaliert oder verzerrt.
|
||||
|
||||
import type { Drawing2D, Project, Vec2 } from "../model/types";
|
||||
import { geomBBox } from "../state/selectionInfo";
|
||||
import { documentFor } from "../core/document";
|
||||
import { mvGeom, patchItems } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
|
||||
@@ -27,9 +27,11 @@ interface Boxed {
|
||||
|
||||
function boxesOf(project: Project, ids: string[]): Boxed[] {
|
||||
const wanted = new Set(ids);
|
||||
return project.drawings2d
|
||||
.filter((d) => wanted.has(d.id))
|
||||
.map((d) => ({ d, ...geomBBox(d.geom) }));
|
||||
const list = project.drawings2d.filter((d) => wanted.has(d.id));
|
||||
if (list.length === 0) return [];
|
||||
// Je Element `[id, minX, minY, maxX, maxY]`, in Listen-Reihenfolge wie `list`.
|
||||
const b = documentFor(project).queryRootMarked<[string, number, number, number, number][]>("drawingBBoxes", JSON.stringify(ids));
|
||||
return list.map((d, i) => ({ d, minX: b[i][1], minY: b[i][2], maxX: b[i][3], maxY: b[i][4] }));
|
||||
}
|
||||
|
||||
/** Ops: verschiebt die genannten Elemente um je einen eigenen Vektor. */
|
||||
|
||||
@@ -43,30 +43,6 @@ export function ceilingArea(pts: Vec2[]): number {
|
||||
return Math.abs(signedArea(pts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Achsparallele Bounding-Box eines Umrisses (Modell-Meter). Leerer/entarteter
|
||||
* Umriss → Null-Box.
|
||||
*/
|
||||
export function outlineBBox(pts: Vec2[]): {
|
||||
minX: number;
|
||||
minY: number;
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
} {
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of pts) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
||||
return { minX, minY, maxX, maxY };
|
||||
}
|
||||
|
||||
/** Schwerpunkt (Zentroid) des Umriss-Polygons (für HUD/Beschriftung). */
|
||||
export function outlineCentroid(pts: Vec2[]): Vec2 {
|
||||
const a = signedArea(pts);
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { drawingVertices, openEdges, polylineEdgeGrips, ringEdges } from "./grips";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
|
||||
// ── Bemassung: Masszahl-Griffe (Lage und Einrasten rechnet der Kern, `grips.rs`) ──
|
||||
|
||||
const dim = (pts: { x: number; y: number }[], offset: number, textOffsetsMm?: { along: number; perp: number }[]): Drawing2D =>
|
||||
({ id: "m", type: "drawing2d", levelId: "f", categoryCode: "1", geom: { shape: "dimension", pts, offset, textHeightMm: 4, ...(textOffsetsMm ? { textOffsetsMm } : {}) } }) as Drawing2D;
|
||||
const A = { x: 0, y: 0 };
|
||||
const B = { x: 4, y: 0 };
|
||||
/** Schrifthöhe 4 mm bei 1:50 in Modell-Metern. */
|
||||
const H = 0.2;
|
||||
|
||||
describe("Bemassung: Griffe der Masszahl", () => {
|
||||
it("Standardlage: mittig über der Masslinie (Offset eingerechnet), Reihenfolge Punkte · Masslinie · Zahl", () => {
|
||||
const v = drawingVertices(dim([A, B], 1), 50);
|
||||
expect(v).toHaveLength(4);
|
||||
expect(v[2]).toEqual({ x: 2, y: 1 });
|
||||
expect(v[3].x).toBeCloseTo(2, 9);
|
||||
expect(v[3].y).toBeCloseTo(1 + H * 0.6, 9);
|
||||
});
|
||||
|
||||
it("Leserichtung nie kopfüber — auch bei rückwärts laufender Kette", () => {
|
||||
const fwd = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const back = drawingVertices(dim([B, A], 0), 50)[3];
|
||||
expect(back.x).toBeCloseTo(fwd.x, 9);
|
||||
expect(back.y).toBeCloseTo(fwd.y, 9);
|
||||
});
|
||||
|
||||
it("Versatz (Papier-mm) wirkt entlang der Leserichtung und quer dazu", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
// 20 mm / 40 mm bei 1:50 = 1 m / 2 m.
|
||||
const p = drawingVertices(dim([A, B], 0, [{ along: 20, perp: 40 }]), 50)[3];
|
||||
expect(p.x).toBeCloseTo(base.x + 1, 9);
|
||||
expect(p.y).toBeCloseTo(base.y + 2, 9);
|
||||
});
|
||||
|
||||
const drag = (d: Drawing2D, pt: { x: number; y: number }) => {
|
||||
const p = { drawings2d: [d], walls: [] } as unknown as Project;
|
||||
const res = documentFor(p).gripOps({ op: "moveGrip", drawingId: "m", wallId: null, index: d.geom.shape === "dimension" ? d.geom.pts.length + 1 : 0, pt: [pt.x, pt.y], scale: 50 });
|
||||
const e = res.ops[0] as unknown as { entity: Drawing2D };
|
||||
return (e.entity.geom as { textOffsetsMm: { along: number; perp: number }[] }).textOffsetsMm[0];
|
||||
};
|
||||
|
||||
it("nahe der Standardlage rastet BEIDES auf 0 ein", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
expect(drag(dim([A, B], 0), { x: base.x + H * 0.2, y: base.y - H * 0.2 })).toEqual({ along: 0, perp: 0 });
|
||||
});
|
||||
|
||||
it("die Achsen rasten UNABHÄNGIG ein (seitlich verschoben, Höhe exakt Standard)", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const o = drag(dim([A, B], 0), { x: base.x + 1.5, y: base.y + H * 0.1 });
|
||||
expect(o.along).toBeCloseTo(30, 9);
|
||||
expect(o.perp).toBe(0);
|
||||
});
|
||||
|
||||
it("ausserhalb des Fangbereichs bleibt der gezogene Wert erhalten", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const o = drag(dim([A, B], 0), { x: base.x + 0.8, y: base.y + 0.6 });
|
||||
expect(o.along).toBeCloseTo(16, 9);
|
||||
expect(o.perp).toBeCloseTo(12, 9);
|
||||
});
|
||||
|
||||
it("Rundreise: gezogene Position → Versatz → Griff liegt wieder am Punkt", () => {
|
||||
const pt = { x: 3.1, y: 1.4 };
|
||||
const o = drag(dim([A, B], 0.5), pt);
|
||||
const back = drawingVertices(dim([A, B], 0.5, [o]), 50)[3];
|
||||
expect(back.x).toBeCloseTo(pt.x, 9);
|
||||
expect(back.y).toBeCloseTo(pt.y, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kanten-Griffe von Ringen und Ketten", () => {
|
||||
it("Ring: Normalen nach aussen, auch die Schlusskante; Kette: frei, ohne Schlusskante", () => {
|
||||
const tri = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 0, y: 3 }];
|
||||
const r = ringEdges(tri, {});
|
||||
expect(r.map((e) => [e.aIndex, e.bIndex])).toEqual([[0, 1], [1, 2], [2, 0]]);
|
||||
expect(r[0].normal.x).toBeCloseTo(0, 12);
|
||||
expect(r[0].normal.y).toBe(-1);
|
||||
expect(r[2].normal.x).toBeCloseTo(-1, 12);
|
||||
const o = openEdges(tri, { wallId: "w" });
|
||||
expect(o.map((e) => [e.aIndex, e.bIndex, e.free, e.owner?.wallId])).toEqual([[0, 1, true, "w"], [1, 2, true, "w"]]);
|
||||
expect(ringEdges(tri.slice(0, 2), {})).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
const sq = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 30, y: 0 },
|
||||
{ x: 30, y: 30 },
|
||||
{ x: 0, y: 30 },
|
||||
];
|
||||
|
||||
describe("polylineEdgeGrips", () => {
|
||||
it("geschlossen, gerade: 4 Kanten auf den Seitenmitten, Normalen nach aussen", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true }, { drawingId: "d" });
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 15, y: 0 },
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 15, y: 30 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex])).toEqual([[0, 1], [1, 2], [2, 3], [3, 0]]);
|
||||
expect(e[0].normal.y).toBeCloseTo(-1);
|
||||
expect(e[1].normal.x).toBeCloseTo(1);
|
||||
});
|
||||
|
||||
it("geschlossen mit Bögen: nur gerade Seiten, keine Kanten über die Bogen-Mitten (nichts im Innern)", () => {
|
||||
const e = polylineEdgeGrips(
|
||||
{ shape: "polyline", pts: sq, closed: true, bulge: [0.12, 0, -0.15, 0] },
|
||||
{ drawingId: "d" },
|
||||
);
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
// Lauter Bögen (Strassenparzelle): keine Kanten-Griffe.
|
||||
expect(polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true, bulge: [0.1, 0.1, 0.1, 0.1] }, {})).toEqual([]);
|
||||
});
|
||||
|
||||
it("offen: je gerades Segment ein freier Griff, ohne Schlusskante", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: false, bulge: [0, 0.3, 0] }, {});
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex, g.free])).toEqual([[0, 1, true], [2, 3, true]]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
// Griff-Geometrie der Bauteile ([K4] S3): dünne Fassade über den Rust-Kern (`src-tauri/core/src/grips.rs`,
|
||||
// Bindungen `web/grips.rs`). Die Griff-Änderungen selbst (Eckpunkt/Kante ziehen, verschieben, Grösse,
|
||||
// Decke/Dach/Treppe/Raum, Polylinien-Punkte, Dicken) rechnet der Kern auf dem Dokument und wendet sie
|
||||
// gleich an (`ProjectDocument.commitGrip`, Anfrage {@link GripRequest}); hier stehen die Griff-Listen
|
||||
// für die Anzeige (`drawingVertices`, Kanten-Griffe).
|
||||
//
|
||||
// Bewusst TS: die Rahmen-Ecken einer Textspalte (`textFrameCorners` braucht die Schrift-Metrik der
|
||||
// Hülle) — der Kern meldet dafür nur „Textspalte".
|
||||
|
||||
import type { Ceiling, Drawing2D, Drawing2DGeom, EdgeGrip, Project, Vec2, Wall } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { toMarkedJson } from "../core/ops";
|
||||
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
|
||||
import { textFrameCorners } from "../text/textFrame";
|
||||
|
||||
/** Punkt als `[x, y]` (Anfragen an den Kern). */
|
||||
type P = [number, number];
|
||||
|
||||
/** Eine Griff-Änderung für den Kern (`grips.rs::run`); Zahlen dürfen NaN/±∞ sein (Marken). */
|
||||
export type GripRequest =
|
||||
| { op: "moveGrip"; drawingId: string | null; wallId: string | null; index: number; pt: P; scale: number }
|
||||
| { op: "moveBy"; drawingId: string | null; wallId: string | null; delta: P }
|
||||
| { op: "moveEdge"; drawingId: string | null; wallId: string | null; a: number; b: number; delta: P }
|
||||
| { op: "resize"; kind: string; id: string; w: number; h: number; fx: number; fy: number }
|
||||
| { op: "ceilingGrip" | "roomGrip" | "roofGrip"; id: string; index: number; pt: P }
|
||||
| { op: "ceilingBy" | "roofBy" | "stairBy" | "roomBy" | "roomStamp"; id: string; delta: P }
|
||||
| { op: "ceilingEdge" | "roomEdge"; id: string; a: number; b: number; delta: P }
|
||||
| { op: "insertPoint"; id: string; seg: number; pt: P }
|
||||
| { op: "deletePoint"; id: string; index: number }
|
||||
| { op: "wallThickness" | "ceilingThickness"; id: string; thickness: number; newId: string; newName: string };
|
||||
|
||||
/** Punkt als Anfrage-Paar. */
|
||||
export const gripPt = (p: Vec2): P => [p.x, p.y];
|
||||
|
||||
/**
|
||||
* Editier-Griffe (Eckpunkte) eines 2D-Zeichenelements in Modell-Metern — dieselbe Reihenfolge, in der
|
||||
* der Kern einen Griff-Index auflöst (`moveGrip`). line/polyline/rect: Eckpunkte (Polylinie zusätzlich je
|
||||
* Segment ein Bogen-Mitten-Griff); Kreis Ost/Nord; Bogen Start/Ende/Mitte; Ellipse je Halbachse;
|
||||
* Bemassung Kettenpunkte · Masslinie · je Segment die Masszahl (`scaleDenominator`: Papier-Massstab, die
|
||||
* Masszahl-Lage hängt an der Schrifthöhe in Papier-mm); Text Anker · Knicke · Spitze, Pfadpunkte oder
|
||||
* die vier Rahmen-Ecken einer Textspalte.
|
||||
*/
|
||||
export function drawingVertices(d: Drawing2D, scaleDenominator: number = DEFAULT_SCALE_DENOMINATOR): Vec2[] {
|
||||
const g = d.geom;
|
||||
if (g.shape === "polyline") {
|
||||
// Flach (Kataster-Umrisse mit tausenden Punkten): ein fehlender/null-Bogen ist gerade.
|
||||
const f = core().grip_vertices_polyline(flat(g.pts), Float64Array.from(g.bulge ?? []), !!g.closed);
|
||||
const out: Vec2[] = new Array(f.length >> 1);
|
||||
for (let i = 0; i < out.length; i++) out[i] = { x: f[2 * i], y: f[2 * i + 1] };
|
||||
return out;
|
||||
}
|
||||
// NaN/±∞ als Marken (JSON hätte null daraus gemacht, das rechnet wie 0).
|
||||
const f = core().grip_vertices(toMarkedJson(g), scaleDenominator);
|
||||
if (f[0] === -1 && g.shape === "text") {
|
||||
return textFrameCorners({ at: g.at, text: g.text, heightM: g.height, angle: g.angle, marks: g.marks, doc: g.doc, wrapWidth: g.width });
|
||||
}
|
||||
const n = f[0] ?? 0;
|
||||
const out: Vec2[] = new Array(n);
|
||||
for (let i = 0; i < n; i++) out[i] = { x: f[1 + 2 * i], y: f[2 + 2 * i] };
|
||||
return out;
|
||||
}
|
||||
|
||||
type Owner = { drawingId?: string; wallId?: string };
|
||||
|
||||
function flat(verts: readonly Vec2[]): Float64Array {
|
||||
const f = new Float64Array(verts.length * 2);
|
||||
for (let i = 0; i < verts.length; i++) {
|
||||
f[2 * i] = verts[i].x;
|
||||
f[2 * i + 1] = verts[i].y;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function edges(verts: readonly Vec2[], closed: boolean, bulge: readonly number[] | null, owner: Owner): EdgeGrip[] {
|
||||
const f = core().edge_grips(flat(verts), closed, Float64Array.from(bulge ?? []), bulge !== null);
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i + 5 < f.length; i += 6) {
|
||||
const e: EdgeGrip = { mid: { x: f[i + 2], y: f[i + 3] }, normal: { x: f[i + 4], y: f[i + 5] }, aIndex: f[i], bIndex: f[i + 1] };
|
||||
if (!closed) e.free = true;
|
||||
e.owner = owner;
|
||||
out.push(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Geschlossener Ring → Kanten-Griffe mit Aussennormale (vom Eckpunkt-Mittel weg), inkl. Schlusskante. */
|
||||
export function ringEdges(verts: readonly Vec2[], owner: Owner): EdgeGrip[] {
|
||||
return edges(verts, true, null, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offene Kette (Linie/offene Polylinie) → ein Griff je Segment, OHNE Schlusskante. `normal` dient nur
|
||||
* der Darstellung (linke Normale der Kante); die Bewegung ist frei (`free: true`).
|
||||
*/
|
||||
export function openEdges(verts: readonly Vec2[], owner: Owner): EdgeGrip[] {
|
||||
return edges(verts, false, null, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanten-Griffe einer Polylinie: nur über die Eckpunkte und nur an geraden Segmenten — ein Bogen hat
|
||||
* seinen Bogen-Mitten-Griff (`drawingVertices`), die Sehnen-Mitte läge neben der Linie.
|
||||
*/
|
||||
export function polylineEdgeGrips(g: Extract<Drawing2DGeom, { shape: "polyline" }>, owner: Owner): EdgeGrip[] {
|
||||
return edges(g.pts, !!g.closed, g.bulge ?? [], owner);
|
||||
}
|
||||
|
||||
/** Unter-/Oberkante (absolutes Z, Meter) eines Bauteils. */
|
||||
export interface VerticalExtent {
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* UK/OK von Wänden und Decken aus dem Kern (`selection_info.rs::vertical_extents`, Regeln wie
|
||||
* `wallVerticalExtent`/`ceilingVerticalExtent`): Geschoss-Bindungen und Deckentypen aus `project`, die
|
||||
* Elemente selbst als ganze Fassung (auch gerade gezogene, noch nicht übernommene — 3D-Griffe).
|
||||
*/
|
||||
export function verticalExtents(
|
||||
project: Project,
|
||||
walls: readonly Wall[],
|
||||
ceilings: readonly Ceiling[] = [],
|
||||
): { walls: VerticalExtent[]; ceilings: VerticalExtent[] } {
|
||||
if (walls.length === 0 && ceilings.length === 0) return { walls: [], ceilings: [] };
|
||||
const f = documentFor(project).queryRootMarked<number[]>("verticalExtents", toMarkedJson({ walls, ceilings }));
|
||||
const at = (i: number): VerticalExtent => ({ zBottom: f[2 * i], zTop: f[2 * i + 1] });
|
||||
return { walls: walls.map((_, i) => at(i)), ceilings: ceilings.map((_, i) => at(walls.length + i)) };
|
||||
}
|
||||
+2
-25
@@ -10,9 +10,8 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { add, along, leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import { wallReferenceOffset, wallVerticalExtent } from "../model/wall";
|
||||
import { along, leftNormal, normalize, sub } from "../model/geometry";
|
||||
import { wallVerticalExtent } from "../model/wall";
|
||||
|
||||
/** Achslänge einer Wand (Meter). */
|
||||
export function wallAxisLength(wall: Wall): number {
|
||||
@@ -71,28 +70,6 @@ export function openingJambs(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Lücken-Rechteck-Ecken (über die volle Wanddicke), z. B. um im Plan die
|
||||
* Öffnung als Aussparung zu markieren (Auswahl-Highlight). Reihenfolge:
|
||||
* jambStart(+n/2) → jambEnd(+n/2) → jambEnd(−n/2) → jambStart(−n/2).
|
||||
*/
|
||||
export function openingGapQuad(project: Project, wall: Wall, o: Opening): Vec2[] | null {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return null;
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const outer = refOff + total / 2;
|
||||
const inner = refOff - total / 2;
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
return [
|
||||
add(jambStart, scale(n, outer)),
|
||||
add(jambEnd, scale(n, outer)),
|
||||
add(jambEnd, scale(n, inner)),
|
||||
add(jambStart, scale(n, inner)),
|
||||
];
|
||||
}
|
||||
|
||||
/** Mittelpunkt einer Öffnung im Grundriss (Achse) — für HUD/Auswahl-Anker. */
|
||||
export function openingCenter(wall: Wall, o: Opening): Vec2 | null {
|
||||
const iv = openingInterval(wall, o);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// Bogen-Segmente (`bulge`) werden bewusst über ihre SEHNE gemessen: für die
|
||||
// Frage „welches Segment ist gemeint" reicht das, und der eingefügte Punkt
|
||||
// landet ohnehin exakt auf dem Bogen (s. `projectSlice.insertDrawingPoint`).
|
||||
// landet ohnehin exakt auf dem Bogen (s. `insert_point` im Kern, `grips.rs`).
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { roofGeometry, roofBBox, roofUndersideAt } from "./roof";
|
||||
import { roofGeometry, roofUndersideAt } from "./roof";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
|
||||
/** Bounding-Box eines Umrisses (Prüfhilfe). */
|
||||
function roofBBox(outline: Vec2[]): { x0: number; y0: number; x1: number; y1: number } {
|
||||
const xs = outline.map((p) => p.x);
|
||||
const ys = outline.map((p) => p.y);
|
||||
return { x0: Math.min(...xs), y0: Math.min(...ys), x1: Math.max(...xs), y1: Math.max(...ys) };
|
||||
}
|
||||
|
||||
// Rechteck 6×4 (x:0..6, y:0..4), Neigung 45° (tan=1), Traufhöhe 10, kein Überstand.
|
||||
const RECT: Vec2[] = [
|
||||
{ x: 0, y: 0 },
|
||||
@@ -35,12 +42,6 @@ function allZ(g: ReturnType<typeof roofGeometry>): number[] {
|
||||
return zs;
|
||||
}
|
||||
|
||||
describe("roofBBox", () => {
|
||||
it("liefert die Bounding-Box", () => {
|
||||
expect(roofBBox(RECT)).toEqual({ x0: 0, y0: 0, x1: 6, y1: 4 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("roofGeometry — Formen (6×4, 45°, First entlang X)", () => {
|
||||
it("flach: eine waagrechte Fläche auf Traufhöhe, kein First", () => {
|
||||
const g = roofGeometry(roof({ shape: "flach" }), E);
|
||||
|
||||
@@ -39,21 +39,6 @@ export interface RoofGeometry {
|
||||
ridgeHeight: number;
|
||||
}
|
||||
|
||||
/** Bounding-Box eines Umrisses. */
|
||||
export function roofBBox(outline: Vec2[]): { x0: number; y0: number; x1: number; y1: number } {
|
||||
let x0 = Infinity;
|
||||
let y0 = Infinity;
|
||||
let x1 = -Infinity;
|
||||
let y1 = -Infinity;
|
||||
for (const p of outline) {
|
||||
if (p.x < x0) x0 = p.x;
|
||||
if (p.y < y0) y0 = p.y;
|
||||
if (p.x > x1) x1 = p.x;
|
||||
if (p.y > y1) y1 = p.y;
|
||||
}
|
||||
return { x0, y0, x1, y1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Traufhöhe (absolutes Z) eines Dachs: `baseElevation`, sonst die OBERKANTE des
|
||||
* zugehörigen Geschosses (baseElevation + floorHeight) — das Dach sitzt also
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): Liste, Änderung der Kantenneigung, Hof hinzufügen/entfernen.
|
||||
// Kanten und Höfe eines Dachs ([26]): Änderung der Kantenneigung, Hof hinzufügen/entfernen (die
|
||||
// Kantenliste rechnet der Kern, Test in `state/selectionInfo.test.ts`).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofEdgeList, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
import { addRoofHole, removeRoofHole, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
|
||||
const rect = (x: number, y: number, w: number, h: number): Vec2[] => [
|
||||
{ x, y },
|
||||
@@ -26,27 +27,6 @@ const roof = (extra: Partial<Roof> = {}): Roof => ({
|
||||
|
||||
const court = rect(4, 2, 4, 4);
|
||||
|
||||
describe("roofEdgeList", () => {
|
||||
it("Umrisskanten, dann Hofkanten; Standard ohne Feld", () => {
|
||||
const list = roofEdgeList(roof({ holes: [court] }));
|
||||
expect(list).toHaveLength(8);
|
||||
expect(list.map((e) => e.ring)).toEqual([0, 0, 0, 0, 1, 1, 1, 1]);
|
||||
expect(list[0]).toMatchObject({ index: 0, spec: { kind: "default" }, length: 12 });
|
||||
expect(list[5].index).toBe(5);
|
||||
});
|
||||
|
||||
it("liest Giebel, Neigung und negativ = Standard; Sattel: Giebelregel zeigt sich als Vorgabe", () => {
|
||||
const list = roofEdgeList(roof({ edgePitchDeg: [20, null, -1] }));
|
||||
expect(list[0].spec).toEqual({ kind: "pitch", deg: 20 });
|
||||
expect(list[1].spec).toEqual({ kind: "gable" });
|
||||
expect(list[2].spec).toEqual({ kind: "default" });
|
||||
expect(list[3].spec).toEqual({ kind: "default" });
|
||||
const sattel = roofEdgeList(roof({ shape: "sattel" }));
|
||||
expect(sattel.map((e) => e.defaultGable)).toEqual([false, true, false, true]);
|
||||
expect(roofEdgeList(roof()).every((e) => !e.defaultGable)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setRoofEdge", () => {
|
||||
it("setzt Neigung/Giebel, füllt mit Standard auf, entfernt das Feld wenn alles Standard", () => {
|
||||
const a = setRoofEdge(roof(), 2, { kind: "pitch", deg: 25 });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): die Kantenliste fürs Objekt-Info (Neigung je Kante, Giebel),
|
||||
// Kanten und Höfe eines Dachs ([26]): Typen der Kantenliste (gerechnet im Kern, `selection_info.rs`),
|
||||
// Änderungen als Teilobjekt (`Partial<Roof>`, für `updateRoof`/`patchItem` — ein Undo-Schritt) und
|
||||
// die Prüfung, ob ein Hof wirkt. Die Geometrie selbst rechnet der Rust-Kern (`roof.rs`).
|
||||
//
|
||||
@@ -31,46 +31,6 @@ export interface RoofEdge {
|
||||
|
||||
const MAX_PITCH = 89;
|
||||
|
||||
/** Die Vorgabe aus einem Eintrag von `edgePitchDeg`. */
|
||||
function specOf(v: number | null | undefined): EdgeSpec {
|
||||
if (v === null) return { kind: "gable" };
|
||||
if (v === undefined || !Number.isFinite(v) || v < 0) return { kind: "default" };
|
||||
return { kind: "pitch", deg: v };
|
||||
}
|
||||
|
||||
/** Giebelt der Standard dieser Dachform die Kante a→b (quer zur Firstrichtung)? */
|
||||
function defaultGableEdge(roof: Roof, a: Vec2, b: Vec2): boolean {
|
||||
const gabled = roof.shape === "sattel" || (roof.shape === "mansarde" && (roof.mansardType ?? "giebel") === "giebel");
|
||||
if (!gabled) return false;
|
||||
const dx = Math.abs(b.x - a.x);
|
||||
const dy = Math.abs(b.y - a.y);
|
||||
return roof.ridgeAxis === "y" ? dy < dx : dx < dy;
|
||||
}
|
||||
|
||||
/** Alle Kanten des Dachs (Umriss, dann Höfe) mit ihrer Vorgabe. */
|
||||
export function roofEdgeList(roof: Roof): RoofEdge[] {
|
||||
const rings: Vec2[][] = [roof.outline, ...(roof.holes ?? [])];
|
||||
const out: RoofEdge[] = [];
|
||||
let index = 0;
|
||||
rings.forEach((ring, r) => {
|
||||
ring.forEach((a, edge) => {
|
||||
const b = ring[(edge + 1) % ring.length];
|
||||
out.push({
|
||||
index,
|
||||
ring: r,
|
||||
edge,
|
||||
a,
|
||||
b,
|
||||
length: Math.hypot(b.x - a.x, b.y - a.y),
|
||||
spec: specOf(roof.edgePitchDeg?.[index]),
|
||||
defaultGable: defaultGableEdge(roof, a, b),
|
||||
});
|
||||
index++;
|
||||
});
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `edgePitchDeg` ohne Standard-Einträge am Ende; alles Standard ⇒ `undefined` (Feld entfällt). */
|
||||
function normalized(values: (number | null)[]): (number | null)[] | undefined {
|
||||
const v = values.slice();
|
||||
@@ -80,7 +40,7 @@ function normalized(values: (number | null)[]): (number | null)[] | undefined {
|
||||
|
||||
/** Teilobjekt für `updateRoof`: Kante `index` auf `spec` setzen. */
|
||||
export function setRoofEdge(roof: Roof, index: number, spec: EdgeSpec): Pick<Roof, "edgePitchDeg"> {
|
||||
const total = roofEdgeList(roof).length;
|
||||
const total = roof.outline.length + (roof.holes ?? []).reduce((n, h) => n + h.length, 0);
|
||||
const values: (number | null)[] = Array.from({ length: total }, (_, i) => {
|
||||
const v = roof.edgePitchDeg?.[i];
|
||||
return v === undefined ? -1 : v;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Referenz, Schnitt, Rahmen und Unsinn-Eingaben (Rust-Tests decken die Mathematik je Fall ab).
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { defaultStepCount, stairBBox, stairCut, stairGeometry, stairOutline } from "./stair";
|
||||
import { defaultStepCount, stairCut, stairGeometry, stairOutline } from "./stair";
|
||||
import type { Stair } from "../model/types";
|
||||
|
||||
const base: Stair = {
|
||||
@@ -51,11 +51,10 @@ describe("stairGeometry", () => {
|
||||
expect(stairGeometry(base, NaN).treads).toEqual([]);
|
||||
expect(stairGeometry({ ...base, stepCount: 0 }, 2.8).treads).toHaveLength(2);
|
||||
expect(stairOutline({ ...base, runLength: NaN }, 0)).toEqual({ polygon: null, spiral: null });
|
||||
expect(stairBBox(stairGeometry(base, NaN))).toEqual({ minX: 0, minY: 0, maxX: 0, maxY: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("stairCut / stairBBox / defaultStepCount", () => {
|
||||
describe("stairCut / defaultStepCount", () => {
|
||||
it("Schnitt teilt die Tritte und legt eine Doppel-Bruchlinie", () => {
|
||||
const g = stairGeometry(base, 2.8);
|
||||
const c = stairCut(g, 1.0);
|
||||
@@ -66,12 +65,6 @@ describe("stairCut / stairBBox / defaultStepCount", () => {
|
||||
expect(stairCut(stairGeometry(base, NaN), 1)).toEqual({ belowIndices: [], aboveIndices: [], breakLine: null });
|
||||
});
|
||||
|
||||
it("BBox über Tritte", () => {
|
||||
const b = stairBBox(stairGeometry(base, 2.8));
|
||||
expect(b.maxX).toBeCloseTo(3, 12);
|
||||
expect(b.minY).toBeCloseTo(-0.6, 12);
|
||||
});
|
||||
|
||||
it("Vorgabe-Stufenzahl: Steighöhe 0.17, gedeckelt durch die Lauflänge, mind. 2", () => {
|
||||
expect(defaultStepCount(2.8, 10)).toBe(16);
|
||||
expect(defaultStepCount(2.8, 3)).toBe(13);
|
||||
|
||||
+2
-14
@@ -152,8 +152,8 @@ function encodeGeometry(g: StairGeometry): Float64Array {
|
||||
|
||||
/**
|
||||
* Leitet die vollständige Geometrie einer Treppe ab. `totalRise` MUSS vom
|
||||
* Aufrufer aufgelöst übergeben werden (Geschosshöhe-Default liegt in
|
||||
* `stairVerticalExtent`), damit dieses Modul modellfrei bleibt.
|
||||
* Aufrufer aufgelöst übergeben werden (Geschosshöhe-Default liegt im Kern,
|
||||
* `stair_vertical_extent` in `model/helpers.rs`), damit dieses Modul modellfrei bleibt.
|
||||
*/
|
||||
export function stairGeometry(stair: Stair, totalRise: number): StairGeometry {
|
||||
return decodeGeometry(core().stair_geometry_flat(encodeStair(stair), totalRise));
|
||||
@@ -199,18 +199,6 @@ export function stairCut(geo: StairGeometry, cutRise: number): StairCut {
|
||||
return { belowIndices, aboveIndices, breakLine };
|
||||
}
|
||||
|
||||
/** Achsparallele Bounding-Box aller Tritte (+ Podest) einer Treppengeometrie. */
|
||||
export function stairBBox(geo: StairGeometry): {
|
||||
minX: number;
|
||||
minY: number;
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
} {
|
||||
const f = core().stair_bbox_flat(encodeGeometry(geo));
|
||||
if (f.length < 4) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
||||
return { minX: f[0], minY: f[1], maxX: f[2], maxY: f[3] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Spiral-Outline: Innenbogen + Aussenbogen + zwei radiale Schliesslinien.
|
||||
* Die Bögen werden als Kreisbogen-Parameter geliefert (cx/cy/r/a0/a1), die
|
||||
|
||||
@@ -120,15 +120,6 @@ export function lv95ToLocal(pt: LV95, origin: GeoOrigin): { x: number; y: number
|
||||
return { x: pt.e - origin.e, y: pt.n - origin.n };
|
||||
}
|
||||
|
||||
/** Lokale Modell-Meter → LV95 (Umkehrung von {@link lv95ToLocal}). */
|
||||
export function localToLv95(
|
||||
x: number,
|
||||
y: number,
|
||||
origin: GeoOrigin,
|
||||
): LV95 {
|
||||
return { e: x + origin.e, n: y + origin.n };
|
||||
}
|
||||
|
||||
/**
|
||||
* WGS84 → lokale Modell-Meter (über LV95 und die Origin). Praktisch für
|
||||
* OSM-Punkte (lon/lat), die zuerst nach LV95 projiziert und dann verschoben
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DIM_DEFAULTS_MM,
|
||||
dimTextFrame,
|
||||
dimTextOffsetFromPoint,
|
||||
dimTextPos,
|
||||
mmToModel,
|
||||
modelToMm,
|
||||
} from "./dimension";
|
||||
|
||||
const A = { x: 0, y: 0 };
|
||||
const B = { x: 4, y: 0 };
|
||||
/** Schrifthöhe in MODELL-Metern bei 1:50 — die Helfer rechnen in Modellmass. */
|
||||
const H = mmToModel(DIM_DEFAULTS_MM.textHeight, 50);
|
||||
|
||||
describe("dimTextFrame", () => {
|
||||
it("Standardlage: mittig über der Masslinie (Offset eingerechnet)", () => {
|
||||
const f = dimTextFrame(A, B, 1, H);
|
||||
expect(f.base.x).toBeCloseTo(2, 9);
|
||||
expect(f.base.y).toBeCloseTo(1 + H * 0.6, 9);
|
||||
});
|
||||
|
||||
it("Leserichtung nie kopfüber — auch bei rückwärts laufender Kette", () => {
|
||||
const forward = dimTextFrame(A, B, 0, H);
|
||||
const backward = dimTextFrame(B, A, 0, H);
|
||||
expect(forward.read.x).toBeCloseTo(1, 9);
|
||||
// b→a zeigt nach −X; die Zahl dreht sich trotzdem in die Leserichtung.
|
||||
expect(backward.read.x).toBeCloseTo(1, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dimTextPos", () => {
|
||||
it("ohne Versatz identisch zur Standardlage", () => {
|
||||
const f = dimTextFrame(A, B, 0.5, H);
|
||||
const p = dimTextPos(A, B, 0.5, H, undefined);
|
||||
expect(p).toEqual(f.base);
|
||||
});
|
||||
|
||||
it("Versatz wirkt entlang der Leserichtung und quer dazu", () => {
|
||||
const p = dimTextPos(A, B, 0, H, { along: 1, perp: 2 });
|
||||
const f = dimTextFrame(A, B, 0, H);
|
||||
expect(p.x).toBeCloseTo(f.base.x + 1, 9);
|
||||
expect(p.y).toBeCloseTo(f.base.y + 2, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dimTextOffsetFromPoint — Verschieben mit Einrasten", () => {
|
||||
it("nahe der Standardlage rastet BEIDES auf 0 ein", () => {
|
||||
const f = dimTextFrame(A, B, 0, H);
|
||||
const near = { x: f.base.x + H * 0.2, y: f.base.y - H * 0.2 };
|
||||
expect(dimTextOffsetFromPoint(A, B, 0, H, near)).toEqual({ along: 0, perp: 0 });
|
||||
});
|
||||
|
||||
it("die Achsen rasten UNABHÄNGIG ein (seitlich verschoben, Höhe exakt Standard)", () => {
|
||||
const f = dimTextFrame(A, B, 0, H);
|
||||
const pt = { x: f.base.x + 1.5, y: f.base.y + H * 0.1 };
|
||||
const o = dimTextOffsetFromPoint(A, B, 0, H, pt);
|
||||
expect(o.along).toBeCloseTo(1.5, 9);
|
||||
expect(o.perp).toBe(0);
|
||||
});
|
||||
|
||||
it("ausserhalb des Fangbereichs bleibt der gezogene Wert erhalten", () => {
|
||||
const f = dimTextFrame(A, B, 0, H);
|
||||
const pt = { x: f.base.x + 0.8, y: f.base.y + 0.6 };
|
||||
const o = dimTextOffsetFromPoint(A, B, 0, H, pt);
|
||||
expect(o.along).toBeCloseTo(0.8, 9);
|
||||
expect(o.perp).toBeCloseTo(0.6, 9);
|
||||
});
|
||||
|
||||
it("Rundreise: gezogene Position → Versatz → Position ergibt wieder den Punkt", () => {
|
||||
const pt = { x: 3.1, y: 1.4 };
|
||||
const o = dimTextOffsetFromPoint(A, B, 0.5, H, pt);
|
||||
const back = dimTextPos(A, B, 0.5, H, o);
|
||||
expect(back.x).toBeCloseTo(pt.x, 9);
|
||||
expect(back.y).toBeCloseTo(pt.y, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mmToModel/modelToMm — Papier-mm ↔ Modellmass", () => {
|
||||
it("bei 1:50 entsprechen die Defaults exakt den früheren festen Modellwerten", () => {
|
||||
expect(mmToModel(DIM_DEFAULTS_MM.gap, 50)).toBeCloseTo(0.05, 12);
|
||||
expect(mmToModel(DIM_DEFAULTS_MM.overshoot, 50)).toBeCloseTo(0.05, 12);
|
||||
expect(mmToModel(DIM_DEFAULTS_MM.tickLen, 50)).toBeCloseTo(0.15, 12);
|
||||
expect(mmToModel(DIM_DEFAULTS_MM.textHeight, 50)).toBeCloseTo(0.2, 12);
|
||||
});
|
||||
|
||||
it("derselbe Papierwert ergibt bei anderem Massstab andere Modellmasse", () => {
|
||||
// 2 mm Papier: bei 1:50 = 10 cm im Modell, bei 1:100 = 20 cm.
|
||||
expect(mmToModel(2, 50)).toBeCloseTo(0.1, 12);
|
||||
expect(mmToModel(2, 100)).toBeCloseTo(0.2, 12);
|
||||
});
|
||||
|
||||
it("Rundreise mm → Modell → mm ist verlustfrei", () => {
|
||||
for (const scale of [20, 50, 100, 200]) {
|
||||
expect(modelToMm(mmToModel(2.5, scale), scale)).toBeCloseTo(2.5, 12);
|
||||
}
|
||||
});
|
||||
});
|
||||
+7
-85
@@ -1,19 +1,11 @@
|
||||
// Gemeinsame Geometrie der Bemassung (SIA 400 B.5.3) — von BEIDEN Seiten
|
||||
// genutzt: vom Rendering (Rust-Kern, `plan/drawings.rs`) und von den Griffen
|
||||
// (`state/projectSlice.ts`). Die Lage der Masszahl (`dimTextFrame`) rechnet nur
|
||||
// der Kern (Bindung `dim_text_frame`): sonst driften Masszahl-Position und
|
||||
// Masszahl-Griff auseinander, sobald eine der beiden Stellen angepasst wird.
|
||||
// Konstanten der Bemassung (SIA 400 B.5.3). Die Geometrie (Masszahl-Lage `dim_text_frame`, Griffe der
|
||||
// Kettenpunkte, der Masslinie und der Masszahlen) rechnet der Rust-Kern — für Plan und Griffe dieselbe
|
||||
// Funktion (`plan/drawings.rs`, `grips.rs`), sonst drifteten Masszahl und Masszahl-Griff auseinander.
|
||||
//
|
||||
// EINHEITEN: die Bemassungs-Feinheiten sind PAPIER-MILLIMETER (so denkt die
|
||||
// Zeichnungsnorm: „Überstand 2 mm", unabhängig vom Massstab). Umgerechnet
|
||||
// wird mit dem Massstab des jeweiligen Plans (`mmToModel`) — die Funktionen
|
||||
// hier unten rechnen dann in Modell-Metern, weil die Plan-Geometrie so
|
||||
// vorliegt. Der Plan wird je Ziel (Bildschirm, Layout-Viewport) EIGENS
|
||||
// erzeugt (s. `LayoutSheet.tsx`), der Massstab ist zur Erzeugungszeit also
|
||||
// bekannt und eindeutig.
|
||||
|
||||
import type { Vec2 } from "./types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
// EINHEITEN: die Bemassungs-Feinheiten sind PAPIER-MILLIMETER (so denkt die Zeichnungsnorm: „Überstand
|
||||
// 2 mm", unabhängig vom Massstab). Umgerechnet wird mit dem Massstab des jeweiligen Plans; der Plan wird
|
||||
// je Ziel (Bildschirm, Layout-Viewport) EIGENS erzeugt (s. `LayoutSheet.tsx`), der Massstab ist zur
|
||||
// Erzeugungszeit also bekannt und eindeutig.
|
||||
|
||||
/**
|
||||
* Defaults in PAPIER-MILLIMETERN (übliche Zeichnungswerte; entsprechen bei
|
||||
@@ -31,73 +23,3 @@ export const END_MARK_DEFAULT_SIZE_MM = 3;
|
||||
|
||||
/** Standard-Massstab, wenn ein Aufrufer keinen mitgibt (1:100, üblichster Planmassstab). */
|
||||
export const DEFAULT_SCALE_DENOMINATOR = 100;
|
||||
|
||||
/** Papier-Millimeter → Modell-Meter beim Massstab 1:`scaleDenominator`. */
|
||||
export function mmToModel(mm: number, scaleDenominator: number): number {
|
||||
return (mm / 1000) * scaleDenominator;
|
||||
}
|
||||
|
||||
/** Modell-Meter → Papier-Millimeter (Umkehrung von {@link mmToModel}). */
|
||||
export function modelToMm(m: number, scaleDenominator: number): number {
|
||||
return (m * 1000) / scaleDenominator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lage der Masszahl EINES Segments in ihrer Standardstellung plus die beiden
|
||||
* Achsen, in denen ein Nutzer-Versatz (`textOffsets`) gemessen wird:
|
||||
* `read` = Leserichtung der Zahl, `up` = quer dazu (von der Masslinie weg).
|
||||
* Die Leserichtung ist nie kopfüber (wie beim Rendern), damit „nach oben"
|
||||
* für den Nutzer oben bleibt, egal wie die Kette gedreht ist.
|
||||
*/
|
||||
export function dimTextFrame(
|
||||
a: Vec2,
|
||||
b: Vec2,
|
||||
offset: number,
|
||||
textHeight: number,
|
||||
): { base: Vec2; read: Vec2; up: Vec2; angle: number } {
|
||||
const f = core().dim_text_frame(a.x, a.y, b.x, b.y, offset, textHeight);
|
||||
if (f.length < 7) return { base: { x: NaN, y: NaN }, read: { x: NaN, y: NaN }, up: { x: NaN, y: NaN }, angle: NaN };
|
||||
return { base: { x: f[0], y: f[1] }, read: { x: f[2], y: f[3] }, up: { x: f[4], y: f[5] }, angle: f[6] };
|
||||
}
|
||||
|
||||
/** Endgültige Position der Masszahl inkl. Nutzer-Versatz. */
|
||||
export function dimTextPos(
|
||||
a: Vec2,
|
||||
b: Vec2,
|
||||
offset: number,
|
||||
textHeight: number,
|
||||
textOffset: { along: number; perp: number } | undefined,
|
||||
): Vec2 {
|
||||
const f = dimTextFrame(a, b, offset, textHeight);
|
||||
const o = textOffset ?? { along: 0, perp: 0 };
|
||||
return {
|
||||
x: f.base.x + f.read.x * o.along + f.up.x * o.perp,
|
||||
y: f.base.y + f.read.y * o.along + f.up.y * o.perp,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Zerlegt eine gezogene Masszahl-Position in den Versatz (along/perp) und
|
||||
* lässt ihn dabei EINRASTEN: nahe der Standardlage wird die jeweilige Achse
|
||||
* exakt auf 0 gezogen (Nutzer-Wunsch „schiebbar, aber trotzdem einrastend").
|
||||
* Beide Achsen rasten unabhängig — man kann die Zahl also seitlich
|
||||
* verschieben und trotzdem exakt auf Standardhöhe bleiben.
|
||||
*/
|
||||
export function dimTextOffsetFromPoint(
|
||||
a: Vec2,
|
||||
b: Vec2,
|
||||
offset: number,
|
||||
textHeight: number,
|
||||
pt: Vec2,
|
||||
): { along: number; perp: number } {
|
||||
const f = dimTextFrame(a, b, offset, textHeight);
|
||||
const vx = pt.x - f.base.x;
|
||||
const vy = pt.y - f.base.y;
|
||||
const snap = textHeight * 0.5; // Fangbereich ≈ halbe Schrifthöhe
|
||||
const along = vx * f.read.x + vy * f.read.y;
|
||||
const perp = vx * f.up.x + vy * f.up.y;
|
||||
return {
|
||||
along: Math.abs(along) < snap ? 0 : along,
|
||||
perp: Math.abs(perp) < snap ? 0 : perp,
|
||||
};
|
||||
}
|
||||
+1
-75
@@ -22,53 +22,10 @@ export const cross = (p: Vec2, q: Vec2): number => p.x * q.y - p.y * q.x;
|
||||
/** Skalarprodukt zweier 2D-Vektoren. */
|
||||
export const dot = (p: Vec2, q: Vec2): number => p.x * q.x + p.y * q.y;
|
||||
|
||||
/** Eine unendliche Gerade als Stützpunkt + Richtung. */
|
||||
export interface Line {
|
||||
point: Vec2;
|
||||
dir: Vec2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schnittpunkt der Geraden (a + t·da) mit (b + s·db).
|
||||
* Liefert null bei (nahezu) parallelen Richtungen.
|
||||
*/
|
||||
export function lineIntersect(
|
||||
a: Vec2,
|
||||
da: Vec2,
|
||||
b: Vec2,
|
||||
db: Vec2,
|
||||
): Vec2 | null {
|
||||
const denom = cross(da, db);
|
||||
if (Math.abs(denom) < 1e-9) return null; // parallel → kein Schnitt
|
||||
const t = cross(sub(b, a), db) / denom;
|
||||
return add(a, scale(da, t));
|
||||
}
|
||||
|
||||
/** Punkt entlang einer Strecke p1→p2 im Abstand d vom Start. */
|
||||
export const along = (p1: Vec2, p2: Vec2, d: number): Vec2 =>
|
||||
add(p1, scale(normalize(sub(p2, p1)), d));
|
||||
|
||||
/**
|
||||
* Die vier Eckpunkte eines Bandes, das quer zur Normalen zwischen den
|
||||
* Offsets offA und offB liegt (gemessen entlang der linken Normalen n).
|
||||
* Reihenfolge: start+n*offA, end+n*offA, end+n*offB, start+n*offB.
|
||||
*/
|
||||
export function wallBand(
|
||||
start: Vec2,
|
||||
end: Vec2,
|
||||
offA: number,
|
||||
offB: number,
|
||||
): [Vec2, Vec2, Vec2, Vec2] {
|
||||
const u = normalize(sub(end, start));
|
||||
const n = leftNormal(u);
|
||||
return [
|
||||
add(start, scale(n, offA)),
|
||||
add(end, scale(n, offA)),
|
||||
add(end, scale(n, offB)),
|
||||
add(start, scale(n, offB)),
|
||||
];
|
||||
}
|
||||
|
||||
/** Die vier Eckpunkte einer Wand als Polygon (gegen den Uhrzeigersinn). */
|
||||
export function wallCorners(
|
||||
start: Vec2,
|
||||
@@ -76,38 +33,7 @@ export function wallCorners(
|
||||
thickness: number,
|
||||
): [Vec2, Vec2, Vec2, Vec2] {
|
||||
const h = thickness / 2;
|
||||
return wallBand(start, end, h, -h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie {@link wallBand}, aber die Bandenden werden bei Bedarf an Gehrungslinien
|
||||
* (startCut / endCut) abgeschnitten statt rechtwinklig gekappt. Jede der beiden
|
||||
* Bandkanten (bei Offset offA bzw. offB, Richtung u) wird mit der jeweiligen
|
||||
* Schnittlinie verschnitten; fehlt eine Schnittlinie, bleibt das Ende
|
||||
* rechtwinklig (Punkt auf der Achssenkrechten).
|
||||
* Reihenfolge bleibt konsistent zu wallBand: [A.start, A.end, B.end, B.start].
|
||||
*/
|
||||
export function clippedBand(
|
||||
start: Vec2,
|
||||
end: Vec2,
|
||||
offA: number,
|
||||
offB: number,
|
||||
startCut: Line | null,
|
||||
endCut: Line | null,
|
||||
): [Vec2, Vec2, Vec2, Vec2] {
|
||||
const u = normalize(sub(end, start));
|
||||
const n = leftNormal(u);
|
||||
|
||||
const edgeStart = (off: number): Vec2 => {
|
||||
const base = add(start, scale(n, off));
|
||||
if (!startCut) return base;
|
||||
return lineIntersect(base, u, startCut.point, startCut.dir) ?? base;
|
||||
};
|
||||
const edgeEnd = (off: number): Vec2 => {
|
||||
const base = add(end, scale(n, off));
|
||||
if (!endCut) return base;
|
||||
return lineIntersect(base, u, endCut.point, endCut.dir) ?? base;
|
||||
};
|
||||
|
||||
return [edgeStart(offA), edgeEnd(offA), edgeEnd(offB), edgeStart(offB)];
|
||||
return [add(start, scale(n, h)), add(end, scale(n, h)), add(end, scale(n, -h)), add(start, scale(n, -h))];
|
||||
}
|
||||
+1
-48
@@ -5,7 +5,7 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Ceiling, Column, Project, Stair, VerticalAnchor, Wall } from "./types";
|
||||
import type { Ceiling, Column, Project, VerticalAnchor, Wall } from "./types";
|
||||
import { ceilingThickness, getFloor } from "./types";
|
||||
|
||||
/**
|
||||
@@ -103,37 +103,6 @@ export function ceilingVerticalExtent(
|
||||
return { zBottom, zTop };
|
||||
}
|
||||
|
||||
/**
|
||||
* Vertikale Ausdehnung einer Treppe (absolute Z-Werte in Metern).
|
||||
* • zBottom: OKFF (baseElevation) des zugehörigen Geschosses.
|
||||
* • zTop: zBottom + Gesamt-Steighöhe. Fehlt `stair.totalRise`, gilt die
|
||||
* Geschosshöhe (floorHeight) des Geschosses — so steigt die Treppe genau ins
|
||||
* nächste Geschoss (OKFF → OKFF).
|
||||
* Fehlt das Geschoss, dient 0 als sicherer Rückfall für die Unterkante.
|
||||
*/
|
||||
export function stairVerticalExtent(
|
||||
project: Project,
|
||||
stair: Stair,
|
||||
): { zBottom: number; zTop: number } {
|
||||
let base = 0;
|
||||
let floorHeight = 0;
|
||||
try {
|
||||
const floor = getFloor(project, stair.floorId);
|
||||
base = floor.baseElevation ?? 0;
|
||||
floorHeight = floor.floorHeight ?? 0;
|
||||
} catch {
|
||||
base = 0;
|
||||
floorHeight = 0;
|
||||
}
|
||||
const rise =
|
||||
stair.totalRise != null && stair.totalRise > 0
|
||||
? stair.totalRise
|
||||
: floorHeight > 0
|
||||
? floorHeight
|
||||
: 2.6;
|
||||
return { zBottom: base, zTop: base + rise };
|
||||
}
|
||||
|
||||
/**
|
||||
* Vertikale Ausdehnung einer Stütze (absolute Z-Werte in Metern) — dieselbe
|
||||
* Regel wie {@link wallVerticalExtent}:
|
||||
@@ -155,19 +124,3 @@ export function columnVerticalExtent(
|
||||
const zTop = resolveAnchor(project, column.top) ?? zBottom + column.height;
|
||||
return { zBottom, zTop };
|
||||
}
|
||||
|
||||
/**
|
||||
* Das Geschoss DIREKT ÜBER dem Wand-Geschoss (in Dokumentreihenfolge der
|
||||
* "floor"-Ebenen) oder `undefined`, wenn die Wand im obersten Geschoss liegt.
|
||||
* Dient der „Verknüpfung zum oberen Geschoss" (OK an nächstes Geschoss binden).
|
||||
*/
|
||||
export function nextFloorAbove(
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
): { id: string; name: string } | undefined {
|
||||
const floors = project.drawingLevels.filter((z) => z.kind === "floor");
|
||||
const idx = floors.findIndex((z) => z.id === wall.floorId);
|
||||
if (idx < 0) return undefined;
|
||||
const above = floors[idx + 1];
|
||||
return above ? { id: above.id, name: above.name } : undefined;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { polylineEdgeGrips } from "./edgeGrips";
|
||||
|
||||
const sq = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 30, y: 0 },
|
||||
{ x: 30, y: 30 },
|
||||
{ x: 0, y: 30 },
|
||||
];
|
||||
|
||||
describe("polylineEdgeGrips", () => {
|
||||
it("geschlossen, gerade: 4 Kanten auf den Seitenmitten, Normalen nach aussen", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true }, { drawingId: "d" });
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 15, y: 0 },
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 15, y: 30 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex])).toEqual([[0, 1], [1, 2], [2, 3], [3, 0]]);
|
||||
expect(e[0].normal.y).toBeCloseTo(-1);
|
||||
expect(e[1].normal.x).toBeCloseTo(1);
|
||||
});
|
||||
|
||||
it("geschlossen mit Bögen: nur gerade Seiten, keine Kanten über die Bogen-Mitten (nichts im Innern)", () => {
|
||||
const e = polylineEdgeGrips(
|
||||
{ shape: "polyline", pts: sq, closed: true, bulge: [0.12, 0, -0.15, 0] },
|
||||
{ drawingId: "d" },
|
||||
);
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
// Lauter Bögen (Strassenparzelle): keine Kanten-Griffe.
|
||||
expect(polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true, bulge: [0.1, 0.1, 0.1, 0.1] }, {})).toEqual([]);
|
||||
});
|
||||
|
||||
it("offen: je gerades Segment ein freier Griff, ohne Schlusskante", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: false, bulge: [0, 0.3, 0] }, {});
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex, g.free])).toEqual([[0, 1, true], [2, 3, true]]);
|
||||
});
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
// Kanten-Griffe (je Seite ein Anfasser mit Aussennormale) eines gewählten Elements — reine
|
||||
// Geometrie, ausgelagert aus `useGripEditing.ts`.
|
||||
|
||||
import { leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import type { Drawing2DGeom, EdgeGrip, Vec2 } from "../model/types";
|
||||
|
||||
type Owner = { drawingId?: string; wallId?: string };
|
||||
|
||||
/** Geschlossener Ring aus Vertices → Kanten-Griffe mit Aussennormale (vom Eckpunkt-Mittel weg). */
|
||||
export function ringEdges(verts: Vec2[], owner: Owner): EdgeGrip[] {
|
||||
const n = verts.length;
|
||||
if (n < 3) return [];
|
||||
// Schwerpunkt (Mittel der Eckpunkte) als Innenbezug.
|
||||
let cx = 0, cy = 0;
|
||||
for (const v of verts) { cx += v.x; cy += v.y; }
|
||||
const centroid: Vec2 = { x: cx / n, y: cy / n };
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[(i + 1) % n];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
let nrm = normalize(leftNormal(sub(b, a)));
|
||||
// Nach aussen orientieren: Normale soll von centroid → mid weisen.
|
||||
const outward = sub(mid, centroid);
|
||||
if (nrm.x * outward.x + nrm.y * outward.y < 0) nrm = scale(nrm, -1);
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: (i + 1) % n, owner });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offene Kette (Linie/offene Polylinie) → ein Griff je Segment, OHNE Schlusskante. `normal` dient
|
||||
* nur der Darstellung (leftNormal der Kante); die Bewegung ist frei (`free: true`).
|
||||
*/
|
||||
export function openEdges(verts: Vec2[], owner: Owner): EdgeGrip[] {
|
||||
const n = verts.length;
|
||||
if (n < 2) return [];
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n - 1; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[i + 1];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
const nrm = normalize(leftNormal(sub(b, a)));
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: i + 1, free: true, owner });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanten-Griffe einer Polylinie: nur über die Eckpunkte (`drawingVertices` hängt dahinter je
|
||||
* Segment einen Bogen-Mitten-Griff an — liefen die Kanten auch über diese, sassen Dreiecke quer im
|
||||
* Innern, Fund 29.10.) und nur an geraden Segmenten: ein Bogen hat seinen Bogen-Mitten-Griff, die
|
||||
* Sehnen-Mitte läge neben der Linie.
|
||||
*/
|
||||
export function polylineEdgeGrips(g: Extract<Drawing2DGeom, { shape: "polyline" }>, owner: Owner): EdgeGrip[] {
|
||||
const all = g.closed ? ringEdges(g.pts, owner) : openEdges(g.pts, owner);
|
||||
return all.filter((e) => Math.abs(g.bulge?.[e.aIndex] ?? 0) <= 1e-9);
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { drawingVertices } from "../core";
|
||||
import type { Drawing2D } from "../model/types";
|
||||
|
||||
const circleDrawing: Drawing2D = {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { drawingVertices } from "../core";
|
||||
import type { Drawing2D } from "../model/types";
|
||||
|
||||
const leaderNoBends: Drawing2D = {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { drawingVertices } from "../core";
|
||||
import type { Drawing2D } from "../model/types";
|
||||
|
||||
const openPoly: Drawing2D = {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { drawingVertices } from "../core";
|
||||
import { textFrameCorners } from "../text/textFrame";
|
||||
import type { Drawing2D } from "../model/types";
|
||||
|
||||
|
||||
+61
-979
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,89 @@
|
||||
// Objekt-Info der Auswahl ([K4] S3: gerechnet im Kern, `selection_info.rs`) — Wand, Decke,
|
||||
// Zeichnung, Extrusion (B-Rep-Beschreibung aus TS) und die Meldung bei unbekanntem Wandtyp.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { deriveSelection } from "./selectionInfo";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project, Roof } from "../model/types";
|
||||
|
||||
const base = (): Project => structuredClone(sampleProject);
|
||||
|
||||
describe("deriveSelection (Kern)", () => {
|
||||
it("Wand: Typ-Liste, Geschosse, Länge, Volumen und UK/OK", () => {
|
||||
const p = base();
|
||||
const w = p.walls[0];
|
||||
const sel = deriveSelection(p, [w.id], null)!;
|
||||
expect(sel.kind).toBe("wall");
|
||||
expect(sel.id).toBe(w.id);
|
||||
expect(sel.wall!.wallTypes.length).toBe(p.wallTypes.length);
|
||||
expect(sel.wall!.floors.every((f) => p.drawingLevels.some((z) => z.id === f.id && z.kind === "floor"))).toBe(true);
|
||||
expect(sel.wall!.length).toBeCloseTo(Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y), 12);
|
||||
expect(sel.wall!.netVolume).toBeLessThanOrEqual(sel.wall!.grossVolume);
|
||||
expect(sel.wall!.zTop).toBeGreaterThan(sel.wall!.zBottom);
|
||||
expect(sel.bbox.minX).toBe(Math.min(w.start.x, w.end.x));
|
||||
});
|
||||
|
||||
it("unbekannter Wandtyp bricht mit derselben Meldung ab wie bisher", () => {
|
||||
const p = base();
|
||||
p.walls[0] = { ...p.walls[0], wallTypeId: "fehlt" };
|
||||
expect(() => deriveSelection(p, [p.walls[0].id], null)).toThrow("Unbekannter Wandtyp: fehlt");
|
||||
});
|
||||
|
||||
it("Zeichnung: offene Linie ohne Füllung, Rechteck mit Ebenen-Vorgaben", () => {
|
||||
const p = base();
|
||||
const lvl = p.drawingLevels[0].id;
|
||||
const code = p.layers[0].code;
|
||||
p.drawings2d = [
|
||||
{ id: "l", type: "drawing2d", levelId: lvl, categoryCode: code, geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 3, y: -2 } } },
|
||||
{ id: "r", type: "drawing2d", levelId: lvl, categoryCode: code, hatchId: "h", geom: { shape: "rect", min: { x: 1, y: 1 }, max: { x: 2, y: 4 } } },
|
||||
];
|
||||
const l = deriveSelection(p, [], "l")!;
|
||||
expect(l.closed).toBe(false);
|
||||
expect(l.effectiveHatchId).toBeNull();
|
||||
expect(l.bbox).toEqual({ minX: 0, minY: -2, maxX: 3, maxY: 0 });
|
||||
const r = deriveSelection(p, [], "r")!;
|
||||
expect(r.closed).toBe(true);
|
||||
expect(r.fillHatchId).toBe("h");
|
||||
expect(r.effectiveHatchId).toBe("h");
|
||||
expect(deriveSelection(p, [], "nix")).toBeNull();
|
||||
});
|
||||
|
||||
it("Extrusion: Fläche im Kern, B-Rep-Beschreibung (truck) aus TS", () => {
|
||||
const p = base();
|
||||
const lvl = p.drawingLevels[0].id;
|
||||
p.extrudedSolids = [
|
||||
{ id: "x", type: "extrudedSolid", levelId: lvl, points: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 3 }], height: 2 },
|
||||
];
|
||||
const sel = deriveSelection(p, [], null, null, null, null, null, "x")!;
|
||||
expect(sel.extrudedSolid!.area).toBeCloseTo(3, 12);
|
||||
expect(sel.extrudedSolid!.spec).toMatchObject({ kind: "extrude", height: 2 });
|
||||
expect(Object.keys(sel.extrudedSolid!)).toEqual([
|
||||
"height", "taper", "cornerRadius", "chamfer", "area", "spec", "subtract", "canSubtract", "baseOffset", "floorId", "floorName",
|
||||
]);
|
||||
});
|
||||
|
||||
it("Dach: Kantenliste (Umriss, dann Hof), Vorgaben je Kante und Giebel-Standard", () => {
|
||||
const p = base();
|
||||
const rect = (x: number, y: number, w: number, h: number) => [
|
||||
{ x, y }, { x: x + w, y }, { x: x + w, y: y + h }, { x, y: y + h },
|
||||
];
|
||||
const roof = (extra: Partial<Roof>): Roof => ({
|
||||
id: "R", type: "roof", floorId: p.drawingLevels.find((z) => z.kind === "floor")!.id, categoryCode: "31",
|
||||
outline: rect(0, 0, 12, 8), shape: "walm", pitchDeg: 35, overhang: 0, ridgeAxis: "x", thickness: 0.2, ...extra,
|
||||
});
|
||||
const edges = (r: Roof) => {
|
||||
// Neues Projekt-Objekt je Fall: der Kern gleicht über Referenzen ab.
|
||||
return deriveSelection({ ...p, roofs: [r] }, [], null, null, null, null, null, null, null, "R")!.roof!.edges;
|
||||
};
|
||||
const list = edges(roof({ holes: [rect(4, 2, 4, 4)] }));
|
||||
expect(list).toHaveLength(8);
|
||||
expect(list.map((e) => e.ring)).toEqual([0, 0, 0, 0, 1, 1, 1, 1]);
|
||||
expect(list[0]).toMatchObject({ index: 0, spec: { kind: "default" }, length: 12 });
|
||||
expect(list[5].index).toBe(5);
|
||||
const specs = edges(roof({ edgePitchDeg: [20, null, -1] }));
|
||||
expect(specs.map((e) => e.spec)).toEqual([
|
||||
{ kind: "pitch", deg: 20 }, { kind: "gable" }, { kind: "default" }, { kind: "default" },
|
||||
]);
|
||||
expect(edges(roof({ shape: "sattel" })).map((e) => e.defaultGable)).toEqual([false, true, false, true]);
|
||||
expect(edges(roof({})).every((e) => !e.defaultGable)).toBe(true);
|
||||
});
|
||||
});
|
||||
+53
-817
@@ -8,59 +8,30 @@
|
||||
// Übersteuerung am Element → LineStyle → Kategorie-Default. So zeigt die Palette
|
||||
// den TATSÄCHLICH gezeichneten Wert, nicht nur das (oft leere) Override-Feld.
|
||||
//
|
||||
// [K4] S3: gerechnet wird im Rust-Kern (`src-tauri/core/src/selection_info.rs`, Wurzel-Abfrage
|
||||
// `selectionInfo` auf dem Projekt-Dokument); hier stehen der Kontrakt (Typen) und die Fassade. Der
|
||||
// B-Rep-Körper einer Extrusion (`spec`) kommt aus TS (`extrudedSolidSpec`, truck-Pipeline).
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { extrudedSolidSpec } from "../core";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
import {
|
||||
ceilingThickness,
|
||||
getCeilingType,
|
||||
getComponent,
|
||||
getWallType,
|
||||
wallTypeLabel,
|
||||
wallTypeThickness,
|
||||
} from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import type {
|
||||
AttributeSource,
|
||||
Ceiling,
|
||||
Column,
|
||||
ColumnProfile,
|
||||
ContextImage,
|
||||
ContextObject,
|
||||
Drawing2D,
|
||||
Drawing2DGeom,
|
||||
ExtrudedSolid,
|
||||
Opening,
|
||||
Project,
|
||||
Roof,
|
||||
RoofShape,
|
||||
Room,
|
||||
SiaCategory,
|
||||
SliceTermination,
|
||||
Stair,
|
||||
StairShape,
|
||||
VerticalAnchor,
|
||||
Wall,
|
||||
WallReferenceLine,
|
||||
} from "../model/types";
|
||||
import { findCategory } from "../model/layers";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import { localToLv95 } from "../io/lv95";
|
||||
import { resolveForeground, resolveBackground, resolveHatchId, resolveStrokeWeight } from "../core";
|
||||
import { columnVerticalExtent } from "../model/wall";
|
||||
import { columnFootprint } from "../core";
|
||||
import { evaluateRoom, polygonArea } from "../core";
|
||||
import {
|
||||
ceilingVerticalExtent,
|
||||
nextFloorAbove,
|
||||
stairVerticalExtent,
|
||||
wallVerticalExtent,
|
||||
} from "../model/wall";
|
||||
import { ceilingArea, outlineBBox } from "../core";
|
||||
import { roofBBox, roofBaseElevation, roofEdgeList, roofGeometry } from "../core";
|
||||
import type { RoofEdge } from "../core";
|
||||
import { openingGapQuad, openingVerticalExtent } from "../core";
|
||||
import { stairGeometry, stairBBox } from "../core";
|
||||
|
||||
/** Eintrag für die WallType-Auswahl (Preset-Dropdown) im Object-Info-Panel. */
|
||||
export interface WallTypeChoice {
|
||||
@@ -541,754 +512,16 @@ export interface ContextObjectInfo {
|
||||
lv95Center?: { e: number; n: number };
|
||||
}
|
||||
|
||||
const WALL_FALLBACK_MM = 0.18;
|
||||
const DRAW_FALLBACK_COLOR = "#d0d0d0";
|
||||
const WALL_FALLBACK_COLOR = "#2b3039";
|
||||
|
||||
/** Ob eine 2D-Form geschlossen ist (Füllung/Schraffur sinnvoll). */
|
||||
function isClosedGeom(g: Drawing2DGeom): boolean {
|
||||
return (
|
||||
g.shape === "rect" ||
|
||||
g.shape === "circle" ||
|
||||
g.shape === "ellipse" ||
|
||||
(g.shape === "polyline" && g.closed) ||
|
||||
(g.shape === "spline" && g.closed)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounding-Box einer 2D-Form. Exportiert, weil auch die Editier-Werkzeuge sie
|
||||
* brauchen (Ausrichten/Verteilen, `editors/align.ts`) — dieselbe Herleitung
|
||||
* wie fürs Attribut-Panel, damit beide Seiten nie auseinanderlaufen.
|
||||
*/
|
||||
export function geomBBox(g: Drawing2DGeom): SelectionBBox {
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
const acc = (x: number, y: number) => {
|
||||
minX = Math.min(minX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxX = Math.max(maxX, x);
|
||||
maxY = Math.max(maxY, y);
|
||||
};
|
||||
switch (g.shape) {
|
||||
case "line":
|
||||
case "xline":
|
||||
case "ray":
|
||||
acc(g.a.x, g.a.y);
|
||||
acc(g.b.x, g.b.y);
|
||||
break;
|
||||
case "polyline":
|
||||
for (const p of g.pts) acc(p.x, p.y);
|
||||
break;
|
||||
case "rect":
|
||||
case "image":
|
||||
acc(g.min.x, g.min.y);
|
||||
acc(g.max.x, g.max.y);
|
||||
break;
|
||||
case "circle":
|
||||
case "arc":
|
||||
acc(g.center.x - g.r, g.center.y - g.r);
|
||||
acc(g.center.x + g.r, g.center.y + g.r);
|
||||
break;
|
||||
case "ellipse": {
|
||||
// Präzise Bounding-Box unter Berücksichtigung der Drehung (rotation=0
|
||||
// beim heutigen Werkzeug, Feld existiert für spätere Quellen).
|
||||
const c = Math.cos(g.rotation), s = Math.sin(g.rotation);
|
||||
const hw = Math.hypot(g.rx * c, g.ry * s);
|
||||
const hh = Math.hypot(g.rx * s, g.ry * c);
|
||||
acc(g.center.x - hw, g.center.y - hh);
|
||||
acc(g.center.x + hw, g.center.y + hh);
|
||||
break;
|
||||
}
|
||||
case "bezier":
|
||||
case "spline":
|
||||
for (const p of g.pts) acc(p.x, p.y);
|
||||
break;
|
||||
case "dimension": {
|
||||
for (const p of g.pts) acc(p.x, p.y);
|
||||
if (g.pts.length >= 2) {
|
||||
const a = g.pts[0], b = g.pts[g.pts.length - 1];
|
||||
const dx = b.x - a.x, dy = b.y - a.y;
|
||||
const len = Math.hypot(dx, dy) || 1;
|
||||
const nx = (-dy / len) * g.offset, ny = (dx / len) * g.offset;
|
||||
for (const p of g.pts) acc(p.x + nx, p.y + ny);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "kote":
|
||||
case "text":
|
||||
case "block":
|
||||
case "detailref":
|
||||
case "pointmarker":
|
||||
acc(g.at.x, g.at.y);
|
||||
break;
|
||||
case "scalebar":
|
||||
acc(g.at.x, g.at.y);
|
||||
acc(g.at.x + g.segmentLength * g.segments, g.at.y);
|
||||
break;
|
||||
}
|
||||
if (!isFinite(minX)) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
||||
return { minX, minY, maxX, maxY };
|
||||
}
|
||||
|
||||
/** Selektion für eine Wand ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
|
||||
function wallSelection(project: Project, wall: Wall): Selection {
|
||||
const cat = findCategory(project.layers, wall.categoryCode);
|
||||
const color = wall.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
// Effektive Strichstärke: expliziter Override zuerst, sonst die Kategorie
|
||||
// (die Quelle "layer"/"object" macht heute keinen Unterschied, da Component
|
||||
// keine eigene Strichstärke trägt — siehe resolveStrokeWeight).
|
||||
const weightMm = wall.strokeWeight ?? cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const minX = Math.min(wall.start.x, wall.end.x);
|
||||
const minY = Math.min(wall.start.y, wall.end.y);
|
||||
const maxX = Math.max(wall.start.x, wall.end.x);
|
||||
const maxY = Math.max(wall.start.y, wall.end.y);
|
||||
// Wand-Attribute auflösen (Referenzlinie, Aufbau, Referenzgeschoss, UK/OK).
|
||||
const wt = getWallType(project, wall);
|
||||
const thickness = wallTypeThickness(wt);
|
||||
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau fürs Attribut-Panel
|
||||
// (Nutzer-Wunsch: immer den TATSÄCHLICHEN Wert sehen, nicht nur ein leeres
|
||||
// Override-Feld) — dieselbe Resolve-Kette wie beim Rendern (resolveForeground
|
||||
// & Co.), als Bauteil-Repräsentant die ÄUSSERSTE Schicht (wie `abbrevOf`
|
||||
// unten). Bei mehrschichtigem Aufbau nur eine Annäherung (jede Schicht kann
|
||||
// im Schnitt ihre EIGENE Bauteilfarbe zeigen) — für die Panel-Vorschau
|
||||
// ausreichend, der Override selbst wirkt ohnehin einheitlich auf alle Schichten.
|
||||
const outerComponent = getComponent(project, wt.layers[0]?.componentId);
|
||||
const effectiveForeground = outerComponent
|
||||
? resolveForeground(outerComponent, wall.foreground, cat, wall.foregroundSource)
|
||||
: wall.foreground;
|
||||
const effectiveBackground = outerComponent
|
||||
? resolveBackground(outerComponent, wall.background, cat, wall.backgroundSource)
|
||||
: wall.background;
|
||||
const effectiveHatchId = resolveHatchId(
|
||||
wall.hatchId,
|
||||
wall.hatchSource,
|
||||
cat,
|
||||
outerComponent?.hatchId,
|
||||
);
|
||||
const floor = project.drawingLevels.find((z) => z.id === wall.floorId);
|
||||
const { zBottom, zTop } = wallVerticalExtent(project, wall);
|
||||
const above = nextFloorAbove(project, wall);
|
||||
// Volumen aus Achslänge × Gesamtdicke × Höhe, abzüglich der Öffnungen (jede
|
||||
// Öffnung durchbricht die volle Wanddicke: Breite × Höhe × Dicke).
|
||||
const length = Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
const wallHeight = Math.max(0, zTop - zBottom);
|
||||
const grossVolume = length * thickness * wallHeight;
|
||||
const openingVolume = (project.openings ?? [])
|
||||
.filter((o) => o.hostWallId === wall.id)
|
||||
.reduce((sum, o) => sum + o.width * o.height * thickness, 0);
|
||||
const netVolume = Math.max(0, grossVolume - openingVolume);
|
||||
// Interne Schichttrennlinien als wählbare Referenz: von aussen (Schicht 0)
|
||||
// nach innen aufsummiert; der Achsversatz +n = halbe Dicke − Fugenlage.
|
||||
const half = thickness / 2;
|
||||
const layerBoundaries: WallInfo["layerBoundaries"] = [];
|
||||
let cum = 0;
|
||||
const abbrevOf = (componentId: string): string => {
|
||||
const c = getComponent(project, componentId);
|
||||
return c ? c.abbrev ?? c.name : "?";
|
||||
};
|
||||
for (let i = 0; i < wt.layers.length - 1; i++) {
|
||||
cum += wt.layers[i].thickness;
|
||||
layerBoundaries.push({
|
||||
offset: half - cum,
|
||||
label: `${abbrevOf(wt.layers[i].componentId)}|${abbrevOf(wt.layers[i + 1].componentId)}`,
|
||||
});
|
||||
}
|
||||
const wallInfo: WallInfo = {
|
||||
referenceLine: wall.referenceLine ?? "center",
|
||||
referenceOffset: wall.referenceOffset,
|
||||
layerBoundaries,
|
||||
sliceTermination: wall.sliceTermination ?? "both",
|
||||
wallTypeId: wall.wallTypeId,
|
||||
thickness,
|
||||
singleLayer: wt.layers.length <= 1,
|
||||
wallTypes: project.wallTypes.map((t) => ({
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
label: wallTypeLabel(t, project.components),
|
||||
thickness: wallTypeThickness(t),
|
||||
layerCount: t.layers.length,
|
||||
})),
|
||||
floorId: wall.floorId,
|
||||
floorName: floor?.name ?? wall.floorId,
|
||||
floors: project.drawingLevels
|
||||
.filter((z) => z.kind === "floor")
|
||||
.map((z) => ({ id: z.id, name: z.name })),
|
||||
floorAbove: above,
|
||||
bottom: wall.bottom,
|
||||
top: wall.top,
|
||||
zBottom,
|
||||
zTop,
|
||||
length,
|
||||
grossVolume,
|
||||
openingVolume,
|
||||
netVolume,
|
||||
};
|
||||
// bbox aus der Wandachse (start/end); die Schichtdicke bleibt unberücksichtigt,
|
||||
// damit die Box der Achs-Geometrie folgt (genügt für die Paletten).
|
||||
return {
|
||||
kind: "wall",
|
||||
id: wall.id,
|
||||
categoryCode: wall.categoryCode,
|
||||
floorId: wall.floorId,
|
||||
color,
|
||||
colorPenId: wall.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: wall.hatchId,
|
||||
fillColor: undefined,
|
||||
foreground: wall.foreground,
|
||||
foregroundPenId: wall.foregroundPenId,
|
||||
background: wall.background,
|
||||
backgroundPenId: wall.backgroundPenId,
|
||||
foregroundSource: wall.foregroundSource,
|
||||
backgroundSource: wall.backgroundSource,
|
||||
effectiveForeground,
|
||||
effectiveBackground,
|
||||
effectiveHatchId,
|
||||
strokeWeightOverride: wall.strokeWeight,
|
||||
strokeWeightSource: wall.strokeWeightSource,
|
||||
hatchSource: wall.hatchSource,
|
||||
closed: undefined,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
wall: wallInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für eine Decke ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
|
||||
function ceilingSelection(project: Project, ceiling: Ceiling): Selection {
|
||||
const cat = findCategory(project.layers, ceiling.categoryCode);
|
||||
const color = ceiling.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
const weightMm = ceiling.strokeWeight ?? cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const box = outlineBBox(ceiling.outline);
|
||||
const wt = getCeilingType(project, ceiling);
|
||||
const thickness = ceilingThickness(project, ceiling);
|
||||
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau — s. Kommentar in
|
||||
// wallSelection (dieselbe Kette, äusserste Schicht als Bauteil-Repräsentant).
|
||||
const outerComponent = getComponent(project, wt.layers[0]?.componentId);
|
||||
const effectiveForeground = outerComponent
|
||||
? resolveForeground(outerComponent, ceiling.foreground, cat, ceiling.foregroundSource)
|
||||
: ceiling.foreground;
|
||||
const effectiveBackground = outerComponent
|
||||
? resolveBackground(outerComponent, ceiling.background, cat, ceiling.backgroundSource)
|
||||
: ceiling.background;
|
||||
const effectiveHatchId = resolveHatchId(
|
||||
ceiling.hatchId,
|
||||
ceiling.hatchSource,
|
||||
cat,
|
||||
outerComponent?.hatchId,
|
||||
);
|
||||
const floor = project.drawingLevels.find((z) => z.id === ceiling.floorId);
|
||||
const { zBottom, zTop } = ceilingVerticalExtent(project, ceiling);
|
||||
const ceilingInfo: CeilingInfo = {
|
||||
typeId: ceiling.ceilingTypeId ?? ceiling.wallTypeId,
|
||||
thickness,
|
||||
singleLayer: wt.layers.length <= 1,
|
||||
area: ceilingArea(ceiling.outline),
|
||||
volume: ceilingArea(ceiling.outline) * thickness,
|
||||
ceilingTypes: (project.ceilingTypes ?? []).map((t) => ({
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
label: wallTypeLabel(t, project.components),
|
||||
thickness: wallTypeThickness(t),
|
||||
layerCount: t.layers.length,
|
||||
})),
|
||||
floorId: ceiling.floorId,
|
||||
floorName: floor?.name ?? ceiling.floorId,
|
||||
floors: project.drawingLevels
|
||||
.filter((z) => z.kind === "floor")
|
||||
.map((z) => ({ id: z.id, name: z.name })),
|
||||
top: ceiling.top,
|
||||
bottom: ceiling.bottom,
|
||||
zBottom,
|
||||
zTop,
|
||||
// Aussparungen als anzeigefertige BBox-Masse (Breite × Tiefe je Loch).
|
||||
openings: (ceiling.openings ?? []).map((hole) => {
|
||||
const bb = outlineBBox(hole);
|
||||
return { width: bb.maxX - bb.minX, depth: bb.maxY - bb.minY };
|
||||
}),
|
||||
};
|
||||
return {
|
||||
kind: "ceiling",
|
||||
id: ceiling.id,
|
||||
categoryCode: ceiling.categoryCode,
|
||||
floorId: ceiling.floorId,
|
||||
color,
|
||||
colorPenId: ceiling.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: ceiling.hatchId,
|
||||
fillColor: undefined,
|
||||
foreground: ceiling.foreground,
|
||||
foregroundPenId: ceiling.foregroundPenId,
|
||||
background: ceiling.background,
|
||||
backgroundPenId: ceiling.backgroundPenId,
|
||||
foregroundSource: ceiling.foregroundSource,
|
||||
backgroundSource: ceiling.backgroundSource,
|
||||
effectiveForeground,
|
||||
effectiveBackground,
|
||||
effectiveHatchId,
|
||||
strokeWeightOverride: ceiling.strokeWeight,
|
||||
strokeWeightSource: ceiling.strokeWeightSource,
|
||||
hatchSource: ceiling.hatchSource,
|
||||
closed: true,
|
||||
bbox: { minX: box.minX, minY: box.minY, maxX: box.maxX, maxY: box.maxY },
|
||||
ceiling: ceilingInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für ein Dach ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
|
||||
function roofSelection(project: Project, roof: Roof): Selection {
|
||||
const cat = findCategory(project.layers, roof.categoryCode);
|
||||
const color = roof.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const bb = roofBBox(roof.outline);
|
||||
const eavesZ = roofBaseElevation(project, roof);
|
||||
const g = roofGeometry(roof, eavesZ);
|
||||
const footprintArea = Math.abs(bb.x1 - bb.x0) * Math.abs(bb.y1 - bb.y0);
|
||||
const roofInfo: RoofInfo = {
|
||||
shape: roof.shape,
|
||||
pitchDeg: roof.pitchDeg,
|
||||
pitchUpperDeg: roof.pitchUpperDeg,
|
||||
roofTypeId: roof.roofTypeId,
|
||||
mansardType: roof.mansardType,
|
||||
mansardKneeRatio: roof.mansardKneeRatio,
|
||||
halfHipRatio: roof.halfHipRatio,
|
||||
overhang: roof.overhang,
|
||||
overhangGable: roof.overhangGable,
|
||||
ridgeAxis: roof.ridgeAxis,
|
||||
thickness: roof.thickness,
|
||||
baseElevation: eavesZ,
|
||||
ridgeHeight: g.ridgeHeight,
|
||||
footprintArea,
|
||||
width: Math.abs(bb.x1 - bb.x0),
|
||||
depth: Math.abs(bb.y1 - bb.y0),
|
||||
minX: bb.x0,
|
||||
minY: bb.y0,
|
||||
edges: roofEdgeList(roof),
|
||||
holes: (roof.holes ?? []).map((h) => ({ area: Math.abs(polygonArea(h)), points: h.length })),
|
||||
hasEdgePitch: roof.edgePitchDeg !== undefined,
|
||||
};
|
||||
return {
|
||||
kind: "roof",
|
||||
id: roof.id,
|
||||
categoryCode: roof.categoryCode,
|
||||
floorId: roof.floorId,
|
||||
color,
|
||||
colorPenId: roof.colorPenId,
|
||||
weightMm,
|
||||
closed: true,
|
||||
bbox: { minX: bb.x0, minY: bb.y0, maxX: bb.x1, maxY: bb.y1 },
|
||||
roof: roofInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für eine Öffnung ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
|
||||
function openingSelection(project: Project, o: Opening): Selection {
|
||||
const cat = findCategory(project.layers, o.categoryCode);
|
||||
const color = o.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const wall = project.walls.find((w) => w.id === o.hostWallId);
|
||||
const floor = wall
|
||||
? project.drawingLevels.find((z) => z.id === wall.floorId)
|
||||
: undefined;
|
||||
// Bounding-Box aus dem Lücken-Quad (volle Wanddicke); Fallback: leere Box.
|
||||
const quad = wall ? openingGapQuad(project, wall, o) : null;
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of quad ?? []) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) {
|
||||
minX = minY = maxX = maxY = 0;
|
||||
}
|
||||
const ext = wall
|
||||
? openingVerticalExtent(project, wall, o)
|
||||
: { zBottom: 0, zTop: o.height };
|
||||
const openingInfo: OpeningInfo = {
|
||||
id: o.id,
|
||||
kind: o.kind,
|
||||
hostWallId: o.hostWallId,
|
||||
hostWallName: floor ? `${floor.name}` : o.hostWallId,
|
||||
position: o.position,
|
||||
width: o.width,
|
||||
height: o.height,
|
||||
sillHeight: o.sillHeight,
|
||||
hinge: o.hinge,
|
||||
swing: o.swing,
|
||||
swingAngle: o.swingAngle,
|
||||
openingDir: o.openingDir,
|
||||
wingCount: o.wingCount,
|
||||
doorType: o.doorType,
|
||||
lintelLines: o.lintelLines,
|
||||
typeId: o.typeId,
|
||||
detailLevel: o.detailLevel,
|
||||
zBottom: ext.zBottom,
|
||||
zTop: ext.zTop,
|
||||
frameLine: o.frameLine,
|
||||
frameViewLine: o.frameViewLine,
|
||||
sashLine: o.sashLine,
|
||||
sillLineStyle: o.sillLineStyle,
|
||||
};
|
||||
return {
|
||||
kind: "opening",
|
||||
id: o.id,
|
||||
categoryCode: o.categoryCode,
|
||||
color,
|
||||
colorPenId: o.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: undefined,
|
||||
fillColor: undefined,
|
||||
closed: undefined,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
opening: openingInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für eine Treppe ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
|
||||
function stairSelection(project: Project, s: Stair): Selection {
|
||||
const cat = findCategory(project.layers, s.categoryCode);
|
||||
const color = s.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const { zBottom, zTop } = stairVerticalExtent(project, s);
|
||||
const totalRise = zTop - zBottom;
|
||||
const geo = stairGeometry(s, totalRise);
|
||||
const box = stairBBox(geo);
|
||||
const floor = project.drawingLevels.find((z) => z.id === s.floorId);
|
||||
const stairInfo: StairInfo = {
|
||||
shape: s.shape,
|
||||
width: s.width,
|
||||
stepCount: s.stepCount,
|
||||
totalRise,
|
||||
riserHeight: geo.riserHeight,
|
||||
treadDepth: geo.treadDepth,
|
||||
up: s.up !== false,
|
||||
arrowStyle: s.arrowStyle,
|
||||
referenz: s.referenz,
|
||||
typeId: s.typeId,
|
||||
floorId: s.floorId,
|
||||
floorName: floor?.name ?? s.floorId,
|
||||
zBottom,
|
||||
zTop,
|
||||
};
|
||||
return {
|
||||
kind: "stair",
|
||||
id: s.id,
|
||||
categoryCode: s.categoryCode,
|
||||
floorId: s.floorId,
|
||||
color,
|
||||
colorPenId: s.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: undefined,
|
||||
fillColor: undefined,
|
||||
closed: undefined,
|
||||
bbox: { minX: box.minX, minY: box.minY, maxX: box.maxX, maxY: box.maxY },
|
||||
stair: stairInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für einen Raum ableiten (Fläche/Umfang aus dem Umriss abgeleitet). */
|
||||
function roomSelection(project: Project, r: Room): Selection {
|
||||
const cat = findCategory(project.layers, r.categoryCode);
|
||||
const color = r.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
|
||||
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
|
||||
const res = evaluateRoom(r.boundary, r.siaCategory);
|
||||
const floor = project.drawingLevels.find((z) => z.id === r.floorId);
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of r.boundary) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
|
||||
const roomInfo: RoomInfo = {
|
||||
name: r.name,
|
||||
siaCategory: r.siaCategory,
|
||||
area: res.netArea,
|
||||
perimeter: res.perimeter,
|
||||
floorId: r.floorId,
|
||||
floorName: floor?.name ?? r.floorId,
|
||||
};
|
||||
return {
|
||||
kind: "room",
|
||||
id: r.id,
|
||||
categoryCode: r.categoryCode,
|
||||
floorId: r.floorId,
|
||||
color,
|
||||
colorPenId: r.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: undefined,
|
||||
fillColor: undefined,
|
||||
closed: true,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
room: roomInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/** Auswahl-Farbe der Extrusions-Footprints (identisch zum Grundriss-Umriss/3D-Orange). */
|
||||
const EXTRUSION_COLOR = "#d98c40";
|
||||
|
||||
/** Selektion für einen extrudierten Körper ableiten (truck-Integration). */
|
||||
function extrudedSolidSelection(project: Project, s: ExtrudedSolid): Selection {
|
||||
const floor = project.drawingLevels.find((z) => z.id === s.levelId);
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of s.points) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
|
||||
const info: ExtrudedSolidInfo = {
|
||||
height: s.height,
|
||||
taper: s.taper ?? 0,
|
||||
cornerRadius: s.cornerRadius ?? 0,
|
||||
chamfer: s.chamfer ?? 0,
|
||||
...(s.brep ? { brepLabel: s.brep.label ?? "B-Rep" } : {}),
|
||||
area: polygonArea(s.points),
|
||||
spec: s.operation === "subtract" ? null : extrudedSolidSpec(s, floor?.baseElevation ?? 0),
|
||||
subtract: s.operation === "subtract",
|
||||
canSubtract: !s.brep && (s.taper ?? 0) < 1e-6,
|
||||
baseOffset: s.baseOffset ?? 0,
|
||||
floorId: s.levelId,
|
||||
floorName: floor?.name ?? s.levelId,
|
||||
};
|
||||
return {
|
||||
kind: "extrudedSolid",
|
||||
id: s.id,
|
||||
categoryCode: "",
|
||||
floorId: s.levelId,
|
||||
color: EXTRUSION_COLOR,
|
||||
weightMm: WALL_FALLBACK_MM,
|
||||
fillHatchId: null,
|
||||
fillColor: null,
|
||||
closed: true,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
extrudedSolid: info,
|
||||
};
|
||||
}
|
||||
|
||||
/** Umriss-/Auswahlfarbe der Stützen-Poché (neutrales Tragwerks-Grau). */
|
||||
const COLUMN_COLOR = "#3a3f47";
|
||||
|
||||
/** Selektion für eine Stütze (Column) ableiten. */
|
||||
function columnSelection(project: Project, col: Column): Selection {
|
||||
const floor = project.drawingLevels.find((z) => z.id === col.floorId);
|
||||
const category = findCategory(project.layers, col.categoryCode);
|
||||
const pts = columnFootprint(col);
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of pts) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
|
||||
const { zBottom, zTop } = columnVerticalExtent(project, col);
|
||||
const info: ColumnInfo = {
|
||||
profile: col.profile,
|
||||
height: col.height,
|
||||
rotationDeg: ((col.rotation ?? 0) * 180) / Math.PI,
|
||||
floorId: col.floorId,
|
||||
floorName: floor?.name ?? col.floorId,
|
||||
zBottom,
|
||||
zTop,
|
||||
};
|
||||
// Effektive Vordergrund-/Hintergrund-/Schraffur-/Strichstärke-Vorschau — s.
|
||||
// Kommentar in wallSelection (dieselbe Kette, das zugewiesene Bauteil als
|
||||
// Repräsentant statt der äussersten Schicht, da Column nur EIN componentId
|
||||
// trägt statt eines geschichteten Aufbaus).
|
||||
// `getComponent` wirft bei unbekannter ID (z. B. gelöschtes Bauteil) — die
|
||||
// Panel-Vorschau soll dabei nicht abstürzen (analog dem try/catch in
|
||||
// structures.ts addColumnPoche), einfach auf "kein Bauteil" zurückfallen.
|
||||
const comp = col.componentId
|
||||
? project.components.find((c) => c.id === col.componentId)
|
||||
: undefined;
|
||||
const effectiveForeground = comp
|
||||
? resolveForeground(comp, col.foreground, category, col.foregroundSource)
|
||||
: col.foreground;
|
||||
const effectiveBackground = comp
|
||||
? resolveBackground(comp, col.background, category, col.backgroundSource)
|
||||
: col.background;
|
||||
const effectiveHatchId = resolveHatchId(col.hatchId, col.hatchSource, category, comp?.hatchId);
|
||||
const weightMm = resolveStrokeWeight(col.strokeWeight, col.strokeWeightSource, category, WALL_FALLBACK_MM);
|
||||
return {
|
||||
kind: "column",
|
||||
id: col.id,
|
||||
categoryCode: col.categoryCode,
|
||||
floorId: col.floorId,
|
||||
color: col.color ?? category?.color ?? COLUMN_COLOR,
|
||||
colorPenId: col.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: col.hatchId,
|
||||
foreground: col.foreground,
|
||||
foregroundPenId: col.foregroundPenId,
|
||||
background: col.background,
|
||||
backgroundPenId: col.backgroundPenId,
|
||||
foregroundSource: col.foregroundSource,
|
||||
backgroundSource: col.backgroundSource,
|
||||
effectiveForeground,
|
||||
effectiveBackground,
|
||||
effectiveHatchId,
|
||||
strokeWeightOverride: col.strokeWeight,
|
||||
strokeWeightSource: col.strokeWeightSource,
|
||||
hatchSource: col.hatchSource,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
column: info,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Selektion für ein Kontext-Objekt (importiertes Mesh/Terrain/Konturen-Satz)
|
||||
* ableiten. Bbox aus den rohen x/y-Koordinaten (Meshes: flaches [x,y,z…]-
|
||||
* Array, nur x/y je Vertex; Konturen: `pts` je Kontur) — die Höhe (z) bleibt
|
||||
* unberücksichtigt (2D-Bbox wie bei allen anderen Elementarten). `lv95Center`
|
||||
* nur, wenn `project.geoAnchor` gesetzt ist (sonst kein Rückrechnungs-Bezug).
|
||||
*/
|
||||
function contextObjectSelection(project: Project, obj: ContextObject): Selection {
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
const consider = (x: number, y: number) => {
|
||||
minX = Math.min(minX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxX = Math.max(maxX, x);
|
||||
maxY = Math.max(maxY, y);
|
||||
};
|
||||
if (obj.type === "contourSet") {
|
||||
for (const c of obj.contours) for (const p of c.pts) consider(p.x, p.y);
|
||||
} else if (obj.type === "image") {
|
||||
consider(obj.min.x, obj.min.y);
|
||||
consider(obj.max.x, obj.max.y);
|
||||
} else {
|
||||
const pos = obj.positions;
|
||||
for (let i = 0; i + 2 < pos.length; i += 3) consider(pos[i], pos[i + 1]);
|
||||
}
|
||||
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
|
||||
const anchor = project.geoAnchor;
|
||||
const lv95Center = anchor
|
||||
? localToLv95(
|
||||
(minX + maxX) / 2,
|
||||
(minY + maxY) / 2,
|
||||
{ e: anchor.lv95.e - anchor.model.x, n: anchor.lv95.n - anchor.model.y },
|
||||
)
|
||||
: undefined;
|
||||
const isImage = obj.type === "image";
|
||||
return {
|
||||
kind: "contextObject",
|
||||
id: obj.id,
|
||||
categoryCode: "",
|
||||
color: "#888888",
|
||||
weightMm: WALL_FALLBACK_MM,
|
||||
bbox: { minX, minY, maxX, maxY },
|
||||
contextObject: { objType: obj.type, lv95Center },
|
||||
// Deckkraft + Bildkorrektur nur bei Luftbildern (`ContextImage`) — steuert
|
||||
// die (wiederverwendete) Deckkraft-Zeile + die neue Bildkorrektur-Sektion
|
||||
// im Attribute-Panel, s. `AttributesPanel.tsx`.
|
||||
isImage,
|
||||
opacity: isImage ? ((obj as ContextImage).opacity ?? 1) : undefined,
|
||||
imageFilters: isImage ? (obj as ContextImage).filters : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/** Selektion für ein 2D-Zeichenelement ableiten (gleiche Auflösung wie generatePlan). */
|
||||
function drawingSelection(project: Project, d: Drawing2D): Selection {
|
||||
const ls = d.lineStyleId
|
||||
? project.lineStyles.find((l) => l.id === d.lineStyleId)
|
||||
: undefined;
|
||||
const cat = findCategory(project.layers, d.categoryCode);
|
||||
const color = d.color ?? ls?.color ?? cat?.color ?? DRAW_FALLBACK_COLOR;
|
||||
// Effektive Strichstärke, dieselbe Kette wie der Plan (`plan/drawings.rs`)
|
||||
// (resolveStrokeWeight): Override zuerst, Source ≠ "object" (also "layer"
|
||||
// ODER fehlend, s. AttributeSource-Default) erzwingt die Kategorie (umgeht
|
||||
// das LineStyle-Gewicht), sonst die LineStyle-/Kategorie-Kette.
|
||||
const weightMm =
|
||||
d.weightMm ??
|
||||
(d.strokeWeightSource !== "object" ? cat?.lw : undefined) ??
|
||||
ls?.weight ??
|
||||
cat?.lw ??
|
||||
WALL_FALLBACK_MM;
|
||||
const closed = isClosedGeom(d.geom);
|
||||
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau — s. Kommentar in
|
||||
// wallSelection. Ein Drawing2D hat KEIN eigenes Bauteil (daher auch keine
|
||||
// „Nach Bauteil"-Option im Panel, s. AttributesPanel.tsx) — als Platzhalter
|
||||
// ein leeres Bauteil, dessen foreground/background/hatchId immer fehlen,
|
||||
// sodass die Kette bei einem (aus Alt-Daten) expliziten `source:"object"`
|
||||
// korrekt auf „kein Wert" statt einer erfundenen Bauteilfarbe fällt. Anders
|
||||
// als bei Wand/Decke (Default „Nach Bauteil") gilt bei Drawing2D „Nach
|
||||
// Ebene" als Default — daher hier explizit `?? "layer"` VOR dem Resolver
|
||||
// (der selbst weiterhin generisch „Nach Bauteil" als Default kennt).
|
||||
const noComponent = { id: "", name: "", color, hatchId: "", joinPriority: 0 };
|
||||
const effectiveForeground = closed
|
||||
? resolveForeground(noComponent, d.foreground, cat, d.foregroundSource ?? "layer")
|
||||
: undefined;
|
||||
const effectiveBackground = closed
|
||||
? resolveBackground(noComponent, d.background, cat, d.backgroundSource ?? "layer")
|
||||
: undefined;
|
||||
const effectiveHatchId = closed
|
||||
? resolveHatchId(d.hatchId, d.hatchSource ?? "layer", cat, undefined)
|
||||
: null;
|
||||
return {
|
||||
kind: "drawing2d",
|
||||
id: d.id,
|
||||
categoryCode: d.categoryCode,
|
||||
floorId: d.levelId,
|
||||
color,
|
||||
colorPenId: d.colorPenId,
|
||||
weightMm,
|
||||
fillHatchId: closed ? d.hatchId ?? null : null,
|
||||
fillColor: closed ? d.fillColor ?? null : null,
|
||||
foreground: closed ? d.foreground : undefined,
|
||||
foregroundPenId: closed ? d.foregroundPenId : undefined,
|
||||
background: closed ? d.background : undefined,
|
||||
backgroundPenId: closed ? d.backgroundPenId : undefined,
|
||||
foregroundSource: closed ? d.foregroundSource : undefined,
|
||||
backgroundSource: closed ? d.backgroundSource : undefined,
|
||||
effectiveForeground,
|
||||
effectiveBackground,
|
||||
effectiveHatchId,
|
||||
strokeWeightOverride: d.weightMm,
|
||||
strokeWeightSource: d.strokeWeightSource,
|
||||
hatchSource: closed ? d.hatchSource : undefined,
|
||||
closed,
|
||||
isImage: d.geom.shape === "image",
|
||||
// Deckkraft: beim BILD die eigene Bild-Deckkraft, sonst die
|
||||
// Objekt-Transparenz des Elements (`Drawing2D.opacity`).
|
||||
opacity: d.geom.shape === "image" ? (d.geom.opacity ?? 1) : d.opacity,
|
||||
bbox: geomBBox(d.geom),
|
||||
detailRef:
|
||||
d.geom.shape === "detailref"
|
||||
? {
|
||||
label: d.geom.label,
|
||||
sheetLayoutId: d.geom.sheetLayoutId,
|
||||
sheetLabel: d.geom.sheetLabel,
|
||||
availableLayouts: (project.layouts ?? []).map((l) => ({ id: l.id, name: l.name })),
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
/** Meldungen, mit denen die Objekt-Info wie bisher abbricht (unbekannter Typ/Bauteil). */
|
||||
const THROWN = /^Unbekannte[rs]? /;
|
||||
|
||||
/**
|
||||
* Leitet den Selektions-Kontrakt für das ERSTE selektierte Element ab.
|
||||
* Drawing-Auswahl und Wand-Auswahl schließen sich aus; bei Drawing-Auswahl
|
||||
* hat diese Vorrang. Liefert `null`, wenn nichts (oder kein auffindbares
|
||||
* Element) selektiert ist.
|
||||
* Element) selektiert ist. Ein unbekannter Wand-/Deckentyp oder ein fehlendes
|
||||
* Bauteil wirft wie bisher; ein Element, das das Kern-Modell nicht lesen kann,
|
||||
* ergibt `null` (mit Warnung).
|
||||
*/
|
||||
export function deriveSelection(
|
||||
project: Project,
|
||||
@@ -1303,46 +536,49 @@ export function deriveSelection(
|
||||
selectedRoofId: string | null = null,
|
||||
selectedContextObjectId: string | null = null,
|
||||
): Selection | null {
|
||||
if (selectedContextObjectId) {
|
||||
const o = (project.context ?? []).find((x) => x.id === selectedContextObjectId);
|
||||
if (o) return contextObjectSelection(project, o);
|
||||
const args = {
|
||||
wallIds: selectedWallIds,
|
||||
drawingId: selectedDrawingId,
|
||||
ceilingId: selectedCeilingId,
|
||||
openingId: selectedOpeningId,
|
||||
stairId: selectedStairId,
|
||||
roomId: selectedRoomId,
|
||||
extrudedSolidId: selectedExtrudedSolidId,
|
||||
columnId: selectedColumnId,
|
||||
roofId: selectedRoofId,
|
||||
contextObjectId: selectedContextObjectId,
|
||||
// Lage in der Leseansicht (= Reihenfolge im Dokument): erspart dem Kern die lineare Suche.
|
||||
at: {} as Record<string, number>,
|
||||
};
|
||||
const P = project as unknown as Record<string, { id: string }[] | undefined>;
|
||||
const hint = (list: string, id: string | null | undefined) => {
|
||||
if (!id) return;
|
||||
const i = (P[list] ?? []).findIndex((x) => x.id === id);
|
||||
if (i >= 0) args.at[list] = i;
|
||||
};
|
||||
hint("context", selectedContextObjectId);
|
||||
hint("drawings2d", selectedDrawingId);
|
||||
hint("extrudedSolids", selectedExtrudedSolidId);
|
||||
hint("columns", selectedColumnId);
|
||||
hint("openings", selectedOpeningId);
|
||||
hint("walls", selectedWallIds[0]);
|
||||
hint("ceilings", selectedCeilingId);
|
||||
hint("roofs", selectedRoofId);
|
||||
hint("stairs", selectedStairId);
|
||||
hint("rooms", selectedRoomId);
|
||||
let sel: Selection | null;
|
||||
try {
|
||||
sel = documentFor(project).queryRootMarked<Selection | null>("selectionInfo", JSON.stringify(args));
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
if (THROWN.test(msg)) throw new Error(msg);
|
||||
console.warn("Objekt-Info:", msg);
|
||||
return null;
|
||||
}
|
||||
if (selectedDrawingId) {
|
||||
const d = project.drawings2d.find((x) => x.id === selectedDrawingId);
|
||||
return d ? drawingSelection(project, d) : null;
|
||||
if (sel?.extrudedSolid) {
|
||||
const s = (project.extrudedSolids ?? []).find((x) => x.id === sel!.id);
|
||||
const floor = s && project.drawingLevels.find((z) => z.id === s.levelId);
|
||||
sel.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null;
|
||||
}
|
||||
if (selectedExtrudedSolidId) {
|
||||
const s = (project.extrudedSolids ?? []).find((x) => x.id === selectedExtrudedSolidId);
|
||||
return s ? extrudedSolidSelection(project, s) : null;
|
||||
}
|
||||
if (selectedColumnId) {
|
||||
const c = (project.columns ?? []).find((x) => x.id === selectedColumnId);
|
||||
return c ? columnSelection(project, c) : null;
|
||||
}
|
||||
if (selectedOpeningId) {
|
||||
const o = (project.openings ?? []).find((x) => x.id === selectedOpeningId);
|
||||
if (o) return openingSelection(project, o);
|
||||
}
|
||||
const wallId = selectedWallIds[0];
|
||||
if (wallId) {
|
||||
const w = project.walls.find((x) => x.id === wallId);
|
||||
return w ? wallSelection(project, w) : null;
|
||||
}
|
||||
if (selectedCeilingId) {
|
||||
const c = (project.ceilings ?? []).find((x) => x.id === selectedCeilingId);
|
||||
return c ? ceilingSelection(project, c) : null;
|
||||
}
|
||||
if (selectedRoofId) {
|
||||
const r = (project.roofs ?? []).find((x) => x.id === selectedRoofId);
|
||||
return r ? roofSelection(project, r) : null;
|
||||
}
|
||||
if (selectedStairId) {
|
||||
const s = (project.stairs ?? []).find((x) => x.id === selectedStairId);
|
||||
return s ? stairSelection(project, s) : null;
|
||||
}
|
||||
if (selectedRoomId) {
|
||||
const r = (project.rooms ?? []).find((x) => x.id === selectedRoomId);
|
||||
return r ? roomSelection(project, r) : null;
|
||||
}
|
||||
return null;
|
||||
return sel;
|
||||
}
|
||||
@@ -9,9 +9,9 @@ import { useRef, useState, type RefObject } from "react";
|
||||
import { add, dot, leftNormal, normalize, scale, sub, wallCorners } from "../model/geometry";
|
||||
import type { Ceiling, Drawing2D, EdgeGrip, Project, Room, Stair, Vec2 } from "../model/types";
|
||||
import { wallTypeThickness } from "../model/types";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { drawingVertices } from "../core";
|
||||
import { gripDrawingIdsFor } from "./gripLimits";
|
||||
import { openEdges, polylineEdgeGrips, ringEdges } from "./edgeGrips";
|
||||
import { openEdges, polylineEdgeGrips, ringEdges } from "../core";
|
||||
import { areaMovePreview } from "../tools/transform";
|
||||
import { mvGeom } from "../core";
|
||||
import { drawingPreviewShapes } from "../tools/drawingPreview";
|
||||
@@ -372,7 +372,7 @@ export function useGripEditing(opts: {
|
||||
// Ecken wandern mit, die Nachbar-Segmente dehnen sich nach (Parallel-
|
||||
// Verschieben EINER Kante einer komplexen Polylinie, §Task B).
|
||||
const edgeGrips: EdgeGrip[] = (() => {
|
||||
// ringEdges/openEdges/polylineEdgeGrips: s. edgeGrips.ts.
|
||||
// ringEdges/openEdges/polylineEdgeGrips: Kern (`geometry/grips.ts`, `grips.rs`).
|
||||
// Decke: geschlossener Ring aus dem Umriss (Auswahl exklusiv, wie bei grips).
|
||||
if (modelEditable && selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
return ringEdges(selectedCeiling.outline, {});
|
||||
|
||||
@@ -256,7 +256,7 @@ export function useMouseSelectionHandlers(opts: {
|
||||
// Kontextmenü-„Entsperren", sobald die Selektion einmal woanders hin
|
||||
// wechselt — Sackgasse). Ein gesperrtes Element bleibt anwähl-/
|
||||
// inspizierbar; blockiert wird die MODIFIKATION direkt an den
|
||||
// Mutations-Stellen (`moveGrip`/`moveElementBy` in projectSlice.ts,
|
||||
// Mutations-Stellen (`moveGrip`/`moveElementBy` im Kern, `grips.rs`,
|
||||
// `deleteSelection` in App.tsx) — dieselbe Semantik wie AutoCADs
|
||||
// Layer-„Lock" (weiterhin wählbar, nicht editierbar).
|
||||
// Shift+Klick: Mehrfach-Auswahl — getroffenes Element zu-/abschalten, den
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Geschätzter Rahmen (Modell-Meter) eines gezeichneten Textes — EINE Quelle
|
||||
// für sowohl die visuelle Anzeige (PlanView.tsx Auswahl-Rahmen/Inline-Editor-
|
||||
// Anker) als auch die Eckpunkt-Griffe (state/projectSlice.ts drawingVertices/
|
||||
// moveGrip). Reines Modul: kein React, kein DOM zwingend nötig
|
||||
// Anker) als auch die Eckpunkt-Griffe der Textspalte (`geometry/grips.ts`
|
||||
// drawingVertices). Reines Modul: kein React, kein DOM zwingend nötig
|
||||
// (`contentFontBaselineFromTop` fällt ohne Canvas sicher auf einen
|
||||
// Näherungswert zurück, s. dort) — darf daher auch aus dem Store-Slice
|
||||
// heraus aufgerufen werden.
|
||||
|
||||
@@ -44,8 +44,7 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import type { Project, Wall, Drawing2D, Ceiling, Roof, Vec2 } from "../model/types";
|
||||
import { ceilingVerticalExtent, wallVerticalExtent } from "../model/wall";
|
||||
import { roofBaseElevation, roofGeometry } from "../core";
|
||||
import { roofBaseElevation, roofGeometry, verticalExtents } from "../core";
|
||||
import { projectToModel3d, pickGeometry, draftWorldLines, TRUCK_MESH_READY_EVENT } from "../core";
|
||||
import type { DetailLevel, RenderMode, View3d } from "../model/viewTypes";
|
||||
import type { ToolDraft } from "../tools/types";
|
||||
@@ -146,8 +145,9 @@ function computeGrips(
|
||||
drawingElevation: number,
|
||||
): Grip[] {
|
||||
const out: Grip[] = [];
|
||||
for (const w of walls) {
|
||||
const { zBottom, zTop } = wallVerticalExtent(project, w);
|
||||
const ext = verticalExtents(project, walls, ceilings);
|
||||
walls.forEach((w, wi) => {
|
||||
const { zBottom, zTop } = ext.walls[wi];
|
||||
const target = { wallId: w.id };
|
||||
out.push({ kind: "vertex", target, index: 0, pos: [w.start.x, zBottom, w.start.y] });
|
||||
out.push({ kind: "vertex", target, index: 1, pos: [w.end.x, zBottom, w.end.y] });
|
||||
@@ -155,7 +155,7 @@ function computeGrips(
|
||||
const midY = (w.start.y + w.end.y) / 2;
|
||||
out.push({ kind: "height", target, index: -1, pos: [midX, zTop, midY] });
|
||||
out.push({ kind: "move", target, index: -1, pos: [midX, zBottom + 0.05, midY] });
|
||||
}
|
||||
});
|
||||
for (const d of drawings) {
|
||||
const verts = drawingGripVertices(d);
|
||||
const target = { drawingId: d.id };
|
||||
@@ -167,12 +167,12 @@ function computeGrips(
|
||||
// Decken: Eckpunkt-Griffe (Umriss) + je Seite ein Kanten-Mittelpunkt-Griff
|
||||
// (Nutzer-Wunsch „an allen seiten auch ein punkt … wie an den eckpunkten") +
|
||||
// ein Verschiebe-Griff im Schwerpunkt. Griffe sitzen auf der Deckenoberkante.
|
||||
for (const c of ceilings) {
|
||||
ceilings.forEach((c, ci) => {
|
||||
const pts = c.outline;
|
||||
const n = pts.length;
|
||||
if (n < 2) continue;
|
||||
if (n < 2) return;
|
||||
const target = { ceilingId: c.id };
|
||||
const y = ceilingVerticalExtent(project, c).zTop + 0.02;
|
||||
const y = ext.ceilings[ci].zTop + 0.02;
|
||||
let sx = 0;
|
||||
let sy = 0;
|
||||
pts.forEach((p, i) => {
|
||||
@@ -189,7 +189,7 @@ function computeGrips(
|
||||
sy += p.y;
|
||||
});
|
||||
out.push({ kind: "move", target, index: -1, pos: [sx / n, y + 0.03, sy / n] });
|
||||
}
|
||||
});
|
||||
// Dächer: Eckpunkt-Griffe (Umriss = Traufe-Grundriss, resize) + Verschiebe-Griff
|
||||
// + ein FIRST-/Neigungs-Griff am höchsten Punkt (vertikal ziehen ändert die
|
||||
// Neigung). Eckpunkte auf Traufhöhe.
|
||||
@@ -927,11 +927,11 @@ export function Wasm3DViewport({
|
||||
const gripPlaneY = (target: GripTarget): number | null => {
|
||||
if (target.wallId) {
|
||||
const wall = editWallsRef.current.find((w) => w.id === target.wallId);
|
||||
return wall ? wallVerticalExtent(projectRef.current, wall).zBottom : null;
|
||||
return wall ? verticalExtents(projectRef.current, [wall]).walls[0].zBottom : null;
|
||||
}
|
||||
if (target.ceilingId) {
|
||||
const c = editCeilingsRef.current.find((x) => x.id === target.ceilingId);
|
||||
return c ? ceilingVerticalExtent(projectRef.current, c).zTop : null;
|
||||
return c ? verticalExtents(projectRef.current, [], [c]).ceilings[0].zTop : null;
|
||||
}
|
||||
if (target.roofId) {
|
||||
const r = editRoofsRef.current.find((x) => x.id === target.roofId);
|
||||
|
||||
Reference in new issue
Block a user