Compare commits
No commits in common. "ae2a3c64ef800b53f6492caf89166a8105963859" and "e6bbaabde4a1403dae5b1de8f866a21e613f75b6" have entirely different histories.
ae2a3c64ef
...
e6bbaabde4
|
@ -37,5 +37,5 @@ add_executable(SchemeEditor
|
||||||
comdel/parser/comdel_lexer.cpp
|
comdel/parser/comdel_lexer.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
comdel/domain/comdel_validator.cpp comdel/domain/comdel_validator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h comdel/display/library_list.cpp comdel/display/library_list.h application.cpp application.h comdel/display/single_automatic_dialog.cpp comdel/display/single_automatic_dialog.h comdel/parser/color.cpp comdel/parser/color.h)
|
comdel/domain/comdel_validator.cpp comdel/domain/comdel_validator.h comdel/display/attribute_dialog.cpp comdel/display/attribute_dialog.h comdel/display/name_dialog.cpp comdel/display/name_dialog.h comdel/domain/comdel_generator.cpp comdel/domain/comdel_generator.h comdel/display/library_list.cpp comdel/display/library_list.h application.cpp application.h comdel/display/single_automatic_dialog.cpp comdel/display/single_automatic_dialog.h)
|
||||||
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
target_link_libraries(SchemeEditor Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace display {
|
||||||
Component::Component(const std::shared_ptr<domain::ComponentInstance> &instance): instance(instance) {
|
Component::Component(const std::shared_ptr<domain::ComponentInstance> &instance): instance(instance) {
|
||||||
setFlag(ItemSendsGeometryChanges, true);
|
setFlag(ItemSendsGeometryChanges, true);
|
||||||
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName()));
|
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName()));
|
||||||
instance->component.getDisplay().render(this, domain::ui::DisplayContext(instance.get()));
|
instance->component.getDisplay().render(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
||||||
|
|
|
@ -20,13 +20,13 @@ display::NameDialog::NameDialog(std::string currentName, std::set<std::string> &
|
||||||
|
|
||||||
auto buttonLayout = new QHBoxLayout(this);
|
auto buttonLayout = new QHBoxLayout(this);
|
||||||
|
|
||||||
button = new QPushButton("Ažuriraj");
|
auto okButton = new QPushButton("Ažuriraj");
|
||||||
auto cancelButton = new QPushButton("Odustani", this);
|
auto cancelButton = new QPushButton("Odustani", this);
|
||||||
|
|
||||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
connect(okButton, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||||
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
|
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
|
||||||
|
|
||||||
buttonLayout->addWidget(button);
|
buttonLayout->addWidget(okButton);
|
||||||
buttonLayout->addWidget(cancelButton);
|
buttonLayout->addWidget(cancelButton);
|
||||||
|
|
||||||
layout->addLayout(buttonLayout);
|
layout->addLayout(buttonLayout);
|
||||||
|
|
|
@ -175,14 +175,13 @@ namespace display {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto pinInstance = domain::ConnectionComponent{connection.componentInstance.value()->name, connection.pin.value().getName()};
|
auto pinInstance = domain::ConnectionComponent{connection.componentInstance.value()->name, connection.pin.value().getName()};
|
||||||
auto pin = pins[pinInstance]->getPin().getDisplayPin();
|
auto rect = pins[pinInstance]->boundingRect();
|
||||||
auto position = pins[pinInstance]->getComponentInstance()->position;
|
rect.setX(pins[pinInstance]->scenePos().x());
|
||||||
|
rect.setY(pins[pinInstance]->scenePos().y());
|
||||||
auto rect = QRectF(position.first + pin.x, position.second + pin.y, pin.w, pin.h);
|
|
||||||
|
|
||||||
if (rect.contains(endPoint)) {
|
if (rect.contains(endPoint)) {
|
||||||
auto name = components[pinInstance.component]->getComponentInstance()->component.getName();
|
auto name = components[pinInstance.component]->getComponentInstance()->component.getName();
|
||||||
auto con = library->getConnection({instance->component.getName(), connection.pin.value().getName()},
|
auto con = library->getConnection({instance->component.getName(), pin.getName()},
|
||||||
{name, pinInstance.pin});
|
{name, pinInstance.pin});
|
||||||
if (con.has_value()) {
|
if (con.has_value()) {
|
||||||
auto busInstance = Application::instance()->addBus(library->getBus(con->getBus()), 0, 0);
|
auto busInstance = Application::instance()->addBus(library->getBus(con->getBus()), 0, 0);
|
||||||
|
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QFont>
|
|
||||||
|
|
||||||
#include "comdel/domain/instance.h"
|
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
|
QBrush busBrush(QColor::fromRgb(200, 200, 200));
|
||||||
|
QPen busPen(QColor::fromRgb(200, 200, 200));
|
||||||
|
|
||||||
Display::Display(std::vector<ui::Item> items) : items(items) {}
|
Display::Display(std::vector<ui::Item> items) : items(items) {}
|
||||||
|
|
||||||
void Display::render(QGraphicsItemGroup *group, ui::DisplayContext context) {
|
void Display::render(QGraphicsItemGroup *group) {
|
||||||
for (auto &item: items) {
|
for (auto &item: items) {
|
||||||
item.render(group, context);
|
item.render(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,26 +22,8 @@ namespace domain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Text::render(QGraphicsItemGroup *group, ui::DisplayContext context) {
|
|
||||||
auto formattedText = context.populateMessage(text);
|
|
||||||
|
|
||||||
auto content = new QGraphicsTextItem(QString::fromStdString(formattedText));
|
|
||||||
content->setDefaultTextColor(color);
|
|
||||||
content->setPos(x, y);
|
|
||||||
content->setFont(QFont("arial", 8));
|
|
||||||
group->addToGroup(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui::Text::comdel(std::ostream &buffer, int x, int y) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ui::Rect::render(QGraphicsItemGroup *group) {
|
void ui::Rect::render(QGraphicsItemGroup *group) {
|
||||||
auto rect = new QGraphicsRectItem(x, y, w, h);
|
group->addToGroup(new QGraphicsRectItem(x, y, w, h));
|
||||||
rect->setPen(QPen(config.lineColor));
|
|
||||||
rect->setBrush(QBrush(config.fillColor));
|
|
||||||
group->addToGroup(rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Rect::comdel(std::ostream &buffer, int x, int y) {
|
void ui::Rect::comdel(std::ostream &buffer, int x, int y) {
|
||||||
|
@ -52,9 +34,7 @@ namespace domain {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Line::render(QGraphicsItemGroup *group) {
|
void ui::Line::render(QGraphicsItemGroup *group) {
|
||||||
auto line = new QGraphicsLineItem(x1, y1, x2, y2);
|
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
||||||
line->setPen(QPen(config.lineColor));
|
|
||||||
group->addToGroup(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Line::comdel(std::ostream &buffer, int x, int y) {
|
void ui::Line::comdel(std::ostream &buffer, int x, int y) {
|
||||||
|
@ -72,8 +52,8 @@ namespace domain {
|
||||||
_h = size;
|
_h = size;
|
||||||
}
|
}
|
||||||
auto rect = new QGraphicsRectItem(x, y, _w, _h);
|
auto rect = new QGraphicsRectItem(x, y, _w, _h);
|
||||||
rect->setBrush(QBrush(config.fillColor));
|
rect->setBrush(busBrush);
|
||||||
rect->setPen(QPen(config.lineColor));
|
rect->setPen(busPen);
|
||||||
group->addToGroup(rect);
|
group->addToGroup(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +97,7 @@ namespace domain {
|
||||||
<< QPoint(x + w / 2, y + h / 2) << QPoint(x + w, y);
|
<< QPoint(x + w / 2, y + h / 2) << QPoint(x + w, y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto item = new QGraphicsPolygonItem(polygon);
|
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||||
item->setFillRule(Qt::OddEvenFill);
|
|
||||||
item->setBrush(QBrush(config.fillColor));
|
|
||||||
item->setPen(QPen(config.lineColor));
|
|
||||||
group->addToGroup(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Pin::renderOut(QGraphicsItemGroup *group) {
|
void ui::Pin::renderOut(QGraphicsItemGroup *group) {
|
||||||
|
@ -145,18 +121,11 @@ namespace domain {
|
||||||
<< QPoint(x + w, y + h / 2) << QPoint(x + w / 2, y);
|
<< QPoint(x + w, y + h / 2) << QPoint(x + w / 2, y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto item = new QGraphicsPolygonItem(polygon);
|
group->addToGroup(new QGraphicsPolygonItem(polygon));
|
||||||
item->setFillRule(Qt::OddEvenFill);
|
|
||||||
item->setBrush(QBrush(config.fillColor));
|
|
||||||
item->setPen(QPen(config.lineColor));
|
|
||||||
group->addToGroup(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Pin::renderInOut(QGraphicsItemGroup *group) {
|
void ui::Pin::renderInOut(QGraphicsItemGroup *group) {
|
||||||
auto rect = new QGraphicsRectItem(x, y, w, h);
|
group->addToGroup(new QGraphicsRectItem(x, y, w, h));
|
||||||
rect->setBrush(QBrush(config.fillColor));
|
|
||||||
rect->setPen(QPen(config.lineColor));
|
|
||||||
group->addToGroup(rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Pin::render(QGraphicsItemGroup *group) {
|
void ui::Pin::render(QGraphicsItemGroup *group) {
|
||||||
|
@ -199,12 +168,11 @@ namespace domain {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Item::render(QGraphicsItemGroup *group, ui::DisplayContext context, int size) {
|
void ui::Item::render(QGraphicsItemGroup *group, int size) {
|
||||||
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);
|
if (bus) bus->render(group, size);
|
||||||
if (text) text->render(group, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::Item::comdel(std::ostream &buffer, int x, int y, int size) {
|
void ui::Item::comdel(std::ostream &buffer, int x, int y, int size) {
|
||||||
|
@ -212,32 +180,5 @@ namespace domain {
|
||||||
if (line) line->comdel(buffer, x, y);
|
if (line) line->comdel(buffer, x, y);
|
||||||
// pins aren't exported
|
// pins aren't exported
|
||||||
if (bus) bus->comdel(buffer, x, y, size);
|
if (bus) bus->comdel(buffer, x, y, size);
|
||||||
// text currently isn't exported TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
ui::DisplayContext::DisplayContext(ComponentInstance *instance) {
|
|
||||||
for(auto attr: instance->attributes) {
|
|
||||||
this->values[attr.name] = attr.value;
|
|
||||||
}
|
|
||||||
this->values["instanceName"] = Value::fromString(instance->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
string replacePlaceholder(string source, string key, Value value) {
|
|
||||||
key = "{" + key + "}";
|
|
||||||
auto placeholderValue = value.string();
|
|
||||||
|
|
||||||
auto found = source.find(key);
|
|
||||||
while (found != string::npos) {
|
|
||||||
source.replace(found, key.length(), placeholderValue);
|
|
||||||
found = source.find(key);
|
|
||||||
}
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ui::DisplayContext::populateMessage(std::string source) {
|
|
||||||
for (auto &[key, value]: values) {
|
|
||||||
source = replacePlaceholder(source, key, value);
|
|
||||||
}
|
|
||||||
return source;
|
|
||||||
}
|
}
|
||||||
} // namespace domain
|
} // namespace domain
|
||||||
|
|
|
@ -5,52 +5,16 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include "comdel/parser/color.h"
|
|
||||||
#include "value.h"
|
|
||||||
|
|
||||||
namespace domain {
|
namespace domain {
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class DisplayContext {
|
|
||||||
std::map<std::string, domain::Value> values;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DisplayContext(ComponentInstance *instance);
|
|
||||||
std::string populateMessage(std::string message);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DisplayConfig {
|
|
||||||
QColor lineColor;
|
|
||||||
QColor fillColor;
|
|
||||||
|
|
||||||
DisplayConfig(Color lineColor, Color fillColor) {
|
|
||||||
this->lineColor = QColor::fromRgb(lineColor.r, lineColor.g, lineColor.b, lineColor.a);
|
|
||||||
this->fillColor = QColor::fromRgb(fillColor.r, fillColor.g, fillColor.b, fillColor.a);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Text {
|
|
||||||
public:
|
|
||||||
int x, y, w, h;
|
|
||||||
QColor color;
|
|
||||||
std::string text;
|
|
||||||
|
|
||||||
Text(int x, int y, int w, int h, std::string text, Color color) : x(x), y(y), w(w), h(h), text(text),
|
|
||||||
color(QColor::fromRgb(color.r, color.g, color.b, color.a)) {}
|
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group, ui::DisplayContext context);
|
|
||||||
|
|
||||||
void comdel(std::ostream &buffer, int x, int y);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Rect {
|
class Rect {
|
||||||
public:
|
public:
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
DisplayConfig config;
|
|
||||||
|
|
||||||
Rect(int x, int y, int w, int h, DisplayConfig config) : x(x), y(y), w(w), h(h), config(config) {}
|
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group);
|
void render(QGraphicsItemGroup *group);
|
||||||
|
|
||||||
|
@ -61,9 +25,8 @@ namespace domain {
|
||||||
class Line {
|
class Line {
|
||||||
public:
|
public:
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
DisplayConfig config;
|
|
||||||
|
|
||||||
Line(int x1, int y1, int x2, int y2, DisplayConfig config) : x1(x1), y1(y1), x2(x2), y2(y2), config(config) {}
|
Line(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group);
|
void render(QGraphicsItemGroup *group);
|
||||||
|
|
||||||
|
@ -84,11 +47,9 @@ namespace domain {
|
||||||
public:
|
public:
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
BusOrientation orientation;
|
BusOrientation orientation;
|
||||||
DisplayConfig config;
|
|
||||||
|
|
||||||
Bus(int x, int y, int w, int h, BusOrientation orientation, DisplayConfig config) : x(x), y(y), w(w), h(h),
|
Bus(int x, int y, int w, int h, BusOrientation orientation) : x(x), y(y), w(w), h(h),
|
||||||
orientation(orientation),
|
orientation(orientation) {}
|
||||||
config(config) {}
|
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group, int size);
|
void render(QGraphicsItemGroup *group, int size);
|
||||||
|
|
||||||
|
@ -103,10 +64,10 @@ namespace domain {
|
||||||
PinOrientation orientation;
|
PinOrientation orientation;
|
||||||
PinType pinType;
|
PinType pinType;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
DisplayConfig config;
|
|
||||||
|
|
||||||
Pin(int x, int y, int w, int h, PinOrientation orientation, PinType pinType, DisplayConfig config)
|
Pin(int x, int y, int w, int h, PinOrientation orientation, PinType pinType) : x(x), y(y), w(w), h(h),
|
||||||
: x(x), y(y), w(w), h(h), orientation(orientation), pinType(pinType), config(config) {}
|
orientation(orientation),
|
||||||
|
pinType(pinType) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void render(QGraphicsItemGroup *group);
|
void render(QGraphicsItemGroup *group);
|
||||||
|
@ -129,9 +90,8 @@ namespace domain {
|
||||||
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;
|
std::optional<Bus> bus = std::nullopt;
|
||||||
std::optional<Text> text = std::nullopt;
|
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group, ui::DisplayContext context, int size = 0);
|
void render(QGraphicsItemGroup *group, int size = 0);
|
||||||
void comdel(std::ostream &buffer, int x, int y, int size = 0);
|
void comdel(std::ostream &buffer, int x, int y, int size = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,7 +102,7 @@ namespace domain {
|
||||||
|
|
||||||
Display(std::vector<ui::Item> items);
|
Display(std::vector<ui::Item> items);
|
||||||
|
|
||||||
void render(QGraphicsItemGroup *group, ui::DisplayContext context);
|
void render(QGraphicsItemGroup *group);
|
||||||
|
|
||||||
void comdel(std::ostream &buffer, int x, int y, int size = 0);
|
void comdel(std::ostream &buffer, int x, int y, int size = 0);
|
||||||
|
|
||||||
|
|
|
@ -615,34 +615,20 @@ namespace domain {
|
||||||
for (auto &item: node.items) {
|
for (auto &item: node.items) {
|
||||||
ui::Item displayItem;
|
ui::Item displayItem;
|
||||||
std::string type = item.type.value;
|
std::string type = item.type.value;
|
||||||
|
if (type == "rect") {
|
||||||
auto fillColor = item.asColor(&errors, "fillColor", Color(255, 255, 255, 255));
|
|
||||||
auto lineColor = item.asColor(&errors, "lineColor", Color(0, 0, 0, 255));
|
|
||||||
|
|
||||||
if (type == "text") {
|
|
||||||
long long int x, y, w, h;
|
|
||||||
std::string text;
|
|
||||||
auto color = item.asColor(&errors, "color", Color(0, 0, 0, 255));
|
|
||||||
x = item.asInt(&errors, "x");
|
|
||||||
y = item.asInt(&errors, "y");
|
|
||||||
w = item.asInt(&errors, "w");
|
|
||||||
h = item.asInt(&errors, "h");
|
|
||||||
text = item.asString(&errors, "text");
|
|
||||||
displayItem.text = ui::Text(x, y, w, h, text, color);
|
|
||||||
} else if (type == "rect") {
|
|
||||||
long long int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = item.asInt(&errors, "x");
|
x = item.asInt(&errors, "x");
|
||||||
y = item.asInt(&errors, "y");
|
y = item.asInt(&errors, "y");
|
||||||
w = item.asInt(&errors, "w");
|
w = item.asInt(&errors, "w");
|
||||||
h = item.asInt(&errors, "h");
|
h = item.asInt(&errors, "h");
|
||||||
displayItem.rect = ui::Rect(x, y, w, h, {lineColor, fillColor});
|
displayItem.rect = ui::Rect(x, y, w, h);
|
||||||
} else if (type == "line") {
|
} else if (type == "line") {
|
||||||
long long int x1, y1, x2, y2;
|
long long int x1, y1, x2, y2;
|
||||||
x1 = item.asInt(&errors, "x1");
|
x1 = item.asInt(&errors, "x1");
|
||||||
y1 = item.asInt(&errors, "y1");
|
y1 = item.asInt(&errors, "y1");
|
||||||
x2 = item.asInt(&errors, "x2");
|
x2 = item.asInt(&errors, "x2");
|
||||||
y2 = item.asInt(&errors, "y2");
|
y2 = item.asInt(&errors, "y2");
|
||||||
displayItem.line = ui::Line(x1, y1, x2, y2, {lineColor, fillColor});
|
displayItem.line = ui::Line(x1, y1, x2, y2);
|
||||||
} else if (type == "pin") {
|
} else if (type == "pin") {
|
||||||
long long int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = item.asInt(&errors, "x");
|
x = item.asInt(&errors, "x");
|
||||||
|
@ -676,7 +662,7 @@ namespace domain {
|
||||||
errors.emplace_back(item.span, "unknown pin type '" + _pinType + "'");
|
errors.emplace_back(item.span, "unknown pin type '" + _pinType + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
displayItem.pin = ui::Pin(x, y, w, h, orientation, pinType, {lineColor, fillColor});
|
displayItem.pin = ui::Pin(x, y, w, h, orientation, pinType);
|
||||||
} else if (type == "bus") {
|
} else if (type == "bus") {
|
||||||
long long int x, y, w, h;
|
long long int x, y, w, h;
|
||||||
x = item.asInt(&errors, "x");
|
x = item.asInt(&errors, "x");
|
||||||
|
@ -694,7 +680,7 @@ namespace domain {
|
||||||
errors.emplace_back(item.span, "unknown bus orientation type '" + _orientation + "'");
|
errors.emplace_back(item.span, "unknown bus orientation type '" + _orientation + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
displayItem.bus = ui::Bus(x, y, w, h, orientation, {lineColor, fillColor});
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,19 +20,6 @@ NumberNode::NumberNode(const std::string &expression) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************** COLOR NODE *********************************/
|
|
||||||
|
|
||||||
ColorNode::ColorNode(const std::string &expression) {
|
|
||||||
auto value = expression.substr(1);
|
|
||||||
color.r = std::stoul(value.substr(0, 2), nullptr, 16);
|
|
||||||
color.g = std::stoul(value.substr(2, 4), nullptr, 16);
|
|
||||||
color.b = std::stoul(value.substr(4, 6), nullptr, 16);
|
|
||||||
color.a = 255;
|
|
||||||
if(value.length() == 8) {
|
|
||||||
color.a = std::stoul(value.substr(6,8), nullptr, 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************** STRING NODE ********************************/
|
/*************************** STRING NODE ********************************/
|
||||||
|
|
||||||
std::string StringNode::asString() {
|
std::string StringNode::asString() {
|
||||||
|
@ -62,14 +49,6 @@ std::string ValueNode::asIdentifier() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Color ValueNode::asColor() {
|
|
||||||
if (is(COLOR)) {
|
|
||||||
return colorValue.value();
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ValueNode::asBool() {
|
bool ValueNode::asBool() {
|
||||||
if (is(BOOL)) {
|
if (is(BOOL)) {
|
||||||
return boolValue.value();
|
return boolValue.value();
|
||||||
|
@ -115,13 +94,6 @@ ValueNode ValueNode::ofNull() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueNode ValueNode::ofColor(Color color) {
|
|
||||||
ValueNode value;
|
|
||||||
value.type = EnumNode(COLOR);
|
|
||||||
value.colorValue = color;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueNode ValueNode::ofWire(std::optional<std::string> _value) {
|
ValueNode ValueNode::ofWire(std::optional<std::string> _value) {
|
||||||
ValueNode value;
|
ValueNode value;
|
||||||
value.type = EnumNode(WIRE);
|
value.type = EnumNode(WIRE);
|
||||||
|
@ -134,4 +106,4 @@ ValueNode ValueNode::ofMemory(std::optional<std::string> _value) {
|
||||||
value.type = EnumNode(MEMORY);
|
value.type = EnumNode(MEMORY);
|
||||||
value.identifierValue = _value;
|
value.identifierValue = _value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define AST_NODE_H
|
#define AST_NODE_H
|
||||||
|
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "color.h"
|
|
||||||
#include "source_error.h"
|
#include "source_error.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -57,14 +56,6 @@ struct NumberNode : public AstNode {
|
||||||
NumberNode() : value(0) {}
|
NumberNode() : value(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColorNode : public AstNode {
|
|
||||||
Color color;
|
|
||||||
|
|
||||||
explicit ColorNode(const std::string &expression);
|
|
||||||
|
|
||||||
ColorNode() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct CountNode : public AstNode {
|
struct CountNode : public AstNode {
|
||||||
NumberNode first;
|
NumberNode first;
|
||||||
|
@ -92,7 +83,6 @@ public:
|
||||||
IDENTIFIER,
|
IDENTIFIER,
|
||||||
MEMORY,
|
MEMORY,
|
||||||
NIL,
|
NIL,
|
||||||
COLOR,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -101,7 +91,6 @@ private:
|
||||||
std::optional<std::string> stringValue;
|
std::optional<std::string> stringValue;
|
||||||
std::optional<bool> boolValue;
|
std::optional<bool> boolValue;
|
||||||
std::optional<std::string> identifierValue;
|
std::optional<std::string> identifierValue;
|
||||||
std::optional<Color> colorValue;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ValueNode() = default;
|
ValueNode() = default;
|
||||||
|
@ -116,8 +105,6 @@ public:
|
||||||
|
|
||||||
std::string asIdentifier();
|
std::string asIdentifier();
|
||||||
|
|
||||||
Color asColor();
|
|
||||||
|
|
||||||
bool asBool();
|
bool asBool();
|
||||||
|
|
||||||
bool is(ValueType valueType);
|
bool is(ValueType valueType);
|
||||||
|
@ -134,10 +121,7 @@ public:
|
||||||
|
|
||||||
static ValueNode ofNull();
|
static ValueNode ofNull();
|
||||||
|
|
||||||
static ValueNode ofColor(Color color);
|
|
||||||
|
|
||||||
static ValueNode ofWire(std::optional<std::string> _value);
|
static ValueNode ofWire(std::optional<std::string> _value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConditionNode {
|
struct ConditionNode {
|
||||||
|
@ -212,21 +196,6 @@ struct DisplayItemNode : public AstNode {
|
||||||
return _default;
|
return _default;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color asColor(std::vector<SourceError> *errors, const std::string &property, Color _default = Color(0, 0, 0)) {
|
|
||||||
for (auto &prop: values) {
|
|
||||||
if (prop.key.value == property) {
|
|
||||||
if (prop.value.is(ValueNode::COLOR)) {
|
|
||||||
return prop.value.asColor();
|
|
||||||
} 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 = "") {
|
std::string asIdentifier(std::vector<SourceError> *errors, const std::string &property, std::string _default = "") {
|
||||||
for (auto &prop: values) {
|
for (auto &prop: values) {
|
||||||
if (prop.key.value == property) {
|
if (prop.key.value == property) {
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
//
|
|
||||||
// Created by bbr on 12.06.22..
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "color.h"
|
|
|
@ -1,21 +0,0 @@
|
||||||
//
|
|
||||||
// Created by bbr on 12.06.22..
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SCHEMEEDITOR_COLOR_H
|
|
||||||
#define SCHEMEEDITOR_COLOR_H
|
|
||||||
|
|
||||||
|
|
||||||
struct Color {
|
|
||||||
unsigned char r;
|
|
||||||
unsigned char g;
|
|
||||||
unsigned char b;
|
|
||||||
unsigned char a;
|
|
||||||
|
|
||||||
Color(): r(0), g(0), b(0), a(0) {}
|
|
||||||
|
|
||||||
Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0): r(r), g(g), b(b), a(a) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif //SCHEMEEDITOR_COLOR_H
|
|
|
@ -259,7 +259,9 @@ std::optional<LibraryNode> ComdelParser::parseLibrary() {
|
||||||
TokenType::RBRACE,
|
TokenType::RBRACE,
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
false,
|
false,
|
||||||
[this] { return parseProperty(TokenType::STRING);
|
[this] { return parseProperty(
|
||||||
|
std::optional<TokenType>(
|
||||||
|
TokenType::STRING));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
if (!err.has_value()) {
|
if (!err.has_value()) {
|
||||||
|
@ -300,23 +302,6 @@ PResult<StringNode> ComdelParser::parseString() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
*
|
|
||||||
* ColorNode := #RRGGBB[AA]
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
PResult<ColorNode> ComdelParser::parseColor() {
|
|
||||||
auto spanner = getSpanner();
|
|
||||||
if (check(TokenType::COLOR)) {
|
|
||||||
ColorNode node{current().text};
|
|
||||||
node.span = current().span;
|
|
||||||
bump();
|
|
||||||
return spanner(node);
|
|
||||||
}
|
|
||||||
return unexpected();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* IdentifierNode := IDENTIFIER
|
* IdentifierNode := IDENTIFIER
|
||||||
|
@ -1159,8 +1144,6 @@ PResult<ValueNode> ComdelParser::parseValue() {
|
||||||
} else if (check(TokenType::NIL)) {
|
} else if (check(TokenType::NIL)) {
|
||||||
bump();
|
bump();
|
||||||
value = ValueNode::ofNull();
|
value = ValueNode::ofNull();
|
||||||
} else if(check(TokenType::COLOR)) {
|
|
||||||
value = ValueNode::ofColor(parseColor()->color);
|
|
||||||
} else {
|
} else {
|
||||||
return unexpected();
|
return unexpected();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,6 @@ private:
|
||||||
// used to parse library and schema
|
// used to parse library and schema
|
||||||
PResult<StringNode> parseString();
|
PResult<StringNode> parseString();
|
||||||
|
|
||||||
PResult<ColorNode> parseColor();
|
|
||||||
|
|
||||||
PResult<IdentifierNode> parseIdentifier();
|
PResult<IdentifierNode> parseIdentifier();
|
||||||
|
|
||||||
PResult<NumberNode> parseNumber();
|
PResult<NumberNode> parseNumber();
|
||||||
|
|
|
@ -49,14 +49,6 @@
|
||||||
rect {
|
rect {
|
||||||
x: 0; y:0; w:100; h:100;
|
x: 0; y:0; w:100; h:100;
|
||||||
}
|
}
|
||||||
text {
|
|
||||||
x: 0; y: 0; w: 100; h: 100;
|
|
||||||
text: "FRISC";
|
|
||||||
}
|
|
||||||
text {
|
|
||||||
x: 0; y: 16; w: 100; h: 100;
|
|
||||||
text: "{instanceName}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@pin glavniPin in {
|
@pin glavniPin in {
|
||||||
@tooltip "pin za spajanje na glavnu sabirnicu"
|
@tooltip "pin za spajanje na glavnu sabirnicu"
|
||||||
|
@ -291,7 +283,6 @@
|
||||||
*/
|
*/
|
||||||
pin {
|
pin {
|
||||||
x: 100; y: 30; w: 16; h: 16;
|
x: 100; y: 30; w: 16; h: 16;
|
||||||
orientation: "right";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +293,6 @@
|
||||||
@display {
|
@display {
|
||||||
pin {
|
pin {
|
||||||
x: 100; y: 7; w: 16; h: 16;
|
x: 100; y: 7; w: 16; h: 16;
|
||||||
orientation: "right";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@wires { 0, 0, null, null}
|
@wires { 0, 0, null, null}
|
||||||
|
@ -327,8 +317,6 @@
|
||||||
h: 20; w: 100;
|
h: 20; w: 100;
|
||||||
orientation: "horizontal";
|
orientation: "horizontal";
|
||||||
resizable: true;
|
resizable: true;
|
||||||
lineColor: #bbbbbb;
|
|
||||||
fillColor: #bbbbbb;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@wires {
|
@wires {
|
||||||
|
|
Loading…
Reference in New Issue