1 #include "Parameters.h"
\r
3 #include "Dispatcher.h"
\r
4 #include "BlockLibraryTree.h"
\r
6 #include "BlockCategory.h"
\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
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
23 #include "Exception.h"
\r
24 #include "BlocksToConfigureWidget.h"
\r
26 Parameters::Parameters() {
\r
27 categoryTree = NULL;
\r
30 arrowLineLength = 10;
\r
32 defaultBlockWidth = 100;
\r
33 defaultBlockHeight = 100;
\r
34 defaultBlockFont = QFont("Arial");
\r
35 defaultBlockFontSize = 12;
\r
39 sceneMode = MODE_EDITION; // default mode
\r
40 editState = Parameters::EditNoOperation;
\r
42 unsaveModif = false;
\r
43 isRstClkShown = false;
\r
45 projectPath = QDir::currentPath();
\r
48 Parameters::~Parameters() {
\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
59 availableBlocks.clear();
\r
63 Graph* Parameters::createGraph() {
\r
64 graph = new Graph();
\r
68 void Parameters::destroyGraph() {
\r
72 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
\r
74 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
76 if (blockCat == NULL) return NULL;
\r
77 ReferenceBlock* ref = blockCat->getBlock(idBlock);
\r
83 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
84 // opening configFile
\r
85 QFile xmlFile(xmlFileName);
\r
86 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
87 if (fileType == Configuration) {
\r
88 throw(Exception(CONFIGFILE_NOACCESS));
\r
90 else if (fileType == Reference) {
\r
91 throw(Exception(BLOCKFILE_NOACCESS));
\r
93 else if (fileType == Implementation) {
\r
94 throw(Exception(IMPLFILE_NOACCESS));
\r
96 else if (fileType == Project) {
\r
97 throw(Exception(PROJECTFILE_NOACCESS));
\r
101 QFile xsdFile(xsdFileName);
\r
102 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
104 if (fileType == Configuration) {
\r
105 throw(Exception(CONFIGFILE_NOACCESS));
\r
107 else if (fileType == Reference) {
\r
108 throw(Exception(BLOCKFILE_NOACCESS));
\r
110 else if (fileType == Implementation) {
\r
111 throw(Exception(IMPLFILE_NOACCESS));
\r
113 else if (fileType == Project) {
\r
114 throw(Exception(PROJECTFILE_NOACCESS));
\r
118 if(validate(xmlFile,xsdFile) == false) {
\r
121 if (fileType == Configuration) {
\r
122 throw(Exception(CONFIGFILE_CORRUPTED));
\r
124 else if (fileType == Reference) {
\r
125 throw(Exception(BLOCKFILE_CORRUPTED));
\r
127 else if (fileType == Implementation) {
\r
128 throw(Exception(IMPLFILE_CORRUPTED));
\r
130 else if (fileType == Project) {
\r
131 throw(Exception(PROJECTFILE_CORRUPTED));
\r
138 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
140 // 2 files are supposed to be already opened
\r
143 if(! schema.load(&fileSchema)){
\r
144 cout << "invalid schema" << endl;
\r
148 QXmlSchemaValidator validator(schema);
\r
150 if(! validator.validate(&fileXml)){
\r
151 cout << "invalid xml" << endl;
\r
157 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
160 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
162 catch(Exception err) {
\r
166 QFile projectFile(projectFileName);
\r
167 QDomDocument doc("projectFile");
\r
169 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
170 throw(Exception(PROJECTFILE_NOACCESS));
\r
172 if(!doc.setContent(&projectFile)) {
\r
173 projectFile.close();
\r
174 throw(Exception(PROJECTFILE_CORRUPTED));
\r
176 projectFile.close();
\r
178 QDomElement root = doc.documentElement();
\r
183 GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
\r
186 GroupWidget* groupWidget = NULL;
\r
187 GroupItem *groupItem = NULL;
\r
188 GroupBlock *groupBlock = NULL;
\r
190 GroupWidget* topGroup = NULL;
\r
191 /**********************************************************
\r
192 1 : getting scene and creating associated group widgets
\r
193 ***********************************************************/
\r
194 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
196 int maxIdScene = -1;
\r
197 for(int i=0; i<scenesNodes.length(); i++) {
\r
198 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
199 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
200 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
201 if (idScene > maxIdScene) maxIdScene = idScene;
\r
202 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
203 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
205 if (idUpperScene == -1) {
\r
206 topGroup = dispatcher->createTopScene();
\r
207 topScene->setId(idScene);
\r
208 groupItem = topScene->getGroupItem();
\r
209 cout << "top group added to scene n°" << idScene << endl;
\r
212 cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
\r
213 GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
\r
214 groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);
\r
215 groupWidget->getScene()->setId(idScene);
\r
216 groupItem = groupWidget->getScene()->getGroupItem();
\r
218 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
219 /**********************************************************
\r
220 1.1 : getting the group item of each scene
\r
221 ***********************************************************/
\r
222 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
224 groupItem->load(groupItemNode);
\r
226 catch(Exception err) {
\r
230 if (idUpperScene != -1) {
\r
231 groupWidget->setWindowTitle(groupBlock->getName());
\r
232 groupWidget->show();
\r
235 dispatcher->setSceneCounter(maxIdScene+1);
\r
236 cout << "groupItems loaded and windows created succefully!" << endl;
\r
238 /**********************************************************
\r
239 2 : getting the functional blocks of each scene
\r
240 ***********************************************************/
\r
242 for(int i=0; i<scenesNodes.length(); i++){
\r
243 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
244 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
245 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
246 cout << "SCENE : " << idScene << endl;
\r
247 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
249 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
251 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
253 for(int j=0; j<functionalBlockNodes.length(); j++) {
\r
254 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
255 BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());
\r
257 funcItem->loadFunctional(currentFBNode);
\r
259 catch(Exception err) {
\r
262 // add the block to the GroupScene
\r
263 currentScene->addBoxItem(funcItem);
\r
266 cout << "functional blocks loaded and created succefully!" << endl;
\r
268 /**********************************************************
\r
269 3 : set the BoxItem that represents a GroupItem in a child scene
\r
270 ***********************************************************/
\r
272 for(int i=0; i<scenesNodes.length(); i++){
\r
273 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
274 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
275 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
276 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
277 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
279 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
281 for(int j=0; j<biGroupNodes.length(); j++){
\r
282 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
284 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
285 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
287 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
288 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
290 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
291 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
292 int posX = positionStr.at(0).toInt(&ok);
\r
293 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
294 int posY = positionStr.at(1).toInt(&ok);
\r
295 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
297 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
298 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
299 int dimX = dimensionStr.at(0).toInt(&ok);
\r
300 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
301 int dimY = dimensionStr.at(1).toInt(&ok);
\r
302 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
304 // get the GroupItem already created and set at phase 1
\r
305 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
306 BoxItem* upperItem = NULL;
\r
307 if(insideGroup == NULL) cout << "group null" << endl;
\r
308 // now search within the scene which BoxItem has a childItem that is = to insideGroup
\r
309 QList<BoxItem *> lst = currentScene->getBoxItems();
\r
310 foreach(BoxItem* item, lst) {
\r
311 if (item->getChildGroupItem() == insideGroup) {
\r
316 if (upperItem == NULL) {
\r
317 throw(Exception(PROJECTFILE_CORRUPTED));
\r
320 upperItem->setId(id);
\r
321 upperItem->setPos(posX,posY);
\r
322 upperItem->setDimension(dimX,dimY);
\r
324 // set interfaces of this BoxItem
\r
325 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
327 for(int k=0; k<interfaceNodes.length(); k++){
\r
328 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
330 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
331 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
333 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
334 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
336 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
337 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
338 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
340 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
341 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
343 ConnectedInterface *refInter = insideGroup->searchInterfaceByName(refName)->refInter;
\r
344 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
\r
345 ifaceItem->setId(id);
\r
346 upperItem->addInterface(ifaceItem);
\r
350 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
352 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
354 for(int i=0; i<connectionNodes.length(); i++){
\r
355 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
357 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
358 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
360 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
361 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
364 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
365 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
367 if(iface1 != NULL && iface2 != NULL){
\r
368 dispatcher->createConnectionItem(iface1,iface2);
\r
370 cout << "interfaces not found, connect canceled!" << endl;
\r
373 cout << "connections loaded and created succefully!" << endl;
\r
378 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
381 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
383 catch(Exception err) {
\r
388 // opening configFile
\r
389 QFile configFile(confFile);
\r
390 // reading in into QDomDocument
\r
391 QDomDocument document("configFile");
\r
393 if (!configFile.open(QIODevice::ReadOnly)) {
\r
394 throw(Exception(CONFIGFILE_NOACCESS));
\r
396 if (!document.setContent(&configFile)) {
\r
397 configFile.close();
\r
398 throw(Exception(CONFIGFILE_NOACCESS));
\r
400 configFile.close();
\r
402 //Get the root element
\r
403 QDomElement config = document.documentElement();
\r
405 QDomElement eltCat = config.firstChildElement("categories");
\r
407 categoryTree = new BlockLibraryTree();
\r
408 categoryTree->load(eltCat);
\r
410 catch(Exception err) {
\r
414 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
415 refLib = eltReferences.attribute("lib_file","none");
\r
416 cout << "references lib : " << qPrintable(refLib) << endl;
\r
418 QString nbPathesStr;
\r
419 nbPathesStr = eltReferences.attribute("nb","none");
\r
420 nbPathes = nbPathesStr.toInt(&ok);
\r
421 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
422 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
424 for(int i=0;i<listBlockDir.size();i++) {
\r
425 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
426 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
427 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
428 QString path = eltBlockDir.attribute("path","none");
\r
429 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
430 refPathes.append(path);
\r
431 cout << "references path : " << qPrintable(path) << endl;
\r
434 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
435 implLib = eltImpl.attribute("lib_file","none");
\r
436 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
437 nbPathesStr = eltImpl.attribute("nb","none");
\r
438 nbPathes = nbPathesStr.toInt(&ok);
\r
439 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
440 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
442 for(int i=0;i<listImplDir.size();i++) {
\r
443 QDomNode nodeImplDir = listImplDir.at(i);
\r
444 QDomElement eltImplDir = nodeImplDir.toElement();
\r
445 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
446 QString path = eltImplDir.attribute("path","none");
\r
447 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
448 implPathes.append(path);
\r
449 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
451 // getting elt = the element <defaults>
\r
452 // for each child element, initialize the associated attributes of Parameters
\r
454 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
456 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
457 QString attributeStr = eltBlocks.attribute("width", "none");
\r
458 defaultBlockWidth = attributeStr.toInt(&ok);
\r
459 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
460 attributeStr = eltBlocks.attribute("height", "none");
\r
461 defaultBlockHeight = attributeStr.toInt(&ok);
\r
462 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
463 attributeStr = eltBlocks.attribute("font_size", "none");
\r
464 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
465 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
466 attributeStr = eltBlocks.attribute("font", "none");
\r
467 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
468 defaultBlockFontName = attributeStr;
\r
469 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
471 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
472 attributeStr = eltInterfaces.attribute("width", "none");
\r
473 arrowWidth = attributeStr.toInt(&ok);
\r
474 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
475 attributeStr = eltInterfaces.attribute("height", "none");
\r
476 arrowHeight = attributeStr.toInt(&ok);
\r
477 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
478 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
479 arrowLineLength = attributeStr.toInt(&ok);
\r
480 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
481 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
482 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
483 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
484 attributeStr = eltInterfaces.attribute("font", "none");
\r
485 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
486 defaultIfaceFontName = attributeStr;
\r
487 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
489 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
490 attributeStr = eltConnections.attribute("gaplength", "none");
\r
491 connGapLength = attributeStr.toInt(&ok);
\r
492 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
495 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
496 cout << "load references from xml" << endl;
\r
497 for(int i=0;i<refPathes.size();i++) {
\r
498 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
499 QDir dir(refPathes.at(i));
\r
500 QStringList filter;
\r
502 dir.setNameFilters(filter);
\r
503 QStringList list = dir.entryList();
\r
504 for(int j=0;j<list.size();j++) {
\r
505 QString fileName = dir.absolutePath();
\r
506 fileName.append("/"+list.at(j));
\r
508 QFile blockXML(fileName);
\r
509 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
510 throw(Exception(BLOCKFILE_NOACCESS));
\r
512 QTextStream in(&blockXML);
\r
513 QString line = in.readLine();
\r
514 line = in.readLine();
\r
516 if (!line.contains("<block>")) {
\r
523 validateXmlFile(fileName,"reference.xsd",Reference);
\r
525 catch(Exception err) {
\r
529 // reading in into QDomDocument
\r
530 QDomDocument document ("FileXML");
\r
531 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
532 throw(Exception(BLOCKFILE_NOACCESS));
\r
534 if (!document.setContent(&blockXML)) {
\r
536 throw(Exception(BLOCKFILE_NOACCESS));
\r
540 QDomElement blockRoot = document.documentElement();
\r
541 QString name = blockRoot.tagName();
\r
542 if (name == "block") {
\r
544 cout << "xml:" << fileName.toStdString() << endl;
\r
545 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
547 b->load(blockRoot);
\r
553 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
555 availableBlocks.append(b);
\r
556 foreach (int id,b->getCategories()) {
\r
557 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
558 BlockCategory* cat = categoryTree->searchCategory(id);
\r
559 cat->blocks.append(b);
\r
566 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
568 cout << "loading references from lib" << endl;
\r
570 // removing blocks from category tree if they exist
\r
571 categoryTree->clearBlocks();
\r
572 // deleting existings blocks
\r
573 ReferenceBlock* b = NULL;
\r
574 for(int i=0;i<availableBlocks.size();i++) {
\r
575 b = availableBlocks.at(i);
\r
578 availableBlocks.clear();
\r
580 QFile libFile(refLib);
\r
581 if (!libFile.open(QIODevice::ReadOnly)) {
\r
582 throw(Exception(BLOCKFILE_NOACCESS));
\r
584 QDataStream in(&libFile);
\r
591 for(int i=0;i<nbBlocks;i++) {
\r
592 b = new ReferenceBlock("");
\r
594 availableBlocks.append(b);
\r
595 foreach (int id,b->getCategories()) {
\r
596 BlockCategory* cat = categoryTree->searchCategory(id);
\r
597 cat->blocks.append(b);
\r
603 void Parameters::saveReferencesToLib() throw(Exception) {
\r
605 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
606 QFile libFile(refLib);
\r
607 if (!libFile.open(QIODevice::WriteOnly)) {
\r
608 throw(Exception(BLOCKFILE_NOACCESS));
\r
610 QDataStream out(&libFile);
\r
612 out.setVersion(QDataStream::Qt_5_0);
\r
614 QByteArray blockData;
\r
615 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
617 toWrite << availableBlocks.size();
\r
618 for(int i=0;i<availableBlocks.size();i++) {
\r
619 ReferenceBlock* b = availableBlocks.at(i);
\r
629 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
631 for(int i=0;i<implPathes.size();i++) {
\r
632 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
633 QDir dir(implPathes.at(i));
\r
634 QStringList filter;
\r
636 dir.setNameFilters(filter);
\r
637 QStringList list = dir.entryList();
\r
638 for(int j=0;j<list.size();j++) {
\r
639 QString fileName = dir.absolutePath();
\r
640 fileName.append("/"+list.at(j));
\r
642 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
643 QFile implXML(fileName);
\r
644 if (!implXML.open(QIODevice::ReadOnly)) {
\r
645 throw(Exception(IMPLFILE_NOACCESS));
\r
647 QTextStream in(&implXML);
\r
648 QString line = in.readLine();
\r
649 line = in.readLine();
\r
651 if (!line.contains("<block_impl")) {
\r
657 cout << "OK" << endl;
\r
658 cout << "reading " << qPrintable(fileName) << " content ...";
\r
661 validateXmlFile(fileName,"implementation.xsd",Implementation);
\r
663 catch(Exception e) {
\r
667 // reading in into QDomDocument
\r
668 QDomDocument document ("FileXML");
\r
669 if (!implXML.open(QIODevice::ReadOnly)) {
\r
670 throw(Exception(IMPLFILE_NOACCESS));
\r
672 cout << "OK" << endl;
\r
673 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
674 if (!document.setContent(&implXML)) {
\r
676 throw(Exception(IMPLFILE_NOACCESS));
\r
680 QDomElement implRoot = document.documentElement();
\r
681 QString refXml = implRoot.attribute("ref_name","none");
\r
682 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
683 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
684 availableImplementations.append(impl);
\r
686 ReferenceBlock* ref = NULL;
\r
687 if (! refMd5.isEmpty()) {
\r
688 ref = searchBlockByMd5(refMd5);
\r
691 ref = searchBlockByXml(refXml);
\r
694 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
696 ref->addImplementation(impl);
\r
697 impl->setReference(ref);
\r
698 cout << "OK" << endl;
\r
703 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
705 cout << "loading implementations from lib" << endl;
\r
707 BlockImplementation* impl = NULL;
\r
708 ReferenceBlock* ref = NULL;
\r
709 for(int i=0;i<availableImplementations.size();i++) {
\r
710 impl = availableImplementations.at(i);
\r
713 availableImplementations.clear();
\r
715 QFile libFile(implLib);
\r
716 if (!libFile.open(QIODevice::ReadOnly)) {
\r
717 throw(Exception(IMPLFILE_NOACCESS));
\r
719 QDataStream in(&libFile);
\r
726 for(int i=0;i<nbImpls;i++) {
\r
727 impl = new BlockImplementation("");
\r
729 availableImplementations.append(impl);
\r
730 QString refMd5 = impl->getReferenceMd5();
\r
731 QString refXml = impl->getReferenceXml();
\r
733 if (! refMd5.isEmpty()) {
\r
734 ref = searchBlockByMd5(refMd5);
\r
737 ref = searchBlockByXml(refXml);
\r
740 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
742 ref->addImplementation(impl);
\r
743 impl->setReference(ref);
\r
748 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
750 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
751 QFile libFile(implLib);
\r
752 if (!libFile.open(QIODevice::WriteOnly)) {
\r
753 throw(Exception(IMPLFILE_NOACCESS));
\r
755 QDataStream out(&libFile);
\r
757 out.setVersion(QDataStream::Qt_5_0);
\r
759 QByteArray blockData;
\r
760 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
762 toWrite << availableImplementations.size();
\r
763 for(int i=0;i<availableImplementations.size();i++) {
\r
764 BlockImplementation* impl = availableImplementations.at(i);
\r
773 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
774 availableBlocks.append(block);
\r
775 foreach (int id,block->getCategories()) {
\r
776 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
777 BlockCategory* cat = categoryTree->searchCategory(id);
\r
778 cat->blocks.append(block);
\r
782 void Parameters::parametersValidation() {
\r
783 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
785 if(!blocksToConfigure.isEmpty()){
\r
786 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
791 void Parameters::connectionsValidation() {
\r
793 #ifdef DEBUG_INCLFUN
\r
795 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
796 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
798 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
799 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
801 inter->setWidth(connectedInter->getWidth());
\r
802 interfaceToValidate->push(connectedInter);
\r
808 while(!interfaceToValidate->isEmpty()){
\r
809 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
812 catch(Exception e){
\r
813 cerr << e.getMessage().toStdString() << endl;
\r
818 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
820 #ifdef DEBUG_INCLFUN
\r
822 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
823 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
825 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
826 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
827 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
828 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
832 return *blocksToConfigure;
\r
837 void Parameters::updateToolbar() {
\r
838 int nb = currentScene->getBoxItems().length();
\r
839 for(int i = 0; i<nb; i++){
\r
840 if(currentScene->getBoxItems().at(i)->isSelected()){
\r
841 currentScene->getGroupWidget()->enableGroupButton(true);
\r
845 currentScene->getGroupWidget()->enableGroupButton(false);
\r
849 void Parameters::updateIds() {
\r
851 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
852 are in the correct ordre when saving/loading a project
\r
855 int countIface = 1;
\r
856 QList<GroupScene *> fifo;
\r
857 fifo.append(topScene);
\r
858 while (!fifo.isEmpty()) {
\r
859 GroupScene* scene = fifo.takeFirst();
\r
860 countItem = scene->setItemsId(countItem);
\r
861 countIface = scene->setInterfacesId(countIface);
\r
862 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
869 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
870 foreach(ReferenceBlock *block, availableBlocks){
\r
871 if(block->getXmlFile().contains(xmlName))
\r
877 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
878 foreach(ReferenceBlock *block, availableBlocks){
\r
879 if(block->getHashMd5() == sumMd5)
\r
885 void Parameters::save(QString confFile) {
\r
887 //#ifdef DEBUG_INCLFUN
\r
890 QList<ConnectionItem*> allConnections;
\r
891 QFile file(confFile);
\r
892 if(file.open(QIODevice::WriteOnly)){
\r
894 QXmlStreamWriter writer(&file);
\r
896 writer.setAutoFormatting(true);
\r
897 writer.writeStartDocument();
\r
899 writer.writeStartElement("blast_project");
\r
900 writer.writeStartElement("scenes");
\r
902 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
904 // cross the scene level by level using a FIFO
\r
905 QList<GroupScene*> fifoScene;
\r
906 fifoScene.append(topScene);
\r
909 while (!fifoScene.isEmpty()) {
\r
910 scene = fifoScene.takeFirst();
\r
911 scene->save(writer);
\r
912 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
913 fifoScene.append(s);
\r
916 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
917 allConnections.append(item);
\r
920 writer.writeEndElement(); //</scenes>
\r
922 writer.writeStartElement("connections");
\r
923 foreach(ConnectionItem* item, allConnections) {
\r
925 writer.writeStartElement("connection");
\r
927 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
928 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
930 writer.writeEndElement();
\r
933 writer.writeEndElement(); //</connections>
\r
934 writer.writeEndElement(); //</blast_project
\r
936 writer.writeEndDocument();
\r
939 unsaveModif = false;
\r
944 void Parameters::setArrowPathes() {
\r
945 QPainterPath _inArrow;
\r
946 _inArrow.lineTo(arrowLineLength,0);
\r
947 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
948 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
949 _inArrow.lineTo(arrowLineLength,0);
\r
950 _inArrow.closeSubpath();
\r
951 inArrow = _inArrow;
\r
953 QPainterPath _outArrow;
\r
954 _outArrow.lineTo(arrowLineLength,0);
\r
955 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
956 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
957 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
958 _outArrow.lineTo(arrowLineLength,0);
\r
959 _outArrow.closeSubpath();
\r
960 outArrow = _outArrow;
\r
964 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
966 if (scene->getId() == id) return scene;
\r
967 GroupScene* sc = NULL;
\r
969 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
970 sc = searchSceneById(id,s);
\r
971 if (sc != NULL) return sc;
\r
976 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
978 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
980 GroupItem* item = NULL;
\r
981 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
982 item = searchGroupItemById(id,s);
\r
983 if (item != NULL) return item;
\r
988 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
990 foreach(BoxItem *item, scene->getBoxItems()){
\r
991 if(item->getId() == id){
\r
996 BoxItem* item = NULL;
\r
997 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
998 item = searchBlockItemById(id,s);
\r
999 if (item != NULL) return item;
\r
1004 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1006 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1007 if(item->getId() == id){
\r
1011 foreach(BoxItem *block, scene->getBoxItems()){
\r
1012 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1013 if(item->getId() == id){
\r
1018 InterfaceItem* item = NULL;
\r
1019 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1020 item = searchInterfaceItemById(id,s);
\r
1021 if (item != NULL) return item;
\r