You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/nmNum/nmPlot/nmObjBase.h

90 lines
4.0 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "ZxObjBase.h"
#include "nmPlot_global.h"
// 数值试井绘图对象(基类)
class NM_PLOT_EXPORT nmObjBase : public ZxObjBase
{
Q_OBJECT
ZX_DECLARE_DYNAMIC
public:
nmObjBase();
nmObjBase(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY);
~nmObjBase();
virtual void paintBack(QPainter* painter, \
const ZxPaintParam& param) override;
virtual void afterCreated();
// 画笔修改后通知绑定器,供边界立即同步保存所需的样式。
virtual void setPen(QPen pen) override;
// 返回本地图会话内的编辑标识,首次记录该图元时生成。
QString historyId();
// 将历史记录中的原标识设到重建的图元上,使此前的编辑命令仍能找到它。
void setHistoryId(const QString& id);
// 仅在指定画布内查找该标识对应的当前图元,目标不存在时返回空指针。
static nmObjBase* findHistoryObject(ZxPlot* plot, const QString& id);
// 提交移动、调整大小或加点后的完整点集。positions 使用场景坐标,
// 单点插入时传入 insertedPointIndex,供历史只回放该点和对应的新边。
bool commitPointPositions(const QVector<QPointF>& positions, int insertedPointIndex = -1);
// 提交参数编辑后的模型坐标。成果加载直接使用框架的 setAllValues。
bool commitPointValues(const QVector<QPointF>& values);
// 回放点集并保留图元通知,绑定器可据此限定井位回写的范围。
void applyHistoryPointValues(const QVector<QPointF>& values);
bool isApplyingGeometryHistory() const { return m_bApplyingGeometryHistory; }
// 删除图元数据对象
virtual void removeData();
// 绘制固定逻辑像素大小的节点框,供选中节点和吸附目标共用。
// pt 使用当前画笔坐标;nPixelSize 包含边框,borderColor 指定细边颜色。
// fillColor 无效时绘制空心框,传入有效颜色时绘制实心框。
// 函数只负责绘制,并恢复画笔状态,不改变节点坐标或交互状态。
static void paintNodeHandle(QPainter* painter, const QPointF& pt,
int nPixelSize, const QColor& borderColor,
const QColor& fillColor = QColor());
signals:
void sigMapPenChanged();
protected:
// 将下标 index 处的节点移到鼠标松手时的场景坐标 position。
// 由公共点集提交函数记录历史,返回本次移动是否改变了点集。
bool moveNodeToPosition(int index, const QPointF& position);
// 提交属性面板修改的单个模型坐标,与鼠标拖动共用地图历史。
bool commitPointCoordinate(int index, Qt::Orientation axis, double value);
enum { NodeHitRadiusPixels = 5, OutlineHitRadiusPixels = 4 };
// 点集图元共用的纯命中查询:pt 为场景坐标,点集读取当前对象。
// 在所属视图内按逻辑像素判断:节点半径 5,线段距离 4,节点优先且取最近项。
// closed 决定是否包含末点到首点的闭合边;命中线段时返回其起点下标。
// includeSelectedInterior 由矩形、多边形按需启用,边线未命中后允许选中对象的内部整体拖动。
// 只填写输出参数,不修改点集或选中状态;未命中时类型和下标均为 -1。
bool hitTestPolylineInPixels(const QPointF& pt, bool closed,
int& nOption, int& nSubIndex,
bool includeSelectedInterior = false);
// 选中节点统一为 5 像素蓝色空心框;当前命中节点保留红色实心提示。
// firstIndex 用于跳过圆心、半径等占位数据,同时保留原始命中下标。
void paintSelectedNodeHandles(QPainter* painter, const QVector<QPointF>& points,
int firstIndex = 0) const;
private:
bool m_bApplyingGeometryHistory; // 仅在历史回放发出点集通知期间为真。
};