1
1
use ahash:: { HashMap , HashSet } ;
2
+ use nohash_hasher:: IntSet ;
3
+ use re_arrow_store:: DataStore ;
4
+ use re_log_types:: EntityPath ;
2
5
3
6
use crate :: {
4
7
DynSpaceViewClass , IdentifiedViewSystem , SpaceViewClassIdentifier , ViewContextCollection ,
5
8
ViewContextSystem , ViewPartCollection , ViewPartSystem , ViewSystemIdentifier ,
6
9
} ;
7
10
8
- use super :: space_view_class_placeholder:: SpaceViewClassPlaceholder ;
11
+ use super :: {
12
+ space_view_class_placeholder:: SpaceViewClassPlaceholder ,
13
+ visualizer_entity_subscriber:: VisualizerEntitySubscriber ,
14
+ } ;
9
15
10
16
#[ derive( Debug , thiserror:: Error ) ]
11
17
#[ allow( clippy:: enum_variant_names) ]
@@ -54,7 +60,7 @@ impl SpaceViewSystemRegistrator<'_> {
54
60
self . registry
55
61
. context_systems
56
62
. entry ( T :: identifier ( ) )
57
- . or_insert_with ( || SystemTypeRegistryEntry {
63
+ . or_insert_with ( || ContextSystemTypeRegistryEntry {
58
64
factory_method : Box :: new ( || Box :: < T > :: default ( ) ) ,
59
65
used_by : Default :: default ( ) ,
60
66
} )
@@ -91,9 +97,16 @@ impl SpaceViewSystemRegistrator<'_> {
91
97
self . registry
92
98
. visualizers
93
99
. entry ( T :: identifier ( ) )
94
- . or_insert_with ( || SystemTypeRegistryEntry {
95
- factory_method : Box :: new ( || Box :: < T > :: default ( ) ) ,
96
- used_by : Default :: default ( ) ,
100
+ . or_insert_with ( || {
101
+ let entity_subscriber_handle = DataStore :: register_subscriber ( Box :: new (
102
+ VisualizerEntitySubscriber :: new ( & T :: default ( ) ) ,
103
+ ) ) ;
104
+
105
+ VisualizerTypeRegistryEntry {
106
+ factory_method : Box :: new ( || Box :: < T > :: default ( ) ) ,
107
+ used_by : Default :: default ( ) ,
108
+ entity_subscriber_handle,
109
+ }
97
110
} )
98
111
. used_by
99
112
. insert ( self . identifier ) ;
@@ -110,37 +123,53 @@ impl SpaceViewSystemRegistrator<'_> {
110
123
}
111
124
112
125
/// Space view class entry in [`SpaceViewClassRegistry`].
113
- struct SpaceViewClassRegistryEntry {
114
- class : Box < dyn DynSpaceViewClass > ,
115
- context_systems : HashSet < ViewSystemIdentifier > ,
116
- visualizers : HashSet < ViewSystemIdentifier > ,
126
+ pub struct SpaceViewClassRegistryEntry {
127
+ pub class : Box < dyn DynSpaceViewClass > ,
128
+ pub context_system_ids : HashSet < ViewSystemIdentifier > ,
129
+ pub visualizer_system_ids : HashSet < ViewSystemIdentifier > ,
117
130
}
118
131
119
132
#[ allow( clippy:: derivable_impls) ] // Clippy gets this one wrong.
120
133
impl Default for SpaceViewClassRegistryEntry {
121
134
fn default ( ) -> Self {
122
135
Self {
123
136
class : Box :: < SpaceViewClassPlaceholder > :: default ( ) ,
124
- context_systems : Default :: default ( ) ,
125
- visualizers : Default :: default ( ) ,
137
+ context_system_ids : Default :: default ( ) ,
138
+ visualizer_system_ids : Default :: default ( ) ,
126
139
}
127
140
}
128
141
}
129
142
130
- /// System type entry in [`SpaceViewClassRegistry`].
131
- struct SystemTypeRegistryEntry < T : ? Sized > {
132
- factory_method : Box < dyn Fn ( ) -> Box < T > + Send + Sync > ,
143
+ /// Context system type entry in [`SpaceViewClassRegistry`].
144
+ struct ContextSystemTypeRegistryEntry {
145
+ factory_method : Box < dyn Fn ( ) -> Box < dyn ViewContextSystem > + Send + Sync > ,
133
146
used_by : HashSet < SpaceViewClassIdentifier > ,
134
147
}
135
148
149
+ /// Visualizer entry in [`SpaceViewClassRegistry`].
150
+ struct VisualizerTypeRegistryEntry {
151
+ factory_method : Box < dyn Fn ( ) -> Box < dyn ViewPartSystem > + Send + Sync > ,
152
+ used_by : HashSet < SpaceViewClassIdentifier > ,
153
+
154
+ /// Handle to subscription of [`VisualizerEntitySubscriber`] for this visualizer.
155
+ entity_subscriber_handle : re_arrow_store:: StoreSubscriberHandle ,
156
+ }
157
+
158
+ impl Drop for VisualizerTypeRegistryEntry {
159
+ fn drop ( & mut self ) {
160
+ // TODO(andreas): DataStore unsubscribe is not yet implemented!
161
+ //DataStore::unregister_subscriber(self.entity_subscriber_handle);
162
+ }
163
+ }
164
+
136
165
/// Registry of all known space view types.
137
166
///
138
167
/// Expected to be populated on viewer startup.
139
168
#[ derive( Default ) ]
140
169
pub struct SpaceViewClassRegistry {
141
170
space_view_classes : HashMap < SpaceViewClassIdentifier , SpaceViewClassRegistryEntry > ,
142
- visualizers : HashMap < ViewSystemIdentifier , SystemTypeRegistryEntry < dyn ViewPartSystem > > ,
143
- context_systems : HashMap < ViewSystemIdentifier , SystemTypeRegistryEntry < dyn ViewContextSystem > > ,
171
+ context_systems : HashMap < ViewSystemIdentifier , ContextSystemTypeRegistryEntry > ,
172
+ visualizers : HashMap < ViewSystemIdentifier , VisualizerTypeRegistryEntry > ,
144
173
placeholder : SpaceViewClassRegistryEntry ,
145
174
}
146
175
@@ -175,8 +204,8 @@ impl SpaceViewClassRegistry {
175
204
identifier,
176
205
SpaceViewClassRegistryEntry {
177
206
class,
178
- context_systems,
179
- visualizers,
207
+ context_system_ids : context_systems,
208
+ visualizer_system_ids : visualizers,
180
209
} ,
181
210
)
182
211
. is_some ( )
@@ -245,10 +274,25 @@ impl SpaceViewClassRegistry {
245
274
}
246
275
247
276
/// Iterates over all registered Space View class types.
248
- pub fn iter_classes ( & self ) -> impl Iterator < Item = & dyn DynSpaceViewClass > {
249
- self . space_view_classes
250
- . values ( )
251
- . map ( |entry| entry. class . as_ref ( ) )
277
+ pub fn iter_registry ( & self ) -> impl Iterator < Item = & SpaceViewClassRegistryEntry > {
278
+ self . space_view_classes . values ( )
279
+ }
280
+
281
+ /// Returns the set of entities that are applicable to the given visualizer.
282
+ ///
283
+ /// The list is kept up to date by a store subscriber.
284
+ pub fn applicable_entities_for_visualizer_system (
285
+ & self ,
286
+ visualizer : ViewSystemIdentifier ,
287
+ store : & re_log_types:: StoreId ,
288
+ ) -> Option < IntSet < EntityPath > > {
289
+ self . visualizers . get ( & visualizer) . and_then ( |entry| {
290
+ DataStore :: with_subscriber :: < VisualizerEntitySubscriber , _ , _ > (
291
+ entry. entity_subscriber_handle ,
292
+ |subscriber| subscriber. entities ( store) . cloned ( ) ,
293
+ )
294
+ . flatten ( )
295
+ } )
252
296
}
253
297
254
298
pub fn new_context_collection (
@@ -266,7 +310,7 @@ impl SpaceViewClassRegistry {
266
310
267
311
ViewContextCollection {
268
312
systems : class
269
- . context_systems
313
+ . context_system_ids
270
314
. iter ( )
271
315
. filter_map ( |name| {
272
316
self . context_systems . get ( name) . map ( |entry| {
@@ -293,7 +337,7 @@ impl SpaceViewClassRegistry {
293
337
294
338
ViewPartCollection {
295
339
systems : class
296
- . visualizers
340
+ . visualizer_system_ids
297
341
. iter ( )
298
342
. filter_map ( |name| {
299
343
self . visualizers . get ( name) . map ( |entry| {
0 commit comments