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
82 FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {
\r
84 ReferenceBlock* ref = block->getReference();
\r
85 GroupBlock* group = AB_TO_GRP(block->getParent());
\r
87 // adding to the graph
\r
88 FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref);
\r
92 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
93 // opening configFile
\r
94 QFile xmlFile(xmlFileName);
\r
95 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
96 if (fileType == Configuration) {
\r
97 throw(Exception(CONFIGFILE_NOACCESS));
\r
99 else if (fileType == Reference) {
\r
100 throw(Exception(BLOCKFILE_NOACCESS));
\r
102 else if (fileType == Implementation) {
\r
103 throw(Exception(IMPLFILE_NOACCESS));
\r
105 else if (fileType == Project) {
\r
106 throw(Exception(PROJECTFILE_NOACCESS));
\r
110 QFile xsdFile(xsdFileName);
\r
111 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
113 if (fileType == Configuration) {
\r
114 throw(Exception(CONFIGFILE_NOACCESS));
\r
116 else if (fileType == Reference) {
\r
117 throw(Exception(BLOCKFILE_NOACCESS));
\r
119 else if (fileType == Implementation) {
\r
120 throw(Exception(IMPLFILE_NOACCESS));
\r
122 else if (fileType == Project) {
\r
123 throw(Exception(PROJECTFILE_NOACCESS));
\r
127 if(validate(xmlFile,xsdFile) == false) {
\r
130 if (fileType == Configuration) {
\r
131 throw(Exception(CONFIGFILE_CORRUPTED));
\r
133 else if (fileType == Reference) {
\r
134 throw(Exception(BLOCKFILE_CORRUPTED));
\r
136 else if (fileType == Implementation) {
\r
137 throw(Exception(IMPLFILE_CORRUPTED));
\r
139 else if (fileType == Project) {
\r
140 throw(Exception(PROJECTFILE_CORRUPTED));
\r
147 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
149 // 2 files are supposed to be already opened
\r
152 if(! schema.load(&fileSchema)){
\r
153 cout << "invalid schema" << endl;
\r
157 QXmlSchemaValidator validator(schema);
\r
159 if(! validator.validate(&fileXml)){
\r
160 cout << "invalid xml" << endl;
\r
166 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
169 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
171 catch(Exception err) {
\r
175 QFile projectFile(projectFileName);
\r
176 QDomDocument doc("projectFile");
\r
178 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
179 throw(Exception(PROJECTFILE_NOACCESS));
\r
181 if(!doc.setContent(&projectFile)) {
\r
182 projectFile.close();
\r
183 throw(Exception(PROJECTFILE_CORRUPTED));
\r
185 projectFile.close();
\r
187 QDomElement root = doc.documentElement();
\r
192 void Parameters::loadProject(QDomElement root) {
\r
194 #ifdef DEBUG_INCLFUN
\r
197 GroupWidget* groupWidget = NULL;
\r
198 GroupItem *groupItem = NULL;
\r
199 GroupBlock *groupBlock = NULL;
\r
201 /**********************************************************
\r
202 1 : getting scene and creating associated group widgets
\r
203 ***********************************************************/
\r
204 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
206 for(int i=0; i<scenesNodes.length(); i++) {
\r
207 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
208 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
209 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
210 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
211 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
213 if (idUpperScene == -1) {
\r
214 dispatcher->createTopScene();
\r
215 topScene->setId(idScene);
\r
216 groupItem = topScene->getGroupItem();
\r
217 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
218 cout << "top group added to scene n°" << idScene << endl;
\r
221 GroupScene* scene = searchSceneById(idUpperScene, topScene);
\r
222 GroupWidget* parent = scene->getGroupWindow();
\r
223 groupWidget = dispatcher->createChildScene(parent);
\r
224 groupItem = groupWidget->getScene()->getGroupItem();
\r
225 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
227 /**********************************************************
\r
228 1.1 : getting the group item
\r
229 ***********************************************************/
\r
230 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
232 int id = groupItemNode.attribute("id","none").toInt(&ok);
\r
233 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
235 QString name = groupItemNode.attribute("name","none");
\r
236 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
238 QStringList positionStr = groupItemNode.attribute("position","none").split(",");
\r
239 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
240 int posX = positionStr.at(0).toInt(&ok);
\r
241 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
242 int posY = positionStr.at(1).toInt(&ok);
\r
243 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
245 QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");
\r
246 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
247 int dimX = dimensionStr.at(0).toInt(&ok);
\r
248 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
249 int dimY = dimensionStr.at(1).toInt(&ok);
\r
250 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
252 groupItem->setId(id);
\r
253 groupItem->setPos(posX,posY);
\r
254 groupItem->setDimension(dimX,dimY);
\r
255 groupBlock->setName(name);
\r
257 if (idUpperScene != -1) {
\r
258 groupWidget->setWindowTitle(groupBlock->getName());
\r
259 groupWidget->show();
\r
261 cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;
\r
263 QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");
\r
264 for(int j=0; j<interfaces.length(); j++){
\r
265 QDomElement currentInterfaceNode = interfaces.at(j).toElement();
\r
267 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
268 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
270 QString name = currentInterfaceNode.attribute("name","none");
\r
271 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
273 QString levelStr = currentInterfaceNode.attribute("level","none");
\r
274 int level = AbstractInterface::getIntLevel(levelStr);
\r
275 if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
277 QString directionStr = currentInterfaceNode.attribute("direction","none");
\r
278 int direction = AbstractInterface::getIntDirection(directionStr);
\r
279 if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
281 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
282 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
283 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
285 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
286 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
288 GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);
\r
290 InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);
\r
291 interfaceItem->setId(id);
\r
293 groupBlock->addInterface(groupInterface);
\r
294 groupItem->addInterface(interfaceItem);
\r
295 cout << "interface add to " << groupBlock->getName().toStdString() << endl;
\r
299 cout << "groupItems loaded and windows created succefully!" << endl;
\r
302 for(int i=0; i<scenesNodes.length(); i++){
\r
303 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
304 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
305 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
306 cout << "SCENE : " << idScene << endl;
\r
307 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
309 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
311 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
313 for(int j=0; j<functionalBlockNodes.length(); j++){
\r
314 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
316 int id = currentFBNode.attribute("id","none").toInt(&ok);
\r
317 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
319 QString refXml = currentFBNode.attribute("ref_xml","none");
\r
320 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
322 QString refMd5 = currentFBNode.attribute("ref_md5","none");
\r
323 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
325 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
\r
327 QString name = currentFBNode.attribute("name","none");
\r
328 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
330 QStringList positionStr = currentFBNode.attribute("position","none").split(",");
\r
331 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
332 int posX = positionStr.at(0).toInt(&ok);
\r
333 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
334 int posY = positionStr.at(1).toInt(&ok);
\r
335 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
337 QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");
\r
338 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
339 int dimX = dimensionStr.at(0).toInt(&ok);
\r
340 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
341 int dimY = dimensionStr.at(1).toInt(&ok);
\r
342 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
344 AbstractBlock *reference;
\r
345 /*if(refMd5 != "none"){
\r
346 cout << "md5" << endl;
\r
347 reference = searchBlockByMd5(refMd5);
\r
349 else */if(refXml != "none"){
\r
350 cout << "xml" << endl;
\r
351 reference = searchBlockByXml(refXml);
\r
354 throw(Exception(PROJECTFILE_CORRUPTED));
\r
357 FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);
\r
358 functionalBlock->setName(name);
\r
360 ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);
\r
363 BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);
\r
364 blockItem->setPos(posX,posY);
\r
365 blockItem->setDimension(dimX,dimY);
\r
366 blockItem->setId(id);
\r
367 ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);
\r
368 currentScene->addItem(blockItem);
\r
369 currentScene->addBlockItem(blockItem);
\r
371 QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");
\r
373 for(int i=0; i<blockParamNodes.length(); i++){
\r
374 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
\r
376 QString name = currentBlockParamNode.attribute("name","none");
\r
377 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
379 QString value = currentBlockParamNode.attribute("value","none");
\r
380 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
382 QString context = currentBlockParamNode.attribute("context","none");
\r
383 if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
385 QString type = currentBlockParamNode.attribute("type","none");
\r
386 if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
389 BlockParameter *blockParam = new BlockParameter;
\r
390 blockParam->setName(name);
\r
391 blockParam->setValue(value);
\r
392 blockParam->setType(type);
\r
393 if(context == "constant") blockParam->setContext(BlockParameter::Constant);
\r
394 if(context == "user") blockParam->setContext(BlockParameter::User);
\r
395 if(context == "generic") blockParam->setContext(BlockParameter::Generic);
\r
396 if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);
\r
397 if(context == "port") blockParam->setContext(BlockParameter::Port);
\r
399 functionalBlock->addParameter(blockParam);
\r
403 QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");
\r
405 for(int i=0; i<interfaceNodes.length(); i++){
\r
407 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
\r
409 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
410 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
412 QString name = currentInterfaceNode.attribute("name","none");
\r
413 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
415 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
416 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
418 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
419 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
420 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
422 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
423 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
425 ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);
\r
426 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
\r
427 functionalBlock->addInterface(functionalInterface);
\r
428 functionalInterface->setName(refName);
\r
430 InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);
\r
431 interfaceItem->setId(id);
\r
432 interfaceItem->setName(name);
\r
434 blockItem->addInterface(interfaceItem);
\r
439 cout << "functionalBlocks loaded and created succefully!" << endl;
\r
442 for(int i=0; i<scenesNodes.length(); i++){
\r
443 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
444 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
445 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
446 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
447 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
449 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
451 for(int j=0; j<biGroupNodes.length(); j++){
\r
452 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
454 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
455 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
457 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
458 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
460 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
461 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
462 int posX = positionStr.at(0).toInt(&ok);
\r
463 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
464 int posY = positionStr.at(1).toInt(&ok);
\r
465 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
467 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
468 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
469 int dimX = dimensionStr.at(0).toInt(&ok);
\r
470 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
471 int dimY = dimensionStr.at(1).toInt(&ok);
\r
472 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
475 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
476 if(insideGroup == NULL) cout << "group null" << endl;
\r
477 BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);
\r
478 blockItem->setChildGroupItem(insideGroup);
\r
479 blockItem->setId(id);
\r
480 blockItem->setPos(posX,posY);
\r
481 blockItem->setDimension(dimX,dimY);
\r
483 ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);
\r
484 currentScene->addItem(blockItem);
\r
485 currentScene->addBlockItem(blockItem);
\r
487 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
489 for(int k=0; k<interfaceNodes.length(); k++){
\r
490 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
492 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
493 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
495 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
496 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
498 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
499 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
500 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
502 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
503 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
505 GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;
\r
506 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);
\r
507 ifaceItem->setId(id);
\r
508 blockItem->addInterface(ifaceItem);
\r
512 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
515 for(int i=0; i<scenesNodes.length(); i++){
\r
516 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
518 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
520 int id = groupItemNode.attribute("id","none").toInt(&ok);
\r
521 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
522 int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);
\r
523 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
525 BlockItem *currentItem = searchBlockItemById(id,topScene);
\r
526 GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);
\r
528 if(currentItem != NULL && upperItem != NULL){
\r
529 currentItem->setUpperItem(upperItem);
\r
533 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
535 for(int i=0; i<connectionNodes.length(); i++){
\r
536 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
538 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
539 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
541 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
542 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
545 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
546 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
548 if(iface1 != NULL && iface2 != NULL){
\r
549 dispatcher->connect(iface1,iface2);
\r
551 cout << "interfaces not found, connect canceled!" << endl;
\r
558 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
561 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
563 catch(Exception err) {
\r
568 // opening configFile
\r
569 QFile configFile(confFile);
\r
570 // reading in into QDomDocument
\r
571 QDomDocument document("configFile");
\r
573 if (!configFile.open(QIODevice::ReadOnly)) {
\r
574 throw(Exception(CONFIGFILE_NOACCESS));
\r
576 if (!document.setContent(&configFile)) {
\r
577 configFile.close();
\r
578 throw(Exception(CONFIGFILE_NOACCESS));
\r
580 configFile.close();
\r
582 //Get the root element
\r
583 QDomElement config = document.documentElement();
\r
585 QDomElement eltCat = config.firstChildElement("categories");
\r
587 categoryTree = new BlockLibraryTree();
\r
588 categoryTree->load(eltCat);
\r
590 catch(Exception err) {
\r
594 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
595 refLib = eltReferences.attribute("lib_file","none");
\r
596 cout << "references lib : " << qPrintable(refLib) << endl;
\r
598 QString nbPathesStr;
\r
599 nbPathesStr = eltReferences.attribute("nb","none");
\r
600 nbPathes = nbPathesStr.toInt(&ok);
\r
601 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
602 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
604 for(int i=0;i<listBlockDir.size();i++) {
\r
605 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
606 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
607 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
608 QString path = eltBlockDir.attribute("path","none");
\r
609 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
610 refPathes.append(path);
\r
611 cout << "references path : " << qPrintable(path) << endl;
\r
614 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
615 implLib = eltImpl.attribute("lib_file","none");
\r
616 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
617 nbPathesStr = eltImpl.attribute("nb","none");
\r
618 nbPathes = nbPathesStr.toInt(&ok);
\r
619 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
620 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
622 for(int i=0;i<listImplDir.size();i++) {
\r
623 QDomNode nodeImplDir = listImplDir.at(i);
\r
624 QDomElement eltImplDir = nodeImplDir.toElement();
\r
625 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
626 QString path = eltImplDir.attribute("path","none");
\r
627 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
628 implPathes.append(path);
\r
629 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
631 // getting elt = the element <defaults>
\r
632 // for each child element, initialize the associated attributes of Parameters
\r
634 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
636 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
637 QString attributeStr = eltBlocks.attribute("width", "none");
\r
638 defaultBlockWidth = attributeStr.toInt(&ok);
\r
639 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
640 attributeStr = eltBlocks.attribute("height", "none");
\r
641 defaultBlockHeight = attributeStr.toInt(&ok);
\r
642 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
643 attributeStr = eltBlocks.attribute("font_size", "none");
\r
644 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
645 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
646 attributeStr = eltBlocks.attribute("font", "none");
\r
647 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
648 defaultBlockFontName = attributeStr;
\r
649 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
651 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
652 attributeStr = eltInterfaces.attribute("width", "none");
\r
653 arrowWidth = attributeStr.toInt(&ok);
\r
654 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
655 attributeStr = eltInterfaces.attribute("height", "none");
\r
656 arrowHeight = attributeStr.toInt(&ok);
\r
657 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
658 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
659 arrowLineLength = attributeStr.toInt(&ok);
\r
660 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
661 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
662 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
663 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
664 attributeStr = eltInterfaces.attribute("font", "none");
\r
665 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
666 defaultIfaceFontName = attributeStr;
\r
667 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
669 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
670 attributeStr = eltConnections.attribute("gaplength", "none");
\r
671 connGapLength = attributeStr.toInt(&ok);
\r
672 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
675 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
676 cout << "load references from xml" << endl;
\r
677 for(int i=0;i<refPathes.size();i++) {
\r
678 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
679 QDir dir(refPathes.at(i));
\r
680 QStringList filter;
\r
682 dir.setNameFilters(filter);
\r
683 QStringList list = dir.entryList();
\r
684 for(int j=0;j<list.size();j++) {
\r
685 QString fileName = dir.absolutePath();
\r
686 fileName.append("/"+list.at(j));
\r
688 QFile blockXML(fileName);
\r
689 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
690 throw(Exception(BLOCKFILE_NOACCESS));
\r
692 QTextStream in(&blockXML);
\r
693 QString line = in.readLine();
\r
694 line = in.readLine();
\r
696 if (!line.contains("<block>")) {
\r
703 validateXmlFile(fileName,"block.xsd",Reference);
\r
705 catch(Exception err) {
\r
709 // reading in into QDomDocument
\r
710 QDomDocument document ("FileXML");
\r
711 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
712 throw(Exception(BLOCKFILE_NOACCESS));
\r
714 if (!document.setContent(&blockXML)) {
\r
716 throw(Exception(BLOCKFILE_NOACCESS));
\r
720 QDomElement blockRoot = document.documentElement();
\r
721 QString name = blockRoot.tagName();
\r
722 if (name == "block") {
\r
724 cout << "xml:" << fileName.toStdString() << endl;
\r
725 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
727 b->load(blockRoot);
\r
733 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
735 availableBlocks.append(b);
\r
736 foreach (int id,b->getCategories()) {
\r
737 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
738 BlockCategory* cat = categoryTree->searchCategory(id);
\r
739 cat->blocks.append(b);
\r
746 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
748 cout << "loading references from lib" << endl;
\r
750 // removing blocks from category tree if they exist
\r
751 categoryTree->clearBlocks();
\r
752 // deleting existings blocks
\r
753 ReferenceBlock* b = NULL;
\r
754 for(int i=0;i<availableBlocks.size();i++) {
\r
755 b = availableBlocks.at(i);
\r
758 availableBlocks.clear();
\r
760 QFile libFile(refLib);
\r
761 if (!libFile.open(QIODevice::ReadOnly)) {
\r
762 throw(Exception(BLOCKFILE_NOACCESS));
\r
764 QDataStream in(&libFile);
\r
771 for(int i=0;i<nbBlocks;i++) {
\r
772 b = new ReferenceBlock("");
\r
774 availableBlocks.append(b);
\r
775 foreach (int id,b->getCategories()) {
\r
776 BlockCategory* cat = categoryTree->searchCategory(id);
\r
777 cat->blocks.append(b);
\r
783 void Parameters::saveReferencesToLib() throw(Exception) {
\r
785 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
786 QFile libFile(refLib);
\r
787 if (!libFile.open(QIODevice::WriteOnly)) {
\r
788 throw(Exception(BLOCKFILE_NOACCESS));
\r
790 QDataStream out(&libFile);
\r
792 out.setVersion(QDataStream::Qt_5_0);
\r
794 QByteArray blockData;
\r
795 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
797 toWrite << availableBlocks.size();
\r
798 for(int i=0;i<availableBlocks.size();i++) {
\r
799 ReferenceBlock* b = availableBlocks.at(i);
\r
809 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
811 for(int i=0;i<implPathes.size();i++) {
\r
812 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
813 QDir dir(implPathes.at(i));
\r
814 QStringList filter;
\r
816 dir.setNameFilters(filter);
\r
817 QStringList list = dir.entryList();
\r
818 for(int j=0;j<list.size();j++) {
\r
819 QString fileName = dir.absolutePath();
\r
820 fileName.append("/"+list.at(j));
\r
822 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
823 QFile implXML(fileName);
\r
824 if (!implXML.open(QIODevice::ReadOnly)) {
\r
825 throw(Exception(IMPLFILE_NOACCESS));
\r
827 QTextStream in(&implXML);
\r
828 QString line = in.readLine();
\r
829 line = in.readLine();
\r
831 if (!line.contains("<block_impl")) {
\r
837 cout << "OK" << endl;
\r
838 cout << "reading " << qPrintable(fileName) << " content ...";
\r
841 validateXmlFile(fileName,"block.xsd",Implementation);
\r
843 catch(Exception e) {
\r
847 // reading in into QDomDocument
\r
848 QDomDocument document ("FileXML");
\r
849 if (!implXML.open(QIODevice::ReadOnly)) {
\r
850 throw(Exception(IMPLFILE_NOACCESS));
\r
852 cout << "OK" << endl;
\r
853 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
854 if (!document.setContent(&implXML)) {
\r
856 throw(Exception(IMPLFILE_NOACCESS));
\r
860 QDomElement implRoot = document.documentElement();
\r
861 QString refXml = implRoot.attribute("ref_name","none");
\r
862 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
863 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
864 availableImplementations.append(impl);
\r
866 ReferenceBlock* ref = NULL;
\r
867 if (! refMd5.isEmpty()) {
\r
868 ref = searchBlockByMd5(refMd5);
\r
871 ref = searchBlockByXml(refXml);
\r
874 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
876 ref->addImplementation(impl);
\r
877 impl->setReference(ref);
\r
878 cout << "OK" << endl;
\r
883 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
885 cout << "loading implementations from lib" << endl;
\r
887 BlockImplementation* impl = NULL;
\r
888 ReferenceBlock* ref = NULL;
\r
889 for(int i=0;i<availableImplementations.size();i++) {
\r
890 impl = availableImplementations.at(i);
\r
893 availableImplementations.clear();
\r
895 QFile libFile(implLib);
\r
896 if (!libFile.open(QIODevice::ReadOnly)) {
\r
897 throw(Exception(IMPLFILE_NOACCESS));
\r
899 QDataStream in(&libFile);
\r
906 for(int i=0;i<nbImpls;i++) {
\r
907 impl = new BlockImplementation("");
\r
909 availableImplementations.append(impl);
\r
910 QString refMd5 = impl->getReferenceMd5();
\r
911 QString refXml = impl->getReferenceXml();
\r
913 if (! refMd5.isEmpty()) {
\r
914 ref = searchBlockByMd5(refMd5);
\r
917 ref = searchBlockByXml(refXml);
\r
920 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
922 ref->addImplementation(impl);
\r
923 impl->setReference(ref);
\r
928 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
930 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
931 QFile libFile(implLib);
\r
932 if (!libFile.open(QIODevice::WriteOnly)) {
\r
933 throw(Exception(IMPLFILE_NOACCESS));
\r
935 QDataStream out(&libFile);
\r
937 out.setVersion(QDataStream::Qt_5_0);
\r
939 QByteArray blockData;
\r
940 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
942 toWrite << availableImplementations.size();
\r
943 for(int i=0;i<availableImplementations.size();i++) {
\r
944 BlockImplementation* impl = availableImplementations.at(i);
\r
953 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
954 availableBlocks.append(block);
\r
955 foreach (int id,block->getCategories()) {
\r
956 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
957 BlockCategory* cat = categoryTree->searchCategory(id);
\r
958 cat->blocks.append(block);
\r
962 void Parameters::parametersValidation() {
\r
963 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
965 if(!blocksToConfigure.isEmpty()){
\r
966 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
971 void Parameters::connectionsValidation() {
\r
973 #ifdef DEBUG_INCLFUN
\r
975 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
976 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
978 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
979 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
981 inter->setWidth(connectedInter->getWidth());
\r
982 interfaceToValidate->push(connectedInter);
\r
988 while(!interfaceToValidate->isEmpty()){
\r
989 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
992 catch(Exception e){
\r
993 cerr << e.getMessage().toStdString() << endl;
\r
998 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
1000 #ifdef DEBUG_INCLFUN
\r
1002 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
1003 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
1005 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
1006 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
1007 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
1008 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
1012 return *blocksToConfigure;
\r
1017 void Parameters::updateToolbar() {
\r
1018 int nb = currentScene->getBlockItems().length();
\r
1019 for(int i = 0; i<nb; i++){
\r
1020 if(currentScene->getBlockItems().at(i)->isSelected()){
\r
1021 currentScene->getGroupWidget()->enableGroupButton(true);
\r
1025 currentScene->getGroupWidget()->enableGroupButton(false);
\r
1029 void Parameters::updateIds() {
\r
1031 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
1032 are in the correct ordre when saving/loading a project
\r
1034 int countItem = 1;
\r
1035 int countIface = 1;
\r
1036 QList<GroupScene *> fifo;
\r
1037 fifo.append(topScene);
\r
1038 while (!fifo.isEmpty()) {
\r
1039 GroupScene* scene = fifo.takeFirst();
\r
1040 countItem = scene->setItemsId(countItem);
\r
1041 countIface = scene->setInterfacesId(countIface);
\r
1042 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1049 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
1050 foreach(ReferenceBlock *block, availableBlocks){
\r
1051 if(block->getXmlFile().contains(xmlName))
\r
1057 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
1058 foreach(ReferenceBlock *block, availableBlocks){
\r
1059 if(block->getHashMd5() == sumMd5)
\r
1065 void Parameters::save(QString confFile) {
\r
1067 //#ifdef DEBUG_INCLFUN
\r
1070 QList<ConnectionItem*> allConnections;
\r
1071 QFile file(confFile);
\r
1072 if(file.open(QIODevice::WriteOnly)){
\r
1074 QXmlStreamWriter writer(&file);
\r
1076 writer.setAutoFormatting(true);
\r
1077 writer.writeStartDocument();
\r
1079 writer.writeStartElement("blast_project");
\r
1080 writer.writeStartElement("scenes");
\r
1082 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
1084 // cross the scene level by level using a FIFO
\r
1085 QList<GroupScene*> fifoScene;
\r
1086 fifoScene.append(topScene);
\r
1088 GroupScene *scene;
\r
1089 while (!fifoScene.isEmpty()) {
\r
1090 scene = fifoScene.takeFirst();
\r
1091 scene->save(writer);
\r
1092 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1093 fifoScene.append(s);
\r
1096 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
1097 allConnections.append(item);
\r
1100 writer.writeEndElement(); //</scenes>
\r
1102 writer.writeStartElement("connections");
\r
1103 foreach(ConnectionItem* item, allConnections) {
\r
1105 writer.writeStartElement("connection");
\r
1107 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
1108 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
1110 writer.writeEndElement();
\r
1113 writer.writeEndElement(); //</connections>
\r
1114 writer.writeEndElement(); //</blast_project
\r
1116 writer.writeEndDocument();
\r
1119 unsaveModif = false;
\r
1124 void Parameters::setArrowPathes() {
\r
1125 QPainterPath _inArrow;
\r
1126 _inArrow.lineTo(arrowLineLength,0);
\r
1127 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
1128 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
1129 _inArrow.lineTo(arrowLineLength,0);
\r
1130 _inArrow.closeSubpath();
\r
1131 inArrow = _inArrow;
\r
1133 QPainterPath _outArrow;
\r
1134 _outArrow.lineTo(arrowLineLength,0);
\r
1135 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
1136 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
1137 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
1138 _outArrow.lineTo(arrowLineLength,0);
\r
1139 _outArrow.closeSubpath();
\r
1140 outArrow = _outArrow;
\r
1144 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
1146 if (scene->getId() == id) return scene;
\r
1147 GroupScene* sc = NULL;
\r
1149 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1150 sc = searchSceneById(id,s);
\r
1151 if (sc != NULL) return sc;
\r
1156 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
1158 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
1160 GroupItem* item = NULL;
\r
1161 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1162 item = searchGroupItemById(id,s);
\r
1163 if (item != NULL) return item;
\r
1168 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1170 foreach(BoxItem *item, scene->getBlockItems()){
\r
1171 if(item->getId() == id){
\r
1176 BoxItem* item = NULL;
\r
1177 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1178 item = searchBlockItemById(id,s);
\r
1179 if (item != NULL) return item;
\r
1184 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1186 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1187 if(item->getId() == id){
\r
1191 foreach(BoxItem *block, scene->getBlockItems()){
\r
1192 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1193 if(item->getId() == id){
\r
1198 InterfaceItem* item = NULL;
\r
1199 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1200 item = searchInterfaceItemById(id,s);
\r
1201 if (item != NULL) return item;
\r