From e7fd7df154246b9cafc97aa7c3fe053a85fb882e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Sat, 14 May 2022 15:58:44 +0200 Subject: [PATCH] Added display code generation --- comdel/domain/comdel_generator.cpp | 34 +++++++++++++++++++++++++++--- comdel/domain/display.h | 28 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/comdel/domain/comdel_generator.cpp b/comdel/domain/comdel_generator.cpp index 92983ee..01fe21b 100644 --- a/comdel/domain/comdel_generator.cpp +++ b/comdel/domain/comdel_generator.cpp @@ -65,6 +65,8 @@ std::map generateWires(Schema *schema, ostream &ostream); void generateSubComponents(Schema *schema, map &wires, ostream &buffer); + void generateDisplay(Schema *schema, ostream &buffer); + void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) { buffer << library.getHeader() << std::endl; @@ -82,9 +84,36 @@ std::map generateWires(Schema *schema, ostream &ostream); generateSubComponents(schema, wires, buffer); + generateDisplay(schema, buffer); + buffer << "}"; } +void generateBus(BusInstance *bus, ostream &buffer); + +void generateDisplay(Schema *schema, ostream &buffer) { + buffer << "\n\tdisplay {\n"; + + for(auto &component: schema->componentInstances) { + buffer << "\t\tcomponent { x: " << component->position.first << "; y: " << component->position.second << "; ref: \"" << component->name << "\"; }" << std::endl; + } + + for(auto &bus: schema->busInstances) { + generateBus(bus.get(), buffer); + } + + buffer << "\t}\n"; +} + +void generateBus(BusInstance *bus, ostream &buffer) { + buffer << "\n"; + buffer << "\t\t// " << bus->name << " bus\n\n"; + + if(bus->bus.getDisplay().has_value()) { + bus->bus.getDisplay()->comdel(buffer, bus->position.first, bus->position.second, bus->size); + } +} + void generateWire(std::string &name, Wire& wire, ostream &buffer); std::map generateWires(Schema *schema, ostream &buffer) { @@ -142,12 +171,11 @@ std::set createImports(Schema *schema) { void generateAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map wireNames, stringstream &buffer); - void - generateSingleAutomaticPin(DirectConnectionInstance *instance, string name, string pin, +void generateSingleAutomaticPin(DirectConnectionInstance *instance, string name, string pin, map &wireNames, stringstream &buffer); - void generateSubComponents(Schema *schema, map &wires, ostream &buffer) { +void generateSubComponents(Schema *schema, map &wires, ostream &buffer) { buffer << "\t// components --------------------------------------------" << std::endl; diff --git a/comdel/domain/display.h b/comdel/domain/display.h index 54a035a..4278e99 100644 --- a/comdel/domain/display.h +++ b/comdel/domain/display.h @@ -4,6 +4,8 @@ #include #include +#include + namespace domain { namespace ui { @@ -17,6 +19,14 @@ public: void render(QGraphicsItemGroup *group) { group->addToGroup(new QGraphicsRectItem(x,y,w,h)); } + + 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"; + } + }; class Line { @@ -28,6 +38,13 @@ public: void render(QGraphicsItemGroup *group) { group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2)); } + + 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"; + } }; enum Orientation { @@ -65,6 +82,11 @@ public: std::optional rect = std::nullopt; std::optional line = std::nullopt; std::optional pin = std::nullopt; + + 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); + } }; } @@ -81,6 +103,12 @@ public: } } + void comdel(std::ostream &buffer, int x, int y, int size) { + for(auto &item: items) { + item.comdel(buffer, x, y, size); + } + } + private: std::vector items; };