Skip to content

Commit 0e61377

Browse files
committed
- added simulate with visualization button
1 parent 24e90f4 commit 0e61377

File tree

11 files changed

+120
-38
lines changed

11 files changed

+120
-38
lines changed

OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,9 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
111111
//connect(mpAnimationSlider, SIGNAL(sliderMoved(int)),mpAnimationWindowContainer, SLOT(sliderSetTimeSlotFunction(int)));
112112
addToolBar(Qt::TopToolBarArea,mpAnimationToolBar);
113113

114-
115-
116-
//QVBoxLayout* mainLayout = new QVBoxLayout();
117-
//mainLayout->addWidget(mpViewerWidget);
118-
//QWidget* topWidget = new QWidget();
119-
//topWidget->setLayout(mainLayout);
120114
mpViewerWidget->setParent(this);//important!!
121-
122-
//mpViewerWidget->setParent(topWidget);//kein Einfluss
123-
124-
//setCentralWidget(topWidget); //kein Einfluss
115+
//mpViewerWidget->setParent(topWidget);//no influence
116+
//setCentralWidget(topWidget);//no influence
125117

126118
connect(mpAnimationChooseFileAction, SIGNAL(triggered()),this, SLOT(chooseAnimationFileSlotFunction()));
127119
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
@@ -143,7 +135,6 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
143135
traits->windowDecoration = false;
144136
traits->x = 0;
145137
traits->y = 0;
146-
147138
traits->width = 2000;
148139
traits->height = 1000;
149140
traits->doubleBuffer = true;
@@ -160,7 +151,8 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
160151
osg::ref_ptr<osg::Camera> camera = mpSceneView->getCamera();
161152
camera->setGraphicsContext(gw);
162153
camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));
163-
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
154+
//camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
155+
camera->setViewport(new osg::Viewport(0, 0, 2000, 1000));
164156
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width/2) / static_cast<double>(traits->height/2), 1.0f, 10000.0f);
165157
mpSceneView->setSceneData(rootNode);
166158
mpSceneView->addEventHandler(new osgViewer::StatsHandler());
@@ -185,24 +177,29 @@ void AnimationWindowContainer::loadVisualization(){
185177
std::cout<<"unknown visualization type. "<<std::endl;
186178

187179
//init visualizer
188-
if (visType == VisType::MAT){
180+
if (visType == VisType::MAT)
181+
{
189182
mpVisualizer = new VisualizerMAT(mFileName, mPathName);
190183
}
191-
else{
184+
else
185+
{
192186
std::cout<<"could not init "<<mPathName<<mFileName<<std::endl;
193187
}
194188

195189
//load the XML File, build osgTree, get initial values for the shapes
196190
bool xmlExists = checkForXMLFile(mFileName, mPathName);
197-
if (!xmlExists){
191+
if (!xmlExists)
192+
{
198193
std::cout<<"Could not find the visual XML file "<<assembleXMLFileName(mFileName, mPathName)<<std::endl;
199194
}
200-
mpVisualizer->initData();
201-
mpVisualizer->setUpScene();
202-
mpVisualizer->initVisualization();
203-
204-
//add scene for the chosen visualization
205-
mpSceneView->setSceneData(mpVisualizer->getOMVisScene()->getScene().getRootNode());
195+
else
196+
{
197+
mpVisualizer->initData();
198+
mpVisualizer->setUpScene();
199+
mpVisualizer->initVisualization();
200+
//add scene for the chosen visualization
201+
mpSceneView->setSceneData(mpVisualizer->getOMVisScene()->getScene().getRootNode());
202+
}
206203
}
207204

208205

@@ -217,7 +214,7 @@ void AnimationWindowContainer::chooseAnimationFileSlotFunction(){
217214
std::size_t pos = file.find_last_of("/\\");
218215
mPathName = file.substr(0, pos + 1);
219216
mFileName = file.substr(pos + 1, file.length());
220-
//std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
217+
std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
221218
loadVisualization();
222219
}
223220
else
@@ -312,3 +309,21 @@ double AnimationWindowContainer::getVisTime(){
312309
return mpVisualizer->getTimeManager()->getVisTime();
313310
}
314311

312+
/*!
313+
* \brief AnimationWindowContainer::setPathName
314+
* sets mpPathName
315+
*/
316+
void AnimationWindowContainer::setPathName(std::string pathName){
317+
mPathName = pathName;
318+
}
319+
320+
321+
/*!
322+
* \brief AnimationWindowContainer::setFileName
323+
* sets mpFileName
324+
*/
325+
void AnimationWindowContainer::setFileName(std::string fileName){
326+
mFileName = fileName;
327+
}
328+
329+

OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
6868
void loadVisualization();
6969
double getTimeFraction();
7070
double getVisTime();
71+
void setPathName(std::string name);
72+
void setFileName(std::string name);
7173
public slots:
7274
void sliderSetTimeSlotFunction(int value);
7375
void playSlotFunction();
@@ -96,11 +98,6 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
9698
QAction *mpAnimationInitializeAction;
9799
QAction *mpAnimationPlayAction;
98100
QAction *mpAnimationPauseAction;
99-
100-
//QVBoxLayout* mpMainLayout;
101-
//QHBoxLayout* mpButtonsLayout;
102-
////QVBoxLayout* mpMainRowLayout;
103-
104101
};
105102

106103
#endif // ANIMATIONWINDOWCONTAINER_H

OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,28 @@ void MainWindow::simulateModel()
16131613
}
16141614
}
16151615

1616+
/*!
1617+
Simualtes the model directly with animation flag.
1618+
*/
1619+
//!
1620+
void MainWindow::simulateModelWithAnimation()
1621+
{
1622+
mpOMCProxy->setCommandLineOptions("+d=visxml +n=1");
1623+
1624+
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
1625+
if (pModelWidget) {
1626+
simulate(pModelWidget->getLibraryTreeItem());
1627+
}
1628+
1629+
//QDir dir = QDir(QString("."));
1630+
//std::cout<<"SIMULATED WITH ANIMATION "<<dir.absolutePath().toStdString().append("/").append(pModelWidget->getLibraryTreeItem()->getNameStructure().toStdString()).append("_visual.xml")<<std::endl;
1631+
//mpPlotWindowContainer->addAnimationWindow();
1632+
//AnimationWindowContainer* animation = mpPlotWindowContainer->getCurrentAnimationWindow();
1633+
//animation->setPathName(dir.absolutePath().toStdString().append("/"));
1634+
//animation->setFileName(pModelWidget->getLibraryTreeItem()->getNameStructure().toStdString().append("_res.mat"));
1635+
//animation->loadVisualization();
1636+
}
1637+
16161638
/*!
16171639
Simualtes the model with transformational debugger
16181640
*/
@@ -2499,7 +2521,7 @@ void MainWindow::createActions()
24992521
mpSimulateWithAnimationAction = new QAction(QIcon(":/Resources/icons/simulate-animation.png"), Helper::simulateWithAnimation, this);
25002522
mpSimulateWithAnimationAction->setStatusTip(Helper::simulateWithAnimationTip);
25012523
mpSimulateWithAnimationAction->setEnabled(false);
2502-
//connect(mpSimulateWithAnimationAction, SIGNAL(triggered()), SLOT(simulateModelWithAlgorithmicDebugger()));
2524+
connect(mpSimulateWithAnimationAction, SIGNAL(triggered()), SLOT(simulateModelWithAnimation()));
25032525
// simulation setup action
25042526
mpSimulationSetupAction = new QAction(QIcon(":/Resources/icons/simulation-center.svg"), Helper::simulationSetup, this);
25052527
mpSimulationSetupAction->setStatusTip(Helper::simulationSetupTip);
@@ -3017,7 +3039,7 @@ void MainWindow::switchToPlottingPerspective()
30173039
}
30183040
mpCentralStackedWidget->setCurrentWidget(mpPlotWindowContainer);
30193041
int i = 0;
3020-
/*
3042+
30213043
foreach (QMdiSubWindow *pWindow, mpPlotWindowContainer->subWindowList()) {
30223044
// sanity check
30233045
if (mPlotWindowsStatesList.size() > i && mPlotWindowsGeometriesList.size() > i) {
@@ -3030,7 +3052,6 @@ void MainWindow::switchToPlottingPerspective()
30303052
mPlotWindowsStatesList.clear();
30313053
mPlotWindowsGeometriesList.clear();
30323054
mpModelWidgetContainer->currentModelWidgetChanged(0);
3033-
*/
30343055
mpUndoAction->setEnabled(false);
30353056
mpRedoAction->setEnabled(false);
30363057
mpModelSwitcherToolButton->setEnabled(false);
@@ -3042,12 +3063,10 @@ void MainWindow::switchToPlottingPerspective()
30423063
mpPlotToolBar->setEnabled(true);
30433064
// In case user has tabbed the dock widgets then make VariablesWidget active.
30443065
QList<QDockWidget*> tabifiedDockWidgetsList = tabifiedDockWidgets(mpVariablesDockWidget);
3045-
/*
30463066
if (tabifiedDockWidgetsList.size() > 0) {
30473067
tabifyDockWidget(tabifiedDockWidgetsList.at(0), mpVariablesDockWidget);
30483068
}
30493069
mpVariablesDockWidget->show();
3050-
*/
30513070
mpStackFramesDockWidget->hide();
30523071
mpBreakpointsDockWidget->hide();
30533072
mpLocalsDockWidget->hide();

OMEdit/OMEditGUI/MainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <QItemDelegate>
4747
#include <QDomDocument>
4848
#else
49+
#include <QDir>
4950
#include <QtGui>
5051
#include <QtWebKit>
5152
#include <QtCore>
@@ -187,6 +188,7 @@ class MainWindow : public QMainWindow
187188
void simulate(LibraryTreeItem *pLibraryTreeItem);
188189
void simulateWithTransformationalDebugger(LibraryTreeItem *pLibraryTreeItem);
189190
void simulateWithAlgorithmicDebugger(LibraryTreeItem *pLibraryTreeItem);
191+
void simulateWithAnimation(LibraryTreeItem *pLibraryTreeItem);
190192
void simulationSetup(LibraryTreeItem *pLibraryTreeItem);
191193
void instantiateModel(LibraryTreeItem *pLibraryTreeItem);
192194
void checkModel(LibraryTreeItem *pLibraryTreeItem);
@@ -406,6 +408,7 @@ public slots:
406408
void simulateModel();
407409
void simulateModelWithTransformationalDebugger();
408410
void simulateModelWithAlgorithmicDebugger();
411+
void simulateModelWithAnimation();
409412
void openSimulationDialog();
410413
void exportModelFMU();
411414
void importModelFMU();

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,10 @@ void LibraryTreeView::createActions()
25662566
mpSimulateWithAlgorithmicDebuggerAction = new QAction(QIcon(":/Resources/icons/simulate-debug.svg"), Helper::simulateWithAlgorithmicDebugger, this);
25672567
mpSimulateWithAlgorithmicDebuggerAction->setStatusTip(Helper::simulateWithAlgorithmicDebuggerTip);
25682568
connect(mpSimulateWithAlgorithmicDebuggerAction, SIGNAL(triggered()), SLOT(simulateWithAlgorithmicDebugger()));
2569+
// simulate with animation Action
2570+
mpSimulateWithAnimationAction = new QAction(QIcon(":/Resources/icons/simulate-animation.png"), Helper::simulateWithAnimation, this);
2571+
mpSimulateWithAnimationAction->setStatusTip(Helper::simulateWithAnimationTip);
2572+
connect(mpSimulateWithAnimationAction, SIGNAL(triggered()), SLOT(simulateWithAnimation()));
25692573
// simulation setup Action
25702574
mpSimulationSetupAction = new QAction(QIcon(":/Resources/icons/simulation-center.svg"), Helper::simulationSetup, this);
25712575
mpSimulationSetupAction->setStatusTip(Helper::simulationSetupTip);
@@ -2733,6 +2737,7 @@ void LibraryTreeView::showContextMenu(QPoint point)
27332737
menu.addAction(mpSimulateAction);
27342738
menu.addAction(mpSimulateWithTransformationalDebuggerAction);
27352739
menu.addAction(mpSimulateWithAlgorithmicDebuggerAction);
2740+
menu.addAction(mpSimulateWithAnimationAction);
27362741
menu.addAction(mpSimulationSetupAction);
27372742
}
27382743
/* If item is OpenModelica or part of it then don't show the duplicate menu item for it. */
@@ -2957,6 +2962,21 @@ void LibraryTreeView::simulate()
29572962
}
29582963
}
29592964

2965+
/*!
2966+
* \brief LibraryTreeView::simulate
2967+
* Simulates the selected LibraryTreeItem.
2968+
*/
2969+
void LibraryTreeView::simulateWithAnimation()
2970+
{
2971+
std::cout<<"THIS SIMULATE WITH ANIMATION"<<std::endl;
2972+
//mpOMCProxy->setCommandLineOptions("+d=visxml");
2973+
2974+
LibraryTreeItem *pLibraryTreeItem = getSelectedLibraryTreeItem();
2975+
if (pLibraryTreeItem) {
2976+
mpLibraryWidget->getMainWindow()->simulate(pLibraryTreeItem);
2977+
}
2978+
}
2979+
29602980
/*!
29612981
* \brief LibraryTreeView::simulateWithTransformationalDebugger
29622982
* Simulates the selected LibraryTreeItem with the Transformational Debugger.

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class LibraryTreeView : public QTreeView
310310
QAction *mpSimulateAction;
311311
QAction *mpSimulateWithTransformationalDebuggerAction;
312312
QAction *mpSimulateWithAlgorithmicDebuggerAction;
313+
QAction *mpSimulateWithAnimationAction;
313314
QAction *mpSimulationSetupAction;
314315
QAction *mpDuplicateClassAction;
315316
QAction *mpUnloadClassAction;
@@ -346,6 +347,7 @@ public slots:
346347
void simulate();
347348
void simulateWithTransformationalDebugger();
348349
void simulateWithAlgorithmicDebugger();
350+
void simulateWithAnimation();
349351
void simulationSetup();
350352
void duplicateClass();
351353
void unloadClass();

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
43434343
getMainWindow()->getSimulateModelAction()->setEnabled(enabled && modelica && pLibraryTreeItem->isSimulationAllowed());
43444344
getMainWindow()->getSimulateWithTransformationalDebuggerAction()->setEnabled(enabled && modelica && pLibraryTreeItem->isSimulationAllowed());
43454345
getMainWindow()->getSimulateWithAlgorithmicDebuggerAction()->setEnabled(enabled && modelica && pLibraryTreeItem->isSimulationAllowed());
4346+
getMainWindow()->getSimulateWithAnimationAction()->setEnabled(enabled && modelica && pLibraryTreeItem->isSimulationAllowed());
43464347
getMainWindow()->getSimulationSetupAction()->setEnabled(enabled && modelica && pLibraryTreeItem->isSimulationAllowed());
43474348
getMainWindow()->getInstantiateModelAction()->setEnabled(enabled && modelica);
43484349
getMainWindow()->getCheckModelAction()->setEnabled(enabled && modelica);

OMEdit/OMEditGUI/Options/OptionsDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ void OptionsDialog::saveFillStyleSettings()
995995

996996
//! Saves the Plotting section settings to omedit.ini
997997
void OptionsDialog::savePlottingSettings()
998-
{/*
998+
{
999999
// save the auto scale
10001000
mpSettings->setValue("plotting/autoScale", mpPlottingPage->getAutoScaleCheckBox()->isChecked());
10011001
// save plotting view mode
@@ -1012,7 +1012,7 @@ void OptionsDialog::savePlottingSettings()
10121012
}
10131013

10141014
mpSettings->setValue("curvestyle/pattern", mpPlottingPage->getCurvePattern());
1015-
mpSettings->setValue("curvestyle/thickness", mpPlottingPage->getCurveThickness());*/
1015+
mpSettings->setValue("curvestyle/thickness", mpPlottingPage->getCurveThickness());
10161016
}
10171017

10181018
//! Saves the Figaro section settings to omedit.ini

OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ QString PlotWindowContainer::getUniqueName(QString name, int number)
8181

8282
/*!
8383
* \brief PlotWindowContainer::getCurrentWindow
84-
* Returns the current plot window.
84+
* Returns the current plot window, if the last window is animation, return null
8585
* \return
8686
*/
8787
PlotWindow* PlotWindowContainer::getCurrentWindow()
@@ -99,6 +99,29 @@ PlotWindow* PlotWindowContainer::getCurrentWindow()
9999
}
100100
}
101101

102+
/*!
103+
* \brief PlotWindowContainer::getCurrentAnimationWindow
104+
* Returns the current animation window, if the last window is plot, return null
105+
* \return
106+
*/
107+
AnimationWindowContainer* PlotWindowContainer::getCurrentAnimationWindow()
108+
{
109+
if (subWindowList(QMdiArea::ActivationHistoryOrder).size() == 0) {
110+
return 0;
111+
}
112+
else {
113+
bool isAnimationWidget = (0 == subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget()->objectName().compare(QString("animationWidget")));
114+
std::cout<<"isAnimationWidget "<<isAnimationWidget<<std::endl;
115+
if (isAnimationWidget)
116+
{
117+
std::cout<<"this was good\n"<<std::endl;
118+
return qobject_cast<AnimationWindowContainer*>(subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget());
119+
}
120+
else
121+
return 0;
122+
}
123+
}
124+
102125
/*!
103126
* \brief PlotWindowContainer::eventFilter
104127
* \param pObject

OMEdit/OMEditGUI/Plotting/PlotWindowContainer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
#include "MainWindow.h"
3939
#include "OMPlot.h"
40-
#include "AnimationWindowContainer.h"
40+
#include "Animation/AnimationWindowContainer.h"
4141

4242
class MainWindow;
43+
class AnimationWindowContainer;
4344

4445
class PlotWindowContainer : public MdiArea
4546
{
@@ -48,6 +49,7 @@ class PlotWindowContainer : public MdiArea
4849
PlotWindowContainer(MainWindow *pParent);
4950
QString getUniqueName(QString name = QString("Plot"), int number = 1);
5051
OMPlot::PlotWindow* getCurrentWindow();
52+
AnimationWindowContainer* getCurrentAnimationWindow();
5153
bool eventFilter(QObject *pObject, QEvent *pEvent);
5254
public slots:
5355
void addAnimationWindow();

0 commit comments

Comments
 (0)