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
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
15 name = reference->getName();
\r
19 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
\r
21 checkedBlocks->append(this);
\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
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
40 bool FunctionalBlock::isFunctionalBlock() {
\r
44 bool FunctionalBlock::isSourceBlock() {
\r
45 if (parent == NULL) return true;
\r
49 void FunctionalBlock::populate() {
\r
52 AbstractInterface* inter;
\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
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
67 inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));
\r
69 catch(Exception e) {
\r
70 cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;
\r
73 hashIface.insert(lstRef.at(i),inter);
\r
75 addInterface(inter);
\r
78 AbstractInterface* funCtlIface = NULL;
\r
79 AbstractInterface* funDataIface = NULL;
\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
95 QString FunctionalBlock::getReferenceXmlFile() {
\r
96 return ((ReferenceBlock *)reference)->getXmlFile();
\r
99 QString FunctionalBlock::getReferenceHashMd5()
\r
101 return ((ReferenceBlock *)reference)->getHashMd5();
\r