81 lines
1.9 KiB
C++
81 lines
1.9 KiB
C++
#ifndef DISPLAY_SCHEMA_H
|
|
#define DISPLAY_SCHEMA_H
|
|
|
|
|
|
#include <QGraphicsView>
|
|
#include <QWidget>
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <comdel/domain/schema.h>
|
|
#include <comdel/domain/library.h>
|
|
#include "component_display.h"
|
|
|
|
namespace display {
|
|
|
|
class BusConnection;
|
|
|
|
class Schema : public QGraphicsView {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
QBrush selectedBrush;
|
|
QPen selectedPen;
|
|
|
|
enum State {
|
|
DEFAULT,
|
|
CREATING_CONNECTION
|
|
};
|
|
|
|
struct Context {
|
|
display::Pin *pin = nullptr;
|
|
QPointF startingPoint;
|
|
QGraphicsLineItem *line = nullptr;
|
|
std::vector<QGraphicsRectItem *> selectable;
|
|
};
|
|
|
|
std::map<std::string, display::ComponentGroup *> components;
|
|
std::map<std::string, display::BusGroup *> buses;
|
|
std::map<domain::ConnectionComponent, display::Pin *> pins;
|
|
|
|
State state = DEFAULT;
|
|
Context context;
|
|
|
|
Schema();
|
|
|
|
std::vector<BusConnection *> busConnections;
|
|
std::vector<DirectConnection *> directConnections;
|
|
|
|
void setSchema(domain::Schema *schema, domain::Library *library);
|
|
|
|
void updateConnections();
|
|
|
|
void removeConnectable(QPointF f);
|
|
|
|
void showConnectable(Pin *pin);
|
|
|
|
protected:
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
|
|
private:
|
|
QGraphicsScene scene;
|
|
|
|
domain::Schema *schema;
|
|
domain::Library *library;
|
|
|
|
std::vector<domain::BusInstance *>
|
|
getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
|
|
|
|
std::vector<domain::ConnectionComponent>
|
|
getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
|
|
};
|
|
|
|
} // namespace display
|
|
|
|
#endif // DISPLAY_SCHEMA_H
|