ConnectionItem::ConnectionItem(InterfaceItem* _iface1,
InterfaceItem* _iface2,
Dispatcher* _dispatcher,
- Parameters* _params,
- QGraphicsItem *_parent) : QGraphicsItem(_parent) {
+ Parameters* _params) : QGraphicsItem() {
dispatcher = _dispatcher;
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()) {
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);
setFlag(ItemSendsGeometryChanges);
setCursor(Qt::PointingHandCursor);
setZValue(0);
+
+ if (fromInterfaceItem->refInter->getPurpose() == AbstractInterface::Data) {
+ visible = true;
+ }
+ else {
+ visible = false;
+ }
- setPathes();
+ setPath();
}
const QStyleOptionGraphicsItem *option,
QWidget *widget) {
+ if (!visible) return;
+
painter->setPen(Qt::blue);
if(selected){
painter->setPen(Qt::red);
}
-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();
/* 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;
}
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);
+ }
}
}