rmf_site_editor 0.0.3

File format parsing for rmf_site_editor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
 * Copyright (C) 2022 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

pub mod anchor;
pub use anchor::*;

pub mod assets;
pub use assets::*;

pub mod change_plugin;
pub use change_plugin::*;

pub mod deletion;
pub use deletion::*;

pub mod display_color;
pub use display_color::*;

pub mod drawing_editor;
pub use drawing_editor::{alignment, *};

pub mod door;
pub use door::*;

pub mod drawing;
pub use drawing::*;

pub mod extension_hooks;
pub use extension_hooks::*;

pub mod fiducial;
pub use fiducial::*;

pub mod floor;
pub use floor::*;

pub mod fuel_cache;
pub use fuel_cache::*;

pub mod georeference;
pub use georeference::*;

pub mod group;
pub use group::*;

pub mod headless_export;
pub use headless_export::*;

pub mod inclusion;
pub use inclusion::*;

pub mod lane;
pub use lane::*;

pub mod level;
pub use level::*;

pub mod lift;
pub use lift::*;

pub mod light;
pub use light::*;

pub mod load;
pub use load::*;

pub mod location;
pub use location::*;

pub mod measurement;
pub use measurement::*;

pub mod model;
pub use model::*;

pub mod model_property;
pub use model_property::*;

pub mod modifier;
pub use modifier::*;

pub mod nav_graph;
pub use nav_graph::*;

pub mod path;
pub use path::*;

pub mod physical_camera;
pub use physical_camera::*;

pub mod pose;
pub use pose::*;

pub mod property_plugin;
pub use property_plugin::*;

pub mod primitive_shape;
pub use primitive_shape::*;

pub mod recall_plugin;
pub use recall_plugin::RecallPlugin;

pub mod robot;
#[allow(unused_imports)]
pub use robot::*;

pub mod robot_properties;
pub use robot_properties::*;

pub mod save;
pub use save::*;

pub mod scenario;
pub use scenario::*;

pub mod sdf_exporter;
pub use sdf_exporter::*;

pub mod site;
pub use site::*;

pub mod site_visualizer;
pub use site_visualizer::*;

pub mod task;
pub use task::*;

pub mod slotcar;
pub use slotcar::*;

pub mod texture;
pub use texture::*;

pub mod util;
pub use util::*;

pub mod view_menu;
pub use view_menu::*;

pub mod wall;
pub use wall::*;

use crate::recency::{RecencyRank, RecencyRankingPlugin};
use crate::{AppState, RegisterIssueType};
pub use rmf_site_format::{DirectionalLight, PointLight, SpotLight, *};

use rmf_site_picking::SelectionServiceStages;

use bevy::{
    pbr::ExtendedMaterial, prelude::*, render::view::visibility::VisibilitySystems,
    transform::TransformSystem,
};

use bevy_infinite_grid::*;

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum SiteUpdateSet {
    /// We need a custom stage for assigning orphan elements because the
    /// commands from CoreStage::Update need to flush before the AssignOrphan
    /// systems are run, and the AssignOrphan commands need to flush before the
    /// PostUpdate systems are run.
    AssignOrphans,
    /// Force a command flush
    AssignOrphansFlush,
    /// Use a custom stage for deletions to make sure that all commands are
    /// flushed before and after deleting things.
    Deletion,
    /// Force a command flush after deletion
    DeletionFlush,
    /// Placed between transform and visibility propagation, to avoid one frame delays
    BetweenTransformAndVisibility,
    /// Flush the set above
    BetweenTransformAndVisibilityFlush,
    /// Used to force a command flush after the change plugin's process changes
    ProcessChanges,
    /// Flush the set above
    ProcessChangesFlush,
}

pub struct SitePlugin;

impl Plugin for SitePlugin {
    fn build(&self, app: &mut App) {
        add_site_assets(app);
        app.configure_sets(
            PreUpdate,
            (
                SiteUpdateSet::ProcessChanges,
                SiteUpdateSet::ProcessChangesFlush,
            )
                .chain(),
        )
        .add_systems(
            PreUpdate,
            ApplyDeferred.in_set(SiteUpdateSet::ProcessChangesFlush),
        )
        .configure_sets(
            PostUpdate,
            (
                SiteUpdateSet::AssignOrphans,
                SiteUpdateSet::AssignOrphansFlush,
                TransformSystem::TransformPropagate,
                SiteUpdateSet::BetweenTransformAndVisibility,
                SiteUpdateSet::BetweenTransformAndVisibilityFlush,
                VisibilitySystems::VisibilityPropagate,
                // TODO(luca) remove this when https://github.com/bevyengine/bevy/pull/19064 (or
                // alternative fix) is merged and released
                bevy::asset::AssetEvents,
            )
                .chain(),
        )
        .add_systems(
            PostUpdate,
            ApplyDeferred.in_set(SiteUpdateSet::BetweenTransformAndVisibilityFlush),
        )
        .add_systems(
            PostUpdate,
            ApplyDeferred.in_set(SiteUpdateSet::AssignOrphansFlush),
        )
        .insert_resource(ClearColor(Color::srgb(0., 0., 0.)))
        .init_resource::<SiteAssets>()
        .init_resource::<CurrentLevel>()
        .init_resource::<CurrentScenario>()
        .init_resource::<DefaultScenario>()
        .init_resource::<ExportHandlers>()
        .init_resource::<Trashcan>()
        .init_resource::<PhysicalLightToggle>()
        .init_resource::<ExtensionHooks>()
        .add_event::<LoadSite>()
        .add_event::<ImportNavGraphs>()
        .add_event::<ChangeCurrentSite>()
        .add_event::<ChangeCurrentScenario>()
        .add_event::<ChangeDefaultScenario>()
        .add_event::<CreateScenario>()
        .add_event::<RemoveScenario>()
        .add_event::<SaveSite>()
        .add_event::<ExportLights>()
        .add_event::<ConsiderAssociatedGraph>()
        .add_event::<ConsiderLocationTag>()
        .add_event::<MergeGroups>()
        .add_plugins((
            ChangePlugin::<AssociatedGraphs<Entity>>::default(),
            RecallPlugin::<RecallAssociatedGraphs<Entity>>::default(),
            ChangePlugin::<Motion>::default(),
            RecallPlugin::<RecallMotion>::default(),
            ChangePlugin::<ReverseLane>::default(),
            RecallPlugin::<RecallReverseLane>::default(),
            ChangePlugin::<NameOfSite>::default(),
            ChangePlugin::<NameInSite>::default(),
            ChangePlugin::<Pose>::default(),
            ChangePlugin::<Scale>::default(),
            ChangePlugin::<Distance>::default(),
            ChangePlugin::<Texture>::default(),
        ))
        .add_plugins((
            ChangePlugin::<DoorType>::default(),
            RecallPlugin::<RecallDoorType>::default(),
            ChangePlugin::<LevelElevation>::default(),
            ChangePlugin::<LiftCabin<Entity>>::default(),
            RecallPlugin::<RecallLiftCabin<Entity>>::default(),
            ChangePlugin::<AssetSource>::default(),
            RecallPlugin::<RecallAssetSource>::default(),
            ChangePlugin::<PrimitiveShape>::default(),
            RecallPlugin::<RecallPrimitiveShape>::default(),
            ChangePlugin::<PixelsPerMeter>::default(),
            ChangePlugin::<PhysicalCameraProperties>::default(),
            ChangePlugin::<LightKind>::default(),
            RecallPlugin::<RecallLightKind>::default(),
            ChangePlugin::<DisplayColor>::default(),
            ChangePlugin::<LocationTags>::default(),
        ))
        .add_plugins((
            RecallPlugin::<RecallLocationTags>::default(),
            ChangePlugin::<Visibility>::default(),
            ChangePlugin::<LayerVisibility>::default(),
            ChangePlugin::<GlobalFloorVisibility>::default(),
            ChangePlugin::<GlobalDrawingVisibility>::default(),
            ChangePlugin::<PreferredSemiTransparency>::default(),
            ChangePlugin::<Affiliation<Entity>>::default(),
            RecencyRankingPlugin::<NavGraphMarker>::default(),
            RecencyRankingPlugin::<FloorMarker>::default(),
            RecencyRankingPlugin::<DrawingMarker>::default(),
            DeletionPlugin,
            DrawingEditorPlugin,
            SiteVisualizerPlugin,
            ModelLoadingPlugin::default(),
            FuelPlugin::default(),
        ))
        .add_plugins((
            ChangePlugin::<ModelProperty<AssetSource>>::default(),
            ChangePlugin::<ModelProperty<Scale>>::default(),
            ChangePlugin::<ModelProperty<IsStatic>>::default(),
            ChangePlugin::<ModelProperty<Robot>>::default(),
            ChangePlugin::<Task>::default(),
            PropertyPlugin::<Pose, InstanceMarker>::default(),
            PropertyPlugin::<Inclusion, InstanceMarker>::default(),
            PropertyPlugin::<Inclusion, Task>::default(),
            PropertyPlugin::<TaskParams, Task>::default(),
            PropertyPlugin::<OnLevel<Entity>, Robot>::default(),
            SlotcarSdfPlugin,
            MaterialPlugin::<ExtendedMaterial<StandardMaterial, LaneArrowMaterial>>::default(),
            InfiniteGridPlugin,
        ))
        .add_plugins((
            RobotPropertiesPlugin::default(),
            RobotPropertyPlugin::<Mobility, RecallMobility>::default(),
            RobotPropertyPlugin::<Collision, RecallCollision>::default(),
            RobotPropertyPlugin::<PowerDissipation, RecallPowerDissipation>::default(),
            RobotPropertyPlugin::<PowerSource, RecallPowerSource>::default(),
            EmptyRobotPropertyPlugin::<Mobility>::new(),
            EmptyRobotPropertyPlugin::<Collision>::new(),
            EmptyRobotPropertyPlugin::<PowerSource>::new(),
            RobotPropertyKindPlugin::<DifferentialDrive, Mobility, RecallDifferentialDrive>::default(),
            RobotPropertyKindPlugin::<CircleCollision, Collision, RecallCircleCollision>::default(),
            RobotPropertyKindPlugin::<AmbientSystem, PowerDissipation, RecallAmbientSystem>::default(),
            RobotPropertyKindPlugin::<MechanicalSystem, PowerDissipation, RecallMechanicalSystem>::default(),
            RobotPropertyKindPlugin::<Battery, PowerSource, RecallBattery>::default(),
        ))
        .add_issue_type(&DUPLICATED_DOOR_NAME_ISSUE_UUID, "Duplicate door name")
        .add_issue_type(&DUPLICATED_LIFT_NAME_ISSUE_UUID, "Duplicate lift name")
        .add_issue_type(
            &FIDUCIAL_WITHOUT_AFFILIATION_ISSUE_UUID,
            "Fiducial without affiliation",
        )
        .add_issue_type(&DUPLICATED_DOCK_NAME_ISSUE_UUID, "Duplicated dock name")
        .add_issue_type(&UNCONNECTED_ANCHORS_ISSUE_UUID, "Unconnected anchors")
        .add_systems(Update, (load_site, import_nav_graph))
        .add_systems(
            PreUpdate,
            (
                update_lift_cabin,
                update_lift_edge,
                update_drawing_pixels_per_meter,
                update_drawing_children_to_pixel_coordinates,
                check_for_duplicated_door_names,
                check_for_duplicated_lift_names,
                check_for_duplicated_dock_names,
                check_for_fiducials_without_affiliation,
                check_for_close_unconnected_anchors,
                check_for_orphan_model_instances,
                check_for_hidden_model_instances,
                check_for_accidentally_moved_instances,
                check_for_invalid_level_assignments,
                fetch_image_for_texture,
                detect_last_selected_texture::<FloorMarker>,
                apply_last_selected_texture::<FloorMarker>
                    .after(detect_last_selected_texture::<FloorMarker>),
                detect_last_selected_texture::<WallMarker>,
                apply_last_selected_texture::<WallMarker>
                    .after(detect_last_selected_texture::<WallMarker>),
                update_material_for_display_color,
            )
                .after(SiteUpdateSet::ProcessChangesFlush)
                .run_if(AppState::in_displaying_mode()),
        )
        .add_systems(
            Update,
            (save_site, change_site.after(load_site)).run_if(AppState::in_displaying_mode()),
        )
        .add_systems(
            PostUpdate,
            (
                assign_orphan_anchors_to_parent,
                assign_orphan_levels_to_site,
                assign_orphan_nav_elements_to_site,
                assign_orphan_fiducials_to_parent,
                assign_orphan_elements_to_level::<DoorMarker>,
                assign_orphan_elements_to_level::<DrawingMarker>,
                assign_orphan_elements_to_level::<FloorMarker>,
                assign_orphan_elements_to_level::<LightKind>,
                assign_orphan_elements_to_level::<ModelMarker>,
                assign_orphan_elements_to_level::<PhysicalCameraProperties>,
                assign_orphan_elements_to_level::<WallMarker>,
                add_category_to_graphs,
                add_tags_to_lift,
                add_material_for_display_colors,
                add_physical_lights,
                clear_trashcan,
            )
                .run_if(AppState::in_displaying_mode())
                .in_set(SiteUpdateSet::AssignOrphans),
        )
        .add_systems(
            PostUpdate,
            (
                add_wall_visual,
                update_walls_for_moved_anchors,
                update_walls,
                update_transforms_for_changed_poses,
                align_site_drawings,
                export_lights,
                set_camera_transform_for_changed_site,
            )
                .run_if(AppState::in_displaying_mode())
                .in_set(SiteUpdateSet::BetweenTransformAndVisibility),
        )
        .add_systems(
            PostUpdate,
            (
                update_anchor_transforms,
                add_door_visuals,
                update_changed_door,
                update_door_for_moved_anchors,
                add_floor_visuals,
                update_floors,
                update_floors_for_moved_anchors,
                update_floors_for_changed_lifts,
                update_floor_visibility,
                update_drawing_visibility,
                add_lane_visuals,
                add_location_visuals,
                add_fiducial_visuals,
                update_level_visibility,
                handle_remove_scenarios.before(update_current_scenario),
                update_current_scenario.before(handle_create_scenarios),
                handle_create_scenarios,
            )
                .run_if(AppState::in_displaying_mode())
                .in_set(SiteUpdateSet::BetweenTransformAndVisibility),
        )
        .add_systems(
            PostUpdate,
            (
                update_changed_lane,
                update_lane_for_moved_anchor,
                remove_association_for_deleted_graphs,
                add_unused_fiducial_tracker,
                update_fiducial_usage_tracker,
                update_color_for_lanes.after(update_material_for_display_color),
                update_visibility_for_lanes
                    .after(remove_association_for_deleted_graphs)
                    .after(add_lane_visuals),
                update_visibility_for_locations.after(remove_association_for_deleted_graphs),
                update_changed_location,
                update_location_for_moved_anchors,
                update_location_for_changed_location_tags.before(SelectionServiceStages::Select),
                update_changed_fiducial,
                update_fiducial_for_moved_anchors,
                handle_consider_associated_graph,
                handle_consider_location_tag,
                update_lift_for_moved_anchors,
                update_lift_door_availability,
                update_physical_lights,
                toggle_physical_lights,
            )
                .run_if(AppState::in_displaying_mode())
                .in_set(SiteUpdateSet::BetweenTransformAndVisibility),
        )
        .add_systems(
            PostUpdate,
            (
                add_measurement_visuals,
                update_changed_measurement,
                update_measurement_for_moved_anchors,
                update_model_instances::<AssetSource>,
                update_model_instances::<Scale>,
                update_model_instances::<IsStatic>,
                update_affiliations,
                update_members_of_groups.after(update_affiliations),
                update_model_scales,
                handle_new_primitive_shapes,
                add_drawing_visuals,
                handle_loaded_drawing,
                update_drawing_rank,
                add_physical_camera_visuals,
                check_selected_is_included,
                check_for_missing_root_modifiers::<InstanceMarker>,
                update_default_scenario,
                update_lane_motion_visuals,
            )
                .run_if(AppState::in_displaying_mode())
                .in_set(SiteUpdateSet::BetweenTransformAndVisibility),
        )
        .add_observer(handle_inclusion_change_for_model_visibility)
        .add_observer(handle_on_level_change);
    }
}