Compare commits

..

5 Commits

Author SHA1 Message Date
Borna Rajković f66fc1db26 Updated translations + bugfixes 2022-06-09 20:24:27 +02:00
Borna Rajković 1759adf25a Moved connection determination to schema 2022-06-07 21:13:21 +02:00
Borna Rajković 1ec8b10ef5 Fixed schema generation 2022-06-06 01:10:11 +02:00
Borna Rajković 9b7ede933a Added single automatic connection dialog + bugfixes 2022-06-05 19:02:44 +02:00
Borna Rajković 3172d7e4cf Added component/bus deletion and rename 2022-06-02 01:37:14 +02:00
41 changed files with 930 additions and 378 deletions

View File

@ -34,8 +34,8 @@ add_executable(SchemeEditor
comdel/parser/tokens_type.cpp
comdel/parser/ast_nodes.cpp
comdel/parser/parser_util.cpp
comdel/parser/comdellexer.cpp
comdel/parser/comdel_lexer.cpp
main.cpp
mainwindow.ui
comdel/domain/comdel_validator.cpp comdel/domain/comdel_validator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h comdel/display/library_list.cpp comdel/display/library_list.h application.cpp application.h)
comdel/domain/comdel_validator.cpp comdel/domain/comdel_validator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h comdel/display/library_list.cpp comdel/display/library_list.h application.cpp application.h comdel/display/single_automatic_dialog.cpp comdel/display/single_automatic_dialog.h)
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)

View File

@ -9,77 +9,80 @@ CONFIG += c++17
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
comdel/display/attribute_dialog.cpp \
comdel/display/component_display.cpp \
comdel/display/library_display.cpp \
comdel/display/library_list.cpp \
comdel/display/name_dialog.cpp \
comdel/display/schema_display.cpp \
comdel/domain/addressspace.cpp \
comdel/display/single_automatic_dialog.cpp \
comdel/domain/address_space.cpp \
comdel/domain/attribute.cpp \
comdel/domain/bus.cpp \
comdel/domain/schemacreator.cpp \
comdel/domain/comdel_generator.cpp \
comdel/domain/comdel_validator.cpp \
comdel/domain/component.cpp \
comdel/domain/connection.cpp \
comdel/domain/comdelvalidator.cpp \
comdel/domain/connectioninstance.cpp \
comdel/domain/connection_instance.cpp \
comdel/domain/display.cpp \
comdel/domain/functionsignature.cpp \
comdel/domain/function_signature.cpp \
comdel/domain/instance.cpp \
comdel/domain/instanceattribute.cpp \
comdel/domain/instance_attribute.cpp \
comdel/domain/library.cpp \
comdel/domain/pin.cpp \
comdel/domain/rule.cpp \
comdel/domain/schema.cpp \
comdel/domain/schema_creator.cpp \
comdel/domain/value.cpp \
comdel/domain/wireinstance.cpp \
comdel/parser/astnode.cpp \
comdel/parser/comdellexer.cpp \
comdel/parser/comdelparser.cpp \
comdel/parser/parsecontext.cpp \
comdel/parser/parserutil.cpp \
comdel/parser/sourceerror.cpp \
comdel/parser/ast_nodes.cpp \
comdel/parser/comdel_lexer.cpp \
comdel/parser/comdel_parser.cpp \
comdel/parser/parse_context.cpp \
comdel/parser/parser_util.cpp \
comdel/parser/source_error.cpp \
comdel/parser/token.cpp \
comdel/parser/tokenstype.cpp \
comdel/display/dialogmanager.cpp \
comdel/display/attribute_dialog.cpp \
comdel/display/name_dialog.cpp \
comdel/parser/tokens_type.cpp \
application.cpp \
main.cpp \
mainwindow.cpp
HEADERS += \
comdel/display/attribute_dialog.h \
comdel/display/component_display.h \
comdel/display/library_display.h \
comdel/display/library_list.h \
comdel/display/name_dialog.h \
comdel/display/schema_display.h \
comdel/domain/addressspace.h \
comdel/display/single_automatic_dialog.h \
comdel/domain/address_space.h \
comdel/domain/attribute.h \
comdel/domain/bus.h \
comdel/domain/schemacreator.h \
comdel/domain/comdel_generator.h \
comdel/domain/comdel_validator.h \
comdel/domain/component.h \
comdel/domain/connection.h \
comdel/domain/comdelvalidator.h \
comdel/domain/connectioninstance.h \
comdel/domain/connection_instance.h \
comdel/domain/display.h \
comdel/domain/functionsignature.h \
comdel/domain/function_signature.h \
comdel/domain/instance.h \
comdel/domain/instanceattribute.h \
comdel/domain/instance_attribute.h \
comdel/domain/library.h \
comdel/domain/pin.h \
comdel/domain/rule.h \
comdel/domain/schema.h \
comdel/domain/schema_creator.h \
comdel/domain/value.h \
comdel/domain/wireinstance.h \
comdel/parser/astnode.h \
comdel/parser/comdellexer.h \
comdel/parser/comdelparser.h \
comdel/parser/ast_nodes.h \
comdel/parser/comdel_lexer.h \
comdel/parser/comdel_parser.h \
comdel/parser/expected.h \
comdel/parser/parsecontext.h \
comdel/parser/parserutil.h \
comdel/parser/parse_context.h \
comdel/parser/parser_util.h \
comdel/parser/poly.h \
comdel/parser/presult.h \
comdel/parser/sourceerror.h \
comdel/parser/source_error.h \
comdel/parser/token.h \
comdel/parser/tokenstype.h \
comdel/display/dialogmanager.h \
comdel/display/attribute_dialog.h \
comdel/display/name_dialog.h \
comdel/parser/tokens_type.h \
mainwindow.h
FORMS += \

View File

@ -18,7 +18,7 @@ domain::Schema *Application::getSchema() {
}
void Application::clear() {
if(schema != nullptr) {
if (schema != nullptr) {
delete schema;
schema = nullptr;
}
@ -26,76 +26,97 @@ void Application::clear() {
libraryPath = "";
}
bool Application::loadLibrary(std::string& filename, std::ostream &errorOutput) {
bool Application::loadLibrary(std::string &filename, std::ostream &errorOutput) {
clear();
ParseContext parseContext;
auto libraryNode = load_library_from_file(&parseContext, filename.c_str(), errorOutput);
if(libraryNode) {
if (libraryNode) {
domain::SchemaCreator generator(validators);
library = generator.loadLibrary(*libraryNode);
for (auto& error : generator.getErrors()) {
for (auto &error: generator.getErrors()) {
parseContext.formatError(error, errorOutput, "ERROR: ");
}
if(library.has_value()) {
errorOutput<<"Failed creating library model"<<std::endl;
return false;
} else {
if (library.has_value()) {
libraryPath = filename;
// on library load we create a new schema
schema = new domain::Schema();
schema = new domain::Schema(library.value());
} else {
errorOutput << "Failed creating library model" << std::endl;
return false;
}
} else {
errorOutput<<"Failed parsing library"<<std::endl;
errorOutput << "Failed parsing library" << std::endl;
return false;
}
return true;
}
bool Application::loadSchema(std::string &filename, std::ostream &errorOutput) {
std::pair<bool, std::vector<domain::ValidationError>> Application::loadSchema(std::string &filename, std::ostream &errorOutput) {
clear();
std::vector<domain::ValidationError> errors;
ParseContext parseContext;
auto schemaNode = load_schema_from_file(&parseContext, filename.c_str(), errorOutput);
if(schemaNode) {
if (schemaNode) {
domain::SchemaCreator generator(validators);
library = generator.loadLibrary(*schemaNode->library);
libraryPath = schemaNode->source->asString();
for (auto& error : generator.getErrors()) {
for (auto &error: generator.getErrors()) {
parseContext.formatError(error, errorOutput, "ERROR: ");
}
if(library) {
if (library) {
schema = generator.loadSchema(*schemaNode, *library);
for (auto& error : generator.getErrors()) {
for (auto &error: generator.getErrors()) {
parseContext.formatError(error, errorOutput, "ERROR: ");
}
if(schema == nullptr) {
if (schema == nullptr) {
clear();
return false;
return {false, errors};
}
} else {
clear();
return false;
return {false, errors};
}
} else {
errorOutput<<"Failed parsing library"<<std::endl;
return false;
errorOutput << "Failed parsing library" << std::endl;
return {false, errors};
}
return true;
domain::ComdelValidator validator{validators};
domain::ValidationContext context;
context.instance = nullptr;
context.attribute = nullptr;
context.addressSpaces = {};
auto memoryReferenceValidation = validator.validateMemoryReferences(*schema, *library, context);
errors.insert(errors.end(), memoryReferenceValidation.begin(), memoryReferenceValidation.end());
auto nameValidation = validator.validateInstanceNames(*schema, *library, context);
errors.insert(errors.end(), nameValidation.begin(), nameValidation.end());
if(!errors.empty()) {
clear();
return {false, errors};
}
return {true, errors};
}
bool Application::generateSchema(std::ostringstream &output) {
if(schema == nullptr) {
if (schema == nullptr) {
return false;
}
domain::generate_schema(libraryPath, schema, output);
@ -103,7 +124,7 @@ bool Application::generateSchema(std::ostringstream &output) {
}
std::vector<domain::ValidationError> Application::validateSchema() {
if(schema == nullptr) {
if (schema == nullptr) {
return std::vector<domain::ValidationError>{domain::ValidationError(domain::Action::ERROR, "No schema loaded")};
}
@ -114,17 +135,20 @@ std::vector<domain::ValidationError> Application::validateSchema() {
context.attribute = nullptr;
context.addressSpaces = {};
for(auto &lib: library->getAddressSpaces()) {
for (auto &lib: library->getAddressSpaces()) {
context.addressSpaces.insert(std::make_pair(lib.getName(), lib));
}
auto errors = validator.validateSchema(*schema, context);
auto countValidation = validator.validateInstanceCount(*schema, *library, context);
errors.insert(errors.end(), countValidation.begin(), countValidation.end());
auto memoryReferenceValidation = validator.validateMemoryReferences(*schema, *library, context);
errors.insert(errors.end(), memoryReferenceValidation.begin(), memoryReferenceValidation.end());
auto nameValidation = validator.validateInstanceNames(*schema, *library, context);
errors.insert(errors.end(), nameValidation.begin(), nameValidation.end());
auto countValidation = validator.validateInstanceCount(*schema, *library, context);
errors.insert(errors.end(), countValidation.begin(), countValidation.end());
auto pinValidation = validator.validatePinConnections(*schema, *library, context);
errors.insert(errors.end(), pinValidation.begin(), pinValidation.end());
return errors;
@ -133,7 +157,7 @@ std::vector<domain::ValidationError> Application::validateSchema() {
std::vector<domain::ValidationError> Application::generateComdel(std::ostringstream &output) {
auto errors = validateSchema();
if(Application::hasErrors(errors)) {
if (!Application::hasErrors(errors)) {
// as long as all validation errors are warning we continue with build
domain::generate_comdel(schema, library.value(), output);
}
@ -141,8 +165,8 @@ std::vector<domain::ValidationError> Application::generateComdel(std::ostringstr
}
bool Application::hasErrors(std::vector<domain::ValidationError> errors) {
for(auto& err: errors) {
if(err.type == domain::Action::ERROR) {
for (auto &err: errors) {
if (err.type == domain::Action::ERROR) {
return true;
}
}
@ -153,26 +177,29 @@ bool Application::hasErrors(std::vector<domain::ValidationError> errors) {
static Application *application = nullptr;
Application *Application::instance() {
if(application == nullptr) {
if (application == nullptr) {
application = new Application();
}
return application;
}
std::shared_ptr<domain::ComponentInstance> Application::addComponent(domain::Component component, std::vector<domain::InstanceAttribute> attributes, int x, int y) {
std::shared_ptr<domain::ComponentInstance>
Application::addComponent(domain::Component component, std::vector<domain::InstanceAttribute> attributes, int x,
int y) {
std::set<std::string> names;
for(const auto& c: schema->componentInstances) {
for (const auto &c: schema->componentInstances) {
names.insert(c->name);
}
std::string name = generateName(names, component.getInstanceName());
schema->componentInstances.push_back(std::make_shared<domain::ComponentInstance>(name, attributes, std::make_pair(x, y), component));
schema->componentInstances.push_back(
std::make_shared<domain::ComponentInstance>(name, attributes, std::make_pair(x, y), component));
return schema->componentInstances.back();
}
std::shared_ptr<domain::BusInstance> Application::addBus(domain::Bus bus, int x, int y) {
std::set<std::string> names;
for(const auto& b: schema->busInstances) {
for (const auto &b: schema->busInstances) {
names.insert(b->name);
}
std::string name = generateName(names, bus.getInstanceName());
@ -182,18 +209,162 @@ std::shared_ptr<domain::BusInstance> Application::addBus(domain::Bus bus, int x,
}
std::string Application::generateName(std::set<std::string>& names, std::string instanceName) {
if(names.find(instanceName) == names.end()) {
std::string Application::generateName(std::set<std::string> &names, std::string instanceName) {
if (names.find(instanceName) == names.end()) {
return instanceName;
}
char buffer[4];
for(int i=0; i<1000; i++) {
for (int i = 0; i < 1000; i++) {
sprintf(buffer, "%03d", i);
auto name = instanceName + "_" + buffer;
if(names.find(name) == names.end()) {
if (names.find(name) == names.end()) {
return name;
}
}
// return default value as this should never happen
return instanceName;
}
bool Application::removeComponent(std::string componentName) {
auto component = findComponentByName(componentName);
if (component == nullptr) {
return false;
}
std::set<domain::BusInstance*> automaticBusses;
schema->connections.erase(
std::remove_if(
schema->connections.begin(),
schema->connections.end(),
[component, &automaticBusses](const std::shared_ptr<domain::ConnectionInstance> &conn) {
auto busConnection = dynamic_cast<domain::BusConnectionInstance *>(conn.get());
if (busConnection) {
if (busConnection->instance == component) {
return true;
}
}
auto directConnection = dynamic_cast<domain::DirectConnectionInstance *>(conn.get());
if (directConnection) {
if (directConnection->instance == component || directConnection->secondInstance == component) {
automaticBusses.insert(directConnection->bus);
return true;
}
}
return false;
}),
schema->connections.end()
);
schema->busInstances.erase(
std::remove_if(
schema->busInstances.begin(),
schema->busInstances.end(),
[&automaticBusses](const std::shared_ptr<domain::BusInstance> &bus) {
return automaticBusses.count(bus.get());
}),
schema->busInstances.end()
);
if(component->component.getType() == domain::Component::MEMORY) {
for(auto& comp: schema->componentInstances) {
if(comp->component.getType() == domain::Component::PROCESSOR) {
for(auto& attribute: comp->attributes) {
if(attribute.value.isType(domain::Value::MEMORY_REFERENCE) && attribute.value.asMemoryReference() == component->name) {
attribute.value = domain::Value::fromMemoryReference(std::nullopt);
}
}
}
}
}
for(auto iter = schema->componentInstances.begin(); iter != schema->componentInstances.end(); ++iter) {
if(iter->get() == component) {
schema->componentInstances.erase(iter);
break;
}
}
return true;
}
bool Application::removeBus(std::string busName) {
auto bus = findBusByName(busName);
if (bus == nullptr) {
return false;
}
schema->connections.erase(
std::remove_if(
schema->connections.begin(),
schema->connections.end(),
[bus](const std::shared_ptr<domain::ConnectionInstance> &conn) {
auto busConnection = dynamic_cast<domain::BusConnectionInstance *>(conn.get());
if (busConnection) {
if (busConnection->bus == bus) {
return true;
}
}
return false;
}),
schema->connections.end()
);
for(auto iter = schema->busInstances.begin(); iter != schema->busInstances.end(); ++iter) {
if(iter->get() == bus) {
schema->busInstances.erase(iter);
break;
}
}
return true;
}
domain::ComponentInstance *Application::findComponentByName(std::string componentName) {
for (auto &comp: schema->componentInstances) {
if (comp->name == componentName) {
return comp.get();
}
}
return nullptr;
}
domain::BusInstance *Application::findBusByName(std::string busName) {
for (auto &bus: schema->busInstances) {
if (bus->name == busName) {
return bus.get();
}
}
return nullptr;
}
void Application::renameComponent(std::string currentName, std::string newName) {
if(currentName == newName) {
return;
}
auto component = findComponentByName(currentName);
if(component) {
component->name = newName;
if(component->component.getType() == domain::Component::MEMORY) {
for(auto& comp: schema->componentInstances) {
if(comp.get()->component.getType() == domain::Component::PROCESSOR) {
for(auto& attribute: comp.get()->attributes) {
if(attribute.value.isType(domain::Value::MEMORY_REFERENCE) && attribute.value.asMemoryReference() == currentName) {
attribute.value = domain::Value::fromMemoryReference(newName);
}
}
}
}
}
}
}
void Application::renameBus(std::string currentName, std::string newName) {
if(currentName == newName) {
return;
}
auto bus = findBusByName(currentName);
if(bus) {
bus->name = newName;
}
}

View File

@ -21,6 +21,9 @@ private:
std::string generateName(std::set<std::string>& names, std::string instanceName);
domain::ComponentInstance *findComponentByName(std::string componentName);
domain::BusInstance *findBusByName(std::string busName);
public:
std::optional<domain::Library> getLibrary();
domain::Schema* getSchema();
@ -28,7 +31,7 @@ public:
void clear();
bool loadLibrary(std::string& filename, std::ostream& errorOutput);
bool loadSchema(std::string& filename, std::ostream& errorOutput);
std::pair<bool, std::vector<domain::ValidationError>> loadSchema(std::string& filename, std::ostream& errorOutput);
static Application* instance();
@ -37,11 +40,18 @@ public:
std::vector<domain::ValidationError> generateComdel(std::ostringstream &output);
std::shared_ptr<domain::ComponentInstance> addComponent(domain::Component component, std::vector<domain::InstanceAttribute> attributes, int x, int y);
bool removeComponent(std::string component);
std::shared_ptr<domain::BusInstance> addBus(domain::Bus bus, int x, int y);
bool removeBus(std::string bus);
static bool hasErrors(std::vector<domain::ValidationError> empty);
~Application() = default;
void renameComponent(std::string currentName, std::string newName);
void renameBus(std::string currentName, std::string newName);
};

View File

@ -59,14 +59,16 @@ namespace display {
}
AttributeDialog::AttributeDialog(domain::InstanceAttribute *attribute) {
AttributeDialog::AttributeDialog(domain::InstanceAttribute *attribute, bool updating) {
setAttribute(Qt::WA_DeleteOnClose);
attributeValue = attribute;
this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName()));
auto actionType = updating ? "Izmjeni " : "Postavi ";
this->setWindowTitle(QString::fromStdString(actionType + attribute->attribute.getName()));
auto layout = new QVBoxLayout(this);
this->setLayout(layout);
@ -120,11 +122,11 @@ namespace display {
auto *radioLayout = new QHBoxLayout(group);
group->setLayout(radioLayout);
auto isTrue = new QRadioButton("true", group);
auto isTrue = new QRadioButton("da", group);
connect(isTrue, &QRadioButton::clicked, [this]() {
this->value = domain::Value::fromBool(true);
});
auto isFalse = new QRadioButton("false", group);
auto isFalse = new QRadioButton("ne", group);
connect(isFalse, &QRadioButton::clicked, [this]() {
this->value = domain::Value::fromBool(false);
});
@ -140,7 +142,7 @@ namespace display {
layout->addWidget(group);
}
auto button = new QPushButton("Ažuriraj");
auto button = new QPushButton(updating ? "Ažuriraj" : "Postavi");
connect(button, &QPushButton::clicked, this, &AttributeDialog::onUpdate);
layout->addWidget(button);
@ -170,14 +172,16 @@ namespace display {
}
MemoryDialog::MemoryDialog(domain::InstanceAttribute *attribute,
std::vector<std::shared_ptr<domain::ComponentInstance>> instances) {
std::vector<std::shared_ptr<domain::ComponentInstance>> instances, bool updating) {
memoryInstances = std::vector<std::string>();
setAttribute(Qt::WA_DeleteOnClose);
attributeValue = attribute;
this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName()));
auto actionType = updating ? "Izmjeni memoriju" : "Postavi memoriju";
this->setWindowTitle(QString::fromStdString(actionType));
for (auto &instance: instances) {
if (instance->component.getType() == domain::Component::MEMORY) {
@ -212,7 +216,7 @@ namespace display {
}
}
auto button = new QPushButton("Ažuriraj");
auto button = new QPushButton(updating ? "Ažuriraj" : "Postavi");
connect(button, &QPushButton::clicked, this, &MemoryDialog::onUpdate);
layout->addWidget(button);

View File

@ -42,7 +42,7 @@ namespace display {
domain::InstanceAttribute *attributeValue;
public:
AttributeDialog(domain::InstanceAttribute *attribute);
AttributeDialog(domain::InstanceAttribute *attribute, bool updating = true);
public slots:
@ -63,7 +63,7 @@ namespace display {
public:
MemoryDialog(domain::InstanceAttribute *attribute,
std::vector<std::shared_ptr<domain::ComponentInstance>> instances);
std::vector<std::shared_ptr<domain::ComponentInstance>> instances, bool updating = true);
public slots:

View File

@ -3,14 +3,19 @@
#include "name_dialog.h"
#include "mainwindow.h"
#include "application.h"
#include "single_automatic_dialog.h"
#include <QMenu>
#include <QLine>
#include <QPen>
#include <QGraphicsSceneContextMenuEvent>
#include <set>
namespace display {
QPen connectionPen(QColor::fromRgb(150, 150, 250));
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu;
menu.addAction("Izmjeni ime", [this]() {
@ -18,28 +23,41 @@ namespace display {
for(const auto &component: Application::instance()->getSchema()->componentInstances) {
names.insert(component->name);
}
auto dialog = new NameDialog(this->instance.get(), names);
auto dialog = new NameDialog(this->instance->name, names);
dialog->exec();
auto currentName = this->instance->name;
auto newName = dialog->getName();
Application::instance()->renameComponent(currentName, newName);
});
menu.addSeparator();
for (int i = 0; i < this->instance->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]() {
if (attr->value.getType() == domain::Value::MEMORY_REFERENCE) {
if(attr->value.getType() == domain::Value::MEMORY_REFERENCE) {
menu.addAction("Izmjeni memoriju", [attr]() {
auto dialog = new MemoryDialog(attr,
Application::instance()->getSchema()->componentInstances);
dialog->exec();
});
} else {
auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->name + "'"),
[attr]() {
auto dialog = new AttributeDialog(attr);
dialog->exec();
}
});
action->setEnabled(enabled);
}
}
menu.addSeparator();
menu.addAction(QString::fromStdString("Ukloni " + this->instance->name), [this]() {
Application::instance()->removeComponent(this->instance->name);
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
view->refreshContent();
});
menu.exec(event->screenPos());
}
@ -50,7 +68,7 @@ namespace display {
void Pin::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu;
menu.addAction("Connect pin", [&]() {});
menu.addAction("Poveži pin", [&]() {});
menu.exec(event->screenPos());
}
@ -63,6 +81,8 @@ namespace display {
QPointF(pin.getDisplayPin().getConnectionX(),
pin.getDisplayPin().getConnectionY());
view->context.line = new QGraphicsLineItem(QLineF(view->context.startingPoint, event->scenePos()));
view->context.line->setPen(QPen(QColor::fromRgb(100, 100, 250), 1, Qt::PenStyle::DashLine));
view->context.line->setZValue(1000);
this->scene()->addItem(view->context.line);
view->showConnectable(this);
@ -103,9 +123,19 @@ namespace display {
for(const auto &component: Application::instance()->getSchema()->busInstances) {
names.insert(component->name);
}
auto dialog = new NameDialog(this->busInstance.get(), names);
auto dialog = new NameDialog(this->busInstance->name, names);
dialog->exec();
auto currentName = this->busInstance->name;
auto newName = dialog->getName();
Application::instance()->renameBus(currentName, newName);
});
menu.addSeparator();
menu.addAction(QString::fromStdString("Ukloni " + this->busInstance->name), [this]() {
Application::instance()->removeBus(this->busInstance->name);
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
view->refreshContent();
});
menu.exec(event->screenPos());
}
@ -203,7 +233,8 @@ namespace display {
BusConnection::BusConnection(domain::BusConnectionInstance *connection, ComponentGroup *component, BusGroup *bus): connection(
connection), component(component), bus(bus) {
updateConnection();
setPen(connectionPen);
setZValue(-1);
setHandlesChildEvents(false);
}
@ -228,6 +259,15 @@ namespace display {
QMenu menu;
menu.addAction("Ukloni poveznicu", [this]() {});
menu.addSeparator();
if(connection->bus->bus.getType() == domain::Bus::SINGLE_AUTOMATIC) {
auto &attributes = this->connection->attributes;
menu.addAction(QString::fromStdString("Izmjeni poveznicu"),
[&attributes]() {
auto dialog = new display::SingleAutomaticDialog(attributes);
dialog->exec();
});
} else {
for (int i = 0; i < this->connection->attributes.size(); i++) {
auto *attr = &this->connection->attributes[i];
bool enabled = attr->attribute.getPopup().has_value();
@ -239,12 +279,16 @@ namespace display {
});
action->setEnabled(enabled);
}
}
menu.exec(event->screenPos());
}
DirectConnection::DirectConnection(domain::DirectConnectionInstance *connection, ComponentGroup *first,
ComponentGroup *second): connection(connection), first(first), second(second) {
updateConnection();
setPen(connectionPen);
setZValue(-1);
setHandlesChildEvents(false);
}

View File

@ -3,6 +3,7 @@
#include <QLabel>
#include <QListWidget>
#include <QVBoxLayout>
#include <application.h>
namespace display {
@ -13,17 +14,16 @@ namespace display {
componentList = new LibraryList(this);
busList = new LibraryList(this);
layout->setMargin(4);
layout->addWidget(new QLabel("Components:"));
layout->setContentsMargins(4, 4, 4, 4);
layout->addWidget(new QLabel("Komponente:"));
layout->addWidget(componentList, 1);
layout->addSpacing(8);
layout->addWidget(new QLabel("Buses:"));
layout->addWidget(new QLabel("Sabirnice:"));
layout->addWidget(busList, 1);
setLibrary(library);
}
void Library::setLibrary(std::optional<domain::Library> library) {
void Library::refreshContent() {
library = Application::instance()->getLibrary();
componentList->clear();
busList->clear();

View File

@ -13,7 +13,7 @@ namespace display {
public:
Library();
void setLibrary(std::optional<domain::Library> library);
void refreshContent();
private:
std::optional<domain::Library> library;

View File

@ -5,38 +5,21 @@
#include <set>
#include "name_dialog.h"
display::NameDialog::NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names) : componentInstance(instance), usedNames(names) {
usedNames.erase(instance->name);
display::NameDialog::NameDialog(std::string currentName, std::set<std::string> &names): currentName(currentName) {
usedNames.erase(currentName);
auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Izmjeni ime", this));
edit = new QLineEdit(this);
edit->insert(instance->name.c_str());
edit->insert(currentName.c_str());
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
setWindowTitle("Izmjeni ime");
button = new QPushButton("Ažuriraj", this);
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
layout->addWidget(button);
this->setLayout(layout);
}
display::NameDialog::NameDialog(domain::BusInstance *instance, std::set<std::string>& names): busInstance(instance), usedNames(names) {
usedNames.erase(instance->name);
auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Izmjeni ime", this));
edit = new QLineEdit(this);
edit->insert(instance->name.c_str());
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
layout->addWidget(edit);
this->setWindowTitle("Izmjeni ime");
button = new QPushButton("Ažuriraj", this);
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
layout->addWidget(button);
this->setLayout(layout);
setLayout(layout);
}
void display::NameDialog::onNameUpdate(const QString &text) {
@ -48,12 +31,10 @@ void display::NameDialog::onNameUpdate(const QString &text) {
}
void display::NameDialog::onNameChange() {
if (componentInstance != nullptr) {
componentInstance->name = this->edit->text().toStdString();
} else if (busInstance != nullptr) {
busInstance->name = this->edit->text().toStdString();
}
this->close();
currentName = edit->text().toStdString();
close();
}
std::string display::NameDialog::getName() {
return currentName;
}

View File

@ -17,15 +17,13 @@ namespace display {
std::set<std::string> usedNames;
QLineEdit *edit = nullptr;
domain::ComponentInstance *componentInstance = nullptr;
domain::BusInstance *busInstance = nullptr;
std::string currentName;
QPushButton *button;
public:
NameDialog(std::string currentName, std::set<std::string>& names);
NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names);
NameDialog(domain::BusInstance *instance, std::set<std::string>& names);
std::string getName();
public slots:
void onNameUpdate(const QString& text);

View File

@ -2,6 +2,7 @@
#include "schema_display.h"
#include "application.h"
#include "attribute_dialog.h"
#include "single_automatic_dialog.h"
#include <QDrag>
#include <QDragEnterEvent>
@ -10,8 +11,6 @@
namespace display {
Schema::Schema() {
this->selectedBrush.setColor(QColor::fromRgb(20, 20, 125));
this->selectedPen.setColor(QColor::fromRgb(20, 20, 125));
schema = nullptr;
library = std::nullopt;
this->setScene(&scene);
@ -19,14 +18,17 @@ namespace display {
}
void Schema::setSchema(domain::Schema *_schema, std::optional<domain::Library> _library) {
void Schema::refreshContent() {
schema = Application::instance()->getSchema();
library = Application::instance()->getLibrary();
components.clear();
buses.clear();
scene.clear();
pins.clear();
busConnections.clear();
this->schema = _schema;
this->library = _library;
directConnections.clear();
if (schema != nullptr) {
for (auto &instance: schema->componentInstances) {
auto group = new display::ComponentGroup(instance);
@ -86,28 +88,10 @@ 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();
auto attributes = populateAttributes(component.getAttributes());
if(attributes.size() != component.getAttributes().size()) {
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 currentPos = this->mapToScene(event->pos()).toPoint();
@ -148,18 +132,26 @@ namespace display {
auto instance = context.pin->getComponentInstance();
auto &pin = context.pin->getPin();
auto busInstances = getAvailableConnectionBusses(instance, pin);
auto availableConnections = schema->availableConnections(instance->name, pin.getName(), true);
for (auto &bus: busInstances) {
for(auto &connection: availableConnections) {
if(connection.type != domain::ConnectionEntry::BUS) {
continue;
}
auto bus = connection.busInstance.value();
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()) {
clearSelectable();
return;
}
auto conInstance = std::make_shared<domain::BusConnectionInstance>(instance, attributes, bus, *con);
@ -176,9 +168,11 @@ namespace display {
}
}
auto pinInstances = getAvailableConnectionPins(instance, pin);
for (auto &pinInstance: pinInstances) {
for (auto &connection: availableConnections) {
if(connection.type != domain::ConnectionEntry::COMPONENT) {
continue;
}
auto pinInstance = domain::ConnectionComponent{connection.componentInstance.value()->name, connection.pin.value().getName()};
auto rect = pins[pinInstance]->boundingRect();
rect.setX(pins[pinInstance]->scenePos().x());
rect.setY(pins[pinInstance]->scenePos().y());
@ -188,13 +182,17 @@ 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()) {
clearSelectable();
return;
}
auto conInstance = std::make_shared<domain::DirectConnectionInstance>(instance,
@ -215,28 +213,25 @@ namespace display {
}
}
updateConnections();
for (auto &item: this->context.selectable) {
this->scene.removeItem(item);
delete item;
}
this->context.selectable.clear();
clearSelectable();
}
void Schema::showConnectable(Pin *domainPin) {
auto &pin = domainPin->getPin();
auto busInstances = getAvailableConnectionBusses(domainPin->getComponentInstance(), domainPin->getPin());
auto availableConnections = schema->availableConnections(domainPin->getComponentInstance()->name, pin.getName(), true);
for (auto bus: busInstances) {
for(auto &connection: availableConnections) {
if(connection.type != domain::ConnectionEntry::BUS) {
continue;
}
auto bus = connection.busInstance.value();
auto &group = buses[bus->name];
if(group == nullptr) {
continue;
}
auto rect = new QGraphicsRectItem(group->boundingRect());
rect->setPen(selectedPen);
rect->setBrush(selectedBrush);
rect->setPos(group->scenePos());
auto _rect = rect->rect();
@ -248,12 +243,14 @@ namespace display {
scene.addItem(rect);
}
std::vector<domain::ConnectionComponent> pinInstances = getAvailableConnectionPins(
domainPin->getComponentInstance(), domainPin->getPin());
for (auto &pinInstance: pinInstances) {
for (auto &connection: availableConnections) {
if(connection.type != domain::ConnectionEntry::COMPONENT) {
continue;
}
auto pinInstance = domain::ConnectionComponent{connection.componentInstance.value()->name, connection.pin.value().getName()};
auto &instance = pins[pinInstance];
auto rect = new QGraphicsRectItem(instance->boundingRect());
rect->setBrush(selectedBrush);
rect->setPen(selectedPen);
rect->setPos(instance->scenePos());
@ -268,29 +265,56 @@ namespace display {
}
std::vector<domain::BusInstance *>
Schema::getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin) {
std::vector<domain::BusInstance *> instances;
for (const auto &bus: schema->busInstances) {
if (library->hasConnection(domain::ConnectionComponent{instance->component.getName(), pin.getName()},
bus->bus.getName())) {
instances.push_back(bus.get());
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, false);
if(dialog->exec() == QDialog::Rejected) {
// if any dialog isn't set, whole creation is rejected
return {};
}
} else {
auto dialog = new AttributeDialog(&attribute, false);
if(dialog->exec() == QDialog::Rejected) {
// if any dialog isn't set, whole creation is rejected
return {};
}
}
return instances;
}
instanceAttributes.push_back(attribute);
}
return instanceAttributes;
}
std::vector<domain::ConnectionComponent>
Schema::getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin) {
std::vector<domain::ConnectionComponent> instances;
domain::ConnectionComponent source{instance->component.getName(), pin.getName()};
for (const auto &entry: pins) {
std::string name = components[entry.first.component]->getComponentInstance()->component.getName();
if (library->hasConnection(source, domain::ConnectionComponent{name, entry.first.pin})) {
instances.push_back(entry.first);
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, false);
if(dialog->exec() == QDialog::Rejected) {
// if dialog is rejected, whole creation is rejected
return {};
}
return instances;
return instanceAttributes;
}
void Schema::clearSelectable() {
updateConnections();
for (auto &item: this->context.selectable) {
this->scene.removeItem(item);
delete item;
}
this->context.selectable.clear();
}
} // namespace display

View File

@ -4,6 +4,7 @@
#include <QGraphicsView>
#include <QWidget>
#include <QColor>
#include <QGraphicsLineItem>
#include <comdel/domain/schema.h>
@ -19,8 +20,9 @@ namespace display {
public:
QBrush selectedBrush;
QPen selectedPen;
QBrush selectedBrush = QBrush(QColor::fromRgb(50, 50, 150, 100), Qt::BrushStyle::SolidPattern);
QPen selectedPen = QPen(QColor::fromRgb(50, 50, 150), 1, Qt::PenStyle::SolidLine);
QPen activeLinePen = QPen(QColor::fromRgb(250, 100, 100));
enum State {
DEFAULT,
@ -46,14 +48,14 @@ namespace display {
std::vector<BusConnection *> busConnections;
std::vector<DirectConnection *> directConnections;
void setSchema(domain::Schema *schema, std::optional<domain::Library> library);
void updateConnections();
void removeConnectable(QPointF f);
void showConnectable(Pin *pin);
void refreshContent();
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
@ -68,11 +70,11 @@ namespace display {
domain::Schema *schema{};
std::optional<domain::Library> library;
std::vector<domain::BusInstance *>
getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
std::vector<domain::InstanceAttribute> populateAttributes(std::vector<domain::Attribute>& attributes);
std::vector<domain::ConnectionComponent>
getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
std::vector<domain::InstanceAttribute> populateSingleAutomaticConnection(domain::Connection connection);
void clearSelectable();
};
} // namespace display

View File

@ -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, bool updating): attributes(values) {
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString::fromStdString(updating ? "Ažuriraj poveznicu" : "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(updating ? "Ažuriraj" : "Postavi");
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

View File

@ -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, bool updating = true);
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

View File

@ -59,4 +59,8 @@ namespace domain {
return popup;
}
void Attribute::setPupup(std::optional<Popup> popup) {
this->popup = popup;
}
} // namespace domain

View File

@ -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

View File

@ -285,10 +285,14 @@ namespace domain {
} else {
// if no connection exists than defaults must exist
for (auto &wire: *pin.getWires()) {
if(wire.isType(Value::NIL)) {
tempOutput << "*, ";
} else {
tempOutput << wire.stringify() << ", ";
}
}
}
}
auto wireList = tempOutput.str();
wireList.pop_back();
@ -311,22 +315,26 @@ namespace domain {
std::vector<Value> defaults;
if (connection->instance->name == name && connection->connection.getComponent().pin == pin) {
wires = connection->connection.getWires();
selected = connection->attributes[0].value.asReference();
selected = connection->attributes[0].value.asString();
defaults = *connection->instance->component.getPin(pin).getWires();
} else {
wires = *connection->connection.getSecondWires();
selected = connection->attributes[1].value.asReference();
selected = connection->attributes[1].value.asString();
defaults = *connection->secondInstance->component.getPin(pin).getWires();
}
for (int i = 0; i < wires.size(); i++) {
if (wires[i].isType(Value::STRING)) {
if (wires[i].asString() == selected) {
buffer << wireNames[connection->bus->name + "." + connection->bus->bus.getWires()[0].getName()]
<< ", ";
auto wireName = connection->bus->name + "." + connection->bus->bus.getWires()[0].getName();
buffer << wireNames[wireName] << ", ";
} else if(defaults[i].isType(Value::NIL)) {
buffer << "*, ";
} else {
buffer << defaults[i].stringify();
buffer << defaults[i].stringify() << ", ";
}
} else if(defaults[i].isType(Value::NIL)) {
buffer << "*, ";
} else {
buffer << wires[i].stringify() << ", ";
}

View File

@ -153,6 +153,37 @@ namespace domain {
return nullopt;
}
std::vector<ValidationError>
ComdelValidator::validateMemoryReferences(Schema &schema, Library &library, ValidationContext context) {
std::set<std::string> memoryInstances;
for(auto& component: schema.componentInstances) {
if(component->component.getType() == Component::MEMORY) {
memoryInstances.insert(component->name);
}
}
std::vector<ValidationError> errors;
for(auto& component: schema.componentInstances) {
if(component->component.getType() == Component::PROCESSOR) {
for(auto& attribute: component->attributes) {
if(attribute.value.isType(Value::MEMORY_REFERENCE)) {
auto memoryReference = attribute.value.asMemoryReference();
if(memoryReference != nullopt) {
if(memoryInstances.count(*memoryReference) == 0) {
context.attributes["memoryReference"] = domain::Value::fromString(memoryReference.value());
auto message = populateMessage("Ne postoji memorijska komponenta '{memoryReference}'", context);
errors.emplace_back(component.get(), nullptr, Action::ERROR, message);
}
}
}
}
}
}
return errors;
}
std::vector<ValidationError>
ComdelValidator::validateInstanceNames(Schema &schema, Library &library, ValidationContext context) {
std::set<std::string> names;

View File

@ -35,6 +35,8 @@ namespace domain {
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
std::vector<ValidationError> validateMemoryReferences(Schema &schema, Library &library, ValidationContext context);
std::vector<ValidationError> validateInstanceNames(Schema &schema, Library &library, ValidationContext context);
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library &library, ValidationContext context);

View File

@ -62,7 +62,7 @@ namespace domain {
return false;
}
std::vector<Attribute> Component::getAttributes() {
std::vector<Attribute>& Component::getAttributes() {
return attributes;
}

View File

@ -60,7 +60,7 @@ namespace domain {
Pin getPin(std::string pin);
std::vector<Attribute> getAttributes();
std::vector<Attribute>& getAttributes();
Attribute getAttribute(std::string attribute);

View File

@ -16,11 +16,11 @@ namespace domain {
return second;
}
std::string Connection::getBus() {
std::string &Connection::getBus() {
return bus;
}
std::vector<Attribute> Connection::getAttributes() {
std::vector<Attribute>& Connection::getAttributes() {
return attributes;
}

View File

@ -53,14 +53,17 @@ namespace domain {
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
bool operator==(const Connection& connection) {
return (first == connection.first && bus == connection.bus && second == connection.second);
}
ConnectionComponent getComponent();
std::optional<ConnectionComponent> getSecondComponent();
std::string getBus();
std::string &getBus();
std::vector<Attribute> getAttributes();
std::vector<Attribute>& getAttributes();
std::vector<Value> getWires();

View File

@ -1,7 +1,13 @@
#include "display.h"
#include <QBrush>
#include <QPen>
namespace domain {
QBrush busBrush(QColor::fromRgb(200, 200, 200));
QPen busPen(QColor::fromRgb(200, 200, 200));
Display::Display(std::vector<ui::Item> items) : items(items) {}
void Display::render(QGraphicsItemGroup *group) {
@ -39,11 +45,16 @@ namespace domain {
}
void ui::Bus::render(QGraphicsItemGroup *group, int size) {
int _w = w, _h = h;
if (orientation == HORIZONTAL) {
group->addToGroup(new QGraphicsRectItem(x, y, size, h));
_w = size;
} else {
group->addToGroup(new QGraphicsRectItem(x, y, w, size));
_h = size;
}
auto rect = new QGraphicsRectItem(x, y, _w, _h);
rect->setBrush(busBrush);
rect->setPen(busPen);
group->addToGroup(rect);
}
int ui::Bus::getDefaultSize() {

View File

@ -39,4 +39,72 @@ namespace domain {
return nullptr;
}
std::vector<ConnectionEntry> Schema::availableConnections(std::string instanceName, std::string pinName, bool onlyConnectable) {
std::vector<ConnectionEntry> entries;
auto instance = getComponentInstance(instanceName);
ConnectionComponent connectionComponent{instance->component.getName(), pinName};
for(auto &conn: library.getConnections()) {
if(conn.isConnecting(connectionComponent)) {
// if bus connection
if(library.getBus(conn.getBus()).getType() == Bus::REGULAR) {
for(auto& bus: busInstances) {
if(bus->bus.getName() == conn.getBus()) {
ConnectionEntry entry{ConnectionEntry::BUS, bus.get(), nullopt, nullopt, conn};
entries.emplace_back(entry);
}
}
} else {
for(auto& component: componentInstances) {
for(auto& pin: component->component.getPins()) {
if(conn.isConnecting(connectionComponent, {component->component.getName(), pin.getName()})) {
ConnectionEntry entry{ConnectionEntry::COMPONENT, nullopt, component.get(), pin, conn};
entries.emplace_back(entry);
}
}
}
}
}
}
if(onlyConnectable) {
entries.erase(
std::remove_if(
entries.begin(),
entries.end(),
[this, instance](ConnectionEntry &entry) {
auto& bus = this->library.getBus(entry.connection.getBus());
// we allow duplicates of single automatic connections
if(bus.getType() == Bus::SINGLE_AUTOMATIC) {
return false;
}
for(auto& conn: this->connections) {
if(conn->connection == entry.connection) {
if(bus.getType() == Bus::REGULAR) {
if(entry.busInstance.value()->bus.getName() == conn->connection.getBus()) {
return true;
}
} else {
auto *directInstance = dynamic_cast<DirectConnectionInstance*>(conn.get());
ComponentInstance* secondInstance;
if(directInstance->instance == instance) {
secondInstance = directInstance->secondInstance;
} else {
secondInstance = directInstance->instance;
}
return entry.componentInstance == secondInstance;
}
}
}
return false;
}),
entries.end()
);
}
return entries;
}
} // namespace domain

View File

@ -3,14 +3,33 @@
#include "connection_instance.h"
#include "instance.h"
#include "library.h"
#include <utility>
#include <vector>
namespace domain {
struct ConnectionEntry {
enum Type {
BUS,
COMPONENT
};
Type type;
std::optional<BusInstance*> busInstance;
std::optional<ComponentInstance*> componentInstance;
std::optional<Pin> pin;
Connection connection;
};
class Schema {
private:
Library library;
public:
Schema() = default;
Schema(Library library): library(std::move(library)) {}
std::vector<shared_ptr<BusInstance>> busInstances;
std::vector<shared_ptr<ComponentInstance>> componentInstances;
@ -21,6 +40,8 @@ namespace domain {
ComponentInstance *getComponentInstance(std::string &name);
bool hasConnection(string &component, string &pin);
ConnectionInstance *getConnection(string &component, string &pin);
std::vector<ConnectionEntry> availableConnections(std::string instance, std::string pin, bool onlyConnectable);
};
} // namespace domain

View File

@ -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);
}
}
@ -732,7 +736,7 @@ namespace domain {
std::optional<Popup> popup;
if (node.popup) {
popup = loadPopup(*node.popup, name, value.getType());
popup = loadPopup(*node.popup, name, toType(node.type));
}
pop();
@ -862,7 +866,7 @@ namespace domain {
Schema *SchemaCreator::loadSchema(SchemaNode node, Library &library) {
auto *schema = new Schema();
auto *schema = new Schema(library);
for (auto &instance: node.instances) {
if (library.hasComponent(instance.component.value)) {
@ -935,16 +939,26 @@ 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()) {
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");
}
attributes.emplace_back(attribute.getName(), toType(attr.value), attribute);
attributes.emplace_back(attribute.getName(), value, attribute);
} else {
errors.emplace_back(attr.name.span, "unknown attribute");
}

View File

@ -1,4 +1,4 @@
#include "comdellexer.h"
#include "comdel_lexer.h"
#include "token.h"
#include "tokens_type.h"

View File

@ -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 {

View File

@ -1,4 +1,4 @@
#include "comdellexer.h"
#include "comdel_lexer.h"
#include "comdel_parser.h"
#include "parser_util.h"

View File

@ -7,7 +7,7 @@
component System
{
clock 100MHz;
//bus
//glavnaSabirnica
wire<32> ADR;
wire<32> DATA;
wire READ;
@ -23,32 +23,31 @@ component System
wire --BACK;
//directRam
wire INT;
// components --------------------------------------------
subcomponent Memorija mem<false, 1, 1024, 8, 1024>(ADR, DATA, READ, WRITE, SIZE, WAIT, 94534054858378, 0, null, null);
subcomponent FRISC procesor_002(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, 94534054858378, 0, null, null);
subcomponent FRISC procesor_001(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, 94534054858378, 0, null, null);
subcomponent FRISC procesor_000(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, 94534054858378, 0, null, null);
subcomponent FRISC procesor(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, 94534054858378, 0, null, null);
subcomponent Memorija memorija<false, 1, 65536, 8, 0>(ADR, DATA, READ, WRITE, SIZE, WAIT, *, *, *, INT);
subcomponent FRISC procesor(ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, --IACK, 1, *, INT, *, *, *);
display {
component { x: 0; y: 0; ref: "procesor_002"; }
component { x: 0; y: 250; ref: "mem"; }
component { x: -89; y: 74; ref: "procesor_001"; }
component { x: -175; y: 195; ref: "procesor_000"; }
component { x: -195; y: 63; ref: "procesor"; }
component { x: -377; y: -302; ref: "procesor"; }
component { x: -56; y: -80; ref: "memorija"; }
// bus bus
// glavnaSabirnica bus
rectangle {
x: 0; y: 200;
x: -377; y: -106;
w: 100; h: 20;
}
line {x1:50; y1:116; x2:50; y2:210;}
line {x1:50; y1:234; x2:50; y2:210;}
line {x1:-39; y1:190; x2:50; y2:210;}
line {x1:-145; y1:179; x2:50; y2:210;}
line {x1:-125; y1:311; x2:50; y2:210;}
// directRam bus
line {x1:-6; y1:-96; x2:-326; y2:-95;}
line {x1:-327; y1:-186; x2:-326; y2:-95;}
line {x1:-72; y1:-52; x2:-261; y2:-252;}
}
}

View File

@ -8,13 +8,12 @@
@address pomocniAS(0xFFFF0000,0xFFFFFFFF)
@messages {
Ok: "OK";
Yes: "Da";
No: "Ne";
Cancel: "Otkaži";
ok: "OK";
yes: "Da";
no: "Ne";
cancel: "Odustani";
noneBusLine: "nespojen";
noneValue: "nema vrijednosti";
generalPinNotConnected: "Opći pin nije spojen niti na jednu sabirnicu";
}
@component FRISC processor {
@ -73,6 +72,7 @@
orientation: "right";
}
}
@wires{null, null, null, null}
}
}
@ -215,6 +215,7 @@
orientation: "left";
}
}
@wires{null, null, null, null}
}
}
@ -229,7 +230,7 @@
@title "Početna adresa DMA-kontrolera"
@text "Zadajte početnu adresu DMA-kontrolera"
@rule {
if(contains_address(glavniAS, pocetnaAdresa)) {
if(!contains_address(glavniAS, pocetnaAdresa)) {
error("Početna adresa memorije je izvan 32 bitnog adresnog prostora")
}
}
@ -239,7 +240,7 @@
}
}
@rule {
if(unique(glavniAS, pocetnaAdresa, 32)) {
if(!unique(glavniAS, pocetnaAdresa, 32)) {
error("Adrese memorije nisu jedinstvene u adresnom prostoru (preklapaju se s nekom drugom komponentom)")
}
}
@ -281,7 +282,7 @@
}
*/
pin {
x: 100; y: 50; w: 16; h: 16;
x: 100; y: 30; w: 16; h: 16;
}
}
}
@ -291,7 +292,7 @@
@connection optional("COMDEL se ne može stvoriti. DMA nije spojen na nesto!")
@display {
pin {
x: 0; y: 0; w: 0; h: 0;
x: 100; y: 7; w: 16; h: 16;
}
}
@wires { 0, 0, null, null}
@ -344,7 +345,7 @@
}
}
@bus directRam automatic {
@bus directRam singleAutomatic {
@instanceName directRam
@wires {
INT
@ -375,12 +376,25 @@
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, interupt, BREQ, BACK}
}
@connection (DMA.glavniPin, PIOSabirnica, FRISC.glavniPin) {
@connection (DMA.dodatnaPoveznica, PIOSabirnica, FRISC.glavniPin) {
@wires{PIO_DATA, READY, STROBE}
@wires{PIO_DATA, READY, STROBE}
}
@connection (FRISC.memDirect, directRam, Memorija.memDirect) {
@wires{INT}
@wires{INT}
@attribute procConn string default "INT" {
@popup automatic {
@title "Frisc INT"
@text "Processor interupt 1"
}
}
@attribute memConn string default "INT" {
@popup automatic {
@title "Mem INT"
@text "Memory interupt 1"
}
}
@wires{"INT", null, 1, "INT2"}
@wires{"INT", null, 1, "INT2"}
}

View File

@ -1,42 +1,14 @@
@source "frisc_library.csl"
@source "/home/bbr/Documents/Personal/FER/schema_editor/examples/simplified FRISC model/frisc_library.csl"
@schema {
@instance procesor_002 FRISC {
@position (0, 0)
@attribute _memory null
}
@instance mem Memorija {
@position (0, 250)
@attribute sinkroniziran false
@attribute brzina 1
@attribute kapacitet 1024
@attribute size 8
@attribute pocetnaAdresa 1024
}
@instance procesor_001 FRISC {
@position (-89, 74)
@attribute _memory null
}
@instance procesor_000 FRISC {
@position (-175, 195)
@attribute _memory null
@instance procesor FRISC {
@position (-177, -122)
@attribute _memory memorija2
}
@instance procesor FRISC {
@position (-195, 63)
@position (49, -97)
@attribute _memory null
}
@instance bus glavnaSabirnica {
@position (0, 200)
@size 100
}
@connection (procesor_002.glavniPin, bus) {
}
@connection (mem.glavniPin, bus) {
}
}

View File

@ -2,33 +2,28 @@
@schema {
@instance procesor FRISC {
@position (-76, -97)
@attribute _memory memorija
@position (-464, -314)
@attribute _memory null
}
@instance memorija Memorija {
@position (52, 119)
@attribute sinkroniziran false
@attribute brzina 1
@attribute kapacitet 65536
@attribute size 8
@instance dma DMA {
@position (-269, 46)
@attribute pocetnaAdresa 0
}
@instance glavnaSabirnica glavnaSabirnica {
@position (-78, 88)
@position (-579, -160)
@size 100
}
@instance directRam directRam {
@instance PIOSabirnica PIOSabirnica {
@position (0, 0)
@size 0
}
@connection (memorija.glavniPin, glavnaSabirnica) {
@connection (dma.glavniPin, glavnaSabirnica) {
@attribute interupt INT2
}
@connection (procesor.glavniPin, glavnaSabirnica) {
}
@connection (memorija.memDirect, directRam, procesor.memDirect) {
@connection (dma.glavniPin, PIOSabirnica, procesor.glavniPin) {
}
}

View File

@ -0,0 +1,16 @@
@source "/home/bbr/Documents/Personal/FER/schema_editor/examples/simplified FRISC model/frisc_library.csl"
@schema {
@instance procesor FRISC {
@position (-543, -304)
@attribute _memory null
}
@instance glavnaSabirnica glavnaSabirnica {
@position (-544, -91)
@size 100
}
@connection (procesor.glavniPin, glavnaSabirnica) {
}
}

View File

@ -0,0 +1,49 @@
@source "/home/bbr/Documents/Personal/FER/schema_editor/examples/simplified FRISC model/frisc_library.csl"
@schema {
@instance procesor FRISC {
@position (-104, -102)
@attribute _memory null
}
@instance memorija Memorija {
@position (39, 199)
@attribute sinkroniziran false
@attribute brzina 1
@attribute kapacitet 1024
@attribute size 8
@attribute pocetnaAdresa 0
}
@instance dma DMA {
@position (-352, 13)
@attribute pocetnaAdresa 1024
}
@instance glavnaSabirnica glavnaSabirnica {
@position (-106, 80)
@size 100
}
@instance PIOSabirnica PIOSabirnica {
@position (0, 0)
@size -1
}
@instance directRam directRam {
@position (0, 0)
@size -1
}
@connection (procesor.glavniPin, glavnaSabirnica) {
}
@connection (memorija.glavniPin, glavnaSabirnica) {
}
@connection (dma.glavniPin, glavnaSabirnica) {
@attribute interupt INT0
}
@connection (memorija.memDirect, directRam, procesor.memDirect) {
@attribute procConn "INT"
@attribute memConn "INT"
}
}

View File

@ -32,11 +32,13 @@ void MainWindow::setupUi()
ui->centralwidget->setLayout(layout);
// setup toolbar
ui->toolBar->addAction("Load library", this, &MainWindow::onLoadLibrary);
ui->toolBar->addAction("Load schema", this, &MainWindow::onLoadSchema);
ui->toolBar->addAction("Save schema", this, &MainWindow::onStoreScheme);
ui->toolBar->addAction("Generate system", this, &MainWindow::onGenerateComdel);
ui->toolBar->addAction("Učitaj bibiloteku", this, &MainWindow::onLoadLibrary);
ui->toolBar->addAction("Učitaj shemu", this, &MainWindow::onLoadSchema);
ui->toolBar->addAction("Spremi shemu", this, &MainWindow::onStoreScheme);
ui->toolBar->addAction("Generiraj comdel", this, &MainWindow::onGenerateComdel);
connect(ui->actionSave_schema, &QAction::triggered, this, &MainWindow::onStoreScheme);
connect(ui->actionExport_schema, &QAction::triggered, this, &MainWindow::onGenerateComdel);
connect(ui->actionValidate, &QAction::triggered, this, &MainWindow::onValidateSchema);
// setup central content
@ -47,10 +49,10 @@ void MainWindow::setupUi()
schemaParent->setLayout(schemaLayout);
schemaDisplay = new display::Schema();
schemaLayout->setMargin(0);
schemaLayout->setContentsMargins(0, 0, 0, 0);
schemaLayout->addWidget(schemaDisplay, 1);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(libraryDisplay);
layout->addWidget(schemaParent, 1);
@ -62,10 +64,10 @@ void MainWindow::setupUi()
void MainWindow::onLoadLibrary() {
auto filename = QFileDialog::getOpenFileName(this,
tr("Open library"), "/home", tr("Comdel library (*.csl)"));
tr("Otvori biblioteku"), "", tr("Comdel biblioteka (*.csl)"));
if(!filename.isEmpty()) {
std::ostringstream output;
clear();
log->clear();
auto librarySource = filename.toStdString();
@ -74,33 +76,35 @@ void MainWindow::onLoadLibrary() {
log->appendPlainText(QString::fromStdString(output.str()));
}
libraryDisplay->setLibrary(instance->getLibrary());
schemaDisplay->setSchema(instance->getSchema(), instance->getLibrary());
libraryDisplay->refreshContent();
schemaDisplay->refreshContent();
}
}
void MainWindow::onLoadSchema() {
auto filename = QFileDialog::getOpenFileName(this,
tr("Open schema"), "/home", tr("Comdel schema (*.csl)"));
tr("Otvori shemu"), "", tr("Comdel shema (*.csl)"));
if(!filename.isEmpty()) {
std::ostringstream output;
clear();
log->clear();
auto schemaSource = filename.toStdString();
auto instance = Application::instance();
if(!instance->loadSchema(schemaSource, output)) {
auto result = instance->loadSchema(schemaSource, output);
if(!result.first){
formatErrors(result.second, output);
log->appendPlainText(QString::fromStdString(output.str()));
}
libraryDisplay->setLibrary(instance->getLibrary());
schemaDisplay->setSchema(instance->getSchema(), instance->getLibrary());
libraryDisplay->refreshContent();
schemaDisplay->refreshContent();
}
}
void MainWindow::onStoreScheme() {
auto filename = QFileDialog::getSaveFileName(this,
tr("Save schema"), "/home", tr("Comdel schema (*.csl)"));
tr("Spremi shemu"), "", tr("Comdel shema (*.csl)"));
if(!filename.isEmpty()) {
log->clear();
@ -111,9 +115,9 @@ void MainWindow::onStoreScheme() {
out<<output.str();
out.close();
log->appendPlainText("Successfully stored schema\n");
log->appendPlainText("Uspješno spremljena shema\n");
} else {
log->appendPlainText("Failed storing schema\n");
log->appendPlainText("Greška tijekom spremanja sheme\n");
}
}
@ -121,7 +125,7 @@ void MainWindow::onStoreScheme() {
void MainWindow::onGenerateComdel() {
auto filename = QFileDialog::getSaveFileName(this,
tr("Save schema"), "/home", tr("Comdel system (*.system)"));
tr("Spremi shemu"), "", tr("Comdel sustav (*.system)"));
if(!filename.isEmpty()) {
log->clear();
@ -133,14 +137,14 @@ void MainWindow::onGenerateComdel() {
formatErrors(validationErrors, buff);
log->appendPlainText(QString::fromStdString(buff.str()));
if(Application::hasErrors(validationErrors)) {
if(!Application::hasErrors(validationErrors)) {
std::ofstream out(filename.toStdString(), std::ios::out | std::ios::binary);
out<<output.str();
out.close();
log->appendPlainText("Successfully generated comdel\n");
log->appendPlainText("Uspješno generiranje comdel modela\n");
} else {
log->appendPlainText("Failed generating comdel\n");
log->appendPlainText("Neuspješno generiranje comdel modela\n");
}
}
}
@ -176,12 +180,6 @@ void MainWindow::formatErrors(std::vector<domain::ValidationError>& errors, std:
}
}
void MainWindow::clear() {
log->clear();
this->schemaDisplay->setSchema(nullptr, std::nullopt);
this->libraryDisplay->setLibrary(std::nullopt);
}
MainWindow::~MainWindow()
{
delete ui;

View File

@ -53,17 +53,17 @@
</widget>
<action name="actionSave_schema">
<property name="text">
<string>Save schema</string>
<string>Spremi shemu</string>
</property>
</action>
<action name="actionExport_schema">
<property name="text">
<string>Export schema</string>
<string>Generiraj comdel</string>
</property>
</action>
<action name="actionValidate">
<property name="text">
<string>Validate</string>
<string>Validairaj</string>
</property>
</action>
</widget>