]> AND Private Git Repository - blast.git/blob - Parameters.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
adding save to gitignore
[blast.git] / Parameters.cpp
1 #include "Parameters.h"\r
2 \r
3 #include "Dispatcher.h"\r
4 #include "BlockLibraryTree.h"\r
5 \r
6 #include "BlockCategory.h"\r
7 \r
8 #include "GroupWidget.h"\r
9 #include "GroupScene.h"\r
10 #include "GroupItem.h"\r
11 #include "BoxItem.h"\r
12 #include "InterfaceItem.h"\r
13 #include "ConnectionItem.h"\r
14 \r
15 #include "Graph.h"\r
16 #include "ReferenceBlock.h"\r
17 #include "GroupBlock.h"\r
18 #include "FunctionalBlock.h"\r
19 #include "ReferenceInterface.h"\r
20 #include "GroupInterface.h"\r
21 #include "FunctionalInterface.h"\r
22 \r
23 #include "Exception.h"\r
24 #include "BlocksToConfigureWidget.h"\r
25 \r
26 Parameters::Parameters() {\r
27   categoryTree = NULL;\r
28   arrowWidth = 5;\r
29   arrowHeight = 10;\r
30   arrowLineLength = 10;\r
31 \r
32   defaultBlockWidth = 100;\r
33   defaultBlockHeight = 100;\r
34   defaultBlockFont = QFont("Arial");\r
35   defaultBlockFontSize = 12;\r
36 \r
37   setArrowPathes();\r
38 \r
39   sceneMode = MODE_EDITION; // default mode\r
40   editState = Parameters::EditNoOperation;\r
41 \r
42   unsaveModif = false;\r
43   isRstClkShown = false;\r
44 \r
45   projectPath = QDir::currentPath();\r
46 }\r
47 \r
48 Parameters::~Parameters() {\r
49   clear();\r
50 }\r
51 \r
52 void Parameters::clear() {\r
53   delete categoryTree;\r
54   QListIterator<ReferenceBlock *> iter(availableBlocks);\r
55   while(iter.hasNext()) {\r
56     ReferenceBlock* item = iter.next();\r
57     delete item;\r
58   }\r
59   availableBlocks.clear();\r
60   refPathes.clear();\r
61 }\r
62 \r
63 Graph* Parameters::createGraph() {\r
64   graph = new Graph();\r
65   return graph;\r
66 }\r
67 \r
68 void Parameters::destroyGraph() {\r
69   delete graph;\r
70 }\r
71 \r
72 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {\r
73 \r
74   BlockCategory* blockCat = categoryTree->searchCategory(idCategory);\r
75 \r
76   if (blockCat == NULL) return NULL;\r
77   ReferenceBlock* ref = blockCat->getBlock(idBlock);\r
78   return ref;\r
79 }\r
80 \r
81 \r
82 FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {\r
83 \r
84   ReferenceBlock* ref = block->getReference();\r
85   GroupBlock* group = AB_TO_GRP(block->getParent());\r
86 \r
87   // adding to the graph\r
88   FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref);\r
89   return newBlock;\r
90 }\r
91 \r
92 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {\r
93   // opening configFile\r
94   QFile xmlFile(xmlFileName);\r
95   if (!xmlFile.open(QIODevice::ReadOnly)) {\r
96     if (fileType == Configuration) {\r
97       throw(Exception(CONFIGFILE_NOACCESS));\r
98     }\r
99     else if (fileType == Reference) {\r
100       throw(Exception(BLOCKFILE_NOACCESS));\r
101     }\r
102     else if (fileType == Implementation) {\r
103       throw(Exception(IMPLFILE_NOACCESS));\r
104     }\r
105     else if (fileType == Project) {\r
106       throw(Exception(PROJECTFILE_NOACCESS));\r
107     }\r
108   }\r
109 \r
110   QFile xsdFile(xsdFileName);\r
111   if (!xsdFile.open(QIODevice::ReadOnly)) {\r
112     xsdFile.close();\r
113     if (fileType == Configuration) {\r
114       throw(Exception(CONFIGFILE_NOACCESS));\r
115     }\r
116     else if (fileType == Reference) {\r
117       throw(Exception(BLOCKFILE_NOACCESS));\r
118     }\r
119     else if (fileType == Implementation) {\r
120       throw(Exception(IMPLFILE_NOACCESS));\r
121     }\r
122     else if (fileType == Project) {\r
123       throw(Exception(PROJECTFILE_NOACCESS));\r
124     }\r
125   }\r
126 \r
127   if(validate(xmlFile,xsdFile) == false) {\r
128     xmlFile.close();\r
129     xsdFile.close();\r
130     if (fileType == Configuration) {\r
131       throw(Exception(CONFIGFILE_CORRUPTED));\r
132     }\r
133     else if (fileType == Reference) {\r
134       throw(Exception(BLOCKFILE_CORRUPTED));\r
135     }\r
136     else if (fileType == Implementation) {\r
137       throw(Exception(IMPLFILE_CORRUPTED));\r
138     }\r
139     else if (fileType == Project) {\r
140       throw(Exception(PROJECTFILE_CORRUPTED));\r
141     }\r
142   }\r
143   xmlFile.close();\r
144   xsdFile.close();\r
145 }\r
146 \r
147 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {\r
148 \r
149   // 2 files are supposed to be already opened\r
150   QXmlSchema schema;\r
151 \r
152   if(! schema.load(&fileSchema)){\r
153     cout << "invalid schema" << endl;\r
154     return false;\r
155   }\r
156 \r
157   QXmlSchemaValidator validator(schema);\r
158 \r
159   if(! validator.validate(&fileXml)){\r
160     cout << "invalid xml" << endl;\r
161     return false;\r
162   }\r
163   return true;\r
164 }\r
165 \r
166 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {\r
167 \r
168   try {\r
169     validateXmlFile(projectFileName,"projectfile.xsd",Project);\r
170   }\r
171   catch(Exception err) {\r
172     throw(err);\r
173   }\r
174 \r
175   QFile projectFile(projectFileName);\r
176   QDomDocument doc("projectFile");\r
177 \r
178   if(!projectFile.open(QIODevice::ReadOnly)) {\r
179     throw(Exception(PROJECTFILE_NOACCESS));\r
180   }\r
181   if(!doc.setContent(&projectFile)) {\r
182     projectFile.close();\r
183     throw(Exception(PROJECTFILE_CORRUPTED));\r
184   }\r
185   projectFile.close();\r
186 \r
187   QDomElement root = doc.documentElement();\r
188 \r
189   return root;\r
190 }\r
191 \r
192 void Parameters::loadProject(QDomElement root) {\r
193 \r
194 #ifdef DEBUG_INCLFUN\r
195 \r
196   bool ok = false;\r
197   GroupWidget* groupWidget = NULL;\r
198   GroupItem *groupItem = NULL;\r
199   GroupBlock *groupBlock = NULL;\r
200 \r
201   /**********************************************************\r
202    1 : getting scene and creating associated group widgets\r
203   ***********************************************************/\r
204   QDomNodeList scenesNodes = root.elementsByTagName("scene");\r
205 \r
206   for(int i=0; i<scenesNodes.length(); i++) {\r
207     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
208     int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
209     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
210     int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);\r
211     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
212 \r
213     if (idUpperScene == -1) {\r
214       dispatcher->createTopScene();\r
215       topScene->setId(idScene);\r
216       groupItem = topScene->getGroupItem();\r
217       groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
218       cout << "top group added to scene n°" << idScene << endl;\r
219     }\r
220     else {\r
221       GroupScene* scene = searchSceneById(idUpperScene, topScene);\r
222       GroupWidget* parent = scene->getGroupWindow();\r
223       groupWidget = dispatcher->createChildScene(parent);\r
224       groupItem = groupWidget->getScene()->getGroupItem();\r
225       groupBlock = AB_TO_GRP(groupItem->getRefBlock());\r
226     }\r
227     /**********************************************************\r
228      1.1 : getting the group item\r
229     ***********************************************************/\r
230     QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
231 \r
232     int id = groupItemNode.attribute("id","none").toInt(&ok);\r
233     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
234 \r
235     QString name = groupItemNode.attribute("name","none");\r
236     if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
237 \r
238     QStringList positionStr = groupItemNode.attribute("position","none").split(",");\r
239     if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
240     int posX = positionStr.at(0).toInt(&ok);\r
241     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
242     int posY = positionStr.at(1).toInt(&ok);\r
243     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
244 \r
245     QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");\r
246     if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
247     int dimX = dimensionStr.at(0).toInt(&ok);\r
248     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
249     int dimY = dimensionStr.at(1).toInt(&ok);\r
250     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
251 \r
252     groupItem->setId(id);\r
253     groupItem->setPos(posX,posY);\r
254     groupItem->setDimension(dimX,dimY);\r
255     groupBlock->setName(name);\r
256 \r
257     if (idUpperScene != -1) {\r
258       groupWidget->setWindowTitle(groupBlock->getName());\r
259       groupWidget->show();\r
260     }\r
261     cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;\r
262 \r
263     QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");\r
264     for(int j=0; j<interfaces.length(); j++){\r
265       QDomElement currentInterfaceNode = interfaces.at(j).toElement();\r
266 \r
267       int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
268       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
269 \r
270       QString name = currentInterfaceNode.attribute("name","none");\r
271       if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
272 \r
273       QString levelStr = currentInterfaceNode.attribute("level","none");\r
274       int level = AbstractInterface::getIntLevel(levelStr);\r
275       if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
276 \r
277       QString directionStr = currentInterfaceNode.attribute("direction","none");\r
278       int direction = AbstractInterface::getIntDirection(directionStr);\r
279       if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
280 \r
281       QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
282       int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
283       if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
284 \r
285       double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
286       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
287 \r
288       GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);\r
289 \r
290       InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);\r
291       interfaceItem->setId(id);\r
292 \r
293       groupBlock->addInterface(groupInterface);\r
294       groupItem->addInterface(interfaceItem);\r
295       cout << "interface add to " << groupBlock->getName().toStdString() << endl;\r
296     }\r
297   }\r
298 \r
299   cout << "groupItems loaded and windows created succefully!" << endl;\r
300 \r
301 \r
302   for(int i=0; i<scenesNodes.length(); i++){\r
303     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
304     int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
305     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
306     cout << "SCENE : " << idScene << endl;\r
307     GroupScene *currentScene = searchSceneById(idScene,topScene);\r
308 \r
309     if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
310 \r
311     QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");\r
312 \r
313     for(int j=0; j<functionalBlockNodes.length(); j++){\r
314       QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();\r
315 \r
316       int id = currentFBNode.attribute("id","none").toInt(&ok);\r
317       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
318 \r
319       QString refXml = currentFBNode.attribute("ref_xml","none");\r
320       if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
321 \r
322       QString refMd5 = currentFBNode.attribute("ref_md5","none");\r
323       if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
324 \r
325       cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;\r
326 \r
327       QString name = currentFBNode.attribute("name","none");\r
328       if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
329 \r
330       QStringList positionStr = currentFBNode.attribute("position","none").split(",");\r
331       if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
332       int posX = positionStr.at(0).toInt(&ok);\r
333       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
334       int posY = positionStr.at(1).toInt(&ok);\r
335       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
336 \r
337       QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");\r
338       if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
339       int dimX = dimensionStr.at(0).toInt(&ok);\r
340       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
341       int dimY = dimensionStr.at(1).toInt(&ok);\r
342       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
343 \r
344       AbstractBlock *reference;\r
345       /*if(refMd5 != "none"){\r
346         cout << "md5" << endl;\r
347         reference = searchBlockByMd5(refMd5);\r
348       }\r
349       else */if(refXml != "none"){\r
350         cout << "xml" << endl;\r
351         reference = searchBlockByXml(refXml);\r
352       }\r
353       else {\r
354         throw(Exception(PROJECTFILE_CORRUPTED));\r
355       }\r
356 \r
357       FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);\r
358       functionalBlock->setName(name);\r
359 \r
360       ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);\r
361 \r
362 \r
363       BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);\r
364       blockItem->setPos(posX,posY);\r
365       blockItem->setDimension(dimX,dimY);\r
366       blockItem->setId(id);\r
367       ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
368       currentScene->addItem(blockItem);\r
369       currentScene->addBlockItem(blockItem);\r
370 \r
371       QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");\r
372 \r
373       for(int i=0; i<blockParamNodes.length(); i++){\r
374         QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();\r
375 \r
376         QString name = currentBlockParamNode.attribute("name","none");\r
377         if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
378 \r
379         QString value = currentBlockParamNode.attribute("value","none");\r
380         if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
381 \r
382         QString context = currentBlockParamNode.attribute("context","none");\r
383         if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
384 \r
385         QString type = currentBlockParamNode.attribute("type","none");\r
386         if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
387 \r
388 \r
389         BlockParameter *blockParam = new BlockParameter;\r
390         blockParam->setName(name);\r
391         blockParam->setValue(value);\r
392         blockParam->setType(type);\r
393         if(context == "constant") blockParam->setContext(BlockParameter::Constant);\r
394         if(context == "user") blockParam->setContext(BlockParameter::User);\r
395         if(context == "generic") blockParam->setContext(BlockParameter::Generic);\r
396         if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);\r
397         if(context == "port") blockParam->setContext(BlockParameter::Port);\r
398 \r
399         functionalBlock->addParameter(blockParam);\r
400       }\r
401 \r
402 \r
403       QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");\r
404 \r
405       for(int i=0; i<interfaceNodes.length(); i++){\r
406 \r
407         QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();\r
408 \r
409         int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
410         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
411 \r
412         QString name = currentInterfaceNode.attribute("name","none");\r
413         if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
414 \r
415         QString refName = currentInterfaceNode.attribute("ref_name","none");\r
416         if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
417 \r
418         QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
419         int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
420         if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
421 \r
422         double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
423         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
424 \r
425         ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);\r
426         FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);\r
427         functionalBlock->addInterface(functionalInterface);\r
428         functionalInterface->setName(refName);\r
429 \r
430         InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);\r
431         interfaceItem->setId(id);\r
432         interfaceItem->setName(name);\r
433 \r
434         blockItem->addInterface(interfaceItem);\r
435 \r
436       }\r
437     }\r
438   }\r
439   cout << "functionalBlocks loaded and created succefully!" << endl;\r
440 \r
441 \r
442   for(int i=0; i<scenesNodes.length(); i++){\r
443     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
444     int idScene = currentSceneNode.attribute("id","none").toInt(&ok);\r
445     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
446     GroupScene *currentScene = searchSceneById(idScene, topScene);\r
447     if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));\r
448 \r
449     QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");\r
450 \r
451     for(int j=0; j<biGroupNodes.length(); j++){\r
452       QDomElement currentBiGroup = biGroupNodes.at(j).toElement();\r
453 \r
454       int id = currentBiGroup.attribute("id","none").toInt(&ok);\r
455       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
456 \r
457       int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);\r
458       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
459 \r
460       QStringList positionStr = currentBiGroup.attribute("position","none").split(",");\r
461       if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
462       int posX = positionStr.at(0).toInt(&ok);\r
463       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
464       int posY = positionStr.at(1).toInt(&ok);\r
465       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
466 \r
467       QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");\r
468       if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));\r
469       int dimX = dimensionStr.at(0).toInt(&ok);\r
470       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
471       int dimY = dimensionStr.at(1).toInt(&ok);\r
472       if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
473 \r
474 \r
475       GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);\r
476       if(insideGroup == NULL) cout << "group null" << endl;\r
477       BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);\r
478       blockItem->setChildGroupItem(insideGroup);\r
479       blockItem->setId(id);\r
480       blockItem->setPos(posX,posY);\r
481       blockItem->setDimension(dimX,dimY);\r
482 \r
483       ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);\r
484       currentScene->addItem(blockItem);\r
485       currentScene->addBlockItem(blockItem);\r
486 \r
487       QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");\r
488 \r
489       for(int k=0; k<interfaceNodes.length(); k++){\r
490         QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();\r
491 \r
492         int id = currentInterfaceNode.attribute("id","none").toInt(&ok);\r
493         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
494 \r
495         QString refName = currentInterfaceNode.attribute("ref_name","none");\r
496         if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));\r
497 \r
498         QString orientationStr = currentInterfaceNode.attribute("orientation","none");\r
499         int orientation = InterfaceItem::getIntOrientation(orientationStr);\r
500         if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));\r
501 \r
502         double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);\r
503         if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
504 \r
505         GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;\r
506         InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);\r
507         ifaceItem->setId(id);\r
508         blockItem->addInterface(ifaceItem);\r
509       }\r
510     }\r
511   }\r
512   cout << "blockItems \"group\" loaded and created succefully!" << endl;\r
513 \r
514 \r
515   for(int i=0; i<scenesNodes.length(); i++){\r
516     QDomElement currentSceneNode = scenesNodes.at(i).toElement();\r
517 \r
518     QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");\r
519 \r
520     int id = groupItemNode.attribute("id","none").toInt(&ok);\r
521     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
522     int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);\r
523     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
524 \r
525     BlockItem *currentItem = searchBlockItemById(id,topScene);\r
526     GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);\r
527 \r
528     if(currentItem != NULL && upperItem != NULL){\r
529       currentItem->setUpperItem(upperItem);\r
530     }\r
531   }\r
532 \r
533   QDomNodeList connectionNodes = root.elementsByTagName("connection");\r
534 \r
535   for(int i=0; i<connectionNodes.length(); i++){\r
536     QDomElement currentConnectionNode = connectionNodes.at(i).toElement();\r
537 \r
538     int from = currentConnectionNode.attribute("from","none").toInt(&ok);\r
539     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
540 \r
541     int to = currentConnectionNode.attribute("to","none").toInt(&ok);\r
542     if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));\r
543 \r
544 \r
545     InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);\r
546     InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);\r
547 \r
548     if(iface1 != NULL && iface2 != NULL){\r
549       dispatcher->connect(iface1,iface2);\r
550     } else {\r
551       cout << "interfaces not found, connect canceled!" << endl;\r
552     }\r
553   }\r
554 \r
555 #endif\r
556 }\r
557 \r
558 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {\r
559 \r
560   try {\r
561     validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);\r
562   }\r
563   catch(Exception err) {\r
564     throw(err);\r
565   }\r
566 \r
567   bool ok;\r
568   // opening configFile\r
569   QFile configFile(confFile);\r
570   // reading in into QDomDocument\r
571   QDomDocument document("configFile");\r
572 \r
573   if (!configFile.open(QIODevice::ReadOnly)) {\r
574     throw(Exception(CONFIGFILE_NOACCESS));\r
575   }\r
576   if (!document.setContent(&configFile)) {\r
577     configFile.close();\r
578     throw(Exception(CONFIGFILE_NOACCESS));\r
579   }\r
580   configFile.close();\r
581 \r
582   //Get the root element\r
583   QDomElement config = document.documentElement();\r
584 \r
585   QDomElement eltCat = config.firstChildElement("categories");\r
586   try {\r
587     categoryTree = new BlockLibraryTree();\r
588     categoryTree->load(eltCat);\r
589   }\r
590   catch(Exception err) {\r
591     throw(err);\r
592   }\r
593 \r
594   QDomElement eltReferences = eltCat.nextSiblingElement("references");\r
595   refLib = eltReferences.attribute("lib_file","none");\r
596   cout << "references lib : " << qPrintable(refLib)  << endl;\r
597   int nbPathes;\r
598   QString nbPathesStr;\r
599   nbPathesStr = eltReferences.attribute("nb","none");\r
600   nbPathes = nbPathesStr.toInt(&ok);\r
601   QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");\r
602   if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));\r
603 \r
604   for(int i=0;i<listBlockDir.size();i++) {\r
605     QDomNode nodeBlockDir = listBlockDir.at(i);\r
606     QDomElement eltBlockDir = nodeBlockDir.toElement();\r
607     if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));\r
608     QString path = eltBlockDir.attribute("path","none");\r
609     if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
610     refPathes.append(path);\r
611     cout << "references path : " << qPrintable(path) << endl;\r
612   }\r
613 \r
614   QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");\r
615   implLib = eltImpl.attribute("lib_file","none");\r
616   cout << "implementation lib : " << qPrintable(implLib)  << endl;\r
617   nbPathesStr = eltImpl.attribute("nb","none");\r
618   nbPathes = nbPathesStr.toInt(&ok);\r
619   QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");\r
620   if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));\r
621 \r
622   for(int i=0;i<listImplDir.size();i++) {\r
623     QDomNode nodeImplDir = listImplDir.at(i);\r
624     QDomElement eltImplDir = nodeImplDir.toElement();\r
625     if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));\r
626     QString path = eltImplDir.attribute("path","none");\r
627     if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
628     implPathes.append(path);\r
629     cout << "impl path : " << qPrintable(path) << endl << endl;\r
630   }\r
631   // getting elt = the element <defaults>\r
632   // for each child element, initialize the associated attributes of Parameters\r
633 \r
634   QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");\r
635 \r
636   QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");\r
637   QString attributeStr = eltBlocks.attribute("width", "none");\r
638   defaultBlockWidth = attributeStr.toInt(&ok);\r
639   if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
640   attributeStr = eltBlocks.attribute("height", "none");\r
641   defaultBlockHeight = attributeStr.toInt(&ok);\r
642   if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
643   attributeStr = eltBlocks.attribute("font_size", "none");\r
644   defaultBlockFontSize = attributeStr.toFloat(&ok);\r
645   if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
646   attributeStr = eltBlocks.attribute("font", "none");\r
647   if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
648   defaultBlockFontName = attributeStr;\r
649   defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);\r
650 \r
651   QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");\r
652   attributeStr = eltInterfaces.attribute("width", "none");\r
653   arrowWidth = attributeStr.toInt(&ok);\r
654   if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
655   attributeStr = eltInterfaces.attribute("height", "none");\r
656   arrowHeight = attributeStr.toInt(&ok);\r
657   if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
658   attributeStr = eltInterfaces.attribute("linelength", "none");\r
659   arrowLineLength = attributeStr.toInt(&ok);\r
660   if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
661   attributeStr = eltInterfaces.attribute("font_size", "none");\r
662   defaultIfaceFontSize = attributeStr.toFloat(&ok);\r
663   if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
664   attributeStr = eltInterfaces.attribute("font", "none");\r
665   if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));\r
666   defaultIfaceFontName = attributeStr;\r
667   defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);\r
668 \r
669   QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");\r
670   attributeStr = eltConnections.attribute("gaplength", "none");\r
671   connGapLength = attributeStr.toInt(&ok);\r
672   if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));\r
673 }\r
674 \r
675 void Parameters::loadReferencesFromXml() throw(Exception) {\r
676   cout << "load references from xml" << endl;\r
677   for(int i=0;i<refPathes.size();i++) {\r
678     cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;\r
679     QDir dir(refPathes.at(i));\r
680     QStringList filter;\r
681     filter << "*.xml";\r
682     dir.setNameFilters(filter);\r
683     QStringList list = dir.entryList();\r
684     for(int j=0;j<list.size();j++) {\r
685       QString fileName = dir.absolutePath();\r
686       fileName.append("/"+list.at(j));\r
687 \r
688       QFile blockXML(fileName);\r
689       if (!blockXML.open(QIODevice::ReadOnly)) {\r
690         throw(Exception(BLOCKFILE_NOACCESS));\r
691       }\r
692       QTextStream in(&blockXML);\r
693       QString line = in.readLine();\r
694       line = in.readLine();\r
695 \r
696       if (!line.contains("<block>")) {\r
697         blockXML.close();\r
698         continue;\r
699       }\r
700 \r
701       blockXML.close();\r
702       try {\r
703         validateXmlFile(fileName,"block.xsd",Reference);\r
704       }\r
705       catch(Exception err) {\r
706         throw(err);\r
707       }\r
708 \r
709       // reading in into QDomDocument\r
710       QDomDocument document ("FileXML");\r
711       if (!blockXML.open(QIODevice::ReadOnly)) {\r
712         throw(Exception(BLOCKFILE_NOACCESS));\r
713       }\r
714       if (!document.setContent(&blockXML)) {\r
715         blockXML.close();\r
716         throw(Exception(BLOCKFILE_NOACCESS));\r
717       }\r
718       blockXML.close();\r
719 \r
720       QDomElement blockRoot = document.documentElement();\r
721       QString name = blockRoot.tagName();\r
722       if (name == "block") {\r
723 \r
724         cout << "xml:" << fileName.toStdString() << endl;\r
725         ReferenceBlock* b = new ReferenceBlock(fileName);\r
726         try {\r
727           b->load(blockRoot);\r
728           b->setHashMd5();\r
729         }\r
730         catch(int err) {\r
731           throw(err);\r
732         }\r
733         cout << "xml:" << b->getXmlFile().toStdString() << endl;\r
734 \r
735         availableBlocks.append(b);\r
736         foreach (int id,b->getCategories()) {\r
737           cout << "ajout du bloc dans cat n° : " << id << endl;\r
738           BlockCategory* cat = categoryTree->searchCategory(id);\r
739           cat->blocks.append(b);\r
740         }\r
741       }\r
742     }\r
743   }\r
744 }\r
745 \r
746 void Parameters::loadReferencesFromLib() throw(Exception) {\r
747 \r
748   cout << "loading references from lib" << endl;\r
749 \r
750   // removing blocks from category tree if they exist\r
751   categoryTree->clearBlocks();\r
752   // deleting existings blocks\r
753   ReferenceBlock* b = NULL;\r
754   for(int i=0;i<availableBlocks.size();i++) {\r
755     b = availableBlocks.at(i);\r
756     delete b;\r
757   }\r
758   availableBlocks.clear();\r
759 \r
760   QFile libFile(refLib);\r
761   if (!libFile.open(QIODevice::ReadOnly)) {\r
762     throw(Exception(BLOCKFILE_NOACCESS));\r
763   }\r
764   QDataStream in(&libFile);\r
765   quint32 size;\r
766 \r
767   in >> size;\r
768 \r
769   int nbBlocks;\r
770   in >> nbBlocks;\r
771   for(int i=0;i<nbBlocks;i++) {\r
772     b = new ReferenceBlock("");\r
773     in >> *b;\r
774     availableBlocks.append(b);\r
775     foreach (int id,b->getCategories()) {\r
776       BlockCategory* cat = categoryTree->searchCategory(id);\r
777       cat->blocks.append(b);\r
778     }\r
779   }\r
780   libFile.close();\r
781 }\r
782 \r
783 void Parameters::saveReferencesToLib() throw(Exception) {\r
784 \r
785   cout << "saving blocks in " << qPrintable(refLib) << endl;\r
786   QFile libFile(refLib);\r
787   if (!libFile.open(QIODevice::WriteOnly)) {\r
788     throw(Exception(BLOCKFILE_NOACCESS));\r
789   }\r
790   QDataStream out(&libFile);\r
791 \r
792   out.setVersion(QDataStream::Qt_5_0);\r
793 \r
794   QByteArray blockData;\r
795   QDataStream toWrite(&blockData, QIODevice::WriteOnly);\r
796 \r
797   toWrite << availableBlocks.size();\r
798   for(int i=0;i<availableBlocks.size();i++) {\r
799     ReferenceBlock* b = availableBlocks.at(i);\r
800     toWrite << *b;\r
801   }\r
802 \r
803   out << blockData;\r
804 \r
805   libFile.close();\r
806 \r
807 }\r
808 \r
809 void Parameters::loadImplementationsFromXml() throw(Exception) {\r
810 \r
811   for(int i=0;i<implPathes.size();i++) {\r
812     cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;\r
813     QDir dir(implPathes.at(i));\r
814     QStringList filter;\r
815     filter << "*.xml";\r
816     dir.setNameFilters(filter);\r
817     QStringList list = dir.entryList();\r
818     for(int j=0;j<list.size();j++) {\r
819       QString fileName = dir.absolutePath();\r
820       fileName.append("/"+list.at(j));\r
821 \r
822       cout << "checking " << qPrintable(fileName) << " is an implementation file ...";\r
823       QFile implXML(fileName);\r
824       if (!implXML.open(QIODevice::ReadOnly)) {\r
825         throw(Exception(IMPLFILE_NOACCESS));\r
826       }\r
827       QTextStream in(&implXML);\r
828       QString line = in.readLine();\r
829       line = in.readLine();\r
830 \r
831       if (!line.contains("<block_impl")) {\r
832         implXML.close();\r
833         continue;\r
834       }\r
835 \r
836       implXML.close();\r
837       cout << "OK" << endl;\r
838       cout << "reading " << qPrintable(fileName) << " content ...";\r
839       /*\r
840       try {\r
841         validateXmlFile(fileName,"block.xsd",Implementation);\r
842       }\r
843       catch(Exception e) {\r
844         throw(e);\r
845       }\r
846       */\r
847       // reading in into QDomDocument\r
848       QDomDocument document ("FileXML");\r
849       if (!implXML.open(QIODevice::ReadOnly)) {\r
850         throw(Exception(IMPLFILE_NOACCESS));\r
851       }\r
852       cout << "OK" << endl;\r
853       cout << "convert " << qPrintable(fileName) << " content into document...";\r
854       if (!document.setContent(&implXML)) {\r
855         implXML.close();\r
856         throw(Exception(IMPLFILE_NOACCESS));\r
857       }\r
858       implXML.close();\r
859 \r
860       QDomElement implRoot = document.documentElement();\r
861       QString refXml = implRoot.attribute("ref_name","none");\r
862       QString refMd5 = implRoot.attribute("ref_md5","none");\r
863       BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);\r
864       availableImplementations.append(impl);\r
865 \r
866       ReferenceBlock* ref = NULL;\r
867       if (! refMd5.isEmpty()) {\r
868         ref = searchBlockByMd5(refMd5);\r
869       }\r
870       if (ref == NULL) {\r
871         ref = searchBlockByXml(refXml);\r
872       }\r
873       if (ref == NULL) {\r
874         cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;\r
875       }\r
876       ref->addImplementation(impl);\r
877       impl->setReference(ref);\r
878       cout << "OK" << endl;\r
879     }\r
880   }\r
881 }\r
882 \r
883 void Parameters::loadImplementationsFromLib() throw(Exception) {\r
884 \r
885   cout << "loading implementations from lib" << endl;\r
886 \r
887   BlockImplementation* impl = NULL;\r
888   ReferenceBlock* ref = NULL;\r
889   for(int i=0;i<availableImplementations.size();i++) {\r
890     impl = availableImplementations.at(i);\r
891     delete impl;\r
892   }\r
893   availableImplementations.clear();\r
894 \r
895   QFile libFile(implLib);\r
896   if (!libFile.open(QIODevice::ReadOnly)) {\r
897     throw(Exception(IMPLFILE_NOACCESS));\r
898   }\r
899   QDataStream in(&libFile);\r
900   quint32 size;\r
901 \r
902   in >> size;\r
903 \r
904   int nbImpls;\r
905   in >> nbImpls;\r
906   for(int i=0;i<nbImpls;i++) {\r
907     impl = new BlockImplementation("");\r
908     in >> *impl;\r
909     availableImplementations.append(impl);\r
910     QString refMd5 = impl->getReferenceMd5();\r
911     QString refXml = impl->getReferenceXml();\r
912     ref = NULL;\r
913     if (! refMd5.isEmpty()) {\r
914       ref = searchBlockByMd5(refMd5);\r
915     }\r
916     if (ref == NULL) {\r
917       ref = searchBlockByXml(refXml);\r
918     }\r
919     if (ref == NULL) {\r
920       cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;\r
921     }\r
922     ref->addImplementation(impl);\r
923     impl->setReference(ref);\r
924   }\r
925   libFile.close();\r
926 }\r
927 \r
928 void Parameters::saveImplementationsToLib() throw(Exception) {\r
929 \r
930   cout << "saving implementations in " << qPrintable(implLib) << endl;\r
931   QFile libFile(implLib);\r
932   if (!libFile.open(QIODevice::WriteOnly)) {\r
933     throw(Exception(IMPLFILE_NOACCESS));\r
934   }\r
935   QDataStream out(&libFile);\r
936 \r
937   out.setVersion(QDataStream::Qt_5_0);\r
938 \r
939   QByteArray blockData;\r
940   QDataStream toWrite(&blockData, QIODevice::WriteOnly);\r
941 \r
942   toWrite << availableImplementations.size();\r
943   for(int i=0;i<availableImplementations.size();i++) {\r
944     BlockImplementation* impl = availableImplementations.at(i);\r
945     toWrite << *impl;\r
946   }\r
947 \r
948   out << blockData;\r
949 \r
950   libFile.close();\r
951 \r
952 }\r
953 void Parameters::addAvailableBlock(ReferenceBlock *block) {\r
954   availableBlocks.append(block);\r
955   foreach (int id,block->getCategories()) {\r
956     cout << "ajout du bloc dans cat n° : " << id << endl;\r
957     BlockCategory* cat = categoryTree->searchCategory(id);\r
958     cat->blocks.append(block);\r
959   }\r
960 }\r
961 \r
962 void Parameters::parametersValidation() {\r
963   QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();\r
964 \r
965   if(!blocksToConfigure.isEmpty()){\r
966     BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);\r
967     widget->show();\r
968   }\r
969 }\r
970 \r
971 void Parameters::connectionsValidation() {\r
972 \r
973 #ifdef DEBUG_INCLFUN\r
974 \r
975   QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;\r
976   QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;\r
977 \r
978   foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){\r
979     foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){\r
980 \r
981       inter->setWidth(connectedInter->getWidth());\r
982       interfaceToValidate->push(connectedInter);\r
983     }\r
984   }\r
985 \r
986 \r
987   try{\r
988     while(!interfaceToValidate->isEmpty()){\r
989       interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);\r
990     }\r
991   }\r
992   catch(Exception e){\r
993     cerr << e.getMessage().toStdString() << endl;\r
994   }\r
995 #endif\r
996 }\r
997 \r
998 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {\r
999 \r
1000 #ifdef DEBUG_INCLFUN\r
1001 \r
1002   QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;\r
1003   QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;\r
1004 \r
1005   foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){\r
1006     foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){\r
1007       if(!checkedBlocks->contains(connectedInter->getOwner())){\r
1008         connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);\r
1009       }\r
1010     }\r
1011   }\r
1012   return *blocksToConfigure;\r
1013 #endif\r
1014 }\r
1015 \r
1016 \r
1017 void Parameters::updateToolbar() {\r
1018   int nb = currentScene->getBlockItems().length();\r
1019   for(int i = 0; i<nb; i++){\r
1020     if(currentScene->getBlockItems().at(i)->isSelected()){\r
1021       currentScene->getGroupWidget()->enableGroupButton(true);\r
1022       return;\r
1023     }\r
1024   }\r
1025   currentScene->getGroupWidget()->enableGroupButton(false);\r
1026 }\r
1027 \r
1028 \r
1029 void Parameters::updateIds() {\r
1030 \r
1031   /* a in-width cross of the graph must be done so that ids of GroupItem\r
1032      are in the correct ordre when saving/loading a project\r
1033    */\r
1034   int countItem = 1;\r
1035   int countIface = 1;\r
1036   QList<GroupScene *> fifo;\r
1037   fifo.append(topScene);\r
1038   while (!fifo.isEmpty()) {\r
1039     GroupScene* scene = fifo.takeFirst();\r
1040     countItem = scene->setItemsId(countItem);\r
1041     countIface = scene->setInterfacesId(countIface);\r
1042     foreach(GroupScene* s, scene->getChildrenScene()) {\r
1043       fifo.append(s);\r
1044     }\r
1045   }\r
1046 }\r
1047 \r
1048 \r
1049 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {\r
1050   foreach(ReferenceBlock *block, availableBlocks){\r
1051     if(block->getXmlFile().contains(xmlName))\r
1052       return block;\r
1053   }\r
1054   return NULL;\r
1055 }\r
1056 \r
1057 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {\r
1058   foreach(ReferenceBlock *block, availableBlocks){\r
1059     if(block->getHashMd5() == sumMd5)\r
1060       return block;\r
1061   }\r
1062   return NULL;\r
1063 }\r
1064 \r
1065 void Parameters::save(QString confFile) {\r
1066 \r
1067 //#ifdef DEBUG_INCLFUN\r
1068 \r
1069   updateIds();\r
1070   QList<ConnectionItem*> allConnections;\r
1071   QFile file(confFile);\r
1072   if(file.open(QIODevice::WriteOnly)){\r
1073 \r
1074     QXmlStreamWriter writer(&file);\r
1075 \r
1076     writer.setAutoFormatting(true);\r
1077     writer.writeStartDocument();\r
1078 \r
1079     writer.writeStartElement("blast_project");\r
1080     writer.writeStartElement("scenes");\r
1081 \r
1082     writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));\r
1083 \r
1084     // cross the scene level by level using a FIFO\r
1085     QList<GroupScene*> fifoScene;\r
1086     fifoScene.append(topScene);\r
1087 \r
1088     GroupScene *scene;\r
1089     while (!fifoScene.isEmpty()) {\r
1090       scene = fifoScene.takeFirst();\r
1091       scene->save(writer);\r
1092       foreach(GroupScene* s, scene->getChildrenScene()) {\r
1093         fifoScene.append(s);\r
1094       }\r
1095 \r
1096       foreach(ConnectionItem* item, scene->getConnectionItems()) {\r
1097         allConnections.append(item);\r
1098       }\r
1099     }\r
1100     writer.writeEndElement();    //</scenes>\r
1101 \r
1102     writer.writeStartElement("connections");\r
1103     foreach(ConnectionItem* item, allConnections) {\r
1104 \r
1105       writer.writeStartElement("connection");\r
1106 \r
1107       writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));\r
1108       writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));\r
1109 \r
1110       writer.writeEndElement();\r
1111     }\r
1112 \r
1113     writer.writeEndElement();    //</connections>\r
1114     writer.writeEndElement();      //</blast_project\r
1115 \r
1116     writer.writeEndDocument();\r
1117 \r
1118     file.close();\r
1119     unsaveModif = false;\r
1120   }\r
1121 //#endif\r
1122 }\r
1123 \r
1124 void Parameters::setArrowPathes() {\r
1125   QPainterPath _inArrow;\r
1126   _inArrow.lineTo(arrowLineLength,0);\r
1127   _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);\r
1128   _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);\r
1129   _inArrow.lineTo(arrowLineLength,0);\r
1130   _inArrow.closeSubpath();\r
1131   inArrow = _inArrow;\r
1132 \r
1133   QPainterPath _outArrow;\r
1134   _outArrow.lineTo(arrowLineLength,0);\r
1135   _outArrow.lineTo(arrowLineLength,-arrowHeight/2);\r
1136   _outArrow.lineTo(arrowLineLength+arrowWidth,0);\r
1137   _outArrow.lineTo(arrowLineLength,arrowHeight/2);\r
1138   _outArrow.lineTo(arrowLineLength,0);\r
1139   _outArrow.closeSubpath();\r
1140   outArrow = _outArrow;\r
1141 \r
1142 }\r
1143 \r
1144 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {\r
1145 \r
1146   if (scene->getId() == id) return scene;\r
1147   GroupScene* sc = NULL;\r
1148 \r
1149   foreach(GroupScene *s, scene->getChildrenScene()) {\r
1150     sc = searchSceneById(id,s);\r
1151     if (sc != NULL) return sc;\r
1152   }\r
1153   return NULL;\r
1154 }\r
1155 \r
1156 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {\r
1157 \r
1158   if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();\r
1159 \r
1160   GroupItem* item = NULL;\r
1161   foreach(GroupScene *s, scene->getChildrenScene()) {\r
1162     item = searchGroupItemById(id,s);\r
1163     if (item != NULL) return item;\r
1164   }\r
1165   return NULL;\r
1166 }\r
1167 \r
1168 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {\r
1169 \r
1170   foreach(BoxItem *item, scene->getBlockItems()){\r
1171     if(item->getId() == id){\r
1172       return item;\r
1173     }\r
1174   }\r
1175 \r
1176   BoxItem* item = NULL;\r
1177   foreach(GroupScene *s, scene->getChildrenScene()) {\r
1178     item = searchBlockItemById(id,s);\r
1179     if (item != NULL) return item;\r
1180   }\r
1181   return NULL;\r
1182 }\r
1183 \r
1184 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {\r
1185 \r
1186   foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){\r
1187     if(item->getId() == id){\r
1188       return item;\r
1189     }\r
1190   }\r
1191   foreach(BoxItem *block, scene->getBlockItems()){\r
1192     foreach(InterfaceItem *item, block->getInterfaces()){\r
1193       if(item->getId() == id){\r
1194         return item;\r
1195       }\r
1196     }\r
1197   }\r
1198   InterfaceItem* item = NULL;\r
1199   foreach(GroupScene *s, scene->getChildrenScene()) {\r
1200     item = searchInterfaceItemById(id,s);\r
1201     if (item != NULL) return item;\r
1202   }\r
1203   return NULL;\r
1204 }\r