diff --git a/Include/nmNum/nmPlot/nmGuiPlot.h b/Include/nmNum/nmPlot/nmGuiPlot.h index 3314a091..765326a6 100644 --- a/Include/nmNum/nmPlot/nmGuiPlot.h +++ b/Include/nmNum/nmPlot/nmGuiPlot.h @@ -4,7 +4,9 @@ #include "nmDefines.h" #include "nmPlot_global.h" #include +#include #include +#include class nmObjBase; class nmObjPointWell; @@ -216,8 +218,8 @@ class NM_PLOT_EXPORT nmGuiPlot : public iGuiPlot { // 仅移除 DFN 图元及绑定,不删除工程数据,供确定提交前安全解除旧引用。 void clearDFNPlotObjects(); - // 设置所有图元是否可编辑 - void setAllPlotObjectsEditable(bool editable); + // 测量期间临时锁定图元,退出时恢复各自原有的编辑状态。 + void setMeasureEditingLocked(bool locked); // 绑定由业务窗口创建的模型点对话框 void bindPointerPosDialog(QWidget* pointerPosDlg); @@ -244,6 +246,13 @@ class NM_PLOT_EXPORT nmGuiPlot : public iGuiPlot { virtual void resizeEvent(QResizeEvent* pEvent) override; private: + struct MeasureEditState + { + QPointer object; // 图元销毁后自动清空,恢复时可安全跳过。 + bool readOnly; + bool positionLocked; + }; + /** * @brief 校验所选线段,获取实际长度后按固定轴最小值进行等比例标定。 * @note 成功时将轴范围及米制长度写入本 Map 的数据管理器;取消或无效输入不提交。 @@ -274,5 +283,7 @@ class NM_PLOT_EXPORT nmGuiPlot : public iGuiPlot { nmDataAnalyzeManager* m_pDataManager; // 当前 Map 借用的数据管理器,不负责销毁 bool m_bApplyingAxisRange; // 正在由程序设置坐标轴,防止提前完成首次初始化 bool m_bAxisInitializationPending; // 是否已排队一次首次坐标轴初始化 + bool m_bMeasureEditingLocked; // 重复进入时保留第一次记录的状态。 + QVector m_measureEditStates; // 测量前的只读和位置锁定状态。 }; diff --git a/Include/nmNum/nmPlot/nmGuiPlotCmdHelper.h b/Include/nmNum/nmPlot/nmGuiPlotCmdHelper.h index 106ee4cc..9d7a8a0c 100644 --- a/Include/nmNum/nmPlot/nmGuiPlotCmdHelper.h +++ b/Include/nmNum/nmPlot/nmGuiPlotCmdHelper.h @@ -46,6 +46,9 @@ protected: friend class nmGuiPlot; private: + // 移除测量工具并恢复图元编辑状态,测量结果由面板关闭流程清理。 + void stopMeasureTool(nmGuiPlot* plot); + // 校验模型坐标,成功创建新线后再替换旧测量。 void commitMeasure(nmGuiPlot* plot, QVector& points); diff --git a/Src/nmNum/nmPlot/nmGuiPlot.cpp b/Src/nmNum/nmPlot/nmGuiPlot.cpp index f761abab..ef1821a3 100644 --- a/Src/nmNum/nmPlot/nmGuiPlot.cpp +++ b/Src/nmNum/nmPlot/nmGuiPlot.cpp @@ -124,7 +124,8 @@ nmGuiPlot::nmGuiPlot(bool bUseBtns, QWidget *parent) : m_pGraphicBinder(NULL), m_pDataManager(nmDataAnalyzeManager::getCurrentInstance()), m_bApplyingAxisRange(false), - m_bAxisInitializationPending(false) + m_bAxisInitializationPending(false), + m_bMeasureEditingLocked(false) { m_bUseBtns = bUseBtns; @@ -1382,8 +1383,7 @@ void nmGuiPlot::deleteMeasureObjects() m_pDataManager->removeMeasureData(); } - // 恢复画布可编辑状态 - setAllPlotObjectsEditable(true); + setMeasureEditingLocked(false); } void nmGuiPlot::removeMeasureGraphics(const ZxObjBase* keptGraphic) @@ -1401,23 +1401,38 @@ void nmGuiPlot::removeMeasureGraphics(const ZxObjBase* keptGraphic) } } -void nmGuiPlot::setAllPlotObjectsEditable(bool editable) +void nmGuiPlot::setMeasureEditingLocked(bool locked) { - if(m_pPlot == nullptr) { + if (locked == m_bMeasureEditingLocked || (locked && m_pPlot == nullptr)) { return; } - - int objCount = m_pPlot->getObjCount(); - - for(int i = 0; i < objCount; i++) { - ZxObjBase* obj = m_pPlot->getObjByIndex(i); - - if(obj == nullptr) { - continue; + m_bMeasureEditingLocked = locked; + + if (locked) { + const int count = m_pPlot->getObjCount(); + m_measureEditStates.reserve(count); + for (int i = 0; i < count; ++i) { + ZxObjBase* object = m_pPlot->getObjByIndex(i); + if (object == nullptr) continue; + + MeasureEditState state; + state.object = object; + state.readOnly = object->isReadOnly(); + state.positionLocked = object->isLockPos(); + m_measureEditStates.append(state); + object->setReadOnly(true); + object->setLockPos(true); } + return; + } - obj->setReadOnly(!editable); - obj->setLockPos(!editable); + const QVector states = m_measureEditStates; + m_measureEditStates.clear(); + foreach (const MeasureEditState& state, states) { + if (ZxObjBase* object = state.object.data()) { + object->setReadOnly(state.readOnly); + object->setLockPos(state.positionLocked); + } } } diff --git a/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp b/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp index b8d12039..4e78da2e 100644 --- a/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp +++ b/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp @@ -75,6 +75,11 @@ bool nmGuiPlotCmdHelper::runAction(QString sAction) { // 清除图元选中状态 nmGuiPlot* pNmPlot = static_cast(m_pGuiPlot); + const bool isMeasureAction = _isSame(sAction, "nmInsertObjLineMeasure"); + if (isMeasureAction && m_activeTools.contains(NMOT_Line_Measure)) { + return true; + } + stopMeasureTool(pNmPlot); pNmPlot->clearPlotsSelectStates(); // 添加之前先激活所有图元对象的可见性 @@ -272,12 +277,7 @@ bool nmGuiPlotCmdHelper::runAction(QString sAction) { this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Line_MeasuringScale, pObjTool); return true; - } else if (_isSame(sAction, "nmInsertObjLineMeasure")) { - nmObjToolBase* pExistingTool = m_activeTools.value(NMOT_Line_Measure, nullptr); - if(pExistingTool) { - return true; - } - + } else if (isMeasureAction) { nmObjLineMeasureTool* pMeasureTool = new nmObjLineMeasureTool(); nmObjToolBase* pObjTool = pMeasureTool; nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); @@ -286,6 +286,7 @@ bool nmGuiPlotCmdHelper::runAction(QString sAction) { connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Line_Measure, pObjTool); + pNmPlot->setMeasureEditingLocked(true); pMeasureTool->beginCreationCursor(); return true; } else if (_isSame(sAction, "nmDeleteOneObj")) { @@ -320,6 +321,7 @@ void nmGuiPlotCmdHelper::cancelActiveTools() return; } + stopMeasureTool(pWxPlot); foreach (nmObjToolBase* activeTool, m_activeTools.values()) { // 取消删除模式时同步清理视口上的自定义光标。 if (nmObjDeleteTool* deleteTool = dynamic_cast(activeTool)) { @@ -522,17 +524,20 @@ void nmGuiPlotCmdHelper::finishMeasure() return; } - nmObjToolBase* pMeasureTool = m_activeTools.value(NMOT_Line_Measure, nullptr); - if(pMeasureTool) { - m_activeTools.remove(NMOT_Line_Measure); - pMeasureTool->cancelInteraction(); - pMeasureTool->resetInteractionCursor(); - pWxPlot->m_pPlot->removeTools(pMeasureTool); - } - + 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() { diff --git a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp index 91788192..203480b2 100644 --- a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp +++ b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp @@ -1564,7 +1564,6 @@ void nmSubWndMain::drawMeasure() } bindMeasureDialog(measureDlg); - plot->setAllPlotObjectsEditable(false); this->triggerToolBarAction(NMOT_Line_Measure); }