Merge af1b4eed1e57ae91b
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
18 files changed
+1587
-25
No files matched your search
@@ -1831,6 +1831,23 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]).
|
||||
Tabellenbreite nur über das Zahlenfeld (kein Ziehgriff); keine Kopfzeilen-Füllung/Farben; Schrift im PDF nur
|
||||
Helvetica/Times/Courier (jsPDF-Grundschriften); DXF-Beschriftungen in der Sprache der Oberfläche beim Export;
|
||||
nicht in der Tauri-App getestet. · S
|
||||
- ◐ **[113] Wände bearbeiten: Trim, Extend, Teilen, Bruch, Verketten, Verrunden, Offset.** (30.10.) Die 2D-Editier-
|
||||
befehle nehmen jetzt auch Wände (gerade und Bogen [T2]); Rechnung im Kern `cmd_wall_edit.rs` (Anschluss in
|
||||
`cmd_edit.rs`: Treffer zählen Wände mit — Abstand zum Wandkörper —, Vorschau als Wand-Umriss, je Befehl eine
|
||||
Undo-Stufe). Grenzen: Achsen (Option „Fläche": Aussenflächen) der übrigen Wände des Geschosses, 2D-Linien/
|
||||
-Polylinien mit Bögen/-Rechtecke/-Kreise/-Bögen, Achsraster. **Trim** (Stück zwischen den nächsten Schnitten weg;
|
||||
Trim auf eine Wandachse ergibt einen T-Stoss), **Extend** (Bogenwand auf demselben Kreis), **Teilen** (neuer Befehl
|
||||
`split`, Kürzel `teilen`: am Klickpunkt, Option „Schnittpunkte"; auch offene 2D-Kurven), **Bruch** (Stück zwischen
|
||||
zwei Punkten), **Verketten** (Auswahl: kollinear gleichläufig bzw. gleicher Kreis/Drehsinn, gleicher Wandtyp;
|
||||
Lücken werden geschlossen), **Verrunden** (erster Klick auf eine Wand statt Ecke → zweite Wand: L-Ecke am
|
||||
Achsschnittpunkt; getippter Radius → Bogenwand tangential dazwischen, nur gerade Wände), **Offset** (parallele/
|
||||
konzentrische Kopie im Achsabstand). Öffnungen gehen an das Stück, in dem ihre Mitte liegt (Lage in Achs-/Bogenlänge
|
||||
umgerechnet, ins Stück geklemmt; weggeschnitten → gelöscht). Bemassung [38]: Bezüge auf die Stücke umgehängt,
|
||||
Wandenden folgen bei Trim/Extend/Verrunden dem neuen Ende, Punkte im weggeschnittenen Teil werden `lost`.
|
||||
Anschlüsse (`joins.rs`) folgen geometrisch aus den Endpunkten. Tests: Rust je Operation (gerade/Bogen, Öffnungen,
|
||||
Bemassung), vitest (`wallEdit.test.ts`), e2e (`wallEdit.spec.ts`); CLI-Grundriss vorher/nachher angesehen (Linux).
|
||||
Offen: Verrunden mit Radius bei Bogenwänden, Verketten gegenläufiger Wände (Schichtseite/Anschlag kehren),
|
||||
Extend/Trim von 2D-Kurven an Wänden, Fasen von Wänden; nicht in der Tauri-App geprüft. · M
|
||||
- ✅ **[112] Achsraster.** (30.10.) Neue 2D-Zeichnungsform `Drawing2DGeom::Grid` (`grid.rs`, Auswahl/Verschieben/Kopieren/
|
||||
Ebenen/DXF wie jede Zeichnung): rechtwinklig (`a` = Achsen 1, 2, 3 …, `b` = A, B, C …, unregelmässige Abstände, gedreht
|
||||
um `angle`) oder radial (Strahlen in Grad, Ringe als Bögen/Kreise), `extend` Überstand, `bubbles` Start/Ende/beide,
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// [113] Wände bearbeiten: zwei Wände zeichnen, die eine an der anderen stutzen (T-Stoss), eine teilen,
|
||||
// rückgängig machen. Geprüft am gespeicherten Projekt (Wand-Achsen).
|
||||
import { readFile } from "node:fs/promises";
|
||||
import type { Page } from "@playwright/test";
|
||||
import { blurFocus, commandInput, expect, fileMenu, finishCommand, openTab, startNewProject, test, typeCommand } from "./app";
|
||||
|
||||
/** Modellpunkt (m) → Client-Pixel (wie `dimAssoc.spec.ts`). */
|
||||
async function screenOf(page: Page, x: number, y: number): Promise<{ x: number; y: number }> {
|
||||
return page.locator("svg.plan-svg").evaluate(
|
||||
(el, [mx, my]) => {
|
||||
const [vx, vy, vw, vh] = el.getAttribute("viewBox")!.split(/\s+/).map(Number);
|
||||
const ox = Number(el.getAttribute("data-origin-x") ?? 0);
|
||||
const oy = Number(el.getAttribute("data-origin-y") ?? 0);
|
||||
const r = el.getBoundingClientRect();
|
||||
const s = Math.min(r.width / vw, r.height / vh);
|
||||
return {
|
||||
x: r.left + (r.width - vw * s) / 2 + (mx * 90 - ox - vx) * s,
|
||||
y: r.top + (r.height - vh * s) / 2 + (-my * 90 - oy - vy) * s,
|
||||
};
|
||||
},
|
||||
[x, y],
|
||||
);
|
||||
}
|
||||
|
||||
async function clickModel(page: Page, x: number, y: number): Promise<void> {
|
||||
const p = await screenOf(page, x, y);
|
||||
await page.mouse.move(p.x, p.y);
|
||||
await page.mouse.click(p.x, p.y);
|
||||
}
|
||||
|
||||
type W = { start: { x: number; y: number }; end: { x: number; y: number } };
|
||||
|
||||
/** Wände des gespeicherten Projekts (Download über „Projekt speichern"). */
|
||||
async function savedWalls(page: Page): Promise<W[]> {
|
||||
await blurFocus(page);
|
||||
const pending = page.waitForEvent("download");
|
||||
await fileMenu(page, "Projekt speichern");
|
||||
const dl = await pending;
|
||||
return JSON.parse((await readFile(await dl.path())).toString("utf8")).walls as W[];
|
||||
}
|
||||
|
||||
/** Einzelne Wände zeichnen (Muster `drawing.spec.ts`: das Werkzeug bleibt nach dem Befehl gewählt). */
|
||||
async function drawWalls(page: Page, walls: [string, string][]): Promise<void> {
|
||||
for (const [a, b] of walls) {
|
||||
await page.getByRole("button", { name: "Wand", exact: true }).click();
|
||||
if (!(await page.locator(".cmdline-prompt").textContent())?.includes("Startpunkt")) {
|
||||
await page.getByRole("button", { name: "Wand", exact: true }).click();
|
||||
}
|
||||
await expect(page.locator(".cmdline-prompt")).toHaveText("Startpunkt der Wand:");
|
||||
await commandInput(page).focus();
|
||||
await typeCommand(page, a);
|
||||
await typeCommand(page, b);
|
||||
await finishCommand(page);
|
||||
}
|
||||
}
|
||||
|
||||
test("Wand an Querwand stutzen, teilen, rückgängig", async ({ page }) => {
|
||||
await startNewProject(page);
|
||||
await openTab(page, "Elemente");
|
||||
await drawWalls(page, [
|
||||
["0,0", "10,0"],
|
||||
["6,-3", "6,3"],
|
||||
]);
|
||||
await blurFocus(page);
|
||||
await page.getByTitle("Auf Plan einpassen").click();
|
||||
|
||||
// Stutzen: Klick auf den Überstand rechts der Querwand.
|
||||
await commandInput(page).focus();
|
||||
await typeCommand(page, "trim");
|
||||
await expect(page.locator(".cmdline-prompt")).toHaveText(/Wegschneiden/);
|
||||
await clickModel(page, 8.5, 0);
|
||||
await commandInput(page).press("Enter");
|
||||
await expect.poll(async () => (await savedWalls(page)).some((w) => Math.abs(w.end.x - 6) < 1e-6 && Math.abs(w.start.x) < 1e-6)).toBe(true);
|
||||
|
||||
// Teilen am Punkt x = 3.
|
||||
await commandInput(page).focus();
|
||||
await typeCommand(page, "split");
|
||||
await expect(page.locator(".cmdline-prompt")).toHaveText(/Teilstelle/);
|
||||
await clickModel(page, 3, 0);
|
||||
await commandInput(page).press("Enter");
|
||||
await expect.poll(async () => (await savedWalls(page)).length).toBe(3);
|
||||
|
||||
// Rückgängig: ein Schritt je Befehl.
|
||||
await blurFocus(page);
|
||||
await page.keyboard.press("ControlOrMeta+z");
|
||||
await expect.poll(async () => (await savedWalls(page)).length).toBe(2);
|
||||
await blurFocus(page);
|
||||
await page.keyboard.press("ControlOrMeta+z");
|
||||
await expect.poll(async () => (await savedWalls(page)).some((w) => Math.abs(w.end.x - 10) < 1e-6)).toBe(true);
|
||||
});
|
||||
@@ -4,10 +4,15 @@
|
||||
//! `kernel2d` (Trim/Extend mit Bögen, Verrundung, Fasung, Bruch, Offset, Verketten); hier die
|
||||
//! Übersetzung Zeichnung ↔ Kurve, die Auswahl und die Elemente des Ergebnisses.
|
||||
//!
|
||||
//! Wände ([113]): Trim, Extend, Bruch, Offset und Join nehmen auch Wände (gerade und Bogen); dazu Teilen
|
||||
//! (`splitAt`/`splitInter`) und Verrunden zweier Wände (`filletWalls`). Die Wand-Rechnung steht in
|
||||
//! `cmd_wall_edit.rs`; hier nur Treffer (Wände zählen mit, Abstand zum Wandkörper) und Verteilung.
|
||||
//!
|
||||
//! Rechnung auf der rohen Projekt-Wurzel (Attribute der Quelle bleiben samt Schlüsselreihenfolge;
|
||||
//! unveränderte Punkte werden als dieselben JSON-Werte übernommen wie das Array-Spreizen in TS).
|
||||
|
||||
use crate::cmd_transform::{IdGen, Shapes};
|
||||
use crate::cmd_wall_edit as wall_edit;
|
||||
use crate::grips::{arr, field, js_num, num_of, num_or, pt, truthy, with, with_all, xy};
|
||||
use crate::jsmath::hypot2;
|
||||
use crate::jsnum;
|
||||
@@ -195,9 +200,20 @@ fn pick_curve<'a>(root: &'a Map<String, Value>, level: &str, at: P, take: Take)
|
||||
}
|
||||
}
|
||||
}
|
||||
if take != Take::Corner {
|
||||
if let Some((w, dd)) = wall_edit::pick_wall(root, level, at) {
|
||||
if dd < best_d {
|
||||
best = Some(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
best
|
||||
}
|
||||
|
||||
fn is_wall(v: &Value) -> bool {
|
||||
field(v, "type").and_then(Value::as_str) == Some("wall")
|
||||
}
|
||||
|
||||
/// Kette → Zeichengeometrie (`chainToGeom`/`fromPolyForm`): zwei Punkte offen ohne Bogen = Linie.
|
||||
fn chain_geom(pts: Vec<Value>, closed: Value, bulge: Option<Vec<Value>>) -> Value {
|
||||
let b = bulge.as_deref().map(nums).unwrap_or_default();
|
||||
@@ -286,8 +302,14 @@ pub fn trim_ops(root: &Map<String, Value>, id: &str, at: P, ids: &mut IdGen) ->
|
||||
}
|
||||
|
||||
/// Vorschau des Trims am Punkt: die verbleibenden Ketten der getroffenen Kurve.
|
||||
pub fn trim_preview(root: &Map<String, Value>, level: &str, at: P, out: &mut Shapes) -> bool {
|
||||
pub fn trim_preview(root: &Map<String, Value>, level: &str, at: P, face: bool, out: &mut Shapes) -> bool {
|
||||
let Some(target) = pick_curve(root, level, at, Take::Curve) else { return false };
|
||||
if is_wall(target) {
|
||||
if let Some(e) = wall_edit::trim(root, target, at, face) {
|
||||
wall_edit::preview(root, &e, out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
let Some((_, rest)) = trim_rest(root, target, at) else { return true };
|
||||
for r in rest.iter().filter(|r| r.pts.len() >= 2) {
|
||||
let pts = if real(&r.bulge) { chain_of(&hit_edges(&Curve::of_pts(r.pts.clone(), r.closed, Some(&r.bulge)))) } else { r.pts.clone() };
|
||||
@@ -385,8 +407,14 @@ pub fn extend_ops(root: &Map<String, Value>, id: &str, at: P) -> Vec<Op> {
|
||||
}
|
||||
|
||||
/// Vorschau der Verlängerung (Bögen tesselliert).
|
||||
pub fn extend_preview(root: &Map<String, Value>, level: &str, at: P, out: &mut Shapes) -> bool {
|
||||
pub fn extend_preview(root: &Map<String, Value>, level: &str, at: P, face: bool, out: &mut Shapes) -> bool {
|
||||
let Some(target) = pick_curve(root, level, at, Take::Open) else { return false };
|
||||
if is_wall(target) {
|
||||
if let Some(e) = wall_edit::extend(root, target, at, face) {
|
||||
wall_edit::preview(root, &e, out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
let Some(c) = curve(geom(target), Take::Open) else { return true };
|
||||
let Some(next) = extend_curve(&c, &extend_cutters(root, target), at) else { return true };
|
||||
let pts = if next.has_bulge() { chain_of(&hit_edges(&next)) } else { next.pts.clone() };
|
||||
@@ -550,6 +578,9 @@ fn corner_preview(h: &Corner, fillet: bool, r: f64, out: &mut Shapes) {
|
||||
/// Offene, bogenfreie Kurve unter dem Punkt (die nächste Kurve muss es sein).
|
||||
pub fn pick_breakable<'a>(root: &'a Map<String, Value>, level: &str, at: P) -> Option<&'a Value> {
|
||||
let d = pick_curve(root, level, at, Take::Curve)?;
|
||||
if is_wall(d) {
|
||||
return Some(d);
|
||||
}
|
||||
let c = curve(geom(d), Take::Curve)?;
|
||||
(!c.closed && !c.has_bulge()).then_some(d)
|
||||
}
|
||||
@@ -572,6 +603,12 @@ pub fn break_ops(root: &Map<String, Value>, id: &str, p1: P, p2: P, ids: &mut Id
|
||||
}
|
||||
|
||||
fn break_preview(root: &Map<String, Value>, id: &str, p1: P, p2: P, out: &mut Shapes) {
|
||||
if let Some(w) = wall_edit::find_wall(root, id) {
|
||||
if let Some(e) = wall_edit::break_at(w, p1, p2) {
|
||||
wall_edit::preview(root, &e, out);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some((_, pieces)) = break_pieces(root, id, p1, p2) else { return };
|
||||
for pts in pieces.iter().filter(|p| p.len() >= 2) {
|
||||
if pts.len() == 2 {
|
||||
@@ -860,6 +897,11 @@ pub fn ops(root: &Map<String, Value>, v: &Value) -> Option<Vec<Op>> {
|
||||
let cmd = s_arg(v, "cmd");
|
||||
let mut ids = IdGen::new(s_arg(v, "stamp"));
|
||||
let list = |k: &str| -> Vec<String> { v.get(k).and_then(|x| serde_json::from_value(x.clone()).ok()).unwrap_or_default() };
|
||||
if let Some(w) = wall_edit::find_wall(root, s_arg(v, "id")) {
|
||||
if let Some(e) = wall_edit_of(root, w, v) {
|
||||
return Some(e.map(|e| wall_edit::commit(root, &e, &mut ids)).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
Some(match cmd {
|
||||
"trim" => trim_ops(root, s_arg(v, "id"), p_arg(v, "pt"), &mut ids),
|
||||
"extend" => extend_ops(root, s_arg(v, "id"), p_arg(v, "pt")),
|
||||
@@ -867,13 +909,35 @@ pub fn ops(root: &Map<String, Value>, v: &Value) -> Option<Vec<Op>> {
|
||||
"chamfer" => chamfer_ops(root, s_arg(v, "id"), n_arg(v, "index"), n_arg(v, "d")),
|
||||
"break" => break_ops(root, s_arg(v, "id"), p_arg(v, "p1"), p_arg(v, "p2"), &mut ids),
|
||||
"offset" => offset_ops(root, s_arg(v, "id"), n_arg(v, "d"), &mut ids),
|
||||
"join" => join_ops(root, &list("ids"), &mut ids),
|
||||
"join" => {
|
||||
let mut ops = join_ops(root, &list("ids"), &mut ids);
|
||||
ops.extend(wall_edit::join_ops(root, &list("ids")));
|
||||
ops
|
||||
}
|
||||
"splitAt" => break_ops(root, s_arg(v, "id"), p_arg(v, "pt"), p_arg(v, "pt"), &mut ids),
|
||||
"splitInter" => crate::cmd_split::split_ops(root, &[s_arg(v, "id").to_string()], s_arg(v, "stamp")),
|
||||
"explode" => explode_ops(root, &list("ids"), &mut ids),
|
||||
"dimdetach" => crate::dim_assoc::detach_ops(root, &list("ids")),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Wand-Änderung einer Anfrage an die Wand `w` (`None` = kein Wand-Befehl; `Some(None)` = Befehl ohne
|
||||
/// Ergebnis, z. B. keine Grenze getroffen).
|
||||
fn wall_edit_of<'a>(root: &'a Map<String, Value>, w: &'a Value, v: &Value) -> Option<Option<wall_edit::Edit<'a>>> {
|
||||
let face = truthy(v.get("face"));
|
||||
Some(match s_arg(v, "cmd") {
|
||||
"trim" => wall_edit::trim(root, w, p_arg(v, "pt"), face),
|
||||
"extend" => wall_edit::extend(root, w, p_arg(v, "pt"), face),
|
||||
"break" => wall_edit::break_at(w, p_arg(v, "p1"), p_arg(v, "p2")),
|
||||
"splitAt" => wall_edit::break_at(w, p_arg(v, "pt"), p_arg(v, "pt")),
|
||||
"splitInter" => wall_edit::split_at_intersections(root, w),
|
||||
"offset" => wall_edit::offset(w, n_arg(v, "d")),
|
||||
"filletWalls" => wall_edit::find_wall(root, s_arg(v, "id2")).and_then(|w2| wall_edit::fillet(w, p_arg(v, "p1"), w2, p_arg(v, "p2"), n_arg(v, "r"))),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Abfragen der Befehle zwischen den Schritten (Treffer, Vorschau): Antwort-JSON. Formen flach wie
|
||||
/// `doc_cmd_preview` (`shapes`), Treffer als `hit` (`null` = keiner).
|
||||
pub fn query(root: &Map<String, Value>, v: &Value) -> Result<Value, String> {
|
||||
@@ -908,13 +972,54 @@ pub fn query(root: &Map<String, Value>, v: &Value) -> Result<Value, String> {
|
||||
json!({ "shapes": shapes(s) })
|
||||
}
|
||||
"trim" | "extend" => {
|
||||
let hit = if q == "trim" { trim_preview(root, level, at, &mut s) } else { extend_preview(root, level, at, &mut s) };
|
||||
let face = truthy(v.get("face"));
|
||||
let hit = if q == "trim" { trim_preview(root, level, at, face, &mut s) } else { extend_preview(root, level, at, face, &mut s) };
|
||||
json!({ "hit": hit, "shapes": shapes(s) })
|
||||
}
|
||||
"break" => {
|
||||
break_preview(root, s_arg(v, "id"), p_arg(v, "p1"), at, &mut s);
|
||||
json!({ "shapes": shapes(s) })
|
||||
}
|
||||
"offset" if wall_edit::find_wall(root, s_arg(v, "id")).is_some() => {
|
||||
let w = wall_edit::find_wall(root, s_arg(v, "id")).unwrap_or(&Value::Null);
|
||||
let sign = wall_edit::side(w, at).unwrap_or(n_arg(v, "lastSign"));
|
||||
let dist = n_arg(v, "dist");
|
||||
if let Some(e) = wall_edit::offset(w, sign * dist) {
|
||||
wall_edit::preview(root, &e, &mut s);
|
||||
}
|
||||
json!({ "hit": true, "sign": sign, "shapes": shapes(s) })
|
||||
}
|
||||
"pickWall" => json!({ "hit": hit_id(wall_edit::pick_wall(root, level, at).map(|w| w.0)) }),
|
||||
"filletWalls" => {
|
||||
let e = match (wall_edit::find_wall(root, s_arg(v, "id")), wall_edit::pick_wall(root, level, at)) {
|
||||
(Some(w1), Some((w2, _))) => wall_edit::fillet(w1, p_arg(v, "p1"), w2, at, n_arg(v, "r")),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(e) = &e {
|
||||
wall_edit::preview(root, e, &mut s);
|
||||
}
|
||||
json!({ "hit": e.is_some(), "shapes": shapes(s) })
|
||||
}
|
||||
"split" => {
|
||||
let inter = truthy(v.get("inter"));
|
||||
let target = if inter { pick_curve(root, level, at, Take::Curve) } else { pick_breakable(root, level, at) };
|
||||
let mut hit = Value::Null;
|
||||
if let Some(t) = target {
|
||||
hit = hit_id(Some(t));
|
||||
if is_wall(t) {
|
||||
let e = if inter { wall_edit::split_at_intersections(root, t) } else { wall_edit::break_at(t, at, at) };
|
||||
if let Some(e) = e {
|
||||
wall_edit::preview(root, &e, &mut s);
|
||||
}
|
||||
} else if !inter {
|
||||
// Teilstelle der Zeichnung: kleines Kreuz.
|
||||
let d = 0.15;
|
||||
s.line((at.x - d, at.y - d), (at.x + d, at.y + d));
|
||||
s.line((at.x - d, at.y + d), (at.x + d, at.y - d));
|
||||
}
|
||||
}
|
||||
json!({ "hit": hit, "shapes": shapes(s) })
|
||||
}
|
||||
"offset" => {
|
||||
let c = find(root, s_arg(v, "id")).and_then(|d| curve(geom(d), Take::Curve));
|
||||
match c {
|
||||
@@ -983,4 +1088,26 @@ mod tests {
|
||||
assert_eq!(ops[1].to_json()["at"], 1);
|
||||
assert_eq!(ops[1].to_json()["items"].as_array().unwrap().len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wand_befehle_ueber_die_anfrage() {
|
||||
let w = |id: &str, a: (f64, f64), b: (f64, f64)| json!({"id": id, "type": "wall", "floorId": "L", "start": {"x": a.0, "y": a.1}, "end": {"x": b.0, "y": b.1}, "wallTypeId": "t", "height": 2.5});
|
||||
let r = root(json!({"wallTypes": [{"id": "t", "layers": [{"thickness": 0.2}]}], "walls": [w("a", (0.0, 0.0), (10.0, 0.0)), w("b", (6.0, -3.0), (6.0, 3.0))], "drawings2d": [], "openings": []}));
|
||||
// Treffer: Klick in den Wandkörper trifft die Wand (auch für Bruch/Teilen).
|
||||
assert_eq!(query(&r, &json!({"q": "pickCurve", "level": "L", "pt": [8.0, 0.05]})).unwrap()["hit"], "a");
|
||||
assert_eq!(query(&r, &json!({"q": "pickBreakable", "level": "L", "pt": [8.0, 0.05]})).unwrap()["hit"], "a");
|
||||
let pv = query(&r, &json!({"q": "trim", "level": "L", "pt": [8.0, 0.0]})).unwrap();
|
||||
assert_eq!(pv["hit"], true);
|
||||
assert!(!pv["shapes"].as_array().unwrap().is_empty());
|
||||
let o = super::ops(&r, &json!({"cmd": "trim", "id": "a", "pt": [8.0, 0.0], "stamp": "s"})).unwrap();
|
||||
assert_eq!(o[0].to_json()["entity"]["end"], json!({"x": 6, "y": 0}));
|
||||
let o = super::ops(&r, &json!({"cmd": "splitAt", "id": "a", "pt": [2.0, 0.0], "stamp": "s"})).unwrap();
|
||||
assert_eq!(o.len(), 2);
|
||||
let o = super::ops(&r, &json!({"cmd": "splitInter", "id": "a", "stamp": "s"})).unwrap();
|
||||
assert_eq!(o[1].to_json()["items"][0]["start"], json!({"x": 6, "y": 0}));
|
||||
let o = super::ops(&r, &json!({"cmd": "offset", "id": "a", "d": -1.0, "stamp": "s"})).unwrap();
|
||||
assert_eq!(o[0].to_json()["items"][0]["start"], json!({"x": 0, "y": -1}));
|
||||
let pv = query(&r, &json!({"q": "filletWalls", "level": "L", "id": "a", "p1": [2.0, 0.0], "pt": [6.0, 2.0], "r": 0.5})).unwrap();
|
||||
assert_eq!(pv["hit"], true);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -119,6 +119,7 @@ pub mod import_context;
|
||||
pub mod import_ifc;
|
||||
pub mod cmd_paste;
|
||||
pub mod cmd_split;
|
||||
pub mod cmd_wall_edit;
|
||||
pub mod snap_model;
|
||||
pub mod solid_specs;
|
||||
pub mod highlight3d;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
// 2) „Zweiter Punkt:" → Punkt (Position auf DERSELBEN Kurve) → commit:
|
||||
// der Abschnitt zwischen beiden Positionen (Klick-Reihenfolge egal)
|
||||
// fällt weg, bis zu zwei Reststücke bleiben.
|
||||
// Wände ([113], gerade und Bogen) ebenso: das Stück dazwischen entfällt, Öffnungen bleiben am
|
||||
// richtigen Reststück (Lage umgerechnet), Bemassungs-Bezüge werden umgehängt.
|
||||
//
|
||||
// Bewusst NICHT unterstützt (Klick auf eine geschlossene Kurve oder eine mit
|
||||
// Bogen-Segmenten bricht NICHT ab, sondern bleibt im ersten Schritt — sonst
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
// Befehl bleibt aktiv).
|
||||
// • Wiederholend, bis Esc/Enter.
|
||||
//
|
||||
// Wände ([113], gerade und Bogen) verlängert der Kern bis zur nächsten Wandachse/-fläche, 2D-Kurve
|
||||
// oder Rasterachse (Bogenwände auf demselben Kreis).
|
||||
//
|
||||
// Geschlossene Formen (rect, geschlossene polyline) und reine Punktformen
|
||||
// (circle/arc/text) sind nicht extend-fähig — ein geschlossener Ring hat kein
|
||||
// "Ende". Treffer, Schneider und Verlängerung rechnet der Kern
|
||||
@@ -25,7 +28,14 @@
|
||||
|
||||
import { cmdMutation } from "../../core";
|
||||
import { cmdQuery, decodeShapes, pair } from "../../tools/coreCmd";
|
||||
import type { Command, CommandResult, CommandState } from "../types";
|
||||
import type { CmdOption, Command, CommandResult, CommandState } from "../types";
|
||||
|
||||
/**
|
||||
* Wände ([113]): Grenze ist die Achse der anderen Wand (ergibt einen T-Stoss) oder — Option „Fläche" —
|
||||
* ihre Aussenflächen. Die Wahl bleibt über Aufrufe erhalten.
|
||||
*/
|
||||
let toFace = false;
|
||||
const faceOption = (): CmdOption => ({ id: "face", labelKey: "cmd.wallEdit.faceOpt", value: toFace ? "on" : "off" });
|
||||
|
||||
// ── Zustand ───────────────────────────────────────────────────────────────────
|
||||
// Einziger Schritt „pick": auf die zu verlängernde Kurve (nahe dem Ende) klicken;
|
||||
@@ -47,24 +57,28 @@ export const extendCommand: Command = {
|
||||
name: "extend",
|
||||
labelKey: "cmd.extend.label",
|
||||
prompt: () => "cmd.extend.pick",
|
||||
accepts: () => ["point"],
|
||||
options: () => [],
|
||||
accepts: () => ["point", "option"],
|
||||
options: () => [faceOption()],
|
||||
|
||||
init: (): ExtendPick => ({ phase: "pick", lastPoint: null }),
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as ExtendState;
|
||||
if (s.phase === "done") return finish();
|
||||
if (input.kind === "option" && input.id === "face") {
|
||||
toFace = !toFace;
|
||||
return [s, { draft: null }];
|
||||
}
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const { hit } = cmdQuery<{ hit: string | null }>(ctx.project, { q: "pickOpen", level: ctx.level.id, pt: pair(input.point) });
|
||||
if (!hit) return [s, { draft: null }];
|
||||
return [s, { draft: null, commit: cmdMutation({ cmd: "extend", id: hit, pt: pair(input.point) }) }];
|
||||
return [s, { draft: null, commit: cmdMutation({ cmd: "extend", id: hit, pt: pair(input.point), face: toFace }) }];
|
||||
},
|
||||
|
||||
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as ExtendState;
|
||||
if (s.phase !== "pick") return [s, { draft: null }];
|
||||
const r = cmdQuery<{ hit: boolean; shapes: number[] }>(ctx.project, { q: "extend", level: ctx.level.id, pt: pair(point) });
|
||||
const r = cmdQuery<{ hit: boolean; shapes: number[] }>(ctx.project, { q: "extend", level: ctx.level.id, pt: pair(point), face: toFace });
|
||||
if (!r.hit) return [s, { draft: null }];
|
||||
const preview = decodeShapes(r.shapes);
|
||||
return [s, { draft: { preview, vertices: [], hud: { at: point, text: "↗" } } }];
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// 1) „Ecke wählen:" → Punkt (nächstgelegener Eckpunkt einer polyline/rect
|
||||
// wird gewählt; ein einzelnes `line`-Element hat keine eigene Ecke)
|
||||
// 2) „Radius:" → Punkt (Abstand von der Ecke) ODER getippte Zahl → commit
|
||||
// Wände ([113]): trifft der erste Klick keine Ecke, aber eine Wand, folgt „Zweite Wand“ (Zahl =
|
||||
// Radius, Vorgabe 0 = L-Ecke am Achsschnittpunkt; Radius nur bei geraden Wänden → Bogenwand).
|
||||
//
|
||||
// Die Verrundung wird als ECHTES Bogen-Segment gespeichert (`bulge`, s.
|
||||
// `geometry/bulge.ts`), nicht mehr tesselliert — editierbar wie jeder andere
|
||||
@@ -26,6 +28,7 @@ import type {
|
||||
Vec2,
|
||||
} from "../types";
|
||||
import { cornerPreview, pickCorner } from "./cornerHit";
|
||||
import { cmdQuery, decodeShapes, pair } from "../../tools/coreCmd";
|
||||
import type { CornerHit } from "./cornerHit";
|
||||
|
||||
const DEFAULT_RADIUS = 0.1; // m — Startwert, bis der Nutzer per Maus/Tab einen eigenen setzt
|
||||
@@ -53,7 +56,25 @@ interface FilletRadius extends CommandState {
|
||||
interface FilletDone extends CommandState {
|
||||
phase: "done";
|
||||
}
|
||||
type FilletState = FilletPick | FilletRadius | FilletDone;
|
||||
/**
|
||||
* Wände ([113]): erste Wand getroffen (statt einer Polylinien-Ecke), jetzt die zweite wählen. Beide
|
||||
* werden bis zum Achsschnittpunkt gestutzt/verlängert (L-Ecke); mit Radius > 0 (nur gerade Wände)
|
||||
* schliesst eine Bogenwand tangential an.
|
||||
*/
|
||||
interface FilletWall2 extends CommandState {
|
||||
phase: "wall2";
|
||||
wall: string;
|
||||
p1: Vec2;
|
||||
}
|
||||
type FilletState = FilletPick | FilletRadius | FilletDone | FilletWall2;
|
||||
|
||||
/** Radius der Wand-Verrundung (0 = scharfe L-Ecke), bleibt über Aufrufe. */
|
||||
let wallRadius = 0;
|
||||
|
||||
function wallDraft(ctx: CommandContext, s: FilletWall2, point: Vec2): ToolDraft | null {
|
||||
const r = cmdQuery<{ hit: boolean; shapes: number[] }>(ctx.project, { q: "filletWalls", level: ctx.level.id, id: s.wall, p1: pair(s.p1), pt: pair(point), r: wallRadius });
|
||||
return { preview: decodeShapes(r.shapes), vertices: [s.p1], hud: { at: point, text: `R: ${wallRadius.toFixed(3)}m${r.hit ? "" : " ✗"}` } };
|
||||
}
|
||||
|
||||
const finish = (): [CommandState, CommandResult] => [
|
||||
{ phase: "done", lastPoint: null } as FilletDone,
|
||||
@@ -63,8 +84,11 @@ const finish = (): [CommandState, CommandResult] => [
|
||||
export const filletCommand: Command = {
|
||||
name: "fillet",
|
||||
labelKey: "cmd.fillet.label",
|
||||
prompt: (s) => ((s as FilletState).phase === "radius" ? "cmd.fillet.radius" : "cmd.fillet.pick"),
|
||||
accepts: (s) => ((s as FilletState).phase === "radius" ? ["point", "number"] : ["point"]),
|
||||
prompt: (s) => {
|
||||
const ph = (s as FilletState).phase;
|
||||
return ph === "radius" ? "cmd.fillet.radius" : ph === "wall2" ? "cmd.fillet.wall2" : "cmd.fillet.pick";
|
||||
},
|
||||
accepts: (s) => ((s as FilletState).phase === "radius" || (s as FilletState).phase === "wall2" ? ["point", "number"] : ["point"]),
|
||||
options: () => [],
|
||||
fields: (s) => ((s as FilletState).phase === "radius" ? RADIUS_FIELDS : []),
|
||||
|
||||
@@ -76,10 +100,28 @@ export const filletCommand: Command = {
|
||||
if (s.phase === "pick") {
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const { hit, preview } = pickCorner(ctx.project, ctx.level.id, input.point, "fillet", DEFAULT_RADIUS);
|
||||
if (!hit) return [s, { draft: null }]; // daneben geklickt → aktiv bleiben
|
||||
if (!hit) {
|
||||
const wall = cmdQuery<{ hit: string | null }>(ctx.project, { q: "pickWall", level: ctx.level.id, pt: pair(input.point) }).hit;
|
||||
if (!wall) return [s, { draft: null }]; // daneben geklickt → aktiv bleiben
|
||||
const w2: FilletWall2 = { phase: "wall2", wall, p1: input.point, lastPoint: input.point };
|
||||
return [w2, { draft: { preview: [], vertices: [input.point] } }];
|
||||
}
|
||||
const next: FilletRadius = { phase: "radius", hit, radius: DEFAULT_RADIUS, lastPoint: input.point };
|
||||
return [next, { draft: filletDraft(hit, preview, next.radius, input.point) }];
|
||||
}
|
||||
if (s.phase === "wall2") {
|
||||
if (input.kind === "number") {
|
||||
wallRadius = Math.max(0, input.value);
|
||||
return [s, { draft: null }];
|
||||
}
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const id2 = cmdQuery<{ hit: string | null }>(ctx.project, { q: "pickWall", level: ctx.level.id, pt: pair(input.point) }).hit;
|
||||
if (!id2 || id2 === s.wall) return [s, { draft: null }];
|
||||
return [
|
||||
{ phase: "done", lastPoint: null } as FilletDone,
|
||||
{ draft: null, done: true, commit: cmdMutation({ cmd: "filletWalls", id: s.wall, p1: pair(s.p1), id2, p2: pair(input.point), r: wallRadius }) },
|
||||
];
|
||||
}
|
||||
// phase === "radius"
|
||||
let r = s.radius;
|
||||
if (input.kind === "number") r = Math.max(0, input.value);
|
||||
@@ -98,6 +140,7 @@ export const filletCommand: Command = {
|
||||
if (!hit) return [s, { draft: null }];
|
||||
return [s, { draft: filletDraft(hit, preview, DEFAULT_RADIUS, point) }];
|
||||
}
|
||||
if (s.phase === "wall2") return [s, { draft: wallDraft(ctx, s, point) }];
|
||||
if (s.phase !== "radius") return [s, { draft: null }];
|
||||
const r = Math.max(0, dist(s.hit.corner, point));
|
||||
const ns: FilletRadius = { ...s, radius: r };
|
||||
|
||||
@@ -37,7 +37,8 @@ export const joinCommand: Command = {
|
||||
|
||||
// Sofort auf der Auswahl ausführen (kein Pick nötig).
|
||||
autoRun: (ctx: CommandContext): CommandResult => {
|
||||
const ids = selectedDrawingIds(ctx.selection);
|
||||
// Wände ([113]): kollineare (gleiche Laufrichtung) bzw. Bögen auf demselben Kreis werden eine Wand.
|
||||
const ids = [...selectedDrawingIds(ctx.selection), ...ctx.selection.wallIds];
|
||||
if (ids.length < 2) return { draft: null, done: true };
|
||||
return { draft: null, done: true, commit: cmdMutation({ cmd: "join", ids, stamp: uniqueStamp() }) };
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Offset — DAS Architektur-Primitiv (docs §2.10/§3.4 Tier-1, §3.6 persistente
|
||||
// Offset — DAS Architektur-Primitiv (auch für Wände, [113]) (docs §2.10/§3.4 Tier-1, §3.6 persistente
|
||||
// Distanz). Erzeugt eine parallel versetzte Kopie einer 2D-Kurve (line/polyline/
|
||||
// rect). Schritte:
|
||||
// 1) Kurve bestimmen: ist genau EIN passendes Drawing2D (line/polyline/rect)
|
||||
@@ -50,16 +50,24 @@ function isOffsetable(d: Drawing2D): boolean {
|
||||
return g.shape === "line" || g.shape === "polyline" || g.shape === "rect";
|
||||
}
|
||||
|
||||
/** Genau ein passendes Drawing2D vorselektiert? Dann liefere es. */
|
||||
function singleSelectedCurve(project: Project, sel: CommandSelection): Drawing2D | null {
|
||||
/**
|
||||
* Genau ein passendes Element vorselektiert? Dann liefere seine id: ein offset-fähiges Drawing2D oder
|
||||
* genau eine Wand ([113]: parallele, bei Bogenwänden konzentrische Kopie im Achsabstand).
|
||||
*/
|
||||
function singleSelectedCurve(project: Project, sel: CommandSelection): { id: string } | null {
|
||||
if (!sel.drawingId && sel.wallIds.length === 1) {
|
||||
const w = project.walls.find((x) => x.id === sel.wallIds[0]);
|
||||
return w && !w.locked ? { id: w.id } : null;
|
||||
}
|
||||
if (!sel.drawingId || sel.wallIds.length > 0) return null;
|
||||
const d = project.drawings2d.find((x) => x.id === sel.drawingId);
|
||||
if (d && isOffsetable(d)) return d;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Gibt es die Kurve noch (Side-Zustand)? */
|
||||
/** Gibt es die Kurve (oder Wand) noch (Side-Zustand)? */
|
||||
function hasCurve(project: Project, drawingId: string): boolean {
|
||||
if (project.walls.some((w) => w.id === drawingId)) return true;
|
||||
const src = project.drawings2d.find((x) => x.id === drawingId);
|
||||
return !!src && isOffsetable(src);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// Split — teilt eine Wand (gerade oder Bogen) oder eine offene 2D-Kurve ([113]). Ein Schritt, wiederholend:
|
||||
// • Klick auf das Element → Teilung an dieser Stelle (Wand: Lot auf die Achse; Kurve: nächster Punkt).
|
||||
// • Option „Schnittpunkte" → der Klick teilt das Element an allen Schnittpunkten mit den übrigen
|
||||
// Wänden (Achsen), 2D-Kurven und Achsrastern des Geschosses.
|
||||
// Öffnungen bleiben am Stück, in dem ihre Mitte liegt (Lage umgerechnet), Bemassungs-Bezüge ([38])
|
||||
// werden auf die Stücke umgehängt. Treffer, Teilung und Vorschau rechnet der Kern
|
||||
// (`src-tauri/core/src/cmd_edit.rs` → `cmd_wall_edit.rs`); hier nur der Zustandsautomat.
|
||||
|
||||
import { cmdMutation } from "../../core";
|
||||
import { uniqueStamp } from "../../tools/types";
|
||||
import { cmdQuery, decodeShapes, pair } from "../../tools/coreCmd";
|
||||
import type { CmdOption, Command, CommandResult, CommandState } from "../types";
|
||||
|
||||
/** An allen Schnittpunkten statt am Klickpunkt teilen (bleibt über Aufrufe). */
|
||||
let atIntersections = false;
|
||||
const interOption = (): CmdOption => ({ id: "inter", labelKey: "cmd.split.interOpt", value: atIntersections ? "on" : "off" });
|
||||
|
||||
interface SplitPick extends CommandState {
|
||||
phase: "pick";
|
||||
}
|
||||
interface SplitDone extends CommandState {
|
||||
phase: "done";
|
||||
}
|
||||
type SplitState = SplitPick | SplitDone;
|
||||
|
||||
const finish = (): [CommandState, CommandResult] => [{ phase: "done", lastPoint: null } as SplitDone, { draft: null, done: true }];
|
||||
|
||||
export const splitCommand: Command = {
|
||||
name: "split",
|
||||
labelKey: "cmd.split.label",
|
||||
prompt: () => "cmd.split.pick",
|
||||
accepts: () => ["point", "option"],
|
||||
options: () => [interOption()],
|
||||
init: (): SplitPick => ({ phase: "pick", lastPoint: null }),
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as SplitState;
|
||||
if (s.phase === "done") return finish();
|
||||
if (input.kind === "option" && input.id === "inter") {
|
||||
atIntersections = !atIntersections;
|
||||
return [s, { draft: null }];
|
||||
}
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const { hit } = cmdQuery<{ hit: string | null }>(ctx.project, { q: "split", level: ctx.level.id, pt: pair(input.point), inter: atIntersections });
|
||||
if (!hit) return [s, { draft: null }];
|
||||
const req = atIntersections ? { cmd: "splitInter", id: hit, stamp: uniqueStamp() } : { cmd: "splitAt", id: hit, pt: pair(input.point), stamp: uniqueStamp() };
|
||||
return [s, { draft: null, commit: cmdMutation(req) }];
|
||||
},
|
||||
|
||||
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as SplitState;
|
||||
if (s.phase !== "pick") return [s, { draft: null }];
|
||||
const r = cmdQuery<{ hit: string | null; shapes: number[] }>(ctx.project, { q: "split", level: ctx.level.id, pt: pair(point), inter: atIntersections });
|
||||
if (!r.hit) return [s, { draft: null }];
|
||||
return [s, { draft: { preview: decodeShapes(r.shapes), vertices: [point], hud: { at: point, text: "⫽" } } }];
|
||||
},
|
||||
|
||||
onConfirm: (): [CommandState, CommandResult] => finish(),
|
||||
onCancel: (): [CommandState, CommandResult] => finish(),
|
||||
};
|
||||
@@ -12,7 +12,8 @@
|
||||
// Linie → wird gekürzt/aufgeteilt; Polylinie → der getroffene Abschnitt fällt
|
||||
// raus (kann die Polylinie in Stücke teilen). Treffer, Schneider, Rest-Ketten und
|
||||
// Vorschau rechnet der Kern (`src-tauri/core/src/cmd_edit.rs`, [K4] S3); hier nur
|
||||
// der Zustandsautomat. Wände sind ausgenommen (nur Drawing2D). Sowohl Ziel-Kurve
|
||||
// der Zustandsautomat. Wände (gerade und Bogen, [113]) gehen genauso: Klick auf den wegzuschneidenden
|
||||
// Teil; Schneider sind die anderen Wände (Achse/Fläche), 2D-Kurven und Achsraster. Sowohl Ziel-Kurve
|
||||
// als auch Schneider dürfen Bogen-Segmente (bulge) tragen.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare/UI deutsch (CONVENTIONS.md).
|
||||
@@ -20,7 +21,14 @@
|
||||
import { cmdMutation } from "../../core";
|
||||
import { uniqueStamp } from "../../tools/types";
|
||||
import { cmdQuery, decodeShapes, pair } from "../../tools/coreCmd";
|
||||
import type { Command, CommandResult, CommandState } from "../types";
|
||||
import type { CmdOption, Command, CommandResult, CommandState } from "../types";
|
||||
|
||||
/**
|
||||
* Wände ([113]): Grenze ist die Achse der anderen Wand (ergibt einen T-Stoss) oder — Option „Fläche" —
|
||||
* ihre Aussenflächen. Die Wahl bleibt über Aufrufe erhalten.
|
||||
*/
|
||||
let toFace = false;
|
||||
const faceOption = (): CmdOption => ({ id: "face", labelKey: "cmd.wallEdit.faceOpt", value: toFace ? "on" : "off" });
|
||||
|
||||
// ── Zustand ───────────────────────────────────────────────────────────────────
|
||||
// Einziger Schritt „pick": auf den wegzuschneidenden Abschnitt klicken;
|
||||
@@ -42,14 +50,18 @@ export const trimCommand: Command = {
|
||||
name: "trim",
|
||||
labelKey: "cmd.trim.label",
|
||||
prompt: () => "cmd.trim.pick",
|
||||
accepts: () => ["point"],
|
||||
options: () => [],
|
||||
accepts: () => ["point", "option"],
|
||||
options: () => [faceOption()],
|
||||
|
||||
init: (): TrimPick => ({ phase: "pick", lastPoint: null }),
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as TrimState;
|
||||
if (s.phase === "done") return finish();
|
||||
if (input.kind === "option" && input.id === "face") {
|
||||
toFace = !toFace;
|
||||
return [s, { draft: null }];
|
||||
}
|
||||
if (input.kind !== "point") return [s, { draft: null }];
|
||||
const { hit } = cmdQuery<{ hit: string | null }>(ctx.project, { q: "pickCurve", level: ctx.level.id, pt: pair(input.point) });
|
||||
if (!hit) {
|
||||
@@ -57,13 +69,13 @@ export const trimCommand: Command = {
|
||||
return [s, { draft: null }];
|
||||
}
|
||||
// Wiederholend: NICHT done — nach dem Commit bleibt „pick" aktiv.
|
||||
return [s, { draft: null, commit: cmdMutation({ cmd: "trim", id: hit, pt: pair(input.point), stamp: uniqueStamp() }) }];
|
||||
return [s, { draft: null, commit: cmdMutation({ cmd: "trim", id: hit, pt: pair(input.point), face: toFace, stamp: uniqueStamp() }) }];
|
||||
},
|
||||
|
||||
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as TrimState;
|
||||
if (s.phase !== "pick") return [s, { draft: null }];
|
||||
const r = cmdQuery<{ hit: boolean; shapes: number[] }>(ctx.project, { q: "trim", level: ctx.level.id, pt: pair(point) });
|
||||
const r = cmdQuery<{ hit: boolean; shapes: number[] }>(ctx.project, { q: "trim", level: ctx.level.id, pt: pair(point), face: toFace });
|
||||
if (!r.hit) return [s, { draft: null }];
|
||||
const preview = decodeShapes(r.shapes);
|
||||
return [
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
// Wand-Editierbefehle ([113]): Trim, Extend, Teilen, Bruch, Verrunden, Verketten und Offset an Wänden über
|
||||
// die Befehls-Automaten (Treffer und Ops rechnet der Kern, `cmd_wall_edit.rs`).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../../model/sampleProject";
|
||||
import type { Opening, Project, Wall } from "../../model/types";
|
||||
import type { CmdInput, Command, CommandContext } from "../types";
|
||||
import type { ProjectMutation } from "../../core";
|
||||
import { trimCommand } from "./trim";
|
||||
import { extendCommand } from "./extend";
|
||||
import { splitCommand } from "./split";
|
||||
import { breakCommand } from "./break";
|
||||
import { filletCommand } from "./fillet";
|
||||
import { joinCommand } from "./join";
|
||||
import { offsetCommand } from "./offset";
|
||||
|
||||
const level = sampleProject.drawingLevels.find((l) => l.kind === "floor")!;
|
||||
const wt = sampleProject.wallTypes[0].id;
|
||||
const wall = (id: string, a: [number, number], b: [number, number], bulge?: number): Wall => ({
|
||||
id,
|
||||
type: "wall",
|
||||
floorId: level.id,
|
||||
categoryCode: "20",
|
||||
start: { x: a[0], y: a[1] },
|
||||
end: { x: b[0], y: b[1] },
|
||||
...(bulge !== undefined ? { bulge } : {}),
|
||||
wallTypeId: wt,
|
||||
height: 2.6,
|
||||
});
|
||||
const opening = (id: string, host: string, position: number): Opening =>
|
||||
({ id, type: "opening", hostWallId: host, categoryCode: "21", kind: "window", position, width: 1, height: 1.2, sillHeight: 0.9 }) as Opening;
|
||||
const proj = (walls: Wall[], openings: Opening[] = []): Project => ({ ...sampleProject, walls, openings, drawings2d: [], rooms: [], ceilings: [], stairs: [] });
|
||||
|
||||
function run(cmd: Command, p: Project, inputs: CmdInput[], wallIds: string[] = []): Project {
|
||||
const ctx: CommandContext = {
|
||||
project: p,
|
||||
level,
|
||||
defaultCategoryCode: "20",
|
||||
activeLineStyleId: "solid",
|
||||
activeWallTypeId: wt,
|
||||
lastPoint: null,
|
||||
selection: { wallIds, drawingId: null, drawingIds: [] },
|
||||
};
|
||||
let st = cmd.init();
|
||||
let fn: ProjectMutation | undefined = cmd.autoRun?.(ctx).commit;
|
||||
for (const input of inputs) {
|
||||
const [ns, res] = cmd.onInput(st, input, ctx);
|
||||
st = ns;
|
||||
if (res.commit) fn = res.commit;
|
||||
}
|
||||
return fn ? fn(p) : p;
|
||||
}
|
||||
const pt = (x: number, y: number): CmdInput => ({ kind: "point", point: { x, y } });
|
||||
const byId = (p: Project, id: string) => p.walls.find((w) => w.id === id)!;
|
||||
|
||||
describe("Wand-Editierbefehle ([113])", () => {
|
||||
it("Trim an der Querwand: Ende auf deren Achse, Öffnung im Rest bleibt, die weggeschnittene entfällt", () => {
|
||||
const p = proj([wall("a", [0, 0], [10, 0]), wall("b", [6, -3], [6, 3])], [opening("o1", "a", 1), opening("o2", "a", 7)]);
|
||||
const out = run(trimCommand, p, [pt(8, 0.02)]);
|
||||
expect(byId(out, "a").end).toEqual({ x: 6, y: 0 });
|
||||
expect(out.openings!.map((o) => o.id)).toEqual(["o1"]);
|
||||
});
|
||||
|
||||
it("Extend bis zur Achse bzw. (Option Fläche) bis zur Fläche", () => {
|
||||
const p = proj([wall("a", [0, 0], [4, 0]), wall("b", [6, -3], [6, 3])]);
|
||||
expect(byId(run(extendCommand, p, [pt(3.9, 0)]), "a").end).toEqual({ x: 6, y: 0 });
|
||||
const half = sampleProject.wallTypes[0].layers.reduce((s, l) => s + l.thickness, 0) / 2;
|
||||
const face = run(extendCommand, p, [{ kind: "option", id: "face" }, pt(3.9, 0)]);
|
||||
run(extendCommand, p, [{ kind: "option", id: "face" }]); // Option zurück (bleibt über Aufrufe)
|
||||
expect(byId(face, "a").end.x).toBeCloseTo(6 - half, 9);
|
||||
});
|
||||
|
||||
it("Teilen am Punkt: zwei Wände, Öffnung hängt am zweiten Stück mit umgerechneter Lage", () => {
|
||||
const p = proj([wall("a", [0, 0], [10, 0])], [opening("o", "a", 7)]);
|
||||
const out = run(splitCommand, p, [pt(4, 0.05)]);
|
||||
expect(out.walls).toHaveLength(2);
|
||||
expect(byId(out, "a").end).toEqual({ x: 4, y: 0 });
|
||||
const second = out.walls.find((w) => w.id !== "a")!;
|
||||
expect(out.openings![0].hostWallId).toBe(second.id);
|
||||
expect(out.openings![0].position).toBeCloseTo(3, 9);
|
||||
});
|
||||
|
||||
it("Teilen an Schnittpunkten einer Bogenwand", () => {
|
||||
const p = proj([wall("a", [-5, 0], [5, 0], 1), wall("b", [0, -8], [0, 8])]);
|
||||
const out = run(splitCommand, p, [{ kind: "option", id: "inter" }, pt(-5, 0.01)]);
|
||||
run(splitCommand, p, [{ kind: "option", id: "inter" }]);
|
||||
const arcs = out.walls.filter((w) => w.id !== "b");
|
||||
expect(arcs).toHaveLength(2);
|
||||
for (const w of arcs) expect(w.bulge).toBeCloseTo(Math.tan(Math.PI / 8), 9);
|
||||
});
|
||||
|
||||
it("Bruch: das Stück zwischen zwei Punkten entfällt", () => {
|
||||
const p = proj([wall("a", [0, 0], [10, 0])]);
|
||||
const out = run(breakCommand, p, [pt(3, 0), pt(5, 0)]);
|
||||
expect(out.walls.map((w) => [w.start.x, w.end.x])).toEqual([
|
||||
[0, 3],
|
||||
[5, 10],
|
||||
]);
|
||||
});
|
||||
|
||||
it("Verrunden zweier Wände: L-Ecke am Achsschnittpunkt, mit Radius eine Bogenwand", () => {
|
||||
const p = proj([wall("a", [0, 0], [4, 0]), wall("b", [6, 5], [6, -2])]);
|
||||
const l = run(filletCommand, p, [pt(2, 0), pt(6, 3)]);
|
||||
expect(byId(l, "a").end).toEqual({ x: 6, y: 0 });
|
||||
expect(byId(l, "b").end).toEqual({ x: 6, y: 0 });
|
||||
const r = run(filletCommand, p, [pt(2, 0), { kind: "number", value: 1 }, pt(6, 3)]);
|
||||
run(filletCommand, p, [pt(2, 0), { kind: "number", value: 0 }]);
|
||||
expect(r.walls).toHaveLength(3);
|
||||
const arc = r.walls.find((w) => w.bulge)!;
|
||||
expect(arc.start.x).toBeCloseTo(5, 9);
|
||||
expect(arc.end.y).toBeCloseTo(1, 9);
|
||||
});
|
||||
|
||||
it("Verketten kollinearer Wände und Offset", () => {
|
||||
const p = proj([wall("a", [0, 0], [4, 0]), wall("b", [4, 0], [10, 0])], [opening("o", "b", 1)]);
|
||||
const j = run(joinCommand, p, [], ["a", "b"]);
|
||||
expect(j.walls).toHaveLength(1);
|
||||
expect(j.walls[0].end).toEqual({ x: 10, y: 0 });
|
||||
expect(j.openings![0]).toMatchObject({ hostWallId: "a", position: 5 });
|
||||
const o = run(offsetCommand, proj([wall("a", [0, 0], [4, 0])]), [{ kind: "number", value: 2 }], ["a"]);
|
||||
expect(o.walls).toHaveLength(2);
|
||||
expect(Math.abs(o.walls[1].start.y)).toBeCloseTo(2, 9);
|
||||
});
|
||||
});
|
||||
@@ -59,6 +59,7 @@ import { revolveCommand } from "./cmds/revolve";
|
||||
import { loftCommand } from "./cmds/loft";
|
||||
import { trimCommand } from "./cmds/trim";
|
||||
import { breakCommand } from "./cmds/break";
|
||||
import { splitCommand } from "./cmds/split";
|
||||
import { extendCommand } from "./cmds/extend";
|
||||
import { filletCommand } from "./cmds/fillet";
|
||||
import { chamferCommand } from "./cmds/chamfer";
|
||||
@@ -133,6 +134,7 @@ export const COMMANDS: Record<string, Command> = {
|
||||
loft: loftCommand,
|
||||
trim: trimCommand,
|
||||
break: breakCommand,
|
||||
split: splitCommand,
|
||||
extend: extendCommand,
|
||||
fillet: filletCommand,
|
||||
chamfer: chamferCommand,
|
||||
@@ -271,6 +273,7 @@ export const ALIASES: Record<string, string> = {
|
||||
tr: "trim",
|
||||
br: "break",
|
||||
unterbrechen: "break",
|
||||
teilen: "split",
|
||||
ext: "extend",
|
||||
verlaengern: "extend",
|
||||
verlängern: "extend",
|
||||
|
||||
@@ -1905,6 +1905,11 @@ export const de = {
|
||||
"cmd.fillet.label": "Verrunden",
|
||||
"cmd.fillet.pick": "Ecke wählen:",
|
||||
"cmd.fillet.radius": "Radius:",
|
||||
"cmd.fillet.wall2": "Zweite Wand wählen (Zahl = Radius):",
|
||||
"cmd.wallEdit.faceOpt": "Fläche",
|
||||
"cmd.split.label": "Teilen",
|
||||
"cmd.split.pick": "Wand oder Linie an der Teilstelle anklicken (Esc beendet):",
|
||||
"cmd.split.interOpt": "Schnittpunkte",
|
||||
// Chamfer: Eckpunkt-Fasung mit Distanz (Maus oder getippt) — wie Fillet, ohne Bogen.
|
||||
"cmd.chamfer.label": "Fasen",
|
||||
"cmd.chamfer.pick": "Ecke wählen:",
|
||||
|
||||
@@ -1893,6 +1893,11 @@ export const en: Record<TranslationKey, string> = {
|
||||
"cmd.fillet.label": "Fillet",
|
||||
"cmd.fillet.pick": "Select corner:",
|
||||
"cmd.fillet.radius": "Radius:",
|
||||
"cmd.fillet.wall2": "Select second wall (number = radius):",
|
||||
"cmd.wallEdit.faceOpt": "Face",
|
||||
"cmd.split.label": "Split",
|
||||
"cmd.split.pick": "Click the wall or line at the split point (Esc to finish):",
|
||||
"cmd.split.interOpt": "Intersections",
|
||||
// Chamfer: corner bevel with a distance (mouse or typed) — like Fillet, no arc.
|
||||
"cmd.chamfer.label": "Chamfer",
|
||||
"cmd.chamfer.pick": "Select corner:",
|
||||
|
||||
@@ -368,7 +368,7 @@ const TOOLS_2D: ToolId[] = [
|
||||
];
|
||||
const TOOLS_3D: ToolId[] = ["wall", "ceiling", "window", "door", "stair", "room"];
|
||||
const COMMANDS_3D = ["column", "ceilingopening", "roof", "roofhole", "roofwindow", "dormer", "extrude", "revolve", "loft", "solid", "solidbool", "sectionline", "viewline", "autodim", "excavation"];
|
||||
const COMMANDS_EDIT = ["move", "copy", "array", "rotate", "mirror", "offset", "multiline", "trim", "break", "extend", "fillet", "chamfer", "join", "defblock", "measure"];
|
||||
const COMMANDS_EDIT = ["move", "copy", "array", "rotate", "mirror", "offset", "multiline", "trim", "break", "split", "extend", "fillet", "chamfer", "join", "defblock", "measure"];
|
||||
|
||||
type ToolsView = "list" | "icons";
|
||||
const VIEW_STORAGE_KEY = "dossier.toolsPanel.view";
|
||||
|
||||
@@ -114,6 +114,14 @@ export function CommandIcon({ name }: { name: string }) {
|
||||
<circle cx="4" cy="5" r="2" />
|
||||
</svg>
|
||||
);
|
||||
case "split":
|
||||
// Linie mit Teilstelle (Querstrich) — Teilen ([113]).
|
||||
return (
|
||||
<svg {...common}>
|
||||
<line x1="2.5" y1="9" x2="13.5" y2="9" />
|
||||
<line x1="8" y1="4" x2="8" y2="12" />
|
||||
</svg>
|
||||
);
|
||||
case "break":
|
||||
// Linie mit Lücke in der Mitte (Unterbrechen) + zwei Marker an den Bruchstellen.
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user