|
|
#pragma once
|
|
|
|
|
|
#include "nmDefines.h"
|
|
|
#include "ZxObjToolBase.h"
|
|
|
#include "nmPlot_global.h"
|
|
|
|
|
|
// 数值试井绘图对象之工具(基类)
|
|
|
class NM_PLOT_EXPORT nmObjToolBase : public ZxObjToolBase
|
|
|
{
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
nmObjToolBase();
|
|
|
|
|
|
public:
|
|
|
|
|
|
// 鼠标各种响应
|
|
|
virtual bool onLeftDown(const QPointF& pt) override;
|
|
|
virtual bool onLeftUp(const QPointF& pt) override;
|
|
|
virtual bool onMouseMove(const QPointF& pt) override;
|
|
|
virtual bool onMouseWheel(const QPointF& pt, int delta) override;
|
|
|
virtual bool onLeftDoubleClick(const QPointF& pt) override;
|
|
|
|
|
|
// 绘制
|
|
|
virtual void onPaint(QPainter* painter, const ZxPaintParam& param) override;
|
|
|
|
|
|
signals:
|
|
|
|
|
|
// 鼠标交互完成(双击)
|
|
|
void sigPtsFinished(QVector<QPointF>& vec);
|
|
|
// 仅取消临时绘制工具;命令层负责移除工具及复位工具栏,不创建业务对象。
|
|
|
void sigCreationCancelled();
|
|
|
|
|
|
public:
|
|
|
|
|
|
NM_Obj_Type getNOT();
|
|
|
|
|
|
// 创建工具挂入视图后启用十字光标,并在连续选点期间保持。
|
|
|
void beginCreationCursor();
|
|
|
// 完成、取消或切换工具前,释放本工具持有的光标状态。
|
|
|
void resetInteractionCursor();
|
|
|
// 由视图在框架松手收尾后调用,只刷新当前悬停光标,不触发编辑。
|
|
|
void refreshHoverCursor(const QPointF& pt);
|
|
|
// 取消当前绘制或尚未提交的左键移动;没有可取消操作时返回 false。
|
|
|
bool cancelInteraction();
|
|
|
|
|
|
protected:
|
|
|
|
|
|
// 裂缝、断层、区域显式启用公共光标规则,其他工具保留原有行为。
|
|
|
void enableInteractionCursor();
|
|
|
// 悬停命中统一映射为箭头、十字或张开的手形。
|
|
|
virtual Qt::CursorShape getCursorBy(const int& nOption, const int& nSubIndex) override;
|
|
|
|
|
|
// 裂缝、断层、区域显式开启 Esc 取消,与光标和吸附开关各自独立。
|
|
|
void enableEscapeCancellation();
|
|
|
// 创建取消时由子类丢弃自己的临时点集,不发送绘制完成信号。
|
|
|
virtual void clearCreationPoints();
|
|
|
|
|
|
// 三个点集创建工具共用:先吸附再选点,忽略与上一节点完全重合的点击。
|
|
|
// pt 为原始场景坐标;拒绝选点时保留原点集和预览起点,允许继续绘制。
|
|
|
void appendCreationPoint(QVector<QPointF>& points, const QPointF& pt);
|
|
|
// 双击完成创建:线至少有两个不同点,区域至少有三个不同且不全共线的点。
|
|
|
// 失败只提示并保留绘制;成功去掉区域重复的闭合末点、清理状态后发送完成信号。
|
|
|
void finishPolylineCreation(QVector<QPointF>& points, bool closed);
|
|
|
|
|
|
// 由支持节点编辑的工具显式开启;其他图元沿用原有交互。
|
|
|
void enablePointSnapping();
|
|
|
// 子类提供当前 Map 中可连接的场景坐标,并按数据对象身份排除自身。
|
|
|
virtual QVector<QPointF> pointSnapCandidates() const;
|
|
|
// 鼠标事件中刷新候选点并选取屏幕距离最近的目标,返回实际预览/提交位置。
|
|
|
QPointF updatePointSnap(const QPointF& pt);
|
|
|
// 读取上一次鼠标事件的吸附结果;没有目标时使用传入的原始场景坐标。
|
|
|
QPointF pointSnapPosition(const QPointF& pt) const;
|
|
|
// 仅绘制当前命中目标的绿色实心框;其他候选不显示,不查询数据或改变状态。
|
|
|
void paintPointSnapTargets(QPainter* painter) const;
|
|
|
// 操作结束或取消时清除吸附提示,防止残留到下一次操作。
|
|
|
void clearPointSnap();
|
|
|
// 工具退出时撤去提示;框架继续负责激活状态的收尾。
|
|
|
virtual void onDeactivated() override;
|
|
|
|
|
|
// 已选中图元双击线段时添加节点;bClosed 指定是否包含末点到首点的闭合边。
|
|
|
// 新节点取鼠标在线段上的投影,靠近已有节点时只消费事件,不重复添加。
|
|
|
// 返回 true 表示已处理双击,并接管随后的松手事件,避免误触发拖动或吸附。
|
|
|
bool insertPointOnDoubleClick(const QPointF& pt, bool bClosed);
|
|
|
|
|
|
NM_Obj_Type m_oNot; //内部类型标识,不涉及序列化
|
|
|
bool m_bCreationCancelled; // 临时工具已取消;阻止框架缓存的鼠标回调重新开始绘制。
|
|
|
|
|
|
private:
|
|
|
|
|
|
// 仅允许已开始移动的单节点拖动吸附;单击、整体移动和双击加点不参与。
|
|
|
bool isPointSnapDrag();
|
|
|
|
|
|
// 根据选择、锁定和命中位置决定光标;整体拖动时使用握紧的手形。
|
|
|
Qt::CursorShape interactionCursor(int nOption, bool dragging) const;
|
|
|
|
|
|
// 将创建检查的提示交给视图显示;空字符串清除当前提示。
|
|
|
void setCreationHint(const QString& hint);
|
|
|
|
|
|
// 当前操作开始后登记到所属视图,使按住鼠标时也能接收 Esc。
|
|
|
void registerCancellableInteraction();
|
|
|
|
|
|
bool m_bEscapeCancellationEnabled; // 仅三个点集编辑工具启用取消,不接管其他工具的 Esc。
|
|
|
bool m_bConsumeCancelledRelease; // 取消后等待左键松开,期间不再建立拖动或提交坐标。
|
|
|
bool m_bInteractionCursorEnabled; // 仅显式启用的三个工具使用统一光标。
|
|
|
bool m_bCreationCursorActive; // 记录本工具是否开启了视图的光标保持,便于成对释放。
|
|
|
bool m_bPointSnappingEnabled; // 仅裂缝、断层和区域启用公共节点吸附。
|
|
|
QVector<QPointF> m_vecSnapCandidates; // 当前鼠标事件查询到的候选点,使用场景坐标。
|
|
|
int m_nSnapTargetIndex; // 唯一吸附目标在缓存中的下标;-1 表示没有目标。
|
|
|
bool m_bConsumeInsertPointRelease; // 双击加点后,消费第二次点击的松手事件。
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|