PeriDyno 1.0.0
Loading...
Searching...
No Matches
QVectorTransform3FieldWidget.cpp
Go to the documentation of this file.
2
3#include <QGridLayout>
4
5#include "Field.h"
6#include "QPiecewiseSpinBox.h"
7
8#include <QPushButton.h>
9
10namespace dyno
11{
12
13 IMPL_FIELD_WIDGET(std::vector<Transform3f>, QVectorTransform3FieldWidget)
14
17 {
18 mMainLayout = new QVBoxLayout;
19 mMainLayout->setContentsMargins(0, 0, 0, 0);
20 mMainLayout->setAlignment(Qt::AlignLeft);
21
22 this->setLayout(mMainLayout);
23
24 //Label
25 QHBoxLayout* nameLayout = new QHBoxLayout;
26 QLabel* name = new QLabel();
27 name->setText(FormatFieldWidgetName(field->getObjectName()));
28
29 QPushButton* addItembutton = new QPushButton("add Item",this);
30 addItembutton->setFixedSize(100, 40);
31
32 nameLayout->addWidget(name);
33 nameLayout->addWidget(addItembutton);
34
35 mMainLayout->addLayout(nameLayout);
36
37
38 QObject::connect(addItembutton, SIGNAL(pressed()), this, SLOT(addItemWidget()));
39 QObject::connect(this, SIGNAL(vectorChange()), this, SLOT(updateField()));
40
42 if (f != nullptr)
43 {
44 mVec = f->getValue();
45 }
46
48
49 };
50
52 {
53 for (size_t i = 0; i < mVec.size(); i++)
54 {
56 }
57
58 }
59
68
70 {
71 mVec.clear();
72 for (size_t i = 0; i < mItems.size(); i++)
73 {
74 mVec.push_back(mItems[i]->value());
75 }
76 emit vectorChange();
77 }
78
80 {
82 QObject::connect(itemLayout, SIGNAL(removeById(int)), this, SLOT(removeItemWidgetById(int)));
83 QObject::connect(itemLayout, SIGNAL(valueChange(double)), this, SLOT(updateVector()));
84
85 mMainLayout->addLayout(itemLayout);
86 mItems.push_back(itemLayout);
87
89 }
90
92 {
93 mMainLayout->removeItem(mItems[id]);
94 delete mItems[id];
95 mItems.erase(mItems.begin() + id);
96 for (size_t i = 0; i < mItems.size(); i++)
97 {
98 mItems[i]->setId(i);
99 }
100
101 mMainLayout->update();
102
103 updateVector();
104 }
105
107 {
109 itemLayout->setValue(v);
110
111 QObject::connect(itemLayout, SIGNAL(removeById(int)), this, SLOT(removeItemWidgetById(int)));
112 QObject::connect(itemLayout, SIGNAL(valueChange(double)), this, SLOT(updateVector()));
113
114 mMainLayout->addLayout(itemLayout);
115 mItems.push_back(itemLayout);
116 }
117
118 //************************ mVectorTransformItemLayout ***************************//
120 {
121 mId = id;
122
123 mGroup = new QGroupBox;
124 this->addWidget(mGroup);
125
126 index = new QLabel(std::to_string(id).c_str());
127
131
132 mT0->setValue(0);
133 mT0->setValue(0);
134 mT0->setValue(0);
135
139
140 mR0->setValue(0);
141 mR0->setValue(0);
142 mR0->setValue(0);
143
147
148 mS0->setValue(1);
149 mS1->setValue(1);
150 mS2->setValue(1);
151
152 QHBoxLayout* layout_T = new QHBoxLayout();
153 QHBoxLayout* layout_R = new QHBoxLayout();
154 QHBoxLayout* layout_S = new QHBoxLayout();
155 layout_T->setSpacing(5);
156 layout_R->setSpacing(5);
157 layout_S->setSpacing(5);
158
159 int width = 90;
160 mTLabel = new QLabel("Location");
161 layout_T->addWidget(mTLabel);
162 layout_T->addWidget(mT0);
163 layout_T->addWidget(mT1);
164 layout_T->addWidget(mT2);
165
166 mRLabel = new QLabel("Rotation");
167 layout_R->addWidget(mRLabel);
168 layout_R->addWidget(mR0);
169 layout_R->addWidget(mR1);
170 layout_R->addWidget(mR2);
171
172 mSLabel = new QLabel("Scale");
173 layout_S->addWidget(mSLabel);
174 layout_S->addWidget(mS0);
175 layout_S->addWidget(mS1);
176 layout_S->addWidget(mS2);
177
178 mTLabel->setMinimumWidth(width);
179 mRLabel->setMinimumWidth(width);
180 mSLabel->setMinimumWidth(width);
181 mT0->setMinimumWidth(width);
182 mT1->setMinimumWidth(width);
183 mT2->setMinimumWidth(width);
184 mR0->setMinimumWidth(width);
185 mR1->setMinimumWidth(width);
186 mR2->setMinimumWidth(width);
187 mS0->setMinimumWidth(width);
188 mS1->setMinimumWidth(width);
189 mS2->setMinimumWidth(width);
190
191 QVBoxLayout* list = new QVBoxLayout();
192 list->setSpacing(5);
193
194 list->addItem(layout_T);
195 list->addItem(layout_R);
196 list->addItem(layout_S);
197
198 QHBoxLayout* groupLayout = new QHBoxLayout;
199 mGroup->setLayout(groupLayout);
200
201 groupLayout->addWidget(index);
202 groupLayout->addLayout(list);
203
204 removeButton = new QPushButton("Delete");
205 groupLayout->addWidget(removeButton, 0);
206 removeButton->setFixedSize(100, 40);
207
208 QObject::connect(removeButton, SIGNAL(pressed()), this, SLOT(emitSignal()));
209 QObject::connect(mT0, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
210 QObject::connect(mT1, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
211 QObject::connect(mT2, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
212 QObject::connect(mR0, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
213 QObject::connect(mR1, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
214 QObject::connect(mR2, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
215 QObject::connect(mS0, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
216 QObject::connect(mS1, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
217 QObject::connect(mS2, SIGNAL(valueChanged(double)), this, SLOT(emitChange(double)));
218
219 };
220
222 {
223 delete mT0;
224 delete mT1;
225 delete mT2;
226
227 delete mR0;
228 delete mR1;
229 delete mR2;
230
231 delete mS0;
232 delete mS1;
233 delete mS2;
234
235 delete mTLabel;
236 delete mRLabel;
237 delete mSLabel;
238
239 delete removeButton;
240 delete index;
241 delete mGroup;
242 };
243
245 {
246 auto rot = Vec3f(mR0->getRealValue(), mR1->getRealValue(), mR2->getRealValue());
247
248 Quat<Real> q =
249 Quat<Real>(Real(M_PI) * rot[2] / 180, Vec3f(0, 0, 1))
250 * Quat<Real>(Real(M_PI) * rot[1] / 180, Vec3f(0, 1, 0))
251 * Quat<Real>(Real(M_PI) * rot[0] / 180, Vec3f(1, 0, 0));
252 q.normalize();
253
254 Transform3f transform = Transform3f(
255 Vec3f(mT0->getRealValue(), mT1->getRealValue(), mT2->getRealValue()),
256 q.toMatrix3x3(),
257 Vec3f(mS0->getRealValue(), mS1->getRealValue(), mS2->getRealValue())
258 );
259
260 return transform;
261 }
262
264 {
265 mT0->setValue(v.translation()[0]);
266 mT1->setValue(v.translation()[1]);
267 mT2->setValue(v.translation()[2]);
268
269 Vec3f rot = Vec3f(0);
270
271 Quat<Real>(v.rotation()).toEulerAngle(rot[0], rot[1], rot[2]);
272
273 mR0->setValue(rot[0] * 180 / M_PI);
274 mR1->setValue(rot[1] * 180 / M_PI);
275 mR2->setValue(rot[2] * 180 / M_PI);
276
277 mS0->setValue(v.scale()[0]);
278 mS1->setValue(v.scale()[1]);
279 mS2->setValue(v.scale()[2]);
280
281 }
282
283
284
285
286
287}
288
#define IMPL_FIELD_WIDGET(_data_type_, _type_)
double Real
Definition Typedef.inl:23
#define M_PI
Definition Typedef.inl:36
T getValue()
Definition Field.h:130
void setValue(T val)
Definition Field.h:111
QFieldWidget(FBase *field)
void createItemWidget(Transform3f v)
Creating Vector Elements(std::vector<mVectorTransformItemLayout*>) from fields.
void updateWidget()
Called when the field is updated.
void updateField()
Called when the widget is updated.
DECLARE_FIELD_WIDGET QVectorTransform3FieldWidget(FBase *field)
void removeItemWidgetById(int id)
Called when the "mVectorTransformItemLayout::QPushButton* removeButton" is clicked.
void updateVector()
Update "std::vector<Transform3f> mVec".
void addItemWidget()
Called when the QPushButton* addItembutton is clicked.
std::vector< mVectorTransformItemLayout * > mItems
DYN_FUNC Quat< Real > & normalize()
Definition Quat.inl:183
DYN_FUNC void toEulerAngle(Real &yaw, Real &pitch, Real &roll) const
Definition Quat.inl:207
DYN_FUNC SquareMatrix< Real, 3 > toMatrix3x3() const
Definition Quat.inl:275
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9
Transform< float, 3 > Transform3f
Vector< float, 3 > Vec3f
Definition Vector3D.h:93