Added single automatic connection dialog + bugfixes
This commit is contained in:
1 parent
3172d7e4cf
commit
9b7ede933a
18 files changed
+253
-117
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include "schema_display.h"
|
||||
#include "application.h"
|
||||
#include "attribute_dialog.h"
|
||||
#include "single_automatic_dialog.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
@@ -87,27 +88,9 @@ namespace display {
|
||||
if (event->mimeData()->hasFormat("comdel/component")) {
|
||||
auto component = library->getComponent(event->mimeData()->data("comdel/component").toStdString());
|
||||
|
||||
auto attributes = std::vector<domain::InstanceAttribute>();
|
||||
for (auto attr: component.getAttributes()) {
|
||||
domain::InstanceAttribute attribute(attr.getName(), attr.getDefault(), attr);
|
||||
if(attr.getPopup().has_value() && attr.getPopup()->getType() == domain::Popup::AUTOMATIC) {
|
||||
if(attr.getDefault().isType(domain::Value::MEMORY_REFERENCE)) {
|
||||
auto dialog = new MemoryDialog(&attribute, schema->componentInstances);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
auto dialog = new AttributeDialog(&attribute);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
attributes.push_back(attribute);
|
||||
auto attributes = populateAttributes(component.getAttributes());
|
||||
if(attributes.size() != component.getAttributes().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto currentPos = this->mapToScene(event->pos()).toPoint();
|
||||
@@ -152,15 +135,18 @@ namespace display {
|
||||
auto busInstances = getAvailableConnectionBusses(instance, pin);
|
||||
|
||||
for (auto &bus: busInstances) {
|
||||
if(buses[bus->name] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto rect = buses[bus->name]->boundingRect();
|
||||
rect = QRectF(buses[bus->name]->x(), buses[bus->name]->y(), rect.width(), rect.height());
|
||||
|
||||
if (rect.contains(endPoint)) {
|
||||
auto con = library->getConnection({instance->component.getName(), pin.getName()}, bus->bus.getName());
|
||||
if (con.has_value()) {
|
||||
std::vector<domain::InstanceAttribute> attributes;
|
||||
for (auto attr: con->getAttributes()) {
|
||||
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
auto attributes = populateAttributes(con->getAttributes());
|
||||
if(attributes.size() != con->getAttributes().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto conInstance = std::make_shared<domain::BusConnectionInstance>(instance, attributes, bus, *con);
|
||||
@@ -189,13 +175,16 @@ namespace display {
|
||||
auto con = library->getConnection({instance->component.getName(), pin.getName()},
|
||||
{name, pinInstance.pin});
|
||||
if (con.has_value()) {
|
||||
auto bus = library->getBus(con->getBus());
|
||||
auto busInstance = std::make_shared<domain::BusInstance>(bus.getName(), bus);
|
||||
schema->busInstances.push_back(busInstance);
|
||||
auto busInstance = Application::instance()->addBus(library->getBus(con->getBus()), 0, 0);
|
||||
|
||||
std::vector<domain::InstanceAttribute> attributes;
|
||||
for (auto attr: con->getAttributes()) {
|
||||
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
if(library->getBus(con->getBus()).getType() == domain::Bus::SINGLE_AUTOMATIC) {
|
||||
attributes = populateSingleAutomaticConnection(*con);
|
||||
} else {
|
||||
attributes = populateAttributes(con->getAttributes());
|
||||
}
|
||||
if(attributes.size() != con->getAttributes().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto conInstance = std::make_shared<domain::DirectConnectionInstance>(instance,
|
||||
@@ -294,4 +283,46 @@ namespace display {
|
||||
return instances;
|
||||
}
|
||||
|
||||
std::vector<domain::InstanceAttribute> Schema::populateAttributes(std::vector<domain::Attribute>& attributes) {
|
||||
std::vector<domain::InstanceAttribute> instanceAttributes;
|
||||
|
||||
for (auto attr: attributes) {
|
||||
domain::InstanceAttribute attribute(attr.getName(), attr.getDefault(), attr);
|
||||
if(attr.getPopup().has_value() && attr.getPopup()->getType() == domain::Popup::AUTOMATIC) {
|
||||
if(attr.getDefault().isType(domain::Value::MEMORY_REFERENCE)) {
|
||||
auto dialog = new MemoryDialog(&attribute, schema->componentInstances);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
auto dialog = new AttributeDialog(&attribute);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if any dialog isn't set, whole creation is rejected
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
instanceAttributes.push_back(attribute);
|
||||
}
|
||||
return instanceAttributes;
|
||||
}
|
||||
|
||||
std::vector<domain::InstanceAttribute> Schema::populateSingleAutomaticConnection(domain::Connection connection) {
|
||||
std::vector<domain::InstanceAttribute> instanceAttributes;
|
||||
|
||||
for (auto attr: connection.getAttributes()) {
|
||||
instanceAttributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
}
|
||||
|
||||
auto dialog = new display::SingleAutomaticDialog(instanceAttributes);
|
||||
if(dialog->exec() == QDialog::Rejected) {
|
||||
// if dialog is rejected, whole creation is rejected
|
||||
return {};
|
||||
}
|
||||
|
||||
return instanceAttributes;
|
||||
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
@@ -73,6 +73,10 @@ namespace display {
|
||||
|
||||
std::vector<domain::ConnectionComponent>
|
||||
getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||
|
||||
std::vector<domain::InstanceAttribute> populateAttributes(std::vector<domain::Attribute>& attributes);
|
||||
|
||||
std::vector<domain::InstanceAttribute> populateSingleAutomaticConnection(domain::Connection connection);
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// Created by bbr on 05.06.22..
|
||||
//
|
||||
|
||||
#include "single_automatic_dialog.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace display {
|
||||
SingleAutomaticDialog::SingleAutomaticDialog(std::vector<domain::InstanceAttribute> &values): attributes(values) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowTitle(QString::fromStdString("Postavi poveznicu"));
|
||||
|
||||
firstValue = values[0].value;
|
||||
secondValue = values[1].value;
|
||||
|
||||
auto *parentLayout = new QVBoxLayout(this);
|
||||
auto *contentLayout = new QHBoxLayout(this);
|
||||
auto *firstLayout = new QVBoxLayout(this);
|
||||
auto *secondLayout = new QVBoxLayout(this);
|
||||
|
||||
parentLayout->addLayout(contentLayout);
|
||||
contentLayout->addLayout(firstLayout);
|
||||
contentLayout->addLayout(secondLayout);
|
||||
this->setLayout(parentLayout);
|
||||
|
||||
setupValues(firstLayout, values[0], &SingleAutomaticDialog::onFirstEnumerationChanged);
|
||||
setupValues(secondLayout, values[1], &SingleAutomaticDialog::onSecondEnumerationChanged);
|
||||
|
||||
auto button = new QPushButton("Ažuriraj");
|
||||
connect(button, &QPushButton::clicked, this, &SingleAutomaticDialog::onUpdate);
|
||||
parentLayout->addWidget(button);
|
||||
}
|
||||
|
||||
void SingleAutomaticDialog::setupValues(QVBoxLayout *layout, domain::InstanceAttribute &attribute, void (display::SingleAutomaticDialog::* handler)(int)) {
|
||||
|
||||
auto popup = *attribute.attribute.getPopup();
|
||||
|
||||
layout->addWidget(new QLabel(popup.getTitle().c_str()));
|
||||
layout->addWidget(new QLabel(popup.getText().c_str()));
|
||||
|
||||
auto *combo = new QComboBox(this);
|
||||
auto enumeration = attribute.attribute.getPopup()->getEnumeration();
|
||||
for (auto entry: enumeration) {
|
||||
combo->addItem(QString::fromStdString(entry.getName()));
|
||||
}
|
||||
|
||||
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,handler);
|
||||
layout->addWidget(combo);
|
||||
|
||||
for (int i = 0; i < enumeration.size(); i++) {
|
||||
if (attribute.value.equals(enumeration[i].getValue())) {
|
||||
combo->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SingleAutomaticDialog::onFirstEnumerationChanged(int index) {
|
||||
firstValue = attributes[0].attribute.getPopup()->getEnumeration()[index].getValue();
|
||||
}
|
||||
|
||||
void SingleAutomaticDialog::onSecondEnumerationChanged(int index) {
|
||||
secondValue = attributes[1].attribute.getPopup()->getEnumeration()[index].getValue();
|
||||
}
|
||||
|
||||
void SingleAutomaticDialog::onUpdate() {
|
||||
attributes[0].value = firstValue;
|
||||
attributes[1].value = secondValue;
|
||||
accept();
|
||||
}
|
||||
|
||||
} // display
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by bbr on 05.06.22..
|
||||
//
|
||||
|
||||
#ifndef SCHEMEEDITOR_SINGLE_AUTOMATIC_DIALOG_H
|
||||
#define SCHEMEEDITOR_SINGLE_AUTOMATIC_DIALOG_H
|
||||
|
||||
#include <vector>
|
||||
#include <QDialog>
|
||||
#include <QVBoxLayout>
|
||||
#include "comdel/domain/value.h"
|
||||
#include "comdel/domain/instance_attribute.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
class SingleAutomaticDialog: public QDialog {
|
||||
domain::Value firstValue;
|
||||
domain::Value secondValue;
|
||||
std::vector<domain::InstanceAttribute> &attributes;
|
||||
|
||||
public:
|
||||
explicit SingleAutomaticDialog(std::vector<domain::InstanceAttribute>& values);
|
||||
|
||||
void setupValues(QVBoxLayout *layout, domain::InstanceAttribute &attribute, void (display::SingleAutomaticDialog::* handler)(int));
|
||||
|
||||
public slots:
|
||||
|
||||
void onFirstEnumerationChanged(int index);
|
||||
void onSecondEnumerationChanged(int index);
|
||||
void onUpdate();
|
||||
};
|
||||
|
||||
} // display
|
||||
|
||||
#endif //SCHEMEEDITOR_SINGLE_AUTOMATIC_DIALOG_H
|
||||
@@ -59,4 +59,8 @@ namespace domain {
|
||||
return popup;
|
||||
}
|
||||
|
||||
void Attribute::setPupup(std::optional<Popup> popup) {
|
||||
this->popup = popup;
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
@@ -54,7 +54,7 @@ namespace domain {
|
||||
|
||||
void setEnumeration(std::vector<Enumeration> enums) {
|
||||
enumerated = true;
|
||||
enumeration = std::move(enums);
|
||||
enumeration = enums;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -71,6 +71,7 @@ namespace domain {
|
||||
Value getDefault();
|
||||
|
||||
std::optional<Popup> getPopup();
|
||||
void setPupup(std::optional<Popup> popup);
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace domain {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<Attribute> Component::getAttributes() {
|
||||
std::vector<Attribute>& Component::getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace domain {
|
||||
|
||||
Pin getPin(std::string pin);
|
||||
|
||||
std::vector<Attribute> getAttributes();
|
||||
std::vector<Attribute>& getAttributes();
|
||||
|
||||
Attribute getAttribute(std::string attribute);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace domain {
|
||||
return bus;
|
||||
}
|
||||
|
||||
std::vector<Attribute> Connection::getAttributes() {
|
||||
std::vector<Attribute>& Connection::getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace domain {
|
||||
|
||||
std::string getBus();
|
||||
|
||||
std::vector<Attribute> getAttributes();
|
||||
std::vector<Attribute>& getAttributes();
|
||||
|
||||
std::vector<Value> getWires();
|
||||
|
||||
|
||||
@@ -438,7 +438,9 @@ namespace domain {
|
||||
} else if (attributes[0].getDefault().getType() != Value::STRING) {
|
||||
errors.emplace_back(node.attributes[0].span, "@attribute must be of type string");
|
||||
} else {
|
||||
attributes[0].getPopup()->setEnumeration(createWireEnumeration(firstWires));
|
||||
domain::Popup popup = *attributes[0].getPopup();
|
||||
popup.setEnumeration(createWireEnumeration(firstWires));
|
||||
attributes[0].setPupup(popup);
|
||||
}
|
||||
|
||||
if (!attributes[1].getPopup().has_value()) {
|
||||
@@ -446,7 +448,9 @@ namespace domain {
|
||||
} else if (attributes[1].getDefault().getType() != Value::STRING) {
|
||||
errors.emplace_back(node.attributes[1].span, "@attribute must be of type string");
|
||||
} else {
|
||||
attributes[1].getPopup()->setEnumeration(createWireEnumeration(secondWires));
|
||||
domain::Popup popup = *attributes[1].getPopup();
|
||||
popup.setEnumeration(createWireEnumeration(secondWires));
|
||||
attributes[1].setPupup(popup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -935,12 +939,22 @@ namespace domain {
|
||||
auto attribute = connection->getAttribute(attr.name.value);
|
||||
auto value = toType(attr.value);
|
||||
|
||||
bool valueFound = false;
|
||||
|
||||
// all connection attributes must be of type enumeration
|
||||
for (auto &en: attribute.getPopup()->getEnumeration()) {
|
||||
if (en.getValue().asReference() == value.asReference()) {
|
||||
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
|
||||
if (en.getValue().equals(value)) {
|
||||
valueFound = true;
|
||||
break;
|
||||
} else if(value.isType(Value::UNDEFINED)) {
|
||||
if(en.getValue().isType(Value::WIRE_REFERENCE) && en.getValue().asReference() == value.asReference()) {
|
||||
value = Value::fromReference(value.asReference(), Value::WIRE_REFERENCE);
|
||||
valueFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value.isType(Value::UNDEFINED)) {
|
||||
if (!valueFound) {
|
||||
errors.emplace_back(attr.span, "invalid value");
|
||||
}
|
||||
|
||||
|
||||
@@ -50,12 +50,11 @@ bool ComdelParser::consume(TokenType tokenType) {
|
||||
do{}while(0)
|
||||
|
||||
void ComdelParser::bump() {
|
||||
if (tokens[position].type == TokenType::END_OF_FILE) {
|
||||
ATLAS_ASSERT_FAIL("Internal parser error, called bump after EOF");
|
||||
if (tokens[position].type != TokenType::END_OF_FILE) {
|
||||
++position;
|
||||
} else {
|
||||
tokens[++position];
|
||||
ATLAS_ASSERT_FAIL("Internal parser error, called bump after EOF");
|
||||
}
|
||||
|
||||
expectedTokens.clear();
|
||||
}
|
||||
|
||||
@@ -1348,7 +1347,7 @@ PResult<ValueNode> ComdelParser::parseConnectionWire() {
|
||||
bump();
|
||||
return spanner(ValueNode::ofNull());
|
||||
} else if (check(TokenType::STRING)) {
|
||||
return spanner(ValueNode::ofString(parseString()->value));
|
||||
return spanner(ValueNode::ofString(parseString()->asString()));
|
||||
} else if (check(TokenType::IDENTIFIER)) {
|
||||
return spanner(ValueNode::ofIdentifier(parseIdentifier()->value));
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user