[110] Linientyp ohne Strichstärke: Stärke an Schraffur, Schichtfuge, Element; Migration Format 4
This commit is contained in:
1 parent
ae52efae58
commit
765a93e562
27 files changed
+350
-153
No files matched your search
@@ -819,7 +819,7 @@ mod tests {
|
||||
assert_eq!(d.project().unwrap().walls.len(), 0);
|
||||
assert_eq!(d.field("openings").unwrap()[0]["kind"], "door");
|
||||
assert!(d.undo().is_none());
|
||||
assert!(d.serialize().starts_with("{\n \"formatVersion\": 3,\n \"id\": \"q\""));
|
||||
assert!(d.serialize().starts_with("{\n \"formatVersion\": 4,\n \"id\": \"q\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -745,7 +745,7 @@ fn plan_dash_styles(dashes: &[(String, Vec<f64>)], existing: &[Value], name_temp
|
||||
}
|
||||
used.insert(id.clone());
|
||||
let name = name_template.replace("{pattern}", &label);
|
||||
created.push(json!({"id": id, "name": name, "weight": 0.02, "color": "#1a1a1a", "dash": dash.iter().map(|&d| js_num(d)).collect::<Vec<_>>()}));
|
||||
created.push(json!({"id": id, "name": name, "color": "#1a1a1a", "dash": dash.iter().map(|&d| js_num(d)).collect::<Vec<_>>()}));
|
||||
by_layer.insert(layer.clone(), id);
|
||||
}
|
||||
(created, by_layer)
|
||||
@@ -897,6 +897,8 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
o.insert("geom".into(), geom);
|
||||
if let Some(s) = style_by_layer.get(&c.layer).filter(|s| !s.is_empty()) {
|
||||
o.insert("lineStyleId".into(), s.clone().into());
|
||||
// Strichlinien aus dem PDF als Haarlinie (die Stärke trägt das Element, nicht der Linienstil, [110]).
|
||||
o.insert("weightMm".into(), json!(0.02));
|
||||
}
|
||||
if c.filled && is_polyline {
|
||||
let fill = d.layer_fill_colors.get(&c.layer).and_then(Value::as_str).unwrap_or(DXF_HATCH_FILL);
|
||||
|
||||
@@ -136,7 +136,7 @@ fn pdf_mit_strichmuster() {
|
||||
let dec = decision(json!({"target": {"kind": "existing", "levelId": "eg"}, "categoryMode": "byLayer", "activeCategoryCode": "20", "dashStyleTemplate": "PDF-Strich {pattern}"}));
|
||||
let r = import_ops(&project(), &d, &dec, 0.0);
|
||||
let ops: Vec<Value> = r.ops.iter().map(Op::to_json).collect();
|
||||
assert_eq!(ops[0]["items"][0], json!({"id": "pdf-dash-1_05_0_7", "name": "PDF-Strich 1.05/0.7", "weight": 0.02, "color": "#1a1a1a", "dash": [1.05, 0.7]}));
|
||||
assert_eq!(ops[0]["items"][0], json!({"id": "pdf-dash-1_05_0_7", "name": "PDF-Strich 1.05/0.7", "color": "#1a1a1a", "dash": [1.05, 0.7]}));
|
||||
assert_eq!(ops[1]["items"][0]["lineStyleId"], json!("pdf-dash-1_05_0_7"));
|
||||
let info = pdf_page_info(&page);
|
||||
assert_eq!(info["layers"], json!({"PDF 0.18 #ff0000 (Strich 1.05/0.7)": 1, "PDF Fläche #ffffff": 1}));
|
||||
@@ -147,15 +147,15 @@ fn strichmuster_zu_linienstilen() {
|
||||
assert!(same_dash(&[1.05, 0.7], &[1.0, 0.7]));
|
||||
assert!(!same_dash(&[3.0, 1.0], &[1.0, 3.0]));
|
||||
assert!(!same_dash(&[1.0, 1.0], &[1.0, 1.0, 1.0, 1.0]));
|
||||
let solid = json!({"id": "thin", "name": "Volllinie", "weight": 0.13, "color": "#111", "dash": null});
|
||||
let dashed = json!({"id": "d", "name": "Strich", "weight": 0.02, "color": "#111", "dash": [1, 0.7]});
|
||||
let solid = json!({"id": "thin", "name": "Volllinie", "color": "#111", "dash": null});
|
||||
let dashed = json!({"id": "d", "name": "Strich", "color": "#111", "dash": [1, 0.7]});
|
||||
let dashes: Vec<(String, Vec<f64>)> =
|
||||
vec![("a".into(), vec![1.05, 0.7]), ("b".into(), vec![2.8, 1.4]), ("c".into(), vec![2.8, 1.4]), ("d".into(), vec![0.05, 0.7, 2.8, 0.7])];
|
||||
let (created, by_layer) = plan_dash_styles(&dashes, &[solid.clone(), dashed], "S {pattern}");
|
||||
assert_eq!(by_layer["a"], "d");
|
||||
assert_eq!(created.len(), 2);
|
||||
assert_eq!(by_layer["b"], by_layer["c"]);
|
||||
assert_eq!(created[0], json!({"id": "pdf-dash-2_8_1_4", "name": "S 2.8/1.4", "weight": 0.02, "color": "#1a1a1a", "dash": [2.8, 1.4]}));
|
||||
assert_eq!(created[0], json!({"id": "pdf-dash-2_8_1_4", "name": "S 2.8/1.4", "color": "#1a1a1a", "dash": [2.8, 1.4]}));
|
||||
assert_eq!(created[1]["dash"], json!([0.05, 0.7, 2.8, 0.7]));
|
||||
// Gleiche id schon vergeben → Zähler.
|
||||
let taken = json!({"id": "pdf-dash-2_8_1_4", "kind": "dot", "dash": [2.8, 1.4]});
|
||||
|
||||
@@ -46,15 +46,14 @@ pub struct LineStyleMotif {
|
||||
pub struct LineStyle {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
/// @deprecated Die Strichstärke gehört NICHT mehr in den Linienstil — es gibt nur
|
||||
/// „Vollinie/Strich", die tatsächliche Dicke wird per Element-Attribut (bzw.
|
||||
/// Ebene/Default) aufgelöst. Das Feld bleibt für die Backward-Compat-Auflösung
|
||||
/// erhalten und dient den Renderern noch als Fallback für die Muster-/Fugen-Stärke
|
||||
/// (siehe `resolveHatch` → `HatchRender.lineWeight`). Der Linien-Detail-Editor
|
||||
/// zeigt es nicht mehr an; neue Linienstile bekommen einen Haarlinien-Default.
|
||||
/// Die echte per-Element-Strichstärken-Auflösung (Attribut → Ebene → Default)
|
||||
/// folgt separat mit dem By-Layer/By-Object-Refactor — NICHT hier.
|
||||
pub weight: f64,
|
||||
/// @deprecated Nur noch für die Migration alter Dateien gelesen ([110], Format 4): Ein Linienstil
|
||||
/// legt nur das Muster (Volllinie, Strich, Punkt, Zickzack …) und die Farbe fest — die Strichstärke
|
||||
/// kommt vom Element (`Drawing2D.weightMm`), der Schraffur (`HatchStyle.lineWeight`), der
|
||||
/// Schichtfuge (`Layer.jointWeightMm`) bzw. Ebene/Stift. Die Migration trägt das alte Gewicht dort
|
||||
/// ein und entfernt es hier; die Renderer werten es nicht mehr aus.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub weight: Option<f64>,
|
||||
/// Farbe (hex).
|
||||
pub color: String,
|
||||
/// Strichmuster in Millimetern, alternierend AN/AUS (`[on, off, on, off, …]`),
|
||||
@@ -315,10 +314,14 @@ pub struct HatchStyle {
|
||||
/// `plan/generatePlan.ts` → `resolveHatch`). Bei `pattern==="solid"` ist es die
|
||||
/// Vollfüllfarbe, bei `pattern==="none"` ungenutzt.
|
||||
pub color: String,
|
||||
/// Optionaler Linienstil für die Musterlinien (Line Manager).
|
||||
/// Optionaler Linienstil für die Musterlinien (Line Manager): nur Muster/Farbe.
|
||||
#[serde(rename = "lineStyleId", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub line_style_id: Option<String>,
|
||||
/// Strichstärke der Musterlinien in Papier-mm ([110]); fehlt sie, gilt 0.13.
|
||||
#[serde(rename = "lineWeight", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub line_weight: Option<f64>,
|
||||
/// Steuer-Parameter der Random-Vektor-Schraffur (`kind`/"vector" + `lines`===
|
||||
/// "random", z. B. Kies/Splitt). ALLE additiv & optional — fehlen sie, gilt das
|
||||
/// bestehende deterministische Streu-Verhalten (Seed aus der Flächen-Bounding-Box,
|
||||
@@ -604,6 +607,10 @@ pub struct Layer {
|
||||
#[serde(rename = "jointLineStyleId", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub joint_line_style_id: Option<String>,
|
||||
/// Strichstärke der Schichtfuge in Papier-mm ([110]); fehlt sie, gilt die Standard-Fuge.
|
||||
#[serde(rename = "jointWeightMm", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub joint_weight_mm: Option<f64>,
|
||||
#[serde(flatten)]
|
||||
#[ts(skip)]
|
||||
pub extra: Extra,
|
||||
@@ -3009,7 +3016,7 @@ pub struct Drawing2D {
|
||||
#[ts(optional)]
|
||||
pub fill_color: Option<String>,
|
||||
/// Optionale direkte Strichstärke-Übersteuerung in Millimetern; hat Vorrang
|
||||
/// vor dem LineStyle-Gewicht und der Kategorie-Strichstärke.
|
||||
/// vor der Kategorie-Strichstärke (Linienstile tragen keine Stärke, [110]).
|
||||
#[serde(rename = "weightMm", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub weight_mm: Option<f64>,
|
||||
@@ -3025,8 +3032,8 @@ pub struct Drawing2D {
|
||||
#[ts(optional)]
|
||||
pub background_source: Option<AttributeSource>,
|
||||
/// Quelle der Strichstärke, wenn kein explizites `weightMm` gesetzt ist:
|
||||
/// "layer" erzwingt `LayerCategory.lw` (unter Umgehung des LineStyle-Gewichts),
|
||||
/// "object"/`undefined` (Default) = heutige Kette (LineStyle.weight ?? Kategorie).
|
||||
/// "layer" erzwingt `LayerCategory.lw`,
|
||||
/// "object"/`undefined` (Default) = Kategorie-Strichstärke.
|
||||
#[serde(rename = "strokeWeightSource", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub stroke_weight_source: Option<AttributeSource>,
|
||||
|
||||
@@ -136,14 +136,14 @@ pub fn emit_slabs(p: &Project) -> Vec<RSlab> {
|
||||
let l = &layers[layer_idx as usize];
|
||||
let (color, cut) = match p.component(&l.component_id) {
|
||||
Some(comp) => {
|
||||
let line = resolve_cut_line_style(p, l.joint_line_style_id.as_deref());
|
||||
let line = resolve_cut_line_style(p, l);
|
||||
(
|
||||
hex_to_rgb(&comp.color, style::WALL_RGB),
|
||||
Some(RCutMeta {
|
||||
join_priority: Some(comp.join_priority),
|
||||
component_id: Some(comp.id.clone()),
|
||||
line_color: line.map(|x| x.0),
|
||||
line_weight: line.map(|x| x.1),
|
||||
line_color: line.0,
|
||||
line_weight: line.1,
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -356,7 +356,7 @@ fn resolve_wall_bands(p: &Project, maps: &[String], wall: &Wall, layered: bool)
|
||||
let mut bands = Vec::with_capacity(wt.layers.len());
|
||||
for l in &wt.layers {
|
||||
let Some(comp) = p.component(&l.component_id) else { return fallback() };
|
||||
let line = resolve_cut_line_style(p, l.joint_line_style_id.as_deref());
|
||||
let line = resolve_cut_line_style(p, l);
|
||||
bands.push(WallBand {
|
||||
thickness: l.thickness,
|
||||
color: hex_to_rgb(&comp.color, WALL_RGB),
|
||||
@@ -364,8 +364,8 @@ fn resolve_wall_bands(p: &Project, maps: &[String], wall: &Wall, layered: bool)
|
||||
material_index: material_layer(p, maps, &l.component_id),
|
||||
priority: Some(comp.join_priority),
|
||||
component_id: Some(comp.id.clone()),
|
||||
cut_line_color: line.map(|x| x.0),
|
||||
cut_line_weight: line.map(|x| x.1),
|
||||
cut_line_color: line.0,
|
||||
cut_line_weight: line.1,
|
||||
});
|
||||
}
|
||||
(bands, true)
|
||||
@@ -1462,8 +1462,8 @@ pub fn emit_roof_cut_layers(p: &Project) -> Result<Vec<RRoofLayer>, String> {
|
||||
continue;
|
||||
}
|
||||
let color = roof_color(p, override_color, &layer.component_id)?;
|
||||
let line = resolve_cut_line_style(p, layer.joint_line_style_id.as_deref());
|
||||
let cut = line.map(|(c, w)| RCutMeta { line_color: Some(c), line_weight: Some(w), ..Default::default() });
|
||||
let line = resolve_cut_line_style(p, &layer);
|
||||
let cut = (line.0.is_some() || line.1.is_some()).then(|| RCutMeta { line_color: line.0, line_weight: line.1, ..Default::default() });
|
||||
for (i, plane) in g.planes.iter().enumerate() {
|
||||
let nrm = plane_normal_up(plane);
|
||||
let polygon: Vec<V3> = plane.iter().map(|q| [q[0] - nrm[0] * offset_above, q[1] - nrm[1] * offset_above, q[2] - nrm[2] * offset_above]).collect();
|
||||
|
||||
@@ -575,7 +575,7 @@ fn emit_inner(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed
|
||||
let ls_idx = attrs.line_style_id.filter(|s| !s.is_empty()).and_then(|id| p.line_styles.iter().position(|l| l.id == id));
|
||||
let ls = ls_idx.map(|i| &p.line_styles[i]);
|
||||
let color = attrs.color.or(ls.map(|l| l.color.as_str())).or(category.map(|k| k.color.as_str())).unwrap_or(MONO_INK);
|
||||
let weight = resolve_stroke_weight(attrs.weight, d.stroke_weight_source, category, ls.map(|l| l.weight).or(category.map(|k| k.lw)).unwrap_or(WALL_FALLBACK_MM));
|
||||
let weight = resolve_stroke_weight(attrs.weight, d.stroke_weight_source, category, category.map(|k| k.lw).unwrap_or(WALL_FALLBACK_MM));
|
||||
let dash_scale = match d.dash_scale {
|
||||
Some(s) if s > 0.0 => s,
|
||||
_ => 1.0,
|
||||
|
||||
@@ -101,7 +101,7 @@ pub fn resolve_hatch(p: &Project, hatch_id: &str, wall_angle_deg: Option<f64>, f
|
||||
angle,
|
||||
origin: p_origin,
|
||||
color: foreground.unwrap_or(HATCH_INK).to_string(),
|
||||
line_weight: ls.map_or(0.13, |l| l.weight),
|
||||
line_weight: h.line_weight.unwrap_or(0.13),
|
||||
dash: ls.and_then(|l| l.dash.clone()),
|
||||
kind: h.kind,
|
||||
lines: h.lines,
|
||||
|
||||
@@ -221,7 +221,7 @@ fn wall_poche(c: &Ctx, out: &mut Vec<Primitive>, e: &EffWall, gaps: &[(f64, f64)
|
||||
a,
|
||||
b,
|
||||
"layer-joint",
|
||||
jls.map_or(layer_mm, |s| s.weight * detail.layer_factor()),
|
||||
wt.layers.get(li).and_then(|l| l.joint_weight_mm).filter(|w| w.is_finite() && *w > 0.0).map_or(layer_mm, |w| w * detail.layer_factor()),
|
||||
Some(jls.and_then(|s| s.dash.clone())),
|
||||
Some(jls.map_or(stroke, |s| s.color.as_str())),
|
||||
greyed,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
/// Aktuelle Version des Dateiformats. Bei jeder Formatänderung erhöhen + Migration anhängen.
|
||||
pub const PROJECT_FORMAT_VERSION: u64 = 3;
|
||||
pub const PROJECT_FORMAT_VERSION: u64 = 4;
|
||||
|
||||
const REQUIRED_ARRAYS: [&str; 3] = ["walls", "layers", "drawingLevels"];
|
||||
const DEFAULT_ARRAYS: [&str; 5] = ["lineStyles", "hatches", "components", "wallTypes", "drawings2d"];
|
||||
@@ -236,6 +236,128 @@ pub fn parse_project_file(text: &str, now_ms: f64) -> Parsed {
|
||||
}
|
||||
}
|
||||
|
||||
/// Name ohne angehängte Strichstärke („Volllinie 0.13" → „Volllinie", „Schraffurlinie 0.10 mm" →
|
||||
/// „Schraffurlinie"); sonst unverändert.
|
||||
fn strip_weight_suffix(name: &str) -> String {
|
||||
let t = name.trim_end();
|
||||
let t = t.strip_suffix("mm").map_or(t, str::trim_end);
|
||||
let Some(pos) = t.rfind(' ') else { return name.to_string() };
|
||||
let tail = &t[pos + 1..];
|
||||
if !tail.is_empty() && tail.chars().all(|c| c.is_ascii_digit() || c == '.' || c == ',') && tail.chars().any(|c| c.is_ascii_digit()) {
|
||||
t[..pos].trim_end().to_string()
|
||||
} else {
|
||||
name.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// 3 → 4 ([110]): Linienstile tragen keine Strichstärke mehr. Das alte `LineStyle.weight` wandert an
|
||||
/// die Verwender — Schraffur (`lineWeight`), Schichtfuge der Aufbauten (`jointWeightMm`), 2D-Element
|
||||
/// (`weightMm`, nur wo es vorher galt: kein eigenes `weightMm`, Quelle nicht „layer") und Override-
|
||||
/// Aktion (`lineweight`) —, damit Pläne gleich aussehen. Danach werden Stile, die sich nur in der
|
||||
/// Stärke unterschieden, zu einem zusammengeführt (erster gewinnt, Name ohne Stärke-Anhang).
|
||||
fn migrate_line_weights(mut raw: Map<String, Value>) -> Map<String, Value> {
|
||||
let Some(Value::Array(styles)) = raw.get("lineStyles").cloned() else { return raw };
|
||||
let mut weight: std::collections::HashMap<String, f64> = std::collections::HashMap::new();
|
||||
// Gruppen gleicher Stile ohne id/Name/Stärke → kanonische id.
|
||||
let mut canon: std::collections::HashMap<String, String> = std::collections::HashMap::new();
|
||||
let mut by_key: Vec<(String, String)> = Vec::new();
|
||||
let mut kept: Vec<Value> = Vec::new();
|
||||
for st in styles {
|
||||
let Value::Object(mut o) = st else {
|
||||
kept.push(st);
|
||||
continue;
|
||||
};
|
||||
let id = o.get("id").and_then(Value::as_str).unwrap_or("").to_string();
|
||||
if let Some(w) = o.get("weight").and_then(Value::as_f64).filter(|w| w.is_finite()) {
|
||||
weight.insert(id.clone(), w);
|
||||
}
|
||||
o.shift_remove("weight");
|
||||
let mut key_obj = o.clone();
|
||||
key_obj.shift_remove("id");
|
||||
key_obj.shift_remove("name");
|
||||
if key_obj.get("dash").is_some_and(Value::is_null) {
|
||||
key_obj.shift_remove("dash");
|
||||
}
|
||||
let key = Value::Object(key_obj).to_string();
|
||||
if let Some((_, first)) = by_key.iter().find(|(k, _)| *k == key) {
|
||||
if !id.is_empty() {
|
||||
canon.insert(id, first.clone());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(n) = o.get("name").and_then(Value::as_str) {
|
||||
// Ohne Stärke-Anhang, solange der Name dadurch nicht doppelt wird.
|
||||
let stripped = strip_weight_suffix(n);
|
||||
if !kept.iter().any(|k| k.get("name").and_then(Value::as_str) == Some(stripped.as_str())) {
|
||||
o.insert("name".into(), stripped.into());
|
||||
}
|
||||
}
|
||||
by_key.push((key, id));
|
||||
kept.push(Value::Object(o));
|
||||
}
|
||||
raw.insert("lineStyles".into(), Value::Array(kept));
|
||||
let canon_of = |id: &str| canon.get(id).cloned().unwrap_or_else(|| id.to_string());
|
||||
let weight_of = |v: Option<&Value>| v.and_then(Value::as_str).filter(|s| !s.is_empty()).and_then(|id| weight.get(id).copied());
|
||||
let num = |w: f64| serde_json::Number::from_f64(w).map(Value::Number);
|
||||
let redirect = |o: &mut Map<String, Value>, key: &str| {
|
||||
if let Some(Value::String(id)) = o.get(key) {
|
||||
let c = canon_of(id);
|
||||
o.insert(key.into(), c.into());
|
||||
}
|
||||
};
|
||||
// Schraffuren.
|
||||
if let Some(Value::Array(hs)) = raw.get_mut("hatches") {
|
||||
for h in hs.iter_mut().filter_map(Value::as_object_mut) {
|
||||
if !h.contains_key("lineWeight") {
|
||||
if let Some(w) = weight_of(h.get("lineStyleId")).and_then(num) {
|
||||
h.insert("lineWeight".into(), w);
|
||||
}
|
||||
}
|
||||
redirect(h, "lineStyleId");
|
||||
}
|
||||
}
|
||||
// Schichtfugen der Aufbauten.
|
||||
for key in ["wallTypes", "ceilingTypes", "roofTypes"] {
|
||||
let Some(Value::Array(ts)) = raw.get_mut(key) else { continue };
|
||||
for t in ts.iter_mut().filter_map(Value::as_object_mut) {
|
||||
let Some(Value::Array(ls)) = t.get_mut("layers") else { continue };
|
||||
for l in ls.iter_mut().filter_map(Value::as_object_mut) {
|
||||
if !l.contains_key("jointWeightMm") {
|
||||
if let Some(w) = weight_of(l.get("jointLineStyleId")).and_then(num) {
|
||||
l.insert("jointWeightMm".into(), w);
|
||||
}
|
||||
}
|
||||
redirect(l, "jointLineStyleId");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2D-Elemente.
|
||||
if let Some(Value::Array(ds)) = raw.get_mut("drawings2d") {
|
||||
for d in ds.iter_mut().filter_map(Value::as_object_mut) {
|
||||
let layer_src = d.get("strokeWeightSource").and_then(Value::as_str) == Some("layer");
|
||||
if !layer_src && !d.get("weightMm").is_some_and(Value::is_number) {
|
||||
if let Some(w) = weight_of(d.get("lineStyleId")).and_then(num) {
|
||||
d.insert("weightMm".into(), w);
|
||||
}
|
||||
}
|
||||
redirect(d, "lineStyleId");
|
||||
}
|
||||
}
|
||||
// Override-Regeln.
|
||||
if let Some(Value::Array(rs)) = raw.get_mut("overrideRules") {
|
||||
for r in rs.iter_mut().filter_map(Value::as_object_mut) {
|
||||
let Some(Value::Object(a)) = r.get_mut("actions") else { continue };
|
||||
if !a.get("lineweight").is_some_and(Value::is_number) {
|
||||
if let Some(w) = weight_of(a.get("linetypeId")).and_then(num) {
|
||||
a.insert("lineweight".into(), w);
|
||||
}
|
||||
}
|
||||
redirect(a, "linetypeId");
|
||||
}
|
||||
}
|
||||
raw
|
||||
}
|
||||
|
||||
/// Wie [`parse_project_file`], für ein bereits geparstes Objekt.
|
||||
pub fn parse_project_object(raw: Value, now_ms: f64) -> Parsed {
|
||||
let Value::Object(mut obj) = raw else { return Parsed::Err("Die Datei enthält kein Dossier-Projekt.".into()) };
|
||||
@@ -267,6 +389,7 @@ pub fn parse_project_object(raw: Value, now_ms: f64) -> Parsed {
|
||||
obj = match i {
|
||||
1 => migrate_doors(obj),
|
||||
2 => migrate_layout_annotations(obj),
|
||||
3 => migrate_line_weights(obj),
|
||||
_ => obj, // 0 → 1: Einführung von `formatVersion`; Inhalt unverändert.
|
||||
};
|
||||
}
|
||||
@@ -456,11 +579,67 @@ mod tests {
|
||||
json!({"id":"p","name":"N","walls":[],"layers":[],"drawingLevels":[]})
|
||||
}
|
||||
|
||||
/// [110]: Stärke wandert vom Linienstil an Schraffur, Fuge, Element und Override; Stile, die sich
|
||||
/// nur in der Stärke unterscheiden, werden eins.
|
||||
#[test]
|
||||
fn linienstaerke_wandert_an_die_verwender() {
|
||||
let v = json!({"formatVersion": 3, "id":"p","name":"N","walls":[],"layers":[],"drawingLevels":[],
|
||||
"lineStyles": [
|
||||
{"id":"hair","name":"Volllinie 0.02","weight":0.02,"color":"#1a1a1a","dash":null},
|
||||
{"id":"thin","name":"Volllinie 0.13","weight":0.13,"color":"#1a1a1a","dash":null},
|
||||
{"id":"thick","name":"Volllinie 0.5 mm","weight":0.5,"color":"#1a1a1a"},
|
||||
{"id":"dash","name":"Strich","weight":0.02,"color":"#1a1a1a","dash":[1,0.7]},
|
||||
{"id":"dark","name":"Volllinie 0.5","weight":0.5,"color":"#0a0a0a","dash":null}
|
||||
],
|
||||
"hatches": [
|
||||
{"id":"h1","name":"A","pattern":"diagonal","scale":1,"angle":45,"color":"#000","lineStyleId":"hair"},
|
||||
{"id":"h2","name":"B","pattern":"diagonal","scale":1,"angle":45,"color":"#000","lineStyleId":"thick","lineWeight":0.18},
|
||||
{"id":"h3","name":"C","pattern":"diagonal","scale":1,"angle":45,"color":"#000"}
|
||||
],
|
||||
"wallTypes": [{"id":"w","name":"W","layers":[{"componentId":"c","thickness":0.1,"jointLineStyleId":"thin"},{"componentId":"c","thickness":0.1}]}],
|
||||
"roofTypes": [{"id":"r","name":"R","layers":[{"componentId":"c","thickness":0.1,"jointLineStyleId":"dash"}]}],
|
||||
"drawings2d": [
|
||||
{"id":"d1","lineStyleId":"thick"},
|
||||
{"id":"d2","lineStyleId":"thick","weightMm":0.7},
|
||||
{"id":"d3","lineStyleId":"thick","strokeWeightSource":"layer"}
|
||||
],
|
||||
"overrideRules": [{"id":"o","actions":{"linetypeId":"thin"}}]
|
||||
});
|
||||
let Parsed::Ok { project: p, migrated_from, .. } = parse_project_object(v, 0.0) else { panic!() };
|
||||
assert_eq!(migrated_from, Some(3));
|
||||
assert_eq!(p["lineStyles"], json!([
|
||||
{"id":"hair","name":"Volllinie","color":"#1a1a1a","dash":null},
|
||||
{"id":"dash","name":"Strich","color":"#1a1a1a","dash":[1,0.7]},
|
||||
{"id":"dark","name":"Volllinie 0.5","color":"#0a0a0a","dash":null}
|
||||
]));
|
||||
assert_eq!(p["hatches"][0]["lineWeight"], json!(0.02));
|
||||
assert_eq!(p["hatches"][1]["lineWeight"], json!(0.18));
|
||||
assert_eq!(p["hatches"][1]["lineStyleId"], json!("hair"));
|
||||
assert!(p["hatches"][2].get("lineWeight").is_none());
|
||||
let wl = &p["wallTypes"][0]["layers"];
|
||||
assert_eq!((wl[0]["jointWeightMm"].clone(), wl[0]["jointLineStyleId"].clone()), (json!(0.13), json!("hair")));
|
||||
assert!(wl[1].get("jointWeightMm").is_none());
|
||||
assert_eq!(p["roofTypes"][0]["layers"][0]["jointWeightMm"], json!(0.02));
|
||||
let d = &p["drawings2d"];
|
||||
assert_eq!((d[0]["weightMm"].clone(), d[0]["lineStyleId"].clone()), (json!(0.5), json!("hair")));
|
||||
assert_eq!(d[1]["weightMm"], json!(0.7));
|
||||
assert!(d[2].get("weightMm").is_none());
|
||||
assert_eq!(p["overrideRules"][0]["actions"], json!({"linetypeId":"hair","lineweight":0.13}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staerke_anhang_im_namen() {
|
||||
assert_eq!(strip_weight_suffix("Volllinie 0.13"), "Volllinie");
|
||||
assert_eq!(strip_weight_suffix("Schraffurlinie 0.10 mm"), "Schraffurlinie");
|
||||
assert_eq!(strip_weight_suffix("Strichlinie fein"), "Strichlinie fein");
|
||||
assert_eq!(strip_weight_suffix("PDF-Strich 1.05/0.7"), "PDF-Strich 1.05/0.7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alte_datei_wird_migriert_und_ergaenzt() {
|
||||
let Parsed::Ok { project, warnings, migrated_from } = parse_project_object(minimal(), 0.0) else { panic!() };
|
||||
assert_eq!(migrated_from, Some(0));
|
||||
assert_eq!(project["formatVersion"], 3);
|
||||
assert_eq!(project["formatVersion"], 4);
|
||||
assert_eq!(project["lineStyles"], json!([]));
|
||||
assert!(warnings.is_empty());
|
||||
}
|
||||
@@ -604,6 +783,6 @@ mod tests {
|
||||
fn serialisierung_setzt_version_nach_vorn() {
|
||||
let Value::Object(m) = minimal() else { panic!() };
|
||||
let s = serialize_project(&m);
|
||||
assert!(s.starts_with("{\n \"formatVersion\": 3,\n \"id\": \"p\""));
|
||||
assert!(s.starts_with("{\n \"formatVersion\": 4,\n \"id\": \"p\""));
|
||||
}
|
||||
}
|
||||
@@ -1145,7 +1145,6 @@ fn drawing_selection(root: &Map<String, Value>, d: &Value) -> J {
|
||||
let cat_lw = cat.and_then(|c| nn(field(c, "lw")));
|
||||
let weight = nn(field(d, "weightMm"))
|
||||
.or_else(|| if str_of(field(d, "strokeWeightSource")) != Some("object") { cat_lw } else { None })
|
||||
.or_else(|| ls.and_then(|l| nn(field(l, "weight"))))
|
||||
.or(cat_lw)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| js_num(WALL_FALLBACK_MM));
|
||||
|
||||
@@ -34,22 +34,23 @@ fn material(id: &str, size_m: f64) -> Value {
|
||||
|
||||
const INK: &str = "#1a1a1a";
|
||||
|
||||
/// Linientypen (SIA 400 / ISO 128). Strichmuster in Papier-mm (AN/AUS, 0 = Punkt), unabhängig vom Massstab.
|
||||
/// Linientypen (SIA 400 / ISO 128): nur Muster und Farbe — die Strichstärke kommt vom Element, der
|
||||
/// Schraffur, der Schichtfuge bzw. Ebene/Stift ([110]). Strichmuster in Papier-mm (AN/AUS, 0 = Punkt),
|
||||
/// unabhängig vom Massstab.
|
||||
pub fn line_styles() -> Vec<Value> {
|
||||
let dash = |id: &str, name: &str, w: f64, d: Value| json!({"id": id, "name": name, "weight": w, "color": INK, "dash": d});
|
||||
let dash = |id: &str, name: &str, d: Value| json!({"id": id, "name": name, "color": INK, "dash": d});
|
||||
vec![
|
||||
dash("std-ls-voll", "Volllinie", 0.25, Value::Null),
|
||||
dash("std-ls-strich-fein", "Strichlinie fein", 0.18, json!([3, 1.5])),
|
||||
dash("std-ls-strich-grob", "Strichlinie grob", 0.5, json!([6, 2])),
|
||||
dash("std-ls-punkt", "Punktlinie", 0.25, json!([0, 1])),
|
||||
dash("std-ls-strichpunkt", "Strichpunktlinie (Achse)", 0.18, json!([12, 1.5, 0, 1.5])),
|
||||
dash("std-ls-strichzweipunkt", "Strich-Zweipunktlinie", 0.18, json!([12, 1.5, 0, 1.5, 0, 1.5])),
|
||||
dash("std-ls-grundstueck", "Grundstücksgrenze", 0.5, json!([8, 1.5, 0, 1.5, 0, 1.5])),
|
||||
dash("std-ls-bauteilgrenze", "Baulinie / Bauteilgrenze", 0.35, json!([8, 1.5, 0, 1.5])),
|
||||
json!({"id": "std-ls-bruch", "name": "Bruchlinie (Zickzack)", "weight": 0.18, "color": INK, "dash": null,
|
||||
dash("std-ls-voll", "Volllinie", Value::Null),
|
||||
dash("std-ls-strich-fein", "Strichlinie", json!([3, 1.5])),
|
||||
dash("std-ls-strich-grob", "Strichlinie lang", json!([6, 2])),
|
||||
dash("std-ls-punkt", "Punktlinie", json!([0, 1])),
|
||||
dash("std-ls-strichpunkt", "Strichpunktlinie (Achse)", json!([12, 1.5, 0, 1.5])),
|
||||
dash("std-ls-strichzweipunkt", "Strich-Zweipunktlinie", json!([12, 1.5, 0, 1.5, 0, 1.5])),
|
||||
dash("std-ls-grundstueck", "Grundstücksgrenze", json!([8, 1.5, 0, 1.5, 0, 1.5])),
|
||||
dash("std-ls-bauteilgrenze", "Baulinie / Bauteilgrenze", json!([8, 1.5, 0, 1.5])),
|
||||
json!({"id": "std-ls-bruch", "name": "Bruchlinie (Zickzack)", "color": INK, "dash": null,
|
||||
"kind": "zigzag", "zigzag": {"amplitude": 1.5, "wavelength": 4}}),
|
||||
dash("std-ls-schraffur", "Schraffurlinie 0.10", 0.1, Value::Null),
|
||||
dash("std-ls-schraffur-strich", "Schraffurlinie gestrichelt", 0.1, json!([1, 0.7])),
|
||||
dash("std-ls-schraffur-strich", "Strichlinie kurz", json!([1, 0.7])),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -61,14 +62,19 @@ pub fn hatches() -> Vec<Value> {
|
||||
v["relativeToWall"] = json!(true);
|
||||
}
|
||||
if !ls.is_empty() {
|
||||
v["lineStyleId"] = json!(ls);
|
||||
v["lineWeight"] = json!(if ls == "std-ls-voll-025" { 0.25 } else { 0.1 });
|
||||
if ls == "std-ls-voll-025" {
|
||||
v["lineStyleId"] = json!("std-ls-voll");
|
||||
} else if ls != "std-ls-schraffur" {
|
||||
v["lineStyleId"] = json!(ls);
|
||||
}
|
||||
}
|
||||
v
|
||||
};
|
||||
let solid = |id: &str, name: &str, color: &str| json!({"id": id, "name": name, "pattern": "solid", "scale": 1, "angle": 0, "color": color});
|
||||
let random = |id: &str, name: &str, angle: f64, density: f64, lmin: f64, lmax: f64, seed: f64| {
|
||||
json!({"id": id, "name": name, "kind": "vector", "lines": "random", "pattern": "diagonal", "scale": 1, "angle": angle,
|
||||
"color": INK, "lineStyleId": "std-ls-schraffur", "density": density, "lengthMin": lmin, "lengthMax": lmax, "seed": seed})
|
||||
"color": INK, "lineWeight": 0.1, "density": density, "lengthMin": lmin, "lengthMax": lmax, "seed": seed})
|
||||
};
|
||||
vec![
|
||||
h("std-h-ohne", "SIA Ohne Schraffur", "none", 1.0, 0.0, false, ""),
|
||||
@@ -88,7 +94,7 @@ pub fn hatches() -> Vec<Value> {
|
||||
h("std-h-estrich", "SIA Estrich", "diagonal", 0.35, 45.0, false, "std-ls-schraffur-strich"),
|
||||
solid("std-h-stahl", "SIA Stahl", INK),
|
||||
solid("std-h-alu", "SIA Aluminium", "#8c8c8c"),
|
||||
h("std-h-naturstein", "SIA Naturstein", "diagonal", 0.8, 45.0, false, "std-ls-voll"),
|
||||
h("std-h-naturstein", "SIA Naturstein", "diagonal", 0.8, 45.0, false, "std-ls-voll-025"),
|
||||
random("std-h-erdreich", "SIA Erdreich", 45.0, 0.8, 1.5, 4.0, 11.0),
|
||||
random("std-h-kies", "SIA Kies / Sauberkeitsschicht", 60.0, 1.8, 0.4, 0.9, 13.0),
|
||||
]
|
||||
@@ -330,7 +336,7 @@ mod tests {
|
||||
let tb = p.components.iter().find(|c| c.id == "std-c-trapezblech").unwrap().material.as_ref().unwrap();
|
||||
assert!(tb.color.is_none() && tb.library_id.as_deref() == Some("CorrugatedSteel005"));
|
||||
// Linientypen
|
||||
for name in ["Volllinie", "Strichlinie fein", "Strichlinie grob", "Punktlinie", "Strichpunktlinie (Achse)", "Strich-Zweipunktlinie", "Grundstücksgrenze", "Bruchlinie (Zickzack)"] {
|
||||
for name in ["Volllinie", "Strichlinie", "Strichlinie lang", "Punktlinie", "Strichpunktlinie (Achse)", "Strich-Zweipunktlinie", "Grundstücksgrenze", "Bruchlinie (Zickzack)"] {
|
||||
assert!(p.line_styles.iter().any(|l| l.name == name), "{name}");
|
||||
}
|
||||
}
|
||||
@@ -345,14 +351,14 @@ mod tests {
|
||||
fn gleichnamige_bleiben_und_verweise_zeigen_darauf() {
|
||||
let mut root = empty_root();
|
||||
root.insert("components".into(), json!([{"id": "brick", "name": "backstein ", "color": "#8c5544", "hatchId": "x", "joinPriority": 50}]));
|
||||
root.insert("lineStyles".into(), json!([{"id": "thin", "name": "Schraffurlinie 0.10", "weight": 0.1, "color": "#000", "dash": null}]));
|
||||
root.insert("lineStyles".into(), json!([{"id": "thin", "name": "Strichlinie kurz", "color": "#000", "dash": [1, 0.7]}]));
|
||||
let r = apply(&root, &merge_ops(&root));
|
||||
let comps = r["components"].as_array().unwrap();
|
||||
assert_eq!(comps.iter().filter(|c| c["name"].as_str().unwrap().trim().eq_ignore_ascii_case("backstein")).count(), 1);
|
||||
assert_eq!(comps[0]["color"], "#8c5544", "vorhandenes Bauteil unverändert");
|
||||
let iw = r["wallTypes"].as_array().unwrap().iter().find(|t| t["id"] == "std-wt-iw-backstein").unwrap();
|
||||
assert_eq!(iw["layers"][1]["componentId"], "brick");
|
||||
let bs = r["hatches"].as_array().unwrap().iter().find(|h| h["id"] == "std-h-backstein").unwrap();
|
||||
assert_eq!(bs["lineStyleId"], "thin");
|
||||
let pb = r["hatches"].as_array().unwrap().iter().find(|h| h["id"] == "std-h-porenbeton").unwrap();
|
||||
assert_eq!(pb["lineStyleId"], "thin");
|
||||
}
|
||||
}
|
||||
@@ -58,13 +58,12 @@ pub struct HatchCore {
|
||||
|
||||
pub fn resolve_hatch_core(p: &Project, hatch_id: &str, wall_angle_deg: Option<f64>) -> Option<HatchCore> {
|
||||
let h = p.hatch(hatch_id)?;
|
||||
let ls = h.line_style_id.as_deref().filter(|s| !s.is_empty()).and_then(|id| p.line_style(id));
|
||||
let base = h.angle;
|
||||
let angle = match wall_angle_deg {
|
||||
Some(w) if h.relative_to_wall == Some(true) => base - w,
|
||||
_ => base,
|
||||
};
|
||||
Some(HatchCore { pattern: h.pattern, scale: h.scale * 1.0, angle, line_weight: ls.map_or(0.13, |l| l.weight) })
|
||||
Some(HatchCore { pattern: h.pattern, scale: h.scale * 1.0, angle, line_weight: h.line_weight.unwrap_or(0.13) })
|
||||
}
|
||||
|
||||
/// Schnitt-Schraffur eines Bauteils (`resolveComponentHatch`); `axis_angle_deg` 90 für Wand-Bänder,
|
||||
@@ -113,8 +112,10 @@ pub fn dominant_layer_color(p: &Project, layers: &[crate::model::Layer], fallbac
|
||||
}
|
||||
}
|
||||
|
||||
/// Stil der Schnitt-Umrisslinie einer Schicht (`resolveCutLineStyle`).
|
||||
pub fn resolve_cut_line_style(p: &Project, joint_line_style_id: Option<&str>) -> Option<(Rgb, f64)> {
|
||||
let ls = p.line_styles.iter().find(|l| Some(l.id.as_str()) == joint_line_style_id.filter(|s| !s.is_empty()))?;
|
||||
Some((hex_to_rgb(&ls.color, DRAWING_LINE_FALLBACK_RGB), ls.weight))
|
||||
/// Stil der Schnitt-Umrisslinie einer Schicht (`resolveCutLineStyle`): Farbe aus dem Linienstil der
|
||||
/// Fuge, Stärke aus der Schicht (`jointWeightMm`, [110]) — beide unabhängig optional.
|
||||
pub fn resolve_cut_line_style(p: &Project, layer: &crate::model::Layer) -> (Option<Rgb>, Option<f64>) {
|
||||
let id = layer.joint_line_style_id.as_deref().filter(|s| !s.is_empty());
|
||||
let ls = id.and_then(|id| p.line_styles.iter().find(|l| l.id == id));
|
||||
(ls.map(|ls| hex_to_rgb(&ls.color, DRAWING_LINE_FALLBACK_RGB)), layer.joint_weight_mm.filter(|w| w.is_finite() && *w > 0.0))
|
||||
}
|
||||
Reference in new issue
Block a user