Added initial view
This commit is contained in:
1 parent
3cdd126927
commit
4b99a0bf33
14 files changed
+415
-38
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#include "component_display.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
Component *Component::ofWire(domain::WireInstance *wire) {
|
||||
auto component = new Component();
|
||||
component->wireInstance = wire;
|
||||
component->redraw();
|
||||
return component;
|
||||
};
|
||||
Component *Component::ofComponent(domain::ComponentInstance *instance) {
|
||||
auto component = new Component();
|
||||
component->componentInstance = instance;
|
||||
component->redraw();
|
||||
return component;
|
||||
};
|
||||
Component *Component::ofBus(domain::BusInstance *instance) {
|
||||
auto component = new Component();
|
||||
component->busInstance = instance;
|
||||
component->redraw();
|
||||
return component;
|
||||
};
|
||||
|
||||
void Component::redraw() {
|
||||
if(componentInstance) {
|
||||
componentInstance->component.getDisplay().render(this);
|
||||
for(auto &pin: componentInstance->component.getPins()) {
|
||||
pin.getDisplay().render(this);
|
||||
}
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
||||
}
|
||||
if(busInstance && busInstance->bus.getDisplay()) {
|
||||
busInstance->bus.getDisplay()->render(this);
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(busInstance->name)));
|
||||
}
|
||||
if(wireInstance) {
|
||||
wireInstance->display.render(this);
|
||||
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(wireInstance->name)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef DISPLAY_COMPONENT_H
|
||||
#define DISPLAY_COMPONENT_H
|
||||
|
||||
#include <comdel/domain/instance.h>
|
||||
#include <comdel/domain/wireinstance.h>
|
||||
|
||||
#include <QGraphicsItemGroup>
|
||||
|
||||
namespace display {
|
||||
|
||||
class Component: public QGraphicsItemGroup
|
||||
{
|
||||
public:
|
||||
static Component *ofComponent(domain::ComponentInstance *instance);
|
||||
static Component *ofBus(domain::BusInstance *instance);
|
||||
static Component *ofWire(domain::WireInstance *wire);
|
||||
|
||||
void redraw();
|
||||
|
||||
private:
|
||||
domain::ComponentInstance *componentInstance = nullptr;
|
||||
domain::BusInstance *busInstance = nullptr;
|
||||
domain::WireInstance *wireInstance = nullptr;
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
#endif // DISPLAY_COMPONENT_H
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "library_display.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace display {
|
||||
|
||||
Library::Library()
|
||||
{
|
||||
auto layout = new QVBoxLayout();
|
||||
this->setLayout(layout);
|
||||
|
||||
componentList = new QListWidget();
|
||||
busList = new QListWidget();
|
||||
|
||||
layout->setMargin(4);
|
||||
layout->addWidget(new QLabel("Components:"));
|
||||
layout->addWidget(componentList, 1);
|
||||
layout->addSpacing(8);
|
||||
layout->addWidget(new QLabel("Buses:"));
|
||||
layout->addWidget(busList, 1);
|
||||
|
||||
setLibrary(library);
|
||||
}
|
||||
|
||||
void Library::setLibrary(std::optional<domain::Library> library) {
|
||||
|
||||
componentList->clear();
|
||||
busList->clear();
|
||||
|
||||
if(!library) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(auto& component: library->getComponents()) {
|
||||
auto item = new QListWidgetItem{QString::fromStdString(component.getName())};
|
||||
item->setToolTip(QString::fromStdString(component.getTooltip()));
|
||||
componentList->addItem(item);
|
||||
}
|
||||
|
||||
for(auto& bus: library->getBuses()) {
|
||||
if(bus.getType() == domain::Bus::REGULAR) {
|
||||
auto item = new QListWidgetItem{QString::fromStdString(bus.getName())};
|
||||
item->setToolTip(QString::fromStdString(bus.getTooltip()));
|
||||
busList->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace display
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef DISPLAY_LIBRARY_H
|
||||
#define DISPLAY_LIBRARY_H
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include <comdel/domain/library.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
class Library: public QWidget
|
||||
{
|
||||
public:
|
||||
Library();
|
||||
|
||||
void setLibrary(std::optional<domain::Library> library);
|
||||
|
||||
private:
|
||||
std::optional<domain::Library> library;
|
||||
|
||||
QListWidget *componentList;
|
||||
QListWidget *busList;
|
||||
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
#endif // DISPLAY_LIBRARY_H
|
||||
@@ -0,0 +1,40 @@
|
||||
#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
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef DISPLAY_SCHEMA_H
|
||||
#define DISPLAY_SCHEMA_H
|
||||
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QWidget>
|
||||
|
||||
#include <comdel/domain/schema.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
class Schema: public QGraphicsView
|
||||
{
|
||||
public:
|
||||
Schema();
|
||||
|
||||
void setSchema(std::optional<domain::Schema>& schema);
|
||||
|
||||
private:
|
||||
QGraphicsScene scene;
|
||||
|
||||
std::optional<domain::Schema> schema;
|
||||
|
||||
};
|
||||
|
||||
} // namespace display
|
||||
|
||||
#endif // DISPLAY_SCHEMA_H
|
||||
Reference in new issue
Block a user