X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/e40a5399ec7887c2606f18575c809b0d05b09278..60c13e8b4c7ea3d595969c1e7c0a28b068a17ca6:/BlockLibraryWidget.cpp?ds=sidebyside diff --git a/BlockLibraryWidget.cpp b/BlockLibraryWidget.cpp index 62603b4..d80a78e 100644 --- a/BlockLibraryWidget.cpp +++ b/BlockLibraryWidget.cpp @@ -13,6 +13,7 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher, comboClkGen = NULL; nbRst = 0; comboRstGen = NULL; + currentRefBlock = NULL; // creating the widget : tree, buttons, ... QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this); @@ -26,19 +27,44 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher, 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; - boxClkRst = new QGroupBox("Clock/reset connection"); - boxClkRst->setLayout(layClkRst); + 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(buttonAdd, SIGNAL(clicked()), this, SLOT(addClicked())); + connect(radChooseClk, SIGNAL(toggled(bool)), this, SLOT(enableAvailableClocks(bool))); BlockCategory* cat = params->categoryTree->searchCategory(0); @@ -109,12 +135,13 @@ void BlockLibraryWidget::addClicked() { cout << "adding block to scene " << v.toInt() << endl; QHash clkRstToGen; - for(int i=0;irowCount();i++) { + for(int i=1;iitemAtPosition(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; } @@ -127,24 +154,55 @@ void BlockLibraryWidget::addClicked() { } void BlockLibraryWidget::clicked() { - if(tree->selectedItems().length() > 0){ + if(tree->selectedItems().length() > 0) { + QTreeWidgetItem *item = tree->selectedItems().at(0); + if(item->data(1,Qt::DisplayRole).isValid()) { + + buttonAdd->setEnabled(true); - int idParent = item->data(1,Qt::DisplayRole).toInt(); + int idCat = item->data(1,Qt::DisplayRole).toInt(); int idBlock = item->data(2,Qt::DisplayRole).toInt(); - updateClkRst(idParent, idBlock); + currentRefBlock = params->getReferenceBlock(idCat,idBlock); + QList 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); + updateClkRst(-1,-1); } } } void BlockLibraryWidget::doubleClicked() { + clicked(); 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 list = dispatcher->getAllGroupNames(); @@ -161,26 +219,24 @@ void BlockLibraryWidget::updateClkRst(int idCat, int idBlock) { QWidget* widget = layClkRst->itemAt(0)->widget(); layClkRst->removeWidget(widget); delete widget; - } + } if (nbClock != 0) { - for(int i=0;ideleteLater(); - } delete [] comboClkGen; + nbClock = 0; } if (nbRst != 0) { - for(int i=0;ideleteLater(); - } delete [] comboRstGen; + nbRst = 0; } - ReferenceBlock* ref = params->getReferenceBlock(idCat,idBlock); - QList lstClocks = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock); + if ((idCat == -1) || (idBlock == -1)) return; + + QList lstClocks = currentRefBlock->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock); nbClock = lstClocks.size(); - QList lstRst = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Reset); + QList 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;iaddWidget(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); + } } +