NDEVR
API Documentation
QTDesignObject.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: 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/DesignCommandGroup.h>
37#include <NDEVR/UUID.h>
38namespace NDEVR
39{
40 class DesignCommand;
47 template<class t_type>
48 struct ObjectChecker { static bool is(const DynamicPointer<DesignObject>& object); };
50 template<> struct ObjectChecker<DesignObject> {
51 static bool is(const UUID& id, QTModelManager* manager)
52 {
53 return manager->hasObjectID(id);
54 }
55 };
56
57 template<> struct ObjectChecker<Model> {
58 static bool is(const UUID& id, QTModelManager* manager)
59 {
60 return manager->modelOrLayer(id).isValid();
61 }
62 };
63
64 template<> struct ObjectChecker<Geometry> {
65 static bool is(const UUID& id, QTModelManager* manager)
66 {
67 return manager->hasGeometryID(id);
68 }
69 };
70
71 template<> struct ObjectChecker<Material> {
72 static bool is(const UUID& id, QTModelManager* manager)
73 {
74 return manager->hasMaterialID(id);
75 }
76 };
77#if NDEVR_VIEWPORT
79 template<> struct ObjectChecker<Camera> {
80 static bool is(const UUID& id, QTModelManager* manager)
81 {
82 return manager->hasCamera(id);
83 }
84 };
85#endif
87 template<> struct ObjectChecker<DesignSelection> {
88 static bool is(const UUID& id, QTModelManager* manager)
89 {
90 return manager->hasSelectionInfo(id);
91 }
92 };
93
97 class NDEVR_API QTDesignObject : public QObject
98 {
99 Q_OBJECT
100 friend class QTModelManager;
101 protected:
107 QTDesignObject(const UUID& object, QTModelManager* manager)
108 : m_id(object)
110 {
111 lib_assert(m_manager->hasObjectID(m_id), "Tried to access Invalid id in QTModel");
112 }
113
118 : QObject()
119 , m_id(object.m_id)
120 , m_manager(object.m_manager)
121 {}
122 public:
124 {
125 lib_assert(IsValid(m_id), "Tried to access Invalid id in QTModel");
126 }
127
132 template<class t_type>
133 bool is() const
134 {
135 lib_assert(IsValid(m_id), "Tried to access Invalid id in QTModel");
136 return ObjectChecker<t_type>::is(m_id, m_manager);
137 }
138
142 UUID uuid() const
143 {
144 return m_id;
145 }
146
150 template<class t_type>
151 t_type getAs() const
152 {
153 lib_assert(m_manager->hasObjectID(m_id), "Tried to access Invalid id in QTModel");
154 if (DesignObject obj = m_manager->object(m_id))
155 return t_type(obj);
156 return t_type();
157 }
158
163 template<class t_type, class t_property_type>
164 decltype(auto) get(t_property_type property) const
165 {
166 return m_manager->object(m_id).get<t_type>(property);
167 }
168
172 template<auto t_property>
173 decltype(auto) get() const
174 {
175 return m_manager->object(m_id).get<t_property>();
176 }
177
182 {
183 if (is<Model>())
184 return getAs<Model>().displayName();
185 if (is<Material>())
186 return getAs<Material>().displayName();
187 return get<NDPOC::name>();
188 }
189
198 template<class t_design_command_type>
200 {
201 postCommand(command.template as<DesignCommand>());
202 }
203
207 template<class t_design_command_type>
209 {
210 runCommand(command.template as<DesignCommand>());
211 }
212
216 void postCommand(std::initializer_list<DynamicPointer<DesignCommand>> l)
217 {
219 }
220
224 void runCommand(std::initializer_list<DynamicPointer<DesignCommand>> l)
225 {
227 }
228
242 UUID id() const { return m_id; }
247 QTModelManager* manager() const { return m_manager; }
252 void showProperties(const PopupInfo& location = PopupInfo());
255 QTDesignObject& operator=(const QTDesignObject& other)
256 {
257 lib_assert(m_manager == other.m_manager, "Cannot set equal to Design Object from another Manager");
258 m_id = other.m_id;
259 return *this;
260 }
266 void updateSelected(UUID id, bool is_selected)
267 {
268 if (uuid() == id)
269 {
270 if(is_selected)
271 emit selectedSignal(id);
272 }
273 }
274
279 {
280 if (uuid() == id)
281 emit deletedSignal(id);
282 }
283
285 {
286 emit updatedSignal(uuid());
287 }
288
290 {
292 }
293 public slots:
296 {
297 m_manager->deleteObject(uuid());
298 }
299
300 void update()
301 {
302 m_manager->object(uuid()).updateDesignModifiedTime();
303 }
304
308 void setFocus(bool focus)
309 {
310 if(focus)
311 m_manager->setFocus(uuid());
312 }
313
317 void setSelected(bool is_selected)
318 {
319 if(is_selected)
320 m_manager->setSelected({ m_id });
321 }
322#if NDEVR_VIEWPORT
324 void zoomToModel() const
325 {
326 m_manager->setViewportFocus(uuid());
327 }
328#endif
329 protected slots:
330
331 signals:
336 protected:
338 QTModelManager* m_manager;
339 };
340}
A core object representing a user view as well as convenience functions for moving this view through ...
Definition Camera.h:95
Allows for convenient groupings of commands that can be redo-undo all at once.
Forward declaration of the central design object registry.
bool hasMaterialID(const UUID &id, bool allow_deleted=false) const
Checks whether a material with the given UUID exists.
bool hasCamera(const UUID &id) const
Checks whether a camera with the given UUID exists.
bool hasGeometryID(const UUID &id, bool allow_deleted=false) const
Checks whether a geometry with the given UUID exists.
Model modelOrLayer(const UUID &id, bool allow_deleted=false) const
Retrieves a model or layer by its UUID, checking both stores.
bool hasSelectionInfo(const UUID &id) const
Checks whether selection info with the given UUID exists.
bool hasObjectID(const UUID &id, bool allow_deleted=false) const
Checks whether any design object with the given UUID exists.
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
bool isValid() const
Checks whether this design object has a valid index into the database.
A simple structure for storing a collection of data.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
A core class that represents a node on model hierarchy.
Definition Model.h:292
A pointer to a DesignObject within a QTModelManager that receives and emits update signals based on t...
void postCommand(const DynamicPointer< t_design_command_type > &command)
Posts a typed design command to the command queue for deferred execution.
void showProperties(const PopupInfo &location=PopupInfo())
Opens the properties dialog for this object.
bool is() const
Checks whether this object is of the specified design object type.
void selectedSignal(UUID id)
Emitted when this object is selected.
QTDesignObject(const UUID &object, QTModelManager *manager)
Constructs a QTDesignObject wrapping the given UUID and manager.
QTModelManager * m_manager
The model manager owning this object.
void postCommand(const DynamicPointer< DesignCommand > &command)
Posts a design command to the command queue for deferred execution.
decltype(auto) get(t_property_type property) const
Gets a typed property value from the underlying design object.
void postCommand(std::initializer_list< DynamicPointer< DesignCommand > > l)
Posts a group of design commands to the command queue for deferred execution.
void updateSelected(UUID id, bool is_selected)
Emits the selected signal if this object matches the given UUID and is selected.
decltype(auto) get() const
Gets a compile-time property value from the underlying design object.
void runCommand(std::initializer_list< DynamicPointer< DesignCommand > > l)
Runs a group of design commands immediately.
UUID m_id
The UUID of the wrapped design object.
UUID uuid() const
Gets the UUID of this design object.
TranslatedString displayName() const
Gets the user-facing display name of this object.
void runCommand(const DynamicPointer< DesignCommand > &command)
Runs a design command immediately.
void updatedSignal(UUID id)
Emitted when this object is updated.
QTDesignObject(const QTDesignObject &object)
Copy constructs a QTDesignObject from another.
void deleteModel(UUID id)
Emits the deleted signal if this object matches the given UUID.
void setSelected(bool is_selected)
Sets this object as selected in the model manager.
void zoomToModel() const
Zooms the viewport camera to focus on this model.
void update()
Updates the design modified timestamp for this object.
void updateDescendent()
Emits the descendent updated signal for this object.
void deleteObject()
Deletes this object from the model manager.
void descendentUpdatedSignal(UUID id)
Emitted when a descendent of this object is updated.
UUID id() const
Gets the UUID of this design object.
void deletedSignal(UUID id)
Emitted when this object is deleted.
void runCommand(const DynamicPointer< t_design_command_type > &command)
Runs a typed design command immediately.
void updateObject()
Emits the updated signal for this object.
QTModelManager * manager() const
Gets the model manager that owns this object.
void exportToFile()
Exports this object to an external file format.
void setFocus(bool focus)
Sets the UI focus to this object.
t_type getAs() const
Converts this design object to the specified type.
DesignSelection getAsSelection() const
Gets this object as a DesignSelection.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
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
@ is_selected
Whether the object is currently selected.
Used with QTDesignObject to check the type of an object.
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16