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

Private GIT Repository
add graph modif, progress on vhdl generation
[blast.git] / Parameters.cpp
index 322046d562819e107c937856ef2536e2edf8ba31..d3a8dd4f7c669328a4ec87fad7fb880680d77872 100644 (file)
 #include "Exception.h"\r
 #include "BlocksToConfigureWidget.h"\r
 \r
+#include "BlockParameterGeneric.h"\r
+\r
+#include "DelayInputModifier.h"\r
+\r
 Parameters::Parameters() {\r
   categoryTree = NULL;\r
   arrowWidth = 5;\r
@@ -81,6 +85,48 @@ ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
   return ref;\r
 }\r
 \r
+void Parameters::createDelayBlock() {\r
+  delayRef = new ReferenceBlock("no.xml");\r
+  delayRef->addCategory(100);\r
+  delayRef->setName("delay");\r
+\r
+  BlockCategory* cat = categoryTree->searchCategory(100);\r
+  cat->blocks.append(delayRef);\r
+\r
+  AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width");\r
+  delayRef->addInterface(interIn);\r
+  AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1");\r
+  delayRef->addInterface(interInCtl);\r
+  interInCtl->setAssociatedIface(interIn);\r
+  AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width");\r
+  delayRef->addInterface(interOut);\r
+  AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1");\r
+  delayRef->addInterface(interOutCtl);\r
+  interOutCtl->setAssociatedIface(interOut);\r
+  BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8");\r
+  BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1");\r
+  delayRef->addParameter(param1);\r
+  delayRef->addParameter(param2);\r
+  delayImpl = new BlockImplementation("no.xml");\r
+  delayImpl->setDelta("1");\r
+  QHash<QString,QString> consPattern;\r
+  consPattern.insert("data_in_enb","1");\r
+  delayImpl->setConsumptionPattern(consPattern);\r
+  QHash<QString,QString> prodPattern;\r
+  prodPattern.insert("data_out_enb","O{$dly_length}1");\r
+  delayImpl->setProductionPattern(prodPattern);\r
+  delayImpl->setProductionCounter("1");\r
+  delayRef->addImplementation(delayImpl);\r
+  delayImpl->setReference(delayRef);\r
+  if (! delayImpl->checkPatterns()) {\r
+    cout << "Delay block creation: failure" << endl;\r
+  }\r
+  else {\r
+    cout << "Delay block creation: success" << endl;\r
+  }\r
+\r
+}\r
+\r
 \r
 \r
 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {\r
@@ -398,6 +444,38 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
   }\r
   cout << "connections loaded and created succefully!" << endl;\r
 \r
+  QDomNodeList modifierNodes = root.elementsByTagName("modifier");\r
+\r
+  for(int i=0; i<modifierNodes.length(); i++){\r
+    QDomElement currentModifierNode = modifierNodes.at(i).toElement();\r
+\r
+    int id = currentModifierNode.attribute("id","none").toInt(&ok);\r
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+    QString typeStr = currentModifierNode.attribute("type","none");\r
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+    QString paramsStr = currentModifierNode.attribute("params","none");\r
+    if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+    AbstractInputModifier* mod = NULL;\r
+    if (typeStr == "delay") {\r
+      int delay = paramsStr.toInt(&ok);\r
+      if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+      mod = new DelayInputModifier(delay);\r
+    }\r
+\r
+    /* NB: just adding delays for now. To be cont'd */\r
+    InterfaceItem *iface = searchInterfaceItemById(id,topScene);\r
+\r
+    if(iface != NULL ) {\r
+      iface->refInter->setInputModifier(mod);\r
+\r
+    } else {\r
+      cout << "interfaces not found, modifiers setup canceled!" << endl;\r
+    }\r
+  }\r
+  cout << "modifiers loaded and created succefully!" << endl;\r
+\r
   return topGroup;\r
 }\r
 \r
@@ -539,7 +617,7 @@ void Parameters::loadReferencesFromXml() throw(Exception) {
       QString line = in.readLine();\r
       line = in.readLine();\r
 \r
-      if (!line.contains("<block>")) {\r
+      if (!line.contains("<block")) {\r
         blockXML.close();\r
         continue;\r
       }\r
@@ -969,6 +1047,35 @@ void Parameters::save(QString confFile) {
     }\r
 \r
     writer.writeEndElement();    //</connections>\r
+\r
+    QList<InterfaceItem *> lstIfaceItem;\r
+    // search for modifiers\r
+    foreach(ConnectionItem* item, allConnections) {\r
+      InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();\r
+      AbstractInputModifier* mod = fromIfaceItem->refInter->getInputModifier();\r
+      if (mod != NULL) {\r
+        if (!lstIfaceItem.contains(fromIfaceItem)) lstIfaceItem.append(fromIfaceItem);\r
+      }\r
+      InterfaceItem* toIfaceItem = item->getToInterfaceItem();\r
+      mod = toIfaceItem->refInter->getInputModifier();\r
+      if (mod != NULL) {\r
+        if (!lstIfaceItem.contains(toIfaceItem)) lstIfaceItem.append(toIfaceItem);\r
+      }\r
+    }\r
+    // write input modifiers\r
+    writer.writeStartElement("modifiers");\r
+    foreach(InterfaceItem* item, lstIfaceItem) {\r
+      AbstractInputModifier* mod = item->refInter->getInputModifier();\r
+      if (mod != NULL) {\r
+        writer.writeStartElement("modifier");\r
+        writer.writeAttribute("id", QString::number(item->getId()));\r
+        writer.writeAttribute("type",mod->getTypeStr());\r
+        writer.writeAttribute("params", mod->getParametersStr());\r
+        writer.writeEndElement();\r
+      }\r
+    }\r
+\r
+    writer.writeEndElement();    //</modifiers>\r
     writer.writeEndElement();      //</blast_project\r
 \r
     writer.writeEndDocument();\r
@@ -1039,6 +1146,27 @@ BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
   return NULL;\r
 }\r
 \r
+BoxItem* Parameters::searchFunctionalBlock(AbstractBlock* block) {\r
+\r
+  return searchFunctionalBlockRecur(block,topScene);\r
+}\r
+\r
+BoxItem* Parameters::searchFunctionalBlockRecur(AbstractBlock* block, GroupScene* scene) {\r
+\r
+  foreach(BoxItem *item, scene->getBoxItems()){\r
+    if(item->getRefBlock() == block) {\r
+      return item;\r
+    }\r
+  }\r
+\r
+  BoxItem* item = NULL;\r
+  foreach(GroupScene *s, scene->getChildrenScene()) {\r
+    item = searchFunctionalBlockRecur(block,s);\r
+    if (item != NULL) return item;\r
+  }\r
+  return NULL;\r
+}\r
+\r
 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {\r
 \r
   foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){\r