Skip to content

Commit ac459ee

Browse files
committed
Added addFMU, deleteSubModel, getElement and getFMUPath
Updated to the APIs new structure
1 parent 0731b2d commit ac459ee

15 files changed

+385
-104
lines changed

OMEdit/OMEditGUI/Component/Component.cpp

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ ComponentInfo::ComponentInfo(QObject *pParent)
8888
mTLMCausality = StringHandler::getTLMCausality(StringHandler::TLMBidirectional);
8989
mDomain = StringHandler::getTLMDomain(StringHandler::Mechanical);
9090
mOMSCausality = oms_causality_undefined;
91+
mOMSSignalType = oms_signal_type_real;
9192
}
9293

9394
/*!
@@ -139,6 +140,7 @@ void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
139140
mTLMCausality = pComponentInfo->getTLMCausality();
140141
mDomain = pComponentInfo->getDomain();
141142
mOMSCausality = pComponentInfo->getOMSCausality();
143+
mOMSSignalType = pComponentInfo->getOMSSignalType();
142144
}
143145

144146
/*!
@@ -378,7 +380,8 @@ bool ComponentInfo::operator==(const ComponentInfo &componentInfo) const
378380
(componentInfo.getModelFile() == this->getModelFile()) && (componentInfo.getGeometryFile() == this->getGeometryFile()) &&
379381
(componentInfo.getPosition() == this->getPosition()) && (componentInfo.getAngle321() == this->getAngle321()) &&
380382
(componentInfo.getDimensions() == this->getDimensions()) && (componentInfo.getTLMCausality() == this->getTLMCausality()) &&
381-
(componentInfo.getDomain() == this->getDomain()) && (componentInfo.getOMSCausality() == this->getOMSCausality());
383+
(componentInfo.getDomain() == this->getDomain()) && (componentInfo.getOMSCausality() == this->getOMSCausality()) &&
384+
(componentInfo.getOMSSignalType() == this->getOMSSignalType());
382385
}
383386

384387
/*!
@@ -467,7 +470,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString an
467470
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
468471
mpDefaultComponentRectangle->setVisible(true);
469472
mpDefaultComponentText->setVisible(true);
470-
drawSignals();
473+
drawOMSElementConnectors();
471474
} else {
472475
drawComponent();
473476
}
@@ -722,9 +725,55 @@ Component::Component(ComponentInfo *pComponentInfo, LibraryTreeItem *pLibraryTre
722725
mpDefaultComponentText = 0;
723726
mpInputOutputComponentPolygon = new PolygonAnnotation(this);
724727
if (mpComponentInfo->getOMSCausality() == oms_causality_input) {
725-
mpInputOutputComponentPolygon->setFillColor(QColor(0, 0, 127));
728+
switch (mpComponentInfo->getOMSSignalType()) {
729+
case oms_signal_type_integer:
730+
mpInputOutputComponentPolygon->setLineColor(QColor(255,127,0));
731+
mpInputOutputComponentPolygon->setFillColor(QColor(255,127,0));
732+
break;
733+
case oms_signal_type_boolean:
734+
mpInputOutputComponentPolygon->setLineColor(QColor(255,0,255));
735+
mpInputOutputComponentPolygon->setFillColor(QColor(255,0,255));
736+
break;
737+
case oms_signal_type_string:
738+
qDebug() << "oms_signal_type_string not implemented yet.";
739+
break;
740+
case oms_signal_type_enum:
741+
qDebug() << "oms_signal_type_enum not implemented yet.";
742+
break;
743+
case oms_signal_type_bus:
744+
qDebug() << "oms_signal_type_bus not implemented yet.";
745+
break;
746+
case oms_signal_type_real:
747+
default:
748+
mpInputOutputComponentPolygon->setLineColor(QColor(0, 0, 127));
749+
mpInputOutputComponentPolygon->setFillColor(QColor(0, 0, 127));
750+
break;
751+
}
726752
} else if (mpComponentInfo->getOMSCausality() == oms_causality_output) {
727-
mpInputOutputComponentPolygon->setFillColor(QColor(255, 255, 255));
753+
switch (mpComponentInfo->getOMSSignalType()) {
754+
case oms_signal_type_integer:
755+
mpInputOutputComponentPolygon->setLineColor(QColor(255,127,0));
756+
mpInputOutputComponentPolygon->setFillColor(QColor(255,255,255));
757+
break;
758+
case oms_signal_type_boolean:
759+
mpInputOutputComponentPolygon->setLineColor(QColor(255,0,255));
760+
mpInputOutputComponentPolygon->setFillColor(QColor(255,255,255));
761+
break;
762+
case oms_signal_type_string:
763+
qDebug() << "oms_signal_type_string not implemented yet.";
764+
break;
765+
case oms_signal_type_enum:
766+
qDebug() << "oms_signal_type_enum not implemented yet.";
767+
break;
768+
case oms_signal_type_bus:
769+
qDebug() << "oms_signal_type_bus not implemented yet.";
770+
break;
771+
case oms_signal_type_real:
772+
default:
773+
mpInputOutputComponentPolygon->setLineColor(QColor(0, 0, 127));
774+
mpInputOutputComponentPolygon->setFillColor(QColor(255, 255, 255));
775+
break;
776+
}
728777
}
729778
mpStateComponentRectangle = 0;
730779
mHasTransition = false;
@@ -1598,30 +1647,37 @@ void Component::drawInterfacePoints()
15981647
}
15991648
}
16001649

1601-
void Component::drawSignals()
1650+
/*!
1651+
* \brief Component::drawOMSElementConnectors
1652+
* Draws the OMSimulator element connectors.
1653+
*/
1654+
void Component::drawOMSElementConnectors()
16021655
{
1603-
oms_signal_t** pInterfaces = mpLibraryTreeItem->getOMSComponent()->interfaces;
1604-
ComponentInfo *pComponentInfo = 0;
1605-
QString name;
1606-
for (int i = 0 ; pInterfaces[i] ; i++) {
1607-
switch (pInterfaces[i]->causality) {
1608-
case oms_causality_input:
1609-
case oms_causality_output:
1610-
pComponentInfo = new ComponentInfo;
1611-
name = StringHandler::getLastWordAfterDot(pInterfaces[i]->name);
1612-
name = name.split(':', QString::SkipEmptyParts).last();
1613-
pComponentInfo->setName(name);
1614-
//pComponentInfo->setClassName(pInterfaces[i]->type);
1615-
pComponentInfo->setOMSCausality(pInterfaces[i]->causality);
1616-
mComponentsList.append(new Component(pComponentInfo, mpLibraryTreeItem, this));
1617-
break;
1618-
case oms_causality_parameter:
1619-
case oms_causality_undefined:
1620-
default:
1621-
break;
1656+
if (mpLibraryTreeItem->getOMSElement()) {
1657+
oms_connector_t** pInterfaces = mpLibraryTreeItem->getOMSElement()->interfaces;
1658+
ComponentInfo *pComponentInfo = 0;
1659+
QString name;
1660+
for (int i = 0 ; pInterfaces[i] ; i++) {
1661+
switch (pInterfaces[i]->causality) {
1662+
case oms_causality_input:
1663+
case oms_causality_output:
1664+
pComponentInfo = new ComponentInfo;
1665+
name = StringHandler::getLastWordAfterDot(pInterfaces[i]->name);
1666+
name = name.split(':', QString::SkipEmptyParts).last();
1667+
pComponentInfo->setName(name);
1668+
//pComponentInfo->setClassName(pInterfaces[i]->type);
1669+
pComponentInfo->setOMSCausality(pInterfaces[i]->causality);
1670+
pComponentInfo->setOMSSignalType(pInterfaces[i]->type);
1671+
mComponentsList.append(new Component(pComponentInfo, mpLibraryTreeItem, this));
1672+
break;
1673+
case oms_causality_parameter:
1674+
case oms_causality_undefined:
1675+
default:
1676+
break;
1677+
}
16221678
}
1679+
adjustOMSSignals();
16231680
}
1624-
adjustOMSSignals();
16251681
}
16261682

16271683
/*!

OMEdit/OMEditGUI/Component/Component.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class ComponentInfo : public QObject
124124
QString getTLMCausality() const {return mTLMCausality;}
125125
void setOMSCausality(oms_causality_enu_t causality) {mOMSCausality = causality;}
126126
oms_causality_enu_t getOMSCausality() const {return mOMSCausality;}
127+
void setOMSSignalType(oms_signal_type_enu_t signalType) {mOMSSignalType = signalType;}
128+
oms_signal_type_enu_t getOMSSignalType() const {return mOMSSignalType;}
127129
void setDomain(QString domain) {mDomain = domain;}
128130
QString getDomain() const {return mDomain;}
129131
// operator overloading
@@ -161,6 +163,7 @@ class ComponentInfo : public QObject
161163
QString mTLMCausality;
162164
QString mDomain;
163165
oms_causality_enu_t mOMSCausality;
166+
oms_signal_type_enu_t mOMSSignalType;
164167

165168
bool isModiferClassRecord(QString modifierName, Component *pComponent);
166169
};
@@ -298,7 +301,7 @@ class Component : public QObject, public QGraphicsItem
298301
void createDefaultComponent();
299302
void createStateComponent();
300303
void drawInterfacePoints();
301-
void drawSignals();
304+
void drawOMSElementConnectors();
302305
void drawComponent();
303306
void drawInheritedComponentsAndShapes();
304307
void showNonExistingOrDefaultComponentIfNeeded();

OMEdit/OMEditGUI/Component/ComponentProperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,8 +1879,8 @@ OMSSubModelAttributes::OMSSubModelAttributes(Component *pComponent, QWidget *pPa
18791879
mParameterLabels.clear();
18801880
mParameterLineEdits.clear();
18811881
int index = 0;
1882-
if (mpComponent->getLibraryTreeItem()->getOMSComponent()) {
1883-
oms_signal_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSComponent()->interfaces;
1882+
if (mpComponent->getLibraryTreeItem()->getOMSElement()) {
1883+
oms_connector_t** pInterfaces = mpComponent->getLibraryTreeItem()->getOMSElement()->interfaces;
18841884
for (int i = 0 ; pInterfaces[i] ; i++) {
18851885
if (pInterfaces[i]->causality == oms_causality_parameter) {
18861886
index++;

OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,10 @@ void MainWindow::createActions()
32513251
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
32523252
mpTLMCoSimulationAction->setEnabled(false);
32533253
connect(mpTLMCoSimulationAction, SIGNAL(triggered()), SLOT(TLMSimulate()));
3254+
// Add FMU Action
3255+
mpAddFMUAction = new QAction(QIcon(":/Resources/icons/import-fmu.svg"), Helper::addFMU, this);
3256+
mpAddFMUAction->setStatusTip(Helper::addFMUTip);
3257+
32543258
}
32553259

32563260
//! Creates the menus
@@ -3864,6 +3868,12 @@ void MainWindow::createToolbars()
38643868
mpTLMSimulationToolbar->addAction(mpAlignInterfacesAction);
38653869
mpTLMSimulationToolbar->addSeparator();
38663870
mpTLMSimulationToolbar->addAction(mpTLMCoSimulationAction);
3871+
// OMSimulator Toolbar
3872+
mpOMSimulatorToobar = addToolBar(tr("OMSimulator Toolbar"));
3873+
mpOMSimulatorToobar->setObjectName("OMSimulator Toolbar");
3874+
mpOMSimulatorToobar->setAllowedAreas(Qt::TopToolBarArea);
3875+
// add actions to OMSimulator Toolbar
3876+
mpOMSimulatorToobar->addAction(mpAddFMUAction);
38673877
}
38683878

38693879
//! when the dragged object enters the main window

OMEdit/OMEditGUI/MainWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class MainWindow : public QMainWindow
182182
QAction* getFetchInterfaceDataAction() {return mpFetchInterfaceDataAction;}
183183
QAction* getAlignInterfacesAction() {return mpAlignInterfacesAction;}
184184
QAction* getTLMSimulationAction() {return mpTLMCoSimulationAction;}
185+
QAction* getAddFMUAction() {return mpAddFMUAction;}
185186
QAction* getLogCurrentFileAction() {return mpLogCurrentFileAction;}
186187
QAction* getStageCurrentFileForCommitAction() {return mpStageCurrentFileForCommitAction;}
187188
QAction* getUnstageCurrentFileFromCommitAction() {return mpUnstageCurrentFileFromCommitAction;}
@@ -390,6 +391,8 @@ class MainWindow : public QMainWindow
390391
QAction *mpFetchInterfaceDataAction;
391392
QAction *mpAlignInterfacesAction;
392393
QAction *mpTLMCoSimulationAction;
394+
// OMSimulator Actions
395+
QAction *mpAddFMUAction;
393396
// Toolbars
394397
QMenu *mpRecentFilesMenu;
395398
QMenu *mpLibrariesMenu;
@@ -405,6 +408,7 @@ class MainWindow : public QMainWindow
405408
QToolBar *mpReSimulationToolBar;
406409
QToolBar *mpPlotToolBar;
407410
QToolBar *mpTLMSimulationToolbar;
411+
QToolBar *mpOMSimulatorToobar;
408412
QHash<QString, TransformationsWidget*> mTransformationsWidgetHash;
409413
public slots:
410414
void showSearchBrowser();

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ LibraryTreeItem::LibraryTreeItem()
376376
setClassTextAfter("");
377377
setExpanded(false);
378378
setNonExisting(true);
379-
setOMSComponentType(oms_component_none);
380-
setOMSComponent(0);
379+
setOMSElement(0);
381380
}
382381

383382
/*!
@@ -423,6 +422,11 @@ LibraryTreeItem::LibraryTreeItem(LibraryType type, QString text, QString nameStr
423422
setSaveContentsType(LibraryTreeItem::SaveInOneFile);
424423
}
425424
}
425+
} else if (type == LibraryTreeItem::OMS) {
426+
if (!OMSProxy::instance()->getElement(mNameStructure, &mpOMSElement)) {
427+
setOMSElement(0);
428+
}
429+
setSaveContentsType(LibraryTreeItem::SaveInOneFile);
426430
} else {
427431
setSaveContentsType(LibraryTreeItem::SaveInOneFile);
428432
}
@@ -431,8 +435,6 @@ LibraryTreeItem::LibraryTreeItem(LibraryType type, QString text, QString nameStr
431435
setClassTextAfter("");
432436
setExpanded(false);
433437
setNonExisting(false);
434-
setOMSComponentType(oms_component_none);
435-
setOMSComponent(0);
436438
}
437439

438440
/*!
@@ -585,13 +587,17 @@ QIcon LibraryTreeItem::getLibraryTreeItemIcon() const
585587
if (mLibraryType == LibraryTreeItem::CompositeModel) {
586588
return QIcon(":/Resources/icons/tlm-icon.svg");
587589
} else if (mLibraryType == LibraryTreeItem::OMS) {
588-
switch (getOMSComponentType()) {
589-
case oms_component_fmu:
590-
return QIcon(":/Resources/icons/fmu-icon.svg");
591-
case oms_component_port:
592-
return QIcon(":/Resources/icons/connect-mode.svg");
593-
default:
594-
return QIcon(":/Resources/icons/tlm-icon.svg");
590+
if (mpOMSElement) {
591+
switch (mpOMSElement->type) {
592+
case oms_component_fmu:
593+
return QIcon(":/Resources/icons/fmu-icon.svg");
594+
case oms_component_port:
595+
return QIcon(":/Resources/icons/connect-mode.svg");
596+
default:
597+
return QIcon(":/Resources/icons/tlm-icon.svg");
598+
}
599+
} else {
600+
return QIcon(":/Resources/icons/tlm-icon.svg");
595601
}
596602
} else if (mLibraryType == LibraryTreeItem::Modelica) {
597603
switch (getRestriction()) {
@@ -1895,7 +1901,16 @@ bool LibraryTreeModel::unloadOMSModel(LibraryTreeItem *pLibraryTreeItem, bool as
18951901
}
18961902
}
18971903
// unload OMSimulator model
1898-
if (OMSProxy::instance()->unloadModel(pLibraryTreeItem->getNameStructure())) {
1904+
bool deleted = false;
1905+
if (pLibraryTreeItem->isTopLevel() && OMSProxy::instance()->unloadModel(pLibraryTreeItem->getNameStructure())) {
1906+
deleted = true;
1907+
} else if (!pLibraryTreeItem->isTopLevel()) {
1908+
deleted = true;
1909+
} else {
1910+
deleted = false;
1911+
}
1912+
// if deleted
1913+
if (deleted) {
18991914
/* QSortFilterProxy::filterAcceptRows changes the expand/collapse behavior of indexes or I am using it in some stupid way.
19001915
* If index is expanded and we delete it then the next sibling index automatically becomes expanded.
19011916
* The following code overcomes this issue. It stores the next index expand state and then apply it after deletion.
@@ -2425,26 +2440,23 @@ void LibraryTreeModel::createLibraryTreeItems(LibraryTreeItem *pLibraryTreeItem)
24252440
}
24262441
}
24272442
} else if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
2428-
oms_component_t** pComponents = NULL;
2429-
if (OMSProxy::instance()->getComponents(pLibraryTreeItem->getNameStructure(), &pComponents)) {
2430-
for (int i = 0 ; pComponents[i] ; i++) {
2431-
QString name = StringHandler::getLastWordAfterDot(pComponents[i]->name);
2443+
oms_element_t** pElements = NULL;
2444+
if (pLibraryTreeItem->getOMSElement() && pLibraryTreeItem->getOMSElement()->type == oms_component_fmi &&
2445+
OMSProxy::instance()->getElements(pLibraryTreeItem->getNameStructure(), &pElements)) {
2446+
for (int i = 0 ; pElements[i] ; i++) {
2447+
QString name = StringHandler::getLastWordAfterDot(pElements[i]->name);
2448+
QString path;
2449+
OMSProxy::instance()->getFMUPath(pElements[i]->name, &path);
24322450
LibraryTreeItem *pComponentLibraryTreeItem = createLibraryTreeItemImpl(LibraryTreeItem::OMS, name,
24332451
QString("%1.%2").arg(pLibraryTreeItem->getNameStructure())
2434-
.arg(name), pLibraryTreeItem->getFileName(),
2435-
pLibraryTreeItem->isSaved(), pLibraryTreeItem);
2436-
pComponentLibraryTreeItem->setOMSComponentType(pComponents[i]->type);
2437-
pComponentLibraryTreeItem->setOMSComponent(pComponents[i]);
2438-
for (int j = 0 ; pComponents[i]->interfaces[j] ; j++) {
2439-
QString name = StringHandler::getLastWordAfterDot(pComponents[i]->interfaces[j]->name);
2452+
.arg(name), path, pLibraryTreeItem->isSaved(),
2453+
pLibraryTreeItem);
2454+
for (int j = 0 ; pElements[i]->interfaces[j] ; j++) {
2455+
QString name = StringHandler::getLastWordAfterDot(pElements[i]->interfaces[j]->name);
24402456
name = name.split(':', QString::SkipEmptyParts).last();
2441-
LibraryTreeItem *pInterfaceLibraryTreeItem = createLibraryTreeItemImpl(LibraryTreeItem::OMS, name,
2442-
QString("%1.%2")
2443-
.arg(pComponentLibraryTreeItem->getNameStructure())
2444-
.arg(name), pComponentLibraryTreeItem->getFileName(),
2445-
pLibraryTreeItem->isSaved(), pComponentLibraryTreeItem);
2446-
pInterfaceLibraryTreeItem->setOMSComponentType(oms_component_port);
2447-
pInterfaceLibraryTreeItem->setOMSComponent(0);
2457+
createLibraryTreeItemImpl(LibraryTreeItem::OMS, name,
2458+
QString("%1.%2").arg(pComponentLibraryTreeItem->getNameStructure()).arg(name),
2459+
pComponentLibraryTreeItem->getFileName(), pLibraryTreeItem->isSaved(), pComponentLibraryTreeItem);
24482460
}
24492461
}
24502462
}
@@ -4028,11 +4040,6 @@ void LibraryWidget::openOMSModelFile(QFileInfo fileInfo, bool showProgress)
40284040
LibraryTreeItem *pLibraryTreeItem = 0;
40294041
pLibraryTreeItem = mpLibraryTreeModel->createLibraryTreeItem(LibraryTreeItem::OMS, modelName, modelName, fileInfo.absoluteFilePath(), true,
40304042
mpLibraryTreeModel->getRootLibraryTreeItem());
4031-
// set the component type
4032-
oms_component_type_enu_t componentType = oms_component_none;
4033-
OMSProxy::instance()->getComponentType(pLibraryTreeItem->getNameStructure(), &componentType);
4034-
pLibraryTreeItem->setOMSComponentType(componentType);
4035-
pLibraryTreeItem->setOMSComponent(0);
40364043
// add the item to recent files list
40374044
if (pLibraryTreeItem) {
40384045
MainWindow::instance()->addRecentFile(fileInfo.absoluteFilePath(), Helper::utf8);

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ class LibraryTreeItem : public QObject
147147
bool isExpanded() const {return mExpanded;}
148148
void setNonExisting(bool nonExisting) {mNonExisting = nonExisting;}
149149
bool isNonExisting() const {return mNonExisting;}
150-
void setOMSComponentType(oms_component_type_enu_t type) {mOMSComponentType = type;}
151-
oms_component_type_enu_t getOMSComponentType() const {return mOMSComponentType;}
152-
void setOMSComponent(oms_component_t *pOMSComponent) {mpOMSComponent = pOMSComponent;}
153-
oms_component_t* getOMSComponent() const {return mpOMSComponent;}
150+
void setOMSElement(oms_element_t *pOMSComponent) {mpOMSElement = pOMSComponent;}
151+
oms_element_t* getOMSElement() const {return mpOMSElement;}
154152
QString getTooltip() const;
155153
QIcon getLibraryTreeItemIcon() const;
156154
bool inRange(int lineNumber);
@@ -198,8 +196,7 @@ class LibraryTreeItem : public QObject
198196
QString mClassTextAfter;
199197
bool mExpanded;
200198
bool mNonExisting;
201-
oms_component_type_enu_t mOMSComponentType;
202-
oms_component_t *mpOMSComponent;
199+
oms_element_t *mpOMSElement;
203200
signals:
204201
void loaded(LibraryTreeItem *pLibraryTreeItem);
205202
void loadedForComponent();

0 commit comments

Comments
 (0)