25 #include <Inventor/actions/SoRayPickAction.h>
26 #include <QGridLayout>
27 #include <QDataStream>
32 #include "../controller/AddOperation.h"
33 #include "../controller/SelectOperation.h"
34 #include "../controller/DeselectOperation.h"
35 #include "../controller/RotateTranslateOperation.h"
43 camera(new SoPerspectiveCamera),
50 this->setContentsMargins(1, 1, 1, 1);
52 QGridLayout* grid =
new QGridLayout();
53 grid->setContentsMargins(0, 0, 0, 0);
54 this->setLayout(grid);
55 this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
57 QWidget* view1 =
new QWidget(
this);
58 view1->setMinimumSize(100, 100);
59 view1->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
60 grid->addWidget(view1, 0, 0, 1, 2);
64 std::shared_ptr<gui::ShortcutController> shortcutController =
control->getShortcutController();
67 QPointer<QAction> cameraViewAllAction(
new OverrideAction(
"Scene: Camera view all",
this));
68 this->addAction(cameraViewAllAction);
69 connect(cameraViewAllAction, SIGNAL(triggered()),
this, SLOT(
cameraViewAll()));
70 shortcutController->registerAction(cameraViewAllAction->text(), cameraViewAllAction);
73 QPointer<QAction> cameraViewFromXAction(
new OverrideAction(
"Scene: Camera view from X",
this));
74 this->addAction(cameraViewFromXAction);
75 connect(cameraViewFromXAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromX()));
76 shortcutController->registerAction(cameraViewFromXAction->text(), cameraViewFromXAction);
79 QPointer<QAction> cameraViewFromNegXAction(
new OverrideAction(
"Scene: Camera view from negative X",
this));
80 this->addAction(cameraViewFromNegXAction);
81 connect(cameraViewFromNegXAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromNegX()));
82 shortcutController->registerAction(cameraViewFromNegXAction->text(), cameraViewFromNegXAction);
85 QPointer<QAction> cameraViewFromYAction(
new OverrideAction(
"Scene: Camera view from Y",
this));
86 this->addAction(cameraViewFromYAction);
87 connect(cameraViewFromYAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromY()));
88 shortcutController->registerAction(cameraViewFromYAction->text(), cameraViewFromYAction);
91 QPointer<QAction> cameraViewFromNegYAction(
new OverrideAction(
"Scene: Camera view from negative Y",
this));
92 this->addAction(cameraViewFromNegYAction);
93 connect(cameraViewFromNegYAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromNegY()));
94 shortcutController->registerAction(cameraViewFromNegYAction->text(), cameraViewFromNegYAction);
97 QPointer<QAction> cameraViewFromZAction(
new OverrideAction(
"Scene: Camera view from Z",
this));
98 this->addAction(cameraViewFromZAction);
99 connect(cameraViewFromZAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromZ()));
100 shortcutController->registerAction(cameraViewFromZAction->text(), cameraViewFromZAction);
103 QPointer<QAction> cameraViewFromNegZAction(
new OverrideAction(
"Scene: Camera view from negative Z",
this));
104 this->addAction(cameraViewFromNegZAction);
105 connect(cameraViewFromNegZAction, SIGNAL(triggered()),
this, SLOT(
cameraViewFromNegZ()));
106 shortcutController->registerAction(cameraViewFromNegZAction->text(), cameraViewFromNegZAction);
109 QPointer<QAction> selectToggleAllAction(
new OverrideAction(
"Scene: Select all or deselect all",
this));
110 this->addAction(selectToggleAllAction);
111 connect(selectToggleAllAction, SIGNAL(triggered()),
this, SLOT(
selectToggleAll()));
112 shortcutController->registerAction(selectToggleAllAction->text(), selectToggleAllAction);
115 QPointer<QAction> copyAction(
new OverrideAction(
"Scene: Copy selection",
this));
116 this->addAction(copyAction);
117 connect(copyAction, SIGNAL(triggered()),
this, SLOT(
copy()));
118 shortcutController->registerAction(copyAction->text(), copyAction);
121 QPointer<QAction> pasteAction(
new OverrideAction(
"Scene: Paste selection",
this));
122 this->addAction(pasteAction);
123 connect(pasteAction, SIGNAL(triggered()),
this, SLOT(
paste()));
124 shortcutController->registerAction(pasteAction->text(), pasteAction);
127 QPointer<QAction> duplicateAction(
new OverrideAction(
"Scene: Duplicate selection",
this));
128 this->addAction(duplicateAction);
129 connect(duplicateAction, SIGNAL(triggered()),
this, SLOT(
duplicate()));
130 shortcutController->registerAction(duplicateAction->text(), duplicateAction);
133 QPointer<QAction> resetRotationAction(
new OverrideAction(
"Scene: Reset rotation",
this));
134 this->addAction(resetRotationAction);
135 connect(resetRotationAction, SIGNAL(triggered()),
this, SLOT(
resetRotation()));
136 shortcutController->registerAction(resetRotationAction->text(), resetRotationAction);
139 QPointer<QAction> resetTranslationAction(
new OverrideAction(
"Scene: Reset translation",
this));
140 this->addAction(resetTranslationAction);
141 connect(resetTranslationAction, SIGNAL(triggered()),
this, SLOT(
resetTranslation()));
142 shortcutController->registerAction(resetTranslationAction->text(), resetTranslationAction);
151 viewer->setSceneGraph(mainController->getScene()->registerCamera(camera));
154 camera->position.setValue(SbVec3f(10, -10, 5));
155 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
160 viewer->redrawOnSelectionChange(mainController->getScene()->selectionRootNode);
165 setAcceptDrops(
true);
167 connect(mainController.get(), SIGNAL(reloadScene()),
this, SLOT(cameraViewAll()));
168 connect(mainController.get(), SIGNAL(minimapClicked()),
this, SLOT(cameraViewFromZ()));
175 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
181 controller->getScene(), sceneobject->getObjectId(),
182 sceneobject->getRotation(), SbRotation(SbVec3f(0, 0, 1), 0),
183 sceneobject->getTranslation(), sceneobject->getTranslation()));
185 operations->push_back(operation);
196 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
202 controller->getScene(), sceneobject->getObjectId(),
203 sceneobject->getRotation(), sceneobject->getRotation(),
204 sceneobject->getTranslation(), SbVec3f(0, 0, 0)));
206 operations->push_back(operation);
223 sceneobject->getClassId(), sceneobject->getCollection(),
224 sceneobject->getTranslation(), sceneobject->getRotation()));
226 copyBuffer->push_back(addOperation);
233 if (copyBuffer->size() != 0)
237 std::shared_ptr<std::vector<controller::OperationPtr>> operations(
new std::vector<controller::OperationPtr>());
243 operations->push_back(deselect);
247 for (
auto it = copyBuffer->begin(); it != copyBuffer->end(); ++it)
250 operations->push_back(add);
252 operations->push_back(select);
264 std::shared_ptr<std::vector<controller::OperationPtr>> operations(
new std::vector<controller::OperationPtr>());
269 operations->push_back(deselect);
272 object->getClassId(), object->getCollection(),
273 object->getTranslation(), object->getRotation()));
274 operations->push_back(add);
276 operations->push_back(select);
287 controller->getScene()->makeCameraViewAll(camera, viewer->getViewportRegion());
294 camera->position.setValue(1, 0, 0);
296 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
299 this->cameraViewAll();
305 camera->position.setValue(-1, 0, 0);
307 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
310 this->cameraViewAll();
316 camera->position.setValue(0, 1, 0);
318 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
321 this->cameraViewAll();
327 camera->position.setValue(0, -1, 0);
329 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
332 this->cameraViewAll();
338 camera->position.setValue(0, 0, 1);
340 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 1, 0));
343 this->cameraViewAll();
349 camera->position.setValue(0, 0, -1);
351 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 1, 0));
354 this->cameraViewAll();
362 bool allObjectsAreSelected =
true;
366 if (!
controller->getScene()->getSelectionManager()->isSelected(
object))
368 allObjectsAreSelected =
false;
374 std::shared_ptr<std::vector<controller::OperationPtr>> operations(
new std::vector<controller::OperationPtr>());
376 if (allObjectsAreSelected)
382 operations->push_back(deselect);
390 if (!
controller->getScene()->getSelectionManager()->isSelected(
object))
393 operations->push_back(select);
414 event->acceptProposedAction();
424 if (!event->mimeData()->hasFormat(
"application/vnd.text.list"))
431 QByteArray encodedData =
event->mimeData()->data(
"application/vnd.text.list");
432 QDataStream stream(&encodedData, QIODevice::ReadOnly);
434 std::shared_ptr<std::vector<controller::OperationPtr>> operations(
new std::vector<controller::OperationPtr>());
440 operations->push_back(deselect);
444 while (!stream.atEnd())
446 QString collection, objectType;
447 stream >> collection;
448 stream >> objectType;
451 SoCamera* pCamera = viewer->getCamera();
452 float aspect = viewer->getViewportRegion().getViewportAspectRatio();
453 SbViewVolume vvol = pCamera->getViewVolume(aspect);
457 vvol.scale(1 / aspect);
460 SbPlane ground(SbVec3f(0, 0, 1), SbVec3f(0, 0, 0));
461 SbVec2s clickPoint((
short)event->pos().x(), (
short)(this->height() - event->pos().y()));
462 SbVec2f clickPointNormalized(1.0f * event->pos().x() / this->width(), 1.0f - 1.0f * event->pos().y() / this->height());
465 SbVec3f insertPosition;
467 vvol.projectPointToLine(clickPointNormalized, line);
468 SbVec3f pointOnCameraPlane;
469 vvol.getPlane(0.0).intersect(line, pointOnCameraPlane);
470 ground.intersect(line, insertPosition);
472 if (pointOnCameraPlane.getValue()[2] > 0)
474 SoRayPickAction rp(viewer->getViewportRegion());
475 rp.setPickAll(
false);
476 rp.setPoint(clickPoint);
477 rp.apply(viewer->getSceneGraph());
478 SoPickedPoint* picked = rp.getPickedPoint();
482 insertPosition = picked->getPoint();
487 SbRotation insertRotation(SbVec3f(1, 0, 0), 0);
491 operations->push_back(add);
493 operations->push_back(select);