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

Private GIT Repository
add graph modif, progress on vhdl generation
[blast.git] / Dispatcher.cpp
index 1df7ded886818894ff2e439f91ba701ae8853515..a552f208fa0a1c96064c7ae9aeeac91e893aad93 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;
@@ -167,6 +171,25 @@ 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());
+    ReferenceBlock* ref = block->getReference();
+    BlockImplementation* impl = ref->getImplementations().at(0);
+    try {
+      impl->generateVHDL(block,"/home/sdomas/");
+    }
+    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 +364,67 @@ 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";
+    ConnectedInterface* iface = AI_TO_CON(item->refInter->getAssociatedIface());
+    ConnectedInterface* fromIface = iface->getConnectedFrom();
+    if (fromIface->getOutputPattern() == NULL) return;
+    foreach(char c, *(fromIface->getOutputPattern())) {
+      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";
+  }
+  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 = "";
+  AbstractInputModifier* mod = item->refInter->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());
+
   }
   }
-  cout << endl;
+  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
+
+  item->refInter->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
@@ -421,7 +498,7 @@ void Dispatcher::duplicateInterfaceItem(InterfaceItem *item) {
   // creating control interface if needed
   if (refI->getAssociatedIface() != NULL) {
     QString ctlName = cloneIface->getName()+"_enb";
   // creating control interface if needed
   if (refI->getAssociatedIface() != NULL) {
     QString ctlName = cloneIface->getName()+"_enb";
-    ReferenceInterface* ctlIface = new ReferenceInterface(refB,ctlName,"boolean","1",cloneIface->getDirection(), AbstractInterface::Control, 1);
+    ReferenceInterface* ctlIface = new ReferenceInterface(refB,ctlName,cloneIface->getDirection(), AbstractInterface::Control,"boolean","1", AbstractInterface::LittleEndian, 1);
     refB->addInterface(ctlIface);
     if (! ctlIface->setAssociatedIface(cloneIface)) {
       cerr << "Abnormal case while cloning an interface and creating its associated control interface" << endl;
     refB->addInterface(ctlIface);
     if (! ctlIface->setAssociatedIface(cloneIface)) {
       cerr << "Abnormal case while cloning an interface and creating its associated control interface" << endl;
@@ -430,12 +507,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 +530,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;
 }
 
 
 }
 
 
@@ -482,6 +562,7 @@ GroupWidget *Dispatcher::createTopScene(){
   // creating the view part of the group
   GroupItem *group = new GroupItem(NULL,refBlock,this,params);
 
   // creating the view part of the group
   GroupItem *group = new GroupItem(NULL,refBlock,this,params);
 
+
   // adding the fake interface to the top group item
   //InterfaceItem* item = new InterfaceItem(0.0 , Parameters::West, (ConnectedInterface*)iface, group, params);
   //group->addInterface(item,true);
   // adding the fake interface to the top group item
   //InterfaceItem* item = new InterfaceItem(0.0 , Parameters::West, (ConnectedInterface*)iface, group, params);
   //group->addInterface(item,true);
@@ -531,6 +612,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 +916,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()) {
 
@@ -1114,3 +1198,31 @@ 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
+      AbstractInputModifier* mod = new DelayInputModifier(delay->at(0));
+      ConnectedInterface* toIface = AI_TO_CON(iterD.key()->getAssociatedIface());
+      cout << "modify input of " << qPrintable(toIface->getName()) << endl;
+      toIface->setInputModifier(mod);
+      // repaint
+      toBlockItem->update();
+    }
+  }
+}
+