Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
  • Loading branch information
luca-della-vedova committed Sep 4, 2023
1 parent 25c74fe commit 1fec468
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
19 changes: 12 additions & 7 deletions rmf_site_editor/src/interaction/select_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2295,12 +2295,15 @@ pub fn handle_select_anchor_3d_mode(
{
let pose = compute_parent_inverse_pose(&cursor_tf, &transforms, parent);
let element = find_mesh_element(&params, &cursor_tf, parent);
params.commands.entity(id).insert(MeshConstraint {
entity: parent,
element: element,
relative_pose: pose,
})
.insert(FrameMarker);
params
.commands
.entity(id)
.insert(MeshConstraint {
entity: parent,
element: element,
relative_pose: pose,
})
.insert(FrameMarker);
// Add constraint dependent
if let Ok(mut parent_deps) =
params.constraint_dependents.get_mut(parent)
Expand Down Expand Up @@ -2328,7 +2331,9 @@ pub fn handle_select_anchor_3d_mode(
}
PlaceableObject::Model(ref a) => {
let mut model = a.clone();
let parent = request.parent.unwrap_or(workspace.root.expect("No workspace"));
let parent = request
.parent
.unwrap_or(workspace.root.expect("No workspace"));
model.pose = compute_parent_inverse_pose(&cursor_tf, &transforms, parent);
params.commands.entity(id).insert(model);
parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl<'a> InspectMeshPrimitive<'a> {
ui.label(size[2].to_string());
});
}
MeshPrimitive::Cylinder { radius, length } | MeshPrimitive::Capsule { radius, length }=> {
MeshPrimitive::Cylinder { radius, length }
| MeshPrimitive::Capsule { radius, length } => {
ui.horizontal(|ui| {
ui.label("Radius:");
ui.label(radius.to_string());
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/workcell/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*
*/

use crate::{ExportFormat, SaveWorkspace, SaveWorkspaceDestination};
use bevy::prelude::*;
use bevy_egui::EguiContext;
use crate::{SaveWorkspace, SaveWorkspaceDestination, ExportFormat};

pub fn handle_workcell_keyboard_input(
keyboard_input: Res<Input<KeyCode>>,
Expand Down
23 changes: 18 additions & 5 deletions rmf_site_editor/src/workcell/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
*
*/

use crate::site::{Dependents, ModelTrashcan, Pending};
use bevy::prelude::*;
use crate::site::{Dependents, Pending, ModelTrashcan};
use rmf_site_format::{MeshPrimitive, ModelMarker, NameInSite, NameInWorkcell, Pose, WorkcellProperties};
use rmf_site_format::{
MeshPrimitive, ModelMarker, NameInSite, NameInWorkcell, Pose, WorkcellProperties,
};

/// SDFs loaded through site editor wrap all the collisions and visuals into a single Model entity.
/// This doesn't quite work for URDF / workcells since we need to export and edit single visuals
/// and collisions, hence we process the loaded models to flatten them here
pub fn flatten_loaded_models_hierarchy(
mut commands: Commands,
new_models: Query<(Entity, &Parent), (Without<Pending>, Or<(Added<ModelMarker>, Added<MeshPrimitive>)>)>,
new_models: Query<
(Entity, &Parent),
(
Without<Pending>,
Or<(Added<ModelMarker>, Added<MeshPrimitive>)>,
),
>,
all_model_parents: Query<(Entity, &Parent), (With<ModelMarker>, Without<Pending>)>,
mut poses: Query<&mut Pose>,
mut dependents: Query<&mut Dependents>,
Expand All @@ -33,7 +41,9 @@ pub fn flatten_loaded_models_hierarchy(
) {
for (e, parent) in &new_models {
// Traverse up the hierarchy to find the first model parent and reassign it
if let Some((parent_entity, model_parent)) = AncestorIter::new(&parents, **parent).find_map(|e| all_model_parents.get(e).ok()) {
if let Some((parent_entity, model_parent)) =
AncestorIter::new(&parents, **parent).find_map(|e| all_model_parents.get(e).ok())
{
let Ok(parent_pose) = poses.get(parent_entity).cloned() else {
continue;
};
Expand Down Expand Up @@ -61,7 +71,10 @@ pub fn replace_name_in_site_components(
) {
for (e, name) in &new_names {
if AncestorIter::new(&parents, e).any(|p| workcells.get(p).is_ok()) {
commands.entity(e).insert(NameInWorkcell(name.0.clone())).remove::<NameInSite>();
commands
.entity(e)
.insert(NameInWorkcell(name.0.clone()))
.remove::<NameInSite>();
}
}
}
4 changes: 3 additions & 1 deletion rmf_site_editor/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ fn handle_workspace_data(
focus: true,
default_file: file,
});
if let Err(err) = interaction_state.overwrite_set(InteractionState::Enable) {
if let Err(err) =
interaction_state.overwrite_set(InteractionState::Enable)
{
error!("Failed to turn on interaction: {err}");
}
}
Expand Down
8 changes: 4 additions & 4 deletions rmf_site_format/src/workcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl Recall for RecallMeshPrimitive {

impl RecallMeshPrimitive {
pub fn assume_box(&self, current: &MeshPrimitive) -> MeshPrimitive {
if matches!(current, MeshPrimitive::Box{..}) {
if matches!(current, MeshPrimitive::Box { .. }) {
current.clone()
} else {
MeshPrimitive::Box {
Expand All @@ -296,7 +296,7 @@ impl RecallMeshPrimitive {
}

pub fn assume_cylinder(&self, current: &MeshPrimitive) -> MeshPrimitive {
if matches!(current, MeshPrimitive::Cylinder{..}) {
if matches!(current, MeshPrimitive::Cylinder { .. }) {
current.clone()
} else {
MeshPrimitive::Cylinder {
Expand All @@ -307,7 +307,7 @@ impl RecallMeshPrimitive {
}

pub fn assume_capsule(&self, current: &MeshPrimitive) -> MeshPrimitive {
if matches!(current, MeshPrimitive::Capsule{..}) {
if matches!(current, MeshPrimitive::Capsule { .. }) {
current.clone()
} else {
MeshPrimitive::Capsule {
Expand All @@ -318,7 +318,7 @@ impl RecallMeshPrimitive {
}

pub fn assume_sphere(&self, current: &MeshPrimitive) -> MeshPrimitive {
if matches!(current, MeshPrimitive::Sphere{..}) {
if matches!(current, MeshPrimitive::Sphere { .. }) {
current.clone()
} else {
MeshPrimitive::Sphere {
Expand Down

0 comments on commit 1fec468

Please sign in to comment.