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

Private GIT Repository
moved vhdl gen. into block
[blast.git] / Dispatcher.cpp
index a416f956083249311fa4679113c952dbcd40348c..946f5ec4adc9ba238748325cc4e0f8cecf03e259 100644 (file)
 #include "BlockLibraryWidget.h"
 #include "BlockLibraryTree.h"
 
 #include "BlockLibraryWidget.h"
 #include "BlockLibraryTree.h"
 
+#include "AbstractInputModifier.h"
+#include "DelayInputModifier.h"
+
+
 #include "InterfacePropertiesWindow.h"
 
 int Dispatcher::sceneCounter = 0;
 #include "InterfacePropertiesWindow.h"
 
 int Dispatcher::sceneCounter = 0;
@@ -81,7 +85,7 @@ void Dispatcher::closeCurrentProject() {
   sceneCounter = 0;
 }
 
   sceneCounter = 0;
 }
 
-bool Dispatcher::createConnection(InterfaceItem *iface1, InterfaceItem *iface2) {
+bool Dispatcher::createConnection(InterfaceItem *iface1, InterfaceItem *iface2, bool visible) {
     
   ConnectedInterface* ref1 = iface1->refInter;
   ConnectedInterface* ref2 = iface2->refInter;  
     
   ConnectedInterface* ref1 = iface1->refInter;
   ConnectedInterface* ref2 = iface2->refInter;  
@@ -102,7 +106,7 @@ bool Dispatcher::createConnection(InterfaceItem *iface1, InterfaceItem *iface2)
   }
   if ((ok1 == true) || (ok2 == true)) {
 
   }
   if ((ok1 == true) || (ok2 == true)) {
 
-    iface1->getOwner()->getScene()->createConnectionItem(iface1,iface2);
+    iface1->getOwner()->getScene()->createConnectionItem(iface1,iface2, visible);
 
     unselectAllItems();
     params->unsaveModif = true;
 
     unselectAllItems();
     params->unsaveModif = true;
@@ -167,6 +171,23 @@ void Dispatcher::changeConnectionMode(int mode){
   */
 }
 
   */
 }
 
+void Dispatcher::generateBlockVHDL(BoxItem *item){
+  static QString fctName = "Dispatcher::generateBlockVHDL()";
+#ifdef DEBUG_FCTNAME
+  cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+  if (item->getRefBlock()->isFunctionalBlock()) {
+    FunctionalBlock* block = AB_TO_FUN(item->getRefBlock());
+    try {
+      block->generateVHDL(params->projectPath);      
+    }
+    catch(Exception e) {
+      cout << qPrintable(e.getMessage()) << endl;
+    }
+  }
+}
+
 void Dispatcher::renameFunctionalBlock(BoxItem *item){
   static QString fctName = "Dispatcher::renameFunctionalBlock()";
 #ifdef DEBUG_FCTNAME
 void Dispatcher::renameFunctionalBlock(BoxItem *item){
   static QString fctName = "Dispatcher::renameFunctionalBlock()";
 #ifdef DEBUG_FCTNAME
@@ -341,13 +362,77 @@ void Dispatcher::showPatterns(InterfaceItem *item) {
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
-  ConnectedInterface* iface = AI_TO_CON(item->refInter->getAssociatedIface());
-  foreach(char c, *(iface->getOutputPattern())) {
-    cout << (int)c;
+  QString msg = "";
+  if (item->refInter->getDirection() == AbstractInterface::Input) {
+    msg = "Input pattern of iface ";
+    msg += item->refInter->getName();
+    msg += " owned by ";
+    msg += item->refInter->getOwner()->getName();
+    msg += " is:\n";
+    // get the precursor output pattern
+    ConnectedInterface* connIface = AI_TO_CON(item->refInter->getAssociatedIface());
+    QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
+    // get the modifier
+    AbstractInputModifier* modifier = connIface->getInputModifier();
+    // check if the input is modified
+    if (modifier != NULL) {
+
+      out = modifier->getModifiedInput(out);
+    }
+
+    foreach(char c, *out) {
+      msg += QString::number((int)c);
+    }
+    msg += "\n";
+  }
+  else if (item->refInter->getDirection() == AbstractInterface::Output) {
+    msg = "Output pattern of iface ";
+    msg += item->refInter->getName();
+    msg += " owned by ";
+    msg += item->refInter->getOwner()->getName();
+    msg += " is:\n";
+    ConnectedInterface* iface = AI_TO_CON(item->refInter->getAssociatedIface());
+    if (iface->getOutputPattern() == NULL) return;
+    foreach(char c, *(iface->getOutputPattern())) {
+      msg += QString::number((int)c);
+    }
+    msg += "\n";
   }
   }
-  cout << endl;
+  QMessageBox::information(NULL,"Interface pattern",msg,QMessageBox::Ok,QMessageBox::Ok);
 }
 
 }
 
+void Dispatcher::showModifier(InterfaceItem *item) {
+  static QString fctName = "Dispatcher::showModifier()";
+#ifdef DEBUG_FCTNAME
+  cout << "call to " << qPrintable(fctName) << endl;
+#endif
+  QString msg = "";
+  ConnectedInterface* assoIface = AI_TO_CON(item->refInter->getAssociatedIface());
+  AbstractInputModifier* mod = assoIface->getInputModifier();
+  if (mod->isDelay()) {
+    DelayInputModifier* delay = (DelayInputModifier *)mod;
+    msg = "Pattern of iface ";
+    msg += item->refInter->getName();
+    msg += " owned by ";
+    msg += item->refInter->getOwner()->getName();
+    msg += " is modified by a simple delay of ";
+    msg += QString::number(delay->getDelayLength());
+
+  }
+  QMessageBox::information(NULL,"Interface pattern",msg,QMessageBox::Ok,QMessageBox::Ok);
+}
+
+void Dispatcher::removeModifier(InterfaceItem *item) {
+  static QString fctName = "Dispatcher::showModifier()";
+#ifdef DEBUG_FCTNAME
+  cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+  ConnectedInterface* assoIface = AI_TO_CON(item->refInter->getAssociatedIface());
+  assoIface->clearInputModifier();
+}
+
+
 void Dispatcher::duplicateBoxItem(BoxItem *item){
   static QString fctName = "Dispatcher::duplicateBoxItem()";
 #ifdef DEBUG_FCTNAME
 void Dispatcher::duplicateBoxItem(BoxItem *item){
   static QString fctName = "Dispatcher::duplicateBoxItem()";
 #ifdef DEBUG_FCTNAME
@@ -430,12 +515,13 @@ void Dispatcher::duplicateInterfaceItem(InterfaceItem *item) {
 }
 
 
 }
 
 
-void Dispatcher::addBlock(int idCategory, int idBlock, int idScene) {
+BoxItem* Dispatcher::addBlock(int idCategory, int idBlock, int idScene) {
   static QString fctName = "Dispatcher::addBlock()";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
   bool newSource = false;
   static QString fctName = "Dispatcher::addBlock()";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
 #endif
   bool newSource = false;
+  BoxItem* item = NULL;
   GroupScene *scene = getSceneById(idScene);
   ReferenceBlock* ref = params->getReferenceBlock(idCategory,idBlock);
   // if block has no inputs, propose to add it as a source to top scene
   GroupScene *scene = getSceneById(idScene);
   ReferenceBlock* ref = params->getReferenceBlock(idCategory,idBlock);
   // if block has no inputs, propose to add it as a source to top scene
@@ -452,9 +538,11 @@ void Dispatcher::addBlock(int idCategory, int idBlock, int idScene) {
   else {
     GroupBlock* group = AB_TO_GRP(scene->getGroupItem()->getRefBlock());
     FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(group, ref);
   else {
     GroupBlock* group = AB_TO_GRP(scene->getGroupItem()->getRefBlock());
     FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(group, ref);
-    scene->createBoxItem(newOne);
+    item = scene->createBoxItem(newOne);
+    params->blockToItem.insert(newOne,item);
   }
   params->unsaveModif = true;
   }
   params->unsaveModif = true;
+  return item;
 }
 
 
 }
 
 
@@ -466,7 +554,16 @@ GroupWidget *Dispatcher::createTopScene(){
 
   // creating the model part of the group
   Graph* graph = params->createGraph();
 
   // creating the model part of the group
   Graph* graph = params->createGraph();
-  GroupBlock *refBlock = graph->getTopGroup();
+  GroupBlock *topBlock = graph->getTopGroup();
+  // creating the clkrstgen block
+  ReferenceBlock* ref = params->getHiddenReferenceBlock("clkrstgen");
+  FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(topBlock, ref);  
+  ConnectedInterface* fromIface = AI_TO_CON(topBlock->getIfaceFromName("ext_clk"));
+  ConnectedInterface* toIface = AI_TO_CON(newOne->getIfaceFromName("ext_clk"));
+  fromIface->connectTo(toIface);
+  fromIface = AI_TO_CON(topBlock->getIfaceFromName("ext_reset"));
+  toIface = AI_TO_CON(newOne->getIfaceFromName("ext_reset"));
+  fromIface->connectTo(toIface);
 
   // creating a fake and not connected interface
   //AbstractInterface* iface = new GroupInterface(refBlock,"grp_iface",AbstractInterface::Input,AbstractInterface::Top);
 
   // creating a fake and not connected interface
   //AbstractInterface* iface = new GroupInterface(refBlock,"grp_iface",AbstractInterface::Input,AbstractInterface::Top);
@@ -480,7 +577,8 @@ GroupWidget *Dispatcher::createTopScene(){
   params->setTopScene(scene);
   params->setCurrentScene(scene);
   // creating the view part of the group
   params->setTopScene(scene);
   params->setCurrentScene(scene);
   // creating the view part of the group
-  GroupItem *group = new GroupItem(NULL,refBlock,this,params);
+  GroupItem *group = new GroupItem(NULL,topBlock,this,params);
+
 
   // adding the fake interface to the top group item
   //InterfaceItem* item = new InterfaceItem(0.0 , Parameters::West, (ConnectedInterface*)iface, group, params);
 
   // adding the fake interface to the top group item
   //InterfaceItem* item = new InterfaceItem(0.0 , Parameters::West, (ConnectedInterface*)iface, group, params);
@@ -531,6 +629,7 @@ GroupWidget *Dispatcher::createChildScene(GroupWidget* parentWidget, BoxItem *up
     GroupBlock* groupBlock = AB_TO_GRP(upperItemOfGroupItem->getRefBlock());
     // creating the view part of the group
     GroupItem *groupItem = new GroupItem(upperItemOfGroupItem,groupBlock,this,params);
     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
     // creating the group widget
     group = new GroupWidget(parentWidget, this, params);
     // getting the newly created scene
@@ -834,6 +933,8 @@ void Dispatcher::removeBoxItem(BoxItem *item) {
     FunctionalBlock* block = AB_TO_FUN(item->getRefBlock());    
     item->getScene()->removeBoxItem(item);
     params->getGraph()->removeFunctionalBlock(block);
     FunctionalBlock* block = AB_TO_FUN(item->getRefBlock());    
     item->getScene()->removeBoxItem(item);
     params->getGraph()->removeFunctionalBlock(block);
+    params->blockToItem.remove(block);
+
   }
   else if (item->getRefBlock()->isGroupBlock()) {
 
   }
   else if (item->getRefBlock()->isGroupBlock()) {
 
@@ -989,10 +1090,12 @@ void Dispatcher::connectInterToGroup(InterfaceItem *item){
   // creating/adding the group interface in the graph model
   GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection(),refInter->getPurpose());  
   parentItem->getRefBlock()->addInterface(groupInter);
   // creating/adding the group interface in the graph model
   GroupInterface *groupInter = new GroupInterface(parentBlock,refInter->getName()+"_group",refInter->getDirection(),refInter->getPurpose());  
   parentItem->getRefBlock()->addInterface(groupInter);
-  // creating/adding the group control interface in the graph model
-  GroupInterface *groupCtlInter = new GroupInterface(parentBlock,refInter->getName()+"_group_enb",refInter->getDirection(),AbstractInterface::Control);
-  groupCtlInter->setAssociatedIface(groupInter);
-  parentItem->getRefBlock()->addInterface(groupCtlInter);  
+  // creating/adding the group control interface in the graph model if the purpose is data
+  if (refInter->getPurpose() == AbstractInterface::Data) {
+    GroupInterface *groupCtlInter = new GroupInterface(parentBlock,refInter->getName()+"_group_enb",refInter->getDirection(),AbstractInterface::Control);
+    groupCtlInter->setAssociatedIface(groupInter);
+    parentItem->getRefBlock()->addInterface(groupCtlInter);
+  }
   // creating/adding the group interface in the current scene model, and connection item
   InterfaceItem *groupIfaceItem = new InterfaceItem(0,item->getOrientation(),groupInter,parentItem,params);
   parentItem->addInterfaceItem(groupIfaceItem,true);
   // creating/adding the group interface in the current scene model, and connection item
   InterfaceItem *groupIfaceItem = new InterfaceItem(0,item->getOrientation(),groupInter,parentItem,params);
   parentItem->addInterfaceItem(groupIfaceItem,true);
@@ -1114,3 +1217,32 @@ InterfaceItem* Dispatcher::getInterfaceItemById(int id) {
   return NULL;
 }
 
   return NULL;
 }
 
+void Dispatcher::findGraphModifications(FunctionalBlock *block) {
+  static QString fctName = "Dispatcher::findGraphModifications()";
+#ifdef DEBUG_FCTNAME
+  cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+  block->computeAdmittanceDelays();
+  // get the block item that is associated to block
+  BoxItem* toBlockItem = params->blockToItem.value(block);
+
+  /* VERSION 1: just add delays if needed */
+  QMap<AbstractInterface*,QList<int>* > delays = block->getAdmittanceDelays();
+  QMapIterator<AbstractInterface*,QList<int>* > iterD(delays);
+  while (iterD.hasNext()) {
+    iterD.next();
+    QList<int>* delay = iterD.value();
+    if (delay->at(0) > 0) {
+      // create delay and associate it to the connected input
+
+      ConnectedInterface* toIface = AI_TO_CON(iterD.key());
+      AbstractInputModifier* mod = new DelayInputModifier(toIface, delay->at(0));
+      cout << "modify input of " << qPrintable(toIface->getName()) << endl;
+      toIface->setInputModifier(mod);
+      // repaint
+      toBlockItem->update();
+    }
+  }
+}
+