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

Private GIT Repository
changed sources to stimulis
[blast.git] / BlockLibraryWidget.cpp
index 0d2636d7db1189b88cdc4baa387267327fa88646..d80a78ee795a8938d6b0998d5cfa2c763be367ea 100644 (file)
@@ -9,6 +9,12 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   dispatcher = _dispatcher;
   params = _params;
 
   dispatcher = _dispatcher;
   params = _params;
 
+  nbClock = 0;
+  comboClkGen = NULL;
+  nbRst = 0;
+  comboRstGen = NULL;
+  currentRefBlock = NULL;
+
   // creating the widget : tree, buttons, ...
   QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
   tree = new QTreeWidget(this);
   // creating the widget : tree, buttons, ...
   QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
   tree = new QTreeWidget(this);
@@ -17,13 +23,48 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   buttonAdd->setEnabled(false);
   comboScenes = new QComboBox();
 
   buttonAdd->setEnabled(false);
   comboScenes = new QComboBox();
 
-  QHBoxLayout* layBottom = new QHBoxLayout;
-  layBottom->addWidget(buttonAdd);
-  layBottom->addWidget(comboScenes);
+  QHBoxLayout* layAdd = new QHBoxLayout;
+  layAdd->addWidget(buttonAdd);
+  layAdd->addWidget(comboScenes);
+
+  boxClkRst = new QGroupBox("Clock/reset connection");
+
+
+  QString msg = "Connect to main clock/rst ext_clk/reset_0 (";
+  msg += QString::number(params->clocks.at(0));
+  msg += ")";
+  radAutoClk = new QRadioButton(msg);
+  radChooseClk = new QRadioButton("Choose among available clk/rst");
+  if (params->autoConnMainClk) {
+    radAutoClk->setChecked(true);
+  }
+  else {
+    radChooseClk->setChecked(true);
+  }
+
+  layClkRst = new QGridLayout;
+
+  QVBoxLayout* layConn = new QVBoxLayout;
+  layConn->addWidget(radAutoClk,0,0);
+  layConn->addWidget(radChooseClk,1,0);
+  stack = new QStackedWidget();
+  QLabel* labDummy = new QLabel("");
+  stack->addWidget(labDummy);
+  QWidget* w = new QWidget();
+  w->setLayout(layClkRst);
+  stack->addWidget(w);
+  layConn->addWidget(stack);
+
+  boxClkRst->setLayout(layConn);
+
+  QVBoxLayout* layBottom = new QVBoxLayout;
+  layBottom->addLayout(layAdd);
+  layBottom->addWidget(boxClkRst);
 
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
   connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
 
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
   connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
-  connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addClicked()));
+  connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addClicked()));  
+  connect(radChooseClk, SIGNAL(toggled(bool)), this, SLOT(enableAvailableClocks(bool)));
 
   BlockCategory* cat = params->categoryTree->searchCategory(0);
 
 
   BlockCategory* cat = params->categoryTree->searchCategory(0);
 
@@ -36,7 +77,7 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   layout->addLayout(layBottom);
   this->setLayout(layout);
 
   layout->addLayout(layBottom);
   this->setLayout(layout);
 
-  this->setFixedSize(300,230);
+  //this->setFixedSize(300,230);
 }
 
 
 }
 
 
@@ -87,11 +128,24 @@ void BlockLibraryWidget::addClicked() {
 
   QTreeWidgetItem *item = tree->selectedItems().at(0);
   if(item->data(1,Qt::DisplayRole).isValid() && item->data(2,Qt::DisplayRole).isValid()){
 
   QTreeWidgetItem *item = tree->selectedItems().at(0);
   if(item->data(1,Qt::DisplayRole).isValid() && item->data(2,Qt::DisplayRole).isValid()){
-    int idParent = item->data(1,Qt::DisplayRole).toInt();
+    int idCat = item->data(1,Qt::DisplayRole).toInt();
     int idBlock = item->data(2,Qt::DisplayRole).toInt();
     int idBlock = item->data(2,Qt::DisplayRole).toInt();
-    QVariant v = comboScenes->currentData();
+    QVariant v = comboScenes->currentData();    
+
     cout << "adding block to scene " << v.toInt() << endl;
     cout << "adding block to scene " << v.toInt() << endl;
-    dispatcher->addBlock(idParent, idBlock, v.toInt());
+
+    QHash<QString, int> clkRstToGen;
+    for(int i=1;i<nbClock+nbRst;i++) {
+      QLayoutItem* item = layClkRst->itemAtPosition(i,0);
+      QLabel* lab = (QLabel *)(item->widget());
+      item = layClkRst->itemAtPosition(i,1);
+      QComboBox* combo = (QComboBox *)(item->widget());
+      clkRstToGen.insert(lab->text(),combo->currentIndex());
+      cout << "addblock: have to connect " << qPrintable(lab->text()) << " to clk/rst n° " << combo->currentIndex() << endl;
+    }
+
+
+    dispatcher->addBlock(Dispatcher::Design, idCat, idBlock, v.toInt(), clkRstToGen);
   }
 
   // only take the first selected
   }
 
   // only take the first selected
@@ -100,19 +154,55 @@ void BlockLibraryWidget::addClicked() {
 }
 
 void BlockLibraryWidget::clicked() {
 }
 
 void BlockLibraryWidget::clicked() {
-  if(tree->selectedItems().length() > 0){
+  if(tree->selectedItems().length() > 0) {
+
     QTreeWidgetItem *item = tree->selectedItems().at(0);
     QTreeWidgetItem *item = tree->selectedItems().at(0);
-    if(item->data(1,Qt::DisplayRole).isValid())
+
+    if(item->data(1,Qt::DisplayRole).isValid()) {
+
+
       buttonAdd->setEnabled(true);
       buttonAdd->setEnabled(true);
-    else
+      int idCat = item->data(1,Qt::DisplayRole).toInt();
+      int idBlock = item->data(2,Qt::DisplayRole).toInt();
+      currentRefBlock = params->getReferenceBlock(idCat,idBlock);
+      QList<AbstractInterface*> lstClocks = currentRefBlock->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock);
+      //if there are more than one input clock, force to choose
+      if ((lstClocks.size()>1) || (! params->autoConnMainClk)) {
+        radChooseClk->setChecked(true);
+        //enableAvailableClocks(true);
+      }
+      else {
+        radAutoClk->setChecked(true);
+      }
+      updateClkRst(idCat, idBlock);
+    }
+    else {
       buttonAdd->setEnabled(false);
       buttonAdd->setEnabled(false);
+      updateClkRst(-1,-1);
+    }
   }
 }
 
 void BlockLibraryWidget::doubleClicked() {
   }
 }
 
 void BlockLibraryWidget::doubleClicked() {
+  clicked();
   addClicked();
 }
 
   addClicked();
 }
 
+void BlockLibraryWidget::updateBoxConn() {
+  if (params->autoConnMainClk) {
+    radAutoClk->setChecked(true);
+    //enableAvailableClocks(false);
+  }
+  else {
+    radChooseClk->setChecked(true);
+    //enableAvailableClocks(true);
+  }
+  QString msg = "Auto-connect to main clk/rst (ext_clk_0 at ";
+  msg += QString::number(params->clocks.at(0));
+  msg += " MHz)";
+  radAutoClk->setText(msg);
+}
+
 void BlockLibraryWidget::updateComboScene() {
   comboScenes->clear();
   QMap<int,QString> list = dispatcher->getAllGroupNames();
 void BlockLibraryWidget::updateComboScene() {
   comboScenes->clear();
   QMap<int,QString> list = dispatcher->getAllGroupNames();
@@ -122,3 +212,77 @@ void BlockLibraryWidget::updateComboScene() {
     comboScenes->addItem(iter.value(),QVariant(iter.key()));
   }
 }
     comboScenes->addItem(iter.value(),QVariant(iter.key()));
   }
 }
+
+void BlockLibraryWidget::updateClkRst(int idCat, int idBlock) {
+
+  while (layClkRst->count() > 0) {
+    QWidget* widget = layClkRst->itemAt(0)->widget();
+    layClkRst->removeWidget(widget);
+    delete widget;
+  }  
+
+  if (nbClock != 0) {
+    delete [] comboClkGen;
+    nbClock = 0;
+  }
+  if (nbRst != 0) {
+    delete [] comboRstGen;
+    nbRst = 0;
+  }
+
+  if ((idCat == -1) || (idBlock == -1)) return;
+
+  QList<AbstractInterface*> lstClocks = currentRefBlock->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock);
+  nbClock = lstClocks.size();
+  QList<AbstractInterface*> lstRst = currentRefBlock->getInterfaces(AbstractInterface::Input, AbstractInterface::Reset);
+  nbRst = lstRst.size();
+  cout << "For chosen block there are " << nbClock << " clocks and " << nbRst << " resets" << endl;
+
+  comboClkGen = new QComboBox*[lstClocks.size()];
+  for(int i=0;i<lstClocks.size();i++) {
+    comboClkGen[i] = new QComboBox();
+    QString name = "";
+    int id = 0;
+    foreach(double d, params->clocks) {
+      name = "ext_clk_"+QString::number(id)+" (";
+      name += QString::number(d) + " MHz)";
+      comboClkGen[i]->addItem(name);
+      id++;
+    }
+  }
+
+  comboRstGen = new QComboBox*[lstRst.size()];
+  for(int i=0;i<lstRst.size();i++) {
+    comboRstGen[i] = new QComboBox();
+    QString name = "";
+    for(int j=0;j<params->clocks.size();j++) {
+      name = "ext_rst_"+QString::number(j);
+      comboRstGen[i]->addItem(name);
+    }
+  }
+  layClkRst->addWidget(new QLabel("Clock/Reset name"), 0, 0);
+  layClkRst->addWidget(new QLabel("connect to"), 0, 1);
+  int row = 1;
+  foreach(AbstractInterface* iface, lstClocks) {
+    layClkRst->addWidget(new QLabel(iface->getName()), row,0);
+    layClkRst->addWidget(comboClkGen[row-1],row, 1);
+    row++;
+  }
+
+  foreach(AbstractInterface* iface, lstRst) {
+    layClkRst->addWidget(new QLabel(iface->getName()), row,0);
+    layClkRst->addWidget(comboRstGen[row-1-nbClock],row, 1);
+    row++;
+  }
+}
+
+void BlockLibraryWidget::enableAvailableClocks(bool state) {
+
+  if (state == false) {
+    stack->setCurrentIndex(0);
+  }
+  else {
+    stack->setCurrentIndex(1);
+  }
+}
+