|
|
#include <QPainter>
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
#include "ZxObjBase.h"
|
|
|
|
|
|
#include "nmObjLineCrackTool.h"
|
|
|
#include "nmDataLogFile.h"
|
|
|
|
|
|
#include "nmObjLineCrack.h"
|
|
|
|
|
|
#include "nmObjPointWell.h"
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
|
#include "nmDataAnalyzeManager.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();
|
|
|
|
|
|
// 在数据中心获取所有可连接的点(屏幕坐标)
|
|
|
m_vecCurAllPts = nmDataAnalyzeManager::getCurrentInstance()->getPosAllConnectablePoints();
|
|
|
}
|
|
|
|
|
|
|
|
|
bool nmObjLineCrackTool::onLeftDown(const QPointF& pt)
|
|
|
{
|
|
|
if (NULL == m_pObj) //绘图对象尚未创建(鼠标选点ing)
|
|
|
{
|
|
|
m_bTracking = true;
|
|
|
QPointF p = pt;
|
|
|
|
|
|
changeCursor(Qt::CrossCursor);
|
|
|
|
|
|
// 对于持续性选点的工具,需要设置
|
|
|
getView()->setCursorKeeping(true);
|
|
|
|
|
|
// 判断鼠标是否点击了之前的点中
|
|
|
for (int i = 0; i < m_vecCurAllPts.count(); i++)
|
|
|
{
|
|
|
double nDistance = 2.2f;
|
|
|
if ((qAbs(m_vecCurAllPts[i].x() - p.x()) < nDistance) && \
|
|
|
(qAbs(m_vecCurAllPts[i].y() - p.y()) < nDistance))
|
|
|
{
|
|
|
// 更新当前点的坐标
|
|
|
p = m_vecCurAllPts[i];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
m_ptStart = p;
|
|
|
m_vecPoints.push_back(p);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
else //业已绑定绘图对象
|
|
|
{
|
|
|
return nmObjToolBase::onLeftDown(pt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool nmObjLineCrackTool::onMouseMove(const QPointF& pt)
|
|
|
{
|
|
|
if (NULL == m_pObj) //绘图对象尚未创建(鼠标选点ing)
|
|
|
{
|
|
|
m_ptMove = pt;
|
|
|
if (m_bTracking)
|
|
|
{
|
|
|
updateLastMoveArea(true);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
else // 已绑定绘图对象
|
|
|
{
|
|
|
return nmObjToolBase::onMouseMove(pt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool nmObjLineCrackTool::onLeftUp(const QPointF& pt)
|
|
|
{
|
|
|
QPointF p = pt;
|
|
|
if (NULL == m_pObj) // 绘图对象尚未创建(鼠标选点ing)
|
|
|
{
|
|
|
if (!m_vecPoints.isEmpty()) // 避免本工具被Detach之后无法update
|
|
|
{
|
|
|
updateLastMoveArea(true);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
} else {// 已绑定绘图对象
|
|
|
if(m_pObj->isSelected()){
|
|
|
double dDistance = 2.2f;
|
|
|
for(int i = 0; i < m_vecCurAllPts.count(); i++) {
|
|
|
if((qAbs(m_vecCurAllPts[i].x() - pt.x()) < dDistance) && \
|
|
|
(qAbs(m_vecCurAllPts[i].y() - pt.y()) < dDistance) && \
|
|
|
m_oHitOption == OHO_Point)
|
|
|
{
|
|
|
p = m_vecCurAllPts[i];
|
|
|
}
|
|
|
}
|
|
|
return nmObjToolBase::onLeftUp(p);
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool nmObjLineCrackTool::onLeftDoubleClick(const QPointF& pt)
|
|
|
{
|
|
|
if (NULL == m_pObj) // 绘图对象尚未创建(鼠标选点ing)
|
|
|
{
|
|
|
changeCursor(Qt::ArrowCursor);
|
|
|
emit sigPtsFinished(m_vecPoints);
|
|
|
//m_vecPoints.clear();
|
|
|
//m_vecCurAllPts.clear();
|
|
|
|
|
|
if (m_bTracking)
|
|
|
{
|
|
|
m_bTracking = false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
else // 已绑定绘图对象
|
|
|
{
|
|
|
return nmObjToolBase::onLeftDoubleClick(pt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmObjLineCrackTool::onPaint(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
|
|
|
nmObjLineCrack* pObj = dynamic_cast<nmObjLineCrack*>(m_pObj);
|
|
|
|
|
|
if(pObj == NULL) { // 绘图对象尚未创建(鼠标选点ing)
|
|
|
|
|
|
// 绘制结束,返回
|
|
|
if(!m_bTracking && m_vecPoints.size() > 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Qt::CursorShape o = Qt::CrossCursor;
|
|
|
changeCursor(o);
|
|
|
|
|
|
// 获取当期画布的所有点
|
|
|
painter->save();
|
|
|
|
|
|
// 将需要选中的点绘制正方形
|
|
|
double dDistance = 2.2f;
|
|
|
for(int i = 0; i < m_vecCurAllPts.count(); i++) {
|
|
|
QPointF pt = m_vecCurAllPts[i];
|
|
|
QRectF rect(pt.x() - dDistance * 0.5f, pt.y() - dDistance * 0.5f, dDistance, dDistance);
|
|
|
painter->setPen(QPen(QBrush(Qt::black), \
|
|
|
0.5f, Qt::SolidLine));
|
|
|
painter->drawRect(rect);
|
|
|
}
|
|
|
|
|
|
// 判断鼠标是否进入了某个点的范围,填充捕捉到的矩形背景
|
|
|
for(int i = 0; i < m_vecCurAllPts.count(); i++) {
|
|
|
if((qAbs(m_vecCurAllPts[i].x() - m_ptMove.x()) < dDistance) && \
|
|
|
(qAbs(m_vecCurAllPts[i].y() - m_ptMove.y()) < dDistance)) {
|
|
|
// 修改当前点的的状态
|
|
|
QPointF pt = m_vecCurAllPts[i];
|
|
|
QRectF rect(pt.x() - dDistance * 0.5f, pt.y() - dDistance * 0.5f, dDistance, dDistance);
|
|
|
QPen pen(QBrush(Qt::black), 0.5f, Qt::DotLine);
|
|
|
painter->setPen(pen);
|
|
|
painter->drawRect(rect);
|
|
|
QBrush br(Qt::green);
|
|
|
painter->fillRect(rect, br);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
paintTrackingVirtualObj(painter, param);
|
|
|
} else { // 已绑定绘图对象
|
|
|
if(m_pObj->isSelected()){
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
m_vecCurAllPts.clear();
|
|
|
m_vecCurAllPts = nmDataAnalyzeManager::getCurrentInstance()->removePosByObject(pObj->getFractureData());
|
|
|
|
|
|
// 将需要选中的点绘制正方形
|
|
|
double dDistance = 2.2f;
|
|
|
for(int i = 0; i < m_vecCurAllPts.count(); i++) {
|
|
|
|
|
|
QPointF pt = m_vecCurAllPts[i];
|
|
|
QRectF rect(pt.x() - dDistance * 0.5f, pt.y() - dDistance * 0.5f, dDistance, dDistance);
|
|
|
painter->setPen(QPen(QBrush(Qt::black), \
|
|
|
0.5f, Qt::SolidLine));
|
|
|
painter->drawRect(rect);
|
|
|
}
|
|
|
for(int i = 0; i < m_vecCurAllPts.count(); i++)
|
|
|
{
|
|
|
if((qAbs(m_vecCurAllPts[i].x() - m_ptMove.x()) < dDistance) && \
|
|
|
(qAbs(m_vecCurAllPts[i].y() - m_ptMove.y()) < dDistance) && \
|
|
|
m_oHitOption == OHO_Point) {
|
|
|
|
|
|
// 修改当前点的的状态
|
|
|
QPointF pt = m_vecCurAllPts[i];
|
|
|
QRectF rect(pt.x() - dDistance * 0.5f, pt.y() - dDistance * 0.5f, dDistance, dDistance);
|
|
|
QPen pen(QBrush(Qt::black), 0.5f, Qt::DotLine);
|
|
|
painter->setPen(pen);
|
|
|
painter->drawRect(rect);
|
|
|
QBrush br(Qt::green);
|
|
|
painter->fillRect(rect, br);
|
|
|
}
|
|
|
}
|
|
|
painter->restore();
|
|
|
}
|
|
|
paintTrackingRealObj(painter, param);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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, 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;
|
|
|
Qt::CursorShape o = getCursorBy((int)m_oHitOption, nIndex);
|
|
|
|
|
|
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] = 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]);
|
|
|
}
|
|
|
|
|
|
changeCursor(o);
|
|
|
|
|
|
painter->restore();
|
|
|
}
|
|
|
|
|
|
Qt::CursorShape nmObjLineCrackTool::getCursorBy(const int& nOption,
|
|
|
const int& nSubIndex)
|
|
|
{
|
|
|
if (nOption < 0)
|
|
|
{
|
|
|
return Qt::ArrowCursor;
|
|
|
}
|
|
|
|
|
|
// 选择状态下起作用
|
|
|
if (!m_pObj->isSelected()) {
|
|
|
return Qt::ArrowCursor;
|
|
|
}
|
|
|
|
|
|
ObjHitOption oHitOption = (ObjHitOption)nOption;
|
|
|
if (oHitOption == OHO_Point)
|
|
|
{
|
|
|
return (Qt::CrossCursor);
|
|
|
}
|
|
|
else if (oHitOption == OHO_Bound)
|
|
|
{
|
|
|
return (Qt::CrossCursor);
|
|
|
}
|
|
|
|
|
|
return Qt::ArrowCursor;
|
|
|
}
|