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

Private GIT Repository
corrected some warnings
[blast.git] / GroupScene.cpp
index daf6bf1e2102d782f883655dd708b8b899786169..48de27e6ff76b81a85c5c035337ad98aa3169564 100644 (file)
@@ -5,6 +5,7 @@
 #include "GroupWidget.h"
 #include "GroupItem.h"
 #include "BoxItem.h"
 #include "GroupWidget.h"
 #include "GroupItem.h"
 #include "BoxItem.h"
+#include "SourceItem.h"
 #include "ConnectionItem.h"
 #include "InterfaceItem.h"
 #include "AbstractBlock.h"
 #include "ConnectionItem.h"
 #include "InterfaceItem.h"
 #include "AbstractBlock.h"
@@ -27,7 +28,12 @@ GroupScene::GroupScene(GroupScene *_parentScene, GroupWidget *_window, Dispatche
 }
 
 GroupScene::~GroupScene() {
 }
 
 GroupScene::~GroupScene() {
-  blockItems.clear();
+  static QString fctName = "GroupScene::~GroupScene()";
+#ifdef DEBUG_FCTNAME
+  cout << "call to " << qPrintable(fctName) << endl;
+#endif
+  
+  boxItems.clear();
   connectionItems.clear();
   groupItem = NULL;
 }
   connectionItems.clear();
   groupItem = NULL;
 }
@@ -44,7 +50,7 @@ InterfaceItem* GroupScene::getSelectedInterface(int id) {
 
 QList<BoxItem *> GroupScene::getSelectedBlocks() {
   QList<BoxItem*> lst;
 
 QList<BoxItem *> GroupScene::getSelectedBlocks() {
   QList<BoxItem*> lst;
-  foreach(BoxItem *item, blockItems){
+  foreach(BoxItem *item, boxItems){
     if (item->isSelected()){
       lst.append(item);
     }
     if (item->isSelected()){
       lst.append(item);
     }
@@ -55,7 +61,12 @@ QList<BoxItem *> GroupScene::getSelectedBlocks() {
 int GroupScene::setItemsId(int countInit) {
   int counter = countInit;
   groupItem->setId(counter++);
 int GroupScene::setItemsId(int countInit) {
   int counter = countInit;
   groupItem->setId(counter++);
-  foreach(BoxItem *item, blockItems){
+  if (isTopScene()) {
+    foreach(SourceItem *item, sourceItems){
+      item->setId(counter++);
+    } 
+  }
+  foreach(BoxItem *item, boxItems){
     item->setId(counter++);
   }
   return counter;
     item->setId(counter++);
   }
   return counter;
@@ -66,7 +77,14 @@ int GroupScene::setInterfacesId(int countInit) {
   foreach(InterfaceItem* inter, groupItem->getInterfaces()){
     inter->setId(counter++);
   }
   foreach(InterfaceItem* inter, groupItem->getInterfaces()){
     inter->setId(counter++);
   }
-  foreach(BoxItem *item, blockItems){
+  if (isTopScene()) {
+    foreach(SourceItem *item, sourceItems){
+      foreach(InterfaceItem* inter, item->getInterfaces()){
+        inter->setId(counter++);
+      }
+    } 
+  }
+  foreach(BoxItem *item, boxItems){
     foreach(InterfaceItem* inter, item->getInterfaces()){
       inter->setId(counter++);
     }
     foreach(InterfaceItem* inter, item->getInterfaces()){
       inter->setId(counter++);
     }
@@ -74,48 +92,74 @@ int GroupScene::setInterfacesId(int countInit) {
   return counter;
 }
 
   return counter;
 }
 
-QList<AbstractBoxItem*> GroupScene::getGroupAndBlocks() {
-
-  QList<AbstractBoxItem*> lst;
-  lst.append(groupItem);
-  foreach(BoxItem *item, blockItems){
-    lst.append(item);
-  }
-  return lst;
-}
-
-BoxItem *GroupScene::createBlockItem(AbstractBlock *block) {
+BoxItem *GroupScene::createBoxItem(AbstractBlock *block) {
 
 
-  BoxItem* blockItem = new BoxItem(block,dispatcher,params,groupItem);
-  blockItem->setZValue(1);
-  addBlockItem(blockItem);
-  return blockItem;
-}
-
-void GroupScene::addBlockItem(BoxItem* item) {
-  // add item from the viewport
-  //addItem(item);
+  BoxItem* item = new BoxItem(block,dispatcher,params,groupItem);
+  item->setZValue(1);
   // add item from the QList
   // add item from the QList
-  blockItems.append(item);
+  boxItems.append(item);
   // repainting the group
   groupItem->updateShape();
   // center the new block
   QPointF newPos((groupItem->getWidth()-item->getTotalWidth())/2.0, (groupItem->getHeight()-item->getTotalHeight())/2.0);
   newPos = newPos-item->getOriginPoint();
   // repainting the group
   groupItem->updateShape();
   // center the new block
   QPointF newPos((groupItem->getWidth()-item->getTotalWidth())/2.0, (groupItem->getHeight()-item->getTotalHeight())/2.0);
   newPos = newPos-item->getOriginPoint();
-  item->moveTo(newPos);  
+  item->moveTo(newPos);
+
+  return item;
 }
 
 }
 
-void GroupScene::removeBlockItem(BoxItem* item) {
+void GroupScene::addBoxItem(BoxItem* item) {  
+  // add item from the QList
+  boxItems.append(item);
+  // repainting the group
+  groupItem->updateShape();  
+}
+
+void GroupScene::removeBoxItem(BoxItem* item) {
   // remove item from the viewport
   removeItem(item);
   // remove item from the QList
   // remove item from the viewport
   removeItem(item);
   // remove item from the QList
-  blockItems.removeAll(item);
+  boxItems.removeAll(item);
   // repainting the group
   groupItem->updateShape();
 }
 
   // repainting the group
   groupItem->updateShape();
 }
 
+SourceItem *GroupScene::createSourceItem(AbstractBlock *block) {
+
+  SourceItem* item = new SourceItem(block,dispatcher,params);
+  // adding item to the scene
+  addItem(item);
+  item->setZValue(1);
+  // add item from the QList
+  sourceItems.append(item);    
+  // center the new block
+  QPointF groupPos = groupItem->pos();
+  QPointF newPos(groupPos.x()-item->getTotalWidth()-50, groupPos.y());  
+  newPos = newPos-item->getOriginPoint();
+  item->moveTo(newPos);
+  return item;
+}
+
+void GroupScene::addSourceItem(SourceItem* item) {  
+  // adding item to the scene
+  addItem(item);
+  item->setZValue(1);  
+  // add item from the QList
+  sourceItems.append(item);  
+}
+
+void GroupScene::removeSourceItem(SourceItem* item) {
+  // remove item from the viewport
+  removeItem(item);
+  // remove item from the QList
+  sourceItems.removeAll(item);  
+}
+
 void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2) {
 void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2) {
-  ConnectionItem* conn = new ConnectionItem(iface1,iface2, dispatcher, params, groupItem);
+  ConnectionItem* conn = NULL;
+  
+  conn = new ConnectionItem(iface1,iface2, dispatcher, params);
+  addItem(conn);  
   addConnectionItem(conn);
 }
 
   addConnectionItem(conn);
 }
 
@@ -126,6 +170,7 @@ ConnectionItem* GroupScene::searchConnectionItem(InterfaceItem *iface1, Interfac
       return conn;
     }
   }
       return conn;
     }
   }
+  return NULL;
 }
 
 void GroupScene::addConnectionItem(ConnectionItem* item) {
 }
 
 void GroupScene::addConnectionItem(ConnectionItem* item) {
@@ -136,6 +181,13 @@ void GroupScene::addConnectionItem(ConnectionItem* item) {
 }
 
 void GroupScene::removeConnectionItem(ConnectionItem* item) {
 }
 
 void GroupScene::removeConnectionItem(ConnectionItem* item) {
+  
+  // remove connection from/to InterfaceItem
+  InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();
+  InterfaceItem* toIfaceItem = item->getToInterfaceItem();
+  fromIfaceItem->removeConnectionItem(item);
+  toIfaceItem->removeConnectionItem(item);
+  
   // remove item from the viewport
   removeItem(item);
   // remove item from the QList
   // remove item from the viewport
   removeItem(item);
   // remove item from the QList
@@ -155,16 +207,6 @@ void GroupScene::removeGroupItem() {
   groupItem = NULL;
 }
 
   groupItem = NULL;
 }
 
-QList<ConnectionItem *> GroupScene::getInterfaceConnections(InterfaceItem *item) {
-  QList<ConnectionItem*> list;
-  foreach(ConnectionItem *conn, connectionItems){
-    if(conn->getFromInterfaceItem() == item || conn->getToInterfaceItem() == item){
-      list.append(conn);
-    }
-  }
-  return list;
-}
-
 void GroupScene::unselecteInterfaces() {
 
   if (selectedInterfaces[0] != NULL) {
 void GroupScene::unselecteInterfaces() {
 
   if (selectedInterfaces[0] != NULL) {
@@ -187,14 +229,28 @@ void GroupScene::updateConnectionItemsShape() {
 void GroupScene::save(QXmlStreamWriter &writer) {
   writer.writeStartElement("scene");
   writer.writeAttribute("id",QString::number(id));
 void GroupScene::save(QXmlStreamWriter &writer) {
   writer.writeStartElement("scene");
   writer.writeAttribute("id",QString::number(id));
+  if (parentScene == NULL) {
+    writer.writeAttribute("upper_scene",QString::number(-1));
+  }
+  else {
+    writer.writeAttribute("upper_scene",QString::number(parentScene->getId()));
+  }
   groupItem->save(writer);
 
   groupItem->save(writer);
 
+  if (isTopScene()) {
+    writer.writeStartElement("source_items");
+    writer.writeAttribute("count",QString::number(sourceItems.length()));
+    foreach(SourceItem* item, sourceItems) {
+      item->save(writer);
+    }
+    writer.writeEndElement(); // source_items
+  }
   writer.writeStartElement("block_items");
 
   QList<BoxItem *> functionalBlocks;
   QList<BoxItem *> groupBlocks;
 
   writer.writeStartElement("block_items");
 
   QList<BoxItem *> functionalBlocks;
   QList<BoxItem *> groupBlocks;
 
-  foreach(BoxItem *item, blockItems){
+  foreach(BoxItem *item, boxItems){
     if(item->getRefBlock()->isFunctionalBlock()){
       functionalBlocks.append(item);
     } else if(item->getRefBlock()->isGroupBlock()){
     if(item->getRefBlock()->isFunctionalBlock()){
       functionalBlocks.append(item);
     } else if(item->getRefBlock()->isGroupBlock()){