Skip to content

Commit

Permalink
Changed the speed textbox to editable combobox.
Browse files Browse the repository at this point in the history
Use MessagesWidget for errors instead of cout.
Disable some warnings.
  • Loading branch information
adeas31 committed Nov 10, 2016
1 parent 205399a commit f793884
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
93 changes: 44 additions & 49 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -89,16 +89,24 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(0);
mpAnimationSlider->setEnabled(false);
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pDoubleValidator->setBottom(0);
mpAnimationTimeLabel = new QLabel();
mpAnimationTimeLabel->setText(tr("Time [s]:"));
mpTimeTextBox = new QLineEdit("0.0", this);
mpTimeTextBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpTimeTextBox->setEnabled(false);
mpTimeTextBox->setValidator(pDoubleValidator);
mpAnimationSpeedLabel = new Label;
mpAnimationSpeedLabel->setText(tr("Speed:"));
mpSpeedTextBox = new QLineEdit("1.0", this);
mpSpeedTextBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpSpeedTextBox->setEnabled(false);
mpSpeedComboBox = new QComboBox(this);
mpSpeedComboBox->setEditable(true);
mpSpeedComboBox->addItems(QStringList() << "10" << "5" << "2" << "1" << "0.5" << "0.2" << "0.1");
mpSpeedComboBox->setCurrentIndex(3);
mpSpeedComboBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpSpeedComboBox->setEnabled(false);
mpSpeedComboBox->setValidator(pDoubleValidator);
mpSpeedComboBox->setCompleter(0);
mpPerspectiveDropDownBox = new QComboBox(this);
//mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective0.svg"), QString("to home position"));
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective2.svg"),QString("normal to x-y plane"));
Expand All @@ -119,7 +127,7 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
mpAnimationToolBar->addWidget(mpTimeTextBox);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationSpeedLabel);
mpAnimationToolBar->addWidget(mpSpeedTextBox);
mpAnimationToolBar->addWidget(mpSpeedComboBox);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpPerspectiveDropDownBox);
mpAnimationToolBar->setIconSize(QSize(toolbarIconSize, toolbarIconSize));
Expand All @@ -140,7 +148,8 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
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(mpSpeedTextBox, SIGNAL(textChanged(QString)),this, SLOT(setSpeedUpSlotFunction()));
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()));
}

Expand All @@ -155,42 +164,31 @@ void AnimationWindow::jumpToTimeSlotFunction()
double start = mpVisualizer->getTimeManager()->getStartTime();
double end = mpVisualizer->getTimeManager()->getEndTime();
double value = str.toFloat(&isFloat);
if (isFloat && value >= 0.0)
{
if (start <= value && value <= end)
{
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));
}
else
{
std::cout<<"The point of time has to be between start ("<<start<<") and end time("<<end<<")."<<std::endl;
}
}
else
{
std::cout<<"The point of time has to be a positive real value. "<<std::endl;
}
}

/*!
* \brief AnimationWindow::setSpeedUpSlotFunction
* slot function to set the user input speed up
*/
void AnimationWindow::setSpeedUpSlotFunction()
void AnimationWindow::setSpeedSlotFunction()
{
QString str = mpSpeedTextBox->text();
QString str = mpSpeedComboBox->lineEdit()->text();
bool isFloat = true;
double value = str.toFloat(&isFloat);
if (isFloat && value > 0.0)
{
if (isFloat && value > 0.0) {
mpVisualizer->getTimeManager()->setSpeedUp(value);
}
else
{
std::cout<<"The speedUp has to be a positive real value. "<<std::endl;
}
}
}

AnimationWindow::~AnimationWindow()
Expand Down Expand Up @@ -263,37 +261,37 @@ void AnimationWindow::loadVisualization()
} else if (isCSV(mFileName)) {
visType = VisType::CSV;
} else {
std::cout<<"unknown visualization type. "<<std::endl;
mpPlotWindowContainer->getMainWindow()->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
tr("Unknown visualization type."),
Helper::scriptingKind, Helper::errorLevel));
}
//init visualizer
if (visType == VisType::MAT) {
mpVisualizer = new VisualizerMAT(mFileName, mPathName);
}
else if (visType == VisType::CSV) {
} else if (visType == VisType::CSV) {
mpVisualizer = new VisualizerCSV(mFileName, mPathName);
}
else if (visType == VisType::FMU) {
} else if (visType == VisType::FMU) {
mpVisualizer = new VisualizerFMU(mFileName, mPathName);
}
else {
std::cout<<"could not init "<<mPathName<<mFileName<<std::endl;
} else {
QString msg = tr("Could not init %1 %2.").arg(QString(mPathName.c_str())).arg(QString(mFileName.c_str()));
mpPlotWindowContainer->getMainWindow()->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::errorLevel));
}
//load the XML File, build osgTree, get initial values for the shapes
bool xmlExists = checkForXMLFile(mFileName, mPathName);
if (!xmlExists) {
std::cout<<"Could not find the visual XML file "<<assembleXMLFileName(mFileName, mPathName)<<std::endl;
}
else
{
QString msg = tr("Could not find the visual XML file %1.").arg(QString(assembleXMLFileName(mFileName, mPathName).c_str()));
mpPlotWindowContainer->getMainWindow()->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::errorLevel));
} else {
mpVisualizer->initData();
mpVisualizer->setUpScene();
mpVisualizer->initVisualization();
//add scene for the chosen visualization
mpSceneView->setSceneData(mpVisualizer->getOMVisScene()->getScene().getRootNode());
}
//FMU settings dialog
if (visType == VisType::FMU)
{
if (visType == VisType::FMU) {
//openFMUSettingsDialog();
}
//add window title
Expand Down Expand Up @@ -368,7 +366,9 @@ void AnimationWindow::initSlotFunction()
{
mpVisualizer->initVisualization();
mpAnimationSlider->setValue(0);
bool state = mpTimeTextBox->blockSignals(true);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime()));
mpTimeTextBox->blockSignals(state);
}

/*!
Expand All @@ -379,14 +379,12 @@ void AnimationWindow::updateSceneFunction()
{
if (!(mpVisualizer == NULL)) {
//set time label
if (!mpVisualizer->getTimeManager()->isPaused())
{
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)
{
if (mpVisualizer->getVisType() != VisType::FMU) {
int time = mpVisualizer->getTimeManager()->getTimeFraction();
mpAnimationSlider->setValue(time);
}
Expand Down Expand Up @@ -455,12 +453,9 @@ void AnimationWindow::openAnimationFile(QString fileName)
mpAnimationPauseAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
mpAnimationSlider->setValue(0);
mpSpeedTextBox->setEnabled(true);
bool state = mpSpeedTextBox->blockSignals(true);
mpSpeedTextBox->setText(QString("1.0"));
mpSpeedTextBox->blockSignals(state);
mpSpeedComboBox->setEnabled(true);
mpTimeTextBox->setEnabled(true);
state = mpTimeTextBox->blockSignals(true);
bool state = mpTimeTextBox->blockSignals(true);
mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getStartTime()));
mpTimeTextBox->blockSignals(state);
state = mpPerspectiveDropDownBox->blockSignals(true);
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.h
Expand Up @@ -83,7 +83,7 @@ public slots:
void initSlotFunction();
void renderSlotFunction();
void chooseAnimationFileSlotFunction();
void setSpeedUpSlotFunction();
void setSpeedSlotFunction();
void jumpToTimeSlotFunction();
void updateSceneFunction();
void resetCamera();
Expand All @@ -109,7 +109,7 @@ public slots:
QLabel *mpAnimationTimeLabel;
QLineEdit *mpTimeTextBox;
Label *mpAnimationSpeedLabel;
QLineEdit *mpSpeedTextBox;
QComboBox *mpSpeedComboBox;
QComboBox *mpPerspectiveDropDownBox;
QDialog *mpFMUSettingsDialog;
//actions
Expand Down
2 changes: 0 additions & 2 deletions OMEdit/OMEditGUI/Animation/VisualizerCSV.cpp
Expand Up @@ -59,8 +59,6 @@ void VisualizerCSV::initData()

void VisualizerCSV::initializeVisAttributes(const double time)
{
std::cout<<"VisualizerCSV::initializeVisAttributes "<<time<<std::endl;

if (0.0 > time) {
std::cout<<"Cannot load visualization attributes for time point < 0.0."<<std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -192,8 +192,6 @@ HEADERS += Util/Helper.h \
Editors/CEditor.h \
Editors/MetaModelEditor.h \
Editors/MetaModelicaEditor.h \
$$OPENMODELICAHOME/../OMCompiler/3rdParty/FMIL/install/include/fmilib.h \
$$OPENMODELICAHOME/../OMCompiler/3rdParty/FMIL/install/include/fmilib_config.h \
Plotting/PlotWindowContainer.h \
Component/Component.h \
Annotations/ShapeAnnotation.h \
Expand Down Expand Up @@ -306,6 +304,8 @@ OTHER_FILES += Resources/css/stylesheet.qss \

# Please read the warnings. They are like vegetables; good for you even if you hate them.
CONFIG += warn_on
# Only disable the unused variable/function/parameter warning
QMAKE_CXXFLAGS += -Wno-clobbered -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter

RESOURCES += resource_omedit.qrc

Expand Down

0 comments on commit f793884

Please sign in to comment.