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
47 validityExtension = "_enb";
\r
50 Parameters::~Parameters() {
\r
54 void Parameters::clear() {
\r
55 delete categoryTree;
\r
56 QListIterator<ReferenceBlock *> iter(availableBlocks);
\r
57 while(iter.hasNext()) {
\r
58 ReferenceBlock* item = iter.next();
\r
61 availableBlocks.clear();
\r
65 Graph* Parameters::createGraph() {
\r
66 graph = new Graph();
\r
70 void Parameters::destroyGraph() {
\r
74 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
\r
76 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
78 if (blockCat == NULL) return NULL;
\r
79 ReferenceBlock* ref = blockCat->getBlock(idBlock);
\r
85 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
86 // opening configFile
\r
87 QFile xmlFile(xmlFileName);
\r
88 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
89 if (fileType == Configuration) {
\r
90 throw(Exception(CONFIGFILE_NOACCESS));
\r
92 else if (fileType == Reference) {
\r
93 throw(Exception(BLOCKFILE_NOACCESS));
\r
95 else if (fileType == Implementation) {
\r
96 throw(Exception(IMPLFILE_NOACCESS));
\r
98 else if (fileType == Project) {
\r
99 throw(Exception(PROJECTFILE_NOACCESS));
\r
103 QFile xsdFile(xsdFileName);
\r
104 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
106 if (fileType == Configuration) {
\r
107 throw(Exception(CONFIGFILE_NOACCESS));
\r
109 else if (fileType == Reference) {
\r
110 throw(Exception(BLOCKFILE_NOACCESS));
\r
112 else if (fileType == Implementation) {
\r
113 throw(Exception(IMPLFILE_NOACCESS));
\r
115 else if (fileType == Project) {
\r
116 throw(Exception(PROJECTFILE_NOACCESS));
\r
120 if(validate(xmlFile,xsdFile) == false) {
\r
123 if (fileType == Configuration) {
\r
124 throw(Exception(CONFIGFILE_CORRUPTED));
\r
126 else if (fileType == Reference) {
\r
127 throw(Exception(BLOCKFILE_CORRUPTED));
\r
129 else if (fileType == Implementation) {
\r
130 throw(Exception(IMPLFILE_CORRUPTED));
\r
132 else if (fileType == Project) {
\r
133 throw(Exception(PROJECTFILE_CORRUPTED));
\r
140 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
142 // 2 files are supposed to be already opened
\r
145 if(! schema.load(&fileSchema)){
\r
146 cout << "invalid schema" << endl;
\r
150 QXmlSchemaValidator validator(schema);
\r
152 if(! validator.validate(&fileXml)){
\r
153 cout << "invalid xml" << endl;
\r
159 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
162 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
164 catch(Exception err) {
\r
168 QFile projectFile(projectFileName);
\r
169 QDomDocument doc("projectFile");
\r
171 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
172 throw(Exception(PROJECTFILE_NOACCESS));
\r
174 if(!doc.setContent(&projectFile)) {
\r
175 projectFile.close();
\r
176 throw(Exception(PROJECTFILE_CORRUPTED));
\r
178 projectFile.close();
\r
180 QDomElement root = doc.documentElement();
\r
185 GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
\r
188 GroupWidget* groupWidget = NULL;
\r
189 GroupItem *groupItem = NULL;
\r
190 GroupBlock *groupBlock = NULL;
\r
192 GroupWidget* topGroup = NULL;
\r
193 /**********************************************************
\r
194 1 : getting scene and creating associated group widgets
\r
195 ***********************************************************/
\r
196 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
198 int maxIdScene = -1;
\r
199 for(int i=0; i<scenesNodes.length(); i++) {
\r
200 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
201 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
202 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
203 if (idScene > maxIdScene) maxIdScene = idScene;
\r
204 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
205 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
207 if (idUpperScene == -1) {
\r
208 topGroup = dispatcher->createTopScene();
\r
209 topScene->setId(idScene);
\r
210 groupItem = topScene->getGroupItem();
\r
211 cout << "top group added to scene n°" << idScene << endl;
\r
214 cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
\r
215 GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
\r
216 groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);
\r
217 groupWidget->getScene()->setId(idScene);
\r
218 groupItem = groupWidget->getScene()->getGroupItem();
\r
220 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
221 /**********************************************************
\r
222 1.1 : getting the group item of each scene
\r
223 ***********************************************************/
\r
224 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
226 groupItem->load(groupItemNode);
\r
228 catch(Exception err) {
\r
232 if (idUpperScene != -1) {
\r
233 groupWidget->setWindowTitle(groupBlock->getName());
\r
234 groupWidget->show();
\r
237 dispatcher->setSceneCounter(maxIdScene+1);
\r
238 cout << "groupItems loaded and windows created succefully!" << endl;
\r
240 /**********************************************************
\r
241 2 : getting the functional blocks of each scene
\r
242 ***********************************************************/
\r
244 for(int i=0; i<scenesNodes.length(); i++){
\r
245 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
246 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
247 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
248 cout << "SCENE : " << idScene << endl;
\r
249 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
251 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
253 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
255 for(int j=0; j<functionalBlockNodes.length(); j++) {
\r
256 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
257 BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());
\r
259 funcItem->loadFunctional(currentFBNode);
\r
261 catch(Exception err) {
\r
264 // add the block to the GroupScene
\r
265 currentScene->addBoxItem(funcItem);
\r
268 cout << "functional blocks loaded and created succefully!" << endl;
\r
270 /**********************************************************
\r
271 3 : set the BoxItem that represents a GroupItem in a child scene
\r
272 ***********************************************************/
\r
274 for(int i=0; i<scenesNodes.length(); i++){
\r
275 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
276 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
277 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
278 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
279 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
281 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
283 for(int j=0; j<biGroupNodes.length(); j++){
\r
284 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
286 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
287 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
289 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
290 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
292 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
293 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
294 int posX = positionStr.at(0).toInt(&ok);
\r
295 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
296 int posY = positionStr.at(1).toInt(&ok);
\r
297 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
299 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
300 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
301 int dimX = dimensionStr.at(0).toInt(&ok);
\r
302 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
303 int dimY = dimensionStr.at(1).toInt(&ok);
\r
304 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
306 // get the GroupItem already created and set at phase 1
\r
307 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
308 BoxItem* upperItem = NULL;
\r
309 if(insideGroup == NULL) cout << "group null" << endl;
\r
310 // now search within the scene which BoxItem has a childItem that is = to insideGroup
\r
311 QList<BoxItem *> lst = currentScene->getBoxItems();
\r
312 foreach(BoxItem* item, lst) {
\r
313 if (item->getChildGroupItem() == insideGroup) {
\r
318 if (upperItem == NULL) {
\r
319 throw(Exception(PROJECTFILE_CORRUPTED));
\r
322 upperItem->setId(id);
\r
323 upperItem->setPos(posX,posY);
\r
324 upperItem->setDimension(dimX,dimY);
\r
326 // set interfaces of this BoxItem
\r
327 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
329 for(int k=0; k<interfaceNodes.length(); k++){
\r
330 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
332 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
333 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
335 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
336 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
338 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
339 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
340 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
342 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
343 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
345 ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;
\r
346 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
\r
347 ifaceItem->setId(id);
\r
348 upperItem->addInterfaceItem(ifaceItem);
\r
352 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
354 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
356 for(int i=0; i<connectionNodes.length(); i++){
\r
357 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
359 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
360 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
362 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
363 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
366 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
367 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
369 if(iface1 != NULL && iface2 != NULL){
\r
370 dispatcher->createConnection(iface1,iface2);
\r
372 cout << "interfaces not found, connect canceled!" << endl;
\r
375 cout << "connections loaded and created succefully!" << endl;
\r
380 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
383 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
385 catch(Exception err) {
\r
390 // opening configFile
\r
391 QFile configFile(confFile);
\r
392 // reading in into QDomDocument
\r
393 QDomDocument document("configFile");
\r
395 if (!configFile.open(QIODevice::ReadOnly)) {
\r
396 throw(Exception(CONFIGFILE_NOACCESS));
\r
398 if (!document.setContent(&configFile)) {
\r
399 configFile.close();
\r
400 throw(Exception(CONFIGFILE_NOACCESS));
\r
402 configFile.close();
\r
404 //Get the root element
\r
405 QDomElement config = document.documentElement();
\r
407 QDomElement eltCat = config.firstChildElement("categories");
\r
409 categoryTree = new BlockLibraryTree();
\r
410 categoryTree->load(eltCat);
\r
412 catch(Exception err) {
\r
416 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
417 refLib = eltReferences.attribute("lib_file","none");
\r
418 cout << "references lib : " << qPrintable(refLib) << endl;
\r
420 QString nbPathesStr;
\r
421 nbPathesStr = eltReferences.attribute("nb","none");
\r
422 nbPathes = nbPathesStr.toInt(&ok);
\r
423 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
424 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
426 for(int i=0;i<listBlockDir.size();i++) {
\r
427 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
428 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
429 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
430 QString path = eltBlockDir.attribute("path","none");
\r
431 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
432 refPathes.append(path);
\r
433 cout << "references path : " << qPrintable(path) << endl;
\r
436 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
437 implLib = eltImpl.attribute("lib_file","none");
\r
438 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
439 nbPathesStr = eltImpl.attribute("nb","none");
\r
440 nbPathes = nbPathesStr.toInt(&ok);
\r
441 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
442 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
444 for(int i=0;i<listImplDir.size();i++) {
\r
445 QDomNode nodeImplDir = listImplDir.at(i);
\r
446 QDomElement eltImplDir = nodeImplDir.toElement();
\r
447 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
448 QString path = eltImplDir.attribute("path","none");
\r
449 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
450 implPathes.append(path);
\r
451 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
453 // getting elt = the element <defaults>
\r
454 // for each child element, initialize the associated attributes of Parameters
\r
456 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
458 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
459 QString attributeStr = eltBlocks.attribute("width", "none");
\r
460 defaultBlockWidth = attributeStr.toInt(&ok);
\r
461 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
462 attributeStr = eltBlocks.attribute("height", "none");
\r
463 defaultBlockHeight = attributeStr.toInt(&ok);
\r
464 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
465 attributeStr = eltBlocks.attribute("font_size", "none");
\r
466 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
467 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
468 attributeStr = eltBlocks.attribute("font", "none");
\r
469 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
470 defaultBlockFontName = attributeStr;
\r
471 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
473 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
474 attributeStr = eltInterfaces.attribute("width", "none");
\r
475 arrowWidth = attributeStr.toInt(&ok);
\r
476 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
477 attributeStr = eltInterfaces.attribute("height", "none");
\r
478 arrowHeight = attributeStr.toInt(&ok);
\r
479 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
480 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
481 arrowLineLength = attributeStr.toInt(&ok);
\r
482 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
483 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
484 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
485 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
486 attributeStr = eltInterfaces.attribute("font", "none");
\r
487 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
488 defaultIfaceFontName = attributeStr;
\r
489 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
491 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
492 attributeStr = eltConnections.attribute("gaplength", "none");
\r
493 connGapLength = attributeStr.toInt(&ok);
\r
494 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
497 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
498 cout << "load references from xml" << endl;
\r
499 for(int i=0;i<refPathes.size();i++) {
\r
500 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
501 QDir dir(refPathes.at(i));
\r
502 QStringList filter;
\r
504 dir.setNameFilters(filter);
\r
505 QStringList list = dir.entryList();
\r
506 for(int j=0;j<list.size();j++) {
\r
507 QString fileName = dir.absolutePath();
\r
508 fileName.append("/"+list.at(j));
\r
510 QFile blockXML(fileName);
\r
511 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
512 throw(Exception(BLOCKFILE_NOACCESS));
\r
514 QTextStream in(&blockXML);
\r
515 QString line = in.readLine();
\r
516 line = in.readLine();
\r
518 if (!line.contains("<block>")) {
\r
525 validateXmlFile(fileName,"reference.xsd",Reference);
\r
527 catch(Exception err) {
\r
531 // reading in into QDomDocument
\r
532 QDomDocument document ("FileXML");
\r
533 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
534 throw(Exception(BLOCKFILE_NOACCESS));
\r
536 if (!document.setContent(&blockXML)) {
\r
538 throw(Exception(BLOCKFILE_NOACCESS));
\r
542 QDomElement blockRoot = document.documentElement();
\r
543 QString name = blockRoot.tagName();
\r
544 if (name == "block") {
\r
546 cout << "xml:" << fileName.toStdString() << endl;
\r
547 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
549 b->load(blockRoot);
\r
555 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
557 availableBlocks.append(b);
\r
558 foreach (int id,b->getCategories()) {
\r
559 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
560 BlockCategory* cat = categoryTree->searchCategory(id);
\r
561 cat->blocks.append(b);
\r
568 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
570 cout << "loading references from lib" << endl;
\r
572 // removing blocks from category tree if they exist
\r
573 categoryTree->clearBlocks();
\r
574 // deleting existings blocks
\r
575 ReferenceBlock* b = NULL;
\r
576 for(int i=0;i<availableBlocks.size();i++) {
\r
577 b = availableBlocks.at(i);
\r
580 availableBlocks.clear();
\r
582 QFile libFile(refLib);
\r
583 if (!libFile.open(QIODevice::ReadOnly)) {
\r
584 throw(Exception(BLOCKFILE_NOACCESS));
\r
586 QDataStream in(&libFile);
\r
593 for(int i=0;i<nbBlocks;i++) {
\r
594 b = new ReferenceBlock("");
\r
596 availableBlocks.append(b);
\r
597 foreach (int id,b->getCategories()) {
\r
598 BlockCategory* cat = categoryTree->searchCategory(id);
\r
599 cat->blocks.append(b);
\r
605 void Parameters::saveReferencesToLib() throw(Exception) {
\r
607 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
608 QFile libFile(refLib);
\r
609 if (!libFile.open(QIODevice::WriteOnly)) {
\r
610 throw(Exception(BLOCKFILE_NOACCESS));
\r
612 QDataStream out(&libFile);
\r
614 out.setVersion(QDataStream::Qt_5_0);
\r
616 QByteArray blockData;
\r
617 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
619 toWrite << availableBlocks.size();
\r
620 for(int i=0;i<availableBlocks.size();i++) {
\r
621 ReferenceBlock* b = availableBlocks.at(i);
\r
631 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
633 for(int i=0;i<implPathes.size();i++) {
\r
634 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
635 QDir dir(implPathes.at(i));
\r
636 QStringList filter;
\r
638 dir.setNameFilters(filter);
\r
639 QStringList list = dir.entryList();
\r
640 for(int j=0;j<list.size();j++) {
\r
641 QString fileName = dir.absolutePath();
\r
642 fileName.append("/"+list.at(j));
\r
644 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
645 QFile implXML(fileName);
\r
646 if (!implXML.open(QIODevice::ReadOnly)) {
\r
647 throw(Exception(IMPLFILE_NOACCESS));
\r
649 QTextStream in(&implXML);
\r
650 QString line = in.readLine();
\r
651 line = in.readLine();
\r
653 if (!line.contains("<block_impl")) {
\r
659 cout << "OK" << endl;
\r
660 cout << "reading " << qPrintable(fileName) << " content ...";
\r
663 validateXmlFile(fileName,"implementation.xsd",Implementation);
\r
665 catch(Exception e) {
\r
669 // reading in into QDomDocument
\r
670 QDomDocument document ("FileXML");
\r
671 if (!implXML.open(QIODevice::ReadOnly)) {
\r
672 throw(Exception(IMPLFILE_NOACCESS));
\r
674 cout << "OK" << endl;
\r
675 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
676 if (!document.setContent(&implXML)) {
\r
678 throw(Exception(IMPLFILE_NOACCESS));
\r
682 QDomElement implRoot = document.documentElement();
\r
683 QString refXml = implRoot.attribute("ref_name","none");
\r
684 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
685 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
687 impl->loadPatterns(implRoot);
\r
692 availableImplementations.append(impl);
\r
694 ReferenceBlock* ref = NULL;
\r
695 if (! refMd5.isEmpty()) {
\r
696 ref = searchBlockByMd5(refMd5);
\r
699 ref = searchBlockByXml(refXml);
\r
702 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
705 ref->addImplementation(impl);
\r
706 impl->setReference(ref);
\r
707 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
709 cout << "OK" << endl;
\r
714 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
716 cout << "loading implementations from lib" << endl;
\r
718 BlockImplementation* impl = NULL;
\r
719 ReferenceBlock* ref = NULL;
\r
720 for(int i=0;i<availableImplementations.size();i++) {
\r
721 impl = availableImplementations.at(i);
\r
724 availableImplementations.clear();
\r
726 QFile libFile(implLib);
\r
727 if (!libFile.open(QIODevice::ReadOnly)) {
\r
728 throw(Exception(IMPLFILE_NOACCESS));
\r
730 QDataStream in(&libFile);
\r
737 for(int i=0;i<nbImpls;i++) {
\r
738 impl = new BlockImplementation("");
\r
740 availableImplementations.append(impl);
\r
741 QString refMd5 = impl->getReferenceMd5();
\r
742 QString refXml = impl->getReferenceXml();
\r
744 if (! refMd5.isEmpty()) {
\r
745 ref = searchBlockByMd5(refMd5);
\r
748 ref = searchBlockByXml(refXml);
\r
751 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
754 ref->addImplementation(impl);
\r
755 impl->setReference(ref);
\r
756 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
762 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
764 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
765 QFile libFile(implLib);
\r
766 if (!libFile.open(QIODevice::WriteOnly)) {
\r
767 throw(Exception(IMPLFILE_NOACCESS));
\r
769 QDataStream out(&libFile);
\r
771 out.setVersion(QDataStream::Qt_5_0);
\r
773 QByteArray blockData;
\r
774 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
776 toWrite << availableImplementations.size();
\r
777 for(int i=0;i<availableImplementations.size();i++) {
\r
778 BlockImplementation* impl = availableImplementations.at(i);
\r
787 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
788 availableBlocks.append(block);
\r
789 foreach (int id,block->getCategories()) {
\r
790 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
791 BlockCategory* cat = categoryTree->searchCategory(id);
\r
792 cat->blocks.append(block);
\r
796 void Parameters::parametersValidation() {
\r
797 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
799 if(!blocksToConfigure.isEmpty()){
\r
800 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
805 void Parameters::connectionsValidation() {
\r
807 #ifdef DEBUG_INCLFUN
\r
809 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
810 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
812 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
813 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
815 inter->setWidth(connectedInter->getWidth());
\r
816 interfaceToValidate->push(connectedInter);
\r
822 while(!interfaceToValidate->isEmpty()){
\r
823 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
826 catch(Exception e){
\r
827 cerr << e.getMessage().toStdString() << endl;
\r
832 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
834 #ifdef DEBUG_INCLFUN
\r
836 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
837 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
839 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
840 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
841 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
842 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
846 return *blocksToConfigure;
\r
851 void Parameters::updateToolbar() {
\r
852 int nb = currentScene->getBoxItems().length();
\r
853 for(int i = 0; i<nb; i++){
\r
854 if(currentScene->getBoxItems().at(i)->isSelected()){
\r
855 currentScene->getGroupWidget()->enableGroupButton(true);
\r
859 currentScene->getGroupWidget()->enableGroupButton(false);
\r
863 void Parameters::updateIds() {
\r
865 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
866 are in the correct ordre when saving/loading a project
\r
869 int countIface = 1;
\r
870 QList<GroupScene *> fifo;
\r
871 fifo.append(topScene);
\r
872 while (!fifo.isEmpty()) {
\r
873 GroupScene* scene = fifo.takeFirst();
\r
874 countItem = scene->setItemsId(countItem);
\r
875 countIface = scene->setInterfacesId(countIface);
\r
876 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
883 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
884 foreach(ReferenceBlock *block, availableBlocks){
\r
885 if(block->getXmlFile().contains(xmlName))
\r
891 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
892 foreach(ReferenceBlock *block, availableBlocks){
\r
893 if(block->getHashMd5() == sumMd5)
\r
899 void Parameters::save(QString confFile) {
\r
901 //#ifdef DEBUG_INCLFUN
\r
904 QList<ConnectionItem*> allConnections;
\r
905 QFile file(confFile);
\r
906 if(file.open(QIODevice::WriteOnly)){
\r
908 QXmlStreamWriter writer(&file);
\r
910 writer.setAutoFormatting(true);
\r
911 writer.writeStartDocument();
\r
913 writer.writeStartElement("blast_project");
\r
914 writer.writeStartElement("scenes");
\r
916 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
918 // cross the scene level by level using a FIFO
\r
919 QList<GroupScene*> fifoScene;
\r
920 fifoScene.append(topScene);
\r
923 while (!fifoScene.isEmpty()) {
\r
924 scene = fifoScene.takeFirst();
\r
925 scene->save(writer);
\r
926 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
927 fifoScene.append(s);
\r
930 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
931 allConnections.append(item);
\r
934 writer.writeEndElement(); //</scenes>
\r
936 writer.writeStartElement("connections");
\r
937 foreach(ConnectionItem* item, allConnections) {
\r
939 writer.writeStartElement("connection");
\r
941 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
942 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
944 writer.writeEndElement();
\r
947 writer.writeEndElement(); //</connections>
\r
948 writer.writeEndElement(); //</blast_project
\r
950 writer.writeEndDocument();
\r
953 unsaveModif = false;
\r
958 void Parameters::setArrowPathes() {
\r
959 QPainterPath _inArrow;
\r
960 _inArrow.lineTo(arrowLineLength,0);
\r
961 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
962 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
963 _inArrow.lineTo(arrowLineLength,0);
\r
964 _inArrow.closeSubpath();
\r
965 inArrow = _inArrow;
\r
967 QPainterPath _outArrow;
\r
968 _outArrow.lineTo(arrowLineLength,0);
\r
969 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
970 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
971 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
972 _outArrow.lineTo(arrowLineLength,0);
\r
973 _outArrow.closeSubpath();
\r
974 outArrow = _outArrow;
\r
978 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
980 if (scene->getId() == id) return scene;
\r
981 GroupScene* sc = NULL;
\r
983 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
984 sc = searchSceneById(id,s);
\r
985 if (sc != NULL) return sc;
\r
990 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
992 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
994 GroupItem* item = NULL;
\r
995 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
996 item = searchGroupItemById(id,s);
\r
997 if (item != NULL) return item;
\r
1002 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1004 foreach(BoxItem *item, scene->getBoxItems()){
\r
1005 if(item->getId() == id){
\r
1010 BoxItem* item = NULL;
\r
1011 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1012 item = searchBlockItemById(id,s);
\r
1013 if (item != NULL) return item;
\r
1018 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1020 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1021 if(item->getId() == id){
\r
1025 foreach(BoxItem *block, scene->getBoxItems()){
\r
1026 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1027 if(item->getId() == id){
\r
1032 InterfaceItem* item = NULL;
\r
1033 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1034 item = searchInterfaceItemById(id,s);
\r
1035 if (item != NULL) return item;
\r