X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/3bbc311e444c1ef9ac66dd6861fb0acb13ddb72a..4327c2b8817b627249d98d889835726217c81a4e:/Parameters.cpp diff --git a/Parameters.cpp b/Parameters.cpp index 848ef7f..23b798f 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -9,6 +9,7 @@ #include "GroupScene.h" #include "GroupItem.h" #include "BoxItem.h" +#include "StimuliItem.h" #include "InterfaceItem.h" #include "ConnectionItem.h" @@ -23,6 +24,10 @@ #include "Exception.h" #include "BlocksToConfigureWidget.h" +#include "BlockParameterGeneric.h" + +#include "DelayInputModifier.h" + Parameters::Parameters() { categoryTree = NULL; arrowWidth = 5; @@ -41,10 +46,14 @@ Parameters::Parameters() { unsaveModif = false; isRstClkShown = false; - - projectPath = QDir::currentPath(); validityExtension = "_enb"; + + projectPath = ""; + projectName = ""; + projectFile = ""; + + graph = new Graph(); } Parameters::~Parameters() { @@ -62,13 +71,14 @@ void Parameters::clear() { refPathes.clear(); } -Graph* Parameters::createGraph() { - graph = new Graph(); +Graph* Parameters::initGraph(bool createTopGroupIfaces) { + graph->createTopGroup(createTopGroupIfaces); return graph; } void Parameters::destroyGraph() { delete graph; + graph = new Graph(); } ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) { @@ -76,10 +86,61 @@ 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; +} + + +void Parameters::createDelayBlock() { + delayRef = new ReferenceBlock("no.xml"); + delayRef->addCategory(100); + delayRef->setName("delay"); + + BlockCategory* cat = categoryTree->searchCategory(100); + cat->blocks.append(delayRef); + + AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width"); + delayRef->addInterface(interIn); + AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1"); + delayRef->addInterface(interInCtl); + interInCtl->setAssociatedIface(interIn); + AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width"); + delayRef->addInterface(interOut); + AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1"); + delayRef->addInterface(interOutCtl); + interOutCtl->setAssociatedIface(interOut); + BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8"); + BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1"); + delayRef->addParameter(param1); + delayRef->addParameter(param2); + delayImpl = new BlockImplementation("no.xml"); + delayImpl->setDelta("1"); + QHash consPattern; + consPattern.insert("data_in_enb","1"); + delayImpl->setConsumptionPattern(consPattern); + QHash prodPattern; + prodPattern.insert("data_out_enb","O{$dly_length}1"); + delayImpl->setProductionPattern(prodPattern); + delayImpl->setProductionCounter("1"); + delayRef->addImplementation(delayImpl); + delayImpl->setReference(delayRef); + if (! delayImpl->checkPatterns()) { + cout << "Delay block creation: failure" << endl; + } + else { + cout << "Delay block creation: success" << endl; + } + +} + void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) { @@ -190,6 +251,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 ***********************************************************/ @@ -205,7 +276,15 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); if (idUpperScene == -1) { - topGroup = dispatcher->createTopScene(); + QString clkList = currentSceneNode.attribute("clklist","none"); + if (clkList == "none") throw(Exception(PROJECTFILE_CORRUPTED)); + QStringList clks = clkList.split(","); + for(int j=0;jaddClock(freq); + } + topGroup = dispatcher->createTopScene(Dispatcher::Load); topScene->setId(idScene); groupItem = topScene->getGroupItem(); cout << "top group added to scene n°" << idScene << endl; @@ -213,7 +292,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(); } @@ -232,9 +316,10 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { if (idUpperScene != -1) { groupWidget->setWindowTitle(groupBlock->getName()); groupWidget->show(); + 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; /********************************************************** @@ -249,7 +334,29 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { GroupScene *currentScene = searchSceneById(idScene,topScene); if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED)); - + /********************************************************** + 2.1 : getting sources if it is top scene + ***********************************************************/ + if (currentScene->isTopScene()) { + QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item"); + cout << "top scene has " << sourceNodes.length() << " sources" << endl; + for(int j=0; jload(currentSBNode); + } + catch(Exception err) { + throw(err); + } + cout << "source item has been read, add it to the scene" << endl; + // add the block to the GroupScene + currentScene->addStimuliItem(sourceItem); + } + } + /********************************************************** + 2.2 : getting functional blocks + ***********************************************************/ QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional"); for(int j=0; j lst = currentScene->getBoxItems(); foreach(BoxItem* item, lst) { @@ -342,10 +449,10 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { double position = currentInterfaceNode.attribute("position","none").toDouble(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter; + ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter; InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this); ifaceItem->setId(id); - upperItem->addInterface(ifaceItem); + upperItem->addInterfaceItem(ifaceItem); } } } @@ -362,18 +469,56 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { int to = currentConnectionNode.attribute("to","none").toInt(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - + bool showConn = true; + QString visStr = currentConnectionNode.attribute("visible","none"); + if (visStr == "false") { + showConn = false; + } InterfaceItem *iface1 = searchInterfaceItemById(from,topScene); InterfaceItem *iface2 = searchInterfaceItemById(to,topScene); if(iface1 != NULL && iface2 != NULL){ - dispatcher->createConnection(iface1,iface2); + dispatcher->createConnection(Dispatcher::Load, iface1,iface2,showConn); } else { cout << "interfaces not found, connect canceled!" << endl; } } cout << "connections loaded and created succefully!" << endl; + QDomNodeList modifierNodes = root.elementsByTagName("modifier"); + + for(int i=0; irefInter == NULL) || (iface->refInter->getAssociatedIface() == NULL)) { + cout << "modified interface not found, modifiers setup canceled!" << endl; + } + else { + ConnectedInterface* connIface = AI_TO_CON(iface->refInter->getAssociatedIface()); + + 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; } @@ -450,10 +595,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"); @@ -515,7 +677,7 @@ void Parameters::loadReferencesFromXml() throw(Exception) { QString line = in.readLine(); line = in.readLine(); - if (!line.contains("")) { + if (!line.contains("addResource(s); + } + } + + try { + impl->loadPatterns(implRoot); + } + catch(int err) { + throw(err); + } availableImplementations.append(impl); ReferenceBlock* ref = NULL; @@ -694,9 +878,12 @@ void Parameters::loadImplementationsFromXml() throw(Exception) { } if (ref == NULL) { cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl; - } - ref->addImplementation(impl); - impl->setReference(ref); + } + else { + ref->addImplementation(impl); + impl->setReference(ref); + if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED)); + } cout << "OK" << endl; } } @@ -741,8 +928,11 @@ void Parameters::loadImplementationsFromLib() throw(Exception) { if (ref == NULL) { cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl; } - ref->addImplementation(impl); - impl->setReference(ref); + else { + ref->addImplementation(impl); + impl->setReference(ref); + if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED)); + } } libFile.close(); } @@ -772,6 +962,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()) { @@ -928,11 +1186,42 @@ void Parameters::save(QString confFile) { writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId())); writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId())); - + if (!item->isVisible()) { + writer.writeAttribute("visible","false"); + } writer.writeEndElement(); } writer.writeEndElement(); // + + QList lstIfaceItem; + // search for modifiers + foreach(ConnectionItem* item, allConnections) { + InterfaceItem* fromIfaceItem = item->getFromInterfaceItem(); + AbstractInputModifier* mod = fromIfaceItem->refInter->getInputModifier(); + if (mod != NULL) { + if (!lstIfaceItem.contains(fromIfaceItem)) lstIfaceItem.append(fromIfaceItem); + } + InterfaceItem* toIfaceItem = item->getToInterfaceItem(); + mod = toIfaceItem->refInter->getInputModifier(); + if (mod != NULL) { + if (!lstIfaceItem.contains(toIfaceItem)) lstIfaceItem.append(toIfaceItem); + } + } + // write input modifiers + writer.writeStartElement("modifiers"); + foreach(InterfaceItem* item, lstIfaceItem) { + AbstractInputModifier* mod = item->refInter->getInputModifier(); + if (mod != NULL) { + writer.writeStartElement("modifier"); + writer.writeAttribute("id", QString::number(item->getId())); + writer.writeAttribute("type",mod->getTypeStr()); + writer.writeAttribute("params", mod->getParametersStr()); + writer.writeEndElement(); + } + } + + writer.writeEndElement(); // writer.writeEndElement(); //getBoxItems()){ + if(item->getRefBlock() == block) { + return item; + } + } + + BoxItem* item = NULL; + foreach(GroupScene *s, scene->getChildrenScene()) { + item = searchFunctionalBlockRecur(block,s); + if (item != NULL) return item; + } + return NULL; +} + InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){ @@ -1010,6 +1325,15 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { return item; } } + if (scene->isTopScene()) { + foreach(StimuliItem *block, scene->getSourceItems()){ + foreach(InterfaceItem *item, block->getInterfaces()){ + if(item->getId() == id){ + return item; + } + } + } + } foreach(BoxItem *block, scene->getBoxItems()){ foreach(InterfaceItem *item, block->getInterfaces()){ if(item->getId() == id){ @@ -1024,3 +1348,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; +}