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

Private GIT Repository
added source items
[blast.git] / GroupBlock.cpp
1 #include "GroupBlock.h"
2 #include "BlockParameterGeneric.h"
3 #include "AbstractInterface.h"
4 #include "string.h"
5 #include <sstream>
6
7 int GroupBlock::counter = 1;
8
9 GroupBlock::GroupBlock(GroupBlock *_parent) throw(Exception) :  AbstractBlock() {
10
11   // force topGroup to false if this group has a parent
12   if (_parent != NULL) {    
13     topGroup = false;
14     name = QString("sub_group")+"_"+QString::number(counter++);
15   }
16   else {
17     topGroup = true;
18     name = QString("top_group");
19   }
20   parent = _parent;
21   if (parent != NULL) {
22     // adding this to the child blocks of parent
23     AB_TO_GRP(parent)->addBlock(this);
24   }
25 }
26
27 GroupBlock::~GroupBlock() {
28   foreach(AbstractBlock* block, blocks) {
29     delete block;
30   }
31 }
32
33 bool GroupBlock::isGroupBlock() {
34   return true;
35 }
36
37 void GroupBlock::setParent(AbstractBlock *_parent) {
38   parent = _parent;
39   if (parent != NULL) {
40     topGroup = false;
41   }
42 }
43
44 void GroupBlock::removeAllBlocks() {
45   foreach(AbstractBlock* block, blocks) {
46     if (block->isGroupBlock()) {
47       GroupBlock* group = AB_TO_GRP(block);
48       group->removeAllBlocks();
49     }
50     removeBlock(block);
51   }
52 }
53
54 void GroupBlock::removeBlock(AbstractBlock* block) {
55   /* CAUTION: no check is done if the block has connected interface
56      or not. Thus, they must be deleted elsewhere.
57   */
58   blocks.removeAll(block);
59   delete block;
60 }
61
62 AbstractBlock *GroupBlock::getFunctionalBlockByName(QString name) {
63   foreach(AbstractBlock* block, blocks) {
64     if (block->isFunctionalBlock()) {
65       if (block->getName() == name) return block;
66     }
67   }
68   return NULL;
69 }
70
71 void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
72
73   /*
74   checkedBlocks->append(this);
75
76   foreach(BlockParameter* param, params){
77     if(param->isUserParameter() && !param->isValueSet()){
78       if(!blocksToConfigure->contains(param->getOwner())){
79         blocksToConfigure->append(param->getOwner());
80       }
81     }
82   }
83   foreach(AbstractInterface *inter, outputs){
84     foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
85       if(!checkedBlocks->contains(connectedInter->getOwner())){
86         connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
87       }
88     }
89   }
90   */
91 }
92
93 void GroupBlock::addGenericParameter(QString name, QString type, QString value) {
94   BlockParameter* param = new BlockParameterGeneric(this, name, type, value);
95   params.append(param);
96 }
97
98 void GroupBlock::removeGenericParameter(QString name) {
99   BlockParameter* p = getParameterFromName(name);
100   if (p != NULL) params.removeAll(p);
101 }