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 Class: DesignObject
51
52 A low-level database object that can be used to access general stored properties within a DesignObjectBase.
53 Generally 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
61 Author: Tyler Parke
62
63 Date: 2018-03-22
64 *-----------------------------------------------------------------------------------------------**/
66 {
67 public:
68 /**--------------------------------------------------------------------------------------------------
69 Enum: DesignObjectType
70
71 Enum representing the type of object a design object could be. A design object can be checked for
72 inheritance using the isDesignType function.
73 *-----------------------------------------------------------------------------------------------**/
75 {
76 e_model = 0x00000001
77 , e_geometry = 0x00000002
78 , e_material = 0x00000004
79 , e_bone = 0x00000008
80 , e_effect = 0x00000010
81 , e_layer = 0x00000020
82 , e_scene = 0x00000040
83 , e_camera = 0x00000080
84 , e_selection = 0x00000100
85 };
86 /**--------------------------------------------------------------------------------------------------
87 Enum: DesignProperty
88
89 Values stored in the property database. A specific value can be retrieved using the getProperty command
90 or set via the setPropertyCommand. Upon changing the value, at some point, updateDesignModifiedTime should be
91 called to notify the application about the changes to the design object.
92 *-----------------------------------------------------------------------------------------------**/
94 {
95 e_guid // A 128 bit globally unique identifier for the object.
96 , e_design_types // The location of the bitflag storing what type of obect this is
97 , e_transform // A 4x4 transform that describes how to translate any coordinates into global space
98 , e_bounding_box
99 , e_selection_box
100 , e_name // The name of the object
101 , e_description // The Description of the object
102 , e_editable_description // Whether or not the user is allowed to modify the description of the object
103 , e_creation_time
104 , e_modified_time
105 , e_asc_modified_time
106 , e_desc_modified_time
107 , e_bounds_modified_time
108 , e_author
109 , e_creation_software
110 , e_3D_visible
111 , e_tree_visible
112 , e_icon
114 , e_is_focused
115 , e_allow_interactions
117 , e_search_terms
118 , e_category
119 , e_deletion_allowed
121 , e_is_application_locked
122 , e_is_application_owned
123 , e_bounds_ignored
124 , e_selection_ignored
125 , e_meta_data
126 , e_untranslated_string_data
127 , e_translated_string_data
128 , e_uncompressed_data
129 , e_compressed_data
130 , e_manager_visible
131 , e_library_id
132 , e_is_frozen
133 , e_applied_filters
134 //////////////////
135 , e_design_property_size//always last
136 };
137
138 /**--------------------------------------------------------------------------------------------------
139 Fn: DesignObject::DesignObject()
140
141 Creates an "invalid" design object. This object does not have a backing database, and all indices will
142 be NaN. Checking properties on this object is not permitted but you may use the '=' to set this model
143 to a different model.
144
145 Author: Tyler Parke
146
147 Date: 2018-03-22
148 *-----------------------------------------------------------------------------------------------**/
149 DesignObject() = default;
150
151 /**--------------------------------------------------------------------------------------------------
152 Fn: DesignObject::DesignObject(DesignObjectBase* base)
153
154 Creates an new design object within the given DesignObjectBase. This object is appended to the end
155 of the DesignObjectBase data structure and values are setup to defaults.
156
157 Author: Tyler Parke
158
159 Date: 2018-03-22
160 *-----------------------------------------------------------------------------------------------**/
161 explicit DesignObject(DesignObjectBase* base);
162
163 /**--------------------------------------------------------------------------------------------------
164 Fn: DesignObject::DesignObject()
165
166 Sets a DesignObject up to be a pointer to an existing object in the database. If the index is invalid
167 behavior is undefined.
168
169 Author: Tyler Parke
170
171 Date: 2018-03-22
172 *-----------------------------------------------------------------------------------------------**/
174#ifdef _DEBUG
176#endif
177 void setDesignType(DesignObjectType mode, bool is_type);
178 bool isDesignType(DesignObjectType mode) const;
179 bool isDesignType(uint04 mode) const;
180 bool validateDesignObject() const;
181 JSONNode activeFilters() const;
182 void setActiveFilters(const JSONNode& node);
183 template<class t_type>
184 void setProperty(DesignProperty property, const t_type& value)
185 {
186 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
187 switch (property)
188 {
189 case e_guid:
190 m_uuid = getProperty<UUID>(property);
191 break;
192 case e_bounding_box:
193 //lib_assert((getProperty<Bounds<3, fltp08>>(property) != Constant<Bounds<3, fltp08>>::Min), "Tried to set min bounding box");
194 break;
195#ifdef _DEBUG
196 case e_transform:
197 {
198 Matrix<fltp08> mat = getProperty<Matrix<fltp08>>(property);
199 lib_assert(!isNaN(mat), "Tried to set NaN transform");
200 lib_assert(!isNaN(mat.invert()), "Tried to set to non-invertable transform");
201 } break;
202 case e_name:
203 debug_name = getProperty<String>(property);
204 break;
205#endif
206 default:
207 break;
208 }
209 }
210 template<>
211 void setProperty(DesignProperty property, const UUID& value)
212 {
213 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
214 switch (property)
215 {
216 case e_guid:
217 m_uuid = value;
218 break;
219 default:
220 break;
221 }
222 }
223 template<>
224 void setProperty(DesignProperty property, const String& value)
225 {
226 switch (property)
227 {
228 case e_name:
229 onNameChange(value);
230 break;
231 default:
232 break;
233 }
234 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
235 }
236 File file() const;
237 /*template<>
238 void setProperty(DesignProperty property, const TranslatedString& value)
239 {
240 switch (property)
241 {
242 case e_name:
243 onNameChange(value.translation());
244 break;
245 default:
246 break;
247 }
248 propertyTable().get()[m_base->property_index[cast<uint04>(property)]].set(index(), value);
249 }*/
250 template<class t_type>
251 void updateProperty(DesignProperty property, const t_type& value, const void* lock = nullptr)
252 {
253 if (getProperty<t_type>(property) != value)
254 {
255 WLock wLock(lock);
256 setProperty(property, value);
257 updateDesignModifiedTime();
258 }
259 }
260 //Scene getScene() const;
261
262 template<class t_type>
263 [[nodiscard]] t_type getProperty(DesignProperty property) const
264 {
265 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].get<t_type>(index());
266 }
267
268 template<class t_type>
269 [[nodiscard]] bool hasProperty(DesignProperty property) const
270 {
271 return !isNaN(getProperty<t_type>(property));
272 }
273 [[nodiscard]] bool isProperty(DesignProperty property, const String& value) const
274 {
275 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].isSame(index(), value);
276 }
277 [[nodiscard]] bool isProperty(DesignProperty property, const char* value) const
278 {
279 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].isSame(index(), value);
280 }
281 [[nodiscard]] bool doesPropertyBeginWith(DesignProperty property, const String& value, bool ignore_case) const
282 {
283 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].beginsWith(index(), value, ignore_case);
284 }
285 [[nodiscard]] bool doesPropertyBeginWith(DesignProperty property, const char* value, bool ignore_case) const
286 {
287 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].beginsWith(index(), value, ignore_case);
288 }
289 [[nodiscard]] bool doesPropertyContain(DesignProperty property, const String& value, bool ignore_case) const
290 {
291 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].contains(index(), value, ignore_case);
292 }
293 [[nodiscard]] bool doesPropertyContain(DesignProperty property, const char* value, bool ignore_case) const
294 {
295 return propertyTable().get()[m_base->property_index[cast<uint04>(property)]].contains(index(), value, ignore_case);
296 }
297 template<class t_type>
298 [[nodiscard]] t_type getInheritedProperty(DesignProperty property) const
299 {
300 if (hasProperty<t_type>(property))
301 return getProperty<t_type>(property);
302 uint04 parent_index = getDesignParentIndex();
303 while (!isNaN(parent_index))
304 {
305 DesignObject parent(parent_index, m_base);
306 if (parent.hasProperty<t_type>(property))
307 return parent.getProperty<t_type>(property);
308 else
309 parent_index = parent.getDesignParentIndex();
310 }
311 return getProperty<t_type>(property);
312 }
313
314 //virtual bool processSelection(SelectionInfo& info) const;
315 [[nodiscard]] String getIcon() const;
316
317 [[nodiscard]] uint04 getDesignParentIndex() const;
318
319 [[nodiscard]] Time getModifiedTime() const;
320
321 void updateDesignModifiedTime(Time time = Time::SystemTime());
322 void updateCreatedTime();
323 void copyFrom(const DesignObject& object);
324 //Adjusts this model's index based on models being deleted from the specified index
325 void actionDeletedIndex(uint04 index, uint04 size);
326 void addIndex(uint04 index, uint04 size);
327 void scale(Vector<3, fltp08> scale, Vertex<3, fltp08> center_of_scale = Constant<Vertex<3, fltp08>>::NaN);
328 void offset(const Vector<3, fltp08>& offset);
329 bool hasMetaData(const String& index) const;
330 [[nodiscard]] const JSONNode& metaData(const String& index) const;
331 [[nodiscard]] const JSONNode& metaData() const;
332 void setMetaData(const JSONNode& node);
333 void setMetaData(const String& index, const JSONNode& node);
334 void setMetaData(const String& index, const String& data);
335 void setMetaData(const String& index, const bool& data);
336 void setMetaData(const String& index, const fltp08& data);
337 void setMetaData(const String& index, const uint04& data);
338 void clearMetaData(const String& index);
339 void updateMetaData(const String& index, const String& data, const void* lock_ptr = nullptr);
340 void updateMetaData(const String& index, const fltp08& data, const void* lock_ptr = nullptr);
341 void updateMetaData(const String& index, const bool& data, const void* lock_ptr = nullptr);
342 void removeMetaData(const String& index, const void* lock_ptr = nullptr);
343 void appendData(const String& data, bool compressed);
344 inline uint04 index() const { return m_index; }
345 inline uint04 designIndex() const { return m_design_index; }
346 [[nodiscard]] const DynamicPointer<Table>& propertyTable() const;
347 [[nodiscard]] DynamicPointer<Table>& propertyTable();
348 bool operator==(const DesignObject& model) const;
349 bool operator!=(const DesignObject& model) const;
350 bool operator<(const DesignObject& model) const;
351 bool operator>(const DesignObject& model) const;
352 operator bool() const
353 {
354 return isValid();
355 }
356 [[nodiscard]] DesignObjectBase& base() const { return *m_base; }
357 [[nodiscard]] UUID uuid() const;
358 void updateDesignTransform(const Matrix<fltp08>& transform, const void* lock = nullptr);
359 void setDesignVisible(bool is_visible);
360 void updateDesignVisible(bool is_visible, const void* lock = nullptr);
361 [[nodiscard]] Matrix<fltp08> getTransform() const;
362 [[nodiscard]] bool isValid() const { return !isNaN(m_index); }
363 [[nodiscard]] Scene getScene() const;
364 [[nodiscard]] static constexpr const char* FilePathDesignNameVariable() { return "[DESIGN_NAME]"; }
365
366 protected:
367 void onNameChange(const String& new_name);
368 protected:
369 mutable UUID m_uuid = Constant<UUID>::NaN;
372 DesignObjectBase* m_base = nullptr;
373#ifdef _DEBUG
374 String debug_name;
375#endif
376 };
378 //static_assert(!std::is_polymorphic<DesignObject>(), "Model should not be polymorphic");
379 template<>
381 {
382 static const uint01 Dimensions = 0;
383 static const bool Vector = false;
384 static const bool Buffer = false;
385 static const bool Primitive = DESIGN_PRIM;
386 static const bool Pointer = false;
387 static const bool Unsigned = false;
388 static const bool Float = false;
389 static const bool Integer = false;
390 static const bool Number = false;
391 static const bool Enum = false;
392 static const bool String = false;
393 static const bool Color = false;
394 static const bool Boolean = false;
396 };
397}
398
399namespace std//Define things to allow use within std libs
400{
401 template <>
402 struct hash<NDEVR::DesignObject>
403 {
404 std::size_t operator()(const NDEVR::DesignObject& d) const noexcept
405 {
406 NDEVR::UUID s = d.uuid();
407 std::size_t value = 0;
408 for (NDEVR::uint01 i = 0; i < 8; i++)
409 {
410 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
411 }
412 return value;
413 }
414 };
415};
416
417
418
419
#define NDEVR_DESIGN_API
Definition DLLInfo.h:77
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
bool operator!=(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
Definition VulkanRenderObject.cpp:10
bool operator==(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
Definition VulkanRenderObject.cpp:18
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Color.h:36
Definition DesignObjectBase.h:140
Definition DesignObject.h:66
bool doesPropertyContain(DesignProperty property, const String &value, bool ignore_case) const
Definition DesignObject.h:289
bool isProperty(DesignProperty property, const char *value) const
Definition DesignObject.h:277
static constexpr const char * FilePathDesignNameVariable()
Definition DesignObject.h:364
DesignObject()=default
bool doesPropertyBeginWith(DesignProperty property, const String &value, bool ignore_case) const
Definition DesignObject.h:281
bool isValid() const
Definition DesignObject.h:362
uint04 designIndex() const
Definition DesignObject.h:345
t_type getInheritedProperty(DesignProperty property) const
Definition DesignObject.h:298
uint04 index() const
Definition DesignObject.h:344
void updateProperty(DesignProperty property, const t_type &value, const void *lock=nullptr)
Definition DesignObject.h:251
void setProperty(DesignProperty property, const UUID &value)
Definition DesignObject.h:211
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:263
bool doesPropertyContain(DesignProperty property, const char *value, bool ignore_case) const
Definition DesignObject.h:293
bool hasProperty(DesignProperty property) const
Definition DesignObject.h:269
DesignObjectType
Definition DesignObject.h:75
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:184
uint04 getDesignParentIndex() const
Definition DesignObject.cpp:220
DesignProperty
Definition DesignObject.h:94
void setProperty(DesignProperty property, const String &value)
Definition DesignObject.h:224
DesignObjectBase & base() const
Definition DesignObject.h:356
bool doesPropertyBeginWith(DesignProperty property, const char *value, bool ignore_case) const
Definition DesignObject.h:285
bool isProperty(DesignProperty property, const String &value) const
Definition DesignObject.h:273
Definition Pointer.hpp:303
Definition File.h:47
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:121
Definition Matrix.hpp:173
Matrix< t_type, t_cols, t_rows > invert() const
Definition Matrix.hpp:649
Definition Pointer.hpp:62
Definition Model.h:491
Definition String.h:40
Definition StringStream.h:62
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
Definition RWLock.h:99
Definition ACIColor.h:37
constexpr bool DESIGN_PRIM
Definition DesignObject.h:47
constexpr bool operator<(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:770
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
@ e_file
Definition ModuleResourceManager.h:36
constexpr bool operator>(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:758
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition File.h:213
Definition BaseValues.hpp:272
static constexpr ObjectInfo< DesignObject, false, false > VectorSub()
Definition DesignObject.h:395
Information about the object.
Definition ObjectInfo.h:56
std::size_t operator()(const NDEVR::DesignObject &d) const noexcept
Definition DesignObject.h:404