+#include "Parameters.h"\r
+\r
+#include "Dispatcher.h"\r
+#include "BlockLibraryTree.h"\r
+\r
+#include "BlockCategory.h"\r
+\r
+#include "GroupWidget.h"\r
+#include "GroupScene.h"\r
+#include "GroupItem.h"\r
+#include "BoxItem.h"\r
+#include "InterfaceItem.h"\r
+#include "ConnectionItem.h"\r
+\r
+#include "Graph.h"\r
+#include "ReferenceBlock.h"\r
+#include "GroupBlock.h"\r
+#include "FunctionalBlock.h"\r
+#include "ReferenceInterface.h"\r
+#include "GroupInterface.h"\r
+#include "FunctionalInterface.h"\r
+\r
+#include "Exception.h"\r
+#include "BlocksToConfigureWidget.h"\r
+\r
+Parameters::Parameters() {\r
+ categoryTree = NULL;\r
+ arrowWidth = 5;\r
+ arrowHeight = 10;\r
+ arrowLineLength = 10;\r
+\r
+ defaultBlockWidth = 100;\r
+ defaultBlockHeight = 100;\r
+ defaultBlockFont = QFont("Arial");\r
+ defaultBlockFontSize = 12;\r
+\r
+ setArrowPathes();\r
+\r
+ sceneMode = MODE_EDITION; // default mode\r
+ editState = Parameters::EditNoOperation;\r
+\r
+ unsaveModif = false;\r
+ isRstClkShown = false;\r
+\r
+ projectPath = QDir::currentPath();\r
+}\r
+\r
+Parameters::~Parameters() {\r
+ clear();\r
+}\r
+\r
+void Parameters::clear() {\r
+ delete categoryTree;\r
+ QListIterator<ReferenceBlock *> iter(availableBlocks);\r
+ while(iter.hasNext()) {\r
+ ReferenceBlock* item = iter.next();\r
+ delete item;\r
+ }\r
+ availableBlocks.clear();\r
+ refPathes.clear();\r
+}\r
+\r
+Graph* Parameters::createGraph() {\r
+ graph = new Graph();\r
+ return graph;\r
+}\r
+\r
+void Parameters::destroyGraph() {\r
+ delete graph;\r
+}\r
+\r
+GroupBlock* Parameters::addGroupBlock() {\r
+ GroupBlock* parent = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());\r
+ GroupBlock* newOne = graph->createChildBlock(parent);\r
+ return newOne;\r
+}\r
+\r
+FunctionalBlock* Parameters::addFunctionalBlock(int idCategory, int idBlock) {\r
+\r
+ BlockCategory* blockCat = categoryTree->searchCategory(idCategory);\r
+\r
+ if (blockCat == NULL) return NULL;\r
+ GroupBlock* group = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());\r
+ ReferenceBlock* ref = blockCat->getBlock(idBlock);\r
+ if (ref == NULL) return NULL;\r
+\r
+ FunctionalBlock* newOne = graph->addFunctionalBlock(group, ref);\r
+ unsaveModif = true;\r
+\r
+ return newOne;\r
+}\r
+\r
+FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {\r
+\r
+ ReferenceBlock* ref = block->getReference();\r
+ GroupBlock* group = AB_TO_GRP(block->getParent());\r
+\r
+ // adding to the group\r
+ FunctionalBlock* newBlock = new FunctionalBlock(group,ref);\r
+ newBlock->populate();\r
+ group->addBlock(newBlock);\r
+\r
+ return newBlock;\r
+}\r
+\r
+void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {\r
+ // opening configFile\r
+ QFile xmlFile(xmlFileName);\r
+ if (!xmlFile.open(QIODevice::ReadOnly)) {\r
+ if (fileType == Configuration) {\r
+ throw(Exception(CONFIGFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Reference) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Implementation) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Project) {\r
+ throw(Exception(PROJECTFILE_NOACCESS));\r
+ }\r
+ }\r
+\r
+ QFile xsdFile(xsdFileName);\r
+ if (!xsdFile.open(QIODevice::ReadOnly)) {\r
+ xsdFile.close();\r
+ if (fileType == Configuration) {\r
+ throw(Exception(CONFIGFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Reference) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Implementation) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ else if (fileType == Project) {\r
+ throw(Exception(PROJECTFILE_NOACCESS));\r
+ }\r
+ }\r
+\r
+ if(validate(xmlFile,xsdFile) == false) {\r
+ xmlFile.close();\r
+ xsdFile.close();\r
+ if (fileType == Configuration) {\r
+ throw(Exception(CONFIGFILE_CORRUPTED));\r
+ }\r
+ else if (fileType == Reference) {\r
+ throw(Exception(BLOCKFILE_CORRUPTED));\r
+ }\r
+ else if (fileType == Implementation) {\r
+ throw(Exception(IMPLFILE_CORRUPTED));\r
+ }\r
+ else if (fileType == Project) {\r
+ throw(Exception(PROJECTFILE_CORRUPTED));\r
+ }\r
+ }\r
+ xmlFile.close();\r
+ xsdFile.close();\r
+}\r
+\r
+bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {\r
+\r
+ // 2 files are supposed to be already opened\r
+ QXmlSchema schema;\r
+\r
+ if(! schema.load(&fileSchema)){\r
+ cout << "invalid schema" << endl;\r
+ return false;\r
+ }\r
+\r
+ QXmlSchemaValidator validator(schema);\r
+\r
+ if(! validator.validate(&fileXml)){\r
+ cout << "invalid xml" << endl;\r
+ return false;\r
+ }\r
+ return true;\r
+}\r
+\r
+QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {\r
+\r
+ try {\r
+ validateXmlFile(projectFileName,"projectfile.xsd",Project);\r
+ }\r
+ catch(Exception err) {\r
+ throw(err);\r
+ }\r
+\r
+ QFile projectFile(projectFileName);\r
+ QDomDocument doc("projectFile");\r
+\r
+ if(!projectFile.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(PROJECTFILE_NOACCESS));\r
+ }\r
+ if(!doc.setContent(&projectFile)) {\r
+ projectFile.close();\r
+ throw(Exception(PROJECTFILE_CORRUPTED));\r
+ }\r
+ projectFile.close();\r
+\r
+ QDomElement root = doc.documentElement();\r
+\r
+ return root;\r
+}\r
+\r
+void Parameters::loadProject(QDomElement root) {\r
+\r
+#ifdef DEBUG_INCLFUN\r
+\r
+ bool ok = false;\r
+ GroupWidget* groupWidget = NULL;\r
+ GroupItem *groupItem = NULL;\r
+ GroupBlock *groupBlock = NULL;\r
+\r
+ /**********************************************************\r
+ 1 : getting scene and creating associated group widgets\r
+ ***********************************************************/\r
+ QDomNodeList scenesNodes = root.elementsByTagName("scene");\r
+\r
+ for(int i=0; i<scenesNodes.length(); i++) {\r
+ QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
+ int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ if (idUpperScene == -1) {\r
+ dispatcher->createTopScene();\r
+ topScene->setId(idScene);\r
+ groupItem = topScene->getGroupItem();\r
+ groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+ cout << "top group added to scene n°" << idScene << endl;\r
+ }\r
+ else {\r
+ GroupScene* scene = searchSceneById(idUpperScene, topScene);\r
+ GroupWidget* parent = scene->getGroupWindow();\r
+ groupWidget = dispatcher->createChildScene(parent);\r
+ groupItem = groupWidget->getScene()->getGroupItem();\r
+ groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
+ }\r
+ /**********************************************************\r
+ 1.1 : getting the group item\r
+ ***********************************************************/\r
+ QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
+\r
+ int id = groupItemNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString name = groupItemNode.attribute("name","none");\r
+ if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList positionStr = groupItemNode.attribute("position","none").split(",");\r
+ if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posX = positionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posY = positionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");\r
+ if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimX = dimensionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimY = dimensionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ groupItem->setId(id);\r
+ groupItem->setPos(posX,posY);\r
+ groupItem->setDimension(dimX,dimY);\r
+ groupBlock->setName(name);\r
+\r
+ if (idUpperScene != -1) {\r
+ groupWidget->setWindowTitle(groupBlock->getName());\r
+ groupWidget->show();\r
+ }\r
+ cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;\r
+\r
+ QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");\r
+ for(int j=0; j<interfaces.length(); j++){\r
+ QDomElement currentInterfaceNode = interfaces.at(j).toElement();\r
+\r
+ int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString name = currentInterfaceNode.attribute("name","none");\r
+ if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString levelStr = currentInterfaceNode.attribute("level","none");\r
+ int level = AbstractInterface::getIntLevel(levelStr);\r
+ if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString directionStr = currentInterfaceNode.attribute("direction","none");\r
+ int direction = AbstractInterface::getIntDirection(directionStr);\r
+ if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
+ int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
+ if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);\r
+\r
+ InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);\r
+ interfaceItem->setId(id);\r
+\r
+ groupBlock->addInterface(groupInterface);\r
+ groupItem->addInterface(interfaceItem);\r
+ cout << "interface add to " << groupBlock->getName().toStdString() << endl;\r
+ }\r
+ }\r
+\r
+ cout << "groupItems loaded and windows created succefully!" << endl;\r
+\r
+\r
+ for(int i=0; i<scenesNodes.length(); i++){\r
+ QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
+ int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ cout << "SCENE : " << idScene << endl;\r
+ GroupScene *currentScene = searchSceneById(idScene,topScene);\r
+\r
+ if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");\r
+\r
+ for(int j=0; j<functionalBlockNodes.length(); j++){\r
+ QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();\r
+\r
+ int id = currentFBNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString refXml = currentFBNode.attribute("ref_xml","none");\r
+ if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString refMd5 = currentFBNode.attribute("ref_md5","none");\r
+ if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;\r
+\r
+ QString name = currentFBNode.attribute("name","none");\r
+ if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList positionStr = currentFBNode.attribute("position","none").split(",");\r
+ if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posX = positionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posY = positionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");\r
+ if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimX = dimensionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimY = dimensionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ AbstractBlock *reference;\r
+ /*if(refMd5 != "none"){\r
+ cout << "md5" << endl;\r
+ reference = searchBlockByMd5(refMd5);\r
+ }\r
+ else */if(refXml != "none"){\r
+ cout << "xml" << endl;\r
+ reference = searchBlockByXml(refXml);\r
+ }\r
+ else {\r
+ throw(Exception(PROJECTFILE_CORRUPTED));\r
+ }\r
+\r
+ FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);\r
+ functionalBlock->setName(name);\r
+\r
+ ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);\r
+\r
+\r
+ BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);\r
+ blockItem->setPos(posX,posY);\r
+ blockItem->setDimension(dimX,dimY);\r
+ blockItem->setId(id);\r
+ ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
+ currentScene->addItem(blockItem);\r
+ currentScene->addBlockItem(blockItem);\r
+\r
+ QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");\r
+\r
+ for(int i=0; i<blockParamNodes.length(); i++){\r
+ QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();\r
+\r
+ QString name = currentBlockParamNode.attribute("name","none");\r
+ if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString value = currentBlockParamNode.attribute("value","none");\r
+ if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString context = currentBlockParamNode.attribute("context","none");\r
+ if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString type = currentBlockParamNode.attribute("type","none");\r
+ if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+\r
+ BlockParameter *blockParam = new BlockParameter;\r
+ blockParam->setName(name);\r
+ blockParam->setValue(value);\r
+ blockParam->setType(type);\r
+ if(context == "constant") blockParam->setContext(BlockParameter::Constant);\r
+ if(context == "user") blockParam->setContext(BlockParameter::User);\r
+ if(context == "generic") blockParam->setContext(BlockParameter::Generic);\r
+ if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);\r
+ if(context == "port") blockParam->setContext(BlockParameter::Port);\r
+\r
+ functionalBlock->addParameter(blockParam);\r
+ }\r
+\r
+\r
+ QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");\r
+\r
+ for(int i=0; i<interfaceNodes.length(); i++){\r
+\r
+ QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();\r
+\r
+ int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString name = currentInterfaceNode.attribute("name","none");\r
+ if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString refName = currentInterfaceNode.attribute("ref_name","none");\r
+ if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
+ int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
+ if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);\r
+ FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);\r
+ functionalBlock->addInterface(functionalInterface);\r
+ functionalInterface->setName(refName);\r
+\r
+ InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);\r
+ interfaceItem->setId(id);\r
+ interfaceItem->setName(name);\r
+\r
+ blockItem->addInterface(interfaceItem);\r
+\r
+ }\r
+ }\r
+ }\r
+ cout << "functionalBlocks loaded and created succefully!" << endl;\r
+\r
+\r
+ for(int i=0; i<scenesNodes.length(); i++){\r
+ QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
+ int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ GroupScene *currentScene = searchSceneById(idScene, topScene);\r
+ if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");\r
+\r
+ for(int j=0; j<biGroupNodes.length(); j++){\r
+ QDomElement currentBiGroup = biGroupNodes.at(j).toElement();\r
+\r
+ int id = currentBiGroup.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList positionStr = currentBiGroup.attribute("position","none").split(",");\r
+ if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posX = positionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int posY = positionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");\r
+ if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimX = dimensionStr.at(0).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int dimY = dimensionStr.at(1).toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+\r
+ GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);\r
+ if(insideGroup == NULL) cout << "group null" << endl;\r
+ BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);\r
+ blockItem->setChildGroupItem(insideGroup);\r
+ blockItem->setId(id);\r
+ blockItem->setPos(posX,posY);\r
+ blockItem->setDimension(dimX,dimY);\r
+\r
+ ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
+ currentScene->addItem(blockItem);\r
+ currentScene->addBlockItem(blockItem);\r
+\r
+ QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");\r
+\r
+ for(int k=0; k<interfaceNodes.length(); k++){\r
+ QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();\r
+\r
+ int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString refName = currentInterfaceNode.attribute("ref_name","none");\r
+ if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
+ int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
+ if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;\r
+ InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);\r
+ ifaceItem->setId(id);\r
+ blockItem->addInterface(ifaceItem);\r
+ }\r
+ }\r
+ }\r
+ cout << "blockItems \"group\" loaded and created succefully!" << endl;\r
+\r
+\r
+ for(int i=0; i<scenesNodes.length(); i++){\r
+ QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
+\r
+ QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
+\r
+ int id = groupItemNode.attribute("id","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+ int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ BlockItem *currentItem = searchBlockItemById(id,topScene);\r
+ GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);\r
+\r
+ if(currentItem != NULL && upperItem != NULL){\r
+ currentItem->setUpperItem(upperItem);\r
+ }\r
+ }\r
+\r
+ QDomNodeList connectionNodes = root.elementsByTagName("connection");\r
+\r
+ for(int i=0; i<connectionNodes.length(); i++){\r
+ QDomElement currentConnectionNode = connectionNodes.at(i).toElement();\r
+\r
+ int from = currentConnectionNode.attribute("from","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+ int to = currentConnectionNode.attribute("to","none").toInt(&ok);\r
+ if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
+\r
+\r
+ InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);\r
+ InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);\r
+\r
+ if(iface1 != NULL && iface2 != NULL){\r
+ dispatcher->connect(iface1,iface2);\r
+ } else {\r
+ cout << "interfaces not found, connect canceled!" << endl;\r
+ }\r
+ }\r
+\r
+#endif\r
+}\r
+\r
+void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {\r
+\r
+ try {\r
+ validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);\r
+ }\r
+ catch(Exception err) {\r
+ throw(err);\r
+ }\r
+\r
+ bool ok;\r
+ // opening configFile\r
+ QFile configFile(confFile);\r
+ // reading in into QDomDocument\r
+ QDomDocument document("configFile");\r
+\r
+ if (!configFile.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(CONFIGFILE_NOACCESS));\r
+ }\r
+ if (!document.setContent(&configFile)) {\r
+ configFile.close();\r
+ throw(Exception(CONFIGFILE_NOACCESS));\r
+ }\r
+ configFile.close();\r
+\r
+ //Get the root element\r
+ QDomElement config = document.documentElement();\r
+\r
+ QDomElement eltCat = config.firstChildElement("categories");\r
+ try {\r
+ categoryTree = new BlockLibraryTree();\r
+ categoryTree->load(eltCat);\r
+ }\r
+ catch(Exception err) {\r
+ throw(err);\r
+ }\r
+\r
+ QDomElement eltReferences = eltCat.nextSiblingElement("references");\r
+ refLib = eltReferences.attribute("lib_file","none");\r
+ cout << "references lib : " << qPrintable(refLib) << endl;\r
+ int nbPathes;\r
+ QString nbPathesStr;\r
+ nbPathesStr = eltReferences.attribute("nb","none");\r
+ nbPathes = nbPathesStr.toInt(&ok);\r
+ QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");\r
+ if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));\r
+\r
+ for(int i=0;i<listBlockDir.size();i++) {\r
+ QDomNode nodeBlockDir = listBlockDir.at(i);\r
+ QDomElement eltBlockDir = nodeBlockDir.toElement();\r
+ if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ QString path = eltBlockDir.attribute("path","none");\r
+ if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
+ refPathes.append(path);\r
+ cout << "references path : " << qPrintable(path) << endl;\r
+ }\r
+\r
+ QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");\r
+ implLib = eltImpl.attribute("lib_file","none");\r
+ cout << "implementation lib : " << qPrintable(implLib) << endl;\r
+ nbPathesStr = eltImpl.attribute("nb","none");\r
+ nbPathes = nbPathesStr.toInt(&ok);\r
+ QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");\r
+ if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));\r
+\r
+ for(int i=0;i<listImplDir.size();i++) {\r
+ QDomNode nodeImplDir = listImplDir.at(i);\r
+ QDomElement eltImplDir = nodeImplDir.toElement();\r
+ if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ QString path = eltImplDir.attribute("path","none");\r
+ if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
+ implPathes.append(path);\r
+ cout << "impl path : " << qPrintable(path) << endl << endl;\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
+\r
+ QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");\r
+ QString attributeStr = eltBlocks.attribute("width", "none");\r
+ defaultBlockWidth = attributeStr.toInt(&ok);\r
+ if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltBlocks.attribute("height", "none");\r
+ defaultBlockHeight = attributeStr.toInt(&ok);\r
+ if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltBlocks.attribute("font_size", "none");\r
+ defaultBlockFontSize = attributeStr.toFloat(&ok);\r
+ if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltBlocks.attribute("font", "none");\r
+ if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
+ defaultBlockFontName = attributeStr;\r
+ defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);\r
+\r
+ QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");\r
+ attributeStr = eltInterfaces.attribute("width", "none");\r
+ arrowWidth = attributeStr.toInt(&ok);\r
+ if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltInterfaces.attribute("height", "none");\r
+ arrowHeight = attributeStr.toInt(&ok);\r
+ if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltInterfaces.attribute("linelength", "none");\r
+ arrowLineLength = attributeStr.toInt(&ok);\r
+ if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltInterfaces.attribute("font_size", "none");\r
+ defaultIfaceFontSize = attributeStr.toFloat(&ok);\r
+ if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+ attributeStr = eltInterfaces.attribute("font", "none");\r
+ if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
+ defaultIfaceFontName = attributeStr;\r
+ defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);\r
+\r
+ QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");\r
+ attributeStr = eltConnections.attribute("gaplength", "none");\r
+ connGapLength = attributeStr.toInt(&ok);\r
+ if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
+}\r
+\r
+void Parameters::loadReferencesFromXml() throw(Exception) {\r
+ cout << "load references from xml" << endl;\r
+ for(int i=0;i<refPathes.size();i++) {\r
+ cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;\r
+ QDir dir(refPathes.at(i));\r
+ QStringList filter;\r
+ filter << "*.xml";\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
+ QFile blockXML(fileName);\r
+ if (!blockXML.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ QTextStream in(&blockXML);\r
+ QString line = in.readLine();\r
+ line = in.readLine();\r
+\r
+ if (!line.contains("<block>")) {\r
+ blockXML.close();\r
+ continue;\r
+ }\r
+\r
+ blockXML.close();\r
+ try {\r
+ validateXmlFile(fileName,"block.xsd",Reference);\r
+ }\r
+ catch(Exception err) {\r
+ throw(err);\r
+ }\r
+\r
+ // reading in into QDomDocument\r
+ QDomDocument document ("FileXML");\r
+ if (!blockXML.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ if (!document.setContent(&blockXML)) {\r
+ blockXML.close();\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ blockXML.close();\r
+\r
+ QDomElement blockRoot = document.documentElement();\r
+ QString name = blockRoot.tagName();\r
+ if (name == "block") {\r
+\r
+ cout << "xml:" << fileName.toStdString() << endl;\r
+ ReferenceBlock* b = new ReferenceBlock(fileName);\r
+ try {\r
+ b->load(blockRoot);\r
+ b->setHashMd5();\r
+ }\r
+ catch(int err) {\r
+ throw(err);\r
+ }\r
+ cout << "xml:" << b->getXmlFile().toStdString() << endl;\r
+\r
+ availableBlocks.append(b);\r
+ foreach (int id,b->getCategories()) {\r
+ cout << "ajout du bloc dans cat n° : " << id << endl;\r
+ BlockCategory* cat = categoryTree->searchCategory(id);\r
+ cat->blocks.append(b);\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+void Parameters::loadReferencesFromLib() throw(Exception) {\r
+\r
+ cout << "loading references from lib" << endl;\r
+\r
+ // removing blocks from category tree if they exist\r
+ categoryTree->clearBlocks();\r
+ // deleting existings blocks\r
+ ReferenceBlock* b = NULL;\r
+ for(int i=0;i<availableBlocks.size();i++) {\r
+ b = availableBlocks.at(i);\r
+ delete b;\r
+ }\r
+ availableBlocks.clear();\r
+\r
+ QFile libFile(refLib);\r
+ if (!libFile.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ QDataStream in(&libFile);\r
+ quint32 size;\r
+\r
+ in >> size;\r
+\r
+ int nbBlocks;\r
+ in >> nbBlocks;\r
+ for(int i=0;i<nbBlocks;i++) {\r
+ b = new ReferenceBlock("");\r
+ in >> *b;\r
+ availableBlocks.append(b);\r
+ foreach (int id,b->getCategories()) {\r
+ BlockCategory* cat = categoryTree->searchCategory(id);\r
+ cat->blocks.append(b);\r
+ }\r
+ }\r
+ libFile.close();\r
+}\r
+\r
+void Parameters::saveReferencesToLib() throw(Exception) {\r
+\r
+ cout << "saving blocks in " << qPrintable(refLib) << endl;\r
+ QFile libFile(refLib);\r
+ if (!libFile.open(QIODevice::WriteOnly)) {\r
+ throw(Exception(BLOCKFILE_NOACCESS));\r
+ }\r
+ QDataStream out(&libFile);\r
+\r
+ out.setVersion(QDataStream::Qt_5_0);\r
+\r
+ QByteArray blockData;\r
+ QDataStream toWrite(&blockData, QIODevice::WriteOnly);\r
+\r
+ toWrite << availableBlocks.size();\r
+ for(int i=0;i<availableBlocks.size();i++) {\r
+ ReferenceBlock* b = availableBlocks.at(i);\r
+ toWrite << *b;\r
+ }\r
+\r
+ out << blockData;\r
+\r
+ libFile.close();\r
+\r
+}\r
+\r
+void Parameters::loadImplementationsFromXml() throw(Exception) {\r
+\r
+ for(int i=0;i<implPathes.size();i++) {\r
+ cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;\r
+ QDir dir(implPathes.at(i));\r
+ QStringList filter;\r
+ filter << "*.xml";\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
+ cout << "checking " << qPrintable(fileName) << " is an implementation file ...";\r
+ QFile implXML(fileName);\r
+ if (!implXML.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ QTextStream in(&implXML);\r
+ QString line = in.readLine();\r
+ line = in.readLine();\r
+\r
+ if (!line.contains("<block_impl")) {\r
+ implXML.close();\r
+ continue;\r
+ }\r
+\r
+ implXML.close();\r
+ cout << "OK" << endl;\r
+ cout << "reading " << qPrintable(fileName) << " content ...";\r
+ /*\r
+ try {\r
+ validateXmlFile(fileName,"block.xsd",Implementation);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ */\r
+ // reading in into QDomDocument\r
+ QDomDocument document ("FileXML");\r
+ if (!implXML.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ cout << "OK" << endl;\r
+ cout << "convert " << qPrintable(fileName) << " content into document...";\r
+ if (!document.setContent(&implXML)) {\r
+ implXML.close();\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ implXML.close();\r
+\r
+ QDomElement implRoot = document.documentElement();\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
+ availableImplementations.append(impl);\r
+\r
+ ReferenceBlock* ref = NULL;\r
+ if (! refMd5.isEmpty()) {\r
+ ref = searchBlockByMd5(refMd5);\r
+ }\r
+ if (ref == NULL) {\r
+ ref = searchBlockByXml(refXml);\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
+ cout << "OK" << endl;\r
+ }\r
+ }\r
+}\r
+\r
+void Parameters::loadImplementationsFromLib() throw(Exception) {\r
+\r
+ cout << "loading implementations from lib" << endl;\r
+\r
+ BlockImplementation* impl = NULL;\r
+ ReferenceBlock* ref = NULL;\r
+ for(int i=0;i<availableImplementations.size();i++) {\r
+ impl = availableImplementations.at(i);\r
+ delete impl;\r
+ }\r
+ availableImplementations.clear();\r
+\r
+ QFile libFile(implLib);\r
+ if (!libFile.open(QIODevice::ReadOnly)) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ QDataStream in(&libFile);\r
+ quint32 size;\r
+\r
+ in >> size;\r
+\r
+ int nbImpls;\r
+ in >> nbImpls;\r
+ for(int i=0;i<nbImpls;i++) {\r
+ impl = new BlockImplementation("");\r
+ in >> *impl;\r
+ availableImplementations.append(impl);\r
+ QString refMd5 = impl->getReferenceMd5();\r
+ QString refXml = impl->getReferenceXml();\r
+ ref = NULL;\r
+ if (! refMd5.isEmpty()) {\r
+ ref = searchBlockByMd5(refMd5);\r
+ }\r
+ if (ref == NULL) {\r
+ ref = searchBlockByXml(refXml);\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
+ }\r
+ libFile.close();\r
+}\r
+\r
+void Parameters::saveImplementationsToLib() throw(Exception) {\r
+\r
+ cout << "saving implementations in " << qPrintable(implLib) << endl;\r
+ QFile libFile(implLib);\r
+ if (!libFile.open(QIODevice::WriteOnly)) {\r
+ throw(Exception(IMPLFILE_NOACCESS));\r
+ }\r
+ QDataStream out(&libFile);\r
+\r
+ out.setVersion(QDataStream::Qt_5_0);\r
+\r
+ QByteArray blockData;\r
+ QDataStream toWrite(&blockData, QIODevice::WriteOnly);\r
+\r
+ toWrite << availableImplementations.size();\r
+ for(int i=0;i<availableImplementations.size();i++) {\r
+ BlockImplementation* impl = availableImplementations.at(i);\r
+ toWrite << *impl;\r
+ }\r
+\r
+ out << blockData;\r
+\r
+ libFile.close();\r
+\r
+}\r
+void Parameters::addAvailableBlock(ReferenceBlock *block) {\r
+ availableBlocks.append(block);\r
+ foreach (int id,block->getCategories()) {\r
+ cout << "ajout du bloc dans cat n° : " << id << endl;\r
+ BlockCategory* cat = categoryTree->searchCategory(id);\r
+ cat->blocks.append(block);\r
+ }\r
+}\r
+\r
+void Parameters::parametersValidation() {\r
+ QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();\r
+\r
+ if(!blocksToConfigure.isEmpty()){\r
+ BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);\r
+ widget->show();\r
+ }\r
+}\r
+\r
+void Parameters::connectionsValidation() {\r
+\r
+#ifdef DEBUG_INCLFUN\r
+\r
+ QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;\r
+ QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;\r
+\r
+ foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){\r
+ foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){\r
+\r
+ inter->setWidth(connectedInter->getWidth());\r
+ interfaceToValidate->push(connectedInter);\r
+ }\r
+ }\r
+\r
+\r
+ try{\r
+ while(!interfaceToValidate->isEmpty()){\r
+ interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);\r
+ }\r
+ }\r
+ catch(Exception e){\r
+ cerr << e.getMessage().toStdString() << endl;\r
+ }\r
+#endif\r
+}\r
+\r
+QList<AbstractBlock *> Parameters::getBlocksToConfigure() {\r
+\r
+#ifdef DEBUG_INCLFUN\r
+\r
+ QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;\r
+ QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;\r
+\r
+ foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){\r
+ foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){\r
+ if(!checkedBlocks->contains(connectedInter->getOwner())){\r
+ connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);\r
+ }\r
+ }\r
+ }\r
+ return *blocksToConfigure;\r
+#endif\r
+}\r
+\r
+\r
+void Parameters::updateToolbar() {\r
+ int nb = currentScene->getBlockItems().length();\r
+ for(int i = 0; i<nb; i++){\r
+ if(currentScene->getBlockItems().at(i)->isSelected()){\r
+ currentScene->getGroupWindow()->enableGroupButton(true);\r
+ return;\r
+ }\r
+ }\r
+ currentScene->getGroupWindow()->enableGroupButton(false);\r
+}\r
+\r
+\r
+void Parameters::updateIds() {\r
+\r
+ /* a in-width cross of the graph must be done so that ids of GroupItem\r
+ are in the correct ordre when saving/loading a project\r
+ */\r
+ int countItem = 1;\r
+ int countIface = 1;\r
+ QList<GroupScene *> fifo;\r
+ fifo.append(topScene);\r
+ while (!fifo.isEmpty()) {\r
+ GroupScene* scene = fifo.takeFirst();\r
+ countItem = scene->setItemsId(countItem);\r
+ countIface = scene->setInterfacesId(countIface);\r
+ foreach(GroupScene* s, scene->getChildrenScene()) {\r
+ fifo.append(s);\r
+ }\r
+ }\r
+}\r
+\r
+\r
+ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {\r
+ foreach(ReferenceBlock *block, availableBlocks){\r
+ if(block->getXmlFile().contains(xmlName))\r
+ return block;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {\r
+ foreach(ReferenceBlock *block, availableBlocks){\r
+ if(block->getHashMd5() == sumMd5)\r
+ return block;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+void Parameters::save(QString confFile) {\r
+\r
+//#ifdef DEBUG_INCLFUN\r
+\r
+ updateIds();\r
+ QList<ConnectionItem*> allConnections;\r
+ QFile file(confFile);\r
+ if(file.open(QIODevice::WriteOnly)){\r
+\r
+ QXmlStreamWriter writer(&file);\r
+\r
+ writer.setAutoFormatting(true);\r
+ writer.writeStartDocument();\r
+\r
+ writer.writeStartElement("blast_project");\r
+ writer.writeStartElement("scenes");\r
+\r
+ writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));\r
+\r
+ // cross the scene level by level using a FIFO\r
+ QList<GroupScene*> fifoScene;\r
+ fifoScene.append(topScene);\r
+ foreach(ConnectionItem* item, topScene->getConnectionItems()) {\r
+ allConnections.append(item);\r
+ }\r
+\r
+ GroupScene *scene;\r
+ while (!fifoScene.isEmpty()) {\r
+ scene = fifoScene.takeFirst();\r
+ scene->save(writer);\r
+ foreach(GroupScene* s, scene->getChildrenScene()) {\r
+ fifoScene.append(s);\r
+ }\r
+ foreach(ConnectionItem* item, topScene->getConnectionItems()) {\r
+ allConnections.append(item);\r
+ }\r
+ }\r
+\r
+\r
+ writer.writeStartElement("connections");\r
+ foreach(ConnectionItem* item, allConnections) {\r
+\r
+ writer.writeStartElement("connection");\r
+\r
+ writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));\r
+ writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));\r
+\r
+ writer.writeEndElement();\r
+ }\r
+\r
+ writer.writeEndElement(); //</connections>\r
+ writer.writeEndElement(); //</blast_project\r
+\r
+ writer.writeEndDocument();\r
+\r
+ file.close();\r
+ unsaveModif = false;\r
+ }\r
+//#endif\r
+}\r
+\r
+void Parameters::setArrowPathes() {\r
+ QPainterPath _inArrow;\r
+ _inArrow.lineTo(arrowLineLength,0);\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
+\r
+ QPainterPath _outArrow;\r
+ _outArrow.lineTo(arrowLineLength,0);\r
+ _outArrow.lineTo(arrowLineLength,-arrowHeight/2);\r
+ _outArrow.lineTo(arrowLineLength+arrowWidth,0);\r
+ _outArrow.lineTo(arrowLineLength,arrowHeight/2);\r
+ _outArrow.lineTo(arrowLineLength,0);\r
+ _outArrow.closeSubpath();\r
+ outArrow = _outArrow;\r
+\r
+}\r
+\r
+GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {\r
+\r
+ if (scene->getId() == id) return scene;\r
+ GroupScene* sc = NULL;\r
+\r
+ foreach(GroupScene *s, scene->getChildrenScene()) {\r
+ sc = searchSceneById(id,s);\r
+ if (sc != NULL) return sc;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {\r
+\r
+ if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();\r
+\r
+ GroupItem* item = NULL;\r
+ foreach(GroupScene *s, scene->getChildrenScene()) {\r
+ item = searchGroupItemById(id,s);\r
+ if (item != NULL) return item;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {\r
+\r
+ foreach(BoxItem *item, scene->getBlockItems()){\r
+ if(item->getId() == id){\r
+ return item;\r
+ }\r
+ }\r
+\r
+ BoxItem* item = NULL;\r
+ foreach(GroupScene *s, scene->getChildrenScene()) {\r
+ item = searchBlockItemById(id,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
+ if(item->getId() == id){\r
+ return item;\r
+ }\r
+ }\r
+ foreach(BoxItem *block, scene->getBlockItems()){\r
+ foreach(InterfaceItem *item, block->getInterfaces()){\r
+ if(item->getId() == id){\r
+ return item;\r
+ }\r
+ }\r
+ }\r
+ InterfaceItem* item = NULL;\r
+ foreach(GroupScene *s, scene->getChildrenScene()) {\r
+ item = searchInterfaceItemById(id,s);\r
+ if (item != NULL) return item;\r
+ }\r
+ return NULL;\r
+}\r