From 862fd2780580032ba59a06f6a311485f922c240b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 2 Jun 2022 17:44:26 +0200 Subject: [PATCH 1/3] Add option to assign label to `Shape` --- crates/fj-kernel/src/shape/api.rs | 20 ++++++++++++++++++++ crates/fj-kernel/src/shape/stores.rs | 3 +++ crates/fj-operations/src/shape_processor.rs | 1 + 3 files changed, 24 insertions(+) diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index 03cc6f3b2..83f261ddc 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -51,6 +51,26 @@ impl Shape { } } + /// Assign a label to the shape + /// + /// The assigned label will be part of the `Debug` representation of + /// `Handle`s, making it way easier to understand which `Handle`s belong to + /// which `Shape`. + pub fn with_label(mut self, label: impl Into) -> Self { + let label = label.into(); + + self.stores.points.label = Some(label.clone()); + self.stores.curves.label = Some(label.clone()); + self.stores.surfaces.label = Some(label.clone()); + + self.stores.vertices.label = Some(label.clone()); + self.stores.edges.label = Some(label.clone()); + self.stores.cycles.label = Some(label.clone()); + self.stores.faces.label = Some(label); + + self + } + /// Override the minimum distance between distinct objects /// /// Used for vertex validation, to determine whether vertices are unique. diff --git a/crates/fj-kernel/src/shape/stores.rs b/crates/fj-kernel/src/shape/stores.rs index b46482c29..69c00c8aa 100644 --- a/crates/fj-kernel/src/shape/stores.rs +++ b/crates/fj-kernel/src/shape/stores.rs @@ -51,12 +51,14 @@ impl Stores { #[derive(Debug)] pub struct Store { + pub(super) label: Option, objects: Arc>>, } impl Store { pub fn new() -> Self { Self { + label: None, objects: Arc::new(RwLock::new(SlotMap::new())), } } @@ -109,6 +111,7 @@ impl Store { impl Clone for Store { fn clone(&self) -> Self { Self { + label: self.label.clone().map(|label| format!("{} (clone)", label)), objects: self.objects.clone(), } } diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index 8d26eb010..1335837ad 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -68,6 +68,7 @@ pub struct ProcessedShape { } /// A shape processing error +#[allow(clippy::large_enum_variant)] #[derive(Debug, thiserror::Error)] pub enum Error { /// Error converting to shape From 482db07623dd89757296a2a643f500749330ed60 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 3 Jun 2022 13:48:34 +0200 Subject: [PATCH 2/3] Fix error message --- crates/fj-operations/src/shape_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index 1335837ad..d3693da84 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -76,6 +76,6 @@ pub enum Error { ToShape(#[from] ValidationError), /// Model has zero size - #[error("Model has an zero size")] + #[error("Model has zero size")] Extent(#[from] InvalidTolerance), } From b10f2e4210f721a5ea9dc6a251b2f5cb4cdea11c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 2 Jun 2022 17:44:41 +0200 Subject: [PATCH 3/3] Print label in `Handle`'s `Debug` implementation --- crates/fj-kernel/src/shape/stores.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/shape/stores.rs b/crates/fj-kernel/src/shape/stores.rs index 69c00c8aa..f69a2f66f 100644 --- a/crates/fj-kernel/src/shape/stores.rs +++ b/crates/fj-kernel/src/shape/stores.rs @@ -214,7 +214,10 @@ where T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("Handle").field(&self.get()).finish() + f.debug_struct("Handle") + .field("shape", &self.store.label.as_deref().unwrap_or("unnamed")) + .field("object", &self.get()) + .finish() } }