Skip to content

Commit

Permalink
Clear the 3D Viewer Browser when we don't have any visualization.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jan 24, 2017
1 parent 4b46f22 commit 20360a0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
11 changes: 11 additions & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Expand Up @@ -203,6 +203,17 @@ void AbstractAnimationWindow::createActions()
connect(mpRotateCameraRightAction, SIGNAL(triggered()), this, SLOT(rotateCameraRight()));
}

/*!
* \brief AbstractAnimationWindow::clearView
*/
void AbstractAnimationWindow::clearView()
{
if (mpViewerWidget) {
mpViewerWidget->getSceneView()->setSceneData(0);
mpViewerWidget->update();
}
}

/*!
* \brief AbstractAnimationWindow::loadVisualization
* loads the data and the xml scene description
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h
Expand Up @@ -54,6 +54,7 @@ class AbstractAnimationWindow : public QMainWindow
AbstractAnimationWindow(QWidget *pParent);
void openAnimationFile(QString fileName);
virtual void createActions();
void clearView();
private:
bool loadVisualization();
protected:
Expand Down
54 changes: 37 additions & 17 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -4669,13 +4669,12 @@ ModelWidgetContainer::ModelWidgetContainer(QWidget *pParent)
pModelSwitcherLayout->setContentsMargins(0, 0, 0, 0);
pModelSwitcherLayout->addWidget(mpRecentModelsList, 0, 0);
mpModelSwitcherDialog->setLayout(pModelSwitcherLayout);
mpLastActiveSubWindow = 0;
// install QApplication event filter to handle the ctrl+tab and ctrl+shift+tab
QApplication::instance()->installEventFilter(this);
connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)), SLOT(currentModelWidgetChanged(QMdiSubWindow*)));
connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)), MainWindow::instance(), SLOT(updateModelSwitcherMenu(QMdiSubWindow*)));
#if !defined(WITHOUT_OSG)
connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)), SLOT(updateThreeDViewer(QMdiSubWindow*)));
#endif
// add actions
connect(MainWindow::instance()->getSaveAction(), SIGNAL(triggered()), SLOT(saveModelWidget()));
connect(MainWindow::instance()->getSaveAsAction(), SIGNAL(triggered()), SLOT(saveAsModelWidget()));
Expand Down Expand Up @@ -4977,6 +4976,32 @@ void ModelWidgetContainer::changeRecentModelsListSelection(bool moveDown)
}
}

#if !defined(WITHOUT_OSG)
/*!
* \brief ModelWidgetContainer::updateThreeDViewer
* Updates the ThreeDViewer with the visualization of the current ModelWidget.
* \param pModelWidget
*/
void ModelWidgetContainer::updateThreeDViewer(ModelWidget *pModelWidget)
{
if (pModelWidget->getLibraryTreeItem() && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::MetaModel) {
// write dummy csv file for 3d view
QFileInfo fileInfo(pModelWidget->getLibraryTreeItem()->getFileName());
QString resultFileName = QString("%1/%2.csv").arg(Utilities::tempDirectory()).arg(fileInfo.baseName());
QString visualXMLFileName = QString("%1/%2_visual.xml").arg(Utilities::tempDirectory()).arg(fileInfo.baseName());
// write dummy csv file and visualization file
if (pModelWidget->writeCoSimulationResultFile(resultFileName) && pModelWidget->writeVisualXMLFile(visualXMLFileName)) {
MainWindow::instance()->getThreeDViewerDockWidget()->show();
MainWindow::instance()->getThreeDViewer()->openAnimationFile(resultFileName);
} else {
MainWindow::instance()->getThreeDViewer()->clearView();
}
} else {
MainWindow::instance()->getThreeDViewer()->clearView();
}
}
#endif

/*!
* \brief ModelWidgetContainer::loadPreviousViewType
* Opens the ModelWidget using the previous view type used by user.
Expand Down Expand Up @@ -5126,33 +5151,28 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
}
}

#if !defined(WITHOUT_OSG)
/*!
* \brief ModelWidgetContainer::updateThreeDViewer
* Updates the ThreeDViewer when subWindowActivated(QMdiSubWindow*) signal of ModelWidgetContainer is raised.
* \param pSubWindow
*/
void ModelWidgetContainer::updateThreeDViewer(QMdiSubWindow *pSubWindow)
{
#if !defined(WITHOUT_OSG)
if (!pSubWindow) {
return;
}
ModelWidget *pModelWidget = qobject_cast<ModelWidget*>(pSubWindow->widget());
if (pModelWidget->getLibraryTreeItem() && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::MetaModel) {
// write dummy csv file for 3d view
QFileInfo fileInfo(pModelWidget->getLibraryTreeItem()->getFileName());
QString resultFileName = QString("%1/%2.csv").arg(Utilities::tempDirectory()).arg(fileInfo.baseName());
QString visualXMLFileName = QString("%1/%2_visual.xml").arg(Utilities::tempDirectory()).arg(fileInfo.baseName());
// write dummy csv file and visualization file
if (pModelWidget->writeCoSimulationResultFile(resultFileName) && pModelWidget->writeVisualXMLFile(visualXMLFileName)) {
MainWindow::instance()->getThreeDViewerDockWidget()->show();
MainWindow::instance()->getThreeDViewer()->openAnimationFile(resultFileName);
} else {
//MainWindow::instance()->getThreeDViewer()->
}
/* if the same sub window is activated again then just return */
if (mpLastActiveSubWindow == pSubWindow) {
return;
}
}
mpLastActiveSubWindow = pSubWindow;
ModelWidget *pModelWidget = qobject_cast<ModelWidget*>(pSubWindow->widget());
updateThreeDViewer(pModelWidget);
#else
Q_UNUSED(pSubWindow);
#endif
}

/*!
* \brief ModelWidgetContainer::saveModelWidget
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -461,18 +461,20 @@ class ModelWidgetContainer : public QMdiArea
bool isShowGridLines() {return mShowGridLines;}
bool eventFilter(QObject *object, QEvent *event);
void changeRecentModelsListSelection(bool moveDown);
#if !defined(WITHOUT_OSG)
void updateThreeDViewer(ModelWidget *pModelWidget);
#endif
private:
StringHandler::ViewType mPreviousViewType;
bool mShowGridLines;
QDialog *mpModelSwitcherDialog;
QListWidget *mpRecentModelsList;
QMdiSubWindow *mpLastActiveSubWindow;
void loadPreviousViewType(ModelWidget *pModelWidget);
public slots:
bool openRecentModelWidget(QListWidgetItem *pListWidgetItem);
void currentModelWidgetChanged(QMdiSubWindow *pSubWindow);
#if !defined(WITHOUT_OSG)
void updateThreeDViewer(QMdiSubWindow *pSubWindow);
#endif
void saveModelWidget();
void saveAsModelWidget();
void saveTotalModelWidget();
Expand Down

0 comments on commit 20360a0

Please sign in to comment.