1 #include <AbstractBlock.h>
\r
2 #include <QInputDialog>
\r
3 #include <QMessageBox>
\r
4 #include "AbstractInterface.h"
\r
5 #include "BlockParameter.h"
\r
7 AbstractBlock::AbstractBlock() {
\r
12 AbstractBlock::AbstractBlock(const QString& _name) {
\r
17 AbstractBlock::~AbstractBlock() {
\r
19 removeAllInterfaces();
\r
21 foreach(BlockParameter* p, params) {
\r
27 void AbstractBlock::setName(const QString& str) {
\r
31 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
35 bool AbstractBlock::isReferenceBlock() {
\r
39 bool AbstractBlock::isFunctionalBlock() {
\r
43 bool AbstractBlock::isGroupBlock() {
\r
47 bool AbstractBlock::isTopGroupBlock() {
\r
51 bool AbstractBlock::isSourceBlock() {
\r
55 bool AbstractBlock::isGeneratorBlock() {
\r
56 foreach(AbstractInterface* iface, inputs) {
\r
57 if (iface->getPurpose() == AbstractInterface::Data) return false;
\r
62 void AbstractBlock::addParameter(BlockParameter *param) {
\r
63 params.append(param);
\r
67 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
68 foreach(BlockParameter* p, params) {
\r
69 if (p->getName() == name) return p;
\r
74 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
75 if(inter->getDirection() == AbstractInterface::Input){
\r
76 inputs.append(inter);
\r
77 } else if(inter->getDirection() == AbstractInterface::Output){
\r
78 outputs.append(inter);
\r
79 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
80 bidirs.append(inter);
\r
84 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
85 /* CAUTION: no check is done about the connection state of this interface
\r
86 Thus, if it is still connected to/from, there will be a crash
\r
88 if(inter->getDirection() == AbstractInterface::Input){
\r
89 inputs.removeAll(inter);
\r
90 } else if(inter->getDirection() == AbstractInterface::Output){
\r
91 outputs.removeAll(inter);
\r
92 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
93 bidirs.removeAll(inter);
\r
98 void AbstractBlock::removeAllInterfaces() {
\r
100 foreach(AbstractInterface* iface, inputs) {
\r
103 foreach(AbstractInterface* iface, outputs) {
\r
106 foreach(AbstractInterface* iface, bidirs) {
\r
115 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
117 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
119 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
121 while (!ok && value.isEmpty())
\r
123 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
124 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
126 param->setValue(value);
\r
129 QList<AbstractInterface *> AbstractBlock::getInterfaces() {
\r
130 QList<AbstractInterface *> list;
\r
131 list.append(inputs);
\r
132 list.append(outputs);
\r
133 list.append(bidirs);
\r
137 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
138 QList<AbstractInterface *> list;
\r
139 foreach(AbstractInterface* iface, inputs) {
\r
140 if (iface->getPurpose() == AbstractInterface::Data) {
\r
141 list.append(iface);
\r
147 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
148 QList<AbstractInterface *> list;
\r
149 foreach(AbstractInterface* iface, inputs) {
\r
150 if (iface->getPurpose() == AbstractInterface::Control) {
\r
151 list.append(iface);
\r
157 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
158 QList<AbstractInterface *> list;
\r
159 foreach(AbstractInterface* iface, outputs) {
\r
160 if (iface->getPurpose() == AbstractInterface::Control) {
\r
161 list.append(iface);
\r
167 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
169 foreach(AbstractInterface* iface, inputs) {
\r
170 if (iface->getName() == name) return iface;
\r
172 foreach(AbstractInterface* iface, outputs) {
\r
173 if (iface->getName() == name) return iface;
\r
175 foreach(AbstractInterface* iface, bidirs) {
\r
176 if (iface->getName() == name) return iface;
\r
181 bool AbstractBlock::isWBConfigurable() {
\r
183 foreach(BlockParameter* p, params) {
\r
184 if (p->isWishboneParameter()) return true;
\r
189 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
190 QList<BlockParameter *> lst;
\r
191 foreach(BlockParameter* p, params) {
\r
192 if (p->isUserParameter()) lst.append(p);
\r
197 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
198 QList<BlockParameter *> lst;
\r
199 foreach(BlockParameter* p, params) {
\r
200 if (p->isGenericParameter()) lst.append(p);
\r
205 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
206 QList<BlockParameter *> lst;
\r
207 foreach(BlockParameter* p, params) {
\r
208 if (p->isPortParameter()) lst.append(p);
\r
213 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
214 QList<BlockParameter *> lst;
\r
215 foreach(BlockParameter* p, params) {
\r
216 if (p->isWishboneParameter()) lst.append(p);
\r