SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Insert SVG: say why a sketch is too large (#10874) (#10880)
SilentWolf75afa4f72f7d7b
diff --git a/crates/engine/src/cmd/sketch_import.rs b/crates/engine/src/cmd/sketch_import.rsindex a8d80d3326..eae00ba3db 100644--- a/crates/engine/src/cmd/sketch_import.rs+++ b/crates/engine/src/cmd/sketch_import.rs@@ -245,6 +245,11 @@ fn insert(s: &mut Session, p: &Value, cmd: &str, svg: bool) -> Result<Value> {let v = (q - pivot) * k;Vec2::new(v.x * cos - v.y * sin, v.x * sin + v.y * cos) + off};+ // A dense SVG/DXF (a floorplan) can yield far more entities than a sketch takes; refuse+ // before adding so the message names the cap (#10874). Scale alone does not shrink the count.+ if geom.len() > solidcraft_sketch::MAX_POINTS {+ return Err(solidcraft_sketch::SketchError::TooLarge.into());+ }let ((curves, texts), info) = edit(s, p, cmd, false, |sk, _| {let (cs, texts) = add_geometry(sk, &geom, &f, k, tol)?;Ok((ids_of(sk, &cs), texts))@@ -371,6 +376,22 @@ mod tests {}}+ /// #10874: a drawing with more entities than a sketch can hold is refused with the point+ /// cap and that scale alone does not help (a floorplan SVG often hits this).+ #[test]+ fn a_drawing_with_too_many_entities_names_the_sketch_cap() {+ let n = solidcraft_sketch::MAX_POINTS + 1;+ let mut dxf = String::from("0\nSECTION\n2\nENTITIES\n");+ for i in 0..n {+ dxf.push_str(&format!("0\nLINE\n10\n{i}\n20\n0\n11\n{}\n21\n1\n", i + 1));+ }+ dxf.push_str("0\nENDSEC\n0\nEOF\n");+ let mut s = Session::default();+ let e = s.execute("sketch.insert_dxf", &json!({"text": dxf})).unwrap_err().to_string();+ assert!(e.contains("20000") && e.contains("scale"), "{e}");+ assert!(s.active_sketch.is_none(), "a refused insert leaves no empty sketch behind");+ }+/// #9641: an SVG with nothing SolidCraft can draw (here only an embedded picture) is refused/// with a message naming the file and saying why, not "invalid parameters … no geometry"; a/// UTF-16 SVG file inserts.diff --git a/crates/sketch/src/model.rs b/crates/sketch/src/model.rsindex 3b32a43045..b696bb9558 100644--- a/crates/sketch/src/model.rs+++ b/crates/sketch/src/model.rs@@ -8,6 +8,8 @@ pub const MAX_POINTS: usize = 20_000;pub const MAX_CONSTRAINTS: usize = 40_000;/// Curves need points, so this follows the point cap.pub const MAX_CURVES: usize = MAX_POINTS;+// [`SketchError::TooLarge`]'s message names this number; keep them matched (#10874).+const _: () = assert!(MAX_POINTS == 20_000);/// Largest coordinate or dimension value (mm) a sketch accepts.pub const MAX_COORD: f64 = 1e9;@@ -37,7 +39,12 @@ pub enum SketchError {Duplicate(String),#[error("invalid value: {0}")]Invalid(String),- #[error("sketch is too large")]+ /// Cap hit on points, curves or constraints ([`MAX_POINTS`], [`MAX_CURVES`],+ /// [`MAX_CONSTRAINTS`]). Insert SVG/DXF of a dense drawing (a floorplan) often hits this;+ /// scale alone does not reduce how many curves the file has (#10874).+ #[error(+ "sketch is too large (at most 20000 points or curves); simplify the drawing or split it across sketches — changing scale does not reduce how many curves it has"+ )]TooLarge,}