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.
202 lines
5.4 KiB
C++
202 lines
5.4 KiB
C++
|
3 weeks ago
|
#include "nmPlotGraphicBinder.h"
|
||
|
|
|
||
|
|
#include "nmObjLineFault.h"
|
||
|
|
#include "nmDataFault.h"
|
||
|
|
#include "nmDataAnalyzeManager.h"
|
||
|
|
|
||
|
|
#include <QMetaObject>
|
||
|
|
|
||
|
|
nmPlotGraphicBinder::nmPlotGraphicBinder(nmDataAnalyzeManager* pDataMgr, QObject* parent)
|
||
|
|
: QObject(parent)
|
||
|
|
, m_pDataMgr(pDataMgr)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
// 用户画完断层后:创建数据对象并建立绑定
|
||
|
|
void nmPlotGraphicBinder::createFaultForGraphic(nmObjLineFault* pGraphic)
|
||
|
|
{
|
||
|
|
if (!pGraphic || !m_pDataMgr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 创建数据对象
|
||
|
|
nmDataFault* pData = m_pDataMgr->createFault();
|
||
|
|
|
||
|
|
// 将图元值推入数据
|
||
|
|
pData->setFaultName(pGraphic->getName());
|
||
|
|
pData->setFaultPoints(pGraphic->getAllValues());
|
||
|
|
|
||
|
|
// 建立信号连接
|
||
|
|
_connectFault(pGraphic, pData);
|
||
|
|
|
||
|
|
m_pDataMgr->notifyDataChanged();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 从文件加载:绑定已有数据到已有图元
|
||
|
|
void nmPlotGraphicBinder::bindFaultToGraphic(nmObjLineFault* pGraphic, nmDataFault* pData)
|
||
|
|
{
|
||
|
|
if (!pGraphic || !pData) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 将数据值推到图元
|
||
|
|
_pushFaultDataToGraphic(pGraphic, pData);
|
||
|
|
|
||
|
|
// 建立信号连接
|
||
|
|
_connectFault(pGraphic, pData);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 删除图元:断开连接并移除数据
|
||
|
|
void nmPlotGraphicBinder::removeFaultBinding(nmObjLineFault* pGraphic)
|
||
|
|
{
|
||
|
|
if (!pGraphic) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 断开信号
|
||
|
|
_disconnectFault(pGraphic);
|
||
|
|
|
||
|
|
// 从数据中心移除
|
||
|
|
if (m_mapFaultData.contains(pGraphic)) {
|
||
|
|
nmDataFault* pData = m_mapFaultData.value(pGraphic);
|
||
|
|
if (pData && m_pDataMgr) {
|
||
|
|
m_pDataMgr->removeFaultData(pData);
|
||
|
|
}
|
||
|
|
m_mapFaultData.remove(pGraphic);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
nmDataFault* nmPlotGraphicBinder::getFaultDataFor(nmObjLineFault* pGraphic)
|
||
|
|
{
|
||
|
|
return m_mapFaultData.value(pGraphic, nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 切换分析时更新绑定的 DataManager
|
||
|
|
// 旧图元已由 deleteAllPlotObjs 清除,清理残留映射避免悬空指针
|
||
|
|
void nmPlotGraphicBinder::updateDataMgr(nmDataAnalyzeManager* pDataMgr)
|
||
|
|
{
|
||
|
|
m_mapFaultData.clear();
|
||
|
|
m_setBoundGraphics.clear();
|
||
|
|
m_pDataMgr = pDataMgr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 将数据值推到图元本地副本
|
||
|
|
void nmPlotGraphicBinder::_pushFaultDataToGraphic(nmObjLineFault* pGraphic, nmDataFault* pData)
|
||
|
|
{
|
||
|
|
// 阻断信号,防止推送中触发反向同步
|
||
|
|
pGraphic->blockSignals(true);
|
||
|
|
|
||
|
|
pGraphic->setName(pData->getFaultName());
|
||
|
|
|
||
|
|
int flowModel = (pData->getFaultFlowModel().getValue() == tr("Leaky")) ? 0 : 1;
|
||
|
|
pGraphic->setFaultFlowModel(flowModel);
|
||
|
|
|
||
|
|
pGraphic->setFaultLeakage(pData->getFaultLeakage().getValue().toDouble());
|
||
|
|
|
||
|
|
pGraphic->blockSignals(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 建立图元与数据的双向信号连接
|
||
|
|
void nmPlotGraphicBinder::_connectFault(nmObjLineFault* pGraphic, nmDataFault* pData)
|
||
|
|
{
|
||
|
|
QObject::connect(pGraphic, SIGNAL(sigFlowModelChanged(int)),
|
||
|
|
this, SLOT(onGraphicFlowModelChanged(int)));
|
||
|
|
|
||
|
|
QObject::connect(pGraphic, SIGNAL(sigLeakageChanged(double)),
|
||
|
|
this, SLOT(onGraphicLeakageChanged(double)));
|
||
|
|
|
||
|
|
QObject::connect(pGraphic, SIGNAL(sigPointsChanged()),
|
||
|
|
this, SLOT(onGraphicPointsChanged()));
|
||
|
|
|
||
|
|
QObject::connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
|
||
|
|
this, SLOT(onGraphicVisibleChanged(bool)));
|
||
|
|
|
||
|
|
m_mapFaultData[pGraphic] = pData;
|
||
|
|
|
||
|
|
m_setBoundGraphics.insert(pGraphic);
|
||
|
|
|
||
|
|
pGraphic->setGraphicBinder(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 断开图元与本 Binder 的所有信号连接
|
||
|
|
void nmPlotGraphicBinder::_disconnectFault(nmObjLineFault* pGraphic)
|
||
|
|
{
|
||
|
|
QObject::disconnect(pGraphic, SIGNAL(sigFlowModelChanged(int)),
|
||
|
|
this, SLOT(onGraphicFlowModelChanged(int)));
|
||
|
|
|
||
|
|
QObject::disconnect(pGraphic, SIGNAL(sigLeakageChanged(double)),
|
||
|
|
this, SLOT(onGraphicLeakageChanged(double)));
|
||
|
|
|
||
|
|
QObject::disconnect(pGraphic, SIGNAL(sigPointsChanged()),
|
||
|
|
this, SLOT(onGraphicPointsChanged()));
|
||
|
|
|
||
|
|
QObject::disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
|
||
|
|
this, SLOT(onGraphicVisibleChanged(bool)));
|
||
|
|
|
||
|
|
m_setBoundGraphics.remove(pGraphic);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 图元属性变更 → 同步到数据
|
||
|
|
|
||
|
|
// 流动模型变更
|
||
|
|
void nmPlotGraphicBinder::onGraphicFlowModelChanged(int model)
|
||
|
|
{
|
||
|
|
nmObjLineFault* pGraphic = qobject_cast<nmObjLineFault*>(sender());
|
||
|
|
if (!pGraphic) return;
|
||
|
|
|
||
|
|
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
|
||
|
|
if (!pData) return;
|
||
|
|
|
||
|
|
nmDataAttribute attr = pData->getFaultFlowModel();
|
||
|
|
attr.setValue(model == 0 ? tr("Leaky") : tr("Composite Limit"));
|
||
|
|
pData->setFaultFlowModel(attr);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 渗漏率变更
|
||
|
|
void nmPlotGraphicBinder::onGraphicLeakageChanged(double leakage)
|
||
|
|
{
|
||
|
|
nmObjLineFault* pGraphic = qobject_cast<nmObjLineFault*>(sender());
|
||
|
|
if (!pGraphic) return;
|
||
|
|
|
||
|
|
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
|
||
|
|
if (!pData) return;
|
||
|
|
|
||
|
|
nmDataAttribute attr = pData->getFaultLeakage();
|
||
|
|
attr.setValue(leakage);
|
||
|
|
pData->setFaultLeakage(attr);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 点坐标变更
|
||
|
|
void nmPlotGraphicBinder::onGraphicPointsChanged()
|
||
|
|
{
|
||
|
|
nmObjLineFault* pGraphic = qobject_cast<nmObjLineFault*>(sender());
|
||
|
|
if (!pGraphic) return;
|
||
|
|
|
||
|
|
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
|
||
|
|
if (!pData) return;
|
||
|
|
|
||
|
|
pData->setFaultPoints(pGraphic->getAllValues());
|
||
|
|
pData->setFaultName(pGraphic->getName());
|
||
|
|
|
||
|
|
if (m_pDataMgr) {
|
||
|
|
m_pDataMgr->notifyDataChanged();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 可见性变更
|
||
|
|
void nmPlotGraphicBinder::onGraphicVisibleChanged(bool bVisible)
|
||
|
|
{
|
||
|
|
nmObjLineFault* pGraphic = qobject_cast<nmObjLineFault*>(sender());
|
||
|
|
if (!pGraphic) return;
|
||
|
|
|
||
|
|
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
|
||
|
|
if (!pData) return;
|
||
|
|
|
||
|
|
pData->setPlotVisible(bVisible);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 数据变更(预留)
|
||
|
|
void nmPlotGraphicBinder::onDataChanged()
|
||
|
|
{
|
||
|
|
}
|