Skip to content

Commit 09c2920

Browse files
vwaurichadeas31
authored andcommitted
- some nice perspective actions
1 parent cf7c958 commit 09c2920

File tree

8 files changed

+116
-4
lines changed

8 files changed

+116
-4
lines changed

OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
6060
mpAnimationPlayAction(nullptr),
6161
mpAnimationPauseAction(nullptr)
6262
{
63+
// to distinguish this widget as a subwindow among the plotwindows
6364
this->setObjectName(QString("animationWidget"));
65+
66+
// the osg threading model
6467
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
68+
6569
//the viewer widget
6670
osg::ref_ptr<osg::Node> rootNode = osgDB::readRefNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
6771
mpViewerWidget = setupViewWidget(rootNode);
@@ -71,12 +75,13 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
7175
//mpViewerWidget->setWindowState(Qt::WindowMaximized);
7276
mpViewerWidget->setBaseSize(QSize(2000,1000));
7377
//mpViewerWidget->move(100,100);
74-
// do a scene update at every tick
78+
79+
// let timer do a scene update at every tick
7580
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
7681
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
7782
mpUpdateTimer->start(100);
7883

79-
// animation action
84+
// actions and widgets for the toolbar
8085
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/openFile.png"), Helper::animationChooseFile, this);
8186
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
8287
mpAnimationChooseFileAction->setEnabled(true);
@@ -89,15 +94,19 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
8994
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.png"), Helper::animationPause, this);
9095
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
9196
mpAnimationPauseAction->setEnabled(true);
92-
9397
mpAnimationSlider = new QSlider(Qt::Horizontal);
94-
//mpAnimationSlider->setFixedWidth(200);
9598
mpAnimationSlider->setMinimum(0);
9699
mpAnimationSlider->setMaximum(100);
97100
mpAnimationSlider->setSliderPosition(50);
98101
mpAnimationTimeLabel = new QLabel();
99102
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::fromStdString("0.000")));
103+
mpPerspectiveDropDownBox = new QComboBox(this);
104+
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective0.png"), QString("to home position"));
105+
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective2.png"),QString("normal to x-y plane"));
106+
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective1.png"),QString("normal to y-z plane"));
107+
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective3.png"),QString("normal to x-z plane"));
100108

109+
//assemble the animation toolbar
101110
mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
102111
mpAnimationToolBar->addSeparator();
103112
mpAnimationToolBar->addAction(mpAnimationInitializeAction);
@@ -108,17 +117,22 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
108117
mpAnimationToolBar->addSeparator();
109118
mpAnimationToolBar->addWidget(mpAnimationSlider);
110119
mpAnimationToolBar->addWidget(mpAnimationTimeLabel);
120+
mpAnimationToolBar->addWidget(mpPerspectiveDropDownBox);
121+
111122
//connect(mpAnimationSlider, SIGNAL(sliderMoved(int)),mpAnimationWindowContainer, SLOT(sliderSetTimeSlotFunction(int)));
112123
addToolBar(Qt::TopToolBarArea,mpAnimationToolBar);
113124

114125
mpViewerWidget->setParent(this);//important!!
115126
//mpViewerWidget->setParent(topWidget);//no influence
116127
//setCentralWidget(topWidget);//no influence
117128

129+
//connections
118130
connect(mpAnimationChooseFileAction, SIGNAL(triggered()),this, SLOT(chooseAnimationFileSlotFunction()));
119131
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
120132
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
121133
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
134+
connect(mpPerspectiveDropDownBox, SIGNAL(activated(int)), this, SLOT(setPerspective(int)));
135+
122136
}
123137

124138
/*!
@@ -327,3 +341,91 @@ void AnimationWindowContainer::setFileName(std::string fileName){
327341
}
328342

329343

344+
/*!
345+
* \brief AnimationWindowContainer::cameraPositionXY
346+
* sets the camera position to XY
347+
*/
348+
void AnimationWindowContainer::cameraPositionXY()
349+
{
350+
resetCamera();
351+
//the new orientation
352+
osg::Matrix3 newOrient = osg::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1);
353+
354+
osg::ref_ptr<osgGA::CameraManipulator> manipulator = mpSceneView->getCameraManipulator();
355+
osg::Matrixd mat = manipulator->getMatrix();
356+
357+
//assemble
358+
mat = osg::Matrixd(newOrient(0, 0), newOrient(0, 1), newOrient(0, 2), 0,
359+
newOrient(1, 0), newOrient(1, 1), newOrient(1, 2), 0,
360+
newOrient(2, 0), newOrient(2, 1), newOrient(2, 2), 0,
361+
abs(mat(3, 0)), abs(mat(3, 2)), abs(mat(3, 1)), 1);
362+
manipulator->setByMatrix(mat);
363+
}
364+
365+
/*!
366+
* \brief AnimationWindowContainer::cameraPositionYZ
367+
* sets the camera position to YZ
368+
*/
369+
void AnimationWindowContainer::cameraPositionYZ()
370+
{
371+
//to get the correct distance of the bodies, reset to home position and use the values of this camera position
372+
resetCamera();
373+
//the new orientation
374+
osg::Matrix3 newOrient = osg::Matrix3(0, 1, 0, 0, 0, 1, 1, 0, 0);
375+
376+
osg::ref_ptr<osgGA::CameraManipulator> manipulator = mpSceneView->getCameraManipulator();
377+
osg::Matrixd mat = manipulator->getMatrix();
378+
379+
//assemble
380+
mat = osg::Matrixd(newOrient(0, 0), newOrient(0, 1), newOrient(0, 2), 0,
381+
newOrient(1, 0), newOrient(1, 1), newOrient(1, 2), 0,
382+
newOrient(2, 0), newOrient(2, 1), newOrient(2, 2), 0,
383+
abs(mat(3, 1)), abs(mat(3, 2)), abs(mat(3, 0)), 1);
384+
manipulator->setByMatrix(mat);
385+
}
386+
387+
/*!
388+
* \brief AnimationWindowContainer::cameraPositionXZ
389+
* sets the camera position to XZ
390+
*/
391+
void AnimationWindowContainer::cameraPositionXZ()
392+
{
393+
//to get the correct distance of the bodies, reset to home position and use the values of this camera position
394+
resetCamera();
395+
//the new orientation
396+
osg::Matrix3 newOrient = osg::Matrix3(1, 0, 0, 0, 0, 1, 0, -1, 0);
397+
398+
osg::ref_ptr<osgGA::CameraManipulator> manipulator = mpSceneView->getCameraManipulator();
399+
osg::Matrixd mat = manipulator->getMatrix();
400+
401+
//assemble
402+
mat = osg::Matrixd(newOrient(0, 0), newOrient(0, 1), newOrient(0, 2), 0,
403+
newOrient(1, 0), newOrient(1, 1), newOrient(1, 2), 0,
404+
newOrient(2, 0), newOrient(2, 1), newOrient(2, 2), 0,
405+
abs(mat(3, 0)), -abs(mat(3, 1)), abs(mat(3, 2)), 1);
406+
manipulator->setByMatrix(mat);
407+
}
408+
409+
/*!
410+
* \brief AnimationWindowContainer::resetCamera
411+
* resets the camera position
412+
*/
413+
void AnimationWindowContainer::resetCamera()
414+
{
415+
mpSceneView->home();
416+
}
417+
418+
/*!
419+
* \brief AnimationWindowContainer::setPerspective
420+
* gets the identifier for the chosen perspective and calls the functions
421+
*/
422+
void AnimationWindowContainer::setPerspective(int value)
423+
{
424+
switch(value) {
425+
case(0): resetCamera();break;
426+
case(1): cameraPositionXY();break;
427+
case(2): cameraPositionYZ();break;
428+
case(3): cameraPositionXZ();break;
429+
}
430+
431+
}

OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
7878
void renderSlotFunction();
7979
void chooseAnimationFileSlotFunction();
8080
void updateSceneFunction();
81+
void resetCamera();
82+
void cameraPositionXY();
83+
void cameraPositionXZ();
84+
void cameraPositionYZ();
85+
void setPerspective(int value);
8186
private:
8287
//to be animated
8388
std::string mPathName;
@@ -93,6 +98,7 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
9398
QWidget* topWidget;
9499
QSlider* mpAnimationSlider;
95100
QLabel *mpAnimationTimeLabel;
101+
QComboBox *mpPerspectiveDropDownBox;
96102
//actions
97103
QAction *mpAnimationChooseFileAction;
98104
QAction *mpAnimationInitializeAction;
8.89 KB
Loading
8.46 KB
Loading
8.23 KB
Loading
8.13 KB
Loading
-3.56 KB
Loading

OMEdit/OMEditGUI/resource_omedit.qrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,9 @@
143143
<file>Resources/icons/play.png</file>
144144
<file>Resources/icons/pause.png</file>
145145
<file>Resources/icons/initialize.png</file>
146+
<file>Resources/icons/perspective0.png</file>
147+
<file>Resources/icons/perspective1.png</file>
148+
<file>Resources/icons/perspective2.png</file>
149+
<file>Resources/icons/perspective3.png</file>
146150
</qresource>
147151
</RCC>

0 commit comments

Comments
 (0)