diff --git a/comdel/display/attribute_dialog.h b/comdel/display/attribute_dialog.h index b7b538b..e098145 100644 --- a/comdel/display/attribute_dialog.h +++ b/comdel/display/attribute_dialog.h @@ -2,6 +2,8 @@ #define ATTRIBUTE_DIALOG_H #include +#include +#include #include #include #include @@ -15,9 +17,35 @@ namespace display { class AttributeDialog: public QDialog { + domain::Value value; + + long long int parseInt(std::string expression) { + try { + if (expression.size() > 2) { + if (expression.substr(0, 2) == "0x") { + return std::stoll(expression, 0, 16); + } else if (expression.substr(0, 2) == "0b") { + return std::stoll(expression, 0, 2); + } else { + return std::stoll(expression, 0, 10); + } + } else { + return std::stoll(expression, 0, 10); + } + } catch (std::exception &e) { + return 0; + } + } + + domain::InstanceAttribute* attributeValue; public: AttributeDialog(domain::InstanceAttribute *attribute) { + + setAttribute(Qt::WA_DeleteOnClose); + + attributeValue = attribute; + this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName())); auto layout = new QVBoxLayout(this); @@ -28,12 +56,29 @@ public: layout->addWidget(new QLabel(popup.getText().c_str())); auto type = attribute->attribute.getDefault().getType(); + value = attribute->value; if(attribute->attribute.getPopup()->isEnumerated()) { + auto* combo = new QComboBox(this); + auto enumeration = attribute->attribute.getPopup()->getEnumeration(); + for(auto entry: enumeration) { + combo->addItem(QString::fromStdString(entry.getName()), QVariant::fromValue(NULL)); + } + + connect(combo, QOverload::of(&QComboBox::currentIndexChanged), this, &AttributeDialog::onEnumerationChanged); + layout->addWidget(combo); + + for(int i=0; ivalue.equals(enumeration[i].getValue())) { + combo->setCurrentIndex(i); + break; + } + } } else if(!(type == domain::Value::ValueType::WIRE_REFERENCE || type == domain::Value::ValueType::BOOL)) { auto edit = new QLineEdit(this); + connect(edit, &QLineEdit::textChanged, this, &AttributeDialog::onTextChanged); layout->addWidget(edit); switch (attribute->attribute.getDefault().getType()) { @@ -46,15 +91,20 @@ public: break; } - - } else if(type == domain::Value::ValueType::BOOL) { auto *group = new QGroupBox(this); - group->setCheckable(true); - group->setChecked(true); + + auto *radioLayout = new QHBoxLayout(group); + group->setLayout(radioLayout); auto isTrue = new QRadioButton("true", group); + connect(isTrue, &QRadioButton::clicked, [this]() { + this->value = domain::Value::fromBool(true); + }); auto isFalse = new QRadioButton("false", group); + connect(isFalse, &QRadioButton::clicked, [this]() { + this->value = domain::Value::fromBool(false); + }); if(attribute->value.asBool()) { isTrue->setChecked(true); @@ -62,10 +112,35 @@ public: isFalse->setChecked(true); } - - + radioLayout->addWidget(isTrue); + radioLayout->addWidget(isFalse); layout->addWidget(group); } + + auto button = new QPushButton("Ažuriraj"); + connect(button, &QPushButton::clicked, this, &AttributeDialog::onUpdate); + + layout->addWidget(button); + } + +public slots: + void onTextChanged(const QString& string) { + switch (value.getType()) { + case domain::Value::STRING: + value.setString(string.toStdString()); + break; + case domain::Value::INT: + value = domain::Value::fromInt(parseInt(string.toStdString())); + } + }; + + void onEnumerationChanged(int index) { + value = attributeValue->attribute.getPopup()->getEnumeration()[index].getValue(); + } + + void onUpdate() { + attributeValue->value = value; + accept(); } }; diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index 2ac3d9c..90f1885 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -1,4 +1,6 @@ #include "component_display.h" +#include "attribute_dialog.h" +#include "name_dialog.h" #include #include @@ -11,11 +13,15 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; menu.addAction("Izmjeni ime", [this](){}); menu.addSeparator(); - for(auto attr: this->instance->attributes) { - bool enabled = attr.attribute.getPopup().has_value(); + for(int i=0; iinstance->attributes.size(); i++) { + auto* attr = &this->instance->attributes[i]; + bool enabled = attr->attribute.getPopup().has_value(); - auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr.name), - [&attr, this]() {}); + auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), + [attr]() { + auto dialog = new AttributeDialog(attr); + dialog->exec(); + }); action->setEnabled(enabled); } menu.exec(event->screenPos()); diff --git a/comdel/domain/attribute.cpp b/comdel/domain/attribute.cpp index e57a930..8e79006 100644 --- a/comdel/domain/attribute.cpp +++ b/comdel/domain/attribute.cpp @@ -6,7 +6,7 @@ Enumeration::Enumeration(std::string name, Value value) : name(name), value(value) {} -std::string Enumeration::getName() { +std::string& Enumeration::getName() { return name; } Value Enumeration::getValue() { diff --git a/comdel/domain/attribute.h b/comdel/domain/attribute.h index f00b15a..b4730b2 100644 --- a/comdel/domain/attribute.h +++ b/comdel/domain/attribute.h @@ -15,7 +15,7 @@ class Enumeration { public: Enumeration(std::string name, Value value); - std::string getName(); + std::string& getName(); Value getValue(); }; diff --git a/comdel/domain/value.h b/comdel/domain/value.h index 6b1550c..d2c1ff4 100644 --- a/comdel/domain/value.h +++ b/comdel/domain/value.h @@ -39,6 +39,29 @@ public: this->type = UNDEFINED; } + bool equals(Value value) { + if(value.getType() == type) { + switch (type) { + case INT: + return value.asInt() == intValue; + case STRING: + return value.asString() == stringValue; + case NIL: + case UNDEFINED: + return true; + case WIRE_REFERENCE: + case ATTRIBUTE_REFERENCE: + case ADDRESS_SPACE_REFERENCE: + return value.asReference() == reference; + case BOOL: + return value.asBool() == boolValue; + default: + return false; + } + } + return false; + } + std::string string(); ValueType getType(); diff --git a/examples/simplified FRISC model/frisc_library.csl b/examples/simplified FRISC model/frisc_library.csl index bcffd85..afdd202 100644 --- a/examples/simplified FRISC model/frisc_library.csl +++ b/examples/simplified FRISC model/frisc_library.csl @@ -75,6 +75,27 @@ @tooltip "Memorijska komponenta, mora postojati barem jedna" @count (1,1000) @source "memory.cdl" + + @attribute sinkroniziran bool default false { + @popup automatic { + @title "Postavite sinkroniziranost" + @text "Zadajte sinkronizaciju" + } + } + + + @attribute brzina int default 1 { + @popup automatic { + @title "Postavite brzinu memorije" + @text "Zadajte brzinu memorije" + @enumerated { + "Spora" = 1, + "Srednja" = 5, + "Brza" = 25, + } + } + } + @attribute kapacitet int default 65536 { @popup automatic { @title "Kapacitet memorije" @@ -171,6 +192,7 @@ @tooltip "DMA-kontroler" @count (1,1000) @source "dma.cdl" + @attribute pocetnaAdresa int default 0 { @popup automatic { @title "Početna adresa DMA-kontrolera" diff --git a/examples/simplified FRISC model/schema.csl b/examples/simplified FRISC model/schema.csl index b57dd57..3d1e795 100644 --- a/examples/simplified FRISC model/schema.csl +++ b/examples/simplified FRISC model/schema.csl @@ -7,6 +7,8 @@ @instance mem Memorija { @position (0, 250) + @attribute sinkroniziran false + @attribute brzina 1 @attribute kapacitet 1024 @attribute size 8 @attribute pocetnaAdresa 1023 diff --git a/examples/simplified FRISC model/schema2.csl b/examples/simplified FRISC model/schema2.csl index 82346d4..77177f1 100644 --- a/examples/simplified FRISC model/schema2.csl +++ b/examples/simplified FRISC model/schema2.csl @@ -7,9 +7,10 @@ @instance mem Memorija { @position (0, 250) - @attribute kapacitet 1024 + @attribute brzina 25 + @attribute kapacitet 2048 @attribute size 8 - @attribute pocetnaAdresa 1023 + @attribute pocetnaAdresa 0 } @instance bus glavnaSabirnica { @@ -17,18 +18,17 @@ @size 100 } - @wire wire_001 { - @position (50, 116) - @display {} - } - @wire wire_002 { - @position (50, 220) - @display {} + @instance testBus Test { + @position (0, 200) + @size 0 } + @connection (proc.glavniPin, bus) { - @wire wire_001 } @connection (mem.glavniPin, bus) { - @wire wire_002 + } + @connection (proc.glavniPin, testBus, mem.glavniPin) { + @attribute dmaPoveznica "READY" + @attribute mmaPoveznica "PIO_DATA" } }