Skip to content

Commit

Permalink
Added oms_fmu_info_t to FMUProperties dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 14, 2018
1 parent f9df72e commit 1fae0b2
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 72 deletions.
51 changes: 35 additions & 16 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -2091,22 +2091,33 @@ bool Component::checkEnumerationDisplayString(QString &displayString, const QStr
*/
void Component::updateToolTip()
{
QString comment = mpComponentInfo->getComment().replace("\\\"", "\"");
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
comment = pOMCProxy->makeDocumentationUriToFileName(comment);
// since tooltips can't handle file:// scheme so we have to remove it in order to display images and make links work.
#ifdef WIN32
comment.replace("src=\"file:///", "src=\"");
#else
comment.replace("src=\"file://", "src=\"");
#endif

if ((mIsInheritedComponent || mComponentType == Component::Port) && mpReferenceComponent) {
setToolTip(tr("<b>%1</b> %2<br/>%3<br /><br />Component declared in %4").arg(mpComponentInfo->getClassName())
.arg(mpComponentInfo->getName()).arg(comment)
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
if (!mpParentComponent) { // root component
setToolTip(mpLibraryTreeItem->getTooltip());
} else {
setToolTip(QString("%1 %2<br />%3: %4<br />%5: %6")
.arg(Helper::name).arg(mpComponentInfo->getName())
.arg(Helper::type).arg(OMSProxy::getSignalTypeString(mpComponentInfo->getOMSSignalType()))
.arg(tr("Causality")).arg(OMSProxy::getCausalityString(mpComponentInfo->getOMSCausality())));
}
} else {
setToolTip(tr("<b>%1</b> %2<br/>%3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()).arg(comment));
QString comment = mpComponentInfo->getComment().replace("\\\"", "\"");
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
comment = pOMCProxy->makeDocumentationUriToFileName(comment);
// since tooltips can't handle file:// scheme so we have to remove it in order to display images and make links work.
#ifdef WIN32
comment.replace("src=\"file:///", "src=\"");
#else
comment.replace("src=\"file://", "src=\"");
#endif

if ((mIsInheritedComponent || mComponentType == Component::Port) && mpReferenceComponent) {
setToolTip(tr("<b>%1</b> %2<br/>%3<br /><br />Component declared in %4").arg(mpComponentInfo->getClassName())
.arg(mpComponentInfo->getName()).arg(comment)
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
} else {
setToolTip(tr("<b>%1</b> %2<br/>%3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()).arg(comment));
}
}
}

Expand Down Expand Up @@ -2426,7 +2437,15 @@ void Component::componentCommentHasChanged()
void Component::componentNameHasChanged()
{
updateToolTip();
displayTextChangedRecursive();
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
mpLibraryTreeItem->setName(mpComponentInfo->getName());
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->updateLibraryTreeItem(mpLibraryTreeItem);
if (mpDefaultComponentText) {
mpDefaultComponentText->setTextString(mpComponentInfo->getName());
}
} else {
displayTextChangedRecursive();
}
update();
}

Expand Down
139 changes: 113 additions & 26 deletions OMEdit/OMEditGUI/Component/FMUProperties.cpp
Expand Up @@ -33,6 +33,7 @@

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

FMUProperties::FMUProperties()
{
Expand All @@ -51,22 +52,89 @@ FMUProperties::FMUProperties()
FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent)
: QDialog(pParent)
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("SubModel Attributes")));
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("FMU Properties")));
setAttribute(Qt::WA_DeleteOnClose);
mpComponent = pComponent;
// heading
mpHeading = Utilities::getHeadingLabel(tr("FMU Properties"));
// horizontal line
mpHorizontalLine = Utilities::getHeadingLine();
// 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);
// FMU Info
const oms_fmu_info_t *pFMUInfo = mpComponent->getLibraryTreeItem()->getFMUInfo();
mpGeneralGroupBox = new QGroupBox(Helper::general);
mpDescriptionLabel = new Label(QString("%1:").arg(Helper::description));
mpDescriptionValueLabel = new Label(QString(pFMUInfo->description));
mpFMUKindLabel = new Label(tr("FMU Kind:"));
mpFMUKindValueLabel = new Label(OMSProxy::getFMUKindString(pFMUInfo->fmiKind));
mpFMIVersionLabel = new Label(tr("FMI Version:"));
mpFMIVersionValueLabel = new Label(QString(pFMUInfo->fmiVersion));
mpGenerationToolLabel = new Label(tr("Generation Tool:"));
mpGenerationToolValueLabel = new Label(QString(pFMUInfo->generationTool));
mpGuidLabel = new Label(tr("Guid:"));
mpGuidValueLabel = new Label(QString(pFMUInfo->guid));
mpGenerationTimeLabel = new Label(tr("Generation Time:"));
mpGenerationTimeValueLabel = new Label(QString(pFMUInfo->generationDateAndTime));
mpModelNameLabel = new Label(tr("Model Name:"));
mpModelNameValueLabel = new Label(QString(pFMUInfo->modelName));
QGridLayout *pGeneralLayout = new QGridLayout;
pGeneralLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pGeneralLayout->addWidget(mpDescriptionLabel, 0, 0);
pGeneralLayout->addWidget(mpDescriptionValueLabel, 0, 1);
pGeneralLayout->addWidget(mpFMUKindLabel, 1, 0);
pGeneralLayout->addWidget(mpFMUKindValueLabel, 1, 1);
pGeneralLayout->addWidget(mpFMIVersionLabel, 2, 0);
pGeneralLayout->addWidget(mpFMIVersionValueLabel, 2, 1);
pGeneralLayout->addWidget(mpGenerationToolLabel, 3, 0);
pGeneralLayout->addWidget(mpGenerationTimeValueLabel, 3, 1);
pGeneralLayout->addWidget(mpGuidLabel, 4, 0);
pGeneralLayout->addWidget(mpGuidValueLabel, 4, 1);
pGeneralLayout->addWidget(mpGenerationTimeLabel, 5, 0);
pGeneralLayout->addWidget(mpGenerationTimeValueLabel, 5, 1);
pGeneralLayout->addWidget(mpModelNameLabel, 6, 0);
pGeneralLayout->addWidget(mpModelNameValueLabel, 6, 1);
mpGeneralGroupBox->setLayout(pGeneralLayout);
// FMU capabilities
mpCapabilitiesGroupBox = new QGroupBox(tr("Capabilities"));
mpCanBeInstantiatedOnlyOncePerProcessLabel = new Label("canBeInstantiatedOnlyOncePerProcess:");
mpCanBeInstantiatedOnlyOncePerProcessValueLabel = new Label(pFMUInfo->canBeInstantiatedOnlyOncePerProcess ? "true" : "false");
mpCanGetAndSetFMUStateLabel = new Label("canGetAndSetFMUstate:");
mpCanGetAndSetFMUStateValueLabel = new Label(pFMUInfo->canGetAndSetFMUstate ? "true" : "false");
mpCanNotUseMemoryManagementFunctionsLabel = new Label("canNotUseMemoryManagementFunctions:");
mpCanNotUseMemoryManagementFunctionsValueLabel = new Label(pFMUInfo->canNotUseMemoryManagementFunctions ? "true" : "false");
mpCanSerializeFMUStateLabel = new Label("canSerializeFMUstate:");
mpCanSerializeFMUStateValueLabel = new Label(pFMUInfo->canSerializeFMUstate ? "true" : "false");
mpCompletedIntegratorStepNotNeededLabel = new Label("completedIntegratorStepNotNeeded:");
mpCompletedIntegratorStepNotNeededValueLabel = new Label(pFMUInfo->completedIntegratorStepNotNeeded ? "true" : "false");
mpNeedsExecutionToolLabel = new Label("needsExecutionTool:");
mpNeedsExecutionToolValueLabel = new Label(pFMUInfo->needsExecutionTool ? "true" : "false");
mpProvidesDirectionalDerivativeLabel = new Label("providesDirectionalDerivative:");
mpProvidesDirectionalDerivativeValueLabel = new Label(pFMUInfo->providesDirectionalDerivative ? "true" : "false");
QGridLayout *pCapabilitiesGridLayout = new QGridLayout;
pCapabilitiesGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pCapabilitiesGridLayout->addWidget(mpCanBeInstantiatedOnlyOncePerProcessLabel, 0, 0);
pCapabilitiesGridLayout->addWidget(mpCanBeInstantiatedOnlyOncePerProcessValueLabel, 0, 1);
pCapabilitiesGridLayout->addWidget(mpCanGetAndSetFMUStateLabel, 1, 0);
pCapabilitiesGridLayout->addWidget(mpCanGetAndSetFMUStateValueLabel, 1, 1);
pCapabilitiesGridLayout->addWidget(mpCanNotUseMemoryManagementFunctionsLabel, 2, 0);
pCapabilitiesGridLayout->addWidget(mpCanNotUseMemoryManagementFunctionsValueLabel, 2, 1);
pCapabilitiesGridLayout->addWidget(mpCanSerializeFMUStateLabel, 3, 0);
pCapabilitiesGridLayout->addWidget(mpCanSerializeFMUStateValueLabel, 3, 1);
pCapabilitiesGridLayout->addWidget(mpCompletedIntegratorStepNotNeededLabel, 4, 0);
pCapabilitiesGridLayout->addWidget(mpCompletedIntegratorStepNotNeededValueLabel, 4, 1);
pCapabilitiesGridLayout->addWidget(mpNeedsExecutionToolLabel, 5, 0);
pCapabilitiesGridLayout->addWidget(mpNeedsExecutionToolValueLabel, 5, 1);
pCapabilitiesGridLayout->addWidget(mpProvidesDirectionalDerivativeLabel, 6, 0);
pCapabilitiesGridLayout->addWidget(mpProvidesDirectionalDerivativeValueLabel, 6, 1);
mpCapabilitiesGroupBox->setLayout(pCapabilitiesGridLayout);
// FMU Parameters
ParametersScrollArea *pParametersScrollArea = new ParametersScrollArea;
pParametersScrollArea->setBackgroundRole(QPalette::NoRole);
pParametersScrollArea->getLayout()->setContentsMargins(0, 0, 0, 0);
GroupBox *pParametersGroupBox = new GroupBox("Parameters");
pParametersScrollArea->addGroupBox(pParametersGroupBox);
mParameterLabels.clear();
mParameterLineEdits.clear();
int index = 0;
Expand All @@ -78,22 +146,27 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
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);
bool status = false;
if (pInterfaces[i]->type == oms_signal_type_real) {
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pParameterLineEdit->setValidator(pDoubleValidator);
double value;
if (OMSProxy::instance()->getRealParameter(pInterfaces[i]->name, &value)) {
if ((status = OMSProxy::instance()->getRealParameter(pInterfaces[i]->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 (OMSProxy::instance()->getIntegerParameter(pInterfaces[i]->name, &value)) {
if ((status = OMSProxy::instance()->getIntegerParameter(pInterfaces[i]->name, &value))) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_boolean) {
int value;
if (OMSProxy::instance()->getBooleanParameter(pInterfaces[i]->name, &value)) {
QIntValidator *pIntValidator = new QIntValidator(this);
pParameterLineEdit->setValidator(pIntValidator);
bool value;
if ((status = OMSProxy::instance()->getBooleanParameter(pInterfaces[i]->name, &value))) {
pParameterLineEdit->setText(QString::number(value));
}
} else if (pInterfaces[i]->type == oms_signal_type_string) {
Expand All @@ -105,15 +178,23 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
} else {
qDebug() << "OMSSubModelAttributes::OMSSubModelAttributes() unknown oms_signal_type_enu_t.";
}
if (!status) {
pParameterLineEdit->setPlaceholderText("unknown");
}
mParameterLineEdits.append(pParameterLineEdit);
mOldFMUProperties.mParameterValues.append(pParameterLineEdit->text());
mpParametersLayout->addWidget(mParameterLabels.last(), index, 0);
mpParametersLayout->addWidget(mParameterLineEdits.last(), index, 1);
GroupBox *pParametersGroupBox = pParametersScrollArea->getGroupBox("Parameters");
if (pParametersGroupBox) {
pParametersGroupBox->show();
QGridLayout *pGroupBoxGridLayout = pParametersGroupBox->getGridLayout();
int layoutIndex = pGroupBoxGridLayout->rowCount();
int columnIndex = 0;
pGroupBoxGridLayout->addWidget(mParameterLabels.last(), layoutIndex, columnIndex++);
pGroupBoxGridLayout->addWidget(mParameterLineEdits.last(), layoutIndex, columnIndex++);
}
}
}
}
mpParametersScrollWidget->setVisible(index > 0);
mpParametersLabel->setVisible(index > 0);
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
Expand All @@ -128,10 +209,14 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
// 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);
pMainLayout->addWidget(mpHeading, 0, 0, 1, 2);
pMainLayout->addWidget(mpHorizontalLine, 1, 0, 1, 2);
pMainLayout->addWidget(mpNameLabel, 2, 0);
pMainLayout->addWidget(mpNameTextBox, 2, 1);
pMainLayout->addWidget(mpGeneralGroupBox, 3, 0, 1, 2);
pMainLayout->addWidget(mpCapabilitiesGroupBox, 4, 0, 1, 2);
pMainLayout->addWidget(pParametersScrollArea, 5, 0, 1, 2);
pMainLayout->addWidget(mpButtonBox, 6, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

Expand All @@ -142,12 +227,14 @@ FMUPropertiesDialog::FMUPropertiesDialog(Component *pComponent, QWidget *pParent
*/
void FMUPropertiesDialog::updateFMUParameters()
{
QString oldName = mpComponent->getLibraryTreeItem()->getNameStructure();
QString newName = QString("%1.%2").arg(mpComponent->getLibraryTreeItem()->parent()->getNameStructure(), mpNameTextBox->text());
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);
FMUPropertiesCommand *pFMUPropertiesCommand = new FMUPropertiesCommand(mpComponent, oldName, newName, mOldFMUProperties, newFMUProperties);
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->push(pFMUPropertiesCommand);
pModelWidget->updateModelText();
Expand Down
36 changes: 32 additions & 4 deletions OMEdit/OMEditGUI/Component/FMUProperties.h
Expand Up @@ -51,12 +51,40 @@ class FMUPropertiesDialog : public QDialog
FMUPropertiesDialog(Component *pComponent, QWidget *pParent = 0);
private:
Component *mpComponent;
Label *mpHeading;
QFrame *mpHorizontalLine;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpParametersLabel;
QGridLayout *mpParametersLayout;
QWidget *mpParametersScrollWidget;
QScrollArea *mpParametersScrollArea;
QGroupBox *mpGeneralGroupBox;
Label *mpDescriptionLabel;
Label *mpDescriptionValueLabel;
Label *mpFMUKindLabel;
Label *mpFMUKindValueLabel;
Label *mpFMIVersionLabel;
Label *mpFMIVersionValueLabel;
Label *mpGenerationToolLabel;
Label *mpGenerationToolValueLabel;
Label *mpGuidLabel;
Label *mpGuidValueLabel;
Label *mpGenerationTimeLabel;
Label *mpGenerationTimeValueLabel;
Label *mpModelNameLabel;
Label *mpModelNameValueLabel;
QGroupBox *mpCapabilitiesGroupBox;
Label *mpCanBeInstantiatedOnlyOncePerProcessLabel;
Label *mpCanBeInstantiatedOnlyOncePerProcessValueLabel;
Label *mpCanGetAndSetFMUStateLabel;
Label *mpCanGetAndSetFMUStateValueLabel;
Label *mpCanNotUseMemoryManagementFunctionsLabel;
Label *mpCanNotUseMemoryManagementFunctionsValueLabel;
Label *mpCanSerializeFMUStateLabel;
Label *mpCanSerializeFMUStateValueLabel;
Label *mpCompletedIntegratorStepNotNeededLabel;
Label *mpCompletedIntegratorStepNotNeededValueLabel;
Label *mpNeedsExecutionToolLabel;
Label *mpNeedsExecutionToolValueLabel;
Label *mpProvidesDirectionalDerivativeLabel;
Label *mpProvidesDirectionalDerivativeValueLabel;
QList<Label*> mParameterLabels;
QList<QLineEdit*> mParameterLineEdits;
FMUProperties mOldFMUProperties;
Expand Down
18 changes: 16 additions & 2 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1785,11 +1785,13 @@ void RenameCompositeModelCommand::undo()
mpCompositeModelEditor->getModelWidget()->setWindowTitle(mOldCompositeModelName);
}

FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, FMUProperties oldFMUProperties, FMUProperties newFMUProperties,
QUndoCommand *pParent)
FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, QString oldName, QString newName, FMUProperties oldFMUProperties,
FMUProperties newFMUProperties, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpComponent = pComponent;
mOldName = oldName;
mNewName = newName;
mOldFMUProperties = oldFMUProperties;
mNewFMUProperties = newFMUProperties;
setText(QString("Update FMU %1 Parameters").arg(mpComponent->getName()));
Expand All @@ -1801,6 +1803,12 @@ FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, FMUProperties
*/
void FMUPropertiesCommand::redo()
{
// Rename
if (OMSProxy::instance()->rename(mOldName, mNewName)) {
mpComponent->getComponentInfo()->setName(mNewName.split('.').last());
mpComponent->componentNameHasChanged();
}
// Parameters
int index = 0;
if (mpComponent->getLibraryTreeItem()->getOMSElement()) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->interfaces;
Expand Down Expand Up @@ -1834,6 +1842,12 @@ void FMUPropertiesCommand::redo()
*/
void FMUPropertiesCommand::undo()
{
// Rename
if (OMSProxy::instance()->rename(mNewName, mOldName)) {
mpComponent->getComponentInfo()->setName(mOldName.split('.').last());
mpComponent->componentNameHasChanged();
}
// Parameters
int index = 0;
if (mpComponent->getLibraryTreeItem()->getOMSElement()) {
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->interfaces;
Expand Down
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -399,11 +399,14 @@ class RenameCompositeModelCommand : public QUndoCommand
class FMUPropertiesCommand : public QUndoCommand
{
public:
FMUPropertiesCommand(Component *pComponent, FMUProperties oldFMUProperties, FMUProperties newFMUProperties, QUndoCommand *pParent = 0);
FMUPropertiesCommand(Component *pComponent, QString oldName, QString newName, FMUProperties oldFMUProperties,
FMUProperties newFMUProperties, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Component *mpComponent;
QString mOldName;
QString mNewName;
FMUProperties mOldFMUProperties;
FMUProperties mNewFMUProperties;
};
Expand Down

0 comments on commit 1fae0b2

Please sign in to comment.