Skip to content

Commit

Permalink
Visual difference between system, fmu and table
Browse files Browse the repository at this point in the history
Also added extra visual information on system like system type and on fmu like fmukind and fmuversion.
  • Loading branch information
adeas31 committed Nov 20, 2018
1 parent 3ee0acc commit 6d42c9d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 72 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -1684,6 +1684,7 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::OMS) {
BitmapAnnotation *pBitmapAnnotation = dynamic_cast<BitmapAnnotation*>(this);
if (pBitmapAnnotation && mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSElement()) {
menu.addAction(MainWindow::instance()->getAddOrEditIconAction());
menu.addAction(MainWindow::instance()->getDeleteIconAction());
} else {
return;
Expand Down
54 changes: 8 additions & 46 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -2270,15 +2270,9 @@ void AddIconCommand::redoInternal()
mpGraphicsView->deleteShapeFromList(pShapeAnnotation);
mpGraphicsView->removeItem(pShapeAnnotation);
}
// Add new bitmap shape
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mIcon, mpGraphicsView);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pBitmapAnnotation);
mpGraphicsView->addItem(pBitmapAnnotation);
ShapeAnnotation *pShapeAnnotation = mpGraphicsView->getModelWidget()->drawOMSModelElement();
pElementLibraryTreeItem->handleIconUpdated();
pElementLibraryTreeItem->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
pElementLibraryTreeItem->emitShapeAdded(pShapeAnnotation, mpGraphicsView);
}
}
}
Expand All @@ -2303,22 +2297,9 @@ void AddIconCommand::undo()
mpGraphicsView->deleteShapeFromList(pShapeAnnotation);
mpGraphicsView->removeItem(pShapeAnnotation);
}
// Rectangle shape as base
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(mpGraphicsView);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pRectangleAnnotation);
mpGraphicsView->addItem(pRectangleAnnotation);
// Text for name
TextAnnotation *pTextAnnotation = new TextAnnotation(mpGraphicsView);
pTextAnnotation->initializeTransformation();
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pTextAnnotation);
mpGraphicsView->addItem(pTextAnnotation);
ShapeAnnotation *pShapeAnnotation = mpGraphicsView->getModelWidget()->drawOMSModelElement();
pElementLibraryTreeItem->handleIconUpdated();
pElementLibraryTreeItem->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
pElementLibraryTreeItem->emitShapeAdded(pShapeAnnotation, mpGraphicsView);
}
}
}
Expand Down Expand Up @@ -2418,22 +2399,9 @@ void DeleteIconCommand::redoInternal()
mpGraphicsView->deleteShapeFromList(pShapeAnnotation);
mpGraphicsView->removeItem(pShapeAnnotation);
}
// Rectangle shape as base
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(mpGraphicsView);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pRectangleAnnotation);
mpGraphicsView->addItem(pRectangleAnnotation);
// Text for name
TextAnnotation *pTextAnnotation = new TextAnnotation(mpGraphicsView);
pTextAnnotation->initializeTransformation();
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pTextAnnotation);
mpGraphicsView->addItem(pTextAnnotation);
ShapeAnnotation *pShapeAnnotation = mpGraphicsView->getModelWidget()->drawOMSModelElement();
pElementLibraryTreeItem->handleIconUpdated();
pElementLibraryTreeItem->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
pElementLibraryTreeItem->emitShapeAdded(pShapeAnnotation, mpGraphicsView);
}
}
}
Expand Down Expand Up @@ -2461,15 +2429,9 @@ void DeleteIconCommand::undo()
mpGraphicsView->deleteShapeFromList(pShapeAnnotation);
mpGraphicsView->removeItem(pShapeAnnotation);
}
// Add new bitmap shape
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mIcon, mpGraphicsView);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
mpGraphicsView->addShapeToList(pBitmapAnnotation);
mpGraphicsView->addItem(pBitmapAnnotation);
ShapeAnnotation *pShapeAnnotation = mpGraphicsView->getModelWidget()->drawOMSModelElement();
pElementLibraryTreeItem->handleIconUpdated();
pElementLibraryTreeItem->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
pElementLibraryTreeItem->emitShapeAdded(pShapeAnnotation, mpGraphicsView);
}
}
}
Expand Down
106 changes: 80 additions & 26 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3927,6 +3927,84 @@ void ModelWidget::createModelWidgetComponents()
}
}

/*!
* \brief ModelWidget::drawOMSModelElement
* Draws the OMS model element i.e, system, FMU or table.
*/
ShapeAnnotation* ModelWidget::drawOMSModelElement()
{
if (mpLibraryTreeItem->getOMSElement()->geometry && mpLibraryTreeItem->getOMSElement()->geometry->iconSource) {
// Draw bitmap with icon source
QUrl url(mpLibraryTreeItem->getOMSElement()->geometry->iconSource);
QFileInfo fileInfo(url.toLocalFile());
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(fileInfo.absoluteFilePath(), mpIconGraphicsView);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pBitmapAnnotation);
mpIconGraphicsView->addItem(pBitmapAnnotation);
return pBitmapAnnotation;
} else {
// Rectangle shape as base
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(mpIconGraphicsView);
pRectangleAnnotation->initializeTransformation();
if (mpLibraryTreeItem->isSystemElement()) {
pRectangleAnnotation->setLineColor(QColor(128, 128, 0));
pRectangleAnnotation->setFillColor(Qt::white);
} else if (mpLibraryTreeItem->isFMUComponent()) {
pRectangleAnnotation->setFillColor(Qt::white);
} else if (mpLibraryTreeItem->isTableComponent()) {
pRectangleAnnotation->setLinePattern(StringHandler::LineNone);
if (mpLibraryTreeItem->getSubModelPath().endsWith(".csv")) {
pRectangleAnnotation->setFillColor(QColor(0, 148, 21));
} else {
pRectangleAnnotation->setFillColor(QColor(3, 75, 220));
}
}
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pRectangleAnnotation);
mpIconGraphicsView->addItem(pRectangleAnnotation);
// Text for name
TextAnnotation *pTextAnnotation = new TextAnnotation(mpIconGraphicsView);
pTextAnnotation->initializeTransformation();
if (mpLibraryTreeItem->isSystemElement() || mpLibraryTreeItem->isFMUComponent()) {
QList<QPointF> extents;
extents << QPointF(-100, 80) << QPointF(100, 40);
pTextAnnotation->setExtents(extents);
if (mpLibraryTreeItem->isSystemElement()) {
pTextAnnotation->setLineColor(QColor(128, 128, 0));
}
} else if (mpLibraryTreeItem->isTableComponent()) {
pTextAnnotation->setLineColor(Qt::white);
}
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pTextAnnotation);
mpIconGraphicsView->addItem(pTextAnnotation);
// Text for further information
if (mpLibraryTreeItem->isSystemElement() || mpLibraryTreeItem->isFMUComponent()) {
TextAnnotation *pInfoTextAnnotation = new TextAnnotation(mpIconGraphicsView);
pInfoTextAnnotation->initializeTransformation();
QList<QPointF> extents;
extents << QPointF(-100, -40) << QPointF(100, -80);
pInfoTextAnnotation->setExtents(extents);
if (mpLibraryTreeItem->isSystemElement()) {
pInfoTextAnnotation->setLineColor(QColor(128, 128, 0));
pInfoTextAnnotation->setTextString(OMSProxy::getSystemTypeShortString(mpLibraryTreeItem->getSystemType()));
} else {
pInfoTextAnnotation->setTextString(QString("%1 %2").arg(OMSProxy::getFMUKindString(mpLibraryTreeItem->getFMUInfo()->fmiKind))
.arg(QString(mpLibraryTreeItem->getFMUInfo()->fmiVersion)));
}
pInfoTextAnnotation->drawCornerItems();
pInfoTextAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pInfoTextAnnotation);
mpIconGraphicsView->addItem(pInfoTextAnnotation);
}
return pRectangleAnnotation;
}
}

/*!
* \brief ModelWidget::getConnectorComponent
* Finds the Port Component within the Component.
Expand Down Expand Up @@ -5880,32 +5958,8 @@ void ModelWidget::drawOMSModelIconElements()
if (mpLibraryTreeItem->isTopLevel()) {
return;
} else if (mpLibraryTreeItem->isSystemElement() || mpLibraryTreeItem->isComponentElement()) {
if (mpLibraryTreeItem->getOMSElement()->geometry && mpLibraryTreeItem->getOMSElement()->geometry->iconSource) {
// Draw bitmap with icon source
QUrl url(mpLibraryTreeItem->getOMSElement()->geometry->iconSource);
QFileInfo fileInfo(url.toLocalFile());
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(fileInfo.absoluteFilePath(), mpIconGraphicsView);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pBitmapAnnotation);
mpIconGraphicsView->addItem(pBitmapAnnotation);
} else {
// Rectangle shape as base
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(mpIconGraphicsView);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pRectangleAnnotation);
mpIconGraphicsView->addItem(pRectangleAnnotation);
// Text for name
TextAnnotation *pTextAnnotation = new TextAnnotation(mpIconGraphicsView);
pTextAnnotation->initializeTransformation();
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
mpIconGraphicsView->addShapeToList(pTextAnnotation);
mpIconGraphicsView->addItem(pTextAnnotation);
}
drawOMSModelElement();
// draw connectors
for (int i = 0 ; i < mpLibraryTreeItem->childrenSize() ; i++) {
LibraryTreeItem *pChildLibraryTreeItem = mpLibraryTreeItem->childAt(i);
if (pChildLibraryTreeItem->getOMSConnector()
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -422,6 +422,7 @@ class ModelWidget : public QWidget
void loadConnections();
void getModelConnections();
void createModelWidgetComponents();
ShapeAnnotation* drawOMSModelElement();
Component* getConnectorComponent(Component *pConnectorComponent, QString connectorName);
void clearGraphicsViews();
void reDrawModelWidget();
Expand Down
21 changes: 21 additions & 0 deletions OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -197,6 +197,27 @@ QString OMSProxy::getSystemTypeString(oms_system_enu_t type)
}
}

/*!
* \brief OMSProxy::getSystemTypeShortString
* Returns the oms_system_enu_t as short string.
* \param type
* \return
*/
QString OMSProxy::getSystemTypeShortString(oms_system_enu_t type)
{
switch (type) {
case oms_system_tlm:
return "TLM";
case oms_system_wc:
return "WC";
case oms_system_sc:
return "SC";
default:
// should never be reached
return "";
}
}

/*!
* \brief OMSProxy::getFMUKindString
* Returns the oms_fmi_kind_enu_t as string.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMS/OMSProxy.h
Expand Up @@ -62,6 +62,7 @@ class OMSProxy : public QObject
static OMSProxy* instance() {return mpInstance;}

static QString getSystemTypeString(oms_system_enu_t type);
static QString getSystemTypeShortString(oms_system_enu_t type);
static QString getFMUKindString(oms_fmi_kind_enu_t kind);
static QString getSignalTypeString(oms_signal_type_enu_t type);
static QString getCausalityString(oms_causality_enu_t causality);
Expand Down

0 comments on commit 6d42c9d

Please sign in to comment.