schema_editor/comdel/display/schema_display.cpp

53 lines
1.5 KiB
C++
Raw Normal View History

2022-04-07 22:21:23 +00:00
#include "component_display.h"
#include "schema_display.h"
namespace display {
Schema::Schema()
{
this->setScene(&scene);
}
void Schema::setSchema(domain::Schema* _schema)
2022-04-07 22:21:23 +00:00
{
2022-05-17 22:14:33 +00:00
std::map<std::string, display::ComponentGroup*> components;
std::map<std::string, display::BusGroup*> buses;
2022-04-07 22:21:23 +00:00
scene.clear();
2022-05-17 22:14:33 +00:00
connections.clear();
this->schema = _schema;
2022-04-18 09:41:02 +00:00
if(schema != nullptr) {
2022-05-07 11:20:09 +00:00
for(auto &instance: schema->componentInstances) {
2022-05-17 22:14:33 +00:00
auto group = new display::ComponentGroup(instance);
components.insert(std::make_pair(instance->name, group));
scene.addItem(group);
2022-04-07 22:21:23 +00:00
}
2022-05-07 11:20:09 +00:00
for(auto &instance: schema->busInstances) {
if(instance->bus.getDisplay().has_value()) {
2022-05-17 22:14:33 +00:00
auto group = new display::BusGroup(instance);
buses.insert(std::make_pair(instance->name, group));
scene.addItem(group);
}
}
for(auto &connection: schema->connections) {
auto busInstance = dynamic_cast<domain::BusConnectionInstance*>(connection.get());
if(busInstance != nullptr) {
auto con = new display::BusConnection(busInstance, components[busInstance->instance->name], buses[busInstance->bus->name]);
connections.push_back(con);
scene.addItem(con);
}
2022-04-07 22:21:23 +00:00
}
}
}
2022-05-17 22:14:33 +00:00
void Schema::updateConnections() {
if(schema != nullptr) {
for(auto conn: connections) {
conn->updateConnection();
}
}
}
2022-04-07 22:21:23 +00:00
} // namespace display