schema_editor/comdel/display/schema_display.cpp

41 lines
1.1 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);
}
2022-04-09 19:11:17 +00:00
void Schema::setSchema(std::optional<domain::Schema> schema)
2022-04-07 22:21:23 +00:00
{
scene.clear();
this->schema = schema;
if(schema.has_value()) {
for(auto &instance: schema->instances) {
2022-04-10 15:24:15 +00:00
ComponentWrapper *group = nullptr;
2022-04-07 22:21:23 +00:00
auto component = dynamic_cast<domain::ComponentInstance*>(instance);
if(component) {
2022-04-10 15:24:15 +00:00
group = ComponentWrapper::ofComponent(component);
2022-04-07 22:21:23 +00:00
}
auto bus = dynamic_cast<domain::BusInstance*>(instance);
if(bus) {
2022-04-10 15:24:15 +00:00
group = ComponentWrapper::ofBus(bus);
2022-04-07 22:21:23 +00:00
}
if(group != nullptr) {
group->setPos(instance->position.first, instance->position.second);
scene.addItem(group);
}
}
for(auto &wire: schema->wires) {
2022-04-10 15:24:15 +00:00
auto group = ComponentWrapper::ofWire(wire);
2022-04-07 22:21:23 +00:00
group->setPos(wire->position.first, wire->position.second);
scene.addItem(group);
}
}
}
} // namespace display