diff --git a/rmf_site_editor/src/interaction/camera_controls.rs b/rmf_site_editor/src/interaction/camera_controls.rs index 2f27ecdc..bf13cfc8 100644 --- a/rmf_site_editor/src/interaction/camera_controls.rs +++ b/rmf_site_editor/src/interaction/camera_controls.rs @@ -365,7 +365,12 @@ fn camera_controls( mut change_mode: EventReader, ) { if let Some(mode) = change_mode.iter().last() { - controls.use_mode(mode.0, &mut bevy_cameras, &mut visibility, headlight_toggle.0); + controls.use_mode( + mode.0, + &mut bevy_cameras, + &mut visibility, + headlight_toggle.0, + ); } if headlight_toggle.is_changed() { diff --git a/rmf_site_editor/src/interaction/highlight.rs b/rmf_site_editor/src/interaction/highlight.rs index 8a640895..e9c66596 100644 --- a/rmf_site_editor/src/interaction/highlight.rs +++ b/rmf_site_editor/src/interaction/highlight.rs @@ -15,10 +15,7 @@ * */ -use crate::{ - interaction::*, - site::DrawingMarker, -}; +use crate::{interaction::*, site::DrawingMarker}; use bevy::prelude::*; #[derive(Component)] @@ -46,15 +43,19 @@ pub fn add_highlight_visualization( new_drawings: Query>, ) { for e in &new_drawings { - commands - .entity(e) - .insert(Highlight::for_drawing()); + commands.entity(e).insert(Highlight::for_drawing()); } } pub fn update_highlight_visualization( highlightable: Query< - (&Hovered, &Selected, &Handle, &Highlight, Option<&SuppressHighlight>), + ( + &Hovered, + &Selected, + &Handle, + &Highlight, + Option<&SuppressHighlight>, + ), Or<( Changed, Changed, diff --git a/rmf_site_editor/src/interaction/outline.rs b/rmf_site_editor/src/interaction/outline.rs index 727776c1..d404b8a4 100644 --- a/rmf_site_editor/src/interaction/outline.rs +++ b/rmf_site_editor/src/interaction/outline.rs @@ -15,10 +15,7 @@ * */ -use crate::{ - site::DrawingMarker, - interaction::*, -}; +use crate::{interaction::*, site::DrawingMarker}; use bevy::render::view::RenderLayers; use bevy_mod_outline::{OutlineBundle, OutlineRenderLayers, OutlineVolume, SetOutlineDepth}; use rmf_site_format::{ @@ -143,8 +140,18 @@ pub fn add_outline_visualization( pub fn update_outline_visualization( mut commands: Commands, outlinable: Query< - (Entity, &Hovered, &Selected, &OutlineVisualization, Option<&SuppressOutline>), - Or<(Changed, Changed, Changed)>, + ( + Entity, + &Hovered, + &Selected, + &OutlineVisualization, + Option<&SuppressOutline>, + ), + Or<( + Changed, + Changed, + Changed, + )>, >, descendants: Query<(Option<&Children>, Option<&ComputedVisualCue>)>, ) { diff --git a/rmf_site_editor/src/interaction/popup.rs b/rmf_site_editor/src/interaction/popup.rs index b0a2559e..914af825 100644 --- a/rmf_site_editor/src/interaction/popup.rs +++ b/rmf_site_editor/src/interaction/popup.rs @@ -15,10 +15,7 @@ * */ -use crate::{ - interaction::*, - site::*, -}; +use crate::{interaction::*, site::*}; #[derive(Component, Clone, Copy)] pub struct Popup { @@ -29,10 +26,7 @@ pub struct Popup { pub fn add_popups( mut commands: Commands, - new_poppers: Query, - Added, - )>>, + new_poppers: Query, Added)>>, ) { for e in &new_poppers { commands.entity(e).insert(Popup { diff --git a/rmf_site_editor/src/interaction/select_anchor.rs b/rmf_site_editor/src/interaction/select_anchor.rs index 9dc8fdc5..9b50881b 100644 --- a/rmf_site_editor/src/interaction/select_anchor.rs +++ b/rmf_site_editor/src/interaction/select_anchor.rs @@ -18,17 +18,17 @@ use crate::{ interaction::*, site::{ - drawing_editor::CurrentEditDrawing, - Anchor, AnchorBundle, Category, Dependents, DrawingMarker, Original, PathBehavior, Pending, + drawing_editor::CurrentEditDrawing, Anchor, AnchorBundle, Category, Dependents, + DrawingMarker, Original, PathBehavior, Pending, }, CurrentWorkspace, }; use bevy::{ecs::system::SystemParam, prelude::*}; use rmf_site_format::{ Constraint, ConstraintDependents, Door, Edge, Fiducial, Floor, Lane, LiftProperties, Location, - Measurement, MeshConstraint, MeshElement, Model, ModelMarker, NameInWorkcell, Path, - PixelsPerMeter, Point, Pose, Side, NameOfSite, Wall, WorkcellCollisionMarker, - WorkcellModel, WorkcellVisualMarker, + Measurement, MeshConstraint, MeshElement, Model, ModelMarker, NameInWorkcell, NameOfSite, Path, + PixelsPerMeter, Point, Pose, Side, Wall, WorkcellCollisionMarker, WorkcellModel, + WorkcellVisualMarker, }; use std::collections::HashSet; use std::sync::Arc; @@ -2038,8 +2038,14 @@ pub fn handle_select_anchor_mode( new_anchor } Scope::Drawing => { - let drawing_entity = current_drawing.target().expect("No drawing while spawning drawing anchor").drawing; - let (parent, ppm) = params.drawings.get(drawing_entity).expect("Entity being edited is not a drawing"); + let drawing_entity = current_drawing + .target() + .expect("No drawing while spawning drawing anchor") + .drawing; + let (parent, ppm) = params + .drawings + .get(drawing_entity) + .expect("Entity being edited is not a drawing"); // We also need to have a transform such that the anchor will spawn in the // right spot let pose = compute_parent_inverse_pose(&tf, &transforms, parent); @@ -2103,9 +2109,7 @@ pub fn handle_select_anchor_mode( .filter(|s| anchors.contains(*s)) { request = match request.next(AnchorSelection::existing(new_selection), &mut params) { - Some(next_mode) => { - next_mode - } + Some(next_mode) => next_mode, None => { params.cleanup(); *mode = InteractionMode::Inspect; diff --git a/rmf_site_editor/src/keyboard.rs b/rmf_site_editor/src/keyboard.rs index 65b1d1aa..f8773463 100644 --- a/rmf_site_editor/src/keyboard.rs +++ b/rmf_site_editor/src/keyboard.rs @@ -18,7 +18,7 @@ use crate::{ interaction::{ camera_controls::{CameraControls, HeadlightToggle}, - ChangeMode, InteractionMode, Selection, ChangeProjectionMode, + ChangeMode, ChangeProjectionMode, InteractionMode, Selection, }, site::{AlignSiteDrawings, CurrentLevel, Delete}, CreateNewWorkspace, CurrentWorkspace, LoadWorkspace, SaveWorkspace, diff --git a/rmf_site_editor/src/occupancy.rs b/rmf_site_editor/src/occupancy.rs index b54840f3..877fe3c0 100644 --- a/rmf_site_editor/src/occupancy.rs +++ b/rmf_site_editor/src/occupancy.rs @@ -18,7 +18,7 @@ use crate::{ interaction::ComputedVisualCue, shapes::*, - site::{Category, LevelElevation, SiteAssets, NameOfSite, LANE_LAYER_START}, + site::{Category, LevelElevation, NameOfSite, SiteAssets, LANE_LAYER_START}, }; use bevy::{ math::{swizzles::*, Affine3A, Mat3A, Vec2, Vec3A}, diff --git a/rmf_site_editor/src/site/assets.rs b/rmf_site_editor/src/site/assets.rs index f2a06303..3ec8078d 100644 --- a/rmf_site_editor/src/site/assets.rs +++ b/rmf_site_editor/src/site/assets.rs @@ -193,20 +193,18 @@ impl FromWorld for SiteAssets { ); let location_mesh = meshes.add( Mesh::from( - make_icon_halo(1.1 * LANE_WIDTH / 2.0, 0.01, 6) - .transform_by(Affine3A::from_translation( - (0.00125 + LOCATION_LAYER_HEIGHT) * Vec3::Z) - ), + make_icon_halo(1.1 * LANE_WIDTH / 2.0, 0.01, 6).transform_by( + Affine3A::from_translation((0.00125 + LOCATION_LAYER_HEIGHT) * Vec3::Z), + ), ) .with_generated_outline_normals() .unwrap(), ); let fiducial_mesh = meshes.add( Mesh::from( - make_icon_halo(1.1 * LANE_WIDTH / 2.0, 0.01, 4) - .transform_by(Affine3A::from_translation( - (0.00125 + LOCATION_LAYER_HEIGHT) * Vec3::Z) - ), + make_icon_halo(1.1 * LANE_WIDTH / 2.0, 0.01, 4).transform_by( + Affine3A::from_translation((0.00125 + LOCATION_LAYER_HEIGHT) * Vec3::Z), + ), ) .with_generated_outline_normals() .unwrap(), diff --git a/rmf_site_editor/src/site/deletion.rs b/rmf_site_editor/src/site/deletion.rs index 52c5a223..35436066 100644 --- a/rmf_site_editor/src/site/deletion.rs +++ b/rmf_site_editor/src/site/deletion.rs @@ -19,8 +19,8 @@ use crate::{ interaction::{Select, Selection}, log::Log, site::{ - Category, CurrentLevel, Dependents, LevelProperties, NameInSite, - LevelElevation, SiteUpdateStage, + Category, CurrentLevel, Dependents, LevelElevation, LevelProperties, NameInSite, + SiteUpdateStage, }, }; use bevy::{ecs::system::SystemParam, prelude::*}; diff --git a/rmf_site_editor/src/site/drawing.rs b/rmf_site_editor/src/site/drawing.rs index d9853c61..2d1f0711 100644 --- a/rmf_site_editor/src/site/drawing.rs +++ b/rmf_site_editor/src/site/drawing.rs @@ -19,17 +19,14 @@ use crate::{ interaction::Selectable, shapes::make_flat_rect_mesh, site::{ - get_current_workspace_path, Anchor, DefaultFile, FiducialMarker, - GlobalDrawingVisibility, LayerVisibility, MeasurementMarker, - MeasurementSegment, RecencyRank, + get_current_workspace_path, Anchor, DefaultFile, FiducialMarker, GlobalDrawingVisibility, + LayerVisibility, MeasurementMarker, MeasurementSegment, RecencyRank, DEFAULT_MEASUREMENT_OFFSET, FLOOR_LAYER_START, }, CurrentWorkspace, }; use bevy::{asset::LoadState, math::Affine3A, prelude::*}; -use rmf_site_format::{ - AssetSource, Category, DrawingProperties, NameInSite, PixelsPerMeter, Pose, -}; +use rmf_site_format::{AssetSource, Category, DrawingProperties, NameInSite, PixelsPerMeter, Pose}; use std::path::PathBuf; #[derive(Bundle, Debug, Clone)] @@ -62,7 +59,6 @@ pub struct DrawingMarker; pub const DRAWING_LAYER_START: f32 = 0.0; - #[derive(Debug, Clone, Copy, Component)] pub struct DrawingSegments { leaf: Entity, @@ -80,10 +76,7 @@ fn drawing_layer_height(rank: Option<&RecencyRank>) -> f32 { pub fn add_drawing_visuals( mut commands: Commands, - changed_drawings: Query< - (Entity, &AssetSource), - (With, Changed), - >, + changed_drawings: Query<(Entity, &AssetSource), (With, Changed)>, asset_server: Res, current_workspace: Res, site_files: Query<&DefaultFile>, @@ -110,9 +103,7 @@ pub fn add_drawing_visuals( _ => source.clone(), }; let texture_handle: Handle = asset_server.load(&String::from(&asset_source)); - commands - .entity(e) - .insert(LoadingDrawing(texture_handle)); + commands.entity(e).insert(LoadingDrawing(texture_handle)); } } @@ -136,7 +127,9 @@ pub fn handle_loaded_drawing( segments: Query<&DrawingSegments>, default_drawing_vis: Query<&GlobalDrawingVisibility>, ) { - for (entity, source, pose, pixels_per_meter, handle, vis, parent, rank) in loading_drawings.iter() { + for (entity, source, pose, pixels_per_meter, handle, vis, parent, rank) in + loading_drawings.iter() + { match asset_server.get_load_state(&handle.0) { LoadState::Loaded => { let img = assets.get(&handle.0).unwrap(); @@ -148,7 +141,9 @@ pub fn handle_loaded_drawing( Affine3A::from_translation(Vec3::new(width / 2.0, -height / 2.0, 0.0)), ); let mesh = mesh_assets.add(mesh.into()); - let default = parent.map(|p| default_drawing_vis.get(p.get()).ok()).flatten(); + let default = parent + .map(|p| default_drawing_vis.get(p.get()).ok()) + .flatten(); let (alpha, alpha_mode) = drawing_alpha(vis, rank, default); let material = materials.add(StandardMaterial { base_color_texture: Some(handle.0.clone()), @@ -182,7 +177,8 @@ pub fn handle_loaded_drawing( ..Default::default() }) .insert(Selectable::new(entity)); - commands.entity(entity) + commands + .entity(entity) // Put a handle for the material into the main entity // so that we can modify it during interactions. .insert(material) @@ -239,7 +235,10 @@ pub fn update_drawing_pixels_per_meter( pub fn update_drawing_children_to_pixel_coordinates( mut commands: Commands, - changed_drawings: Query<(&PixelsPerMeter, &Children), Or<(Changed, Changed)>>, + changed_drawings: Query< + (&PixelsPerMeter, &Children), + Or<(Changed, Changed)>, + >, meshes: Query, With, With)>>, mut transforms: Query<&mut Transform>, ) { @@ -266,18 +265,21 @@ fn drawing_alpha( rank: Option<&RecencyRank>, general: Option<&GlobalDrawingVisibility>, ) -> (f32, AlphaMode) { - let alpha = specific.copied() - .unwrap_or_else( - || general.map(|v| { - if let Some(r) = rank { - if r.rank() < v.bottom_count { - return v.bottom; + let alpha = specific + .copied() + .unwrap_or_else(|| { + general + .map(|v| { + if let Some(r) = rank { + if r.rank() < v.bottom_count { + return v.bottom; + } } - } - v.general - }) - .unwrap_or(LayerVisibility::Opaque) - ).alpha(); + v.general + }) + .unwrap_or(LayerVisibility::Opaque) + }) + .alpha(); let alpha_mode = if alpha < 1.0 { AlphaMode::Blend @@ -289,12 +291,14 @@ fn drawing_alpha( #[inline] fn iter_update_drawing_visibility<'a>( - iter: impl Iterator, - Option<&'a Parent>, - Option<&'a RecencyRank>, - &'a DrawingSegments, - )>, + iter: impl Iterator< + Item = ( + Option<&'a LayerVisibility>, + Option<&'a Parent>, + Option<&'a RecencyRank>, + &'a DrawingSegments, + ), + >, material_handles: &Query<&Handle>, material_assets: &mut ResMut>, default_drawing_vis: &Query<&GlobalDrawingVisibility>, @@ -302,7 +306,9 @@ fn iter_update_drawing_visibility<'a>( for (vis, parent, rank, segments) in iter { if let Ok(handle) = material_handles.get(segments.leaf) { if let Some(mat) = material_assets.get_mut(handle) { - let default = parent.map(|p| default_drawing_vis.get(p.get()).ok()).flatten(); + let default = parent + .map(|p| default_drawing_vis.get(p.get()).ok()) + .flatten(); let (alpha, alpha_mode) = drawing_alpha(vis, rank, default); mat.base_color = *mat.base_color.set_a(alpha); mat.alpha_mode = alpha_mode; @@ -313,26 +319,40 @@ fn iter_update_drawing_visibility<'a>( // TODO(luca) RemovedComponents is brittle, maybe wrap component in an option? pub fn update_drawing_visibility( - changed_drawings: Query, Changed, Changed>)>>, + changed_drawings: Query< + Entity, + Or<( + Changed, + Changed, + Changed>, + )>, + >, removed_vis: RemovedComponents, - all_drawings: Query<(Option<&LayerVisibility>, Option<&Parent>, Option<&RecencyRank>, &DrawingSegments)>, + all_drawings: Query<( + Option<&LayerVisibility>, + Option<&Parent>, + Option<&RecencyRank>, + &DrawingSegments, + )>, material_handles: Query<&Handle>, mut material_assets: ResMut>, default_drawing_vis: Query<&GlobalDrawingVisibility>, - changed_default_drawing_vis: Query<&Children, Changed> + changed_default_drawing_vis: Query<&Children, Changed>, ) { iter_update_drawing_visibility( - changed_drawings.iter().filter_map(|e| all_drawings.get(e).ok()), + changed_drawings + .iter() + .filter_map(|e| all_drawings.get(e).ok()), &material_handles, &mut material_assets, - &default_drawing_vis + &default_drawing_vis, ); iter_update_drawing_visibility( removed_vis.iter().filter_map(|e| all_drawings.get(e).ok()), &material_handles, &mut material_assets, - &default_drawing_vis + &default_drawing_vis, ); for children in &changed_default_drawing_vis { @@ -340,7 +360,7 @@ pub fn update_drawing_visibility( children.iter().filter_map(|e| all_drawings.get(*e).ok()), &material_handles, &mut material_assets, - &default_drawing_vis + &default_drawing_vis, ); } } diff --git a/rmf_site_editor/src/site/drawing_editor/alignment.rs b/rmf_site_editor/src/site/drawing_editor/alignment.rs index b2619c6a..a69d8cae 100644 --- a/rmf_site_editor/src/site/drawing_editor/alignment.rs +++ b/rmf_site_editor/src/site/drawing_editor/alignment.rs @@ -17,19 +17,19 @@ use bevy::ecs::system::SystemParam; use bevy::{ - prelude::*, math::{DVec2, Vec2}, + prelude::*, }; use crate::site::{ - AlignSiteDrawings, Anchor, Angle, Category, Change, ConstraintMarker, - Distance, DrawingMarker, Edge, LevelElevation, MeasurementMarker, PixelsPerMeter, - Pose, Rotation, SiteProperties, NameOfSite, Affiliation, Point, FiducialMarker, + Affiliation, AlignSiteDrawings, Anchor, Angle, Category, Change, ConstraintMarker, Distance, + DrawingMarker, Edge, FiducialMarker, LevelElevation, MeasurementMarker, NameOfSite, + PixelsPerMeter, Point, Pose, Rotation, SiteProperties, }; +use itertools::{Either, Itertools}; use rmf_site_format::alignment::{ - align_site, SiteVariables, DrawingVariables, FiducialVariables, MeasurementVariables, + align_site, DrawingVariables, FiducialVariables, MeasurementVariables, SiteVariables, }; -use itertools::{Either, Itertools}; use std::collections::HashSet; #[derive(SystemParam)] @@ -45,23 +45,10 @@ pub struct OptimizationParams<'w, 's> { With, >, anchors: Query<'w, 's, &'static Anchor>, - fiducials: Query< - 'w, - 's, - ( - &'static Affiliation, - &'static Point, - ), - With, - >, - measurements: Query< - 'w, - 's, - ( - &'static Edge, - &'static Distance, - ), - With>, + fiducials: + Query<'w, 's, (&'static Affiliation, &'static Point), With>, + measurements: + Query<'w, 's, (&'static Edge, &'static Distance), With>, } pub fn align_site_drawings( @@ -108,16 +95,21 @@ pub fn align_site_drawings( let Ok([anchor0, anchor1]) = params.anchors.get_many(edge.array()) else { continue }; let Some(in_meters) = distance.0 else { continue }; let in_meters = in_meters as f64; - let p0 = Vec2::from_slice(anchor0.translation_for_category(Category::Fiducial)); - let p1 = Vec2::from_slice(anchor1.translation_for_category(Category::Fiducial)); + let p0 = + Vec2::from_slice(anchor0.translation_for_category(Category::Fiducial)); + let p1 = + Vec2::from_slice(anchor1.translation_for_category(Category::Fiducial)); let in_pixels = (p1 - p0).length() as f64; - drawing_variables.measurements.push( - MeasurementVariables { in_pixels, in_meters } - ); + drawing_variables.measurements.push(MeasurementVariables { + in_pixels, + in_meters, + }); } } - site_variables.drawings.insert(*level_child, drawing_variables); + site_variables + .drawings + .insert(*level_child, drawing_variables); } } @@ -128,9 +120,8 @@ pub fn align_site_drawings( let Ok((_, mut pose, mut ppm)) = params.drawings.get_mut(e) else { continue }; pose.trans[0] = alignment.translation.x as f32; pose.trans[1] = alignment.translation.y as f32; - pose.rot = Rotation::Yaw( - Angle::Rad(alignment.rotation as f32).match_variant(pose.rot.yaw()) - ); + pose.rot = + Rotation::Yaw(Angle::Rad(alignment.rotation as f32).match_variant(pose.rot.yaw())); ppm.0 = 1.0 / alignment.scale as f32; } } diff --git a/rmf_site_editor/src/site/drawing_editor/mod.rs b/rmf_site_editor/src/site/drawing_editor/mod.rs index d14dee3e..0be419f2 100644 --- a/rmf_site_editor/src/site/drawing_editor/mod.rs +++ b/rmf_site_editor/src/site/drawing_editor/mod.rs @@ -20,16 +20,15 @@ use bevy::{prelude::*, render::view::visibility::RenderLayers}; pub mod alignment; pub use alignment::*; +use crate::AppState; use crate::{ - interaction::{Selection, ChangeProjectionMode, SuppressHighlight, SuppressOutline}, + interaction::{ChangeProjectionMode, Selection, SuppressHighlight, SuppressOutline}, site::{ - Anchor, DrawingMarker, Edge, FiducialMarker, MeasurementMarker, Pending, + Anchor, DrawingMarker, Edge, FiducialMarker, MeasurementMarker, NameOfSite, Pending, PixelsPerMeter, Point, PreventDeletion, SiteProperties, WorkcellProperties, - NameOfSite, }, - WorkspaceMarker, CurrentWorkspace, + CurrentWorkspace, WorkspaceMarker, }; -use crate::AppState; use std::collections::HashSet; @@ -57,7 +56,10 @@ pub struct CurrentEditDrawing { impl FromWorld for CurrentEditDrawing { fn from_world(world: &mut World) -> Self { let editor = world.spawn(SpatialBundle::default()).id(); - Self { editor, target: None } + Self { + editor, + target: None, + } } } @@ -115,13 +117,13 @@ fn switch_edit_drawing_mode( }; current.target = Some(EditDrawing { drawing: *e, level }); - commands.entity(*e) + commands + .entity(*e) .set_parent(current.editor) .insert(Visibility { is_visible: true }) .insert(ComputedVisibility::default()) .insert(PreventDeletion::because( - "Cannot delete a drawing that is currently being edited" - .to_owned() + "Cannot delete a drawing that is currently being edited".to_owned(), )) // Highlighting the drawing looks bad when the user will be // constantly hovering over it anyway. @@ -193,11 +195,9 @@ fn switch_edit_drawing_mode( } /// Restore a drawing that was being edited back to its normal place and behavior -fn restore_edited_drawing( - edit: &EditDrawing, - commands: &mut Commands, -) { - commands.entity(edit.drawing) +fn restore_edited_drawing(edit: &EditDrawing, commands: &mut Commands) { + commands + .entity(edit.drawing) .set_parent(edit.level) .remove::() .remove::(); @@ -240,7 +240,10 @@ fn make_drawing_default_selected( ) { if selection.is_changed() { if selection.0.is_none() { - let drawing_entity = current.target().expect("No drawing while spawning drawing anchor").drawing; + let drawing_entity = current + .target() + .expect("No drawing while spawning drawing anchor") + .drawing; selection.0 = Some(drawing_entity); } } @@ -248,8 +251,7 @@ fn make_drawing_default_selected( impl Plugin for DrawingEditorPlugin { fn build(&self, app: &mut App) { - app - .add_event::() + app.add_event::() .add_event::() .add_event::() .init_resource::() diff --git a/rmf_site_editor/src/site/fiducial.rs b/rmf_site_editor/src/site/fiducial.rs index 2412e3bc..8e143b10 100644 --- a/rmf_site_editor/src/site/fiducial.rs +++ b/rmf_site_editor/src/site/fiducial.rs @@ -71,13 +71,23 @@ pub fn update_fiducial_usage_tracker( parent: Query<&Parent>, children: Query<&Children>, fiducials: Query<&Affiliation, With>, - changed_fiducials: Query<(Entity, &Parent), (Changed>, With)>, + changed_fiducials: Query< + (Entity, &Parent), + (Changed>, With), + >, fiducial_groups: Query<(Entity, &NameInSite, &Parent), (With, With)>, - changed_fiducial_groups: Query, With), - (With, Added), - (Or<(Changed, Changed)>, With, With), - )>>, + changed_fiducial_groups: Query< + Entity, + Or<( + (Added, With), + (With, Added), + ( + Or<(Changed, Changed)>, + With, + With, + ), + )>, + >, removed_fiducial_groups: RemovedComponents, ) { for e in &changed_parent { @@ -88,7 +98,8 @@ pub fn update_fiducial_usage_tracker( } } - for e in changed_parent.iter() + for e in changed_parent + .iter() .chain(changed_fiducial.iter().map(|p| p.get())) { let Ok((_, mut tracker)) = unused_fiducial_trackers.get_mut(e) else { continue }; @@ -208,7 +219,7 @@ pub fn assign_orphan_fiducials_to_parent( mut commands: Commands, orphans: Query< (Entity, &Point), - (With, Without, Without) + (With, Without, Without), >, anchors: Query<&Parent, With>, site_id: Query<&SiteID>, diff --git a/rmf_site_editor/src/site/floor.rs b/rmf_site_editor/src/site/floor.rs index a4179314..4b679e31 100644 --- a/rmf_site_editor/src/site/floor.rs +++ b/rmf_site_editor/src/site/floor.rs @@ -15,12 +15,7 @@ * */ -use crate::{ - interaction::Selectable, - shapes::*, - site::*, - RecencyRanking, -}; +use crate::{interaction::Selectable, shapes::*, site::*, RecencyRanking}; use bevy::{ math::Affine3A, prelude::*, @@ -175,17 +170,21 @@ fn floor_material( specific: Option<&LayerVisibility>, general: Option<(&GlobalFloorVisibility, &RecencyRanking)>, ) -> StandardMaterial { - let alpha = specific.copied() - .unwrap_or_else( - || general.map(|(v, r)| { - if r.is_empty() { - &v.without_drawings - } else { - &v.general - } - }).copied() - .unwrap_or(LayerVisibility::Opaque) - ).alpha(); + let alpha = specific + .copied() + .unwrap_or_else(|| { + general + .map(|(v, r)| { + if r.is_empty() { + &v.without_drawings + } else { + &v.general + } + }) + .copied() + .unwrap_or(LayerVisibility::Opaque) + }) + .alpha(); Color::rgba(0.3, 0.3, 0.3, alpha).into() } @@ -212,7 +211,9 @@ pub fn add_floor_visuals( let mesh = make_floor_mesh(e, new_floor, &anchors); let mut cmd = commands.entity(e); let height = floor_height(rank); - let default = parent.map(|p| default_floor_vis.get(p.get()).ok()).flatten(); + let default = parent + .map(|p| default_floor_vis.get(p.get()).ok()) + .flatten(); let material = materials.add(floor_material(vis, default)); let mesh_entity_id = cmd @@ -295,7 +296,13 @@ pub fn update_floor_for_moved_anchors( #[inline] fn iter_update_floor_visibility<'a>( - iter: impl Iterator, Option<&'a Parent>, &'a FloorSegments)>, + iter: impl Iterator< + Item = ( + Option<&'a LayerVisibility>, + Option<&'a Parent>, + &'a FloorSegments, + ), + >, material_handles: &Query<&Handle>, material_assets: &mut ResMut>, default_floor_vis: &Query<(&GlobalFloorVisibility, &RecencyRanking)>, @@ -303,7 +310,9 @@ fn iter_update_floor_visibility<'a>( for (vis, parent, segments) in iter { if let Ok(handle) = material_handles.get(segments.mesh) { if let Some(mat) = material_assets.get_mut(handle) { - let default = parent.map(|p| default_floor_vis.get(p.get()).ok()).flatten(); + let default = parent + .map(|p| default_floor_vis.get(p.get()).ok()) + .flatten(); *mat = floor_material(vis, default); } } @@ -320,7 +329,10 @@ pub fn update_floor_visibility( default_floor_vis: Query<(&GlobalFloorVisibility, &RecencyRanking)>, changed_default_floor_vis: Query< &Children, - Or<(Changed, Changed>)>, + Or<( + Changed, + Changed>, + )>, >, ) { iter_update_floor_visibility( diff --git a/rmf_site_editor/src/site/lift.rs b/rmf_site_editor/src/site/lift.rs index d287c5a0..3a04523a 100644 --- a/rmf_site_editor/src/site/lift.rs +++ b/rmf_site_editor/src/site/lift.rs @@ -170,9 +170,8 @@ pub fn update_lift_cabin( let cabin_tf = match cabin { LiftCabin::Rect(params) => { let Aabb { center, .. } = params.aabb(); - let cabin_tf = Transform::from_translation( - Vec3::new(center.x, center.y, FLOOR_LAYER_START) - ); + let cabin_tf = + Transform::from_translation(Vec3::new(center.x, center.y, FLOOR_LAYER_START)); let floor_mesh: Mesh = make_flat_rect_mesh( params.depth + 2.0 * params.thickness(), params.width + 2.0 * params.thickness(), diff --git a/rmf_site_editor/src/site/light.rs b/rmf_site_editor/src/site/light.rs index 91c10166..c42d614b 100644 --- a/rmf_site_editor/src/site/light.rs +++ b/rmf_site_editor/src/site/light.rs @@ -27,7 +27,7 @@ use bevy::{ view::VisibleEntities, }, }; -use rmf_site_format::{Category, NameInSite, LevelElevation, Light, LightKind, Pose}; +use rmf_site_format::{Category, LevelElevation, Light, LightKind, NameInSite, Pose}; use std::collections::{BTreeMap, HashMap}; /// True/false for whether the physical lights of an environment should be diff --git a/rmf_site_editor/src/site/load.rs b/rmf_site_editor/src/site/load.rs index 5e3588a7..f3c7938b 100644 --- a/rmf_site_editor/src/site/load.rs +++ b/rmf_site_editor/src/site/load.rs @@ -15,9 +15,7 @@ * */ -use crate::{ - recency::RecencyRanking, site::*, Autoload, CurrentWorkspace, WorkspaceMarker, -}; +use crate::{recency::RecencyRanking, site::*, Autoload, CurrentWorkspace, WorkspaceMarker}; use bevy::{ecs::system::SystemParam, prelude::*, tasks::AsyncComputeTaskPool}; use futures_lite::future; use rmf_site_format::legacy::building_map::BuildingMap; @@ -66,10 +64,7 @@ fn generate_site_entities(commands: &mut Commands, site_data: &rmf_site_format:: } for (group_id, group) in &site_data.fiducial_groups { - let group_entity = site - .spawn(group.clone()) - .insert(SiteID(*group_id)) - .id(); + let group_entity = site.spawn(group.clone()).insert(SiteID(*group_id)).id(); id_to_entity.insert(*group_id, group_entity); consider_id(*group_id); } diff --git a/rmf_site_editor/src/site/save.rs b/rmf_site_editor/src/site/save.rs index b94f41f0..8f2f80c1 100644 --- a/rmf_site_editor/src/site/save.rs +++ b/rmf_site_editor/src/site/save.rs @@ -111,21 +111,27 @@ fn assign_site_ids(world: &mut World, site: Entity) -> Result<(), SiteGeneration Query< Entity, ( - Or<( - With, - With, - With, - )>, + Or<(With, With, With)>, Without, - )>, + ), + >, Query<(), With>, Query<&NextSiteID>, Query<&SiteID>, Query<&Children>, )> = SystemState::new(world); - let (level_children, nav_graph_elements, levels, lifts, drawing_children, drawings, sites, site_ids, children) = - state.get_mut(world); + let ( + level_children, + nav_graph_elements, + levels, + lifts, + drawing_children, + drawings, + sites, + site_ids, + children, + ) = state.get_mut(world); let mut new_entities = Vec::new(); @@ -363,7 +369,17 @@ fn generate_levels( ) = state.get(world); let mut levels = BTreeMap::new(); - for (name, elevation, floor_vis, drawing_vis, level_id, parent, floor_ranking, drawing_ranking) in &q_levels { + for ( + name, + elevation, + floor_vis, + drawing_vis, + level_id, + parent, + floor_ranking, + drawing_ranking, + ) in &q_levels + { if parent.get() == site { levels.insert( level_id.0, @@ -395,9 +411,10 @@ fn generate_levels( }; let get_group_id = |entity| { - q_groups.get(entity) - .map(|id| id.0) - .map_err(|_| SiteGenerationError::BrokenAffiliation(entity)) + q_groups + .get(entity) + .map(|id| id.0) + .map_err(|_| SiteGenerationError::BrokenAffiliation(entity)) }; let get_anchor_id_edge = |edge: &Edge| { @@ -442,7 +459,8 @@ fn generate_levels( } } - for (name, source, pose, pixels_per_meter, preferred_alpha, id, parent, children) in &q_drawings { + for (name, source, pose, pixels_per_meter, preferred_alpha, id, parent, children) in &q_drawings + { if let Ok((_, _, _, _, level_id, _, _, _)) = q_levels.get(parent.get()) { if let Some(level) = levels.get_mut(&level_id.0) { let mut measurements = BTreeMap::new(); @@ -554,7 +572,7 @@ fn generate_levels( } for (name, pose, properties, id, parent) in &q_physical_cameras { - if let Ok((_, _, _ , _, level_id, _, _, _)) = q_levels.get(parent.get()) { + if let Ok((_, _, _, _, level_id, _, _, _)) = q_levels.get(parent.get()) { if let Some(level) = levels.get_mut(&level_id.0) { level.physical_cameras.insert( id.0, @@ -780,16 +798,14 @@ fn generate_fiducials( let mut state: SystemState<( Query<&SiteID, (With, Without)>, Query<&SiteID, (With, Without)>, - Query<(&Point, &Affiliation, &SiteID), (With, Without)>, + Query< + (&Point, &Affiliation, &SiteID), + (With, Without), + >, Query<&Children>, )> = SystemState::new(world); - let ( - q_anchor_ids, - q_group_ids, - q_fiducials, - q_children, - ) = state.get(world); + let (q_anchor_ids, q_group_ids, q_fiducials, q_children) = state.get(world); let Ok(children) = q_children.get(parent) else { return Ok(BTreeMap::new()); @@ -798,22 +814,29 @@ fn generate_fiducials( let mut fiducials = BTreeMap::new(); for child in children { let Ok((point, affiliation, site_id)) = q_fiducials.get(*child) else { continue }; - let anchor = q_anchor_ids.get(point.0) - .map_err(|_| SiteGenerationError::BrokenAnchorReference(point.0))?.0; + let anchor = q_anchor_ids + .get(point.0) + .map_err(|_| SiteGenerationError::BrokenAnchorReference(point.0))? + .0; let anchor = Point(anchor); let affiliation = if let Some(e) = affiliation.0 { - let group_id = q_group_ids.get(e) - .map_err(|_| SiteGenerationError::BrokenAffiliation(e))?.0; + let group_id = q_group_ids + .get(e) + .map_err(|_| SiteGenerationError::BrokenAffiliation(e))? + .0; Affiliation(Some(group_id)) } else { Affiliation(None) }; - fiducials.insert(site_id.0, Fiducial { - anchor, - affiliation, - marker: Default::default(), - }); + fiducials.insert( + site_id.0, + Fiducial { + anchor, + affiliation, + marker: Default::default(), + }, + ); } Ok(fiducials) @@ -828,10 +851,7 @@ fn generate_fiducial_groups( Query<&Children>, )> = SystemState::new(world); - let ( - q_groups, - q_children - ) = state.get(world); + let (q_groups, q_children) = state.get(world); let Ok(children) = q_children.get(parent) else { return Ok(BTreeMap::new()); diff --git a/rmf_site_editor/src/site/site.rs b/rmf_site_editor/src/site/site.rs index d8649d74..df7d32d5 100644 --- a/rmf_site_editor/src/site/site.rs +++ b/rmf_site_editor/src/site/site.rs @@ -17,7 +17,7 @@ use crate::CurrentWorkspace; use bevy::prelude::*; -use rmf_site_format::{LevelElevation, NameOfSite, NameInSite, LevelProperties}; +use rmf_site_format::{LevelElevation, LevelProperties, NameInSite, NameOfSite}; /// Used as an event to command that a new site should be made the current one #[derive(Clone, Copy, Debug)] diff --git a/rmf_site_editor/src/site/site_visualizer/mod.rs b/rmf_site_editor/src/site/site_visualizer/mod.rs index f1e6aa5b..59fc1c6c 100644 --- a/rmf_site_editor/src/site/site_visualizer/mod.rs +++ b/rmf_site_editor/src/site/site_visualizer/mod.rs @@ -18,7 +18,7 @@ use bevy::prelude::*; use crate::interaction::{InteractionState, SetCategoryVisibility}; -use crate::site::{CurrentLevel, LaneMarker, NameOfSite, LevelElevation, SiteProperties}; +use crate::site::{CurrentLevel, LaneMarker, LevelElevation, NameOfSite, SiteProperties}; use crate::{AppState, CurrentWorkspace}; #[derive(Default)] diff --git a/rmf_site_editor/src/widgets/create.rs b/rmf_site_editor/src/widgets/create.rs index 1591cee5..dc4d62e6 100644 --- a/rmf_site_editor/src/widgets/create.rs +++ b/rmf_site_editor/src/widgets/create.rs @@ -18,15 +18,15 @@ use crate::{ inspector::{InspectAssetSource, InspectScale}, interaction::{ChangeMode, SelectAnchor, SelectAnchor3D}, - site::{Change, DrawingBundle, DrawingMarker, Recall, DefaultFile}, - AppEvents, AppState, SuppressRecencyRank, CurrentWorkspace, + site::{Change, DefaultFile, DrawingBundle, DrawingMarker, Recall}, + AppEvents, AppState, CurrentWorkspace, SuppressRecencyRank, }; -use bevy::{prelude::*, ecs::system::SystemParam}; +use bevy::{ecs::system::SystemParam, prelude::*}; use bevy_egui::egui::{CollapsingHeader, Ui}; use rmf_site_format::{ - AssetSource, DrawingProperties, Geometry, Model, ModelMarker, Pending, - RecallAssetSource, Scale, WorkcellModel, + AssetSource, DrawingProperties, Geometry, Model, ModelMarker, Pending, RecallAssetSource, + Scale, WorkcellModel, }; #[derive(SystemParam)] @@ -40,10 +40,7 @@ pub struct CreateWidget<'a, 'w1, 'w2, 's1, 's2> { } impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { - pub fn new( - params: &'a CreateParams<'w1, 's1>, - events: &'a mut AppEvents<'w2, 's2>, - ) -> Self { + pub fn new(params: &'a CreateParams<'w1, 's1>, events: &'a mut AppEvents<'w2, 's2>) -> Self { Self { params, events } } @@ -99,34 +96,44 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { CollapsingHeader::new("New drawing") .default_open(false) .show(ui, |ui| { - let default_file = self.events.request.current_workspace.root + let default_file = self + .events + .request + .current_workspace + .root .map(|e| self.params.default_file.get(e).ok()) .flatten(); if let Some(new_asset_source) = InspectAssetSource::new( &self.events.display.pending_drawings.source, &self.events.display.pending_drawings.recall_source, default_file, - ).show(ui) { - self.events.display.pending_drawings.recall_source.remember( - &new_asset_source - ); + ) + .show(ui) + { + self.events + .display + .pending_drawings + .recall_source + .remember(&new_asset_source); self.events.display.pending_drawings.source = new_asset_source; } ui.add_space(5.0); if ui.button("Add Drawing").clicked() { - self.events.commands.spawn(DrawingBundle::new( - DrawingProperties { + self.events + .commands + .spawn(DrawingBundle::new(DrawingProperties { source: self.events.display.pending_drawings.source.clone(), ..default() - }) - ); + })); } }); } AppState::SiteDrawingEditor => { if ui.button("Fiducial").clicked() { self.events.request.change_mode.send(ChangeMode::To( - SelectAnchor::create_new_point().for_drawing_fiducial().into(), + SelectAnchor::create_new_point() + .for_drawing_fiducial() + .into(), )); } if ui.button("Measurement").clicked() { @@ -150,21 +157,31 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { CollapsingHeader::new("New model") .default_open(false) .show(ui, |ui| { - let default_file = self.events.request.current_workspace.root + let default_file = self + .events + .request + .current_workspace + .root .map(|e| self.params.default_file.get(e).ok()) .flatten(); if let Some(new_asset_source) = InspectAssetSource::new( &self.events.display.pending_model.source, &self.events.display.pending_model.recall_source, default_file, - ).show(ui) { - self.events.display.pending_model.recall_source.remember(&new_asset_source); + ) + .show(ui) + { + self.events + .display + .pending_model + .recall_source + .remember(&new_asset_source); self.events.display.pending_model.source = new_asset_source; } ui.add_space(5.0); - if let Some(new_scale) = InspectScale::new( - &self.events.display.pending_model.scale, - ).show(ui) { + if let Some(new_scale) = + InspectScale::new(&self.events.display.pending_model.scale).show(ui) + { self.events.display.pending_model.scale = new_scale; } ui.add_space(5.0); @@ -175,7 +192,12 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { AppState::SiteEditor => { if ui.button("Spawn model").clicked() { let model = Model { - source: self.events.display.pending_model.source.clone(), + source: self + .events + .display + .pending_model + .source + .clone(), scale: self.events.display.pending_model.scale, ..default() }; @@ -190,8 +212,15 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { if ui.button("Spawn visual").clicked() { let workcell_model = WorkcellModel { geometry: Geometry::Mesh { - filename: (&self.events.display.pending_model.source).into(), - scale: Some(*self.events.display.pending_model.scale), + filename: (&self + .events + .display + .pending_model + .source) + .into(), + scale: Some( + *self.events.display.pending_model.scale, + ), }, ..default() }; @@ -204,8 +233,15 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { if ui.button("Spawn collision").clicked() { let workcell_model = WorkcellModel { geometry: Geometry::Mesh { - filename: (&self.events.display.pending_model.source).into(), - scale: Some(*self.events.display.pending_model.scale), + filename: (&self + .events + .display + .pending_model + .source) + .into(), + scale: Some( + *self.events.display.pending_model.scale, + ), }, ..default() }; @@ -219,7 +255,7 @@ impl<'a, 'w1, 'w2, 's1, 's2> CreateWidget<'a, 'w1, 'w2, 's1, 's2> { } } }); - } + } } }); } diff --git a/rmf_site_editor/src/widgets/inspector/inspect_asset_source.rs b/rmf_site_editor/src/widgets/inspector/inspect_asset_source.rs index 8f22ce78..ac4690f0 100644 --- a/rmf_site_editor/src/widgets/inspector/inspect_asset_source.rs +++ b/rmf_site_editor/src/widgets/inspector/inspect_asset_source.rs @@ -15,10 +15,10 @@ * */ -use bevy_egui::egui::{ComboBox, Ui}; -use rmf_site_format::{AssetSource, RecallAssetSource}; use crate::site::DefaultFile; +use bevy_egui::egui::{ComboBox, Ui}; use pathdiff::diff_paths; +use rmf_site_format::{AssetSource, RecallAssetSource}; #[cfg(not(target_arch = "wasm32"))] use rfd::FileDialog; @@ -35,7 +35,11 @@ impl<'a> InspectAssetSource<'a> { recall: &'a RecallAssetSource, default_file: Option<&'a DefaultFile>, ) -> Self { - Self { source, recall, default_file } + Self { + source, + recall, + default_file, + } } pub fn show(self, ui: &mut Ui) -> Option { @@ -72,7 +76,9 @@ impl<'a> InspectAssetSource<'a> { let mut is_relative = path.is_relative(); if ui.checkbox(&mut is_relative, "Relative").clicked() { if is_relative { - let parent_dir = default_file.0.parent() + let parent_dir = default_file + .0 + .parent() .map(|p| p.to_str()) .flatten() .unwrap_or(""); @@ -98,8 +104,11 @@ impl<'a> InspectAssetSource<'a> { if ui.button("Browse").clicked() { if let Some(file) = FileDialog::new().pick_file() { if let Some(src) = file.to_str() { - if let (Some(default_file), true) = (self.default_file, is_relative) { - let parent_dir = default_file.0.parent() + if let (Some(default_file), true) = (self.default_file, is_relative) + { + let parent_dir = default_file + .0 + .parent() .map(|p| p.to_str()) .flatten() .unwrap_or(""); diff --git a/rmf_site_editor/src/widgets/inspector/inspect_fiducial.rs b/rmf_site_editor/src/widgets/inspector/inspect_fiducial.rs index 8739bf6a..f406ed68 100644 --- a/rmf_site_editor/src/widgets/inspector/inspect_fiducial.rs +++ b/rmf_site_editor/src/widgets/inspector/inspect_fiducial.rs @@ -16,17 +16,11 @@ */ use crate::{ - site::{ - Affiliation, FiducialMarker, FiducialUsage, NameInSite, Group, - FiducialGroup, Change - }, + site::{Affiliation, Change, FiducialGroup, FiducialMarker, FiducialUsage, Group, NameInSite}, widgets::{AppEvents, Icons}, }; -use bevy::{ - prelude::*, - ecs::system::SystemParam, -}; -use bevy_egui::egui::{ComboBox, Ui, ImageButton}; +use bevy::{ecs::system::SystemParam, prelude::*}; +use bevy_egui::egui::{ComboBox, ImageButton, Ui}; #[derive(Resource, Default)] pub struct SearchForFiducial(pub String); @@ -42,19 +36,23 @@ enum SearchResult { impl SearchResult { fn consider(&mut self, entity: Entity) { match self { - Self::NoMatch => { *self = SearchResult::Match(entity); } - Self::Match(_) => { *self = SearchResult::Conflict("Multiple groups have this name"); } - Self::Conflict(_) | Self::Current | Self::Empty => { } + Self::NoMatch => { + *self = SearchResult::Match(entity); + } + Self::Match(_) => { + *self = SearchResult::Conflict("Multiple groups have this name"); + } + Self::Conflict(_) | Self::Current | Self::Empty => {} } } fn conflict(&mut self, text: &'static str) { match self { // If we already found a match then don't change the behavior - Self::Match(_) | Self::Current | Self::Conflict(_) | Self::Empty => { } + Self::Match(_) | Self::Current | Self::Conflict(_) | Self::Empty => {} // If there is not a match, prevent the user from creating a duplicate // fiducial name - _ => { *self = Self::Conflict(text) } + _ => *self = Self::Conflict(text), } } } @@ -79,7 +77,11 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { params: &'a InspectFiducialParams<'w1, 's1>, events: &'a mut AppEvents<'w2, 's2>, ) -> Self { - Self { entity, params, events } + Self { + entity, + params, + events, + } } pub fn show(self, ui: &mut Ui) { @@ -99,8 +101,8 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { Some("".to_owned()) } }; - let selected_text = get_group_name(*affiliation) - .unwrap_or_else(|| "".to_owned()); + let selected_text = + get_group_name(*affiliation).unwrap_or_else(|| "".to_owned()); ui.horizontal(|ui| { let search = &mut self.events.change_more.search_for_fiducial.0; @@ -135,7 +137,11 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { } if any_partial_matches { - if ui.add(ImageButton::new(self.params.icons.search.egui(), [18., 18.])) + if ui + .add(ImageButton::new( + self.params.icons.search.egui(), + [18., 18.], + )) .on_hover_text("Search results for this text can be found below") .clicked() { @@ -148,7 +154,11 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { match result { SearchResult::Empty => { - if ui.add(ImageButton::new(self.params.icons.hidden.egui(), [18., 18.])) + if ui + .add(ImageButton::new( + self.params.icons.hidden.egui(), + [18., 18.], + )) .on_hover_text("An empty string is not a good fiducial group name") .clicked() { @@ -156,7 +166,11 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { } } SearchResult::Current => { - if ui.add(ImageButton::new(self.params.icons.selected.egui(), [18., 18.])) + if ui + .add(ImageButton::new( + self.params.icons.selected.egui(), + [18., 18.], + )) .on_hover_text("This is the name of the fiducial's current group") .clicked() { @@ -164,31 +178,44 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { } } SearchResult::NoMatch => { - if ui.add(ImageButton::new(self.params.icons.add.egui(), [18., 18.])) + if ui + .add(ImageButton::new(self.params.icons.add.egui(), [18., 18.])) .on_hover_text("Create a new group for this fiducial") .clicked() { - let new_group = self.events.commands + let new_group = self + .events + .commands .spawn(FiducialGroup::new(NameInSite(search.clone()))) .set_parent(tracker.site()) .id(); - self.events.change_more.affiliation.send( - Change::new(Affiliation(Some(new_group)), self.entity) - ); + self.events + .change_more + .affiliation + .send(Change::new(Affiliation(Some(new_group)), self.entity)); } } SearchResult::Match(group) => { - if ui.add(ImageButton::new(self.params.icons.confirm.egui(), [18., 18.])) + if ui + .add(ImageButton::new( + self.params.icons.confirm.egui(), + [18., 18.], + )) .on_hover_text("Select this group") .clicked() { - self.events.change_more.affiliation.send( - Change::new(Affiliation(Some(group)), self.entity) - ); + self.events + .change_more + .affiliation + .send(Change::new(Affiliation(Some(group)), self.entity)); } } SearchResult::Conflict(text) => { - if ui.add(ImageButton::new(self.params.icons.reject.egui(), [18., 18.])) + if ui + .add(ImageButton::new( + self.params.icons.reject.egui(), + [18., 18.], + )) .on_hover_text(text) .clicked() { @@ -203,42 +230,37 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectFiducialWidget<'a, 'w1, 'w2, 's1, 's2> { let mut new_affiliation = affiliation.clone(); ui.horizontal(|ui| { - if ui.add(ImageButton::new(self.params.icons.trash.egui(), [18., 18.])) + if ui + .add(ImageButton::new(self.params.icons.trash.egui(), [18., 18.])) .on_hover_text("Remove this fiducial from its group") .clicked() { - self.events.change_more.affiliation.send( - Change::new(Affiliation(None), self.entity) - ); + self.events + .change_more + .affiliation + .send(Change::new(Affiliation(None), self.entity)); } ComboBox::from_id_source("fiducial_affiliation") .selected_text(selected_text) .show_ui(ui, |ui| { if let Some(group_name) = get_group_name(new_affiliation) { - ui.selectable_value( - &mut new_affiliation, - *affiliation, - group_name, - ); + ui.selectable_value(&mut new_affiliation, *affiliation, group_name); } for (group, name) in tracker.unused() { if name.contains(&self.events.change_more.search_for_fiducial.0) { let select_affiliation = Affiliation(Some(*group)); - ui.selectable_value( - &mut new_affiliation, - select_affiliation, - name, - ); + ui.selectable_value(&mut new_affiliation, select_affiliation, name); } } }); }); if new_affiliation != *affiliation { - self.events.change_more.affiliation.send( - Change::new(new_affiliation, self.entity) - ); + self.events + .change_more + .affiliation + .send(Change::new(new_affiliation, self.entity)); } ui.separator(); } diff --git a/rmf_site_editor/src/widgets/inspector/inspect_layer.rs b/rmf_site_editor/src/widgets/inspector/inspect_layer.rs index dacaac19..4d7474ce 100644 --- a/rmf_site_editor/src/widgets/inspector/inspect_layer.rs +++ b/rmf_site_editor/src/widgets/inspector/inspect_layer.rs @@ -19,13 +19,13 @@ use crate::{ interaction::Hover, recency::ChangeRank, site::{ - Change, LayerVisibility, SiteID, VisibilityCycle, BeginEditDrawing, - PreferredSemiTransparency, + BeginEditDrawing, Change, LayerVisibility, PreferredSemiTransparency, SiteID, + VisibilityCycle, }, widgets::{inspector::SelectionWidget, AppEvents, Icons, MoveLayerButton}, }; use bevy::prelude::*; -use bevy_egui::egui::{ImageButton, Ui, DragValue}; +use bevy_egui::egui::{DragValue, ImageButton, Ui}; pub struct InspectLayer<'a, 'w, 's> { pub entity: Entity, @@ -79,18 +79,22 @@ impl<'a, 'w, 's> InspectLayer<'a, 'w, 's> { .show(ui); if !self.is_floor { - let response = ui.add(ImageButton::new( - self.events.layers.icons.edit.egui(), [18., 18.] - )).on_hover_text("Edit Drawing"); + let response = ui + .add(ImageButton::new( + self.events.layers.icons.edit.egui(), + [18., 18.], + )) + .on_hover_text("Edit Drawing"); if response.hovered() { self.events.request.hover.send(Hover(Some(self.entity))); } if response.clicked() { - self.events.layers.begin_edit_drawing.send( - BeginEditDrawing(self.entity) - ); + self.events + .layers + .begin_edit_drawing + .send(BeginEditDrawing(self.entity)); } } } @@ -123,11 +127,14 @@ impl<'a, 'w, 's> InspectLayer<'a, 'w, 's> { } if let Some(LayerVisibility::Alpha(mut alpha)) = self.layer_vis { - if ui.add( - DragValue::new(&mut alpha) - .clamp_range(0_f32..=1_f32) - .speed(0.01) - ).changed() { + if ui + .add( + DragValue::new(&mut alpha) + .clamp_range(0_f32..=1_f32) + .speed(0.01), + ) + .changed() + { self.events .layers .layer_vis diff --git a/rmf_site_editor/src/widgets/inspector/inspect_lift.rs b/rmf_site_editor/src/widgets/inspector/inspect_lift.rs index f79e698a..04a4c7ee 100644 --- a/rmf_site_editor/src/widgets/inspector/inspect_lift.rs +++ b/rmf_site_editor/src/widgets/inspector/inspect_lift.rs @@ -16,9 +16,7 @@ */ use crate::{ - site::{ - CabinDoorId, NameInSite, LevelElevation, SiteID, ToggleLiftDoorAvailability - }, + site::{CabinDoorId, LevelElevation, NameInSite, SiteID, ToggleLiftDoorAvailability}, widgets::{ inspector::{InspectOptionF32, SelectionWidget}, AppEvents, Icons, diff --git a/rmf_site_editor/src/widgets/inspector/inspect_location.rs b/rmf_site_editor/src/widgets/inspector/inspect_location.rs index a8c0f702..de64d7ea 100644 --- a/rmf_site_editor/src/widgets/inspector/inspect_location.rs +++ b/rmf_site_editor/src/widgets/inspector/inspect_location.rs @@ -17,8 +17,8 @@ use crate::{ site::{ - ConsiderLocationTag, LocationTag, LocationTags, Model, RecallAssetSource, - RecallLocationTags, DefaultFile, + ConsiderLocationTag, DefaultFile, LocationTag, LocationTags, Model, RecallAssetSource, + RecallLocationTags, }, widgets::{ inspector::{InspectAssetSource, InspectName}, @@ -152,7 +152,8 @@ impl<'a, 'w1, 'w2, 's2> InspectLocationWidget<'a, 'w1, 'w2, 's2> { default_file: Option<&'a DefaultFile>, ) -> Option { let new_name = InspectName::new(&model.name).show(ui); - let new_source = InspectAssetSource::new(&model.source, &recall_asset, default_file).show(ui); + let new_source = + InspectAssetSource::new(&model.source, &recall_asset, default_file).show(ui); if new_name.is_some() || new_source.is_some() { let mut new_model = model.clone(); diff --git a/rmf_site_editor/src/widgets/inspector/mod.rs b/rmf_site_editor/src/widgets/inspector/mod.rs index 0d89cd1e..c5c3ec3b 100644 --- a/rmf_site_editor/src/widgets/inspector/mod.rs +++ b/rmf_site_editor/src/widgets/inspector/mod.rs @@ -92,8 +92,8 @@ use super::move_layer::MoveLayer; use crate::{ interaction::{Selection, SpawnPreview}, site::{ - Category, Change, DrawingMarker, EdgeLabels, LayerVisibility, Original, - SiteID, BeginEditDrawing, DefaultFile, AlignSiteDrawings, + AlignSiteDrawings, BeginEditDrawing, Category, Change, DefaultFile, DrawingMarker, + EdgeLabels, LayerVisibility, Original, SiteID, }, widgets::AppEvents, AppState, CurrentWorkspace, @@ -161,9 +161,32 @@ pub struct InspectDrawingParams<'w, 's> { #[derive(SystemParam)] pub struct InspectorLayerParams<'w, 's> { - pub floors: Query<'w, 's, (Option<&'static LayerVisibility>, &'static PreferredSemiTransparency), With>, - pub drawings: Query<'w, 's, (Option<&'static LayerVisibility>, &'static PreferredSemiTransparency), With>, - pub levels: Query<'w, 's, (&'static GlobalFloorVisibility, &'static GlobalDrawingVisibility)>, + pub floors: Query< + 'w, + 's, + ( + Option<&'static LayerVisibility>, + &'static PreferredSemiTransparency, + ), + With, + >, + pub drawings: Query< + 'w, + 's, + ( + Option<&'static LayerVisibility>, + &'static PreferredSemiTransparency, + ), + With, + >, + pub levels: Query< + 'w, + 's, + ( + &'static GlobalFloorVisibility, + &'static GlobalDrawingVisibility, + ), + >, } pub struct InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { @@ -211,11 +234,8 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { ui.add_space(10.0); } - InspectFiducialWidget::new( - selection, - &self.params.drawing.fiducial, - &mut self.events, - ).show(ui); + InspectFiducialWidget::new(selection, &self.params.drawing.fiducial, &mut self.events) + .show(ui); if let Ok(name) = self.params.component.names.get(selection) { if let Some(new_name) = InspectName::new(name).show(ui) { @@ -242,7 +262,7 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { MoveLayer::new( selection, &mut self.events.layers.floors, - &self.events.layers.icons + &self.events.layers.icons, ) .show(ui); }); @@ -264,7 +284,7 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { MoveLayer::new( selection, &mut self.events.layers.drawings, - &self.events.layers.icons + &self.events.layers.icons, ) .show(ui); }); @@ -284,24 +304,30 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { if let Ok(ppm) = self.params.component.pixels_per_meter.get(selection) { if *self.events.app_state.current() == AppState::SiteEditor { ui.add_space(10.0); - if ui.add( - Button::image_and_text( - self.events.layers.icons.edit.egui(), [18., 18.], + if ui + .add(Button::image_and_text( + self.events.layers.icons.edit.egui(), + [18., 18.], "Edit Drawing", - ) - ).clicked() { - self.events.layers.begin_edit_drawing.send( - BeginEditDrawing(selection) - ); + )) + .clicked() + { + self.events + .layers + .begin_edit_drawing + .send(BeginEditDrawing(selection)); } } ui.add_space(10.0); - if ui.add(Button::image_and_text( - self.events.layers.icons.alignment.egui(), - [18., 18.], - "Align Drawings", - )) - .on_hover_text("Align all drawings in the site based on their fiducials and measurements") + if ui + .add(Button::image_and_text( + self.events.layers.icons.alignment.egui(), + [18., 18.], + "Align Drawings", + )) + .on_hover_text( + "Align all drawings in the site based on their fiducials and measurements", + ) .clicked() { if let Some(site) = self.events.request.current_workspace.root { @@ -438,12 +464,16 @@ impl<'a, 'w1, 'w2, 's1, 's2> InspectorWidget<'a, 'w1, 'w2, 's1, 's2> { } if let Ok((source, recall)) = self.params.component.asset_sources.get(selection) { - let default_file = self.events.request.current_workspace.root + let default_file = self + .events + .request + .current_workspace + .root .map(|e| self.params.default_file.get(e).ok()) .flatten(); - if let Some(new_asset_source) = InspectAssetSource::new( - source, recall, default_file - ).show(ui) { + if let Some(new_asset_source) = + InspectAssetSource::new(source, recall, default_file).show(ui) + { self.events .change .asset_source diff --git a/rmf_site_editor/src/widgets/mod.rs b/rmf_site_editor/src/widgets/mod.rs index 261f27d7..2253370e 100644 --- a/rmf_site_editor/src/widgets/mod.rs +++ b/rmf_site_editor/src/widgets/mod.rs @@ -24,11 +24,10 @@ use crate::{ occupancy::CalculateGrid, recency::ChangeRank, site::{ - AlignSiteDrawings, AssociatedGraphs, Change, ConsiderAssociatedGraph, - ConsiderLocationTag, CurrentLevel, Delete, DrawingMarker, ExportLights, + AlignSiteDrawings, AssociatedGraphs, BeginEditDrawing, Change, ConsiderAssociatedGraph, + ConsiderLocationTag, CurrentLevel, Delete, DrawingMarker, ExportLights, FinishEditDrawing, GlobalDrawingVisibility, GlobalFloorVisibility, LayerVisibility, PhysicalLightToggle, SaveNavGraphs, SiteState, ToggleLiftDoorAvailability, - BeginEditDrawing, FinishEditDrawing, }, AppState, CreateNewWorkspace, CurrentWorkspace, LoadWorkspace, SaveWorkspace, }; @@ -406,12 +405,18 @@ fn site_drawing_ui_layout( CreateWidget::new(&create_params, &mut events).show(ui); }); ui.separator(); - if ui.add(Button::image_and_text( - events.layers.icons.exit.egui(), - [18., 18.], - "Return to site editor", - )).clicked() { - events.layers.finish_edit_drawing.send(FinishEditDrawing(None)); + if ui + .add(Button::image_and_text( + events.layers.icons.exit.egui(), + [18., 18.], + "Return to site editor", + )) + .clicked() + { + events + .layers + .finish_edit_drawing + .send(FinishEditDrawing(None)); } }); }); diff --git a/rmf_site_editor/src/widgets/move_layer.rs b/rmf_site_editor/src/widgets/move_layer.rs index 61d45183..2ae4d02a 100644 --- a/rmf_site_editor/src/widgets/move_layer.rs +++ b/rmf_site_editor/src/widgets/move_layer.rs @@ -35,21 +35,21 @@ impl<'a, 'w, 's, T: Component> MoveLayer<'a, 'w, 's, T> { rank_events: &'a mut EventWriter<'w, 's, ChangeRank>, icons: &'a Icons, ) -> Self { - Self { entity, rank_events, icons } + Self { + entity, + rank_events, + icons, + } } pub fn show(self, ui: &mut Ui) { - MoveLayerButton::to_top(self.entity, self.rank_events, self.icons) - .show(ui); + MoveLayerButton::to_top(self.entity, self.rank_events, self.icons).show(ui); - MoveLayerButton::up(self.entity, self.rank_events, self.icons) - .show(ui); + MoveLayerButton::up(self.entity, self.rank_events, self.icons).show(ui); - MoveLayerButton::down(self.entity, self.rank_events, self.icons) - .show(ui); + MoveLayerButton::down(self.entity, self.rank_events, self.icons).show(ui); - MoveLayerButton::to_bottom(self.entity, self.rank_events, self.icons) - .show(ui); + MoveLayerButton::to_bottom(self.entity, self.rank_events, self.icons).show(ui); } } diff --git a/rmf_site_editor/src/widgets/view_layers.rs b/rmf_site_editor/src/widgets/view_layers.rs index 50847891..a7714e74 100644 --- a/rmf_site_editor/src/widgets/view_layers.rs +++ b/rmf_site_editor/src/widgets/view_layers.rs @@ -22,14 +22,42 @@ use crate::{ widgets::{inspector::InspectLayer, AppEvents, Icons, MoveLayer}, }; use bevy::{ecs::system::SystemParam, prelude::*}; -use bevy_egui::egui::{Button, CollapsingHeader, Ui, DragValue, ScrollArea}; +use bevy_egui::egui::{Button, CollapsingHeader, DragValue, ScrollArea, Ui}; #[derive(SystemParam)] pub struct LayersParams<'w, 's> { - pub floors: Query<'w, 's, (&'static RecencyRanking, &'static GlobalFloorVisibility)>, - pub drawings: Query<'w, 's, (&'static RecencyRanking, &'static GlobalDrawingVisibility)>, - pub layer_visibility: Query<'w, 's, (Option<&'static LayerVisibility>, &'static PreferredSemiTransparency)>, - pub levels: Query<'w, 's, (&'static GlobalFloorVisibility, &'static GlobalDrawingVisibility)>, + pub floors: Query< + 'w, + 's, + ( + &'static RecencyRanking, + &'static GlobalFloorVisibility, + ), + >, + pub drawings: Query< + 'w, + 's, + ( + &'static RecencyRanking, + &'static GlobalDrawingVisibility, + ), + >, + pub layer_visibility: Query< + 'w, + 's, + ( + Option<&'static LayerVisibility>, + &'static PreferredSemiTransparency, + ), + >, + pub levels: Query< + 'w, + 's, + ( + &'static GlobalFloorVisibility, + &'static GlobalDrawingVisibility, + ), + >, pub site_id: Query<'w, 's, Option<&'static SiteID>>, pub icons: Res<'w, Icons>, pub selection: Res<'w, Selection>, @@ -51,9 +79,12 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { None => return, }; - let has_drawings = self.params.drawings.get(current_level).ok().is_some_and( - |(ranking, _)| !ranking.is_empty() - ); + let has_drawings = self + .params + .drawings + .get(current_level) + .ok() + .is_some_and(|(ranking, _)| !ranking.is_empty()); if let Ok((ranking, global)) = self.params.floors.get(current_level) { CollapsingHeader::new("Floors") @@ -64,15 +95,19 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { let (text, vis) = if has_drawings { ("Global", &mut shown_global.general) } else { - ("Global (without drawings)", &mut shown_global.without_drawings) + ( + "Global (without drawings)", + &mut shown_global.without_drawings, + ) }; let default_alpha = &mut shown_global.preferred_semi_transparency; self.show_global(text, vis, default_alpha, ui); if shown_global != *global { - self.events.layers.global_floor_vis.send( - Change::new(shown_global, current_level) - ); + self.events + .layers + .global_floor_vis + .send(Change::new(shown_global, current_level)); } }); ui.separator(); @@ -81,8 +116,9 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { MoveLayer::new( selected, &mut self.events.layers.floors, - &self.events.layers.icons - ).show(ui); + &self.events.layers.icons, + ) + .show(ui); }); } ui.separator(); @@ -106,22 +142,23 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { }); ui.horizontal(|ui| { ui.label("Bottom Count").on_hover_text( - "How many of the lowest layer drawings are part of the bottom?" + "How many of the lowest layer drawings are part of the bottom?", ); // ui.with_layer_id(, add_contents) ui.push_id("Bottom Drawing Count", |ui| { ui.add( DragValue::new(&mut shown_global.bottom_count) - .clamp_range(0..=usize::MAX) - .speed(0.05) + .clamp_range(0..=usize::MAX) + .speed(0.05), ); }); }); if shown_global != *global { - self.events.layers.global_drawing_vis.send( - Change::new(shown_global, current_level) - ); + self.events + .layers + .global_drawing_vis + .send(Change::new(shown_global, current_level)); } if let Some(selected) = self.show_rankings(ranking.entities(), false, ui) { @@ -129,8 +166,9 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { MoveLayer::new( selected, &mut self.events.layers.drawings, - &self.events.layers.icons - ).show(ui); + &self.events.layers.icons, + ) + .show(ui); }); } }); @@ -154,11 +192,10 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { } if let LayerVisibility::Alpha(alpha) = vis { - if ui.add( - DragValue::new(alpha) - .clamp_range(0_f32..=1_f32) - .speed(0.01) - ).changed() { + if ui + .add(DragValue::new(alpha).clamp_range(0_f32..=1_f32).speed(0.01)) + .changed() + { *default_alpha = *alpha; } } @@ -172,8 +209,7 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { ) -> Option { let mut layer_selected = None; ui.vertical(|ui| { - ScrollArea::vertical() - .show(ui, |ui| { + ScrollArea::vertical().show(ui, |ui| { for e in ranking.iter().rev() { let mut as_selected = false; if self.params.selection.0.is_some_and(|sel| sel == *e) { @@ -190,9 +226,9 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewLayers<'a, 'w1, 's1, 'w2, 's2> { alpha.0, is_floor, ) - .with_selecting(self.params.site_id.get(*e).ok().flatten().copied()) - .as_selected(as_selected) - .show(ui); + .with_selecting(self.params.site_id.get(*e).ok().flatten().copied()) + .as_selected(as_selected) + .show(ui); }); } }); diff --git a/rmf_site_editor/src/widgets/view_nav_graphs.rs b/rmf_site_editor/src/widgets/view_nav_graphs.rs index 87f98333..85bc05ef 100644 --- a/rmf_site_editor/src/widgets/view_nav_graphs.rs +++ b/rmf_site_editor/src/widgets/view_nav_graphs.rs @@ -16,15 +16,15 @@ */ use crate::{ + interaction::Selection, recency::RecencyRanking, site::{ - Change, Delete, DisplayColor, ImportNavGraphs, NameInSite, NavGraph, NavGraphMarker, - SaveNavGraphs, NameOfSite, DEFAULT_NAV_GRAPH_COLORS, SiteID, + Change, Delete, DisplayColor, ImportNavGraphs, NameInSite, NameOfSite, NavGraph, + NavGraphMarker, SaveNavGraphs, SiteID, DEFAULT_NAV_GRAPH_COLORS, }, - interaction::Selection, widgets::{ inspector::{color_edit, selection_widget::SelectionWidget}, - AppEvents, Icons, MoveLayerButton + AppEvents, Icons, MoveLayerButton, }, Autoload, CurrentWorkspace, }; @@ -187,12 +187,7 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewNavGraphs<'a, 'w1, 's1, 'w2, 's2> { } } - SelectionWidget::new( - e, - site_id.copied(), - &self.params.icons, - self.events, - ).show(ui); + SelectionWidget::new(e, site_id.copied(), &self.params.icons, self.events).show(ui); let mut new_color = color.0; color_edit(ui, &mut new_color); @@ -215,21 +210,21 @@ impl<'a, 'w1, 's1, 'w2, 's2> ViewNavGraphs<'a, 'w1, 's1, 'w2, 's2> { if let Some(e) = selected_graph { ui.horizontal(|ui| { - MoveLayerButton::to_top( - e, &mut self.events.layers.nav_graphs, &self.params.icons - ).show(ui); + MoveLayerButton::to_top(e, &mut self.events.layers.nav_graphs, &self.params.icons) + .show(ui); - MoveLayerButton::up( - e, &mut self.events.layers.nav_graphs, &self.params.icons - ).show(ui); + MoveLayerButton::up(e, &mut self.events.layers.nav_graphs, &self.params.icons) + .show(ui); - MoveLayerButton::down( - e, &mut self.events.layers.nav_graphs, &self.params.icons - ).show(ui); + MoveLayerButton::down(e, &mut self.events.layers.nav_graphs, &self.params.icons) + .show(ui); MoveLayerButton::to_bottom( - e, &mut self.events.layers.nav_graphs, &self.params.icons - ).show(ui); + e, + &mut self.events.layers.nav_graphs, + &self.params.icons, + ) + .show(ui); }); } diff --git a/rmf_site_editor/src/workcell/load.rs b/rmf_site_editor/src/workcell/load.rs index 87ad64f9..92f25997 100644 --- a/rmf_site_editor/src/workcell/load.rs +++ b/rmf_site_editor/src/workcell/load.rs @@ -27,8 +27,8 @@ use bevy::prelude::*; use std::collections::HashSet; use rmf_site_format::{ - Category, ConstraintDependents, MeshConstraint, NameInWorkcell, SiteID, - WorkcellCollisionMarker, WorkcellVisualMarker, Workcell, + Category, ConstraintDependents, MeshConstraint, NameInWorkcell, SiteID, Workcell, + WorkcellCollisionMarker, WorkcellVisualMarker, }; pub struct LoadWorkcell { @@ -40,10 +40,7 @@ pub struct LoadWorkcell { pub default_file: Option, } -fn generate_workcell_entities( - commands: &mut Commands, - workcell: &Workcell, -) -> Entity { +fn generate_workcell_entities(commands: &mut Commands, workcell: &Workcell) -> Entity { // Create hashmap of ids to entity to correctly generate hierarchy let mut id_to_entity = HashMap::new(); // Hashmap of parent id to list of its children entities diff --git a/rmf_site_editor/src/workspace.rs b/rmf_site_editor/src/workspace.rs index d88880b9..371ee92f 100644 --- a/rmf_site_editor/src/workspace.rs +++ b/rmf_site_editor/src/workspace.rs @@ -25,7 +25,7 @@ use crate::site::LoadSite; use crate::workcell::LoadWorkcell; use crate::AppState; use rmf_site_format::legacy::building_map::BuildingMap; -use rmf_site_format::{Level, Site, SiteProperties, Workcell, NameOfSite}; +use rmf_site_format::{Level, NameOfSite, Site, SiteProperties, Workcell}; use crossbeam_channel::{Receiver, Sender}; diff --git a/rmf_site_format/src/alignment.rs b/rmf_site_format/src/alignment.rs index 14f0750b..4efca465 100644 --- a/rmf_site_format/src/alignment.rs +++ b/rmf_site_format/src/alignment.rs @@ -1,6 +1,6 @@ use super::legacy::building_map::BuildingMap; use crate::RefTrait; -use glam::{DMat2, DVec2, DAffine2}; +use glam::{DAffine2, DMat2, DVec2}; use std::collections::HashMap; pub struct SiteVariables { @@ -26,11 +26,7 @@ pub struct DrawingVariables { } impl DrawingVariables { - pub fn new( - position: DVec2, - yaw: f64, - scale: f64, - ) -> Self { + pub fn new(position: DVec2, yaw: f64, scale: f64) -> Self { Self { position, yaw, @@ -69,9 +65,7 @@ impl Alignment { } } -pub fn align_site( - site_variables: &SiteVariables, -) -> HashMap { +pub fn align_site(site_variables: &SiteVariables) -> HashMap { let mut drawing_map = HashMap::new(); let mut measurements = Vec::new(); let mut fiducials = Vec::new(); @@ -431,18 +425,15 @@ fn calculate_yaw_gradient( let mut weight = 0.0; - traverse_yaws( - fiducials, u, - |i, yaw_i, j, yaw_j| { - if !(has_ground_truth && i == 0) { - *LevelGradient::new(i, gradient).theta() += yaw_i - yaw_j; - weight += 1.0; - } - - *LevelGradient::new(j, gradient).theta() += yaw_j - yaw_i; + traverse_yaws(fiducials, u, |i, yaw_i, j, yaw_j| { + if !(has_ground_truth && i == 0) { + *LevelGradient::new(i, gradient).theta() += yaw_i - yaw_j; weight += 1.0; } - ); + + *LevelGradient::new(j, gradient).theta() += yaw_j - yaw_i; + weight += 1.0; + }); for x in gradient.iter_mut() { *x /= f64::max(weight, 1.0); @@ -494,23 +485,20 @@ fn calculate_displacement_gradient( let mut weight = 0.0; - traverse_locations( - fiducials, u, - |i, f_ki, j, f_kj| { - let delta = f_ki - f_kj; - if !(has_ground_truth && i == 0) { - let mut grad_i = LevelGradient::new(i, gradient); - *grad_i.dx() += delta.x; - *grad_i.dy() += delta.y; - weight += 1.0; - } - - let mut grad_j = LevelGradient::new(j, gradient); - *grad_j.dx() += -delta.x; - *grad_j.dy() += -delta.y; + traverse_locations(fiducials, u, |i, f_ki, j, f_kj| { + let delta = f_ki - f_kj; + if !(has_ground_truth && i == 0) { + let mut grad_i = LevelGradient::new(i, gradient); + *grad_i.dx() += delta.x; + *grad_i.dy() += delta.y; weight += 1.0; } - ); + + let mut grad_j = LevelGradient::new(j, gradient); + *grad_j.dx() += -delta.x; + *grad_j.dy() += -delta.y; + weight += 1.0; + }); for x in gradient.iter_mut() { *x /= f64::max(weight, 1.0); diff --git a/rmf_site_format/src/drawing.rs b/rmf_site_format/src/drawing.rs index 885c88d8..14aad717 100644 --- a/rmf_site_format/src/drawing.rs +++ b/rmf_site_format/src/drawing.rs @@ -17,7 +17,7 @@ use crate::*; #[cfg(feature = "bevy")] -use bevy::prelude::{Component, Bundle}; +use bevy::prelude::{Bundle, Component}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; @@ -50,7 +50,10 @@ pub struct DrawingProperties { pub source: AssetSource, pub pose: Pose, pub pixels_per_meter: PixelsPerMeter, - #[serde(default = "PreferredSemiTransparency::for_drawing", skip_serializing_if = "PreferredSemiTransparency::is_default_for_drawing")] + #[serde( + default = "PreferredSemiTransparency::for_drawing", + skip_serializing_if = "PreferredSemiTransparency::is_default_for_drawing" + )] pub preferred_semi_transparency: PreferredSemiTransparency, } diff --git a/rmf_site_format/src/fiducial.rs b/rmf_site_format/src/fiducial.rs index 74cac0c1..ed7c5c26 100644 --- a/rmf_site_format/src/fiducial.rs +++ b/rmf_site_format/src/fiducial.rs @@ -15,7 +15,7 @@ * */ -use crate::{NameInSite, Point, RefTrait, Affiliation, Group}; +use crate::{Affiliation, Group, NameInSite, Point, RefTrait}; #[cfg(feature = "bevy")] use bevy::prelude::{Bundle, Component, Entity}; use serde::{Deserialize, Serialize}; diff --git a/rmf_site_format/src/floor.rs b/rmf_site_format/src/floor.rs index 6060ac08..429df8ce 100644 --- a/rmf_site_format/src/floor.rs +++ b/rmf_site_format/src/floor.rs @@ -26,7 +26,10 @@ pub struct Floor { pub anchors: Path, #[serde(default, skip_serializing_if = "is_default")] pub texture: Texture, - #[serde(default = "PreferredSemiTransparency::for_floor", skip_serializing_if = "PreferredSemiTransparency::is_default_for_floor")] + #[serde( + default = "PreferredSemiTransparency::for_floor", + skip_serializing_if = "PreferredSemiTransparency::is_default_for_floor" + )] pub preferred_semi_transparency: PreferredSemiTransparency, #[serde(skip)] pub marker: FloorMarker, diff --git a/rmf_site_format/src/layer.rs b/rmf_site_format/src/layer.rs index a384f0d0..8eaab0d8 100644 --- a/rmf_site_format/src/layer.rs +++ b/rmf_site_format/src/layer.rs @@ -17,10 +17,10 @@ #[cfg(feature = "bevy")] use bevy::prelude::Component; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "bevy", derive(Component))] +#[cfg_attr(feature = "bevy", derive(Component))] pub enum LayerVisibility { /// The layer is fully opaque. This is the default for floors when no drawing is /// present. @@ -116,14 +116,23 @@ impl VisibilityCycle for Option { pub struct GlobalFloorVisibility { /// The global visibility that will be applied to all floors when a drawing /// is not present on the level - #[serde(default = "default_floor_without_drawings_visibility", skip_serializing_if = "LayerVisibility::is_opaque")] + #[serde( + default = "default_floor_without_drawings_visibility", + skip_serializing_if = "LayerVisibility::is_opaque" + )] pub without_drawings: LayerVisibility, /// The global visibility that will be applied to all floors when at least /// one drawing is present on the same level. - #[serde(default = "default_floor_general_visibility", skip_serializing_if = "LayerVisibility::is_floor_general_default")] + #[serde( + default = "default_floor_general_visibility", + skip_serializing_if = "LayerVisibility::is_floor_general_default" + )] pub general: LayerVisibility, /// The user's preference for semi-transparency values for floors - #[serde(default = "default_floor_semi_transparency", skip_serializing_if = "is_default_floor_semi_transparency")] + #[serde( + default = "default_floor_semi_transparency", + skip_serializing_if = "is_default_floor_semi_transparency" + )] pub preferred_semi_transparency: f32, } @@ -161,20 +170,35 @@ fn default_floor_general_visibility() -> LayerVisibility { pub struct GlobalDrawingVisibility { /// The global visibility that will be applied to the bottom-most drawings /// in the ranking. - #[serde(default = "default_bottom_drawing_visibility", skip_serializing_if = "LayerVisibility::is_opaque")] + #[serde( + default = "default_bottom_drawing_visibility", + skip_serializing_if = "LayerVisibility::is_opaque" + )] pub bottom: LayerVisibility, /// The user's preference for semi-transparency values for bottom drawings - #[serde(default = "default_drawing_semi_transparency", skip_serializing_if = "is_default_drawing_semi_transparency")] + #[serde( + default = "default_drawing_semi_transparency", + skip_serializing_if = "is_default_drawing_semi_transparency" + )] pub preferred_bottom_semi_transparency: f32, /// How many of the bottom-most drawings count as being on the bottom - #[serde(default = "default_bottom_drawing_count", skip_serializing_if = "is_default_bottom_drawing_count")] + #[serde( + default = "default_bottom_drawing_count", + skip_serializing_if = "is_default_bottom_drawing_count" + )] pub bottom_count: usize, /// The global visibility that will be applied to all drawings which are not /// on the bottom. - #[serde(default = "default_general_drawing_visibility", skip_serializing_if = "is_default_drawing_visibility")] + #[serde( + default = "default_general_drawing_visibility", + skip_serializing_if = "is_default_drawing_visibility" + )] pub general: LayerVisibility, /// The user's preference for semi-transparency values for general drawings - #[serde(default = "default_drawing_semi_transparency", skip_serializing_if = "is_default_drawing_semi_transparency")] + #[serde( + default = "default_drawing_semi_transparency", + skip_serializing_if = "is_default_drawing_semi_transparency" + )] pub preferred_general_semi_transparency: f32, } diff --git a/rmf_site_format/src/legacy/building_map.rs b/rmf_site_format/src/legacy/building_map.rs index 98248fcc..4bfceb58 100644 --- a/rmf_site_format/src/legacy/building_map.rs +++ b/rmf_site_format/src/legacy/building_map.rs @@ -1,12 +1,12 @@ use super::{level::Level, lift::Lift, PortingError, Result}; use crate::{ - alignment::align_legacy_building, Anchor, Angle, AssetSource, AssociatedGraphs, - DisplayColor, Dock as SiteDock, Drawing as SiteDrawing, Fiducial as SiteFiducial, - FiducialMarker, Guided, Lane as SiteLane, LaneMarker, Level as SiteLevel, - LevelProperties as SiteLevelProperties, Motion, NameInSite, NavGraph, Navigation, - OrientationConstraint, PixelsPerMeter, Pose, RankingsInLevel, ReverseLane, Rotation, Site, - SiteProperties, DEFAULT_NAV_GRAPH_COLORS, LevelElevation, NameOfSite, - DrawingProperties, PreferredSemiTransparency, FiducialGroup, Affiliation, + alignment::align_legacy_building, Affiliation, Anchor, Angle, AssetSource, AssociatedGraphs, + DisplayColor, Dock as SiteDock, Drawing as SiteDrawing, DrawingProperties, + Fiducial as SiteFiducial, FiducialGroup, FiducialMarker, Guided, Lane as SiteLane, LaneMarker, + Level as SiteLevel, LevelElevation, LevelProperties as SiteLevelProperties, Motion, NameInSite, + NameOfSite, NavGraph, Navigation, OrientationConstraint, PixelsPerMeter, Pose, + PreferredSemiTransparency, RankingsInLevel, ReverseLane, Rotation, Site, SiteProperties, + DEFAULT_NAV_GRAPH_COLORS, }; use glam::{DAffine2, DMat3, DQuat, DVec2, DVec3, EulerRot}; use serde::{Deserialize, Serialize}; @@ -227,7 +227,7 @@ impl BuildingMap { // Use this transform to create anchors that pin the main // drawing to where it belongs in Cartesian coordinates. let drawing_tf = DAffine2::from_scale_angle_translation( - DVec2::splat(1.0/pixels_per_meter.0 as f64), + DVec2::splat(1.0 / pixels_per_meter.0 as f64), pose.trans[2] as f64, DVec2::new(pose.trans[0] as f64, pose.trans[1] as f64), ); @@ -237,34 +237,32 @@ impl BuildingMap { // Do not add this anchor to the vertex_to_anchor_id map // because this fiducial is not really recognized as a // vertex to the building format. - drawing_anchors.insert( - anchor_id, - [fiducial.0 as f32, fiducial.1 as f32].into() - ); + drawing_anchors + .insert(anchor_id, [fiducial.0 as f32, fiducial.1 as f32].into()); let affiliation = if fiducial.2.is_empty() { // We assume an empty reference name means this fiducial // is not really being used. Affiliation(None) } else { let name = &fiducial.2; - let group_id = if let Some((group_id, _)) = fiducial_groups.iter().find( - |(_, group)| group.name.0 == *name - ) { + let group_id = if let Some((group_id, _)) = fiducial_groups + .iter() + .find(|(_, group)| group.name.0 == *name) + { // The group already exists *group_id } else { // The group does not exist yet, so let's create it let group_id = site_id.next().unwrap(); - fiducial_groups.insert( - group_id, - FiducialGroup::new(NameInSite(name.clone())), - ); + fiducial_groups + .insert(group_id, FiducialGroup::new(NameInSite(name.clone()))); group_id }; let drawing_coords = DVec2::new(fiducial.0, fiducial.1); - cartesian_fiducials.entry(group_id).or_default().push( - drawing_tf.transform_point2(drawing_coords) - ); + cartesian_fiducials + .entry(group_id) + .or_default() + .push(drawing_tf.transform_point2(drawing_coords)); Affiliation(Some(group_id)) }; @@ -284,10 +282,7 @@ impl BuildingMap { // building format. let anchor_id = site_id.next().unwrap(); let fiducial_id = site_id.next().unwrap(); - drawing_anchors.insert( - anchor_id, - [feature.x as f32, feature.y as f32].into() - ); + drawing_anchors.insert(anchor_id, [feature.x as f32, feature.y as f32].into()); drawing_fiducials.insert( fiducial_id, @@ -298,12 +293,15 @@ impl BuildingMap { }, ); - feature_info.insert(feature.id.clone(), FeatureInfo { - fiducial_id, - on_anchor: anchor_id, - in_drawing: primary_drawing_id, - name: (!feature.name.is_empty()).then(|| feature.name.clone()), - }); + feature_info.insert( + feature.id.clone(), + FeatureInfo { + fiducial_id, + on_anchor: anchor_id, + in_drawing: primary_drawing_id, + name: (!feature.name.is_empty()).then(|| feature.name.clone()), + }, + ); } let mut measurements = BTreeMap::new(); @@ -365,10 +363,7 @@ impl BuildingMap { // building format. let anchor_id = site_id.next().unwrap(); let fiducial_id = site_id.next().unwrap(); - drawing_anchors.insert( - anchor_id, - [feature.x as f32, feature.y as f32].into() - ); + drawing_anchors.insert(anchor_id, [feature.x as f32, feature.y as f32].into()); drawing_fiducials.insert( fiducial_id, @@ -379,12 +374,15 @@ impl BuildingMap { }, ); - feature_info.insert(feature.id.clone(), FeatureInfo { - fiducial_id, - on_anchor: anchor_id, - in_drawing: drawing_id, - name: (!feature.name.is_empty()).then(|| feature.name.clone()), - }); + feature_info.insert( + feature.id.clone(), + FeatureInfo { + fiducial_id, + on_anchor: anchor_id, + in_drawing: drawing_id, + name: (!feature.name.is_empty()).then(|| feature.name.clone()), + }, + ); } drawings.insert( @@ -406,13 +404,17 @@ impl BuildingMap { for (i, constraint) in level.constraints.iter().enumerate() { let fiducial_group_id = site_id.next().unwrap(); - let group_name = constraint.ids.iter().find_map(|id| { - if let Some(info) = feature_info.get(id) { - info.name.clone() - } else { - None - } - }).unwrap_or_else(|| format!("{}_constraint_{i}", level_name)); + let group_name = constraint + .ids + .iter() + .find_map(|id| { + if let Some(info) = feature_info.get(id) { + info.name.clone() + } else { + None + } + }) + .unwrap_or_else(|| format!("{}_constraint_{i}", level_name)); fiducial_groups.insert( fiducial_group_id, FiducialGroup::new(NameInSite(group_name)), @@ -572,12 +574,13 @@ impl BuildingMap { ); } - let cartesian_fiducials: BTreeMap> = cartesian_fiducials.into_iter().map( - |(group_id, locations)| { - let p = locations.iter().fold( - DVec2::ZERO, - |base, next| base + *next - ) / locations.len() as f64; + let cartesian_fiducials: BTreeMap> = cartesian_fiducials + .into_iter() + .map(|(group_id, locations)| { + let p = locations + .iter() + .fold(DVec2::ZERO, |base, next| base + *next) + / locations.len() as f64; let anchor_id = site_id.next().unwrap(); site_anchors.insert(anchor_id, [p.x as f32, p.y as f32].into()); let fiducial_id = site_id.next().unwrap(); @@ -587,10 +590,10 @@ impl BuildingMap { anchor: anchor_id.into(), affiliation: Affiliation(Some(group_id)), marker: FiducialMarker, - } + }, ) - } - ).collect(); + }) + .collect(); Ok(Site { format_version: Default::default(), diff --git a/rmf_site_format/src/legacy/floor.rs b/rmf_site_format/src/legacy/floor.rs index d3211e4d..4417d43a 100644 --- a/rmf_site_format/src/legacy/floor.rs +++ b/rmf_site_format/src/legacy/floor.rs @@ -1,5 +1,8 @@ use super::{rbmf::*, PortingError, Result}; -use crate::{Angle, CustomTexture, Floor as SiteFloor, FloorMarker, Path, Texture, TextureSource, PreferredSemiTransparency}; +use crate::{ + Angle, CustomTexture, Floor as SiteFloor, FloorMarker, Path, PreferredSemiTransparency, + Texture, TextureSource, +}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/rmf_site_format/src/legacy/level.rs b/rmf_site_format/src/legacy/level.rs index 10eff012..676af40e 100644 --- a/rmf_site_format/src/legacy/level.rs +++ b/rmf_site_format/src/legacy/level.rs @@ -1,8 +1,7 @@ use super::{ - super::Light, door::Door, fiducial::Fiducial, floor::Floor, lane::Lane, - measurement::Measurement, model::Model, physical_camera::PhysicalCamera, vertex::Vertex, - wall::Wall, - super::alignment::Alignment, + super::alignment::Alignment, super::Light, door::Door, fiducial::Fiducial, floor::Floor, + lane::Lane, measurement::Measurement, model::Model, physical_camera::PhysicalCamera, + vertex::Vertex, wall::Wall, }; use glam::DVec2; use serde::{Deserialize, Serialize}; diff --git a/rmf_site_format/src/legacy/nav_graph.rs b/rmf_site_format/src/legacy/nav_graph.rs index ea356035..026aea54 100644 --- a/rmf_site_format/src/legacy/nav_graph.rs +++ b/rmf_site_format/src/legacy/nav_graph.rs @@ -84,7 +84,10 @@ impl NavGraph { } } - levels.insert(level.properties.name.clone().0, NavLevel { lanes, vertices }); + levels.insert( + level.properties.name.clone().0, + NavLevel { lanes, vertices }, + ); } graphs.push(( diff --git a/rmf_site_format/src/level.rs b/rmf_site_format/src/level.rs index b3b51f65..b4486773 100644 --- a/rmf_site_format/src/level.rs +++ b/rmf_site_format/src/level.rs @@ -43,7 +43,6 @@ impl Default for LevelProperties { } } - #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[serde(transparent)] #[cfg_attr(feature = "bevy", derive(Component, Deref, DerefMut))] diff --git a/rmf_site_format/src/misc.rs b/rmf_site_format/src/misc.rs index c3843ca6..5c6bc50a 100644 --- a/rmf_site_format/src/misc.rs +++ b/rmf_site_format/src/misc.rs @@ -477,7 +477,10 @@ impl Default for Affiliation { #[cfg(feature = "bevy")] impl Affiliation { - pub fn to_ecs(&self, id_to_entity: &std::collections::HashMap) -> Affiliation { + pub fn to_ecs( + &self, + id_to_entity: &std::collections::HashMap, + ) -> Affiliation { Affiliation(self.0.map(|a| *id_to_entity.get(&a).unwrap())) } } diff --git a/rmf_site_format/src/site.rs b/rmf_site_format/src/site.rs index b3a0f34d..832cf080 100644 --- a/rmf_site_format/src/site.rs +++ b/rmf_site_format/src/site.rs @@ -17,9 +17,9 @@ use crate::*; #[cfg(feature = "bevy")] -use bevy::prelude::{Component, Bundle, Entity, Deref, DerefMut}; +use bevy::prelude::{Bundle, Component, Deref, DerefMut, Entity}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, io, hash::Hash}; +use std::{collections::BTreeMap, hash::Hash, io}; pub use ron::ser::PrettyConfig as Style;