|
|
|
|
|
#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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建时点击提交的坐标,与移动预览使用同一个吸附计算入口。
|
|
|
|
|
|
m_bTracking = true;
|
|
|
|
|
|
beginCreationCursor();
|
|
|
|
|
|
m_ptMove = pt;
|
|
|
|
|
|
m_ptStart = updatePointSnap(pt);
|
|
|
|
|
|
m_vecPoints.push_back(m_ptStart);
|
|
|
|
|
|
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(NULL == m_pObj) {
|
|
|
|
|
|
// 区域至少需要 3 个点才能闭合成有效面,点数不足时吞掉双击。
|
|
|
|
|
|
if (m_vecPoints.count() < 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resetInteractionCursor();
|
|
|
|
|
|
clearPointSnap();
|
|
|
|
|
|
emit sigPtsFinished(m_vecPoints);
|
|
|
|
|
|
|
|
|
|
|
|
m_vecPoints.clear();
|
|
|
|
|
|
|
|
|
|
|
|
if(m_bTracking)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bTracking = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 双击已完成本工具的处理,这里直接消费事件。
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
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);
|
|
|
|
|
|
painter->drawLine(m_ptStart, pointSnapPosition(m_ptMove));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath oPath;
|
|
|
|
|
|
oPath.moveTo(vec[0]);
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 1; i < vec.count(); i++) {
|
|
|
|
|
|
oPath.lineTo(vec[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oPath.closeSubpath();
|
|
|
|
|
|
|
|
|
|
|
|
QColor clr = pObj->getBackgrdColor();
|
|
|
|
|
|
clr.setAlpha(128);
|
|
|
|
|
|
painter->fillPath(oPath, QBrush(clr));
|
|
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector<QPointF> nmObjRegionTool::pointSnapCandidates() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return nmPlotGraphicBinder::pointSnapCandidates(getView(), m_pObj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjRegionTool::clearCreationPoints()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_vecPoints.clear();
|
|
|
|
|
|
}
|