Skip to content

Commit

Permalink
Fix style
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <[email protected]>
  • Loading branch information
mxgrey committed Jul 24, 2023
1 parent b9a2897 commit a8a25f7
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 132 deletions.
1 change: 0 additions & 1 deletion rmf_site_editor/src/site/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ fn generate_site_entities(commands: &mut Commands, site_data: &rmf_site_format::
.id();
id_to_entity.insert(*location_id, location);
consider_id(*location_id);

}

for (robot_id, robot) in &site_data.models.mobile_robots {
Expand Down
27 changes: 10 additions & 17 deletions rmf_site_editor/src/site/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
*/

use rmf_site_format::{AssetSource, Scale};
use bevy::{
prelude::*,
ecs::system::{Command, EntityCommands},
prelude::*,
};
use rmf_site_format::{AssetSource, Scale};

#[derive(Component, Clone, Copy)]
pub struct InScenario(pub Entity);
Expand All @@ -35,7 +35,7 @@ impl ModelSource {
#[derive(Component, Clone)]
pub struct ModelInstances(Vec<Entity>);
impl ModelInstances {
pub fn iter(&self) -> impl Iterator<Item=&Entity> {
pub fn iter(&self) -> impl Iterator<Item = &Entity> {
self.0.iter()
}
}
Expand Down Expand Up @@ -78,14 +78,12 @@ impl Command for ChangeModelSource {
error!(
"Cannot change model source of instance {:?} to {:?} because \
that source no longer exists",
self.instance,
self.source,
self.instance, self.source,
);

if let (Some(mut e), Some(prev)) = (
world.get_entity_mut(self.instance),
previous_source
) {
if let (Some(mut e), Some(prev)) =
(world.get_entity_mut(self.instance), previous_source)
{
e.insert(ModelSource(prev));
}
return;
Expand Down Expand Up @@ -127,26 +125,21 @@ fn handle_changed_model_sources(
for change in changed_instances.iter() {
let Some(mut instance) = commands.get_entity(change.source) else { continue };
let Ok((source, scale)) = sources.get(change.source) else { continue };
instance
.insert(source.clone())
.insert(scale.clone());
instance.insert(source.clone()).insert(scale.clone());
}

for (instances, source, scale) in &changed_sources {
for instance in instances.iter() {
let Some(mut instance) = commands.get_entity(*instance) else { continue };
instance
.insert(source.clone())
.insert(scale.clone());
instance.insert(source.clone()).insert(scale.clone());
}
}
}

pub struct ModelSourcePlugin;
impl Plugin for ModelSourcePlugin {
fn build(&self, app: &mut App) {
app
.add_event::<ChangeModelSource>()
app.add_event::<ChangeModelSource>()
.add_system(handle_changed_model_sources);
}
}
110 changes: 53 additions & 57 deletions rmf_site_editor/src/site/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,24 +860,16 @@ fn generate_scenarios(
) -> Result<(BTreeMap<u32, Scenario>, Models), SiteGenerationError> {
let models = {
let mut state: SystemState<(
Query<(
&NameInSite,
&AssetSource,
&Scale,
&MobileRobotKinematics,
&SiteID,
&Parent,
)>,
Query<
(
&NameInSite,
&AssetSource,
&Scale,
&MobileRobotKinematics,
&SiteID,
&Parent,
)
>,
Query<
(
&NameInSite,
&AssetSource,
&Scale,
&SiteID,
&Parent,
),
(&NameInSite, &AssetSource, &Scale, &SiteID, &Parent),
With<StationaryRobotMarker>,
>,
)> = SystemState::new(world);
Expand All @@ -889,49 +881,47 @@ fn generate_scenarios(
continue;
}

models.mobile_robots.insert(site_id.0, MobileRobot {
model_name: model_name.clone(),
source: source.clone(),
scale: scale.clone(),
kinematics: kinematics.clone(),
});
models.mobile_robots.insert(
site_id.0,
MobileRobot {
model_name: model_name.clone(),
source: source.clone(),
scale: scale.clone(),
kinematics: kinematics.clone(),
},
);
}

for (model_name, source, scale, site_id, parent) in &q_stationary {
if parent.get() != site {
continue;
}

models.workcells.insert(site_id.0, StationaryRobot {
model_name: model_name.clone(),
source: source.clone(),
scale: scale.clone(),
marker: StationaryRobotMarker,
});
models.workcells.insert(
site_id.0,
StationaryRobot {
model_name: model_name.clone(),
source: source.clone(),
scale: scale.clone(),
marker: StationaryRobotMarker,
},
);
}

models
};

let scenarios = {
let mut state: SystemState<(
Query<
(
&ScenarioProperties,
&SiteID,
&Parent,
)
>,
Query<
(
&NameInSite,
&Pose,
&Parent,
&ModelSource,
&InScenario,
&SiteID,
)
>,
Query<(&ScenarioProperties, &SiteID, &Parent)>,
Query<(
&NameInSite,
&Pose,
&Parent,
&ModelSource,
&InScenario,
&SiteID,
)>,
Query<&SiteID>,
)> = SystemState::new(world);

Expand All @@ -943,10 +933,13 @@ fn generate_scenarios(
continue;
}

scenarios.insert(site_id.0, Scenario {
properties: properties.clone(),
instances: BTreeMap::new(),
});
scenarios.insert(
site_id.0,
Scenario {
properties: properties.clone(),
instances: BTreeMap::new(),
},
);
}

for (name, pose, parent, model, in_scenario, site_id) in &q_instances {
Expand Down Expand Up @@ -984,14 +977,17 @@ fn generate_scenarios(
);
}

scenario.instances.insert(site_id.0, Instance {
parent,
model,
bundle: InstanceBundle {
name: name.clone(),
pose: pose.clone()
scenario.instances.insert(
site_id.0,
Instance {
parent,
model,
bundle: InstanceBundle {
name: name.clone(),
pose: pose.clone(),
},
},
});
);
}

scenarios
Expand Down
42 changes: 20 additions & 22 deletions rmf_site_editor/src/widgets/inspector/inspect_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,28 @@ impl<'a, 'w1, 'w2, 's2> InspectLocationWidget<'a, 'w1, 'w2, 's2> {

pub fn show(self, ui: &mut Ui) -> Option<LocationTags> {
ui.label(RichText::new("Location Tags").size(18.0));
let changed_charger = InspectOptionString::new(
"Charger",
&self.tags.charger,
&self.recall.recall_charger,
).multiline().default("").show(ui);
let changed_parking = InspectOptionString::new(
"Parking",
&self.tags.parking,
&self.recall.recall_parking,
).multiline().default("").show(ui);
let changed_holding = InspectOptionString::new(
"Holding",
&self.tags.holding,
&self.recall.recall_holding,
).multiline().default("").show(ui);
let changed_charger =
InspectOptionString::new("Charger", &self.tags.charger, &self.recall.recall_charger)
.multiline()
.default("")
.show(ui);
let changed_parking =
InspectOptionString::new("Parking", &self.tags.parking, &self.recall.recall_parking)
.multiline()
.default("")
.show(ui);
let changed_holding =
InspectOptionString::new("Holding", &self.tags.holding, &self.recall.recall_holding)
.multiline()
.default("")
.show(ui);

if changed_charger.is_some() || changed_parking.is_some() || changed_holding.is_some() {
return Some(
LocationTags {
charger: changed_charger.unwrap_or_else(|| self.tags.charger.clone()),
parking: changed_parking.unwrap_or_else(|| self.tags.parking.clone()),
holding: changed_holding.unwrap_or_else(|| self.tags.holding.clone()),
}
)
return Some(LocationTags {
charger: changed_charger.unwrap_or_else(|| self.tags.charger.clone()),
parking: changed_parking.unwrap_or_else(|| self.tags.parking.clone()),
holding: changed_holding.unwrap_or_else(|| self.tags.holding.clone()),
});
}

return None;
Expand Down
5 changes: 2 additions & 3 deletions rmf_site_editor/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ use crate::{
occupancy::CalculateGrid,
recency::ChangeRank,
site::{
AssociatedGraphs, Change, ConsiderAssociatedGraph, CurrentLevel,
Delete, ExportLights, FloorVisibility, PhysicalLightToggle, SaveNavGraphs, SiteState,
ToggleLiftDoorAvailability,
AssociatedGraphs, Change, ConsiderAssociatedGraph, CurrentLevel, Delete, ExportLights,
FloorVisibility, PhysicalLightToggle, SaveNavGraphs, SiteState, ToggleLiftDoorAvailability,
},
AppState, CreateNewWorkspace, CurrentWorkspace, LoadWorkspace, SaveWorkspace,
};
Expand Down
25 changes: 12 additions & 13 deletions rmf_site_format/src/legacy/building_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use super::{level::Level, lift::Lift, PortingError, Result};
use crate::{
legacy::optimization::align_building, Anchor, Angle, AssetSource, AssociatedGraphs,
DisplayColor, Dock as SiteDock, Drawing as SiteDrawing, DrawingMarker,
Fiducial as SiteFiducial, FiducialMarker, Guided, Label, 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, Models, Instance,
Scenario, ScenarioProperties,
Fiducial as SiteFiducial, FiducialMarker, Guided, Instance, Label, Lane as SiteLane,
LaneMarker, Level as SiteLevel, LevelProperties as SiteLevelProperties, Models, Motion,
NameInSite, NavGraph, Navigation, OrientationConstraint, PixelsPerMeter, Pose, RankingsInLevel,
ReverseLane, Rotation, Scenario, ScenarioProperties, Site, SiteProperties,
DEFAULT_NAV_GRAPH_COLORS,
};
use glam::{DAffine2, DMat3, DQuat, DVec2, DVec3, EulerRot};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -173,12 +173,9 @@ impl BuildingMap {
locations.insert(site_id.next().unwrap(), location);
}

if let Some(instance) = v.make_instance(
&mut site_id,
&mut model_source_map,
&mut models,
anchor_id,
) {
if let Some(instance) =
v.make_instance(&mut site_id, &mut model_source_map, &mut models, anchor_id)
{
let instance_id = site_id.next().unwrap();
instances.insert(instance_id, instance);
}
Expand Down Expand Up @@ -394,9 +391,11 @@ impl BuildingMap {
scenarios.insert(
default_scenario_id,
Scenario {
properties: ScenarioProperties { name: "Default Scenario".to_owned() },
properties: ScenarioProperties {
name: "Default Scenario".to_owned(),
},
instances,
}
},
);

Ok(Site {
Expand Down
27 changes: 13 additions & 14 deletions rmf_site_format/src/legacy/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use super::rbmf::*;
use crate::{
is_default, AssetSource, AssociatedGraphs, ConstraintDependents, IsStatic,
Location, LocationTags, Model, ModelMarker, NameInSite, Pose, Scale,
Instance, InstanceBundle, Models, MobileRobot, MobileRobotKinematics,
DifferentialDrive,
is_default, AssetSource, AssociatedGraphs, ConstraintDependents, DifferentialDrive, Instance,
InstanceBundle, IsStatic, Location, LocationTags, MobileRobot, MobileRobotKinematics, Model,
ModelMarker, Models, NameInSite, Pose, Scale,
};
use glam::DVec2;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -94,7 +93,7 @@ impl Vertex {
bundle: InstanceBundle {
name: NameInSite(me.spawn_robot_name.1.clone()),
pose: Pose::default(),
}
},
});
}

Expand All @@ -103,15 +102,15 @@ impl Vertex {
let model_id = new_site_id.next().unwrap();
let mobile_robot = MobileRobot {
model_name: NameInSite(me.spawn_robot_type.1.clone()),
source: AssetSource::Search("OpenRobotics/".to_owned() + &me.spawn_robot_type.1.clone()),
source: AssetSource::Search(
"OpenRobotics/".to_owned() + &me.spawn_robot_type.1.clone(),
),
scale: Scale::default(),
kinematics: MobileRobotKinematics::DifferentialDrive(
DifferentialDrive {
translational_speed: 0.5,
rotational_speed: 0.6,
bidirectional: false,
}
)
kinematics: MobileRobotKinematics::DifferentialDrive(DifferentialDrive {
translational_speed: 0.5,
rotational_speed: 0.6,
bidirectional: false,
}),
};

models.mobile_robots.insert(model_id, mobile_robot);
Expand All @@ -122,7 +121,7 @@ impl Vertex {
bundle: InstanceBundle {
name: NameInSite(me.spawn_robot_name.1.clone()),
pose: Pose::default(),
}
},
});
}

Expand Down
Loading

0 comments on commit a8a25f7

Please sign in to comment.