schema_editor/comdel/display/schema_display.cpp

41 lines
1.1 KiB
C++

#include "component_display.h"
#include "schema_display.h"
namespace display {
Schema::Schema()
{
this->setScene(&scene);
}
void Schema::setSchema(std::optional<domain::Schema> schema)
{
scene.clear();
this->schema = schema;
if(schema.has_value()) {
for(auto &instance: schema->instances) {
Component *group = nullptr;
auto component = dynamic_cast<domain::ComponentInstance*>(instance);
if(component) {
group = Component::ofComponent(component);
}
auto bus = dynamic_cast<domain::BusInstance*>(instance);
if(bus) {
group = Component::ofBus(bus);
}
if(group != nullptr) {
group->setPos(instance->position.first, instance->position.second);
scene.addItem(group);
}
}
for(auto &wire: schema->wires) {
auto group = Component::ofWire(wire);
group->setPos(wire->position.first, wire->position.second);
scene.addItem(group);
}
}
}
} // namespace display