- // getting the GroupBlock and GroupItem that are parent of the block that owns item
- ConnectedInterface *refInter = item->refInter;
- ConnectedInterface *groupInter = NULL;
- GroupBlock* parentGroup = AB_TO_GRP(refInter->getOwner()->getParent());
- GroupItem *parentItem = item->getOwner()->getScene()->getGroupItem();
-
- // removing the connection from graph
-#ifdef DEBUG
- cout << "removing connections from graph ..." ;
-#endif
-
- if (refInter->getDirection() == AbstractInterface::Output) {
- groupInter = refInter->getConnectionToParentGroup(); // must be a single connection to
- refInter->clearConnectedTo();
- groupInter->clearConnectedFrom();
- }
- else if (refInter->getDirection() == AbstractInterface::Input) {
- groupInter = refInter->getConnectedFrom();
- refInter->clearConnectedFrom();
- groupInter->clearConnectedTo();
- }
- else if (refInter->getDirection() == AbstractInterface::InOut) {
- groupInter = refInter->getConnectionToParentGroup(); // must be a single connection to
- refInter->clearConnectedTo();
- refInter->clearConnectedFrom();
- groupInter->clearConnectedTo();
- groupInter->clearConnectedFrom();
- }
-#ifdef DEBUG
- cout << "done." << endl ;
-#endif
-
- if (groupInter == NULL) {
- cerr << "abnormal case 1 while removing an interface item of a block, linked to a parent group" << endl;
- }
-
-#ifdef DEBUG
- cout << "getting group interface item, and connection item ..." ;
-#endif
-
-
- InterfaceItem* groupIfaceItem = parentItem->searchInterfaceByRef(groupInter);
- if (groupIfaceItem == NULL) {
- cerr << "abnormal case 2 while removing an interface item of a block, linked to a parent group" << endl;
- }
- ConnectionItem* conn = parentItem->getScene()->searchConnectionItem(item,groupIfaceItem);
- if (conn == NULL) {
- cerr << "abnormal case 3 while removing an interface item of a block, linked to a parent group" << endl;
- }
-#ifdef DEBUG
- cout << "done." << endl ;
-#endif
-
- // removing the interface group item from the group item, and the connection item
-#ifdef DEBUG
- cout << "removing group interface item, and connection item ..." ;
-#endif
-
- item->removeConnectionItem(conn);
- groupIfaceItem->removeConnectionItem(conn);
- parentItem->removeInterface(groupIfaceItem); // CAUTION : this deletes the interface item.
- parentItem->getScene()->removeConnectionItem(conn);
-#ifdef DEBUG
- cout << "done." << endl ;
-#endif
-
- // removing the interface box item in the parent scene
-#ifdef DEBUG
- cout << "removing the inteeface item of box item in parent scene if needed ..." ;
-#endif
-
- BoxItem* parent2Item = parentItem->getParentItem();
- if (parent2Item != NULL) {
- InterfaceItem* group2IfaceItem = parent2Item->searchInterfaceByRef(groupInter);
- parent2Item->removeInterface(group2IfaceItem);
+ /* first, remove all connections from item
+ NB: if there is a connection to a group interface, then this
+ method should not be called if the group interface is also
+ connected to another interface. Normally, this is not possible
+ because such a check is done when creating the contextual menu
+ that allows to remove an interface.
+ */
+ foreach(ConnectionItem* conn, item->connections) {
+ removeConnection(conn);