Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added commands for object transforming (translate, rotate and scale) #441

Merged
merged 13 commits into from
Jan 8, 2025
Merged
19 changes: 19 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
length_unit::LengthUnit,
shared::{
Angle,
TransformBy,
CutType,
CameraMovement,
ExtrudedFaceInfo,
Expand Down Expand Up @@ -1196,6 +1197,24 @@
)]
pub struct GetNumObjects;

///Set the transform of an object.
#[derive(
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,

Check warning on line 1202 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1202

Added line #L1202 was not covered by tests
)]
pub struct SetObjectTransform
{
///Id of the object whose transform is to be set
pub object_id: Uuid,
///Optional translation value
#[serde(default)]
pub translate: Option<TransformBy<Point3d>>,
///Optional rotate value
#[serde(default)]
pub rotate: Option<TransformBy<Point3d>>,
///Optional scale value
#[serde(default)]
pub scale: Option<TransformBy<Point3d>>,
}
/// Make a new path by offsetting an object by a given distance.
/// The new path's ID will be the ID of this command.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
Expand Down
29 changes: 2 additions & 27 deletions modeling-cmds/src/format/fbx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,7 @@ use serde::{Deserialize, Serialize};
pub mod import {
use super::*;
/// Options for importing FBX.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("")]
#[serde(rename = "FbxImportOptions")]
pub struct Options {}
Expand Down Expand Up @@ -64,19 +51,7 @@ pub mod export {

/// Describes the storage format of an FBX file.
#[derive(
Default,
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[display(style = "snake_case")]
#[serde(rename = "FbxStorage", rename_all = "snake_case")]
Expand Down
16 changes: 1 addition & 15 deletions modeling-cmds/src/format/gltf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -8,20 +7,7 @@ pub mod import {
use super::*;

/// Options for importing glTF 2.0.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("")]
#[serde(rename = "GltfImportOptions")]
pub struct Options {}
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/obj.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@
use super::*;

/// Options for importing OBJ.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]

Check warning on line 12 in modeling-cmds/src/format/obj.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/format/obj.rs#L12

Added line #L12 was not covered by tests
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "ObjImportOptions")]
pub struct Options {
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/ply.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@
use super::*;

/// Options for importing PLY.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]

Check warning on line 12 in modeling-cmds/src/format/ply.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/format/ply.rs#L12

Added line #L12 was not covered by tests
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "PlyImportOptions")]
pub struct Options {
Expand Down
17 changes: 2 additions & 15 deletions modeling-cmds/src/format/sldprt.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
/// Import functionality.
pub mod import {

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Options for importing SolidWorks parts.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]

Check warning on line 9 in modeling-cmds/src/format/sldprt.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/format/sldprt.rs#L9

Added line #L9 was not covered by tests
#[display("split_closed_faces: {split_closed_faces}")]
#[serde(default, rename = "SldprtImportOptions")]
pub struct Options {
Expand Down
15 changes: 1 addition & 14 deletions modeling-cmds/src/format/step.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,19 +9,7 @@
use super::*;

/// Options for importing STEP format.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,
)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]

Check warning on line 12 in modeling-cmds/src/format/step.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/format/step.rs#L12

Added line #L12 was not covered by tests
#[display("split_closed_faces: {split_closed_faces}")]
#[serde(default, rename = "StepImportOptions")]
pub struct Options {
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/stl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@
use super::*;

/// Options for importing STL.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]

Check warning on line 12 in modeling-cmds/src/format/stl.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/format/stl.rs#L12

Added line #L12 was not covered by tests
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "StlImportOptions")]
pub struct Options {
Expand Down
5 changes: 5 additions & 0 deletions modeling-cmds/src/ok_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ define_ok_modeling_cmd_response_enum! {
pub entity_ids: Vec<Uuid>,
}

/// The response from the `SetObjectTransform` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct SetObjectTransform {
}

/// The response from the `DefaultCameraFocusOn` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct DefaultCameraFocusOn { }
Expand Down
12 changes: 12 additions & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,15 @@ mod tests {
assert!(c >= a);
}
}

/// How a property of an object should be transformed.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
pub struct TransformBy<Property> {
/// The scale, or rotation, or translation.
pub property: Property,
/// If true, overwrite the previous value with this.
/// If false, the previous value will be modified.
/// E.g. when translating, `set=true` will set a new location,
/// and `set=false` will translate the current location by the given X/Y/Z.
pub set: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not the same as relative? If it is then should we not call this relative for consistency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that, if the intention is for relative to be the default then maybe absolute is a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative, absolute, override. There are many ways of describing this

}
Loading