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

Private GIT Repository
added clk/rst link when creating a block
[blast.git] / BlockLibraryWidget.cpp
index 0aa9ed14faf203eb2bca833ded49d193b8f2ac86..62603b43cbda45514a8b04ce5280977abc9b8ea3 100644 (file)
@@ -9,29 +9,49 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   dispatcher = _dispatcher;
   params = _params;
 
   dispatcher = _dispatcher;
   params = _params;
 
+  nbClock = 0;
+  comboClkGen = NULL;
+  nbRst = 0;
+  comboRstGen = NULL;
+
   // creating the widget : tree, buttons, ...
   // creating the widget : tree, buttons, ...
-  layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
   tree = new QTreeWidget(this);
   tree = new QTreeWidget(this);
-  buttonAdd = new QPushButton("add", this);
+
+  buttonAdd = new QPushButton("add to", this);
   buttonAdd->setEnabled(false);
   buttonAdd->setEnabled(false);
+  comboScenes = new QComboBox();
+
+  QHBoxLayout* layAdd = new QHBoxLayout;
+  layAdd->addWidget(buttonAdd);
+  layAdd->addWidget(comboScenes);
+
+  layClkRst = new QGridLayout;
+
+  boxClkRst = new QGroupBox("Clock/reset connection");
+  boxClkRst->setLayout(layClkRst);
+
+  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()));  
 
   BlockCategory* cat = params->categoryTree->searchCategory(0);
 
   QTreeWidgetItem* item = tree->invisibleRootItem();
   tree->setHeaderLabel("Blocks list");
 
 
   BlockCategory* cat = params->categoryTree->searchCategory(0);
 
   QTreeWidgetItem* item = tree->invisibleRootItem();
   tree->setHeaderLabel("Blocks list");
 
-
   addChild(cat,item);
 
   layout->addWidget(tree);
   addChild(cat,item);
 
   layout->addWidget(tree);
-  layout->addWidget(buttonAdd);
+  layout->addLayout(layBottom);
   this->setLayout(layout);
 
   this->setLayout(layout);
 
-  this->setFixedSize(300,230);
+  //this->setFixedSize(300,230);
 }
 
 
 }
 
 
@@ -45,17 +65,20 @@ void BlockLibraryWidget::addChild(BlockCategory *catParent,QTreeWidgetItem* item
 
   QList<BlockCategory *> childs = catParent->getAllChilds();
   foreach(BlockCategory* cat, childs){
 
   QList<BlockCategory *> childs = catParent->getAllChilds();
   foreach(BlockCategory* cat, childs){
-    newItemCat = new QTreeWidgetItem(itemParent);
-    newItemCat->setData(0,Qt::DisplayRole, cat->getName());
-    QList<ReferenceBlock*> list = cat->getBlocks();
-    for(int i=0; i<list.length(); i++){
-      newItemBlock = new QTreeWidgetItem(newItemCat);
-      newItemBlock->setData(0,Qt::DisplayRole, list.at(i)->getName());
-      newItemBlock->setData(1,Qt::DisplayRole, cat->getId());
-      newItemBlock->setData(2,Qt::DisplayRole, i);
-      newItemBlock->setIcon(0,QIcon("icons/window_new.png"));
+
+    if (cat->getId()<100) {
+      newItemCat = new QTreeWidgetItem(itemParent);
+      newItemCat->setData(0,Qt::DisplayRole, cat->getName());
+      QList<ReferenceBlock*> list = cat->getBlocks();
+      for(int i=0; i<list.length(); i++){
+        newItemBlock = new QTreeWidgetItem(newItemCat);
+        newItemBlock->setData(0,Qt::DisplayRole, list.at(i)->getName());
+        newItemBlock->setData(1,Qt::DisplayRole, cat->getId());
+        newItemBlock->setData(2,Qt::DisplayRole, i);
+        newItemBlock->setIcon(0,QIcon("icons/window_new.png"));
+      }
+      addChild(cat,newItemCat);
     }
     }
-    addChild(cat,newItemCat);
   }
   /* TO DO :
      - getting the childs of catParent
   }
   /* TO DO :
      - getting the childs of catParent
@@ -79,9 +102,23 @@ 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();
-    dispatcher->addBlock(idParent, idBlock);
+    QVariant v = comboScenes->currentData();    
+
+    cout << "adding block to scene " << v.toInt() << endl;
+
+    QHash<QString, int> clkRstToGen;
+    for(int i=0;i<layClkRst->rowCount();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());
+    }
+
+
+    dispatcher->addBlock(Dispatcher::Design, idCat, idBlock, v.toInt(), clkRstToGen);
   }
 
   // only take the first selected
   }
 
   // only take the first selected
@@ -89,19 +126,96 @@ void BlockLibraryWidget::addClicked() {
   // calling dispatcher addBlock() method.
 }
 
   // calling dispatcher addBlock() method.
 }
 
-
-void BlockLibraryWidget::clicked()
-{
+void BlockLibraryWidget::clicked() {
   if(tree->selectedItems().length() > 0){
     QTreeWidgetItem *item = tree->selectedItems().at(0);
   if(tree->selectedItems().length() > 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 idParent = item->data(1,Qt::DisplayRole).toInt();
+      int idBlock = item->data(2,Qt::DisplayRole).toInt();
+      updateClkRst(idParent, idBlock);
+    }
+    else {
       buttonAdd->setEnabled(false);
       buttonAdd->setEnabled(false);
+    }
   }
 }
 
   }
 }
 
-void BlockLibraryWidget::doubleClicked()
-{
+void BlockLibraryWidget::doubleClicked() {
   addClicked();
 }
   addClicked();
 }
+
+void BlockLibraryWidget::updateComboScene() {
+  comboScenes->clear();
+  QMap<int,QString> list = dispatcher->getAllGroupNames();
+  QMapIterator<int,QString> iter(list);
+  while (iter.hasNext()) {
+    iter.next();
+    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) {
+    for(int i=0;i<nbClock;i++) {
+      comboClkGen[i]->deleteLater();
+    }
+    delete [] comboClkGen;
+  }
+  if (nbRst != 0) {
+    for(int i=0;i<nbRst;i++) {
+      comboRstGen[i]->deleteLater();
+    }
+    delete [] comboRstGen;
+  }
+
+  ReferenceBlock* ref = params->getReferenceBlock(idCat,idBlock);
+  QList<AbstractInterface*> lstClocks = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock);
+  nbClock = lstClocks.size();
+  QList<AbstractInterface*> lstRst = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Reset);
+  nbRst = lstRst.size();
+
+  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++;
+  }
+
+}