#include <QMessageBox>\r
#include "AbstractInterface.h"\r
#include "BlockParameter.h"\r
+#include "Parameters.h"\r
+#include "GroupBlock.h"\r
+#include "ConnectedInterface.h"\r
\r
-AbstractBlock::AbstractBlock() {\r
+\r
+AbstractBlock::AbstractBlock(Graph *_graph) {\r
name = "";\r
parent = NULL;\r
+ specialType = NotSpecial;\r
+ graph = _graph;\r
}\r
\r
+/*\r
AbstractBlock::AbstractBlock(const QString& _name) {\r
- name = _name;\r
+ name = Parameters::normalizeName(_name);\r
parent = NULL;\r
}\r
+*/\r
\r
AbstractBlock::~AbstractBlock() {\r
\r
}\r
\r
void AbstractBlock::setName(const QString& str) {\r
- name = str;\r
+ name = Parameters::normalizeName(str);\r
+}\r
+\r
+void AbstractBlock::setSpecialType(int type) {\r
+ if ((type >= NotSpecial) && (type <= ClkConvert)) {\r
+ specialType = type;\r
+ }\r
+ else {\r
+ specialType = NotSpecial;\r
+ }\r
}\r
\r
void AbstractBlock::setParent(AbstractBlock* _parent) {\r
return false;\r
}\r
\r
+bool AbstractBlock::isSpecialBlock() {\r
+ return false;\r
+}\r
+\r
bool AbstractBlock::isGroupBlock() {\r
return false;\r
}\r
return false;\r
}\r
\r
+bool AbstractBlock::isStimuliBlock() {\r
+ return false;\r
+}\r
+/* NB: a source is a block that has no data inputs\r
+ * and has at least one data output.\r
+ * By the way, blocks that have no data input/output\r
+ * (like clkrstgen) are not sources !\r
+ */\r
bool AbstractBlock::isSourceBlock() {\r
+ if (getDataInputs().size() > 0) return false;\r
+ if (getDataOutputs().size() == 0) return false;\r
+ return true;\r
+}\r
+\r
+/* NB: a sink is a block without outputs of any type */\r
+bool AbstractBlock::isSinkBlock() {\r
+ if (getOutputs().size() == 0) return true;\r
return false;\r
}\r
\r
-bool AbstractBlock::isGeneratorBlock() {\r
- foreach(AbstractInterface* iface, inputs) {\r
- if (iface->getPurpose() == AbstractInterface::Data) return false;\r
+int AbstractBlock::getSpecialTypeFromString(QString str) {\r
+ if (str == "source") {\r
+ return Source;\r
}\r
- return true;\r
+ else if (str == "sink") {\r
+ return Sink;\r
+ }\r
+ else if (str == "clkconvert") {\r
+ return ClkConvert;\r
+ }\r
+ return NotSpecial;\r
}\r
\r
+\r
void AbstractBlock::addParameter(BlockParameter *param) {\r
params.append(param);\r
}\r
param->setValue(value); \r
}\r
\r
-QList<AbstractInterface *> AbstractBlock::getInterfaces() {\r
+QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {\r
QList<AbstractInterface *> list;\r
- list.append(inputs);\r
- list.append(outputs);\r
- list.append(bidirs);\r
+ bool selIn = false;\r
+ bool selOut = false;\r
+ bool selInOut = false;\r
+ \r
+ if (direction == AbstractInterface::AnyDirection) {\r
+ selIn = true;\r
+ selOut = true;\r
+ selInOut = true;\r
+ }\r
+ else if (direction == AbstractInterface::Input) {\r
+ selIn = true; \r
+ }\r
+ else if (direction == AbstractInterface::Output) {\r
+ selOut = true; \r
+ }\r
+ else if (direction == AbstractInterface::InOut) {\r
+ selInOut = true; \r
+ }\r
+ if (selIn) {\r
+ foreach(AbstractInterface* iface, inputs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
+ if (selOut) {\r
+ foreach(AbstractInterface* iface, outputs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
+ if (selInOut) {\r
+ foreach(AbstractInterface* iface, bidirs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
return list;\r
}\r
\r
QList<AbstractInterface *> AbstractBlock::getDataInputs() {\r
- QList<AbstractInterface *> list;\r
- foreach(AbstractInterface* iface, inputs) {\r
- if (iface->getPurpose() == AbstractInterface::Data) {\r
- list.append(iface);\r
- }\r
- }\r
- return list;\r
+ return getInterfaces(AbstractInterface::Input, AbstractInterface::Data); \r
+}\r
+\r
+QList<AbstractInterface *> AbstractBlock::getDataOutputs() {\r
+ return getInterfaces(AbstractInterface::Output, AbstractInterface::Data); \r
}\r
\r
QList<AbstractInterface *> AbstractBlock::getControlInputs() {\r
- QList<AbstractInterface *> list;\r
- foreach(AbstractInterface* iface, inputs) {\r
- if (iface->getPurpose() == AbstractInterface::Control) {\r
- list.append(iface);\r
- }\r
- }\r
- return list;\r
+ return getInterfaces(AbstractInterface::Input, AbstractInterface::Control); \r
}\r
\r
QList<AbstractInterface *> AbstractBlock::getControlOutputs() {\r
- QList<AbstractInterface *> list;\r
- foreach(AbstractInterface* iface, outputs) {\r
- if (iface->getPurpose() == AbstractInterface::Control) {\r
- list.append(iface);\r
- }\r
- }\r
- return list;\r
+ return getInterfaces(AbstractInterface::Output, AbstractInterface::Control); \r
}\r
\r
AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {\r
}\r
return lst;\r
}\r
+\r
+void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {\r
+\r
+ out << "entity " << name << " is" << endl;\r
+ try {\r
+ generateEntityOrComponentBody(out, 0, hasController);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ out << "end entity " << name << ";" << endl << endl;\r
+}\r
+\r
+void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {\r
+\r
+ out << " component " << name << " is" << endl;\r
+ try {\r
+ generateEntityOrComponentBody(out, 2, hasController);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ out << " end component; " << endl << endl;\r
+}\r
+\r
+\r