2022-04-07 22:21:23 +00:00
|
|
|
#ifndef DISPLAY_COMPONENT_H
|
|
|
|
#define DISPLAY_COMPONENT_H
|
|
|
|
|
|
|
|
#include <comdel/domain/instance.h>
|
|
|
|
#include <comdel/domain/wireinstance.h>
|
|
|
|
|
|
|
|
#include <QGraphicsItemGroup>
|
2022-05-17 22:14:33 +00:00
|
|
|
#include "comdel/domain/connectioninstance.h"
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
namespace display {
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
class Pin: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
domain::Pin pin;
|
|
|
|
public:
|
|
|
|
Pin(domain::Pin pin): pin(pin) {
|
2022-05-17 22:14:33 +00:00
|
|
|
pin.getDisplayPin().render(this);
|
2022-05-08 22:51:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Component: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<domain::ComponentInstance> instance;
|
|
|
|
public:
|
|
|
|
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
2022-05-17 19:31:32 +00:00
|
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
instance->component.getDisplay().render(this);
|
|
|
|
}
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
2022-05-17 19:31:32 +00:00
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Bus: public QGraphicsItemGroup
|
|
|
|
{
|
2022-05-15 15:00:20 +00:00
|
|
|
std::shared_ptr<domain::BusInstance> busInstance;
|
2022-05-08 22:51:47 +00:00
|
|
|
public:
|
2022-05-15 15:00:20 +00:00
|
|
|
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
2022-05-08 22:51:47 +00:00
|
|
|
instance->bus.getDisplay()->render(this);
|
|
|
|
}
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
2022-05-17 19:31:32 +00:00
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ComponentGroup: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
|
|
|
|
setFlag(ItemIsMovable, true);
|
2022-05-17 19:31:32 +00:00
|
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
setHandlesChildEvents(false);
|
|
|
|
|
|
|
|
addToGroup(new display::Component(instance));
|
|
|
|
|
|
|
|
for(auto &pin: instance->component.getPins()) {
|
|
|
|
addToGroup(new display::Pin(pin));
|
|
|
|
}
|
|
|
|
|
|
|
|
setPos(instance->position.first, instance->position.second);
|
|
|
|
}
|
2022-05-17 19:31:32 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BusGroup: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<domain::BusInstance> busInstance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
|
|
|
setFlag(ItemIsMovable, true);
|
2022-05-17 19:31:32 +00:00
|
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
setHandlesChildEvents(false);
|
|
|
|
|
|
|
|
addToGroup(new display::Bus(instance));
|
|
|
|
|
|
|
|
setPos(instance->position.first, instance->position.second);
|
|
|
|
}
|
2022-05-17 19:31:32 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
2022-05-08 22:51:47 +00:00
|
|
|
};
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-05-17 22:14:33 +00:00
|
|
|
class BusConnection: public QGraphicsLineItem
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
domain::BusConnectionInstance* connection;
|
|
|
|
ComponentGroup* component;
|
|
|
|
BusGroup* bus;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BusConnection(domain::BusConnectionInstance* connection, ComponentGroup *component, BusGroup *bus): connection(connection), component(component), bus(bus) {
|
|
|
|
updateConnection();
|
|
|
|
|
|
|
|
setHandlesChildEvents(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateConnection() {
|
|
|
|
auto busPosition = bus->boundingRect();
|
|
|
|
auto pin = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
|
|
|
|
|
|
|
setLine(connection->instance->position.first + pin.getConnectionX(), connection->instance->position.second + pin.getConnectionY(), connection->bus->position.first + busPosition.width()/2, connection->bus->position.second + busPosition.height()/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
2022-05-17 19:31:32 +00:00
|
|
|
|
|
|
|
|
2022-05-19 19:08:00 +00:00
|
|
|
class DirectConnection: public QGraphicsLineItem
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
domain::DirectConnectionInstance* connection;
|
|
|
|
ComponentGroup* first;
|
|
|
|
ComponentGroup* second;
|
|
|
|
BusGroup* bus;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DirectConnection(domain::DirectConnectionInstance* connection, ComponentGroup *first, ComponentGroup *second, BusGroup *bus): connection(connection), first(first), second(second), bus(bus) {
|
|
|
|
updateConnection();
|
|
|
|
setHandlesChildEvents(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateConnection() {
|
|
|
|
auto pin1 = connection->instance->component.getPin(connection->connection.getComponent().pin).getDisplayPin();
|
|
|
|
auto pin2 = connection->secondInstance->component.getPin(connection->connection.getSecondComponent()->pin).getDisplayPin();
|
|
|
|
|
|
|
|
setLine(connection->instance->position.first + pin1.getConnectionX(), connection->instance->position.second + pin1.getConnectionY(),
|
|
|
|
connection->secondInstance->position.first + pin2.getConnectionX(), connection->secondInstance->position.second + pin2.getConnectionY());
|
|
|
|
}
|
|
|
|
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-04-07 22:21:23 +00:00
|
|
|
} // namespace display
|
|
|
|
|
|
|
|
#endif // DISPLAY_COMPONENT_H
|