2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
7 topGroup = new GroupBlock(NULL);
8 topGroup->setName("top group");
9 groups.append(topGroup);
17 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
18 return topGroup->getInterfaces();
21 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent) {
22 GroupBlock* b = new GroupBlock(parent);
27 bool Graph::removeGroupBlock(GroupBlock *group) {
28 group->removeAllBlocks();
29 GroupBlock* parent = AB_TO_GRP(group->getParent());
30 parent->removeBlock(group);
31 groups.removeAll(group);
34 GroupBlock* Graph::getGroupBlockByName(QString name) {
35 foreach(GroupBlock* group, groups) {
36 if (group->getName() == name) return group;
41 FunctionalBlock* Graph::createFunctionalBlock(GroupBlock* group, ReferenceBlock* ref) {
43 FunctionalBlock* newBlock = new FunctionalBlock(group,ref);
45 group->addBlock(newBlock);
50 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
52 ReferenceBlock* ref = block->getReference();
53 GroupBlock* group = AB_TO_GRP(block->getParent());
55 // adding to the graph
56 FunctionalBlock* newBlock = createFunctionalBlock(group,ref);
61 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
62 GroupBlock* group = AB_TO_GRP(block->getParent());
63 group->removeBlock(block);
67 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
68 FunctionalBlock* block = NULL;
70 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
73 foreach(GroupBlock* group, groups) {
74 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
75 if (block != NULL) return block;
81 FunctionalBlock* Graph::createSourceBlock(ReferenceBlock* ref) {
83 FunctionalBlock* newBlock = new FunctionalBlock(NULL,ref);
85 sources.append(newBlock);
89 FunctionalBlock* Graph::duplicateSourceBlock(FunctionalBlock *block) {
91 ReferenceBlock* ref = block->getReference();
92 GroupBlock* group = AB_TO_GRP(block->getParent());
94 // adding to the graph
95 FunctionalBlock* newBlock = createSourceBlock(ref);
99 FunctionalBlock* Graph::getSourceBlockByName(QString name) {
100 foreach(FunctionalBlock* block, sources) {
101 if (block->getName() == name) return block;
106 bool Graph::removeSourceBlock(FunctionalBlock *block) {
107 sources.removeAll(block);
111 bool Graph::createPatterns() {
113 foreach(AbstractBlock* block, sources) {
114 FunctionalBlock* funBlock = AB_TO_FUN(block);
115 ok = funBlock->createPatterns();
116 if (!ok) return false;
119 foreach(AbstractBlock* block, groups) {
120 GroupBlock* group = AB_TO_GRP(block);
121 foreach(AbstractBlock* inBlock, group->getBlocks()) {
122 if (inBlock->isFunctionalBlock()) {
123 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
124 ok = funBlock->createPatterns();
125 if (!ok) return false;
132 void Graph::resetPatternComputed() {
133 foreach(AbstractBlock* block, sources) {
134 block->setPatternComputed(false);
136 foreach(AbstractBlock* block, groups) {
137 GroupBlock* group = AB_TO_GRP(block);
138 group->setPatternComputed(false);
139 foreach(AbstractBlock* inBlock, group->getBlocks()) {
140 inBlock->setPatternComputed(false);