Skip to content

Commit

Permalink
Update according to OMSimulator signal format
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Aug 3, 2018
1 parent 51c079c commit d86a2f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
18 changes: 12 additions & 6 deletions OMEdit/OMEditGUI/Component/FMUProperties.cpp
Expand Up @@ -160,21 +160,24 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pParameterLineEdit->setValidator(pDoubleValidator);
double value;
if ((status = OMSProxy::instance()->getRealParameter(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getRealParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
QIntValidator *pIntValidator = new QIntValidator(this);
pParameterLineEdit->setValidator(pIntValidator);
int value;
if ((status = OMSProxy::instance()->getIntegerParameter(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getIntegerParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
QIntValidator *pIntValidator = new QIntValidator(this);
pParameterLineEdit->setValidator(pIntValidator);
bool value;
if ((status = OMSProxy::instance()->getBooleanParameter(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getBooleanParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_string) {
Expand Down Expand Up @@ -228,21 +231,24 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pInputLineEdit->setValidator(pDoubleValidator);
double value;
if ((status = OMSProxy::instance()->getReal(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getReal(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pInputLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
QIntValidator *pIntValidator = new QIntValidator(this);
pInputLineEdit->setValidator(pIntValidator);
int value;
if ((status = OMSProxy::instance()->getInteger(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getInteger(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pInputLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
QIntValidator *pIntValidator = new QIntValidator(this);
pInputLineEdit->setValidator(pIntValidator);
bool value;
if ((status = OMSProxy::instance()->getBoolean(pInterfaces[i]->name, &value))) {
if ((status = OMSProxy::instance()->getBoolean(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name), &value))) {
pInputLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_string) {
Expand Down
38 changes: 26 additions & 12 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1953,15 +1953,19 @@ void FMUPropertiesCommand::redo()
if (mpComponent->getLibraryTreeItem()->getOMSElement() && mpComponent->getLibraryTreeItem()->getOMSElement()->connectors) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->connectors;
for (int i = 0 ; pInterfaces[i] ; i++) {
QString name = QString(pInterfaces[i]->name).split(':', QString::SkipEmptyParts).last();
if (pInterfaces[i]->causality == oms_causality_parameter) {
QString parameterValue = mNewFMUProperties.mParameterValues.at(parametersIndex);
parametersIndex++;
if (pInterfaces[i]->type == oms_signal_type_real) {
OMSProxy::instance()->setRealParameter(pInterfaces[i]->name, parameterValue.toDouble());
OMSProxy::instance()->setRealParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toDouble());
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
OMSProxy::instance()->setIntegerParameter(pInterfaces[i]->name, parameterValue.toInt());
OMSProxy::instance()->setIntegerParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
OMSProxy::instance()->setBooleanParameter(pInterfaces[i]->name, parameterValue.toInt());
OMSProxy::instance()->setBooleanParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_string) {
qDebug() << "FMUPropertiesCommand::redo() oms_signal_type_string not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_enum) {
Expand All @@ -1975,11 +1979,14 @@ void FMUPropertiesCommand::redo()
QString inputValue = mNewFMUProperties.mInputValues.at(inputsIndex);
inputsIndex++;
if (pInterfaces[i]->type == oms_signal_type_real) {
OMSProxy::instance()->setReal(pInterfaces[i]->name, inputValue.toDouble());
OMSProxy::instance()->setReal(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toDouble());
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
OMSProxy::instance()->setInteger(pInterfaces[i]->name, inputValue.toInt());
OMSProxy::instance()->setInteger(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
OMSProxy::instance()->setBoolean(pInterfaces[i]->name, inputValue.toInt());
OMSProxy::instance()->setBoolean(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_string) {
qDebug() << "FMUPropertiesCommand::redo() oms_signal_type_string not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_enum) {
Expand All @@ -2006,15 +2013,19 @@ void FMUPropertiesCommand::undo()
if (mpComponent->getLibraryTreeItem()->getOMSElement() && mpComponent->getLibraryTreeItem()->getOMSElement()->connectors) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->connectors;
for (int i = 0 ; pInterfaces[i] ; i++) {
QString name = QString(pInterfaces[i]->name).split(':', QString::SkipEmptyParts).last();
if (pInterfaces[i]->causality == oms_causality_parameter) {
QString parameterValue = mOldFMUProperties.mParameterValues.at(parametersIndex);
parametersIndex++;
if (pInterfaces[i]->type == oms_signal_type_real) {
OMSProxy::instance()->setRealParameter(pInterfaces[i]->name, parameterValue.toDouble());
OMSProxy::instance()->setRealParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toDouble());
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
OMSProxy::instance()->setIntegerParameter(pInterfaces[i]->name, parameterValue.toInt());
OMSProxy::instance()->setIntegerParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
OMSProxy::instance()->setBooleanParameter(pInterfaces[i]->name, parameterValue.toInt());
OMSProxy::instance()->setBooleanParameter(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), parameterValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_string) {
qDebug() << "FMUPropertiesCommand::redo() oms_signal_type_string not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_enum) {
Expand All @@ -2028,11 +2039,14 @@ void FMUPropertiesCommand::undo()
QString inputValue = mOldFMUProperties.mInputValues.at(inputsIndex);
inputsIndex++;
if (pInterfaces[i]->type == oms_signal_type_real) {
OMSProxy::instance()->setReal(pInterfaces[i]->name, inputValue.toDouble());
OMSProxy::instance()->setReal(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toDouble());
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
OMSProxy::instance()->setInteger(pInterfaces[i]->name, inputValue.toInt());
OMSProxy::instance()->setInteger(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
OMSProxy::instance()->setBoolean(pInterfaces[i]->name, inputValue.toInt());
OMSProxy::instance()->setBoolean(QString("%1:%2").arg(mpComponent->getLibraryTreeItem()->getNameStructure(),
name).toStdString().c_str(), inputValue.toInt());
} else if (pInterfaces[i]->type == oms_signal_type_string) {
qDebug() << "FMUPropertiesCommand::redo() oms_signal_type_string not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_enum) {
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -363,7 +363,7 @@ class UndoStack : public QUndoStack
{
Q_OBJECT
public:
UndoStack(QObject *parent = Q_NULLPTR);
UndoStack(QObject *parent = 0);
void push(QUndoCommand *cmd);

bool isEnabled() {return mEnabled;}
Expand Down

0 comments on commit d86a2f0

Please sign in to comment.