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 void AbstractBlock::addParameter(BlockParameter *param) {
\r
56 params.append(param);
\r
60 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
61 foreach(BlockParameter* p, params) {
\r
62 if (p->getName() == name) return p;
\r
67 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
68 if(inter->getDirection() == AbstractInterface::Input){
\r
69 inputs.append(inter);
\r
70 } else if(inter->getDirection() == AbstractInterface::Output){
\r
71 outputs.append(inter);
\r
72 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
73 bidirs.append(inter);
\r
77 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
78 /* CAUTION: no check is done about the connection state of this interface
\r
79 Thus, if it is still connected to/from, there will be a crash
\r
81 if(inter->getDirection() == AbstractInterface::Input){
\r
82 inputs.removeAll(inter);
\r
83 } else if(inter->getDirection() == AbstractInterface::Output){
\r
84 outputs.removeAll(inter);
\r
85 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
86 bidirs.removeAll(inter);
\r
91 void AbstractBlock::removeAllInterfaces() {
\r
93 foreach(AbstractInterface* iface, inputs) {
\r
96 foreach(AbstractInterface* iface, outputs) {
\r
99 foreach(AbstractInterface* iface, bidirs) {
\r
108 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
110 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
112 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
114 while (!ok && value.isEmpty())
\r
116 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
117 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
119 param->setValue(value);
\r
122 QList<AbstractInterface *> AbstractBlock::getInterfaces() {
\r
123 QList<AbstractInterface *> list;
\r
124 list.append(inputs);
\r
125 list.append(outputs);
\r
126 list.append(bidirs);
\r
130 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
131 QList<AbstractInterface *> list;
\r
132 foreach(AbstractInterface* iface, inputs) {
\r
133 if (iface->getPurpose() == AbstractInterface::Data) {
\r
134 list.append(iface);
\r
140 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
142 foreach(AbstractInterface* iface, inputs) {
\r
143 if (iface->getName() == name) return iface;
\r
145 foreach(AbstractInterface* iface, outputs) {
\r
146 if (iface->getName() == name) return iface;
\r
148 foreach(AbstractInterface* iface, bidirs) {
\r
149 if (iface->getName() == name) return iface;
\r
154 bool AbstractBlock::isWBConfigurable() {
\r
156 foreach(BlockParameter* p, params) {
\r
157 if (p->isWishboneParameter()) return true;
\r
162 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
163 QList<BlockParameter *> lst;
\r
164 foreach(BlockParameter* p, params) {
\r
165 if (p->isUserParameter()) lst.append(p);
\r
170 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
171 QList<BlockParameter *> lst;
\r
172 foreach(BlockParameter* p, params) {
\r
173 if (p->isGenericParameter()) lst.append(p);
\r
178 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
179 QList<BlockParameter *> lst;
\r
180 foreach(BlockParameter* p, params) {
\r
181 if (p->isPortParameter()) lst.append(p);
\r
186 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
187 QList<BlockParameter *> lst;
\r
188 foreach(BlockParameter* p, params) {
\r
189 if (p->isWishboneParameter()) lst.append(p);
\r