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 "SourceItem.h"
\r
13 #include "InterfaceItem.h"
\r
14 #include "ConnectionItem.h"
\r
17 #include "ReferenceBlock.h"
\r
18 #include "GroupBlock.h"
\r
19 #include "FunctionalBlock.h"
\r
20 #include "ReferenceInterface.h"
\r
21 #include "GroupInterface.h"
\r
22 #include "FunctionalInterface.h"
\r
24 #include "Exception.h"
\r
25 #include "BlocksToConfigureWidget.h"
\r
27 Parameters::Parameters() {
\r
28 categoryTree = NULL;
\r
31 arrowLineLength = 10;
\r
33 defaultBlockWidth = 100;
\r
34 defaultBlockHeight = 100;
\r
35 defaultBlockFont = QFont("Arial");
\r
36 defaultBlockFontSize = 12;
\r
40 sceneMode = MODE_EDITION; // default mode
\r
41 editState = Parameters::EditNoOperation;
\r
43 unsaveModif = false;
\r
44 isRstClkShown = false;
\r
46 projectPath = QDir::currentPath();
\r
48 validityExtension = "_enb";
\r
51 Parameters::~Parameters() {
\r
55 void Parameters::clear() {
\r
56 delete categoryTree;
\r
57 QListIterator<ReferenceBlock *> iter(availableBlocks);
\r
58 while(iter.hasNext()) {
\r
59 ReferenceBlock* item = iter.next();
\r
62 availableBlocks.clear();
\r
66 Graph* Parameters::createGraph() {
\r
67 graph = new Graph();
\r
71 void Parameters::destroyGraph() {
\r
75 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
\r
77 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
79 if (blockCat == NULL) return NULL;
\r
80 ReferenceBlock* ref = blockCat->getBlock(idBlock);
\r
86 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
87 // opening configFile
\r
88 QFile xmlFile(xmlFileName);
\r
89 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
90 if (fileType == Configuration) {
\r
91 throw(Exception(CONFIGFILE_NOACCESS));
\r
93 else if (fileType == Reference) {
\r
94 throw(Exception(BLOCKFILE_NOACCESS));
\r
96 else if (fileType == Implementation) {
\r
97 throw(Exception(IMPLFILE_NOACCESS));
\r
99 else if (fileType == Project) {
\r
100 throw(Exception(PROJECTFILE_NOACCESS));
\r
104 QFile xsdFile(xsdFileName);
\r
105 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
107 if (fileType == Configuration) {
\r
108 throw(Exception(CONFIGFILE_NOACCESS));
\r
110 else if (fileType == Reference) {
\r
111 throw(Exception(BLOCKFILE_NOACCESS));
\r
113 else if (fileType == Implementation) {
\r
114 throw(Exception(IMPLFILE_NOACCESS));
\r
116 else if (fileType == Project) {
\r
117 throw(Exception(PROJECTFILE_NOACCESS));
\r
121 if(validate(xmlFile,xsdFile) == false) {
\r
124 if (fileType == Configuration) {
\r
125 throw(Exception(CONFIGFILE_CORRUPTED));
\r
127 else if (fileType == Reference) {
\r
128 throw(Exception(BLOCKFILE_CORRUPTED));
\r
130 else if (fileType == Implementation) {
\r
131 throw(Exception(IMPLFILE_CORRUPTED));
\r
133 else if (fileType == Project) {
\r
134 throw(Exception(PROJECTFILE_CORRUPTED));
\r
141 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
143 // 2 files are supposed to be already opened
\r
146 if(! schema.load(&fileSchema)){
\r
147 cout << "invalid schema" << endl;
\r
151 QXmlSchemaValidator validator(schema);
\r
153 if(! validator.validate(&fileXml)){
\r
154 cout << "invalid xml" << endl;
\r
160 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
163 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
165 catch(Exception err) {
\r
169 QFile projectFile(projectFileName);
\r
170 QDomDocument doc("projectFile");
\r
172 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
173 throw(Exception(PROJECTFILE_NOACCESS));
\r
175 if(!doc.setContent(&projectFile)) {
\r
176 projectFile.close();
\r
177 throw(Exception(PROJECTFILE_CORRUPTED));
\r
179 projectFile.close();
\r
181 QDomElement root = doc.documentElement();
\r
186 GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
\r
189 GroupWidget* groupWidget = NULL;
\r
190 GroupItem *groupItem = NULL;
\r
191 GroupBlock *groupBlock = NULL;
\r
193 GroupWidget* topGroup = NULL;
\r
194 /**********************************************************
\r
195 1 : getting scene and creating associated group widgets
\r
196 ***********************************************************/
\r
197 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
199 int maxIdScene = -1;
\r
200 for(int i=0; i<scenesNodes.length(); i++) {
\r
201 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
202 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
203 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
204 if (idScene > maxIdScene) maxIdScene = idScene;
\r
205 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
206 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
208 if (idUpperScene == -1) {
\r
209 topGroup = dispatcher->createTopScene();
\r
210 topScene->setId(idScene);
\r
211 groupItem = topScene->getGroupItem();
\r
212 cout << "top group added to scene n°" << idScene << endl;
\r
215 cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
\r
216 GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
\r
217 groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);
\r
218 groupWidget->getScene()->setId(idScene);
\r
219 groupItem = groupWidget->getScene()->getGroupItem();
\r
221 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
222 /**********************************************************
\r
223 1.1 : getting the group item of each scene
\r
224 ***********************************************************/
\r
225 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
227 groupItem->load(groupItemNode);
\r
229 catch(Exception err) {
\r
233 if (idUpperScene != -1) {
\r
234 groupWidget->setWindowTitle(groupBlock->getName());
\r
235 groupWidget->show();
\r
236 cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;
\r
239 dispatcher->setSceneCounter(maxIdScene+1);
\r
240 cout << "groupItems loaded and windows created succefully!" << endl;
\r
242 /**********************************************************
\r
243 2 : getting the functional blocks of each scene
\r
244 ***********************************************************/
\r
246 for(int i=0; i<scenesNodes.length(); i++){
\r
247 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
248 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
249 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
250 cout << "SCENE : " << idScene << endl;
\r
251 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
253 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
254 /**********************************************************
\r
255 2.1 : getting sources if it is top scene
\r
256 ***********************************************************/
\r
257 if (currentScene->isTopScene()) {
\r
258 QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");
\r
259 cout << "top scene has " << sourceNodes.length() << " sources" << endl;
\r
260 for(int j=0; j<sourceNodes.length(); j++) {
\r
261 QDomElement currentSBNode = sourceNodes.at(j).toElement();
\r
262 SourceItem* sourceItem = new SourceItem(dispatcher,this);
\r
264 sourceItem->load(currentSBNode);
\r
266 catch(Exception err) {
\r
269 cout << "source item has been read, add it to the scene" << endl;
\r
270 // add the block to the GroupScene
\r
271 currentScene->addSourceItem(sourceItem);
\r
274 /**********************************************************
\r
275 2.2 : getting functional blocks
\r
276 ***********************************************************/
\r
277 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
279 for(int j=0; j<functionalBlockNodes.length(); j++) {
\r
280 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
281 BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());
\r
283 funcItem->loadFunctional(currentFBNode);
\r
285 catch(Exception err) {
\r
288 // add the block to the GroupScene
\r
289 currentScene->addBoxItem(funcItem);
\r
292 cout << "functional blocks loaded and created succefully!" << endl;
\r
294 /**********************************************************
\r
295 3 : set the BoxItem that represents a GroupItem in a child scene
\r
296 ***********************************************************/
\r
298 for(int i=0; i<scenesNodes.length(); i++){
\r
299 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
300 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
301 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
302 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
303 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
305 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
307 for(int j=0; j<biGroupNodes.length(); j++){
\r
308 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
310 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
311 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
313 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
314 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
316 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
317 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
318 int posX = positionStr.at(0).toInt(&ok);
\r
319 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
320 int posY = positionStr.at(1).toInt(&ok);
\r
321 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
323 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
324 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
325 int dimX = dimensionStr.at(0).toInt(&ok);
\r
326 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
327 int dimY = dimensionStr.at(1).toInt(&ok);
\r
328 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
330 // get the GroupItem already created and set at phase 1
\r
331 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
332 BoxItem* upperItem = NULL;
\r
333 if(insideGroup == NULL) cout << "group null" << endl;
\r
334 // now search within the scene which BoxItem has a childItem that is = to insideGroup
\r
335 QList<BoxItem *> lst = currentScene->getBoxItems();
\r
336 foreach(BoxItem* item, lst) {
\r
337 if (item->getChildGroupItem() == insideGroup) {
\r
342 if (upperItem == NULL) {
\r
343 throw(Exception(PROJECTFILE_CORRUPTED));
\r
346 upperItem->setId(id);
\r
347 upperItem->setPos(posX,posY);
\r
348 upperItem->setDimension(dimX,dimY);
\r
350 // set interfaces of this BoxItem
\r
351 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
353 for(int k=0; k<interfaceNodes.length(); k++){
\r
354 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
356 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
357 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
359 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
360 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
362 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
363 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
364 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
366 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
367 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
369 ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;
\r
370 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
\r
371 ifaceItem->setId(id);
\r
372 upperItem->addInterfaceItem(ifaceItem);
\r
376 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
378 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
380 for(int i=0; i<connectionNodes.length(); i++){
\r
381 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
383 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
384 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
386 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
387 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
390 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
391 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
393 if(iface1 != NULL && iface2 != NULL){
\r
394 dispatcher->createConnection(iface1,iface2);
\r
396 cout << "interfaces not found, connect canceled!" << endl;
\r
399 cout << "connections loaded and created succefully!" << endl;
\r
404 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
407 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
409 catch(Exception err) {
\r
414 // opening configFile
\r
415 QFile configFile(confFile);
\r
416 // reading in into QDomDocument
\r
417 QDomDocument document("configFile");
\r
419 if (!configFile.open(QIODevice::ReadOnly)) {
\r
420 throw(Exception(CONFIGFILE_NOACCESS));
\r
422 if (!document.setContent(&configFile)) {
\r
423 configFile.close();
\r
424 throw(Exception(CONFIGFILE_NOACCESS));
\r
426 configFile.close();
\r
428 //Get the root element
\r
429 QDomElement config = document.documentElement();
\r
431 QDomElement eltCat = config.firstChildElement("categories");
\r
433 categoryTree = new BlockLibraryTree();
\r
434 categoryTree->load(eltCat);
\r
436 catch(Exception err) {
\r
440 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
441 refLib = eltReferences.attribute("lib_file","none");
\r
442 cout << "references lib : " << qPrintable(refLib) << endl;
\r
444 QString nbPathesStr;
\r
445 nbPathesStr = eltReferences.attribute("nb","none");
\r
446 nbPathes = nbPathesStr.toInt(&ok);
\r
447 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
448 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
450 for(int i=0;i<listBlockDir.size();i++) {
\r
451 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
452 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
453 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
454 QString path = eltBlockDir.attribute("path","none");
\r
455 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
456 refPathes.append(path);
\r
457 cout << "references path : " << qPrintable(path) << endl;
\r
460 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
461 implLib = eltImpl.attribute("lib_file","none");
\r
462 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
463 nbPathesStr = eltImpl.attribute("nb","none");
\r
464 nbPathes = nbPathesStr.toInt(&ok);
\r
465 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
466 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
468 for(int i=0;i<listImplDir.size();i++) {
\r
469 QDomNode nodeImplDir = listImplDir.at(i);
\r
470 QDomElement eltImplDir = nodeImplDir.toElement();
\r
471 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
472 QString path = eltImplDir.attribute("path","none");
\r
473 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
474 implPathes.append(path);
\r
475 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
477 // getting elt = the element <defaults>
\r
478 // for each child element, initialize the associated attributes of Parameters
\r
480 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
482 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
483 QString attributeStr = eltBlocks.attribute("width", "none");
\r
484 defaultBlockWidth = attributeStr.toInt(&ok);
\r
485 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
486 attributeStr = eltBlocks.attribute("height", "none");
\r
487 defaultBlockHeight = attributeStr.toInt(&ok);
\r
488 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
489 attributeStr = eltBlocks.attribute("font_size", "none");
\r
490 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
491 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
492 attributeStr = eltBlocks.attribute("font", "none");
\r
493 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
494 defaultBlockFontName = attributeStr;
\r
495 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
497 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
498 attributeStr = eltInterfaces.attribute("width", "none");
\r
499 arrowWidth = attributeStr.toInt(&ok);
\r
500 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
501 attributeStr = eltInterfaces.attribute("height", "none");
\r
502 arrowHeight = attributeStr.toInt(&ok);
\r
503 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
504 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
505 arrowLineLength = attributeStr.toInt(&ok);
\r
506 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
507 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
508 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
509 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
510 attributeStr = eltInterfaces.attribute("font", "none");
\r
511 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
512 defaultIfaceFontName = attributeStr;
\r
513 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
515 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
516 attributeStr = eltConnections.attribute("gaplength", "none");
\r
517 connGapLength = attributeStr.toInt(&ok);
\r
518 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
521 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
522 cout << "load references from xml" << endl;
\r
523 for(int i=0;i<refPathes.size();i++) {
\r
524 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
525 QDir dir(refPathes.at(i));
\r
526 QStringList filter;
\r
528 dir.setNameFilters(filter);
\r
529 QStringList list = dir.entryList();
\r
530 for(int j=0;j<list.size();j++) {
\r
531 QString fileName = dir.absolutePath();
\r
532 fileName.append("/"+list.at(j));
\r
534 QFile blockXML(fileName);
\r
535 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
536 throw(Exception(BLOCKFILE_NOACCESS));
\r
538 QTextStream in(&blockXML);
\r
539 QString line = in.readLine();
\r
540 line = in.readLine();
\r
542 if (!line.contains("<block>")) {
\r
549 validateXmlFile(fileName,"reference.xsd",Reference);
\r
551 catch(Exception err) {
\r
555 // reading in into QDomDocument
\r
556 QDomDocument document ("FileXML");
\r
557 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
558 throw(Exception(BLOCKFILE_NOACCESS));
\r
560 if (!document.setContent(&blockXML)) {
\r
562 throw(Exception(BLOCKFILE_NOACCESS));
\r
566 QDomElement blockRoot = document.documentElement();
\r
567 QString name = blockRoot.tagName();
\r
568 if (name == "block") {
\r
570 cout << "xml:" << fileName.toStdString() << endl;
\r
571 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
573 b->load(blockRoot);
\r
579 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
581 availableBlocks.append(b);
\r
582 foreach (int id,b->getCategories()) {
\r
583 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
584 BlockCategory* cat = categoryTree->searchCategory(id);
\r
585 cat->blocks.append(b);
\r
592 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
594 cout << "loading references from lib" << endl;
\r
596 // removing blocks from category tree if they exist
\r
597 categoryTree->clearBlocks();
\r
598 // deleting existings blocks
\r
599 ReferenceBlock* b = NULL;
\r
600 for(int i=0;i<availableBlocks.size();i++) {
\r
601 b = availableBlocks.at(i);
\r
604 availableBlocks.clear();
\r
606 QFile libFile(refLib);
\r
607 if (!libFile.open(QIODevice::ReadOnly)) {
\r
608 throw(Exception(BLOCKFILE_NOACCESS));
\r
610 QDataStream in(&libFile);
\r
617 for(int i=0;i<nbBlocks;i++) {
\r
618 b = new ReferenceBlock("");
\r
620 availableBlocks.append(b);
\r
621 foreach (int id,b->getCategories()) {
\r
622 BlockCategory* cat = categoryTree->searchCategory(id);
\r
623 cat->blocks.append(b);
\r
629 void Parameters::saveReferencesToLib() throw(Exception) {
\r
631 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
632 QFile libFile(refLib);
\r
633 if (!libFile.open(QIODevice::WriteOnly)) {
\r
634 throw(Exception(BLOCKFILE_NOACCESS));
\r
636 QDataStream out(&libFile);
\r
638 out.setVersion(QDataStream::Qt_5_0);
\r
640 QByteArray blockData;
\r
641 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
643 toWrite << availableBlocks.size();
\r
644 for(int i=0;i<availableBlocks.size();i++) {
\r
645 ReferenceBlock* b = availableBlocks.at(i);
\r
655 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
657 for(int i=0;i<implPathes.size();i++) {
\r
658 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
659 QDir dir(implPathes.at(i));
\r
660 QStringList filter;
\r
662 dir.setNameFilters(filter);
\r
663 QStringList list = dir.entryList();
\r
664 for(int j=0;j<list.size();j++) {
\r
665 QString fileName = dir.absolutePath();
\r
666 fileName.append("/"+list.at(j));
\r
668 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
669 QFile implXML(fileName);
\r
670 if (!implXML.open(QIODevice::ReadOnly)) {
\r
671 throw(Exception(IMPLFILE_NOACCESS));
\r
673 QTextStream in(&implXML);
\r
674 QString line = in.readLine();
\r
675 line = in.readLine();
\r
677 if (!line.contains("<block_impl")) {
\r
683 cout << "OK" << endl;
\r
684 cout << "reading " << qPrintable(fileName) << " content ...";
\r
687 validateXmlFile(fileName,"implementation.xsd",Implementation);
\r
689 catch(Exception e) {
\r
693 // reading in into QDomDocument
\r
694 QDomDocument document ("FileXML");
\r
695 if (!implXML.open(QIODevice::ReadOnly)) {
\r
696 throw(Exception(IMPLFILE_NOACCESS));
\r
698 cout << "OK" << endl;
\r
699 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
700 if (!document.setContent(&implXML)) {
\r
702 throw(Exception(IMPLFILE_NOACCESS));
\r
706 QDomElement implRoot = document.documentElement();
\r
707 QString refXml = implRoot.attribute("ref_name","none");
\r
708 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
709 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
711 impl->loadPatterns(implRoot);
\r
716 availableImplementations.append(impl);
\r
718 ReferenceBlock* ref = NULL;
\r
719 if (! refMd5.isEmpty()) {
\r
720 ref = searchBlockByMd5(refMd5);
\r
723 ref = searchBlockByXml(refXml);
\r
726 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
729 ref->addImplementation(impl);
\r
730 impl->setReference(ref);
\r
731 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
733 cout << "OK" << endl;
\r
738 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
740 cout << "loading implementations from lib" << endl;
\r
742 BlockImplementation* impl = NULL;
\r
743 ReferenceBlock* ref = NULL;
\r
744 for(int i=0;i<availableImplementations.size();i++) {
\r
745 impl = availableImplementations.at(i);
\r
748 availableImplementations.clear();
\r
750 QFile libFile(implLib);
\r
751 if (!libFile.open(QIODevice::ReadOnly)) {
\r
752 throw(Exception(IMPLFILE_NOACCESS));
\r
754 QDataStream in(&libFile);
\r
761 for(int i=0;i<nbImpls;i++) {
\r
762 impl = new BlockImplementation("");
\r
764 availableImplementations.append(impl);
\r
765 QString refMd5 = impl->getReferenceMd5();
\r
766 QString refXml = impl->getReferenceXml();
\r
768 if (! refMd5.isEmpty()) {
\r
769 ref = searchBlockByMd5(refMd5);
\r
772 ref = searchBlockByXml(refXml);
\r
775 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
778 ref->addImplementation(impl);
\r
779 impl->setReference(ref);
\r
780 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
786 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
788 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
789 QFile libFile(implLib);
\r
790 if (!libFile.open(QIODevice::WriteOnly)) {
\r
791 throw(Exception(IMPLFILE_NOACCESS));
\r
793 QDataStream out(&libFile);
\r
795 out.setVersion(QDataStream::Qt_5_0);
\r
797 QByteArray blockData;
\r
798 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
800 toWrite << availableImplementations.size();
\r
801 for(int i=0;i<availableImplementations.size();i++) {
\r
802 BlockImplementation* impl = availableImplementations.at(i);
\r
811 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
812 availableBlocks.append(block);
\r
813 foreach (int id,block->getCategories()) {
\r
814 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
815 BlockCategory* cat = categoryTree->searchCategory(id);
\r
816 cat->blocks.append(block);
\r
820 void Parameters::parametersValidation() {
\r
821 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
823 if(!blocksToConfigure.isEmpty()){
\r
824 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
829 void Parameters::connectionsValidation() {
\r
831 #ifdef DEBUG_INCLFUN
\r
833 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
834 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
836 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
837 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
839 inter->setWidth(connectedInter->getWidth());
\r
840 interfaceToValidate->push(connectedInter);
\r
846 while(!interfaceToValidate->isEmpty()){
\r
847 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
850 catch(Exception e){
\r
851 cerr << e.getMessage().toStdString() << endl;
\r
856 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
858 #ifdef DEBUG_INCLFUN
\r
860 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
861 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
863 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
864 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
865 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
866 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
870 return *blocksToConfigure;
\r
875 void Parameters::updateToolbar() {
\r
876 int nb = currentScene->getBoxItems().length();
\r
877 for(int i = 0; i<nb; i++){
\r
878 if(currentScene->getBoxItems().at(i)->isSelected()){
\r
879 currentScene->getGroupWidget()->enableGroupButton(true);
\r
883 currentScene->getGroupWidget()->enableGroupButton(false);
\r
887 void Parameters::updateIds() {
\r
889 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
890 are in the correct ordre when saving/loading a project
\r
893 int countIface = 1;
\r
894 QList<GroupScene *> fifo;
\r
895 fifo.append(topScene);
\r
896 while (!fifo.isEmpty()) {
\r
897 GroupScene* scene = fifo.takeFirst();
\r
898 countItem = scene->setItemsId(countItem);
\r
899 countIface = scene->setInterfacesId(countIface);
\r
900 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
907 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
908 foreach(ReferenceBlock *block, availableBlocks){
\r
909 if(block->getXmlFile().contains(xmlName))
\r
915 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
916 foreach(ReferenceBlock *block, availableBlocks){
\r
917 if(block->getHashMd5() == sumMd5)
\r
923 void Parameters::save(QString confFile) {
\r
925 //#ifdef DEBUG_INCLFUN
\r
928 QList<ConnectionItem*> allConnections;
\r
929 QFile file(confFile);
\r
930 if(file.open(QIODevice::WriteOnly)){
\r
932 QXmlStreamWriter writer(&file);
\r
934 writer.setAutoFormatting(true);
\r
935 writer.writeStartDocument();
\r
937 writer.writeStartElement("blast_project");
\r
938 writer.writeStartElement("scenes");
\r
940 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
942 // cross the scene level by level using a FIFO
\r
943 QList<GroupScene*> fifoScene;
\r
944 fifoScene.append(topScene);
\r
947 while (!fifoScene.isEmpty()) {
\r
948 scene = fifoScene.takeFirst();
\r
949 scene->save(writer);
\r
950 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
951 fifoScene.append(s);
\r
954 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
955 allConnections.append(item);
\r
958 writer.writeEndElement(); //</scenes>
\r
960 writer.writeStartElement("connections");
\r
961 foreach(ConnectionItem* item, allConnections) {
\r
963 writer.writeStartElement("connection");
\r
965 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
966 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
968 writer.writeEndElement();
\r
971 writer.writeEndElement(); //</connections>
\r
972 writer.writeEndElement(); //</blast_project
\r
974 writer.writeEndDocument();
\r
977 unsaveModif = false;
\r
982 void Parameters::setArrowPathes() {
\r
983 QPainterPath _inArrow;
\r
984 _inArrow.lineTo(arrowLineLength,0);
\r
985 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
986 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
987 _inArrow.lineTo(arrowLineLength,0);
\r
988 _inArrow.closeSubpath();
\r
989 inArrow = _inArrow;
\r
991 QPainterPath _outArrow;
\r
992 _outArrow.lineTo(arrowLineLength,0);
\r
993 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
994 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
995 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
996 _outArrow.lineTo(arrowLineLength,0);
\r
997 _outArrow.closeSubpath();
\r
998 outArrow = _outArrow;
\r
1002 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
1004 if (scene->getId() == id) return scene;
\r
1005 GroupScene* sc = NULL;
\r
1007 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1008 sc = searchSceneById(id,s);
\r
1009 if (sc != NULL) return sc;
\r
1014 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
1016 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
1018 GroupItem* item = NULL;
\r
1019 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1020 item = searchGroupItemById(id,s);
\r
1021 if (item != NULL) return item;
\r
1026 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1028 foreach(BoxItem *item, scene->getBoxItems()){
\r
1029 if(item->getId() == id){
\r
1034 BoxItem* item = NULL;
\r
1035 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1036 item = searchBlockItemById(id,s);
\r
1037 if (item != NULL) return item;
\r
1042 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1044 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1045 if(item->getId() == id){
\r
1049 if (scene->isTopScene()) {
\r
1050 foreach(SourceItem *block, scene->getSourceItems()){
\r
1051 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1052 if(item->getId() == id){
\r
1058 foreach(BoxItem *block, scene->getBoxItems()){
\r
1059 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1060 if(item->getId() == id){
\r
1065 InterfaceItem* item = NULL;
\r
1066 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1067 item = searchInterfaceItemById(id,s);
\r
1068 if (item != NULL) return item;
\r