#include "GroupScene.h"\r
#include "GroupItem.h"\r
#include "BoxItem.h"\r
+#include "SourceItem.h"\r
#include "InterfaceItem.h"\r
#include "ConnectionItem.h"\r
\r
#include "Exception.h"\r
#include "BlocksToConfigureWidget.h"\r
\r
+#include "BlockParameterGeneric.h"\r
+\r
+#include "DelayInputModifier.h"\r
+\r
Parameters::Parameters() {\r
categoryTree = NULL;\r
arrowWidth = 5;\r
\r
unsaveModif = false;\r
isRstClkShown = false;\r
-\r
- projectPath = QDir::currentPath();\r
\r
validityExtension = "_enb";\r
+\r
+ projectPath = "";\r
+ projectName = "";\r
+ projectFile = "";\r
}\r
\r
Parameters::~Parameters() {\r
refPathes.clear();\r
}\r
\r
-Graph* Parameters::createGraph() {\r
- graph = new Graph();\r
+Graph* Parameters::createGraph(bool createTopGroupIfaces) {\r
+ graph = new Graph(createTopGroupIfaces);\r
return graph;\r
}\r
\r
BlockCategory* blockCat = categoryTree->searchCategory(idCategory);\r
\r
if (blockCat == NULL) return NULL;\r
- ReferenceBlock* ref = blockCat->getBlock(idBlock);\r
+ ReferenceBlock* ref = blockCat->getBlockById(idBlock);\r
return ref;\r
}\r
\r
+ReferenceBlock* Parameters::getHiddenReferenceBlock(QString blockName) {\r
+\r
+ BlockCategory* blockCat = categoryTree->searchCategory(100);\r
+ if (blockCat == NULL) return NULL;\r
+ ReferenceBlock* ref = blockCat->getBlockByName(blockName);\r
+ return ref;\r
+}\r
+\r
+void Parameters::createDelayBlock() {\r
+ delayRef = new ReferenceBlock("no.xml");\r
+ delayRef->addCategory(100);\r
+ delayRef->setName("delay");\r
+\r
+ BlockCategory* cat = categoryTree->searchCategory(100);\r
+ cat->blocks.append(delayRef);\r
+\r
+ AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width");\r
+ delayRef->addInterface(interIn);\r
+ AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1");\r
+ delayRef->addInterface(interInCtl);\r
+ interInCtl->setAssociatedIface(interIn);\r
+ AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width");\r
+ delayRef->addInterface(interOut);\r
+ AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1");\r
+ delayRef->addInterface(interOutCtl);\r
+ interOutCtl->setAssociatedIface(interOut);\r
+ BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8");\r
+ BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1");\r
+ delayRef->addParameter(param1);\r
+ delayRef->addParameter(param2);\r
+ delayImpl = new BlockImplementation("no.xml");\r
+ delayImpl->setDelta("1");\r
+ QHash<QString,QString> consPattern;\r
+ consPattern.insert("data_in_enb","1");\r
+ delayImpl->setConsumptionPattern(consPattern);\r
+ QHash<QString,QString> prodPattern;\r
+ prodPattern.insert("data_out_enb","O{$dly_length}1");\r
+ delayImpl->setProductionPattern(prodPattern);\r
+ delayImpl->setProductionCounter("1");\r
+ delayRef->addImplementation(delayImpl);\r
+ delayImpl->setReference(delayRef);\r
+ if (! delayImpl->checkPatterns()) {\r
+ cout << "Delay block creation: failure" << endl;\r
+ }\r
+ else {\r
+ cout << "Delay block creation: success" << endl;\r
+ }\r
+\r
+}\r
+\r
\r
\r
void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {\r
GroupBlock *groupBlock = NULL;\r
\r
GroupWidget* topGroup = NULL;\r
+\r
+ QString path = root.attribute("project_path","none");\r
+ if (path != "none") {\r
+ QDir dir(path);\r
+ if (dir.exists()) {\r
+ projectPath = path;\r
+\r
+ }\r
+ cout << "project path set to " << qPrintable(projectPath) << endl;\r
+ }\r
/**********************************************************\r
1 : getting scene and creating associated group widgets\r
***********************************************************/\r
if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
\r
if (idUpperScene == -1) {\r
- topGroup = dispatcher->createTopScene();\r
+ topGroup = dispatcher->createTopScene(Dispatcher::Load);\r
topScene->setId(idScene);\r
groupItem = topScene->getGroupItem(); \r
cout << "top group added to scene n°" << idScene << endl;\r
else {\r
cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;\r
GroupScene* upperScene = searchSceneById(idUpperScene, topScene);\r
- groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);\r
+ groupWidget = dispatcher->addNewEmptyGroup(Dispatcher::Load, upperScene,false);\r
groupWidget->getScene()->setId(idScene);\r
groupItem = groupWidget->getScene()->getGroupItem(); \r
}\r
if (idUpperScene != -1) {\r
groupWidget->setWindowTitle(groupBlock->getName());\r
groupWidget->show();\r
+ cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;\r
} \r
}\r
- dispatcher->setSceneCounter(maxIdScene+1);\r
+ dispatcher->setSceneCounter(Dispatcher::Load, maxIdScene+1);\r
cout << "groupItems loaded and windows created succefully!" << endl;\r
\r
/**********************************************************\r
GroupScene *currentScene = searchSceneById(idScene,topScene);\r
\r
if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
-\r
+ /**********************************************************\r
+ 2.1 : getting sources if it is top scene\r
+ ***********************************************************/\r
+ if (currentScene->isTopScene()) {\r
+ QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");\r
+ cout << "top scene has " << sourceNodes.length() << " sources" << endl;\r
+ for(int j=0; j<sourceNodes.length(); j++) {\r
+ QDomElement currentSBNode = sourceNodes.at(j).toElement(); \r
+ SourceItem* sourceItem = new SourceItem(dispatcher,this);\r
+ try {\r
+ sourceItem->load(currentSBNode);\r
+ }\r
+ catch(Exception err) {\r
+ throw(err);\r
+ }\r
+ cout << "source item has been read, add it to the scene" << endl;\r
+ // add the block to the GroupScene\r
+ currentScene->addSourceItem(sourceItem);\r
+ } \r
+ }\r
+ /**********************************************************\r
+ 2.2 : getting functional blocks\r
+ ***********************************************************/\r
QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");\r
\r
for(int j=0; j<functionalBlockNodes.length(); j++) {\r
// get the GroupItem already created and set at phase 1\r
GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);\r
BoxItem* upperItem = NULL;\r
- if(insideGroup == NULL) cout << "group null" << endl;\r
+ if(insideGroup == NULL) cout << "group null" << endl; \r
// now search within the scene which BoxItem has a childItem that is = to insideGroup\r
QList<BoxItem *> lst = currentScene->getBoxItems();\r
foreach(BoxItem* item, lst) {\r
double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
\r
- ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter;\r
+ ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;\r
InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);\r
ifaceItem->setId(id);\r
- upperItem->addInterface(ifaceItem);\r
+ upperItem->addInterfaceItem(ifaceItem);\r
}\r
}\r
}\r
InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);\r
\r
if(iface1 != NULL && iface2 != NULL){\r
- dispatcher->createConnectionItem(iface1,iface2);\r
+ dispatcher->createConnection(Dispatcher::Load, iface1,iface2);\r
} else {\r
cout << "interfaces not found, connect canceled!" << endl;\r
}\r
}\r
cout << "connections loaded and created succefully!" << endl;\r
\r
+ QDomNodeList modifierNodes = root.elementsByTagName("modifier");\r
+\r
+ for(int i=0; i<modifierNodes.length(); i++){\r
+ QDomElement currentModifierNode = modifierNodes.at(i).toElement();\r
+\r
+ int id = currentModifierNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString typeStr = currentModifierNode.attribute("type","none");\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ QString paramsStr = currentModifierNode.attribute("params","none");\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ /* NB: just adding delays for now. To be cont'd */\r
+ InterfaceItem *iface = searchInterfaceItemById(id,topScene);\r
+\r
+ if ((iface == NULL ) || (iface->refInter == NULL) || (iface->refInter->getAssociatedIface() == NULL)) {\r
+ cout << "modified interface not found, modifiers setup canceled!" << endl;\r
+ }\r
+ else {\r
+ ConnectedInterface* connIface = AI_TO_CON(iface->refInter->getAssociatedIface());\r
+\r
+ AbstractInputModifier* mod = NULL;\r
+ if (typeStr == "delay") {\r
+ int delay = paramsStr.toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ mod = new DelayInputModifier(connIface, delay);\r
+ connIface->setInputModifier(mod);\r
+ }\r
+ }\r
+ }\r
+\r
+ cout << "modifiers loaded and created succefully!" << endl;\r
+\r
return topGroup;\r
}\r
\r
implPathes.append(path);\r
cout << "impl path : " << qPrintable(path) << endl << endl;\r
}\r
+\r
+ QDomElement eltSource = eltImpl.nextSiblingElement("sources");\r
+ nbPathesStr = eltSource.attribute("nb","none");\r
+ nbPathes = nbPathesStr.toInt(&ok);\r
+ QDomNodeList listSourceDir = eltSource.elementsByTagName("source_lib");\r
+ if ((!ok) || (nbPathes != listSourceDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));\r
+\r
+ for(int i=0;i<listSourceDir.size();i++) {\r
+ QDomNode nodeSourceDir = listSourceDir.at(i);\r
+ QDomElement eltSourceDir = nodeSourceDir.toElement();\r
+ if (eltSourceDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ QString path = eltSourceDir.attribute("path","none");\r
+ if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
+ sourcePathes.append(path);\r
+ cout << "core path : " << qPrintable(path) << endl << endl;\r
+ }\r
+\r
// getting elt = the element <defaults>\r
// for each child element, initialize the associated attributes of Parameters\r
\r
- QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");\r
+ QDomElement eltDefaults = eltSource.nextSiblingElement("defaults");\r
\r
QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");\r
QString attributeStr = eltBlocks.attribute("width", "none");\r
QString line = in.readLine();\r
line = in.readLine();\r
\r
- if (!line.contains("<block>")) {\r
+ if (!line.contains("<block")) {\r
blockXML.close();\r
continue;\r
}\r
QString refXml = implRoot.attribute("ref_name","none");\r
QString refMd5 = implRoot.attribute("ref_md5","none");\r
BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);\r
+\r
+ QDomNodeList archNode = implRoot.elementsByTagName("architecture");\r
+\r
+ if (archNode.isEmpty()) {\r
+ cout << "impl has no architecture" << endl;\r
+ return;\r
+ }\r
+ QDomElement archElt = archNode.at(0).toElement();\r
+ QString compList = archElt.attribute("comp_list","none");\r
+ if (compList != "none") {\r
+ QStringList compos = compList.split(",");\r
+ foreach(QString s, compos) {\r
+ impl->addResource(s);\r
+ }\r
+ }\r
+\r
+ try {\r
+ impl->loadPatterns(implRoot);\r
+ }\r
+ catch(int err) {\r
+ throw(err);\r
+ }\r
availableImplementations.append(impl);\r
\r
ReferenceBlock* ref = NULL;\r
}\r
if (ref == NULL) {\r
cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;\r
- }\r
- ref->addImplementation(impl);\r
- impl->setReference(ref);\r
+ } \r
+ else { \r
+ ref->addImplementation(impl);\r
+ impl->setReference(ref);\r
+ if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));\r
+ } \r
cout << "OK" << endl;\r
}\r
}\r
if (ref == NULL) {\r
cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;\r
}\r
- ref->addImplementation(impl);\r
- impl->setReference(ref);\r
+ else { \r
+ ref->addImplementation(impl);\r
+ impl->setReference(ref);\r
+ if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));\r
+ }\r
}\r
libFile.close();\r
}\r
libFile.close();\r
\r
}\r
+\r
+\r
+void Parameters::loadSources() throw(Exception) {\r
+\r
+ for(int i=0;i<sourcePathes.size();i++) {\r
+ cout << "analyzing " << qPrintable(sourcePathes.at(i)) << endl;\r
+ QDir dir(sourcePathes.at(i));\r
+ QStringList filter;\r
+ filter << "*.vhd" << "*.ngc";\r
+ dir.setNameFilters(filter);\r
+ QStringList list = dir.entryList();\r
+ for(int j=0;j<list.size();j++) {\r
+ QString fileName = dir.absolutePath();\r
+ fileName.append("/"+list.at(j));\r
+\r
+ if (list.at(j).endsWith(".ngc")) {\r
+ QString netName = list.at(j);\r
+ netName.truncate(list.at(j).size() -4);\r
+ cout << "found netlist " << qPrintable(netName) << endl;\r
+ availableResources.append(new ExternalResource(netName,fileName,ExternalResource::Netlist));\r
+ }\r
+ else {\r
+ cout << "parsing " << qPrintable(fileName) << " ... ";\r
+ QFile srcXML(fileName);\r
+ if (!srcXML.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ QTextStream in(&srcXML);\r
+\r
+ QString line = in.readLine();\r
+ while (!line.isNull()) {\r
+ if (line.contains("package", Qt::CaseInsensitive)) {\r
+ QRegularExpression rxPack("^package (.+) is$",QRegularExpression::CaseInsensitiveOption);\r
+ QRegularExpressionMatch matchPack = rxPack.match(line);\r
+ if (matchPack.hasMatch()) {\r
+ QString packName = matchPack.captured(1);\r
+ cout << "found package " << qPrintable(packName) << endl;\r
+ availableResources.append(new ExternalResource(packName,fileName,ExternalResource::Package));\r
+ }\r
+ }\r
+ else if (line.contains("entity", Qt::CaseInsensitive)) {\r
+ QRegularExpression rxEnt("^entity (.+) is$",QRegularExpression::CaseInsensitiveOption);\r
+ QRegularExpressionMatch matchEnt = rxEnt.match(line);\r
+ if (matchEnt.hasMatch()) {\r
+ QString entityName = matchEnt.captured(1);\r
+ cout << "found entity " << qPrintable(entityName) << endl;\r
+ availableResources.append(new ExternalResource(entityName,fileName,ExternalResource::Code));\r
+ }\r
+ }\r
+ line = in.readLine();\r
+ }\r
+ srcXML.close();\r
+ cout << "OK" << endl;\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+QList<ExternalResource *> Parameters::searchResourceByName(const QString& name) {\r
+ QList<ExternalResource*> listRes;\r
+ foreach(ExternalResource* s, availableResources) {\r
+ if (s->getName() == name) {\r
+ listRes.append(s);\r
+ }\r
+ }\r
+ return listRes;\r
+}\r
+\r
void Parameters::addAvailableBlock(ReferenceBlock *block) {\r
availableBlocks.append(block);\r
foreach (int id,block->getCategories()) {\r
}\r
\r
writer.writeEndElement(); //</connections>\r
+\r
+ QList<InterfaceItem *> lstIfaceItem;\r
+ // search for modifiers\r
+ foreach(ConnectionItem* item, allConnections) {\r
+ InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();\r
+ AbstractInputModifier* mod = fromIfaceItem->refInter->getInputModifier();\r
+ if (mod != NULL) {\r
+ if (!lstIfaceItem.contains(fromIfaceItem)) lstIfaceItem.append(fromIfaceItem);\r
+ }\r
+ InterfaceItem* toIfaceItem = item->getToInterfaceItem();\r
+ mod = toIfaceItem->refInter->getInputModifier();\r
+ if (mod != NULL) {\r
+ if (!lstIfaceItem.contains(toIfaceItem)) lstIfaceItem.append(toIfaceItem);\r
+ }\r
+ }\r
+ // write input modifiers\r
+ writer.writeStartElement("modifiers");\r
+ foreach(InterfaceItem* item, lstIfaceItem) {\r
+ AbstractInputModifier* mod = item->refInter->getInputModifier();\r
+ if (mod != NULL) {\r
+ writer.writeStartElement("modifier");\r
+ writer.writeAttribute("id", QString::number(item->getId()));\r
+ writer.writeAttribute("type",mod->getTypeStr());\r
+ writer.writeAttribute("params", mod->getParametersStr());\r
+ writer.writeEndElement();\r
+ }\r
+ }\r
+\r
+ writer.writeEndElement(); //</modifiers>\r
writer.writeEndElement(); //</blast_project\r
\r
writer.writeEndDocument();\r
_inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);\r
_inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);\r
_inArrow.lineTo(arrowLineLength,0);\r
- _inArrow.closeSubpath();\r
- inArrow = _inArrow;\r
+ //_inArrow.closeSubpath();\r
+ dataArrowIn = _inArrow;\r
+\r
+ QPainterPath _inArrowC;\r
+ _inArrowC.lineTo(arrowLineLength,0);\r
+ _inArrowC.addEllipse(arrowLineLength,-arrowHeight/2,arrowHeight-1,arrowHeight-1);\r
+ clkrstArrow = _inArrowC;\r
\r
QPainterPath _outArrow;\r
_outArrow.lineTo(arrowLineLength,0);\r
_outArrow.lineTo(arrowLineLength+arrowWidth,0);\r
_outArrow.lineTo(arrowLineLength,arrowHeight/2);\r
_outArrow.lineTo(arrowLineLength,0);\r
- _outArrow.closeSubpath();\r
- outArrow = _outArrow;\r
+ //_outArrow.closeSubpath();\r
+ dataArrowOut = _outArrow;\r
\r
}\r
\r
return NULL;\r
}\r
\r
+BoxItem* Parameters::searchFunctionalBlock(AbstractBlock* block) {\r
+\r
+ return searchFunctionalBlockRecur(block,topScene);\r
+}\r
+\r
+BoxItem* Parameters::searchFunctionalBlockRecur(AbstractBlock* block, GroupScene* scene) {\r
+\r
+ foreach(BoxItem *item, scene->getBoxItems()){\r
+ if(item->getRefBlock() == block) {\r
+ return item;\r
+ }\r
+ }\r
+\r
+ BoxItem* item = NULL;\r
+ foreach(GroupScene *s, scene->getChildrenScene()) {\r
+ item = searchFunctionalBlockRecur(block,s);\r
+ if (item != NULL) return item;\r
+ }\r
+ return NULL;\r
+}\r
+\r
InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {\r
\r
foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){\r
return item;\r
}\r
}\r
+ if (scene->isTopScene()) {\r
+ foreach(SourceItem *block, scene->getSourceItems()){\r
+ foreach(InterfaceItem *item, block->getInterfaces()){\r
+ if(item->getId() == id){\r
+ return item;\r
+ }\r
+ }\r
+ } \r
+ }\r
foreach(BoxItem *block, scene->getBoxItems()){\r
foreach(InterfaceItem *item, block->getInterfaces()){\r
if(item->getId() == id){\r
}\r
return NULL;\r
}\r
+\r
+QString Parameters::normalizeName(const QString &name) {\r
+ QString s = name;\r
+ s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_");\r
+ s.replace(QRegularExpression("[_]+"),"_");\r
+ return s;\r
+}\r