2026-01-04 16:54:55 +08:00
|
|
|
|
#ifndef DrawFrac_H
|
|
|
|
|
|
#define DrawFrac_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2026-04-23 09:10:28 +08:00
|
|
|
|
#include <QColor>
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
|
#include <QPointF>
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
class QMyCustomPlot;
|
|
|
|
|
|
class QCustomPlot;
|
|
|
|
|
|
class QCPItemCurve;
|
|
|
|
|
|
class QCPItemTracer;
|
|
|
|
|
|
class QCPItemLine;
|
|
|
|
|
|
class QCPCurve;
|
|
|
|
|
|
class QCPItemText;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
static const int iFracType2 = 15;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
typedef struct tagPOINTF { float x; float y; } POINTF;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
int iCode;
|
|
|
|
|
|
QString csName;
|
|
|
|
|
|
int iType; // 1:正弦曲线 2:连线 3:封闭区域 4:直线
|
|
|
|
|
|
QColor crColor;
|
|
|
|
|
|
int nLineWidth;
|
|
|
|
|
|
int bDraw;
|
|
|
|
|
|
} FRAC_DEF_Crack;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2026-01-04 16:54:55 +08:00
|
|
|
|
float DEP;
|
2026-04-23 09:10:28 +08:00
|
|
|
|
float AorX;
|
|
|
|
|
|
float XETAorH;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
float W;
|
2026-04-23 09:10:28 +08:00
|
|
|
|
float DIPorS;
|
|
|
|
|
|
float DIR;
|
|
|
|
|
|
float TDIP;
|
|
|
|
|
|
float TDIR;
|
|
|
|
|
|
float ID;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
float NUM;
|
|
|
|
|
|
POINTF point[16];
|
2026-04-23 09:10:28 +08:00
|
|
|
|
} FRAC_TABLE_Crack;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
typedef struct {
|
2026-01-04 16:54:55 +08:00
|
|
|
|
float DEP;
|
|
|
|
|
|
float AorX;
|
|
|
|
|
|
float XETAorH;
|
|
|
|
|
|
float W;
|
|
|
|
|
|
float DIPorS;
|
|
|
|
|
|
float DIR;
|
2026-04-23 09:10:28 +08:00
|
|
|
|
float ID;
|
|
|
|
|
|
} FRAC_TABLE_OLD_Crack;
|
|
|
|
|
|
|
|
|
|
|
|
class DraggableCrackItem;
|
|
|
|
|
|
|
|
|
|
|
|
class CPickFrac : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
CPickFrac(QMyCustomPlot *widget, QString strSlfName, QString csCurve, int iMyWidth);
|
2026-04-23 09:10:28 +08:00
|
|
|
|
virtual ~CPickFrac();
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
void setDraggingEnabled(bool enabled);
|
|
|
|
|
|
QList<DraggableCrackItem*> getAllItems() const { return m_items; }
|
|
|
|
|
|
bool saveToFile();
|
2026-04-23 09:38:17 +08:00
|
|
|
|
bool createNewCrack(int iType, double depth);
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
2026-04-23 09:10:28 +08:00
|
|
|
|
QMyCustomPlot *m_myCustomPlot;
|
|
|
|
|
|
int m_iMyWidth = 0;
|
|
|
|
|
|
QList<FRAC_DEF_Crack> m_FracDef;
|
|
|
|
|
|
bool m_bTypeDraw[iFracType2];
|
|
|
|
|
|
|
2026-01-04 16:54:55 +08:00
|
|
|
|
void ReadFracDef();
|
|
|
|
|
|
void ReadData(QString strSlfName, QString csCurve);
|
2026-04-23 09:10:28 +08:00
|
|
|
|
void drawOne(FRAC_TABLE_Crack frac, int iType, int nLineWidth, QColor crColor);
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
private slots:
|
|
|
|
|
|
void onRemoveCrackItem(DraggableCrackItem *item);
|
2026-01-04 16:54:55 +08:00
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
private:
|
|
|
|
|
|
QList<DraggableCrackItem*> m_items;
|
|
|
|
|
|
bool m_draggingEnabled = true;
|
|
|
|
|
|
QString m_currentSlfName;
|
|
|
|
|
|
QString m_currentTableName;
|
2026-01-04 16:54:55 +08:00
|
|
|
|
};
|
2026-04-23 09:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
// ========== 可拖拽裂缝项 ==========
|
|
|
|
|
|
class DraggableCrackItem : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
enum Type { TypeA_Sine, TypeB_Polyline, TypeC_Closed };
|
|
|
|
|
|
DraggableCrackItem(QCustomPlot *plot, Type type, const QColor &color, int lineWidth);
|
|
|
|
|
|
~DraggableCrackItem();
|
|
|
|
|
|
|
|
|
|
|
|
void setSineData(double depth, double amplitude, double phase, double xScale, double width);
|
|
|
|
|
|
void setPolylineData(const QVector<QPointF> &points, double scaleX = 1.0, double flipY = -1.0);
|
|
|
|
|
|
void setClosedData(const QVector<QPointF> &points, double scaleX = 1.0, double flipY = -1.0);
|
|
|
|
|
|
void setVisible(bool visible);
|
|
|
|
|
|
void deactivate();
|
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
|
|
|
|
|
|
|
|
|
|
// 保存接口
|
|
|
|
|
|
Type getType() const { return m_type; }
|
|
|
|
|
|
void setCrackCode(int code) { m_crackCode = code; }
|
|
|
|
|
|
int getCrackCode() const { return m_crackCode; }
|
|
|
|
|
|
double getDepthForSort() const;
|
|
|
|
|
|
void getCurrentFracData(FRAC_TABLE_Crack &data) const;
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑模式
|
|
|
|
|
|
void startEditing();
|
|
|
|
|
|
void finishEditing();
|
|
|
|
|
|
|
|
|
|
|
|
// 控制所有拖拽点的可见性
|
|
|
|
|
|
void setDragPointsVisible(bool visible);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前激活的item(静态)
|
|
|
|
|
|
static DraggableCrackItem* getActiveItem() { return s_activeItem; }
|
|
|
|
|
|
|
2026-04-23 09:38:17 +08:00
|
|
|
|
void cleanupFromPlot(); // 立即从画布移除所有图形项
|
|
|
|
|
|
|
2026-04-23 09:10:28 +08:00
|
|
|
|
signals:
|
|
|
|
|
|
void dataChanged();
|
|
|
|
|
|
void removeMe(DraggableCrackItem* item);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
QCustomPlot *m_plot;
|
|
|
|
|
|
Type m_type;
|
|
|
|
|
|
QColor m_color;
|
|
|
|
|
|
int m_lineWidth;
|
|
|
|
|
|
int m_crackCode = 0;
|
|
|
|
|
|
double m_originalXETAorH = 0.0;
|
|
|
|
|
|
double m_originalAorX = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
// 模式A
|
|
|
|
|
|
QCPItemCurve *m_curve = nullptr;
|
|
|
|
|
|
QCPItemTracer *m_tracer1 = nullptr, *m_tracer2 = nullptr;
|
|
|
|
|
|
double m_orig_x1, m_orig_x2, m_orig_y1, m_orig_y2;
|
|
|
|
|
|
double m_orig_startX, m_orig_endX, m_orig_startDirX, m_orig_startDirY, m_orig_endDirX, m_orig_endDirY;
|
|
|
|
|
|
double m_offsetXA = 0.0, m_offsetYA = 0.0;
|
|
|
|
|
|
double m_depth = 0.0, m_endX = 0.0;
|
|
|
|
|
|
enum DragStateA { IdleA, DraggingPoint1, DraggingPoint2, DraggingCurveA } m_dragStateA = IdleA;
|
|
|
|
|
|
QPointF m_lastDragPixelA;
|
|
|
|
|
|
|
|
|
|
|
|
// 模式B
|
|
|
|
|
|
struct LineItem {
|
|
|
|
|
|
QCPItemLine *line;
|
|
|
|
|
|
QCPItemTracer *startTracer, *endTracer;
|
|
|
|
|
|
QPointF startOrig, endOrig;
|
|
|
|
|
|
};
|
|
|
|
|
|
QList<LineItem> m_lines;
|
|
|
|
|
|
double m_offsetXB = 0.0, m_offsetYB = 0.0;
|
|
|
|
|
|
bool m_isAddingLine = false;
|
|
|
|
|
|
QPointF m_tempPoint;
|
|
|
|
|
|
enum DragStateB { IdleB, DraggingStartPoint, DraggingEndPoint, DraggingLineOverall } m_dragStateB = IdleB;
|
|
|
|
|
|
QPointF m_bDragStart;
|
|
|
|
|
|
int m_draggedLineIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
// 模式C
|
|
|
|
|
|
QCPCurve *m_curveC = nullptr;
|
|
|
|
|
|
QVector<QPointF> m_pointsC;
|
|
|
|
|
|
QVector<QCPItemText*> m_labelsC;
|
|
|
|
|
|
double m_offsetXC = 0.0, m_offsetYC = 0.0;
|
|
|
|
|
|
bool m_cFinished = false, m_cDragging = false, m_draggingPoint = false;
|
|
|
|
|
|
int m_draggedPointIndex = -1;
|
|
|
|
|
|
QPointF m_cDragStart;
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑模式标志
|
|
|
|
|
|
bool m_editingMode = false;
|
2026-04-23 09:38:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 删除安全标志
|
|
|
|
|
|
bool m_pendingDelete = false;
|
2026-04-23 09:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 辅助函数
|
|
|
|
|
|
void updateCurveFromTargets();
|
|
|
|
|
|
void updateCurvePosition();
|
|
|
|
|
|
void updateTracers();
|
|
|
|
|
|
void setTracerHighlight(QCPItemTracer *tracer, bool highlight);
|
|
|
|
|
|
void updateLineEndpoints(LineItem &item);
|
|
|
|
|
|
void updateLinesPosition();
|
|
|
|
|
|
void clearLines();
|
|
|
|
|
|
void updatePolylineC(bool closed);
|
|
|
|
|
|
void clearPolylineC();
|
|
|
|
|
|
|
|
|
|
|
|
static QPointer<DraggableCrackItem> s_activeItem;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-04 16:54:55 +08:00
|
|
|
|
#endif
|