VR-Engage  2.2
Loading...
Searching...
No Matches
vreGlstudioUpdater.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreGlstudioUpdater.h
7//! \brief Defines templates for GLStudio attribute updaters with simulation state awareness
8//! \ingroup vrePilotFrontend
9
10#pragma once
11
14
15#include <vrvGlStudioShared/DtGlStudioAttributeUpdater.h>
16
17namespace makVre
18{
19//! \brief Template class that extends GLStudio updaters with simulation state awareness
20//!
21//! \tparam UpdaterBase Base updater class to extend
22//!
23//! This template extends GLStudio attribute updaters to be aware of simulation state,
24//! allowing instruments to be disabled based on aircraft system states. It caches the
25//! last valid value to avoid excessive updates and handles simulation state changes.
26template <typename UpdaterBase>
27class DtVreGlstudioUpdater : public UpdaterBase
28{
29public:
30 //! \brief Default constructor
32 : UpdaterBase()
33 , myLastValue("")
34 , myActive(false)
35 {
36 }
37
38 //! \brief Virtual destructor
39 //!
40 //! Removes message handlers when the updater is destroyed
46
47 //! \brief Initializes the updater
48 //! \param smoother Pointer to the smoother to use for value smoothing
49 //! \param de Pointer to the display element
50 //!
51 //! Registers message handlers and initializes the base updater
52 virtual void init(DtSmoother* smoother, makVrv::DtDe* de)
53 {
56
57 UpdaterBase::init(smoother, de);
58 }
59
60 //! \brief Gets the current value as a string
61 //! \param time Current simulation time in seconds
62 //! \return Current value formatted as a string
63 //!
64 //! If the instrument is active, updates the cached value. Otherwise, returns the last cached value.
65 virtual std::string value(double time)
66 {
67 if (myActive)
68 {
69 myLastValue = UpdaterBase::value(time);
70 }
71 return myLastValue;
72 }
73
74protected:
75 //! \brief Handles simulation state change messages
76 //! \param msg Pointer to the message being processed
77 //! \return Message processing result
78 //!
79 //! Updates the active state of the instrument based on the list of disabled instruments
80 //! in the simulation state message.
82 {
83 SimulationStateMessage* smsg = static_cast<SimulationStateMessage*>(msg);
84 const std::vector<std::string>& instruments = smsg->getDisabledInstruments();
85 myActive = std::find(instruments.begin(), instruments.end(), myStateAttribute) == instruments.end();
86 return HANDLED;
87 }
88
89private:
90 //! \brief Copy constructor (not implemented)
91 //! \param other Source object to copy from
93
94 //! \brief Assignment operator (not implemented)
95 //! \param other Source object to assign from
96 //! \return Reference to this object
98
99public:
100 //! \brief Name of the state attribute this updater is associated with
101 std::string myStateAttribute;
102
103 //! \brief Last calculated value, cached to avoid unnecessary updates
104 std::string myLastValue;
105
106 //! \brief Flag indicating if this instrument is currently active
108};
109
110//! \brief Creator template for registering VRE GLStudio updaters
111//!
112//! \tparam VreGlstudioUpdater Updater class to create
113//! \tparam GlstudioUpdaterCreator Base creator class
114//!
115//! Factory template that creates instances of GLStudio updaters with simulation
116//! state awareness. It allows replacing existing updaters or creating new ones.
117//! \ingroup vrePilotFrontend
118template <typename VreGlstudioUpdater, typename GlstudioUpdaterCreator>
119class DtVreGlstudioUpdaterCreator : public GlstudioUpdaterCreator
120{
121public:
122 //! \brief Constructor for replacing an existing updater
123 //! \param stateAttribute Name of the state attribute to associate with
124 //!
125 //! Use this constructor to replace an existing updater with a VRE-aware version.
126 DtVreGlstudioUpdaterCreator(const std::string& stateAttribute)
127 : GlstudioUpdaterCreator()
128 , myStateAttribute(stateAttribute)
129 {
130 }
131
132 //! \brief Constructor for creating a new updater with a custom name
133 //! \param stateAttribute Name of the state attribute to associate with
134 //! \param name Custom name for the updater
135 //!
136 //! Use this constructor to install this updater with a new name,
137 //! instead of replacing the base class updater.
138 DtVreGlstudioUpdaterCreator(const std::string& stateAttribute, const std::string& name)
139 : GlstudioUpdaterCreator()
140 , myStateAttribute(stateAttribute)
141 {
142 this->myName = name;
143 }
144
145 //! \brief Virtual destructor
147
148 //! \brief Creates a new instance of the updater
149 //! \return Pointer to a newly created updater
150 //!
151 //! Creates a new VRE GLStudio updater instance and configures its state attribute.
152 virtual makVrv::DtGlStudioAttributeUpdater* create() const
153 {
154 VreGlstudioUpdater* updater = new VreGlstudioUpdater;
155 updater->myStateAttribute = myStateAttribute;
156 return updater;
157 }
158
159 std::string myStateAttribute;
160
161private:
163};
164} // namespace makVre
std::string myStateAttribute
Definition vreGlstudioUpdater.h:159
virtual makVrv::DtGlStudioAttributeUpdater * create() const
Creates a new instance of the updater.
Definition vreGlstudioUpdater.h:152
virtual ~DtVreGlstudioUpdaterCreator()
Virtual destructor.
Definition vreGlstudioUpdater.h:146
DtVreGlstudioUpdaterCreator(const std::string &stateAttribute, const std::string &name)
Constructor for creating a new updater with a custom name.
Definition vreGlstudioUpdater.h:138
DtVreGlstudioUpdaterCreator(const std::string &stateAttribute)
Constructor for replacing an existing updater.
Definition vreGlstudioUpdater.h:126
virtual void init(DtSmoother *smoother, makVrv::DtDe *de)
Initializes the updater.
Definition vreGlstudioUpdater.h:52
virtual DtVreMessageResult handleSimulationStateMessage(makVre::DtVreMessage *msg)
Handles simulation state change messages.
Definition vreGlstudioUpdater.h:81
DtVreGlstudioUpdater()
Default constructor.
Definition vreGlstudioUpdater.h:31
DtVreGlstudioUpdater(const DtVreGlstudioUpdater &other)
Copy constructor (not implemented)
virtual std::string value(double time)
Gets the current value as a string.
Definition vreGlstudioUpdater.h:65
bool myActive
Flag indicating if this instrument is currently active.
Definition vreGlstudioUpdater.h:107
std::string myStateAttribute
Name of the state attribute this updater is associated with.
Definition vreGlstudioUpdater.h:101
virtual ~DtVreGlstudioUpdater()
Virtual destructor.
Definition vreGlstudioUpdater.h:41
DtVreGlstudioUpdater & operator=(const DtVreGlstudioUpdater &other)
Assignment operator (not implemented)
std::string myLastValue
Last calculated value, cached to avoid unnecessary updates.
Definition vreGlstudioUpdater.h:104
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
static DtVreMessageManager & instance()
Gets the singleton instance of the message manager.
virtual void addHandler(const std::string &messageType, const DtVreMessageDelegate &handler, HandlerPosition handlerPos=HandlerPosition::BACK)=0
Registers a message handler for a specific message type.
virtual void removeHandler(const std::string &messageType, const DtVreMessageDelegate &handler)=0
Unregisters a message handler for a specific message type.
Definition simulationState.h:34
static const std::string & theType()
static message identity functions
virtual const std::vector< std::string > & getDisabledInstruments() const
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtDelegate< DtVreMessageResult, DtVreMessage * > DtVreMessageDelegate
Delegate type for message handler callbacks.
Definition vreMessage.h:212
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
@ HANDLED
The handler processed the message; continue processing.
Definition vreMessage.h:35
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Defines the central message manager for the VREngage messaging system.