From 410cba92f66f5cbd9fe4a2e0b2782c18976f5edd Mon Sep 17 00:00:00 2001 From: lvjunjie Date: Mon, 22 Jun 2026 15:39:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=82=E7=BC=9D=E5=9B=BE=E5=85=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Include/nmNum/nmPlot/nmObjLineCrack.h | 30 ++-- Include/nmNum/nmPlot/nmPlotGraphicBinder.h | 38 +++- Src/nmNum/nmPlot/nmGuiPlot.cpp | 13 +- Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp | 8 +- Src/nmNum/nmPlot/nmObjDeleteTool.cpp | 1 + Src/nmNum/nmPlot/nmObjLineCrack.cpp | 155 +++++++--------- Src/nmNum/nmPlot/nmObjLineCrackTool.cpp | 1 + Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp | 199 +++++++++++++++++++++ Src/nmNum/nmSubWxs/nmWxDFNGenerateDlg.cpp | 7 +- Src/nmNum/nmSubWxs/nmWxDFNLoadFromFile.cpp | 7 +- 10 files changed, 346 insertions(+), 113 deletions(-) diff --git a/Include/nmNum/nmPlot/nmObjLineCrack.h b/Include/nmNum/nmPlot/nmObjLineCrack.h index 9f446a5..ffddcc8 100644 --- a/Include/nmNum/nmPlot/nmObjLineCrack.h +++ b/Include/nmNum/nmPlot/nmObjLineCrack.h @@ -4,7 +4,8 @@ #include "nmDefines.h" #include "nmPlot_global.h" -#include "nmDataFracture.h" +class nmPlotGraphicBinder; +class nmDataFracture; // 数值试井绘图对象(线) class NM_PLOT_EXPORT nmObjLineCrack : public nmObjBase @@ -69,11 +70,17 @@ public: virtual void paintBack(QPainter* painter, \ const ZxPaintParam& param) override; - // 创建后调用,初始化裂缝默认参数 - virtual void afterCreated() override; +signals: + // 流动模型变更 + void sigFlowModelChanged(int model); + // 导流能力变更 + void sigDfcChanged(double dfc); + // 储能比变更 + void sigDwChanged(double dw); + // 点坐标变更 + void sigPointsChanged(); - // 删除裂缝数据对象 - virtual void removeData() override; +public: int getCrackFlowModel(); void setCrackFlowModel(int newCrackFlowModel); @@ -84,9 +91,11 @@ public: double getCrackDw(); void setCrackDw(double newCrackDw); - void setFractureData(nmDataFracture* newFractureData); + // 查找数据指针(通过 Binder 反查) nmDataFracture* getFractureData() const; + void setGraphicBinder(nmPlotGraphicBinder* pBinder) { m_pGraphicBinder = pBinder; } + double getStartX(); void setStartX(double newValue); double getStartY(); @@ -99,12 +108,11 @@ public: // 如果是DFN生成的裂缝,调用该方法禁止修改 void setLockForDFN(); - public slots: - // 图元状态改变 - void onObjVisibleChanged(bool bIsVisible); - private: - nmDataFracture* m_fractureData; // 裂缝数据对象 + QString m_sFlowModel; // 流动模型本地副本 + double m_dDfc; // 导流能力本地副本 + double m_dDw; // 储能比本地副本 + nmPlotGraphicBinder* m_pGraphicBinder; // 图元-数据绑定协调器 }; diff --git a/Include/nmNum/nmPlot/nmPlotGraphicBinder.h b/Include/nmNum/nmPlot/nmPlotGraphicBinder.h index 5334ace..24b7aca 100644 --- a/Include/nmNum/nmPlot/nmPlotGraphicBinder.h +++ b/Include/nmNum/nmPlot/nmPlotGraphicBinder.h @@ -9,6 +9,8 @@ class nmDataAnalyzeManager; class nmDataFault; class nmObjLineFault; +class nmDataFracture; +class nmObjLineCrack; // 图元与数据绑定协调器,由 nmGuiPlot 托管 class NM_PLOT_EXPORT nmPlotGraphicBinder : public QObject @@ -30,6 +32,18 @@ public: // 查找图元对应的数据指针 nmDataFault* getFaultDataFor(nmObjLineFault* pGraphic); + // 调用:用户画完裂缝后 + void createCrackForGraphic(nmObjLineCrack* pGraphic); + + // 调用:从文件加载,绑定已有裂缝数据到已有图元 + void bindCrackToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData); + + // 调用:删除裂缝图元前 + void removeCrackBinding(nmObjLineCrack* pGraphic); + + // 查找裂缝图元对应的数据指针 + nmDataFracture* getCrackDataFor(nmObjLineCrack* pGraphic); + // 切换分析时更新绑定的 DataManager,并清理旧图元的残留映射 void updateDataMgr(nmDataAnalyzeManager* pDataMgr); @@ -38,12 +52,19 @@ public slots: void onDataChanged(); private slots: - // 图元信号 → 数据同步 + // 断层图元信号 → 数据同步 void onGraphicFlowModelChanged(int model); void onGraphicLeakageChanged(double leakage); void onGraphicPointsChanged(); void onGraphicVisibleChanged(bool bVisible); + // 裂缝图元信号 → 数据同步 + void onGraphicCrackFlowModelChanged(int model); + void onGraphicCrackDfcChanged(double dfc); + void onGraphicCrackDwChanged(double dw); + void onGraphicCrackPointsChanged(); + void onGraphicCrackVisibleChanged(bool bVisible); + private: nmDataAnalyzeManager* m_pDataMgr; // 数据中心,不持有,外部注入 @@ -61,4 +82,19 @@ private: // 从数据对象读取值,写入图元本地副本(加载时用) void _pushFaultDataToGraphic(nmObjLineFault* pGraphic, nmDataFault* pData); + + // 裂缝图元 → 数据 的映射表 + QMap m_mapCrackData; + + // 已建立信号连接的裂缝图元集合 + QSet m_setBoundCrackGraphics; + + // 裂缝图元 ←→ 数据 双向信号连接 + void _connectCrack(nmObjLineCrack* pGraphic, nmDataFracture* pData); + + // 断开指定裂缝图元与本 Binder 的五条信号连接 + void _disconnectCrack(nmObjLineCrack* pGraphic); + + // 从裂缝数据对象读取值,写入图元本地副本(加载时用) + void _pushCrackDataToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData); }; diff --git a/Src/nmNum/nmPlot/nmGuiPlot.cpp b/Src/nmNum/nmPlot/nmGuiPlot.cpp index ba3b0a8..022d5c0 100644 --- a/Src/nmNum/nmPlot/nmGuiPlot.cpp +++ b/Src/nmNum/nmPlot/nmGuiPlot.cpp @@ -49,6 +49,7 @@ #include "nmDataAnalyzeManager.h" #include "nmDataFault.h" +#include "nmDataFracture.h" #include "nmDataOutline.h" #include "nmDataAxis.h" @@ -656,8 +657,8 @@ void nmGuiPlot::initFractureObjsFromData(nmDataAnalyzeManager* pDataManager) continue; } - // 4.7 绑定裂缝数据到图元对象上 - pFracturePlot->setFractureData(pDataFracture); + // 4.7 通过 Binder 绑定数据(推值 + 建立信号连接) + m_pGraphicBinder->bindCrackToGraphic(pFracturePlot, pDataFracture); // TODO: 设置裂缝其他属性 } @@ -1375,9 +1376,11 @@ void nmGuiPlot::slotDeleteOneObj(QString sName, void* obj) if(nmObj) { m_pPlot->removeObjByName(sName); - // 先通过 Binder 清理数据绑定(如果是断层等 Binder 管理的类型) + // 先通过 Binder 清理数据绑定(如果是断层/裂缝等 Binder 管理的类型) if (nmObjLineFault* pFault = dynamic_cast(nmObj)) { m_pGraphicBinder->removeFaultBinding(pFault); + } else if (nmObjLineCrack* pCrack = dynamic_cast(nmObj)) { + m_pGraphicBinder->removeCrackBinding(pCrack); } else { // 其他类型回退到旧方式 nmObj->removeData(); @@ -1420,8 +1423,8 @@ void nmGuiPlot::deleteAllDFNPlots() } if(pCrack->getFractureData()->getFractureType().getValue() == tr("DFN")) { - // 清空绑定的数据 - pCrack->removeData(); + // 通过 Binder 清理数据绑定 + m_pGraphicBinder->removeCrackBinding(pCrack); // 删除DFN图元 m_pPlot->removeObjByName(pCrack->getName()); } diff --git a/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp b/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp index 1b4ddb3..7a84b91 100644 --- a/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp +++ b/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp @@ -13,6 +13,7 @@ #include "nmObjPolygonTool.h" #include "nmObjPolygonOutlineTool.h" #include "nmObjLineCrackTool.h" +#include "nmObjLineCrack.h" #include "nmObjLineFaultTool.h" #include "nmObjLineFault.h" #include "nmObjLineMeasuringScaleTool.h" @@ -347,12 +348,17 @@ void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector& vec) { } nmObjBase* pObj = pWxPlot->appendOneObj(pTool->getNOT(), sName, vec); - // 断层创建逻辑已改由 Binder 负责(创建数据 + 建立信号连接) + // 断层/裂缝创建逻辑已改由 Binder 负责(创建数据 + 建立信号连接) if (pTool->getNOT() == NMOT_Line_Fault) { nmObjLineFault* pFault = dynamic_cast(pObj); if (pFault && pWxPlot->graphicBinder()) { pWxPlot->graphicBinder()->createFaultForGraphic(pFault); } + } else if (pTool->getNOT() == NMOT_Line_Fracture) { + nmObjLineCrack* pCrack = dynamic_cast(pObj); + if (pCrack && pWxPlot->graphicBinder()) { + pWxPlot->graphicBinder()->createCrackForGraphic(pCrack); + } } else { pObj->afterCreated(); } diff --git a/Src/nmNum/nmPlot/nmObjDeleteTool.cpp b/Src/nmNum/nmPlot/nmObjDeleteTool.cpp index 8d79970..6cd341b 100644 --- a/Src/nmNum/nmPlot/nmObjDeleteTool.cpp +++ b/Src/nmNum/nmPlot/nmObjDeleteTool.cpp @@ -11,6 +11,7 @@ #include #include "nmObjLineCrack.h" +#include "nmDataFracture.h" nmObjDeleteTool::nmObjDeleteTool() : nmObjToolBase() , m_pPlot(nullptr) diff --git a/Src/nmNum/nmPlot/nmObjLineCrack.cpp b/Src/nmNum/nmPlot/nmObjLineCrack.cpp index c825dbd..31bacc9 100644 --- a/Src/nmNum/nmPlot/nmObjLineCrack.cpp +++ b/Src/nmNum/nmPlot/nmObjLineCrack.cpp @@ -12,6 +12,7 @@ #include "nmObjLineCrack.h" +#include "nmPlotGraphicBinder.h" #include "nmDataAnalyzeManager.h" ZX_DEFINE_DYNAMIC(nObjLineFracture, nmObjLineCrack) @@ -32,8 +33,6 @@ nmObjLineCrack::nmObjLineCrack(const QString& sName, \ nmObjLineCrack::~nmObjLineCrack() { - // 裂缝数据由DataManager统一释放,图元只保存引用。 - m_fractureData = nullptr; } void nmObjLineCrack::init(const QString& sName, \ @@ -47,13 +46,13 @@ void nmObjLineCrack::init(const QString& sName, \ m_oPen = QPen(QBrush(Qt::red), \ 0.3f, Qt::SolidLine); - m_fractureData = nullptr; + // 业务属性本地默认值 + m_sFlowModel = tr("Infinite Conductivity"); + m_dDfc = 0; + m_dDw = 0; + m_pGraphicBinder = nullptr; loadTempl(); - - // 连接图元可见性信号和槽 - connect(this, SIGNAL(sigObjVisibleChanged(bool)), - this, SLOT(onObjVisibleChanged(bool))); } void nmObjLineCrack::initTools() @@ -121,7 +120,8 @@ bool nmObjLineCrack::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex m_vecPoints = getValueOf(pts); nOption = (int)OHO_Point; nSubIndex = i + 1; - + // 点集变更 + emit sigPointsChanged(); return true; } @@ -155,8 +155,10 @@ bool nmObjLineCrack::runMove(const QPointF& pt1, if(m_oHitOption == OHO_Point && m_nHitIndex >= 0) { // 如果是点,不用计算偏移量,直接将该点移动到鼠标抬起的位置即可 vecPts[m_nHitIndex] = pt2; - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); - return moveToPos(vecPts); + bool bRet = moveToPos(vecPts); + // 移动后通知点集变更 + emit sigPointsChanged(); + return bRet; } else if(m_oHitOption == OHO_Bound && m_nHitIndex >= 0) { for(int i = 0; i < nCount; i++) { vecPts[i] = offsetPoint(vecPts[i], pt1, pt2); @@ -164,8 +166,10 @@ bool nmObjLineCrack::runMove(const QPointF& pt1, m_dOffsetX = pt2.x() - pt1.x(); m_dOffsetY = pt2.y() - pt1.y(); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); - return moveToPos(vecPts); + bool bRet = moveToPos(vecPts); + // 移动后通知点集变更 + emit sigPointsChanged(); + return bRet; } else { return false; } @@ -184,12 +188,6 @@ void nmObjLineCrack::paintBack(QPainter* painter, const ZxPaintParam& param) painter->save(); QVector pts = getPosOf(m_vecPoints); - // 动态更新裂缝基础数据 - if(m_fractureData != nullptr) { - m_fractureData->setFractureName(m_sName); - m_fractureData->setFracturePoints(m_vecPoints); - } - // 不选中的状态 if(!pts.empty()) { @@ -289,7 +287,7 @@ void nmObjLineCrack::paintBack(QPainter* painter, const ZxPaintParam& param) int nmObjLineCrack::getCrackFlowModel() { - if(m_fractureData->getFractureFlowModel().getValue() == tr("Infinite Conductivity")) + if(m_sFlowModel == tr("Infinite Conductivity")) return 0; else return 1; @@ -297,56 +295,44 @@ int nmObjLineCrack::getCrackFlowModel() void nmObjLineCrack::setCrackFlowModel(int newCrackFlowModel) { - nmDataAttribute tempAttr = m_fractureData->getFractureFlowModel(); - if(newCrackFlowModel == 0) { - tempAttr.setValue(tr("Infinite Conductivity")); + m_sFlowModel = tr("Infinite Conductivity"); } else { - tempAttr.setValue(tr("Finite Conductivity")); + m_sFlowModel = tr("Finite Conductivity"); } - - m_fractureData->setFractureFlowModel(tempAttr); + emit sigFlowModelChanged(newCrackFlowModel); } double nmObjLineCrack::getCrackDfc() { - return m_fractureData->getFractureDfc().getValue().toDouble(); + return m_dDfc; } void nmObjLineCrack::setCrackDfc(double newCrackDfc) { - // 从Data中取数据 - nmDataAttribute tempAttr = m_fractureData->getFractureDfc(); - tempAttr.setValue(newCrackDfc); - m_fractureData->setFractureDfc(tempAttr); + m_dDfc = newCrackDfc; + emit sigDfcChanged(newCrackDfc); } double nmObjLineCrack::getCrackDw() { - return m_fractureData->getFractureDw().getValue().toDouble(); + return m_dDw; } void nmObjLineCrack::setCrackDw(double newCrackDw) { - // 从Data中取数据 - nmDataAttribute tempAttr = m_fractureData->getFractureDw(); - tempAttr.setValue(newCrackDw); - m_fractureData->setFractureDw(tempAttr); + m_dDw = newCrackDw; + emit sigDwChanged(newCrackDw); } void nmObjLineCrack::onSerialize(ZxSerializer* ser) { nmObjBase::onSerialize(ser); - int flowModel; - - if(m_fractureData->getFractureFlowModel().getValue() == tr("Infinite Conductivity")) - flowModel = 0; - else - flowModel = 1; + int flowModel = getCrackFlowModel(); ser->write("FlowModel", flowModel); - ser->write("dFc", m_fractureData->getFractureDfc().getValue().toDouble()); - ser->write("dW", m_fractureData->getFractureDw().getValue().toDouble()); + ser->write("dFc", m_dDfc); + ser->write("dW", m_dDw); } void nmObjLineCrack::onDeserialize(ZxSerializer* ser) @@ -367,16 +353,11 @@ void nmObjLineCrack::onDeserialize(ZxSerializer* ser) void nmObjLineCrack::onSaveTempl(ZxSerializer* ser) { nmObjBase::onSaveTempl(ser); - int flowModel; - - if(m_fractureData->getFractureFlowModel().getValue() == tr("Infinite Conductivity")) - flowModel = 0; - else - flowModel = 1; + int flowModel = getCrackFlowModel(); ser->write("FlowModel", flowModel); - ser->write("dFc", m_fractureData->getFractureDfc().getValue().toDouble()); - ser->write("dW", m_fractureData->getFractureDw().getValue().toDouble()); + ser->write("dFc", m_dDfc); + ser->write("dW", m_dDw); } void nmObjLineCrack::onLoadTempl(ZxSerializer* ser) @@ -419,75 +400,72 @@ void nmObjLineCrack::fillPtyPano(IxPtyPano* sheet) ZX_PROP("ObjLineCrackEndPos.EndPointY", getEndY, setEndY); } -void nmObjLineCrack::setFractureData(nmDataFracture* newFractureData) -{ - m_fractureData = newFractureData; -} - nmDataFracture* nmObjLineCrack::getFractureData() const { - return m_fractureData; -} - -void nmObjLineCrack::afterCreated() -{ - m_fractureData = nmDataAnalyzeManager::getCurrentInstance()->createFracture(); - m_fractureData->setFractureName(m_sName); - m_fractureData->setFracturePoints(m_vecPoints); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); -} - -void nmObjLineCrack::removeData() -{ - if(m_fractureData) { - // 从数据中心移除该数据 - nmDataAnalyzeManager::getCurrentInstance()->removeFractureData(m_fractureData); - m_fractureData = nullptr; + if(m_pGraphicBinder) { + return m_pGraphicBinder->getCrackDataFor(const_cast(this)); } + return nullptr; } double nmObjLineCrack::getStartX() { - return m_fractureData->getFracturePoints().first().x(); + if(!m_vecPoints.isEmpty()) + return m_vecPoints.first().x(); + return 0; } void nmObjLineCrack::setStartX(double newValue) { - m_vecPoints.first().setX(newValue); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); + if(!m_vecPoints.isEmpty()) { + m_vecPoints.first().setX(newValue); + emit sigPointsChanged(); + } } double nmObjLineCrack::getStartY() { - return m_fractureData->getFracturePoints().first().y(); + if(!m_vecPoints.isEmpty()) + return m_vecPoints.first().y(); + return 0; } void nmObjLineCrack::setStartY(double newValue) { - m_vecPoints.first().setY(newValue); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); + if(!m_vecPoints.isEmpty()) { + m_vecPoints.first().setY(newValue); + emit sigPointsChanged(); + } } double nmObjLineCrack::getEndX() { - return m_fractureData->getFracturePoints().last().x(); + if(!m_vecPoints.isEmpty()) + return m_vecPoints.last().x(); + return 0; } void nmObjLineCrack::setEndX(double newValue) { - m_vecPoints.last().setX(newValue); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); + if(!m_vecPoints.isEmpty()) { + m_vecPoints.last().setX(newValue); + emit sigPointsChanged(); + } } double nmObjLineCrack::getEndY() { - return m_fractureData->getFracturePoints().last().y(); + if(!m_vecPoints.isEmpty()) + return m_vecPoints.last().y(); + return 0; } void nmObjLineCrack::setEndY(double newValue) { - m_vecPoints.last().setY(newValue); - nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged(); + if(!m_vecPoints.isEmpty()) { + m_vecPoints.last().setY(newValue); + emit sigPointsChanged(); + } } void nmObjLineCrack::setLockForDFN() @@ -496,10 +474,3 @@ void nmObjLineCrack::setLockForDFN() setLockSize(true); setReadOnly(true); } - -void nmObjLineCrack::onObjVisibleChanged(bool bIsVisible) -{ - if(m_fractureData != nullptr) { - m_fractureData->setPlotVisible(bIsVisible); - } -} diff --git a/Src/nmNum/nmPlot/nmObjLineCrackTool.cpp b/Src/nmNum/nmPlot/nmObjLineCrackTool.cpp index 495f4cb..ffcc8f6 100644 --- a/Src/nmNum/nmPlot/nmObjLineCrackTool.cpp +++ b/Src/nmNum/nmPlot/nmObjLineCrackTool.cpp @@ -7,6 +7,7 @@ #include "nmDataLogFile.h" #include "nmObjLineCrack.h" +#include "nmDataFracture.h" #include "nmObjPointWell.h" diff --git a/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp b/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp index 8aaa75e..c37b2fa 100644 --- a/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp +++ b/Src/nmNum/nmPlot/nmPlotGraphicBinder.cpp @@ -2,6 +2,8 @@ #include "nmObjLineFault.h" #include "nmDataFault.h" +#include "nmObjLineCrack.h" +#include "nmDataFracture.h" #include "nmDataAnalyzeManager.h" #include @@ -77,6 +79,8 @@ void nmPlotGraphicBinder::updateDataMgr(nmDataAnalyzeManager* pDataMgr) { m_mapFaultData.clear(); m_setBoundGraphics.clear(); + m_mapCrackData.clear(); + m_setBoundCrackGraphics.clear(); m_pDataMgr = pDataMgr; } @@ -199,3 +203,198 @@ void nmPlotGraphicBinder::onGraphicVisibleChanged(bool bVisible) void nmPlotGraphicBinder::onDataChanged() { } + +// ============ 裂缝绑定 ============ + +// 用户画完裂缝后:创建数据对象并建立绑定 +void nmPlotGraphicBinder::createCrackForGraphic(nmObjLineCrack* pGraphic) +{ + if (!pGraphic || !m_pDataMgr) { + return; + } + + // 创建数据对象 + nmDataFracture* pData = m_pDataMgr->createFracture(); + + // 将图元值推入数据 + pData->setFractureName(pGraphic->getName()); + pData->setFracturePoints(pGraphic->getAllValues()); + + // 建立信号连接 + _connectCrack(pGraphic, pData); + + m_pDataMgr->notifyDataChanged(); +} + +// 从文件加载:绑定已有裂缝数据到已有图元 +void nmPlotGraphicBinder::bindCrackToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData) +{ + if (!pGraphic || !pData) { + return; + } + + // 将数据值推到图元 + _pushCrackDataToGraphic(pGraphic, pData); + + // 建立信号连接 + _connectCrack(pGraphic, pData); +} + +// 删除裂缝图元:断开连接并移除数据 +void nmPlotGraphicBinder::removeCrackBinding(nmObjLineCrack* pGraphic) +{ + if (!pGraphic) { + return; + } + + // 断开信号 + _disconnectCrack(pGraphic); + + // 从数据中心移除 + if (m_mapCrackData.contains(pGraphic)) { + nmDataFracture* pData = m_mapCrackData.value(pGraphic); + if (pData && m_pDataMgr) { + m_pDataMgr->removeFractureData(pData); + } + m_mapCrackData.remove(pGraphic); + } +} + +nmDataFracture* nmPlotGraphicBinder::getCrackDataFor(nmObjLineCrack* pGraphic) +{ + return m_mapCrackData.value(pGraphic, nullptr); +} + +// 将裂缝数据值推到图元本地副本 +void nmPlotGraphicBinder::_pushCrackDataToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData) +{ + // 阻断信号,防止推送中触发反向同步 + pGraphic->blockSignals(true); + + pGraphic->setName(pData->getFractureName()); + + int flowModel = (pData->getFractureFlowModel().getValue() == tr("Infinite Conductivity")) ? 0 : 1; + pGraphic->setCrackFlowModel(flowModel); + + pGraphic->setCrackDfc(pData->getFractureDfc().getValue().toDouble()); + pGraphic->setCrackDw(pData->getFractureDw().getValue().toDouble()); + + pGraphic->blockSignals(false); +} + +// 建立裂缝图元与数据的双向信号连接 +void nmPlotGraphicBinder::_connectCrack(nmObjLineCrack* pGraphic, nmDataFracture* pData) +{ + QObject::connect(pGraphic, SIGNAL(sigFlowModelChanged(int)), + this, SLOT(onGraphicCrackFlowModelChanged(int))); + + QObject::connect(pGraphic, SIGNAL(sigDfcChanged(double)), + this, SLOT(onGraphicCrackDfcChanged(double))); + + QObject::connect(pGraphic, SIGNAL(sigDwChanged(double)), + this, SLOT(onGraphicCrackDwChanged(double))); + + QObject::connect(pGraphic, SIGNAL(sigPointsChanged()), + this, SLOT(onGraphicCrackPointsChanged())); + + QObject::connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)), + this, SLOT(onGraphicCrackVisibleChanged(bool))); + + m_mapCrackData[pGraphic] = pData; + + m_setBoundCrackGraphics.insert(pGraphic); + + pGraphic->setGraphicBinder(this); +} + +// 断开裂缝图元与本 Binder 的所有信号连接 +void nmPlotGraphicBinder::_disconnectCrack(nmObjLineCrack* pGraphic) +{ + QObject::disconnect(pGraphic, SIGNAL(sigFlowModelChanged(int)), + this, SLOT(onGraphicCrackFlowModelChanged(int))); + + QObject::disconnect(pGraphic, SIGNAL(sigDfcChanged(double)), + this, SLOT(onGraphicCrackDfcChanged(double))); + + QObject::disconnect(pGraphic, SIGNAL(sigDwChanged(double)), + this, SLOT(onGraphicCrackDwChanged(double))); + + QObject::disconnect(pGraphic, SIGNAL(sigPointsChanged()), + this, SLOT(onGraphicCrackPointsChanged())); + + QObject::disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)), + this, SLOT(onGraphicCrackVisibleChanged(bool))); + + m_setBoundCrackGraphics.remove(pGraphic); +} + +// 裂缝流动模型变更 +void nmPlotGraphicBinder::onGraphicCrackFlowModelChanged(int model) +{ + nmObjLineCrack* pGraphic = qobject_cast(sender()); + if (!pGraphic) return; + + nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr); + if (!pData) return; + + nmDataAttribute attr = pData->getFractureFlowModel(); + attr.setValue(model == 0 ? tr("Infinite Conductivity") : tr("Finite Conductivity")); + pData->setFractureFlowModel(attr); +} + +// 裂缝导流能力变更 +void nmPlotGraphicBinder::onGraphicCrackDfcChanged(double dfc) +{ + nmObjLineCrack* pGraphic = qobject_cast(sender()); + if (!pGraphic) return; + + nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr); + if (!pData) return; + + nmDataAttribute attr = pData->getFractureDfc(); + attr.setValue(dfc); + pData->setFractureDfc(attr); +} + +// 裂缝储能比变更 +void nmPlotGraphicBinder::onGraphicCrackDwChanged(double dw) +{ + nmObjLineCrack* pGraphic = qobject_cast(sender()); + if (!pGraphic) return; + + nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr); + if (!pData) return; + + nmDataAttribute attr = pData->getFractureDw(); + attr.setValue(dw); + pData->setFractureDw(attr); +} + +// 裂缝点坐标变更 +void nmPlotGraphicBinder::onGraphicCrackPointsChanged() +{ + nmObjLineCrack* pGraphic = qobject_cast(sender()); + if (!pGraphic) return; + + nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr); + if (!pData) return; + + pData->setFracturePoints(pGraphic->getAllValues()); + pData->setFractureName(pGraphic->getName()); + + if (m_pDataMgr) { + m_pDataMgr->notifyDataChanged(); + } +} + +// 裂缝可见性变更 +void nmPlotGraphicBinder::onGraphicCrackVisibleChanged(bool bVisible) +{ + nmObjLineCrack* pGraphic = qobject_cast(sender()); + if (!pGraphic) return; + + nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr); + if (!pData) return; + + pData->setPlotVisible(bVisible); +} diff --git a/Src/nmNum/nmSubWxs/nmWxDFNGenerateDlg.cpp b/Src/nmNum/nmSubWxs/nmWxDFNGenerateDlg.cpp index 68f1a70..e44369e 100644 --- a/Src/nmNum/nmSubWxs/nmWxDFNGenerateDlg.cpp +++ b/Src/nmNum/nmSubWxs/nmWxDFNGenerateDlg.cpp @@ -1,5 +1,6 @@ #include "nmWxDFNGenerateDlg.h" #include "nmDataAnalyzeManager.h" +#include "nmDataFracture.h" #include "nmObjLineCrack.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" @@ -7,6 +8,7 @@ #include "ZxObjBase.h" #include "nmDataOutline.h" #include "nmGuiPlot.h" +#include "nmPlotGraphicBinder.h" #include #include @@ -479,7 +481,10 @@ void nmWxDFNGenerateDlg::generateFractures() nmObjBase* obj = plot->appendOneObj(NMOT_Line_Fracture, name, scPts); nmObjLineCrack* crack = dynamic_cast(obj); if (crack) { - crack->afterCreated(); + // 通过 Binder 创建裂缝数据并建立信号连接 + if (plot->graphicBinder()) { + plot->graphicBinder()->createCrackForGraphic(crack); + } // 设置属性为 DFN nmDataAttribute attr = crack->getFractureData()->getFractureType(); attr.setValue(tr("DFN")); diff --git a/Src/nmNum/nmSubWxs/nmWxDFNLoadFromFile.cpp b/Src/nmNum/nmSubWxs/nmWxDFNLoadFromFile.cpp index bc9399a..d49b59c 100644 --- a/Src/nmNum/nmSubWxs/nmWxDFNLoadFromFile.cpp +++ b/Src/nmNum/nmSubWxs/nmWxDFNLoadFromFile.cpp @@ -11,6 +11,7 @@ #include "nmDataAnalyzeManager.h" #include "nmDataFracture.h" #include "nmGuiPlot.h" +#include "nmPlotGraphicBinder.h" #include "nmObjLineCrack.h" #include "ZxPlot.h" @@ -664,8 +665,10 @@ void nmWxDFNLoadFromFile::onOkClicked() continue; } - // 绑定边界数据到图元对象上 - pFractrePlot->setFractureData(pFractrue); + // 通过 Binder 绑定裂缝数据(推值 + 建立信号连接) + if (pCurPlot->graphicBinder()) { + pCurPlot->graphicBinder()->bindCrackToGraphic(pFractrePlot, pFractrue); + } pFractrePlot->setPen(QPen(QBrush(QColor("#00bfff")), 0.4f, Qt::SolidLine));