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 void AbstractBlock::addParameter(BlockParameter *param) {
\r
48 params.append(param);
\r
52 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
53 foreach(BlockParameter* p, params) {
\r
54 if (p->getName() == name) return p;
\r
59 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
60 if(inter->getDirection() == AbstractInterface::Input){
\r
61 inputs.append(inter);
\r
62 } else if(inter->getDirection() == AbstractInterface::Output){
\r
63 outputs.append(inter);
\r
64 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
65 bidirs.append(inter);
\r
69 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
70 /* CAUTION: no check is done about the connection state of this interface
\r
71 Thus, if it is still connected to/from, there will be a crash
\r
73 if(inter->getDirection() == AbstractInterface::Input){
\r
74 inputs.removeAll(inter);
\r
75 } else if(inter->getDirection() == AbstractInterface::Output){
\r
76 outputs.removeAll(inter);
\r
77 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
78 bidirs.removeAll(inter);
\r
83 void AbstractBlock::removeAllInterfaces() {
\r
85 foreach(AbstractInterface* iface, inputs) {
\r
88 foreach(AbstractInterface* iface, outputs) {
\r
91 foreach(AbstractInterface* iface, bidirs) {
\r
100 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
102 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
104 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
106 while (!ok && value.isEmpty())
\r
108 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
109 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
111 param->setValue(value);
\r
114 QList<AbstractInterface *> AbstractBlock::getInterfaces() {
\r
115 QList<AbstractInterface *> list;
\r
116 list.append(inputs);
\r
117 list.append(outputs);
\r
118 list.append(bidirs);
\r
122 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
124 foreach(AbstractInterface* iface, inputs) {
\r
125 if (iface->getName() == name) return iface;
\r
127 foreach(AbstractInterface* iface, outputs) {
\r
128 if (iface->getName() == name) return iface;
\r
130 foreach(AbstractInterface* iface, bidirs) {
\r
131 if (iface->getName() == name) return iface;
\r
136 bool AbstractBlock::isWBConfigurable() {
\r
138 foreach(BlockParameter* p, params) {
\r
139 if (p->isWishboneParameter()) return true;
\r
144 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
145 QList<BlockParameter *> lst;
\r
146 foreach(BlockParameter* p, params) {
\r
147 if (p->isUserParameter()) lst.append(p);
\r
152 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
153 QList<BlockParameter *> lst;
\r
154 foreach(BlockParameter* p, params) {
\r
155 if (p->isGenericParameter()) lst.append(p);
\r
160 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
161 QList<BlockParameter *> lst;
\r
162 foreach(BlockParameter* p, params) {
\r
163 if (p->isPortParameter()) lst.append(p);
\r
168 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
169 QList<BlockParameter *> lst;
\r
170 foreach(BlockParameter* p, params) {
\r
171 if (p->isWishboneParameter()) lst.append(p);
\r