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

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