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>
|
|
|
|
|
|
|
|
namespace display {
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
/*
|
2022-04-10 15:24:15 +00:00
|
|
|
class ComponentItem: public QGraphicsItemGroup
|
2022-04-07 22:21:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-04-10 15:24:15 +00:00
|
|
|
ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent);
|
|
|
|
void redraw();
|
2022-04-20 19:50:39 +00:00
|
|
|
void clear();
|
2022-04-10 15:24:15 +00:00
|
|
|
private:
|
|
|
|
domain::ComponentInstance *componentInstance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-04-10 15:24:15 +00:00
|
|
|
class PinItem: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PinItem(domain::Pin pin, QGraphicsItem *parent);
|
|
|
|
void redraw();
|
2022-04-20 19:50:39 +00:00
|
|
|
void clear();
|
2022-04-10 15:24:15 +00:00
|
|
|
private:
|
|
|
|
domain::Pin pin;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ComponentWrapper: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static ComponentWrapper *ofComponent(domain::ComponentInstance *instance);
|
|
|
|
static ComponentWrapper *ofBus(domain::BusInstance *instance);
|
|
|
|
static ComponentWrapper *ofWire(domain::WireInstance *wire);
|
|
|
|
|
|
|
|
ComponentWrapper() {
|
|
|
|
this->setHandlesChildEvents(false);
|
|
|
|
}
|
2022-04-07 22:21:23 +00:00
|
|
|
void redraw();
|
2022-04-20 19:50:39 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
|
|
|
|
QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override
|
|
|
|
{
|
|
|
|
auto response = QGraphicsItem::itemChange(change, value);
|
|
|
|
if (change == ItemPositionChange){
|
|
|
|
if(componentInstance != nullptr) {
|
|
|
|
componentInstance->position.first = (int)scenePos().x();
|
|
|
|
componentInstance->position.second = (int)scenePos().y();
|
|
|
|
} else if(busInstance != nullptr) {
|
|
|
|
busInstance->position.first = (int)scenePos().x();
|
|
|
|
busInstance->position.second = (int)scenePos().y();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
domain::ComponentInstance *componentInstance = nullptr;
|
|
|
|
domain::BusInstance *busInstance = nullptr;
|
|
|
|
domain::WireInstance *wireInstance = nullptr;
|
2022-04-10 15:24:15 +00:00
|
|
|
|
|
|
|
ComponentItem *componentItem;
|
|
|
|
std::vector<PinItem*> pinItems;
|
2022-04-07 22:21:23 +00:00
|
|
|
};
|
2022-05-08 22:51:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class Pin: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
domain::Pin pin;
|
|
|
|
public:
|
|
|
|
Pin(domain::Pin pin): pin(pin) {
|
|
|
|
pin.getDisplay().render(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Component: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<domain::ComponentInstance> instance;
|
|
|
|
public:
|
|
|
|
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
|
|
|
instance->component.getDisplay().render(this);
|
|
|
|
}
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Bus: public QGraphicsItemGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Bus(const std::shared_ptr<domain::BusInstance>& instance) {
|
|
|
|
instance->bus.getDisplay()->render(this);
|
|
|
|
}
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
setHandlesChildEvents(false);
|
|
|
|
|
|
|
|
addToGroup(new display::Bus(instance));
|
|
|
|
|
|
|
|
setPos(instance->position.first, instance->position.second);
|
|
|
|
}
|
|
|
|
};
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
} // namespace display
|
|
|
|
|
|
|
|
#endif // DISPLAY_COMPONENT_H
|