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

Private GIT Repository
clkconvert OP compute done
[blast.git] / GroupScene.cpp
index b24c39cf48bdcbbbfeab3a956635e1f6395878c6..13b6e112b05834328d1fd1c7c7508a12b15fdd86 100644 (file)
@@ -5,10 +5,11 @@
 #include "GroupWidget.h"
 #include "GroupItem.h"
 #include "BoxItem.h"
 #include "GroupWidget.h"
 #include "GroupItem.h"
 #include "BoxItem.h"
-#include "SourceItem.h"
+#include "StimuliItem.h"
 #include "ConnectionItem.h"
 #include "InterfaceItem.h"
 #include "AbstractBlock.h"
 #include "ConnectionItem.h"
 #include "InterfaceItem.h"
 #include "AbstractBlock.h"
+#include "Graph.h"
 
 GroupScene::GroupScene(GroupScene *_parentScene, GroupWidget *_window, Dispatcher* _dispatcher, Parameters* _params, bool _topScene, QObject *parent) : QGraphicsScene(parent) {
   dispatcher = _dispatcher;
 
 GroupScene::GroupScene(GroupScene *_parentScene, GroupWidget *_window, Dispatcher* _dispatcher, Parameters* _params, bool _topScene, QObject *parent) : QGraphicsScene(parent) {
   dispatcher = _dispatcher;
@@ -38,6 +39,17 @@ GroupScene::~GroupScene() {
   groupItem = NULL;
 }
 
   groupItem = NULL;
 }
 
+/*
+void GroupScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+
+  //QGraphicsScene::mouseMoveEvent(event);
+  
+  QPointF p = event->scenePos();
+  cout << p.x() << "," << p.y() << endl;
+
+}
+*/
+
 void GroupScene::setSelectedInterface(int id, InterfaceItem* iface) {
   if ((id < 1)|| (id > 2)) return;
   selectedInterfaces[id-1] = iface;
 void GroupScene::setSelectedInterface(int id, InterfaceItem* iface) {
   if ((id < 1)|| (id > 2)) return;
   selectedInterfaces[id-1] = iface;
@@ -61,6 +73,11 @@ 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++);
+  if (isTopScene()) {
+    foreach(StimuliItem *item, stimuliItems){
+      item->setId(counter++);
+    } 
+  }
   foreach(BoxItem *item, boxItems){
     item->setId(counter++);
   }
   foreach(BoxItem *item, boxItems){
     item->setId(counter++);
   }
@@ -72,6 +89,13 @@ int GroupScene::setInterfacesId(int countInit) {
   foreach(InterfaceItem* inter, groupItem->getInterfaces()){
     inter->setId(counter++);
   }
   foreach(InterfaceItem* inter, groupItem->getInterfaces()){
     inter->setId(counter++);
   }
+  if (isTopScene()) {
+    foreach(StimuliItem *item, stimuliItems){
+      foreach(InterfaceItem* inter, item->getInterfaces()){
+        inter->setId(counter++);
+      }
+    } 
+  }
   foreach(BoxItem *item, boxItems){
     foreach(InterfaceItem* inter, item->getInterfaces()){
       inter->setId(counter++);
   foreach(BoxItem *item, boxItems){
     foreach(InterfaceItem* inter, item->getInterfaces()){
       inter->setId(counter++);
@@ -80,19 +104,40 @@ int GroupScene::setInterfacesId(int countInit) {
   return counter;
 }
 
   return counter;
 }
 
-BoxItem *GroupScene::createBoxItem(AbstractBlock *block) {
+BoxItem *GroupScene::createBoxItem(AbstractBlock *block, BoxItem::Position position, int lock, BoxItem::SpanType span) {
 
 
-  BoxItem* item = new BoxItem(block,dispatcher,params,groupItem);
+  BoxItem* item = new BoxItem(block,dispatcher,params,groupItem, lock, span, position);
   item->setZValue(1);
   // add item from the QList
   boxItems.append(item);
   // repainting the group
   groupItem->updateShape();
   item->setZValue(1);
   // add item from the QList
   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);
+
+/*
+  // position the new block
+  double x,y;
+  if (hPos == BoxItem::Left) {
+    x = 0;
+  }
+  else if (hPos == BoxItem::Center) {
+    x = (groupItem->getWidth()-item->getTotalWidth())/2.0;
+  }
+  else if (hPos == BoxItem::Right) {
+    x = groupItem->getWidth()-item->getTotalWidth();
+  }
+  if (vPos == BoxItem::Top) {
+    y = 0;
+  }
+  else if (vPos == BoxItem::Center) {
+    y = (groupItem->getHeight()-item->getTotalHeight())/2.0;
+  }
+  else if (vPos == BoxItem::Bottom) {
+    y = groupItem->getHeight()-item->getTotalHeight();
+  }
+  QPointF newPos(x,y);
   newPos = newPos-item->getOriginPoint();
   item->moveTo(newPos);
   newPos = newPos-item->getOriginPoint();
   item->moveTo(newPos);
-
+*/
   return item;
 }
 
   return item;
 }
 
@@ -112,43 +157,52 @@ void GroupScene::removeBoxItem(BoxItem* item) {
   groupItem->updateShape();
 }
 
   groupItem->updateShape();
 }
 
-SourceItem *GroupScene::createSourceItem(AbstractBlock *block) {
+BoxItem* GroupScene::searchBoxItemByName(QString name) {
+  foreach(BoxItem* item, boxItems) {
+    if (item->getRefBlock()->getName() == name) {
+      return item;
+    }
+  }
+  return NULL;
+}
+
+StimuliItem *GroupScene::createStimuliItem(AbstractBlock *block) {
 
 
-  SourceItem* item = new SourceItem(block,dispatcher,params);
+  StimuliItem* item = new StimuliItem(block,dispatcher,params);
   // adding item to the scene
   addItem(item);
   item->setZValue(1);
   // add item from the QList
   // adding item to the scene
   addItem(item);
   item->setZValue(1);
   // add item from the QList
-  sourceItems.append(item);    
+  stimuliItems.append(item);    
   // center the new block
   QPointF groupPos = groupItem->pos();
   // center the new block
   QPointF groupPos = groupItem->pos();
-  QPointF newPos(groupPos.x()-item->getTotalWidth()-50, groupPos.y());  
+  QPointF newPos(groupPos.x()-item->getTotalWidth()-100, groupPos.y());
   newPos = newPos-item->getOriginPoint();
   item->moveTo(newPos);
   return item;
 }
 
   newPos = newPos-item->getOriginPoint();
   item->moveTo(newPos);
   return item;
 }
 
-void GroupScene::addSourceItem(SourceItem* item) {  
+void GroupScene::addStimuliItem(StimuliItem* item) {  
+  // adding item to the scene
+  addItem(item);
+  item->setZValue(1);  
   // add item from the QList
   // add item from the QList
-  sourceItems.append(item);  
+  stimuliItems.append(item);  
 }
 
 }
 
-void GroupScene::removeSourceItem(SourceItem* item) {
+void GroupScene::removeStimuliItem(StimuliItem* 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
-  sourceItems.removeAll(item);  
+  stimuliItems.removeAll(item);  
 }
 
 }
 
-void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2, bool withinGroup) {
+void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2, bool visible) {
   ConnectionItem* conn = NULL;
   ConnectionItem* conn = NULL;
-  if (withinGroup) {
-    conn = new ConnectionItem(iface1,iface2, dispatcher, params, groupItem);
-  }
-  else {
-    conn = new ConnectionItem(iface1,iface2, dispatcher, params, NULL);
-    addItem(conn);
-  }
+  
+  conn = new ConnectionItem(iface1,iface2, dispatcher, params);
+  conn->setVisible(visible);
+  addItem(conn);  
   addConnectionItem(conn);
 }
 
   addConnectionItem(conn);
 }
 
@@ -170,6 +224,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
@@ -193,11 +254,11 @@ void GroupScene::unselecteInterfaces() {
 
   if (selectedInterfaces[0] != NULL) {
     selectedInterfaces[0]->selected = false;
 
   if (selectedInterfaces[0] != NULL) {
     selectedInterfaces[0]->selected = false;
-    selectedInterfaces[0] == NULL;
+    selectedInterfaces[0] = NULL;
   }
   if (selectedInterfaces[1] != NULL) {
     selectedInterfaces[1]->selected = false;
   }
   if (selectedInterfaces[1] != NULL) {
     selectedInterfaces[1]->selected = false;
-    selectedInterfaces[1] == NULL;
+    selectedInterfaces[1] = NULL;
   }
 }
 
   }
 }
 
@@ -217,12 +278,22 @@ void GroupScene::save(QXmlStreamWriter &writer) {
   else {
     writer.writeAttribute("upper_scene",QString::number(parentScene->getId()));
   }
   else {
     writer.writeAttribute("upper_scene",QString::number(parentScene->getId()));
   }
+  if (isTopScene()) {
+    QString clkList = "";
+    QList<double> lst = params->getGraph()->getClocks();
+    foreach(double d, lst) {
+      clkList += QString::number(d)+",";
+    }
+    clkList.chop(1);
+    writer.writeAttribute("clkList",clkList);
+
+  }
   groupItem->save(writer);
 
   if (isTopScene()) {
     writer.writeStartElement("source_items");
   groupItem->save(writer);
 
   if (isTopScene()) {
     writer.writeStartElement("source_items");
-    writer.writeAttribute("count",QString::number(sourceItems.length()));
-    foreach(SourceItem* item, sourceItems) {
+    writer.writeAttribute("count",QString::number(stimuliItems.length()));
+    foreach(StimuliItem* item, stimuliItems) {
       item->save(writer);
     }
     writer.writeEndElement(); // source_items
       item->save(writer);
     }
     writer.writeEndElement(); // source_items