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 foreach(AbstractInterface* iface, inputs) {
\r
22 foreach(AbstractInterface* iface, outputs) {
\r
25 foreach(AbstractInterface* iface, bidirs) {
\r
31 foreach(BlockParameter* p, params) {
\r
37 void AbstractBlock::setName(const QString& str) {
\r
41 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
45 bool AbstractBlock::isReferenceBlock() {
\r
49 bool AbstractBlock::isFunctionalBlock() {
\r
53 bool AbstractBlock::isGroupBlock() {
\r
57 void AbstractBlock::addParameter(BlockParameter *param) {
\r
58 params.append(param);
\r
62 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
63 foreach(BlockParameter* p, params) {
\r
64 if (p->getName() == name) return p;
\r
69 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
70 if(inter->getDirection() == AbstractInterface::Input){
\r
71 inputs.append(inter);
\r
72 } else if(inter->getDirection() == AbstractInterface::Output){
\r
73 outputs.append(inter);
\r
74 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
75 bidirs.append(inter);
\r
79 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
80 /* CAUTION: no check is done about the connection state of this interface
\r
81 Thus, if it is still connected to/from, there will be a crash
\r
83 if(inter->getDirection() == AbstractInterface::Input){
\r
84 inputs.removeAll(inter);
\r
85 } else if(inter->getDirection() == AbstractInterface::Output){
\r
86 outputs.removeAll(inter);
\r
87 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
88 bidirs.removeAll(inter);
\r
93 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
95 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
97 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
99 while (!ok && value.isEmpty())
\r
101 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
102 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
104 param->setValue(value);
\r
107 QList<AbstractInterface *> AbstractBlock::getInterfaces() {
\r
108 QList<AbstractInterface *> list;
\r
109 list.append(inputs);
\r
110 list.append(outputs);
\r
111 list.append(bidirs);
\r
115 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
117 foreach(AbstractInterface* iface, inputs) {
\r
118 if (iface->getName() == name) return iface;
\r
120 foreach(AbstractInterface* iface, outputs) {
\r
121 if (iface->getName() == name) return iface;
\r
123 foreach(AbstractInterface* iface, bidirs) {
\r
124 if (iface->getName() == name) return iface;
\r
129 bool AbstractBlock::isWBConfigurable() {
\r
131 foreach(BlockParameter* p, params) {
\r
132 if (p->isWishboneParameter()) return true;
\r
137 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
138 QList<BlockParameter *> lst;
\r
139 foreach(BlockParameter* p, params) {
\r
140 if (p->isUserParameter()) lst.append(p);
\r
145 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
146 QList<BlockParameter *> lst;
\r
147 foreach(BlockParameter* p, params) {
\r
148 if (p->isGenericParameter()) lst.append(p);
\r
153 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
154 QList<BlockParameter *> lst;
\r
155 foreach(BlockParameter* p, params) {
\r
156 if (p->isPortParameter()) lst.append(p);
\r
161 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
162 QList<BlockParameter *> lst;
\r
163 foreach(BlockParameter* p, params) {
\r
164 if (p->isWishboneParameter()) lst.append(p);
\r