schema_editor/comdel/domain/display.h

118 lines
3.0 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>
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
2022-05-27 06:18:17 +00:00
class Rect {
public:
int x, y, w, h;
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
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;
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
Line(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
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;
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
Bus(int x, int y, int w, int h, BusOrientation orientation) : x(x), y(y), w(w), h(h),
orientation(orientation) {}
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;
2022-05-26 17:21:53 +00:00
2022-05-27 06:18:17 +00:00
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) {}
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;
2022-04-07 20:40:31 +00:00
2022-05-27 06:18:17 +00:00
void render(QGraphicsItemGroup *group, int size = 0);
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
2022-05-27 06:18:17 +00:00
void render(QGraphicsItemGroup *group);
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