-
Notifications
You must be signed in to change notification settings - Fork 13
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
Introducing model descriptions and instances #242
base: main
Are you sure you want to change the base?
Changes from all commits
ce017cb
f00141d
6167ec1
03cace2
0010b9f
243b2b4
8386209
9f30004
1215fa9
1c25265
7adb5c6
ce9f345
97f8dbf
537ff76
b3f232d
c284a64
8cf25e7
9c96e32
f6124a2
e84dc58
6d0a7e8
63fb8b9
443a3fe
ecb9bb7
5a8ef05
c896ea8
f7a24be
69ea1df
9963a8f
a944432
94ccc5c
4b413a2
d95be3b
42f25c2
4729bef
afddc82
bb13ee0
8ffcfe6
1d8aa7d
af5a2d5
c6eebf4
e2b365c
f0fa12c
ad5ba6e
d331a79
5786bae
7b01c91
d450cd7
83f3d85
de9b60e
90a60ba
acb39b9
1c2cdcf
057e186
94b54a9
6ad0ea7
8c19eed
5aed94f
3a6ad1d
cc29375
01fca32
4252c38
bbc373c
d97232d
766fd62
48c94e9
347d546
73076af
6663e1a
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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::{interaction::*, site::*}; | ||
use bevy::prelude::*; | ||
|
||
pub fn update_model_instance_visual_cues( | ||
model_descriptions: Query< | ||
(Entity, &Selected, &Hovered), | ||
( | ||
With<ModelMarker>, | ||
With<Group>, | ||
Or<(Changed<Hovered>, Changed<Selected>)>, | ||
), | ||
>, | ||
mut model_instances: Query< | ||
( | ||
Entity, | ||
&mut Selected, | ||
&mut Hovered, | ||
&mut Affiliation<Entity>, | ||
Option<Ref<Tasks<Entity>>>, | ||
), | ||
(With<ModelMarker>, Without<Group>), | ||
>, | ||
mut locations: Query<&mut Selected, (With<LocationTags>, Without<ModelMarker>)>, | ||
mut removed_components: RemovedComponents<Tasks<Entity>>, | ||
) { | ||
for (instance_entity, mut instance_selected, mut instance_hovered, affiliation, tasks) in | ||
&mut model_instances | ||
{ | ||
let mut is_description_selected = false; | ||
if let Some(description_entity) = affiliation.0 { | ||
if let Ok((_, description_selected, description_hovered)) = | ||
model_descriptions.get(description_entity) | ||
{ | ||
if description_selected.cue() { | ||
instance_selected | ||
.support_selected | ||
.insert(description_entity); | ||
is_description_selected = true; | ||
} else { | ||
instance_selected | ||
.support_selected | ||
.remove(&description_entity); | ||
} | ||
if description_hovered.cue() { | ||
instance_hovered.support_hovering.insert(description_entity); | ||
} else { | ||
instance_hovered | ||
.support_hovering | ||
.remove(&description_entity); | ||
} | ||
} | ||
} | ||
|
||
// When an instance is selected, select all locations supporting it | ||
if let Some(tasks) = tasks { | ||
// When tasks for an instance have changed, reset all locations from supporting this instance | ||
if tasks.is_changed() { | ||
for mut location_selected in locations.iter_mut() { | ||
location_selected.support_selected.remove(&instance_entity); | ||
} | ||
} | ||
|
||
if let Some(task_location) = tasks.0.first().and_then(|t| t.location()) { | ||
if let Ok(mut location_selected) = locations.get_mut(task_location.0) { | ||
if instance_selected.cue() && !is_description_selected { | ||
location_selected.support_selected.insert(instance_entity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the use of support selected. It may also be worth doing |
||
} else { | ||
location_selected.support_selected.remove(&instance_entity); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// When instances are removed, prevent any location from supporting them | ||
for removed in removed_components.read() { | ||
for mut location_selected in locations.iter_mut() { | ||
location_selected.support_selected.remove(&removed); | ||
} | ||
} | ||
} |
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.
In the current setup, we iterate over
&mut model_instances
which does not have this filter, meaning it will include all model instances in the world every update cycle. Moreover, this query will only include model descriptions whoseHovered
orSelected
status has changed during the latest cycle, so this line will not fetch anything if neither of these components changed for the model description.I have a feeling this filter was meant to go on
model_instances
, not onmodel_descriptions
.