24 #include <QtConcurrent/qtconcurrentrun.h>
26 #include "../controller/DeselectOperation.h"
27 #include "../controller/RemoveOperation.h"
28 #include "../controller/RemoveFromGroupOperation.h"
35 collisionMeshToggleButton(new QPushButton(this)),
36 rotateManipulatorToggleButton(new QPushButton(this)),
37 translateManipulatorToggleButton(new QPushButton(this)),
38 undoButton(new QPushButton(this)),
39 redoButton(new QPushButton(this)),
40 removeSelectedObjectsButton(new QPushButton(this)),
41 editorToggleButton(new QPushButton(this)),
42 viewerToggleButton(new QPushButton(this)),
43 editorViewerButtonGroup(new QButtonGroup(this)),
44 mainLayout(new QVBoxLayout(this)),
45 leftButtonsSize(30, 30),
46 buttonColor(
"lightgray"),
49 showCollisionMesh(false),
50 showTranslateManipulator(false),
51 showRotateManipulator(false)
55 setObjectName(QString::fromUtf8(
"SceneEditorWidget"));
57 mainLayout->addWidget(sceneGraph);
59 this->setLayout(mainLayout);
61 editorViewerButtonGroup->setExclusive(
true);
63 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
64 sizePolicy.setHorizontalStretch(0);
65 sizePolicy.setVerticalStretch(0);
67 collisionMeshToggleButton->setObjectName(QString::fromUtf8(
"collisionMeshToggleButton"));
68 sizePolicy.setHeightForWidth(collisionMeshToggleButton->sizePolicy().hasHeightForWidth());
69 collisionMeshToggleButton->setSizePolicy(sizePolicy);
71 icon1.addFile(QString::fromUtf8(
":/images/Collision.png"), QSize(), QIcon::Normal,
QIcon::Off);
72 collisionMeshToggleButton->setIcon(icon1);
73 collisionMeshToggleButton->setToolTip(tr(
"Toggle Collisionmesh"));
74 collisionMeshToggleButton->setIconSize(leftButtonsSize);
75 collisionMeshToggleButton->setCheckable(
true);
76 collisionMeshToggleButton->setFixedSize(leftButtonsSize);
77 collisionMeshToggleButton->setStyleSheet(
"background-color: " + buttonColor);
78 collisionMeshToggleButton->move(margin, margin);
79 collisionMeshToggleButton->show();
81 rotateManipulatorToggleButton->setObjectName(QString::fromUtf8(
"rotateManipulatorToggleButton"));
82 sizePolicy.setHeightForWidth(rotateManipulatorToggleButton->sizePolicy().hasHeightForWidth());
83 rotateManipulatorToggleButton->setSizePolicy(sizePolicy);
85 icon2.addFile(QString::fromUtf8(
":/images/Rotate.png"), QSize(), QIcon::Normal,
QIcon::Off);
86 rotateManipulatorToggleButton->setIcon(icon2);
87 rotateManipulatorToggleButton->setToolTip(tr(
"Toggle Rotationmanipulator"));
88 rotateManipulatorToggleButton->setIconSize(leftButtonsSize);
89 rotateManipulatorToggleButton->setCheckable(
true);
90 rotateManipulatorToggleButton->setFixedSize(leftButtonsSize);
91 rotateManipulatorToggleButton->setStyleSheet(
"background-color: " + buttonColor);
92 rotateManipulatorToggleButton->move(margin, collisionMeshToggleButton->pos().y() + leftButtonsSize.height() + spacing);
93 rotateManipulatorToggleButton->show();
95 translateManipulatorToggleButton->setObjectName(QString::fromUtf8(
"translateManipulatorToggleButton"));
96 sizePolicy.setHeightForWidth(translateManipulatorToggleButton->sizePolicy().hasHeightForWidth());
97 translateManipulatorToggleButton->setSizePolicy(sizePolicy);
99 icon3.addFile(QString::fromUtf8(
":/images/Translate.png"), QSize(), QIcon::Normal,
QIcon::Off);
100 translateManipulatorToggleButton->setIcon(icon3);
101 translateManipulatorToggleButton->setToolTip(tr(
"Toggle Translationmanipulator"));
102 translateManipulatorToggleButton->setIconSize(leftButtonsSize);
103 translateManipulatorToggleButton->setCheckable(
true);
104 translateManipulatorToggleButton->setFixedSize(leftButtonsSize);
105 translateManipulatorToggleButton->setStyleSheet(
"background-color: " + buttonColor);
106 translateManipulatorToggleButton->move(margin, rotateManipulatorToggleButton->pos().y() + leftButtonsSize.height() + spacing);
107 translateManipulatorToggleButton->show();
110 undoButton->setObjectName(QString::fromUtf8(
"undoButton"));
111 sizePolicy.setHeightForWidth(undoButton->sizePolicy().hasHeightForWidth());
112 undoButton->setSizePolicy(sizePolicy);
114 icon4.addFile(QString::fromUtf8(
":/icons/edit-undo-3.svg"), QSize(), QIcon::Normal,
QIcon::Off);
115 undoButton->setIcon(icon4);
116 undoButton->setToolTip(tr(
"Undo last Action"));
117 undoButton->setIconSize(leftButtonsSize);
118 undoButton->setFixedSize(leftButtonsSize);
119 undoButton->setStyleSheet(
"background-color: " + buttonColor);
120 undoButton->move(margin, translateManipulatorToggleButton->pos().y() + leftButtonsSize.height() + spacing);
123 redoButton =
new QPushButton(
this);
124 redoButton->setObjectName(QString::fromUtf8(
"redoButton"));
125 sizePolicy.setHeightForWidth(redoButton->sizePolicy().hasHeightForWidth());
126 redoButton->setSizePolicy(sizePolicy);
128 icon5.addFile(QString::fromUtf8(
":/icons/edit-redo-3.svg"), QSize(), QIcon::Normal,
QIcon::Off);
129 redoButton->setIcon(icon5);
130 redoButton->setToolTip(tr(
"Redo last Action"));
131 redoButton->setIconSize(leftButtonsSize);
132 redoButton->setFixedSize(leftButtonsSize);
133 redoButton->setStyleSheet(
"background-color: " + buttonColor);
134 redoButton->move(margin, undoButton->pos().y() + leftButtonsSize.height() + spacing);
137 removeSelectedObjectsButton =
new QPushButton(
this);
138 removeSelectedObjectsButton->setObjectName(QString::fromUtf8(
"removeSelectedObjectsButton"));
139 sizePolicy.setHeightForWidth(removeSelectedObjectsButton->sizePolicy().hasHeightForWidth());
140 removeSelectedObjectsButton->setSizePolicy(sizePolicy);
142 icon6.addFile(QString::fromUtf8(
":/icons/dialog-close.ico"), QSize(), QIcon::Normal,
QIcon::Off);
143 removeSelectedObjectsButton->setIcon(icon6);
144 removeSelectedObjectsButton->setToolTip(tr(
"Remove selected Objects from scene"));
145 removeSelectedObjectsButton->setIconSize(leftButtonsSize);
146 removeSelectedObjectsButton->setFixedSize(leftButtonsSize);
147 removeSelectedObjectsButton->setStyleSheet(
"background-color: " + buttonColor);
148 removeSelectedObjectsButton->move(margin, redoButton->pos().y() + leftButtonsSize.height() + spacing);
149 removeSelectedObjectsButton->show();
151 viewerToggleButton->setObjectName(QString::fromUtf8(
"viewerToggleButton"));
152 viewerToggleButton->setText(tr(
"Viewer"));
153 viewerToggleButton->setCheckable(
true);
154 viewerToggleButton->adjustSize();
155 viewerToggleButton->setStyleSheet(
"background-color: " + buttonColor);
156 viewerToggleButton->show();
157 editorViewerButtonGroup->addButton(viewerToggleButton, VIEWER_BUTTON_ID);
159 editorToggleButton->setObjectName(QString::fromUtf8(
"editorToggleButton"));
160 editorToggleButton->setText(tr(
"Editor"));
161 editorToggleButton->setCheckable(
true);
162 editorToggleButton->setChecked(
true);
163 editorToggleButton->adjustSize();
164 editorToggleButton->setStyleSheet(
"background-color: " + buttonColor);
165 editorToggleButton->show();
166 editorViewerButtonGroup->addButton(editorToggleButton, EDITOR_BUTTON_ID);
169 connect(undoButton, SIGNAL(released()),
this, SLOT(undoButtonReleased()));
170 connect(redoButton, SIGNAL(released()),
this, SLOT(redoButtonReleased()));
171 connect(removeSelectedObjectsButton, SIGNAL(released()),
this, SLOT(removeSelectedObjectsButtonReleased()));
172 connect(collisionMeshToggleButton, SIGNAL(toggled(
bool)),
this, SLOT(collisionMeshToggleButtonToggled(
bool)));
173 connect(rotateManipulatorToggleButton, SIGNAL(toggled(
bool)),
this, SLOT(rotateManipulatorToggleButtonToggled(
bool)));
174 connect(translateManipulatorToggleButton, SIGNAL(toggled(
bool)),
this, SLOT(translateManipulatorToggleButtonToggled(
bool)));
175 connect(editorViewerButtonGroup, SIGNAL(
buttonClicked(
int)),
this, SLOT(editorViewerButtonGroupButtonClicked(
int)));
177 std::shared_ptr<gui::ShortcutController> shortcutController =
control->getShortcutController();
179 QPointer<QAction> undoAction(
new OverrideAction(
"Scene: Undo last Action",
this));
180 this->addAction(undoAction);
181 connect(undoAction, SIGNAL(triggered()), undoButton, SLOT(click()));
182 shortcutController->registerAction(undoAction->text(), undoAction);
184 QPointer<QAction> redoAction(
new OverrideAction(
"Scene: Redo last Action",
this));
185 this->addAction(redoAction);
186 connect(redoAction, SIGNAL(triggered()), redoButton, SLOT(click()));
187 shortcutController->registerAction(redoAction->text(), redoAction);
189 QPointer<QAction> removeSelectedObjectsAction(
new OverrideAction(
"Scene: Remove the selected Objects",
this));
190 this->addAction(removeSelectedObjectsAction);
191 connect(removeSelectedObjectsAction, SIGNAL(triggered()), removeSelectedObjectsButton, SLOT(click()));
192 shortcutController->registerAction(removeSelectedObjectsAction->text(), removeSelectedObjectsAction);
194 QPointer<QAction> collisionAction(
new OverrideAction(
"Scene: Toggle Collision Meshes",
this));
195 this->addAction(collisionAction);
196 connect(collisionAction, SIGNAL(triggered()), collisionMeshToggleButton, SLOT(toggle()));
197 shortcutController->registerAction(collisionAction->text(), collisionAction);
199 QPointer<QAction> rotateAction(
new OverrideAction(
"Scene: Toggle Rotation Manipulator",
this));
200 this->addAction(rotateAction);
201 connect(rotateAction, SIGNAL(triggered()), rotateManipulatorToggleButton, SLOT(toggle()));
202 shortcutController->registerAction(rotateAction->text(), rotateAction);
204 QPointer<QAction> translateAction(
new OverrideAction(
"Scene: Toggle Translation Manipulator",
this));
205 this->addAction(translateAction);
206 connect(translateAction, SIGNAL(triggered()), translateManipulatorToggleButton, SLOT(toggle()));
207 shortcutController->registerAction(translateAction->text(), translateAction);
209 QPointer<QAction> editorAction(
new OverrideAction(
"Scene: Switch to Editor Mode",
this));
210 this->addAction(editorAction);
211 connect(editorAction, SIGNAL(triggered()), editorToggleButton, SLOT(click()));
212 shortcutController->registerAction(editorAction->text(), editorAction);
214 QPointer<QAction> viewerAction(
new OverrideAction(
"Scene: Switch to Viewer Mode",
this));
215 this->addAction(viewerAction);
216 connect(viewerAction, SIGNAL(triggered()), viewerToggleButton, SLOT(click()));
217 shortcutController->registerAction(viewerAction->text(), viewerAction);
219 QPointer<QAction> switchEditorViewerAction(
new OverrideAction(
"Scene: Switch between Editor and Viewer Mode",
this));
220 this->addAction(switchEditorViewerAction);
221 connect(switchEditorViewerAction, SIGNAL(triggered()),
this, SLOT(toggleEditorViewerMode()));
222 shortcutController->registerAction(switchEditorViewerAction->text(), switchEditorViewerAction);
224 emit sizeChanged(this->size());
231 void gui::SceneEditorWidget::resizeEvent(QResizeEvent* event)
233 QWidget::resizeEvent(event);
234 emit sizeChangedSignal(event->size());
237 void gui::SceneEditorWidget::sizeChanged(QSize newSize)
239 viewerToggleButton->move(newSize.width() - margin - viewerToggleButton->size().width(), margin);
240 editorToggleButton->move(viewerToggleButton->pos().x() - editorToggleButton->size().width(), margin);
243 void gui::SceneEditorWidget::undoButtonReleased()
247 sharedController->undo();
251 void gui::SceneEditorWidget::redoButtonReleased()
255 sharedController->redo();
259 void gui::SceneEditorWidget::removeSelectedObjectsButtonReleased()
263 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
264 std::vector<scene3D::SceneObjectPtr> selectedObjects = sharedController->getScene()->getSelectionManager()->getAllSelected();
265 std::vector<scene3D::SceneGroupPtr> groups = sharedController->getScene()->getGroupManager()->getAllGroups();
267 for (
auto it = selectedObjects.rbegin(); it != selectedObjects.rend(); ++it)
270 operations->push_back(deselectOperation);
272 for (
auto itG = groups.begin(); itG != groups.end(); ++itG)
274 if ((*itG)->contains(*it))
277 operations->push_back(removeFromGroupOperation);
282 operations->push_back(removeOperation);
289 void gui::SceneEditorWidget::collisionMeshToggleButtonToggled(
bool checked)
295 object->showCollisionMesh(checked);
300 void gui::SceneEditorWidget::rotateManipulatorToggleButtonToggled(
bool checked)
308 if (sharedController->getScene()->getManipulatorManager()->getManipulatorMode()
320 if (sharedController->getScene()->getManipulatorManager()->getManipulatorMode()
331 sharedController->getScene()->getManipulatorManager()->setManipulatorMode(mode);
335 void gui::SceneEditorWidget::translateManipulatorToggleButtonToggled(
bool checked)
343 if (sharedController->getScene()->getManipulatorManager()->getManipulatorMode()
355 if (sharedController->getScene()->getManipulatorManager()->getManipulatorMode()
366 sharedController->getScene()->getManipulatorManager()->setManipulatorMode(mode);
370 void gui::SceneEditorWidget::editorViewerButtonGroupButtonClicked(
int id)
374 if (
id == VIEWER_BUTTON_ID)
376 showCollisionMesh = collisionMeshToggleButton->isChecked();
378 if (showCollisionMesh)
380 collisionMeshToggleButton->click();
383 collisionMeshToggleButton->hide();
384 collisionMeshToggleButton->setEnabled(
false);
385 collisionMeshToggleButton->setCheckable(
false);
386 showRotateManipulator = rotateManipulatorToggleButton->isChecked();
388 if (showRotateManipulator)
390 rotateManipulatorToggleButton->click();
393 rotateManipulatorToggleButton->hide();
394 rotateManipulatorToggleButton->setEnabled(
false);
395 rotateManipulatorToggleButton->setCheckable(
false);
396 showTranslateManipulator = translateManipulatorToggleButton->isChecked();
398 if (showTranslateManipulator)
400 translateManipulatorToggleButton->click();
403 translateManipulatorToggleButton->hide();
404 translateManipulatorToggleButton->setEnabled(
false);
405 translateManipulatorToggleButton->setCheckable(
false);
407 undoButton->setEnabled(
false);
409 redoButton->setEnabled(
false);
410 removeSelectedObjectsButton->hide();
411 removeSelectedObjectsButton->setEnabled(
false);
413 sharedController->getScene()->enterViewerMode();
415 else if (
id == EDITOR_BUTTON_ID)
417 collisionMeshToggleButton->show();
418 collisionMeshToggleButton->setEnabled(
true);
419 collisionMeshToggleButton->setCheckable(
true);
421 if (showCollisionMesh)
423 collisionMeshToggleButton->click();
426 rotateManipulatorToggleButton->show();
427 rotateManipulatorToggleButton->setEnabled(
true);
428 rotateManipulatorToggleButton->setCheckable(
true);
430 if (showRotateManipulator)
432 rotateManipulatorToggleButton->click();
435 translateManipulatorToggleButton->show();
436 translateManipulatorToggleButton->setEnabled(
true);
437 translateManipulatorToggleButton->setCheckable(
true);
439 if (showTranslateManipulator)
441 translateManipulatorToggleButton->click();
445 undoButton->setEnabled(
true);
447 redoButton->setEnabled(
true);
448 removeSelectedObjectsButton->show();
449 removeSelectedObjectsButton->setEnabled(
true);
451 sharedController->getScene()->enterEditorMode();
456 void gui::SceneEditorWidget::toggleEditorViewerMode()
458 switch (this->editorViewerButtonGroup->checkedId())
460 case VIEWER_BUTTON_ID:
461 this->editorToggleButton->click();
464 case EDITOR_BUTTON_ID:
465 this->viewerToggleButton->click();
472 collisionMeshToggleButton->setToolTip(tr(
"Toggle Collisionmesh"));
473 rotateManipulatorToggleButton->setToolTip(tr(
"Toggle Rotationmanipulator"));
474 translateManipulatorToggleButton->setToolTip(tr(
"Toggle Translationmanipulator"));
475 undoButton->setToolTip(tr(
"Undo last Action"));
476 redoButton->setToolTip(tr(
"Redo last Action"));
477 removeSelectedObjectsButton->setToolTip(tr(
"Remove selected Objects from scene"));
478 viewerToggleButton->setText(tr(
"Viewer"));
479 editorToggleButton->setText(tr(
"Editor"));
484 sceneGraph->postDocking();