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

Private GIT Repository
source connection ok
[blast.git] / GroupItem.cpp
index bb26e53b17c42e64995373dfa6f75c91ede37caa..e219f4c7fa68e24843f95bbb6c6060096a7e7bba 100644 (file)
@@ -9,6 +9,9 @@
 #include "AbstractInterface.h"
 #include "ConnectedInterface.h"
 #include "GroupScene.h"
 #include "AbstractInterface.h"
 #include "ConnectedInterface.h"
 #include "GroupScene.h"
+#include "ParametersWindow.h"
+#include "GroupBlock.h"
+#include "GroupInterface.h"
 
 
 GroupItem::GroupItem(BoxItem *_parentItem,
 
 
 GroupItem::GroupItem(BoxItem *_parentItem,
@@ -17,6 +20,9 @@ GroupItem::GroupItem(BoxItem *_parentItem,
                      Parameters *_params) throw(Exception) :AbstractBoxItem( _refBlock, _dispatcher, _params) {
 
   parentItem = _parentItem;
                      Parameters *_params) throw(Exception) :AbstractBoxItem( _refBlock, _dispatcher, _params) {
 
   parentItem = _parentItem;
+  if (parentItem != NULL) {
+    parentItem->setChildGroupItem(this);
+  }
 
   /*
   minimumBoxWidth = nameWidth+2*nameMargin;
 
   /*
   minimumBoxWidth = nameWidth+2*nameMargin;
@@ -44,6 +50,21 @@ GroupItem::GroupItem(BoxItem *_parentItem,
   cout << "pos in scene: " << x() << "," << y() << endl;
 }
 
   cout << "pos in scene: " << x() << "," << y() << endl;
 }
 
+GroupItem::GroupItem(Dispatcher *_dispatcher,Parameters *_params) throw(Exception) :AbstractBoxItem(_dispatcher, _params) {
+
+  parentItem = NULL;
+  rectTitle = QRectF(0,-(nameHeight+2*nameMargin),nameWidth+2*nameMargin,nameHeight+2*nameMargin);
+  selected = false;
+  setZValue(-100);
+  setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
+
+  updateGeometry(InterfaceMove);
+  QPointF initPos = QPointF(0.0,0.0) - originPoint;
+  setPos(initPos);
+  cout << "total size of group: " << totalWidth << "," << totalHeight << endl;
+  cout << "pos in scene: " << x() << "," << y() << endl;
+}
+
 GroupItem::~GroupItem() {
   // since the reference block is nowhere referenced except in this class, it must be deleted here
   delete refBlock;
 GroupItem::~GroupItem() {
   // since the reference block is nowhere referenced except in this class, it must be deleted here
   delete refBlock;
@@ -57,6 +78,13 @@ BoxItem* GroupItem::getParentItem() {
   return parentItem;
 }
 
   return parentItem;
 }
 
+void GroupItem::setParentItem(BoxItem *_parentItem) {
+  parentItem = _parentItem;
+  if (parentItem != NULL) {
+    parentItem->setChildGroupItem(this);
+  }
+}
+
 void GroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
   if(boxWidth > 0 && boxHeight > 0){
     if(selected)
 void GroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
   if(boxWidth > 0 && boxHeight > 0){
     if(selected)
@@ -97,7 +125,7 @@ void GroupItem::updateMinimumSize() {
 
   if (getScene() == NULL) return;
 
 
   if (getScene() == NULL) return;
 
-  QList<BoxItem *> blocks = getScene()->getBlockItems();
+  QList<BoxItem *> blocks = getScene()->getBoxItems();
   if(blocks.length() > 0) {
     // first, search for blocks that are at (0,0)
     int xMaxZero = 0;
   if(blocks.length() > 0) {
     // first, search for blocks that are at (0,0)
     int xMaxZero = 0;
@@ -231,13 +259,29 @@ bool GroupItem::updateGeometry(ChangeType type) {
   originPoint.setY(y);
 
   if ((boxSizeChanged) || (newSize != oldSize) || (originPoint != oldOrigin)) {
   originPoint.setY(y);
 
   if ((boxSizeChanged) || (newSize != oldSize) || (originPoint != oldOrigin)) {
-    cout << "must change group item shape" << endl;
+    cout << "GroupItem: must change group item shape" << endl;
     prepareGeometryChange();
     return true;
   }
   return false;
 }
 
     prepareGeometryChange();
     return true;
   }
   return false;
 }
 
+void GroupItem::nameChanged() {
+
+  
+  QFontMetrics fmId(params->defaultBlockFont);
+  nameWidth = fmId.width(refBlock->getName());
+  nameHeight = fmId.height();
+  // changing the BoxItem in the upperscene
+  if (parentItem != NULL) {
+    parentItem->nameChanged();
+  }
+  updateGeometry(InterfaceMove);
+  // force the update in case of the size has not changed
+  update();  
+}
+
+
 void GroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
   if(params->editState == Parameters::EditGroupMove) {
 void GroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
   if(params->editState == Parameters::EditGroupMove) {
@@ -337,14 +381,9 @@ void GroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
   int mode = getScene()->getEditionMode();
 
 
   int mode = getScene()->getEditionMode();
 
-  dispatcher->setCurrentGroupWidget(getScene()->getGroupWindow());
+  dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
 
 
-  /* NOTE : commneted because group interface are normally
-     created and the connected directly to a block within
-     the group. Furthermore, there can be a single connection
-     from a groupe interface.
-
-  if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
+  if ((refBlock->isTopGroupBlock()) && (mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
     InterfaceItem *inter = getInterfaceFromCursor(x,y);
     if (inter != NULL) {
 
     InterfaceItem *inter = getInterfaceFromCursor(x,y);
     if (inter != NULL) {
 
@@ -362,9 +401,8 @@ void GroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
         }
       }
     }
         }
       }
     }
-  }
-  */
-  if (mode == GroupScene::ItemEdition) {
+  }  
+  else if (mode == GroupScene::ItemEdition) {
 
     if (params->cursorState == Parameters::CursorOnInterface) {
       InterfaceItem *inter = getInterfaceFromCursor(x,y);
 
     if (params->cursorState == Parameters::CursorOnInterface) {
       InterfaceItem *inter = getInterfaceFromCursor(x,y);
@@ -389,12 +427,7 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
 
   int mode = getScene()->getEditionMode();
 
 
   int mode = getScene()->getEditionMode();
 
-  /* NOTE : commneted because group interface are normally
-     created and the connected directly to a block within
-     the group. Furthermore, there can be a single connection
-     from a groupe interface.
-
-  if (mode == GroupScene::AddConnection) {
+  if ((refBlock->isTopGroupBlock()) && (mode == GroupScene::AddConnection)) {
 
     if (params->editState == Parameters::EditStartConnection) {
       params->setEditState(Parameters::EditStartConnection);
 
     if (params->editState == Parameters::EditStartConnection) {
       params->setEditState(Parameters::EditStartConnection);
@@ -412,7 +445,7 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
     else if (params->editState == Parameters::EditCloseConnection) {
       InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
       InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
     else if (params->editState == Parameters::EditCloseConnection) {
       InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
       InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
-      bool ok = dispatcher->connect(iface1,iface2);
+      bool ok = dispatcher->createConnectionItem(iface1,iface2);
       if (ok) {
         iface1->selected = false;
         update(iface1->boundingRect());
       if (ok) {
         iface1->selected = false;
         update(iface1->boundingRect());
@@ -421,9 +454,8 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent  *event) {
         params->setEditState(Parameters::EditNoOperation);
       }
     }
         params->setEditState(Parameters::EditNoOperation);
       }
     }
-  }
-  */
-  if (mode == GroupScene::ItemEdition) {
+  }  
+  else if (mode == GroupScene::ItemEdition) {
     currentInterface = NULL;
     setFlag(ItemIsMovable, true);
     params->editState = Parameters::EditNoOperation;
     currentInterface = NULL;
     setFlag(ItemIsMovable, true);
     params->editState = Parameters::EditNoOperation;
@@ -500,12 +532,19 @@ void GroupItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
 
 void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   QMenu menu;
 
 void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   QMenu menu;
+  QAction* titleAction = NULL;
   QAction* showProperties = NULL;
   QAction* removeAction = NULL;
   QAction* renameAction = NULL;
   QAction* showProperties = NULL;
   QAction* removeAction = NULL;
   QAction* renameAction = NULL;
+  QAction* showParameters = NULL;
 
   InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
 
   InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
-  if( ifaceItem != NULL){
+
+  // 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");
     menu.addSeparator();
     showProperties = menu.addAction("Show properties");
     renameAction = menu.addAction("Rename");
     menu.addSeparator();
@@ -520,6 +559,13 @@ void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
     }
   }
   else {
     }
   }
   else {
+    titleAction = menu.addAction("Block operations");
+    titleAction->setEnabled(false);
+    menu.addSeparator();
+
+    if (refBlock->nbParameters() > 0) {
+      showParameters = menu.addAction("Show parameters");
+    }
     renameAction = menu.addAction("Rename");
   }
   QAction* selectedAction = menu.exec(event->screenPos());
     renameAction = menu.addAction("Rename");
   }
   QAction* selectedAction = menu.exec(event->screenPos());
@@ -528,16 +574,19 @@ void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
 
   if(selectedAction == renameAction){
     if(ifaceItem != NULL)
 
   if(selectedAction == renameAction){
     if(ifaceItem != NULL)
-      dispatcher->rename(ifaceItem);
+      dispatcher->renameInterface(ifaceItem);
     else
     else
-      dispatcher->rename(this);
+      dispatcher->renameGroupBlock(this);
   }
   else if(selectedAction == showProperties){
     dispatcher->showProperties(ifaceItem);
   }
   else if(selectedAction == showProperties){
     dispatcher->showProperties(ifaceItem);
-  }
+  }  
   else if (selectedAction == removeAction) {
     dispatcher->removeGroupInterface(ifaceItem);
   }
   else if (selectedAction == removeAction) {
     dispatcher->removeGroupInterface(ifaceItem);
   }
+  else if(selectedAction == showParameters) {
+    new ParametersWindow(refBlock, params, NULL);
+  }
 }
 
 InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
 }
 
 InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
@@ -548,6 +597,72 @@ InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
   return NULL;
 }
 
   return NULL;
 }
 
+void GroupItem::load(QDomElement groupElement) throw(Exception) {
+
+  GroupBlock* groupBlock = AB_TO_GRP(refBlock);
+
+  bool ok = false;
+
+  int id = groupElement.attribute("id","none").toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QString nameStr = groupElement.attribute("name","none");
+  if(nameStr == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList positionStr = groupElement.attribute("position","none").split(",");
+  if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posX = positionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int posY = positionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  QStringList dimensionStr = groupElement.attribute("dimension","none").split(",");
+  if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimX = dimensionStr.at(0).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+  int dimY = dimensionStr.at(1).toInt(&ok);
+  if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+  setId(id);
+  setPos(posX,posY);
+  setDimension(dimX,dimY);
+  groupBlock->setName(nameStr);
+
+  cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << nameStr.toStdString() << endl;
+
+  QDomNodeList interfaces = groupElement.elementsByTagName("group_iface");
+  for(int j=0; j<interfaces.length(); j++){
+    QDomElement currentInterfaceNode = interfaces.at(j).toElement();
+
+    int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString name = currentInterfaceNode.attribute("name","none");
+    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString directionStr = currentInterfaceNode.attribute("direction","none");
+    int direction = AbstractInterface::getIntDirection(directionStr);
+    if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    QString orientationStr = currentInterfaceNode.attribute("orientation","none");
+    int orientation = InterfaceItem::getIntOrientation(orientationStr);
+    if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
+
+    GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,AbstractInterface::Data);
+
+    InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,this,params);
+    interfaceItem->setId(id);
+
+    groupBlock->addInterface(groupInterface);
+    addInterface(interfaceItem, false);
+    cout << "interface add to " << groupBlock->getName().toStdString() << endl;
+  }
+
+}
+
 void GroupItem::save(QXmlStreamWriter &writer) {
 
   writer.writeStartElement("group_item");
 void GroupItem::save(QXmlStreamWriter &writer) {
 
   writer.writeStartElement("group_item");
@@ -558,7 +673,7 @@ void GroupItem::save(QXmlStreamWriter &writer) {
   if(parentItem != NULL){
     attrUpperItem = QString::number(parentItem->getId());
   }
   if(parentItem != NULL){
     attrUpperItem = QString::number(parentItem->getId());
   }
-  QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
+  QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
   QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
 
 
   QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
 
 
@@ -576,8 +691,7 @@ void GroupItem::save(QXmlStreamWriter &writer) {
     writer.writeStartElement("group_iface");
 
     writer.writeAttribute("id",QString::number(item->getId()));
     writer.writeStartElement("group_iface");
 
     writer.writeAttribute("id",QString::number(item->getId()));
-    writer.writeAttribute("name",item->getName());
-    writer.writeAttribute("level",QString(item->refInter->getLevelString()));
+    writer.writeAttribute("name",item->getName());    
     writer.writeAttribute("direction",QString(item->refInter->getDirectionString()));
     writer.writeAttribute("orientation",item->getStrOrientation());
     writer.writeAttribute("position",QString::number(item->getPositionRatio()));
     writer.writeAttribute("direction",QString(item->refInter->getDirectionString()));
     writer.writeAttribute("orientation",item->getStrOrientation());
     writer.writeAttribute("position",QString::number(item->getPositionRatio()));