1 #include "GroupBlock.h"
2 #include "BlockParameterGeneric.h"
3 #include "AbstractInterface.h"
7 int GroupBlock::counter = 1;
9 GroupBlock::GroupBlock(GroupBlock *_parent) throw(Exception) : AbstractBlock() {
11 // force topGroup to false if this group has a parent
12 if (_parent != NULL) {
14 name = QString("sub_group")+"_"+QString::number(counter++);
18 name = QString("top_group");
22 // adding this to the child blocks of parent
23 AB_TO_GRP(parent)->addBlock(this);
27 GroupBlock::~GroupBlock() {
28 foreach(AbstractBlock* block, blocks) {
33 bool GroupBlock::isGroupBlock() {
37 void GroupBlock::setParent(AbstractBlock *_parent) {
44 void GroupBlock::removeAllBlocks() {
45 foreach(AbstractBlock* block, blocks) {
46 if (block->isGroupBlock()) {
47 GroupBlock* group = AB_TO_GRP(block);
48 group->removeAllBlocks();
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.
58 blocks.removeAll(block);
62 AbstractBlock *GroupBlock::getFunctionalBlockByName(QString name) {
63 foreach(AbstractBlock* block, blocks) {
64 if (block->isFunctionalBlock()) {
65 if (block->getName() == name) return block;
71 void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
74 checkedBlocks->append(this);
76 foreach(BlockParameter* param, params){
77 if(param->isUserParameter() && !param->isValueSet()){
78 if(!blocksToConfigure->contains(param->getOwner())){
79 blocksToConfigure->append(param->getOwner());
83 foreach(AbstractInterface *inter, outputs){
84 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
85 if(!checkedBlocks->contains(connectedInter->getOwner())){
86 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
93 void GroupBlock::addGenericParameter(QString name, QString type, QString value) {
94 BlockParameter* param = new BlockParameterGeneric(this, name, type, value);
98 void GroupBlock::removeGenericParameter(QString name) {
99 BlockParameter* p = getParameterFromName(name);
100 if (p != NULL) params.removeAll(p);