X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..d111eaf49741a0a79d372445f97c314a637e331e:/ConnectionItem.cpp?ds=sidebyside diff --git a/ConnectionItem.cpp b/ConnectionItem.cpp index dee71ba..c99d489 100644 --- a/ConnectionItem.cpp +++ b/ConnectionItem.cpp @@ -12,8 +12,7 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, InterfaceItem* _iface2, Dispatcher* _dispatcher, - Parameters* _params, - QGraphicsItem *_parent) : QGraphicsItem(_parent) { + Parameters* _params) : QGraphicsItem() { dispatcher = _dispatcher; @@ -25,6 +24,8 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, case 1 : ref1 is group interface, and ref2 block interface of a block within the group case 2 : the opposite of case 1 case 3 : ref1 and ref2 are block interface of blocks that are both within the same parent group. + case 4 : ref1 is source interface and ref2 interface of top group + case 5 : the opposite of case 4 */ if (ref1->getOwner() == ref2->getOwner()->getParent()) { @@ -72,6 +73,14 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, fromInterfaceItem = _iface1; } } + else if ((ref1->getOwner()->isSourceBlock()) && (ref2->getOwner()->isTopGroupBlock())) { + fromInterfaceItem = _iface1; + toInterfaceItem = _iface2; + } + else if ((ref2->getOwner()->isSourceBlock()) && (ref1->getOwner()->isTopGroupBlock())) { + fromInterfaceItem = _iface2; + toInterfaceItem = _iface1; + } // adding this to interface items fromInterfaceItem->addConnectionItem(this); toInterfaceItem->addConnectionItem(this); @@ -84,8 +93,15 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, setFlag(ItemSendsGeometryChanges); setCursor(Qt::PointingHandCursor); setZValue(0); + + if (fromInterfaceItem->refInter->getPurpose() == AbstractInterface::Data) { + visible = true; + } + else { + visible = false; + } - setPathes(); + setPath(); } @@ -133,6 +149,8 @@ void ConnectionItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + if (!visible) return; + painter->setPen(Qt::blue); if(selected){ painter->setPen(Qt::red); @@ -145,12 +163,35 @@ void ConnectionItem::addInterPoint(QPointF point) { } -void ConnectionItem::setPathes() { +void ConnectionItem::setPath() { + // signals to the scene that this connection is going to change of shape. prepareGeometryChange(); - pointFrom = fromInterfaceItem->getEndPointInGroup(); - pointTo = toInterfaceItem->getEndPointInGroup(); + bool withinGroup = false; + /* NB: four cases + 1: from group input iface to box input iface + 2: from output box iface to group output iface + 3: from output box iface to input box iface + 4: from source output iface to input group iface + + For cases 1 & 2, the position of group iface is given by getStartPosition + For all other cases, the iface from and to position is given by getEndPosition + */ + if ((fromInterfaceItem->getOwner()->isGroupItem()) && (toInterfaceItem->getOwner()->isBoxItem())) { + pointFrom = fromInterfaceItem->getStartPosition(); + pointTo = toInterfaceItem->getEndPosition(); + withinGroup = true; + } + else if ((toInterfaceItem->getOwner()->isGroupItem()) && (fromInterfaceItem->getOwner()->isBoxItem())) { + pointFrom = fromInterfaceItem->getEndPosition(); + pointTo = toInterfaceItem->getStartPosition(); + withinGroup = true; + } + else { + pointFrom = fromInterfaceItem->getEndPosition(); + pointTo = toInterfaceItem->getEndPosition(); + } int oriFrom, oriTo; oriFrom = fromInterfaceItem->getOrientation(); @@ -159,36 +200,38 @@ void ConnectionItem::setPathes() { /* NB: if src or dest is onwed by a GroupItem the orientation must be changed as it is a block. */ - if(fromInterfaceItem->owner->isGroupItem()){ - switch(fromInterfaceItem->getOrientation()){ - case Parameters::North : - oriFrom = Parameters::South; - break; - case Parameters::South : - oriFrom = Parameters::North; - break; - case Parameters::East : - oriFrom = Parameters::West; - break; - case Parameters::West : - oriFrom = Parameters::East; - break; - } - } - if(toInterfaceItem->owner->isGroupItem()){ - switch(toInterfaceItem->getOrientation()){ - case Parameters::North : - oriTo = Parameters::South; - break; - case Parameters::South : - oriTo = Parameters::North; - break; - case Parameters::East : - oriTo = Parameters::West; - break; - case Parameters::West : - oriTo = Parameters::East; - break; + if (withinGroup) { + if(fromInterfaceItem->owner->isGroupItem()){ + switch(fromInterfaceItem->getOrientation()){ + case Parameters::North : + oriFrom = Parameters::South; + break; + case Parameters::South : + oriFrom = Parameters::North; + break; + case Parameters::East : + oriFrom = Parameters::West; + break; + case Parameters::West : + oriFrom = Parameters::East; + break; + } + } + else if(toInterfaceItem->owner->isGroupItem()){ + switch(toInterfaceItem->getOrientation()){ + case Parameters::North : + oriTo = Parameters::South; + break; + case Parameters::South : + oriTo = Parameters::North; + break; + case Parameters::East : + oriTo = Parameters::West; + break; + case Parameters::West : + oriTo = Parameters::East; + break; + } } } double gap1 = 0.0; @@ -726,13 +769,37 @@ void ConnectionItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { } void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { - QMenu menu; - QAction* removeAction = menu.addAction("Remove"); - QAction * selectedAction= menu.exec(event->screenPos()); + /* have to check if the connection can be removed. + If the from or to InterfaceItem is owned by a group item, and this item + is both connected to and from, thus it is impossible to remove this connection + */ + bool canRemove = true; + InterfaceItem* groupIfaceItem = NULL; + if (fromInterfaceItem->getOwner()->isGroupItem()) { + groupIfaceItem = fromInterfaceItem; + } + else if (toInterfaceItem->getOwner()->isGroupItem()) { + groupIfaceItem = toInterfaceItem; + } - if(selectedAction == removeAction){ - dispatcher->removeConnection(this); - dispatcher->removeUselessGroupInterfaces(); + if (groupIfaceItem != NULL) { + ConnectedInterface* ref = groupIfaceItem->refInter; + if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) { + canRemove = false; + } + } + + if (canRemove) { + QMenu menu; + QAction* titleAction = menu.addAction("Connection operations"); + titleAction->setEnabled(false); + menu.addSeparator(); + QAction* removeAction = menu.addAction("Remove"); + QAction * selectedAction= menu.exec(event->screenPos()); + + if(selectedAction == removeAction){ + dispatcher->removeConnection(this); + } } }