Skip to content

Commit

Permalink
Use oms3_import to load a model
Browse files Browse the repository at this point in the history
Built-in icons for the connectors
Draw the systems and connectors in the ModelWidget
  • Loading branch information
adeas31 committed Nov 5, 2018
1 parent b854125 commit 59832c1
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 11 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -569,7 +569,7 @@ Component::Component(Component *pComponent, Component *pParentComponent, Compone
mpInputOutputComponentPolygon = 0;
mHasTransition = false;
mIsInitialState = false;
if (mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
if (mpLibraryTreeItem && mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
mShapesList.append(new PolygonAnnotation(mpReferenceComponent->getInputOutputComponentPolygon(), this));
} else {
drawInheritedComponentsAndShapes();
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1820,6 +1820,7 @@ void AddSystemCommand::redo()
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
mpLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, "",
pParentLibraryTreeItem->isSaved(), pParentLibraryTreeItem, pOMSElement, 0);
mpLibraryTreeItem->handleIconUpdated();
}
// add the FMU to view
ComponentInfo *pComponentInfo = new ComponentInfo;
Expand Down
48 changes: 43 additions & 5 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -388,6 +388,39 @@ QIcon LibraryTreeItem::getLibraryTreeItemIcon() const
if (mLibraryType == LibraryTreeItem::CompositeModel) {
return QIcon(":/Resources/icons/tlm-icon.svg");
} else if (mLibraryType == LibraryTreeItem::OMS) {
if (mpOMSConnector) {
switch (mpOMSConnector->type) {
case oms_signal_type_real:
switch (mpOMSConnector->causality) {
case oms_causality_input:
return QIcon(":/Resources/icons/real-input-connector.svg");
case oms_causality_output:
return QIcon(":/Resources/icons/real-output-connector.svg");
default:
break;
}
case oms_signal_type_integer:
switch (mpOMSConnector->causality) {
case oms_causality_input:
return QIcon(":/Resources/icons/integer-input-connector.svg");
case oms_causality_output:
return QIcon(":/Resources/icons/integer-output-connector.svg");
default:
break;
}
case oms_signal_type_boolean:
switch (mpOMSConnector->causality) {
case oms_causality_input:
return QIcon(":/Resources/icons/boolean-input-connector.svg");
case oms_causality_output:
return QIcon(":/Resources/icons/boolean-output-connector.svg");
default:
break;
}
default:
break;
}
}
return QIcon(":/Resources/icons/tlm-icon.svg");
} else if (mLibraryType == LibraryTreeItem::Modelica) {
switch (getRestriction()) {
Expand Down Expand Up @@ -1246,7 +1279,7 @@ LibraryTreeItem* LibraryTreeModel::createLibraryTreeItem(QString name, QString n
QModelIndex index = libraryTreeItemIndex(pParentLibraryTreeItem);
beginInsertRows(index, row, row);
LibraryTreeItem *pLibraryTreeItem = createOMSLibraryTreeItemImpl(name, nameStructure, path, isSaved, pParentLibraryTreeItem,
pOMSElement, pOMSConnector, row);
pOMSElement, pOMSConnector);
pParentLibraryTreeItem->insertChild(row, pLibraryTreeItem);
endInsertRows();
// create library tree items
Expand Down Expand Up @@ -1466,7 +1499,7 @@ void LibraryTreeModel::loadLibraryTreeItemPixmap(LibraryTreeItem *pLibraryTreeIt
showModelWidget(pLibraryTreeItem, false);
}
GraphicsView *pGraphicsView = pLibraryTreeItem->getModelWidget()->getIconGraphicsView();
if (pGraphicsView->hasAnnotation()) {
if (pGraphicsView && pGraphicsView->hasAnnotation()) {
qreal left = pGraphicsView->mCoOrdinateSystem.getExtent().at(0).x();
qreal bottom = pGraphicsView->mCoOrdinateSystem.getExtent().at(0).y();
qreal right = pGraphicsView->mCoOrdinateSystem.getExtent().at(1).x();
Expand Down Expand Up @@ -2333,10 +2366,16 @@ void LibraryTreeModel::createLibraryTreeItems(LibraryTreeItem *pLibraryTreeItem)
for (int i = 0 ; pElements[i] ; i++) {
QString name = QString(pElements[i]->name);
createLibraryTreeItem(name, QString("%1.%2").arg(pLibraryTreeItem->getNameStructure()).arg(name),
"", pLibraryTreeItem->isSaved(), pLibraryTreeItem, pElements[i], 0);
pLibraryTreeItem->getFileName(), pLibraryTreeItem->isSaved(), pLibraryTreeItem, pElements[i], 0);
}
}
} else if (pLibraryTreeItem->getOMSElement()) {
for (int i = 0 ; pLibraryTreeItem->getOMSElement()->elements[i] ; i++) {
QString name = QString(pLibraryTreeItem->getOMSElement()->elements[i]->name);
createLibraryTreeItem(name, QString("%1.%2").arg(pLibraryTreeItem->getNameStructure()).arg(name),
pLibraryTreeItem->getFileName(), pLibraryTreeItem->isSaved(), pLibraryTreeItem,
pLibraryTreeItem->getOMSElement()->elements[i], 0);
}
createOMSConnectorLibraryTreeItems(pLibraryTreeItem);
}
} else {
Expand Down Expand Up @@ -2475,12 +2514,11 @@ LibraryTreeItem* LibraryTreeModel::createLibraryTreeItemImpl(LibraryTreeItem::Li
* \param pParentLibraryTreeItem
* \param pOMSElement
* \param pOMSConnector
* \param row
* \return
*/
LibraryTreeItem* LibraryTreeModel::createOMSLibraryTreeItemImpl(QString name, QString nameStructure, QString path, bool isSaved,
LibraryTreeItem *pParentLibraryTreeItem, oms3_element_t *pOMSElement,
oms_connector_t *pOMSConnector, int row)
oms_connector_t *pOMSConnector)
{
OMCInterface::getClassInformation_res classInformation;
LibraryTreeItem *pLibraryTreeItem = new LibraryTreeItem(LibraryTreeItem::OMS, name, nameStructure, classInformation, path, isSaved, pParentLibraryTreeItem);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -304,7 +304,7 @@ class LibraryTreeModel : public QAbstractItemModel
LibraryTreeItem *pParentLibraryTreeItem, int row = -1);
LibraryTreeItem* createOMSLibraryTreeItemImpl(QString name, QString nameStructure, QString path, bool isSaved,
LibraryTreeItem *pParentLibraryTreeItem, oms3_element_t *pOMSElement,
oms_connector_t *pOMSConnector, int row = -1);
oms_connector_t *pOMSConnector);
void createOMSConnectorLibraryTreeItems(LibraryTreeItem *pLibraryTreeItem);
void unloadClassHelper(LibraryTreeItem *pLibraryTreeItem, LibraryTreeItem *pParentLibraryTreeItem);
void unloadClassChildren(LibraryTreeItem *pLibraryTreeItem);
Expand Down
24 changes: 23 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -5698,12 +5698,32 @@ void ModelWidget::drawOMSModelIconElements()
mpIconGraphicsView->addShapeToList(pTextAnnotation);
mpIconGraphicsView->addItem(pTextAnnotation);
}
for (int i = 0 ; i < mpLibraryTreeItem->childrenSize() ; i++) {
LibraryTreeItem *pChildLibraryTreeItem = mpLibraryTreeItem->childAt(i);
if (pChildLibraryTreeItem->getOMSConnector()) {
double x = 0.5;
double y = 0.5;
if (pChildLibraryTreeItem->getOMSConnector()->geometry) {
x = pChildLibraryTreeItem->getOMSConnector()->geometry->x;
y = pChildLibraryTreeItem->getOMSConnector()->geometry->y;
}
// No ModelWidget for connectors.
QString annotation = QString("Placement(true,%1,%2,-10.0,-10.0,10.0,10.0,0,%1,%2,-10.0,-10.0,10.0,10.0,)")
.arg(Utilities::mapToCoOrdinateSystem(x, 0, 1, -100, 100))
.arg(Utilities::mapToCoOrdinateSystem(y, 0, 1, -100, 100));
AddConnectorCommand *pAddConnectorCommand = new AddConnectorCommand(pChildLibraryTreeItem->getName(), pChildLibraryTreeItem,
annotation, mpIconGraphicsView, true,
pChildLibraryTreeItem->getOMSConnector()->causality,
pChildLibraryTreeItem->getOMSConnector()->type);
mpUndoStack->push(pAddConnectorCommand);
}
}
}
}

void ModelWidget::drawOMSModelDiagramElements()
{
if (mpLibraryTreeItem->isTopLevel()) {
if (mpLibraryTreeItem->isTopLevel() || mpLibraryTreeItem->isSystemElement()) {
for (int i = 0 ; i < mpLibraryTreeItem->childrenSize() ; i++) {
LibraryTreeItem *pChildLibraryTreeItem = mpLibraryTreeItem->childAt(i);
if (pChildLibraryTreeItem->getOMSElement() && pChildLibraryTreeItem->getOMSElement()->geometry) {
Expand Down Expand Up @@ -5734,6 +5754,8 @@ void ModelWidget::drawOMSModelDiagramElements()
annotation, mpDiagramGraphicsView, true,
pChildLibraryTreeItem->getSystemType());
mpUndoStack->push(pAddSystemCommand);
} else if (pChildLibraryTreeItem->getOMSConnector()) {
// connectors are already drawn as part of ModelWidget::drawOMSModelIconElements();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -401,9 +401,9 @@ bool OMSProxy::deleteSubModel(QString modelIdent, QString subModelIdent)
*/
bool OMSProxy::loadModel(QString filename, QString* pModelName)
{
char* ident = NULL;
oms_status_enu_t status = oms2_loadModel(filename.toStdString().c_str(), &ident);
*pModelName = QString(ident);
char* cref = NULL;
oms_status_enu_t status = oms3_import(filename.toStdString().c_str(), &cref);
*pModelName = QString(cref);
return statusToBool(status);
}

Expand Down
67 changes: 67 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/boolean-input-connector.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/boolean-output-connector.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/integer-input-connector.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59832c1

Please sign in to comment.