1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// SPDX-License-Identifier: Apache-2.0
//! Typed string identifiers for the IR graph.
//!
//! Each identity kind wraps a string in a distinct newtype, preventing references
//! between incompatible entity arenas and state-local member sets. Entity IDs
//! must be stable and globally unique within a document. State-local IDs need
//! only be unique within their owning state.
#[cfg(feature = "schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
macro_rules! id_type {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(transparent)]
pub struct $name(pub String);
impl Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
crate::schema::serialize_reference_id(&self.0, serializer)
}
}
impl $name {
/// Borrow the underlying id string.
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl<S: Into<String>> From<S> for $name {
fn from(value: S) -> Self {
$name(value.into())
}
}
};
}
macro_rules! local_id_type {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(transparent)]
pub struct $name(pub String);
impl $name {
/// Borrow the underlying id string.
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl<S: Into<String>> From<S> for $name {
fn from(value: S) -> Self {
$name(value.into())
}
}
};
}
id_type!(
/// Identifies a [`crate::topology::Body`].
BodyId
);
id_type!(
/// Identifies one feature-input topology state.
FeatureInputTopologyId
);
id_type!(
/// Identifies one feature-result topology state.
FeatureResultTopologyId
);
local_id_type!(
/// Identifies a body within one feature-input topology state.
HistoricalBodyId
);
local_id_type!(
/// Identifies a face within one feature-input topology state.
HistoricalFaceId
);
local_id_type!(
/// Identifies an edge within one feature-input topology state.
HistoricalEdgeId
);
id_type!(
/// Identifies a [`crate::topology::Region`].
RegionId
);
id_type!(
/// Identifies a [`crate::topology::Shell`].
ShellId
);
id_type!(
/// Identifies a [`crate::topology::Face`].
FaceId
);
id_type!(
/// Identifies a [`crate::topology::Loop`].
LoopId
);
id_type!(
/// Identifies a [`crate::topology::Coedge`].
CoedgeId
);
id_type!(
/// Identifies a [`crate::topology::Edge`].
EdgeId
);
id_type!(
/// Identifies a [`crate::topology::Vertex`].
VertexId
);
id_type!(
/// Identifies a [`crate::geometry::Surface`] carrier.
SurfaceId
);
id_type!(
/// Identifies a [`crate::geometry::Curve`] carrier.
CurveId
);
id_type!(
/// Identifies a [`crate::geometry::Pcurve`] carrier.
PcurveId
);
id_type!(
/// Identifies a [`crate::geometry::ProceduralSurface`] construction.
ProceduralSurfaceId
);
id_type!(
/// Identifies a [`crate::geometry::ProceduralCurve`] construction.
ProceduralCurveId
);
id_type!(
/// Identifies a [`crate::subd::SubdSurface`] carrier.
SubdId
);
id_type!(
/// Identifies a [`crate::topology::Point`] carrier (a vertex position).
PointId
);
id_type!(
/// Identifies a passthrough [`crate::unknown::UnknownRecord`].
UnknownId
);
id_type!(
/// Identifies a decoded [`crate::appearance::Appearance`] asset.
AppearanceId
);
id_type!(
/// Identifies a linked [`crate::attributes::SourceAttribute`] record.
AttributeId
);
id_type!(
/// Identifies a canonical [`crate::products::ProductDefinition`].
ProductDefinitionId
);
id_type!(
/// Identifies a placed [`crate::products::Occurrence`].
OccurrenceId
);
id_type!(
/// Identifies a document-level [`crate::pmi::PmiAnnotation`].
PmiId
);
id_type!(
/// Identifies a [`crate::presentation::PresentationLayer`].
LayerId
);