Skip to content

Commit cab2697

Browse files
authored
Add DXF as an exportable 2D format (#762)
There is no corresponding import 2D format yet. This is intended only as an export format from the engine. Conversions to/from DXF are not supported yet. `Export` has been split into two variants:` Export2d` and `Export3d`. For backward compatibility, `Export` is now a deprecated alias for `Export3d`. Similar changes have been introduced for `Import`.
1 parent 3a99f91 commit cab2697

File tree

6 files changed

+167
-53
lines changed

6 files changed

+167
-53
lines changed

modeling-cmds/src/convert_client_crate.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,34 @@ mod format {
125125
}
126126
}
127127

128-
impl From<InputFormat> for kt::InputFormat {
129-
fn from(format: InputFormat) -> kt::InputFormat {
128+
impl From<InputFormat3d> for kt::InputFormat {
129+
fn from(format: InputFormat3d) -> kt::InputFormat {
130130
match format {
131-
InputFormat::Fbx(fbx::import::Options {}) => kt::InputFormat::Fbx {},
132-
InputFormat::Gltf(gltf::import::Options {}) => kt::InputFormat::Gltf {},
133-
InputFormat::Obj(obj::import::Options { coords, units }) => kt::InputFormat::Obj {
131+
InputFormat3d::Fbx(fbx::import::Options {}) => kt::InputFormat::Fbx {},
132+
InputFormat3d::Gltf(gltf::import::Options {}) => kt::InputFormat::Gltf {},
133+
InputFormat3d::Obj(obj::import::Options { coords, units }) => kt::InputFormat::Obj {
134134
coords: coords.into(),
135135
units: units.into(),
136136
},
137-
InputFormat::Ply(ply::import::Options { coords, units }) => kt::InputFormat::Ply {
137+
InputFormat3d::Ply(ply::import::Options { coords, units }) => kt::InputFormat::Ply {
138138
coords: coords.into(),
139139
units: units.into(),
140140
},
141-
InputFormat::Sldprt(sldprt::import::Options { split_closed_faces }) => {
141+
InputFormat3d::Sldprt(sldprt::import::Options { split_closed_faces }) => {
142142
kt::InputFormat::Sldprt { split_closed_faces }
143143
}
144-
InputFormat::Step(step::import::Options { split_closed_faces }) => {
144+
InputFormat3d::Step(step::import::Options { split_closed_faces }) => {
145145
kt::InputFormat::Step { split_closed_faces }
146146
}
147-
InputFormat::Stl(stl::import::Options { coords, units }) => kt::InputFormat::Stl {
147+
InputFormat3d::Stl(stl::import::Options { coords, units }) => kt::InputFormat::Stl {
148148
coords: coords.into(),
149149
units: units.into(),
150150
},
151151
}
152152
}
153153
}
154154

155-
impl From<kt::InputFormat> for InputFormat {
155+
impl From<kt::InputFormat> for InputFormat3d {
156156
fn from(value: kt::InputFormat) -> Self {
157157
match value {
158158
kt::InputFormat::Fbx {} => Self::Fbx(Default::default()),

modeling-cmds/src/def_enum.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ define_modeling_cmd_enum! {
1717
use uuid::Uuid;
1818

1919
use crate::{
20-
format::OutputFormat,
20+
format::{OutputFormat2d, OutputFormat3d},
2121
id::ModelingCmdId,
2222
length_unit::LengthUnit,
2323
shared::{
@@ -326,15 +326,30 @@ define_modeling_cmd_enum! {
326326
pub magnitude: f32,
327327
}
328328

329+
/// Alias for backward compatibility.
330+
#[deprecated(since = "0.2.96", note = "use `Export3d` instead")]
331+
pub type Export = Export3d;
332+
333+
/// Export a sketch to a file.
334+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
335+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
336+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
337+
pub struct Export2d {
338+
/// IDs of the entities to be exported.
339+
pub entity_ids: Vec<Uuid>,
340+
/// The file format to export to.
341+
pub format: OutputFormat2d,
342+
}
343+
329344
/// Export the scene to a file.
330345
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
331346
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
332347
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
333-
pub struct Export {
348+
pub struct Export3d {
334349
/// IDs of the entities to be exported. If this is empty, then all entities are exported.
335350
pub entity_ids: Vec<Uuid>,
336351
/// The file format to export to.
337-
pub format: OutputFormat,
352+
pub format: OutputFormat3d,
338353
}
339354

340355
/// What is this entity's parent?
@@ -1254,7 +1269,7 @@ define_modeling_cmd_enum! {
12541269
/// Files to import.
12551270
pub files: Vec<super::ImportFile>,
12561271
/// Input file format.
1257-
pub format: crate::format::InputFormat,
1272+
pub format: crate::format::InputFormat3d,
12581273
}
12591274

12601275
/// Set the units of the scene.

modeling-cmds/src/format/dxf.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// Export sketches in DXF format.
2+
pub mod export {
3+
use parse_display::{Display, FromStr};
4+
use schemars::JsonSchema;
5+
use serde::{Deserialize, Serialize};
6+
7+
/// Export storage.
8+
#[derive(
9+
Clone, Copy, Debug, Default, Deserialize, Display, Eq, FromStr, Hash, JsonSchema, PartialEq, Serialize,
10+
)]
11+
#[display(style = "snake_case")]
12+
#[serde(rename = "DxfStorage", rename_all = "snake_case")]
13+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
14+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
15+
pub enum Storage {
16+
/// Plaintext encoding.
17+
///
18+
/// This is the default setting.
19+
#[default]
20+
Ascii,
21+
22+
/// Binary encoding.
23+
Binary,
24+
}
25+
26+
/// Options for exporting DXF format.
27+
#[derive(Clone, Debug, Default, Deserialize, Display, Eq, FromStr, Hash, JsonSchema, PartialEq, Serialize)]
28+
#[display("storage: {storage}")]
29+
#[serde(rename = "DxfExportOptions")]
30+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
31+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
32+
pub struct Options {
33+
/// Export storage.
34+
pub storage: Storage,
35+
}
36+
}

modeling-cmds/src/format/mod.rs

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use parse_display_derive::{Display, FromStr};
22
use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
44

5-
use crate::shared::{FileExportFormat, FileImportFormat};
5+
use crate::shared::{FileExportFormat, FileExportFormat2d, FileImportFormat};
66

7+
/// AutoCAD drawing interchange format.
8+
pub mod dxf;
79
/// Autodesk Filmbox (FBX) format.
810
pub mod fbx;
911
/// glTF 2.0.
@@ -23,13 +25,29 @@ pub mod stl;
2325
/// SolidWorks part (SLDPRT) format.
2426
pub mod sldprt;
2527

26-
/// Output format specifier.
28+
/// Output 2D format specifier.
2729
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2830
#[serde(tag = "type", rename_all = "snake_case")]
2931
#[display(style = "snake_case")]
3032
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
3133
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
32-
pub enum OutputFormat {
34+
pub enum OutputFormat2d {
35+
/// AutoCAD drawing interchange format.
36+
#[display("{}: {0}")]
37+
Dxf(dxf::export::Options),
38+
}
39+
40+
/// Alias for backward compatibility.
41+
#[deprecated(since = "0.2.96", note = "use `OutputFormat3d` instead")]
42+
pub type OutputFormat = OutputFormat3d;
43+
44+
/// Output 3D format specifier.
45+
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
46+
#[serde(tag = "type", rename_all = "snake_case")]
47+
#[display(style = "snake_case")]
48+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
49+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
50+
pub enum OutputFormat3d {
3351
/// Autodesk Filmbox (FBX) format.
3452
#[display("{}: {0}")]
3553
Fbx(fbx::export::Options),
@@ -53,13 +71,17 @@ pub enum OutputFormat {
5371
Stl(stl::export::Options),
5472
}
5573

74+
/// Alias for backward compatibility.
75+
#[deprecated(since = "0.2.96", note = "use `InputFormat3d` instead")]
76+
pub type InputFormat = InputFormat3d;
77+
5678
/// Input format specifier.
5779
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
5880
#[serde(tag = "type", rename_all = "snake_case")]
5981
#[display(style = "snake_case")]
6082
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
6183
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
62-
pub enum InputFormat {
84+
pub enum InputFormat3d {
6385
/// Autodesk Filmbox (FBX) format.
6486
#[display("{}: {0}")]
6587
Fbx(fbx::import::Options),
@@ -158,66 +180,82 @@ impl VirtualFile {
158180
}
159181
}
160182

161-
impl From<OutputFormat> for FileExportFormat {
162-
fn from(output_format: OutputFormat) -> Self {
183+
impl From<OutputFormat3d> for FileExportFormat {
184+
fn from(output_format: OutputFormat3d) -> Self {
163185
match output_format {
164-
OutputFormat::Fbx(_) => Self::Fbx,
165-
OutputFormat::Gltf(_) => Self::Gltf,
166-
OutputFormat::Obj(_) => Self::Obj,
167-
OutputFormat::Ply(_) => Self::Ply,
168-
OutputFormat::Step(_) => Self::Step,
169-
OutputFormat::Stl(_) => Self::Stl,
186+
OutputFormat3d::Fbx(_) => Self::Fbx,
187+
OutputFormat3d::Gltf(_) => Self::Gltf,
188+
OutputFormat3d::Obj(_) => Self::Obj,
189+
OutputFormat3d::Ply(_) => Self::Ply,
190+
OutputFormat3d::Step(_) => Self::Step,
191+
OutputFormat3d::Stl(_) => Self::Stl,
192+
}
193+
}
194+
}
195+
196+
impl From<OutputFormat2d> for FileExportFormat2d {
197+
fn from(output_format: OutputFormat2d) -> Self {
198+
match output_format {
199+
OutputFormat2d::Dxf(_) => Self::Dxf,
200+
}
201+
}
202+
}
203+
204+
impl From<FileExportFormat2d> for OutputFormat2d {
205+
fn from(export_format: FileExportFormat2d) -> Self {
206+
match export_format {
207+
FileExportFormat2d::Dxf => OutputFormat2d::Dxf(Default::default()),
170208
}
171209
}
172210
}
173211

174-
impl From<FileExportFormat> for OutputFormat {
212+
impl From<FileExportFormat> for OutputFormat3d {
175213
fn from(export_format: FileExportFormat) -> Self {
176214
match export_format {
177-
FileExportFormat::Fbx => OutputFormat::Fbx(Default::default()),
178-
FileExportFormat::Glb => OutputFormat::Gltf(gltf::export::Options {
215+
FileExportFormat::Fbx => OutputFormat3d::Fbx(Default::default()),
216+
FileExportFormat::Glb => OutputFormat3d::Gltf(gltf::export::Options {
179217
storage: gltf::export::Storage::Binary,
180218
..Default::default()
181219
}),
182-
FileExportFormat::Gltf => OutputFormat::Gltf(gltf::export::Options {
220+
FileExportFormat::Gltf => OutputFormat3d::Gltf(gltf::export::Options {
183221
storage: gltf::export::Storage::Embedded,
184222
presentation: gltf::export::Presentation::Pretty,
185223
}),
186-
FileExportFormat::Obj => OutputFormat::Obj(Default::default()),
187-
FileExportFormat::Ply => OutputFormat::Ply(Default::default()),
188-
FileExportFormat::Step => OutputFormat::Step(Default::default()),
189-
FileExportFormat::Stl => OutputFormat::Stl(stl::export::Options {
224+
FileExportFormat::Obj => OutputFormat3d::Obj(Default::default()),
225+
FileExportFormat::Ply => OutputFormat3d::Ply(Default::default()),
226+
FileExportFormat::Step => OutputFormat3d::Step(Default::default()),
227+
FileExportFormat::Stl => OutputFormat3d::Stl(stl::export::Options {
190228
storage: stl::export::Storage::Ascii,
191229
..Default::default()
192230
}),
193231
}
194232
}
195233
}
196234

197-
impl From<InputFormat> for FileImportFormat {
198-
fn from(input_format: InputFormat) -> Self {
235+
impl From<InputFormat3d> for FileImportFormat {
236+
fn from(input_format: InputFormat3d) -> Self {
199237
match input_format {
200-
InputFormat::Fbx(_) => Self::Fbx,
201-
InputFormat::Gltf(_) => Self::Gltf,
202-
InputFormat::Obj(_) => Self::Obj,
203-
InputFormat::Ply(_) => Self::Ply,
204-
InputFormat::Sldprt(_) => Self::Sldprt,
205-
InputFormat::Step(_) => Self::Step,
206-
InputFormat::Stl(_) => Self::Stl,
238+
InputFormat3d::Fbx(_) => Self::Fbx,
239+
InputFormat3d::Gltf(_) => Self::Gltf,
240+
InputFormat3d::Obj(_) => Self::Obj,
241+
InputFormat3d::Ply(_) => Self::Ply,
242+
InputFormat3d::Sldprt(_) => Self::Sldprt,
243+
InputFormat3d::Step(_) => Self::Step,
244+
InputFormat3d::Stl(_) => Self::Stl,
207245
}
208246
}
209247
}
210248

211-
impl From<FileImportFormat> for InputFormat {
249+
impl From<FileImportFormat> for InputFormat3d {
212250
fn from(import_format: FileImportFormat) -> Self {
213251
match import_format {
214-
FileImportFormat::Fbx => InputFormat::Fbx(Default::default()),
215-
FileImportFormat::Gltf => InputFormat::Gltf(Default::default()),
216-
FileImportFormat::Obj => InputFormat::Obj(Default::default()),
217-
FileImportFormat::Ply => InputFormat::Ply(Default::default()),
218-
FileImportFormat::Sldprt => InputFormat::Sldprt(Default::default()),
219-
FileImportFormat::Step => InputFormat::Step(Default::default()),
220-
FileImportFormat::Stl => InputFormat::Stl(Default::default()),
252+
FileImportFormat::Fbx => InputFormat3d::Fbx(Default::default()),
253+
FileImportFormat::Gltf => InputFormat3d::Gltf(Default::default()),
254+
FileImportFormat::Obj => InputFormat3d::Obj(Default::default()),
255+
FileImportFormat::Ply => InputFormat3d::Ply(Default::default()),
256+
FileImportFormat::Sldprt => InputFormat3d::Sldprt(Default::default()),
257+
FileImportFormat::Step => InputFormat3d::Step(Default::default()),
258+
FileImportFormat::Stl => InputFormat3d::Stl(Default::default()),
221259
}
222260
}
223261
}

modeling-cmds/src/ok_response.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,24 @@ define_ok_modeling_cmd_response_enum! {
293293
pub struct SelectClear {
294294
}
295295

296-
/// The response from the `Export` endpoint.
296+
/// Alias for backward compatibility.
297+
#[deprecated(since = "0.2.96", note = "use `Export3d` instead")]
298+
pub type Export = Export3d;
299+
300+
/// The response from the `Export2d` endpoint.
297301
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
298-
pub struct Export {
302+
pub struct Export2d {
299303
/// The files that were exported.
300304
pub files: Vec<ExportFile>,
301305
}
306+
307+
/// The response from the `Export3d` endpoint.
308+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
309+
pub struct Export3d {
310+
/// The files that were exported.
311+
pub files: Vec<ExportFile>,
312+
}
313+
302314
/// The response from the `SelectWithPoint` command.
303315
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
304316
pub struct SelectWithPoint {

modeling-cmds/src/shared.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,19 @@ pub enum FileExportFormat {
622622
Stl,
623623
}
624624

625+
/// The valid types of 2D output file formats.
626+
#[derive(
627+
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
628+
)]
629+
#[serde(rename_all = "lowercase")]
630+
#[display(style = "lowercase")]
631+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
632+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
633+
pub enum FileExportFormat2d {
634+
/// AutoCAD drawing interchange format.
635+
Dxf,
636+
}
637+
625638
/// The valid types of source file formats.
626639
#[derive(
627640
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,

0 commit comments

Comments
 (0)