1use cadmpeg_core::dialect::DialectId;
9use cadmpeg_core::target::TargetDescriptor;
10
11use crate::dialect::{
12 STEP_AP203_E1, STEP_AP203_E2, STEP_AP214, STEP_AP242_E1, STEP_AP242_E2, STEP_AP242_E3,
13};
14
15#[derive(Debug, Clone)]
22pub struct StepWriteOptions {
23 pub product_name: String,
30 pub author: String,
32 pub organization: String,
34 pub timestamp: Option<String>,
38 pub originating_system: String,
40}
41
42impl Default for StepWriteOptions {
43 fn default() -> Self {
44 StepWriteOptions {
45 product_name: "cadmpeg_model".to_string(),
46 author: String::new(),
47 organization: String::new(),
48 timestamp: None,
49 originating_system: "cadmpeg".to_string(),
50 }
51 }
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
59pub enum StepSchema {
60 Ap203Edition1,
62 Ap203Edition2,
64 Ap214,
66 Ap242Edition1,
68 Ap242Edition2,
70 Ap242Edition3,
72}
73
74macro_rules! writer_vocabulary {
75 ($(#[$all_meta:meta])* $count:literal; $($variant:ident),+ $(,)?) => {
76 $(#[$all_meta])*
77 pub(crate) const ALL: [Self; $count] = [$(Self::$variant),+];
78 pub(crate) const TARGETS: &'static [TargetDescriptor] = &[
80 $(Self::$variant.descriptor()),+
81 ];
82 pub(crate) const fn from_target_index(index: usize) -> Option<Self> {
84 if index < Self::ALL.len() {
85 Some(Self::ALL[index])
86 } else {
87 None
88 }
89 }
90 };
91}
92
93impl StepSchema {
94 writer_vocabulary!(
95 6;
101 Ap203Edition1,
102 Ap203Edition2,
103 Ap214,
104 Ap242Edition1,
105 Ap242Edition2,
106 Ap242Edition3,
107 );
108
109 pub const fn file_schema(self) -> &'static str {
111 match self {
112 Self::Ap203Edition1 => "CONFIG_CONTROL_DESIGN",
113 Self::Ap203Edition2 => "AP203_CONFIGURATION_CONTROLLED_3D_DESIGN_OF_MECHANICAL_PARTS_AND_ASSEMBLIES_MIM_LF { 1 0 10303 403 2 1 2 }",
114 Self::Ap214 => "AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }",
115 Self::Ap242Edition1 => "AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF { 1 0 10303 442 1 1 4 }",
116 Self::Ap242Edition2 => "AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF { 1 0 10303 442 3 1 4 }",
117 Self::Ap242Edition3 => "AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF { 1 0 10303 442 4 1 4 }",
118 }
119 }
120
121 pub(crate) const fn id(self) -> DialectId {
123 match self {
124 Self::Ap203Edition1 => STEP_AP203_E1,
125 Self::Ap203Edition2 => STEP_AP203_E2,
126 Self::Ap214 => STEP_AP214,
127 Self::Ap242Edition1 => STEP_AP242_E1,
128 Self::Ap242Edition2 => STEP_AP242_E2,
129 Self::Ap242Edition3 => STEP_AP242_E3,
130 }
131 }
132
133 #[must_use]
135 pub const fn descriptor(self) -> TargetDescriptor {
136 let aliases = match self {
137 Self::Ap203Edition1 => &["ap203e1"].as_slice(),
138 Self::Ap203Edition2 => &["ap203e2"].as_slice(),
139 Self::Ap214 => &["ap214"].as_slice(),
140 Self::Ap242Edition1 => &["ap242e1"].as_slice(),
141 Self::Ap242Edition2 => &["ap242e2"].as_slice(),
142 Self::Ap242Edition3 => &["ap242e3"].as_slice(),
143 };
144 TargetDescriptor {
145 id: self.id(),
146 aliases,
147 }
148 }
149
150 pub(crate) const fn supports_tessellation(self) -> bool {
151 matches!(
152 self,
153 Self::Ap242Edition1 | Self::Ap242Edition2 | Self::Ap242Edition3
154 )
155 }
156
157 pub(crate) const fn supports_semantic_pmi(self) -> bool {
158 self.supports_tessellation()
159 }
160
161 pub(crate) const fn supports_visibility(self) -> bool {
162 !matches!(self, Self::Ap203Edition1)
163 }
164
165 pub(crate) const fn application_protocol(self) -> (&'static str, &'static str, i32) {
166 match self {
167 Self::Ap203Edition1 => (
168 "configuration controlled 3d designs of mechanical parts and assemblies",
169 "config_control_design",
170 1994,
171 ),
172 Self::Ap203Edition2 => (
173 "configuration controlled 3d designs of mechanical parts and assemblies",
174 "ap203_configuration_controlled_3d_design_of_mechanical_parts_and_assemblies",
175 2011,
176 ),
177 Self::Ap214 => ("automotive design", "automotive_design", 2000),
178 Self::Ap242Edition1 => (
179 "managed model based 3d engineering",
180 "ap242_managed_model_based_3d_engineering",
181 2014,
182 ),
183 Self::Ap242Edition2 => (
184 "managed model based 3d engineering",
185 "ap242_managed_model_based_3d_engineering",
186 2020,
187 ),
188 Self::Ap242Edition3 => (
189 "managed model based 3d engineering",
190 "ap242_managed_model_based_3d_engineering",
191 2022,
192 ),
193 }
194 }
195}