2024-12-07 17:24:36 +08:00
|
|
|
#ifndef ELECTRICCONNECTLINEITEM_H
|
|
|
|
|
#define ELECTRICCONNECTLINEITEM_H
|
|
|
|
|
|
|
|
|
|
#include <QPainterPath>
|
2025-02-06 16:36:50 +08:00
|
|
|
#include <QUuid>
|
2024-12-07 17:24:36 +08:00
|
|
|
#include "graphicsBaseItem.h"
|
|
|
|
|
|
|
|
|
|
struct Connection
|
|
|
|
|
{
|
2025-02-06 16:36:50 +08:00
|
|
|
QUuid nSrcNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
QUuid nSrcPortId;
|
2024-12-07 17:24:36 +08:00
|
|
|
HandleType srcType;
|
2024-12-13 18:08:00 +08:00
|
|
|
PortPos srcPos;
|
2025-02-06 16:36:50 +08:00
|
|
|
QUuid nDestNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
QUuid nDestPortId;
|
2024-12-07 17:24:36 +08:00
|
|
|
HandleType destType;
|
2024-12-13 18:08:00 +08:00
|
|
|
PortPos destPos;
|
2024-12-07 17:24:36 +08:00
|
|
|
|
|
|
|
|
Connection()
|
|
|
|
|
{
|
|
|
|
|
srcType = T_none;
|
2024-12-13 18:08:00 +08:00
|
|
|
srcPos = P_top;
|
2024-12-07 17:24:36 +08:00
|
|
|
destType = T_none;
|
2024-12-13 18:08:00 +08:00
|
|
|
destPos = P_top;
|
2024-12-07 17:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
Connection(const Connection& obj)
|
|
|
|
|
{
|
|
|
|
|
nSrcNodeId = obj.nSrcNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
nSrcPortId = obj.nSrcPortId;
|
2025-02-06 16:36:50 +08:00
|
|
|
srcType = obj.srcType;
|
|
|
|
|
srcPos = obj.srcPos;
|
|
|
|
|
nDestNodeId = obj.nDestNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
nDestPortId = obj.nDestPortId;
|
2025-02-06 16:36:50 +08:00
|
|
|
destType = obj.destType;
|
|
|
|
|
destPos = obj.destPos;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-16 19:20:46 +08:00
|
|
|
Connection(QUuid nSNI,QUuid nSPI,HandleType sT,PortPos sPOS,QUuid nDNI,QUuid nDPI,HandleType dT,PortPos dPOS)
|
2024-12-07 17:24:36 +08:00
|
|
|
{
|
|
|
|
|
nSrcNodeId = nSNI;
|
2025-05-16 19:20:46 +08:00
|
|
|
nSrcPortId = nSPI;
|
2024-12-07 17:24:36 +08:00
|
|
|
srcType = sT;
|
2024-12-13 18:08:00 +08:00
|
|
|
srcPos = sPOS;
|
2024-12-07 17:24:36 +08:00
|
|
|
nDestNodeId = nDNI;
|
2025-05-16 19:20:46 +08:00
|
|
|
nDestPortId = nDPI;
|
2024-12-07 17:24:36 +08:00
|
|
|
destType = dT;
|
2024-12-13 18:08:00 +08:00
|
|
|
destPos = dPOS;
|
2024-12-07 17:24:36 +08:00
|
|
|
}
|
2025-02-06 16:36:50 +08:00
|
|
|
bool operator==(const Connection& obj)
|
2024-12-07 17:24:36 +08:00
|
|
|
{
|
2025-05-16 19:20:46 +08:00
|
|
|
return ((obj.nSrcNodeId == nSrcNodeId)&&(obj.nSrcPortId == nSrcPortId)&&(obj.srcType == srcType)&&(obj.nDestNodeId == nDestNodeId)&&(obj.nDestPortId == nDestPortId)&&(obj.destType == destType));
|
2024-12-07 17:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
Connection& operator=(const Connection& obj)
|
2024-12-07 17:24:36 +08:00
|
|
|
{
|
|
|
|
|
if(*this == obj)
|
|
|
|
|
return *this;
|
|
|
|
|
nSrcNodeId = obj.nSrcNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
nSrcPortId = obj.nSrcPortId;
|
2024-12-07 17:24:36 +08:00
|
|
|
srcType = obj.srcType;
|
2024-12-13 18:08:00 +08:00
|
|
|
srcPos = obj.srcPos;
|
2024-12-07 17:24:36 +08:00
|
|
|
nDestNodeId = obj.nDestNodeId;
|
2025-05-16 19:20:46 +08:00
|
|
|
nDestPortId = obj.nDestPortId;
|
2024-12-07 17:24:36 +08:00
|
|
|
destType = obj.destType;
|
2024-12-13 18:08:00 +08:00
|
|
|
destPos = obj.destPos;
|
2024-12-07 17:24:36 +08:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ElectricConnectLineItem : public GraphicsBaseItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ElectricConnectLineItem(QGraphicsItem *parent = 0);
|
|
|
|
|
virtual ~ElectricConnectLineItem();
|
|
|
|
|
|
2024-12-13 18:08:00 +08:00
|
|
|
void setStartPoint(const QPointF& p);
|
|
|
|
|
void setEndPoint(const QPointF& p);
|
2024-12-07 17:24:36 +08:00
|
|
|
QPainterPath getPoints(void) const { return m_points; }
|
|
|
|
|
|
2024-12-13 18:08:00 +08:00
|
|
|
void moveLine(QPointF); //鼠标点击拖动
|
2024-12-07 17:24:36 +08:00
|
|
|
void calculatePath();
|
|
|
|
|
bool addConnection();
|
2024-12-13 18:08:00 +08:00
|
|
|
void resetCurLine(){_curLine = QPoint();}
|
2024-12-07 17:24:36 +08:00
|
|
|
|
2025-04-30 16:29:17 +08:00
|
|
|
//void updateConnection(QUuid callerId,QPointF pos); //外部调用的更新函数,id为调用者id
|
2024-12-07 17:24:36 +08:00
|
|
|
void setConnection(Connection con){m_connectState = con;}
|
2025-02-06 16:36:50 +08:00
|
|
|
Connection getConnection() const {return m_connectState;}
|
2025-04-30 16:29:17 +08:00
|
|
|
//QUuid getOppositeId(QUuid); //获取另一端点id
|
2024-12-07 17:24:36 +08:00
|
|
|
protected:
|
2024-12-13 18:08:00 +08:00
|
|
|
virtual QPainterPath shape() const override;
|
|
|
|
|
virtual QRectF boundingRect() const override;
|
|
|
|
|
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
2024-12-07 17:24:36 +08:00
|
|
|
private:
|
2024-12-13 18:08:00 +08:00
|
|
|
Connection m_connectState;
|
|
|
|
|
QPainterPath m_points;
|
|
|
|
|
QPainterPath m_pointsBoundingRect; //包裹点的矩形集合
|
|
|
|
|
QList<QPointF> m_lstPoints;
|
|
|
|
|
QPoint _curLine; //参数1用点序号表示的当前线段起始点,参数2表示线段方向
|
|
|
|
|
|
|
|
|
|
//QPointF m_pStart;
|
|
|
|
|
//QPointF m_pEnd;
|
2024-12-07 17:24:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|