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
54 /* NB: a generator is a block that has no data inputs
\r
55 * and has at least one data output.
\r
57 bool AbstractBlock::isGeneratorBlock() {
\r
58 if (getDataInputs().size() > 0) return false;
\r
63 void AbstractBlock::addParameter(BlockParameter *param) {
\r
64 params.append(param);
\r
68 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
69 foreach(BlockParameter* p, params) {
\r
70 if (p->getName() == name) return p;
\r
75 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
76 if(inter->getDirection() == AbstractInterface::Input){
\r
77 inputs.append(inter);
\r
78 } else if(inter->getDirection() == AbstractInterface::Output){
\r
79 outputs.append(inter);
\r
80 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
81 bidirs.append(inter);
\r
85 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
86 /* CAUTION: no check is done about the connection state of this interface
\r
87 Thus, if it is still connected to/from, there will be a crash
\r
89 if(inter->getDirection() == AbstractInterface::Input){
\r
90 inputs.removeAll(inter);
\r
91 } else if(inter->getDirection() == AbstractInterface::Output){
\r
92 outputs.removeAll(inter);
\r
93 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
94 bidirs.removeAll(inter);
\r
99 void AbstractBlock::removeAllInterfaces() {
\r
101 foreach(AbstractInterface* iface, inputs) {
\r
104 foreach(AbstractInterface* iface, outputs) {
\r
107 foreach(AbstractInterface* iface, bidirs) {
\r
116 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
118 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
120 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
122 while (!ok && value.isEmpty())
\r
124 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
125 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
127 param->setValue(value);
\r
130 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
131 QList<AbstractInterface *> list;
\r
132 bool selIn = false;
\r
133 bool selOut = false;
\r
134 bool selInOut = false;
\r
136 if (direction == AbstractInterface::AnyDirection) {
\r
141 else if (direction == AbstractInterface::Input) {
\r
144 else if (direction == AbstractInterface::Output) {
\r
147 else if (direction == AbstractInterface::InOut) {
\r
151 foreach(AbstractInterface* iface, inputs) {
\r
152 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
156 foreach(AbstractInterface* iface, outputs) {
\r
157 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
161 foreach(AbstractInterface* iface, bidirs) {
\r
162 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
168 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
169 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
172 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
173 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
176 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
177 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
180 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
181 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
184 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
186 foreach(AbstractInterface* iface, inputs) {
\r
187 if (iface->getName() == name) return iface;
\r
189 foreach(AbstractInterface* iface, outputs) {
\r
190 if (iface->getName() == name) return iface;
\r
192 foreach(AbstractInterface* iface, bidirs) {
\r
193 if (iface->getName() == name) return iface;
\r
198 bool AbstractBlock::isWBConfigurable() {
\r
200 foreach(BlockParameter* p, params) {
\r
201 if (p->isWishboneParameter()) return true;
\r
206 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
207 QList<BlockParameter *> lst;
\r
208 foreach(BlockParameter* p, params) {
\r
209 if (p->isUserParameter()) lst.append(p);
\r
214 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
215 QList<BlockParameter *> lst;
\r
216 foreach(BlockParameter* p, params) {
\r
217 if (p->isGenericParameter()) lst.append(p);
\r
222 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
223 QList<BlockParameter *> lst;
\r
224 foreach(BlockParameter* p, params) {
\r
225 if (p->isPortParameter()) lst.append(p);
\r
230 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
231 QList<BlockParameter *> lst;
\r
232 foreach(BlockParameter* p, params) {
\r
233 if (p->isWishboneParameter()) lst.append(p);
\r