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
|
comdel/parser/comdellexer.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.ui
|
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)
|
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
@@ -4,9 +4,8 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QLine>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
@@ -36,8 +35,45 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|||||||
menu.exec(event->screenPos());
|
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;
|
QMenu menu;
|
||||||
menu.addAction("Izmjeni ime", [this](){
|
menu.addAction("Izmjeni ime", [this](){
|
||||||
auto dialog = new NameDialog(this->busInstance.get());
|
auto dialog = new NameDialog(this->busInstance.get());
|
||||||
@@ -46,4 +82,79 @@ void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|||||||
menu.exec(event->screenPos());
|
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
|
} // namespace display
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
#include <comdel/domain/wireinstance.h>
|
#include <comdel/domain/wireinstance.h>
|
||||||
|
|
||||||
#include <QGraphicsItemGroup>
|
#include <QGraphicsItemGroup>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include "comdel/domain/connectioninstance.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
@@ -12,9 +15,24 @@ class Pin: public QGraphicsItemGroup
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
domain::Pin pin;
|
domain::Pin pin;
|
||||||
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Pin(domain::Pin pin): pin(pin) {
|
Pin(domain::Pin pin, std::shared_ptr<domain::ComponentInstance> componentInstance): pin(pin), componentInstance(componentInstance) {
|
||||||
pin.getDisplay().render(this);
|
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;
|
std::shared_ptr<domain::ComponentInstance> instance;
|
||||||
public:
|
public:
|
||||||
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
||||||
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
|
|
||||||
instance->component.getDisplay().render(this);
|
instance->component.getDisplay().render(this);
|
||||||
}
|
}
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bus: public QGraphicsItemGroup
|
class Bus: public QGraphicsItemGroup
|
||||||
@@ -34,8 +55,9 @@ class Bus: public QGraphicsItemGroup
|
|||||||
std::shared_ptr<domain::BusInstance> busInstance;
|
std::shared_ptr<domain::BusInstance> busInstance;
|
||||||
public:
|
public:
|
||||||
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
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;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,38 +65,111 @@ class ComponentGroup: public QGraphicsItemGroup
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
||||||
|
std::vector<display::Pin*> pins;
|
||||||
|
|
||||||
public:
|
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) {
|
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
|
||||||
setFlag(ItemIsMovable, true);
|
setFlag(ItemIsMovable, true);
|
||||||
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
|
|
||||||
setHandlesChildEvents(false);
|
setHandlesChildEvents(false);
|
||||||
|
|
||||||
addToGroup(new display::Component(instance));
|
addToGroup(new display::Component(instance));
|
||||||
|
|
||||||
for(auto &pin: instance->component.getPins()) {
|
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);
|
setPos(instance->position.first, instance->position.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BusGroup: public QGraphicsItemGroup
|
class BusGroup: public QGraphicsItemGroup
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<domain::BusInstance> busInstance;
|
std::shared_ptr<domain::BusInstance> busInstance;
|
||||||
|
display::Bus* bus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance);
|
||||||
setFlag(ItemIsMovable, true);
|
|
||||||
setHandlesChildEvents(false);
|
|
||||||
|
|
||||||
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
|
} // namespace display
|
||||||
|
|
||||||
#endif // DISPLAY_COMPONENT_H
|
#endif // DISPLAY_COMPONENT_H
|
||||||
@@ -11,8 +11,8 @@ Library::Library()
|
|||||||
auto layout = new QVBoxLayout();
|
auto layout = new QVBoxLayout();
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
|
|
||||||
componentList = new QListWidget();
|
componentList = new LibraryList(this);
|
||||||
busList = new QListWidget();
|
busList = new LibraryList(this);
|
||||||
|
|
||||||
layout->setMargin(4);
|
layout->setMargin(4);
|
||||||
layout->addWidget(new QLabel("Components:"));
|
layout->addWidget(new QLabel("Components:"));
|
||||||
@@ -34,14 +34,14 @@ void Library::setLibrary(std::optional<domain::Library> library) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(auto& component: library->getComponents()) {
|
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()));
|
item->setToolTip(QString::fromStdString(component.getTooltip()));
|
||||||
componentList->addItem(item);
|
componentList->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& bus: library->getBuses()) {
|
for(auto& bus: library->getBuses()) {
|
||||||
if(bus.getType() == domain::Bus::REGULAR) {
|
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()));
|
item->setToolTip(QString::fromStdString(bus.getTooltip()));
|
||||||
busList->addItem(item);
|
busList->addItem(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <comdel/domain/library.h>
|
#include <comdel/domain/library.h>
|
||||||
|
#include "library_list.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::optional<domain::Library> library;
|
std::optional<domain::Library> library;
|
||||||
|
|
||||||
QListWidget *componentList;
|
LibraryList *componentList;
|
||||||
QListWidget *busList;
|
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 "component_display.h"
|
||||||
#include "schema_display.h"
|
#include "schema_display.h"
|
||||||
|
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
Schema::Schema()
|
Schema::Schema()
|
||||||
{
|
{
|
||||||
|
this->selectedBrush.setColor(QColor::fromRgb(20,20,125));
|
||||||
|
this->selectedPen.setColor(QColor::fromRgb(20, 20, 125));
|
||||||
|
|
||||||
this->setScene(&scene);
|
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();
|
scene.clear();
|
||||||
|
busConnections.clear();
|
||||||
this->schema = _schema;
|
this->schema = _schema;
|
||||||
|
this->library = _library;
|
||||||
if(schema != nullptr) {
|
if(schema != nullptr) {
|
||||||
for(auto &instance: schema->componentInstances) {
|
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) {
|
for(auto &instance: schema->busInstances) {
|
||||||
if(instance->bus.getDisplay().has_value()) {
|
if(instance->bus.getDisplayBus().has_value()) {
|
||||||
scene.addItem(new display::BusGroup(instance));
|
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
|
} // namespace display
|
||||||
@@ -4,22 +4,72 @@
|
|||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
|
||||||
#include <comdel/domain/schema.h>
|
#include <comdel/domain/schema.h>
|
||||||
|
#include <comdel/domain/library.h>
|
||||||
|
#include "component_display.h"
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
|
class BusConnection;
|
||||||
|
|
||||||
class Schema: public QGraphicsView
|
class Schema: public QGraphicsView
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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();
|
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:
|
private:
|
||||||
QGraphicsScene scene;
|
QGraphicsScene scene;
|
||||||
|
|
||||||
domain::Schema* schema;
|
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
|
} // namespace display
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ Wire::WireType Wire::getType() {
|
|||||||
return type;
|
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)
|
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), display(display)
|
: name(name), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Bus::getName() {
|
std::string Bus::getName() {
|
||||||
@@ -42,12 +42,11 @@ Bus::BusType Bus::getType() {
|
|||||||
std::pair<int, int> Bus::getCount() {
|
std::pair<int, int> Bus::getCount() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
std::optional<Display> Bus::getDisplay() {
|
|
||||||
return display;
|
|
||||||
}
|
|
||||||
std::vector<Wire> Bus::getWires() {
|
std::vector<Wire> Bus::getWires() {
|
||||||
return wires;
|
return wires;
|
||||||
}
|
}
|
||||||
|
std::optional<ui::Bus> Bus::getDisplayBus() {
|
||||||
|
return displayBus;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
+3
-3
@@ -55,18 +55,18 @@ private:
|
|||||||
BusType type;
|
BusType type;
|
||||||
|
|
||||||
std::pair<int, int> count;
|
std::pair<int, int> count;
|
||||||
std::optional<Display> display;
|
std::optional<ui::Bus> displayBus;
|
||||||
std::vector<Wire> wires;
|
std::vector<Wire> wires;
|
||||||
|
|
||||||
public:
|
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 getName();
|
||||||
std::string getTooltip();
|
std::string getTooltip();
|
||||||
BusType getType();
|
BusType getType();
|
||||||
std::pair<int, int> getCount();
|
std::pair<int, int> getCount();
|
||||||
std::vector<Wire> getWires();
|
std::vector<Wire> getWires();
|
||||||
std::optional<Display> getDisplay();
|
std::optional<ui::Bus> getDisplayBus();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void generateBus(BusInstance *bus, ostream &buffer);
|
void generateBus(BusInstance *bus, ostream &buffer);
|
||||||
|
void generateConnection(ConnectionInstance *connection, ostream &buffer);
|
||||||
|
|
||||||
void generateDisplay(Schema *schema, ostream &buffer) {
|
void generateDisplay(Schema *schema, ostream &buffer) {
|
||||||
buffer << "\n\tdisplay {\n";
|
buffer << "\n\tdisplay {\n";
|
||||||
@@ -106,15 +107,26 @@ void generateDisplay(Schema *schema, ostream &buffer) {
|
|||||||
generateBus(bus.get(), buffer);
|
generateBus(bus.get(), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer << "\n";
|
||||||
|
|
||||||
|
for(auto &connection: schema->connections) {
|
||||||
|
generateConnection(connection.get(), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
buffer << "\t}\n";
|
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) {
|
void generateBus(BusInstance *bus, ostream &buffer) {
|
||||||
buffer << "\n";
|
buffer << "\n";
|
||||||
buffer << "\t\t// " << bus->name << " bus\n\n";
|
buffer << "\t\t// " << bus->name << " bus\n\n";
|
||||||
|
|
||||||
if(bus->bus.getDisplay().has_value()) {
|
if(bus->bus.getDisplayBus().has_value()) {
|
||||||
bus->bus.getDisplay()->comdel(buffer, bus->position.first, bus->position.second, bus->size);
|
bus->bus.getDisplayBus()->comdel(buffer, bus->position.first, bus->position.second, bus->size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "comdelvalidator.h"
|
#include "comdelvalidator.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
@@ -15,6 +16,78 @@ std::vector<ValidationError> ComdelValidator::validateSchema(Schema &schema, Val
|
|||||||
return errors;
|
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> ComdelValidator::validateComponent(ComponentInstance* instance, ValidationContext context) {
|
||||||
std::vector<ValidationError> errors;
|
std::vector<ValidationError> errors;
|
||||||
|
|
||||||
@@ -89,4 +162,26 @@ string ComdelValidator::replacePlaceholder(string source, string key, Value valu
|
|||||||
return source;
|
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 "instance.h"
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
@@ -29,6 +30,9 @@ public:
|
|||||||
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
|
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
|
||||||
std::optional<ValidationError> validateRule(Rule rule, 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) {
|
ComdelValidator(std::vector<FunctionValidator*> validators) {
|
||||||
for(auto* validator: validators) {
|
for(auto* validator: validators) {
|
||||||
validator->clear();
|
validator->clear();
|
||||||
@@ -42,6 +46,8 @@ private:
|
|||||||
std::string populateMessage(string message, ValidationContext context);
|
std::string populateMessage(string message, ValidationContext context);
|
||||||
|
|
||||||
string replacePlaceholder(string message, const string name, Value value);
|
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);
|
(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
|
} // namespace domain
|
||||||
@@ -21,6 +21,17 @@ struct ConnectionComponent
|
|||||||
{
|
{
|
||||||
return !operator==(rhs);
|
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
|
class Connection
|
||||||
@@ -40,6 +51,7 @@ public:
|
|||||||
bool isConnecting(ConnectionComponent first);
|
bool isConnecting(ConnectionComponent first);
|
||||||
bool isConnecting(ConnectionComponent first, std::string bus);
|
bool isConnecting(ConnectionComponent first, std::string bus);
|
||||||
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
||||||
|
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
|
||||||
|
|
||||||
|
|
||||||
ConnectionComponent getComponent();
|
ConnectionComponent getComponent();
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "wireinstance.h"
|
#include "wireinstance.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
class ConnectionInstance
|
class ConnectionInstance
|
||||||
@@ -19,6 +17,9 @@ public:
|
|||||||
|
|
||||||
std::vector<InstanceAttribute> attributes;
|
std::vector<InstanceAttribute> attributes;
|
||||||
|
|
||||||
|
std::pair<int, int> start;
|
||||||
|
std::pair<int, int> end;
|
||||||
|
|
||||||
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection);
|
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection);
|
||||||
|
|
||||||
InstanceAttribute getAttribute(string attribute);
|
InstanceAttribute getAttribute(string attribute);
|
||||||
|
|||||||
+139
-12
@@ -20,7 +20,7 @@ public:
|
|||||||
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
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\trectangle {\n";
|
||||||
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
buffer << "\t\t\tx: " << (this->x + x) << "; y: " << (this->y + y) << ";\n";
|
||||||
buffer << "\t\t\tw: " << w << "; h: " << h << ";\n";
|
buffer << "\t\t\tw: " << w << "; h: " << h << ";\n";
|
||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
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\tline {\n";
|
||||||
buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n";
|
buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n";
|
||||||
buffer << "\t\t\tx2: " << (x2 + x) << "; y2: " << (y2 + 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
|
LEFT, RIGHT, TOP, BOTTOM
|
||||||
};
|
};
|
||||||
|
enum BusOrientation {
|
||||||
|
VERTICAL, HORIZONTAL
|
||||||
|
};
|
||||||
|
|
||||||
enum PinType {
|
enum PinType {
|
||||||
IN, OUT, IN_OUT
|
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 {
|
class Pin {
|
||||||
public:
|
public:
|
||||||
Orientation orientation;
|
PinOrientation orientation;
|
||||||
PinType pinType;
|
PinType pinType;
|
||||||
int x, y, w, h;
|
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) {
|
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 {
|
class Item {
|
||||||
public:
|
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(rect) rect->render(group);
|
||||||
if(line) line->render(group);
|
if(line) line->render(group);
|
||||||
if(pin) pin->render(group);
|
if(pin) pin->render(group);
|
||||||
|
if(bus) bus->render(group, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Rect> rect = std::nullopt;
|
std::optional<Rect> rect = std::nullopt;
|
||||||
std::optional<Line> line = std::nullopt;
|
std::optional<Line> line = std::nullopt;
|
||||||
std::optional<Pin> pin = 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) {
|
void comdel(std::ostream &buffer, int x, int y, int size = 0) {
|
||||||
if(rect) rect->comdel(buffer, x, y, size);
|
if(rect) rect->comdel(buffer, x, y);
|
||||||
if(line) line->comdel(buffer, x, y, size);
|
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) {
|
for(auto &item: items) {
|
||||||
item.comdel(buffer, x, y, size);
|
item.comdel(buffer, x, y, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ui::Item>& getItems() {return items;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ui::Item> items;
|
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)
|
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
|
||||||
: name(name), position(position), bus(bus), size(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)
|
: name(name), attributes(std::move(attributes)), position(position), component(component)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ public:
|
|||||||
Bus bus;
|
Bus bus;
|
||||||
int size;
|
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;
|
virtual ~BusInstance() = default;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,4 +113,18 @@ std::string Library::getMessage(std::string key) {
|
|||||||
return messages[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
|
} // namespace domain
|
||||||
@@ -60,6 +60,10 @@ public:
|
|||||||
|
|
||||||
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||||
std::optional<Connection> getConnection(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
|
} // 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)
|
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), display(display), wires(wires)
|
: name(name), type(type), tooltip(tooltip), connection(connection), displayPin(pin), wires(wires)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string &Pin::getName() {
|
std::string &Pin::getName() {
|
||||||
@@ -27,8 +27,8 @@ Pin::PinType Pin::getType() {
|
|||||||
std::string Pin::getTooltip() {
|
std::string Pin::getTooltip() {
|
||||||
return tooltip;
|
return tooltip;
|
||||||
}
|
}
|
||||||
Display &Pin::getDisplay() {
|
ui::Pin &Pin::getDisplayPin() {
|
||||||
return display;
|
return displayPin;
|
||||||
}
|
}
|
||||||
PinConnection &Pin::getConnection() {
|
PinConnection &Pin::getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
|
|||||||
+3
-3
@@ -43,17 +43,17 @@ private:
|
|||||||
PinType type;
|
PinType type;
|
||||||
std::string tooltip;
|
std::string tooltip;
|
||||||
PinConnection connection;
|
PinConnection connection;
|
||||||
Display display;
|
domain::ui::Pin displayPin;
|
||||||
|
|
||||||
std::optional<std::vector<Value>> wires;
|
std::optional<std::vector<Value>> wires;
|
||||||
|
|
||||||
public:
|
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();
|
std::string &getName();
|
||||||
PinType getType();
|
PinType getType();
|
||||||
std::string getTooltip();
|
std::string getTooltip();
|
||||||
Display &getDisplay();
|
ui::Pin &getDisplayPin();
|
||||||
PinConnection &getConnection();
|
PinConnection &getConnection();
|
||||||
std::optional<std::vector<Value>> &getWires();
|
std::optional<std::vector<Value>> &getWires();
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-14
@@ -9,8 +9,7 @@
|
|||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
class Schema
|
class Schema {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Schema();
|
Schema();
|
||||||
|
|
||||||
@@ -19,16 +18,8 @@ public:
|
|||||||
|
|
||||||
std::vector<shared_ptr<ConnectionInstance>> connections;
|
std::vector<shared_ptr<ConnectionInstance>> connections;
|
||||||
|
|
||||||
BusInstance *getBusInstance(std::string& name) {
|
BusInstance *getBusInstance(std::string &name) {
|
||||||
for(auto& instance: busInstances) {
|
for (auto &instance: busInstances) {
|
||||||
if (instance->name == name) {
|
|
||||||
return instance.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
ComponentInstance *getComponentInstance(std::string& name) {
|
|
||||||
for(auto& instance: componentInstances) {
|
|
||||||
if (instance->name == name) {
|
if (instance->name == name) {
|
||||||
return instance.get();
|
return instance.get();
|
||||||
}
|
}
|
||||||
@@ -36,8 +27,18 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasConnection(string& component, string& pin);
|
ComponentInstance *getComponentInstance(std::string &name) {
|
||||||
ConnectionInstance* getConnection(string& component, string& pin);
|
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
|
} // namespace domain
|
||||||
|
|||||||
@@ -210,12 +210,17 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<Display> display;
|
optional<ui::Bus> displayBus;
|
||||||
if(type == Bus::REGULAR) {
|
if(type == Bus::REGULAR) {
|
||||||
display = loadDisplay(*node.display);
|
auto display = loadDisplay(*node.display);
|
||||||
if(!display) {
|
if(!display) {
|
||||||
return nullopt;
|
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) {
|
if(node.wires.size() == 0) {
|
||||||
@@ -235,7 +240,7 @@ std::optional<Bus> SchemaCreator::loadBus(BusNode node)
|
|||||||
return nullopt;
|
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) {
|
if(!display) {
|
||||||
return nullopt;
|
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) {
|
if(!node.connection) {
|
||||||
errors.emplace_back(node.span, "missing @connection");
|
errors.emplace_back(node.span, "missing @connection");
|
||||||
@@ -565,16 +576,7 @@ optional<Pin> SchemaCreator::loadPin(PinNode node)
|
|||||||
wiresOpt = wires;
|
wiresOpt = wires;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pin(name, type, tooltip, connection, *display, wiresOpt);
|
return Pin(name, type, tooltip, connection, displayPin, 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
||||||
@@ -584,26 +586,71 @@ std::optional<Display> SchemaCreator::loadDisplay(DisplayNode node)
|
|||||||
ui::Item displayItem;
|
ui::Item displayItem;
|
||||||
std::string type = item.type.value;
|
std::string type = item.type.value;
|
||||||
if(type == "rect") {
|
if(type == "rect") {
|
||||||
int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = getIntProperty(item, "x");
|
x = item.asInt(&errors, "x");
|
||||||
y = getIntProperty(item, "y");
|
y = item.asInt(&errors, "y");
|
||||||
w = getIntProperty(item, "w");
|
w = item.asInt(&errors, "w");
|
||||||
h = getIntProperty(item, "h");
|
h = item.asInt(&errors, "h");
|
||||||
displayItem.rect = ui::Rect(x, y, w, h);
|
displayItem.rect = ui::Rect(x, y, w, h);
|
||||||
} else if(type == "line") {
|
} else if(type == "line") {
|
||||||
int x1, y1, x2, y2;
|
long long int x1, y1, x2, y2;
|
||||||
x1 = getIntProperty(item, "x1");
|
x1 = item.asInt(&errors, "x1");
|
||||||
y1 = getIntProperty(item, "y1");
|
y1 = item.asInt(&errors, "y1");
|
||||||
x2 = getIntProperty(item, "x2");
|
x2 = item.asInt(&errors, "x2");
|
||||||
y2 = getIntProperty(item, "y2");
|
y2 = item.asInt(&errors, "y2");
|
||||||
displayItem.line = ui::Line(x1, y1, x2, y2);
|
displayItem.line = ui::Line(x1, y1, x2, y2);
|
||||||
} else if(type == "pin") {
|
} else if(type == "pin") {
|
||||||
int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = getIntProperty(item, "x");
|
x = item.asInt(&errors, "x");
|
||||||
y = getIntProperty(item, "y");
|
y = item.asInt(&errors, "y");
|
||||||
w = getIntProperty(item, "w");
|
w = item.asInt(&errors, "w");
|
||||||
h = getIntProperty(item, "h");
|
h = item.asInt(&errors, "h");
|
||||||
displayItem.pin = ui::Pin(x, y, w, 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 {
|
} else {
|
||||||
errors.emplace_back(item.type.span, "unsupported display type");
|
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() {
|
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() {
|
std::optional<Popup> SchemaCreator::createMemoryPopup() {
|
||||||
|
|||||||
@@ -162,10 +162,10 @@ std::string Value::stringify() {
|
|||||||
case ATTRIBUTE_REFERENCE:
|
case ATTRIBUTE_REFERENCE:
|
||||||
return reference;
|
return reference;
|
||||||
case MEMORY_REFERENCE:
|
case MEMORY_REFERENCE:
|
||||||
if(memoryReference->empty()) {
|
if(memoryReference.has_value()) {
|
||||||
return "null";
|
|
||||||
} else {
|
|
||||||
return memoryReference.value();
|
return memoryReference.value();
|
||||||
|
} else {
|
||||||
|
return "null";
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
|
|||||||
@@ -29,22 +29,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long intValue;
|
long long intValue = 0;
|
||||||
std::string stringValue;
|
std::string stringValue;
|
||||||
bool boolValue;
|
bool boolValue = false;
|
||||||
std::optional<AddressSpace> addressSpace;
|
std::optional<AddressSpace> addressSpace = std::nullopt;
|
||||||
std::string reference;
|
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:
|
public:
|
||||||
|
|
||||||
Value() {
|
Value() {}
|
||||||
this->type = UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool equals(Value value) {
|
bool equals(Value value) {
|
||||||
if(value.getType() == type) {
|
if(value.getType() == type) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define AST_NODE_H
|
#define AST_NODE_H
|
||||||
|
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include "sourceerror.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -173,6 +174,52 @@ struct DisplayItemNode: public AstNode
|
|||||||
{
|
{
|
||||||
IdentifierNode type;
|
IdentifierNode type;
|
||||||
std::vector<PropertyNode> values;
|
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
|
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,22 +51,26 @@
|
|||||||
x: 0; y:0; w:100; h:100;
|
x: 0; y:0; w:100; h:100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@pin glavniPin inOut {
|
@pin glavniPin in {
|
||||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||||
@connection required("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
@connection required("COMDEL se ne može stvoriti. FRISC nije spojen na sabirnicu")
|
||||||
@display {
|
@display {
|
||||||
/*
|
|
||||||
pin {
|
|
||||||
x: 100; y: 50;
|
|
||||||
fillColor: white;
|
|
||||||
lineColor: red;
|
|
||||||
fillColorConnected: white;
|
|
||||||
lineColorConnected: black;
|
|
||||||
side: left;
|
|
||||||
size: 20;
|
|
||||||
}*/
|
|
||||||
pin {
|
pin {
|
||||||
x: 42; y: 100; w: 16; h:16;
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +187,32 @@
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
pin {
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +221,7 @@
|
|||||||
@component DMA {
|
@component DMA {
|
||||||
@instanceName "dma"
|
@instanceName "dma"
|
||||||
@tooltip "DMA-kontroler"
|
@tooltip "DMA-kontroler"
|
||||||
@count (1,1000)
|
@count (0,1000)
|
||||||
@source "dma.cdl"
|
@source "dma.cdl"
|
||||||
|
|
||||||
@attribute pocetnaAdresa int default 0 {
|
@attribute pocetnaAdresa int default 0 {
|
||||||
@@ -281,9 +310,11 @@
|
|||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
lineColor: black;
|
lineColor: black;
|
||||||
}*/
|
}*/
|
||||||
rect {
|
bus {
|
||||||
x:0; y:0;
|
x:0; y:0;
|
||||||
h: 20; w: 100;
|
h: 20; w: 100;
|
||||||
|
orientation: "horizontal";
|
||||||
|
resizable: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@wires {
|
@wires {
|
||||||
@@ -303,21 +334,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@bus PIOSabirnica automatic {
|
@bus PIOSabirnica automatic {
|
||||||
|
@count (0, 20)
|
||||||
@wires {
|
@wires {
|
||||||
PIO_DATA<8>,
|
PIO_DATA<8>,
|
||||||
READY,
|
READY,
|
||||||
STROBE
|
STROBE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@bus Test singleAutomatic {
|
|
||||||
@tooltip "sabirnica za spajanje FRISC a s memorijama i UI/jedinicama"
|
|
||||||
@count (1,1)
|
|
||||||
|
|
||||||
|
@bus directRam automatic {
|
||||||
@wires {
|
@wires {
|
||||||
CONNECTOR,
|
INT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@connection (FRISC.glavniPin, glavnaSabirnica) {
|
@connection (FRISC.glavniPin, glavnaSabirnica) {
|
||||||
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, IACK, 1, null}
|
@wires{ADR, DATA, READ, WRITE, SIZE, WAIT, INT0, INT1, INT2, INT3, IACK, 1, null}
|
||||||
}
|
}
|
||||||
@@ -346,21 +377,7 @@
|
|||||||
@wires{PIO_DATA, READY, STROBE}
|
@wires{PIO_DATA, READY, STROBE}
|
||||||
}
|
}
|
||||||
|
|
||||||
@connection (FRISC.glavniPin, Test, Memorija.glavniPin) {
|
@connection (FRISC.memDirect, directRam, Memorija.memDirect) {
|
||||||
@wires{null, "READY", null}
|
@wires{INT}
|
||||||
@wires{"PIO_DATA", null, null}
|
@wires{INT}
|
||||||
|
|
||||||
@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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
@attribute brzina 1
|
@attribute brzina 1
|
||||||
@attribute kapacitet 1024
|
@attribute kapacitet 1024
|
||||||
@attribute size 8
|
@attribute size 8
|
||||||
@attribute pocetnaAdresa 1023
|
@attribute pocetnaAdresa 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance bus glavnaSabirnica {
|
@instance bus glavnaSabirnica {
|
||||||
@@ -20,14 +20,8 @@
|
|||||||
@size 100
|
@size 100
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance testBus Test {}
|
@connection (proc.glavniPin, bus) {
|
||||||
|
}
|
||||||
@connection (proc.glavniPin, bus) {}
|
@connection (mem.glavniPin, bus) {
|
||||||
|
|
||||||
@connection (mem.glavniPin, bus) {}
|
|
||||||
|
|
||||||
@connection (proc.glavniPin, testBus, mem.glavniPin) {
|
|
||||||
@attribute dmaPoveznica "READY"
|
|
||||||
@attribute mmaPoveznica "PIO_DATA"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
@schema {
|
@schema {
|
||||||
@instance proc FRISC {
|
@instance proc FRISC {
|
||||||
@position (0, 0)
|
@position (0, 0)
|
||||||
@attribute _memory mem
|
@attribute _memory null
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance mem Memorija {
|
@instance mem Memorija {
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
@attribute brzina 1
|
@attribute brzina 1
|
||||||
@attribute kapacitet 1024
|
@attribute kapacitet 1024
|
||||||
@attribute size 8
|
@attribute size 8
|
||||||
@attribute pocetnaAdresa 1023
|
@attribute pocetnaAdresa 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance bus glavnaSabirnica {
|
@instance bus glavnaSabirnica {
|
||||||
@@ -20,17 +20,6 @@
|
|||||||
@size 100
|
@size 100
|
||||||
}
|
}
|
||||||
|
|
||||||
@instance testBus Test {
|
|
||||||
@position (0, 200)
|
|
||||||
@size 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@connection (proc.glavniPin, bus) {
|
|
||||||
}
|
|
||||||
@connection (mem.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
|
// on library load we create a new schema
|
||||||
schema = new domain::Schema();
|
schema = new domain::Schema();
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, &(*library));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -145,7 +145,7 @@ void MainWindow::onLoadSchema() {
|
|||||||
|
|
||||||
if(generator.getErrors().empty()) {
|
if(generator.getErrors().empty()) {
|
||||||
libraryDisplay->setLibrary(library);
|
libraryDisplay->setLibrary(library);
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, &(*library));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +193,8 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log->clear();
|
||||||
|
|
||||||
this->validationErrors.clear();
|
this->validationErrors.clear();
|
||||||
|
|
||||||
domain::ComdelValidator validator{validators};
|
domain::ComdelValidator validator{validators};
|
||||||
@@ -207,6 +209,12 @@ void MainWindow::onValidateSchema(bool /*toggled*/) {
|
|||||||
}
|
}
|
||||||
auto errors = validator.validateSchema(*schema, context);
|
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.erase(std::remove_if(
|
||||||
errors.begin(), errors.end(), [](const domain::ValidationError& error) { return error.type == domain::Action::WARNING;}),
|
errors.begin(), errors.end(), [](const domain::ValidationError& error) { return error.type == domain::Action::WARNING;}),
|
||||||
errors.end());
|
errors.end());
|
||||||
@@ -243,7 +251,7 @@ void MainWindow::clear() {
|
|||||||
library = std::nullopt;
|
library = std::nullopt;
|
||||||
|
|
||||||
libraryDisplay->setLibrary(library);
|
libraryDisplay->setLibrary(library);
|
||||||
schemaDisplay->setSchema(schema);
|
schemaDisplay->setSchema(schema, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|||||||
Reference in new issue
Block a user