|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
|
#include "nmObjRegion.h"
|
|
|
|
|
|
#include "nmObjRegionTool.h"
|
|
|
|
|
|
#include "nmObjPointWell.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
|
|
|
|
|
|
|
nmObjRegionTool::nmObjRegionTool() : nmObjToolBase()
|
|
|
|
|
|
, m_pCurPlot(nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
setText(tr("nObjRegionTool"));
|
|
|
|
|
|
m_oNot = NMOT_Region;
|
|
|
|
|
|
enablePointSnapping();
|
|
|
|
|
|
enableInteractionCursor();
|
|
|
|
|
|
enableEscapeCancellation();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionTool::onLeftDown(const QPointF& pt)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bCreationCancelled) {
|
|
|
|
|
|
return true; // 取消的临时工具不再接收新点。
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pObj != nullptr) {
|
|
|
|
|
|
return nmObjToolBase::onLeftDown(pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 公共选点入口统一吸附和重复点防护;拒绝重复点时保留原预览起点。
|
|
|
|
|
|
appendCreationPoint(m_vecPoints, pt);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionTool::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 nmObjRegionTool::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 nmObjRegionTool::onLeftDoubleClick(const QPointF& pt)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bCreationCancelled) {
|
|
|
|
|
|
return true; // 取消不能转成双击完成。
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pObj == nullptr) {
|
|
|
|
|
|
// 检查失败仍消费双击,保留当前工具及已选节点,等待继续绘制。
|
|
|
|
|
|
finishPolylineCreation(m_vecPoints, true);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (insertPointOnDoubleClick(pt, true)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return nmObjToolBase::onLeftDoubleClick(pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjRegionTool::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 nmObjRegionTool::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);
|
|
|
|
|
|
// 两条预览边共用实际吸附位置,确保闭合轮廓与点击后的落点一致。
|
|
|
|
|
|
const QPointF previewPos = pointSnapPosition(m_ptMove);
|
|
|
|
|
|
painter->drawLine(m_ptStart, previewPos);
|
|
|
|
|
|
if (m_vecPoints.count() >= 2) {
|
|
|
|
|
|
// 已确定两个节点后,补上当前落点到首点的闭合虚线。
|
|
|
|
|
|
painter->drawLine(previewPos, m_vecPoints.first());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjRegionTool::paintTrackingRealObj(QPainter* painter, const ZxPaintParam& param)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!m_bTracking) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmObjRegion* pObj = dynamic_cast<nmObjRegion*>(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);
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath oPath;
|
|
|
|
|
|
oPath.moveTo(vec[0]);
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 1; i < vec.count(); i++) {
|
|
|
|
|
|
oPath.lineTo(vec[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oPath.closeSubpath();
|
|
|
|
|
|
|
|
|
|
|
|
// 预览填充使用约 19% 的不透明度,减轻对下方井、裂缝等图元的遮挡。
|
|
|
|
|
|
QColor clr = pObj->getBackgrdColor();
|
|
|
|
|
|
clr.setAlpha(48);
|
|
|
|
|
|
painter->fillPath(oPath, QBrush(clr));
|
|
|
|
|
|
// 在填充上方绘制闭合虚线;strokePath 只描边,避免继承画刷再次填充。
|
|
|
|
|
|
painter->strokePath(oPath, pen);
|
|
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> nmObjRegionTool::pointSnapCandidates() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return nmPlotGraphicBinder::pointSnapCandidates(getView(), m_pObj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjRegionTool::stepBackCreation(bool autoRepeat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return stepBackCreationPoints(m_vecPoints, autoRepeat);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjRegionTool::clearCreationPoints()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_vecPoints.clear();
|
|
|
|
|
|
}
|