1 #include <AbstractBlock.h>
\r
2 #include <QInputDialog>
\r
3 #include <QMessageBox>
\r
4 #include "AbstractInterface.h"
\r
5 #include "BlockParameter.h"
\r
6 #include "Parameters.h"
\r
7 #include "GroupBlock.h"
\r
8 #include "ConnectedInterface.h"
\r
11 AbstractBlock::AbstractBlock(Graph *_graph) {
\r
14 specialType = NotSpecial;
\r
19 AbstractBlock::AbstractBlock(const QString& _name) {
\r
20 name = Parameters::normalizeName(_name);
\r
25 AbstractBlock::~AbstractBlock() {
\r
27 removeAllInterfaces();
\r
29 foreach(BlockParameter* p, params) {
\r
35 void AbstractBlock::setName(const QString& str) {
\r
36 name = Parameters::normalizeName(str);
\r
39 void AbstractBlock::setSpecialType(int type) {
\r
40 if ((type >= NotSpecial) && (type <= ClkConvert)) {
\r
44 specialType = NotSpecial;
\r
48 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
52 bool AbstractBlock::isReferenceBlock() {
\r
56 bool AbstractBlock::isFunctionalBlock() {
\r
60 bool AbstractBlock::isSpecialBlock() {
\r
64 bool AbstractBlock::isGroupBlock() {
\r
68 bool AbstractBlock::isTopGroupBlock() {
\r
72 bool AbstractBlock::isStimuliBlock() {
\r
75 /* NB: a source is a block that has no data inputs
\r
76 * and has at least one data output.
\r
77 * By the way, blocks that have no data input/output
\r
78 * (like clkrstgen) are not sources !
\r
80 bool AbstractBlock::isSourceBlock() {
\r
81 if (getDataInputs().size() > 0) return false;
\r
82 if (getDataOutputs().size() == 0) return false;
\r
86 /* NB: a sink is a block without outputs of any type */
\r
87 bool AbstractBlock::isSinkBlock() {
\r
88 if (getOutputs().size() == 0) return true;
\r
92 int AbstractBlock::getSpecialTypeFromString(QString str) {
\r
93 if (str == "source") {
\r
96 else if (str == "sink") {
\r
99 else if (str == "clkconvert") {
\r
106 void AbstractBlock::addParameter(BlockParameter *param) {
\r
107 params.append(param);
\r
111 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
112 foreach(BlockParameter* p, params) {
\r
113 if (p->getName() == name) return p;
\r
118 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
119 if(inter->getDirection() == AbstractInterface::Input){
\r
120 inputs.append(inter);
\r
121 } else if(inter->getDirection() == AbstractInterface::Output){
\r
122 outputs.append(inter);
\r
123 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
124 bidirs.append(inter);
\r
128 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
129 /* CAUTION: no check is done about the connection state of this interface
\r
130 Thus, if it is still connected to/from, there will be a crash
\r
132 if(inter->getDirection() == AbstractInterface::Input){
\r
133 inputs.removeAll(inter);
\r
134 } else if(inter->getDirection() == AbstractInterface::Output){
\r
135 outputs.removeAll(inter);
\r
136 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
137 bidirs.removeAll(inter);
\r
142 void AbstractBlock::removeAllInterfaces() {
\r
144 foreach(AbstractInterface* iface, inputs) {
\r
147 foreach(AbstractInterface* iface, outputs) {
\r
150 foreach(AbstractInterface* iface, bidirs) {
\r
159 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
161 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
163 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
165 while (!ok && value.isEmpty())
\r
167 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
168 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
170 param->setValue(value);
\r
173 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
174 QList<AbstractInterface *> list;
\r
175 bool selIn = false;
\r
176 bool selOut = false;
\r
177 bool selInOut = false;
\r
179 if (direction == AbstractInterface::AnyDirection) {
\r
184 else if (direction == AbstractInterface::Input) {
\r
187 else if (direction == AbstractInterface::Output) {
\r
190 else if (direction == AbstractInterface::InOut) {
\r
194 foreach(AbstractInterface* iface, inputs) {
\r
195 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
199 foreach(AbstractInterface* iface, outputs) {
\r
200 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
204 foreach(AbstractInterface* iface, bidirs) {
\r
205 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
211 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
212 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
215 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
216 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
219 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
220 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
223 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
224 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
227 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
229 foreach(AbstractInterface* iface, inputs) {
\r
230 if (iface->getName() == name) return iface;
\r
232 foreach(AbstractInterface* iface, outputs) {
\r
233 if (iface->getName() == name) return iface;
\r
235 foreach(AbstractInterface* iface, bidirs) {
\r
236 if (iface->getName() == name) return iface;
\r
241 bool AbstractBlock::isWBConfigurable() {
\r
243 foreach(BlockParameter* p, params) {
\r
244 if (p->isWishboneParameter()) return true;
\r
249 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
250 QList<BlockParameter *> lst;
\r
251 foreach(BlockParameter* p, params) {
\r
252 if (p->isUserParameter()) lst.append(p);
\r
257 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
258 QList<BlockParameter *> lst;
\r
259 foreach(BlockParameter* p, params) {
\r
260 if (p->isGenericParameter()) lst.append(p);
\r
265 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
266 QList<BlockParameter *> lst;
\r
267 foreach(BlockParameter* p, params) {
\r
268 if (p->isPortParameter()) lst.append(p);
\r
273 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
274 QList<BlockParameter *> lst;
\r
275 foreach(BlockParameter* p, params) {
\r
276 if (p->isWishboneParameter()) lst.append(p);
\r
281 void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {
\r
283 out << "entity " << name << " is" << endl;
\r
285 generateEntityOrComponentBody(out, 0, hasController);
\r
287 catch(Exception e) {
\r
290 out << "end entity " << name << ";" << endl << endl;
\r
293 void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {
\r
295 out << " component " << name << " is" << endl;
\r
297 generateEntityOrComponentBody(out, 2, hasController);
\r
299 catch(Exception e) {
\r
302 out << " end component; " << endl << endl;
\r