Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aac972c6ca | ||
|
|
5cf8235608 | ||
|
|
cbff8ff5f2 | ||
|
|
0a658a4aba | ||
|
|
1100a9f0b9 | ||
|
|
f11551fef6 | ||
|
|
281926cb8b |
No files matched your search
+1
-1
@@ -38,5 +38,5 @@ add_executable(SchemeEditor
|
||||
comdel/parser/comdellexer.cpp
|
||||
main.cpp
|
||||
mainwindow.ui
|
||||
comdel/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.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/domain/comdelvalidator.cpp comdel/domain/comdelvalidator.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)
|
||||
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
@@ -4,9 +4,8 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QLine>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <iostream>
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -36,8 +35,45 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
void Pin::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Connect pin", [&]() {});
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
void Pin::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if(event->button() == Qt::MouseButton::LeftButton) {
|
||||
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||
view->state = Schema::CREATING_CONNECTION;
|
||||
view->context.pin = this;
|
||||
view->context.startingPoint = dynamic_cast<ComponentGroup*>(this->parentItem())->pos() + QPointF(pin.getDisplayPin().getConnectionX(), pin.getDisplayPin().getConnectionY());
|
||||
view->context.line = new QGraphicsLineItem(QLineF(view->context.startingPoint, event->scenePos()));
|
||||
this->scene()->addItem(view->context.line);
|
||||
|
||||
view->showConnectable(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Pin::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||
if(view->state == Schema::CREATING_CONNECTION) {
|
||||
auto line = view->context.line->line();
|
||||
line.setP2(event->scenePos());
|
||||
view->context.line->setLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
void Pin::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if(event->button() == Qt::MouseButton::LeftButton) {
|
||||
auto view = dynamic_cast<Schema*>(this->scene()->views()[0]);
|
||||
view->state = Schema::DEFAULT;
|
||||
this->scene()->removeItem(view->context.line);
|
||||
delete view->context.line;
|
||||
view->removeConnectable(event->scenePos());
|
||||
}
|
||||
}
|
||||
|
||||
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Izmjeni ime", [this](){
|
||||
auto dialog = new NameDialog(this->busInstance.get());
|
||||
@@ -46,4 +82,79 @@ void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
QVariant BusGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == ItemPositionChange && scene()) {
|
||||
// value is the new position.
|
||||
QPointF newPos = value.toPointF();
|
||||
busInstance->position.first = newPos.x();
|
||||
busInstance->position.second = newPos.y();
|
||||
|
||||
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
||||
view->updateConnections();
|
||||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
BusGroup::BusGroup(const std::shared_ptr<domain::BusInstance> &instance): busInstance(instance) {
|
||||
setFlag(ItemIsMovable, true);
|
||||
setFlag(ItemSendsGeometryChanges, true);
|
||||
|
||||
setHandlesChildEvents(false);
|
||||
|
||||
bus = new display::Bus(instance);
|
||||
addToGroup(bus);
|
||||
|
||||
setPos(instance->position.first, instance->position.second);
|
||||
}
|
||||
|
||||
|
||||
QVariant ComponentGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == ItemPositionChange && scene()) {
|
||||
// value is the new position.
|
||||
QPointF newPos = value.toPointF();
|
||||
componentInstance->position.first = newPos.x();
|
||||
componentInstance->position.second = newPos.y();
|
||||
|
||||
auto view = dynamic_cast<Schema*>(scene()->views()[0]);
|
||||
view->updateConnections();
|
||||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void BusConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Ukloni poveznicu", [this](){});
|
||||
menu.addSeparator();
|
||||
for(int i=0; i<this->connection->attributes.size(); i++) {
|
||||
auto* attr = &this->connection->attributes[i];
|
||||
bool enabled = attr->attribute.getPopup().has_value();
|
||||
|
||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||
[attr]() {
|
||||
auto dialog = new AttributeDialog(attr);
|
||||
dialog->exec();
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
void DirectConnection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||
QMenu menu;
|
||||
menu.addAction("Ukloni poveznicu", [this](){});
|
||||
menu.addSeparator();
|
||||
for(int i=0; i<this->connection->attributes.size(); i++) {
|
||||
auto* attr = &this->connection->attributes[i];
|
||||
bool enabled = attr->attribute.getPopup().has_value();
|
||||
|
||||
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
||||
[attr]() {
|
||||
auto dialog = new AttributeDialog(attr);
|
||||
dialog->exec();
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <comdel/domain/wireinstance.h>
|
||||
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "comdel/domain/connectioninstance.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -12,9 +15,24 @@ class Pin: public QGraphicsItemGroup
|
||||
{
|
||||
private:
|
||||
domain::Pin pin;
|
||||
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||
|
||||
public:
|
||||
Pin(domain::Pin pin): pin(pin) {
|
||||
pin.getDisplay().render(this);
|
||||
Pin(domain::Pin pin, std::shared_ptr<domain::ComponentInstance> componentInstance): pin(pin), componentInstance(componentInstance) {
|
||||
pin.getDisplayPin().render(this);
|
||||
}
|
||||
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
domain::Pin& getPin() {
|
||||
return pin;
|
||||
}
|
||||
|
||||
domain::ComponentInstance* getComponentInstance() {
|
||||
return componentInstance.get();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,9 +42,12 @@ private:
|
||||
std::shared_ptr<domain::ComponentInstance> instance;
|
||||
public:
|
||||
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
||||
setFlag(ItemSendsGeometryChanges, true);
|
||||
|
||||
instance->component.getDisplay().render(this);
|
||||
}
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
||||
};
|
||||
|
||||
class Bus: public QGraphicsItemGroup
|
||||
@@ -34,8 +55,9 @@ class Bus: public QGraphicsItemGroup
|
||||
std::shared_ptr<domain::BusInstance> busInstance;
|
||||
public:
|
||||
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
||||
instance->bus.getDisplay()->render(this);
|
||||
instance->bus.getDisplayBus()->render(this, instance->size);
|
||||
}
|
||||
domain::BusInstance *getBusInstance() { return busInstance.get(); }
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
};
|
||||
|
||||
@@ -43,38 +65,111 @@ class ComponentGroup: public QGraphicsItemGroup
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||
std::vector<display::Pin*> pins;
|
||||
|
||||
public:
|
||||
|
||||
std::shared_ptr<domain::ComponentInstance> getComponentInstance() { return componentInstance; }
|
||||
std::vector<display::Pin*>& getPins() { return pins; }
|
||||
|
||||
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
|
||||
setFlag(ItemIsMovable, true);
|
||||
setFlag(ItemSendsGeometryChanges, true);
|
||||
|
||||
setHandlesChildEvents(false);
|
||||
|
||||
addToGroup(new display::Component(instance));
|
||||
|
||||
for(auto &pin: instance->component.getPins()) {
|
||||
addToGroup(new display::Pin(pin));
|
||||
pins.push_back(new display::Pin(pin, componentInstance));
|
||||
addToGroup(pins.back());
|
||||
}
|
||||
|
||||
setPos(instance->position.first, instance->position.second);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
};
|
||||
|
||||
class BusGroup: public QGraphicsItemGroup
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<domain::BusInstance> busInstance;
|
||||
display::Bus* bus;
|
||||
|
||||
public:
|
||||
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
||||
setFlag(ItemIsMovable, true);
|
||||
setHandlesChildEvents(false);
|
||||
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance);
|
||||
|
||||
addToGroup(new display::Bus(instance));
|
||||
display::Bus* getBus() { return bus; }
|
||||
|
||||
setPos(instance->position.first, instance->position.second);
|
||||
}
|
||||
protected:
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
};
|
||||
|
||||
class BusConnection: public QGraphicsLineItem
|
||||
{
|
||||
private:
|
||||
domain::BusConnectionInstance* connection;
|
||||
ComponentGroup* component;
|
||||
BusGroup* bus;
|
||||
|
||||
public:
|
||||
BusConnection(domain::BusConnectionInstance* connection, ComponentGroup *component, BusGroup *bus): connection(connection), component(component), bus(bus) {
|
||||
updateConnection();
|
||||
|
||||
setHandlesChildEvents(false);
|
||||
}
|
||||
|
||||
void updateConnection() {
|
||||
auto busPosition = bus->boundingRect();
|
||||
auto pin = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
||||
|
||||
setLine(connection->instance->position.first + pin.getConnectionX(), connection->instance->position.second + pin.getConnectionY(), connection->bus->position.first + busPosition.width()/2, connection->bus->position.second + busPosition.height()/2);
|
||||
|
||||
connection->start.first = connection->instance->position.first + pin.getConnectionX();
|
||||
connection->start.second = connection->instance->position.second + pin.getConnectionY();
|
||||
connection->end.first = connection->bus->position.first + busPosition.width()/2;
|
||||
connection->end.second = connection->bus->position.second + busPosition.height()/2;
|
||||
|
||||
}
|
||||
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
};
|
||||
|
||||
|
||||
class DirectConnection: public QGraphicsLineItem
|
||||
{
|
||||
private:
|
||||
domain::DirectConnectionInstance* connection;
|
||||
ComponentGroup* first;
|
||||
ComponentGroup* second;
|
||||
|
||||
public:
|
||||
DirectConnection(domain::DirectConnectionInstance* connection, ComponentGroup *first, ComponentGroup *second): connection(connection), first(first), second(second) {
|
||||
updateConnection();
|
||||
setHandlesChildEvents(false);
|
||||
}
|
||||
|
||||
void updateConnection() {
|
||||
auto pin1 = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
||||
auto pin2 = connection->secondInstance->component.getPin(connection->connection.getSecondComponent()->pin).getDisplayPin();
|
||||
|
||||
setLine(connection->instance->position.first + pin1.getConnectionX(), connection->instance->position.second + pin1.getConnectionY(),
|
||||
connection->secondInstance->position.first + pin2.getConnectionX(), connection->secondInstance->position.second + pin2.getConnectionY());
|
||||
|
||||
connection->start.first = connection->instance->position.first + pin1.getConnectionX();
|
||||
connection->start.second = connection->instance->position.second + pin1.getConnectionY();
|
||||
connection->end.first = connection->secondInstance->position.first + pin2.getConnectionX();
|
||||
connection->end.second = connection->secondInstance->position.second + pin2.getConnectionY();
|
||||
|
||||
}
|
||||
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace display
|
||||
|
||||
#endif // DISPLAY_COMPONENT_H
|
||||
@@ -11,8 +11,8 @@ Library::Library()
|
||||
auto layout = new QVBoxLayout();
|
||||
this->setLayout(layout);
|
||||
|
||||
componentList = new QListWidget();
|
||||
busList = new QListWidget();
|
||||
componentList = new LibraryList(this);
|
||||
busList = new LibraryList(this);
|
||||
|
||||
layout->setMargin(4);
|
||||
layout->addWidget(new QLabel("Components:"));
|
||||
@@ -34,14 +34,14 @@ void Library::setLibrary(std::optional<domain::Library> library) {
|
||||
}
|
||||
|
||||
for(auto& component: library->getComponents()) {
|
||||
auto item = new QListWidgetItem{QString::fromStdString(component.getName())};
|
||||
auto item = new LibraryListItem{component.getName(), "comdel/component", component.getName(), componentList};
|
||||
item->setToolTip(QString::fromStdString(component.getTooltip()));
|
||||
componentList->addItem(item);
|
||||
}
|
||||
|
||||
for(auto& bus: library->getBuses()) {
|
||||
if(bus.getType() == domain::Bus::REGULAR) {
|
||||
auto item = new QListWidgetItem{QString::fromStdString(bus.getName())};
|
||||
auto item = new LibraryListItem{bus.getName(), "comdel/bus", bus.getName(), busList};
|
||||
item->setToolTip(QString::fromStdString(bus.getTooltip()));
|
||||
busList->addItem(item);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include <comdel/domain/library.h>
|
||||
#include "library_list.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -18,8 +19,8 @@ public:
|
||||
private:
|
||||
std::optional<domain::Library> library;
|
||||
|
||||
QListWidget *componentList;
|
||||
QListWidget *busList;
|
||||
LibraryList *componentList;
|
||||
LibraryList *busList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by bbr on 22.05.22..
|
||||
//
|
||||
|
||||
#include "library_list.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace display {
|
||||
|
||||
LibraryList::LibraryList(QWidget *parent): QListWidget(parent) {
|
||||
setDragDropMode(DragOnly);
|
||||
}
|
||||
|
||||
QMimeData *LibraryList::mimeData(const QList<QListWidgetItem *> items) const {
|
||||
for(auto qItem: items) {
|
||||
// we only allow one item to be dragged at a time
|
||||
auto item = dynamic_cast<LibraryListItem*>(qItem);
|
||||
auto* md = new QMimeData();
|
||||
md->setData(QString::fromStdString(item->mimeType), QByteArray::fromStdString(item->value));
|
||||
return md;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LibraryListItem::LibraryListItem(std::string title, std::string mimeType, std::string value, QListWidget *parent): QListWidgetItem(parent), mimeType(mimeType), value(value) {
|
||||
setText(QString::fromStdString(title));
|
||||
}
|
||||
} // display
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by bbr on 22.05.22..
|
||||
//
|
||||
|
||||
#ifndef SCHEMEEDITOR_LIBRARY_LIST_H
|
||||
#define SCHEMEEDITOR_LIBRARY_LIST_H
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QList>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace display {
|
||||
|
||||
class LibraryList: public QListWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LibraryList(QWidget *parent);
|
||||
|
||||
protected:
|
||||
QMimeData *mimeData(const QList<QListWidgetItem*> items) const override;
|
||||
};
|
||||
|
||||
class LibraryListItem: public QListWidgetItem {
|
||||
|
||||
public:
|
||||
std::string mimeType;
|
||||
std::string value;
|
||||
|
||||
LibraryListItem(std::string title, std::string mimeType, std::string value, QListWidget *parent);
|
||||
};
|
||||
|
||||
} // display
|
||||
|
||||
#endif //SCHEMEEDITOR_LIBRARY_LIST_H
|
||||
@@ -1,28 +1,264 @@
|
||||
#include "component_display.h"
|
||||
#include "schema_display.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace display {
|
||||
|
||||
Schema::Schema()
|
||||
{
|
||||
this->selectedBrush.setColor(QColor::fromRgb(20,20,125));
|
||||
this->selectedPen.setColor(QColor::fromRgb(20, 20, 125));
|
||||
|
||||
this->setScene(&scene);
|
||||
this->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
|
||||
void Schema::setSchema(domain::Schema* _schema)
|
||||
void Schema::setSchema(domain::Schema* _schema, domain::Library* _library)
|
||||
{
|
||||
components.clear();
|
||||
buses.clear();
|
||||
|
||||
scene.clear();
|
||||
busConnections.clear();
|
||||
this->schema = _schema;
|
||||
this->library = _library;
|
||||
if(schema != nullptr) {
|
||||
for(auto &instance: schema->componentInstances) {
|
||||
scene.addItem(new display::ComponentGroup(instance));
|
||||
auto group = new display::ComponentGroup(instance);
|
||||
for(auto pin: group->getPins()) {
|
||||
display::Pin* p = pin;
|
||||
domain::ConnectionComponent connection{instance->name, p->getPin().getName()};
|
||||
pins.insert(std::make_pair(connection, p));
|
||||
}
|
||||
components.insert(std::make_pair(instance->name, group));
|
||||
scene.addItem(group);
|
||||
}
|
||||
for(auto &instance: schema->busInstances) {
|
||||
if(instance->bus.getDisplay().has_value()) {
|
||||
scene.addItem(new display::BusGroup(instance));
|
||||
if(instance->bus.getDisplayBus().has_value()) {
|
||||
auto group = new display::BusGroup(instance);
|
||||
buses.insert(std::make_pair(instance->name, group));
|
||||
scene.addItem(group);
|
||||
}
|
||||
}
|
||||
for(auto &connection: schema->connections) {
|
||||
auto busInstance = dynamic_cast<domain::BusConnectionInstance*>(connection.get());
|
||||
if(busInstance != nullptr) {
|
||||
auto con = new display::BusConnection(busInstance, components[busInstance->instance->name], buses[busInstance->bus->name]);
|
||||
busConnections.push_back(con);
|
||||
scene.addItem(con);
|
||||
}
|
||||
auto directInstance = dynamic_cast<domain::DirectConnectionInstance*>(connection.get());
|
||||
if(directInstance != nullptr) {
|
||||
auto con = new display::DirectConnection(directInstance, components[directInstance->instance->name], components[directInstance->secondInstance->name]);
|
||||
directConnections.push_back(con);
|
||||
scene.addItem(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Schema::updateConnections() {
|
||||
if(schema != nullptr) {
|
||||
for(auto conn: busConnections) {
|
||||
conn->updateConnection();
|
||||
}
|
||||
for(auto conn: directConnections) {
|
||||
conn->updateConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Schema::dragEnterEvent(QDragEnterEvent *event) {
|
||||
if(event->mimeData()->hasFormat("comdel/component") ||
|
||||
event->mimeData()->hasFormat("comdel/bus")) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void Schema::dropEvent(QDropEvent *event) {
|
||||
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()) {
|
||||
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
}
|
||||
|
||||
auto currentPos = this->mapToScene(event->pos());
|
||||
|
||||
auto instance = std::make_shared<domain::ComponentInstance>(component.getInstanceName(), attributes, std::make_pair(currentPos.x(), currentPos.y()), component);
|
||||
schema->componentInstances.push_back(instance);
|
||||
|
||||
auto group = new display::ComponentGroup(instance);
|
||||
scene.addItem(group);
|
||||
for(auto pin: group->getPins()) {
|
||||
display::Pin* p = pin;
|
||||
domain::ConnectionComponent connection{instance->name, p->getPin().getName()};
|
||||
pins.insert(std::make_pair(connection, p));
|
||||
}
|
||||
|
||||
components[instance->name] = group;
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
if(event->mimeData()->hasFormat("comdel/bus")) {
|
||||
auto bus = library->getBus(event->mimeData()->data("comdel/bus").toStdString());
|
||||
|
||||
auto currentPos = this->mapToScene(event->pos());
|
||||
|
||||
auto instance = std::make_shared<domain::BusInstance>(bus.getName(), std::make_pair(currentPos.x(), currentPos.y()), bus);
|
||||
schema->busInstances.push_back(instance);
|
||||
|
||||
auto group = new display::BusGroup(instance);
|
||||
scene.addItem(group);
|
||||
buses[instance->name] = group;
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void Schema::dragMoveEvent(QDragMoveEvent *event) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void Schema::removeConnectable(QPointF endPoint) {
|
||||
auto instance = context.pin->getComponentInstance();
|
||||
auto& pin = context.pin->getPin();
|
||||
|
||||
auto busInstances = getAvailableConnectionBusses(instance, pin);
|
||||
|
||||
for(auto &bus: busInstances) {
|
||||
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 conInstance = std::make_shared<domain::BusConnectionInstance>(instance, attributes, bus, *con);
|
||||
schema->connections.push_back(conInstance);
|
||||
|
||||
if (conInstance != nullptr) {
|
||||
auto c = new display::BusConnection(conInstance.get(), components[conInstance->instance->name],
|
||||
buses[conInstance->bus->name]);
|
||||
busConnections.push_back(c);
|
||||
scene.addItem(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto pinInstances = getAvailableConnectionPins(instance, pin);
|
||||
|
||||
for(auto &pinInstance: pinInstances) {
|
||||
auto rect = pins[pinInstance]->boundingRect();
|
||||
rect.setX(pins[pinInstance]->scenePos().x());
|
||||
rect.setY(pins[pinInstance]->scenePos().y());
|
||||
|
||||
if(rect.contains(endPoint)) {
|
||||
auto name = components[pinInstance.component]->getComponentInstance()->component.getName();
|
||||
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);
|
||||
|
||||
std::vector<domain::InstanceAttribute> attributes;
|
||||
for(auto attr: con->getAttributes()) {
|
||||
attributes.emplace_back(attr.getName(), attr.getDefault(), attr);
|
||||
}
|
||||
|
||||
auto conInstance = std::make_shared<domain::DirectConnectionInstance>(instance, components[pinInstance.component]->getComponentInstance().get(), attributes, busInstance.get(), *con);
|
||||
schema->connections.push_back(conInstance);
|
||||
|
||||
if (conInstance != nullptr) {
|
||||
auto c = new display::DirectConnection(conInstance.get(), components[conInstance->instance->name], components[conInstance->secondInstance->name]);
|
||||
directConnections.push_back(c);
|
||||
scene.addItem(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateConnections();
|
||||
|
||||
|
||||
for(auto& item: this->context.selectable) {
|
||||
this->scene.removeItem(item);
|
||||
delete item;
|
||||
}
|
||||
this->context.selectable.clear();
|
||||
}
|
||||
|
||||
void Schema::showConnectable(Pin *domainPin) {
|
||||
auto& pin = domainPin->getPin();
|
||||
|
||||
auto busInstances = getAvailableConnectionBusses(domainPin->getComponentInstance(), domainPin->getPin());
|
||||
|
||||
for(auto bus: busInstances) {
|
||||
auto& group = buses[bus->name];
|
||||
auto rect = new QGraphicsRectItem(group->boundingRect());
|
||||
rect->setPen(selectedPen);
|
||||
rect->setPos(group->scenePos());
|
||||
|
||||
auto _rect = rect->rect();
|
||||
_rect.setWidth(_rect.width() + 1);
|
||||
_rect.setHeight(_rect.height() + 1);
|
||||
rect->setRect(_rect);
|
||||
|
||||
context.selectable.push_back(rect);
|
||||
scene.addItem(rect);
|
||||
}
|
||||
|
||||
std::vector<domain::ConnectionComponent> pinInstances = getAvailableConnectionPins(domainPin->getComponentInstance(), domainPin->getPin());
|
||||
|
||||
for(auto& pinInstance: pinInstances) {
|
||||
auto& instance = pins[pinInstance];
|
||||
auto rect = new QGraphicsRectItem(instance->boundingRect());
|
||||
rect->setPen(selectedPen);
|
||||
rect->setPos(instance->scenePos());
|
||||
|
||||
auto _rect = rect->rect();
|
||||
_rect.setWidth(_rect.width() + 1);
|
||||
_rect.setHeight(_rect.height() + 1);
|
||||
rect->setRect(_rect);
|
||||
|
||||
context.selectable.push_back(rect);
|
||||
scene.addItem(rect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
@@ -4,22 +4,72 @@
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QWidget>
|
||||
#include <QGraphicsLineItem>
|
||||
|
||||
#include <comdel/domain/schema.h>
|
||||
#include <comdel/domain/library.h>
|
||||
#include "component_display.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
class BusConnection;
|
||||
|
||||
class Schema: public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
QBrush selectedBrush;
|
||||
QPen selectedPen;
|
||||
|
||||
enum State {
|
||||
DEFAULT,
|
||||
CREATING_CONNECTION
|
||||
};
|
||||
|
||||
struct Context {
|
||||
display::Pin *pin = nullptr;
|
||||
QPointF startingPoint;
|
||||
QGraphicsLineItem *line = nullptr;
|
||||
std::vector<QGraphicsRectItem*> selectable;
|
||||
};
|
||||
|
||||
std::map<std::string, display::ComponentGroup*> components;
|
||||
std::map<std::string, display::BusGroup*> buses;
|
||||
std::map<domain::ConnectionComponent, display::Pin*> pins;
|
||||
|
||||
State state = DEFAULT;
|
||||
Context context;
|
||||
|
||||
Schema();
|
||||
|
||||
void setSchema(domain::Schema* schema);
|
||||
std::vector<BusConnection*> busConnections;
|
||||
std::vector<DirectConnection*> directConnections;
|
||||
|
||||
void setSchema(domain::Schema* schema, domain::Library* library);
|
||||
|
||||
void updateConnections();
|
||||
|
||||
void removeConnectable(QPointF f);
|
||||
|
||||
void showConnectable(Pin *pin);
|
||||
|
||||
protected:
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
|
||||
private:
|
||||
QGraphicsScene scene;
|
||||
|
||||
domain::Schema* schema;
|
||||
domain::Library* library;
|
||||
|
||||
std::vector<domain::BusInstance*> getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||
|
||||
std::vector<domain::ConnectionComponent> getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
@@ -26,8 +26,8 @@ Wire::WireType Wire::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
Bus::Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<Display> display)
|
||||
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), display(display)
|
||||
Bus::Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<ui::Bus> displayBus)
|
||||
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus)
|
||||
{}
|
||||
|
||||
std::string Bus::getName() {
|
||||
@@ -42,12 +42,11 @@ Bus::BusType Bus::getType() {
|
||||
std::pair<int, int> Bus::getCount() {
|
||||
return count;
|
||||
}
|
||||
std::optional<Display> Bus::getDisplay() {
|
||||
return display;
|
||||
}
|
||||
std::vector<Wire> Bus::getWires() {
|
||||
return wires;
|
||||
}
|
||||
|
||||
std::optional<ui::Bus> Bus::getDisplayBus() {
|
||||
return displayBus;
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
+3
-3
@@ -55,18 +55,18 @@ private:
|
||||
BusType type;
|
||||
|
||||
std::pair<int, int> count;
|
||||
std::optional<Display> display;
|
||||
std::optional<ui::Bus> displayBus;
|
||||
std::vector<Wire> wires;
|
||||
|
||||
public:
|
||||
Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<Display> display = std::nullopt);
|
||||
Bus(std::string name, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires, std::optional<ui::Bus> display = std::nullopt);
|
||||
|
||||
std::string getName();
|
||||
std::string getTooltip();
|
||||
BusType getType();
|
||||
std::pair<int, int> getCount();
|
||||
std::vector<Wire> getWires();
|
||||
std::optional<Display> getDisplay();
|
||||
std::optional<ui::Bus> getDisplayBus();
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
@@ -94,6 +94,7 @@ void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer)
|
||||
}
|
||||
|
||||
void generateBus(BusInstance *bus, ostream &buffer);
|
||||
void generateConnection(ConnectionInstance *connection, ostream &buffer);
|
||||
|
||||
void generateDisplay(Schema *schema, ostream &buffer) {
|
||||
buffer << "\n\tdisplay {\n";
|
||||
@@ -106,15 +107,26 @@ void generateDisplay(Schema *schema, ostream &buffer) {
|
||||
generateBus(bus.get(), buffer);
|
||||
}
|
||||
|
||||
buffer << "\n";
|
||||
|
||||
for(auto &connection: schema->connections) {
|
||||
generateConnection(connection.get(), buffer);
|
||||
}
|
||||
|
||||
buffer << "\t}\n";
|
||||
}
|
||||
|
||||
void generateConnection(ConnectionInstance *connection, ostream &buffer) {
|
||||
buffer << "\t\tline {x1:" << connection->start.first << "; y1:" << connection->start.second << "; " <<
|
||||
"x2:" << connection->end.first << "; y2:" << connection->end.second << ";}" << "\n";
|
||||
}
|
||||
|
||||
void generateBus(BusInstance *bus, ostream &buffer) {
|
||||
buffer << "\n";
|
||||
buffer << "\t\t// " << bus->name << " bus\n\n";
|
||||
|
||||
if(bus->bus.getDisplay().has_value()) {
|
||||
bus->bus.getDisplay()->comdel(buffer, bus->position.first, bus->position.second, bus->size);
|
||||
if(bus->bus.getDisplayBus().has_value()) {
|
||||
bus->bus.getDisplayBus()->comdel(buffer, bus->position.first, bus->position.second, bus->size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "comdelvalidator.h"
|
||||
#include "library.h"
|
||||
|
||||
namespace domain {
|
||||
|
||||
@@ -15,6 +16,78 @@ std::vector<ValidationError> ComdelValidator::validateSchema(Schema &schema, Val
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<ValidationError> ComdelValidator::validateInstanceCount(Schema& schema, Library& library, ValidationContext context) {
|
||||
std::vector<ValidationError> errors;
|
||||
|
||||
// validate instance count
|
||||
std::map<std::string, int> instanceMap;
|
||||
for(auto& inst: schema.componentInstances) {
|
||||
instanceMap[inst->component.getName()]++;
|
||||
}
|
||||
|
||||
for(auto comp: library.getComponents()) {
|
||||
int count = instanceMap[comp.getName()];
|
||||
|
||||
context.attributes["componentName"] = Value::fromString(comp.getName());
|
||||
context.attributes["min"] = Value::fromInt(comp.getCount().first);
|
||||
context.attributes["max"] = Value::fromInt(comp.getCount().second);
|
||||
context.attributes["count"] = Value::fromInt(count);
|
||||
|
||||
if(count < comp.getCount().first) {
|
||||
auto message = populateMessage("Not enough instances of component '{componentName}' required at least {min}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
} else if(count > comp.getCount().second) {
|
||||
auto message = populateMessage("To many instances of component '{componentName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// validate bus instance count
|
||||
std::map<std::string, int> busInstanceMap;
|
||||
for(auto& inst: schema.busInstances) {
|
||||
busInstanceMap[inst->bus.getName()]++;
|
||||
}
|
||||
|
||||
for(auto bus: library.getBuses()) {
|
||||
int count = busInstanceMap[bus.getName()];
|
||||
|
||||
context.attributes["busName"] = Value::fromString(bus.getName());
|
||||
context.attributes["min"] = Value::fromInt(bus.getCount().first);
|
||||
context.attributes["max"] = Value::fromInt(bus.getCount().second);
|
||||
context.attributes["count"] = Value::fromInt(count);
|
||||
|
||||
if(count < bus.getCount().first) {
|
||||
auto message = populateMessage("Not enough instances of bus '{busName}' required at least {min}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
} else if(count > bus.getCount().second) {
|
||||
auto message = populateMessage("To many instances of bus '{busName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<ValidationError> ComdelValidator::validatePinConnections(Schema &schema, Library &library, ValidationContext context) {
|
||||
std::vector<ValidationError> errors;
|
||||
|
||||
for(auto& inst: schema.componentInstances) {
|
||||
for(auto& pin: inst->component.getPins()) {
|
||||
if(pin.getConnection().getType() == PinConnection::REQUIRED) {
|
||||
if(!connectionExists(schema, inst, pin)) {
|
||||
context.instance = inst.get();
|
||||
context.attributes["instanceName"] = Value::fromString(inst->name);
|
||||
auto message = populateMessage(pin.getConnection().getMessage(), context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<ValidationError> ComdelValidator::validateComponent(ComponentInstance* instance, ValidationContext context) {
|
||||
std::vector<ValidationError> errors;
|
||||
|
||||
@@ -89,4 +162,26 @@ string ComdelValidator::replacePlaceholder(string source, string key, Value valu
|
||||
return source;
|
||||
}
|
||||
|
||||
bool ComdelValidator::connectionExists(Schema &schema, shared_ptr<ComponentInstance> &component, Pin &pin) {
|
||||
for(auto conn: schema.connections) {
|
||||
auto busConnection = dynamic_cast<BusConnectionInstance*>(conn.get());
|
||||
if(busConnection != nullptr) {
|
||||
if(busConnection->instance->name == component->name && busConnection->connection.getComponent().pin == pin.getName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
auto directConnection = dynamic_cast<DirectConnectionInstance*>(conn.get());
|
||||
if(directConnection != nullptr) {
|
||||
if(directConnection->instance->name == component->name && busConnection->connection.getComponent().pin == pin.getName()) {
|
||||
return true;
|
||||
}
|
||||
if(directConnection->secondInstance->name == component->name && busConnection->connection.getSecondComponent()->pin == pin.getName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "instance.h"
|
||||
#include "schema.h"
|
||||
#include "library.h"
|
||||
|
||||
namespace domain {
|
||||
|
||||
@@ -29,6 +30,9 @@ public:
|
||||
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
|
||||
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library& library, ValidationContext context);
|
||||
std::vector<ValidationError> validatePinConnections(Schema &schema, Library& library, ValidationContext context);
|
||||
|
||||
ComdelValidator(std::vector<FunctionValidator*> validators) {
|
||||
for(auto* validator: validators) {
|
||||
validator->clear();
|
||||
@@ -42,6 +46,8 @@ private:
|
||||
std::string populateMessage(string message, ValidationContext context);
|
||||
|
||||
string replacePlaceholder(string message, const string name, Value value);
|
||||
|
||||
bool connectionExists(Schema &schema, shared_ptr <ComponentInstance> &component, Pin &pin);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -63,4 +63,14 @@ bool Connection::isConnecting(ConnectionComponent component, std::string bus, Co
|
||||
(this->first == secondComponent && this->bus == bus && this->second == component);
|
||||
}
|
||||
|
||||
|
||||
bool Connection::isConnecting(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
if(!second.has_value()) {
|
||||
return false;
|
||||
}
|
||||
return (this->first == component && this->second == secondComponent) ||
|
||||
(this->first == secondComponent && this->second == component);
|
||||
}
|
||||
|
||||
|
||||
} // namespace domain
|
||||
@@ -21,6 +21,17 @@ struct ConnectionComponent
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
bool operator<(const ConnectionComponent& rhs) const
|
||||
{
|
||||
if(component < rhs.component) {
|
||||
return true;
|
||||
} else if(component == rhs.component) {
|
||||
if(pin < rhs.pin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Connection
|
||||
@@ -40,6 +51,7 @@ public:
|
||||
bool isConnecting(ConnectionComponent first);
|
||||
bool isConnecting(ConnectionComponent first, std::string bus);
|
||||
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
||||
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
|
||||
|
||||
|
||||
ConnectionComponent getComponent();
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "instance.h"
|
||||
#include "wireinstance.h"
|
||||
|
||||
|
||||
|
||||
namespace domain {
|
||||
|
||||
class ConnectionInstance
|
||||
@@ -19,6 +17,9 @@ public:
|
||||
|
||||
std::vector<InstanceAttribute> attributes;
|
||||
|
||||
std::pair<int, int> start;
|
||||
std::pair<int, int> end;
|
||||
|
||||
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection);
|
||||
|
||||
InstanceAttribute getAttribute(string attribute);
|
||||
|
||||
+139
-12
@@ -20,7 +20,7 @@ public:
|
||||
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
||||
}
|
||||
|
||||
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||
void comdel(std::ostream &buffer, int x, int y) {
|
||||
buffer << "\t\trectangle {\n";
|
||||
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
||||
buffer << "\t\t\tw: " << w << "; h: " << h << ";\n";
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||
void comdel(std::ostream &buffer, int x, int y) {
|
||||
buffer << "\t\tline {\n";
|
||||
buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n";
|
||||
buffer << "\t\t\tx2: " << (x2 + x) << "; y2: " << (y2 + y) << ";\n";
|
||||
@@ -47,45 +47,170 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
enum Orientation {
|
||||
enum PinOrientation {
|
||||
LEFT, RIGHT, TOP, BOTTOM
|
||||
};
|
||||
enum BusOrientation {
|
||||
VERTICAL, HORIZONTAL
|
||||
};
|
||||
|
||||
enum PinType {
|
||||
IN, OUT, IN_OUT
|
||||
};
|
||||
|
||||
|
||||
class Bus {
|
||||
public:
|
||||
int x, y, w, h;
|
||||
BusOrientation orientation;
|
||||
|
||||
Bus(int x, int y, int w, int h, BusOrientation orientation): x(x), y(y), w(w), h(h), orientation(orientation) {}
|
||||
|
||||
void render(QGraphicsItemGroup *group, int size) {
|
||||
if(orientation == HORIZONTAL) {
|
||||
group->addToGroup(new QGraphicsRectItem(x,y,size, h));
|
||||
} else {
|
||||
group->addToGroup(new QGraphicsRectItem(x,y,w,size));
|
||||
}
|
||||
}
|
||||
|
||||
int getDefaultSize() {
|
||||
if(orientation == HORIZONTAL) {
|
||||
return w;
|
||||
} else {
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||
buffer << "\t\trectangle {\n";
|
||||
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
||||
if(orientation == HORIZONTAL) {
|
||||
buffer << "\t\t\tw: " << size << "; h: " << h << ";\n";
|
||||
} else {
|
||||
buffer << "\t\t\tw: " << w << "; h: " << size << ";\n";
|
||||
}
|
||||
buffer << "\t\t}\n\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Pin {
|
||||
public:
|
||||
Orientation orientation;
|
||||
PinOrientation orientation;
|
||||
PinType pinType;
|
||||
int x, y, w, h;
|
||||
|
||||
Pin(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {}
|
||||
Pin(int x, int y, int w, int h, PinOrientation orientation, PinType pinType): x(x), y(y), w(w), h(h), orientation(orientation), pinType(pinType) {}
|
||||
|
||||
void renderIn(QGraphicsItemGroup *group) {
|
||||
QPolygon polygon;
|
||||
|
||||
switch (orientation) {
|
||||
case PinOrientation::TOP:
|
||||
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y) << QPoint(x+w/2, y+h/2);
|
||||
break;
|
||||
case PinOrientation::BOTTOM:
|
||||
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w/2, y+h/2) << QPoint(x+w, y+h) << QPoint(x+w, y);
|
||||
break;
|
||||
case PinOrientation::LEFT:
|
||||
polygon << QPoint(x, y) << QPoint(x+w/2, y+h/2) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y);
|
||||
break;
|
||||
case PinOrientation::RIGHT:
|
||||
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w/2, y+h/2) << QPoint(x+w, y);
|
||||
break;
|
||||
}
|
||||
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||
}
|
||||
|
||||
void renderOut(QGraphicsItemGroup *group) {
|
||||
QPolygon polygon;
|
||||
|
||||
switch (orientation) {
|
||||
case PinOrientation::TOP:
|
||||
polygon << QPoint(x, y+h/2) << QPoint(x, y+h) << QPoint(x+w, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w/2, y);
|
||||
break;
|
||||
case PinOrientation::BOTTOM:
|
||||
polygon << QPoint(x, y) << QPoint(x, y+h/2) << QPoint(x+w/2, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w, y);
|
||||
break;
|
||||
case PinOrientation::LEFT:
|
||||
polygon << QPoint(x+w, y) << QPoint(x+w/2, y) << QPoint(x, y+h/2) << QPoint(x+w/2, y+h) << QPoint(x+w, y+w);
|
||||
break;
|
||||
case PinOrientation::RIGHT:
|
||||
polygon << QPoint(x, y) << QPoint(x, y+h) << QPoint(x+w/2, y+h) << QPoint(x+w, y+h/2) << QPoint(x+w/2, y);
|
||||
break;
|
||||
}
|
||||
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||
}
|
||||
|
||||
void renderInOut(QGraphicsItemGroup *group) {
|
||||
group->addToGroup(new QGraphicsRectItem(x, y ,w, h));
|
||||
}
|
||||
|
||||
void render(QGraphicsItemGroup *group) {
|
||||
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
||||
switch (pinType) {
|
||||
case PinType::IN:
|
||||
renderIn(group);
|
||||
break;
|
||||
case PinType::OUT:
|
||||
renderOut(group);
|
||||
break;
|
||||
case PinType::IN_OUT:
|
||||
renderInOut(group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int getConnectionX() {
|
||||
switch (orientation) {
|
||||
case ui::PinOrientation::TOP:
|
||||
case ui::PinOrientation::BOTTOM:
|
||||
return x+w/2;
|
||||
case ui::PinOrientation::LEFT:
|
||||
return x;
|
||||
case ui::PinOrientation::RIGHT:
|
||||
return x+w;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getConnectionY() {
|
||||
switch (orientation) {
|
||||
case ui::PinOrientation::LEFT:
|
||||
case ui::PinOrientation::RIGHT:
|
||||
return y+h/2;
|
||||
case ui::PinOrientation::TOP:
|
||||
return y;
|
||||
case ui::PinOrientation::BOTTOM:
|
||||
return y+h;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Item {
|
||||
public:
|
||||
Item(): rect(std::nullopt), line(std::nullopt), pin(std::nullopt) {}
|
||||
Item(): rect(std::nullopt), line(std::nullopt), pin(std::nullopt), bus(std::nullopt) {}
|
||||
|
||||
void render(QGraphicsItemGroup *group) {
|
||||
void render(QGraphicsItemGroup *group, int size = 0) {
|
||||
if(rect) rect->render(group);
|
||||
if(line) line->render(group);
|
||||
if(pin) pin->render(group);
|
||||
if(bus) bus->render(group, size);
|
||||
}
|
||||
|
||||
std::optional<Rect> rect = std::nullopt;
|
||||
std::optional<Line> line = std::nullopt;
|
||||
std::optional<Pin> pin = std::nullopt;
|
||||
std::optional<Bus> bus = std::nullopt;
|
||||
|
||||
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||
if(rect) rect->comdel(buffer, x, y, size);
|
||||
if(line) line->comdel(buffer, x, y, size);
|
||||
void comdel(std::ostream &buffer, int x, int y, int size = 0) {
|
||||
if(rect) rect->comdel(buffer, x, y);
|
||||
if(line) line->comdel(buffer, x, y);
|
||||
// pins aren't exported
|
||||
if(bus) bus->comdel(buffer, x, y, size);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,12 +228,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void comdel(std::ostream &buffer, int x, int y, int size) {
|
||||
void comdel(std::ostream &buffer, int x, int y, int size = 0) {
|
||||
for(auto &item: items) {
|
||||
item.comdel(buffer, x, y, size);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ui::Item>& getItems() {return items;}
|
||||
|
||||
private:
|
||||
std::vector<ui::Item> items;
|
||||
};
|
||||
|
||||
@@ -4,8 +4,15 @@ namespace domain {
|
||||
|
||||
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
|
||||
: name(name), position(position), bus(bus), size(size)
|
||||
{}
|
||||
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
|
||||
{
|
||||
if(size < 0 && bus.getDisplayBus().has_value()) {
|
||||
this->size = bus.getDisplayBus()->getDefaultSize();
|
||||
}
|
||||
}
|
||||
|
||||
BusInstance::BusInstance(std::string name, Bus bus): name(name), bus(bus), position(0,0), size(0) {}
|
||||
|
||||
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
|
||||
: name(name), attributes(std::move(attributes)), position(position), component(component)
|
||||
{}
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ public:
|
||||
Bus bus;
|
||||
int size;
|
||||
|
||||
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size);
|
||||
BusInstance(std::string name, Bus bus);
|
||||
|
||||
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size = -1);
|
||||
|
||||
virtual ~BusInstance() = default;
|
||||
};
|
||||
|
||||
@@ -113,4 +113,18 @@ std::string Library::getMessage(std::string key) {
|
||||
return messages[key];
|
||||
}
|
||||
|
||||
bool Library::hasConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
return getConnection(component, secondComponent).has_value();
|
||||
}
|
||||
|
||||
std::optional<Connection>
|
||||
Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
for(auto & connection : connections) {
|
||||
if(connection.isConnecting(component, secondComponent)) {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
@@ -60,6 +60,10 @@ public:
|
||||
|
||||
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||
std::optional<Connection> getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||
|
||||
bool hasConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||
std::optional<Connection> getConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
@@ -14,8 +14,8 @@ std::string PinConnection::getMessage() {
|
||||
}
|
||||
|
||||
|
||||
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires)
|
||||
: name(name), type(type), tooltip(tooltip), connection(connection), display(display), wires(wires)
|
||||
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin, std::optional<std::vector<Value>> wires)
|
||||
: name(name), type(type), tooltip(tooltip), connection(connection), displayPin(pin), wires(wires)
|
||||
{}
|
||||
|
||||
std::string &Pin::getName() {
|
||||
@@ -27,8 +27,8 @@ Pin::PinType Pin::getType() {
|
||||
std::string Pin::getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
Display &Pin::getDisplay() {
|
||||
return display;
|
||||
ui::Pin &Pin::getDisplayPin() {
|
||||
return displayPin;
|
||||
}
|
||||
PinConnection &Pin::getConnection() {
|
||||
return connection;
|
||||
|
||||
+3
-3
@@ -43,17 +43,17 @@ private:
|
||||
PinType type;
|
||||
std::string tooltip;
|
||||
PinConnection connection;
|
||||
Display display;
|
||||
domain::ui::Pin displayPin;
|
||||
|
||||
std::optional<std::vector<Value>> wires;
|
||||
|
||||
public:
|
||||
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires);
|
||||
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, domain::ui::Pin pin, std::optional<std::vector<Value>> wires);
|
||||
|
||||
std::string &getName();
|
||||
PinType getType();
|
||||
std::string getTooltip();
|
||||
Display &getDisplay();
|
||||
ui::Pin &getDisplayPin();
|
||||
PinConnection &getConnection();
|
||||
std::optional<std::vector<Value>> &getWires();
|
||||
};
|
||||
|
||||
+15
-14
@@ -9,8 +9,7 @@
|
||||
|
||||
namespace domain {
|
||||
|
||||
class Schema
|
||||
{
|
||||
class Schema {
|
||||
public:
|
||||
Schema();
|
||||
|
||||
@@ -19,16 +18,8 @@ public:
|
||||
|
||||
std::vector<shared_ptr<ConnectionInstance>> connections;
|
||||
|
||||
BusInstance *getBusInstance(std::string& name) {
|
||||
for(auto& instance: busInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
ComponentInstance *getComponentInstance(std::string& name) {
|
||||
for(auto& instance: componentInstances) {
|
||||
BusInstance *getBusInstance(std::string &name) {
|
||||
for (auto &instance: busInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
@@ -36,8 +27,18 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasConnection(string& component, string& pin);
|
||||
ConnectionInstance* getConnection(string& component, string& pin);
|
||||
ComponentInstance *getComponentInstance(std::string &name) {
|
||||
for (auto &instance: componentInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasConnection(string &component, string &pin);
|
||||
|
||||
ConnectionInstance *getConnection(string &component, string &pin);
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
@@ -210,12 +210,17 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
optional<Display> display;
|
||||
optional<ui::Bus> displayBus;
|
||||
if(type == Bus::REGULAR) {
|
||||
display = loadDisplay(*node.display);
|
||||
auto display = loadDisplay(*node.display);
|
||||
if(!display) {
|
||||
return nullopt;
|
||||
}
|
||||
if(display->getItems().size() != 1 || !display->getItems()[0].bus.has_value()) {
|
||||
errors.emplace_back(node.span, "@display must contain only exactly one bus definition");
|
||||
return nullopt;
|
||||
}
|
||||
displayBus = *display->getItems()[0].bus;
|
||||
}
|
||||
|
||||
if(node.wires.size() == 0) {
|
||||
@@ -235,7 +240,7 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
return Bus(name, tooltip, type, count, wires, display);
|
||||
return Bus(name, tooltip, type, count, wires, displayBus);
|
||||
}
|
||||
|
||||
|
||||
@@ -542,6 +547,12 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
||||
if(!display) {
|
||||
return nullopt;
|
||||
}
|
||||
if(display->getItems().size() != 1 || !display->getItems()[0].pin.has_value()) {
|
||||
errors.emplace_back(node.span, "@display must contain only exactly one pin definition");
|
||||
return nullopt;
|
||||
}
|
||||
ui::Pin displayPin = *display->getItems()[0].pin;
|
||||
|
||||
|
||||
if(!node.connection) {
|
||||
errors.emplace_back(node.span, "missing @connection");
|
||||
@@ -565,16 +576,7 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
||||
wiresOpt = wires;
|
||||
}
|
||||
|
||||
return Pin(name, type, tooltip, connection, *display, wiresOpt);
|
||||
}
|
||||
|
||||
int getIntProperty(DisplayItemNode &node, std::string property) {
|
||||
for(auto& prop: node.values) {
|
||||
if(prop.key.value == property) {
|
||||
return prop.value.asInt();
|
||||
}
|
||||
}
|
||||
throw std::exception();
|
||||
return Pin(name, type, tooltip, connection, displayPin, wiresOpt);
|
||||
}
|
||||
|
||||
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
||||
@@ -584,26 +586,71 @@ std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
||||
ui::Item displayItem;
|
||||
std::string type = item.type.value;
|
||||
if(type == "rect") {
|
||||
int x, y, w, h;
|
||||
x = getIntProperty(item, "x");
|
||||
y = getIntProperty(item, "y");
|
||||
w = getIntProperty(item, "w");
|
||||
h = getIntProperty(item, "h");
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
displayItem.rect = ui::Rect(x, y, w, h);
|
||||
} else if(type == "line") {
|
||||
int x1, y1, x2, y2;
|
||||
x1 = getIntProperty(item, "x1");
|
||||
y1 = getIntProperty(item, "y1");
|
||||
x2 = getIntProperty(item, "x2");
|
||||
y2 = getIntProperty(item, "y2");
|
||||
long long int x1, y1, x2, y2;
|
||||
x1 = item.asInt(&errors, "x1");
|
||||
y1 = item.asInt(&errors, "y1");
|
||||
x2 = item.asInt(&errors, "x2");
|
||||
y2 = item.asInt(&errors, "y2");
|
||||
displayItem.line = ui::Line(x1, y1, x2, y2);
|
||||
} else if(type == "pin") {
|
||||
int x, y, w, h;
|
||||
x = getIntProperty(item, "x");
|
||||
y = getIntProperty(item, "y");
|
||||
w = getIntProperty(item, "w");
|
||||
h = getIntProperty(item, "h");
|
||||
displayItem.pin = ui::Pin(x, y, w, h);
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
std::string _orientation = item.asString(&errors, "orientation", "bottom");
|
||||
std::string _pinType = item.asString(&errors, "type", "out");
|
||||
|
||||
ui::PinOrientation orientation;
|
||||
if(_orientation == "left") {
|
||||
orientation = ui::PinOrientation::LEFT;
|
||||
} else if(_orientation == "right") {
|
||||
orientation = ui::PinOrientation::RIGHT;
|
||||
} else if(_orientation == "top") {
|
||||
orientation = ui::PinOrientation::TOP;
|
||||
} else if(_orientation == "bottom") {
|
||||
orientation = ui::PinOrientation::BOTTOM;
|
||||
} else {
|
||||
errors.emplace_back(item.span, "unknown pin orientation type '" + _orientation + "'");
|
||||
}
|
||||
|
||||
ui::PinType pinType;
|
||||
if(_pinType == "in") {
|
||||
pinType = ui::PinType::IN;
|
||||
} else if(_pinType == "out") {
|
||||
pinType = ui::PinType::OUT;
|
||||
} else if(_pinType == "in_out") {
|
||||
pinType = ui::PinType::IN_OUT;
|
||||
} else {
|
||||
errors.emplace_back(item.span, "unknown pin type '" + _pinType + "'");
|
||||
}
|
||||
|
||||
displayItem.pin = ui::Pin(x, y, w, h, orientation, pinType);
|
||||
} else if(type == "bus") {
|
||||
long long int x, y, w, h;
|
||||
x = item.asInt(&errors, "x");
|
||||
y = item.asInt(&errors, "y");
|
||||
w = item.asInt(&errors, "w");
|
||||
h = item.asInt(&errors, "h");
|
||||
std::string _orientation = item.asString(&errors, "orientation", "bottom");
|
||||
|
||||
ui::BusOrientation orientation;
|
||||
if(_orientation == "horizontal") {
|
||||
orientation = ui::BusOrientation::HORIZONTAL;
|
||||
} else if(_orientation == "vertical") {
|
||||
orientation = ui::BusOrientation::VERTICAL;
|
||||
} else {
|
||||
errors.emplace_back(item.span, "unknown bus orientation type '" + _orientation + "'");
|
||||
}
|
||||
|
||||
displayItem.bus = ui::Bus(x, y, w, h, orientation);
|
||||
} else {
|
||||
errors.emplace_back(item.type.span, "unsupported display type");
|
||||
}
|
||||
@@ -946,7 +993,7 @@ vector<Enumeration> SchemaCreator::createWireEnumeration(vector<Value> wireValue
|
||||
}
|
||||
|
||||
std::optional<Attribute> SchemaCreator::createMemoryAttribute() {
|
||||
return Attribute("_memory", Value::fromMemoryReference(nullopt), createMemoryPopup());
|
||||
return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup());
|
||||
}
|
||||
|
||||
std::optional<Popup> SchemaCreator::createMemoryPopup() {
|
||||
|
||||
@@ -162,10 +162,10 @@ std::string Value::stringify() {
|
||||
case ATTRIBUTE_REFERENCE:
|
||||
return reference;
|
||||
case MEMORY_REFERENCE:
|
||||
if(memoryReference->empty()) {
|
||||
return "null";
|
||||
} else {
|
||||
if(memoryReference.has_value()) {
|
||||
return memoryReference.value();
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
default:
|
||||
throw std::exception();
|
||||
|
||||
@@ -29,22 +29,20 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
long long intValue;
|
||||
long long intValue = 0;
|
||||
std::string stringValue;
|
||||
bool boolValue;
|
||||
std::optional<AddressSpace> addressSpace;
|
||||
bool boolValue = false;
|
||||
std::optional<AddressSpace> addressSpace = std::nullopt;
|
||||
std::string reference;
|
||||
domain::ComponentInstance *memory;
|
||||
domain::ComponentInstance *memory = nullptr;
|
||||
|
||||
std::optional<std::string> memoryReference;
|
||||
std::optional<std::string> memoryReference = std::nullopt;
|
||||
|
||||
ValueType type;
|
||||
ValueType type = UNDEFINED;
|
||||
|
||||
public:
|
||||
|
||||
Value() {
|
||||
this->type = UNDEFINED;
|
||||
}
|
||||
Value() {}
|
||||
|
||||
bool equals(Value value) {
|
||||
if(value.getType() == type) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define AST_NODE_H
|
||||
|
||||
#include "token.h"
|
||||
#include "sourceerror.h"
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
@@ -173,6 +174,52 @@ struct DisplayItemNode: public AstNode
|
||||
{
|
||||
IdentifierNode type;
|
||||
std::vector<PropertyNode> values;
|
||||
|
||||
long long int asInt(std::vector<SourceError>* errors, const std::string& property, long long int _default = 0) {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::INT)) {
|
||||
return prop.value.asInt();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected number");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
|
||||
std::string asIdentifier(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::IDENTIFIER)) {
|
||||
return prop.value.asIdentifier();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected identifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
|
||||
|
||||
std::string asString(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::STRING)) {
|
||||
return prop.value.asString();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected string");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
};
|
||||
|
||||
struct DisplayNode: public AstNode
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// Version 0.0.1
|
||||
#include "libraries\frisc\vjezba1\FRISC.cdl"
|
||||
#include "libraries\frisc\vjezba1\memory.cdl"
|
||||
|
||||
|
||||
|
||||
component System
|
||||
{
|
||||
clock 100MHz;
|
||||
//directRam
|
||||
wire INT;
|
||||
|
||||
|
||||
//glavnaSabirnica
|
||||
wire<32> ADR;
|
||||
wire<32> DATA;
|
||||
wire READ;
|
||||
wire WRITE;
|
||||
wired_and WAIT;
|
||||
wired_and INT0;
|
||||
wired_and INT1;
|
||||
wired_and INT2;
|
||||
wired_and INT3;
|
||||
wire<3> SIZE;
|
||||
wire --IACK;
|
||||
wire --BREQ;
|
||||
wire --BACK;
|
||||
|
||||
|
||||
// components --------------------------------------------
|
||||
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) uses memorija;
|
||||
|
||||
display {
|
||||
component { x: -12; y: 68; ref: "memorija"; }
|
||||
component { x: -206; y: -76; ref: "procesor"; }
|
||||
|
||||
// directRam bus
|
||||
|
||||
|
||||
// glavnaSabirnica bus
|
||||
|
||||
rectangle {
|
||||
x: -222; y: 130;
|
||||
w: 100; h: 20;
|
||||
}
|
||||
|
||||
|
||||
line {x1:-28; y1:96; x2:-90; y2:-26;}
|
||||
line {x1:38; y1:52; x2:-171; y2:140;}
|
||||
line {x1:-156; y1:40; x2:-171; y2:140;}
|
||||
}
|
||||
}
|
||||
@@ -51,25 +51,29 @@
|
||||
x: 0; y:0; w:100; h:100;
|
||||
}
|
||||
}
|
||||
@pin glavniPin inOut {
|
||||
@pin glavniPin in {
|
||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||
@connection required("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
||||
@display {
|
||||
/*
|
||||
pin {
|
||||
x: 100; y: 50;
|
||||
fillColor: white;
|
||||
lineColor: red;
|
||||
fillColorConnected: white;
|
||||
lineColorConnected: black;
|
||||
side: left;
|
||||
size: 20;
|
||||
}*/
|
||||
pin {
|
||||
x: 42; y: 100; w: 16; h:16;
|
||||
type: "in";
|
||||
orientation: "bottom";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@pin memDirect inOut {
|
||||
@tooltip "pin za izravno spajanje na RAM"
|
||||
@connection optional("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
||||
@display {
|
||||
pin {
|
||||
x: 100; y: 42; w: 16; h:16;
|
||||
type: "in";
|
||||
orientation: "right";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@component Memorija memory {
|
||||
@@ -183,16 +187,41 @@
|
||||
}
|
||||
*/
|
||||
pin {
|
||||
x: 42; y: -16; w: 16; h: 16;
|
||||
x: 42; y: -16; w: 16; h:16;
|
||||
type: "out";
|
||||
orientation: "top";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@pin memDirect inOut {
|
||||
@tooltip "pin za spajanje na procesor"
|
||||
@connection optional("COMDEL se ne može stvoriti. Memorija nije spojena na sabirnicu")
|
||||
@display {
|
||||
/*
|
||||
pin {
|
||||
x: 100; y: 25;
|
||||
fillColor: blue;
|
||||
lineColor: red;
|
||||
fillColorConnected: white;
|
||||
lineColorConnected: black;
|
||||
side: right;
|
||||
size: 20;
|
||||
}
|
||||
*/
|
||||
pin {
|
||||
x: -16; y: 20; w: 16; h:16;
|
||||
type: "out";
|
||||
orientation: "left";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@component DMA {
|
||||
@instanceName "dma"
|
||||
@tooltip "DMA-kontroler"
|
||||
@count (1,1000)
|
||||
@count (0,1000)
|
||||
@source "dma.cdl"
|
||||
|
||||
@attribute pocetnaAdresa int default 0 {
|
||||
@@ -281,9 +310,11 @@
|
||||
orientation: horizontal;
|
||||
lineColor: black;
|
||||
}*/
|
||||
rect {
|
||||
bus {
|
||||
x:0; y:0;
|
||||
h: 20; w: 100;
|
||||
orientation: "horizontal";
|
||||
resizable: true;
|
||||
}
|
||||
}
|
||||
@wires {
|
||||
@@ -303,21 +334,21 @@
|
||||
}
|
||||
}
|
||||
@bus PIOSabirnica automatic {
|
||||
@count (0, 20)
|
||||
@wires {
|
||||
PIO_DATA<8>,
|
||||
READY,
|
||||
STROBE
|
||||
}
|
||||
}
|
||||
@bus Test singleAutomatic {
|
||||
@tooltip "sabirnica za spajanje FRISC a s memorijama i UI/jedinicama"
|
||||
@count (1,1)
|
||||
|
||||
@bus directRam automatic {
|
||||
@wires {
|
||||
CONNECTOR,
|
||||
INT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@connection (FRISC.glavniPin, glavnaSabirnica) {
|
||||
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, IACK, 1, null}
|
||||
}
|
||||
@@ -346,21 +377,7 @@
|
||||
@wires{PIO_DATA, READY, STROBE}
|
||||
}
|
||||
|
||||
@connection (FRISC.glavniPin, Test, Memorija.glavniPin) {
|
||||
@wires{null, "READY", null}
|
||||
@wires{"PIO_DATA", null, null}
|
||||
|
||||
@attribute dmaPoveznica string default "" {
|
||||
@popup automatic {
|
||||
@title "Spoji DMA kraj"
|
||||
@text "Odaberite poveznicu za dma kraja"
|
||||
}
|
||||
}
|
||||
|
||||
@attribute mmaPoveznica string default "" {
|
||||
@popup automatic {
|
||||
@title "Spoji MMA kraj"
|
||||
@text "Odaberite poveznicu za mma kraja"
|
||||
}
|
||||
}
|
||||
@connection (FRISC.memDirect, directRam, Memorija.memDirect) {
|
||||
@wires{INT}
|
||||
@wires{INT}
|
||||
}
|
||||
@@ -1,33 +1,27 @@
|
||||
@source "frisc_library.csl"
|
||||
|
||||
@schema {
|
||||
@instance proc FRISC {
|
||||
@position (0, 0)
|
||||
@attribute _memory null
|
||||
}
|
||||
@instance proc 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 1023
|
||||
}
|
||||
@instance mem Memorija {
|
||||
@position (0, 250)
|
||||
@attribute sinkroniziran false
|
||||
@attribute brzina 1
|
||||
@attribute kapacitet 1024
|
||||
@attribute size 8
|
||||
@attribute pocetnaAdresa 1024
|
||||
}
|
||||
|
||||
@instance bus glavnaSabirnica {
|
||||
@position (0, 200)
|
||||
@size 100
|
||||
}
|
||||
@instance bus glavnaSabirnica {
|
||||
@position (0, 200)
|
||||
@size 100
|
||||
}
|
||||
|
||||
@instance testBus Test {}
|
||||
|
||||
@connection (proc.glavniPin, bus) {}
|
||||
|
||||
@connection (mem.glavniPin, bus) {}
|
||||
|
||||
@connection (proc.glavniPin, testBus, mem.glavniPin) {
|
||||
@attribute dmaPoveznica "READY"
|
||||
@attribute mmaPoveznica "PIO_DATA"
|
||||
}
|
||||
@connection (proc.glavniPin, bus) {
|
||||
}
|
||||
@connection (mem.glavniPin, bus) {
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
@schema {
|
||||
@instance proc FRISC {
|
||||
@position (0, 0)
|
||||
@attribute _memory mem
|
||||
@attribute _memory null
|
||||
}
|
||||
|
||||
@instance mem Memorija {
|
||||
@@ -12,7 +12,7 @@
|
||||
@attribute brzina 1
|
||||
@attribute kapacitet 1024
|
||||
@attribute size 8
|
||||
@attribute pocetnaAdresa 1023
|
||||
@attribute pocetnaAdresa 1024
|
||||
}
|
||||
|
||||
@instance bus glavnaSabirnica {
|
||||
@@ -20,17 +20,6 @@
|
||||
@size 100
|
||||
}
|
||||
|
||||
@instance testBus Test {
|
||||
@position (0, 200)
|
||||
@size 0
|
||||
}
|
||||
|
||||
@connection (proc.glavniPin, bus) {
|
||||
}
|
||||
@connection (mem.glavniPin, bus) {
|
||||
}
|
||||
@connection (proc.glavniPin, testBus, mem.glavniPin) {
|
||||
@attribute dmaPoveznica "READY"
|
||||
@attribute mmaPoveznica "PIO_DATA"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
@source "/home/bbr/Documents/Personal/FER/schema_editor/examples/simplified FRISC model/frisc_library.csl"
|
||||
|
||||
@schema {
|
||||
@instance memorija Memorija {
|
||||
@position (-12, 68)
|
||||
@attribute sinkroniziran false
|
||||
@attribute brzina 1
|
||||
@attribute kapacitet 65536
|
||||
@attribute size 8
|
||||
@attribute pocetnaAdresa 0
|
||||
}
|
||||
|
||||
@instance procesor FRISC {
|
||||
@position (-206, -76)
|
||||
@attribute _memory memorija
|
||||
}
|
||||
|
||||
@instance directRam directRam {
|
||||
@position (0, 0)
|
||||
@size 0
|
||||
}
|
||||
|
||||
@instance glavnaSabirnica glavnaSabirnica {
|
||||
@position (-222, 130)
|
||||
@size 50
|
||||
}
|
||||
|
||||
@connection (memorija.memDirect, directRam, procesor.memDirect) {
|
||||
}
|
||||
@connection (memorija.glavniPin, glavnaSabirnica) {
|
||||
}
|
||||
@connection (procesor.glavniPin, glavnaSabirnica) {
|
||||
}
|
||||
}
|
||||
+11
-3
@@ -96,7 +96,7 @@ void MainWindow::onLoadLibrary() {
|
||||
|
||||
// on library load we create a new schema
|
||||
schema = new domain::Schema();
|
||||
schemaDisplay->setSchema(schema);
|
||||
schemaDisplay->setSchema(schema, &(*library));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -145,7 +145,7 @@ void MainWindow::onLoadSchema() {
|
||||
|
||||
if(generator.getErrors().empty()) {
|
||||
libraryDisplay->setLibrary(library);
|
||||
schemaDisplay->setSchema(schema);
|
||||
schemaDisplay->setSchema(schema, &(*library));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,6 +193,8 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
||||
return;
|
||||
}
|
||||
|
||||
log->clear();
|
||||
|
||||
this->validationErrors.clear();
|
||||
|
||||
domain::ComdelValidator validator{validators};
|
||||
@@ -207,6 +209,12 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
||||
}
|
||||
auto errors = validator.validateSchema(*schema, context);
|
||||
|
||||
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());
|
||||
|
||||
errors.erase(std::remove_if(
|
||||
errors.begin(), errors.end(), [](const domain::ValidationError& error) { return error.type == domain::Action::WARNING;}),
|
||||
errors.end());
|
||||
@@ -243,7 +251,7 @@ void MainWindow::clear() {
|
||||
library = std::nullopt;
|
||||
|
||||
libraryDisplay->setLibrary(library);
|
||||
schemaDisplay->setSchema(schema);
|
||||
schemaDisplay->setSchema(schema, nullptr);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
||||
Reference in new issue
Block a user