|
|
#include <QPainter>
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
#include "ZxObjBase.h"
|
|
|
|
|
|
#include "nmObjLineFaultTool.h"
|
|
|
#include "nmDataLogFile.h"
|
|
|
|
|
|
#include "nmObjLineFault.h"
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
#include "nmObjPointWell.h"
|
|
|
|
|
|
nmObjLineFaultTool::nmObjLineFaultTool()
|
|
|
{
|
|
|
setText(tr("nObjLineFaultTool"));
|
|
|
m_oNot = NMOT_Line_Fault;
|
|
|
nmDataLogFile::getInstance()->writeLog(" nmObjLineCrackTool ++++++++ " + QString::number(m_oNot));
|
|
|
m_vecPoints.clear();
|
|
|
enablePointSnapping();
|
|
|
enableInteractionCursor();
|
|
|
enableEscapeCancellation();
|
|
|
}
|
|
|
|
|
|
nmObjLineFaultTool::~nmObjLineFaultTool()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
bool nmObjLineFaultTool::onLeftDown(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 取消的临时工具不再接收新点。
|
|
|
}
|
|
|
if (m_pObj != nullptr) {
|
|
|
return nmObjToolBase::onLeftDown(pt);
|
|
|
}
|
|
|
|
|
|
// 创建时点击提交的坐标,与移动预览使用同一个吸附计算入口。
|
|
|
m_bTracking = true;
|
|
|
beginCreationCursor();
|
|
|
m_ptMove = pt;
|
|
|
m_ptStart = updatePointSnap(pt);
|
|
|
m_vecPoints.push_back(m_ptStart);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmObjLineFaultTool::onMouseMove(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 框架仍可能回调旧工具,禁止恢复预览和十字光标。
|
|
|
}
|
|
|
if (m_pObj != nullptr) {
|
|
|
return nmObjToolBase::onMouseMove(pt);
|
|
|
}
|
|
|
|
|
|
// 保留原始鼠标位置;预览读取公共吸附结果,绘制阶段不再查询数据。
|
|
|
m_ptMove = pt;
|
|
|
beginCreationCursor();
|
|
|
updatePointSnap(pt);
|
|
|
if (m_bTracking) {
|
|
|
updateLastMoveArea(true);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmObjLineFaultTool::onLeftUp(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 消费取消后仍在队列中的松手事件。
|
|
|
}
|
|
|
if (m_pObj != nullptr) {
|
|
|
// 公共工具区分单节点拖动、整体移动以及双击后的松手。
|
|
|
return nmObjToolBase::onLeftUp(pt);
|
|
|
}
|
|
|
if (!m_vecPoints.isEmpty()) {
|
|
|
updateLastMoveArea(true);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmObjLineFaultTool::onLeftDoubleClick(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 取消不能转成双击完成。
|
|
|
}
|
|
|
nmObjLineFault* pObj = dynamic_cast<nmObjLineFault*>(m_pObj);
|
|
|
if(NULL == pObj) { // 绘图对象尚未创建(鼠标选点ing)
|
|
|
// 点数不足时吞掉双击,避免误结束创建流程。
|
|
|
if (m_vecPoints.count() < 2) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
resetInteractionCursor();
|
|
|
clearPointSnap();
|
|
|
emit sigPtsFinished(m_vecPoints);
|
|
|
m_vecPoints.clear();
|
|
|
|
|
|
if(m_bTracking) {
|
|
|
m_bTracking = false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
} else { // 已绑定绘图对象
|
|
|
if (insertPointOnDoubleClick(pt, false)) {
|
|
|
return true;
|
|
|
}
|
|
|
return nmObjToolBase::onLeftDoubleClick(pt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmObjLineFaultTool::onPaint(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
if (m_pObj == nullptr) {
|
|
|
if (!m_bTracking && !m_vecPoints.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
paintTrackingVirtualObj(painter, param);
|
|
|
} else {
|
|
|
paintTrackingRealObj(painter, param);
|
|
|
}
|
|
|
// 吸附标记画在预览上方,避免区域填充遮住唯一目标。
|
|
|
paintPointSnapTargets(painter);
|
|
|
}
|
|
|
|
|
|
void nmObjLineFaultTool::paintTrackingVirtualObj(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
painter->save();
|
|
|
|
|
|
// 已经选的点
|
|
|
{
|
|
|
QPen pen(Qt::SolidLine);
|
|
|
painter->setPen(pen);
|
|
|
|
|
|
for(int i = 0; i < m_vecPoints.count() - 1; i++) {
|
|
|
painter->drawLine(m_vecPoints[i], m_vecPoints[i + 1]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 当前正在进行的点
|
|
|
if(m_bTracking || !m_vecPoints.isEmpty()) {
|
|
|
QPen pen(Qt::DashLine);
|
|
|
painter->setPen(pen);
|
|
|
painter->drawLine(m_ptStart, pointSnapPosition(m_ptMove));
|
|
|
}
|
|
|
|
|
|
painter->restore();
|
|
|
}
|
|
|
|
|
|
void nmObjLineFaultTool::paintTrackingRealObj(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
if(!m_bTracking) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
nmObjLineFault* pObj = dynamic_cast<nmObjLineFault*>(m_pObj);
|
|
|
Q_ASSERT(NULL != pObj);
|
|
|
|
|
|
if (nullptr == pObj)
|
|
|
{
|
|
|
return; // 如果pObj为nullptr,直接返回
|
|
|
}
|
|
|
|
|
|
int nIndex = pObj->m_nHitIndex;
|
|
|
|
|
|
QVector<QPointF> vec = pObj->getAllPos();
|
|
|
QPointF ptOld = m_ptStart;
|
|
|
QPointF ptNew = getCurrentPos();
|
|
|
|
|
|
if(m_oHitOption == OHO_Point) {
|
|
|
if(nIndex >= 0 && nIndex < vec.count()) {
|
|
|
vec[nIndex] = pointSnapPosition(getCurrentPos());
|
|
|
}
|
|
|
} else if(m_oHitOption == OHO_Bound) {
|
|
|
for(int i = 0; i < vec.count(); i++) {
|
|
|
vec[i] = pObj->offsetPoint(vec[i], ptOld, ptNew);
|
|
|
}
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
painter->save();
|
|
|
QPen pen(Qt::DashLine);
|
|
|
painter->setPen(pen);
|
|
|
|
|
|
for(int i = 0; i < vec.count() - 1; i++) {
|
|
|
painter->drawLine(vec[i], vec[i + 1]);
|
|
|
}
|
|
|
|
|
|
painter->restore();
|
|
|
}
|
|
|
|
|
|
QVector<QPointF> nmObjLineFaultTool::pointSnapCandidates() const
|
|
|
{
|
|
|
return nmPlotGraphicBinder::pointSnapCandidates(getView(), m_pObj);
|
|
|
}
|
|
|
|
|
|
void nmObjLineFaultTool::clearCreationPoints()
|
|
|
{
|
|
|
m_vecPoints.clear();
|
|
|
}
|