Skip to content

Commit

Permalink
Update the time when slider is moved.
Browse files Browse the repository at this point in the history
Connect to returnPressed signal of time text box instead of textChanged.
If time is out of range then set start/end time automatically.
Make the animation run until the end time.
  • Loading branch information
adeas31 committed Nov 10, 2016
1 parent 66a60fc commit 965594a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
34 changes: 18 additions & 16 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -148,10 +148,10 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
connect(mpPerspectiveDropDownBox, SIGNAL(activated(int)), this, SLOT(setPerspective(int)));
connect(mpAnimationSlider, SIGNAL(sliderMoved(int)),this, SLOT(sliderSetTimeSlotFunction(int)));
connect(mpAnimationSlider, SIGNAL(valueChanged(int)),this, SLOT(sliderSetTimeSlotFunction(int)));
connect(mpSpeedComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(setSpeedSlotFunction()));
connect(mpSpeedComboBox->lineEdit(), SIGNAL(textChanged(QString)),this, SLOT(setSpeedSlotFunction()));
connect(mpTimeTextBox, SIGNAL(textChanged(QString)),this, SLOT(jumpToTimeSlotFunction()));
connect(mpTimeTextBox, SIGNAL(returnPressed()),this, SLOT(jumpToTimeSlotFunction()));
}

/*!
Expand All @@ -166,15 +166,16 @@ void AnimationWindow::jumpToTimeSlotFunction()
double end = mpVisualizer->getTimeManager()->getEndTime();
double value = str.toFloat(&isFloat);
if (isFloat && value >= 0.0) {
if (start <= value && value <= end) {
mpVisualizer->getTimeManager()->setVisTime(value);
mpAnimationSlider->setValue(mpVisualizer->getTimeManager()->getTimeFraction());
mpVisualizer->updateScene(value);
} else {
QString msg = tr("The point of time has to be between start (%1) and end time(%2).").arg(start).arg(end);
mpPlotWindowContainer->getMainWindow()->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::errorLevel));
if (value < start) {
value = start;
} else if (value > end) {
value = end;
}
mpVisualizer->getTimeManager()->setVisTime(value);
bool state = mpAnimationSlider->blockSignals(true);
mpAnimationSlider->setValue(mpVisualizer->getTimeManager()->getTimeFraction());
mpAnimationSlider->blockSignals(state);
mpVisualizer->updateScene(value);
}
}

Expand Down Expand Up @@ -339,6 +340,7 @@ void AnimationWindow::sliderSetTimeSlotFunction(int value)
- mpVisualizer->getTimeManager()->getStartTime())
* (float) (value / 100.0);
mpVisualizer->getTimeManager()->setVisTime(time);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime()));
mpVisualizer->updateScene(time);
}

Expand Down Expand Up @@ -367,10 +369,10 @@ void AnimationWindow::pauseSlotFunction()
void AnimationWindow::initSlotFunction()
{
mpVisualizer->initVisualization();
bool state = mpAnimationSlider->blockSignals(true);
mpAnimationSlider->setValue(0);
bool state = mpTimeTextBox->blockSignals(true);
mpAnimationSlider->blockSignals(state);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime()));
mpTimeTextBox->blockSignals(state);
}

/*!
Expand All @@ -382,13 +384,13 @@ void AnimationWindow::updateScene()
if (!(mpVisualizer == NULL)) {
//set time label
if (!mpVisualizer->getTimeManager()->isPaused()) {
bool state = mpTimeTextBox->blockSignals(true);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime()));
mpTimeTextBox->blockSignals(state);
// set time slider
if (mpVisualizer->getVisType() != VisType::FMU) {
int time = mpVisualizer->getTimeManager()->getTimeFraction();
bool state = mpAnimationSlider->blockSignals(true);
mpAnimationSlider->setValue(time);
mpAnimationSlider->blockSignals(state);
}
}
//update the scene
Expand Down Expand Up @@ -454,12 +456,12 @@ void AnimationWindow::openAnimationFile(QString fileName)
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
bool state = mpAnimationSlider->blockSignals(true);
mpAnimationSlider->setValue(0);
mpAnimationSlider->blockSignals(state);
mpSpeedComboBox->setEnabled(true);
mpTimeTextBox->setEnabled(true);
bool state = mpTimeTextBox->blockSignals(true);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getStartTime()));
mpTimeTextBox->blockSignals(state);
state = mpPerspectiveDropDownBox->blockSignals(true);
mpPerspectiveDropDownBox->setCurrentIndex(0);
mpPerspectiveDropDownBox->blockSignals(state);
Expand Down
18 changes: 9 additions & 9 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -269,18 +269,18 @@ void VisualizerAbstract::sceneUpdate()
//measure realtime
mpTimeManager->updateTick();
//update scene and set next time step
if (!mpTimeManager->isPaused())
{
if (!mpTimeManager->isPaused()) {
updateScene(mpTimeManager->getVisTime());
double newTime = mpTimeManager->getVisTime() + (mpTimeManager->getHVisual()*mpTimeManager->getSpeedUp());
if (newTime <= mpTimeManager->getEndTime())
{
mpTimeManager->setVisTime(newTime);
}
//finish animation with pause when endtime is reached
else
{
if (mpTimeManager->getVisTime() >= mpTimeManager->getEndTime()) {
mpTimeManager->setPause(true);
} else { // get the new visualization time
double newTime = mpTimeManager->getVisTime() + (mpTimeManager->getHVisual()*mpTimeManager->getSpeedUp());
if (newTime <= mpTimeManager->getEndTime()) {
mpTimeManager->setVisTime(newTime);
} else {
mpTimeManager->setVisTime(mpTimeManager->getEndTime());
}
}
}
}
Expand Down

0 comments on commit 965594a

Please sign in to comment.