#include "display.h" namespace domain { Display::Display(std::vector items) : items(items) {} void Display::render(QGraphicsItemGroup *group) { for (auto &item: items) { item.render(group); } } void Display::comdel(std::ostream &buffer, int x, int y, int size) { for (auto &item: items) { item.comdel(buffer, x, y, size); } } void ui::Rect::render(QGraphicsItemGroup *group) { group->addToGroup(new QGraphicsRectItem(x, y, w, h)); } void ui::Rect::comdel(std::ostream &buffer, int x, int y) { 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"; } void ui::Line::render(QGraphicsItemGroup *group) { group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2)); } void ui::Line::comdel(std::ostream &buffer, int x, int y) { 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"; } void ui::Bus::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 ui::Bus::getDefaultSize() { if (orientation == HORIZONTAL) { return w; } else { return h; } } void ui::Bus::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"; } void ui::Pin::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 ui::Pin::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 ui::Pin::renderInOut(QGraphicsItemGroup *group) { group->addToGroup(new QGraphicsRectItem(x, y, w, h)); } void ui::Pin::render(QGraphicsItemGroup *group) { switch (pinType) { case PinType::IN: renderIn(group); break; case PinType::OUT: renderOut(group); break; case PinType::IN_OUT: renderInOut(group); break; } } int ui::Pin::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 ui::Pin::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; } void ui::Item::render(QGraphicsItemGroup *group, int size) { if (rect) rect->render(group); if (line) line->render(group); if (pin) pin->render(group); if (bus) bus->render(group, size); } void ui::Item::comdel(std::ostream &buffer, int x, int y, int size) { if (rect) rect->comdel(buffer, x, y); if (line) line->comdel(buffer, x, y); // pins aren't exported if (bus) bus->comdel(buffer, x, y, size); } } // namespace domain