1 #include "BlockParameterGeneric.h"
\r
2 #include "GroupBlock.h"
\r
3 #include "FunctionalBlock.h"
\r
5 BlockParameterGeneric::BlockParameterGeneric() : BlockParameter() {
\r
6 userValue = defaultValue;
\r
9 BlockParameterGeneric::BlockParameterGeneric(AbstractBlock* _owner, const QString &_name, const QString &_type, const QString &_value) : BlockParameter(_owner, _name, _type, _value) {
\r
10 /* CAUTION: no check done on the type parameter !
\r
11 * It must never be "expression" but something that is numeric/boolean
\r
13 userValue = defaultValue;
\r
16 QVariant BlockParameterGeneric::getValue() {
\r
20 return defaultValue;
\r
23 bool BlockParameterGeneric::isGenericParameter() {
\r
27 void BlockParameterGeneric::setValue(const QString& _value) {
\r
28 userValue = QVariant(_value);
\r
32 bool BlockParameterGeneric::isValueSet() {
\r
33 if (userValue.isNull()) return false;
\r
37 bool BlockParameterGeneric::isDefaultValue() {
\r
38 if (userValue == defaultValue) return true;
\r
42 BlockParameter* BlockParameterGeneric::clone() {
\r
44 BlockParameter* block = new BlockParameterGeneric(owner,name,getTypeString(),defaultValue.toString());
\r
48 QString BlockParameterGeneric::toVHDL(int context, int flags) {
\r
53 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
\r
55 QString formatValue = "%1 : %2 := %3";
\r
56 QString formatNoValue = "%1 : %2";
\r
57 if ((flags & BlockParameter::NoComma) == 0) {
\r
58 formatValue.append(";");
\r
59 formatNoValue.append(";");
\r
62 QString typeStr = "";
\r
63 QString valueStr = "";
\r
64 if ((type == Boolean)||(type == Bit)) {
\r
65 typeStr = "std_logic";
\r
66 if (!userValue.isNull()) {
\r
67 valueStr = "'"+userValue.toString()+"'";
\r
68 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
70 else if (!defaultValue.isNull()) {
\r
71 valueStr = "'"+defaultValue.toString()+"'";
\r
72 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
75 ret = formatNoValue.arg(name).arg(typeStr);
\r
79 typeStr = getTypeString();
\r
80 if (!userValue.isNull()) {
\r
81 ret = formatValue.arg(name).arg(typeStr).arg(userValue.toString());
\r
83 else if (!defaultValue.isNull()) {
\r
84 ret = formatValue.arg(name).arg(typeStr).arg(defaultValue.toString());
\r
87 ret = formatNoValue.arg(name).arg(typeStr);
\r
91 else if (context == BlockParameter::Instance) {
\r
92 QString format = "%1 => %2";
\r
93 if ((flags & BlockParameter::NoComma) == 0) {
\r
96 AbstractBlock* parent = owner->getParent();
\r
97 BlockParameter* p = NULL;
\r
98 if (parent != NULL) {
\r
99 p = parent->getParameterFromName(name);
\r
102 /* the parent group has a generic parameter with the same
\r
105 ret = format.arg(name).arg(name);
\r
108 if (!userValue.isNull()) {
\r
109 if ((type == Boolean)||(type == Bit)) {
\r
110 ret = format.arg(name).arg("'"+userValue.toString()+"'");
\r
113 ret = format.arg(name).arg(userValue.toString());
\r
116 else if (!defaultValue.isNull()) {
\r
117 if ((type == Boolean)||(type == Bit)) {
\r
118 ret = format.arg(name).arg("'"+defaultValue.toString()+"'");
\r
121 ret = format.arg(name).arg(defaultValue.toString());
\r
126 ret = format.arg(name).arg("INVALID_VALUE");
\r