API Documentation
Loading...
Searching...
No Matches
LibraryDialog.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: LibraryDialog
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/DesignObjectChooser.h>
34#include <NDEVR/ContainerWidget.h>
35#include <NDEVR/QCustomDockWidget.h>
36#include <NDEVR/PointWidget.h>
37#include <NDEVR/ResizeVisibleAnimation.h>
38#include <NDEVR/ModelEditController.h>
39#include <QWidget>
40#include <QBoxLayout>
41namespace NDEVR
42{
43 class LibraryWidget : public QWidget
44 {
45 public:
46 LibraryWidget(QTModelManager* manager, const DynamicPointer<ModelEditController>& edit_controller, QWidget* parent = nullptr)
47 : QWidget(parent)
48 , m_editor(edit_controller)
49 , m_manager(manager)
50 {
51 QVBoxLayout* layout = new QVBoxLayout();
52 m_container = new ContainerWidget(this);
53 layout->addWidget(m_container);
54
55 setWindowTitle(_tqs("Library"));
56 //QTIconManager::SetWindowIcon("model", this);
57
59 //m_material_chooser = new DockWidget<DesignObjectChooser>(new DesignObjectChooser(manager), RibbonArea::e_bottom, m_container);
60
61 m_model_chooser->setTitle(_t("Models"));
63 //m_material_chooser->setTitle(_t("Materials"));
64 //m_material_chooser->widget().setSelectionMode(DesignObjectGallery::e_single_selection);
65
66 //m_model_chooser->setIcon("Models");
67 //m_model_chooser->setIcon("Materials");
70 m_size_widget->setLabel(X, _t("Length"));
71 m_size_widget->setLabel(Y, _t("Width"));
72 m_size_widget->setLabel(Z, _t("Height"));
73 layout->addWidget(m_size_widget);
74 connect(m_size_widget, &PointWidget::edited2, this, [this]
75 {
77 Model model = m_manager->model(m_editor->activeModel());
78 if (!model.isValid())
79 return;
80
81 Matrix<fltp08> current_transform = m_editor->originalTransform();
82 Vector<3, fltp08> current_size = (current_transform * model.getSelectionBounds()).span();
83 if (isNaN(current_size))
84 return;
85 Vector<3, fltp08> scale(1.0);
86 for (uint04 i = 0; i < 3; i++)
87 {
88 if (current_size[i] != 0.0)
89 scale[i] = n_size[i] / current_size[i];
90 }
91 current_transform = Matrix<fltp08>::ScalerMatrix(scale) * current_transform;
92 m_editor->setOriginalTransform(current_transform);
93
94 model.updateModifiedTime();
95 });
96
97 m_model_chooser->setDockArea(DropArea::e_drop_center, nullptr);
98 //m_material_chooser->setDockArea(DropArea::e_drop_center, m_model_chooser->section());
99
100 m_model_chooser->widget().updateFromArchive(true, false, false);
101 //m_material_chooser->widget().updateFromArchive(false, true);
103 connect(lib.rawptr(), &LibraryManager::modelAdded, this, [this](UUID)
104 {
105 m_model_chooser->widget().updateFromArchive(true, false, false);
106 });
107 connect(lib.rawptr(), &LibraryManager::modelRemoved, this, [this](UUID)
108 {
109 m_model_chooser->widget().updateFromArchive(true, false, false);
110 });
111 m_model_chooser->setVisible(true);
112 m_size_widget->setVisible(false);
113
114 Button* rubber_stamp_button = new Button(_t("Rubber Stamp"), "stamp", [](Button*){});
115 rubber_stamp_button->setCheckable(true);
116 m_model_chooser->widget().addButton(rubber_stamp_button);
117 connect(&m_model_chooser->widget(), &DesignObjectChooser::onSelectedSignal, [this, rubber_stamp_button](Buffer<UUID> id)
118 {
119 if(id.size() > 0)
120 m_selected_id = id.last();
121 else
122 m_selected_id = Constant<UUID>::NaN;
123 m_editor->addNextFinishedCallback(nullptr);
124 m_editor->cancel();
125 m_editor->edit_mode.set(ModelEditController::ModelEditMode::e_no_edit);
126 if (m_manager->libraryManager()->hasID(m_selected_id))
127 {
128 Model lib_object = m_manager->libraryManager()->loadObject(m_selected_id, true);
129 Scene model(_t(""));
130 model.copyFrom(lib_object, true);
131 m_size_widget->setPoint((model.getTransform() * model.getSelectionBounds()).span());
132 ResizeVisibleAnimation::run(m_size_widget, true, true);
133 if(rubber_stamp_button->isChecked())
134 m_editor->edit_mode.set(ModelEditController::e_rubber_stamp);
135 else
136 m_editor->edit_mode.set(ModelEditController::e_place);
137 m_manager->addModel(model);
138 m_editor->setActiveModel(model.uuid());
139 m_editor->addNextFinishedCallback([this](bool, UUID)
140 {
141 QTTools::postToThread([this]
142 {
143 m_model_chooser->widget().setSelected({});
144 ResizeVisibleAnimation::run(m_size_widget, false, true);
145 });
146 });
147 }
148 else
149 {
150 ResizeVisibleAnimation::run(m_size_widget, false, true);
151 }
152 });
153
154 /*connect(&m_material_chooser->widget(), &DesignObjectChooser::onSelectedSignal, [this](Buffer<UUID> id)
155 {
156 if (id.size() > 0)
157 m_editor->setPasteModel(id.last());
158 });*/
159 setLayout(layout);
160 }
161 void setCategory(const String& category)
162 {
163 m_model_chooser->widget().setCategory(category);
164 }
165
166 protected:
174 };
175}
#define _tqs(var)
Definition QTTools.h:193
#define _t(english_string)
Definition Translator.h:87
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Button.h:60
void setCheckable(bool checkable)
Definition Button.cpp:1464
Definition ContainerWidget.h:157
Definition DesignObjectChooser.h:42
void onSelectedSignal(Buffer< UUID > id)
bool isValid() const
Definition DesignObject.h:362
Model model(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1683
Definition QCustomDockWidget.h:117
Definition Pointer.hpp:303
constexpr t_type * rawptr() const
Definition Pointer.hpp:325
void modelAdded(UUID id)
void modelRemoved(UUID id)
Definition LibraryDialog.h:44
ContainerWidget * m_container
Definition LibraryDialog.h:167
LibraryWidget(QTModelManager *manager, const DynamicPointer< ModelEditController > &edit_controller, QWidget *parent=nullptr)
Definition LibraryDialog.h:46
DockWidget< DesignObjectChooser > * m_material_chooser
Definition LibraryDialog.h:170
PointWidget * m_size_widget
Definition LibraryDialog.h:168
void setCategory(const String &category)
Definition LibraryDialog.h:161
UUID m_selected_id
Definition LibraryDialog.h:173
DynamicPointer< ModelEditController > m_editor
Definition LibraryDialog.h:171
QTModelManager * m_manager
Definition LibraryDialog.h:172
DockWidget< DesignObjectChooser > * m_model_chooser
Definition LibraryDialog.h:169
Definition Matrix.hpp:173
static constexpr Matrix< t_type > ScalerMatrix(t_type scale)
Definition Matrix.hpp:304
Definition Model.h:54
void updateModifiedTime(Time time=Time::SystemTime())
Definition Model.cpp:2289
Bounds< 3, fltp08 > getSelectionBounds() const
Definition Model.cpp:172
Definition PointWidget.h:60
Vertex< 3, fltp08 > getPoint() const
Definition PointWidget.cpp:238
void setUnitToApplicationDistanceUnit()
Definition PointWidget.cpp:63
void setLabel(uint01 dimension, const TranslatedString &label)
Definition PointWidget.cpp:186
Definition QTModelManager.h:94
virtual DynamicPointer< LibraryManager > libraryManager()
Definition QTModelManager.cpp:924
Definition String.h:40
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition ACIColor.h:37
@ e_drop_center
Definition RibbonArea.h:50
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
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204