X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/f311fbc3e1436bf248c54225f0743cfa671c4bd7..e40a5399ec7887c2606f18575c809b0d05b09278:/Parameters.cpp?ds=sidebyside diff --git a/Parameters.cpp b/Parameters.cpp index fce0435..60d7971 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -9,6 +9,7 @@ #include "GroupScene.h" #include "GroupItem.h" #include "BoxItem.h" +#include "SourceItem.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,8 +46,12 @@ Parameters::Parameters() { unsaveModif = false; isRstClkShown = false; + + validityExtension = "_enb"; - projectPath = QDir::currentPath(); + projectPath = ""; + projectName = ""; + projectFile = ""; } Parameters::~Parameters() { @@ -60,8 +69,8 @@ void Parameters::clear() { refPathes.clear(); } -Graph* Parameters::createGraph() { - graph = new Graph(); +Graph* Parameters::createGraph(bool createTopGroupIfaces) { + graph = new Graph(createTopGroupIfaces); return graph; } @@ -74,21 +83,62 @@ 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) { -FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) { + BlockCategory* blockCat = categoryTree->searchCategory(100); + if (blockCat == NULL) return NULL; + ReferenceBlock* ref = blockCat->getBlockByName(blockName); + return ref; +} - ReferenceBlock* ref = block->getReference(); - GroupBlock* group = AB_TO_GRP(block->getParent()); +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<QString,QString> consPattern; + consPattern.insert("data_in_enb","1"); + delayImpl->setConsumptionPattern(consPattern); + QHash<QString,QString> 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; + } - // adding to the graph - FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref); - return newBlock; } + + void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) { // opening configFile QFile xmlFile(xmlFileName); @@ -189,115 +239,75 @@ QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Ex return root; } -void Parameters::loadProject(QDomElement root) { - -#ifdef DEBUG_INCLFUN +GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { bool ok = false; GroupWidget* groupWidget = NULL; GroupItem *groupItem = NULL; 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 ***********************************************************/ QDomNodeList scenesNodes = root.elementsByTagName("scene"); + int maxIdScene = -1; for(int i=0; i<scenesNodes.length(); i++) { QDomElement currentSceneNode = scenesNodes.at(i).toElement(); int idScene = currentSceneNode.attribute("id","none").toInt(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + if (idScene > maxIdScene) maxIdScene = idScene; int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); if (idUpperScene == -1) { - dispatcher->createTopScene(); + topGroup = dispatcher->createTopScene(Dispatcher::Load); topScene->setId(idScene); - groupItem = topScene->getGroupItem(); - groupBlock = AB_TO_GRP(groupItem->getRefBlock()); + groupItem = topScene->getGroupItem(); cout << "top group added to scene n°" << idScene << endl; } else { - GroupScene* scene = searchSceneById(idUpperScene, topScene); - GroupWidget* parent = scene->getGroupWindow(); - groupWidget = dispatcher->createChildScene(parent); - groupItem = groupWidget->getScene()->getGroupItem(); - groupBlock = AB_TO_GRP(groupItem->getRefBlock()); + cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl; + GroupScene* upperScene = searchSceneById(idUpperScene, topScene); + groupWidget = dispatcher->addNewEmptyGroup(Dispatcher::Load, upperScene,false); + groupWidget->getScene()->setId(idScene); + groupItem = groupWidget->getScene()->getGroupItem(); } + groupBlock = AB_TO_GRP(groupItem->getRefBlock()); /********************************************************** - 1.1 : getting the group item + 1.1 : getting the group item of each scene ***********************************************************/ QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item"); - - int id = groupItemNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString name = groupItemNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QStringList positionStr = groupItemNode.attribute("position","none").split(","); - if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); - int posX = positionStr.at(0).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - int posY = positionStr.at(1).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(","); - if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); - int dimX = dimensionStr.at(0).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - int dimY = dimensionStr.at(1).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - groupItem->setId(id); - groupItem->setPos(posX,posY); - groupItem->setDimension(dimX,dimY); - groupBlock->setName(name); + try { + groupItem->load(groupItemNode); + } + catch(Exception err) { + throw(err); + } if (idUpperScene != -1) { groupWidget->setWindowTitle(groupBlock->getName()); groupWidget->show(); - } - cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl; - - QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface"); - for(int j=0; j<interfaces.length(); j++){ - QDomElement currentInterfaceNode = interfaces.at(j).toElement(); - - int id = currentInterfaceNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString name = currentInterfaceNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString levelStr = currentInterfaceNode.attribute("level","none"); - int level = AbstractInterface::getIntLevel(levelStr); - if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString directionStr = currentInterfaceNode.attribute("direction","none"); - int direction = AbstractInterface::getIntDirection(directionStr); - if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString orientationStr = currentInterfaceNode.attribute("orientation","none"); - int orientation = InterfaceItem::getIntOrientation(orientationStr); - if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED)); - - double position = currentInterfaceNode.attribute("position","none").toDouble(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level); - - InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this); - interfaceItem->setId(id); - - groupBlock->addInterface(groupInterface); - groupItem->addInterface(interfaceItem); - cout << "interface add to " << groupBlock->getName().toStdString() << endl; - } + cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl; + } } - + dispatcher->setSceneCounter(Dispatcher::Load, maxIdScene+1); cout << "groupItems loaded and windows created succefully!" << endl; + /********************************************************** + 2 : getting the functional blocks of each scene + ***********************************************************/ for(int i=0; i<scenesNodes.length(); i++){ QDomElement currentSceneNode = scenesNodes.at(i).toElement(); @@ -307,137 +317,49 @@ void Parameters::loadProject(QDomElement root) { 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; j<sourceNodes.length(); j++) { + QDomElement currentSBNode = sourceNodes.at(j).toElement(); + SourceItem* sourceItem = new SourceItem(dispatcher,this); + try { + sourceItem->load(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->addSourceItem(sourceItem); + } + } + /********************************************************** + 2.2 : getting functional blocks + ***********************************************************/ QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional"); - for(int j=0; j<functionalBlockNodes.length(); j++){ - QDomElement currentFBNode = functionalBlockNodes.at(j).toElement(); - - int id = currentFBNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString refXml = currentFBNode.attribute("ref_xml","none"); - if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString refMd5 = currentFBNode.attribute("ref_md5","none"); - if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl; - - QString name = currentFBNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QStringList positionStr = currentFBNode.attribute("position","none").split(","); - if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); - int posX = positionStr.at(0).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - int posY = positionStr.at(1).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(","); - if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED)); - int dimX = dimensionStr.at(0).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - int dimY = dimensionStr.at(1).toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - AbstractBlock *reference; - /*if(refMd5 != "none"){ - cout << "md5" << endl; - reference = searchBlockByMd5(refMd5); - } - else */if(refXml != "none"){ - cout << "xml" << endl; - reference = searchBlockByXml(refXml); - } - else { - throw(Exception(PROJECTFILE_CORRUPTED)); - } - - FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference); - functionalBlock->setName(name); - - ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock); - - - BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this); - blockItem->setPos(posX,posY); - blockItem->setDimension(dimX,dimY); - blockItem->setId(id); - ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem); - currentScene->addItem(blockItem); - currentScene->addBlockItem(blockItem); - - QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter"); - - for(int i=0; i<blockParamNodes.length(); i++){ - QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement(); - - QString name = currentBlockParamNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString value = currentBlockParamNode.attribute("value","none"); - if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString context = currentBlockParamNode.attribute("context","none"); - if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString type = currentBlockParamNode.attribute("type","none"); - if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - - BlockParameter *blockParam = new BlockParameter; - blockParam->setName(name); - blockParam->setValue(value); - blockParam->setType(type); - if(context == "constant") blockParam->setContext(BlockParameter::Constant); - if(context == "user") blockParam->setContext(BlockParameter::User); - if(context == "generic") blockParam->setContext(BlockParameter::Generic); - if(context == "wb") blockParam->setContext(BlockParameter::Wishbone); - if(context == "port") blockParam->setContext(BlockParameter::Port); - - functionalBlock->addParameter(blockParam); + for(int j=0; j<functionalBlockNodes.length(); j++) { + QDomElement currentFBNode = functionalBlockNodes.at(j).toElement(); + BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem()); + try { + funcItem->loadFunctional(currentFBNode); } - - - QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface"); - - for(int i=0; i<interfaceNodes.length(); i++){ - - QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement(); - - int id = currentInterfaceNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - QString name = currentInterfaceNode.attribute("name","none"); - if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString refName = currentInterfaceNode.attribute("ref_name","none"); - if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED)); - - QString orientationStr = currentInterfaceNode.attribute("orientation","none"); - int orientation = InterfaceItem::getIntOrientation(orientationStr); - if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED)); - - double position = currentInterfaceNode.attribute("position","none").toDouble(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName); - FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter); - functionalBlock->addInterface(functionalInterface); - functionalInterface->setName(refName); - - InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this); - interfaceItem->setId(id); - interfaceItem->setName(name); - - blockItem->addInterface(interfaceItem); - + catch(Exception err) { + throw(err); } + // add the block to the GroupScene + currentScene->addBoxItem(funcItem); } } - cout << "functionalBlocks loaded and created succefully!" << endl; + cout << "functional blocks loaded and created succefully!" << endl; + /********************************************************** + 3 : set the BoxItem that represents a GroupItem in a child scene + ***********************************************************/ for(int i=0; i<scenesNodes.length(); i++){ QDomElement currentSceneNode = scenesNodes.at(i).toElement(); @@ -471,19 +393,27 @@ void Parameters::loadProject(QDomElement root) { int dimY = dimensionStr.at(1).toInt(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - + // get the GroupItem already created and set at phase 1 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene); - if(insideGroup == NULL) cout << "group null" << endl; - BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this); - blockItem->setChildGroupItem(insideGroup); - blockItem->setId(id); - blockItem->setPos(posX,posY); - blockItem->setDimension(dimX,dimY); + BoxItem* upperItem = NULL; + if(insideGroup == NULL) cout << "group null" << endl; + // now search within the scene which BoxItem has a childItem that is = to insideGroup + QList<BoxItem *> lst = currentScene->getBoxItems(); + foreach(BoxItem* item, lst) { + if (item->getChildGroupItem() == insideGroup) { + upperItem = item; + break; + } + } + if (upperItem == NULL) { + throw(Exception(PROJECTFILE_CORRUPTED)); + } - ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem); - currentScene->addItem(blockItem); - currentScene->addBlockItem(blockItem); + upperItem->setId(id); + upperItem->setPos(posX,posY); + upperItem->setDimension(dimX,dimY); + // set interfaces of this BoxItem QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface"); for(int k=0; k<interfaceNodes.length(); k++){ @@ -502,34 +432,15 @@ void Parameters::loadProject(QDomElement root) { double position = currentInterfaceNode.attribute("position","none").toDouble(&ok); if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter; - InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this); + ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter; + InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this); ifaceItem->setId(id); - blockItem->addInterface(ifaceItem); + upperItem->addInterfaceItem(ifaceItem); } } } cout << "blockItems \"group\" loaded and created succefully!" << endl; - - for(int i=0; i<scenesNodes.length(); i++){ - QDomElement currentSceneNode = scenesNodes.at(i).toElement(); - - QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item"); - - int id = groupItemNode.attribute("id","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok); - if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); - - BlockItem *currentItem = searchBlockItemById(id,topScene); - GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene); - - if(currentItem != NULL && upperItem != NULL){ - currentItem->setUpperItem(upperItem); - } - } - QDomNodeList connectionNodes = root.elementsByTagName("connection"); for(int i=0; i<connectionNodes.length(); i++){ @@ -546,13 +457,48 @@ void Parameters::loadProject(QDomElement root) { InterfaceItem *iface2 = searchInterfaceItemById(to,topScene); if(iface1 != NULL && iface2 != NULL){ - dispatcher->connect(iface1,iface2); + dispatcher->createConnection(Dispatcher::Load, iface1,iface2); } else { cout << "interfaces not found, connect canceled!" << endl; } } + cout << "connections loaded and created succefully!" << endl; -#endif + QDomNodeList modifierNodes = root.elementsByTagName("modifier"); + + for(int i=0; i<modifierNodes.length(); i++){ + QDomElement currentModifierNode = modifierNodes.at(i).toElement(); + + int id = currentModifierNode.attribute("id","none").toInt(&ok); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + + QString typeStr = currentModifierNode.attribute("type","none"); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + QString paramsStr = currentModifierNode.attribute("params","none"); + if(!ok) throw(Exception(PROJECTFILE_CORRUPTED)); + + /* NB: just adding delays for now. To be cont'd */ + InterfaceItem *iface = searchInterfaceItemById(id,topScene); + + 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()); + + 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; } void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) { @@ -628,10 +574,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<listSourceDir.size();i++) { + QDomNode nodeSourceDir = listSourceDir.at(i); + QDomElement eltSourceDir = nodeSourceDir.toElement(); + if (eltSourceDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED)); + QString path = eltSourceDir.attribute("path","none"); + if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED)); + sourcePathes.append(path); + cout << "core path : " << qPrintable(path) << endl << endl; + } + // getting elt = the element <defaults> // 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"); @@ -693,14 +656,14 @@ void Parameters::loadReferencesFromXml() throw(Exception) { QString line = in.readLine(); line = in.readLine(); - if (!line.contains("<block>")) { + if (!line.contains("<block")) { blockXML.close(); continue; } blockXML.close(); try { - validateXmlFile(fileName,"block.xsd",Reference); + validateXmlFile(fileName,"reference.xsd",Reference); } catch(Exception err) { throw(err); @@ -836,14 +799,14 @@ void Parameters::loadImplementationsFromXml() throw(Exception) { implXML.close(); cout << "OK" << endl; cout << "reading " << qPrintable(fileName) << " content ..."; - /* + try { - validateXmlFile(fileName,"block.xsd",Implementation); + validateXmlFile(fileName,"implementation.xsd",Implementation); } catch(Exception e) { throw(e); } - */ + // reading in into QDomDocument QDomDocument document ("FileXML"); if (!implXML.open(QIODevice::ReadOnly)) { @@ -861,6 +824,28 @@ 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); + } + catch(int err) { + throw(err); + } availableImplementations.append(impl); ReferenceBlock* ref = NULL; @@ -872,9 +857,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; } } @@ -919,8 +907,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(); } @@ -950,6 +941,74 @@ void Parameters::saveImplementationsToLib() throw(Exception) { libFile.close(); } + + +void Parameters::loadSources() throw(Exception) { + + for(int i=0;i<sourcePathes.size();i++) { + cout << "analyzing " << qPrintable(sourcePathes.at(i)) << endl; + QDir dir(sourcePathes.at(i)); + QStringList filter; + filter << "*.vhd" << "*.ngc"; + dir.setNameFilters(filter); + QStringList list = dir.entryList(); + for(int j=0;j<list.size();j++) { + QString fileName = dir.absolutePath(); + fileName.append("/"+list.at(j)); + + if (list.at(j).endsWith(".ngc")) { + QString netName = list.at(j); + netName.truncate(list.at(j).size() -4); + cout << "found netlist " << qPrintable(netName) << endl; + availableResources.append(new ExternalResource(netName,fileName,ExternalResource::Netlist)); + } + else { + cout << "parsing " << qPrintable(fileName) << " ... "; + QFile srcXML(fileName); + if (!srcXML.open(QIODevice::ReadOnly)) { + throw(Exception(IMPLFILE_NOACCESS)); + } + QTextStream in(&srcXML); + + QString line = in.readLine(); + while (!line.isNull()) { + if (line.contains("package", Qt::CaseInsensitive)) { + QRegularExpression rxPack("^package (.+) is$",QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch matchPack = rxPack.match(line); + if (matchPack.hasMatch()) { + QString packName = matchPack.captured(1); + cout << "found package " << qPrintable(packName) << endl; + availableResources.append(new ExternalResource(packName,fileName,ExternalResource::Package)); + } + } + else if (line.contains("entity", Qt::CaseInsensitive)) { + QRegularExpression rxEnt("^entity (.+) is$",QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch matchEnt = rxEnt.match(line); + if (matchEnt.hasMatch()) { + QString entityName = matchEnt.captured(1); + cout << "found entity " << qPrintable(entityName) << endl; + availableResources.append(new ExternalResource(entityName,fileName,ExternalResource::Code)); + } + } + line = in.readLine(); + } + srcXML.close(); + cout << "OK" << endl; + } + } + } +} + +QList<ExternalResource *> Parameters::searchResourceByName(const QString& name) { + QList<ExternalResource*> 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()) { @@ -1015,9 +1074,9 @@ QList<AbstractBlock *> Parameters::getBlocksToConfigure() { void Parameters::updateToolbar() { - int nb = currentScene->getBlockItems().length(); + int nb = currentScene->getBoxItems().length(); for(int i = 0; i<nb; i++){ - if(currentScene->getBlockItems().at(i)->isSelected()){ + if(currentScene->getBoxItems().at(i)->isSelected()){ currentScene->getGroupWidget()->enableGroupButton(true); return; } @@ -1111,6 +1170,35 @@ void Parameters::save(QString confFile) { } writer.writeEndElement(); //</connections> + + QList<InterfaceItem *> 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(); //</modifiers> writer.writeEndElement(); //</blast_project writer.writeEndDocument(); @@ -1127,8 +1215,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); @@ -1136,8 +1229,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; } @@ -1167,7 +1260,7 @@ GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) { BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) { - foreach(BoxItem *item, scene->getBlockItems()){ + foreach(BoxItem *item, scene->getBoxItems()){ if(item->getId() == id){ return item; } @@ -1181,6 +1274,27 @@ BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) { return NULL; } +BoxItem* Parameters::searchFunctionalBlock(AbstractBlock* block) { + + return searchFunctionalBlockRecur(block,topScene); +} + +BoxItem* Parameters::searchFunctionalBlockRecur(AbstractBlock* block, GroupScene* scene) { + + foreach(BoxItem *item, scene->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()){ @@ -1188,7 +1302,16 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { return item; } } - foreach(BoxItem *block, scene->getBlockItems()){ + if (scene->isTopScene()) { + foreach(SourceItem *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){ return item; @@ -1202,3 +1325,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; +}