PeriDyno 1.0.0
Loading...
Searching...
No Matches
QVehicleInfoWidget.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#include <QWheelEvent>
10
11void QComboBox::wheelEvent(QWheelEvent* e){}
12
13void QAbstractSpinBox::wheelEvent(QWheelEvent* e){}
14
15namespace dyno
16{
17 //RigidBody Detail
18
20 {
21 mRigidBodyData = &rigidInfo;
22 this->setWindowFlags(Qt::WindowStaysOnTopHint);
23
24 this->setContentsMargins(0, 0, 0, 0);
25
26 mCurrentType = rigidInfo.shapeType;
27
28 auto mainLayout = new QVBoxLayout;
29 mainLayout->setContentsMargins(0, 0, 0, 0);
30 mainLayout->setAlignment(Qt::AlignLeft);
31 mainLayout->setSpacing(0);
32
33 this->setLayout(mainLayout);
34
35 auto title = new QLabel(QString((std::string("<b>") + std::string("Rigid Body Name: ") + rigidInfo.shapeName.name + std::string("</b>")).c_str()), this);
36
37 title->setAlignment(Qt::AlignCenter);
38 auto titleLayout = new QHBoxLayout;
39 titleLayout->addWidget(title);
40 titleLayout->setAlignment(Qt::AlignHCenter);
41 titleLayout->setContentsMargins(0, 10, 0, 15);
42 mainLayout->addItem(titleLayout);
43 //Offset
44 mOffsetWidget = new mVec3fWidget(rigidInfo.Offset, std::string("Offset"), this);
45 mainLayout->addWidget(mOffsetWidget);
46
47 QObject::connect(mOffsetWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
48
49 //Transform
50 Vec3f R;
51 Quat<Real>(rigidInfo.transform.rotation()).toEulerAngle(R[2], R[1], R[0]);
52
53 mTranslationWidget = new mVec3fWidget(rigidInfo.transform.translation(), std::string("Translation"), this);
54 mRotationWidget = new mVec3fWidget(R * 180 / M_PI, std::string("Rotation"), this);
55 mScaleWidget = new mVec3fWidget(rigidInfo.transform.scale(), std::string("Scale"), this);
56
57 mainLayout->addWidget(mTranslationWidget);
58 mainLayout->addWidget(mRotationWidget);
59 mainLayout->addWidget(mScaleWidget);
60
61 mMotionWidget = new QComboBox(this);
62 for (auto it : mAllConfigMotionTypes)
63 {
64 switch (it)
65 {
67 mMotionWidget->addItem("Static");
68 break;
70 mMotionWidget->addItem("Kinematic");
71 break;
73 mMotionWidget->addItem("Dynamic");
74 break;
75 default:
76 break;
77 }
78 }
79
80
81
82 QHBoxLayout* motionLayout = new QHBoxLayout;
83 motionLayout->addWidget(new QLabel("Motion Type", this));
84 motionLayout->addWidget(mMotionWidget);
85 motionLayout->setContentsMargins(9, 0, 8, 0);
86 mainLayout->addItem(motionLayout);
87
88
89 QObject::connect(mTranslationWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
90 QObject::connect(mRotationWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
91 QObject::connect(mScaleWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
92 QObject::connect(mMotionWidget, QOverload<int>::of(&QComboBox::currentIndexChanged), [=]() {updateData(); });
93
94
95 if (true)
96 {
97 switch (mCurrentType)
98 {
99 case dyno::Box:
100 mHalfLengthWidget = new mVec3fWidget(rigidInfo.mHalfLength, std::string("Half Length"));
101 mainLayout->addWidget(mHalfLengthWidget);
102 QObject::connect(mHalfLengthWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
103
104 break;
105
106 case dyno::Tet:
107 mTetWidget_0 = new mVec3fWidget(rigidInfo.tet[0], std::string("Tet[0]"), this);
108 mTetWidget_1 = new mVec3fWidget(rigidInfo.tet[1], std::string("Tet[1]"), this);
109 mTetWidget_2 = new mVec3fWidget(rigidInfo.tet[2], std::string("Tet[2]"), this);
110 mTetWidget_3 = new mVec3fWidget(rigidInfo.tet[3], std::string("Tet[3]"), this);
111 mainLayout->addWidget(mTetWidget_0);
112 mainLayout->addWidget(mTetWidget_1);
113 mainLayout->addWidget(mTetWidget_2);
114 mainLayout->addWidget(mTetWidget_3);
115 QObject::connect(mTetWidget_0, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
116 QObject::connect(mTetWidget_1, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
117 QObject::connect(mTetWidget_2, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
118 QObject::connect(mTetWidget_3, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
119
120
121 break;
122 case dyno::Capsule:
123 mRadiusWidget = new mPiecewiseDoubleSpinBox(rigidInfo.radius, "Capsule Radius", this);
124 mCapsuleLengthWidget = new mPiecewiseDoubleSpinBox(rigidInfo.capsuleLength, "Capsule Length", this);
125 mainLayout->addWidget(mRadiusWidget);
126 mainLayout->addWidget(mCapsuleLengthWidget);
127 QObject::connect(mRadiusWidget, QOverload<>::of(&mPiecewiseDoubleSpinBox::valueChange), [=]() {updateData(); });
128 QObject::connect(mCapsuleLengthWidget, QOverload<>::of(&mPiecewiseDoubleSpinBox::valueChange), [=]() {updateData(); });
129
130 break;
131 case dyno::Sphere:
132 mRadiusWidget = new mPiecewiseDoubleSpinBox(rigidInfo.radius, "Radius", this);
133 mainLayout->addWidget(mRadiusWidget);
134 QObject::connect(mRadiusWidget, QOverload<>::of(&mPiecewiseDoubleSpinBox::valueChange), [=]() {updateData(); });
135
136 break;
137 case dyno::Tri:
138 //;
139 break;
140 case dyno::OtherShape:
141 //;
142 break;
143
144 default:
145 break;
146 }
147 }
148
149 mRigidGroup = new QSpinBox(this);
150 QHBoxLayout* rigidGroupLayout = new QHBoxLayout;
151 rigidGroupLayout->addWidget(new QLabel("Rigidbody Group", this));
152 rigidGroupLayout->addWidget(mRigidGroup);
153 rigidGroupLayout->setContentsMargins(9, 0, 8, 0);
154 mRigidGroup->setValue(mRigidBodyData->rigidGroup);
155 mRigidGroup->setRange(0, 100);
156 mainLayout->addItem(rigidGroupLayout);
157
158 QObject::connect(mRigidGroup, QOverload<int>::of(&QSpinBox::valueChanged), [=]() {updateData(); });
159
160 mainLayout->addStretch();
161
162 }
163
164
166 {
167
168 mRigidBodyData->mHalfLength = mOffsetWidget->getValue();
169
170 Quat<Real> q = Quat<Real>(mRotationWidget->getValue()[2] * M_PI / 180, mRotationWidget->getValue()[1] * M_PI / 180, mRotationWidget->getValue()[0] * M_PI / 180);
171
172 mRigidBodyData->transform = Transform3f(mTranslationWidget->getValue(), q.toMatrix3x3(), mScaleWidget->getValue());
173 mRigidBodyData->rigidGroup = mRigidGroup->value();
174
175 switch (mCurrentType)
176 {
177 case dyno::Box:
178 mRigidBodyData->mHalfLength = mHalfLengthWidget->getValue();
179 break;
180
181 case dyno::Tet:
182 mRigidBodyData->tet[0] = mTetWidget_0->getValue();
183 mRigidBodyData->tet[1] = mTetWidget_1->getValue();
184 mRigidBodyData->tet[2] = mTetWidget_2->getValue();
185 mRigidBodyData->tet[3] = mTetWidget_3->getValue();
186
187 break;
188 case dyno::Capsule:
189 mRigidBodyData->radius = mRadiusWidget->getValue();
190 mRigidBodyData->capsuleLength = mCapsuleLengthWidget->getValue();
191
192 break;
193 case dyno::Sphere:
194 mRigidBodyData->radius = mRadiusWidget->getValue();
195
196 break;
197 case dyno::Tri:
198 //;
199 break;
200 case dyno::OtherShape:
201 //;
202 break;
203
204 default:
205 break;
206 }
207 emit rigidChange();
208 }
209
210
211 //Joint Detail
213 {
214 mJointData = &jointInfo;
215
216 this->setFixedWidth(400);
217
218 this->setWindowFlags(Qt::WindowStaysOnTopHint);
219
220 this->setContentsMargins(0, 0, 0, 0);
221
222 mCurrentType = jointInfo.mJointType;
223
224 auto mainLayout = new QVBoxLayout;
225 mainLayout->setContentsMargins(0, 0, 0, 0);
226 mainLayout->setAlignment(Qt::AlignLeft);
227 mainLayout->setSpacing(0);
228 this->setLayout(mainLayout);
229
230
231
232 auto title = new QLabel(QString((std::string("<b>") +std::string("Joint: ")
233 + jointInfo.mRigidBodyName_1.name + std::string(" - ")
234 + jointInfo.mRigidBodyName_2.name + std::string("</b>")).c_str()), this);
235 title->setAlignment(Qt::AlignCenter);
236 auto titleLayout = new QHBoxLayout;
237 titleLayout->addWidget(title);
238 titleLayout->setAlignment(Qt::AlignHCenter);
239 titleLayout->setContentsMargins(0, 10, 0, 15);
240 mainLayout->addItem(titleLayout);
241
242 mAnchorPointWidget = new mVec3fWidget(jointInfo.mAnchorPoint, std::string("AnchorPoint"), this);
243 mAxisWidget = new mVec3fWidget(jointInfo.mAxis, std::string("Axis"), this);
244
245
246 mNameLabel = new QToggleLabel("Range", this);
247 mNameLabel->setMinimumWidth(90);
248 mUseRangeWidget = new QCheckBox(this);
249 mUseRangeWidget->setChecked(jointInfo.mUseRange);
250 mMinWidget = new QPiecewiseDoubleSpinBox(jointInfo.mMin, this);
251 mMaxWidget = new QPiecewiseDoubleSpinBox(jointInfo.mMax, this);
252 mMinWidget->setRange(-9999999999,99999999999);
253 mMaxWidget->setRange(-9999999999, 99999999999);
254 mMinWidget->setMinimumWidth(120);
255 mMaxWidget->setMinimumWidth(120);
256
257 QHBoxLayout* rangeLayout = new QHBoxLayout;
258 rangeLayout->setContentsMargins(9, 0, 8, 10);
259 rangeLayout->setAlignment(Qt::AlignLeft);
260 rangeLayout->setSpacing(10);
261
262 rangeLayout->addWidget(mNameLabel);
263 rangeLayout->addStretch();
264 rangeLayout->addWidget(mUseRangeWidget);
265 rangeLayout->addWidget(mMinWidget);
266 rangeLayout->addWidget(mMaxWidget);
267
268
269 QObject::connect(mNameLabel, SIGNAL(toggle(bool)), mMinWidget, SLOT(toggleDecimals(bool)));
270 QObject::connect(mNameLabel, SIGNAL(toggle(bool)), mMaxWidget, SLOT(toggleDecimals(bool)));
271
272 QObject::connect(mAnchorPointWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
273 QObject::connect(mAxisWidget, QOverload<>::of(&mVec3fWidget::vec3fChange), [=]() {updateData(); });
274 QObject::connect(mUseRangeWidget, QOverload<int>::of(&QCheckBox::stateChanged), [=]() {updateData(); });
275 QObject::connect(mMinWidget, QOverload<double>::of(&QPiecewiseDoubleSpinBox::valueChanged), [=]() {updateData(); });
276 QObject::connect(mMaxWidget, QOverload<double>::of(&QPiecewiseDoubleSpinBox::valueChanged), [=]() {updateData(); });
277
278 mainLayout->addWidget(mAnchorPointWidget);
279 mainLayout->addWidget(mAxisWidget);
280 mainLayout->addItem(rangeLayout);
281 mainLayout->addStretch();
282 }
283
284
286 {
287 mJointData->mAnchorPoint = mAnchorPointWidget->getValue();
288 mJointData->mAxis = mAxisWidget->getValue();
289 mJointData->mUseRange = mUseRangeWidget->checkState();
290 mJointData->mMin = mMinWidget->getRealValue();
291 mJointData->mMax = mMaxWidget->getRealValue();
292
293 emit jointChange();
294 }
295
296
297 //mRigidBodyItemLayout //RigidBody Configuration
298
300 {
301 this->setContentsMargins(0, 0, 0, 0);
302
303 mElementIndex = id;
304 mIndexLabel = new QLabel(std::to_string(id).c_str());
305 mNameInput = new QLineEdit;
306 mTypeCombox = new QComboBox;
307
308 mShapeIDSpin = new QSpinBox;
309 mShapeIDSpin->setRange(-1, 2000);
310 mShapeIDSpin->setValue(id);
311 mRemoveButton = new QPushButton("Delete");
312 mOffsetButton = new QPushButton("Edit");
313
315 {
316 switch (it)
317 {
319 mTypeCombox->addItem("Box");
320 break;
322 mTypeCombox->addItem("Tet");
323 break;
325 mTypeCombox->addItem("Capsule");
326 break;
328 mTypeCombox->addItem("Sphere");
329 break;
331 mTypeCombox->addItem("Tri");
332 break;
334 mTypeCombox->addItem("Other");
335 break;
336 default:
337 break;
338 }
339 }
340
341 this->addWidget(mIndexLabel, 0);
342 this->addWidget(mNameInput, 0);
343 this->addWidget(mShapeIDSpin, 0);
344 this->addWidget(mTypeCombox, 0);
345 this->addWidget(mOffsetButton, 0);
346 this->addWidget(mRemoveButton, 0);
347
348 mIndexLabel->setFixedWidth(25);
349 mNameInput->setFixedWidth(100);
350 mTypeCombox->setFixedWidth(76);
351 mShapeIDSpin->setFixedWidth(76);
352 mOffsetButton->setFixedWidth(76);
353 mRemoveButton->setFixedWidth(76);
354
355 QObject::connect(mNameInput, &QLineEdit::editingFinished, [=]() {emitChange(1); });
356 QObject::connect(mNameInput, &QLineEdit::editingFinished, [=]() {emitNameChange(1); });
357 QObject::connect(mShapeIDSpin, SIGNAL(valueChanged(int)), this, SLOT(emitChange(int)));
358 QObject::connect(mTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(emitChange(int)));
359
360 QObject::connect(mRemoveButton, SIGNAL(pressed()), this, SLOT(emitRemove()));
361
362 this->mNameInput->setText(std::string("Rigid").append(std::to_string(mElementIndex)).c_str());
363 this->mTypeCombox->setCurrentIndex(2);
364
365 QObject::connect(mOffsetButton, SIGNAL(released()), this, SLOT(createRigidDetailWidget()));
366
367 };
368
369
371 {
372 delete mNameInput;
373 delete mShapeIDSpin;
374 delete mRemoveButton;
375 delete mIndexLabel;
376 delete mOffsetButton;
377 delete mTypeCombox;
378
379 for (auto it : mDetailWidgets)
380 {
381 if (it)
382 it->close();
383 }
384 mDetailWidgets.clear();
385 };
386
387
389 {
390 mRigidInfo.shapeName.name = mNameInput->text().toStdString();
391 mRigidInfo.shapeName.rigidBodyId = mElementIndex;
392 mRigidInfo.meshShapeId = mShapeIDSpin->value();
393 mRigidInfo.shapeType = mVecShapeType[mTypeCombox->currentIndex()];
394 return mRigidInfo;
395 };
396
398 {
399 mNameInput->setText(QString(v.shapeName.name.c_str()));
400 mShapeIDSpin->setValue(v.meshShapeId);
401 for (size_t i = 0; i < mVecShapeType.size(); i++)
402 {
403 if (mVecShapeType[i] == v.shapeType)
404 mTypeCombox->setCurrentIndex(i);
405 }
406
407 mRigidInfo.transform = v.transform;
408 mRigidInfo.Offset = v.Offset;
409 mRigidInfo.mHalfLength = v.mHalfLength;
410 mRigidInfo.radius = v.radius;
411 mRigidInfo.tet = v.tet;
412 mRigidInfo.capsuleLength = v.capsuleLength;
413 mRigidInfo.motion = v.motion;
414 mRigidInfo.rigidGroup = v.rigidGroup;
415 }
416
418 {
419 auto detail = new QRigidBodyDetail(this->mRigidInfo);
420 detail->show();
421 QObject::connect(detail, QOverload<>::of(&QRigidBodyDetail::rigidChange), [=]() {emitChange(1); });
422 mDetailWidgets.push_back(detail);
423
424 }
425
426
427
428 //mJointItemLayout // Joint Configuration;
430 {
431 this->setContentsMargins(0, 0, 0, 0);
432
433 mElementIndex = id;
434
435 mIndex = new QLabel(std::to_string(id).c_str());
436 mNameInput1 = new QComboBox;
437 mNameInput2 = new QComboBox;
438 mTypeInput = new QComboBox;
439
440 mUseMoter = new QCheckBox;
441 mMoterInput = new QDoubleSpinBox;
442 mEditButton = new QPushButton("Edit");
443 mRemoveButton = new QPushButton("Delete");
444
446 {
447 switch (it)
448 {
450 mTypeInput->addItem("Ball");
451 break;
452 case dyno::Slider:
453 mTypeInput->addItem("Slider");
454 break;
455 case dyno::Hinge:
456 mTypeInput->addItem("Hinge");
457 break;
458 case dyno::Fixed:
459 mTypeInput->addItem("Fixed");
460 break;
461 case dyno::Point:
462 mTypeInput->addItem("Point");
463 break;
464 case dyno::OtherJoint:
465 mTypeInput->addItem("Other");
466 break;
467 default:
468 break;
469 }
470 }
471
472 this->addWidget(mIndex, 0);
473 this->addWidget(mNameInput1, 0);
474 this->addWidget(mNameInput2, 0);
475 this->addWidget(mTypeInput, 0);
476 this->addWidget(mUseMoter, 0);
477 this->addWidget(mMoterInput, 0);
478 this->addWidget(mEditButton, 0);
479 this->addWidget(mRemoveButton, 0);
480
481 mIndex->setFixedWidth(25);
482 mNameInput1->setFixedWidth(90);
483 mNameInput2->setFixedWidth(90);
484 mTypeInput->setFixedWidth(65);
485 mUseMoter->setFixedWidth(20);
486 mMoterInput->setFixedWidth(45);
487 mEditButton->setFixedWidth(50);
488 mRemoveButton->setFixedWidth(75);
489
490 QObject::connect(mNameInput1, SIGNAL(currentIndexChanged(int)), this, SLOT(emitChange(int)));
491 QObject::connect(mNameInput2, SIGNAL(currentIndexChanged(int)), this, SLOT(emitChange(int)));
492 QObject::connect(mNameInput2, SIGNAL(currentIndexChanged(int)), this, SLOT(emitChange(int)));
493 QObject::connect(mUseMoter, SIGNAL(stateChanged(int)), this, SLOT(emitChange(int)));
494 QObject::connect(mMoterInput, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double value)
495 {
496 int intValue = static_cast<int>(value);
497
498 emitChange(intValue);
499 });
500 QObject::connect(mTypeInput, SIGNAL(currentIndexChanged(int)), this, SLOT(emitChange(int)));
501 QObject::connect(mRemoveButton, SIGNAL(pressed()), this, SLOT(emitRemove()));
502 QObject::connect(mEditButton, SIGNAL(released()), this, SLOT(createJointDetailWidget()));
503
504 this->mTypeInput->setCurrentIndex(2);
505 };
506
507
509 {
510 delete mNameInput1;
511 delete mNameInput2;
512 delete mTypeInput;
513 delete mIndex;
514 delete mUseMoter;
515 delete mMoterInput;
516 delete mEditButton;
517 delete mRemoveButton;
518 for (auto it : mDetailWidgets)
519 {
520 if (it)
521 it->close();
522 }
523 mDetailWidgets.clear();
524 }
525
527 {
528 //jointInfo.Joint_Actor = ActorId;
529 mJointInfo.mRigidBodyName_1.name = mNameInput1->currentText().toStdString();
530 mJointInfo.mRigidBodyName_2.name = mNameInput2->currentText().toStdString();
531
532 mJointInfo.mJointType = mVecJointType[mTypeInput->currentIndex()];
533 mJointInfo.mUseMoter = mUseMoter->isChecked();
534 mJointInfo.mMoter = mMoterInput->value();
535
536
537 return mJointInfo;
538 }
539
541 {
544
545 //Type
546 mUseMoter->setChecked(v.mUseMoter);
547 mJointInfo.mUseRange = v.mUseRange;
548 mJointInfo.mAnchorPoint = v.mAnchorPoint;
549 mJointInfo.mMin = v.mMin;
550 mJointInfo.mMax = v.mMax;
551 mMoterInput->setValue(v.mMoter);
552 mJointInfo.mAxis = v.mAxis;
553 }
554
555
557 {
558 auto detail = new QJointBodyDetail(this->mJointInfo);
559 detail->show();
560 QObject::connect(detail, QOverload<>::of(&QJointBodyDetail::jointChange), [=]() {emitChange(1); });
561
562 mDetailWidgets.push_back(detail);
563 }
564
565
567
570 {
571 mMainLayout = new QVBoxLayout;
572 mMainLayout->setContentsMargins(0, 0, 0, 0);
573 mMainLayout->setAlignment(Qt::AlignLeft);
574
575 this->setLayout(mMainLayout);
576
577 //Label
578
579 auto titleLayout = new QVBoxLayout;
580
581 QLabel* name = new QLabel();
582 name->setText(FormatFieldWidgetName(field->getObjectName()));
583 titleLayout->addWidget(name);
584 mMainLayout->addLayout(titleLayout);
585
586 //RigidBody UI
587 auto RigidBodyUI = new QVBoxLayout;
588 RigidBodyUI->setContentsMargins(0, 0, 0, 0);
589
590 QHBoxLayout* nameLayout = new QHBoxLayout;
591
592 QLabel* idLabel = new QLabel("<b>No.</b>",this);
593 QLabel* rigidNameLabel = new QLabel("<b>Name</b>", this);
594 QLabel* shapeIdLabel = new QLabel("<b>ShapeID</b>", this);
595 QLabel* typeLabel = new QLabel("<b>Type</b>", this);
596 QLabel* offsetLabel = new QLabel("<b>Edit</b>", this);
597
598 QPushButton* addItembutton = new QPushButton("Add Item", this);
599 addItembutton->setFixedSize(80, 30);
600
601 nameLayout->addWidget(idLabel);
602 nameLayout->addWidget(rigidNameLabel);
603 nameLayout->addWidget(shapeIdLabel);
604 nameLayout->addWidget(typeLabel);
605 nameLayout->addWidget(offsetLabel);
606 nameLayout->addWidget(addItembutton);
607
608 RigidBodyUI->addLayout(nameLayout);
609 mMainLayout->addLayout(RigidBodyUI);
610
611 mRigidsLayout = new QVBoxLayout;
612 mMainLayout->addLayout(mRigidsLayout);
613
614 idLabel->setFixedWidth(25);
615 rigidNameLabel->setFixedWidth(100);
616 typeLabel->setFixedWidth(76);
617 shapeIdLabel->setFixedWidth(76);
618 offsetLabel->setFixedWidth(76);
619
620 idLabel->setAlignment(Qt::AlignCenter);
621 rigidNameLabel->setAlignment(Qt::AlignCenter);
622 typeLabel->setAlignment(Qt::AlignCenter);
623 shapeIdLabel->setAlignment(Qt::AlignCenter);
624 offsetLabel->setAlignment(Qt::AlignCenter);
625
626 QObject::connect(addItembutton, SIGNAL(pressed()), this, SLOT(addRigidBodyItemWidget()));
627 QObject::connect(addItembutton, SIGNAL(pressed()), this, SLOT(updateJointComboBox()));
628
629 //Joint UI
630 auto jointUI = new QVBoxLayout;
631 jointUI->setContentsMargins(0, 0, 0, 0);
632 QHBoxLayout* jointLayout = new QHBoxLayout;
633
634 QLabel* jointNumLabel = new QLabel("<b>No.</b>",this);
635 QLabel* actor1 = new QLabel("<b>RigidBody1</b>",this);
636 QLabel* actor2 = new QLabel("<b>RigidBody2</b>",this);
637 QLabel* jointTypeLabel = new QLabel("<b>Type</b>",this);
638 QLabel* moterLabel = new QLabel("<b>Moter</b>",this);
639 QLabel* anchorOffsetLabel = new QLabel("<b>Edit</b>",this);
640
641 QPushButton* addJointItembutton = new QPushButton("Add Item",this);
642 addJointItembutton->setFixedSize(80, 30);
643
644 jointLayout->addWidget(jointNumLabel);
645 jointLayout->addWidget(actor1);
646 jointLayout->addWidget(actor2);
647 jointLayout->addWidget(jointTypeLabel);
648 jointLayout->addWidget(moterLabel);
649 jointLayout->addWidget(anchorOffsetLabel);
650 jointLayout->addWidget(addJointItembutton);
651
652 jointUI->addLayout(jointLayout);
653 jointUI->setContentsMargins(0, 0, 0, 0);
654
655 mMainLayout->addLayout(jointUI);
656 mJointsLayout = new QVBoxLayout;
657 mMainLayout->addLayout(mJointsLayout);
658
659 jointNumLabel->setFixedWidth(25);
660 actor1->setFixedWidth(90);
661 actor2->setFixedWidth(90);
662 jointTypeLabel->setFixedWidth(65);
663 moterLabel->setFixedWidth(65);
664 anchorOffsetLabel->setFixedWidth(50);
665
666 jointNumLabel->setAlignment(Qt::AlignCenter);
667 actor1->setAlignment(Qt::AlignCenter);
668 actor2->setAlignment(Qt::AlignCenter);
669 jointTypeLabel->setAlignment(Qt::AlignCenter);
670 moterLabel->setAlignment(Qt::AlignCenter);
671 anchorOffsetLabel->setAlignment(Qt::AlignCenter);
672
673 QObject::connect(addJointItembutton, SIGNAL(pressed()), this, SLOT(addJointItemWidget()));
674 QObject::connect(this, SIGNAL(vectorChange()), this, SLOT(updateField()));
675
677 if (f != nullptr)
678 {
679 mVec = f->getValue();
680 }
681
682 updateWidget();
683
684 };
685
687 {
689 if (f != nullptr)
690 {
691 f->setValue(mVec);
692 }
693
694 //printField();
695 };
696
698 {
699 delete mMainLayout;
700 mName2RigidId.clear();
701 mObjID2Name.clear();
702 }
703
705 {
706 for (size_t i = 0; i < mVec.mVehicleRigidBodyInfo.size(); i++)
707 {
708 createItemWidget(mVec.mVehicleRigidBodyInfo[i]);
709 }
710
712
713 for (size_t i = 0; i < mVec.mVehicleJointInfo.size(); i++)
714 {
715 createJointItemWidget(mVec.mVehicleJointInfo[i]);
716 }
718 updateVector();
719 }
720
722 {
723 mObjID2Name.clear();
724 mName2RigidId.clear();
725
726 for (auto it : mRigidBodyItems)
727 {
728 mObjID2Name[it->getObjID()] = it->mNameInput->text().toStdString();
729 mName2RigidId[it->mNameInput->text().toStdString()] = it->getRigidID();
730 }
731 }
732
734 {
736
737 for (auto itemLayout : mJointItems)
738 {
739 //update RigidBody name to widget
740 updateJointLayoutComboxText(itemLayout);
741
742 //set index
743 itemLayout->mNameInput1->blockSignals(true);
744 itemLayout->mNameInput2->blockSignals(true);
745
746 if (itemLayout->mName1_ObjID != -1)
747 {
748 auto str = mObjID2Name[itemLayout->mName1_ObjID];
749 if (str == std::string(""))
750 {
751 setJointNameComboxEmpty(itemLayout, true, 1, -1);
752 }
753 else
754 {
755 auto index = mName2RigidId[str];
756 itemLayout->mNameInput1->setCurrentIndex(index);
757 }
758 }
759
760 if (itemLayout->mName2_ObjID != -1)
761 {
762 auto str = mObjID2Name[itemLayout->mName2_ObjID];
763 if (str == std::string(""))
764 {
765 setJointNameComboxEmpty(itemLayout, true, 2, -1);
766 }
767 else
768 {
769 auto index = mName2RigidId[str];
770 itemLayout->mNameInput2->setCurrentIndex(index);
771 }
772 }
773
774
775 if (itemLayout->mName1_ObjID == -1)
776 {
777 setJointNameComboxEmpty(itemLayout, true, 1, -1);
778 }
779
780 if (itemLayout->mName2_ObjID == -1)
781 {
782 setJointNameComboxEmpty(itemLayout, true, 2, -1);
783 }
784 itemLayout->mNameInput1->blockSignals(false);
785 itemLayout->mNameInput2->blockSignals(false);
786
787 }
788
790
791 }
792
793 void QVehicleInfoWidget::setJointNameComboxEmpty(mJointItemLayout* item, bool emitSignal, int select, int index)
794 {
795 if (select == 1)
796 {
797 if (emitSignal)
798 item->mNameInput1->blockSignals(false);
799 else
800 item->mNameInput1->blockSignals(true);
801 item->mNameInput1->setCurrentIndex(index);
802 }
803 else if (select == 2)
804 {
805 if (emitSignal)
806 item->mNameInput2->blockSignals(false);
807 else
808 item->mNameInput2->blockSignals(true);
809 item->mNameInput2->setCurrentIndex(index);
810 }
811
812 item->mNameInput1->blockSignals(false);
813 item->mNameInput2->blockSignals(false);
814
815
816 };
817
818
820 {
821 //******************************* UpdateData *******************************//
822
823 mVec.mVehicleRigidBodyInfo.clear();
824 for (size_t i = 0; i < mRigidBodyItems.size(); i++)
825 {
826 mVec.mVehicleRigidBodyInfo.push_back(mRigidBodyItems[i]->value());
827 }
828
829 //******************************* bulidQueryMap *******************************//
831
832 //******************************* UpdateData *******************************//
833 mVec.mVehicleJointInfo.clear();
834
835 //update Rigid ID
836 for (size_t i = 0; i < mJointItems.size(); i++)
837 {
838 auto& jointItem = mJointItems[i];
839 mVec.mVehicleJointInfo.push_back(jointItem->value());
840 auto& jointInfo = mVec.mVehicleJointInfo[i];
841
842 if (jointInfo.mRigidBodyName_1.name != std::string(""))
843 jointInfo.mRigidBodyName_1.rigidBodyId = mName2RigidId[jointInfo.mRigidBodyName_1.name];
844
845 if (jointInfo.mRigidBodyName_2.name != std::string(""))
846 jointInfo.mRigidBodyName_2.rigidBodyId = mName2RigidId[jointInfo.mRigidBodyName_2.name];
847 }
848 emit vectorChange();
849 }
850
852 {
853 mJointsLayout->removeItem(mJointItems[id]);
854 delete mJointItems[id];
855 mJointItems.erase(mJointItems.begin() + id);
856 for (size_t i = 0; i < mJointItems.size(); i++)
857 {
858 mJointItems[i]->setId(i);
859 }
860
861 updateVector();
862 }
863
864
866 {
867 for (size_t i = 0; i < mJointItems.size(); i++)
868 {
869 auto& jointItem = mJointItems[i];
870 jointItem->mName1_ObjID = getRigidItemObjID(jointItem->mNameInput1->currentText().toStdString());
871 //std::cout << jointItem->mNameInput1->currentText().toStdString() << ", " << jointItem->mName1_ObjID << std::endl;
872 jointItem->mName2_ObjID = getRigidItemObjID(jointItem->mNameInput2->currentText().toStdString());
873
874 }
875 }
876
882
884 {
886 itemLayout->setObjId(objId);
887
888 connectRigidWidgetSignal(itemLayout);
889
890 mRigidsLayout->addLayout(itemLayout);
891 mRigidBodyItems.push_back(itemLayout);
892
893 updateVector();
894 }
895
896
898 {
899 mRigidsLayout->removeItem(mRigidBodyItems[id]);
900 delete mRigidBodyItems[id];
901 mRigidBodyItems.erase(mRigidBodyItems.begin() + id);
902 for (size_t i = 0; i < mRigidBodyItems.size(); i++)
903 {
904 mRigidBodyItems[i]->setId(i);
905 }
906
907 //******************************* UpdateData *******************************//
908 updateVector();
911 }
912
914 {
915 mJointItemLayout* itemLayout = new mJointItemLayout(mJointItems.size());
916
917 connectJointWidgetSignal(itemLayout);
918
919 mJointsLayout->addLayout(itemLayout);
920 mJointItems.push_back(itemLayout);
921
922 updateJointLayoutComboxText(itemLayout);
923
924 updateVector();
925 }
926
928 {
929 for (const auto& pair : mObjID2Name) {
930 if (pair.second == str) {
931 return pair.first;
932 }
933 }
934 return -1;
935 }
936
938 {
939 itemLayout->mNameInput1->blockSignals(true);
940 itemLayout->mNameInput2->blockSignals(true);
941
942 itemLayout->mNameInput1->clear();
943 itemLayout->mNameInput2->clear();
944
945 for (auto it : mObjID2Name)
946 {
947 auto name = it.second;
948 itemLayout->mNameInput1->addItem(name.c_str());
949 itemLayout->mNameInput2->addItem(name.c_str());
950 }
951
952 itemLayout->mNameInput1->setCurrentIndex(-1);
953 itemLayout->mNameInput2->setCurrentIndex(-1);
954
955 itemLayout->mNameInput1->blockSignals(false);
956 itemLayout->mNameInput2->blockSignals(false);
957 }
958
960 {
962 itemLayout->setObjId(mRigidCounter);
964
965 itemLayout->setValue(rigidBody);
966 connectRigidWidgetSignal(itemLayout);
967 mRigidsLayout->addLayout(itemLayout);
968 mRigidBodyItems.push_back(itemLayout);
969
970 }
971
973 {
974 mJointItemLayout* itemLayout = new mJointItemLayout(mJointItems.size());
975 itemLayout->setValue(rigidBody);
976 connectJointWidgetSignal(itemLayout);
977 mJointsLayout->addLayout(itemLayout);
978 mJointItems.push_back(itemLayout);
979 }
980
982 {
983 QObject::connect(itemLayout, SIGNAL(removeByElementIndexId(int)), this, SLOT(removeJointItemWidgetById(int)));
984 QObject::connect(itemLayout, SIGNAL(valueChange(int)), this, SLOT(updateVector()));
985
986 QObject::connect(itemLayout->mNameInput1, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoint_RigidObjID()));
987 QObject::connect(itemLayout->mNameInput2, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoint_RigidObjID()));
988
989 }
990
992 {
993 QObject::connect(itemLayout, SIGNAL(removeByElementIndexId(int)), this, SLOT(removeRigidBodyItemWidgetById(int)));
994 QObject::connect(itemLayout, SIGNAL(nameChange(int)), this, SLOT(updateJointComboBox()));
995 QObject::connect(itemLayout, SIGNAL(valueChange(int)), this, SLOT(updateVector()));
996 QObject::connect(itemLayout->mNameInput, SIGNAL(editingFinished()), this, SLOT(bulidQueryMap()));
997 }
998
999
1000}
1001
1002
#define IMPL_FIELD_WIDGET(_data_type_, _type_)
#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 jointChange()
Transmits a signal when data is updated.
QPiecewiseDoubleSpinBox * mMinWidget
QPiecewiseDoubleSpinBox * mMaxWidget
QJointBodyDetail(VehicleJointInfo &jointInfo)
void updateData()
Updated when any element parameter is changed.
VehicleJointInfo * mJointData
mVec3fWidget * mAnchorPointWidget
QRigidBodyDetail(VehicleRigidBodyInfo &rigidInfo)
std::vector< ConfigMotionType > mAllConfigMotionTypes
void updateData()
Updated when any element parameter is changed.
mVec3fWidget * mHalfLengthWidget
mPiecewiseDoubleSpinBox * mRadiusWidget
mVec3fWidget * mTranslationWidget
VehicleRigidBodyInfo * mRigidBodyData
mPiecewiseDoubleSpinBox * mCapsuleLengthWidget
void rigidChange()
Transmits a signal when data is updated.
std::map< std::string, int > mName2RigidId
void setJointNameComboxEmpty(mJointItemLayout *item, bool emitSignal, int select, int index)
void updateJointComboBox()
Update text and key of the comboxbox.
void updateWidget()
Called when the field is updated.
void addRigidBodyItemWidgetByID(int objId)
std::vector< mJointItemLayout * > mJointItems
void updateJointLayoutComboxText(mJointItemLayout *itemLayout)
std::map< int, std::string > mObjID2Name
void connectRigidWidgetSignal(RigidBodyItemLayout *itemLayout)
void vectorChange()
Data Change.
std::vector< RigidBodyItemLayout * > mRigidBodyItems
void updateField()
Called when the widget is updated.
int getRigidItemObjID(std::string str)
void connectJointWidgetSignal(mJointItemLayout *itemLayout)
void createItemWidget(const VehicleRigidBodyInfo &rigidBody)
void createJointItemWidget(const VehicleJointInfo &rigidBody)
DECLARE_FIELD_WIDGET QVehicleInfoWidget(FBase *field)
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
void setObjId(int id)
Unique objId used to identify this Item.
const std::vector< ConfigShapeType > mVecShapeType
void createRigidDetailWidget()
Create RigidBody Detail Panel.
VehicleRigidBodyInfo value()
Get current RigidBodyInfo.
void setValue(const VehicleRigidBodyInfo &v)
Initialization RigidBodyInfo.
VehicleRigidBodyInfo mRigidInfo
std::vector< QRigidBodyDetail * > mDetailWidgets
The VehicleBind class is used to record information about created rigid bodies and joints....
const std::vector< ConfigJointType > mVecJointType
std::vector< QJointBodyDetail * > mDetailWidgets
void createJointDetailWidget()
Create Joint Detail Panel.
VehicleJointInfo value()
Get current RigidBodyInfo.
void setValue(const VehicleJointInfo &v)
Initialization RigidBodyInfo.
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
ConfigJointType
Definition VehicleInfo.h:32
@ Point
Definition VehicleInfo.h:37
@ BallAndSocket
Definition VehicleInfo.h:33
@ OtherJoint
Definition VehicleInfo.h:38
@ Slider
Definition VehicleInfo.h:34
@ Hinge
Definition VehicleInfo.h:35
@ Fixed
Definition VehicleInfo.h:36
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9
ConfigShapeType
Definition VehicleInfo.h:22
@ Sphere
Definition VehicleInfo.h:26
@ OtherShape
Definition VehicleInfo.h:28
@ Capsule
Definition VehicleInfo.h:25
Transform< float, 3 > Transform3f
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
@ CMT_Static
Definition VehicleInfo.h:16
@ CMT_Dynamic
Definition VehicleInfo.h:18
@ CMT_Kinematic
Definition VehicleInfo.h:17
std::string name
Definition VehicleInfo.h:52
The joint information is stored in mVehicleJointInfo.
Vector< Real, 3 > mAnchorPoint
ConfigJointType mJointType
Name_Shape mRigidBodyName_2
Name_Shape mRigidBodyName_1
Vector< Real, 3 > mAxis
The Rigid body information is stored in mVehicleJointInfo.
Definition VehicleInfo.h:61
std::vector< Vec3f > tet
Definition VehicleInfo.h:91
ConfigMotionType motion
Definition VehicleInfo.h:93
ConfigShapeType shapeType
Definition VehicleInfo.h:85