Skip to content

Commit

Permalink
Automatically launch the animation window.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 30, 2016
1 parent 77d8742 commit 6ec4f43
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 43 deletions.
54 changes: 31 additions & 23 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -271,30 +271,12 @@ void AnimationWindow::loadVisualization()
*/
void AnimationWindow::chooseAnimationFileSlotFunction()
{
std::string file = StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile),
NULL, Helper::matFileTypes, NULL).toStdString();
if (file.compare(""))
{
std::size_t pos = file.find_last_of("/\\");
mPathName = file.substr(0, pos + 1);
mFileName = file.substr(pos + 1, file.length());
//std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
loadVisualization();
// start the widgets
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
mpAnimationSlider->setValue(0);
mpSpeedUpEdit->setEnabled(true);
mpSpeedUpEdit->setPlainText(QString("1.0"));
mpTimeEdit->setEnabled(true);
mpTimeEdit->setPlainText(QString::number(mpVisualizer->getTimeManager()->getStartTime()));
}
else
{
std::cout<<"No Visualization selected!"<<std::endl;
QString fileName = StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile),
NULL, Helper::matFileTypes, NULL);
if (fileName.isEmpty()) {
return;
}
openAnimationFile(fileName);
}

/*!
Expand Down Expand Up @@ -414,6 +396,32 @@ void AnimationWindow::setFileName(std::string fileName)
mFileName = fileName;
}

/*!
* \brief AnimationWindow::openAnimationFile
* \param fileName
*/
void AnimationWindow::openAnimationFile(QString fileName)
{
std::string file = fileName.toStdString();
if (file.compare("")) {
std::size_t pos = file.find_last_of("/\\");
mPathName = file.substr(0, pos + 1);
mFileName = file.substr(pos + 1, file.length());
//std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
loadVisualization();
// start the widgets
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
mpAnimationSlider->setValue(0);
mpSpeedUpEdit->setEnabled(true);
mpSpeedUpEdit->setPlainText(QString("1.0"));
mpTimeEdit->setEnabled(true);
mpTimeEdit->setPlainText(QString::number(mpVisualizer->getTimeManager()->getStartTime()));
}
}

/*!
* \brief AnimationWindow::cameraPositionXY
* sets the camera position to XY
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.h
Expand Up @@ -70,6 +70,7 @@ class AnimationWindow : public QMainWindow, public osgViewer::CompositeViewer
double getVisTime();
void setPathName(std::string name);
void setFileName(std::string name);
void openAnimationFile(QString fileName);
public slots:
void sliderSetTimeSlotFunction(int value);
void playSlotFunction();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -3037,7 +3037,7 @@ void MainWindow::switchToPlottingPerspective()
mpUndoAction->setEnabled(false);
mpRedoAction->setEnabled(false);
mpModelSwitcherToolButton->setEnabled(false);
// if not plotwindow is opened then open one for user
// if no plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
mpPlotWindowContainer->addPlotWindow(true);
}
Expand Down
16 changes: 6 additions & 10 deletions OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp
Expand Up @@ -108,17 +108,13 @@ AnimationWindow* PlotWindowContainer::getCurrentAnimationWindow()
{
if (subWindowList(QMdiArea::ActivationHistoryOrder).size() == 0) {
return 0;
}
else {
bool isAnimationWidget = (0 == subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget()->objectName().compare(QString("animationWidget")));
std::cout<<"isAnimationWidget "<<isAnimationWidget<<std::endl;
if (isAnimationWidget)
{
std::cout<<"this was good\n"<<std::endl;
} else {
bool isAnimationWidget = (0 == subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget()->objectName().compare(QString("animationWidget")));
if (isAnimationWidget) {
return qobject_cast<AnimationWindow*>(subWindowList(QMdiArea::ActivationHistoryOrder).last()->widget());
}
else
return 0;
} else {
return 0;
}
}
}

Expand Down
24 changes: 16 additions & 8 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -106,7 +106,7 @@ void SimulationDialog::directSimulate(LibraryTreeItem *pLibraryTreeItem, bool la
mpBuildOnlyCheckBox->setChecked(false);
mpLaunchTransformationalDebuggerCheckBox->setChecked(launchTransformationalDebugger);
mpLaunchAlgorithmicDebuggerCheckBox->setChecked(launchAlgorithmicDebugger);
mpSimulateWithAnimationCheckBox->setChecked(launchAnimation);
mpLaunchAnimationCheckBox->setChecked(launchAnimation);
simulate();
}

Expand Down Expand Up @@ -252,8 +252,8 @@ void SimulationDialog::setUpForm()
mpLaunchTransformationalDebuggerCheckBox = new QCheckBox(tr("Launch Transformational Debugger"));
// Launch Algorithmic Debugger checkbox
mpLaunchAlgorithmicDebuggerCheckBox = new QCheckBox(tr("Launch Algorithmic Debugger"));
// simulate with animation
mpSimulateWithAnimationCheckBox = new QCheckBox(Helper::simulateWithAnimation);
// Launch Animation
mpLaunchAnimationCheckBox = new QCheckBox(tr("Launch Animation"));
// set General Tab Layout
QGridLayout *pGeneralTabLayout = new QGridLayout;
pGeneralTabLayout->setAlignment(Qt::AlignTop);
Expand All @@ -267,7 +267,7 @@ void SimulationDialog::setUpForm()
pGeneralTabLayout->addWidget(mpBuildOnlyCheckBox, 4, 0, 1, 3);
pGeneralTabLayout->addWidget(mpLaunchTransformationalDebuggerCheckBox, 5, 0, 1, 3);
pGeneralTabLayout->addWidget(mpLaunchAlgorithmicDebuggerCheckBox, 6, 0, 1, 3);
pGeneralTabLayout->addWidget(mpSimulateWithAnimationCheckBox, 7, 0, 1, 3);
pGeneralTabLayout->addWidget(mpLaunchAnimationCheckBox, 7, 0, 1, 3);
mpGeneralTab->setLayout(pGeneralTabLayout);
// add General Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpGeneralTab, Helper::general);
Expand Down Expand Up @@ -682,7 +682,7 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
// Launch Algorithmic Debugger checkbox
mpLaunchAlgorithmicDebuggerCheckBox->setChecked(simulationOptions.getLaunchAlgorithmicDebugger());
// Simulate with Animation checkbox
mpSimulateWithAnimationCheckBox->setChecked(simulationOptions.getSimulateWithAnimation());
mpLaunchAnimationCheckBox->setChecked(simulationOptions.getSimulateWithAnimation());
// build only
mpBuildOnlyCheckBox->setChecked(simulationOptions.getBuildOnly());
// Number Of Intervals
Expand Down Expand Up @@ -787,7 +787,7 @@ bool SimulationDialog::translateModel(QString simulationParameters)
mpMainWindow->getOMCProxy()->setCommandLineOptions("+d=gendebugsymbols");
}
// set the visulation flag before translation
if (mpSimulateWithAnimationCheckBox->isChecked()) {
if (mpLaunchAnimationCheckBox->isChecked()) {
mpMainWindow->getOMCProxy()->setCommandLineOptions("+d=visxml");
}
bool result = mpMainWindow->getOMCProxy()->translateModel(mClassName, simulationParameters);
Expand Down Expand Up @@ -815,7 +815,7 @@ SimulationOptions SimulationDialog::createSimulationOptions()
simulationOptions.setBuildOnly(mpBuildOnlyCheckBox->isChecked());
simulationOptions.setLaunchTransformationalDebugger(mpLaunchTransformationalDebuggerCheckBox->isChecked());
simulationOptions.setLaunchAlgorithmicDebugger(mpLaunchAlgorithmicDebuggerCheckBox->isChecked());
simulationOptions.setSimulateWithAnimation(mpSimulateWithAnimationCheckBox->isChecked());
simulationOptions.setSimulateWithAnimation(mpLaunchAnimationCheckBox->isChecked());
simulationOptions.setNumberofIntervals(mpNumberofIntervalsSpinBox->value());
qreal startTime = mpStartTimeTextBox->text().toDouble();
qreal stopTime = mpStopTimeTextBox->text().toDouble();
Expand Down Expand Up @@ -1271,6 +1271,14 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
pOMCProxy->closeSimulationResultFile();
if (list.size() > 0) {
mpMainWindow->getPerspectiveTabBar()->setCurrentIndex(2);
// if simulated with animation then open the animation directly.
if (mpLaunchAnimationCheckBox->isChecked()) {
mpMainWindow->getPlotWindowContainer()->addAnimationWindow();
AnimationWindow *pAnimationWindow = mpMainWindow->getPlotWindowContainer()->getCurrentAnimationWindow();
if (pAnimationWindow) {
pAnimationWindow->openAnimationFile(simulationOptions.getResultFileName());
}
}
pVariablesWidget->insertVariablesItemsToTree(simulationOptions.getResultFileName(), workingDirectory, list, simulationOptions);
}
}
Expand Down Expand Up @@ -1374,7 +1382,7 @@ void SimulationDialog::updateJacobianToolTip(int index)
void SimulationDialog::buildOnly(bool checked)
{
mpLaunchAlgorithmicDebuggerCheckBox->setEnabled(!checked);
mpSimulateWithAnimationCheckBox->setEnabled(!checked);
mpLaunchAnimationCheckBox->setEnabled(!checked);
mpSimulationFlagsTab->setEnabled(!checked);
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Simulation/SimulationDialog.h
Expand Up @@ -117,7 +117,7 @@ class SimulationDialog : public QDialog
QCheckBox *mpBuildOnlyCheckBox;
QCheckBox *mpLaunchTransformationalDebuggerCheckBox;
QCheckBox *mpLaunchAlgorithmicDebuggerCheckBox;
QCheckBox *mpSimulateWithAnimationCheckBox;
QCheckBox *mpLaunchAnimationCheckBox;
// Output Tab
QWidget *mpOutputTab;
Label *mpOutputFormatLabel;
Expand Down

0 comments on commit 6ec4f43

Please sign in to comment.