53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#include "component_display.h"
|
|
#include "schema_display.h"
|
|
|
|
namespace display {
|
|
|
|
Schema::Schema()
|
|
{
|
|
this->setScene(&scene);
|
|
}
|
|
|
|
|
|
void Schema::setSchema(domain::Schema* _schema)
|
|
{
|
|
std::map<std::string, display::ComponentGroup*> components;
|
|
std::map<std::string, display::BusGroup*> buses;
|
|
|
|
scene.clear();
|
|
connections.clear();
|
|
this->schema = _schema;
|
|
if(schema != nullptr) {
|
|
for(auto &instance: schema->componentInstances) {
|
|
auto group = new display::ComponentGroup(instance);
|
|
components.insert(std::make_pair(instance->name, group));
|
|
scene.addItem(group);
|
|
}
|
|
for(auto &instance: schema->busInstances) {
|
|
if(instance->bus.getDisplay().has_value()) {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Schema::updateConnections() {
|
|
if(schema != nullptr) {
|
|
for(auto conn: connections) {
|
|
conn->updateConnection();
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace display
|