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.
86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
#include <QPainter>
|
|
|
|
#include <QLineF>
|
|
#include <QtCore/qnumeric.h>
|
|
|
|
#include "ZxRenderView.h"
|
|
#include "nmObjLineMeasureTool.h"
|
|
#include "nmDataLogFile.h"
|
|
|
|
nmObjLineMeasureTool::nmObjLineMeasureTool()
|
|
{
|
|
setText(tr("nObjLineMeasureTool"));
|
|
m_oNot = NMOT_Line_Measure;
|
|
enableInteractionCursor();
|
|
enableEscapeCancellation();
|
|
nmDataLogFile::getInstance()->writeLog(" nmObjLineMeasureTool ++++++++ " + QString::number(m_oNot));
|
|
}
|
|
|
|
bool nmObjLineMeasureTool::onLeftDown(const QPointF& pt)
|
|
{
|
|
if (m_pObj == nullptr) {
|
|
beginCreationCursor(); // 每次按下重新登记,可连续取消多次测量。
|
|
}
|
|
return nmObjLineTool::onLeftDown(pt);
|
|
}
|
|
|
|
bool nmObjLineMeasureTool::onLeftUp(const QPointF& pt)
|
|
{
|
|
if (m_pObj != nullptr) return nmObjLineTool::onLeftUp(pt);
|
|
ZxRenderView* view = getView();
|
|
if (!m_bTracking || view == nullptr) return true;
|
|
|
|
const QPointF start = m_ptStart;
|
|
clearMeasurePreview();
|
|
if (!qIsFinite(start.x()) || !qIsFinite(start.y()) ||
|
|
!qIsFinite(pt.x()) || !qIsFinite(pt.y())) {
|
|
return true;
|
|
}
|
|
|
|
// 真正的单击可为首次拟合井位提供参考点,提交时再检查是否已有结果。
|
|
if (start != pt) {
|
|
const qreal pixelLength = QLineF(view->mapFromScene(start), view->mapFromScene(pt)).length();
|
|
const qreal minimumPixels = 3.0;
|
|
if (!qIsFinite(pixelLength) || pixelLength < minimumPixels) return true;
|
|
}
|
|
|
|
QVector<QPointF> points;
|
|
points << start << pt;
|
|
emit sigPtsFinished(points);
|
|
return true;
|
|
}
|
|
|
|
bool nmObjLineMeasureTool::cancelInteraction()
|
|
{
|
|
if (m_pObj != nullptr) return nmObjToolBase::cancelInteraction();
|
|
if (!m_bTracking || getView() == nullptr || getCompoundTool() == nullptr || !isEnabled()) {
|
|
return false;
|
|
}
|
|
|
|
clearMeasurePreview();
|
|
return true;
|
|
}
|
|
|
|
void nmObjLineMeasureTool::clearMeasurePreview()
|
|
{
|
|
m_bTracking = false; // 取消后收到的松手事件不会再提交。
|
|
if (ZxRenderView* view = getView()) {
|
|
view->setSnapshotMode(false);
|
|
updateScene();
|
|
}
|
|
}
|
|
|
|
void nmObjLineMeasureTool::onPaint(QPainter* painter, const ZxPaintParam& param)
|
|
{
|
|
if (m_pObj != nullptr) {
|
|
nmObjLineTool::onPaint(painter, param);
|
|
return;
|
|
}
|
|
if (!m_bTracking) return;
|
|
|
|
painter->save();
|
|
painter->setPen(QPen(Qt::DashLine));
|
|
painter->drawLine(m_ptStart, getCurrentPos());
|
|
painter->restore();
|
|
}
|