Skip to content

Commit

Permalink
settings dialog for fmu-based visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Jan 10, 2017
1 parent 87791ed commit f026f3d
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 76 deletions.
60 changes: 11 additions & 49 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Expand Up @@ -50,7 +50,6 @@
#include "Visualizer.h"
#include "VisualizerMAT.h"
#include "VisualizerCSV.h"
#include "VisualizerFMU.h"

/*!
* \class AbstractAnimationWindow
Expand Down Expand Up @@ -149,42 +148,6 @@ void AbstractAnimationWindow::openAnimationFile(QString fileName)
}
}

/*!
* \brief AbstractAnimationWindow::openmpFMUSettingsDialog
* opens a dialog to set the settings for the FMU visualization
*/
void AbstractAnimationWindow::openFMUSettingsDialog()
{
//create dialog
mpFMUSettingsDialog = new QDialog(this);
mpFMUSettingsDialog->setWindowTitle("FMU settings");
mpFMUSettingsDialog->setWindowIcon(QIcon(":/Resources/icons/animation.svg"));
//the layouts
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *simulationLayout = new QHBoxLayout;
QVBoxLayout *leftSimLayout = new QVBoxLayout;
QVBoxLayout *rightSimLayout = new QVBoxLayout;
//the widgets
QLabel *simulationLabel = new QLabel(tr("Simulation settings"));
QPushButton *okButton = new QPushButton(tr("OK"));
//solver settings
QLabel *solverLabel = new QLabel(tr("solver"));
QComboBox *solverComboBox = new QComboBox(mpFMUSettingsDialog);
solverComboBox->addItem(QString("euler forward"));
//assemble
mainLayout->addWidget(simulationLabel);
mainLayout->addLayout(simulationLayout);
simulationLayout->addLayout(leftSimLayout);
simulationLayout->addLayout(rightSimLayout);
leftSimLayout->addWidget(solverLabel);
rightSimLayout->addWidget(solverComboBox);
mainLayout->addWidget(okButton);
mpFMUSettingsDialog->setLayout(mainLayout);
//connections
connect(okButton, SIGNAL(clicked()),this, SLOT(saveSimSettings()));
mpFMUSettingsDialog->show();
}

void AbstractAnimationWindow::createActions()
{
// perspective drop down
Expand Down Expand Up @@ -252,6 +215,15 @@ QWidget* AbstractAnimationWindow::setupViewWidget()
return gw->getGLWidget();
}

/*!
* \brief AbstractAnimationWindow::openFMUSettingsDialog
* opens a dialog to set the settings for the FMU visualization
*/
void AbstractAnimationWindow::openFMUSettingsDialog(VisualizerFMU* fmuVisualizer)
{
mpFMUSettingsDialog = new FMUSettingsWindow(this, fmuVisualizer);
}

/*!
* \brief AbstractAnimationWindow::loadVisualization
* loads the data and the xml scene description
Expand All @@ -277,6 +249,7 @@ void AbstractAnimationWindow::loadVisualization()
mpVisualizer = new VisualizerCSV(mFileName, mPathName);
} else if (visType == VisType::FMU) {
mpVisualizer = new VisualizerFMU(mFileName, mPathName);
openFMUSettingsDialog(dynamic_cast <VisualizerFMU*>(mpVisualizer));
} else {
QString msg = tr("Could not init %1 %2.").arg(QString(mPathName.c_str())).arg(QString(mFileName.c_str()));
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg, Helper::scriptingKind,
Expand All @@ -296,10 +269,6 @@ void AbstractAnimationWindow::loadVisualization()
//add scene for the chosen visualization
mpSceneView->setSceneData(mpVisualizer->getOMVisScene()->getScene().getRootNode());
}
//FMU settings dialog
if (visType == VisType::FMU) {
//openFMUSettingsDialog();
}
//add window title
this->setWindowTitle(QString::fromStdString(mFileName));
//jump to xy-view
Expand Down Expand Up @@ -586,11 +555,4 @@ void AbstractAnimationWindow::rotateCameraRight()
mpSceneView->getCameraManipulator()->setByMatrix(mat*rotMatrix);
}

/*!
* \brief AbstractAnimationWindow::saveSimSettings
*/
void AbstractAnimationWindow::saveSimSettings()
{
std::cout<<"save simulation settings"<<std::endl;
mpFMUSettingsDialog->close();
}

7 changes: 5 additions & 2 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h
Expand Up @@ -43,6 +43,9 @@
#include <QComboBox>
#include <QTimer>

#include "FMUSettingsWindow.h"


class VisualizerAbstract;
class Label;

Expand Down Expand Up @@ -83,14 +86,15 @@ class AbstractAnimationWindow : public QMainWindow, public osgViewer::CompositeV
QComboBox *mpPerspectiveDropDownBox;
QAction *mpRotateCameraLeftAction;
QAction *mpRotateCameraRightAction;
QDialog *mpFMUSettingsDialog;
FMUSettingsWindow *mpFMUSettingsDialog;

void resetCamera();
void cameraPositionIsometric();
void cameraPositionSide();
void cameraPositionFront();
void cameraPositionTop();
double computeDistanceToOrigin();
void openFMUSettingsDialog(VisualizerFMU* fmuVisualizer);
public slots:
void renderFrame();
void updateScene();
Expand All @@ -104,7 +108,6 @@ public slots:
void setPerspective(int value);
void rotateCameraLeft();
void rotateCameraRight();
void saveSimSettings();
};

#endif // ABSTRACTANIMATIONWINDOW_H
3 changes: 0 additions & 3 deletions OMEdit/OMEditGUI/Animation/ExtraShapes.cpp
Expand Up @@ -682,9 +682,6 @@ DXFile::DXFile(std::string filename)
(*facette)[1] = (i * 4) + 1;
(*facette)[2] = (i * 4) + 2;
this->addPrimitiveSet(facette);

//normal calculation
osg::Vec3f normal = faces[i].calcNormals();
}
else
{
Expand Down
154 changes: 154 additions & 0 deletions OMEdit/OMEditGUI/Animation/FMUSettingsWindow.cpp
@@ -0,0 +1,154 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Volker Waurich <volker.waurich@tu-dresden.de>
*/

#include "FMUSettingsWindow.h"



/*!
* \class FMUSettingsWindow
* \brief widget for FMu-simulation settings.
*/

FMUSettingsWindow::FMUSettingsWindow(QWidget *pParent, VisualizerFMU* fmuVisualizer)
: QMainWindow(pParent),
fmu(fmuVisualizer),
stepSize(0.001),
renderFreq(0.1),
solver(Solver::EULER_FORWARD)
{
//create dialog
mpSettingsDialog = new QDialog;
mpSettingsDialog->setWindowTitle("Visualization settings");
mpSettingsDialog->setWindowIcon(QIcon(":/Resources/icons/animation.svg"));
//the layouts
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *buttonLayout = new QHBoxLayout;
QHBoxLayout *visualizationLayout = new QHBoxLayout;
QVBoxLayout *visLeftLayout = new QVBoxLayout;
QVBoxLayout *visRightLayout = new QVBoxLayout;
QHBoxLayout *simulationLayout = new QHBoxLayout;
QVBoxLayout *simLeftLayout = new QVBoxLayout;
QVBoxLayout *simRightLayout = new QVBoxLayout;
//the widgets
QLabel *visualizationHeading = new QLabel(tr("Visualization Settings"));
QLabel *freqLabel = new QLabel(tr("Render Frequency [s]"));
mpRenderFreqLineEdit = new QLineEdit(QString::number(renderFreq));
mpOkButton = new QPushButton(tr("OK"));
//solver settings
QLabel *simulationHeading = new QLabel(tr("FMU-Simulation Settings"));
QLabel *solverLabel = new QLabel(tr("solver"));
mpSolverComboBox = new QComboBox(mpSettingsDialog);
mpSolverComboBox->addItem(QString("explicit euler"));
QLabel *stepsizeLabel = new QLabel(tr("step size [s]"));
mpStepsizeLineEdit = new QLineEdit(QString::number(stepSize));
QLabel *handleEventsLabel = new QLabel(tr("Process Events in FMU"));
mpHandleEventsCheck = new QCheckBox();
mpHandleEventsCheck->setCheckState(Qt::Checked);
//assemble
mpSettingsDialog->setLayout(mainLayout);
//mainLayout->addWidget(visualizationHeading);
//mainLayout->addLayout(visualizationLayout);
visualizationLayout->addLayout(visLeftLayout);
visualizationLayout->addLayout(visRightLayout);
visLeftLayout->addWidget(freqLabel);
visRightLayout->addWidget(mpRenderFreqLineEdit);
mainLayout->addWidget(simulationHeading);
mainLayout->addLayout(simulationLayout);
simulationLayout->addLayout(simLeftLayout);
simulationLayout->addLayout(simRightLayout);

simLeftLayout->addWidget(solverLabel);
simRightLayout->addWidget(mpSolverComboBox);
simLeftLayout->addWidget(stepsizeLabel);
simRightLayout->addWidget(mpStepsizeLineEdit);
simLeftLayout->addWidget(handleEventsLabel);
simRightLayout->addWidget(mpHandleEventsCheck);

mainLayout->addLayout(buttonLayout);
buttonLayout->addWidget(mpOkButton);

//connections
QObject::connect(mpOkButton, SIGNAL(clicked()), this,SLOT(saveSimSettings()));

mpSettingsDialog->show();
}

FMUSettingsWindow::~FMUSettingsWindow()
{
if (mpRenderFreqLineEdit)
delete mpRenderFreqLineEdit;
if (mpStepsizeLineEdit)
delete mpStepsizeLineEdit;
if (mpHandleEventsCheck)
delete mpHandleEventsCheck;
if (mpSolverComboBox)
delete mpSolverComboBox;
if (mpOkButton)
delete mpOkButton;
}

/*!
* \brief FMUSettingsWindow::saveSimSettings
*/
void FMUSettingsWindow::saveSimSettings()
{
//step size and render freq
bool isFloat = true;
double stepSize = mpStepsizeLineEdit->text().toFloat(&isFloat);
if (!isFloat) {
stepSize = 0.0001;
};
double renderFreq = mpRenderFreqLineEdit->text().toFloat(&isFloat);
if (!isFloat) {
stepSize = 0.1;
};

//handle events
bool handleEvents = true;
if (!mpHandleEventsCheck->isChecked()){
handleEvents = false;
};

//solver
QString s = mpSolverComboBox->currentText();
if (0 == s.compare(QString("explicit euler")))
{
Solver solver = Solver::EULER_FORWARD;
}

//store in FMU simulator
fmu->setSimulationSettings(stepSize, solver, handleEvents);
mpSettingsDialog->close();
}
73 changes: 73 additions & 0 deletions OMEdit/OMEditGUI/Animation/FMUSettingsWindow.h
@@ -0,0 +1,73 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Volker Waurich <volker.waurich@tu-dresden.de>
*/


#ifndef FMU_SETTINGS_WINDOW_H
#define FMU_SETTINGS_WINDOW_H

#include "VisualizerFMU.h"

#include <QMainWindow>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
#include <QLayout>
#include <QLabel>
#include <QPushButton>
#include <QDialog>

class FMUSettingsWindow : public QMainWindow
{
Q_OBJECT
public:
FMUSettingsWindow(QWidget *pParent, VisualizerFMU* fmuVisualizer);
~FMUSettingsWindow();
private:
VisualizerFMU* fmu;
double stepSize;
double renderFreq;
Solver solver;
bool handleEvents;
QDialog* mpSettingsDialog;
QLineEdit* mpRenderFreqLineEdit;
QLineEdit* mpStepsizeLineEdit;
QCheckBox* mpHandleEventsCheck;
QComboBox* mpSolverComboBox;
QPushButton* mpOkButton;
public slots:
void saveSimSettings();
};


#endif // end FMU_SETTINGS_WINDOW_H

0 comments on commit f026f3d

Please sign in to comment.