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 template<class t_type>
41 struct ObjectChecker { static bool is(const DynamicPointer<DesignObject>& object); };
42 template<> struct ObjectChecker<DesignObject> {
43 static bool is(const UUID& id, QTModelManager* manager)
44 {
45 return manager->hasObjectID(id);
46 }
47 };
48 template<> struct ObjectChecker<Model> {
49 static bool is(const UUID& id, QTModelManager* manager)
50 {
51 return manager->modelOrLayer(id).isValid();
52 }
53 };
54 template<> struct ObjectChecker<Geometry> {
55 static bool is(const UUID& id, QTModelManager* manager)
56 {
57 return manager->hasGeometryID(id);
58 }
59 };
60 template<> struct ObjectChecker<Material> {
61 static bool is(const UUID& id, QTModelManager* manager)
62 {
63 return manager->hasMaterialID(id);
64 }
65 };
66#if NDEVR_VIEWPORT
67 template<> struct ObjectChecker<Camera> {
68 static bool is(const UUID& id, QTModelManager* manager)
69 {
70 return manager->hasCamera(id);
71 }
72 };
73#endif
74 template<> struct ObjectChecker<DesignSelection> {
75 static bool is(const UUID& id, QTModelManager* manager)
76 {
77 return manager->hasSelectionInfo(id);
78 }
79 };
80 class NDEVR_API QTDesignObject : public QObject
81 {
82 Q_OBJECT
83 friend class QTModelManager;
84 protected:
85 QTDesignObject(const UUID& object, QTModelManager* manager)
86 : m_id(object)
87 , m_manager(manager)
88 {}
90 : QObject()
91 , m_id(object.m_id)
92 , m_manager(object.m_manager)
93 {}
94 public:
96 {
97 lib_assert(!isNaN(m_id), "Tried to access NaN id in QTModel");
98 }
99
100 template<class t_type>
101 bool is() const
102 {
103 lib_assert(!isNaN(m_id), "Tried to access NaN id in QTModel");
104 return ObjectChecker<t_type>::is(m_id, m_manager);
105 }
106 UUID uuid() const
107 {
108 return m_id;
109 }
110 template<class t_type>
111 t_type getAs() const
112 {
113 lib_assert(m_manager->hasObjectID(m_id), "Tried to access NaN id in QTModel");
114 if(DesignObject obj = m_manager->object(m_id))
115 return t_type(obj);
116 return t_type();
117 }
118 template<class t_type>
120 {
121 return m_manager->object(m_id).getProperty<t_type>(property);
122 }
123 template<class t_type>
125 {
126 return getAs<Model>().getModelProperty<t_type>(property);
127 }
128 template<class t_type>
130 {
131 return getAs<Material>().getMaterialProperty<t_type>(property);
132 }
133 template<class t_type>
135 {
136 return getAs<Geometry>().getGeometryProperty<t_type>(property);
137 }
138
140 {
141 if (is<Model>())
142 return getAs<Model>().displayName();
143 if (is<Material>())
144 return getAs<Material>().displayName();
145 return getProperty<TranslatedString>(DesignObject::e_name);
146 }
147 DesignSelection getAsSelection() const;
148 void postCommand(const DynamicPointer<DesignCommand>& command);
149 void runCommand(const DynamicPointer<DesignCommand>& command);
150 UUID id() const
151 {
152 return m_id;
153 }
155 {
156 return m_manager;
157 }
158 void showProperties(const PopupInfo& location = PopupInfo());
159 void exportToFile();
161 {
162 lib_assert(m_manager == other.m_manager, "Cannot set equal to Design Object from another Manager");
163 m_id = other.m_id;
164 return *this;
165 }
167 {
168 return getAs<DesignObject>();
169 }
170
171 void updateSelected(UUID id, bool is_selected)
172 {
173 if (uuid() == id)
174 {
175 if(is_selected)
176 emit selectedSignal(id);
177 }
178 }
180 {
181 if (uuid() == id)
182 emit deletedSignal(id);
183 }
185 {
186 emit updatedSignal(uuid());
187 }
189 {
190 emit descendentUpdatedSignal(uuid());
191 }
192 public slots:
194 {
195 m_manager->deleteObject(uuid());
196 }
197 void update()
198 {
199 m_manager->object(uuid()).updateDesignModifiedTime();
200 }
201 void setFocus(bool focus)
202 {
203 if(focus)
204 m_manager->setFocus(uuid());
205 }
206 void setSelected(bool is_selected)
207 {
208 if(is_selected)
209 m_manager->setSelected({ m_id });
210 }
211#if NDEVR_VIEWPORT
212 void zoomToModel() const
213 {
214 m_manager->setViewportFocus(uuid());
215 }
216#endif
217 protected slots:
218
219 signals:
224 protected:
227 };
228}
#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
#define NDEVR_API
Definition DLLInfo.h:67
Definition DesignObject.h:66
bool isValid() const
Definition DesignObject.h:362
DesignProperty
Definition DesignObject.h:94
bool hasObjectID(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1792
bool hasGeometryID(const UUID &id) const
Definition DesignObjectLookup.cpp:1808
Model modelOrLayer(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1674
bool hasMaterialID(const UUID &id) const
Definition DesignObjectLookup.cpp:1801
bool hasSelectionInfo(const UUID &id) const
Definition DesignObjectLookup.cpp:1847
Definition DesignSelection.h:19
Definition Pointer.hpp:303
Definition Geometry.h:64
GeometryProperty
Definition Geometry.h:99
Definition Material.h:45
MaterialProperties
Definition Material.h:108
Definition Model.h:54
ModelProperty
Definition Model.h:99
Definition QTDesignObject.h:81
void deleteObject()
Definition QTDesignObject.h:193
t_type getModelProperty(Model::ModelProperty property) const
Definition QTDesignObject.h:124
void setSelected(bool is_selected)
Definition QTDesignObject.h:206
QTDesignObject(const UUID &object, QTModelManager *manager)
Definition QTDesignObject.h:85
void updateDescendent()
Definition QTDesignObject.h:188
UUID id() const
Definition QTDesignObject.h:150
t_type getGeometryProperty(Geometry::GeometryProperty property) const
Definition QTDesignObject.h:134
void updateObject()
Definition QTDesignObject.h:184
UUID m_id
Definition QTDesignObject.h:225
UUID uuid() const
Definition QTDesignObject.h:106
void updatedSignal(UUID id)
QTModelManager * manager() const
Definition QTDesignObject.h:154
DesignObject get() const
Definition QTDesignObject.h:166
void deleteModel(UUID id)
Definition QTDesignObject.h:179
void descendentUpdatedSignal(UUID id)
QTDesignObject(const QTDesignObject &object)
Definition QTDesignObject.h:89
QTDesignObject & operator=(const QTDesignObject &other)
Definition QTDesignObject.h:160
t_type getAs() const
Definition QTDesignObject.h:111
~QTDesignObject()
Definition QTDesignObject.h:95
t_type getMaterialProperty(Material::MaterialProperties property) const
Definition QTDesignObject.h:129
void update()
Definition QTDesignObject.h:197
QTModelManager * m_manager
Definition QTDesignObject.h:226
t_type getProperty(DesignObject::DesignProperty property) const
Definition QTDesignObject.h:119
bool is() const
Definition QTDesignObject.h:101
void deletedSignal(UUID id)
void selectedSignal(UUID id)
void setFocus(bool focus)
Definition QTDesignObject.h:201
void updateSelected(UUID id, bool is_selected)
Definition QTDesignObject.h:171
TranslatedString displayName() const
Definition QTDesignObject.h:139
Definition QTModelManager.h:94
Definition TranslatedString.h:9
Definition UUID.h:66
Definition ACIColor.h:37
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:43
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:75
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:55
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:61
static bool is(const UUID &id, QTModelManager *manager)
Definition QTDesignObject.h:49
Definition QTDesignObject.h:41
static bool is(const DynamicPointer< DesignObject > &object)
Definition PopupInfo.h:10