2022-03-31 21:20:41 +00:00
|
|
|
#ifndef DOMAIN_DISPLAY_H
|
|
|
|
#define DOMAIN_DISPLAY_H
|
|
|
|
|
2022-04-07 20:40:31 +00:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <optional>
|
2022-03-31 21:20:41 +00:00
|
|
|
|
2022-05-14 13:58:44 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
namespace domain {
|
|
|
|
|
2022-04-07 20:40:31 +00:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
class Rect {
|
|
|
|
public:
|
|
|
|
int x, y, w, h;
|
|
|
|
|
|
|
|
Rect(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {}
|
|
|
|
|
|
|
|
void render(QGraphicsItemGroup *group) {
|
|
|
|
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
|
|
|
}
|
2022-05-14 13:58:44 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
buffer << "\t\t\tw: " << w << "; h: " << h << ";\n";
|
|
|
|
buffer << "\t\t}\n\n";
|
|
|
|
}
|
|
|
|
|
2022-04-07 20:40:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Line {
|
|
|
|
public:
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
|
|
|
Line(int x1, int y1, int x2, int y2): x1(x1), y1(y1), x2(x2), y2(y2) {}
|
|
|
|
|
|
|
|
void render(QGraphicsItemGroup *group) {
|
|
|
|
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2));
|
|
|
|
}
|
2022-05-14 13:58:44 +00:00
|
|
|
|
|
|
|
void comdel(std::ostream &buffer, int x, int y, int size) {
|
|
|
|
buffer << "\t\tline {\n";
|
|
|
|
buffer << "\t\t\tx1: " << (x1 + x) << "; y1: " << (y1 + y) << ";\n";
|
|
|
|
buffer << "\t\t\tx2: " << (x2 + x) << "; y2: " << (y2 + y) << ";\n";
|
|
|
|
buffer << "\t\t}\n\n";
|
|
|
|
}
|
2022-04-07 20:40:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Orientation {
|
|
|
|
LEFT, RIGHT, TOP, BOTTOM
|
|
|
|
};
|
|
|
|
|
|
|
|
enum PinType {
|
|
|
|
IN, OUT, IN_OUT
|
|
|
|
};
|
|
|
|
|
|
|
|
class Pin {
|
|
|
|
public:
|
|
|
|
Orientation orientation;
|
|
|
|
PinType pinType;
|
|
|
|
int x, y, w, h;
|
|
|
|
|
|
|
|
Pin(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {}
|
|
|
|
|
|
|
|
void render(QGraphicsItemGroup *group) {
|
|
|
|
group->addToGroup(new QGraphicsRectItem(x,y,w,h));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Item {
|
|
|
|
public:
|
|
|
|
Item(): rect(std::nullopt), line(std::nullopt), pin(std::nullopt) {}
|
|
|
|
|
|
|
|
void render(QGraphicsItemGroup *group) {
|
|
|
|
if(rect) rect->render(group);
|
|
|
|
if(line) line->render(group);
|
|
|
|
if(pin) pin->render(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<Rect> rect = std::nullopt;
|
|
|
|
std::optional<Line> line = std::nullopt;
|
|
|
|
std::optional<Pin> pin = std::nullopt;
|
2022-05-14 13:58:44 +00:00
|
|
|
|
|
|
|
void comdel(std::ostream &buffer, int x, int y, int size) {
|
|
|
|
if(rect) rect->comdel(buffer, x, y, size);
|
|
|
|
if(line) line->comdel(buffer, x, y, size);
|
|
|
|
}
|
2022-04-07 20:40:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
class Display
|
|
|
|
{
|
|
|
|
public:
|
2022-04-07 20:40:31 +00:00
|
|
|
|
|
|
|
Display(std::vector<ui::Item> items);
|
|
|
|
|
|
|
|
void render(QGraphicsItemGroup *group) {
|
|
|
|
for(auto &item: items) {
|
|
|
|
item.render(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-14 13:58:44 +00:00
|
|
|
void comdel(std::ostream &buffer, int x, int y, int size) {
|
|
|
|
for(auto &item: items) {
|
|
|
|
item.comdel(buffer, x, y, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 20:40:31 +00:00
|
|
|
private:
|
|
|
|
std::vector<ui::Item> items;
|
2022-03-31 21:20:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace domain
|
|
|
|
|
|
|
|
#endif // DOMAIN_DISPLAY_H
|