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

Private GIT Repository
modif in VHDLConverter
[blast.git] / Parameters.cpp
index fce043506b96dce7c4a8ccb6962ceb386345dd11..322046d562819e107c937856ef2536e2edf8ba31 100644 (file)
@@ -9,6 +9,7 @@
 #include "GroupScene.h"\r
 #include "GroupItem.h"\r
 #include "BoxItem.h"\r
+#include "SourceItem.h"\r
 #include "InterfaceItem.h"\r
 #include "ConnectionItem.h"\r
 \r
@@ -43,6 +44,8 @@ Parameters::Parameters() {
   isRstClkShown = false;\r
 \r
   projectPath = QDir::currentPath();\r
+  \r
+  validityExtension = "_enb";\r
 }\r
 \r
 Parameters::~Parameters() {\r
@@ -79,15 +82,6 @@ ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
 }\r
 \r
 \r
-FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {\r
-\r
-  ReferenceBlock* ref = block->getReference();\r
-  GroupBlock* group = AB_TO_GRP(block->getParent());\r
-\r
-  // adding to the graph\r
-  FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref);\r
-  return newBlock;\r
-}\r
 \r
 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {\r
   // opening configFile\r
@@ -189,115 +183,65 @@ QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Ex
   return root;\r
 }\r
 \r
-void Parameters::loadProject(QDomElement root) {\r
-\r
-#ifdef DEBUG_INCLFUN\r
+GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {\r
 \r
   bool ok = false;\r
   GroupWidget* groupWidget = NULL;\r
   GroupItem *groupItem = NULL;\r
   GroupBlock *groupBlock = NULL;\r
 \r
+  GroupWidget* topGroup = NULL;\r
   /**********************************************************\r
    1 : getting scene and creating associated group widgets\r
   ***********************************************************/\r
   QDomNodeList scenesNodes = root.elementsByTagName("scene");\r
 \r
+  int maxIdScene = -1;\r
   for(int i=0; i<scenesNodes.length(); i++) {\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
     int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+    if (idScene > maxIdScene) maxIdScene = idScene;\r
     int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);\r
     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
     if (idUpperScene == -1) {\r
-      dispatcher->createTopScene();\r
+      topGroup = dispatcher->createTopScene();\r
       topScene->setId(idScene);\r
-      groupItem = topScene->getGroupItem();\r
-      groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+      groupItem = topScene->getGroupItem();      \r
       cout << "top group added to scene n°" << idScene << endl;\r
     }\r
     else {\r
-      GroupScene* scene = searchSceneById(idUpperScene, topScene);\r
-      GroupWidget* parent = scene->getGroupWindow();\r
-      groupWidget = dispatcher->createChildScene(parent);\r
-      groupItem = groupWidget->getScene()->getGroupItem();\r
-      groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+      cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;\r
+      GroupScene* upperScene = searchSceneById(idUpperScene, topScene);\r
+      groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);\r
+      groupWidget->getScene()->setId(idScene);\r
+      groupItem = groupWidget->getScene()->getGroupItem();      \r
     }\r
+    groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
     /**********************************************************\r
-     1.1 : getting the group item\r
+     1.1 : getting the group item of each scene\r
     ***********************************************************/\r
     QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
-\r
-    int id = groupItemNode.attribute("id","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QString name = groupItemNode.attribute("name","none");\r
-    if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QStringList positionStr = groupItemNode.attribute("position","none").split(",");\r
-    if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int posX = positionStr.at(0).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int posY = positionStr.at(1).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");\r
-    if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int dimX = dimensionStr.at(0).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int dimY = dimensionStr.at(1).toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    groupItem->setId(id);\r
-    groupItem->setPos(posX,posY);\r
-    groupItem->setDimension(dimX,dimY);\r
-    groupBlock->setName(name);\r
+    try {\r
+      groupItem->load(groupItemNode);\r
+    }\r
+    catch(Exception err) {\r
+      throw(err);\r
+    }\r
 \r
     if (idUpperScene != -1) {\r
       groupWidget->setWindowTitle(groupBlock->getName());\r
       groupWidget->show();\r
-    }\r
-    cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;\r
-\r
-    QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");\r
-    for(int j=0; j<interfaces.length(); j++){\r
-      QDomElement currentInterfaceNode = interfaces.at(j).toElement();\r
-\r
-      int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString name = currentInterfaceNode.attribute("name","none");\r
-      if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString levelStr = currentInterfaceNode.attribute("level","none");\r
-      int level = AbstractInterface::getIntLevel(levelStr);\r
-      if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString directionStr = currentInterfaceNode.attribute("direction","none");\r
-      int direction = AbstractInterface::getIntDirection(directionStr);\r
-      if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
-      int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
-      if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);\r
-\r
-      InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);\r
-      interfaceItem->setId(id);\r
-\r
-      groupBlock->addInterface(groupInterface);\r
-      groupItem->addInterface(interfaceItem);\r
-      cout << "interface add to " << groupBlock->getName().toStdString() << endl;\r
-    }\r
+      cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;\r
+    }    \r
   }\r
-\r
+  dispatcher->setSceneCounter(maxIdScene+1);\r
   cout << "groupItems loaded and windows created succefully!" << endl;\r
 \r
+  /**********************************************************\r
+   2 : getting the functional blocks of each scene\r
+  ***********************************************************/\r
 \r
   for(int i=0; i<scenesNodes.length(); i++){\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
@@ -307,137 +251,49 @@ void Parameters::loadProject(QDomElement root) {
     GroupScene *currentScene = searchSceneById(idScene,topScene);\r
 \r
     if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
+    /**********************************************************\r
+     2.1 : getting sources if it is top scene\r
+    ***********************************************************/\r
+    if (currentScene->isTopScene()) {\r
+      QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");\r
+      cout << "top scene has " << sourceNodes.length() << " sources" << endl;\r
+      for(int j=0; j<sourceNodes.length(); j++) {\r
+        QDomElement currentSBNode = sourceNodes.at(j).toElement();      \r
+        SourceItem* sourceItem = new SourceItem(dispatcher,this);\r
+        try {\r
+          sourceItem->load(currentSBNode);\r
+        }\r
+        catch(Exception err) {\r
+          throw(err);\r
+        }\r
+        cout << "source item has been read, add it to the scene" << endl;\r
+        // add the block to the GroupScene\r
+        currentScene->addSourceItem(sourceItem);\r
+      } \r
+    }\r
+    /**********************************************************\r
+     2.2 : getting functional blocks\r
+    ***********************************************************/\r
     QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");\r
 \r
-    for(int j=0; j<functionalBlockNodes.length(); j++){\r
-      QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();\r
-\r
-      int id = currentFBNode.attribute("id","none").toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString refXml = currentFBNode.attribute("ref_xml","none");\r
-      if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QString refMd5 = currentFBNode.attribute("ref_md5","none");\r
-      if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;\r
-\r
-      QString name = currentFBNode.attribute("name","none");\r
-      if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QStringList positionStr = currentFBNode.attribute("position","none").split(",");\r
-      if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int posX = positionStr.at(0).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int posY = positionStr.at(1).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");\r
-      if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int dimX = dimensionStr.at(0).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-      int dimY = dimensionStr.at(1).toInt(&ok);\r
-      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-      AbstractBlock *reference;\r
-      /*if(refMd5 != "none"){\r
-        cout << "md5" << endl;\r
-        reference = searchBlockByMd5(refMd5);\r
-      }\r
-      else */if(refXml != "none"){\r
-        cout << "xml" << endl;\r
-        reference = searchBlockByXml(refXml);\r
-      }\r
-      else {\r
-        throw(Exception(PROJECTFILE_CORRUPTED));\r
-      }\r
-\r
-      FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);\r
-      functionalBlock->setName(name);\r
-\r
-      ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);\r
-\r
-\r
-      BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);\r
-      blockItem->setPos(posX,posY);\r
-      blockItem->setDimension(dimX,dimY);\r
-      blockItem->setId(id);\r
-      ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
-      currentScene->addItem(blockItem);\r
-      currentScene->addBlockItem(blockItem);\r
-\r
-      QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");\r
-\r
-      for(int i=0; i<blockParamNodes.length(); i++){\r
-        QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();\r
-\r
-        QString name = currentBlockParamNode.attribute("name","none");\r
-        if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString value = currentBlockParamNode.attribute("value","none");\r
-        if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString context = currentBlockParamNode.attribute("context","none");\r
-        if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString type = currentBlockParamNode.attribute("type","none");\r
-        if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-\r
-        BlockParameter *blockParam = new BlockParameter;\r
-        blockParam->setName(name);\r
-        blockParam->setValue(value);\r
-        blockParam->setType(type);\r
-        if(context == "constant") blockParam->setContext(BlockParameter::Constant);\r
-        if(context == "user") blockParam->setContext(BlockParameter::User);\r
-        if(context == "generic") blockParam->setContext(BlockParameter::Generic);\r
-        if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);\r
-        if(context == "port") blockParam->setContext(BlockParameter::Port);\r
-\r
-        functionalBlock->addParameter(blockParam);\r
+    for(int j=0; j<functionalBlockNodes.length(); j++) {\r
+      QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();      \r
+      BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());\r
+      try {\r
+        funcItem->loadFunctional(currentFBNode);\r
       }\r
-\r
-\r
-      QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");\r
-\r
-      for(int i=0; i<interfaceNodes.length(); i++){\r
-\r
-        QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();\r
-\r
-        int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
-        if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString name = currentInterfaceNode.attribute("name","none");\r
-        if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString refName = currentInterfaceNode.attribute("ref_name","none");\r
-        if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
-        int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
-        if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
-        if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-        ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);\r
-        FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);\r
-        functionalBlock->addInterface(functionalInterface);\r
-        functionalInterface->setName(refName);\r
-\r
-        InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);\r
-        interfaceItem->setId(id);\r
-        interfaceItem->setName(name);\r
-\r
-        blockItem->addInterface(interfaceItem);\r
-\r
+      catch(Exception err) {\r
+        throw(err);\r
       }\r
+      // add the block to the GroupScene\r
+      currentScene->addBoxItem(funcItem);\r
     }\r
   }\r
-  cout << "functionalBlocks loaded and created succefully!" << endl;\r
+  cout << "functional blocks loaded and created succefully!" << endl;\r
 \r
+  /**********************************************************\r
+   3 : set the BoxItem that represents a GroupItem in a child scene\r
+  ***********************************************************/\r
 \r
   for(int i=0; i<scenesNodes.length(); i++){\r
     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
@@ -471,19 +327,27 @@ void Parameters::loadProject(QDomElement root) {
       int dimY = dimensionStr.at(1).toInt(&ok);\r
       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
-\r
+      // get the GroupItem already created and set at phase 1\r
       GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);\r
-      if(insideGroup == NULL) cout << "group null" << endl;\r
-      BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);\r
-      blockItem->setChildGroupItem(insideGroup);\r
-      blockItem->setId(id);\r
-      blockItem->setPos(posX,posY);\r
-      blockItem->setDimension(dimX,dimY);\r
+      BoxItem* upperItem = NULL;\r
+      if(insideGroup == NULL) cout << "group null" << endl;      \r
+      // now search within the scene which BoxItem has a childItem that is = to insideGroup\r
+      QList<BoxItem *> lst = currentScene->getBoxItems();\r
+      foreach(BoxItem* item, lst) {\r
+        if (item->getChildGroupItem() == insideGroup) {\r
+          upperItem = item;\r
+          break;\r
+        }\r
+      }\r
+      if (upperItem == NULL) {\r
+        throw(Exception(PROJECTFILE_CORRUPTED));\r
+      }\r
 \r
-      ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
-      currentScene->addItem(blockItem);\r
-      currentScene->addBlockItem(blockItem);\r
+      upperItem->setId(id);\r
+      upperItem->setPos(posX,posY);\r
+      upperItem->setDimension(dimX,dimY);\r
 \r
+      // set interfaces of this BoxItem\r
       QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");\r
 \r
       for(int k=0; k<interfaceNodes.length(); k++){\r
@@ -502,34 +366,15 @@ void Parameters::loadProject(QDomElement root) {
         double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
 \r
-        GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;\r
-        InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);\r
+        ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;\r
+        InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);\r
         ifaceItem->setId(id);\r
-        blockItem->addInterface(ifaceItem);\r
+        upperItem->addInterfaceItem(ifaceItem);\r
       }\r
     }\r
   }\r
   cout << "blockItems \"group\" loaded and created succefully!" << endl;\r
 \r
-\r
-  for(int i=0; i<scenesNodes.length(); i++){\r
-    QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
-\r
-    QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
-\r
-    int id = groupItemNode.attribute("id","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-    int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);\r
-    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
-    BlockItem *currentItem = searchBlockItemById(id,topScene);\r
-    GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);\r
-\r
-    if(currentItem != NULL && upperItem != NULL){\r
-      currentItem->setUpperItem(upperItem);\r
-    }\r
-  }\r
-\r
   QDomNodeList connectionNodes = root.elementsByTagName("connection");\r
 \r
   for(int i=0; i<connectionNodes.length(); i++){\r
@@ -546,13 +391,14 @@ void Parameters::loadProject(QDomElement root) {
     InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);\r
 \r
     if(iface1 != NULL && iface2 != NULL){\r
-      dispatcher->connect(iface1,iface2);\r
+      dispatcher->createConnection(iface1,iface2);\r
     } else {\r
       cout << "interfaces not found, connect canceled!" << endl;\r
     }\r
   }\r
+  cout << "connections loaded and created succefully!" << endl;\r
 \r
-#endif\r
+  return topGroup;\r
 }\r
 \r
 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {\r
@@ -700,7 +546,7 @@ void Parameters::loadReferencesFromXml() throw(Exception) {
 \r
       blockXML.close();\r
       try {\r
-        validateXmlFile(fileName,"block.xsd",Reference);\r
+        validateXmlFile(fileName,"reference.xsd",Reference);\r
       }\r
       catch(Exception err) {\r
         throw(err);\r
@@ -836,14 +682,14 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       implXML.close();\r
       cout << "OK" << endl;\r
       cout << "reading " << qPrintable(fileName) << " content ...";\r
-      /*\r
+\r
       try {\r
-        validateXmlFile(fileName,"block.xsd",Implementation);\r
+        validateXmlFile(fileName,"implementation.xsd",Implementation);\r
       }\r
       catch(Exception e) {\r
         throw(e);\r
       }\r
-      */\r
+\r
       // reading in into QDomDocument\r
       QDomDocument document ("FileXML");\r
       if (!implXML.open(QIODevice::ReadOnly)) {\r
@@ -861,6 +707,12 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       QString refXml = implRoot.attribute("ref_name","none");\r
       QString refMd5 = implRoot.attribute("ref_md5","none");\r
       BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);\r
+      try {\r
+        impl->loadPatterns(implRoot);\r
+      }\r
+      catch(int err) {\r
+        throw(err);\r
+      }\r
       availableImplementations.append(impl);\r
 \r
       ReferenceBlock* ref = NULL;\r
@@ -872,9 +724,12 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       }\r
       if (ref == NULL) {\r
         cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;\r
-      }\r
-      ref->addImplementation(impl);\r
-      impl->setReference(ref);\r
+      }      \r
+      else {          \r
+        ref->addImplementation(impl);\r
+        impl->setReference(ref);\r
+        if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));\r
+      }      \r
       cout << "OK" << endl;\r
     }\r
   }\r
@@ -919,8 +774,11 @@ void Parameters::loadImplementationsFromLib() throw(Exception) {
     if (ref == NULL) {\r
       cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;\r
     }\r
-    ref->addImplementation(impl);\r
-    impl->setReference(ref);\r
+    else {          \r
+      ref->addImplementation(impl);\r
+      impl->setReference(ref);\r
+      if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));\r
+    }\r
   }\r
   libFile.close();\r
 }\r
@@ -1015,9 +873,9 @@ QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
 \r
 \r
 void Parameters::updateToolbar() {\r
-  int nb = currentScene->getBlockItems().length();\r
+  int nb = currentScene->getBoxItems().length();\r
   for(int i = 0; i<nb; i++){\r
-    if(currentScene->getBlockItems().at(i)->isSelected()){\r
+    if(currentScene->getBoxItems().at(i)->isSelected()){\r
       currentScene->getGroupWidget()->enableGroupButton(true);\r
       return;\r
     }\r
@@ -1167,7 +1025,7 @@ GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
 \r
 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {\r
 \r
-  foreach(BoxItem *item, scene->getBlockItems()){\r
+  foreach(BoxItem *item, scene->getBoxItems()){\r
     if(item->getId() == id){\r
       return item;\r
     }\r
@@ -1188,7 +1046,16 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
       return item;\r
     }\r
   }\r
-  foreach(BoxItem *block, scene->getBlockItems()){\r
+  if (scene->isTopScene()) {\r
+    foreach(SourceItem *block, scene->getSourceItems()){\r
+      foreach(InterfaceItem *item, block->getInterfaces()){\r
+        if(item->getId() == id){\r
+          return item;\r
+        }\r
+      }\r
+    } \r
+  }\r
+  foreach(BoxItem *block, scene->getBoxItems()){\r
     foreach(InterfaceItem *item, block->getInterfaces()){\r
       if(item->getId() == id){\r
         return item;\r