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

Private GIT Repository
correct relative positionning of source/group
[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 bool GroupBlock::isTopGroupBlock() {
38   return topGroup;
39 }
40
41 void GroupBlock::setParent(AbstractBlock *_parent) {
42   parent = _parent;
43   if (parent != NULL) {
44     topGroup = false;
45   }
46 }
47
48 void GroupBlock::removeAllBlocks() {
49   foreach(AbstractBlock* block, blocks) {
50     if (block->isGroupBlock()) {
51       GroupBlock* group = AB_TO_GRP(block);
52       group->removeAllBlocks();
53     }
54     removeBlock(block);
55   }
56 }
57
58 void GroupBlock::removeBlock(AbstractBlock* block) {
59   /* CAUTION: no check is done if the block has connected interface
60      or not. Thus, they must be deleted elsewhere.
61   */
62   blocks.removeAll(block);
63   delete block;
64 }
65
66 AbstractBlock *GroupBlock::getFunctionalBlockByName(QString name) {
67   foreach(AbstractBlock* block, blocks) {
68     if (block->isFunctionalBlock()) {
69       if (block->getName() == name) return block;
70     }
71   }
72   return NULL;
73 }
74
75 void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
76
77   /*
78   checkedBlocks->append(this);
79
80   foreach(BlockParameter* param, params){
81     if(param->isUserParameter() && !param->isValueSet()){
82       if(!blocksToConfigure->contains(param->getOwner())){
83         blocksToConfigure->append(param->getOwner());
84       }
85     }
86   }
87   foreach(AbstractInterface *inter, outputs){
88     foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
89       if(!checkedBlocks->contains(connectedInter->getOwner())){
90         connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
91       }
92     }
93   }
94   */
95 }
96
97 void GroupBlock::addGenericParameter(QString name, QString type, QString value) {
98   BlockParameter* param = new BlockParameterGeneric(this, name, type, value);
99   params.append(param);
100 }
101
102 void GroupBlock::removeGenericParameter(QString name) {
103   BlockParameter* p = getParameterFromName(name);
104   if (p != NULL) params.removeAll(p);
105 }