API Documentation
Loading...
Searching...
No Matches
QTDesignObject.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: NDEVR
28File: QTDesignObject
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/QTModelManager.h>
35#include <NDEVR/Model.h>
36#include <NDEVR/UUID.h>
37namespace NDEVR
38{
39 class DesignCommand;
40 /**--------------------------------------------------------------------------------------------------
41 \brief Used with QTDesignObject to check the type of an object.
42 **/
43 template<class t_type>
44 struct ObjectChecker { static bool is(const DynamicPointer<DesignObject>& object); };
45 template<> struct ObjectChecker<DesignObject> {
46 static bool is(const UUID& id, QTModelManager* manager)
47 {
48 return manager->hasObjectID(id);
49 }
50 };
51 template<> struct ObjectChecker<Model> {
52 static bool is(const UUID& id, QTModelManager* manager)
53 {
54 return manager->modelOrLayer(id).isValid();
55 }
56 };
57 template<> struct ObjectChecker<Geometry> {
58 static bool is(const UUID& id, QTModelManager* manager)
59 {
60 return manager->hasGeometryID(id);
61 }
62 };
63 template<> struct ObjectChecker<Material> {
64 static bool is(const UUID& id, QTModelManager* manager)
65 {
66 return manager->hasMaterialID(id);
67 }
68 };
69#if NDEVR_VIEWPORT
70 template<> struct ObjectChecker<Camera> {
71 static bool is(const UUID& id, QTModelManager* manager)
72 {
73 return manager->hasCamera(id);
74 }
75 };
76#endif
77 template<> struct ObjectChecker<DesignSelection> {
78 static bool is(const UUID& id, QTModelManager* manager)
79 {
80 return manager->hasSelectionInfo(id);
81 }
82 };
83 /**--------------------------------------------------------------------------------------------------
84 \brief A pointer to a DesignObject within a QTModelManager that recieves and emits update signals
85 based on the state of the object.
86 **/
87 class NDEVR_API QTDesignObject : public QObject
88 {
89 Q_OBJECT
90 friend class QTModelManager;
91 protected:
92 QTDesignObject(const UUID& object, QTModelManager* manager)
93 : m_id(object)
94 , m_manager(manager)
95 {}
97 : QObject()
98 , m_id(object.m_id)
99 , m_manager(object.m_manager)
100 {}
101 public:
103 {
104 lib_assert(!IsInvalid(m_id), "Tried to access Invalid id in QTModel");
105 }
106
107 template<class t_type>
108 bool is() const
109 {
110 lib_assert(!IsInvalid(m_id), "Tried to access Invalid id in QTModel");
111 return ObjectChecker<t_type>::is(m_id, m_manager);
112 }
113 UUID uuid() const
114 {
115 return m_id;
116 }
117 template<class t_type>
118 t_type getAs() const
119 {
120 lib_assert(m_manager->hasObjectID(m_id), "Tried to access Invalid id in QTModel");
121 if(DesignObject obj = m_manager->object(m_id))
122 return t_type(obj);
123 return t_type();
124 }
125 template<class t_type>
127 {
128 return m_manager->object(m_id).getProperty<t_type>(property);
129 }
130 template<class t_type>
132 {
133 return getAs<Model>().getModelProperty<t_type>(property);
134 }
135 template<class t_type>
137 {
138 return getAs<Material>().getMaterialProperty<t_type>(property);
139 }
140 template<class t_type>
142 {
143 return getAs<Geometry>().getGeometryProperty<t_type>(property);
144 }
145
147 {
148 if (is<Model>())
149 return getAs<Model>().displayName();
150 if (is<Material>())
151 return getAs<Material>().displayName();
152 return getProperty<TranslatedString>(DesignObject::e_name);
153 }
157 UUID id() const
158 {
159 return m_id;
160 }
162 {
163 return m_manager;
164 }
165 void showProperties(const PopupInfo& location = PopupInfo());
168 {
169 lib_assert(m_manager == other.m_manager, "Cannot set equal to Design Object from another Manager");
170 m_id = other.m_id;
171 return *this;
172 }
174 {
175 return getAs<DesignObject>();
176 }
177
178 void updateSelected(UUID id, bool is_selected)
179 {
180 if (uuid() == id)
181 {
182 if(is_selected)
183 emit selectedSignal(id);
184 }
185 }
187 {
188 if (uuid() == id)
189 emit deletedSignal(id);
190 }
192 {
193 emit updatedSignal(uuid());
194 }
196 {
197 emit descendentUpdatedSignal(uuid());
198 }
199 public slots:
201 {
202 m_manager->deleteObject(uuid());
203 }
204 void update()
205 {
206 m_manager->object(uuid()).updateDesignModifiedTime();
207 }
208 void setFocus(bool focus)
209 {
210 if(focus)
211 m_manager->setFocus(uuid());
212 }
213 void setSelected(bool is_selected)
214 {
215 if(is_selected)
216 m_manager->setSelected({ m_id });
217 }
218#if NDEVR_VIEWPORT
219 void zoomToModel() const
220 {
221 m_manager->setViewportFocus(uuid());
222 }
223#endif
224 protected slots:
225
226 signals:
231 protected:
234 };
235}
#define lib_assert(expression, message)
Definition LibAssert.h:61
#define NDEVR_API
Definition DLLInfo.h:50
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
bool isValid() const
Definition DesignObject.h:355
DesignProperty
Values stored in the property database.
Definition DesignObject.h:93
bool hasObjectID(const UUID &id, bool allow_deleted=false) const
bool hasGeometryID(const UUID &id) const
Model modelOrLayer(const UUID &id, bool allow_deleted=false) const
bool hasMaterialID(const UUID &id) const
bool hasSelectionInfo(const UUID &id) const
A simple structure for storing a collection of data.
Definition DesignSelection.h:26
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A core class within the model heirarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:64
GeometryProperty
Definition Geometry.h:99
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:51
MaterialProperties
Definition Material.h:114
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
ModelProperty
Definition Model.h:103
A pointer to a DesignObject within a QTModelManager that recieves and emits update signals based on t...
Definition QTDesignObject.h:88
void deleteObject()
Definition QTDesignObject.h:200
t_type getModelProperty(Model::ModelProperty property) const
Definition QTDesignObject.h:131
void setSelected(bool is_selected)
Definition QTDesignObject.h:213
void runCommand(const DynamicPointer< DesignCommand > &command)
QTDesignObject(const UUID &object, QTModelManager *manager)
Definition QTDesignObject.h:92
void showProperties(const PopupInfo &location=PopupInfo())
void updateDescendent()
Definition QTDesignObject.h:195
UUID id() const
Definition QTDesignObject.h:157
void postCommand(const DynamicPointer< DesignCommand > &command)
t_type getGeometryProperty(Geometry::GeometryProperty property) const
Definition QTDesignObject.h:141
void updateObject()
Definition QTDesignObject.h:191
UUID m_id
Definition QTDesignObject.h:232
UUID uuid() const
Definition QTDesignObject.h:113
void updatedSignal(UUID id)
QTModelManager * manager() const
Definition QTDesignObject.h:161
DesignObject get() const
Definition QTDesignObject.h:173
void deleteModel(UUID id)
Definition QTDesignObject.h:186
void descendentUpdatedSignal(UUID id)
QTDesignObject(const QTDesignObject &object)
Definition QTDesignObject.h:96
QTDesignObject & operator=(const QTDesignObject &other)
Definition QTDesignObject.h:167
DesignSelection getAsSelection() const
t_type getAs() const
Definition QTDesignObject.h:118
~QTDesignObject()
Definition QTDesignObject.h:102
t_type getMaterialProperty(Material::MaterialProperties property) const
Definition QTDesignObject.h:136
void update()
Definition QTDesignObject.h:204
QTModelManager * m_manager
Definition QTDesignObject.h:233
t_type getProperty(DesignObject::DesignProperty property) const
Definition QTDesignObject.h:126
bool is() const
Definition QTDesignObject.h:108
void deletedSignal(UUID id)
void selectedSignal(UUID id)
void setFocus(bool focus)
Definition QTDesignObject.h:208
void updateSelected(UUID id, bool is_selected)
Definition QTDesignObject.h:178
TranslatedString displayName() const
Definition QTDesignObject.h:146
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
Definition QTModelManager.h:105
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
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
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:46
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:78
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:58
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:64
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:52
Used with QTDesignObject to check the type of an object.
Definition QTDesignObject.h:44
static bool is(const DynamicPointer< DesignObject > &object)
Class which is used to pass arguments and requests for creating a popup dialog or widget....
Definition PopupInfo.h:15