]> AND Private Git Repository - blast.git/blobdiff - BoxItem.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
correcting bugs but still exsitings
[blast.git] / BoxItem.cpp
index 77e9533be3c44d7fd729bb678d8718ad51e74b1e..0b1cd034bda7230e0ba92901800c37e9f54699af 100644 (file)
@@ -33,7 +33,7 @@ BoxItem::BoxItem(AbstractBlock *_refBlock,
   setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
 
   initInterfaces();
-  updateGeometry();
+  updateGeometry(InterfaceMove);
   resetInterfacesPosition();
   QPointF initPos = QPointF(0.0,0.0) - originPoint;
   setPos(initPos);
@@ -133,27 +133,29 @@ bool BoxItem::updateGeometry(ChangeType type) {
 
   bool boxSizeChanged = false;
 
-  if ((type == Resize) || (type == InterfaceMove)) {
-    updateMinimumSize();
-  }
+  // whatever the change, the minimum size may ahve changed
+  updateMinimumSize();
 
   if (type == Resize) {
-    prepareGeometryChange();
-    updateInterfacesAndConnections();
+    // resize implies to move interfaces and to update connections
     boxSizeChanged = true;
   }
-  if (boxWidth < minimumBoxWidth) {
-    boxWidth = minimumBoxWidth;
-    boxSizeChanged = true;
-  }
-  if (boxHeight < minimumBoxHeight) {
-    boxHeight = minimumBoxHeight;
-     boxSizeChanged = true;
+  else if (type == InterfaceMove) {
+    // if an interface moves, it may change the box size
+    if (boxWidth < minimumBoxWidth) {
+      boxWidth = minimumBoxWidth;
+      boxSizeChanged = true;
+    }
+    if (boxHeight < minimumBoxHeight) {
+      boxHeight = minimumBoxHeight;
+      boxSizeChanged = true;
+    }
   }
   if (boxSizeChanged) {
     updateInterfacesAndConnections();
   }
 
+
   double x = 0.0;
   double y = 0.0;
   totalWidth = boxWidth;
@@ -208,7 +210,7 @@ void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
     // update all connections from/to this block
     foreach(ConnectionItem *item, getScene()->getConnectionItems()){
       if ((item->getFromInterfaceItem()->getOwner() == this) || (item->getToInterfaceItem()->getOwner() == this)) {
-        item->setPathes();
+        item->setPath();
       }
     }
     cursorPosition = event->scenePos();
@@ -248,7 +250,7 @@ void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
       break;
     }
     // recompute the geometry of the block and possibly the group item
-    if (updateGeometry()) {
+    if (updateGeometry(Resize)) {
       (getScene()->getGroupItem())->updateShape();
     }
 
@@ -256,16 +258,16 @@ void BoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
   }
   else if(params->editState == Parameters::EditInterfaceMove) {
     prepareGeometryChange();
-    deplaceInterface(event->pos());
+    moveInterfaceTo(event->pos());
     // recompute the geometry of the block
-    if (updateGeometry()) {
+    if (updateGeometry(InterfaceMove)) {
       cout << "must recompute group item geometry" << endl;
       (getScene()->getGroupItem())->updateShape();
     }
     // update connection from/to the selected interface
     foreach(ConnectionItem *item, getScene()->getConnectionItems()){
       if ((item->getFromInterfaceItem() == currentInterface) || (item->getToInterfaceItem() == currentInterface)) {
-        item->setPathes();
+        item->setPath();
       }
     }    
   }
@@ -468,14 +470,26 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
     showProperties = menu.addAction("Show properties");
 
     ConnectedInterface* iface = ifaceItem->refInter;
+    ConnectedInterface* ifaceGroup = NULL;
+
+
     if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
         connectToGroup = menu.addAction("Connect to group input");
     }
     else if ((iface->getDirection() == AbstractInterface::Output) && (!iface->isConnectedTo())) {
       connectToGroup = menu.addAction("Connect to group output");
     }
-    else if ((iface->getConnectionFromParentGroup() != NULL) || (iface->getConnectionToParentGroup() != NULL)) {
-      disconnectFromGroup = menu.addAction("Disconnect from group");
+    else if (iface->getConnectionFromParentGroup() != NULL) {
+      ifaceGroup = iface->getConnectionFromParentGroup();
+      if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+        disconnectFromGroup = menu.addAction("Disconnect from group");
+      }
+    }
+    else if (iface->getConnectionToParentGroup() != NULL) {
+      ifaceGroup = iface->getConnectionToParentGroup();
+      if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+        disconnectFromGroup = menu.addAction("Disconnect from group");
+      }
     }
 
     if (iface->isFunctionalInterface()) {