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 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
123 QList<AbstractInterface *> list;
\r
124 foreach(AbstractInterface* iface, inputs) {
\r
125 if (iface->getPurpose() == AbstractInterface::Data) {
\r
126 list.append(iface);
\r
132 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
134 foreach(AbstractInterface* iface, inputs) {
\r
135 if (iface->getName() == name) return iface;
\r
137 foreach(AbstractInterface* iface, outputs) {
\r
138 if (iface->getName() == name) return iface;
\r
140 foreach(AbstractInterface* iface, bidirs) {
\r
141 if (iface->getName() == name) return iface;
\r
146 bool AbstractBlock::isWBConfigurable() {
\r
148 foreach(BlockParameter* p, params) {
\r
149 if (p->isWishboneParameter()) return true;
\r
154 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
155 QList<BlockParameter *> lst;
\r
156 foreach(BlockParameter* p, params) {
\r
157 if (p->isUserParameter()) lst.append(p);
\r
162 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
163 QList<BlockParameter *> lst;
\r
164 foreach(BlockParameter* p, params) {
\r
165 if (p->isGenericParameter()) lst.append(p);
\r
170 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
171 QList<BlockParameter *> lst;
\r
172 foreach(BlockParameter* p, params) {
\r
173 if (p->isPortParameter()) lst.append(p);
\r
178 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
179 QList<BlockParameter *> lst;
\r
180 foreach(BlockParameter* p, params) {
\r
181 if (p->isWishboneParameter()) lst.append(p);
\r