X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/4cf57e6db08da791233d75237f62e74bc88dd427..3fb762e7042d9b4a1cf78556ad9ed7f117cc53ba:/Parameters.cpp diff --git a/Parameters.cpp b/Parameters.cpp index d3a8dd4..d7621d2 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -9,7 +9,7 @@ #include "GroupScene.h" #include "GroupItem.h" #include "BoxItem.h" -#include "SourceItem.h" +#include "StimuliItem.h" #include "InterfaceItem.h" #include "ConnectionItem.h" @@ -46,10 +46,14 @@ Parameters::Parameters() { unsaveModif = false; isRstClkShown = false; - - projectPath = QDir::currentPath(); validityExtension = "_enb"; + + projectPath = ""; + projectName = ""; + projectFile = ""; + + graph = new Graph(); } Parameters::~Parameters() { @@ -67,8 +71,8 @@ void Parameters::clear() { refPathes.clear(); } -Graph* Parameters::createGraph() { - graph = new Graph(); +Graph* Parameters::initGraph(bool createTopGroupIfaces) { + graph->createTopGroup(createTopGroupIfaces); return graph; } @@ -81,10 +85,84 @@ ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) { BlockCategory* blockCat = categoryTree->searchCategory(idCategory); if (blockCat == NULL) return NULL; - ReferenceBlock* ref = blockCat->getBlock(idBlock); + ReferenceBlock* ref = blockCat->getBlockById(idBlock); + return ref; +} + +ReferenceBlock* Parameters::getHiddenReferenceBlock(QString blockName) { + + BlockCategory* blockCat = categoryTree->searchCategory(100); + if (blockCat == NULL) return NULL; + ReferenceBlock* ref = blockCat->getBlockByName(blockName); return ref; } +double Parameters::getFeedingClockFrequency(AbstractInterface *iface) { + + int idClock = 0; + + if (iface->isReferenceInterface()) return 0.0; + + if (iface->getClockIfaceType() == AbstractInterface::ParameterName) { + BlockParameter* param = iface->getOwner()->getParameterFromName(iface->getClockIfaceString()); + if (!param->isUserParameter()) return 0.0; + bool ok; + double freq = param->getDoubleValue(&ok); + if (!ok) { + cerr << "Abnormal case: cannot retrieve clock id from parameter " << qPrintable(param->getName()) << endl; + } + return freq; + } + else if ( (iface->getClockIfaceType() == AbstractInterface::ClockName) || ((iface->getDirection() == AbstractInterface::Input) && (iface->getPurpose() == AbstractInterface::Clock))) { + + // if iface is not clock, retrieve the clock related to it + if (iface->getClockIfaceType() == AbstractInterface::ClockName) { + iface = iface->getClockIface(); + } + // if iface is a group interface, then iface name is ext_clk_X, thus extract the X + if (iface->isGroupInterface()) { + QString name = iface->getName(); + name.remove(0,8); + bool ok; + idClock = name.toInt(&ok); + if (!ok) { + cerr << "Abnormal case: cannot retrieve clock id from iface name " << qPrintable(iface->getName()) << endl; + return 0.0; + } + } + // if iface is a functional interface, it is connected to clkrstgen_X (in top group) or to ext_clk_X (in subgroup) + else if (iface->isFunctionalInterface()) { + FunctionalInterface* funIface = AI_TO_FUN(iface); + ConnectedInterface* connFrom = funIface->getConnectedFrom(); + if (connFrom == NULL) { + cerr << "Abnormal case: input clock " << qPrintable(iface->getName()) << " is not connected" << endl; + return 0.0; + } + if (iface->getOwner()->isTopGroupBlock()) { + QString name = connFrom->getOwner()->getName(); + name.remove(0,10); + bool ok; + idClock = name.toInt(&ok); + if (!ok) { + cerr << "Abnormal case: cannot retrieve clock id for " << qPrintable(iface->getName()) << endl; + return 0.0; + } + } + else { + QString name = connFrom->getName(); + name.remove(0,8); + bool ok; + idClock = name.toInt(&ok); + if (!ok) { + cerr << "Abnormal case: cannot retrieve clock id for " << qPrintable(iface->getName()) << endl; + return 0.0; + } + } + } + } + return graph->getClock(idClock); +} + void Parameters::createDelayBlock() { delayRef = new ReferenceBlock("no.xml"); delayRef->addCategory(100); @@ -237,6 +315,16 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { GroupBlock *groupBlock = NULL; GroupWidget* topGroup = NULL; + + QString path = root.attribute("project_path","none"); + if (path != "none") { + QDir dir(path); + if (dir.exists()) { + projectPath = path; + + } + cout << "project path set to " << qPrintable(projectPath) << endl; + } /********************************************************** 1 : getting scene and creating associated group widgets ***********************************************************/ @@ -252,7 +340,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); if (idUpperScene == -1) { - topGroup = dispatcher->createTopScene(); + topGroup = dispatcher->createTopScene(Dispatcher::Load); topScene->setId(idScene); groupItem = topScene->getGroupItem(); cout << "top group added to scene n°" << idScene << endl; @@ -260,7 +348,12 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { else { cout << "trying to create scene n°" << idScene << " with upper scene n°" <addNewEmptyGroup(upperScene,false); + /* IMPORTANT: calling addNewEmptyGroup() leads to create a new GroupWidget + * AND a BoxItem in upperScene that represents the GroupItem in the + * newly created child scene. Thus, it has not to be created when + * reading bi_group tags in the following but just searched + */ + groupWidget = dispatcher->addNewEmptyGroup(Dispatcher::Load, upperScene,false); groupWidget->getScene()->setId(idScene); groupItem = groupWidget->getScene()->getGroupItem(); } @@ -282,7 +375,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl; } } - dispatcher->setSceneCounter(maxIdScene+1); + dispatcher->setSceneCounter(Dispatcher::Load, maxIdScene+1); cout << "groupItems loaded and windows created succefully!" << endl; /********************************************************** @@ -305,7 +398,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { cout << "top scene has " << sourceNodes.length() << " sources" << endl; for(int j=0; jload(currentSBNode); } @@ -314,7 +407,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { } cout << "source item has been read, add it to the scene" << endl; // add the block to the GroupScene - currentScene->addSourceItem(sourceItem); + currentScene->addStimuliItem(sourceItem); } } /********************************************************** @@ -437,7 +530,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { InterfaceItem *iface2 = searchInterfaceItemById(to,topScene); if(iface1 != NULL && iface2 != NULL){ - dispatcher->createConnection(iface1,iface2); + dispatcher->createConnection(Dispatcher::Load, iface1,iface2); } else { cout << "interfaces not found, connect canceled!" << endl; } @@ -457,23 +550,25 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { QString paramsStr = currentModifierNode.attribute("params","none"); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - AbstractInputModifier* mod = NULL; - if (typeStr == "delay") { - int delay = paramsStr.toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - mod = new DelayInputModifier(delay); - } - /* NB: just adding delays for now. To be cont'd */ InterfaceItem *iface = searchInterfaceItemById(id,topScene); - if(iface != NULL ) { - iface->refInter->setInputModifier(mod); + if ((iface == NULL ) || (iface->refInter == NULL) || (iface->refInter->getAssociatedIface() == NULL)) { + cout << "modified interface not found, modifiers setup canceled!" << endl; + } + else { + ConnectedInterface* connIface = AI_TO_CON(iface->refInter->getAssociatedIface()); - } else { - cout << "interfaces not found, modifiers setup canceled!" << endl; + AbstractInputModifier* mod = NULL; + if (typeStr == "delay") { + int delay = paramsStr.toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + mod = new DelayInputModifier(connIface, delay); + connIface->setInputModifier(mod); + } } } + cout << "modifiers loaded and created succefully!" << endl; return topGroup; @@ -552,10 +647,27 @@ void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) { implPathes.append(path); cout << "impl path : " << qPrintable(path) << endl << endl; } + + QDomElement eltSource = eltImpl.nextSiblingElement("sources"); + nbPathesStr = eltSource.attribute("nb","none"); + nbPathes = nbPathesStr.toInt(&ok); + QDomNodeList listSourceDir = eltSource.elementsByTagName("source_lib"); + if ((!ok) || (nbPathes != listSourceDir.size())) throw(Exception(CONFIGFILE_CORRUPTED)); + + for(int i=0;i // for each child element, initialize the associated attributes of Parameters - QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults"); + QDomElement eltDefaults = eltSource.nextSiblingElement("defaults"); QDomElement eltBlocks = eltDefaults.firstChildElement("blocks"); QString attributeStr = eltBlocks.attribute("width", "none"); @@ -785,6 +897,22 @@ void Parameters::loadImplementationsFromXml() throw(Exception) { QString refXml = implRoot.attribute("ref_name","none"); QString refMd5 = implRoot.attribute("ref_md5","none"); BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5); + + QDomNodeList archNode = implRoot.elementsByTagName("architecture"); + + if (archNode.isEmpty()) { + cout << "impl has no architecture" << endl; + return; + } + QDomElement archElt = archNode.at(0).toElement(); + QString compList = archElt.attribute("comp_list","none"); + if (compList != "none") { + QStringList compos = compList.split(","); + foreach(QString s, compos) { + impl->addResource(s); + } + } + try { impl->loadPatterns(implRoot); } @@ -886,6 +1014,74 @@ void Parameters::saveImplementationsToLib() throw(Exception) { libFile.close(); } + + +void Parameters::loadSources() throw(Exception) { + + for(int i=0;i Parameters::searchResourceByName(const QString& name) { + QList listRes; + foreach(ExternalResource* s, availableResources) { + if (s->getName() == name) { + listRes.append(s); + } + } + return listRes; +} + void Parameters::addAvailableBlock(ReferenceBlock *block) { availableBlocks.append(block); foreach (int id,block->getCategories()) { @@ -1092,8 +1288,13 @@ void Parameters::setArrowPathes() { _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2); _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2); _inArrow.lineTo(arrowLineLength,0); - _inArrow.closeSubpath(); - inArrow = _inArrow; + //_inArrow.closeSubpath(); + dataArrowIn = _inArrow; + + QPainterPath _inArrowC; + _inArrowC.lineTo(arrowLineLength,0); + _inArrowC.addEllipse(arrowLineLength,-arrowHeight/2,arrowHeight-1,arrowHeight-1); + clkrstArrow = _inArrowC; QPainterPath _outArrow; _outArrow.lineTo(arrowLineLength,0); @@ -1101,8 +1302,8 @@ void Parameters::setArrowPathes() { _outArrow.lineTo(arrowLineLength+arrowWidth,0); _outArrow.lineTo(arrowLineLength,arrowHeight/2); _outArrow.lineTo(arrowLineLength,0); - _outArrow.closeSubpath(); - outArrow = _outArrow; + //_outArrow.closeSubpath(); + dataArrowOut = _outArrow; } @@ -1175,7 +1376,7 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { } } if (scene->isTopScene()) { - foreach(SourceItem *block, scene->getSourceItems()){ + foreach(StimuliItem *block, scene->getSourceItems()){ foreach(InterfaceItem *item, block->getInterfaces()){ if(item->getId() == id){ return item; @@ -1197,3 +1398,10 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { } return NULL; } + +QString Parameters::normalizeName(const QString &name) { + QString s = name; + s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_"); + s.replace(QRegularExpression("[_]+"),"_"); + return s; +}