X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/718736f825077e345ad396f78735c10e21547982..c8c1e24dac94abfacb78fb3b661c9a5dbbb0d86a:/Parameters.cpp?ds=inline

diff --git a/Parameters.cpp b/Parameters.cpp
index af8eb22..322046d 100644
--- a/Parameters.cpp
+++ b/Parameters.cpp
@@ -9,6 +9,7 @@
 #include "GroupScene.h"
 #include "GroupItem.h"
 #include "BoxItem.h"
+#include "SourceItem.h"
 #include "InterfaceItem.h"
 #include "ConnectionItem.h"
 
@@ -43,6 +44,8 @@ Parameters::Parameters() {
   isRstClkShown = false;
 
   projectPath = QDir::currentPath();
+  
+  validityExtension = "_enb";
 }
 
 Parameters::~Parameters() {
@@ -79,15 +82,6 @@ ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
 }
 
 
-FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {
-
-  ReferenceBlock* ref = block->getReference();
-  GroupBlock* group = AB_TO_GRP(block->getParent());
-
-  // adding to the graph
-  FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref);
-  return newBlock;
-}
 
 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
   // opening configFile
@@ -239,6 +233,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
     if (idUpperScene != -1) {
       groupWidget->setWindowTitle(groupBlock->getName());
       groupWidget->show();
+      cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;
     }    
   }
   dispatcher->setSceneCounter(maxIdScene+1);
@@ -256,7 +251,29 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
     GroupScene *currentScene = searchSceneById(idScene,topScene);
 
     if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
-
+    /**********************************************************
+     2.1 : getting sources if it is top scene
+    ***********************************************************/
+    if (currentScene->isTopScene()) {
+      QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");
+      cout << "top scene has " << sourceNodes.length() << " sources" << endl;
+      for(int j=0; j<sourceNodes.length(); j++) {
+        QDomElement currentSBNode = sourceNodes.at(j).toElement();      
+        SourceItem* sourceItem = new SourceItem(dispatcher,this);
+        try {
+          sourceItem->load(currentSBNode);
+        }
+        catch(Exception err) {
+          throw(err);
+        }
+        cout << "source item has been read, add it to the scene" << endl;
+        // add the block to the GroupScene
+        currentScene->addSourceItem(sourceItem);
+      } 
+    }
+    /**********************************************************
+     2.2 : getting functional blocks
+    ***********************************************************/
     QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
 
     for(int j=0; j<functionalBlockNodes.length(); j++) {
@@ -269,7 +286,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
         throw(err);
       }
       // add the block to the GroupScene
-      currentScene->addBlockItem(funcItem);
+      currentScene->addBoxItem(funcItem);
     }
   }
   cout << "functional blocks loaded and created succefully!" << endl;
@@ -313,9 +330,9 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
       // get the GroupItem already created and set at phase 1
       GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
       BoxItem* upperItem = NULL;
-      if(insideGroup == NULL) cout << "group null" << endl;
+      if(insideGroup == NULL) cout << "group null" << endl;      
       // now search within the scene which BoxItem has a childItem that is = to insideGroup
-      QList<BoxItem *> lst = currentScene->getBlockItems();
+      QList<BoxItem *> lst = currentScene->getBoxItems();
       foreach(BoxItem* item, lst) {
         if (item->getChildGroupItem() == insideGroup) {
           upperItem = item;
@@ -349,10 +366,10 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
         double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
 
-        ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter;
+        ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;
         InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
         ifaceItem->setId(id);
-        upperItem->addInterface(ifaceItem);
+        upperItem->addInterfaceItem(ifaceItem);
       }
     }
   }
@@ -374,7 +391,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
     InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
 
     if(iface1 != NULL && iface2 != NULL){
-      dispatcher->connect(iface1,iface2);
+      dispatcher->createConnection(iface1,iface2);
     } else {
       cout << "interfaces not found, connect canceled!" << endl;
     }
@@ -690,6 +707,12 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       QString refXml = implRoot.attribute("ref_name","none");
       QString refMd5 = implRoot.attribute("ref_md5","none");
       BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
+      try {
+        impl->loadPatterns(implRoot);
+      }
+      catch(int err) {
+        throw(err);
+      }
       availableImplementations.append(impl);
 
       ReferenceBlock* ref = NULL;
@@ -701,9 +724,12 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       }
       if (ref == NULL) {
         cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
-      }
-      ref->addImplementation(impl);
-      impl->setReference(ref);
+      }      
+      else {          
+        ref->addImplementation(impl);
+        impl->setReference(ref);
+        if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
+      }      
       cout << "OK" << endl;
     }
   }
@@ -748,8 +774,11 @@ void Parameters::loadImplementationsFromLib() throw(Exception) {
     if (ref == NULL) {
       cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
     }
-    ref->addImplementation(impl);
-    impl->setReference(ref);
+    else {          
+      ref->addImplementation(impl);
+      impl->setReference(ref);
+      if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
+    }
   }
   libFile.close();
 }
@@ -844,9 +873,9 @@ QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
 
 
 void Parameters::updateToolbar() {
-  int nb = currentScene->getBlockItems().length();
+  int nb = currentScene->getBoxItems().length();
   for(int i = 0; i<nb; i++){
-    if(currentScene->getBlockItems().at(i)->isSelected()){
+    if(currentScene->getBoxItems().at(i)->isSelected()){
       currentScene->getGroupWidget()->enableGroupButton(true);
       return;
     }
@@ -996,7 +1025,7 @@ GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
 
 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
 
-  foreach(BoxItem *item, scene->getBlockItems()){
+  foreach(BoxItem *item, scene->getBoxItems()){
     if(item->getId() == id){
       return item;
     }
@@ -1017,7 +1046,16 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
       return item;
     }
   }
-  foreach(BoxItem *block, scene->getBlockItems()){
+  if (scene->isTopScene()) {
+    foreach(SourceItem *block, scene->getSourceItems()){
+      foreach(InterfaceItem *item, block->getInterfaces()){
+        if(item->getId() == id){
+          return item;
+        }
+      }
+    } 
+  }
+  foreach(BoxItem *block, scene->getBoxItems()){
     foreach(InterfaceItem *item, block->getInterfaces()){
       if(item->getId() == id){
         return item;