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 GroupBlock* Parameters::addGroupBlock() {
\r
73 GroupBlock* parent = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());
\r
74 GroupBlock* newOne = graph->createChildBlock(parent);
\r
78 FunctionalBlock* Parameters::addFunctionalBlock(int idCategory, int idBlock) {
\r
80 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
82 if (blockCat == NULL) return NULL;
\r
83 GroupBlock* group = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());
\r
84 ReferenceBlock* ref = blockCat->getBlock(idBlock);
\r
85 if (ref == NULL) return NULL;
\r
87 FunctionalBlock* newOne = graph->addFunctionalBlock(group, ref);
\r
93 FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {
\r
95 ReferenceBlock* ref = block->getReference();
\r
96 GroupBlock* group = AB_TO_GRP(block->getParent());
\r
98 // adding to the group
\r
99 FunctionalBlock* newBlock = new FunctionalBlock(group,ref);
\r
100 newBlock->populate();
\r
101 group->addBlock(newBlock);
\r
106 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
107 // opening configFile
\r
108 QFile xmlFile(xmlFileName);
\r
109 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
110 if (fileType == Configuration) {
\r
111 throw(Exception(CONFIGFILE_NOACCESS));
\r
113 else if (fileType == Reference) {
\r
114 throw(Exception(BLOCKFILE_NOACCESS));
\r
116 else if (fileType == Implementation) {
\r
117 throw(Exception(IMPLFILE_NOACCESS));
\r
119 else if (fileType == Project) {
\r
120 throw(Exception(PROJECTFILE_NOACCESS));
\r
124 QFile xsdFile(xsdFileName);
\r
125 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
127 if (fileType == Configuration) {
\r
128 throw(Exception(CONFIGFILE_NOACCESS));
\r
130 else if (fileType == Reference) {
\r
131 throw(Exception(BLOCKFILE_NOACCESS));
\r
133 else if (fileType == Implementation) {
\r
134 throw(Exception(IMPLFILE_NOACCESS));
\r
136 else if (fileType == Project) {
\r
137 throw(Exception(PROJECTFILE_NOACCESS));
\r
141 if(validate(xmlFile,xsdFile) == false) {
\r
144 if (fileType == Configuration) {
\r
145 throw(Exception(CONFIGFILE_CORRUPTED));
\r
147 else if (fileType == Reference) {
\r
148 throw(Exception(BLOCKFILE_CORRUPTED));
\r
150 else if (fileType == Implementation) {
\r
151 throw(Exception(IMPLFILE_CORRUPTED));
\r
153 else if (fileType == Project) {
\r
154 throw(Exception(PROJECTFILE_CORRUPTED));
\r
161 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
163 // 2 files are supposed to be already opened
\r
166 if(! schema.load(&fileSchema)){
\r
167 cout << "invalid schema" << endl;
\r
171 QXmlSchemaValidator validator(schema);
\r
173 if(! validator.validate(&fileXml)){
\r
174 cout << "invalid xml" << endl;
\r
180 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
183 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
185 catch(Exception err) {
\r
189 QFile projectFile(projectFileName);
\r
190 QDomDocument doc("projectFile");
\r
192 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
193 throw(Exception(PROJECTFILE_NOACCESS));
\r
195 if(!doc.setContent(&projectFile)) {
\r
196 projectFile.close();
\r
197 throw(Exception(PROJECTFILE_CORRUPTED));
\r
199 projectFile.close();
\r
201 QDomElement root = doc.documentElement();
\r
206 void Parameters::loadProject(QDomElement root) {
\r
208 #ifdef DEBUG_INCLFUN
\r
211 GroupWidget* groupWidget = NULL;
\r
212 GroupItem *groupItem = NULL;
\r
213 GroupBlock *groupBlock = NULL;
\r
215 /**********************************************************
\r
216 1 : getting scene and creating associated group widgets
\r
217 ***********************************************************/
\r
218 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
220 for(int i=0; i<scenesNodes.length(); i++) {
\r
221 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
222 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
223 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
224 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
225 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
227 if (idUpperScene == -1) {
\r
228 dispatcher->createTopScene();
\r
229 topScene->setId(idScene);
\r
230 groupItem = topScene->getGroupItem();
\r
231 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
232 cout << "top group added to scene n°" << idScene << endl;
\r
235 GroupScene* scene = searchSceneById(idUpperScene, topScene);
\r
236 GroupWidget* parent = scene->getGroupWindow();
\r
237 groupWidget = dispatcher->createChildScene(parent);
\r
238 groupItem = groupWidget->getScene()->getGroupItem();
\r
239 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
241 /**********************************************************
\r
242 1.1 : getting the group item
\r
243 ***********************************************************/
\r
244 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
246 int id = groupItemNode.attribute("id","none").toInt(&ok);
\r
247 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
249 QString name = groupItemNode.attribute("name","none");
\r
250 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
252 QStringList positionStr = groupItemNode.attribute("position","none").split(",");
\r
253 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
254 int posX = positionStr.at(0).toInt(&ok);
\r
255 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
256 int posY = positionStr.at(1).toInt(&ok);
\r
257 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
259 QStringList dimensionStr = groupItemNode.attribute("dimension","none").split(",");
\r
260 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
261 int dimX = dimensionStr.at(0).toInt(&ok);
\r
262 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
263 int dimY = dimensionStr.at(1).toInt(&ok);
\r
264 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
266 groupItem->setId(id);
\r
267 groupItem->setPos(posX,posY);
\r
268 groupItem->setDimension(dimX,dimY);
\r
269 groupBlock->setName(name);
\r
271 if (idUpperScene != -1) {
\r
272 groupWidget->setWindowTitle(groupBlock->getName());
\r
273 groupWidget->show();
\r
275 cout << "group info : \n-id : " << id << "\n-pos : " << posX << ", " << posY << "\n-dim : " << dimX << ", " << dimY << "\n-name : " << name.toStdString() << endl;
\r
277 QDomNodeList interfaces = groupItemNode.elementsByTagName("group_iface");
\r
278 for(int j=0; j<interfaces.length(); j++){
\r
279 QDomElement currentInterfaceNode = interfaces.at(j).toElement();
\r
281 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
282 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
284 QString name = currentInterfaceNode.attribute("name","none");
\r
285 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
287 QString levelStr = currentInterfaceNode.attribute("level","none");
\r
288 int level = AbstractInterface::getIntLevel(levelStr);
\r
289 if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
291 QString directionStr = currentInterfaceNode.attribute("direction","none");
\r
292 int direction = AbstractInterface::getIntDirection(directionStr);
\r
293 if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
295 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
296 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
297 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
299 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
300 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
302 GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);
\r
304 InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,groupItem,this);
\r
305 interfaceItem->setId(id);
\r
307 groupBlock->addInterface(groupInterface);
\r
308 groupItem->addInterface(interfaceItem);
\r
309 cout << "interface add to " << groupBlock->getName().toStdString() << endl;
\r
313 cout << "groupItems loaded and windows created succefully!" << endl;
\r
316 for(int i=0; i<scenesNodes.length(); i++){
\r
317 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
318 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
319 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
320 cout << "SCENE : " << idScene << endl;
\r
321 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
323 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
325 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
327 for(int j=0; j<functionalBlockNodes.length(); j++){
\r
328 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
330 int id = currentFBNode.attribute("id","none").toInt(&ok);
\r
331 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
333 QString refXml = currentFBNode.attribute("ref_xml","none");
\r
334 if(refXml == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
336 QString refMd5 = currentFBNode.attribute("ref_md5","none");
\r
337 if(refMd5 == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
339 cout << "ref md5 : " << refMd5.toStdString() << "\nref xml : " << refXml.toStdString() << endl;
\r
341 QString name = currentFBNode.attribute("name","none");
\r
342 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
344 QStringList positionStr = currentFBNode.attribute("position","none").split(",");
\r
345 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
346 int posX = positionStr.at(0).toInt(&ok);
\r
347 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
348 int posY = positionStr.at(1).toInt(&ok);
\r
349 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
351 QStringList dimensionStr = currentFBNode.attribute("dimension","none").split(",");
\r
352 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
353 int dimX = dimensionStr.at(0).toInt(&ok);
\r
354 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
355 int dimY = dimensionStr.at(1).toInt(&ok);
\r
356 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
358 AbstractBlock *reference;
\r
359 /*if(refMd5 != "none"){
\r
360 cout << "md5" << endl;
\r
361 reference = searchBlockByMd5(refMd5);
\r
363 else */if(refXml != "none"){
\r
364 cout << "xml" << endl;
\r
365 reference = searchBlockByXml(refXml);
\r
368 throw(Exception(PROJECTFILE_CORRUPTED));
\r
371 FunctionalBlock *functionalBlock = new FunctionalBlock(currentScene->getGroupItem()->getRefBlock(),reference);
\r
372 functionalBlock->setName(name);
\r
374 ((GroupBlock*)currentScene->getGroupItem()->getRefBlock())->addBlock(functionalBlock);
\r
377 BlockItem *blockItem = new BlockItem(currentScene->getGroupItem(),functionalBlock,dispatcher,this);
\r
378 blockItem->setPos(posX,posY);
\r
379 blockItem->setDimension(dimX,dimY);
\r
380 blockItem->setId(id);
\r
381 ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);
\r
382 currentScene->addItem(blockItem);
\r
383 currentScene->addBlockItem(blockItem);
\r
385 QDomNodeList blockParamNodes = currentFBNode.elementsByTagName("bif_parameter");
\r
387 for(int i=0; i<blockParamNodes.length(); i++){
\r
388 QDomElement currentBlockParamNode = blockParamNodes.at(i).toElement();
\r
390 QString name = currentBlockParamNode.attribute("name","none");
\r
391 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
393 QString value = currentBlockParamNode.attribute("value","none");
\r
394 if(value == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
396 QString context = currentBlockParamNode.attribute("context","none");
\r
397 if(context == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
399 QString type = currentBlockParamNode.attribute("type","none");
\r
400 if(type == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
403 BlockParameter *blockParam = new BlockParameter;
\r
404 blockParam->setName(name);
\r
405 blockParam->setValue(value);
\r
406 blockParam->setType(type);
\r
407 if(context == "constant") blockParam->setContext(BlockParameter::Constant);
\r
408 if(context == "user") blockParam->setContext(BlockParameter::User);
\r
409 if(context == "generic") blockParam->setContext(BlockParameter::Generic);
\r
410 if(context == "wb") blockParam->setContext(BlockParameter::Wishbone);
\r
411 if(context == "port") blockParam->setContext(BlockParameter::Port);
\r
413 functionalBlock->addParameter(blockParam);
\r
417 QDomNodeList interfaceNodes = currentFBNode.elementsByTagName("bif_iface");
\r
419 for(int i=0; i<interfaceNodes.length(); i++){
\r
421 QDomElement currentInterfaceNode = interfaceNodes.at(i).toElement();
\r
423 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
424 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
426 QString name = currentInterfaceNode.attribute("name","none");
\r
427 if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
429 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
430 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
432 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
433 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
434 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
436 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
437 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
439 ReferenceInterface *refInter = (ReferenceInterface*)reference->getIfaceFromName(refName);
\r
440 FunctionalInterface *functionalInterface = new FunctionalInterface(functionalBlock,refInter);
\r
441 functionalBlock->addInterface(functionalInterface);
\r
442 functionalInterface->setName(refName);
\r
444 InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,functionalInterface,blockItem,this);
\r
445 interfaceItem->setId(id);
\r
446 interfaceItem->setName(name);
\r
448 blockItem->addInterface(interfaceItem);
\r
453 cout << "functionalBlocks loaded and created succefully!" << endl;
\r
456 for(int i=0; i<scenesNodes.length(); i++){
\r
457 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
458 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
459 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
460 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
461 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
463 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
465 for(int j=0; j<biGroupNodes.length(); j++){
\r
466 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
468 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
469 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
471 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
472 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
474 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
475 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
476 int posX = positionStr.at(0).toInt(&ok);
\r
477 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
478 int posY = positionStr.at(1).toInt(&ok);
\r
479 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
481 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
482 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
483 int dimX = dimensionStr.at(0).toInt(&ok);
\r
484 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
485 int dimY = dimensionStr.at(1).toInt(&ok);
\r
486 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
489 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
490 if(insideGroup == NULL) cout << "group null" << endl;
\r
491 BlockItem *blockItem = new BlockItem(insideGroup->getRefBlock(), dispatcher, this);
\r
492 blockItem->setChildGroupItem(insideGroup);
\r
493 blockItem->setId(id);
\r
494 blockItem->setPos(posX,posY);
\r
495 blockItem->setDimension(dimX,dimY);
\r
497 ((GroupItem*)currentScene->getGroupItem())->addBlockItem(blockItem);
\r
498 currentScene->addItem(blockItem);
\r
499 currentScene->addBlockItem(blockItem);
\r
501 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
503 for(int k=0; k<interfaceNodes.length(); k++){
\r
504 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
506 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
507 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
509 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
510 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
512 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
513 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
514 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
516 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
517 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
519 GroupInterface *refInter = (GroupInterface*)insideGroup->searchInterfaceByName(refName)->refInter;
\r
520 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, blockItem, this);
\r
521 ifaceItem->setId(id);
\r
522 blockItem->addInterface(ifaceItem);
\r
526 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
529 for(int i=0; i<scenesNodes.length(); i++){
\r
530 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
532 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
534 int id = groupItemNode.attribute("id","none").toInt(&ok);
\r
535 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
536 int idUpperItem = groupItemNode.attribute("upper_item","none").toInt(&ok);
\r
537 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
539 BlockItem *currentItem = searchBlockItemById(id,topScene);
\r
540 GroupItem *upperItem = searchGroupItemById(idUpperItem, topScene);
\r
542 if(currentItem != NULL && upperItem != NULL){
\r
543 currentItem->setUpperItem(upperItem);
\r
547 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
549 for(int i=0; i<connectionNodes.length(); i++){
\r
550 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
552 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
553 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
555 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
556 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
559 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
560 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
562 if(iface1 != NULL && iface2 != NULL){
\r
563 dispatcher->connect(iface1,iface2);
\r
565 cout << "interfaces not found, connect canceled!" << endl;
\r
572 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
575 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
577 catch(Exception err) {
\r
582 // opening configFile
\r
583 QFile configFile(confFile);
\r
584 // reading in into QDomDocument
\r
585 QDomDocument document("configFile");
\r
587 if (!configFile.open(QIODevice::ReadOnly)) {
\r
588 throw(Exception(CONFIGFILE_NOACCESS));
\r
590 if (!document.setContent(&configFile)) {
\r
591 configFile.close();
\r
592 throw(Exception(CONFIGFILE_NOACCESS));
\r
594 configFile.close();
\r
596 //Get the root element
\r
597 QDomElement config = document.documentElement();
\r
599 QDomElement eltCat = config.firstChildElement("categories");
\r
601 categoryTree = new BlockLibraryTree();
\r
602 categoryTree->load(eltCat);
\r
604 catch(Exception err) {
\r
608 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
609 refLib = eltReferences.attribute("lib_file","none");
\r
610 cout << "references lib : " << qPrintable(refLib) << endl;
\r
612 QString nbPathesStr;
\r
613 nbPathesStr = eltReferences.attribute("nb","none");
\r
614 nbPathes = nbPathesStr.toInt(&ok);
\r
615 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
616 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
618 for(int i=0;i<listBlockDir.size();i++) {
\r
619 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
620 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
621 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
622 QString path = eltBlockDir.attribute("path","none");
\r
623 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
624 refPathes.append(path);
\r
625 cout << "references path : " << qPrintable(path) << endl;
\r
628 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
629 implLib = eltImpl.attribute("lib_file","none");
\r
630 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
631 nbPathesStr = eltImpl.attribute("nb","none");
\r
632 nbPathes = nbPathesStr.toInt(&ok);
\r
633 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
634 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
636 for(int i=0;i<listImplDir.size();i++) {
\r
637 QDomNode nodeImplDir = listImplDir.at(i);
\r
638 QDomElement eltImplDir = nodeImplDir.toElement();
\r
639 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
640 QString path = eltImplDir.attribute("path","none");
\r
641 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
642 implPathes.append(path);
\r
643 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
645 // getting elt = the element <defaults>
\r
646 // for each child element, initialize the associated attributes of Parameters
\r
648 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
650 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
651 QString attributeStr = eltBlocks.attribute("width", "none");
\r
652 defaultBlockWidth = attributeStr.toInt(&ok);
\r
653 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
654 attributeStr = eltBlocks.attribute("height", "none");
\r
655 defaultBlockHeight = attributeStr.toInt(&ok);
\r
656 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
657 attributeStr = eltBlocks.attribute("font_size", "none");
\r
658 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
659 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
660 attributeStr = eltBlocks.attribute("font", "none");
\r
661 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
662 defaultBlockFontName = attributeStr;
\r
663 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
665 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
666 attributeStr = eltInterfaces.attribute("width", "none");
\r
667 arrowWidth = attributeStr.toInt(&ok);
\r
668 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
669 attributeStr = eltInterfaces.attribute("height", "none");
\r
670 arrowHeight = attributeStr.toInt(&ok);
\r
671 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
672 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
673 arrowLineLength = attributeStr.toInt(&ok);
\r
674 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
675 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
676 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
677 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
678 attributeStr = eltInterfaces.attribute("font", "none");
\r
679 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
680 defaultIfaceFontName = attributeStr;
\r
681 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
683 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
684 attributeStr = eltConnections.attribute("gaplength", "none");
\r
685 connGapLength = attributeStr.toInt(&ok);
\r
686 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
689 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
690 cout << "load references from xml" << endl;
\r
691 for(int i=0;i<refPathes.size();i++) {
\r
692 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
693 QDir dir(refPathes.at(i));
\r
694 QStringList filter;
\r
696 dir.setNameFilters(filter);
\r
697 QStringList list = dir.entryList();
\r
698 for(int j=0;j<list.size();j++) {
\r
699 QString fileName = dir.absolutePath();
\r
700 fileName.append("/"+list.at(j));
\r
702 QFile blockXML(fileName);
\r
703 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
704 throw(Exception(BLOCKFILE_NOACCESS));
\r
706 QTextStream in(&blockXML);
\r
707 QString line = in.readLine();
\r
708 line = in.readLine();
\r
710 if (!line.contains("<block>")) {
\r
717 validateXmlFile(fileName,"block.xsd",Reference);
\r
719 catch(Exception err) {
\r
723 // reading in into QDomDocument
\r
724 QDomDocument document ("FileXML");
\r
725 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
726 throw(Exception(BLOCKFILE_NOACCESS));
\r
728 if (!document.setContent(&blockXML)) {
\r
730 throw(Exception(BLOCKFILE_NOACCESS));
\r
734 QDomElement blockRoot = document.documentElement();
\r
735 QString name = blockRoot.tagName();
\r
736 if (name == "block") {
\r
738 cout << "xml:" << fileName.toStdString() << endl;
\r
739 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
741 b->load(blockRoot);
\r
747 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
749 availableBlocks.append(b);
\r
750 foreach (int id,b->getCategories()) {
\r
751 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
752 BlockCategory* cat = categoryTree->searchCategory(id);
\r
753 cat->blocks.append(b);
\r
760 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
762 cout << "loading references from lib" << endl;
\r
764 // removing blocks from category tree if they exist
\r
765 categoryTree->clearBlocks();
\r
766 // deleting existings blocks
\r
767 ReferenceBlock* b = NULL;
\r
768 for(int i=0;i<availableBlocks.size();i++) {
\r
769 b = availableBlocks.at(i);
\r
772 availableBlocks.clear();
\r
774 QFile libFile(refLib);
\r
775 if (!libFile.open(QIODevice::ReadOnly)) {
\r
776 throw(Exception(BLOCKFILE_NOACCESS));
\r
778 QDataStream in(&libFile);
\r
785 for(int i=0;i<nbBlocks;i++) {
\r
786 b = new ReferenceBlock("");
\r
788 availableBlocks.append(b);
\r
789 foreach (int id,b->getCategories()) {
\r
790 BlockCategory* cat = categoryTree->searchCategory(id);
\r
791 cat->blocks.append(b);
\r
797 void Parameters::saveReferencesToLib() throw(Exception) {
\r
799 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
800 QFile libFile(refLib);
\r
801 if (!libFile.open(QIODevice::WriteOnly)) {
\r
802 throw(Exception(BLOCKFILE_NOACCESS));
\r
804 QDataStream out(&libFile);
\r
806 out.setVersion(QDataStream::Qt_5_0);
\r
808 QByteArray blockData;
\r
809 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
811 toWrite << availableBlocks.size();
\r
812 for(int i=0;i<availableBlocks.size();i++) {
\r
813 ReferenceBlock* b = availableBlocks.at(i);
\r
823 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
825 for(int i=0;i<implPathes.size();i++) {
\r
826 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
827 QDir dir(implPathes.at(i));
\r
828 QStringList filter;
\r
830 dir.setNameFilters(filter);
\r
831 QStringList list = dir.entryList();
\r
832 for(int j=0;j<list.size();j++) {
\r
833 QString fileName = dir.absolutePath();
\r
834 fileName.append("/"+list.at(j));
\r
836 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
837 QFile implXML(fileName);
\r
838 if (!implXML.open(QIODevice::ReadOnly)) {
\r
839 throw(Exception(IMPLFILE_NOACCESS));
\r
841 QTextStream in(&implXML);
\r
842 QString line = in.readLine();
\r
843 line = in.readLine();
\r
845 if (!line.contains("<block_impl")) {
\r
851 cout << "OK" << endl;
\r
852 cout << "reading " << qPrintable(fileName) << " content ...";
\r
855 validateXmlFile(fileName,"block.xsd",Implementation);
\r
857 catch(Exception e) {
\r
861 // reading in into QDomDocument
\r
862 QDomDocument document ("FileXML");
\r
863 if (!implXML.open(QIODevice::ReadOnly)) {
\r
864 throw(Exception(IMPLFILE_NOACCESS));
\r
866 cout << "OK" << endl;
\r
867 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
868 if (!document.setContent(&implXML)) {
\r
870 throw(Exception(IMPLFILE_NOACCESS));
\r
874 QDomElement implRoot = document.documentElement();
\r
875 QString refXml = implRoot.attribute("ref_name","none");
\r
876 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
877 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
878 availableImplementations.append(impl);
\r
880 ReferenceBlock* ref = NULL;
\r
881 if (! refMd5.isEmpty()) {
\r
882 ref = searchBlockByMd5(refMd5);
\r
885 ref = searchBlockByXml(refXml);
\r
888 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
890 ref->addImplementation(impl);
\r
891 impl->setReference(ref);
\r
892 cout << "OK" << endl;
\r
897 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
899 cout << "loading implementations from lib" << endl;
\r
901 BlockImplementation* impl = NULL;
\r
902 ReferenceBlock* ref = NULL;
\r
903 for(int i=0;i<availableImplementations.size();i++) {
\r
904 impl = availableImplementations.at(i);
\r
907 availableImplementations.clear();
\r
909 QFile libFile(implLib);
\r
910 if (!libFile.open(QIODevice::ReadOnly)) {
\r
911 throw(Exception(IMPLFILE_NOACCESS));
\r
913 QDataStream in(&libFile);
\r
920 for(int i=0;i<nbImpls;i++) {
\r
921 impl = new BlockImplementation("");
\r
923 availableImplementations.append(impl);
\r
924 QString refMd5 = impl->getReferenceMd5();
\r
925 QString refXml = impl->getReferenceXml();
\r
927 if (! refMd5.isEmpty()) {
\r
928 ref = searchBlockByMd5(refMd5);
\r
931 ref = searchBlockByXml(refXml);
\r
934 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
936 ref->addImplementation(impl);
\r
937 impl->setReference(ref);
\r
942 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
944 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
945 QFile libFile(implLib);
\r
946 if (!libFile.open(QIODevice::WriteOnly)) {
\r
947 throw(Exception(IMPLFILE_NOACCESS));
\r
949 QDataStream out(&libFile);
\r
951 out.setVersion(QDataStream::Qt_5_0);
\r
953 QByteArray blockData;
\r
954 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
956 toWrite << availableImplementations.size();
\r
957 for(int i=0;i<availableImplementations.size();i++) {
\r
958 BlockImplementation* impl = availableImplementations.at(i);
\r
967 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
968 availableBlocks.append(block);
\r
969 foreach (int id,block->getCategories()) {
\r
970 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
971 BlockCategory* cat = categoryTree->searchCategory(id);
\r
972 cat->blocks.append(block);
\r
976 void Parameters::parametersValidation() {
\r
977 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
979 if(!blocksToConfigure.isEmpty()){
\r
980 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
985 void Parameters::connectionsValidation() {
\r
987 #ifdef DEBUG_INCLFUN
\r
989 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
990 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
992 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
993 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
995 inter->setWidth(connectedInter->getWidth());
\r
996 interfaceToValidate->push(connectedInter);
\r
1002 while(!interfaceToValidate->isEmpty()){
\r
1003 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
1006 catch(Exception e){
\r
1007 cerr << e.getMessage().toStdString() << endl;
\r
1012 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
1014 #ifdef DEBUG_INCLFUN
\r
1016 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
1017 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
1019 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
1020 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
1021 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
1022 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
1026 return *blocksToConfigure;
\r
1031 void Parameters::updateToolbar() {
\r
1032 int nb = currentScene->getBlockItems().length();
\r
1033 for(int i = 0; i<nb; i++){
\r
1034 if(currentScene->getBlockItems().at(i)->isSelected()){
\r
1035 currentScene->getGroupWindow()->enableGroupButton(true);
\r
1039 currentScene->getGroupWindow()->enableGroupButton(false);
\r
1043 void Parameters::updateIds() {
\r
1045 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
1046 are in the correct ordre when saving/loading a project
\r
1048 int countItem = 1;
\r
1049 int countIface = 1;
\r
1050 QList<GroupScene *> fifo;
\r
1051 fifo.append(topScene);
\r
1052 while (!fifo.isEmpty()) {
\r
1053 GroupScene* scene = fifo.takeFirst();
\r
1054 countItem = scene->setItemsId(countItem);
\r
1055 countIface = scene->setInterfacesId(countIface);
\r
1056 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1063 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
1064 foreach(ReferenceBlock *block, availableBlocks){
\r
1065 if(block->getXmlFile().contains(xmlName))
\r
1071 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
1072 foreach(ReferenceBlock *block, availableBlocks){
\r
1073 if(block->getHashMd5() == sumMd5)
\r
1079 void Parameters::save(QString confFile) {
\r
1081 //#ifdef DEBUG_INCLFUN
\r
1084 QList<ConnectionItem*> allConnections;
\r
1085 QFile file(confFile);
\r
1086 if(file.open(QIODevice::WriteOnly)){
\r
1088 QXmlStreamWriter writer(&file);
\r
1090 writer.setAutoFormatting(true);
\r
1091 writer.writeStartDocument();
\r
1093 writer.writeStartElement("blast_project");
\r
1094 writer.writeStartElement("scenes");
\r
1096 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
1098 // cross the scene level by level using a FIFO
\r
1099 QList<GroupScene*> fifoScene;
\r
1100 fifoScene.append(topScene);
\r
1101 foreach(ConnectionItem* item, topScene->getConnectionItems()) {
\r
1102 allConnections.append(item);
\r
1105 GroupScene *scene;
\r
1106 while (!fifoScene.isEmpty()) {
\r
1107 scene = fifoScene.takeFirst();
\r
1108 scene->save(writer);
\r
1109 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1110 fifoScene.append(s);
\r
1112 foreach(ConnectionItem* item, topScene->getConnectionItems()) {
\r
1113 allConnections.append(item);
\r
1118 writer.writeStartElement("connections");
\r
1119 foreach(ConnectionItem* item, allConnections) {
\r
1121 writer.writeStartElement("connection");
\r
1123 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
1124 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
1126 writer.writeEndElement();
\r
1129 writer.writeEndElement(); //</connections>
\r
1130 writer.writeEndElement(); //</blast_project
\r
1132 writer.writeEndDocument();
\r
1135 unsaveModif = false;
\r
1140 void Parameters::setArrowPathes() {
\r
1141 QPainterPath _inArrow;
\r
1142 _inArrow.lineTo(arrowLineLength,0);
\r
1143 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
1144 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
1145 _inArrow.lineTo(arrowLineLength,0);
\r
1146 _inArrow.closeSubpath();
\r
1147 inArrow = _inArrow;
\r
1149 QPainterPath _outArrow;
\r
1150 _outArrow.lineTo(arrowLineLength,0);
\r
1151 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
1152 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
1153 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
1154 _outArrow.lineTo(arrowLineLength,0);
\r
1155 _outArrow.closeSubpath();
\r
1156 outArrow = _outArrow;
\r
1160 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
1162 if (scene->getId() == id) return scene;
\r
1163 GroupScene* sc = NULL;
\r
1165 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1166 sc = searchSceneById(id,s);
\r
1167 if (sc != NULL) return sc;
\r
1172 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
1174 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
1176 GroupItem* item = NULL;
\r
1177 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1178 item = searchGroupItemById(id,s);
\r
1179 if (item != NULL) return item;
\r
1184 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1186 foreach(BoxItem *item, scene->getBlockItems()){
\r
1187 if(item->getId() == id){
\r
1192 BoxItem* item = NULL;
\r
1193 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1194 item = searchBlockItemById(id,s);
\r
1195 if (item != NULL) return item;
\r
1200 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1202 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1203 if(item->getId() == id){
\r
1207 foreach(BoxItem *block, scene->getBlockItems()){
\r
1208 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1209 if(item->getId() == id){
\r
1214 InterfaceItem* item = NULL;
\r
1215 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1216 item = searchInterfaceItemById(id,s);
\r
1217 if (item != NULL) return item;
\r