NDEVR
API Documentation
DesignObject.h
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 "DesignProperties.h"
35#include <NDEVR/DesignObjectBase.h>
36#include <NDEVR/RWLock.h>
37#include <NDEVR/TranslatedString.h>
38namespace NDEVR
39{
40 class DesignCommand;
41 class File;
42 class Scene;
43 class JSONNode;
44 class SelectionInfo;
45
46 class Model;
47 typedef PrimitiveAlignedBuffer<Model, 16> ModelBuffer;
48 class Effect;
49 typedef PrimitiveAlignedBuffer<Effect, 16> EffectBuffer;
50 class Material;
51 typedef PrimitiveAlignedBuffer<Material, 16> MaterialBuffer;
52 class Geometry;
53 typedef PrimitiveAlignedBuffer<Geometry, 16> GeometryBuffer;
73 class NDEVR_DESIGN_API DesignObject : public DesignInfo
74 {
75 public:
76 friend class Model;
86 DesignObject() = default;
87
97
107
112 DesignObject(const DesignInfo& info);
113
119 void setDesignType(DesignObjectType mode, bool is_type);
120
127
133 bool isDesignType(uint04 mode) const;
134
140
146
151 void setActiveFilters(const JSONNode& node);
152
160 template<class t_type, class t_property_type>
161 [[nodiscard]] constexpr decltype(auto) get(t_property_type property) const
162 {
163 return PropertyInterface<t_property_type>::template Get<t_type>(this, property);
164 }
165
172 template<auto t_property, class t_type>
173 [[nodiscard]] constexpr decltype(auto) get() const
174 {
175 using t_property_type = std::decay_t<decltype(t_property)>;
176 return PropertyInterface<t_property_type>::template Get<t_property, t_type>(this);
177 }
178
185 template<auto t_property>
186 [[nodiscard]] constexpr decltype(auto) get() const
187 {
188 using t_property_type = std::decay_t<decltype(t_property)>;
189 return PropertyInterface<t_property_type>::template Get<t_property>(this);
190 }
191
199 template<class t_type, class t_property_type>
200 void set(t_property_type property, const t_type& value)
201 {
202 PropertyInterface<t_property_type>::Set(this, property, value);
203 }
204
211 template<auto t_property, class t_type>
212 void set(const t_type& value)
213 {
214 using t_property_type = std::decay_t<decltype(t_property)>;
215 PropertyInterface<t_property_type>::template Set<t_property>(this, value);
216 }
217
228 template<class t_type, class t_property_type>
229 bool update(t_property_type property, const t_type& value, const void* lock = nullptr)
230 {
231 if (!is(property, value))
232 {
233 WLock wLock(lock);
234 set(property, value);
236 return true;
237 }
238 return false;
239 }
240
250 template<auto t_property, class t_type>
251 bool update(const t_type& value, const void* lock = nullptr)
252 {
253 if (!is<t_property>(value))
254 {
255 WLock wLock(lock);
256 set<t_property>(value);
258 return true;
259 }
260 return false;
261 }
262
270 template<class t_type, class t_design_type>
271 [[nodiscard]] bool hasProperty(t_design_type property) const
272 {
273 return IsValid(get<t_type>(property));
274 }
275
283 template<class t_property_type>
284 [[nodiscard]] bool is(t_property_type property, const StringView& value) const
285 {
286 return PropertyInterface<t_property_type>::IsSame(this, property, value);
287 }
288
296 template<class t_property_type>
297 [[nodiscard]] bool is(t_property_type property, const char* value) const
298 {
299 return PropertyInterface<t_property_type>::IsSame(this, property, value);
300 }
301
309 template<class t_property_type>
310 [[nodiscard]] bool is(t_property_type property, const String& value) const
311 {
312 return PropertyInterface<t_property_type>::IsSame(this, property, value);
313 }
314
323 template<class t_property_type, class t_type>
324 [[nodiscard]] typename std::enable_if<!ObjectInfo<t_type>::String, bool>::type is(t_property_type property, const t_type& value) const
325 {
326 return get<t_type>(property) == value;
327 }
328
335 template<auto t_property>
336 [[nodiscard]] bool is(const StringView& value) const
337 {
338 using t_property_type = std::decay_t<decltype(t_property)>;
339 return PropertyInterface<t_property_type>::IsSame(this, t_property, value);
340 }
341
348 template<auto t_property>
349 [[nodiscard]] bool is(const char* value) const
350 {
351 using t_property_type = std::decay_t<decltype(t_property)>;
352 return PropertyInterface<t_property_type>::IsSame(this, t_property, value);
353 }
354
361 template<auto t_property>
362 [[nodiscard]] bool is(const String& value) const
363 {
364 using t_property_type = std::decay_t<decltype(t_property)>;
365 return PropertyInterface<t_property_type>::IsSame(this, t_property, value);
366 }
367
375 template<auto t_property, class t_type>
376 [[nodiscard]] typename std::enable_if<!ObjectInfo<t_type>::String, bool>::type is(const t_type& value) const
377 {
378 return get<t_property, t_type>() == value;
379 }
380
388 [[nodiscard]] bool doesPropertyBeginWith(NDPO property, const StringView& value, bool ignore_case) const
389 {
390 return m_base->design_properties[eint01(property)]->beginsWith(index(), value, ignore_case);
391 }
392
400 [[nodiscard]] bool doesPropertyContain(NDPO property, const StringView& value, bool ignore_case) const
401 {
402 return m_base->design_properties[eint01(property)]->contains(index(), value, ignore_case);
403 }
404
412 template<class t_type>
413 [[nodiscard]] decltype(auto) getInheritedProperty(NDPO property) const
414 {
415 if (hasProperty<t_type>(property))
416 return get<t_type>(property);
417 DesignObject parent = getDesignParent();
418 while (parent.isValid())
419 {
420 if (parent.hasProperty<t_type>(property))
421 return parent.get<t_type>(property);
422 else
423 parent = parent.getDesignParent();
424 }
425 return get<t_type>(property);
426 }
427
432 [[nodiscard]] File file() const { return File(get<StringView>(NDPO::file)); }
433 //virtual bool processSelection(SelectionInfo& info) const;
434
439 [[nodiscard]] StringView getIcon() const;
440
445 [[nodiscard]] DesignObject getDesignParent() const;
446
453
458
463 void copyFrom(const DesignObject& object);
464
465 //Adjusts this model's index based on models being deleted from the specified index
472
480 void scale(Vector<3, fltp08> scale, Vertex<3, fltp08> center_of_scale, const Matrix<fltp08>& transform);
481
486 void offsetDesign(const Vector<3, fltp08>& offset);
487
493 bool hasMetaData(const StringView& index) const;
494
500 [[nodiscard]] const JSONNode& metaData(const StringView& index) const;
501
506 [[nodiscard]] const JSONNode& metaData() const;
507
512 void setMetaData(const JSONNode& node);
513
519 void setMetaData(const StringView& index, const JSONNode& node);
520
526 void setMetaData(const StringView& index, const String& data);
527
533 void setMetaData(const StringView& index, const StringView& data);
534
540 void setMetaData(const StringView& index, const bool& data);
541
547 void setMetaData(const StringView& index, const fltp08& data);
548
554 void setMetaData(const StringView& index, const uint01& data);
555
561 void setMetaData(const StringView& index, const uint04& data);
562
567
573
580 void updateMetaData(const StringView& index, const String& data, const void* lock_ptr = nullptr);
581
588 void updateMetaData(const StringView& index, const StringView& data, const void* lock_ptr = nullptr);
589
596 void updateMetaData(const StringView& index, const fltp08& data, const void* lock_ptr = nullptr);
597
604 void updateMetaData(const StringView& index, const bool& data, const void* lock_ptr = nullptr);
605
611 void removeMetaData(const StringView& index, const void* lock_ptr = nullptr);
612
618 void appendData(const StringView& data, bool compressed);
619
624 inline uint04 index() const { return m_index; }
625
631 inline uint04 designIndex() const { return m_design_index; }
632
637 [[nodiscard]] const Table& propertyTable() const;
638
643 [[nodiscard]] Table& propertyTable();
644
650 bool operator==(const DesignObject& object) const;
651
657 bool operator!=(const DesignObject& object) const;
658
664 bool operator<(const DesignObject& object) const;
665
671 bool operator>(const DesignObject& object) const;
672
676 operator bool() const { return isValid(); }
677
682 [[nodiscard]] DesignObjectBase& base() const { return *m_base; }
683
689 void updateDesignTransform(const Matrix<fltp08>& transform, const void* lock = nullptr);
690
697 bool updateDesignVisible(bool is_visible, const void* lock = nullptr);
698
703 [[nodiscard]] bool isValid() const { return IsValid(m_index); }
704
709 [[nodiscard]] Scene getScene() const;
710
715 [[nodiscard]] static constexpr StringView FilePathDesignNameVariable() { return "[DESIGN_NAME]"; }
716 protected:
721
729 template<class t_type>
730 void _setProperty(NDPO property, const t_type& value)
731 {
732 m_base->design_properties[eint01(property)]->set(m_index, value);
733 }
734 };
735#ifndef _DEBUG
736 static_assert(sizeof(DesignObject) == 16, "DesignObject size incorrect");
737#endif
738 template class NDEVR_DESIGN_API StringStream<NDPO>;
739 //static_assert(!std::is_polymorphic<DesignObject>(), "Model should not be polymorphic");
740
746 template<>
748 {
749 static const uint01 Dimensions = 0;
750 static const bool Vector = false;
751 static const bool Buffer = false;
752 static const bool Primitive = true;
753 static const bool Pointer = false;
754 static const bool Unsigned = false;
755 static const bool Float = false;
756 static const bool Integer = false;
757 static const bool Number = false;
758 static const bool Enum = false;
759 static const bool String = false;
760 static const bool Color = false;
761 static const bool Boolean = false;
762
768 };
769}
770
771namespace std//Define things to allow use within std libs
772{
778 template <>
779 struct hash<DesignObject>
780 {
786 std::size_t operator()(const DesignObject& d) const noexcept
787 {
788 UUID s = d.get<NDPO::guid>();
789 std::size_t value = 0;
790 for (uint01 i = 0; i < 8; i++)
791 {
792 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
793 }
794 return value;
795 }
796 };
797};
798
799
800
801
Forward declaration of the central design object registry.
uint04 m_index
Row index of this object within the property database.
uint04 m_design_index
Index of the parent design that owns this object.
DesignObjectBase * m_base
Pointer to the owning DesignObjectBase property database.
Provides the underlying data storage for the NDEVR Scene Model hierarchy.
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
DesignObject()=default
Creates an "invalid" design object.
void setActiveFilters(const JSONNode &node)
Sets the active filters on this design object from a JSON structure.
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
void scale(Vector< 3, fltp08 > scale, Vertex< 3, fltp08 > center_of_scale=Constant< Vertex< 3, fltp08 > >::Invalid)
Scales this design object's geometry and transform by the given scale factors around a center point.
void appendData(const StringView &data, bool compressed)
Appends data to this design object's data storage.
bool operator!=(const DesignObject &object) const
Checks inequality with another DesignObject.
void setMetaData(const StringView &index, const bool &data)
Sets a metadata entry at the given key to a boolean value.
bool hasProperty(t_design_type property) const
Checks whether a property has a valid (non-default) value.
std::enable_if<!ObjectInfo< t_type >::String, bool >::type is(const t_type &value) const
Checks whether a compile-time property matches a non-string value using equality comparison.
bool is(t_property_type property, const char *value) const
Checks whether a string property matches the given C-string value.
bool operator==(const DesignObject &object) const
Checks equality with another DesignObject by comparing base pointers and indices.
uint04 index() const
Returns the primary row index of this object within the DesignObjectBase property table.
void set(const t_type &value)
Sets a property value in the database using a compile-time property constant.
void set(t_property_type property, const t_type &value)
Sets a property value in the database.
bool update(const t_type &value, const void *lock=nullptr)
Updates a property using a compile-time property constant, only if the new value differs.
constexpr decltype(auto) get() const
Retrieves a property value using a compile-time property constant, cast to the requested type.
void clearMetaData(const StringView &index)
Removes a specific metadata entry by key.
void scale(Vector< 3, fltp08 > scale, Vertex< 3, fltp08 > center_of_scale, const Matrix< fltp08 > &transform)
Scales this design object's geometry by the given scale factors around a center point,...
void copyFrom(const DesignObject &object)
Copies all properties from the given design object into this one.
bool is(const char *value) const
Checks whether a compile-time property matches the given C-string value.
bool is(const String &value) const
Checks whether a compile-time property matches the given String value.
DesignObject(uint04 index, DesignObjectBase *base)
Sets a DesignObject up to be a pointer to an existing object in the database.
bool hasMetaData(const StringView &index) const
Checks whether a metadata entry exists for the given key.
void offsetDesign(const Vector< 3, fltp08 > &offset)
Translates this design object by the given offset vector.
const JSONNode & metaData() const
Retrieves the entire metadata tree for this design object.
void setMetaData(const StringView &index, const uint01 &data)
Sets a metadata entry at the given key to a uint01 value.
bool is(t_property_type property, const String &value) const
Checks whether a string property matches the given String value.
void _setProperty(NDPO property, const t_type &value)
Low-level property setter that directly writes to the design properties table without triggering side...
constexpr decltype(auto) get() const
Retrieves a property value using a compile-time property constant, with the type deduced from Propert...
const Table & propertyTable() const
Returns a const reference to the property table that stores this object's properties.
decltype(auto) getInheritedProperty(NDPO property) const
Retrieves a property value, walking up the parent hierarchy if the property is not set on this object...
Scene getScene() const
Retrieves the Scene that this design object belongs to.
void setMetaData(const StringView &index, const StringView &data)
Sets a metadata entry at the given key to a StringView value.
void setMetaData(const StringView &index, const JSONNode &node)
Sets a metadata entry at the given key to the specified JSON node value.
std::enable_if<!ObjectInfo< t_type >::String, bool >::type is(t_property_type property, const t_type &value) const
Checks whether a non-string property matches the given value using equality comparison.
File file() const
Returns the file path associated with this design object as a File object.
Table & propertyTable()
Returns a mutable reference to the property table that stores this object's properties.
static constexpr StringView FilePathDesignNameVariable()
Returns the placeholder variable string used in file paths to represent the design name.
bool isDesignType(DesignObjectType mode) const
Checks whether this object has the specified design type flag set.
bool isValid() const
Checks whether this design object has a valid index into the database.
void setMetaData(const JSONNode &node)
Replaces the entire metadata tree with the given JSON node.
DesignObject(DesignObjectBase *base)
Creates an new design object within the given DesignObjectBase.
bool isDesignType(uint04 mode) const
Checks whether this object has the specified design type flag set, using a raw integer value.
bool validateDesignObject() const
Validates the internal state of this design object, ensuring indices and base pointer are consistent.
bool is(t_property_type property, const StringView &value) const
Checks whether a string property matches the given StringView value.
DesignObjectBase & base() const
Returns a reference to the underlying DesignObjectBase database.
void removeMetaData(const StringView &index, const void *lock_ptr=nullptr)
Removes a metadata entry by key, with optional write lock support.
void updateMetaData(const StringView &index, const String &data, const void *lock_ptr=nullptr)
Updates a metadata entry only if the new value differs from the current value.
void setDesignType(DesignObjectType mode, bool is_type)
Sets or clears a design type flag on this object.
const JSONNode & metaData(const StringView &index) const
Retrieves a specific metadata entry by key.
bool doesPropertyContain(NDPO property, const StringView &value, bool ignore_case) const
Checks whether a string property's value contains the given substring.
void updateMetaData(const StringView &index, const StringView &data, const void *lock_ptr=nullptr)
Updates a metadata entry only if the new value differs from the current value.
bool doesPropertyBeginWith(NDPO property, const StringView &value, bool ignore_case) const
Checks whether a string property's value begins with the given substring.
DesignObject getDesignParent() const
Retrieves the parent design object of this object in the model hierarchy.
void clearAllMetaData()
Removes all metadata entries from this design object.
void setMetaData(const StringView &index, const uint04 &data)
Sets a metadata entry at the given key to a uint04 value.
bool update(t_property_type property, const t_type &value, const void *lock=nullptr)
Updates a property only if the new value differs from the current value.
void initDesignObject()
Initializes default property values for this design object after construction.
void setMetaData(const StringView &index, const String &data)
Sets a metadata entry at the given key to a String value.
StringView getIcon() const
Retrieves the icon identifier string associated with this design object.
void setMetaData(const StringView &index, const fltp08 &data)
Sets a metadata entry at the given key to a 64-bit floating point value.
void updateCreatedTime()
Sets the creation time stamp for this design object to the current system time.
JSONNode activeFilters() const
Retrieves the active filters applied to this design object as a JSON structure.
uint04 designIndex() const
Returns the design-specific index used to access type-specific properties (e.g., model,...
bool updateDesignVisible(bool is_visible, const void *lock=nullptr)
Updates the spatial visibility of this design object if it differs from the current value.
void updateDesignModifiedTime(Time time=Time::SystemTime())
Updates the modified time stamp for this design object.
void updateMetaData(const StringView &index, const bool &data, const void *lock_ptr=nullptr)
Updates a metadata entry only if the new value differs from the current value.
void updateMetaData(const StringView &index, const fltp08 &data, const void *lock_ptr=nullptr)
Updates a metadata entry only if the new value differs from the current value.
bool is(const StringView &value) const
Checks whether a compile-time property matches the given StringView value.
bool operator<(const DesignObject &object) const
Less-than comparison for ordering DesignObjects (e.g., for sorted containers).
DesignObject(const DesignInfo &info)
Constructs a DesignObject from an existing DesignInfo, sharing the same base and indices.
bool operator>(const DesignObject &object) const
Greater-than comparison for ordering DesignObjects (e.g., for sorted containers).
void updateDesignTransform(const Matrix< fltp08 > &transform, const void *lock=nullptr)
Updates the transform of this design object if it differs from the current value.
A core class that provides a dynamic effect to an object in a model hierarchy.
Definition Effect.h:158
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:149
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
static void Set(DesignInfo *object, t_property_enum property, const t_value_type &value)
Sets the value of a property on a design object using a runtime property enum.
static bool IsSame(const DesignInfo *object, t_value_type property, const StringView &value)
Checks whether a property's stored value matches a given string representation.
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Scene.h:52
Responsible for turning a user interaction into a selection within a DesignObjectLookup.
Definition Selector.h:52
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
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
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
static Time SystemTime()
Retrieves the current system time which is a combination of std::chrono::steady_clock to ensure smoot...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
PrimitiveAlignedBuffer< Effect, 16 > EffectBuffer
Aligned buffer of Effect objects with 16-byte alignment.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 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.
@ file
The source file path associated with this object.
PrimitiveAlignedBuffer< Model, 16 > ModelBuffer
Aligned buffer of Model objects with 16-byte alignment.
PrimitiveAlignedBuffer< Geometry, 16 > GeometryBuffer
Aligned buffer of Geometry objects with 16-byte alignment.
PrimitiveAlignedBuffer< Material, 16 > MaterialBuffer
Aligned buffer of Material objects with 16-byte alignment.
STL namespace.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
static const bool Float
Whether this type is a floating-point type.
static const bool Unsigned
Whether this type is unsigned.
static const bool Integer
Whether this type is an integer type.
static const bool String
Whether this type is a string type.
static const uint01 Dimensions
Number of vector dimensions (0 for scalar types).
static const bool Number
Whether this type is a numeric type.
static const bool Primitive
Whether this type is a primitive type.
static const bool Enum
Whether this type is an enum type.
static const bool Pointer
Whether this type is a pointer type.
static const bool Color
Whether this type is a color type.
static const bool Vector
Whether this type is a vector type.
static constexpr ObjectInfo< DesignObject, false, false > VectorSub()
Returns the ObjectInfo for the sub-element type when this type is used as a vector.
static const bool Boolean
Whether this type is a boolean type.
static const bool Buffer
Whether this type is a buffer type.
Information about the object.
Definition ObjectInfo.h:55