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

Private GIT Repository
removing save from repo
[blast.git] / BoxItem.cpp
index 77e9533be3c44d7fd729bb678d8718ad51e74b1e..237c7ee0f843b8f1dd05322791e69cadb3c4f6a6 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();
-    boxSizeChanged = true;
-  }
-  if (boxWidth < minimumBoxWidth) {
-    boxWidth = minimumBoxWidth;
+    // resize implies to move interfaces and to update connections
     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();
       }
     }    
   }
@@ -283,7 +285,7 @@ void BoxItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
   int mode = getScene()->getEditionMode();
 
-  dispatcher->setCurrentGroupWidget(getScene()->getGroupWindow());
+  dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
 
   if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
     InterfaceItem *inter = getInterfaceFromCursor(x,y);
@@ -366,6 +368,7 @@ void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
         params->setEditState(Parameters::EditNoOperation);
       }
       else {
+        //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
         getScene()->setSelectedInterface(2,NULL);
         params->setEditState(Parameters::EditStartConnection);
       }
@@ -452,9 +455,10 @@ void BoxItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
 void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
 
   QMenu menu;
-  QAction* removeAction = menu.addAction("Remove");
-  QAction* duplicateAction = menu.addAction("Duplicate");
-  QAction* renameAction = menu.addAction("Rename");
+  QAction* titleAction = NULL;
+  QAction* removeAction = NULL;
+  QAction* duplicateAction = NULL;
+  QAction* renameAction = NULL;
   QAction* connectToGroup = NULL;
   QAction* disconnectFromGroup = NULL;
   QAction* showProperties = NULL;
@@ -464,36 +468,81 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
   QAction* showParameters = NULL;
 
   InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
+  // menu for interface
   if( ifaceItem != NULL){
+
+    titleAction = menu.addAction("Interface operations");
+    titleAction->setEnabled(false);
+    menu.addSeparator();
+
+
     showProperties = menu.addAction("Show properties");
+    renameAction = menu.addAction("Rename");
 
     ConnectedInterface* iface = ifaceItem->refInter;
+    ConnectedInterface* ifaceGroup = NULL;
+    bool canRemove = true;
+
+
     if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
         connectToGroup = menu.addAction("Connect to group input");
     }
-    else if ((iface->getDirection() == AbstractInterface::Output) && (!iface->isConnectedTo())) {
+    else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
       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())) {
+      if (!ifaceGroup->isConnectedFrom()) {
+        disconnectFromGroup = menu.addAction("Disconnect from group");
+      }
+      else {
+        canRemove = false;
+      }
+    }
+    else if (iface->getConnectionToParentGroup() != NULL) {
+      ifaceGroup = iface->getConnectionToParentGroup();
+      //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+      if (!ifaceGroup->isConnectedTo()) {
+        disconnectFromGroup = menu.addAction("Disconnect from group");
+      }
+      else {
+        canRemove = false;
+      }
     }
 
     if (iface->isFunctionalInterface()) {
       FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
       ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
       if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
-        cloneInterface = menu.addAction("Clone interface");
-      }
+        cloneInterface = menu.addAction("Duplicate");
+        if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
+          removeAction = menu.addAction("Remove");
+        }
+      }      
     }
   }
-  if(refBlock->isGroupBlock()){
-    openWindow = menu.addAction("Open/show group window");
-  } else {
-    showRstClkInter = menu.addAction("Show reset/clock interfaces");
-    showRstClkInter->setCheckable(true);
-    showRstClkInter->setChecked(rstClkVisible);
+  // menu for blocks (group or func)
+  else {
+    titleAction = menu.addAction("Block operations");
+    titleAction->setEnabled(false);
+    menu.addSeparator();
 
-    showParameters = menu.addAction("Show parameters");
+    if (refBlock->nbParameters() > 0) {
+      showParameters = menu.addAction("Show parameters");
+    }
+    renameAction = menu.addAction("Rename");
+
+    if(refBlock->isGroupBlock()){
+      openWindow = menu.addAction("Open/show group window");
+    }
+    else {
+      duplicateAction = menu.addAction("Duplicate");
+      showRstClkInter = menu.addAction("Show reset/clock interfaces");
+      showRstClkInter->setCheckable(true);
+      showRstClkInter->setChecked(rstClkVisible);
+    }
+    removeAction = menu.addAction("Remove");
   }
 
   QAction* selectedAction = NULL;
@@ -502,16 +551,21 @@ void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
   if(selectedAction == NULL) return ;
 
   if (selectedAction == removeAction) {
-    dispatcher->removeBlock(this);
+    if(ifaceItem != NULL) {
+     dispatcher->removeBlockInterface(ifaceItem);
+    }
+    else {
+      dispatcher->removeBlock(this);
+    }
   }
   else if (selectedAction == duplicateAction) {
     dispatcher->duplicateBlock(this);
   }
   else if(selectedAction == renameAction){
     if(ifaceItem != NULL)
-      dispatcher->rename(ifaceItem);
+      dispatcher->renameInterface(ifaceItem);
     else
-      dispatcher->rename(this);
+      dispatcher->renameBlockOrGroup(this);
   }
   else if(selectedAction == showProperties){
     dispatcher->showProperties(ifaceItem);