Skip to content

Commit

Permalink
- plot and animation share an mdi
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Sep 30, 2016
1 parent fa40827 commit 03c48b2
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 142 deletions.
88 changes: 45 additions & 43 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -60,45 +60,46 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
mpAnimationPlayAction(nullptr),
mpAnimationPauseAction(nullptr)
{
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
//the viewer widget
osg::ref_ptr<osg::Node> rootNode = osgDB::readRefNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
mpViewerWidget = setupViewWidget(rootNode);

//mpViewerWidget->setParent(this);
//mpViewerWidget->setWindowFlags(Qt::SubWindow);
//mpViewerWidget->setWindowState(Qt::WindowMaximized);
mpViewerWidget->setBaseSize(QSize(2000,1000));
//mpViewerWidget->move(100,100);
// do a scene update at every tick
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
mpUpdateTimer->start(100);

// animation action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/openFile.png"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
mpAnimationChooseFileAction->setEnabled(true);
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.png"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/play.png"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.png"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(true);

mpAnimationSlider = new QSlider(Qt::Horizontal);
//mpAnimationSlider->setFixedWidth(200);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(50);
mpAnimationTimeLabel = new QLabel();
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::fromStdString("0.000")));

mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
mpAnimationToolBar->addSeparator();
this->setObjectName(QString("animationWidget"));
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
//the viewer widget
osg::ref_ptr<osg::Node> rootNode = osgDB::readRefNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
mpViewerWidget = setupViewWidget(rootNode);

//mpViewerWidget->setParent(this);
//mpViewerWidget->setWindowFlags(Qt::SubWindow);
//mpViewerWidget->setWindowState(Qt::WindowMaximized);
mpViewerWidget->setBaseSize(QSize(2000,1000));
//mpViewerWidget->move(100,100);
// do a scene update at every tick
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
mpUpdateTimer->start(100);

// animation action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/openFile.png"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
mpAnimationChooseFileAction->setEnabled(true);
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.png"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/play.png"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.png"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(true);

mpAnimationSlider = new QSlider(Qt::Horizontal);
//mpAnimationSlider->setFixedWidth(200);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(50);
mpAnimationTimeLabel = new QLabel();
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::fromStdString("0.000")));

mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationInitializeAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationPlayAction);
Expand Down Expand Up @@ -126,10 +127,8 @@ AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));



}

/*!
* \brief AnimationWindowContainer::setupViewWidget
* creates the widget for the osg viewer
Expand Down Expand Up @@ -235,6 +234,10 @@ void AnimationWindowContainer::showWidgets(){
show();
}

/*!
* \brief AnimationWindowContainer::getTimeFraction
* gets the fraction of the complete simulation time to move the slider
*/
double AnimationWindowContainer::getTimeFraction(){
if (mpVisualizer==NULL)
return 0.0;
Expand Down Expand Up @@ -295,7 +298,6 @@ void AnimationWindowContainer::updateSceneFunction(){
*/
void AnimationWindowContainer::renderSlotFunction()
{
std::cout<<"render"<<std::endl;
frame();
}

Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -68,7 +68,6 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
void loadVisualization();
double getTimeFraction();
double getVisTime();

public slots:
void sliderSetTimeSlotFunction(int value);
void playSlotFunction();
Expand All @@ -93,14 +92,15 @@ class AnimationWindowContainer : public QMainWindow, public osgViewer::Composite
QSlider* mpAnimationSlider;
QLabel *mpAnimationTimeLabel;
//actions
QVBoxLayout* mainLayout;
QHBoxLayout* buttonsLayout;
QVBoxLayout* mainRowLayout;

QAction *mpAnimationChooseFileAction;
QAction *mpAnimationInitializeAction;
QAction *mpAnimationPlayAction;
QAction *mpAnimationPauseAction;

//QVBoxLayout* mpMainLayout;
//QHBoxLayout* mpButtonsLayout;
////QVBoxLayout* mpMainRowLayout;

};

#endif // ANIMATIONWINDOWCONTAINER_H
5 changes: 2 additions & 3 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1027,7 +1027,7 @@ void MainWindow::PlotCallbackFunction(void *p, int externalWindow, const char* f
const char *x1, const char *x2, const char *y1, const char *y2, const char *curveWidth,
const char *curveStyle, const char *legendPosition, const char *footer, const char *autoScale,
const char *variables)
{/*
{
MainWindow *pMainWindow = (MainWindow*)p;
if (pMainWindow) {
QFileInfo fileInfo(filename);
Expand Down Expand Up @@ -1111,7 +1111,6 @@ void MainWindow::PlotCallbackFunction(void *p, int externalWindow, const char* f
}
pVariablesTreeModel->blockSignals(state);
}
*/
}

//! Opens the new model widget.
Expand Down Expand Up @@ -2686,7 +2685,7 @@ void MainWindow::createActions()
mpNewParametricPlotWindowAction->setStatusTip(tr("Inserts new parametric plot window"));
connect(mpNewParametricPlotWindowAction, SIGNAL(triggered()), mpPlotWindowContainer, SLOT(addParametricPlotWindow()));
// new mpAnimationWindowAction plot action
mpAnimationWindowAction = new QAction(QIcon(":/Resources/icons/parametric-plot-window.svg"), tr("New Animation Window"), this);
mpAnimationWindowAction = new QAction(QIcon(":/Resources/icons/animation.png"), tr("New Animation Window"), this);
mpAnimationWindowAction->setStatusTip(tr("Inserts new animation window"));
connect(mpAnimationWindowAction, SIGNAL(triggered()), mpPlotWindowContainer, SLOT(addAnimationWindow()));
// export variables action
Expand Down
150 changes: 80 additions & 70 deletions OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp
Expand Up @@ -64,9 +64,9 @@ PlotWindowContainer::PlotWindowContainer(MainWindow *pParent)
* \param number
* \return
*/
//QString PlotWindowContainer::getUniqueName(QString name, int number)
//{
/*
QString PlotWindowContainer::getUniqueName(QString name, int number)
{

QString newName;
newName = name + QString::number(number);

Expand All @@ -76,47 +76,52 @@ PlotWindowContainer::PlotWindowContainer(MainWindow *pParent)
break;
}
}
return newName;*/
// return "Hase";
//}
return newName;
}

/*!
* \brief PlotWindowContainer::getCurrentWindow
* Returns the current plot window.
* \return
*/
//PlotWindow* PlotWindowContainer::getCurrentWindow()
//{
/*
PlotWindow* PlotWindowContainer::getCurrentWindow()
{
if (subWindowList(QMdiArea::ActivationHistoryOrder).size() == 0) {
return 0;
} else {
return qobject_cast<PlotWindow*>(subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget());
}*/
// return 0;
//}
}
else {
bool isPlotWidget = (0 != subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget()->objectName().compare(QString("animationWidget")));
//std::cout<<"isPlotWidget "<<isPlotWidget<<std::endl;
if (isPlotWidget)
return qobject_cast<PlotWindow*>(subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget());
else
return 0;
}
}

/*!
* \brief PlotWindowContainer::eventFilter
* \param pObject
* \param pEvent
* \return
*/
//bool PlotWindowContainer::eventFilter(QObject *pObject, QEvent *pEvent)
//{
/*
PlotWindow *pPlotWindow = qobject_cast<PlotWindow*>(pObject);
if (pPlotWindow && pEvent->type() == QEvent::Paint) {
QPainter painter (pPlotWindow);
painter.setPen(Qt::gray);
QRect rectangle = pPlotWindow->rect();
rectangle.setWidth(pPlotWindow->rect().width() - 1);
rectangle.setHeight(pPlotWindow->rect().height() - 1);
painter.drawRect(rectangle);
return true;
}*/
//return QMdiArea::eventFilter(pObject, pEvent);
//}
bool PlotWindowContainer::eventFilter(QObject *pObject, QEvent *pEvent)
{
bool isPlotWidget = (0 != pObject->objectName().compare(QString("animationWidget")));
if (isPlotWidget){
PlotWindow *pPlotWindow = qobject_cast<PlotWindow*>(pObject);
if (pPlotWindow && pEvent->type() == QEvent::Paint) {
QPainter painter (pPlotWindow);
painter.setPen(Qt::gray);
QRect rectangle = pPlotWindow->rect();
rectangle.setWidth(pPlotWindow->rect().width() - 1);
rectangle.setHeight(pPlotWindow->rect().height() - 1);
painter.drawRect(rectangle);
return true;
}
}
return QMdiArea::eventFilter(pObject, pEvent);
}

/*!
* \brief PlotWindowContainer::addPlotWindow
Expand All @@ -128,13 +133,13 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
try {
PlotWindow *pPlotWindow = new PlotWindow(QStringList(), this);
pPlotWindow->setPlotType(PlotWindow::PLOT);
//pPlotWindow->setWindowTitle(getUniqueName("Plot : "));
//pPlotWindow->setTitle("");
//pPlotWindow->setLegendPosition("top");
//pPlotWindow->setAutoScale(mpMainWindow->getOptionsDialog()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
//pPlotWindow->setTimeUnit(mpMainWindow->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
//pPlotWindow->setXLabel(QString("time [%1]").arg(pPlotWindow->getTimeUnit()));
//pPlotWindow->installEventFilter(this);
pPlotWindow->setWindowTitle(getUniqueName("Plot : "));
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(mpMainWindow->getOptionsDialog()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setTimeUnit(mpMainWindow->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time [%1]").arg(pPlotWindow->getTimeUnit()));
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
pPlotWindow->show();
Expand All @@ -156,11 +161,11 @@ void PlotWindowContainer::addParametricPlotWindow()
try {
PlotWindow *pPlotWindow = new PlotWindow(QStringList(), this);
pPlotWindow->setPlotType(PlotWindow::PLOTPARAMETRIC);
//pPlotWindow->setWindowTitle(getUniqueName("Parametric Plot : "));
//pPlotWindow->setTitle("");
//pPlotWindow->setLegendPosition("top");
//pPlotWindow->setAutoScale(mpMainWindow->getOptionsDialog()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
//pPlotWindow->installEventFilter(this);
pPlotWindow->setWindowTitle(getUniqueName("Parametric Plot : "));
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(mpMainWindow->getOptionsDialog()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/parametric-plot-window.svg"));
pPlotWindow->show();
Expand All @@ -174,9 +179,8 @@ void PlotWindowContainer::addParametricPlotWindow()
* \brief PlotWindowContainer::clearPlotWindow
* Clears the plot window
*/
//void PlotWindowContainer::clearPlotWindow()
//{
/*
void PlotWindowContainer::clearPlotWindow()
{
PlotWindow *pPlotWindow = getCurrentWindow();
if (!pPlotWindow) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
Expand All @@ -192,16 +196,14 @@ void PlotWindowContainer::addParametricPlotWindow()
}
pPlotWindow->fitInView();
mpMainWindow->getVariablesWidget()->updateVariablesTreeHelper(subWindowList(QMdiArea::ActivationHistoryOrder).last());
*/
//}
}

/*!
* \brief PlotWindowContainer::exportVariables
* Exports the selected variables to CSV file.
*/
//void PlotWindowContainer::exportVariables()
//{
/*
void PlotWindowContainer::exportVariables()
{
PlotWindow *pPlotWindow = getCurrentWindow();
if (!pPlotWindow) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
Expand Down Expand Up @@ -243,37 +245,45 @@ void PlotWindowContainer::addParametricPlotWindow()
if (mpMainWindow->getLibraryWidget()->saveFile(fileName, contents)) {
mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, tr("Exported variables in %1")
.arg(fileName), Helper::scriptingKind, Helper::notificationLevel));
}*/
//}
}
}

/*!
* \brief PlotWindowContainer::updatePlotWindows
* Updates the plot windows when the result file is updated.
* \param variable
*/
//void PlotWindowContainer::updatePlotWindows(QString variable)
//{
/*
void PlotWindowContainer::updatePlotWindows(QString variable)
{
foreach (QMdiSubWindow *pSubWindow, subWindowList()) {
PlotWindow *pPlotWindow = qobject_cast<PlotWindow*>(pSubWindow->widget());
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
if (variable.compare(pPlotCurve->getFileName()) == 0) {
pPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->getPlot()->replot();
}
}
}
}*/
//}
bool isPlotWidget = (0 != pSubWindow->widget()->objectName().compare(QString("animationWidget")));
if (isPlotWidget){

PlotWindow *pPlotWindow = qobject_cast<PlotWindow*>(pSubWindow->widget());
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
if (variable.compare(pPlotCurve->getFileName()) == 0) {
pPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
}
else {
pPlotWindow->getPlot()->replot();
}
}

}
} // is plotWidget
}
}

/*!
* \brief PlotWindowContainer::addAnimationWindow
* Adds an animation widget as subwindow
*/
void PlotWindowContainer::addAnimationWindow(){
std::cout<<"HUHUHUHUH"<<std::endl;
AnimationWindowContainer *pAnimation = new AnimationWindowContainer(this);
QMdiSubWindow *pSubWindow = addSubWindow(pAnimation);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/animation.png"));
pAnimation->show();
}

0 comments on commit 03c48b2

Please sign in to comment.