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.
nmWTAI-Platform/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp

595 lines
23 KiB
C++

#include "ZxBaseUtil.h"
#include "zxLogInstance.h"
#include <QAction>
#include <QLineF>
#include <QWidget>
#include <QtCore/qnumeric.h>
#include "ZxPlot.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "iGuiPlot.h"
#include "nmObjBase.h"
#include "nmObjPointTool.h"
#include "nmObjLineTool.h"
#include "nmObjPolygonTool.h"
#include "nmObjPolygonOutlineTool.h"
#include "nmObjLineCrackTool.h"
#include "nmObjLineCrack.h"
#include "nmObjLineFaultTool.h"
#include "nmObjLineFault.h"
#include "nmObjLineMeasuringScaleTool.h"
#include "nmObjPointWellTool.h"
#include "nmObjPointWell.h"
#include "nmObjLineMeasureTool.h"
#include "nmObjLineMeasure.h"
#include "nmGuiPlot.h"
#include "nmGuiPlotCmdHelper.h"
#include "nmMapObjectState.h"
#include "nmPlotView.h"
#include "nmPlotGraphicBinder.h"
#include "nmDataLogFile.h"
#include "nmObjRectTool.h"
#include "nmObjRectOutlineTool.h"
#include "nmObjRectOutline.h"
#include "nmObjRoundTool.h"
#include "nmObjRoundOutlineTool.h"
#include "nmObjRoundOutline.h"
#include "nmObjPolygonOutline.h"
#include "nmObjRegionMark.h"
#include "nmObjRegionTool.h"
#include "nmObjDeleteTool.h"
#include "nmPlotDialogContext.h"
#include "nmPlotDialogContextProvider.h"
#include "nmObjRegionMarkTool.h"
namespace {
bool isBoundaryObject(ZxObjBase* obj)
{
return dynamic_cast<nmObjRectOutline*>(obj) != nullptr ||
dynamic_cast<nmObjRoundOutline*>(obj) != nullptr ||
dynamic_cast<nmObjPolygonOutline*>(obj) != nullptr;
}
} // namespace
nmGuiPlotCmdHelper::nmGuiPlotCmdHelper(iGuiPlot* p)
: iGuiPlotCmdHelper(p) {
}
nmGuiPlotCmdHelper::~nmGuiPlotCmdHelper() {
}
void nmGuiPlotCmdHelper::fuzzyCheckStates(QAction* pAction, bool& bRepeatedHit)
{
iGuiPlotCmdHelper::fuzzyCheckStates(pAction, bRepeatedHit);
if (pAction != nullptr && pAction->objectName() == QLatin1String("Select")) {
// 测量等工具启动后,选择按钮可能仍处于选中状态。
bRepeatedHit = false;
pAction->setChecked(true);
}
}
bool nmGuiPlotCmdHelper::runAction(QString sAction) {
Q_ASSERT (NULL != m_pGuiPlot);
ZxPlot* pPlot = m_pGuiPlot->m_pPlot;
Q_ASSERT (NULL != pPlot);
nmGuiPlot* pNmPlot = static_cast<nmGuiPlot*>(m_pGuiPlot);
const bool undo = _isSame(sAction, "Undo");
if (undo || _isSame(sAction, "Redo")) {
QPointer<nmPlotView> view = qobject_cast<nmPlotView*>(pNmPlot->m_pPlotView);
if (!view.isNull() && view->canReplayMapEdit(undo)) {
// 先退出临时工具,再应用已提交的编辑记录。
cancelActiveTools();
if (view.isNull() || !view->canReplayMapEdit(undo)) return true;
if (undo) {
view->mapEditHistory()->undo();
} else {
view->mapEditHistory()->redo();
}
}
return true;
}
// 清除图元选中状态
const bool isMeasureAction = _isSame(sAction, "nmInsertObjLineMeasure");
if (pNmPlot->isMapEditingLocked() &&
((_isSame(sAction, "nmDeleteOneObj")) ||
(sAction.startsWith(QLatin1String("nmInsert"), Qt::CaseInsensitive) && !isMeasureAction))) {
return true;
}
if (isMeasureAction && m_activeTools.contains(NMOT_Line_Measure)) {
return true;
}
stopMeasureTool(pNmPlot);
pNmPlot->clearPlotsSelectStates();
// 清除上次的工具
foreach (nmObjToolBase* oldTool, m_activeTools.values()) {
// 移除工具不会保证触发停用回调,切换命令前主动清理工具光标。
if (nmObjDeleteTool* deleteTool = dynamic_cast<nmObjDeleteTool*>(oldTool)) {
deleteTool->resetDeleteCursor();
}
oldTool->resetInteractionCursor();
pPlot->removeTools(oldTool);
}
m_activeTools.clear();
// 绘制前确认替换意图,提交新图元前保留原边界。
if (sAction == "nmInsertObjPolygonOutline" || \
sAction == "nmInsertObjRectOutline" || \
sAction == "nmInsertObjRoundOutline" )
{
const QString sTargetOutlineTag = sAction == "nmInsertObjRectOutline"
? QLatin1String("nObjRectOutline")
: (sAction == "nmInsertObjRoundOutline"
? QLatin1String("nObjRoundOutline") : QLatin1String("nObjPolygonOutline"));
for (int i = pPlot->getObjCount() - 1; i >= 0; --i) {
ZxObjBase* obj = pPlot->getObjByIndex(i);
if (!isBoundaryObject(obj)) continue;
nmPlotDialogContextProvider* provider = nmPlotDialogContext::provider();
if (provider == nullptr ||
!provider->confirmSwitchOutline(pNmPlot, obj->getTagName(), sTargetOutlineTag)) {
return false;
}
break; // 地图只保留一个业务边界。
}
}
nmDataLogFile::getInstance()->writeLog(" cmdHelper " + sAction);
// 鼠标交互,插入数值试井绘图对象 的例子:点、线、多边形
if (_isSame(sAction, "nmInsertObjPoint")) {
nmObjToolBase* pObjTool = new nmObjPointTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjPointWell")) {
nmObjToolBase* pObjTool = new nmObjPointWellTool();
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjLine")) {
nmObjToolBase* pObjTool = new nmObjLineTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjPolygon")) {
nmObjToolBase* pObjTool = new nmObjPolygonTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjPolygonOutline")) {
nmObjToolBase* pObjTool = new nmObjPolygonOutlineTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjRect")) {
nmObjToolBase* pObjTool = new nmObjRectTool(); //矩形对象工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjRectOutline")) {
nmObjToolBase* pObjTool = new nmObjRectOutlineTool(); //矩形边界工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjRound")) {
nmObjToolBase* pObjTool = new nmObjRoundTool(); //圆形对象工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjRoundOutline")) {
nmObjToolBase* pObjTool = new nmObjRoundOutlineTool(); //圆形边界工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(pObjTool->getNOT(), pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjLineCrack")) {
nmObjToolBase* pObjTool = new nmObjLineCrackTool();
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(NMOT_Line_Fracture, pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjLineFault")) {
nmObjToolBase* pObjTool = new nmObjLineFaultTool();
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(NMOT_Line_Fault, pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjRegion")) {
nmObjToolBase* pObjTool = new nmObjRegionTool();
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
pObjTool->beginCreationCursor();
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(NMOT_Region, pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertObjLineMeasuringScale")) {
nmObjToolBase* pObjTool = new nmObjLineMeasuringScaleTool();
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(NMOT_Line_MeasuringScale, pObjTool);
pObjTool->beginCreationCursor();
if (pNmPlot->m_pPlotView != nullptr) {
pNmPlot->m_pPlotView->setFocus(Qt::OtherFocusReason);
}
return true;
} else if (isMeasureAction) {
nmObjLineMeasureTool* pMeasureTool = new nmObjLineMeasureTool();
nmObjToolBase* pObjTool = pMeasureTool;
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
m_activeTools.insert(NMOT_Line_Measure, pObjTool);
pNmPlot->setMeasureEditingLocked(true);
pMeasureTool->beginCreationCursor();
return true;
} else if (_isSame(sAction, "nmDeleteOneObj")) {
nmObjDeleteTool* pObjTool = new nmObjDeleteTool(pPlot);
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigDeleteRequested(ZxObjBase*)), this, SLOT(slotDeleteRequested(ZxObjBase*)));
m_activeTools.insert(NMOT_Delete, pObjTool);
return true;
} else if (_isSame(sAction, "nmInsertRegionMark")) {
nmObjToolBase* pObjTool = new nmObjRegionMarkTool(pPlot);
nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT()));
Q_ASSERT(NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
connect(pObjTool, SIGNAL(sigCreationCancelled()),
this, SLOT(slotObjCreationCancelled()));
m_activeTools.insert(NMOT_RegionMark, pObjTool);
pObjTool->beginCreationCursor();
if (pNmPlot->m_pPlotView != nullptr) {
pNmPlot->m_pPlotView->setFocus(Qt::OtherFocusReason);
}
return true;
} else {
// 其它Action
}
return iGuiPlotCmdHelper::runAction(sAction);
}
void nmGuiPlotCmdHelper::cancelActiveTools()
{
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(m_pGuiPlot);
if(pWxPlot == nullptr || pWxPlot->m_pPlot == nullptr ||
pWxPlot->m_pPlotView == nullptr) {
return;
}
stopMeasureTool(pWxPlot);
foreach (nmObjToolBase* activeTool, m_activeTools.values()) {
// 取消删除模式时同步清理视口上的自定义光标。
if (nmObjDeleteTool* deleteTool = dynamic_cast<nmObjDeleteTool*>(activeTool)) {
deleteTool->resetDeleteCursor();
}
activeTool->resetInteractionCursor();
pWxPlot->m_pPlot->removeTools(activeTool);
}
m_activeTools.clear();
finalWithAcm(true, true);
}
void nmGuiPlotCmdHelper::slotObjCreationCancelled()
{
nmObjToolBase* tool = qobject_cast<nmObjToolBase*>(sender());
if (tool == nullptr || m_pGuiPlot == nullptr || m_pGuiPlot->m_pPlot == nullptr ||
m_activeTools.value(tool->getNOT(), nullptr) != tool) {
return;
}
// 先撤销登记,避免取消旧工具时误清掉后来切换的新工具。
m_activeTools.remove(tool->getNOT());
m_pGuiPlot->m_pPlot->removeTools(tool);
finalWithAcm(true, true);
}
void nmGuiPlotCmdHelper::slotDeleteRequested(ZxObjBase* object)
{
if (m_activeTools.value(NMOT_Delete, nullptr) != sender()) return;
// 退出工具可能导致画布更新,用弱引用确认目标仍可传给确认窗口。
QPointer<ZxObjBase> target = object;
cancelActiveTools();
if (target) static_cast<nmGuiPlot*>(m_pGuiPlot)->confirmDeleteMapObject(target.data());
}
void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
nmObjToolBase* pTool = dynamic_cast<nmObjToolBase*>(sender());
if (NULL == pTool) {
return;
}
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(m_pGuiPlot);
if (NULL == pWxPlot) {
return;
}
ZxPlot* pPlot = pWxPlot->m_pPlot;
Q_ASSERT (NULL != pPlot);
// 连续测量保留工具。已退出的工具不能通过延迟到达的松手事件提交。
const NM_Obj_Type type = pTool->getNOT();
if (type == NMOT_Line_Measure) {
if (m_activeTools.value(type, nullptr) == pTool) {
commitMeasure(pWxPlot, vec);
}
return;
}
pTool->resetInteractionCursor();
pPlot->removeTools(pTool);
m_activeTools.remove(type);
QString sName = tr("nmObj"); // 默认名称
// 根据类型设置绘图对象名称
if (type == NMOT_Point) {
sName = tr("Point");
} else if (type == NMOT_Point_Well) {
sName = tr("Well");
} else if (type == NMOT_Line) {
sName = tr("Line");
} else if (type == NMOT_Polygon) {
sName = tr("Polygon");
} else if (type == NMOT_PolygonOutline) {
sName.clear(); // 边界默认不命名,用户可在图元属性中自行填写。
} else if (type == NMOT_Line_Fracture) {
sName = tr("Fracture");
} else if (type == NMOT_Line_Fault) {
sName = tr("Fault");
} else if (type == NMOT_Line_MeasuringScale) {
sName = tr("MeasuringScale");
} else if (type == NMOT_Rect) {
sName = tr("Rectangle");
} else if (type == NMOT_RectOutline) {
sName.clear();
} else if (type == NMOT_Round) {
sName = tr("Circle");
} else if (type == NMOT_RoundOutline) {
sName.clear();
} else if (type == NMOT_Region) {
sName = tr("Limit");
} else if (type == NMOT_Delete) {
sName = tr("Delete");
} else if (type == NMOT_RegionMark) {
sName = tr("Region");
}
// 新边界提交前保存旧边界,替换只占用一个历史步骤。
QSharedPointer<nmMapObjectState> previous;
if (type == NMOT_RectOutline || type == NMOT_RoundOutline || type == NMOT_PolygonOutline) {
for (int i = 0; i < pPlot->getObjCount(); ++i) {
ZxObjBase* old = pPlot->getObjByIndex(i);
if (isBoundaryObject(old)) {
previous = pWxPlot->captureMapObject(static_cast<nmObjBase*>(old));
break;
}
}
}
nmObjBase* pObj = pWxPlot->appendOneObj(type, sName, vec);
if (pObj == nullptr) {
finalWithAcm(true, true);
return;
}
// 断层/裂缝/边界创建逻辑已改由 Binder 负责(创建数据 + 建立信号连接)
if (type == NMOT_Line_Fault) {
nmObjLineFault* pFault = dynamic_cast<nmObjLineFault*>(pObj);
if (pFault && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createFaultForGraphic(pFault);
}
} else if (type == NMOT_Line_Fracture) {
nmObjLineCrack* pCrack = dynamic_cast<nmObjLineCrack*>(pObj);
if (pCrack && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createCrackForGraphic(pCrack);
}
} else if (type == NMOT_RectOutline ||
type == NMOT_RoundOutline ||
type == NMOT_PolygonOutline) {
// 新边界已成形。按索引移除旧图元,旧数据由接下来的 Binder 创建流程替换。
nmPlotGraphicBinder* binder = pWxPlot->graphicBinder();
for (int i = pPlot->getObjCount() - 1; i >= 0; --i) {
ZxObjBase* oldObj = pPlot->getObjByIndex(i);
if (oldObj == pObj || !isBoundaryObject(oldObj)) continue;
if (binder != nullptr) {
binder->removeOutlineBinding(static_cast<nmObjBase*>(oldObj), false);
}
pPlot->removeObjByIndex(i);
}
// 先执行 afterCreated(矩形边界会在其中 reorderPoints)
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
if (binder != nullptr) {
nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pObj);
nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pObj);
nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pObj);
if (pRound) {
binder->createOutlineForGraphic(pRound);
} else if (pRect) {
binder->createOutlineForGraphic(pRect);
} else if (pPolygon) {
binder->createOutlineForGraphic(pPolygon);
}
}
} else if (type == NMOT_RegionMark) {
// 先执行 afterCreated(图元内部初始化)
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
nmObjRegionMark* pRegionMark = dynamic_cast<nmObjRegionMark*>(pObj);
if (pRegionMark && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createRegionMarkForGraphic(pRegionMark);
}
} else if (type == NMOT_Region) {
// 先执行 afterCreated(图元内部初始化:点排序)
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
nmObjRegion* pRegion = dynamic_cast<nmObjRegion*>(pObj);
if (pRegion && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createRegionForGraphic(pRegion);
}
} else if (type == NMOT_Point_Well) {
// 井图元:先设置 Binder,再执行 afterCreated(内部通过 Binder 创建井数据)
nmObjPointWell* pWell = dynamic_cast<nmObjPointWell*>(pObj);
if (pWell && pWxPlot->graphicBinder()) {
pWell->setGraphicBinder(pWxPlot->graphicBinder());
}
pObj->afterCreated();
} else {
pObj->afterCreated();
}
pWxPlot->recordMapCreation(pObj, previous);
}
void nmGuiPlotCmdHelper::commitMeasure(nmGuiPlot* plot, QVector<QPointF>& points)
{
ZxPlot* chart = plot->m_pPlot;
nmPlotGraphicBinder* binder = plot->graphicBinder();
if (chart == nullptr || binder == nullptr || plot->boundDataManager() == nullptr ||
points.count() != 2) {
return;
}
const ZxSubAxisX* axisX = chart->getMainAxisX();
const ZxSubAxisY* axisY = chart->getMainAxisY();
if (axisX == nullptr || axisY == nullptr ||
axisX->getRangeMin() == axisX->getRangeMax() ||
axisY->getRangeMin() == axisY->getRangeMax()) {
return;
}
// 首次单击仍可选取拟合参考点。已有测量时,只允许有效线段替换。
const bool singlePoint = points[0] == points[1];
if (singlePoint && !plot->getObjsByTag("nObjLineMeasure").isEmpty()) return;
const QVector<QPointF> values = chart->getValueForPos(points);
if (values.count() != 2) return;
const qreal length = QLineF(values[0], values[1]).length();
if (!qIsFinite(length) || (!singlePoint && length <= 0.0)) return;
QString name = tr("Measure");
nmObjLineMeasure* measure = static_cast<nmObjLineMeasure*>(
plot->appendOneObj(NMOT_Line_Measure, name, points));
if (measure == nullptr) return;
// 新线已创建,先断开旧线绑定,再写入供面板监听的同一个数据对象。
plot->removeMeasureGraphics(measure);
measure->afterCreated();
binder->createMeasureForGraphic(measure);
emit sigMeasureCommitted();
}
void nmGuiPlotCmdHelper::finishMeasure()
{
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(m_pGuiPlot);
if(pWxPlot == nullptr || pWxPlot->m_pPlot == nullptr) {
return;
}
stopMeasureTool(pWxPlot);
pWxPlot->deleteMeasureObjects();
}
void nmGuiPlotCmdHelper::stopMeasureTool(nmGuiPlot* plot)
{
if (nmObjToolBase* tool = m_activeTools.take(NMOT_Line_Measure)) {
tool->cancelInteraction();
tool->resetInteractionCursor();
plot->m_pPlot->removeTools(tool);
}
plot->setMeasureEditingLocked(false);
}
// 插入背景
void nmGuiPlotCmdHelper::insertBkImg()
{
// 与业务窗口共用导入通道,确保图片归属、保存和坐标保持规则一致。
nmGuiPlot* pMap = qobject_cast<nmGuiPlot*>(m_pGuiPlot);
if(pMap != NULL) {
pMap->importBackgroundImage();
}
}
// 插入井点
void nmGuiPlotCmdHelper::insertOneWell() {
}