X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/cfe8322b50c9ef08ffbc3e52b0849bca4cd1d0bf..4327c2b8817b627249d98d889835726217c81a4e:/ConnectionItem.cpp?ds=sidebyside diff --git a/ConnectionItem.cpp b/ConnectionItem.cpp index 5dcd338..61af6c8 100644 --- a/ConnectionItem.cpp +++ b/ConnectionItem.cpp @@ -9,24 +9,30 @@ //int ConnectionItem::counter = 0; -ConnectionItem::ConnectionItem(InterfaceItem* _iface1, - InterfaceItem* _iface2, +ConnectionItem::ConnectionItem(InterfaceItem* _fromInterfaceItem, + InterfaceItem* _toInterfaceItem, Dispatcher* _dispatcher, Parameters* _params) : QGraphicsItem() { dispatcher = _dispatcher; params = _params; + fromInterfaceItem = _fromInterfaceItem; + toInterfaceItem = _toInterfaceItem; + + /* NOTE: originally, the following was testing the correct order + * to connect the 2 interfaces. Presently, the order is predetermined + * when testing the AbstractInterface objets that must be connected. ConnectedInterface* ref1 = _iface1->refInter; ConnectedInterface* ref2 = _iface2->refInter; - /* ref. note in .h + ref. note in .h 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 4 : ref1 is stimuli interface and ref2 interface of top group case 5 : the opposite of case 4 - */ + if (ref1->getOwner() == ref2->getOwner()->getParent()) { if (ref1->getDirection() == AbstractInterface::Input) { @@ -73,14 +79,16 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1, fromInterfaceItem = _iface1; } } - else if ((ref1->getOwner()->isSourceBlock()) && (ref2->getOwner()->isTopGroupBlock())) { - fromInterfaceItem = _iface1; + else if ((ref1->getOwner()->isStimuliBlock()) && (ref2->getOwner()->isTopGroupBlock())) { + fromInterfaceItem = _iface1; toInterfaceItem = _iface2; } - else if ((ref2->getOwner()->isSourceBlock()) && (ref1->getOwner()->isTopGroupBlock())) { - fromInterfaceItem = _iface2; + else if ((ref2->getOwner()->isStimuliBlock()) && (ref1->getOwner()->isTopGroupBlock())) { + fromInterfaceItem = _iface2; toInterfaceItem = _iface1; } + + */ // adding this to interface items fromInterfaceItem->addConnectionItem(this); toInterfaceItem->addConnectionItem(this); @@ -876,18 +884,22 @@ void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { /* 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 + because there would be a group interface alone and not connected and this situation is not allowed. + + Nevertheless, there are 2 exceptions : + - a from group interface is connected to more than one input interface + - the connection is between a source block outside the top group and the top group */ bool canRemove = true; - InterfaceItem* groupIfaceItem = NULL; + if (fromInterfaceItem->getOwner()->isGroupItem()) { - groupIfaceItem = fromInterfaceItem; - } - else if (toInterfaceItem->getOwner()->isGroupItem()) { - groupIfaceItem = toInterfaceItem; + ConnectedInterface* ref = fromInterfaceItem->refInter; + if ((ref->isConnectedFrom()) && (ref->getConnectedTo().length() == 1)) { + canRemove = false; + } } - - if (groupIfaceItem != NULL) { - ConnectedInterface* ref = groupIfaceItem->refInter; + else if ((toInterfaceItem->getOwner()->isGroupItem()) && (! toInterfaceItem->getOwner()->getRefBlock()->isTopGroupBlock())) { + ConnectedInterface* ref = toInterfaceItem->refInter; if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) { canRemove = false; } @@ -902,7 +914,7 @@ void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { QAction * selectedAction= menu.exec(event->screenPos()); if(selectedAction == removeAction){ - dispatcher->removeConnection(this); + dispatcher->removeConnection(Dispatcher::Design, this); } } }