]> AND Private Git Repository - blast.git/blob - FunctionalBlock.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
added creation of control ifaces
[blast.git] / FunctionalBlock.cpp
1 #include "FunctionalBlock.h"\r
2 #include "ReferenceBlock.h"\r
3 #include "GroupBlock.h"\r
4 #include "AbstractInterface.h"\r
5 #include "FunctionalInterface.h"\r
6 #include "ReferenceInterface.h"\r
7 #include "BlockParameter.h"\r
8 \r
9 \r
10 FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference) throw(Exception) :  AbstractBlock() {\r
11   //if (! _reference->isReferenceBlock()) throw(Exception(BLOCK_INVALID_TYPE));\r
12   //if (! _group->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE));\r
13   reference = _reference;\r
14   parent = _parent;\r
15   name = reference->getName();\r
16 }\r
17 \r
18 \r
19 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {\r
20   /*\r
21   checkedBlocks->append(this);\r
22 \r
23   foreach(BlockParameter* param, params){\r
24     if(param->isUserParameter() && !param->isValueSet()){\r
25       if(!blocksToConfigure->contains(param->getOwner())){\r
26         blocksToConfigure->append(param->getOwner());\r
27       }\r
28     }\r
29   }\r
30   foreach(AbstractInterface *inter, outputs){\r
31     foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){\r
32       if(!checkedBlocks->contains(connectedInter->getOwner())){\r
33         connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);\r
34       }\r
35     }\r
36   }\r
37   */\r
38 }\r
39 \r
40 bool FunctionalBlock::isFunctionalBlock() {\r
41   return true;\r
42 }\r
43 \r
44 void FunctionalBlock::populate() {\r
45   int i;\r
46   BlockParameter* p;\r
47   AbstractInterface* inter;\r
48 \r
49   // create parameters from reference block\r
50   QList<BlockParameter*> lstParam = reference->getParameters();\r
51   for(i=0;i<lstParam.size();i++) {\r
52     p = lstParam.at(i)->clone();\r
53     addParameter(p);\r
54   }\r
55 \r
56   // create interfaces from reference block\r
57   QList<AbstractInterface *> lstRef = reference->getInterfaces();\r
58   // store relation between functional and reference\r
59   QHash<AbstractInterface *, AbstractInterface *> hashIface;\r
60   for(i=0;i<lstRef.size();i++) {\r
61     try {\r
62       inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));\r
63     }\r
64     catch(Exception e) {\r
65       cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;\r
66       exit(1);\r
67     }\r
68     hashIface.insert(lstRef.at(i),inter);\r
69 \r
70     addInterface(inter);\r
71   }\r
72     \r
73   AbstractInterface* funCtlIface = NULL;\r
74   AbstractInterface* funDataIface = NULL;\r
75   \r
76   for(i=0;i<lstRef.size();i++) {    \r
77     AbstractInterface* refIface = lstRef.at(i);    \r
78     if (refIface->getPurpose() == AbstractInterface::Control) {\r
79       funCtlIface = hashIface.value(refIface);\r
80       funDataIface = hashIface.value(refIface->getAssociatedIface());\r
81       if (! funCtlIface->setAssociatedIface(funDataIface)) {\r
82         cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;\r
83         exit(1);\r
84       }       \r
85     }\r
86   }\r
87 }\r
88 \r
89 \r
90 QString FunctionalBlock::getReferenceXmlFile() {\r
91     return ((ReferenceBlock *)reference)->getXmlFile();\r
92 }\r
93 \r
94 QString FunctionalBlock::getReferenceHashMd5()\r
95 {\r
96     return ((ReferenceBlock *)reference)->getHashMd5();\r
97 }\r