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
79 * A source may also be a block of special type source.
\r
81 bool AbstractBlock::isSourceBlock() {
\r
82 if (specialType == Source) return true;
\r
83 if (getDataInputs().size() > 0) return false;
\r
84 if (getDataOutputs().size() == 0) return false;
\r
88 /* NB: a sink is a block without outputs of any type */
\r
89 bool AbstractBlock::isSinkBlock() {
\r
90 if (getOutputs().size() == 0) return true;
\r
94 int AbstractBlock::getSpecialTypeFromString(QString str) {
\r
95 if (str == "source") {
\r
98 else if (str == "sink") {
\r
101 else if (str == "clkconvert") {
\r
108 void AbstractBlock::addParameter(BlockParameter *param) {
\r
109 params.append(param);
\r
113 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
114 foreach(BlockParameter* p, params) {
\r
115 if (p->getName() == name) return p;
\r
120 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
121 if(inter->getDirection() == AbstractInterface::Input){
\r
122 inputs.append(inter);
\r
123 } else if(inter->getDirection() == AbstractInterface::Output){
\r
124 outputs.append(inter);
\r
125 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
126 bidirs.append(inter);
\r
130 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
131 /* CAUTION: no check is done about the connection state of this interface
\r
132 Thus, if it is still connected to/from, there will be a crash
\r
134 if(inter->getDirection() == AbstractInterface::Input){
\r
135 inputs.removeAll(inter);
\r
136 } else if(inter->getDirection() == AbstractInterface::Output){
\r
137 outputs.removeAll(inter);
\r
138 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
139 bidirs.removeAll(inter);
\r
144 void AbstractBlock::removeAllInterfaces() {
\r
146 foreach(AbstractInterface* iface, inputs) {
\r
149 foreach(AbstractInterface* iface, outputs) {
\r
152 foreach(AbstractInterface* iface, bidirs) {
\r
161 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
163 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
165 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
167 while (!ok && value.isEmpty())
\r
169 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
170 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
172 param->setValue(value);
\r
175 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
176 QList<AbstractInterface *> list;
\r
177 bool selIn = false;
\r
178 bool selOut = false;
\r
179 bool selInOut = false;
\r
181 if (direction == AbstractInterface::AnyDirection) {
\r
186 else if (direction == AbstractInterface::Input) {
\r
189 else if (direction == AbstractInterface::Output) {
\r
192 else if (direction == AbstractInterface::InOut) {
\r
196 foreach(AbstractInterface* iface, inputs) {
\r
197 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
201 foreach(AbstractInterface* iface, outputs) {
\r
202 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
206 foreach(AbstractInterface* iface, bidirs) {
\r
207 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
213 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
214 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
217 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
218 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
221 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
222 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
225 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
226 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
229 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
231 foreach(AbstractInterface* iface, inputs) {
\r
232 if (iface->getName() == name) return iface;
\r
234 foreach(AbstractInterface* iface, outputs) {
\r
235 if (iface->getName() == name) return iface;
\r
237 foreach(AbstractInterface* iface, bidirs) {
\r
238 if (iface->getName() == name) return iface;
\r
243 bool AbstractBlock::isWBConfigurable() {
\r
245 foreach(BlockParameter* p, params) {
\r
246 if (p->isWishboneParameter()) return true;
\r
251 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
252 QList<BlockParameter *> lst;
\r
253 foreach(BlockParameter* p, params) {
\r
254 if (p->isUserParameter()) lst.append(p);
\r
259 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
260 QList<BlockParameter *> lst;
\r
261 foreach(BlockParameter* p, params) {
\r
262 if (p->isGenericParameter()) lst.append(p);
\r
267 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
268 QList<BlockParameter *> lst;
\r
269 foreach(BlockParameter* p, params) {
\r
270 if (p->isPortParameter()) lst.append(p);
\r
275 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
276 QList<BlockParameter *> lst;
\r
277 foreach(BlockParameter* p, params) {
\r
278 if (p->isWishboneParameter()) lst.append(p);
\r
283 void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {
\r
285 out << "entity " << name << " is" << endl;
\r
287 generateEntityOrComponentBody(out, 0, hasController);
\r
289 catch(Exception e) {
\r
292 out << "end entity " << name << ";" << endl << endl;
\r
295 void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {
\r
297 out << " component " << name << " is" << endl;
\r
299 generateEntityOrComponentBody(out, 2, hasController);
\r
301 catch(Exception e) {
\r
304 out << " end component; " << endl << endl;
\r