1 #include "GroupBlock.h"
2 #include "BlockParameterGeneric.h"
3 #include "AbstractInterface.h"
4 #include "ConnectedInterface.h"
8 int GroupBlock::counter = 1;
10 GroupBlock::GroupBlock(GroupBlock *_parent) throw(Exception) : AbstractBlock() {
12 // force topGroup to false if this group has a parent
13 if (_parent != NULL) {
15 name = QString("sub_group")+"_"+QString::number(counter++);
19 name = QString("top_group");
23 // adding this to the child blocks of parent
24 AB_TO_GRP(parent)->addBlock(this);
28 GroupBlock::~GroupBlock() {
29 foreach(AbstractBlock* block, blocks) {
34 bool GroupBlock::isGroupBlock() {
38 bool GroupBlock::isTopGroupBlock() {
42 void GroupBlock::setParent(AbstractBlock *_parent) {
49 void GroupBlock::removeAllBlocks() {
50 foreach(AbstractBlock* block, blocks) {
51 if (block->isGroupBlock()) {
52 GroupBlock* group = AB_TO_GRP(block);
53 group->removeAllBlocks();
59 void GroupBlock::removeBlock(AbstractBlock* block) {
60 /* CAUTION: no check is done if the block has connected interface
61 or not. Thus, they must be deleted elsewhere.
63 blocks.removeAll(block);
67 AbstractBlock *GroupBlock::getFunctionalBlockByName(QString name) {
68 foreach(AbstractBlock* block, blocks) {
69 if (block->isFunctionalBlock()) {
70 if (block->getName() == name) return block;
76 void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
79 checkedBlocks->append(this);
81 foreach(BlockParameter* param, params){
82 if(param->isUserParameter() && !param->isValueSet()){
83 if(!blocksToConfigure->contains(param->getOwner())){
84 blocksToConfigure->append(param->getOwner());
88 foreach(AbstractInterface *inter, outputs){
89 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
90 if(!checkedBlocks->contains(connectedInter->getOwner())){
91 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
98 void GroupBlock::addGenericParameter(QString name, QString type, QString value) {
99 BlockParameter* param = new BlockParameterGeneric(this, name, type, value);
100 params.append(param);
103 void GroupBlock::removeGenericParameter(QString name) {
104 BlockParameter* p = getParameterFromName(name);
105 if (p != NULL) params.removeAll(p);
108 void GroupBlock::initInputPattern() {
109 foreach(AbstractInterface* iface, getControlInputs()) {
110 iface->setOutputPattern(iface->getConnectedFrom()->getOutputPattern());
114 bool GroupBlock::computeOutputPattern(int nbExec) {
116 bool canCompute = true;
117 // get the input pattern on each inputs
120 // find blocks that are connected to that inputs and generators
121 QList<AbstractBlock*> fifo;
122 foreach(AbstractBlock* block, blocks) {
125 // if a block is a generator and has control outputs, add it
126 if (block->isGeneratorBlock()) {
127 if (block->getControlOutputs().size() > 0) addIt = true;
130 // if the block has a control input connected from an intput of the group, add it too
131 foreach(AbstractInterface* iface, block->getControlInputs()) {
132 ConnectedInterface* conn = (ConnectedInterface*)iface;
133 ConnectedInterface* groupIface = conn->getConnectionFromParentGroup();
134 if (groupIface != NULL) {
140 if (addIt) fifo.append(block);
142 while (!fifo.isEmpty()) {
143 AbstractBlock* block = fifo.takeFirst();
144 cout << "computing pattern for " << qPrintable(block->getName()) << endl;
145 canCompute = block->computeOutputPattern();
147 cout << "cannot finalize output pattern computation of " << qPrintable(block->getName()) << endl;
150 block->setPatternComputed(true);
151 // add other blocks connected from block to the fifo
152 foreach(AbstractInterface* iface, block->getControlOutputs()) {
153 ConnectedInterface* conn = (ConnectedInterface*)iface;
154 foreach(ConnectedInterface* connTo, conn->getConnectedTo()) {
155 /* if connTo is owned by a functional block
156 or by a group block that is within this, add the block to the fifo.
158 if (connTo->getOwner()->isFunctionalBlock()) {
159 fifo.append(connTo->getOwner());
161 else if (connTo->getOwner() != this) {
162 fifo.append(connTo->getOwner());
169 foreach(AbstractInterface* iface, getControlOutputs()) {
170 iface->setOutputPattern(iface->getConnectedFrom()->getOutputPattern());
172 setPatternComputed(true);