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

Private GIT Repository
correct relative positionning of source/group
[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 bool FunctionalBlock::isSourceBlock() {\r
45   if (parent == NULL) return true;\r
46   return false;\r
47 }\r
48 \r
49 void FunctionalBlock::populate() {\r
50   int i;\r
51   BlockParameter* p;\r
52   AbstractInterface* inter;\r
53 \r
54   // create parameters from reference block\r
55   QList<BlockParameter*> lstParam = reference->getParameters();\r
56   for(i=0;i<lstParam.size();i++) {\r
57     p = lstParam.at(i)->clone();\r
58     addParameter(p);\r
59   }\r
60 \r
61   // create interfaces from reference block\r
62   QList<AbstractInterface *> lstRef = reference->getInterfaces();\r
63   // store relation between functional and reference\r
64   QHash<AbstractInterface *, AbstractInterface *> hashIface;\r
65   for(i=0;i<lstRef.size();i++) {\r
66     try {\r
67       inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));\r
68     }\r
69     catch(Exception e) {\r
70       cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;\r
71       exit(1);\r
72     }\r
73     hashIface.insert(lstRef.at(i),inter);\r
74 \r
75     addInterface(inter);\r
76   }\r
77     \r
78   AbstractInterface* funCtlIface = NULL;\r
79   AbstractInterface* funDataIface = NULL;\r
80   \r
81   for(i=0;i<lstRef.size();i++) {    \r
82     AbstractInterface* refIface = lstRef.at(i);    \r
83     if (refIface->getPurpose() == AbstractInterface::Control) {\r
84       funCtlIface = hashIface.value(refIface);\r
85       funDataIface = hashIface.value(refIface->getAssociatedIface());\r
86       if (! funCtlIface->setAssociatedIface(funDataIface)) {\r
87         cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;\r
88         exit(1);\r
89       }       \r
90     }\r
91   }\r
92 }\r
93 \r
94 \r
95 QString FunctionalBlock::getReferenceXmlFile() {\r
96     return ((ReferenceBlock *)reference)->getXmlFile();\r
97 }\r
98 \r
99 QString FunctionalBlock::getReferenceHashMd5()\r
100 {\r
101     return ((ReferenceBlock *)reference)->getHashMd5();\r
102 }\r