[K4] Objekt-Info im Kern: deriveSelection rechnet selection_info.rs
Die Objekt-Info der Auswahl (effektive Attribute, bbox, Wand/Decke/Dach/Öffnung/Treppe/Raum/ Extrusion/Stütze/Kontext/Detailverweis) ist die Wurzel-Abfrage selectionInfo; state/selectionInfo.ts hält Kontrakt und Fassade (B-Rep-Beschreibung der Extrusion aus TS). geomBBox ist gelöscht, Ausrichten/Verteilen fragt drawingBBoxes. Schneller in Griffen und Objekt-Info: Felder kleiner Objekte linear statt über den Map-Hash, Griff-Anfrage typisiert, Antworten direkt als Text, js_fmt::to_fixed mit Schnellweg. Gleichheit über 174 360 Auswahlen und 24 000 Ausricht-Fälle (einmaliger Test, gelöscht); TODO.md nachgeführt. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
11 files changed
+1705
-958
No files matched your search
@@ -491,13 +491,35 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom 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, 3000 Wände + 2000 Polylinien, alt/neu abwechselnd, Median, Container unter Last): Wand-Griff an Position
|
||||
10/1500/2990 39–43/198–218/324–348 µs → 40–44/192–193/318–337 µs (dominiert von der linearen id-Suche), Polylinien-Griff
|
||||
97–122 → 102–122 µs, Polylinien-Kante 108–138 → 109 µs, Wand verschieben 146–200 → 149–206 µs (gleich im Rahmen der
|
||||
Streuung), Griff an einer 5000-Punkte-Polylinie 16–18 → 13–14 ms; Griff-Liste der 5000-Punkte-Polylinie 2,7 → 1,1 ms
|
||||
(kleine Polylinie 2 → 4,5 µs). Nicht in der Tauri-App geprüft (vitest/Linux, e2e im Browser). Offen: `setPolylineVertexType`
|
||||
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 (~12 ms bei 5000 Punkten: Verlauf/Prüfung in `document.rs`/`ops.rs`).
|
||||
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.
|
||||
- ◐ **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
|
||||
|
||||
+227
-126
@@ -21,6 +21,18 @@ use serde_json::{Map, Value};
|
||||
|
||||
// ── JS-Zahlen in JSON ────────────────────────────────────────────────────────
|
||||
|
||||
/// Feld `k` eines Objekts. Kleine Objekte (Punkte, Elemente) werden linear durchsucht: das ist deutlich
|
||||
/// billiger als der Hash (SipHash) der `IndexMap` je Zugriff — die Griff- und Objekt-Info-Rechnung liest
|
||||
/// Dutzende Felder je Aufruf.
|
||||
#[inline]
|
||||
pub fn field<'a>(v: &'a Value, k: &str) -> Option<&'a Value> {
|
||||
match v {
|
||||
Value::Object(m) if m.len() <= 32 => m.iter().find(|(kk, _)| kk.as_str() == k).map(|(_, x)| x),
|
||||
Value::Object(m) => m.get(k),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Zahl als JSON-Wert wie nach `JSON.stringify` → `serde_json`: ganze Zahlen als Ganzzahl, sonst f64;
|
||||
/// NaN/±∞ als Marke (`"\u{1}NaN"` …), −0 als 0.
|
||||
pub fn js_num(x: f64) -> Value {
|
||||
@@ -90,7 +102,7 @@ pub fn pt(x: f64, y: f64) -> Value {
|
||||
|
||||
/// `(x, y)` eines Punkt-Werts (fehlende Koordinaten NaN).
|
||||
pub fn xy(v: &Value) -> (f64, f64) {
|
||||
(num_of(v.get("x")), num_of(v.get("y")))
|
||||
(num_of(field(v, "x")), num_of(field(v, "y")))
|
||||
}
|
||||
|
||||
/// `{...v, key: val}` (vorhandener Schlüssel behält seine Stelle). Der ersetzte Wert wird nicht kopiert
|
||||
@@ -189,20 +201,103 @@ fn with_geom(d: &Value, g: Value) -> Value {
|
||||
|
||||
// ── Anfrage ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/// Eine Änderung aus den Griff-Aktionen des Stores (JSON, Zahlen mit Nicht-endlich-Marken).
|
||||
pub struct Request<'a>(&'a Value);
|
||||
/// Zahl der Anfrage: Zahl oder Nicht-endlich-Marke, `null` = 0 (wie `num_of`), fehlend = NaN.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct N(pub f64);
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
fn n(&self, k: &str) -> f64 {
|
||||
num_of(self.0.get(k))
|
||||
impl Default for N {
|
||||
fn default() -> Self {
|
||||
N(f64::NAN)
|
||||
}
|
||||
fn s(&self, k: &str) -> Option<&'a str> {
|
||||
self.0.get(k).and_then(Value::as_str).filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for N {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||
struct V;
|
||||
impl serde::de::Visitor<'_> for V {
|
||||
type Value = N;
|
||||
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.write_str("Zahl")
|
||||
}
|
||||
fn visit_f64<E>(self, v: f64) -> Result<N, E> {
|
||||
Ok(N(v))
|
||||
}
|
||||
fn visit_i64<E>(self, v: i64) -> Result<N, E> {
|
||||
Ok(N(v as f64))
|
||||
}
|
||||
fn visit_u64<E>(self, v: u64) -> Result<N, E> {
|
||||
Ok(N(v as f64))
|
||||
}
|
||||
fn visit_str<E>(self, v: &str) -> Result<N, E> {
|
||||
Ok(N(num_of(Some(&Value::String(v.to_owned())))))
|
||||
}
|
||||
fn visit_unit<E>(self) -> Result<N, E> {
|
||||
Ok(N(0.0))
|
||||
}
|
||||
fn visit_bool<E>(self, _: bool) -> Result<N, E> {
|
||||
Ok(N(f64::NAN))
|
||||
}
|
||||
}
|
||||
d.deserialize_any(V)
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine Änderung aus den Griff-Aktionen des Stores (`GripRequest` in `geometry/grips.ts`); Zahlen dürfen
|
||||
/// Nicht-endlich-Marken sein. Typisiert gelesen (je Mausschritt billiger als ein JSON-Baum).
|
||||
#[derive(serde::Deserialize, Default, Debug)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct Request {
|
||||
pub op: String,
|
||||
drawing_id: Option<String>,
|
||||
wall_id: Option<String>,
|
||||
id: Option<String>,
|
||||
kind: Option<String>,
|
||||
new_id: Option<String>,
|
||||
new_name: Value,
|
||||
index: N,
|
||||
a: N,
|
||||
b: N,
|
||||
seg: N,
|
||||
scale: N,
|
||||
w: N,
|
||||
h: N,
|
||||
fx: N,
|
||||
fy: N,
|
||||
thickness: N,
|
||||
pt: [N; 2],
|
||||
delta: [N; 2],
|
||||
}
|
||||
|
||||
impl Request {
|
||||
fn n(&self, k: &str) -> f64 {
|
||||
match k {
|
||||
"index" => self.index.0,
|
||||
"a" => self.a.0,
|
||||
"b" => self.b.0,
|
||||
"seg" => self.seg.0,
|
||||
"scale" => self.scale.0,
|
||||
"w" => self.w.0,
|
||||
"h" => self.h.0,
|
||||
"fx" => self.fx.0,
|
||||
"fy" => self.fy.0,
|
||||
_ => self.thickness.0,
|
||||
}
|
||||
}
|
||||
/// Text-Feld; leer = fehlend (JS-Wahrheitswert der ids).
|
||||
fn s(&self, k: &str) -> Option<&str> {
|
||||
let v = match k {
|
||||
"drawingId" => &self.drawing_id,
|
||||
"wallId" => &self.wall_id,
|
||||
"kind" => &self.kind,
|
||||
"newId" => &self.new_id,
|
||||
_ => &self.id,
|
||||
};
|
||||
v.as_deref().filter(|s| !s.is_empty())
|
||||
}
|
||||
/// Punkt als `[x, y]`.
|
||||
fn p(&self, k: &str) -> (f64, f64) {
|
||||
let a = arr(self.0.get(k));
|
||||
(num_of(a.first()), num_of(a.get(1)))
|
||||
let [x, y] = if k == "pt" { self.pt } else { self.delta };
|
||||
(x.0, y.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,35 +316,37 @@ impl From<Vec<Op>> for GripResult {
|
||||
|
||||
/// Antwort-JSON `{"ops": […], "notice": …}` (Ops wie `CoreOp` in TS; `replace` ohne Kopie des Elements).
|
||||
pub fn result_json(r: &GripResult) -> String {
|
||||
let mut out = String::from("{\"ops\":[");
|
||||
// Direkt in einen Puffer (`to_writer`; `to_string` ginge über `fmt::Display` und wäre langsamer).
|
||||
let mut out: Vec<u8> = b"{\"ops\":[".to_vec();
|
||||
for (i, op) in r.ops.iter().enumerate() {
|
||||
if i > 0 {
|
||||
out.push(',');
|
||||
out.push(b',');
|
||||
}
|
||||
match op {
|
||||
let _ = match op {
|
||||
Op::Replace { collection, entity } => {
|
||||
out.push_str("{\"kind\":\"replace\",\"collection\":");
|
||||
out.push_str(&Value::from(collection.as_str()).to_string());
|
||||
out.push_str(",\"entity\":");
|
||||
out.push_str(&entity.to_string());
|
||||
out.push('}');
|
||||
out.extend_from_slice(b"{\"kind\":\"replace\",\"collection\":");
|
||||
let _ = serde_json::to_writer(&mut out, collection);
|
||||
out.extend_from_slice(b",\"entity\":");
|
||||
let w = serde_json::to_writer(&mut out, entity);
|
||||
out.push(b'}');
|
||||
w
|
||||
}
|
||||
op => out.push_str(&op.to_json().to_string()),
|
||||
}
|
||||
op => serde_json::to_writer(&mut out, &op.to_json()),
|
||||
};
|
||||
}
|
||||
out.push(']');
|
||||
out.push(b']');
|
||||
if let Some(n) = r.notice {
|
||||
out.push_str(",\"notice\":");
|
||||
out.push_str(&Value::from(n).to_string());
|
||||
out.extend_from_slice(b",\"notice\":");
|
||||
let _ = serde_json::to_writer(&mut out, n);
|
||||
}
|
||||
out.push('}');
|
||||
out
|
||||
out.push(b'}');
|
||||
String::from_utf8(out).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Führt eine Griff-Änderung aus (`req.op` wählt die Art, s. `src/state/gripOps.ts`).
|
||||
pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String> {
|
||||
let r = Request(req);
|
||||
let op = req.get("op").and_then(Value::as_str).unwrap_or("");
|
||||
pub fn run(root: &Map<String, Value>, req: &Request) -> Result<GripResult, String> {
|
||||
let r = req;
|
||||
let op = req.op.as_str();
|
||||
let patch = |coll: &str, id: Option<&str>, f: &dyn Fn(&Value) -> Option<Value>| -> Vec<Op> {
|
||||
id.and_then(|id| find(root, coll, id)).and_then(f).map(|e| vec![replace(coll, e)]).unwrap_or_default()
|
||||
};
|
||||
@@ -260,7 +357,7 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
let d = did.and_then(|i| find(root, "drawings2d", i));
|
||||
let w = wid.and_then(|i| find(root, "walls", i));
|
||||
// Objekt-Sperre: gesperrte Elemente lassen sich anwählen, aber nicht ziehen.
|
||||
if d.is_some_and(|d| truthy(d.get("locked"))) || w.is_some_and(|w| truthy(w.get("locked"))) {
|
||||
if d.is_some_and(|d| truthy(field(d, "locked"))) || w.is_some_and(|w| truthy(field(w, "locked"))) {
|
||||
return Ok(GripResult::default());
|
||||
}
|
||||
let f: Box<dyn Fn(&Value, bool) -> Option<Value>> = match op {
|
||||
@@ -284,11 +381,11 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"resize" => {
|
||||
let (w, h, fx, fy) = (r.n("w"), r.n("h"), r.n("fx"), r.n("fy"));
|
||||
if r.s("kind") == Some("drawing2d") {
|
||||
patch("drawings2d", r.s("id"), &|d| resize_geom(d.get("geom")?, w, h, fx, fy).map(|g| with_geom(d, g))).into()
|
||||
patch("drawings2d", r.s("id"), &|d| resize_geom(field(d, "geom")?, w, h, fx, fy).map(|g| with_geom(d, g))).into()
|
||||
} else {
|
||||
patch("walls", r.s("id"), &|wall| {
|
||||
let s = xy(wall.get("start").unwrap_or(&Value::Null));
|
||||
let e = xy(wall.get("end").unwrap_or(&Value::Null));
|
||||
let s = xy(field(wall, "start").unwrap_or(&Value::Null));
|
||||
let e = xy(field(wall, "end").unwrap_or(&Value::Null));
|
||||
let (ax, ay, sx, sy) = scale_around(bbox(&[s, e]), w, h, fx, fy);
|
||||
let f = |p: (f64, f64)| pt(ax + (p.0 - ax) * sx, ay + (p.1 - ay) * sy);
|
||||
Some(with_all(wall, vec![("start", f(s)), ("end", f(e))]))
|
||||
@@ -304,7 +401,7 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"ceilingBy" | "roofBy" => {
|
||||
let coll = if op == "ceilingBy" { "ceilings" } else { "roofs" };
|
||||
let (dx, dy) = r.p("delta");
|
||||
patch(coll, r.s("id"), &|e| Some(with(e, "outline", moved_all(e.get("outline")?.as_array()?, dx, dy)))).into()
|
||||
patch(coll, r.s("id"), &|e| Some(with(e, "outline", moved_all(field(e, "outline")?.as_array()?, dx, dy)))).into()
|
||||
}
|
||||
"ceilingEdge" | "roomEdge" => {
|
||||
let (coll, field) = if op == "ceilingEdge" { ("ceilings", "outline") } else { ("rooms", "boundary") };
|
||||
@@ -318,8 +415,8 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"stairBy" => {
|
||||
let (dx, dy) = r.p("delta");
|
||||
patch("stairs", r.s("id"), &|s| {
|
||||
let mut out = with(s, "start", moved(s.get("start").unwrap_or(&Value::Null), dx, dy));
|
||||
if truthy(s.get("center")) {
|
||||
let mut out = with(s, "start", moved(field(s, "start").unwrap_or(&Value::Null), dx, dy));
|
||||
if truthy(field(s, "center")) {
|
||||
out = with(&out, "center", moved(&s["center"], dx, dy));
|
||||
}
|
||||
Some(out)
|
||||
@@ -329,8 +426,8 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"roomBy" => {
|
||||
let (dx, dy) = r.p("delta");
|
||||
patch("rooms", r.s("id"), &|rm| {
|
||||
let mut out = with(rm, "boundary", moved_all(rm.get("boundary")?.as_array()?, dx, dy));
|
||||
if truthy(rm.get("stampAnchor")) {
|
||||
let mut out = with(rm, "boundary", moved_all(field(rm, "boundary")?.as_array()?, dx, dy));
|
||||
if truthy(field(rm, "stampAnchor")) {
|
||||
out = with(&out, "stampAnchor", moved(&rm["stampAnchor"], dx, dy));
|
||||
}
|
||||
Some(out)
|
||||
@@ -340,10 +437,10 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"roomStamp" => {
|
||||
let (dx, dy) = r.p("delta");
|
||||
patch("rooms", r.s("id"), &|rm| {
|
||||
let base = match rm.get("stampAnchor") {
|
||||
let base = match field(rm, "stampAnchor") {
|
||||
Some(a) if !a.is_null() => xy(a),
|
||||
_ => {
|
||||
let ring: Vec<[f64; 2]> = arr(rm.get("boundary")).iter().map(|p| xy(p).into()).collect();
|
||||
let ring: Vec<[f64; 2]> = arr(field(rm, "boundary")).iter().map(|p| xy(p).into()).collect();
|
||||
let c = crate::room_area::evaluate(&ring, 0.0).centroid;
|
||||
(c[0], c[1])
|
||||
}
|
||||
@@ -359,12 +456,12 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
"deletePoint" => {
|
||||
let index = r.n("index");
|
||||
let Some(d) = r.s("id").and_then(|i| find(root, "drawings2d", i)) else { return Ok(GripResult::default()) };
|
||||
let g = d.get("geom").unwrap_or(&Value::Null);
|
||||
if g.get("shape").and_then(Value::as_str) != Some("polyline") {
|
||||
let g = field(d, "geom").unwrap_or(&Value::Null);
|
||||
if field(g, "shape").and_then(Value::as_str) != Some("polyline") {
|
||||
return Ok(GripResult::default());
|
||||
}
|
||||
let pts = arr(g.get("pts"));
|
||||
let min = if truthy(g.get("closed")) { 4 } else { 3 };
|
||||
let pts = arr(field(g, "pts"));
|
||||
let min = if truthy(field(g, "closed")) { 4 } else { 3 };
|
||||
if pts.len() < min {
|
||||
return Ok(GripResult { ops: vec![], notice: Some("alert.polylineMinPoints") });
|
||||
}
|
||||
@@ -373,13 +470,13 @@ pub fn run(root: &Map<String, Value>, req: &Value) -> Result<GripResult, String>
|
||||
// seinen (die genaue Bogenform lässt sich ohne den Stützpunkt nicht erhalten).
|
||||
let drop = |l: &[Value]| Value::Array(l.iter().enumerate().filter(|(i, _)| *i != k).map(|(_, v)| v.clone()).collect());
|
||||
let mut fields = vec![("pts", drop(pts))];
|
||||
if truthy(g.get("bulge")) {
|
||||
fields.push(("bulge", drop(arr(g.get("bulge")))));
|
||||
if truthy(field(g, "bulge")) {
|
||||
fields.push(("bulge", drop(arr(field(g, "bulge")))));
|
||||
}
|
||||
vec![replace("drawings2d", with_geom(d, with_all(g, fields)))].into()
|
||||
}
|
||||
"wallThickness" => wall_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.get("newName").cloned().unwrap_or(Value::Null)).into(),
|
||||
"ceilingThickness" => ceiling_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.get("newName").cloned().unwrap_or(Value::Null)).into(),
|
||||
"wallThickness" => wall_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.new_name.clone()).into(),
|
||||
"ceilingThickness" => ceiling_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.new_name.clone()).into(),
|
||||
other => return Err(format!("Unbekannte Griff-Änderung: {other}")),
|
||||
})
|
||||
}
|
||||
@@ -391,15 +488,15 @@ fn wall_grip(w: &Value, index: f64, x: f64, y: f64) -> Value {
|
||||
}
|
||||
|
||||
fn wall_moved(w: &Value, dx: f64, dy: f64) -> Value {
|
||||
let s = moved(w.get("start").unwrap_or(&Value::Null), dx, dy);
|
||||
let e = moved(w.get("end").unwrap_or(&Value::Null), dx, dy);
|
||||
let s = moved(field(w, "start").unwrap_or(&Value::Null), dx, dy);
|
||||
let e = moved(field(w, "end").unwrap_or(&Value::Null), dx, dy);
|
||||
with_all(w, vec![("start", s), ("end", e)])
|
||||
}
|
||||
|
||||
// ── 2D-Zeichnungen ───────────────────────────────────────────────────────────
|
||||
|
||||
fn shape(g: &Value) -> &str {
|
||||
g.get("shape").and_then(Value::as_str).unwrap_or("")
|
||||
field(g, "shape").and_then(Value::as_str).unwrap_or("")
|
||||
}
|
||||
|
||||
/// Kreis, solange rx≈ry (relative Toleranz 0.5 %) — sonst Ellipse (rotation 0). Neues Objekt (weitere
|
||||
@@ -456,18 +553,18 @@ fn dim_text_pos(a: (f64, f64), b: (f64, f64), offset: f64, h: f64, along: f64, p
|
||||
|
||||
/// Schrifthöhe der Masszahl in Modell-Metern.
|
||||
fn dim_height(g: &Value, scale: f64) -> f64 {
|
||||
mm_to_model(num_or(g.get("textHeightMm"), DIM_TEXT_HEIGHT_MM), scale)
|
||||
mm_to_model(num_or(field(g, "textHeightMm"), DIM_TEXT_HEIGHT_MM), scale)
|
||||
}
|
||||
|
||||
/// Griff `index` einer 2D-Zeichnung auf (x, y) (`moveGrip`); `None` = keine Änderung.
|
||||
fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Value> {
|
||||
let g = d.get("geom")?;
|
||||
let g = field(d, "geom")?;
|
||||
let p = pt(x, y);
|
||||
let set = |k: &str, v: Value| Some(with_geom(d, with(g, k, v)));
|
||||
match shape(g) {
|
||||
"line" | "xline" | "ray" => set(if index == 0.0 { "a" } else { "b" }, p),
|
||||
"polyline" => {
|
||||
let pts = arr(g.get("pts"));
|
||||
let pts = arr(field(g, "pts"));
|
||||
let n = pts.len();
|
||||
if index < n as f64 {
|
||||
return set("pts", replace_at(pts, index, &p));
|
||||
@@ -478,16 +575,16 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
let a = xy(&pts[k]);
|
||||
let b = xy(if k == n - 1 { &pts[0] } else { &pts[k + 1] });
|
||||
let val = crate::bulge::from_sagitta_point(a.0, a.1, b.0, b.1, x, y);
|
||||
let mut bulge: Vec<Value> = arr(g.get("bulge")).to_vec();
|
||||
let mut bulge: Vec<Value> = arr(field(g, "bulge")).to_vec();
|
||||
while bulge.len() <= k {
|
||||
bulge.push(Value::from(0u64));
|
||||
}
|
||||
bulge[k] = js_num(val);
|
||||
set("bulge", Value::Array(bulge))
|
||||
}
|
||||
"bezier" | "spline" => set("pts", replace_at(arr(g.get("pts")), index, &p)),
|
||||
"bezier" | "spline" => set("pts", replace_at(arr(field(g, "pts")), index, &p)),
|
||||
"dimension" => {
|
||||
let pts = arr(g.get("pts"));
|
||||
let pts = arr(field(g, "pts"));
|
||||
let n = pts.len();
|
||||
if index < n as f64 {
|
||||
return set("pts", replace_at(pts, index, &p));
|
||||
@@ -507,7 +604,7 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
}
|
||||
let k = index_in(seg, n)?;
|
||||
let h = dim_height(g, scale);
|
||||
let (base, read, up) = dim_frame(xy(&pts[k]), xy(&pts[k + 1]), num_of(g.get("offset")), h);
|
||||
let (base, read, up) = dim_frame(xy(&pts[k]), xy(&pts[k + 1]), num_of(field(g, "offset")), h);
|
||||
let (vx, vy) = (x - base.0, y - base.1);
|
||||
let snap = h * 0.5;
|
||||
let along = vx * read.0 + vy * read.1;
|
||||
@@ -517,7 +614,7 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
let mut next = Map::new();
|
||||
next.insert("along".into(), js_num(model_to_mm(along, scale)));
|
||||
next.insert("perp".into(), js_num(model_to_mm(perp, scale)));
|
||||
let old = arr(g.get("textOffsetsMm"));
|
||||
let old = arr(field(g, "textOffsetsMm"));
|
||||
let offs: Vec<Value> = (0..n - 1)
|
||||
.map(|i| {
|
||||
if i == k {
|
||||
@@ -541,11 +638,11 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
Some(with_geom(d, with_all(g, vec![("min", min), ("max", max)])))
|
||||
}
|
||||
"text" => {
|
||||
if truthy(g.get("pathPts")) {
|
||||
return set("pathPts", replace_at(arr(g.get("pathPts")), index, &p));
|
||||
if truthy(field(g, "pathPts")) {
|
||||
return set("pathPts", replace_at(arr(field(g, "pathPts")), index, &p));
|
||||
}
|
||||
if truthy(g.get("leaderTarget")) {
|
||||
let bends = arr(g.get("leaderBendPoints"));
|
||||
if truthy(field(g, "leaderTarget")) {
|
||||
let bends = arr(field(g, "leaderBendPoints"));
|
||||
let tip = bends.len() as f64 + 1.0;
|
||||
if index == 0.0 {
|
||||
return set("at", p);
|
||||
@@ -559,12 +656,12 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
}
|
||||
return None;
|
||||
}
|
||||
let width = num_of(g.get("width"));
|
||||
if truthy(g.get("width")) && width > 0.0 && index >= 0.0 && index < 4.0 {
|
||||
let width = num_of(field(g, "width"));
|
||||
if truthy(field(g, "width")) && width > 0.0 && index >= 0.0 && index < 4.0 {
|
||||
// Nur die Spaltenbreite ändert sich (InDesign-Textrahmen); Zug auf die lokale x-Achse.
|
||||
let angle = num_of(g.get("angle"));
|
||||
let angle = num_of(field(g, "angle"));
|
||||
let (cos, sin) = (jsnum::cos(angle), jsnum::sin(angle));
|
||||
let (ax, ay) = xy(g.get("at").unwrap_or(&Value::Null));
|
||||
let (ax, ay) = xy(field(g, "at").unwrap_or(&Value::Null));
|
||||
let local_x = (x - ax) * cos + (y - ay) * sin;
|
||||
const MIN_WIDTH: f64 = 0.1;
|
||||
if index == 0.0 || index == 3.0 {
|
||||
@@ -578,30 +675,30 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option<Val
|
||||
}
|
||||
"kote" | "detailref" | "scalebar" | "pointmarker" | "block" => set("at", p),
|
||||
"circle" => {
|
||||
let (cx, cy) = xy(g.get("center").unwrap_or(&Value::Null));
|
||||
let r = pass(g.get("r"));
|
||||
let (cx, cy) = xy(field(g, "center").unwrap_or(&Value::Null));
|
||||
let r = pass(field(g, "r"));
|
||||
let (rx, ry) = if index == 0.0 { (calc(jsnum::max(1e-3, (x - cx).abs())), r) } else { (r, calc(jsnum::max(1e-3, (y - cy).abs()))) };
|
||||
Some(with_geom(d, ellipse_or_circle(g.get("center"), rx, ry)))
|
||||
Some(with_geom(d, ellipse_or_circle(field(g, "center"), rx, ry)))
|
||||
}
|
||||
"arc" => {
|
||||
let (cx, cy) = xy(g.get("center").unwrap_or(&Value::Null));
|
||||
let (cx, cy) = xy(field(g, "center").unwrap_or(&Value::Null));
|
||||
if index == 2.0 {
|
||||
return set("r", js_num(jsnum::max(1e-3, hypot2(x - cx, y - cy))));
|
||||
}
|
||||
set(if index == 0.0 { "a0" } else { "a1" }, js_num(jsnum::atan2(y - cy, x - cx)))
|
||||
}
|
||||
"ellipse" => {
|
||||
let rot = num_of(g.get("rotation"));
|
||||
let rot = num_of(field(g, "rotation"));
|
||||
let (c, s) = (jsnum::cos(rot), jsnum::sin(rot));
|
||||
let (cx, cy) = xy(g.get("center").unwrap_or(&Value::Null));
|
||||
let (cx, cy) = xy(field(g, "center").unwrap_or(&Value::Null));
|
||||
let (dx, dy) = (x - cx, y - cy);
|
||||
let lx = dx * c + dy * s;
|
||||
let ly = -dx * s + dy * c;
|
||||
let rx = if index == 0.0 { calc(jsnum::max(1e-3, lx.abs())) } else { pass(g.get("rx")) };
|
||||
let ry = if index == 0.0 { pass(g.get("ry")) } else { calc(jsnum::max(1e-3, ly.abs())) };
|
||||
let rx = if index == 0.0 { calc(jsnum::max(1e-3, lx.abs())) } else { pass(field(g, "rx")) };
|
||||
let ry = if index == 0.0 { pass(field(g, "ry")) } else { calc(jsnum::max(1e-3, ly.abs())) };
|
||||
// Nur ungedreht (`rotation === 0`) kann eine (fast) gleichseitige Ellipse wieder zum Kreis werden.
|
||||
if g.get("rotation").and_then(Value::as_f64) == Some(0.0) {
|
||||
return Some(with_geom(d, ellipse_or_circle(g.get("center"), rx, ry)));
|
||||
if field(g, "rotation").and_then(Value::as_f64) == Some(0.0) {
|
||||
return Some(with_geom(d, ellipse_or_circle(field(g, "center"), rx, ry)));
|
||||
}
|
||||
Some(with_geom(d, with_opt(g, vec![("rx", rx.v), ("ry", ry.v)])))
|
||||
}
|
||||
@@ -620,18 +717,18 @@ fn or1(l: f64) -> f64 {
|
||||
|
||||
/// Ecken eines Rechtecks/Bilds in Griff-Reihenfolge: min, (max.x, min.y), max, (min.x, max.y).
|
||||
fn rect_corners(g: &Value) -> [(f64, f64); 4] {
|
||||
let mn = xy(g.get("min").unwrap_or(&Value::Null));
|
||||
let mx = xy(g.get("max").unwrap_or(&Value::Null));
|
||||
let mn = xy(field(g, "min").unwrap_or(&Value::Null));
|
||||
let mx = xy(field(g, "max").unwrap_or(&Value::Null));
|
||||
[mn, (mx.0, mn.1), mx, (mn.0, mx.1)]
|
||||
}
|
||||
|
||||
/// Ganze 2D-Zeichnung verschieben (`moveElementBy`); `None` = Form ohne Verschiebung.
|
||||
fn drawing_moved(d: &Value, dx: f64, dy: f64) -> Option<Value> {
|
||||
let g = d.get("geom")?;
|
||||
let g = field(d, "geom")?;
|
||||
let mv = |k: &str| moved(g.get(k).unwrap_or(&Value::Null), dx, dy);
|
||||
let ng = match shape(g) {
|
||||
"line" => with_all(g, vec![("a", mv("a")), ("b", mv("b"))]),
|
||||
"polyline" | "bezier" | "spline" | "dimension" => with(g, "pts", moved_all(arr(g.get("pts")), dx, dy)),
|
||||
"polyline" | "bezier" | "spline" | "dimension" => with(g, "pts", moved_all(arr(field(g, "pts")), dx, dy)),
|
||||
"rect" | "image" => with_all(g, vec![("min", mv("min")), ("max", mv("max"))]),
|
||||
"circle" | "arc" | "ellipse" => with(g, "center", mv("center")),
|
||||
"kote" | "detailref" | "scalebar" | "pointmarker" | "text" => with(g, "at", mv("at")),
|
||||
@@ -642,10 +739,10 @@ fn drawing_moved(d: &Value, dx: f64, dy: f64) -> Option<Value> {
|
||||
|
||||
/// Kante (a, b) einer 2D-Zeichnung verschieben (`moveEdge`); `None` = keine Änderung.
|
||||
fn drawing_edge(d: &Value, a: f64, b: f64, dx: f64, dy: f64) -> Option<Value> {
|
||||
let g = d.get("geom")?;
|
||||
let g = field(d, "geom")?;
|
||||
let ng = match shape(g) {
|
||||
"line" => with_all(g, vec![("a", moved(g.get("a").unwrap_or(&Value::Null), dx, dy)), ("b", moved(g.get("b").unwrap_or(&Value::Null), dx, dy))]),
|
||||
"polyline" | "spline" => with(g, "pts", move_polygon_edge(arr(g.get("pts")), a, b, dx, dy, truthy(g.get("closed")))?),
|
||||
"line" => with_all(g, vec![("a", moved(field(g, "a").unwrap_or(&Value::Null), dx, dy)), ("b", moved(field(g, "b").unwrap_or(&Value::Null), dx, dy))]),
|
||||
"polyline" | "spline" => with(g, "pts", move_polygon_edge(arr(field(g, "pts")), a, b, dx, dy, truthy(field(g, "closed")))?),
|
||||
"rect" | "image" => {
|
||||
// Die zwei Kanten-Ecken verschieben, dann die bbox neu bilden (achsparallel).
|
||||
let corners = rect_corners(g);
|
||||
@@ -786,18 +883,18 @@ fn resize_geom(g: &Value, w: f64, h: f64, fx: f64, fy: f64) -> Option<Value> {
|
||||
"circle" | "arc" => {
|
||||
// bbox eines Kreises ist 2r × 2r; Radius = grössere Zielhälfte, Mitte nicht-uniform um den Anker.
|
||||
let c = p("center");
|
||||
let r = num_of(g.get("r"));
|
||||
let r = num_of(field(g, "r"));
|
||||
let ax = (c.0 - r) + fx * (2.0 * r);
|
||||
let ay = (c.1 - r) + fy * (2.0 * r);
|
||||
let half = jsnum::max(w, h) / 2.0;
|
||||
let nr = if half > 0.0 { Some(js_num(half)) } else { g.get("r").cloned() };
|
||||
let nr = if half > 0.0 { Some(js_num(half)) } else { field(g, "r").cloned() };
|
||||
let sx = if r > 1e-9 { (w / 2.0) / r } else { 1.0 };
|
||||
let sy = if r > 1e-9 { (h / 2.0) / r } else { 1.0 };
|
||||
with_opt(g, vec![("center", Some(pt(ax + (c.0 - ax) * sx, ay + (c.1 - ay) * sy))), ("r", nr)])
|
||||
}
|
||||
"ellipse" => {
|
||||
let c = p("center");
|
||||
let (rx, ry) = (num_of(g.get("rx")), num_of(g.get("ry")));
|
||||
let (rx, ry) = (num_of(field(g, "rx")), num_of(field(g, "ry")));
|
||||
let (ax, ay, sx, sy) = scale_around((c.0 - rx, c.1 - ry, c.0 + rx, c.1 + ry), w, h, fx, fy);
|
||||
with_all(g, vec![("center", pt(ax + (c.0 - ax) * sx, ay + (c.1 - ay) * sy)), ("rx", js_num(jsnum::max(1e-3, rx * sx))), ("ry", js_num(jsnum::max(1e-3, ry * sy)))])
|
||||
}
|
||||
@@ -815,7 +912,7 @@ fn resize_geom(g: &Value, w: f64, h: f64, fx: f64, fy: f64) -> Option<Value> {
|
||||
|
||||
/// Dach-Eckgriff: die gegenüberliegende Ecke bleibt fix, der Umriss bleibt ein achsparalleles Rechteck.
|
||||
fn roof_grip(r: &Value, index: f64, x: f64, y: f64) -> Option<Value> {
|
||||
let outline = r.get("outline")?.as_array()?;
|
||||
let outline = field(r, "outline")?.as_array()?;
|
||||
let n = outline.len();
|
||||
if n < 4 {
|
||||
return None;
|
||||
@@ -831,20 +928,20 @@ fn roof_grip(r: &Value, index: f64, x: f64, y: f64) -> Option<Value> {
|
||||
/// Winkel-Mitte geteilt (wie `kernel2d` Bogen-Segmente zuschneidet); eine Näherung über tessellierte
|
||||
/// Punkte wäre zu ungenau. Die Bulge-Liste wird nur mitgeführt, wenn es eine gab.
|
||||
fn insert_point(d: &Value, seg: f64, x: f64, y: f64) -> Option<Value> {
|
||||
let g = d.get("geom")?;
|
||||
let g = field(d, "geom")?;
|
||||
if shape(g) != "polyline" {
|
||||
return None;
|
||||
}
|
||||
let pts = arr(g.get("pts"));
|
||||
let pts = arr(field(g, "pts"));
|
||||
let n = pts.len();
|
||||
let k = index_in(seg, n)?;
|
||||
let last = k == n - 1;
|
||||
if last && !truthy(g.get("closed")) {
|
||||
if last && !truthy(field(g, "closed")) {
|
||||
return None;
|
||||
}
|
||||
let a = xy(&pts[k]);
|
||||
let b = xy(if last { &pts[0] } else { &pts[k + 1] });
|
||||
let bulge = num_or(arr(g.get("bulge")).get(k), 0.0);
|
||||
let bulge = num_or(arr(field(g, "bulge")).get(k), 0.0);
|
||||
// `bulgeArc` der Fassade: gerade (|bulge| < 1e-9 oder NaN) ohne Bogen.
|
||||
let arc = if bulge.abs() >= 1e-9 { crate::bulge::arc(a.0, a.1, b.0, b.1, bulge) } else { vec![] };
|
||||
let (insert, b1, b2) = if arc.len() >= 6 {
|
||||
@@ -863,8 +960,8 @@ fn insert_point(d: &Value, seg: f64, x: f64, y: f64) -> Option<Value> {
|
||||
np.push(insert);
|
||||
np.extend_from_slice(&pts[k + 1..]);
|
||||
let mut fields = vec![("pts", Value::Array(np))];
|
||||
if truthy(g.get("bulge")) {
|
||||
let old = arr(g.get("bulge"));
|
||||
if truthy(field(g, "bulge")) {
|
||||
let old = arr(field(g, "bulge"));
|
||||
let mut nb: Vec<Value> = old.iter().take(k).cloned().collect();
|
||||
nb.push(js_num(b1));
|
||||
nb.push(js_num(b2));
|
||||
@@ -899,17 +996,17 @@ fn wall_thickness(root: &Map<String, Value>, wall_id: &str, thickness: f64, new_
|
||||
return vec![];
|
||||
}
|
||||
let Some(wall) = find(root, "walls", wall_id) else { return vec![] };
|
||||
let wt_id = wall.get("wallTypeId");
|
||||
let Some(wt) = arr(root.get("wallTypes")).iter().find(|t| t.get("id") == wt_id) else { return vec![] };
|
||||
let layers = arr(wt.get("layers"));
|
||||
let wt_id = field(wall, "wallTypeId");
|
||||
let Some(wt) = arr(root.get("wallTypes")).iter().find(|t| field(t, "id") == wt_id) else { return vec![] };
|
||||
let layers = arr(field(wt, "layers"));
|
||||
if layers.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
let wt_idv = wt.get("id");
|
||||
let used_by_others = arr(root.get("walls")).iter().any(|w| id_of(w) != Some(wall_id) && w.get("wallTypeId") == wt_idv);
|
||||
let wt_idv = field(wt, "id");
|
||||
let used_by_others = arr(root.get("walls")).iter().any(|w| id_of(w) != Some(wall_id) && field(w, "wallTypeId") == wt_idv);
|
||||
if layers.len() == 1 && !used_by_others {
|
||||
let tid = id_of(wt).unwrap_or("");
|
||||
return find(root, "wallTypes", tid).map(|t| vec![replace("wallTypes", with(t, "layers", single_layer(arr(t.get("layers")), thickness)))]).unwrap_or_default();
|
||||
return find(root, "wallTypes", tid).map(|t| vec![replace("wallTypes", with(t, "layers", single_layer(arr(field(t, "layers")), thickness)))]).unwrap_or_default();
|
||||
}
|
||||
vec![add("wallTypes", new_type(new_id, new_name, layers, thickness)), replace("walls", with(wall, "wallTypeId", new_id.into()))]
|
||||
}
|
||||
@@ -922,20 +1019,20 @@ fn ceiling_thickness(root: &Map<String, Value>, ceiling_id: &str, thickness: f64
|
||||
}
|
||||
let Some(c) = find(root, "ceilings", ceiling_id) else { return vec![] };
|
||||
let active = |c: &Value| -> Option<Value> {
|
||||
let v = c.get("ceilingTypeId");
|
||||
if nullish(v) { c.get("wallTypeId").cloned() } else { v.cloned() }
|
||||
let v = field(c, "ceilingTypeId");
|
||||
if nullish(v) { field(c, "wallTypeId").cloned() } else { v.cloned() }
|
||||
};
|
||||
let active_id = active(c);
|
||||
let by_id = |coll: &str, id: Option<&Value>| arr(root.get(coll)).iter().find(|t| t.get("id") == id).cloned();
|
||||
let Some(ct) = by_id("ceilingTypes", c.get("ceilingTypeId")).or_else(|| by_id("wallTypes", c.get("wallTypeId"))) else { return vec![] };
|
||||
let layers = arr(ct.get("layers"));
|
||||
let by_id = |coll: &str, id: Option<&Value>| arr(root.get(coll)).iter().find(|t| field(t, "id") == id).cloned();
|
||||
let Some(ct) = by_id("ceilingTypes", field(c, "ceilingTypeId")).or_else(|| by_id("wallTypes", field(c, "wallTypeId"))) else { return vec![] };
|
||||
let layers = arr(field(&ct, "layers"));
|
||||
if layers.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
let used_by_others = arr(root.get("ceilings")).iter().any(|o| id_of(o) != Some(ceiling_id) && active(o) == active_id);
|
||||
if layers.len() == 1 && !used_by_others && truthy(c.get("ceilingTypeId")) {
|
||||
if layers.len() == 1 && !used_by_others && truthy(field(c, "ceilingTypeId")) {
|
||||
let tid = id_of(&ct).unwrap_or("");
|
||||
return find(root, "ceilingTypes", tid).map(|t| vec![replace("ceilingTypes", with(t, "layers", single_layer(arr(t.get("layers")), thickness)))]).unwrap_or_default();
|
||||
return find(root, "ceilingTypes", tid).map(|t| vec![replace("ceilingTypes", with(t, "layers", single_layer(arr(field(t, "layers")), thickness)))]).unwrap_or_default();
|
||||
}
|
||||
let mut nc = with(c, "ceilingTypeId", new_id.into());
|
||||
if let Value::Object(m) = &mut nc {
|
||||
@@ -957,25 +1054,25 @@ pub fn drawing_vertices(g: &Value, scale: f64) -> Option<Vec<(f64, f64)>> {
|
||||
Some(match shape(g) {
|
||||
"line" | "xline" | "ray" => vec![p("a"), p("b")],
|
||||
"polyline" => {
|
||||
let bulge = arr(g.get("bulge"));
|
||||
polyline_vertices(pts("pts"), truthy(g.get("closed")), |i| num_or(bulge.get(i), 0.0))
|
||||
let bulge = arr(field(g, "bulge"));
|
||||
polyline_vertices(pts("pts"), truthy(field(g, "closed")), |i| num_or(bulge.get(i), 0.0))
|
||||
}
|
||||
"rect" | "image" => rect_corners(g).to_vec(),
|
||||
"circle" => {
|
||||
let (c, r) = (p("center"), num_of(g.get("r")));
|
||||
let (c, r) = (p("center"), num_of(field(g, "r")));
|
||||
vec![(c.0 + r, c.1), (c.0, c.1 + r)]
|
||||
}
|
||||
"arc" => {
|
||||
let (c, r) = (p("center"), num_of(g.get("r")));
|
||||
let (a0, a1) = (num_of(g.get("a0")), num_of(g.get("a1")));
|
||||
let (c, r) = (p("center"), num_of(field(g, "r")));
|
||||
let (a0, a1) = (num_of(field(g, "a0")), num_of(field(g, "a1")));
|
||||
let mid = (a0 + a1) / 2.0;
|
||||
[a0, a1, mid].iter().map(|a| (c.0 + r * jsnum::cos(*a), c.1 + r * jsnum::sin(*a))).collect()
|
||||
}
|
||||
"ellipse" => {
|
||||
let rot = num_of(g.get("rotation"));
|
||||
let rot = num_of(field(g, "rotation"));
|
||||
let (c, s) = (jsnum::cos(rot), jsnum::sin(rot));
|
||||
let ctr = p("center");
|
||||
let (rx, ry) = (num_of(g.get("rx")), num_of(g.get("ry")));
|
||||
let (rx, ry) = (num_of(field(g, "rx")), num_of(field(g, "ry")));
|
||||
vec![(ctr.0 + rx * c, ctr.1 + rx * s), (ctr.0 - ry * s, ctr.1 + ry * c)]
|
||||
}
|
||||
"bezier" | "spline" => pts("pts"),
|
||||
@@ -986,14 +1083,14 @@ pub fn drawing_vertices(g: &Value, scale: f64) -> Option<Vec<(f64, f64)>> {
|
||||
let (a, b) = (out.first().copied().unwrap_or(nan), out.last().copied().unwrap_or(nan));
|
||||
let (dx, dy) = (b.0 - a.0, b.1 - a.1);
|
||||
let len = or1(hypot2(dx, dy));
|
||||
let offset = num_of(g.get("offset"));
|
||||
let offset = num_of(field(g, "offset"));
|
||||
let (nx, ny) = ((-dy / len) * offset, (dx / len) * offset);
|
||||
out.push(((a.0 + b.0) / 2.0 + nx, (a.1 + b.1) / 2.0 + ny));
|
||||
let h = dim_height(g, scale);
|
||||
let offs = arr(g.get("textOffsetsMm"));
|
||||
let offs = arr(field(g, "textOffsetsMm"));
|
||||
for i in 0..n.saturating_sub(1) {
|
||||
let (along, perp) = match offs.get(i) {
|
||||
Some(o) if truthy(Some(o)) => (mm_to_model(num_of(o.get("along")), scale), mm_to_model(num_of(o.get("perp")), scale)),
|
||||
Some(o) if truthy(Some(o)) => (mm_to_model(num_of(field(o, "along")), scale), mm_to_model(num_of(field(o, "perp")), scale)),
|
||||
_ => (0.0, 0.0),
|
||||
};
|
||||
out.push(dim_text_pos(out[i], out[i + 1], offset, h, along, perp));
|
||||
@@ -1002,14 +1099,14 @@ pub fn drawing_vertices(g: &Value, scale: f64) -> Option<Vec<(f64, f64)>> {
|
||||
}
|
||||
"kote" | "detailref" | "scalebar" | "pointmarker" | "block" => vec![p("at")],
|
||||
"text" => {
|
||||
if truthy(g.get("pathPts")) {
|
||||
if truthy(field(g, "pathPts")) {
|
||||
pts("pathPts")
|
||||
} else if truthy(g.get("leaderTarget")) {
|
||||
} else if truthy(field(g, "leaderTarget")) {
|
||||
let mut out = vec![p("at")];
|
||||
out.extend(pts("leaderBendPoints"));
|
||||
out.push(p("leaderTarget"));
|
||||
out
|
||||
} else if truthy(g.get("width")) && num_of(g.get("width")) > 0.0 {
|
||||
} else if truthy(field(g, "width")) && num_of(field(g, "width")) > 0.0 {
|
||||
return None;
|
||||
} else {
|
||||
vec![p("at")]
|
||||
@@ -1080,6 +1177,10 @@ mod tests {
|
||||
v.as_object().unwrap().clone()
|
||||
}
|
||||
|
||||
fn rq(v: Value) -> Request {
|
||||
serde_json::from_value(v).unwrap()
|
||||
}
|
||||
|
||||
fn entity(r: &GripResult) -> &Value {
|
||||
match &r.ops[0] {
|
||||
Op::Replace { entity, .. } => entity,
|
||||
@@ -1103,18 +1204,18 @@ mod tests {
|
||||
#[test]
|
||||
fn wand_griff_und_sperre() {
|
||||
let r = root(json!({"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 1, "y": 0}, "extra": 1}]}));
|
||||
let res = run(&r, &json!({"op": "moveGrip", "wallId": "w", "index": 1, "pt": [2, 3]})).unwrap();
|
||||
let res = run(&r, &rq(json!({"op": "moveGrip", "wallId": "w", "index": 1, "pt": [2, 3]}))).unwrap();
|
||||
assert_eq!(entity(&res).to_string(), r#"{"id":"w","start":{"x":0,"y":0},"end":{"x":2,"y":3},"extra":1}"#);
|
||||
let locked = root(json!({"walls": [{"id": "w", "locked": true, "start": {"x": 0, "y": 0}, "end": {"x": 1, "y": 0}}]}));
|
||||
assert!(run(&locked, &json!({"op": "moveGrip", "wallId": "w", "index": 1, "pt": [2, 3]})).unwrap().ops.is_empty());
|
||||
assert!(run(&locked, &rq(json!({"op": "moveGrip", "wallId": "w", "index": 1, "pt": [2, 3]}))).unwrap().ops.is_empty());
|
||||
// Fehlendes Element: keine Op.
|
||||
assert!(run(&r, &json!({"op": "moveGrip", "wallId": "x", "index": 1, "pt": [2, 3]})).unwrap().ops.is_empty());
|
||||
assert!(run(&r, &rq(json!({"op": "moveGrip", "wallId": "x", "index": 1, "pt": [2, 3]}))).unwrap().ops.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kreis_wird_ellipse() {
|
||||
let r = root(json!({"drawings2d": [{"id": "d", "geom": {"shape": "circle", "center": {"x": 0, "y": 0}, "r": 1}}]}));
|
||||
let res = run(&r, &json!({"op": "moveGrip", "drawingId": "d", "index": 0, "pt": [2, 0]})).unwrap();
|
||||
let res = run(&r, &rq(json!({"op": "moveGrip", "drawingId": "d", "index": 0, "pt": [2, 0]}))).unwrap();
|
||||
assert_eq!(entity(&res)["geom"].to_string(), r#"{"shape":"ellipse","center":{"x":0,"y":0},"rx":2,"ry":1,"rotation":0}"#);
|
||||
}
|
||||
|
||||
@@ -1130,14 +1231,14 @@ mod tests {
|
||||
#[test]
|
||||
fn nan_als_marke() {
|
||||
let r = root(json!({"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 1, "y": 0}}]}));
|
||||
let res = run(&r, &json!({"op": "moveBy", "wallId": "w", "delta": ["\u{1}NaN", 0]})).unwrap();
|
||||
let res = run(&r, &rq(json!({"op": "moveBy", "wallId": "w", "delta": ["\u{1}NaN", 0]}))).unwrap();
|
||||
assert_eq!(entity(&res)["start"]["x"], json!("\u{1}NaN"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn punkt_loeschen_mindestzahl() {
|
||||
let r = root(json!({"drawings2d": [{"id": "d", "geom": {"shape": "polyline", "closed": false, "pts": [{"x": 0, "y": 0}, {"x": 1, "y": 0}]}}]}));
|
||||
let res = run(&r, &json!({"op": "deletePoint", "id": "d", "index": 0})).unwrap();
|
||||
let res = run(&r, &rq(json!({"op": "deletePoint", "id": "d", "index": 0}))).unwrap();
|
||||
assert_eq!(res.notice, Some("alert.polylineMinPoints"));
|
||||
assert!(res.ops.is_empty());
|
||||
}
|
||||
@@ -1148,7 +1249,7 @@ mod tests {
|
||||
"wallTypes": [{"id": "wt", "name": "W", "layers": [{"componentId": "c", "thickness": 0.2}]}],
|
||||
"ceilings": [{"id": "c1", "wallTypeId": "wt", "thickness": 0.3}, {"id": "c2", "wallTypeId": "wt"}],
|
||||
}));
|
||||
let ops = run(&r, &json!({"op": "ceilingThickness", "id": "c1", "thickness": 0.25, "newId": "ct-1", "newName": "Decke"})).unwrap().ops;
|
||||
let ops = run(&r, &rq(json!({"op": "ceilingThickness", "id": "c1", "thickness": 0.25, "newId": "ct-1", "newName": "Decke"}))).unwrap().ops;
|
||||
assert_eq!(crate::ops::ops_to_json(&ops), r#"[{"kind":"add","collection":"ceilingTypes","items":[{"id":"ct-1","name":"Decke","layers":[{"componentId":"c","thickness":0.25}]}]},{"kind":"replace","collection":"ceilings","entity":{"id":"c1","wallTypeId":"wt","ceilingTypeId":"ct-1"}}]"#);
|
||||
}
|
||||
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ pub mod geo_translate;
|
||||
pub mod selection_filter;
|
||||
pub mod reorder;
|
||||
pub mod grips;
|
||||
pub mod selection_info;
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
@@ -100,9 +100,20 @@ pub fn run_root(root: &serde_json::Map<String, serde_json::Value>, name: &str, t
|
||||
}
|
||||
// Griff-Änderungen ([K4] S3, `grips.rs`): `text` = JSON der Anfrage; Antwort `{ops, notice}` (ohne Commit).
|
||||
"gripOps" => {
|
||||
let req: serde_json::Value = serde_json::from_str(text).map_err(|e| format!("gripOps: {e}"))?;
|
||||
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())
|
||||
}
|
||||
_ => Err(format!("Unbekannte Wurzel-Abfrage: {name}")),
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,7 +12,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
|
||||
/// (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: Value = match serde_json::from_str(req_json) {
|
||||
let req: crate::grips::Request = match serde_json::from_str(req_json) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return format!("\u{1}Griff-Anfrage: {e}"),
|
||||
};
|
||||
|
||||
+22
-2
@@ -245,7 +245,7 @@ export class ProjectDocument {
|
||||
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, toMarkedJson(req), coalesceKey ?? "", now);
|
||||
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;
|
||||
@@ -255,10 +255,21 @@ export class ProjectDocument {
|
||||
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", 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", toMarkedJson(req));
|
||||
const out = core().doc_query_root(this.handle, "gripOps", gripJson(req));
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
return fromMarkedJson(out);
|
||||
}
|
||||
@@ -320,6 +331,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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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 } 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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
+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;
|
||||
}
|
||||
Reference in new issue
Block a user