VR-Engage  2.3
Loading...
Searching...
No Matches
vreModelSetEntry.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreModelSetEntry.h
7//! \ingroup vreUtil
8//! \brief Extends model set entries with VR-Engage specific role data
9//!
10//! This file defines the DtVreModelSetEntry class which extends VR-Forces' DtModelSetEntry
11//! with the ability to read and write VR-Engage-specific role data in entity files.
12//! It manages role descriptors, parameters, and display configurations for entities.
13
14#pragma once
15
16#include "vreUtil/export.h"
19
20#include <vrfobjparam/modelSetEntry.h>
21
22namespace vreXml
23{
24//! \brief XML tag for VR-Engage roles container
25static const char* EngageRolesTag = "vrEngageRoles";
26//! \brief XML tag for individual VR-Engage role
27static const char* EngageRoleTag = "role";
28//! \brief XML tag for role slot name attribute
29static const char* EngageRoleSlotNameTag = "slotName";
30//! \brief XML tag for unlisted role attribute
31static const char* EngageRoleUnlistedTag = "unlisted";
32//! \brief XML tag for default display layout attribute
33static const char* EngageRoleDefaultDisplayConfigTag = "defaultDisplayLayout";
34//! \brief XML tag for the role's ordinal position within the role list
35//!
36//! The Simulation Object Editor alphabetically sorts XML elements when it saves
37//! an .entity file, which would otherwise scramble the authored order of role
38//! entries. This attribute records each role's intended position so the order
39//! can be restored on read regardless of the on-disk element order.
40static const char* EngageRoleOrderTag = "order";
41//! \brief XML tag for parameter override element
42static const char* EngageParameterOverrideTag = "parameterOverride";
43//! \brief XML tag for display configuration element
44static const char* EngageDisplayConfigurationTag = "displayConfiguration";
45} // namespace vreXml
46
47namespace makVre
48{
49//! \brief Default display layout name for entity roles
50//!
51//! It is expected that there will always be a default display layout available
52//! for all entity roles. This is the name of that expected display layout.
53static const char* DtDefaultDisplayLayout = "1 Screen Horizontal";
54
55//! \brief Default value for the unlisted attribute of roles
56//!
57//! By default, role configurations should be listed in the Choose Role panel.
58//! Setting this to true would hide the role from the panel.
59static bool DtDefaultUnlistedValue = false;
60
61//! \brief VR-Engage specific model set entry with role information
62//!
63//! This class extends the base VR-Forces model set entry to provide VR-Engage
64//! specific functionality for managing entity roles, role parameters, and display
65//! configurations. It handles reading and writing role data to/from entity files.
66class UTIL_DLL DtVreModelSetEntry : public DtModelSetEntry
67{
68public:
69 //! \brief Default constructor
70 //!
71 //! Creates an empty model set entry with no name or registry
73
74 //! \brief Named constructor with optional registry
75 //! \param name The name of the model set entry
76 //! \param parentRegistry Optional parent registry for resource loading
77 DtVreModelSetEntry(const DtString& name, DtReaderWriterRegistry* const parentRegistry = NULL);
78
79 //! \brief Copy constructor
80 //! \param orig The model set entry to copy
81 //! \param parentRegistry Optional parent registry for resource loading
82 DtVreModelSetEntry(const DtVreModelSetEntry& orig, DtReaderWriterRegistry* const parentRegistry = NULL);
83
84 //! \brief Assignment operator for VR-Engage model set entries
85 //! \param orig The model set entry to copy from
86 //! \return Reference to this object
87 //!
88 //! Performs a deep copy of the VR-Engage specific data
90
91 //! \brief Assignment operator for base model set entries
92 //! \param orig The base model set entry to copy from
93 //! \return Reference to this object
94 //!
95 //! The override allows us to eventually call the derived assignment operator
96 virtual DtVreModelSetEntry& operator=(const DtModelSetEntry& orig) override;
97
98 //! \brief Virtual destructor
99 //!
100 //! Cleans up resources owned by the model set entry
101 virtual ~DtVreModelSetEntry() override;
102
103 //! \brief Creates a copy of this model set entry
104 //! \return Pointer to the newly created copy
105 virtual DtModelSetEntry* clone() override;
106
107 //! \brief Checks if this entity can be controlled in VR-Engage
108 //! \return True if the entity is controllable in VR-Engage, false otherwise
109 virtual bool engageControllable() const;
110
111 //! \brief Gets the list of available roles for this entity
112 //! \return Vector of role names
113 virtual std::vector<std::string> roles();
114
115 //! \brief Finds a role descriptor by name
116 //! \param role The name of the role to find
117 //! \return Pointer to the role descriptor if found, nullptr otherwise
118 virtual const DtEntityRoleDescriptor* findRoleDescriptor(const std::string& role);
119
120 //! \brief Adds a new role to the entity
121 //! \param role The name of the role to add
122 //! \param rolePath Path to the role configuration file
123 //! \param unlisted Whether the role should be hidden from role selection panels
124 virtual void addRole(const std::string& role, const std::string& rolePath, bool unlisted = false);
125
126 //! \brief Adds a parameter to an existing role
127 //! \param role The name of the role to add the parameter to
128 //! \param roleParameter The name of the parameter to add
129 //! \param paramValue The value of the parameter
130 virtual void addRoleParameter(
131 const std::string& role, const std::string& roleParameter, const std::string& paramValue);
132
133 //! \brief Loads model set entry information from the specified environment
134 //! \param e The environment to read from
135 //! \param objectNode The object node to read from
136 //! \param keepCurrentData Whether to retain existing data when reading
137 //!
138 //! Looks for a variable in the environment called guiInformation and extracts
139 //! attributes and role information from that node. VR-Engage specific data is
140 //! read from the vrEngageRoles section if present.
141 virtual void readFromEnvironment(DtEnvironmentSP e, DtEnvValueSP objectNode, bool keepCurrentData = false) override;
142
143 //! \brief Writes entry contents to the specified environment
144 //! \param e The environment to write to
145 //! \param objectNode The object node to write to
146 //! \param vec Optional vector to track modified attributes
147 //! \param mse Optional model set entry for reference
148 //!
149 //! Writes the model set entry information to the guiInformation section of the
150 //! environment. VR-Engage specific role data is written to the vrEngageRoles section.
151 virtual void writeToEnvironment(DtEnvironmentSP e,
152 DtEnvValueSP objectNode,
153 std::vector<DtString>* vec = nullptr,
154 DtModelSetEntry* mse = nullptr) const override;
155
156 //! \brief Factory method for creating model set entry instances
157 //! \param name The name of the model set entry to create
158 //! \param parentRegistry Optional parent registry for resource loading
159 //! \return Pointer to the newly created model set entry
160 //!
161 //! This static method creates a new instance of DtVreModelSetEntry. Used by the factory system.
162 static DtModelSetEntry* Create(
163 const DtString& name = "model-set-entry", DtReaderWriterRegistry* const parentRegistry = nullptr);
164
165protected:
166 //! \brief Gets parameter overrides from an environment node
167 //! \param e The environment to read from
168 //! \param node The node to read parameters from
169 //! \param parameterOverrides Output map to store parameter name/value pairs
170 //!
171 //! Extracts parameter overrides from the given node, only including parameters
172 //! that are immediate children of that node.
174 DtEnvironmentSP e, DtEnvValueSP node, std::map<std::string, std::string>& parameterOverrides);
175
176 //! \brief Resolves path variables in a string
177 //! \param path The path string to resolve
178 //! \return The resolved path with variables expanded
179 //!
180 //! Replaces instances of '@' with '$' (as '@' is used instead of '$' in XML files)
181 //! and then resolves any $DATA_DIR or $SHARED_DATA_DIR variables in the path.
182 virtual std::string resolvePath(const std::string& path) const;
183
184 //! \brief Marks up a path with variables for XML storage
185 //! \param path The path string to mark up
186 //! \return The marked up path with variables and XML-safe characters
187 //!
188 //! Substitutes in $DATA_DIR or $SHARED_DATA_DIR variables for specific path prefixes,
189 //! and replaces '$' with '@' (needed for XML files which cannot tolerate '$').
190 virtual std::string markupPath(const std::string& path) const;
191
192protected:
193 //! \brief Map of role names to role descriptors
194 //!
195 //! Contains all the roles supported by this entity and their associated configuration
196 std::vector<std::pair<std::string, DtEntityRoleDescriptor>> myRoleDescriptors;
197
198 //! \brief Cache of the filename used to create this entry
199 //!
200 //! Stores the path to the entity file that was loaded to create this entry
201 std::string myFilename;
202};
203} // namespace makVre
virtual DtModelSetEntry * clone() override
Creates a copy of this model set entry.
virtual DtVreModelSetEntry & operator=(const DtModelSetEntry &orig) override
Assignment operator for base model set entries.
virtual std::string markupPath(const std::string &path) const
Marks up a path with variables for XML storage.
DtVreModelSetEntry(const DtVreModelSetEntry &orig, DtReaderWriterRegistry *const parentRegistry=NULL)
Copy constructor.
virtual std::string resolvePath(const std::string &path) const
Resolves path variables in a string.
virtual const DtEntityRoleDescriptor * findRoleDescriptor(const std::string &role)
Finds a role descriptor by name.
virtual ~DtVreModelSetEntry() override
Virtual destructor.
virtual std::vector< std::string > roles()
Gets the list of available roles for this entity.
virtual void addRole(const std::string &role, const std::string &rolePath, bool unlisted=false)
Adds a new role to the entity.
std::string myFilename
Cache of the filename used to create this entry.
Definition vreModelSetEntry.h:201
DtVreModelSetEntry()
Default constructor.
DtVreModelSetEntry(const DtString &name, DtReaderWriterRegistry *const parentRegistry=NULL)
Named constructor with optional registry.
virtual void writeToEnvironment(DtEnvironmentSP e, DtEnvValueSP objectNode, std::vector< DtString > *vec=nullptr, DtModelSetEntry *mse=nullptr) const override
Writes entry contents to the specified environment.
virtual void getParameterOverrides(DtEnvironmentSP e, DtEnvValueSP node, std::map< std::string, std::string > &parameterOverrides)
Gets parameter overrides from an environment node.
std::vector< std::pair< std::string, DtEntityRoleDescriptor > > myRoleDescriptors
Map of role names to role descriptors.
Definition vreModelSetEntry.h:196
virtual DtVreModelSetEntry & operator=(const DtVreModelSetEntry &orig)
Assignment operator for VR-Engage model set entries.
virtual void readFromEnvironment(DtEnvironmentSP e, DtEnvValueSP objectNode, bool keepCurrentData=false) override
Loads model set entry information from the specified environment.
static DtModelSetEntry * Create(const DtString &name="model-set-entry", DtReaderWriterRegistry *const parentRegistry=nullptr)
Factory method for creating model set entry instances.
virtual bool engageControllable() const
Checks if this entity can be controlled in VR-Engage.
virtual void addRoleParameter(const std::string &role, const std::string &roleParameter, const std::string &paramValue)
Adds a parameter to an existing role.
Defines data structures for entity role configurations.
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
!
Definition glsVreMessageUtil.h:50
static bool DtDefaultUnlistedValue
Default value for the unlisted attribute of roles.
Definition vreModelSetEntry.h:59
static const char * DtDefaultDisplayLayout
Default display layout name for entity roles.
Definition vreModelSetEntry.h:53
Definition vreModelSetEntry.h:23
static const char * EngageParameterOverrideTag
XML tag for parameter override element.
Definition vreModelSetEntry.h:42
static const char * EngageRoleUnlistedTag
XML tag for unlisted role attribute.
Definition vreModelSetEntry.h:31
static const char * EngageRoleTag
XML tag for individual VR-Engage role.
Definition vreModelSetEntry.h:27
static const char * EngageRolesTag
XML tag for VR-Engage roles container.
Definition vreModelSetEntry.h:25
static const char * EngageDisplayConfigurationTag
XML tag for display configuration element.
Definition vreModelSetEntry.h:44
static const char * EngageRoleOrderTag
XML tag for the role's ordinal position within the role list.
Definition vreModelSetEntry.h:40
static const char * EngageRoleDefaultDisplayConfigTag
XML tag for default display layout attribute.
Definition vreModelSetEntry.h:33
static const char * EngageRoleSlotNameTag
XML tag for role slot name attribute.
Definition vreModelSetEntry.h:29
Descriptor for an entity role.
Definition entityRoleDescriptorStructs.h:46
Extends model set entries with VR-Engage specific role data.