API Documentation
Loading...
Searching...
No Matches
DesignObject.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: DesignObject
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/DesignObjectBase.h>
35#include <NDEVR/RWLock.h>
36#include <NDEVR/TranslatedString.h>
37namespace NDEVR
38{
39 class DesignCommand;
40 class File;
41 class Scene;
42 class JSONNode;
43 class SelectionInfo;
44#ifdef _DEBUG
45 constexpr bool DESIGN_PRIM = false;
46#else
47 constexpr bool DESIGN_PRIM = true;
48#endif
49 /**--------------------------------------------------------------------------------------------------
50 \brief A low-level database object that can be used to access general stored properties within the NDEVR
51 Model heirarchy or 3D environment.
52
53 Can represent a geometry, model, material, bone, or effect. The object itself can be thought of
54 as pointer to an entity in the database, and in general its destruction, will have no impact on the database
55 itself.
56
57 This object stores a pointer to a DesignObjectBase object which is the database containing all properties
58 which are retrieved via an index (for general properties) or a design index, for properties specific to
59 models, geometries, etc
60 \warning Access to these members and data should be made in a thread-safe manner using DesignObjectLookup
61 read and write locks.
62 Author: Tyler Parke
63
64 Date: 2018-03-22
65 **/
67 {
68 public:
69 /**--------------------------------------------------------------------------------------------------
70 Enum representing the type of object a design object could be. A design object can be checked for
71 inheritance using the isDesignType function.
72 **/
74 {
75 e_model = 0x00000001
76 , e_geometry = 0x00000002
77 , e_material = 0x00000004
78 , e_bone = 0x00000008
79 , e_effect = 0x00000010
80 , e_layer = 0x00000020
81 , e_scene = 0x00000040
82 , e_camera = 0x00000080
83 , e_selection = 0x00000100
84 };
85 /**--------------------------------------------------------------------------------------------------
86 \brief Values stored in the property database.
87
88 A specific value can be retrieved using the getProperty command
89 or set via the setPropertyCommand. Upon changing the value, at some point, updateDesignModifiedTime
90 should be called to notify the application about the changes to the design object.
91 **/
93 {
94 e_guid // A 128 bit globally unique identifier for the object.
95 , e_design_types // The location of the bitflag storing what type of obect this is
96 , e_transform // A 4x4 transform that describes how to translate any coordinates into global space
97 , e_bounding_box
98 , e_selection_box
99 , e_name // The name of the object
100 , e_description // The Description of the object
101 , e_editable_description // Whether or not the user is allowed to modify the description of the object
102 , e_creation_time
103 , e_modified_time
104 , e_asc_modified_time
105 , e_desc_modified_time
106 , e_bounds_modified_time
107 , e_author
108 , e_creation_software
109 , e_3D_visible
110 , e_tree_visible
111 , e_icon
113 , e_is_focused
114 , e_allow_interactions
116 , e_search_terms
117 , e_category
118 , e_deletion_allowed
120 , e_is_application_locked
121 , e_is_application_owned
122 , e_bounds_ignored
123 , e_selection_ignored
124 , e_meta_data
125 , e_untranslated_string_data
126 , e_translated_string_data
127 , e_uncompressed_data
128 , e_compressed_data
129 , e_manager_visible
130 , e_library_id
131 , e_is_frozen
132 , e_applied_filters
133 //////////////////
134 , e_design_property_size//always last
135 };
136
137 /**--------------------------------------------------------------------------------------------------
138 \brief Creates an "invalid" design object. This object does not have a backing database, and all indices will
139 be Invalid. Checking properties on this object is not permitted but you may use the '=' to set this model
140 to a different model.
141
142 Author: Tyler Parke
143
144 Date: 2018-03-22
145 **/
146 DesignObject() = default;
147
148 /**--------------------------------------------------------------------------------------------------
149 \brief Creates an new design object within the given DesignObjectBase. This object is appended to the end
150 of the DesignObjectBase data structure and values are setup to defaults.
151
152 Author: Tyler Parke
153
154 Date: 2018-03-22
155 **/
157
158 /**--------------------------------------------------------------------------------------------------
159 \brief Sets a DesignObject up to be a pointer to an existing object in the database. If the index is invalid
160 behavior is undefined.
161
162 Author: Tyler Parke
163
164 Date: 2018-03-22
165 **/
167#ifdef _DEBUG
169#endif
170 void setDesignType(DesignObjectType mode, bool is_type);
172 bool isDesignType(uint04 mode) const;
175 void setActiveFilters(const JSONNode& node);
176 template<class t_type>
177 void setProperty(DesignProperty property, const t_type& value)
178 {
179 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
180 switch (property)
181 {
182 case e_guid:
183 m_uuid = getProperty<UUID>(property);
184 break;
185 case e_bounding_box:
186 //lib_assert((getProperty<Bounds<3, fltp08>>(property) != Constant<Bounds<3, fltp08>>::Min), "Tried to set min bounding box");
187 break;
188#ifdef _DEBUG
189 case e_transform:
190 {
191 Matrix<fltp08> mat = getProperty<Matrix<fltp08>>(property);
192 lib_assert(!IsInvalid(mat), "Tried to set Invalid transform");
193 lib_assert(!IsInvalid(mat.invert()), "Tried to set to non-invertable transform");
194 } break;
195 case e_name:
196 debug_name = getProperty<String>(property);
197 break;
198#endif
199 default:
200 break;
201 }
202 }
203 template<>
204 void setProperty(DesignProperty property, const UUID& value)
205 {
206 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
207 switch (property)
208 {
209 case e_guid:
210 m_uuid = value;
211 break;
212 default:
213 break;
214 }
215 }
216 template<>
217 void setProperty(DesignProperty property, const String& value)
218 {
219 switch (property)
220 {
221 case e_name:
222 onNameChange(value);
223 break;
224 default:
225 break;
226 }
227 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
228 }
229 File file() const;
230 /*template<>
231 void setProperty(DesignProperty property, const TranslatedString& value)
232 {
233 switch (property)
234 {
235 case e_name:
236 onNameChange(value.translation());
237 break;
238 default:
239 break;
240 }
241 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
242 }*/
243 template<class t_type>
244 void updateProperty(DesignProperty property, const t_type& value, const void* lock = nullptr)
245 {
246 if (getProperty<t_type>(property) != value)
247 {
248 WLock wLock(lock);
249 setProperty(property, value);
250 updateDesignModifiedTime();
251 }
252 }
253 //Scene getScene() const;
254
255 template<class t_type>
256 [[nodiscard]] t_type getProperty(DesignProperty property) const
257 {
258 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].get<t_type>(index());
259 }
260
261 template<class t_type>
262 [[nodiscard]] bool hasProperty(DesignProperty property) const
263 {
264 return !IsInvalid(getProperty<t_type>(property));
265 }
266 [[nodiscard]] bool isProperty(DesignProperty property, const String& value) const
267 {
268 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].isSame(index(), value);
269 }
270 [[nodiscard]] bool isProperty(DesignProperty property, const char* value) const
271 {
272 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].isSame(index(), value);
273 }
274 [[nodiscard]] bool doesPropertyBeginWith(DesignProperty property, const String& value, bool ignore_case) const
275 {
276 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].beginsWith(index(), value, ignore_case);
277 }
278 [[nodiscard]] bool doesPropertyBeginWith(DesignProperty property, const char* value, bool ignore_case) const
279 {
280 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].beginsWith(index(), value, ignore_case);
281 }
282 [[nodiscard]] bool doesPropertyContain(DesignProperty property, const String& value, bool ignore_case) const
283 {
284 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].contains(index(), value, ignore_case);
285 }
286 [[nodiscard]] bool doesPropertyContain(DesignProperty property, const char* value, bool ignore_case) const
287 {
288 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].contains(index(), value, ignore_case);
289 }
290 template<class t_type>
291 [[nodiscard]] t_type getInheritedProperty(DesignProperty property) const
292 {
293 if (hasProperty<t_type>(property))
294 return getProperty<t_type>(property);
295 uint04 parent_index = getDesignParentIndex();
296 while (!IsInvalid(parent_index))
297 {
298 DesignObject parent(parent_index, m_base);
299 if (parent.hasProperty<t_type>(property))
300 return parent.getProperty<t_type>(property);
301 else
302 parent_index = parent.getDesignParentIndex();
303 }
304 return getProperty<t_type>(property);
305 }
306
307 //virtual bool processSelection(SelectionInfo& info) const;
308 [[nodiscard]] String getIcon() const;
309
310 [[nodiscard]] uint04 getDesignParentIndex() const;
311
312 [[nodiscard]] Time getModifiedTime() const;
313
314 void updateDesignModifiedTime(Time time = Time::SystemTime());
316 void copyFrom(const DesignObject& object);
317 //Adjusts this model's index based on models being deleted from the specified index
319 void addIndex(uint04 index, uint04 size);
320 void scale(Vector<3, fltp08> scale, Vertex<3, fltp08> center_of_scale = Constant<Vertex<3, fltp08>>::Invalid);
321 void offset(const Vector<3, fltp08>& offset);
322 bool hasMetaData(const String& index) const;
323 [[nodiscard]] const JSONNode& metaData(const String& index) const;
324 [[nodiscard]] const JSONNode& metaData() const;
325 void setMetaData(const JSONNode& node);
326 void setMetaData(const String& index, const JSONNode& node);
327 void setMetaData(const String& index, const String& data);
328 void setMetaData(const String& index, const bool& data);
329 void setMetaData(const String& index, const fltp08& data);
330 void setMetaData(const String& index, const uint04& data);
331 void clearMetaData(const String& index);
332 void updateMetaData(const String& index, const String& data, const void* lock_ptr = nullptr);
333 void updateMetaData(const String& index, const fltp08& data, const void* lock_ptr = nullptr);
334 void updateMetaData(const String& index, const bool& data, const void* lock_ptr = nullptr);
335 void removeMetaData(const String& index, const void* lock_ptr = nullptr);
336 void appendData(const String& data, bool compressed);
337 inline uint04 index() const { return m_index; }
338 inline uint04 designIndex() const { return m_design_index; }
339 [[nodiscard]] const DynamicPointer<Table>& propertyTable() const;
341 bool operator==(const DesignObject& model) const;
342 bool operator!=(const DesignObject& model) const;
343 bool operator<(const DesignObject& model) const;
344 bool operator>(const DesignObject& model) const;
345 operator bool() const
346 {
347 return isValid();
348 }
349 [[nodiscard]] DesignObjectBase& base() const { return *m_base; }
350 [[nodiscard]] UUID uuid() const;
351 void updateDesignTransform(const Matrix<fltp08>& transform, const void* lock = nullptr);
352 void setDesignVisible(bool is_visible);
353 void updateDesignVisible(bool is_visible, const void* lock = nullptr);
354 [[nodiscard]] Matrix<fltp08> getTransform() const;
355 [[nodiscard]] bool isValid() const { return !IsInvalid(m_index); }
356 [[nodiscard]] Scene getScene() const;
357 [[nodiscard]] static constexpr const char* FilePathDesignNameVariable() { return "[DESIGN_NAME]"; }
358
359 protected:
360 void onNameChange(const String& new_name);
361 protected:
365 DesignObjectBase* m_base = nullptr;
366#ifdef _DEBUG
367 String debug_name;
368#endif
369 };
371 //static_assert(!std::is_polymorphic<DesignObject>(), "Model should not be polymorphic");
372 template<>
374 {
375 static const uint01 Dimensions = 0;
376 static const bool Vector = false;
377 static const bool Buffer = false;
378 static const bool Primitive = DESIGN_PRIM;
379 static const bool Pointer = false;
380 static const bool Unsigned = false;
381 static const bool Float = false;
382 static const bool Integer = false;
383 static const bool Number = false;
384 static const bool Enum = false;
385 static const bool String = false;
386 static const bool Color = false;
387 static const bool Boolean = false;
389 };
390}
391
392namespace std//Define things to allow use within std libs
393{
394 template <>
395 struct hash<NDEVR::DesignObject>
396 {
397 std::size_t operator()(const NDEVR::DesignObject& d) const noexcept
398 {
399 NDEVR::UUID s = d.uuid();
400 std::size_t value = 0;
401 for (NDEVR::uint01 i = 0; i < 8; i++)
402 {
403 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
404 }
405 return value;
406 }
407 };
408};
409
410
411
412
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
#define lib_assert(expression, message)
Definition LibAssert.h:61
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
The core Color class in the NDEVR API. Colors can be defined in several ways. The ACIColor is compact...
Definition Color.h:41
Provides the underlying data storage for the NDEVR Scene Model heirarchy.
Definition DesignObjectBase.h:150
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
void updateMetaData(const String &index, const String &data, const void *lock_ptr=nullptr)
DesignObject(uint04 index, DesignObjectBase *base)
Sets a DesignObject up to be a pointer to an existing object in the database. If the index is invalid...
bool doesPropertyContain(DesignProperty property, const String &value, bool ignore_case) const
Definition DesignObject.h:282
Scene getScene() const
DynamicPointer< Table > & propertyTable()
bool operator!=(const DesignObject &model) const
bool operator==(const DesignObject &model) const
const DynamicPointer< Table > & propertyTable() const
bool isProperty(DesignProperty property, const char *value) const
Definition DesignObject.h:270
static constexpr const char * FilePathDesignNameVariable()
Definition DesignObject.h:357
void removeMetaData(const String &index, const void *lock_ptr=nullptr)
JSONNode activeFilters() const
DesignObject()=default
Creates an "invalid" design object. This object does not have a backing database, and all indices wil...
bool doesPropertyBeginWith(DesignProperty property, const String &value, bool ignore_case) const
Definition DesignObject.h:274
void setActiveFilters(const JSONNode &node)
void updateMetaData(const String &index, const bool &data, const void *lock_ptr=nullptr)
String getIcon() const
bool isDesignType(DesignObjectType mode) const
void actionDeletedIndex(uint04 index, uint04 size)
bool isValid() const
Definition DesignObject.h:355
void setDesignType(DesignObjectType mode, bool is_type)
bool hasMetaData(const String &index) const
uint04 designIndex() const
Definition DesignObject.h:338
t_type getInheritedProperty(DesignProperty property) const
Definition DesignObject.h:291
UUID uuid() const
DesignObject(DesignObjectBase *base)
Creates an new design object within the given DesignObjectBase. This object is appended to the end of...
void updateDesignTransform(const Matrix< fltp08 > &transform, const void *lock=nullptr)
void updateDesignModifiedTime(Time time=Time::SystemTime())
uint04 index() const
Definition DesignObject.h:337
void updateProperty(DesignProperty property, const t_type &value, const void *lock=nullptr)
Definition DesignObject.h:244
void setProperty(DesignProperty property, const UUID &value)
Definition DesignObject.h:204
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:256
void setMetaData(const String &index, const fltp08 &data)
bool validateDesignObject() const
bool operator<(const DesignObject &model) const
void offset(const Vector< 3, fltp08 > &offset)
void setMetaData(const String &index, const String &data)
void updateMetaData(const String &index, const fltp08 &data, const void *lock_ptr=nullptr)
void setMetaData(const JSONNode &node)
File file() const
bool doesPropertyContain(DesignProperty property, const char *value, bool ignore_case) const
Definition DesignObject.h:286
void setDesignVisible(bool is_visible)
Matrix< fltp08 > getTransform() const
const JSONNode & metaData(const String &index) const
bool hasProperty(DesignProperty property) const
Definition DesignObject.h:262
DesignObjectType
Definition DesignObject.h:74
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:177
void addIndex(uint04 index, uint04 size)
void setMetaData(const String &index, const bool &data)
void copyFrom(const DesignObject &object)
void setMetaData(const String &index, const JSONNode &node)
void clearMetaData(const String &index)
bool operator>(const DesignObject &model) const
uint04 getDesignParentIndex() const
DesignProperty
Values stored in the property database.
Definition DesignObject.h:93
Time getModifiedTime() const
void updateDesignVisible(bool is_visible, const void *lock=nullptr)
void onNameChange(const String &new_name)
const JSONNode & metaData() const
void setMetaData(const String &index, const uint04 &data)
void setProperty(DesignProperty property, const String &value)
Definition DesignObject.h:217
DesignObjectBase & base() const
Definition DesignObject.h:349
bool doesPropertyBeginWith(DesignProperty property, const char *value, bool ignore_case) const
Definition DesignObject.h:278
void appendData(const String &data, bool compressed)
bool isProperty(DesignProperty property, const String &value) const
Definition DesignObject.h:266
bool isDesignType(uint04 mode) const
void scale(Vector< 3, fltp08 > scale, Vertex< 3, fltp08 > center_of_scale=Constant< Vertex< 3, fltp08 > >::Invalid)
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:60
Definition Matrix.hpp:176
Matrix< t_type, t_cols, t_rows > invert() const
Definition Matrix.hpp:652
Provides shared ownership of a dynamically allocated object.
Definition Pointer.hpp:71
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Model.h:492
The core String class for the NDEVR API.
Definition String.h:69
Logic for reading or writing to a string or a user friendly, TranslatedString.
Definition StringStream.h:230
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Used to lock a particular variable for writing. Only one write lock can be created when no read locks...
Definition RWLock.h:115
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
constexpr bool DESIGN_PRIM
Definition DesignObject.h:47
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
@ e_file
Definition ModuleResourceManager.h:52
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Definition File.h:211
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Information about the object.
Definition ObjectInfo.h:54