Files
DOSSIER/src-tauri/core/src/web/grips.rs
T
Claude ed475fe64b [213] Kameras als Modell-Elemente und Begehen (WASD) im 3D
Project.cameras (Rust Camera: Standpunkt + Augenhöhe über Geschoss, Ziel, Bildwinkel, Perspektive/
Axonometrie/Parallel, Sonnenstand) auf der neuen Klasse "Kameras" (92). Grundriss-Symbol im Kern
(plan/cameras.rs: Gehäuse, Sichtkegel, Ziel, Name, schmale Pick-Bänder), Griffe im Kern (camera.rs,
grips.rs: Standpunkt, Ziel, Bildwinkel/Sichtbreite), Auswahl/Entf, Objekt-Info CameraSection, Liste im
Panel Ausschnitte, "Kamera aus aktueller Ansicht anlegen", "Kamera öffnen" (auch per Doppelklick auf das
Symbol), cameraToView() für das Rendering [211]. Begehen im 3D: Umschalt+F, W/A/S/D/Pfeile, Q/E,
Umschalt/Alt, Umschauen um den Augpunkt (viewport/walk.ts). Beispiel: Kamera im Musterhaus komplex.
2026-11-12 18:31:37 +00:00

103 lines
5.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Bindungen der Griff-Geometrie (`crate::grips`): Griff-Änderung im Dokument rechnen und gleich als
//! Benutzer-Änderung anwenden (ein Aufruf je Mausschritt, keine Op-Übergabe hin und zurück), Griff-
//! und Kanten-Listen für die Anzeige als flache Puffer.
use super::document::with_doc;
use serde_json::{json, Value};
use wasm_bindgen::prelude::wasm_bindgen;
/// Griff-Änderung `req_json` (s. `crate::grips::run`) auf dem Dokument `h` rechnen und mit Verlauf
/// anwenden (`key` = coalesceKey, `now_ms` = Zeit für das Koaleszenz-Fenster, wie `doc_commit`).
/// Antwort: `{"ops":[…],"notice":…}` (angewendet; leer = nichts zu tun) oder `{"problems":[…]}`
/// (zurückgewiesen, Dokument unverändert); Fehler als Text mit vorangestelltem `\u{1}`.
#[wasm_bindgen]
pub fn doc_grip_commit(h: u32, req_json: &str, key: &str, now_ms: f64) -> String {
let req: crate::grips::Request = match serde_json::from_str(req_json) {
Ok(v) => v,
Err(e) => return format!("\u{1}Griff-Anfrage: {e}"),
};
let key = (!key.is_empty()).then_some(key);
let now = if now_ms.is_finite() { now_ms } else { 0.0 };
let out = with_doc(h, |d| -> Result<String, String> {
let res = crate::grips::run_doc(d, &req)?;
let text = crate::grips::result_json(&res);
if res.ops.is_empty() {
return Ok(text);
}
// Nicht endliche Ergebnisse stehen als Marken in den Ops (die Prüfung weist sie zurück).
let marks = text.contains("\\u0001");
match d.commit(res.ops, key, now, marks) {
Ok(()) => Ok(text),
Err(problems) => Ok(json!({ "problems": problems }).to_string()),
}
});
match out {
Some(Ok(t)) => t,
Some(Err(e)) => format!("\u{1}{e}"),
None => "\u{1}Dokument nicht offen".to_string(),
}
}
/// Editier-Griffe einer 2D-Zeichnung (JSON) beim Massstab 1:`scale`: `[n, x0, y0, …]`; `[-1]` = Textspalte
/// (Rahmen-Ecken rechnet die Hülle mit der Schrift-Metrik), `[]` bei kaputtem JSON.
#[wasm_bindgen]
pub fn grip_vertices(drawing_json: &str, scale: f64) -> Vec<f64> {
let Ok(d) = serde_json::from_str::<Value>(drawing_json) else { return vec![] };
let g = d.get("geom").unwrap_or(&d);
match crate::grips::drawing_vertices(g, scale) {
None => vec![-1.0],
Some(v) => {
let mut out = Vec::with_capacity(1 + 2 * v.len());
out.push(v.len() as f64);
for p in v {
out.push(p.0);
out.push(p.1);
}
out
}
}
}
/// [213] Griffe einer Kamera (JSON) beim Massstab 1:`scale`: `[x0, y0, x1, y1, x2, y2]` (Standpunkt, Ziel,
/// Bildwinkel/Sichtbreite), `[]` bei kaputtem JSON.
#[wasm_bindgen]
pub fn camera_grip_points(camera_json: &str, scale: f64) -> Vec<f64> {
let Ok(c) = serde_json::from_str::<crate::model::Camera>(camera_json) else { return vec![] };
crate::camera::grip_points(&c, scale).into_iter().flat_map(|p| [p.0, p.1]).collect()
}
/// Editier-Griffe einer Polylinie aus flachen Puffern (grosse Kataster-Umrisse ohne JSON): `pts = [x0, y0, …]`,
/// `bulge` je Segment (fehlend/NaN = gerade) → `[x0, y0, …]` (Eckpunkte, dann je Segment die Bogen-Mitte).
#[wasm_bindgen]
pub fn grip_vertices_polyline(pts: &[f64], bulge: &[f64], closed: bool) -> Vec<f64> {
let verts: Vec<(f64, f64)> = pts.chunks_exact(2).map(|c| (c[0], c[1])).collect();
crate::grips::polyline_vertices(verts, closed, |i| bulge.get(i).copied().unwrap_or(0.0)).into_iter().flat_map(|p| [p.0, p.1]).collect()
}
/// Kanten-Griffe eines Rings (`closed`) bzw. einer Kette aus `pts = [x0, y0, …]`; `bulge` je Segment
/// nur bei `use_bulge` (Polylinie: Bogen-Segmente ohne Kanten-Griff). Antwort je Kante
/// `[a, b, mitteX, mitteY, normaleX, normaleY]`.
#[wasm_bindgen]
pub fn edge_grips(pts: &[f64], closed: bool, bulge: &[f64], use_bulge: bool) -> Vec<f64> {
let verts: Vec<(f64, f64)> = pts.chunks_exact(2).map(|c| (c[0], c[1])).collect();
let edges = crate::grips::edge_grips(&verts, closed, use_bulge.then_some(bulge));
let mut out = Vec::with_capacity(6 * edges.len());
for (a, b, m, n) in edges {
out.extend([a as f64, b as f64, m.0, m.1, n.0, n.1]);
}
out
}
/// Punkttyp am Punkt `index` einer Polylinie (`crate::polyline_vertex`; `pts = [x0, y0, …]`, `bulge` je
/// Segment): `[typ, ecke, bogen, spline]` mit typ −1 = gemischt bzw. kein Punkt, 0 Ecke, 1 Bogen,
/// 2 Spline; danach je Typ 1/0, ob er sich setzen lässt.
#[wasm_bindgen]
pub fn polyline_vertex_info(pts: &[f64], bulge: &[f64], closed: bool, index: f64) -> Vec<f64> {
use crate::polyline_vertex::{can_set, index_of, type_of, Poly, VertexType};
let verts: Vec<(f64, f64)> = pts.chunks_exact(2).map(|c| (c[0], c[1])).collect();
let g = Poly { pts: &verts, closed, bulge };
let Some(i) = index_of(index, verts.len()) else { return vec![-1.0, 0.0, 0.0, 0.0] };
let can = |t| if can_set(&g, i, t) { 1.0 } else { 0.0 };
vec![type_of(&g, i).map_or(-1.0, VertexType::code), can(VertexType::Corner), can(VertexType::Arc), can(VertexType::Spline)]
}