2022-04-07 22:21:23 +00:00
|
|
|
#ifndef DISPLAY_SCHEMA_H
|
|
|
|
#define DISPLAY_SCHEMA_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QWidget>
|
2022-05-25 05:39:45 +00:00
|
|
|
#include <QGraphicsLineItem>
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
#include <comdel/domain/schema.h>
|
2022-05-23 06:48:13 +00:00
|
|
|
#include <comdel/domain/library.h>
|
2022-05-25 05:39:45 +00:00
|
|
|
#include "component_display.h"
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
namespace display {
|
|
|
|
|
2022-05-17 22:14:33 +00:00
|
|
|
class BusConnection;
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
class Schema : public QGraphicsView {
|
2022-05-23 06:48:13 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
public:
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
QBrush selectedBrush;
|
|
|
|
QPen selectedPen;
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
enum State {
|
|
|
|
DEFAULT,
|
|
|
|
CREATING_CONNECTION
|
|
|
|
};
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
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;
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
State state = DEFAULT;
|
|
|
|
Context context;
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
Schema();
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
std::vector<BusConnection *> busConnections;
|
|
|
|
std::vector<DirectConnection *> directConnections;
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-05-30 21:11:06 +00:00
|
|
|
void setSchema(domain::Schema *schema, std::optional<domain::Library> library);
|
2022-05-17 22:14:33 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void updateConnections();
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void removeConnectable(QPointF f);
|
2022-05-17 22:14:33 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void showConnectable(Pin *pin);
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
protected:
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void dropEvent(QDropEvent *event) override;
|
2022-05-23 06:48:13 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
private:
|
|
|
|
QGraphicsScene scene;
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-30 21:11:06 +00:00
|
|
|
domain::Schema *schema{};
|
|
|
|
std::optional<domain::Library> library;
|
2022-05-25 05:39:45 +00:00
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
std::vector<domain::BusInstance *>
|
|
|
|
getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
|
|
|
|
|
|
|
|
std::vector<domain::ConnectionComponent>
|
|
|
|
getAvailableConnectionPins(domain::ComponentInstance *instance, domain::Pin &pin);
|
|
|
|
};
|
2022-04-07 22:21:23 +00:00
|
|
|
|
|
|
|
} // namespace display
|
|
|
|
|
|
|
|
#endif // DISPLAY_SCHEMA_H
|