Skip to content

Commit

Permalink
Fixes ticket:5422 Use the root component
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #135
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Apr 9, 2019
1 parent 44507d2 commit 6a4c0f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
84 changes: 41 additions & 43 deletions OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -129,27 +129,16 @@ LineAnnotation::LineAnnotation(LineAnnotation::LineType lineType, Component *pSt
setOMSConnectionType(oms_connection_single);
setActiveState(false);
if (mLineType == LineAnnotation::ConnectionType) {
/* Use the linecolor of the first shape from icon layer of start component for the connection line.
* Or use black color if there is no shape in the icon layer
/* Use the linecolor of the first shape of the start component for the connection line.
* If there is no shape then look in the inherited shapes.
* Or use black color if no shape is found even in inheritance.
* Dymola is doing it the way explained above. The Modelica specification doesn't say anything about it.
* We are also doing it the same way except that we will use the diagram layer shape if there is no shape in the icon layer.
* If there is no shape even in diagram layer then use the default black color.
*/
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (pStartComponent->getShapesList().size() > 0) {
ShapeAnnotation *pShapeAnnotation = pStartComponent->getShapesList().at(0);
mLineColor = pShapeAnnotation->getLineColor();
}
if (pStartComponent->getLibraryTreeItem() && pStartComponent->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (!pStartComponent->getLibraryTreeItem()->getModelWidget()) {
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pStartComponent->getLibraryTreeItem(), false);
}
ShapeAnnotation *pShapeAnnotation;
if (pStartComponent->getLibraryTreeItem()->getModelWidget()->getIconGraphicsView()
&& pStartComponent->getLibraryTreeItem()->getModelWidget()->getIconGraphicsView()->getShapesList().size() > 0) {
pShapeAnnotation = pStartComponent->getLibraryTreeItem()->getModelWidget()->getIconGraphicsView()->getShapesList().at(0);
mLineColor = pShapeAnnotation->getLineColor();
}
mLineColor = pStartComponent->getShapesList().at(0)->getLineColor();
} else {
mLineColor = findLineColorForConnection(pStartComponent);
}
}
mpTextAnnotation = 0;
Expand Down Expand Up @@ -1102,6 +1091,22 @@ void LineAnnotation::updateOMSConnection()
OMSProxy::instance()->setConnectionGeometry(getStartComponentName(), getEndComponentName(), &connectionGeometry);
}

void LineAnnotation::updateToolTip()
{
if (mLineType == LineAnnotation::ConnectionType) {
setToolTip(QString("<b>connect</b>(%1, %2)").arg(getStartComponentName()).arg(getEndComponentName()));
} else if (mLineType == LineAnnotation::TransitionType) {
setToolTip(QString("<b>transition</b>(%1, %2, %3, %4, %5, %6, %7)")
.arg(getStartComponentName())
.arg(getEndComponentName())
.arg(getCondition())
.arg(getImmediate() ? "true" : "false")
.arg(getReset() ? "true" : "false")
.arg(getSynchronize() ? "true" : "false")
.arg(getPriority()));
}
}

void LineAnnotation::showOMSConnection()
{
if ((mpStartComponent && mpStartComponent->getLibraryTreeItem()->getOMSBusConnector())
Expand All @@ -1115,20 +1120,23 @@ void LineAnnotation::showOMSConnection()
}
}

void LineAnnotation::updateToolTip()
/*!
* \brief LineAnnotation::findLineColorForConnection
* Finds the line color for the connection from the shapes of the start component.
* \param pComponent
* \return
*/
QColor LineAnnotation::findLineColorForConnection(Component *pComponent)
{
if (mLineType == LineAnnotation::ConnectionType) {
setToolTip(QString("<b>connect</b>(%1, %2)").arg(getStartComponentName()).arg(getEndComponentName()));
} else if (mLineType == LineAnnotation::TransitionType) {
setToolTip(QString("<b>transition</b>(%1, %2, %3, %4, %5, %6, %7)")
.arg(getStartComponentName())
.arg(getEndComponentName())
.arg(getCondition())
.arg(getImmediate() ? "true" : "false")
.arg(getReset() ? "true" : "false")
.arg(getSynchronize() ? "true" : "false")
.arg(getPriority()));
QColor lineColor(0, 0, 0);
foreach (Component *pInheritedComponent, pComponent->getInheritedComponentsList()) {
if (pInheritedComponent->getShapesList().size() > 0) {
return pInheritedComponent->getShapesList().at(0)->getLineColor();
} else {
lineColor = findLineColorForConnection(pInheritedComponent);
}
}
return lineColor;
}

QVariant LineAnnotation::itemChange(GraphicsItemChange change, const QVariant &value)
Expand Down Expand Up @@ -1709,13 +1717,8 @@ CreateConnectionDialog::CreateConnectionDialog(GraphicsView *pGraphicsView, Line
mpStartExpandableConnectorTreeProxyModel->setSourceModel(mpStartExpandableConnectorTreeModel);
mpStartExpandableConnectorTreeView = new ExpandableConnectorTreeView(this);
mpStartExpandableConnectorTreeView->setModel(mpStartExpandableConnectorTreeProxyModel);
if (mpConnectionLineAnnotation->getStartComponent()->getParentComponent()) {
mpStartExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getStartComponent()->getParentComponent(),
mpStartExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
} else {
mpStartExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getStartComponent(),
mpStartExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
}
mpStartExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getStartComponent()->getRootParentComponent(),
mpStartExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
mpStartExpandableConnectorTreeView->expandAll();
mpStartExpandableConnectorTreeView->setSortingEnabled(true);
mpStartExpandableConnectorTreeView->sortByColumn(0, Qt::AscendingOrder);
Expand All @@ -1732,13 +1735,8 @@ CreateConnectionDialog::CreateConnectionDialog(GraphicsView *pGraphicsView, Line
mpEndExpandableConnectorTreeProxyModel->setSourceModel(mpEndExpandableConnectorTreeModel);
mpEndExpandableConnectorTreeView = new ExpandableConnectorTreeView(this);
mpEndExpandableConnectorTreeView->setModel(mpEndExpandableConnectorTreeProxyModel);
if (mpConnectionLineAnnotation->getEndComponent()->getParentComponent()) {
mpEndExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getEndComponent()->getParentComponent(),
mpEndExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
} else {
mpEndExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getEndComponent(),
mpEndExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
}
mpEndExpandableConnectorTreeModel->createExpandableConnectorTreeItem(mpConnectionLineAnnotation->getEndComponent()->getRootParentComponent(),
mpEndExpandableConnectorTreeModel->getRootExpandableConnectorTreeItem());
mpEndExpandableConnectorTreeView->expandAll();
mpEndExpandableConnectorTreeView->setSortingEnabled(true);
mpEndExpandableConnectorTreeView->sortByColumn(0, Qt::AscendingOrder);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -136,6 +136,8 @@ class LineAnnotation : public ShapeAnnotation
void updateOMSConnection();
void updateToolTip();
void showOMSConnection();

static QColor findLineColorForConnection(Component *pComponent);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);

Expand Down

0 comments on commit 6a4c0f4

Please sign in to comment.