-
Notifications
You must be signed in to change notification settings - Fork 28
Re-Introduces Occupancy Grid Export #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arjo129
wants to merge
13
commits into
main
Choose a base branch
from
arjoc/fix/reintroduce_occupancy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e729cba
Add a UI for eexporting occupancy grid
arjo129 7c3e16f
Export Occupancy Grid to PNG
arjo129 8fbbebb
Fix headless export
arjo129 f7064e5
Added support for saving to correct file name.
arjo129 1189cb0
Merge branch 'main' into arjoc/fix/reintroduce_occupancy
arjo129 eabde95
Fix compilation error
arjo129 45c1166
Adds a new menu item
arjo129 bea3134
Remove the unessecary keyboard command
arjo129 d445dbc
Rewire everything for being able to export from the top level menu.
arjo129 2e40884
Close menu upon succesful configuration
arjo129 6923669
Pin image dependency and address minor PR feedback
arjo129 4f15f8c
style
arjo129 d8686df
Merge branch 'main' into arjoc/fix/reintroduce_occupancy
mxgrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
crates/rmf_site_editor/src/widgets/occupancy_export_menu.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright (C) 2025 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. | ||
| * | ||
| */ | ||
|
|
||
| use crate::{ | ||
| occupancy::{CalculateGrid, ExportGridRequest, OccupancyInfo}, | ||
| AppState, WorkspaceSaver, | ||
| }; | ||
| use bevy::{ecs::hierarchy::ChildOf, prelude::*}; | ||
| use bevy_egui::{ | ||
| egui::{self, DragValue}, | ||
| EguiContexts, | ||
| }; | ||
| use rmf_site_egui::*; | ||
|
|
||
| /// Keeps track of which entity is associated to the export sdf button. | ||
| #[derive(Resource)] | ||
| pub struct OccupancyExportMenu { | ||
| export_sdf: Entity, | ||
| } | ||
|
|
||
| impl OccupancyExportMenu { | ||
| pub fn get(&self) -> Entity { | ||
| self.export_sdf | ||
| } | ||
| } | ||
|
|
||
| impl FromWorld for OccupancyExportMenu { | ||
| fn from_world(world: &mut World) -> Self { | ||
| let file_header = world.resource::<FileMenu>().get(); | ||
| let export_sdf = world | ||
| .spawn(( | ||
| MenuItem::Text(TextMenuItem::new("Export Occupancy")), | ||
| ChildOf(file_header), | ||
| )) | ||
| .id(); | ||
|
|
||
| OccupancyExportMenu { export_sdf } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| struct ExportOccupancyConfig { | ||
| visible: bool, | ||
| } | ||
|
|
||
| fn handle_export_occupancy_menu_events( | ||
| mut menu_events: EventReader<MenuEvent>, | ||
| mut export_event: EventWriter<ExportGridRequest>, | ||
| occupancy_menu: Res<OccupancyExportMenu>, | ||
| mut occupancy_info: ResMut<OccupancyInfo>, | ||
| mut egui_context: EguiContexts, | ||
| mut configuration: Local<ExportOccupancyConfig>, | ||
| ) { | ||
| for event in menu_events.read() { | ||
| if event.clicked() && event.source() == occupancy_menu.get() { | ||
| configuration.visible = true; | ||
| } | ||
| } | ||
|
|
||
| if !configuration.visible { | ||
| return; | ||
| } | ||
|
|
||
| egui::Window::new("Occupancy Export Options").show(egui_context.ctx_mut(), |ui| { | ||
| ui.horizontal(|ui| { | ||
| ui.label("Cell Size:"); | ||
| ui.add(DragValue::new(&mut occupancy_info.cell_size)); | ||
| }); | ||
| if ui.button("Export").clicked() { | ||
| configuration.visible = false; | ||
| export_event.write(ExportGridRequest); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct OccupancyExportMenuPlugin {} | ||
|
|
||
| impl Plugin for OccupancyExportMenuPlugin { | ||
| fn build(&self, app: &mut App) { | ||
| app.init_resource::<OccupancyExportMenu>().add_systems( | ||
| Update, | ||
| handle_export_occupancy_menu_events.run_if(AppState::in_displaying_mode()), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally not too excited about this function since it's pretty much the exact same as the one below, with one line of difference in "what we do after
calculate_gridis over".My preference would be to refactor them into a single function, on top of my head I can think of a few ways:
ExportGridRequestandCalculateGridRequestinto a single event that has an additional field that says "what do we do with the output", we could match it and either send the saving event (your function) or send the replan event (the original function).Worldand decides what to do after the grid is exported?calculate_gridrequest in a common service, then two workflows, one to calculate the occupancy grid and replan and the other one to calculate the occupancy grid and send a file dialog request.First is quick and easy, second is possibly not a great idea, third would probably be the best but a bit more work to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had done 1 earlier (before having to rewrite the entire PR): #389 (comment)
2 will make the code unnecessarily complex.
3 is a fair deal more of work but probably the correct way to handle it.