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 "StimuliItem.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 validityExtension = "_enb";
\r
56 graph = new Graph();
\r
59 Parameters::~Parameters() {
\r
63 void Parameters::clear() {
\r
64 delete categoryTree;
\r
65 QListIterator<ReferenceBlock *> iter(availableBlocks);
\r
66 while(iter.hasNext()) {
\r
67 ReferenceBlock* item = iter.next();
\r
70 availableBlocks.clear();
\r
74 Graph* Parameters::initGraph(bool createTopGroupIfaces) {
\r
75 graph->createTopGroup(createTopGroupIfaces);
\r
79 void Parameters::destroyGraph() {
\r
81 graph = new Graph();
\r
84 ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {
\r
86 BlockCategory* blockCat = categoryTree->searchCategory(idCategory);
\r
88 if (blockCat == NULL) return NULL;
\r
89 ReferenceBlock* ref = blockCat->getBlockById(idBlock);
\r
93 ReferenceBlock* Parameters::getHiddenReferenceBlock(QString blockName) {
\r
95 BlockCategory* blockCat = categoryTree->searchCategory(100);
\r
96 if (blockCat == NULL) return NULL;
\r
97 ReferenceBlock* ref = blockCat->getBlockByName(blockName);
\r
102 void Parameters::createDelayBlock() {
\r
103 delayRef = new ReferenceBlock("no.xml");
\r
104 delayRef->addCategory(100);
\r
105 delayRef->setName("delay");
\r
107 BlockCategory* cat = categoryTree->searchCategory(100);
\r
108 cat->blocks.append(delayRef);
\r
110 AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width");
\r
111 delayRef->addInterface(interIn);
\r
112 AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1");
\r
113 delayRef->addInterface(interInCtl);
\r
114 interInCtl->setAssociatedIface(interIn);
\r
115 AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width");
\r
116 delayRef->addInterface(interOut);
\r
117 AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1");
\r
118 delayRef->addInterface(interOutCtl);
\r
119 interOutCtl->setAssociatedIface(interOut);
\r
120 BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8");
\r
121 BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1");
\r
122 delayRef->addParameter(param1);
\r
123 delayRef->addParameter(param2);
\r
124 delayImpl = new BlockImplementation("no.xml");
\r
125 delayImpl->setDelta("1");
\r
126 QHash<QString,QString> consPattern;
\r
127 consPattern.insert("data_in_enb","1");
\r
128 delayImpl->setConsumptionPattern(consPattern);
\r
129 QHash<QString,QString> prodPattern;
\r
130 prodPattern.insert("data_out_enb","O{$dly_length}1");
\r
131 delayImpl->setProductionPattern(prodPattern);
\r
132 delayImpl->setProductionCounter("1");
\r
133 delayRef->addImplementation(delayImpl);
\r
134 delayImpl->setReference(delayRef);
\r
135 if (! delayImpl->checkPatterns()) {
\r
136 cout << "Delay block creation: failure" << endl;
\r
139 cout << "Delay block creation: success" << endl;
\r
146 void Parameters::validateXmlFile(const QString& xmlFileName, const QString& xsdFileName, XmlFileType fileType) throw(Exception) {
\r
147 // opening configFile
\r
148 QFile xmlFile(xmlFileName);
\r
149 if (!xmlFile.open(QIODevice::ReadOnly)) {
\r
150 if (fileType == Configuration) {
\r
151 throw(Exception(CONFIGFILE_NOACCESS));
\r
153 else if (fileType == Reference) {
\r
154 throw(Exception(BLOCKFILE_NOACCESS));
\r
156 else if (fileType == Implementation) {
\r
157 throw(Exception(IMPLFILE_NOACCESS));
\r
159 else if (fileType == Project) {
\r
160 throw(Exception(PROJECTFILE_NOACCESS));
\r
164 QFile xsdFile(xsdFileName);
\r
165 if (!xsdFile.open(QIODevice::ReadOnly)) {
\r
167 if (fileType == Configuration) {
\r
168 throw(Exception(CONFIGFILE_NOACCESS));
\r
170 else if (fileType == Reference) {
\r
171 throw(Exception(BLOCKFILE_NOACCESS));
\r
173 else if (fileType == Implementation) {
\r
174 throw(Exception(IMPLFILE_NOACCESS));
\r
176 else if (fileType == Project) {
\r
177 throw(Exception(PROJECTFILE_NOACCESS));
\r
181 if(validate(xmlFile,xsdFile) == false) {
\r
184 if (fileType == Configuration) {
\r
185 throw(Exception(CONFIGFILE_CORRUPTED));
\r
187 else if (fileType == Reference) {
\r
188 throw(Exception(BLOCKFILE_CORRUPTED));
\r
190 else if (fileType == Implementation) {
\r
191 throw(Exception(IMPLFILE_CORRUPTED));
\r
193 else if (fileType == Project) {
\r
194 throw(Exception(PROJECTFILE_CORRUPTED));
\r
201 bool Parameters::validate(QFile& fileXml, QFile& fileSchema) {
\r
203 // 2 files are supposed to be already opened
\r
206 if(! schema.load(&fileSchema)){
\r
207 cout << "invalid schema" << endl;
\r
211 QXmlSchemaValidator validator(schema);
\r
213 if(! validator.validate(&fileXml)){
\r
214 cout << "invalid xml" << endl;
\r
220 QDomElement Parameters::openProjectFile(const QString& projectFileName) throw(Exception) {
\r
223 validateXmlFile(projectFileName,"projectfile.xsd",Project);
\r
225 catch(Exception err) {
\r
229 QFile projectFile(projectFileName);
\r
230 QDomDocument doc("projectFile");
\r
232 if(!projectFile.open(QIODevice::ReadOnly)) {
\r
233 throw(Exception(PROJECTFILE_NOACCESS));
\r
235 if(!doc.setContent(&projectFile)) {
\r
236 projectFile.close();
\r
237 throw(Exception(PROJECTFILE_CORRUPTED));
\r
239 projectFile.close();
\r
241 QDomElement root = doc.documentElement();
\r
246 GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
\r
249 GroupWidget* groupWidget = NULL;
\r
250 GroupItem *groupItem = NULL;
\r
251 GroupBlock *groupBlock = NULL;
\r
253 GroupWidget* topGroup = NULL;
\r
255 QString path = root.attribute("project_path","none");
\r
256 if (path != "none") {
\r
258 if (dir.exists()) {
\r
259 projectPath = path;
\r
262 cout << "project path set to " << qPrintable(projectPath) << endl;
\r
265 /**********************************************************
\r
266 0 : getting parameters
\r
267 ***********************************************************/
\r
270 int lineLength = 0;
\r
272 QString fontName="";
\r
274 QString autoConn="";
\r
275 QDomNode paramsNode = root.elementsByTagName("parameters").at(0);
\r
277 QDomElement blocksElt = paramsNode.firstChildElement("block_view");
\r
278 width = blocksElt.attribute("width","none").toInt(&ok);
\r
279 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
280 height = blocksElt.attribute("height","none").toInt(&ok);
\r
281 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
282 fontName = blocksElt.attribute("font","none");
\r
283 if(fontName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
284 fontSize = blocksElt.attribute("font_size","none").toInt(&ok);
\r
285 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
286 defaultBlockWidth = width;
\r
287 defaultBlockHeight = height;
\r
288 defaultBlockFontName = fontName;
\r
289 defaultBlockFontSize = fontSize;
\r
290 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
292 QDomElement ifacesElt = paramsNode.firstChildElement("interface_view");
\r
293 lineLength = ifacesElt.attribute("line_length","none").toInt(&ok);
\r
294 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
295 width = ifacesElt.attribute("width","none").toInt(&ok);
\r
296 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
297 height = ifacesElt.attribute("height","none").toInt(&ok);
\r
298 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
299 fontName = ifacesElt.attribute("font","none");
\r
300 if(fontName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
301 fontSize = ifacesElt.attribute("font_size","none").toInt(&ok);
\r
302 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
303 arrowLineLength = lineLength;
\r
304 arrowWidth = width;
\r
305 arrowHeight = height;
\r
306 defaultIfaceFontName = fontName;
\r
307 defaultIfaceFontSize = fontSize;
\r
308 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
310 QDomElement connsElt = paramsNode.firstChildElement("connection_view");
\r
311 gapLength = connsElt.attribute("gap_length","none").toInt(&ok);
\r
312 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
313 autoConn = connsElt.attribute("auto_conn","none");
\r
314 if (autoConn == "false") {
\r
315 autoConnMainClk = false;
\r
318 autoConnMainClk = true;
\r
320 connGapLength = gapLength;
\r
322 /**********************************************************
\r
323 1 : getting scene and creating associated group widgets
\r
324 ***********************************************************/
\r
325 QDomNodeList scenesNodes = root.elementsByTagName("scene");
\r
327 int maxIdScene = -1;
\r
328 for(int i=0; i<scenesNodes.length(); i++) {
\r
329 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
330 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
331 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
332 if (idScene > maxIdScene) maxIdScene = idScene;
\r
333 int idUpperScene = currentSceneNode.attribute("upper_scene","none").toInt(&ok);
\r
334 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
336 if (idUpperScene == -1) {
\r
337 QString clkList = currentSceneNode.attribute("clklist","none");
\r
338 if (clkList == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
339 QStringList clks = clkList.split(",");
\r
340 for(int j=0;j<clks.size();j++) {
\r
341 double freq = clks.at(j).toDouble(&ok);
\r
342 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
343 graph->addClock(freq);
\r
345 topGroup = dispatcher->createTopScene(Dispatcher::Load);
\r
346 topScene->setId(idScene);
\r
347 groupItem = topScene->getGroupItem();
\r
348 cout << "top group added to scene n°" << idScene << endl;
\r
351 cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
\r
352 GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
\r
353 /* IMPORTANT: calling addNewEmptyGroup() leads to create a new GroupWidget
\r
354 * AND a BoxItem in upperScene that represents the GroupItem in the
\r
355 * newly created child scene. Thus, it has not to be created when
\r
356 * reading bi_group tags in the following but just searched
\r
358 groupWidget = dispatcher->addNewEmptyGroup(Dispatcher::Load, upperScene,false);
\r
359 groupWidget->getScene()->setId(idScene);
\r
360 groupItem = groupWidget->getScene()->getGroupItem();
\r
362 groupBlock = AB_TO_GRP(groupItem->getRefBlock());
\r
363 /**********************************************************
\r
364 1.1 : getting the group item of each scene
\r
365 ***********************************************************/
\r
366 QDomElement groupItemNode = currentSceneNode.firstChildElement("group_item");
\r
368 groupItem->load(groupItemNode);
\r
370 catch(Exception err) {
\r
374 if (idUpperScene != -1) {
\r
375 groupWidget->setWindowTitle(groupBlock->getName());
\r
376 groupWidget->show();
\r
377 cout << qPrintable(groupItem->getRefBlock()->getName()) << " has upper box item in " << qPrintable(groupItem->getParentItem()->getScene()->getGroupItem()->getRefBlock()->getName()) << endl;
\r
380 dispatcher->setSceneCounter(Dispatcher::Load, maxIdScene+1);
\r
381 cout << "groupItems loaded and windows created succefully!" << endl;
\r
383 /**********************************************************
\r
384 2 : getting the functional blocks of each scene
\r
385 ***********************************************************/
\r
387 for(int i=0; i<scenesNodes.length(); i++){
\r
388 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
389 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
390 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
391 cout << "SCENE : " << idScene << endl;
\r
392 GroupScene *currentScene = searchSceneById(idScene,topScene);
\r
394 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
395 /**********************************************************
\r
396 2.1 : getting sources if it is top scene
\r
397 ***********************************************************/
\r
398 if (currentScene->isTopScene()) {
\r
399 QDomNodeList sourceNodes = currentSceneNode.elementsByTagName("source_item");
\r
400 cout << "top scene has " << sourceNodes.length() << " sources" << endl;
\r
401 for(int j=0; j<sourceNodes.length(); j++) {
\r
402 QDomElement currentSBNode = sourceNodes.at(j).toElement();
\r
403 StimuliItem* sourceItem = new StimuliItem(dispatcher,this);
\r
405 sourceItem->load(currentSBNode);
\r
407 catch(Exception err) {
\r
410 cout << "source item has been read, add it to the scene" << endl;
\r
411 // add the block to the GroupScene
\r
412 currentScene->addStimuliItem(sourceItem);
\r
415 /**********************************************************
\r
416 2.2 : getting functional blocks
\r
417 ***********************************************************/
\r
418 QDomNodeList functionalBlockNodes = currentSceneNode.elementsByTagName("bi_functional");
\r
420 for(int j=0; j<functionalBlockNodes.length(); j++) {
\r
421 QDomElement currentFBNode = functionalBlockNodes.at(j).toElement();
\r
422 BoxItem* funcItem = new BoxItem(dispatcher,this, currentScene->getGroupItem());
\r
424 funcItem->loadFunctional(currentFBNode);
\r
426 catch(Exception err) {
\r
429 // add the block to the GroupScene
\r
430 currentScene->addBoxItem(funcItem);
\r
433 cout << "functional blocks loaded and created succefully!" << endl;
\r
435 /**********************************************************
\r
436 3 : set the BoxItem that represents a GroupItem in a child scene
\r
437 ***********************************************************/
\r
439 for(int i=0; i<scenesNodes.length(); i++){
\r
440 QDomElement currentSceneNode = scenesNodes.at(i).toElement();
\r
441 int idScene = currentSceneNode.attribute("id","none").toInt(&ok);
\r
442 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
443 GroupScene *currentScene = searchSceneById(idScene, topScene);
\r
444 if(currentScene == NULL) throw(Exception(PROJECTFILE_CORRUPTED));
\r
446 QDomNodeList biGroupNodes = currentSceneNode.elementsByTagName("bi_group");
\r
448 for(int j=0; j<biGroupNodes.length(); j++){
\r
449 QDomElement currentBiGroup = biGroupNodes.at(j).toElement();
\r
451 int id = currentBiGroup.attribute("id","none").toInt(&ok);
\r
452 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
454 int idGroup = currentBiGroup.attribute("inside_group","none").toInt(&ok);
\r
455 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
457 QStringList positionStr = currentBiGroup.attribute("position","none").split(",");
\r
458 if(positionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
459 int posX = positionStr.at(0).toInt(&ok);
\r
460 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
461 int posY = positionStr.at(1).toInt(&ok);
\r
462 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
464 QStringList dimensionStr = currentBiGroup.attribute("dimension","none").split(",");
\r
465 if(dimensionStr.length() != 2) throw(Exception(PROJECTFILE_CORRUPTED));
\r
466 int dimX = dimensionStr.at(0).toInt(&ok);
\r
467 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
468 int dimY = dimensionStr.at(1).toInt(&ok);
\r
469 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
471 // get the GroupItem already created and set at phase 1
\r
472 GroupItem *insideGroup = searchGroupItemById(idGroup, topScene);
\r
473 BoxItem* upperItem = NULL;
\r
474 if(insideGroup == NULL) cout << "group null" << endl;
\r
475 // now search within the scene which BoxItem has a childItem that is = to insideGroup
\r
476 QList<BoxItem *> lst = currentScene->getBoxItems();
\r
477 foreach(BoxItem* item, lst) {
\r
478 if (item->getChildGroupItem() == insideGroup) {
\r
483 if (upperItem == NULL) {
\r
484 throw(Exception(PROJECTFILE_CORRUPTED));
\r
487 upperItem->setId(id);
\r
488 upperItem->setPos(posX,posY);
\r
489 upperItem->setDimension(dimX,dimY);
\r
491 // set interfaces of this BoxItem
\r
492 QDomNodeList interfaceNodes = currentBiGroup.elementsByTagName("big_iface");
\r
494 for(int k=0; k<interfaceNodes.length(); k++){
\r
495 QDomElement currentInterfaceNode = interfaceNodes.at(k).toElement();
\r
497 int id = currentInterfaceNode.attribute("id","none").toInt(&ok);
\r
498 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
500 QString refName = currentInterfaceNode.attribute("ref_name","none");
\r
501 if(refName == "none") throw(Exception(PROJECTFILE_CORRUPTED));
\r
503 QString orientationStr = currentInterfaceNode.attribute("orientation","none");
\r
504 int orientation = InterfaceItem::getIntOrientation(orientationStr);
\r
505 if(orientation == -1) throw(Exception(PROJECTFILE_CORRUPTED));
\r
507 double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
\r
508 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
510 ConnectedInterface *refInter = insideGroup->searchInterfaceItemByName(refName)->refInter;
\r
511 InterfaceItem *ifaceItem = new InterfaceItem(position, orientation, refInter, upperItem, this);
\r
512 ifaceItem->setId(id);
\r
513 upperItem->addInterfaceItem(ifaceItem);
\r
517 cout << "blockItems \"group\" loaded and created succefully!" << endl;
\r
519 QDomNodeList connectionNodes = root.elementsByTagName("connection");
\r
521 for(int i=0; i<connectionNodes.length(); i++){
\r
522 QDomElement currentConnectionNode = connectionNodes.at(i).toElement();
\r
524 int from = currentConnectionNode.attribute("from","none").toInt(&ok);
\r
525 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
527 int to = currentConnectionNode.attribute("to","none").toInt(&ok);
\r
528 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
530 bool showConn = true;
\r
531 QString visStr = currentConnectionNode.attribute("visible","none");
\r
532 if (visStr == "false") {
\r
535 InterfaceItem *iface1 = searchInterfaceItemById(from,topScene);
\r
536 InterfaceItem *iface2 = searchInterfaceItemById(to,topScene);
\r
538 if(iface1 != NULL && iface2 != NULL){
\r
539 dispatcher->createConnection(Dispatcher::Load, iface1,iface2,showConn);
\r
541 cout << "interfaces not found, connect canceled!" << endl;
\r
544 cout << "connections loaded and created succefully!" << endl;
\r
546 QDomNodeList modifierNodes = root.elementsByTagName("modifier");
\r
548 for(int i=0; i<modifierNodes.length(); i++){
\r
549 QDomElement currentModifierNode = modifierNodes.at(i).toElement();
\r
551 int id = currentModifierNode.attribute("id","none").toInt(&ok);
\r
552 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
554 QString typeStr = currentModifierNode.attribute("type","none");
\r
555 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
556 QString paramsStr = currentModifierNode.attribute("params","none");
\r
557 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
559 /* NB: just adding delays for now. To be cont'd */
\r
560 InterfaceItem *iface = searchInterfaceItemById(id,topScene);
\r
562 if ((iface == NULL ) || (iface->refInter == NULL) || (iface->refInter->getAssociatedIface() == NULL)) {
\r
563 cout << "modified interface not found, modifiers setup canceled!" << endl;
\r
566 ConnectedInterface* connIface = AI_TO_CON(iface->refInter->getAssociatedIface());
\r
568 AbstractInputModifier* mod = NULL;
\r
569 if (typeStr == "delay") {
\r
570 int delay = paramsStr.toInt(&ok);
\r
571 if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
\r
572 mod = new DelayInputModifier(connIface, delay);
\r
573 connIface->setInputModifier(mod);
\r
578 cout << "modifiers loaded and created succefully!" << endl;
\r
583 void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
\r
586 validateXmlFile("blastconfig.xml", "blastconfig.xsd",Configuration);
\r
588 catch(Exception err) {
\r
593 // opening configFile
\r
594 QFile configFile(confFile);
\r
595 // reading in into QDomDocument
\r
596 QDomDocument document("configFile");
\r
598 if (!configFile.open(QIODevice::ReadOnly)) {
\r
599 throw(Exception(CONFIGFILE_NOACCESS));
\r
601 if (!document.setContent(&configFile)) {
\r
602 configFile.close();
\r
603 throw(Exception(CONFIGFILE_NOACCESS));
\r
605 configFile.close();
\r
607 //Get the root element
\r
608 QDomElement config = document.documentElement();
\r
610 QDomElement eltCat = config.firstChildElement("categories");
\r
612 categoryTree = new BlockLibraryTree();
\r
613 categoryTree->load(eltCat);
\r
615 catch(Exception err) {
\r
619 QDomElement eltReferences = eltCat.nextSiblingElement("references");
\r
620 refLib = eltReferences.attribute("lib_file","none");
\r
621 cout << "references lib : " << qPrintable(refLib) << endl;
\r
623 QString nbPathesStr;
\r
624 nbPathesStr = eltReferences.attribute("nb","none");
\r
625 nbPathes = nbPathesStr.toInt(&ok);
\r
626 QDomNodeList listBlockDir = eltReferences.elementsByTagName("reference_lib");
\r
627 if ((!ok) || (nbPathes != listBlockDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
629 for(int i=0;i<listBlockDir.size();i++) {
\r
630 QDomNode nodeBlockDir = listBlockDir.at(i);
\r
631 QDomElement eltBlockDir = nodeBlockDir.toElement();
\r
632 if (eltBlockDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
633 QString path = eltBlockDir.attribute("path","none");
\r
634 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
635 refPathes.append(path);
\r
636 cout << "references path : " << qPrintable(path) << endl;
\r
639 QDomElement eltImpl = eltReferences.nextSiblingElement("implementations");
\r
640 implLib = eltImpl.attribute("lib_file","none");
\r
641 cout << "implementation lib : " << qPrintable(implLib) << endl;
\r
642 nbPathesStr = eltImpl.attribute("nb","none");
\r
643 nbPathes = nbPathesStr.toInt(&ok);
\r
644 QDomNodeList listImplDir = eltImpl.elementsByTagName("impl_lib");
\r
645 if ((!ok) || (nbPathes != listImplDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
647 for(int i=0;i<listImplDir.size();i++) {
\r
648 QDomNode nodeImplDir = listImplDir.at(i);
\r
649 QDomElement eltImplDir = nodeImplDir.toElement();
\r
650 if (eltImplDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
651 QString path = eltImplDir.attribute("path","none");
\r
652 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
653 implPathes.append(path);
\r
654 cout << "impl path : " << qPrintable(path) << endl << endl;
\r
657 QDomElement eltSource = eltImpl.nextSiblingElement("sources");
\r
658 nbPathesStr = eltSource.attribute("nb","none");
\r
659 nbPathes = nbPathesStr.toInt(&ok);
\r
660 QDomNodeList listSourceDir = eltSource.elementsByTagName("source_lib");
\r
661 if ((!ok) || (nbPathes != listSourceDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
\r
663 for(int i=0;i<listSourceDir.size();i++) {
\r
664 QDomNode nodeSourceDir = listSourceDir.at(i);
\r
665 QDomElement eltSourceDir = nodeSourceDir.toElement();
\r
666 if (eltSourceDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
\r
667 QString path = eltSourceDir.attribute("path","none");
\r
668 if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
669 sourcePathes.append(path);
\r
670 cout << "core path : " << qPrintable(path) << endl << endl;
\r
673 // getting elt = the element <defaults>
\r
674 // for each child element, initialize the associated attributes of Parameters
\r
676 QDomElement eltDefaults = eltSource.nextSiblingElement("defaults");
\r
678 QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
\r
679 QString attributeStr = eltBlocks.attribute("width", "none");
\r
680 defaultBlockWidth = attributeStr.toInt(&ok);
\r
681 if (!ok || defaultBlockWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
682 attributeStr = eltBlocks.attribute("height", "none");
\r
683 defaultBlockHeight = attributeStr.toInt(&ok);
\r
684 if (!ok || defaultBlockHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
685 attributeStr = eltBlocks.attribute("font_size", "none");
\r
686 defaultBlockFontSize = attributeStr.toFloat(&ok);
\r
687 if (!ok || defaultBlockFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
688 attributeStr = eltBlocks.attribute("font", "none");
\r
689 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
690 defaultBlockFontName = attributeStr;
\r
691 defaultBlockFont = QFont(defaultBlockFontName, defaultBlockFontSize);
\r
693 QDomElement eltInterfaces = eltBlocks.nextSiblingElement("interfaces");
\r
694 attributeStr = eltInterfaces.attribute("width", "none");
\r
695 arrowWidth = attributeStr.toInt(&ok);
\r
696 if (!ok || arrowWidth < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
697 attributeStr = eltInterfaces.attribute("height", "none");
\r
698 arrowHeight = attributeStr.toInt(&ok);
\r
699 if (!ok || arrowHeight < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
700 attributeStr = eltInterfaces.attribute("line_length", "none");
\r
701 arrowLineLength = attributeStr.toInt(&ok);
\r
702 if (!ok || arrowLineLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
703 attributeStr = eltInterfaces.attribute("font_size", "none");
\r
704 defaultIfaceFontSize = attributeStr.toFloat(&ok);
\r
705 if (!ok || defaultIfaceFontSize < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
706 attributeStr = eltInterfaces.attribute("font", "none");
\r
707 if (attributeStr == "none") throw(Exception(CONFIGFILE_CORRUPTED));
\r
708 defaultIfaceFontName = attributeStr;
\r
709 defaultIfaceFont = QFont(defaultIfaceFontName, defaultIfaceFontSize);
\r
711 QDomElement eltConnections = eltInterfaces.nextSiblingElement("connections");
\r
712 attributeStr = eltConnections.attribute("gap_length", "none");
\r
713 connGapLength = attributeStr.toInt(&ok);
\r
714 if (!ok || connGapLength < 1) throw(Exception(CONFIGFILE_CORRUPTED));
\r
717 void Parameters::loadReferencesFromXml() throw(Exception) {
\r
718 cout << "load references from xml" << endl;
\r
719 for(int i=0;i<refPathes.size();i++) {
\r
720 cout << "analyzing " << qPrintable(refPathes.at(i)) << endl;
\r
721 QDir dir(refPathes.at(i));
\r
722 QStringList filter;
\r
724 dir.setNameFilters(filter);
\r
725 QStringList list = dir.entryList();
\r
726 for(int j=0;j<list.size();j++) {
\r
727 QString fileName = dir.absolutePath();
\r
728 fileName.append("/"+list.at(j));
\r
730 QFile blockXML(fileName);
\r
731 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
732 throw(Exception(BLOCKFILE_NOACCESS));
\r
734 QTextStream in(&blockXML);
\r
735 QString line = in.readLine();
\r
736 line = in.readLine();
\r
738 if (!line.contains("<block")) {
\r
745 validateXmlFile(fileName,"reference.xsd",Reference);
\r
747 catch(Exception err) {
\r
751 // reading in into QDomDocument
\r
752 QDomDocument document ("FileXML");
\r
753 if (!blockXML.open(QIODevice::ReadOnly)) {
\r
754 throw(Exception(BLOCKFILE_NOACCESS));
\r
756 if (!document.setContent(&blockXML)) {
\r
758 throw(Exception(BLOCKFILE_NOACCESS));
\r
762 QDomElement blockRoot = document.documentElement();
\r
763 QString name = blockRoot.tagName();
\r
764 if (name == "block") {
\r
766 cout << "xml:" << fileName.toStdString() << endl;
\r
767 ReferenceBlock* b = new ReferenceBlock(fileName);
\r
769 b->load(blockRoot);
\r
775 cout << "xml:" << b->getXmlFile().toStdString() << endl;
\r
777 availableBlocks.append(b);
\r
778 foreach (int id,b->getCategories()) {
\r
779 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
780 BlockCategory* cat = categoryTree->searchCategory(id);
\r
781 cat->blocks.append(b);
\r
788 void Parameters::loadReferencesFromLib() throw(Exception) {
\r
790 cout << "loading references from lib" << endl;
\r
792 // removing blocks from category tree if they exist
\r
793 categoryTree->clearBlocks();
\r
794 // deleting existings blocks
\r
795 ReferenceBlock* b = NULL;
\r
796 for(int i=0;i<availableBlocks.size();i++) {
\r
797 b = availableBlocks.at(i);
\r
800 availableBlocks.clear();
\r
802 QFile libFile(refLib);
\r
803 if (!libFile.open(QIODevice::ReadOnly)) {
\r
804 throw(Exception(BLOCKFILE_NOACCESS));
\r
806 QDataStream in(&libFile);
\r
813 for(int i=0;i<nbBlocks;i++) {
\r
814 b = new ReferenceBlock("");
\r
816 availableBlocks.append(b);
\r
817 foreach (int id,b->getCategories()) {
\r
818 BlockCategory* cat = categoryTree->searchCategory(id);
\r
819 cat->blocks.append(b);
\r
825 void Parameters::saveReferencesToLib() throw(Exception) {
\r
827 cout << "saving blocks in " << qPrintable(refLib) << endl;
\r
828 QFile libFile(refLib);
\r
829 if (!libFile.open(QIODevice::WriteOnly)) {
\r
830 throw(Exception(BLOCKFILE_NOACCESS));
\r
832 QDataStream out(&libFile);
\r
834 out.setVersion(QDataStream::Qt_5_0);
\r
836 QByteArray blockData;
\r
837 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
839 toWrite << availableBlocks.size();
\r
840 for(int i=0;i<availableBlocks.size();i++) {
\r
841 ReferenceBlock* b = availableBlocks.at(i);
\r
851 void Parameters::loadImplementationsFromXml() throw(Exception) {
\r
853 for(int i=0;i<implPathes.size();i++) {
\r
854 cout << "analyzing " << qPrintable(implPathes.at(i)) << endl;
\r
855 QDir dir(implPathes.at(i));
\r
856 QStringList filter;
\r
858 dir.setNameFilters(filter);
\r
859 QStringList list = dir.entryList();
\r
860 for(int j=0;j<list.size();j++) {
\r
861 QString fileName = dir.absolutePath();
\r
862 fileName.append("/"+list.at(j));
\r
864 cout << "checking " << qPrintable(fileName) << " is an implementation file ...";
\r
865 QFile implXML(fileName);
\r
866 if (!implXML.open(QIODevice::ReadOnly)) {
\r
867 throw(Exception(IMPLFILE_NOACCESS));
\r
869 QTextStream in(&implXML);
\r
870 QString line = in.readLine();
\r
871 line = in.readLine();
\r
873 if (!line.contains("<block_impl")) {
\r
879 cout << "OK" << endl;
\r
880 cout << "reading " << qPrintable(fileName) << " content ...";
\r
883 validateXmlFile(fileName,"implementation.xsd",Implementation);
\r
885 catch(Exception e) {
\r
889 // reading in into QDomDocument
\r
890 QDomDocument document ("FileXML");
\r
891 if (!implXML.open(QIODevice::ReadOnly)) {
\r
892 throw(Exception(IMPLFILE_NOACCESS));
\r
894 cout << "OK" << endl;
\r
895 cout << "convert " << qPrintable(fileName) << " content into document...";
\r
896 if (!document.setContent(&implXML)) {
\r
898 throw(Exception(IMPLFILE_NOACCESS));
\r
902 QDomElement implRoot = document.documentElement();
\r
903 QString refXml = implRoot.attribute("ref_name","none");
\r
904 QString refMd5 = implRoot.attribute("ref_md5","none");
\r
905 BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
\r
907 QDomNodeList archNode = implRoot.elementsByTagName("architecture");
\r
909 if (archNode.isEmpty()) {
\r
910 cout << "impl has no architecture" << endl;
\r
913 QDomElement archElt = archNode.at(0).toElement();
\r
914 QString compList = archElt.attribute("comp_list","none");
\r
915 if (compList != "none") {
\r
916 QStringList compos = compList.split(",");
\r
917 foreach(QString s, compos) {
\r
918 impl->addResource(s);
\r
923 impl->loadPatterns(implRoot);
\r
928 availableImplementations.append(impl);
\r
930 ReferenceBlock* ref = NULL;
\r
931 if (! refMd5.isEmpty()) {
\r
932 ref = searchBlockByMd5(refMd5);
\r
935 ref = searchBlockByXml(refXml);
\r
938 cout << "Cannot find a reference block for impl :" << qPrintable(fileName) << endl;
\r
941 ref->addImplementation(impl);
\r
942 impl->setReference(ref);
\r
943 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
945 cout << "OK" << endl;
\r
950 void Parameters::loadImplementationsFromLib() throw(Exception) {
\r
952 cout << "loading implementations from lib" << endl;
\r
954 BlockImplementation* impl = NULL;
\r
955 ReferenceBlock* ref = NULL;
\r
956 for(int i=0;i<availableImplementations.size();i++) {
\r
957 impl = availableImplementations.at(i);
\r
960 availableImplementations.clear();
\r
962 QFile libFile(implLib);
\r
963 if (!libFile.open(QIODevice::ReadOnly)) {
\r
964 throw(Exception(IMPLFILE_NOACCESS));
\r
966 QDataStream in(&libFile);
\r
973 for(int i=0;i<nbImpls;i++) {
\r
974 impl = new BlockImplementation("");
\r
976 availableImplementations.append(impl);
\r
977 QString refMd5 = impl->getReferenceMd5();
\r
978 QString refXml = impl->getReferenceXml();
\r
980 if (! refMd5.isEmpty()) {
\r
981 ref = searchBlockByMd5(refMd5);
\r
984 ref = searchBlockByXml(refXml);
\r
987 cout << "Cannot find a reference block for impl :" << qPrintable(impl->getXmlFile()) << endl;
\r
990 ref->addImplementation(impl);
\r
991 impl->setReference(ref);
\r
992 if (! impl->checkPatterns()) throw(Exception(IMPLFILE_CORRUPTED));
\r
998 void Parameters::saveImplementationsToLib() throw(Exception) {
\r
1000 cout << "saving implementations in " << qPrintable(implLib) << endl;
\r
1001 QFile libFile(implLib);
\r
1002 if (!libFile.open(QIODevice::WriteOnly)) {
\r
1003 throw(Exception(IMPLFILE_NOACCESS));
\r
1005 QDataStream out(&libFile);
\r
1007 out.setVersion(QDataStream::Qt_5_0);
\r
1009 QByteArray blockData;
\r
1010 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
1012 toWrite << availableImplementations.size();
\r
1013 for(int i=0;i<availableImplementations.size();i++) {
\r
1014 BlockImplementation* impl = availableImplementations.at(i);
\r
1025 void Parameters::loadSources() throw(Exception) {
\r
1027 for(int i=0;i<sourcePathes.size();i++) {
\r
1028 cout << "analyzing " << qPrintable(sourcePathes.at(i)) << endl;
\r
1029 QDir dir(sourcePathes.at(i));
\r
1030 QStringList filter;
\r
1031 filter << "*.vhd" << "*.ngc";
\r
1032 dir.setNameFilters(filter);
\r
1033 QStringList list = dir.entryList();
\r
1034 for(int j=0;j<list.size();j++) {
\r
1035 QString fileName = dir.absolutePath();
\r
1036 fileName.append("/"+list.at(j));
\r
1038 if (list.at(j).endsWith(".ngc")) {
\r
1039 QString netName = list.at(j);
\r
1040 netName.truncate(list.at(j).size() -4);
\r
1041 cout << "found netlist " << qPrintable(netName) << endl;
\r
1042 availableResources.append(new ExternalResource(netName,fileName,ExternalResource::Netlist));
\r
1045 cout << "parsing " << qPrintable(fileName) << " ... ";
\r
1046 QFile srcXML(fileName);
\r
1047 if (!srcXML.open(QIODevice::ReadOnly)) {
\r
1048 throw(Exception(IMPLFILE_NOACCESS));
\r
1050 QTextStream in(&srcXML);
\r
1052 QString line = in.readLine();
\r
1053 while (!line.isNull()) {
\r
1054 if (line.contains("package", Qt::CaseInsensitive)) {
\r
1055 QRegularExpression rxPack("^package (.+) is$",QRegularExpression::CaseInsensitiveOption);
\r
1056 QRegularExpressionMatch matchPack = rxPack.match(line);
\r
1057 if (matchPack.hasMatch()) {
\r
1058 QString packName = matchPack.captured(1);
\r
1059 cout << "found package " << qPrintable(packName) << endl;
\r
1060 availableResources.append(new ExternalResource(packName,fileName,ExternalResource::Package));
\r
1063 else if (line.contains("entity", Qt::CaseInsensitive)) {
\r
1064 QRegularExpression rxEnt("^entity (.+) is$",QRegularExpression::CaseInsensitiveOption);
\r
1065 QRegularExpressionMatch matchEnt = rxEnt.match(line);
\r
1066 if (matchEnt.hasMatch()) {
\r
1067 QString entityName = matchEnt.captured(1);
\r
1068 cout << "found entity " << qPrintable(entityName) << endl;
\r
1069 availableResources.append(new ExternalResource(entityName,fileName,ExternalResource::Code));
\r
1072 line = in.readLine();
\r
1075 cout << "OK" << endl;
\r
1081 QList<ExternalResource *> Parameters::searchResourceByName(const QString& name) {
\r
1082 QList<ExternalResource*> listRes;
\r
1083 foreach(ExternalResource* s, availableResources) {
\r
1084 if (s->getName() == name) {
\r
1085 listRes.append(s);
\r
1091 void Parameters::addAvailableBlock(ReferenceBlock *block) {
\r
1092 availableBlocks.append(block);
\r
1093 foreach (int id,block->getCategories()) {
\r
1094 cout << "ajout du bloc dans cat n° : " << id << endl;
\r
1095 BlockCategory* cat = categoryTree->searchCategory(id);
\r
1096 cat->blocks.append(block);
\r
1100 void Parameters::parametersValidation() {
\r
1101 QList<AbstractBlock*> blocksToConfigure = getBlocksToConfigure();
\r
1103 if(!blocksToConfigure.isEmpty()){
\r
1104 BlocksToConfigureWidget *widget = new BlocksToConfigureWidget(blocksToConfigure, this, NULL);
\r
1109 void Parameters::connectionsValidation() {
\r
1111 #ifdef DEBUG_INCLFUN
\r
1113 QStack<AbstractInterface*> *interfaceToValidate = new QStack<AbstractInterface*>;
\r
1114 QList<AbstractInterface*> *validatedInterface = new QList<AbstractInterface*>;
\r
1116 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
1117 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
1119 inter->setWidth(connectedInter->getWidth());
\r
1120 interfaceToValidate->push(connectedInter);
\r
1126 while(!interfaceToValidate->isEmpty()){
\r
1127 interfaceToValidate->pop()->connectionsValidation(interfaceToValidate, validatedInterface);
\r
1130 catch(Exception e){
\r
1131 cerr << e.getMessage().toStdString() << endl;
\r
1136 QList<AbstractBlock *> Parameters::getBlocksToConfigure() {
\r
1138 #ifdef DEBUG_INCLFUN
\r
1140 QList<AbstractBlock*> *checkedBlocks = new QList<AbstractBlock*>;
\r
1141 QList<AbstractBlock*> *blocksToConfigure = new QList<AbstractBlock*>;
\r
1143 foreach(AbstractInterface *inter, topWindow->getScene()->getGroupItem()->getRefBlock()->getInterfaces()){
\r
1144 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
1145 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
1146 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
1150 return *blocksToConfigure;
\r
1155 void Parameters::updateToolbar() {
\r
1156 int nb = currentScene->getBoxItems().length();
\r
1157 for(int i = 0; i<nb; i++){
\r
1158 if(currentScene->getBoxItems().at(i)->isSelected()){
\r
1159 currentScene->getGroupWidget()->enableGroupButton(true);
\r
1163 currentScene->getGroupWidget()->enableGroupButton(false);
\r
1167 void Parameters::updateIds() {
\r
1169 /* a in-width cross of the graph must be done so that ids of GroupItem
\r
1170 are in the correct ordre when saving/loading a project
\r
1172 int countItem = 1;
\r
1173 int countIface = 1;
\r
1174 QList<GroupScene *> fifo;
\r
1175 fifo.append(topScene);
\r
1176 while (!fifo.isEmpty()) {
\r
1177 GroupScene* scene = fifo.takeFirst();
\r
1178 countItem = scene->setItemsId(countItem);
\r
1179 countIface = scene->setInterfacesId(countIface);
\r
1180 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1187 ReferenceBlock *Parameters::searchBlockByXml(QString xmlName) {
\r
1188 foreach(ReferenceBlock *block, availableBlocks){
\r
1189 if(block->getXmlFile().contains(xmlName))
\r
1195 ReferenceBlock *Parameters::searchBlockByMd5(QString sumMd5) {
\r
1196 foreach(ReferenceBlock *block, availableBlocks){
\r
1197 if(block->getHashMd5() == sumMd5)
\r
1203 void Parameters::save(QString confFile) {
\r
1205 //#ifdef DEBUG_INCLFUN
\r
1208 QList<ConnectionItem*> allConnections;
\r
1209 QFile file(confFile);
\r
1210 if(file.open(QIODevice::WriteOnly)){
\r
1212 QXmlStreamWriter writer(&file);
\r
1214 writer.setAutoFormatting(true);
\r
1215 writer.writeStartDocument();
\r
1217 writer.writeStartElement("blast_project");
\r
1219 writer.writeStartElement("parameters");
\r
1220 writer.writeStartElement("block_view");
\r
1221 writer.writeAttribute("width",QString::number(defaultBlockWidth));
\r
1222 writer.writeAttribute("height",QString::number(defaultBlockHeight));
\r
1223 writer.writeAttribute("font",defaultBlockFontName);
\r
1224 writer.writeAttribute("font_size",QString::number(defaultBlockFontSize));
\r
1225 writer.writeEndElement(); //</blocks>
\r
1226 writer.writeStartElement("interface_view");
\r
1227 writer.writeAttribute("line_length",QString::number(arrowLineLength));
\r
1228 writer.writeAttribute("width",QString::number(arrowWidth));
\r
1229 writer.writeAttribute("height",QString::number(arrowHeight));
\r
1230 writer.writeAttribute("font",defaultIfaceFontName);
\r
1231 writer.writeAttribute("font_size",QString::number(defaultIfaceFontSize));
\r
1232 writer.writeEndElement(); //</interfaces>
\r
1233 writer.writeStartElement("connection_view");
\r
1234 writer.writeAttribute("gap_length",QString::number(connGapLength));
\r
1235 if (autoConnMainClk) {
\r
1236 writer.writeAttribute("auto_conn","true");
\r
1239 writer.writeAttribute("auto_conn","false");
\r
1241 writer.writeEndElement(); //</connections>
\r
1243 writer.writeEndElement(); //</parameters>
\r
1245 writer.writeStartElement("scenes");
\r
1247 writer.writeAttribute("count",QString::number(dispatcher->getNumberOfScenes()));
\r
1249 // cross the scene level by level using a FIFO
\r
1250 QList<GroupScene*> fifoScene;
\r
1251 fifoScene.append(topScene);
\r
1253 GroupScene *scene;
\r
1254 while (!fifoScene.isEmpty()) {
\r
1255 scene = fifoScene.takeFirst();
\r
1256 scene->save(writer);
\r
1257 foreach(GroupScene* s, scene->getChildrenScene()) {
\r
1258 fifoScene.append(s);
\r
1261 foreach(ConnectionItem* item, scene->getConnectionItems()) {
\r
1262 allConnections.append(item);
\r
1265 writer.writeEndElement(); //</scenes>
\r
1267 writer.writeStartElement("connections");
\r
1268 foreach(ConnectionItem* item, allConnections) {
\r
1270 writer.writeStartElement("connection");
\r
1272 writer.writeAttribute("from",QString::number(item->getFromInterfaceItem()->getId()));
\r
1273 writer.writeAttribute("to", QString::number(item->getToInterfaceItem()->getId()));
\r
1274 if (!item->isVisible()) {
\r
1275 writer.writeAttribute("visible","false");
\r
1277 writer.writeEndElement();
\r
1280 writer.writeEndElement(); //</connections>
\r
1282 QList<InterfaceItem *> lstIfaceItem;
\r
1283 // search for modifiers
\r
1284 foreach(ConnectionItem* item, allConnections) {
\r
1285 InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();
\r
1286 AbstractInputModifier* mod = fromIfaceItem->refInter->getInputModifier();
\r
1287 if (mod != NULL) {
\r
1288 if (!lstIfaceItem.contains(fromIfaceItem)) lstIfaceItem.append(fromIfaceItem);
\r
1290 InterfaceItem* toIfaceItem = item->getToInterfaceItem();
\r
1291 mod = toIfaceItem->refInter->getInputModifier();
\r
1292 if (mod != NULL) {
\r
1293 if (!lstIfaceItem.contains(toIfaceItem)) lstIfaceItem.append(toIfaceItem);
\r
1296 // write input modifiers
\r
1297 writer.writeStartElement("modifiers");
\r
1298 foreach(InterfaceItem* item, lstIfaceItem) {
\r
1299 AbstractInputModifier* mod = item->refInter->getInputModifier();
\r
1300 if (mod != NULL) {
\r
1301 writer.writeStartElement("modifier");
\r
1302 writer.writeAttribute("id", QString::number(item->getId()));
\r
1303 writer.writeAttribute("type",mod->getTypeStr());
\r
1304 writer.writeAttribute("params", mod->getParametersStr());
\r
1305 writer.writeEndElement();
\r
1309 writer.writeEndElement(); //</modifiers>
\r
1310 writer.writeEndElement(); //</blast_project
\r
1312 writer.writeEndDocument();
\r
1315 unsaveModif = false;
\r
1320 void Parameters::setArrowPathes() {
\r
1321 QPainterPath _inArrow;
\r
1322 _inArrow.lineTo(arrowLineLength,0);
\r
1323 _inArrow.lineTo(arrowLineLength+arrowWidth,-arrowHeight/2);
\r
1324 _inArrow.lineTo(arrowLineLength+arrowWidth,arrowHeight/2);
\r
1325 _inArrow.lineTo(arrowLineLength,0);
\r
1326 //_inArrow.closeSubpath();
\r
1327 dataArrowIn = _inArrow;
\r
1329 QPainterPath _inArrowC;
\r
1330 _inArrowC.lineTo(arrowLineLength,0);
\r
1331 _inArrowC.addEllipse(arrowLineLength,-arrowHeight/2,arrowHeight-1,arrowHeight-1);
\r
1332 clkrstArrow = _inArrowC;
\r
1334 QPainterPath _outArrow;
\r
1335 _outArrow.lineTo(arrowLineLength,0);
\r
1336 _outArrow.lineTo(arrowLineLength,-arrowHeight/2);
\r
1337 _outArrow.lineTo(arrowLineLength+arrowWidth,0);
\r
1338 _outArrow.lineTo(arrowLineLength,arrowHeight/2);
\r
1339 _outArrow.lineTo(arrowLineLength,0);
\r
1340 //_outArrow.closeSubpath();
\r
1341 dataArrowOut = _outArrow;
\r
1345 GroupScene* Parameters::searchSceneById(int id, GroupScene *scene) {
\r
1347 if (scene->getId() == id) return scene;
\r
1348 GroupScene* sc = NULL;
\r
1350 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1351 sc = searchSceneById(id,s);
\r
1352 if (sc != NULL) return sc;
\r
1357 GroupItem* Parameters::searchGroupItemById(int id, GroupScene *scene) {
\r
1359 if (scene->getGroupItem()->getId() == id) return scene->getGroupItem();
\r
1361 GroupItem* item = NULL;
\r
1362 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1363 item = searchGroupItemById(id,s);
\r
1364 if (item != NULL) return item;
\r
1369 BoxItem* Parameters::searchBlockItemById(int id, GroupScene *scene) {
\r
1371 foreach(BoxItem *item, scene->getBoxItems()){
\r
1372 if(item->getId() == id){
\r
1377 BoxItem* item = NULL;
\r
1378 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1379 item = searchBlockItemById(id,s);
\r
1380 if (item != NULL) return item;
\r
1385 BoxItem* Parameters::searchFunctionalBlock(AbstractBlock* block) {
\r
1387 return searchFunctionalBlockRecur(block,topScene);
\r
1390 BoxItem* Parameters::searchFunctionalBlockRecur(AbstractBlock* block, GroupScene* scene) {
\r
1392 foreach(BoxItem *item, scene->getBoxItems()){
\r
1393 if(item->getRefBlock() == block) {
\r
1398 BoxItem* item = NULL;
\r
1399 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1400 item = searchFunctionalBlockRecur(block,s);
\r
1401 if (item != NULL) return item;
\r
1406 InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
\r
1408 foreach(InterfaceItem *item, scene->getGroupItem()->getInterfaces()){
\r
1409 if(item->getId() == id){
\r
1413 if (scene->isTopScene()) {
\r
1414 foreach(StimuliItem *block, scene->getSourceItems()){
\r
1415 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1416 if(item->getId() == id){
\r
1422 foreach(BoxItem *block, scene->getBoxItems()){
\r
1423 foreach(InterfaceItem *item, block->getInterfaces()){
\r
1424 if(item->getId() == id){
\r
1429 InterfaceItem* item = NULL;
\r
1430 foreach(GroupScene *s, scene->getChildrenScene()) {
\r
1431 item = searchInterfaceItemById(id,s);
\r
1432 if (item != NULL) return item;
\r
1437 QString Parameters::normalizeName(const QString &name) {
\r
1439 s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_");
\r
1440 s.replace(QRegularExpression("[_]+"),"_");
\r