Skip to content
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

Introduce an extensible widget system #229

Merged
merged 39 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
83c045c
Designing extensible widget framework
mxgrey Jun 12, 2024
dd8d958
Finished migrating InspectAnchor
mxgrey Jun 12, 2024
071314a
Rework how panel widgets are handled
mxgrey Jun 13, 2024
2652b42
Account for egui blocking mouse picks
mxgrey Jun 13, 2024
8f5c2a6
Migrated log console
mxgrey Jun 13, 2024
6d13ee5
Finished migrating menu bar
mxgrey Jun 13, 2024
941426e
Finished migrating InspectFiducial
mxgrey Jun 13, 2024
50075b0
Migrated layer inspection
mxgrey Jun 13, 2024
9523e0e
Fixed layer inspection layout
mxgrey Jun 13, 2024
4ae7627
Migrated ViewLayers panel
mxgrey Jun 15, 2024
20c9fbf
Migrated ViewLevels
mxgrey Jun 15, 2024
4a3825d
Migrated ViewNavGraphs
mxgrey Jun 15, 2024
8c41bf1
Migrated nav graphs view
mxgrey Jun 15, 2024
83869a6
Migrated group viewer
mxgrey Jun 15, 2024
bc73f4d
Migrated lights viewer
mxgrey Jun 15, 2024
b09cca9
Migrate occupancy
mxgrey Jun 15, 2024
15f0fc7
Migrate building preview
mxgrey Jun 15, 2024
07c8535
Make building preview UI work
mxgrey Jun 16, 2024
4138453
Migrated fuel asset browser and diagnostic tool
mxgrey Jun 17, 2024
574edf1
Migrate drawing inspection
mxgrey Jun 18, 2024
88419c8
Switch to main branch of gz-fuel-rs
mxgrey Jun 18, 2024
5e179e7
Migrated location and associated graph inspection
mxgrey Jun 18, 2024
36b2eca
Migrated inspect texture affiliation
mxgrey Jun 18, 2024
5383aa1
Finished migrating full inspector widget
mxgrey Jun 18, 2024
d095249
Cleanup
mxgrey Jun 18, 2024
ecfe1b0
Introduce PropertiesTilePlugin to make it easier to add new propertie…
mxgrey Jun 18, 2024
e534d8c
Fix style
mxgrey Jun 18, 2024
f638155
Cleanup the organization of widget modules and add documentation
mxgrey Jun 20, 2024
4a3ac60
Fix typo
mxgrey Jun 20, 2024
6d9f88c
Fix style
mxgrey Jun 20, 2024
fc8f1a6
Remove align drawings button from drawing editor mode
mxgrey Jun 20, 2024
2fe3acd
Tweak fuel cache message
mxgrey Jun 20, 2024
dc5e08f
Merge branch 'main' into ui_refactor
mxgrey Jun 20, 2024
5fcac9e
Fix `StandardUiPlugin` links
luca-della-vedova Jun 21, 2024
42ca392
Fix merge conflicts and reorganize resources
mxgrey Jun 22, 2024
fe388aa
Fix style
mxgrey Jun 22, 2024
834b07a
Only import HashSet for bevy feature
mxgrey Jun 22, 2024
4b93f05
Fix doctest
mxgrey Jun 23, 2024
f062f49
Add quick links to simple custom widget examples
mxgrey Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ rfd = "0.12"
urdf-rs = "0.7"
utm = "0.1.6"
sdformat_rs = { git = "https://github.com/open-rmf/sdf_rust_experimental", rev = "a5daef0"}
gz-fuel = { git = "https://github.com/open-rmf/gz-fuel-rs", branch = "luca/ehttp" }
gz-fuel = { git = "https://github.com/open-rmf/gz-fuel-rs", branch = "main" }
pathdiff = "*"
tera = "1.19.1"
ehttp = { version = "0.4", features = ["native-async"] }
Expand Down
53 changes: 4 additions & 49 deletions rmf_site_editor/src/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
*/

use crate::site::ChangePlugin;
use crate::widgets::{
diagnostic_window::DiagnosticWindowState,
menu_bar::{MenuEvent, MenuItem, MenuVisualizationStates, ToolMenu},
use bevy::{
prelude::*,
utils::{HashMap, Uuid},
};
use crate::AppState;
use bevy::prelude::*;
use bevy::utils::{HashMap, Uuid};
use rmf_site_format::{FilteredIssueKinds, FilteredIssues, IssueKey};
use std::collections::HashSet;

#[derive(Component, Debug, Clone)]
pub struct Issue {
Expand Down Expand Up @@ -60,55 +56,14 @@ pub struct IssueDictionary(HashMap<Uuid, String>);
#[derive(Default)]
pub struct IssuePlugin;

#[derive(Resource)]
pub struct IssueMenu {
diagnostic_tool: Entity,
}

impl FromWorld for IssueMenu {
fn from_world(world: &mut World) -> Self {
let target_states = HashSet::from([
AppState::SiteEditor,
AppState::SiteDrawingEditor,
AppState::SiteVisualizer,
]);
// Tools menu
let diagnostic_tool = world
.spawn(MenuItem::Text("Diagnostic Tool".to_string()))
.insert(MenuVisualizationStates(target_states))
.id();

let tool_header = world.resource::<ToolMenu>().get();
world
.entity_mut(tool_header)
.push_children(&[diagnostic_tool]);

IssueMenu { diagnostic_tool }
}
}

fn handle_diagnostic_window_visibility(
mut menu_events: EventReader<MenuEvent>,
issue_menu: Res<IssueMenu>,
mut diagnostic_window: ResMut<DiagnosticWindowState>,
) {
for event in menu_events.read() {
if event.clicked() && event.source() == issue_menu.diagnostic_tool {
diagnostic_window.show = true;
}
}
}

impl Plugin for IssuePlugin {
fn build(&self, app: &mut App) {
app.add_event::<ValidateWorkspace>()
.add_plugins((
ChangePlugin::<FilteredIssues<Entity>>::default(),
ChangePlugin::<FilteredIssueKinds>::default(),
))
.init_resource::<IssueDictionary>()
.init_resource::<IssueMenu>()
.add_systems(Update, handle_diagnostic_window_visibility);
.init_resource::<IssueDictionary>();
}
}

Expand Down
38 changes: 32 additions & 6 deletions rmf_site_editor/src/site/fuel_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ pub struct SetFuelApiKey(pub String);
/// Using channels instead of events to allow usage in wasm since, unlike event writers, they can
/// be cloned and moved into async functions therefore don't have lifetime issues
#[derive(Debug, Resource)]
pub struct UpdateFuelCacheChannels {
pub struct FuelCacheUpdateChannel {
pub sender: Sender<FuelCacheUpdated>,
pub receiver: Receiver<FuelCacheUpdated>,
}

impl Default for UpdateFuelCacheChannels {
impl Default for FuelCacheUpdateChannel {
fn default() -> Self {
let (sender, receiver) = crossbeam_channel::unbounded();
Self { sender, receiver }
}
}

/// Channels that give incremental updates about what models have been fetched.
#[derive(Debug, Resource)]
pub struct FuelCacheProgressChannel {
pub sender: Sender<FuelModel>,
pub receiver: Receiver<FuelModel>,
}

impl Default for FuelCacheProgressChannel {
fn default() -> Self {
let (sender, receiver) = crossbeam_channel::unbounded();
Self { sender, receiver }
Expand All @@ -56,13 +70,15 @@ pub fn handle_update_fuel_cache_requests(
mut events: EventReader<UpdateFuelCache>,
mut gallery_status: ResMut<AssetGalleryStatus>,
fuel_client: Res<FuelClient>,
channels: Res<UpdateFuelCacheChannels>,
update_channel: Res<FuelCacheUpdateChannel>,
progress_channel: Res<FuelCacheProgressChannel>,
) {
if events.read().last().is_some() {
info!("Updating fuel cache, this might take a few minutes");
gallery_status.fetching_cache = true;
let mut fuel_client = fuel_client.clone();
let sender = channels.sender.clone();
let sender = update_channel.sender.clone();
let progress = progress_channel.sender.clone();
IoTaskPool::get()
.spawn(async move {
// Only write to cache in non wasm, no file system in web
Expand All @@ -71,17 +87,27 @@ pub fn handle_update_fuel_cache_requests(
#[cfg(not(target_arch = "wasm32"))]
let write_to_disk = true;
// Send client if update was successful
let res = fuel_client.update_cache(write_to_disk).await;

let res = fuel_client
.update_cache_with_progress(write_to_disk, Some(progress))
.await;
sender
.send(FuelCacheUpdated(res))
.expect("Failed sending fuel cache update event");
})
.detach();
}

while let Ok(next_model) = progress_channel.receiver.try_recv() {
info!(
"Received model {} owned by {}",
next_model.name, next_model.owner,
);
}
luca-della-vedova marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn read_update_fuel_cache_results(
channels: Res<UpdateFuelCacheChannels>,
channels: Res<FuelCacheUpdateChannel>,
mut fuel_client: ResMut<FuelClient>,
mut gallery_status: ResMut<AssetGalleryStatus>,
) {
Expand Down
3 changes: 2 additions & 1 deletion rmf_site_editor/src/site/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ impl Plugin for SitePlugin {
.init_resource::<SiteAssets>()
.init_resource::<CurrentLevel>()
.init_resource::<PhysicalLightToggle>()
.init_resource::<UpdateFuelCacheChannels>()
.init_resource::<FuelCacheUpdateChannel>()
.init_resource::<FuelCacheProgressChannel>()
.init_resource::<ModelTrashcan>()
.register_type::<NameInSite>()
.register_type::<AssetSource>()
Expand Down
7 changes: 7 additions & 0 deletions rmf_site_editor/src/site/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ impl EdgeLabels {
Self::LeftRight => "right",
}
}

pub fn side(&self, side: Side) -> &'static str {
match side {
Side::Left => self.start(),
Side::Right => self.end(),
}
}
}

#[derive(Component, Debug, Default, Clone, Deref, DerefMut)]
Expand Down
93 changes: 93 additions & 0 deletions rmf_site_editor/src/widgets/building_preview.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2024 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::{
site::{AlignSiteDrawings, FinishEditDrawing},
widgets::prelude::*,
AppState, CurrentWorkspace, Icons,
};
use bevy::prelude::*;
use bevy_egui::egui::{Button, Ui};

#[derive(Default)]
pub struct BuildingPreviewPlugin {}

impl Plugin for BuildingPreviewPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(PropertiesTilePlugin::<BuildingPreview>::new());
}
}

#[derive(SystemParam)]
pub struct BuildingPreview<'w> {
app_state: Res<'w, State<AppState>>,
next_app_state: ResMut<'w, NextState<AppState>>,
icons: Res<'w, Icons>,
current_workspace: Res<'w, CurrentWorkspace>,
align_site: EventWriter<'w, AlignSiteDrawings>,
finish_edit_drawing: EventWriter<'w, FinishEditDrawing>,
}

impl<'w> WidgetSystem<Tile> for BuildingPreview<'w> {
fn show(_: Tile, ui: &mut Ui, state: &mut SystemState<Self>, world: &mut World) {
let mut params = state.get_mut(world);
if *params.app_state == AppState::SiteEditor {
if ui.add(Button::new("Building preview")).clicked() {
params.next_app_state.set(AppState::SiteVisualizer);
}
}

if *params.app_state == AppState::SiteVisualizer {
if ui
.add(Button::image_and_text(
params.icons.alignment.egui(),
"Align Drawings",
))
.on_hover_text(
"Align all drawings in the site based on their fiducials and measurements",
)
.clicked()
{
if let Some(site) = params.current_workspace.root {
params.align_site.send(AlignSiteDrawings(site));
}
}

if ui
.add(Button::image_and_text(
params.icons.exit.egui(),
"Return to site editor",
))
.clicked()
{
params.next_app_state.set(AppState::SiteEditor);
}
}

if *params.app_state == AppState::SiteDrawingEditor {
if ui
.add(Button::image_and_text(
params.icons.exit.egui(),
"Return to site editor",
))
.clicked()
{
params.finish_edit_drawing.send(FinishEditDrawing(None));
}
}
}
}
Loading
Loading