VR-Engage  2.2
Loading...
Searching...
No Matches
entityResolver.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file entityResolver.h
7//! \brief Defines the entity resolver for mapping between entity representations
8//!
9//! This file contains the DtEntityResolver class which provides a central system
10//! for resolving and translating between different entity representation schemes.
11//! It maps between display names, object IDs, entity IDs, and scene objects, enabling
12//! the application to work with entities regardless of their underlying protocol.
13
14#pragma once
15
17#include <vrvCore/DtDataBank.h>
18#include <vrvCore/DtUniqueID.h>
19#include <vrvCore/DtElementAttributeManager.h>
20#include <vlpi/entityIdentifier.h>
22#include <vrfutil/rwUUID.h>
23
24// #include <boost/unordered_map.hpp>
25#include <map>
26
27#include <string>
28#include <boost/signals2/signal.hpp>
29
30namespace makVrv
31{
32class DtDe;
33class DtSceneObject;
34}; // namespace makVrv
35
36namespace makVre
37{
38//! \brief Forward declaration of the entity discovered message class
40
41//! \brief Entity resolution and mapping system
42//!
43//! DtEntityResolver provides a central service for mapping between different
44//! representations of entities in the simulation. It maintains mappings between
45//! display names (marking text), object IDs, element IDs, and scene objects.
46//! This enables the application to find and work with entities regardless of
47//! which identifier system is used to reference them.
48//!
49//! The resolver also emits signals when entities are added or removed,
50//! allowing other components to react to entity lifecycle events.
52{
53public:
54 //! \brief Type definition for mapping from strings to element IDs
55 using StringToElementIdMap = std::map<std::string, makVrv::DtElementID>;
56
57 //! \brief Type definition for mapping from element IDs to strings
58 using ElementIdToStringMap = std::map<makVrv::DtElementID, std::string>;
59
60 //! \brief Type definition for mapping from element IDs to scene objects
61 using SceneObjectMap = std::map<makVrv::DtElementID, makVrv::DtSceneObject*>;
62
63 //! \brief Constructor
64 //! \param de Reference to the display engine
65 //!
66 //! Creates a new entity resolver associated with the given display engine.
67 //! The display engine provides access to the visual representation of entities.
68 DtEntityResolver(makVrv::DtDe& de);
69
70 //! \brief Virtual destructor
71 //!
72 //! Cleans up resources used by the entity resolver.
74
75 //! \brief Retrieves a scene object from an element ID
76 //! \param elementId Element ID to look up
77 //! \param modelSet Model set to search in
78 //! \return Pointer to the scene object, or NULL if not found
79 //!
80 //! Utility function to find a scene object associated with an element ID
81 //! in the specified model set. This is useful for accessing the visual
82 //! representation of an entity when only its element ID is known.
83 makVrv::DtSceneObject* sceneObjectFromElementId(makVrv::DtElementID elementId, makVrv::DtModelSetId modelSet);
84
85 //! \brief Gets the map of all display names to element IDs
86 //! \return Constant reference to the display name mapping
87 //!
88 //! Provides access to the complete mapping of display names to element IDs.
89 //! When iterating through this map, iterator->first provides the display name,
90 //! and iterator->second provides the corresponding element ID.
92
93 //! \brief Gets the map of all scene objects
94 //! \return Constant reference to the scene object mapping
95 //!
96 //! Provides access to the complete mapping of element IDs to scene objects.
97 //! When iterating through this map, iterator->first provides the element ID,
98 //! and iterator->second provides the corresponding scene object pointer.
100
101 //! \brief Element ID lookup methods
102 //! @{
103
104 //! \brief Finds the element ID for an entity by its display name
105 //! \param displayName Display name (marking text) of the entity
106 //! \return Element ID of the entity, or NULL_ELEMENT_ID if not found
107 //!
108 //! Looks up the element ID associated with a particular display name.
109 //! This is typically used to find an entity by its visible name or marking text.
110 makVrv::DtElementID findElementID(const std::string& displayName) const;
111
112 //! \brief Finds the element ID for an entity by its object ID
113 //! \param objectId Object ID of the entity
114 //! \return Element ID of the entity, or NULL_ELEMENT_ID if not found
115 //!
116 //! Looks up the element ID associated with a particular object ID.
117 //! The object ID is typically a unique identifier from the network protocol.
118 makVrv::DtElementID findElementIdByObjectId(const std::string& objectId) const;
119 //! \brief Finds the element ID for an entity by its entity identifier
120 //! \param entityId Entity identifier of the entity
121 //! \return Element ID of the entity, or NULL_ELEMENT_ID if not found
122 //!
123 //! Looks up the element ID associated with a particular entity identifier.
124 //! In DIS and RPR HLA, the VRL Connection Object ID is a string representation
125 //! of a DtEntityIdentifier, so this delegates to findElementIdByObjectId.
126 makVrv::DtElementID findElementIdByEntityId(const DtEntityIdentifier& entityId) const
127 {
128 return findElementIdByObjectId(entityId.string());
129 }
130 //! @}
131
132 //! \brief UUID lookup methods
133 //! @{
134
135 //! \brief Finds the UUID for an entity by its element ID
136 //! \param elementID Element ID of the entity
137 //! \return UUID of the entity
138 //!
139 //! Retrieves the UUID associated with a particular element ID.
140 //! Currently this performs the lookup by marking text, which may be ambiguous
141 //! if multiple elements have the same marking text.
142 DtUUID findUUID(makVrv::DtElementID elementID) const;
143 //! \brief Finds the UUID for an entity by its entity identifier
144 //! \param entityId Entity identifier of the entity
145 //! \return UUID of the entity
146 //!
147 //! Convenience method that combines findElementIdByEntityId and findUUID
148 //! to retrieve the UUID associated with a particular entity identifier.
149 DtUUID findUUID(const DtEntityIdentifier& entityId) const { return findUUID(findElementIdByEntityId(entityId)); }
150 //! @}
151
152 //! \brief Display name lookup methods
153 //! @{
154
155 //! \brief Finds the display name for an entity by its element ID
156 //! \param elementID Element ID of the entity
157 //! \return Display name of the entity, or empty string if not found
158 //!
159 //! Retrieves the display name (marking text) associated with a particular element ID.
160 //! This is typically the human-readable name of the entity as shown in the UI.
161 std::string findDisplayName(makVrv::DtElementID elementID) const;
162 //! \brief Finds the display name for an entity by its entity identifier
163 //! \param entityId Entity identifier of the entity
164 //! \return Display name of the entity, or empty string if not found
165 //!
166 //! Convenience method that combines findElementIdByEntityId and findDisplayName
167 //! to retrieve the display name associated with a particular entity identifier.
168 std::string findDisplayName(const DtEntityIdentifier& entityId) const
169 {
171 }
172 //! @}
173
174 //! \brief Object ID lookup methods
175 //! @{
176
177 //! \brief Finds the object ID for an entity by its element ID
178 //! \param elementID Element ID of the entity
179 //! \return Object ID of the entity, or empty string if not found
180 //!
181 //! Retrieves the object ID associated with a particular element ID.
182 //! The object ID is typically a unique identifier from the network protocol.
183 std::string findObjectId(makVrv::DtElementID elementID) const;
184 //! @}
185
186 //! \brief Entity identifier lookup methods
187 //! @{
188
189 //! \brief Finds the entity identifier for an entity by its element ID
190 //! \param elementID Element ID of the entity
191 //! \return Entity identifier of the entity
192 //!
193 //! Retrieves the entity identifier associated with a particular element ID.
194 //! In DIS and RPR HLA, the VRL Connection Object ID is a string representation
195 //! of a DtEntityIdentifier, so this converts the object ID to an entity identifier.
196 DtEntityIdentifier findEntityId(makVrv::DtElementID elementID) const
197 {
198 // In DIS and RPR HLA, the VRL Connection Object ID is a string rep of a DtEntityIdentifier
199 return DtEntityIdentifier(findObjectId(elementID).c_str());
200 }
201
202 //! \brief Finds the entity identifier for an entity by its display name
203 //! \param displayName Display name (marking text) of the entity
204 //! \return Entity identifier of the entity
205 //!
206 //! Convenience method that combines findElementID and findEntityId
207 //! to retrieve the entity identifier associated with a particular display name.
208 DtEntityIdentifier findEntityId(const std::string& displayName) const
209 {
210 return findEntityId(findElementID(displayName));
211 }
212 //! @}
213
214 //! \brief Object type lookup methods
215 //! @{
216
217 //! \brief Finds the object type for an entity by its element ID
218 //! \param elementID Element ID of the entity
219 //! \return Object type of the entity, or empty string if not found
220 //!
221 //! Retrieves the object type associated with a particular element ID.
222 //! The object type describes the kind of entity (e.g., "Tank", "Aircraft").
223 std::string findObjectType(makVrv::DtElementID elementID) const;
224 //! \brief Finds the object type for an entity by its entity identifier
225 //! \param entityId Entity identifier of the entity
226 //! \return Object type of the entity, or empty string if not found
227 //!
228 //! Convenience method that combines findElementIdByEntityId and findObjectType
229 //! to retrieve the object type associated with a particular entity identifier.
230 std::string findObjectType(const DtEntityIdentifier& entityId) const
231 {
232 return findObjectType(findElementIdByEntityId(entityId));
233 }
234 //! @}
235
236 //! \brief Message handlers
237 //! @{
238
239 //! \brief Handles entity discovered messages
240 //! \param msg Pointer to the entity discovered message
241 //! \return Message handling result
242 //!
243 //! Processes notifications about newly discovered entities, adding them
244 //! to the resolver's tracking system and pending realization list.
246
247 //! \brief Handles entity removed messages
248 //! \param msg Pointer to the entity removed message
249 //! \return Message handling result
250 //!
251 //! Processes notifications about entities being removed from the simulation,
252 //! removing them from the resolver's tracking system.
254
255 //! \brief Handles element ID realization
256 //! \param id Element ID that has been realized
257 //!
258 //! Called when an element ID has been fully realized in the simulation.
259 //! This triggers the sending of EntityRealizedMessages for pending entities.
260 void onElementIdRealized(makVrv::DtElementID id);
261 //! @}
262
263 //! \brief Scene object lookup methods
264 //! @{
265
266 //! \brief Finds the scene object for an entity by its element ID
267 //! \param elementId Element ID of the entity
268 //! \return Pointer to the scene object, or NULL if not found
269 //!
270 //! Retrieves the scene object associated with a particular element ID.
271 //! Note that DtSceneObject has an elementID method, so given a DtSceneObject,
272 //! you can also look up the display name (which, when using DIS or HLA/RPR is
273 //! the marking text).
274 makVrv::DtSceneObject* findSceneObject(makVrv::DtElementID elementId) const;
275
276 //! \brief Finds the scene object for an entity by its display name
277 //! \param displayName Display name (marking text) of the entity
278 //! \return Pointer to the scene object, or NULL if not found
279 //!
280 //! Retrieves the scene object associated with a particular display name.
281 makVrv::DtSceneObject* findSceneObject(const std::string& displayName) const;
282
283 //! \brief Finds the scene object for an entity by its object ID
284 //! \param objectId Object ID of the entity
285 //! \return Pointer to the scene object, or NULL if not found
286 //!
287 //! Retrieves the scene object associated with a particular object ID.
288 makVrv::DtSceneObject* findSceneObjectByObjectId(const std::string& objectId) const;
289 //! \brief Finds the scene object for an entity by its entity identifier
290 //! \param entityId Entity identifier of the entity
291 //! \return Pointer to the scene object, or NULL if not found
292 //!
293 //! Convenience method that retrieves the scene object associated with
294 //! a particular entity identifier. In DIS and RPR HLA, the VRL Connection
295 //! Object ID is a string representation of a DtEntityIdentifier.
296 makVrv::DtSceneObject* findSceneObjectByEntityId(const DtEntityIdentifier& entityId) const
297 {
298 // In DIS and RPR HLA, the VRL Connection Object ID is a string rep of a DtEntityIdentifier
299 return findSceneObjectByObjectId(entityId.string());
300 }
301 //! @}
302
303 //! \brief Signal emitted when an entity is added
304 //!
305 //! This signal is emitted whenever a new entity is added to the simulation.
306 //! Handlers can connect to this signal to perform initialization or other
307 //! operations when new entities are added.
308 boost::signalslib::signal<void(makVrv::DtElementID entity)> signal_entityAdded;
309
310 //! \brief Signal emitted when an entity is removed
311 //!
312 //! This signal is emitted whenever an entity is removed from the simulation.
313 //! Handlers can connect to this signal to perform cleanup or other operations
314 //! when entities are removed.
315 boost::signalslib::signal<void(makVrv::DtElementID entity)> signal_entityRemoved;
316
317protected:
318 //! \brief Element processing slots
319 //! @{
320
321 //! \brief Slot called when elements are ready to process
322 //! \param elements List of element IDs that are ready
323 //!
324 //! Internal handler that processes element ready notifications,
325 //! updating the resolver's tracking system with the new elements.
326 void slot_elementsReadyToProcess(const makVrv::DtElementData::ElementIdList& elements);
327
328 //! \brief Slot called when elements are removed
329 //! \param elements List of element IDs that were removed
330 //!
331 //! Internal handler that processes element removal notifications,
332 //! removing the elements from the resolver's tracking system and
333 //! emitting the signal_entityRemoved signal.
334 void slot_elementsRemoved(const makVrv::DtElementData::ElementIdList& elements);
335
336 //! \brief Slot called when element attributes are changed
337 //! \param attrs List of element attributes that were changed
338 //!
339 //! Internal handler that processes element attribute change notifications,
340 //! updating the resolver's tracking system with the modified attributes.
341 void slot_elementsChanged(const makVrv::DtElementAttributeManager::EntryAttributesList& attrs);
342 //! @}
343
344protected:
345 //! \brief Reference to the display engine
346 //!
347 //! Provides access to the 3D visualization and scene management system.
348 makVrv::DtDe& myDe;
349
350 //! \brief Mapping from display names to element IDs
352
353 //! \brief Mapping from element IDs to display names
355
356 //! \brief Mapping from object IDs to element IDs
358
359 //! \brief Mapping from element IDs to object IDs
361
362 //! \brief Mapping from element IDs to scene objects
364
365 //! \brief List of discovered entities awaiting realization
366 //!
367 //! When an entity is discovered but not yet fully realized in the system,
368 //! it is added to this list. Once realized, an EntityRealizedMessage is sent.
369 std::vector<std::shared_ptr<EntityDiscoveredMessage>> myPendingRealization;
370};
371} // namespace makVre
std::string findDisplayName(makVrv::DtElementID elementID) const
Display name lookup methods.
StringToElementIdMap myObjectIdToElementIdMap
Mapping from object IDs to element IDs.
Definition entityResolver.h:357
makVrv::DtElementID findElementID(const std::string &displayName) const
Element ID lookup methods.
makVrv::DtSceneObject * findSceneObject(const std::string &displayName) const
Finds the scene object for an entity by its display name.
makVre::DtVreMessageResult handleEntityDiscovered(makVre::DtVreMessage *msg)
Message handlers.
boost::signalslib::signal< void(makVrv::DtElementID entity)> signal_entityAdded
Signal emitted when an entity is added.
Definition entityResolver.h:308
makVre::DtVreMessageResult handleEntityRemoved(makVre::DtVreMessage *msg)
Handles entity removed messages.
void slot_elementsChanged(const makVrv::DtElementAttributeManager::EntryAttributesList &attrs)
Slot called when element attributes are changed.
DtUUID findUUID(const DtEntityIdentifier &entityId) const
Finds the UUID for an entity by its entity identifier.
Definition entityResolver.h:149
DtEntityIdentifier findEntityId(makVrv::DtElementID elementID) const
Entity identifier lookup methods.
Definition entityResolver.h:196
std::map< makVrv::DtElementID, makVrv::DtSceneObject * > SceneObjectMap
Type definition for mapping from element IDs to scene objects.
Definition entityResolver.h:61
makVrv::DtDe & myDe
Reference to the display engine.
Definition entityResolver.h:348
std::map< makVrv::DtElementID, std::string > ElementIdToStringMap
Type definition for mapping from element IDs to strings.
Definition entityResolver.h:58
SceneObjectMap mySceneObjectMap
Mapping from element IDs to scene objects.
Definition entityResolver.h:363
const DtEntityResolver::SceneObjectMap & sceneObjects() const
Gets the map of all scene objects.
makVrv::DtElementID findElementIdByObjectId(const std::string &objectId) const
Finds the element ID for an entity by its object ID.
DtEntityIdentifier findEntityId(const std::string &displayName) const
Finds the entity identifier for an entity by its display name.
Definition entityResolver.h:208
makVrv::DtSceneObject * findSceneObjectByObjectId(const std::string &objectId) const
Finds the scene object for an entity by its object ID.
std::string findObjectId(makVrv::DtElementID elementID) const
Object ID lookup methods.
void onElementIdRealized(makVrv::DtElementID id)
Handles element ID realization.
DtEntityResolver(makVrv::DtDe &de)
Constructor.
StringToElementIdMap myDisplayNameToElementIdMap
Mapping from display names to element IDs.
Definition entityResolver.h:351
virtual ~DtEntityResolver()
Virtual destructor.
makVrv::DtSceneObject * findSceneObjectByEntityId(const DtEntityIdentifier &entityId) const
Finds the scene object for an entity by its entity identifier.
Definition entityResolver.h:296
const StringToElementIdMap & displayNames() const
Gets the map of all display names to element IDs.
std::vector< std::shared_ptr< EntityDiscoveredMessage > > myPendingRealization
List of discovered entities awaiting realization.
Definition entityResolver.h:369
boost::signalslib::signal< void(makVrv::DtElementID entity)> signal_entityRemoved
Signal emitted when an entity is removed.
Definition entityResolver.h:315
makVrv::DtSceneObject * findSceneObject(makVrv::DtElementID elementId) const
Scene object lookup methods.
ElementIdToStringMap myElementIdToObjectIdMap
Mapping from element IDs to object IDs.
Definition entityResolver.h:360
std::map< std::string, makVrv::DtElementID > StringToElementIdMap
Type definition for mapping from strings to element IDs.
Definition entityResolver.h:55
void slot_elementsRemoved(const makVrv::DtElementData::ElementIdList &elements)
Slot called when elements are removed.
std::string findObjectType(const DtEntityIdentifier &entityId) const
Finds the object type for an entity by its entity identifier.
Definition entityResolver.h:230
void slot_elementsReadyToProcess(const makVrv::DtElementData::ElementIdList &elements)
Element processing slots.
DtUUID findUUID(makVrv::DtElementID elementID) const
UUID lookup methods.
ElementIdToStringMap myElementIdToDisplayNameMap
Mapping from element IDs to display names.
Definition entityResolver.h:354
std::string findDisplayName(const DtEntityIdentifier &entityId) const
Finds the display name for an entity by its entity identifier.
Definition entityResolver.h:168
makVrv::DtSceneObject * sceneObjectFromElementId(makVrv::DtElementID elementId, makVrv::DtModelSetId modelSet)
Retrieves a scene object from an element ID.
std::string findObjectType(makVrv::DtElementID elementID) const
Object type lookup methods.
makVrv::DtElementID findElementIdByEntityId(const DtEntityIdentifier &entityId) const
Finds the element ID for an entity by its entity identifier.
Definition entityResolver.h:126
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Definition entityDiscovered.h:31
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Defines the base class for all VREngage messages.