|
|
#include <QPainter>
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
#include "ZxObjBase.h"
|
|
|
|
|
|
#include "nmObjLineCrackTool.h"
|
|
|
#include "nmDataLogFile.h"
|
|
|
|
|
|
#include "nmObjLineCrack.h"
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
#include "nmObjPointWell.h"
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
|
nmObjLineCrackTool::nmObjLineCrackTool()
|
|
|
: nmObjToolBase()
|
|
|
, m_pCurPlot(nullptr)
|
|
|
{
|
|
|
setText(tr("nObjLineFractureTool"));
|
|
|
m_oNot = NMOT_Line_Fracture;
|
|
|
nmDataLogFile::getInstance()->writeLog(" nmObjLineCrackTool ++++++++ " + QString::number(m_oNot));
|
|
|
m_vecPoints.clear();
|
|
|
enablePointSnapping();
|
|
|
enableInteractionCursor();
|
|
|
enableEscapeCancellation();
|
|
|
}
|
|
|
|
|
|
|
|
|
bool nmObjLineCrackTool::onLeftDown(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 取消的临时工具不再接收新点。
|
|
|
}
|
|
|
if (m_pObj != nullptr) {
|
|
|
return nmObjToolBase::onLeftDown(pt);
|
|
|
}
|
|
|
|
|
|
// 公共选点入口统一吸附和重复点防护;拒绝重复点时保留原预览起点。
|
|
|
appendCreationPoint(m_vecPoints, pt);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmObjLineCrackTool::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 nmObjLineCrackTool::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 nmObjLineCrackTool::onLeftDoubleClick(const QPointF& pt)
|
|
|
{
|
|
|
if (m_bCreationCancelled) {
|
|
|
return true; // 取消不能转成双击完成。
|
|
|
}
|
|
|
if (m_pObj == nullptr) {
|
|
|
// 检查失败仍消费双击,保留当前工具及已选节点,等待继续绘制。
|
|
|
finishPolylineCreation(m_vecPoints, false);
|
|
|
return true;
|
|
|
}
|
|
|
if (insertPointOnDoubleClick(pt, false)) {
|
|
|
return true;
|
|
|
}
|
|
|
return nmObjToolBase::onLeftDoubleClick(pt);
|
|
|
}
|
|
|
|
|
|
void nmObjLineCrackTool::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 nmObjLineCrackTool::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 nmObjLineCrackTool::paintTrackingRealObj(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
if (!m_bTracking)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
nmObjLineCrack* pObj = dynamic_cast<nmObjLineCrack*>(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> nmObjLineCrackTool::pointSnapCandidates() const
|
|
|
{
|
|
|
return nmPlotGraphicBinder::pointSnapCandidates(getView(), m_pObj);
|
|
|
}
|
|
|
|
|
|
void nmObjLineCrackTool::clearCreationPoints()
|
|
|
{
|
|
|
m_vecPoints.clear();
|
|
|
}
|