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

Private GIT Repository
adding xsd files to master
[blast.git] / Dispatcher.cpp
index b191651df14951e2d3a1b3a6bbb7d692163338e6..73577b2a5fed6a991a55e760c10ea2436db8a01f 100644 (file)
@@ -44,6 +44,7 @@ GroupWidget *Dispatcher::loadProject(const QString& filename) {
     return NULL;
   }
 
     return NULL;
   }
 
+  /*
   // creating the top widget/scene
   topGroup = new GroupWidget(NULL,this,params);
   currentGroup = topGroup;
   // creating the top widget/scene
   topGroup = new GroupWidget(NULL,this,params);
   currentGroup = topGroup;
@@ -52,9 +53,9 @@ GroupWidget *Dispatcher::loadProject(const QString& filename) {
 
   params->setTopScene(scene);
   params->setCurrentScene(scene);
 
   params->setTopScene(scene);
   params->setCurrentScene(scene);
-
+*/
   try {   
   try {   
-    params->loadProject(root);
+    topGroup = params->loadProject(root);
   }
   catch(Exception e){
     cerr << qPrintable(e.getDefaultMessage()) << endl;
   }
   catch(Exception e){
     cerr << qPrintable(e.getDefaultMessage()) << endl;
@@ -72,7 +73,11 @@ void Dispatcher::closeCurrentProject() {
   foreach(GroupWidget* win, groupList) {
     win->deleteLater();
   }
   foreach(GroupWidget* win, groupList) {
     win->deleteLater();
   }
+  groupList.clear();
   params->destroyGraph();
   params->destroyGraph();
+  topGroup = NULL;
+  currentGroup = NULL;
+  sceneCounter = 0;
 }
 
 bool Dispatcher::connect(InterfaceItem *iface1, InterfaceItem *iface2) {
 }
 
 bool Dispatcher::connect(InterfaceItem *iface1, InterfaceItem *iface2) {
@@ -234,8 +239,6 @@ void Dispatcher::renameInterface(InterfaceItem *item) {
     if (item->refInter->getOwner()->isGroupBlock()) {
       item->refInter->setName(text);
     }
     if (item->refInter->getOwner()->isGroupBlock()) {
       item->refInter->setName(text);
     }
-    item->setName(text);
-
   }
   else {
     QMessageBox::warning(NULL,"Error in given name",
   }
   else {
     QMessageBox::warning(NULL,"Error in given name",
@@ -343,7 +346,7 @@ GroupWidget *Dispatcher::createTopScene(){
   return topGroup;
 }
 
   return topGroup;
 }
 
-void Dispatcher::addNewEmptyGroup(GroupScene* scene) {
+GroupWidget* Dispatcher::addNewEmptyGroup(GroupScene* scene, bool show) {
   static QString fctName = "Dispatcher::addNewEmptyGroup();";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
   static QString fctName = "Dispatcher::addNewEmptyGroup();";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
@@ -360,7 +363,8 @@ void Dispatcher::addNewEmptyGroup(GroupScene* scene) {
   params->unsaveModif = true;
 
   GroupWidget* child = createChildScene(scene->getGroupWidget(),newItem);
   params->unsaveModif = true;
 
   GroupWidget* child = createChildScene(scene->getGroupWidget(),newItem);
-  child->show();
+  if (show) child->show();
+  return child;
 
 }
 
 
 }
 
@@ -370,24 +374,38 @@ GroupWidget *Dispatcher::createChildScene(GroupWidget* parentWidget, BoxItem *up
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 
-  // getting back the goup block already created
-  GroupBlock* groupBlock = NULL;
-  if (upperItemOfGroupItem != NULL) {
-    groupBlock = AB_TO_GRP(upperItemOfGroupItem->getRefBlock());
-  }  
-  // creating the view part of the group
-  GroupItem *groupItem = new GroupItem(upperItemOfGroupItem,groupBlock,this,params);
-  // creating the group widget
-  GroupWidget* group = new GroupWidget(parentWidget, this, params);
-  // getting the newly created scene
-  GroupScene *scene = group->getScene();
-  scene->setId(sceneCounter++);
-  // affecting group item to the scene
-  scene->setGroupItem(groupItem);
-  groupList.append(group);
-
-  mainWindow->getLibrary()->updateComboScene();
+  GroupWidget* group = NULL;
+  /* NB: this method may be called during design process or when loading
+     a project. In this case, upperItemOfGroupItem is NULL, thus a lot of things
+     cannot be initialized yet. This is why there are 2 cases below
+   */
 
 
+  if (upperItemOfGroupItem != NULL) {
+    // getting back the goup block already created
+    GroupBlock* groupBlock = AB_TO_GRP(upperItemOfGroupItem->getRefBlock());
+    // creating the view part of the group
+    GroupItem *groupItem = new GroupItem(upperItemOfGroupItem,groupBlock,this,params);
+    // creating the group widget
+    group = new GroupWidget(parentWidget, this, params);
+    // getting the newly created scene
+    GroupScene *scene = group->getScene();
+    scene->setId(sceneCounter++);
+    // affecting group item to the scene
+    scene->setGroupItem(groupItem);
+    groupList.append(group);
+
+    mainWindow->getLibrary()->updateComboScene();
+  }
+  else {
+    GroupItem *groupItem = new GroupItem(this,params);
+    // creating the group widget
+    group = new GroupWidget(parentWidget, this, params);
+    // getting the newly created scene
+    GroupScene *scene = group->getScene();
+    // affecting group item to the scene
+    scene->setGroupItem(groupItem);
+    groupList.append(group);
+  }
   return group;
 }
 
   return group;
 }
 
@@ -789,7 +807,7 @@ void Dispatcher::connectInterToGroup(InterfaceItem *item){
   GroupItem *parentItem = item->getOwner()->getScene()->getGroupItem();
 
   // creating/adding the group interface in the graph model
   GroupItem *parentItem = item->getOwner()->getScene()->getGroupItem();
 
   // creating/adding the group interface in the graph model
-  GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection(),refInter->getLevel());
+  GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection());
   groupInter->setType(refInter->getType());
   groupInter->setWidth(refInter->getWidth());
   groupInter->setPurpose(refInter->getPurpose());
   groupInter->setType(refInter->getType());
   groupInter->setWidth(refInter->getWidth());
   groupInter->setPurpose(refInter->getPurpose());