NDEVR
API Documentation
SetPropertiesCommand.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/DesignCommand.h>
4#include <NDEVR/Model.h>
5#include <NDEVR/Geometry.h>
6#include <NDEVR/Material.h>
7#include <NDEVR/Buffer.h>
8#include <NDEVR/DesignObjectLookup.h>
9#include <NDEVR/DesignParameter.h>
10#include <NDEVR/Translator.h>
11namespace NDEVR
12{
21 template<auto t_property, class t_type = typename PropertySpec<t_property>::type>
23 {
24 public:
27 {}
28
33 SetProperty(const DesignObject& object, const t_type& value)
34 : value(value)
35 , m_target(object.get<NDPO::guid>())
37 {}
38
43 SetProperty(const t_type& value)
44 : value(value)
45 , m_target(Constant<UUID>::Invalid)
47 {}
48
59
63 virtual StringView icon() const override
64 {
65 return "about";
66 }
67
71 virtual TranslatedString name() const override
72 {
73 return _t("Set Property");
74 }
75
81 void execute(DesignObjectLookup* lookup) override
82 {
83 WLock lock(lookup->writeLock());
84 DesignObject object = lookup->object(m_target);
85 if (is_undo)
86 {
87 object.update<t_property>(m_previous_value);
88 }
89 else
90 {
91 m_previous_value = object.get<t_property, t_type>();
92 object.update<t_property>(value);
93 }
94 }
95
100 virtual bool addTarget(UUID target_id) override { m_target = target_id; return true; }
101 t_type value;
102 protected:
105 };
106
114 template<auto t_property, class t_type = typename PropertySpec<t_property>::type>
116 {
117 public:
120 {
121 }
122
127 : value(value)
128 {
129 }
130
134 virtual StringView icon() const override
135 {
136 return "about";
137 }
138
142 virtual TranslatedString name() const override
143 {
144 return _t("Set Properties");
145 }
146
154 {
155 WLock lock(lookup->writeLock());
156 if (!is_undo)
157 m_previous_values.clear(targets.size());
158 for (uint04 i = 0; i < targets.size(); i++)
159 {
160 DesignObject object = lookup->object(targets[i]);
161 if (!object.isValid())
162 continue;
163 t_type previous_value;
164 if (is_undo)
165 {
166 object.update<t_property>(m_previous_values[i]);
167 }
168 else
169 {
170 m_previous_values.add(object.get<t_property, t_type>());
171 object.update<t_property>(value);
172 }
173 }
174 }
175
180 virtual bool addTarget(UUID target_id) override { targets.add(target_id); return true; }
181 t_type value;
183 protected:
185 };
186
194 {
195 public:
206
209
213 virtual StringView icon() const override
214 {
215 return "about";
216 }
217
221 virtual TranslatedString name() const override
222 {
223 return _t("Set Properties");
224 }
225
229 NDEVR_DESIGN_API virtual void execute(DesignObjectLookup* lookup) override;
237 template<class t_type>
238 void add(const DesignObject& obj, NDPO prop, const t_type& value)
239 {
240 properties.add({ obj.get<NDPO::guid>(), DesignParameter(prop), String(value) });
241 }
242
249 template<class t_type>
250 void add(const Geometry& geo, NDPG prop, const t_type& value)
251 {
252 properties.add({ geo.get<NDPO::guid>(), DesignParameter(prop), String(value) });
253 }
254
261 template<class t_type>
262 void add(const Material& mat, NDPM prop, const t_type& value)
263 {
264 properties.add({ mat.get<NDPO::guid>(), DesignParameter(prop), String(value) });
265 }
266
272 virtual bool addTarget(UUID) override { return false; }
273 public:
275 };
276}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
DesignCommand()
Default constructor.
bool is_undo
Whether this command represents an undo operation.
A core class where all Design Objects including models, materials, and geometries are stored.
DesignObject object(const UUID &id) const
Retrieves a generic design object by its UUID.
WLock writeLock() const
Acquires an exclusive write lock on the design object store.
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
A definition of data that is logically stored in the Model hierarchy.
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
void add(const Geometry &geo, NDPG prop, const t_type &value)
Adds a property change for a Geometry object identified by an NDPG property.
void add(const DesignObject &obj, NDPO prop, const t_type &value)
Adds a property change for a DesignObject identified by an NDPO property.
virtual void execute(DesignObjectLookup *lookup) override
Executes or undoes all property changes stored in this command.
SetPropertiesCommand()
Default constructor.
void add(const Material &mat, NDPM prop, const t_type &value)
Adds a property change for a Material object identified by an NDPM property.
virtual StringView icon() const override
Returns the icon identifier for this command.
virtual TranslatedString name() const override
Returns the human-readable name of this command for display in the UI.
Buffer< PropertyValue > properties
The list of property changes to apply.
virtual bool addTarget(UUID) override
This command does not support adding targets via UUID; property targets are specified individually th...
virtual TranslatedString name() const override
Returns the human-readable name of this command for display in the UI.
void execute(DesignObjectLookup *lookup)
Executes or undoes the property change on all target objects.
virtual bool addTarget(UUID target_id) override
Adds a target object by UUID to this command's target list.
virtual StringView icon() const override
Returns the icon identifier for this command.
SetProperties()
Default constructor.
t_type value
The new property value to apply to all targets.
Buffer< UUID > targets
The list of target design object UUIDs.
SetProperties(t_type value)
Constructs a SetProperties command with the value to apply to all targets.
Buffer< t_type > m_previous_values
Stored previous values for each target, used for undo.
void execute(DesignObjectLookup *lookup) override
Executes or undoes the property change on the target object.
SetProperty(const t_type &value)
Constructs a SetProperty command with a value but no target.
virtual StringView icon() const override
Returns the icon identifier for this command.
SetProperty(const SetProperty< t_property, t_type > &value)
Copy constructor.
t_type value
The new property value to apply.
virtual bool addTarget(UUID target_id) override
Sets the target object for this command by UUID, replacing any previous target.
UUID m_target
The UUID of the target design object.
SetProperty(const DesignObject &object, const t_type &value)
Constructs a SetProperty command targeting a specific object with the given value.
virtual TranslatedString name() const override
Returns the human-readable name of this command for display in the UI.
SetProperty()
Default constructor.
t_type m_previous_value
The stored previous value, used for undo.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
NDPM
NDPM - NDEVR Design Property Material: Values stored in the material database.
Definition Material.h:53
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
NDPO
NDPO - NDEVR Design Property Object: Values stored in the property database.
@ guid
A 128-bit globally unique identifier for the object.
NDPG
Forward declaration for Geometry design object.
Definition Geometry.h:56
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Holds a single property assignment: a target object UUID, the property to change, and the new value s...
UUID target
The UUID of the design object to modify.
DesignParameter parameter
The property identifier to set.
String value
The new value, serialized as a string.