Added display code generation

This commit is contained in:
Borna Rajković 2022-05-14 15:58:44 +02:00
parent 45a668fc46
commit e7fd7df154
2 changed files with 59 additions and 3 deletions

View File

@ -65,6 +65,8 @@ std::map<string, string> generateWires(Schema *schema, ostream &ostream);
void generateSubComponents(Schema *schema, map <string, string> &wires, ostream &buffer); void generateSubComponents(Schema *schema, map <string, string> &wires, ostream &buffer);
void generateDisplay(Schema *schema, ostream &buffer);
void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) { void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer) {
buffer << library.getHeader() << std::endl; buffer << library.getHeader() << std::endl;
@ -82,9 +84,36 @@ std::map<string, string> generateWires(Schema *schema, ostream &ostream);
generateSubComponents(schema, wires, buffer); generateSubComponents(schema, wires, buffer);
generateDisplay(schema, buffer);
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); void generateWire(std::string &name, Wire& wire, ostream &buffer);
std::map<string, string> generateWires(Schema *schema, ostream &buffer) { std::map<string, string> generateWires(Schema *schema, ostream &buffer) {
@ -142,12 +171,11 @@ std::set<std::string> createImports(Schema *schema) {
void generateAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map<string, string> wireNames, stringstream &buffer); void generateAutomaticPin(DirectConnectionInstance *connection, string name, string pin, map<string, string> wireNames, stringstream &buffer);
void void generateSingleAutomaticPin(DirectConnectionInstance *instance, string name, string pin,
generateSingleAutomaticPin(DirectConnectionInstance *instance, string name, string pin,
map <string, string> &wireNames, map <string, string> &wireNames,
stringstream &buffer); stringstream &buffer);
void generateSubComponents(Schema *schema, map<string, string> &wires, ostream &buffer) { void generateSubComponents(Schema *schema, map<string, string> &wires, ostream &buffer) {
buffer << "\t// components --------------------------------------------" << std::endl; buffer << "\t// components --------------------------------------------" << std::endl;

View File

@ -4,6 +4,8 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include <optional> #include <optional>
#include <ostream>
namespace domain { namespace domain {
namespace ui { namespace ui {
@ -17,6 +19,14 @@ public:
void render(QGraphicsItemGroup *group) { void render(QGraphicsItemGroup *group) {
group->addToGroup(new QGraphicsRectItem(x,y,w,h)); 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 { class Line {
@ -28,6 +38,13 @@ public:
void render(QGraphicsItemGroup *group) { void render(QGraphicsItemGroup *group) {
group->addToGroup(new QGraphicsLineItem(x1, y1, x2, y2)); 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 { enum Orientation {
@ -65,6 +82,11 @@ public:
std::optional<Rect> rect = std::nullopt; std::optional<Rect> rect = std::nullopt;
std::optional<Line> line = std::nullopt; std::optional<Line> line = std::nullopt;
std::optional<Pin> pin = std::nullopt; std::optional<Pin> 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: private:
std::vector<ui::Item> items; std::vector<ui::Item> items;
}; };