Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sketch palette: a new empty sketch is not "Fully constrained" (#2906) (#3011)

rlartot750e08aab70f
diff --git a/assets/locales/en.json b/assets/locales/en.json
index a948a4e068..1baf033927 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -1370,6 +1370,7 @@
"ui.newSketchGroup": "New Sketch Group",
"ui.new_body": "New Body",
"ui.new_design": "New Design",
+ "ui.no_geometry_yet": "No geometry yet",
"ui.no_slicer_found": "No slicer found",
"ui.normal": "Normal",
"ui.normalConstruction": "Normal / Construction",
diff --git a/assets/locales/fr.json b/assets/locales/fr.json
index 47905bc056..6d303e34da 100644
--- a/assets/locales/fr.json
+++ b/assets/locales/fr.json
@@ -1355,6 +1355,7 @@
"ui.newSketchGroup": "Nouveau groupe d'esquisses",
"ui.new_body": "Nouveau corps",
"ui.new_design": "Nouvelle conception",
+ "ui.no_geometry_yet": "Aucune géométrie pour l'instant",
"ui.no_slicer_found": "Aucun slicer trouvé",
"ui.normal": "Normal",
"ui.normalConstruction": "Normal / Construction",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index ff55a1600d..3bce6c9528 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -1370,6 +1370,7 @@
"ui.newSketchGroup": "新しいスケッチグループ",
"ui.new_body": "新規ボディ",
"ui.new_design": "新規デザイン",
+ "ui.no_geometry_yet": "ジオメトリはまだありません",
"ui.no_slicer_found": "スライサーが見つかりません",
"ui.normal": "標準",
"ui.normalConstruction": "通常 / コンストラクション",
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index 1a4fd6a176..0c43a69052 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -1370,6 +1370,7 @@
"ui.newSketchGroup": "新建草图组",
"ui.new_body": "新建实体",
"ui.new_design": "新建设计",
+ "ui.no_geometry_yet": "尚无几何图形",
"ui.no_slicer_found": "未找到切片软件",
"ui.normal": "法向",
"ui.normalConstruction": "普通 / 构造",
diff --git a/crates/ui-egui/src/sketch_palette.rs b/crates/ui-egui/src/sketch_palette.rs
index 57fe403ea2..26924ad7d3 100644
--- a/crates/ui-egui/src/sketch_palette.rs
+++ b/crates/ui-egui/src/sketch_palette.rs
@@ -69,10 +69,19 @@ pub const TOGGLES: [(&str, &str); 10] = [
("sketch_3d", "3D Sketch"),
];
-/// The degrees-of-freedom line: "Fully constrained" or "N degrees of freedom".
-pub fn dof_text(dof: usize, ok: bool) -> String {
+/// Does the sketch hold any geometry of its own: a drawn curve or a 3D curve? Projected curves
+/// and the origin are held in place and do not count.
+pub fn has_geometry(sketch: &solidcraft_engine::sketch::Sketch) -> bool {
+ !sketch.curves.is_empty() || !sketch.wires.is_empty()
+}
+
+/// The degrees-of-freedom line: "No geometry yet" (an empty sketch only has its fixed origin),
+/// "Fully constrained" or "N degrees of freedom".
+pub fn dof_text(dof: usize, ok: bool, has_geometry: bool) -> String {
if !ok {
"Constraints conflict".into()
+ } else if !has_geometry {
+ "No geometry yet".into()
} else if dof == 0 {
"Fully constrained".into()
} else if dof == 1 {
@@ -345,8 +354,8 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let Some(ss) = app.session.active_sketch.and_then(|s| st.sketch(s)) else { return };
(
ss.sketch.view.clone(),
- dof_text(ss.report.dof, ss.report.ok()),
- ss.report.ok() && ss.report.dof == 0,
+ dof_text(ss.report.dof, ss.report.ok(), has_geometry(&ss.sketch)),
+ ss.report.ok() && ss.report.dof == 0 && has_geometry(&ss.sketch),
ss.ends.open.len(),
ss.ends.untied.len(),
)
@@ -942,9 +951,28 @@ mod tests {
#[test]
fn dof_readout() {
- assert_eq!(dof_text(0, true), "Fully constrained");
- assert_eq!(dof_text(1, true), "1 degree of freedom");
- assert_eq!(dof_text(4, true), "4 degrees of freedom");
- assert_eq!(dof_text(4, false), "Constraints conflict");
+ assert_eq!(dof_text(0, true, true), "Fully constrained");
+ assert_eq!(dof_text(1, true, true), "1 degree of freedom");
+ assert_eq!(dof_text(4, true, true), "4 degrees of freedom");
+ assert_eq!(dof_text(4, false, true), "Constraints conflict");
+ assert_eq!(dof_text(0, true, false), "No geometry yet");
+ }
+
+ /// #2906: a new sketch has no degree of freedom (only the fixed origin), which is not
+ /// "Fully constrained"; the palette says there is no geometry until a curve is drawn.
+ #[test]
+ fn an_empty_sketch_is_not_reported_fully_constrained() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
+ h.settle();
+ let line = |h: &crate::scenario::Harness| {
+ let st = h.app.session.world_state();
+ let ss = h.app.session.active_sketch.and_then(|s| st.sketch(s)).unwrap();
+ dof_text(ss.report.dof, ss.report.ok(), has_geometry(&ss.sketch))
+ };
+ assert_eq!(line(&h), "No geometry yet");
+ h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[10,5]})).unwrap();
+ h.settle();
+ assert_ne!(line(&h), "No geometry yet", "a drawn rectangle is geometry");
}
}