X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/6a0ffdb10d7344d99e04c5518fca2b8295df94be..3fb762e7042d9b4a1cf78556ad9ed7f117cc53ba:/Dispatcher.cpp?ds=sidebyside diff --git a/Dispatcher.cpp b/Dispatcher.cpp index 8d11649..b162559 100644 --- a/Dispatcher.cpp +++ b/Dispatcher.cpp @@ -18,7 +18,7 @@ #include "GroupScene.h" #include "GroupItem.h" #include "BoxItem.h" -#include "SourceItem.h" +#include "StimuliItem.h" #include "InterfaceItem.h" #include "ConnectionItem.h" @@ -29,7 +29,9 @@ #include "DelayInputModifier.h" -#include "InterfacePropertiesWindow.h" +#include "InterfacePropertiesDialog.h" + +#include int Dispatcher::sceneCounter = 0; @@ -379,8 +381,8 @@ void Dispatcher::renameGroupBlock(Context context, GroupItem *item){ mainWindow->getLibrary()->updateComboScene(); } -void Dispatcher::renameSourceBlock(Context context, SourceItem *item){ - static QString fctName = "Dispatcher::renameSourceBlock()"; +void Dispatcher::renameStimuliItem(Context context, StimuliItem *item){ + static QString fctName = "Dispatcher::renameStimuliItem()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif @@ -390,7 +392,7 @@ void Dispatcher::renameSourceBlock(Context context, SourceItem *item){ bool ok = false; QString text = ""; while (!ok) { - text = QInputDialog::getText(win, "Rename a source", + text = QInputDialog::getText(win, "Rename a stimuli", "New name:", QLineEdit::Normal, item->getRefBlock()->getName(), &ok); if (!ok) return; @@ -404,10 +406,10 @@ void Dispatcher::renameSourceBlock(Context context, SourceItem *item){ ok = false; } else { - FunctionalBlock* block = params->getGraph()->getSourceBlockByName(text); + FunctionalBlock* block = params->getGraph()->getStimuliBlockByName(text); if (block != NULL) { QMessageBox::warning(win,"Error in given name", - "the name provided is similar to that of another source block within the top group", + "the name provided is similar to that of another stimuli block within the top group", QMessageBox::Ok); ok = false; } @@ -562,8 +564,8 @@ void Dispatcher::duplicateBoxItem(Context context, BoxItem *item){ } } -void Dispatcher::duplicateSourceItem(Context context, SourceItem *item) { - static QString fctName = "Dispatcher::duplicateSourceItem()"; +void Dispatcher::duplicateStimuliItem(Context context, StimuliItem *item) { + static QString fctName = "Dispatcher::duplicateStimuliItem()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif @@ -577,9 +579,9 @@ void Dispatcher::duplicateSourceItem(Context context, SourceItem *item) { // adding to the model FunctionalBlock* funBlock = (FunctionalBlock*)block; - newBlock = params->getGraph()->duplicateSourceBlock(funBlock); + newBlock = params->getGraph()->duplicateStimuliBlock(funBlock); // adding to the view - scene->createSourceItem(newBlock); + scene->createStimuliItem(newBlock); params->unsaveModif = true; } @@ -621,12 +623,12 @@ void Dispatcher::duplicateInterfaceItem(Context context, InterfaceItem *item) { } -BoxItem* Dispatcher::addBlock(Context context, int idCategory, int idBlock, int idScene) { +BoxItem* Dispatcher::addBlock(Context context, int idCategory, int idBlock, int idScene, QHash clkRstToGen) { static QString fctName = "Dispatcher::addBlock()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - bool newSource = false; + bool newStimuli = false; BoxItem* item = NULL; /* For now, this method is only used while designing and not loading */ @@ -634,20 +636,37 @@ BoxItem* Dispatcher::addBlock(Context context, int idCategory, int idBlock, int 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 - if ((scene->isTopScene()) && (ref->isGeneratorBlock())) { - int ret = QMessageBox::question(NULL,"Adding a block to top scene","Selected block may be used as a source for the top scene. Do you want to add it as a source ?"); + if ((scene->isTopScene()) && (ref->isSourceBlock())) { + int ret = QMessageBox::question(NULL,"Adding a block to top scene","Selected block may be used as a stimuli for the top scene. Do you want to add it as a stimuli ?"); if (ret == QMessageBox::Yes) { - newSource = true; + newStimuli = true; } } - if (newSource) { - FunctionalBlock* newOne = params->getGraph()->createSourceBlock(ref, true); - scene->createSourceItem(newOne); + if (newStimuli) { + FunctionalBlock* newOne = params->getGraph()->createStimuliBlock(ref, true); + scene->createStimuliItem(newOne); } else { + GroupBlock* group = AB_TO_GRP(scene->getGroupItem()->getRefBlock()); FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(group, ref, true); + + // creating the box item item = scene->createBoxItem(newOne); + if (params->autoConnMainClk) { + // for now just use the first one + QHashIterator iter(clkRstToGen); + while (iter.hasNext()) { + iter.next(); + AbstractInterface* iface = newOne->getIfaceFromName(iter.key()); + if (iface->getPurpose() == AbstractInterface::Clock) { + newOne->connectClock(iface->getName(), iter.value()); + } + else if (iface->getPurpose() == AbstractInterface::Reset) { + newOne->connectReset(iface->getName(), iter.value()); + } + } + } params->blockToItem.insert(newOne,item); } params->unsaveModif = true; @@ -656,8 +675,69 @@ BoxItem* Dispatcher::addBlock(Context context, int idCategory, int idBlock, int return item; } +void Dispatcher::addClkRstGenBlock(Context context, double frequency) { + static QString fctName = "Dispatcher::addClkRstGenBlock()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + + + if (context == Design) { + + params->getGraph()->addClock(frequency); -GroupWidget *Dispatcher::createTopScene(Context context){ + // get the top group + GroupBlock *group = params->getGraph()->getTopGroup(); + GroupScene *scene = topGroupWidget->getScene(); + + // creating the clkrstgen block + ReferenceBlock* ref = params->getHiddenReferenceBlock("clkrstgen"); + FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(group, ref, true); + + QString name = "clkrstgen_"; + name += QString::number(params->getGraph()->getClocks().size()-1); + newOne->setName(name); + + // creating the box item + BoxItem* item = scene->createBoxItem(newOne, BoxItem::Left, AbstractBoxItem::Dimension); + item->setVisible(false); + + ConnectedInterface* fromIfaceClk = NULL; + ConnectedInterface* fromIfaceReset = NULL; + QString clkName = "ext_clk_"+QString::number(params->getGraph()->getClocks().size()-1); + QString rstName = "ext_reset_"+QString::number(params->getGraph()->getClocks().size()-1); + fromIfaceClk = new GroupInterface(group,clkName, AbstractInterface::Input, AbstractInterface::Clock); + fromIfaceReset = new GroupInterface(group,rstName, AbstractInterface::Input, AbstractInterface::Reset); + group->addInterface(fromIfaceClk); + group->addInterface(fromIfaceReset); + // creating top group ext_clk iface item + GroupItem* groupItem = scene->getGroupItem(); + InterfaceItem* fromIfaceItemClk = new InterfaceItem(0.5 , Parameters::West, fromIfaceClk, groupItem, params, true); + groupItem->addInterfaceItem(fromIfaceItemClk,true); + // creating top group ext_reset iface item + InterfaceItem* fromIfaceItemReset = new InterfaceItem(0.5 , Parameters::West, fromIfaceReset, groupItem, params, false); + groupItem->addInterfaceItem(fromIfaceItemReset,true); + // connecting ext_clk iface items + InterfaceItem* toIfaceItemClk = item->searchInterfaceItemByName("ext_clk"); + if (toIfaceItemClk == NULL) { + cerr << "Abnormal case while connecting top group ext_clk to clkrstgen" << endl; + } + createConnection(context,fromIfaceItemClk, toIfaceItemClk, false); + // connecting ext_reset iface items + InterfaceItem* toIfaceItemReset = item->searchInterfaceItemByName("ext_reset"); + if (toIfaceItemReset == NULL) { + cerr << "Abnormal case while connecting top group ext_reset to clkrstgen" << endl; + } + createConnection(context,fromIfaceItemReset, toIfaceItemReset, false); + + params->blockToItem.insert(newOne,item); + params->unsaveModif = true; + } +} + + + +GroupWidget *Dispatcher::createTopScene(Context context, double mainClock){ static QString fctName = "Dispatcher::createTopScene()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; @@ -668,7 +748,8 @@ GroupWidget *Dispatcher::createTopScene(Context context){ createIfaces = false; } // creating the graph and thus, the topgroup - Graph* graph = params->createGraph(createIfaces); + Graph* graph = params->initGraph(createIfaces); + graph->addClock(mainClock); // get the top group GroupBlock *topBlock = graph->getTopGroup(); // creating the top group widget @@ -690,35 +771,12 @@ GroupWidget *Dispatcher::createTopScene(Context context){ if (context == Design) { - // creating the clkrstgen block - ReferenceBlock* ref = params->getHiddenReferenceBlock("clkrstgen"); - FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(topBlock, ref, true); - // creating the clkrstgen item - BoxItem* clkResetItem = scene->createBoxItem(newOne, BoxItem::TopLeft, AbstractBoxItem::Position | AbstractBoxItem::Dimension, BoxItem::NoSpan); - params->blockToItem.insert(newOne,clkResetItem); - // creating top group ext_clk iface item - ConnectedInterface* fromIfaceClk = AI_TO_CON(topBlock->getIfaceFromName("ext_clk")); - InterfaceItem* fromIfaceItemClk = new InterfaceItem(0.5 , Parameters::West, fromIfaceClk, group, params, true); - group->addInterfaceItem(fromIfaceItemClk,true); - // creating top group ext_reset iface item - ConnectedInterface* fromIfaceReset = AI_TO_CON(topBlock->getIfaceFromName("ext_reset")); - InterfaceItem* fromIfaceItemReset = new InterfaceItem(0.5 , Parameters::West, fromIfaceReset, group, params, false); - group->addInterfaceItem(fromIfaceItemReset,true); - // connecting ext_clk iface items - InterfaceItem* toIfaceItemClk = clkResetItem->searchInterfaceItemByName("ext_clk"); - if (toIfaceItemClk == NULL) { - cerr << "Abnormal case while connecting top group ext_clk to clkrstgen" << endl; - } - createConnection(context,fromIfaceItemClk, toIfaceItemClk, false); - // connecting ext_reset iface items - InterfaceItem* toIfaceItemReset = clkResetItem->searchInterfaceItemByName("ext_reset"); - if (toIfaceItemReset == NULL) { - cerr << "Abnormal case while connecting top group ext_reset to clkrstgen" << endl; - } - createConnection(context,fromIfaceItemReset, toIfaceItemReset, false); + // create clkrstgen + double freq = params->getGraph()->getClock(0); + params->getGraph()->resetClocks(); + addClkRstGenBlock(context,freq); } - groupList.append(topGroupWidget); return topGroupWidget; } @@ -728,11 +786,15 @@ GroupWidget* Dispatcher::addNewEmptyGroup(Context context, GroupScene* scene, bo #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif + bool createIfaces = true; + if (context == Load) { + createIfaces = false; + } // getting the parent block in the graph GroupBlock* parent = AB_TO_GRP(scene->getGroupItem()->getRefBlock()); cout << "new group : parent = "<< qPrintable(parent->getName()) << endl; - GroupBlock* groupBlock = params->getGraph()->createChildGroupBlock(parent); + GroupBlock* groupBlock = params->getGraph()->createChildGroupBlock(parent, createIfaces); cout << "new group : child = "<< qPrintable(groupBlock->getName()) << ", child of " << qPrintable(groupBlock->getParent()->getName()) << endl; // creating the BlockItem in the scene BoxItem* newItem = scene->createBoxItem(groupBlock); @@ -1098,26 +1160,26 @@ void Dispatcher::removeAllBlockConnections(Context context, AbstractBoxItem *ite } } -void Dispatcher::removeSourceItem(Context context, SourceItem *item) { - static QString fctName = "Dispatcher::removeSourceItem()"; +void Dispatcher::removeStimuliItem(Context context, StimuliItem *item) { + static QString fctName = "Dispatcher::removeStimuliItem()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - QString msg = "Removing source "; + QString msg = "Removing stimmuli "; msg += item->getRefBlock()->getName(); msg += " and all its connections.\n\nAre you sure ?"; - int ret = QMessageBox::question(NULL,"Removing source block",msg, QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); + int ret = QMessageBox::question(NULL,"Removing stimuli block",msg, QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); if (ret == QMessageBox::Cancel) { return; } removeAllBlockConnections(context, item); FunctionalBlock* block = AB_TO_FUN(item->getRefBlock()); - item->getScene()->removeSourceItem(item); - params->getGraph()->removeSourceBlock(block); + item->getScene()->removeStimuliItem(item); + params->getGraph()->removeStimuliBlock(block); } @@ -1204,7 +1266,8 @@ void Dispatcher::showBlocksLibrary(){ } void Dispatcher::showProperties(Context context, InterfaceItem *inter) { - new InterfacePropertiesWindow(inter); + QDialog* dial = new InterfacePropertiesDialog(inter); + dial->exec(); } /* connectInterToGroup() :