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 #include "BlockParameterGeneric.h"
\r
29 #include "DelayInputModifier.h"
\r
31 Parameters::Parameters() {
\r
32 categoryTree = NULL;
\r
35 arrowLineLength = 10;
\r
37 defaultBlockWidth = 100;
\r
38 defaultBlockHeight = 100;
\r
39 defaultBlockFont = QFont("Arial");
\r
40 defaultBlockFontSize = 12;
\r
44 sceneMode = MODE_EDITION; // default mode
\r
45 editState = Parameters::EditNoOperation;
\r
47 unsaveModif = false;
\r
48 isRstClkShown = false;
\r
50 projectPath = QDir::currentPath();
\r
52 validityExtension = "_enb";
\r
55 Parameters::~Parameters() {
\r
59 void Parameters::clear() {
\r
60 delete categoryTree;
\r
61 QListIterator<ReferenceBlock *> iter(availableBlocks);
\r
62 while(iter.hasNext()) {
\r
63 ReferenceBlock* item = iter.next();
\r
66 availableBlocks.clear();
\r
70 Graph* Parameters::createGraph() {
\r
71 graph = new Graph();
\r
75 void Parameters::destroyGraph() {
\r
79 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
\r
81 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
83 if (blockCat == NULL) return NULL;
\r
84 ReferenceBlock* ref = blockCat->getBlock(idBlock);
\r
88 void Parameters::createDelayBlock() {
\r
89 delayRef = new ReferenceBlock("no.xml");
\r
90 delayRef->addCategory(100);
\r
91 delayRef->setName("delay");
\r
93 BlockCategory* cat = categoryTree->searchCategory(100);
\r
94 cat->blocks.append(delayRef);
\r
96 AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width");
\r
97 delayRef->addInterface(interIn);
\r
98 AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1");
\r
99 delayRef->addInterface(interInCtl);
\r
100 interInCtl->setAssociatedIface(interIn);
\r
101 AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width");
\r
102 delayRef->addInterface(interOut);
\r
103 AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1");
\r
104 delayRef->addInterface(interOutCtl);
\r
105 interOutCtl->setAssociatedIface(interOut);
\r
106 BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8");
\r
107 BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1");
\r
108 delayRef->addParameter(param1);
\r
109 delayRef->addParameter(param2);
\r
110 delayImpl = new BlockImplementation("no.xml");
\r
111 delayImpl->setDelta("1");
\r
112 QHash<QString,QString> consPattern;
\r
113 consPattern.insert("data_in_enb","1");
\r
114 delayImpl->setConsumptionPattern(consPattern);
\r
115 QHash<QString,QString> prodPattern;
\r
116 prodPattern.insert("data_out_enb","O{$dly_length}1");
\r
117 delayImpl->setProductionPattern(prodPattern);
\r
118 delayImpl->setProductionCounter("1");
\r
119 delayRef->addImplementation(delayImpl);
\r
120 delayImpl->setReference(delayRef);
\r
121 if (! delayImpl->checkPatterns()) {
\r
122 cout << "Delay block creation: failure" << endl;
\r
125 cout << "Delay block creation: success" << endl;
\r
132 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
133 // opening configFile
\r
134 QFile xmlFile(xmlFileName);
\r
135 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
136 if (fileType == Configuration) {
\r
137 throw(Exception(CONFIGFILE_NOACCESS));
\r
139 else if (fileType == Reference) {
\r
140 throw(Exception(BLOCKFILE_NOACCESS));
\r
142 else if (fileType == Implementation) {
\r
143 throw(Exception(IMPLFILE_NOACCESS));
\r
145 else if (fileType == Project) {
\r
146 throw(Exception(PROJECTFILE_NOACCESS));
\r
150 QFile xsdFile(xsdFileName);
\r
151 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
153 if (fileType == Configuration) {
\r
154 throw(Exception(CONFIGFILE_NOACCESS));
\r
156 else if (fileType == Reference) {
\r
157 throw(Exception(BLOCKFILE_NOACCESS));
\r
159 else if (fileType == Implementation) {
\r
160 throw(Exception(IMPLFILE_NOACCESS));
\r
162 else if (fileType == Project) {
\r
163 throw(Exception(PROJECTFILE_NOACCESS));
\r
167 if(validate(xmlFile,xsdFile) == false) {
\r
170 if (fileType == Configuration) {
\r
171 throw(Exception(CONFIGFILE_CORRUPTED));
\r
173 else if (fileType == Reference) {
\r
174 throw(Exception(BLOCKFILE_CORRUPTED));
\r
176 else if (fileType == Implementation) {
\r
177 throw(Exception(IMPLFILE_CORRUPTED));
\r
179 else if (fileType == Project) {
\r
180 throw(Exception(PROJECTFILE_CORRUPTED));
\r
187 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
189 // 2 files are supposed to be already opened
\r
192 if(! schema.load(&fileSchema)){
\r
193 cout << "invalid schema" << endl;
\r
197 QXmlSchemaValidator validator(schema);
\r
199 if(! validator.validate(&fileXml)){
\r
200 cout << "invalid xml" << endl;
\r
206 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
209 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
211 catch(Exception err) {
\r
215 QFile projectFile(projectFileName);
\r
216 QDomDocument doc("projectFile");
\r
218 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
219 throw(Exception(PROJECTFILE_NOACCESS));
\r
221 if(!doc.setContent(&projectFile)) {
\r
222 projectFile.close();
\r
223 throw(Exception(PROJECTFILE_CORRUPTED));
\r
225 projectFile.close();
\r
227 QDomElement root = doc.documentElement();
\r
232 GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
\r
235 GroupWidget* groupWidget = NULL;
\r
236 GroupItem *groupItem = NULL;
\r
237 GroupBlock *groupBlock = NULL;
\r
239 GroupWidget* topGroup = NULL;
\r
240 /**********************************************************
\r
241 1 : getting scene and creating associated group widgets
\r
242 ***********************************************************/
\r
243 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
245 int maxIdScene = -1;
\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 if (idScene > maxIdScene) maxIdScene = idScene;
\r
251 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
252 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
254 if (idUpperScene == -1) {
\r
255 topGroup = dispatcher->createTopScene();
\r
256 topScene->setId(idScene);
\r
257 groupItem = topScene->getGroupItem();
\r
258 cout << "top group added to scene n°" << idScene << endl;
\r
261 cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
\r
262 GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
\r
263 groupWidget = dispatcher->addNewEmptyGroup(upperScene,false);
\r
264 groupWidget->getScene()->setId(idScene);
\r
265 groupItem = groupWidget->getScene()->getGroupItem();
\r
267 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
268 /**********************************************************
\r
269 1.1 : getting the group item of each scene
\r
270 ***********************************************************/
\r
271 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
273 groupItem->load(groupItemNode);
\r
275 catch(Exception err) {
\r
279 if (idUpperScene != -1) {
\r
280 groupWidget->setWindowTitle(groupBlock->getName());
\r
281 groupWidget->show();
\r
282 cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;
\r
285 dispatcher->setSceneCounter(maxIdScene+1);
\r
286 cout << "groupItems loaded and windows created succefully!" << endl;
\r
288 /**********************************************************
\r
289 2 : getting the functional blocks of each scene
\r
290 ***********************************************************/
\r
292 for(int i=0; i<scenesNodes.length(); i++){
\r
293 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
294 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
295 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
296 cout << "SCENE : " << idScene << endl;
\r
297 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
299 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
300 /**********************************************************
\r
301 2.1 : getting sources if it is top scene
\r
302 ***********************************************************/
\r
303 if (currentScene->isTopScene()) {
\r
304 QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");
\r
305 cout << "top scene has " << sourceNodes.length() << " sources" << endl;
\r
306 for(int j=0; j<sourceNodes.length(); j++) {
\r
307 QDomElement currentSBNode = sourceNodes.at(j).toElement();
\r
308 SourceItem* sourceItem = new SourceItem(dispatcher,this);
\r
310 sourceItem->load(currentSBNode);
\r
312 catch(Exception err) {
\r
315 cout << "source item has been read, add it to the scene" << endl;
\r
316 // add the block to the GroupScene
\r
317 currentScene->addSourceItem(sourceItem);
\r
320 /**********************************************************
\r
321 2.2 : getting functional blocks
\r
322 ***********************************************************/
\r
323 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
325 for(int j=0; j<functionalBlockNodes.length(); j++) {
\r
326 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
327 BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());
\r
329 funcItem->loadFunctional(currentFBNode);
\r
331 catch(Exception err) {
\r
334 // add the block to the GroupScene
\r
335 currentScene->addBoxItem(funcItem);
\r
338 cout << "functional blocks loaded and created succefully!" << endl;
\r
340 /**********************************************************
\r
341 3 : set the BoxItem that represents a GroupItem in a child scene
\r
342 ***********************************************************/
\r
344 for(int i=0; i<scenesNodes.length(); i++){
\r
345 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
346 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
347 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
348 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
349 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
351 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
353 for(int j=0; j<biGroupNodes.length(); j++){
\r
354 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
356 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
357 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
359 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
360 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
362 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
363 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
364 int posX = positionStr.at(0).toInt(&ok);
\r
365 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
366 int posY = positionStr.at(1).toInt(&ok);
\r
367 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
369 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
370 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
371 int dimX = dimensionStr.at(0).toInt(&ok);
\r
372 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
373 int dimY = dimensionStr.at(1).toInt(&ok);
\r
374 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
376 // get the GroupItem already created and set at phase 1
\r
377 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
378 BoxItem* upperItem = NULL;
\r
379 if(insideGroup == NULL) cout << "group null" << endl;
\r
380 // now search within the scene which BoxItem has a childItem that is = to insideGroup
\r
381 QList<BoxItem *> lst = currentScene->getBoxItems();
\r
382 foreach(BoxItem* item, lst) {
\r
383 if (item->getChildGroupItem() == insideGroup) {
\r
388 if (upperItem == NULL) {
\r
389 throw(Exception(PROJECTFILE_CORRUPTED));
\r
392 upperItem->setId(id);
\r
393 upperItem->setPos(posX,posY);
\r
394 upperItem->setDimension(dimX,dimY);
\r
396 // set interfaces of this BoxItem
\r
397 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
399 for(int k=0; k<interfaceNodes.length(); k++){
\r
400 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
402 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
403 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
405 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
406 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
408 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
409 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
410 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
412 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
413 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
415 ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;
\r
416 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
\r
417 ifaceItem->setId(id);
\r
418 upperItem->addInterfaceItem(ifaceItem);
\r
422 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
424 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
426 for(int i=0; i<connectionNodes.length(); i++){
\r
427 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
429 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
430 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
432 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
433 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
436 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
437 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
439 if(iface1 != NULL && iface2 != NULL){
\r
440 dispatcher->createConnection(iface1,iface2);
\r
442 cout << "interfaces not found, connect canceled!" << endl;
\r
445 cout << "connections loaded and created succefully!" << endl;
\r
447 QDomNodeList modifierNodes = root.elementsByTagName("modifier");
\r
449 for(int i=0; i<modifierNodes.length(); i++){
\r
450 QDomElement currentModifierNode = modifierNodes.at(i).toElement();
\r
452 int id = currentModifierNode.attribute("id","none").toInt(&ok);
\r
453 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
455 QString typeStr = currentModifierNode.attribute("type","none");
\r
456 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
457 QString paramsStr = currentModifierNode.attribute("params","none");
\r
458 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
460 AbstractInputModifier* mod = NULL;
\r
461 if (typeStr == "delay") {
\r
462 int delay = paramsStr.toInt(&ok);
\r
463 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
464 mod = new DelayInputModifier(delay);
\r
467 /* NB: just adding delays for now. To be cont'd */
\r
468 InterfaceItem *iface = searchInterfaceItemById(id,topScene);
\r
470 if(iface != NULL ) {
\r
471 iface->refInter->setInputModifier(mod);
\r
474 cout << "interfaces not found, modifiers setup canceled!" << endl;
\r
477 cout << "modifiers loaded and created succefully!" << endl;
\r
482 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
485 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
487 catch(Exception err) {
\r
492 // opening configFile
\r
493 QFile configFile(confFile);
\r
494 // reading in into QDomDocument
\r
495 QDomDocument document("configFile");
\r
497 if (!configFile.open(QIODevice::ReadOnly)) {
\r
498 throw(Exception(CONFIGFILE_NOACCESS));
\r
500 if (!document.setContent(&configFile)) {
\r
501 configFile.close();
\r
502 throw(Exception(CONFIGFILE_NOACCESS));
\r
504 configFile.close();
\r
506 //Get the root element
\r
507 QDomElement config = document.documentElement();
\r
509 QDomElement eltCat = config.firstChildElement("categories");
\r
511 categoryTree = new BlockLibraryTree();
\r
512 categoryTree->load(eltCat);
\r
514 catch(Exception err) {
\r
518 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
519 refLib = eltReferences.attribute("lib_file","none");
\r
520 cout << "references lib : " << qPrintable(refLib) << endl;
\r
522 QString nbPathesStr;
\r
523 nbPathesStr = eltReferences.attribute("nb","none");
\r
524 nbPathes = nbPathesStr.toInt(&ok);
\r
525 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
526 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
528 for(int i=0;i<listBlockDir.size();i++) {
\r
529 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
530 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
531 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
532 QString path = eltBlockDir.attribute("path","none");
\r
533 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
534 refPathes.append(path);
\r
535 cout << "references path : " << qPrintable(path) << endl;
\r
538 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
539 implLib = eltImpl.attribute("lib_file","none");
\r
540 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
541 nbPathesStr = eltImpl.attribute("nb","none");
\r
542 nbPathes = nbPathesStr.toInt(&ok);
\r
543 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
544 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
546 for(int i=0;i<listImplDir.size();i++) {
\r
547 QDomNode nodeImplDir = listImplDir.at(i);
\r
548 QDomElement eltImplDir = nodeImplDir.toElement();
\r
549 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
550 QString path = eltImplDir.attribute("path","none");
\r
551 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
552 implPathes.append(path);
\r
553 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
555 // getting elt = the element <defaults>
\r
556 // for each child element, initialize the associated attributes of Parameters
\r
558 QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
\r
560 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
561 QString attributeStr = eltBlocks.attribute("width", "none");
\r
562 defaultBlockWidth = attributeStr.toInt(&ok);
\r
563 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
564 attributeStr = eltBlocks.attribute("height", "none");
\r
565 defaultBlockHeight = attributeStr.toInt(&ok);
\r
566 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
567 attributeStr = eltBlocks.attribute("font_size", "none");
\r
568 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
569 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
570 attributeStr = eltBlocks.attribute("font", "none");
\r
571 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
572 defaultBlockFontName = attributeStr;
\r
573 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
575 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
576 attributeStr = eltInterfaces.attribute("width", "none");
\r
577 arrowWidth = attributeStr.toInt(&ok);
\r
578 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
579 attributeStr = eltInterfaces.attribute("height", "none");
\r
580 arrowHeight = attributeStr.toInt(&ok);
\r
581 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
582 attributeStr = eltInterfaces.attribute("linelength", "none");
\r
583 arrowLineLength = attributeStr.toInt(&ok);
\r
584 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
585 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
586 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
587 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
588 attributeStr = eltInterfaces.attribute("font", "none");
\r
589 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
590 defaultIfaceFontName = attributeStr;
\r
591 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
593 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
594 attributeStr = eltConnections.attribute("gaplength", "none");
\r
595 connGapLength = attributeStr.toInt(&ok);
\r
596 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
599 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
600 cout << "load references from xml" << endl;
\r
601 for(int i=0;i<refPathes.size();i++) {
\r
602 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
603 QDir dir(refPathes.at(i));
\r
604 QStringList filter;
\r
606 dir.setNameFilters(filter);
\r
607 QStringList list = dir.entryList();
\r
608 for(int j=0;j<list.size();j++) {
\r
609 QString fileName = dir.absolutePath();
\r
610 fileName.append("/"+list.at(j));
\r
612 QFile blockXML(fileName);
\r
613 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
614 throw(Exception(BLOCKFILE_NOACCESS));
\r
616 QTextStream in(&blockXML);
\r
617 QString line = in.readLine();
\r
618 line = in.readLine();
\r
620 if (!line.contains("<block")) {
\r
627 validateXmlFile(fileName,"reference.xsd",Reference);
\r
629 catch(Exception err) {
\r
633 // reading in into QDomDocument
\r
634 QDomDocument document ("FileXML");
\r
635 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
636 throw(Exception(BLOCKFILE_NOACCESS));
\r
638 if (!document.setContent(&blockXML)) {
\r
640 throw(Exception(BLOCKFILE_NOACCESS));
\r
644 QDomElement blockRoot = document.documentElement();
\r
645 QString name = blockRoot.tagName();
\r
646 if (name == "block") {
\r
648 cout << "xml:" << fileName.toStdString() << endl;
\r
649 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
651 b->load(blockRoot);
\r
657 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
659 availableBlocks.append(b);
\r
660 foreach (int id,b->getCategories()) {
\r
661 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
662 BlockCategory* cat = categoryTree->searchCategory(id);
\r
663 cat->blocks.append(b);
\r
670 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
672 cout << "loading references from lib" << endl;
\r
674 // removing blocks from category tree if they exist
\r
675 categoryTree->clearBlocks();
\r
676 // deleting existings blocks
\r
677 ReferenceBlock* b = NULL;
\r
678 for(int i=0;i<availableBlocks.size();i++) {
\r
679 b = availableBlocks.at(i);
\r
682 availableBlocks.clear();
\r
684 QFile libFile(refLib);
\r
685 if (!libFile.open(QIODevice::ReadOnly)) {
\r
686 throw(Exception(BLOCKFILE_NOACCESS));
\r
688 QDataStream in(&libFile);
\r
695 for(int i=0;i<nbBlocks;i++) {
\r
696 b = new ReferenceBlock("");
\r
698 availableBlocks.append(b);
\r
699 foreach (int id,b->getCategories()) {
\r
700 BlockCategory* cat = categoryTree->searchCategory(id);
\r
701 cat->blocks.append(b);
\r
707 void Parameters::saveReferencesToLib() throw(Exception) {
\r
709 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
710 QFile libFile(refLib);
\r
711 if (!libFile.open(QIODevice::WriteOnly)) {
\r
712 throw(Exception(BLOCKFILE_NOACCESS));
\r
714 QDataStream out(&libFile);
\r
716 out.setVersion(QDataStream::Qt_5_0);
\r
718 QByteArray blockData;
\r
719 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
721 toWrite << availableBlocks.size();
\r
722 for(int i=0;i<availableBlocks.size();i++) {
\r
723 ReferenceBlock* b = availableBlocks.at(i);
\r
733 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
735 for(int i=0;i<implPathes.size();i++) {
\r
736 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
737 QDir dir(implPathes.at(i));
\r
738 QStringList filter;
\r
740 dir.setNameFilters(filter);
\r
741 QStringList list = dir.entryList();
\r
742 for(int j=0;j<list.size();j++) {
\r
743 QString fileName = dir.absolutePath();
\r
744 fileName.append("/"+list.at(j));
\r
746 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
747 QFile implXML(fileName);
\r
748 if (!implXML.open(QIODevice::ReadOnly)) {
\r
749 throw(Exception(IMPLFILE_NOACCESS));
\r
751 QTextStream in(&implXML);
\r
752 QString line = in.readLine();
\r
753 line = in.readLine();
\r
755 if (!line.contains("<block_impl")) {
\r
761 cout << "OK" << endl;
\r
762 cout << "reading " << qPrintable(fileName) << " content ...";
\r
765 validateXmlFile(fileName,"implementation.xsd",Implementation);
\r
767 catch(Exception e) {
\r
771 // reading in into QDomDocument
\r
772 QDomDocument document ("FileXML");
\r
773 if (!implXML.open(QIODevice::ReadOnly)) {
\r
774 throw(Exception(IMPLFILE_NOACCESS));
\r
776 cout << "OK" << endl;
\r
777 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
778 if (!document.setContent(&implXML)) {
\r
780 throw(Exception(IMPLFILE_NOACCESS));
\r
784 QDomElement implRoot = document.documentElement();
\r
785 QString refXml = implRoot.attribute("ref_name","none");
\r
786 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
787 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
789 impl->loadPatterns(implRoot);
\r
794 availableImplementations.append(impl);
\r
796 ReferenceBlock* ref = NULL;
\r
797 if (! refMd5.isEmpty()) {
\r
798 ref = searchBlockByMd5(refMd5);
\r
801 ref = searchBlockByXml(refXml);
\r
804 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
807 ref->addImplementation(impl);
\r
808 impl->setReference(ref);
\r
809 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
811 cout << "OK" << endl;
\r
816 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
818 cout << "loading implementations from lib" << endl;
\r
820 BlockImplementation* impl = NULL;
\r
821 ReferenceBlock* ref = NULL;
\r
822 for(int i=0;i<availableImplementations.size();i++) {
\r
823 impl = availableImplementations.at(i);
\r
826 availableImplementations.clear();
\r
828 QFile libFile(implLib);
\r
829 if (!libFile.open(QIODevice::ReadOnly)) {
\r
830 throw(Exception(IMPLFILE_NOACCESS));
\r
832 QDataStream in(&libFile);
\r
839 for(int i=0;i<nbImpls;i++) {
\r
840 impl = new BlockImplementation("");
\r
842 availableImplementations.append(impl);
\r
843 QString refMd5 = impl->getReferenceMd5();
\r
844 QString refXml = impl->getReferenceXml();
\r
846 if (! refMd5.isEmpty()) {
\r
847 ref = searchBlockByMd5(refMd5);
\r
850 ref = searchBlockByXml(refXml);
\r
853 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
856 ref->addImplementation(impl);
\r
857 impl->setReference(ref);
\r
858 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
864 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
866 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
867 QFile libFile(implLib);
\r
868 if (!libFile.open(QIODevice::WriteOnly)) {
\r
869 throw(Exception(IMPLFILE_NOACCESS));
\r
871 QDataStream out(&libFile);
\r
873 out.setVersion(QDataStream::Qt_5_0);
\r
875 QByteArray blockData;
\r
876 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
878 toWrite << availableImplementations.size();
\r
879 for(int i=0;i<availableImplementations.size();i++) {
\r
880 BlockImplementation* impl = availableImplementations.at(i);
\r
889 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
890 availableBlocks.append(block);
\r
891 foreach (int id,block->getCategories()) {
\r
892 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
893 BlockCategory* cat = categoryTree->searchCategory(id);
\r
894 cat->blocks.append(block);
\r
898 void Parameters::parametersValidation() {
\r
899 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
901 if(!blocksToConfigure.isEmpty()){
\r
902 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
907 void Parameters::connectionsValidation() {
\r
909 #ifdef DEBUG_INCLFUN
\r
911 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
912 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
914 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
915 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
917 inter->setWidth(connectedInter->getWidth());
\r
918 interfaceToValidate->push(connectedInter);
\r
924 while(!interfaceToValidate->isEmpty()){
\r
925 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
928 catch(Exception e){
\r
929 cerr << e.getMessage().toStdString() << endl;
\r
934 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
936 #ifdef DEBUG_INCLFUN
\r
938 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
939 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
941 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
942 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
943 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
944 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
948 return *blocksToConfigure;
\r
953 void Parameters::updateToolbar() {
\r
954 int nb = currentScene->getBoxItems().length();
\r
955 for(int i = 0; i<nb; i++){
\r
956 if(currentScene->getBoxItems().at(i)->isSelected()){
\r
957 currentScene->getGroupWidget()->enableGroupButton(true);
\r
961 currentScene->getGroupWidget()->enableGroupButton(false);
\r
965 void Parameters::updateIds() {
\r
967 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
968 are in the correct ordre when saving/loading a project
\r
971 int countIface = 1;
\r
972 QList<GroupScene *> fifo;
\r
973 fifo.append(topScene);
\r
974 while (!fifo.isEmpty()) {
\r
975 GroupScene* scene = fifo.takeFirst();
\r
976 countItem = scene->setItemsId(countItem);
\r
977 countIface = scene->setInterfacesId(countIface);
\r
978 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
985 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
986 foreach(ReferenceBlock *block, availableBlocks){
\r
987 if(block->getXmlFile().contains(xmlName))
\r
993 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
994 foreach(ReferenceBlock *block, availableBlocks){
\r
995 if(block->getHashMd5() == sumMd5)
\r
1001 void Parameters::save(QString confFile) {
\r
1003 //#ifdef DEBUG_INCLFUN
\r
1006 QList<ConnectionItem*> allConnections;
\r
1007 QFile file(confFile);
\r
1008 if(file.open(QIODevice::WriteOnly)){
\r
1010 QXmlStreamWriter writer(&file);
\r
1012 writer.setAutoFormatting(true);
\r
1013 writer.writeStartDocument();
\r
1015 writer.writeStartElement("blast_project");
\r
1016 writer.writeStartElement("scenes");
\r
1018 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
1020 // cross the scene level by level using a FIFO
\r
1021 QList<GroupScene*> fifoScene;
\r
1022 fifoScene.append(topScene);
\r
1024 GroupScene *scene;
\r
1025 while (!fifoScene.isEmpty()) {
\r
1026 scene = fifoScene.takeFirst();
\r
1027 scene->save(writer);
\r
1028 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1029 fifoScene.append(s);
\r
1032 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
1033 allConnections.append(item);
\r
1036 writer.writeEndElement(); //</scenes>
\r
1038 writer.writeStartElement("connections");
\r
1039 foreach(ConnectionItem* item, allConnections) {
\r
1041 writer.writeStartElement("connection");
\r
1043 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
1044 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
1046 writer.writeEndElement();
\r
1049 writer.writeEndElement(); //</connections>
\r
1051 QList<InterfaceItem *> lstIfaceItem;
\r
1052 // search for modifiers
\r
1053 foreach(ConnectionItem* item, allConnections) {
\r
1054 InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();
\r
1055 AbstractInputModifier* mod = fromIfaceItem->refInter->getInputModifier();
\r
1056 if (mod != NULL) {
\r
1057 if (!lstIfaceItem.contains(fromIfaceItem)) lstIfaceItem.append(fromIfaceItem);
\r
1059 InterfaceItem* toIfaceItem = item->getToInterfaceItem();
\r
1060 mod = toIfaceItem->refInter->getInputModifier();
\r
1061 if (mod != NULL) {
\r
1062 if (!lstIfaceItem.contains(toIfaceItem)) lstIfaceItem.append(toIfaceItem);
\r
1065 // write input modifiers
\r
1066 writer.writeStartElement("modifiers");
\r
1067 foreach(InterfaceItem* item, lstIfaceItem) {
\r
1068 AbstractInputModifier* mod = item->refInter->getInputModifier();
\r
1069 if (mod != NULL) {
\r
1070 writer.writeStartElement("modifier");
\r
1071 writer.writeAttribute("id", QString::number(item->getId()));
\r
1072 writer.writeAttribute("type",mod->getTypeStr());
\r
1073 writer.writeAttribute("params", mod->getParametersStr());
\r
1074 writer.writeEndElement();
\r
1078 writer.writeEndElement(); //</modifiers>
\r
1079 writer.writeEndElement(); //</blast_project
\r
1081 writer.writeEndDocument();
\r
1084 unsaveModif = false;
\r
1089 void Parameters::setArrowPathes() {
\r
1090 QPainterPath _inArrow;
\r
1091 _inArrow.lineTo(arrowLineLength,0);
\r
1092 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
1093 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
1094 _inArrow.lineTo(arrowLineLength,0);
\r
1095 _inArrow.closeSubpath();
\r
1096 inArrow = _inArrow;
\r
1098 QPainterPath _outArrow;
\r
1099 _outArrow.lineTo(arrowLineLength,0);
\r
1100 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
1101 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
1102 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
1103 _outArrow.lineTo(arrowLineLength,0);
\r
1104 _outArrow.closeSubpath();
\r
1105 outArrow = _outArrow;
\r
1109 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
1111 if (scene->getId() == id) return scene;
\r
1112 GroupScene* sc = NULL;
\r
1114 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1115 sc = searchSceneById(id,s);
\r
1116 if (sc != NULL) return sc;
\r
1121 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
1123 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
1125 GroupItem* item = NULL;
\r
1126 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1127 item = searchGroupItemById(id,s);
\r
1128 if (item != NULL) return item;
\r
1133 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1135 foreach(BoxItem *item, scene->getBoxItems()){
\r
1136 if(item->getId() == id){
\r
1141 BoxItem* item = NULL;
\r
1142 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1143 item = searchBlockItemById(id,s);
\r
1144 if (item != NULL) return item;
\r
1149 BoxItem* Parameters::searchFunctionalBlock(AbstractBlock* block) {
\r
1151 return searchFunctionalBlockRecur(block,topScene);
\r
1154 BoxItem* Parameters::searchFunctionalBlockRecur(AbstractBlock* block, GroupScene* scene) {
\r
1156 foreach(BoxItem *item, scene->getBoxItems()){
\r
1157 if(item->getRefBlock() == block) {
\r
1162 BoxItem* item = NULL;
\r
1163 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1164 item = searchFunctionalBlockRecur(block,s);
\r
1165 if (item != NULL) return item;
\r
1170 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1172 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1173 if(item->getId() == id){
\r
1177 if (scene->isTopScene()) {
\r
1178 foreach(SourceItem *block, scene->getSourceItems()){
\r
1179 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1180 if(item->getId() == id){
\r
1186 foreach(BoxItem *block, scene->getBoxItems()){
\r
1187 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1188 if(item->getId() == id){
\r
1193 InterfaceItem* item = NULL;
\r
1194 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1195 item = searchInterfaceItemById(id,s);
\r
1196 if (item != NULL) return item;
\r