Skip to content

Commit

Permalink
get/set real fmu parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 12, 2018
1 parent 3a1daf4 commit 9ee5459
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 171 deletions.
17 changes: 9 additions & 8 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -35,6 +35,7 @@
#include "MainWindow.h"
#include "Component.h"
#include "ComponentProperties.h"
#include "FMUProperties.h"
#include "Modeling/Commands.h"
#include "Modeling/DocumentationWidget.h"

Expand Down Expand Up @@ -735,13 +736,13 @@ Component::Component(ComponentInfo *pComponentInfo, LibraryTreeItem *pLibraryTre
mpInputOutputComponentPolygon->setFillColor(QColor(255,0,255));
break;
case oms_signal_type_string:
qDebug() << "oms_signal_type_string not implemented yet.";
qDebug() << "Component::Component() oms_signal_type_string not implemented yet.";
break;
case oms_signal_type_enum:
qDebug() << "oms_signal_type_enum not implemented yet.";
qDebug() << "Component::Component() oms_signal_type_enum not implemented yet.";
break;
case oms_signal_type_bus:
qDebug() << "oms_signal_type_bus not implemented yet.";
qDebug() << "Component::Component() oms_signal_type_bus not implemented yet.";
break;
case oms_signal_type_real:
default:
Expand Down Expand Up @@ -2799,13 +2800,13 @@ void Component::showSubModelAttributes()
}

/*!
* \brief Component::showOMSModelAttributes
* Slot that opens up the CompositeModelSubModelAttributes Dialog.
* \brief Component::showFMUPropertiesDialog
* Slot that opens up the FMUPropertiesDialog Dialog.
*/
void Component::showOMSModelAttributes()
void Component::showFMUPropertiesDialog()
{
OMSSubModelAttributes *pOMSSubModelAttributes = new OMSSubModelAttributes(this, MainWindow::instance());
pOMSSubModelAttributes->exec();
FMUPropertiesDialog *pFMUPropertiesDialog = new FMUPropertiesDialog(this, MainWindow::instance());
pFMUPropertiesDialog->exec();
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -370,7 +370,7 @@ public slots:
void openClass();
void viewDocumentation();
void showSubModelAttributes();
void showOMSModelAttributes();
void showFMUPropertiesDialog();
protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
Expand Down
73 changes: 0 additions & 73 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1847,76 +1847,3 @@ void CompositeModelConnectionAttributes::createCompositeModelConnection()
mpGraphicsView->getModelWidget()->updateModelText();
accept();
}

/*!
* \class OMSSubModelAttributes
* \brief A dialog for displaying OMSSubModel attributes.
*/
/*!
* \brief OMSSubModelAttributes::OMSSubModelAttributes
* \param pComponent - pointer to Component
* \param pParent
*/
OMSSubModelAttributes::OMSSubModelAttributes(Component *pComponent, QWidget *pParent)
: QDialog(pParent)
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("SubModel Attributes")));
setAttribute(Qt::WA_DeleteOnClose);
mpComponent = pComponent;
// Create the name label and text box
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit(mpComponent->getName());
mpNameTextBox->setDisabled(true);
// Model parameters
mpParametersLabel = new Label("Parameters:");
mpParametersLayout = new QGridLayout;
mpParametersLayout->addWidget(mpParametersLabel, 0, 0, 1, 2);
mpParametersScrollWidget = new QWidget;
mpParametersScrollWidget->setLayout(mpParametersLayout);
mpParametersScrollArea = new QScrollArea;
mpParametersScrollArea->setWidgetResizable(true);
mpParametersScrollArea->setWidget(mpParametersScrollWidget);
mParameterLabels.clear();
mParameterLineEdits.clear();
int index = 0;
if (mpComponent->getLibraryTreeItem()->getOMSElement()) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->interfaces;
for (int i = 0 ; pInterfaces[i] ; i++) {
if (pInterfaces[i]->causality == oms_causality_parameter) {
index++;
QString name = StringHandler::getLastWordAfterDot(pInterfaces[i]->name);
name = name.split(':', QString::SkipEmptyParts).last();
mParameterLabels.append(new Label(name));
mParameterLineEdits.append(new QLineEdit);
mpParametersLayout->addWidget(mParameterLabels.last(), index, 0);
mpParametersLayout->addWidget(mParameterLineEdits.last(), index, 1);
}
}
}
mpParametersScrollWidget->setVisible(index > 0);
mpParametersLabel->setVisible(index > 0);
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateSubModelParameters()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
// Create buttons box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpNameLabel, 0, 0);
pMainLayout->addWidget(mpNameTextBox, 0, 1);
pMainLayout->addWidget(mpParametersScrollArea, 1, 0, 1, 2);
pMainLayout->addWidget(mpButtonBox, 2, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

void OMSSubModelAttributes::updateSubModelParameters()
{

}
22 changes: 0 additions & 22 deletions OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -307,26 +307,4 @@ public slots:
void createCompositeModelConnection();
};

class OMSSubModelAttributes : public QDialog
{
Q_OBJECT
public:
OMSSubModelAttributes(Component *pComponent, QWidget *pParent = 0);
private:
Component *mpComponent;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpParametersLabel;
QGridLayout *mpParametersLayout;
QWidget *mpParametersScrollWidget;
QScrollArea *mpParametersScrollArea;
QList<Label*> mParameterLabels;
QList<QLineEdit*> mParameterLineEdits;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void updateSubModelParameters();
};

#endif // COMPONENTPROPERTIES_H
150 changes: 150 additions & 0 deletions OMEdit/OMEditGUI/Component/FMUProperties.cpp
@@ -0,0 +1,150 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#include "FMUProperties.h"
#include "Modeling/Commands.h"

FMUProperties::FMUProperties()
{
mParameterValues.clear();
}

/*!
* \class FMUPropertiesDialog
* \brief A dialog for displaying FMU properties.
*/
/*!
* \brief FMUPropertiesDialog::FMUPropertiesDialog
* \param pComponent - pointer to Component
* \param pParent
*/
FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent)
: QDialog(pParent)
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("SubModel Attributes")));
setAttribute(Qt::WA_DeleteOnClose);
mpComponent = pComponent;
// Create the name label and text box
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit(mpComponent->getName());
mpNameTextBox->setDisabled(true);
// Model parameters
mpParametersLabel = new Label("Parameters:");
mpParametersLayout = new QGridLayout;
mpParametersLayout->addWidget(mpParametersLabel, 0, 0, 1, 2);
mpParametersScrollWidget = new QWidget;
mpParametersScrollWidget->setLayout(mpParametersLayout);
mpParametersScrollArea = new QScrollArea;
mpParametersScrollArea->setWidgetResizable(true);
mpParametersScrollArea->setWidget(mpParametersScrollWidget);
mParameterLabels.clear();
mParameterLineEdits.clear();
int index = 0;
if (mpComponent->getLibraryTreeItem()->getOMSElement()) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->interfaces;
for (int i = 0 ; pInterfaces[i] ; i++) {
if (pInterfaces[i]->causality == oms_causality_parameter) {
index++;
QString name = StringHandler::getLastWordAfterDot(pInterfaces[i]->name);
name = name.split(':', QString::SkipEmptyParts).last();
mParameterLabels.append(new Label(name));
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
QLineEdit *pParameterLineEdit = new QLineEdit;
pParameterLineEdit->setValidator(pDoubleValidator);
if (pInterfaces[i]->type == oms_signal_type_real) {
double value;
if (OMSProxy::instance()->getRealParameter(pInterfaces[i]->name, &value)) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_integer) {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() oms_signal_type_integer not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() oms_signal_type_boolean not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_string) {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() oms_signal_type_string not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_enum) {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() oms_signal_type_enum not implemented yet.";
} else if (pInterfaces[i]->type == oms_signal_type_bus) {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() oms_signal_type_bus not implemented yet.";
} else {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() unknown oms_signal_type_enu_t.";
}
mParameterLineEdits.append(pParameterLineEdit);
mOldFMUProperties.mParameterValues.append(pParameterLineEdit->text());
mpParametersLayout->addWidget(mParameterLabels.last(), index, 0);
mpParametersLayout->addWidget(mParameterLineEdits.last(), index, 1);
}
}
}
mpParametersScrollWidget->setVisible(index > 0);
mpParametersLabel->setVisible(index > 0);
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateFMUParameters()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
// Create buttons box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpNameLabel, 0, 0);
pMainLayout->addWidget(mpNameTextBox, 0, 1);
pMainLayout->addWidget(mpParametersScrollArea, 1, 0, 1, 2);
pMainLayout->addWidget(mpButtonBox, 2, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

/*!
* \brief FMUPropertiesDialog::updateFMUParameters
* Slot activated when mpOkButton clicked SIGNAL is raised.\n
* Updates the FMU properties.
*/
void FMUPropertiesDialog::updateFMUParameters()
{
FMUProperties newFMUProperties;
foreach (QLineEdit *pParameterLineEdit, mParameterLineEdits) {
newFMUProperties.mParameterValues.append(pParameterLineEdit->text());
}
// push the change on the undo stack
FMUPropertiesCommand *pFMUPropertiesCommand = new FMUPropertiesCommand(mpComponent, mOldFMUProperties, newFMUProperties);
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->push(pFMUPropertiesCommand);
pModelWidget->updateModelText();
// accept the dialog
accept();
}
70 changes: 70 additions & 0 deletions OMEdit/OMEditGUI/Component/FMUProperties.h
@@ -0,0 +1,70 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#ifndef FMUPROPERTIES_H
#define FMUPROPERTIES_H

#include "Component.h"

class FMUProperties
{
public:
FMUProperties();

QList<QString> mParameterValues;
};

class FMUPropertiesDialog : public QDialog
{
Q_OBJECT
public:
FMUPropertiesDialog(Component *pComponent, QWidget *pParent = 0);
private:
Component *mpComponent;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpParametersLabel;
QGridLayout *mpParametersLayout;
QWidget *mpParametersScrollWidget;
QScrollArea *mpParametersScrollArea;
QList<Label*> mParameterLabels;
QList<QLineEdit*> mParameterLineEdits;
FMUProperties mOldFMUProperties;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void updateFMUParameters();
};

#endif // FMUPROPERTIES_H

0 comments on commit 9ee5459

Please sign in to comment.