Skip to content

Commit

Permalink
Ticket-5848: First level nested components detected by OMSens (#775)
Browse files Browse the repository at this point in the history
* Ticket-5848: First level nested components is now detected by the OMSens plugin
  • Loading branch information
JKRT committed Apr 6, 2020
1 parent 034e66b commit 4f16050
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -4464,6 +4464,7 @@ AboutOMEditDialog::AboutOMEditDialog(MainWindow *pMainWindow)
"<li>Dietmar Winkler</li>"
"<li>Anatoly Severin<li>"
"<li>Adrian Pop - <u><a href=\"mailto:adrian.pop@liu.se\">adrian.pop@liu.se</a></u></li>"
"<li>John Tinnerholm - <u><a href=\"mailto:john.tinnerholm@liu.se\">john.tinnerholm@liu.se</a></u></li>"
"</ul>")
.arg(Helper::applicationName,
Helper::applicationIntroText,
Expand Down
41 changes: 27 additions & 14 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -6201,33 +6201,46 @@ void ModelWidget::associateBusWithConnectors(QString busName)
/*!
* \brief ModelWidget::toOMSensJson
* Creates a list of QVariant containing the model information needed by OMSens.
* Currently only works for REAL types (OMSens currently have similar limitations)
* \return
*/
QList<QVariant> ModelWidget::toOMSensData()
{
QList<QVariant> omSensData;
if (!mpDiagramGraphicsView) {
return omSensData;
}
QStringList inputVariables;
QStringList outputVariables;
QStringList parameters;
QStringList auxVariables;

if (mpDiagramGraphicsView) {
foreach (Component *pComponent, mpDiagramGraphicsView->getComponentsList()) {
ComponentInfo *pComponentInfo = pComponent->getComponentInfo();
if ((pComponentInfo->getCausality().compare("input") == 0) && ((pComponentInfo->getClassName().compare("Real") == 0)
|| (pComponentInfo->getClassName().compare("Modelica.Blocks.Interfaces.RealInput") == 0))) {
inputVariables.append(pComponentInfo->getName());
} else if ((pComponentInfo->getCausality().compare("output") == 0) && ((pComponentInfo->getClassName().compare("Real") == 0)
|| (pComponentInfo->getClassName().compare("Modelica.Blocks.Interfaces.RealOutput") == 0))) {
outputVariables.append(pComponentInfo->getName());
} else if ((pComponentInfo->getVariablity().compare("parameter") == 0) && (pComponentInfo->getClassName().compare("Real") == 0)) {
const QString modelicaBlocksInterfacesRealInput = "Modelica.Blocks.Interfaces.RealInput";
const QString modelicaBlocksInterfacesRealOutput = "Modelica.Blocks.Interfaces.RealOutput";
QList<Component*> pInheritedAndComposedComponents;
QList<Component*> pTopMostComponents = mpDiagramGraphicsView->getComponentsList() + mpDiagramGraphicsView->getInheritedComponentsList();
for (Component *pComponent : pTopMostComponents) {
pInheritedAndComposedComponents = pComponent->getComponentsList() + pComponent->getInheritedComponentsList();
pInheritedAndComposedComponents.append(pComponent);
for (auto component : pInheritedAndComposedComponents) {
ComponentInfo *pComponentInfo = component->getComponentInfo();
auto causality = pComponentInfo->getCausality();
auto variability = pComponentInfo->getVariablity();
const bool classNameIsReal = pComponentInfo->getClassName().compare(QStringLiteral("Real")) == 0;
if (causality.compare(QStringLiteral("input")) == 0) {
if (classNameIsReal || pComponentInfo->getClassName().compare(modelicaBlocksInterfacesRealInput) == 0) {
inputVariables.append(pComponentInfo->getName());
}
} else if (causality.compare(QStringLiteral("output")) == 0) {
if (classNameIsReal || pComponentInfo->getClassName().compare(modelicaBlocksInterfacesRealOutput) == 0) {
outputVariables.append(pComponentInfo->getName());
}
} else if(classNameIsReal && variability.compare(QStringLiteral("parameter")) == 0) {
parameters.append(pComponentInfo->getName());
} else if (pComponentInfo->getClassName().compare("Real") == 0) {
} /* Otherwise we are dealing with an auxiliarly variable */else if (classNameIsReal) {
auxVariables.append(pComponentInfo->getName());
}
}
}

QList<QVariant> omSensData;
omSensData << inputVariables << outputVariables << auxVariables << parameters << mpLibraryTreeItem->getFileName() << mpLibraryTreeItem->getNameStructure();
return omSensData;
}
Expand Down

0 comments on commit 4f16050

Please sign in to comment.