schema_editor/comdel/domain/display.h

158 lines
4.5 KiB
C
Raw Permalink Normal View History

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>
#include "comdel/parser/color.h"
#include "value.h"
2022-05-14 13:58:44 +00:00
2022-03-31 21:20:41 +00:00
namespace domain {
2022-05-27 06:18:17 +00:00
namespace ui {
2022-04-07 20:40:31 +00:00
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);
};
2022-05-27 06:18:17 +00:00
class Rect {
public:
int x, y, w, h;
DisplayConfig config;
2022-04-07 20:40:31 +00:00
Rect(int x, int y, int w, int h, DisplayConfig config) : x(x), y(y), w(w), h(h), config(config) {}
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
void render(QGraphicsItemGroup *group);
2022-05-14 13:58:44 +00:00
2022-05-27 06:18:17 +00:00
void comdel(std::ostream &buffer, int x, int y);
2022-05-14 13:58:44 +00:00
2022-05-27 06:18:17 +00:00
};
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
class Line {
public:
int x1, y1, x2, y2;
DisplayConfig config;
2022-04-07 20:40:31 +00:00
Line(int x1, int y1, int x2, int y2, DisplayConfig config) : x1(x1), y1(y1), x2(x2), y2(y2), config(config) {}
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
void render(QGraphicsItemGroup *group);
2022-05-14 13:58:44 +00:00
2022-05-27 06:18:17 +00:00
void comdel(std::ostream &buffer, int x, int y);
};
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
enum PinType {
IN, OUT, IN_OUT
};
enum PinOrientation {
LEFT, RIGHT, TOP, BOTTOM
};
enum BusOrientation {
VERTICAL, HORIZONTAL
};
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
class Bus {
public:
int x, y, w, h;
BusOrientation orientation;
DisplayConfig config;
2022-04-07 20:40:31 +00:00
Bus(int x, int y, int w, int h, BusOrientation orientation, DisplayConfig config) : x(x), y(y), w(w), h(h),
orientation(orientation),
config(config) {}
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
void render(QGraphicsItemGroup *group, int size);
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
int getDefaultSize();
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
void comdel(std::ostream &buffer, int x, int y, int size);
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
};
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
class Pin {
public:
PinOrientation orientation;
PinType pinType;
int x, y, w, h;
DisplayConfig config;
2022-05-26 17:21:53 +00:00
Pin(int x, int y, int w, int h, PinOrientation orientation, PinType pinType, DisplayConfig config)
: x(x), y(y), w(w), h(h), orientation(orientation), pinType(pinType), config(config) {}
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
public:
void render(QGraphicsItemGroup *group);
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
int getConnectionX();
int getConnectionY();
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
private:
void renderIn(QGraphicsItemGroup *group);
void renderOut(QGraphicsItemGroup *group);
void renderInOut(QGraphicsItemGroup *group);
};
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
class Item {
public:
Item() : rect(std::nullopt), line(std::nullopt), pin(std::nullopt), bus(std::nullopt) {}
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
std::optional<Rect> rect = std::nullopt;
std::optional<Line> line = std::nullopt;
std::optional<Pin> pin = std::nullopt;
std::optional<Bus> bus = std::nullopt;
std::optional<Text> text = std::nullopt;
2022-04-07 20:40:31 +00:00
void render(QGraphicsItemGroup *group, ui::DisplayContext context, int size = 0);
2022-05-27 06:18:17 +00:00
void comdel(std::ostream &buffer, int x, int y, int size = 0);
};
2022-04-07 20:40:31 +00:00
}
2022-05-27 06:18:17 +00:00
class Display {
public:
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
Display(std::vector<ui::Item> items);
2022-04-07 20:40:31 +00:00
void render(QGraphicsItemGroup *group, ui::DisplayContext context);
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
void comdel(std::ostream &buffer, int x, int y, int size = 0);
2022-05-14 13:58:44 +00:00
2022-05-27 06:18:17 +00:00
std::vector<ui::Item> &getItems() { return items; }
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
private:
std::vector<ui::Item> items;
};
2022-03-31 21:20:41 +00:00
} // namespace domain
#endif // DOMAIN_DISPLAY_H