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 bool GroupBlock::isTopGroupBlock() {
41 void GroupBlock::setParent(AbstractBlock *_parent) {
48 void GroupBlock::removeAllBlocks() {
49 foreach(AbstractBlock* block, blocks) {
50 if (block->isGroupBlock()) {
51 GroupBlock* group = AB_TO_GRP(block);
52 group->removeAllBlocks();
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.
62 blocks.removeAll(block);
66 AbstractBlock *GroupBlock::getFunctionalBlockByName(QString name) {
67 foreach(AbstractBlock* block, blocks) {
68 if (block->isFunctionalBlock()) {
69 if (block->getName() == name) return block;
75 void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
78 checkedBlocks->append(this);
80 foreach(BlockParameter* param, params){
81 if(param->isUserParameter() && !param->isValueSet()){
82 if(!blocksToConfigure->contains(param->getOwner())){
83 blocksToConfigure->append(param->getOwner());
87 foreach(AbstractInterface *inter, outputs){
88 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
89 if(!checkedBlocks->contains(connectedInter->getOwner())){
90 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
97 void GroupBlock::addGenericParameter(QString name, QString type, QString value) {
98 BlockParameter* param = new BlockParameterGeneric(this, name, type, value);
102 void GroupBlock::removeGenericParameter(QString name) {
103 BlockParameter* p = getParameterFromName(name);
104 if (p != NULL) params.removeAll(p);