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/nmPlotGraphicBinder.cpp

2554 lines
85 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "nmPlotGraphicBinder.h"
#include "nmObjLineFault.h"
#include "nmDataFault.h"
#include "nmObjLineCrack.h"
#include "nmDataFracture.h"
#include "nmObjRoundOutline.h"
#include "nmObjRectOutline.h"
#include "nmObjPolygonOutline.h"
#include "nmDataOutline.h"
#include "nmObjLineMeasure.h"
#include "nmDataMeasure.h"
#include "nmObjRegionMark.h"
#include "nmDataRegionMark.h"
#include "nmObjRegion.h"
#include "nmDataRegion.h"
#include "nmObjBase.h"
#include "nmDataAnalyzeManager.h"
#include "nmGuiPlot.h"
#include "nmPlotView.h"
#include "nmObjPointWell.h"
#include "nmDataWellBase.h"
#include "nmDataVerticalFracturedWell.h"
#include "nmDataHorizontalFracturedWell.h"
#include "nmPlotDialogContext.h"
#include "nmPlotDialogContextProvider.h"
#include "ZxDataWell.h"
#include "ZxObjText.h"
#include "ZxDataGaugeP.h"
#include "ZxDataGaugeF.h"
#include "ZxBaseUtil.h"
#include "ZxRenderView.h"
#include "ZxPlot.h"
#include "Defines.h"
#include "iDataTypes.h"
#include "zxSysUtils.h"
#include "IxPtyPano.h"
#include "IxPtyItem.h"
#include <QMetaObject>
#include <QMessageBox>
#include <QPointer>
#include <QPolygonF>
#include <QScopedValueRollback>
#include <QUndoStack>
namespace {
// 数据已更新时屏蔽图元的反向通知,参数编辑仍使用地图历史记录坐标。
bool applyWellGraphicPosition(nmObjPointWell* graphic, nmDataWellBase* data,
bool recordPositionEdit)
{
const QPointF position(data->getX().getValue().toDouble(), data->getY().getValue().toDouble());
const QVector<QPointF> points(1, position);
if (graphic->getAllValues() == points) return false;
const bool wasBlocked = graphic->blockSignals(true);
bool changed = true;
if (recordPositionEdit) {
changed = graphic->commitPointValues(points);
} else {
graphic->setAllValues(points);
}
graphic->blockSignals(wasBlocked);
return changed;
}
// 历史标识仅存在于运行中的数据对象上。业务数据序列化和拷贝不带该标识。
template<typename Graphic, typename Data>
void syncHistoryIds(const QMap<Graphic*, Data*>& bindings, bool restore)
{
for (typename QMap<Graphic*, Data*>::const_iterator it = bindings.constBegin();
it != bindings.constEnd(); ++it) {
if (restore) {
it.key()->setHistoryId(it.value()->property("nmMapHistoryId").toString());
} else {
it.value()->setProperty("nmMapHistoryId", it.key()->property("nmMapHistoryId"));
}
}
}
// 参数面板回写图元后,同步当前选中对象的左侧属性项。
void refreshPropertyValue(nmObjBase* pGraphic, const QString& key, const QVariant& value)
{
if (pGraphic == nullptr || !pGraphic->isSelected()) return;
IxPtyPano* pPano = pGraphic->getPtyPano();
if (pPano == nullptr) return;
IxPtyItem* pItem = pPano->findPropertyItem(key);
if (pItem != nullptr && pItem->getValue() != value) {
pItem->setValue(value, pGraphic);
}
}
// 回放时同步数据、图元与属性面板,直接设置底色以避免再次入栈。
void applyRegionFill(nmObjRegion* graphic, nmDataRegion* data,
nmDataRegion::FillMode mode, const QColor& color)
{
QColor fill = color;
if (data != nullptr) {
if (mode == nmDataRegion::AutomaticFill) {
const nmDataRegionMark* mark = data->getRegionMarkData();
fill = mark != nullptr ? mark->getBackgroundColor() : QColor(Qt::transparent);
}
data->setFillMode(mode);
data->setBackgrdColor(fill);
}
graphic->setBackgrdColor(fill);
refreshPropertyValue(graphic, "ObjRect.BackgrdColor", QVariant::fromValue(fill));
if (ZxPlot* plot = graphic->getPlot()) plot->setModified(true);
}
// 以会话内的图元标识定位区域,删除后撤销删除仍可回放此前的改色。
class nmRegionFillCommand : public QUndoCommand
{
public:
// 保存改色前的来源和颜色,首次入栈时由 redo 提交新色。
nmRegionFillCommand(nmPlotGraphicBinder* binder, nmObjRegion* graphic,
const nmDataRegion& data, const QColor& color)
: m_binder(binder), m_plot(graphic->getPlot()), m_id(graphic->historyId()),
m_previousMode(data.getFillMode()), m_previousColor(data.getBackgrdColor()),
m_color(color)
{
}
virtual void undo() override { apply(m_previousMode, m_previousColor); }
virtual void redo() override { apply(nmDataRegion::ManualFill, m_color); }
private:
// 从画布取得当前区域,再从绑定器取得当前数据。
void apply(nmDataRegion::FillMode mode, const QColor& color)
{
if (m_binder.isNull()) return;
nmObjRegion* graphic = qobject_cast<nmObjRegion*>(
nmObjBase::findHistoryObject(m_plot.data(), m_id));
if (graphic == nullptr) return;
if (nmDataRegion* data = m_binder->getRegionDataFor(graphic)) {
applyRegionFill(graphic, data, mode, color);
}
}
QPointer<nmPlotGraphicBinder> m_binder; // 原地图的绑定器。
QPointer<ZxPlot> m_plot; // 原画布,销毁后无需回放。
QString m_id; // 区域重建后沿用的会话标识。
nmDataRegion::FillMode m_previousMode; // 改色前的自动或手动填充状态。
QColor m_previousColor; // 改色前保存的底色。
QColor m_color; // 用户选择的新底色。
};
}
nmPlotGraphicBinder::WellRenderData::WellRenderData()
: valid(false)
, wellType(Vertical_Well)
, x(0.0)
, y(0.0)
, radius(0.0)
, wellLength(0.0)
, drainAngle(0.0)
{
}
nmPlotGraphicBinder::nmPlotGraphicBinder(nmDataAnalyzeManager* pDataMgr, QObject* parent)
: QObject(parent)
, m_pDataMgr(pDataMgr)
, m_pWritingWellPosition(nullptr)
{
}
QVector<QPointF> nmPlotGraphicBinder::pointSnapCandidates(ZxRenderView* pView, ZxObjBase* pGraphic)
{
// 从正在操作的视图向上找到 Map,不使用全局当前分析的数据。
nmGuiPlot* pMap = nullptr;
for (QWidget* pWidget = pView; pWidget != nullptr; pWidget = pWidget->parentWidget()) {
pMap = qobject_cast<nmGuiPlot*>(pWidget);
if (pMap != nullptr) break;
}
if (pMap == nullptr || pMap->boundDataManager() == nullptr) {
return QVector<QPointF>();
}
nmDataAnalyzeManager* pManager = pMap->boundDataManager();
if (pGraphic == nullptr) {
return pManager->getPosAllConnectablePoints();
}
nmPlotGraphicBinder* pBinder = pMap->graphicBinder();
if (pBinder == nullptr) return QVector<QPointF>();
QObject* pExcludedData = nullptr;
if (nmObjLineCrack* pCrack = qobject_cast<nmObjLineCrack*>(pGraphic)) {
pExcludedData = pBinder->m_mapCrackData.value(pCrack, nullptr);
} else if (nmObjLineFault* pFault = qobject_cast<nmObjLineFault*>(pGraphic)) {
pExcludedData = pBinder->m_mapFaultData.value(pFault, nullptr);
} else if (nmObjRegion* pRegion = qobject_cast<nmObjRegion*>(pGraphic)) {
pExcludedData = pBinder->m_mapRegionData.value(pRegion, nullptr);
} else if (nmObjPolygonOutline* pOutline = qobject_cast<nmObjPolygonOutline*>(pGraphic)) {
pExcludedData = pBinder->m_mapOutlineData.value(pOutline, nullptr);
}
// 尚未绑定业务数据时不启用编辑吸附,防止把当前图元自身当成候选。
return pExcludedData != nullptr ? pManager->removePosByObject(pExcludedData)
: QVector<QPointF>();
}
// 用户画完断层后:创建数据对象并建立绑定
void nmPlotGraphicBinder::createFaultForGraphic(nmObjLineFault* pGraphic)
{
if (!pGraphic || !m_pDataMgr) {
return;
}
// 创建数据对象
nmDataFault* pData = m_pDataMgr->createFault();
// 将图元值推入数据
pData->setFaultName(pGraphic->getName());
pData->setFaultPoints(pGraphic->getAllValues());
nmDataAttribute faultFlowModel = pData->getFaultFlowModel();
faultFlowModel.setValue(pGraphic->getFaultFlowModel() == 0 ? tr("Leaky") : tr("Composite limit"));
pData->setFaultFlowModel(faultFlowModel);
nmDataAttribute faultLeakage = pData->getFaultLeakage();
faultLeakage.setValue(pGraphic->getFaultLeakage());
pData->setFaultLeakage(faultLeakage);
// 建立信号连接
_connectFault(pGraphic, pData);
m_pDataMgr->notifyGeometryListChanged();
}
// 从文件加载:绑定已有数据到已有图元
void nmPlotGraphicBinder::bindFaultToGraphic(nmObjLineFault* pGraphic, nmDataFault* pData)
{
if (!pGraphic || !pData) {
return;
}
// 将数据值推到图元
pGraphic->setName(pData->getFaultName());
_pushFaultDataToGraphic(pGraphic, pData);
pGraphic->setVisible(pData->getPlotVisible());
// 建立信号连接
_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);
}
// 名称同步:检测图元名称与数据名称是否一致,不一致则同步
void nmPlotGraphicBinder::syncFaultName(nmObjLineFault* pGraphic)
{
if (!pGraphic) return;
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
if (pData && pData->getFaultName() != pGraphic->getName()) {
pData->setFaultName(pGraphic->getName());
if (m_pDataMgr) {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
}
void nmPlotGraphicBinder::syncMapObjectName(nmObjBase* graphic)
{
if (graphic == nullptr) return;
if (nmObjLineFault* fault = qobject_cast<nmObjLineFault*>(graphic)) {
syncFaultName(fault);
} else if (nmObjLineCrack* crack = qobject_cast<nmObjLineCrack*>(graphic)) {
syncCrackName(crack);
} else if (nmObjRegion* region = qobject_cast<nmObjRegion*>(graphic)) {
syncRegionData(region);
} else if (nmObjRegionMark* mark = qobject_cast<nmObjRegionMark*>(graphic)) {
syncRegionMarkData(mark);
} else if (nmObjPointWell* well = qobject_cast<nmObjPointWell*>(graphic)) {
syncWellData(well);
} else {
syncOutlineName(graphic);
}
}
// 切换分析时更新绑定的 DataManager
// Map 重建时先解除测量刷新连接并清理映射,供调用方安全移除旧图元。
void nmPlotGraphicBinder::updateDataMgr(nmDataAnalyzeManager* pDataMgr)
{
// 重建或切换 Map 时先断开旧测量数据的刷新连接,再清空图元映射。
foreach(nmDataMeasure* pMeasureData, m_mapMeasureData.values()) {
QObject::disconnect(pMeasureData, SIGNAL(sigMeasureDataChanged()),
this, SLOT(onMeasureDataChanged()));
}
m_mapFaultData.clear();
m_setBoundGraphics.clear();
m_mapCrackData.clear();
m_setBoundCrackGraphics.clear();
m_mapOutlineData.clear();
m_setBoundOutlineGraphics.clear();
m_mapMeasureData.clear();
m_mapRegionMarkData.clear();
m_setBoundRegionMarkGraphics.clear();
m_mapRegionData.clear();
m_setBoundRegionGraphics.clear();
m_mapWellData.clear();
m_setBoundWellGraphics.clear();
m_pDataMgr = pDataMgr;
}
void nmPlotGraphicBinder::syncMapHistoryIds(bool restore)
{
syncHistoryIds(m_mapFaultData, restore);
syncHistoryIds(m_mapCrackData, restore);
syncHistoryIds(m_mapOutlineData, restore);
syncHistoryIds(m_mapWellData, restore);
syncHistoryIds(m_mapRegionData, restore);
syncHistoryIds(m_mapRegionMarkData, restore);
}
// 将数据值推到图元本地副本
void nmPlotGraphicBinder::_pushFaultDataToGraphic(nmObjLineFault* pGraphic, nmDataFault* pData, bool recordPointEdit)
{
// 阻断信号,防止推送中触发反向同步
bool bOldSignalsBlocked = pGraphic->blockSignals(true);
if (recordPointEdit) {
pGraphic->commitPointValues(pData->getFaultPoints());
} else {
pGraphic->setAllValues(pData->getFaultPoints());
}
int flowModel = (pData->getFaultFlowModel().getValue() == tr("Leaky")) ? 0 : 1;
pGraphic->setFaultFlowModel(flowModel);
pGraphic->setFaultLeakage(pData->getFaultLeakage().getValue().toDouble());
pGraphic->blockSignals(bOldSignalsBlocked);
refreshPropertyValue(pGraphic, "ObjLineFaultStartPos.StartPointX", pData->getStartX().getValue());
refreshPropertyValue(pGraphic, "ObjLineFaultStartPos.StartPointY", pData->getStartY().getValue());
refreshPropertyValue(pGraphic, "ObjLineFaultEndPos.EndPointX", pData->getEndX().getValue());
refreshPropertyValue(pGraphic, "ObjLineFaultEndPos.EndPointY", pData->getEndY().getValue());
pGraphic->update();
}
// 建立图元与数据的双向信号连接
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()));
// 框架加点、撤销和重做走 setAllPos,只发通用点集信号。
QObject::connect(pGraphic, SIGNAL(sigPtsChanged()),
this, SLOT(onGraphicPointsChanged()), Qt::UniqueConnection);
QObject::connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicVisibleChanged(bool)));
QObject::connect(pData, SIGNAL(sigFaultDataChanged()),
this, SLOT(onFaultDataChanged()), Qt::UniqueConnection);
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(sigPtsChanged()),
this, SLOT(onGraphicPointsChanged()));
QObject::disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicVisibleChanged(bool)));
nmDataFault* pData = m_mapFaultData.value(pGraphic, nullptr);
if (pData != nullptr) {
QObject::disconnect(pData, SIGNAL(sigFaultDataChanged()),
this, SLOT(onFaultDataChanged()));
}
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;
const QVector<QPointF> points = pGraphic->getAllValues();
// 一次拖动可能同时发出通用信号和业务信号,相同点集只通知一次。
if (pData->getFaultPoints() == points) return;
const bool pointCountChanged = pData->getFaultPoints().count() != points.count();
pData->setFaultPoints(points);
if (m_pDataMgr) {
if (pointCountChanged) {
m_pDataMgr->notifyGeometryListChanged();
} else {
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::onFaultDataChanged()
{
nmDataFault* pData = qobject_cast<nmDataFault*>(sender());
if (!pData) return;
nmObjLineFault* pGraphic = m_mapFaultData.key(pData, nullptr);
if (pGraphic) {
_pushFaultDataToGraphic(pGraphic, pData, true);
}
}
// 数据变更(预留)
void nmPlotGraphicBinder::onDataChanged()
{
}
// ============ 裂缝绑定 ============
// 用户画完裂缝后:创建数据对象并建立绑定
void nmPlotGraphicBinder::createCrackForGraphic(nmObjLineCrack* pGraphic)
{
createCrackForGraphic(pGraphic, true);
}
void nmPlotGraphicBinder::createCrackForGraphic(nmObjLineCrack* pGraphic, bool bNotifyGeometryList)
{
if (!pGraphic || !m_pDataMgr) {
return;
}
// 创建数据对象
nmDataFracture* pData = m_pDataMgr->createFracture();
// 将图元值推入数据
pData->setFractureName(pGraphic->getName());
pData->setFracturePoints(pGraphic->getAllValues());
nmDataAttribute fractureFlowModel = pData->getFractureFlowModel();
fractureFlowModel.setValue(pGraphic->getCrackFlowModel() == 0 ? tr("Infinite Conductivity") : tr("Finite Conductivity"));
pData->setFractureFlowModel(fractureFlowModel);
nmDataAttribute fractureDfc = pData->getFractureDfc();
fractureDfc.setValue(pGraphic->getCrackDfc());
pData->setFractureDfc(fractureDfc);
nmDataAttribute fractureDw = pData->getFractureDw();
fractureDw.setValue(pGraphic->getCrackDw());
pData->setFractureDw(fractureDw);
// 建立信号连接
_connectCrack(pGraphic, pData);
if (bNotifyGeometryList) {
m_pDataMgr->notifyGeometryListChanged();
} else {
m_pDataMgr->notifyDataChanged();
}
}
// 从文件加载:绑定已有裂缝数据到已有图元
void nmPlotGraphicBinder::bindCrackToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData)
{
if (!pGraphic || !pData) {
return;
}
// 将数据值推到图元
pGraphic->setName(pData->getFractureName());
_pushCrackDataToGraphic(pGraphic, pData);
pGraphic->setVisible(pData->getPlotVisible());
// 建立信号连接
_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::detachCrackBinding(nmObjLineCrack* pGraphic)
{
if (!pGraphic) return nullptr;
_disconnectCrack(pGraphic);
return m_mapCrackData.take(pGraphic);
}
nmDataFracture* nmPlotGraphicBinder::getCrackDataFor(nmObjLineCrack* pGraphic)
{
return m_mapCrackData.value(pGraphic, nullptr);
}
// 名称同步:检测图元名称与数据名称是否一致,不一致则同步
void nmPlotGraphicBinder::syncCrackName(nmObjLineCrack* pGraphic)
{
if (!pGraphic) return;
nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr);
if (pData && pData->getFractureName() != pGraphic->getName()) {
pData->setFractureName(pGraphic->getName());
// DFN 裂缝不在参数面板中显示,改名时无需重建面板。
if (m_pDataMgr && pData->getFractureType().getValue().toString() != "DFN") {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
}
// 将裂缝数据值推到图元本地副本
void nmPlotGraphicBinder::_pushCrackDataToGraphic(nmObjLineCrack* pGraphic, nmDataFracture* pData, bool recordPointEdit)
{
// 阻断信号,防止推送中触发反向同步
bool bOldSignalsBlocked = pGraphic->blockSignals(true);
if (recordPointEdit) {
pGraphic->commitPointValues(pData->getFracturePoints());
} else {
pGraphic->setAllValues(pData->getFracturePoints());
}
const QString sModel = pData->getFractureFlowModel().getValue().toString();
// 新数据使用稳定英文标识,同时兼容旧工程保存的中文模型名称。
int flowModel = (sModel == "Infinite Conductivity" || sModel == tr("Infinite Conductivity")
|| sModel == QString::fromWCharArray(L"无限导流")) ? 0 : 1;
pGraphic->setCrackFlowModel(flowModel);
pGraphic->setCrackDfc(pData->getFractureDfc().getValue().toDouble());
pGraphic->setCrackDw(pData->getFractureDw().getValue().toDouble());
pGraphic->blockSignals(bOldSignalsBlocked);
refreshPropertyValue(pGraphic, "ObjLineCrackStartPos.StartPointX", pData->getStartX().getValue());
refreshPropertyValue(pGraphic, "ObjLineCrackStartPos.StartPointY", pData->getStartY().getValue());
refreshPropertyValue(pGraphic, "ObjLineCrackEndPos.EndPointX", pData->getEndX().getValue());
refreshPropertyValue(pGraphic, "ObjLineCrackEndPos.EndPointY", pData->getEndY().getValue());
refreshPropertyValue(pGraphic, "ObjLineFracture.dFc", pData->getFractureDfc().getValue());
pGraphic->update();
}
// 建立裂缝图元与数据的双向信号连接
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()));
// 框架加点、撤销和重做走 setAllPos,只发通用点集信号。
QObject::connect(pGraphic, SIGNAL(sigPtsChanged()),
this, SLOT(onGraphicCrackPointsChanged()), Qt::UniqueConnection);
QObject::connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicCrackVisibleChanged(bool)));
QObject::connect(pData, SIGNAL(sigFractureDataChanged()),
this, SLOT(onFractureDataChanged()), Qt::UniqueConnection);
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(sigPtsChanged()),
this, SLOT(onGraphicCrackPointsChanged()));
QObject::disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicCrackVisibleChanged(bool)));
nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr);
if (pData != nullptr) {
QObject::disconnect(pData, SIGNAL(sigFractureDataChanged()),
this, SLOT(onFractureDataChanged()));
}
m_setBoundCrackGraphics.remove(pGraphic);
}
// 裂缝流动模型变更
void nmPlotGraphicBinder::onGraphicCrackFlowModelChanged(int model)
{
nmObjLineCrack* pGraphic = qobject_cast<nmObjLineCrack*>(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<nmObjLineCrack*>(sender());
if (!pGraphic) return;
nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getFractureDfc().getValue().toDouble() != dfc) {
pData->getFractureDfc().setValue(dfc);
}
}
// 裂缝储能比变更
void nmPlotGraphicBinder::onGraphicCrackDwChanged(double dw)
{
nmObjLineCrack* pGraphic = qobject_cast<nmObjLineCrack*>(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<nmObjLineCrack*>(sender());
if (!pGraphic) return;
nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr);
if (!pData) return;
const QVector<QPointF> points = pGraphic->getAllValues();
// 一次拖动可能同时发出通用信号和业务信号,相同点集只通知一次。
if (pData->getFracturePoints() == points) return;
const bool pointCountChanged = pData->getFracturePoints().count() != points.count();
pData->setFracturePoints(points);
if (m_pDataMgr) {
if (pointCountChanged) {
m_pDataMgr->notifyGeometryListChanged();
} else {
m_pDataMgr->notifyDataChanged();
}
}
}
// 裂缝可见性变更
void nmPlotGraphicBinder::onGraphicCrackVisibleChanged(bool bVisible)
{
nmObjLineCrack* pGraphic = qobject_cast<nmObjLineCrack*>(sender());
if (!pGraphic) return;
nmDataFracture* pData = m_mapCrackData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPlotVisible(bVisible);
}
// 数据参数变更 -> 同步到图元和左侧属性面板
void nmPlotGraphicBinder::onFractureDataChanged()
{
nmDataFracture* pData = qobject_cast<nmDataFracture*>(sender());
if (!pData) return;
nmObjLineCrack* pGraphic = m_mapCrackData.key(pData, nullptr);
if (pGraphic) {
_pushCrackDataToGraphic(pGraphic, pData, true);
}
}
// ==================== 边界图元绑定 ====================
// 圆形边界:用户画完后创建数据并绑定
void nmPlotGraphicBinder::createOutlineForGraphic(nmObjRoundOutline* pGraphic)
{
if (!pGraphic || !m_pDataMgr) return;
// 清理旧边界图元的绑定(数据中心同一时间只持有一个边界数据)
QList<nmObjBase*> oldGraphics = m_mapOutlineData.keys();
foreach (nmObjBase* pOld, oldGraphics) {
if (pOld != pGraphic) {
_disconnectOutline(pOld);
m_mapOutlineData.remove(pOld);
}
}
nmDataOutline* pData = m_pDataMgr->createOutline();
pData->setName(pGraphic->getName());
pData->setOutlinePoints(pGraphic->getAllValues());
pData->setFlowTypeList(pGraphic->m_vFlowTypeList);
pData->setOutlineType(NM_Data_Outline_Type::NM_Round_Outline_Type);
// 视觉属性同步到数据
pData->setPen(pGraphic->getPen());
QColor roundClr = pGraphic->getBackgrdColor();
pData->setBackgrdColor(roundClr);
pData->setBackgrdAlpha(roundClr.alpha());
pData->setVisualPropsValid(true);
double qradius = qAbs(pGraphic->getAllValues()[2].y() - pGraphic->getAllValues()[0].y());
pData->setRadius(qradius);
pData->setCenter(pGraphic->getAllValues()[0]);
m_mapOutlineData[pGraphic] = pData;
m_setBoundOutlineGraphics.insert(pGraphic);
_connectOutline(pGraphic, pData);
if (m_pDataMgr) {
m_pDataMgr->notifyGeometryListChanged();
}
}
// 矩形边界:用户画完后创建数据并绑定
void nmPlotGraphicBinder::createOutlineForGraphic(nmObjRectOutline* pGraphic)
{
if (!pGraphic || !m_pDataMgr) return;
// 清理旧边界图元的绑定(数据中心同一时间只持有一个边界数据)
QList<nmObjBase*> oldGraphics = m_mapOutlineData.keys();
foreach (nmObjBase* pOld, oldGraphics) {
if (pOld != pGraphic) {
_disconnectOutline(pOld);
m_mapOutlineData.remove(pOld);
}
}
nmDataOutline* pData = m_pDataMgr->createOutline();
pData->setName(pGraphic->getName());
pData->setOutlinePoints(pGraphic->getAllValues());
pData->setFlowTypeList(pGraphic->m_vFlowTypeList);
pData->setOutlineType(NM_Data_Outline_Type::NM_Rect_Outline_Type);
pData->setPen(pGraphic->getPen());
pData->setBackgrdColor(pGraphic->getBackgrdColor());
pData->setBackgrdAlpha(pGraphic->getBackgrdAlpha());
pData->setVisualPropsValid(true);
m_mapOutlineData[pGraphic] = pData;
m_setBoundOutlineGraphics.insert(pGraphic);
_connectOutline(pGraphic, pData);
if (m_pDataMgr) {
m_pDataMgr->notifyGeometryListChanged();
}
}
// 多边形边界:用户画完后创建数据并绑定
void nmPlotGraphicBinder::createOutlineForGraphic(nmObjPolygonOutline* pGraphic)
{
if (!pGraphic || !m_pDataMgr) return;
// 清理旧边界图元的绑定(数据中心同一时间只持有一个边界数据)
QList<nmObjBase*> oldGraphics = m_mapOutlineData.keys();
foreach (nmObjBase* pOld, oldGraphics) {
if (pOld != pGraphic) {
_disconnectOutline(pOld);
m_mapOutlineData.remove(pOld);
}
}
nmDataOutline* pData = m_pDataMgr->createOutline();
pData->setName(pGraphic->getName());
pData->setOutlinePoints(pGraphic->getAllValues());
pData->setFlowTypeList(pGraphic->m_vFlowTypeList);
pData->setOutlineType(NM_Data_Outline_Type::NM_Polygon_Outline_Type);
pData->setPen(pGraphic->getPen());
pData->setBackgrdColor(pGraphic->getBackgrdColor());
pData->setBackgrdAlpha(pGraphic->getBackgrdAlpha());
pData->setVisualPropsValid(true);
m_mapOutlineData[pGraphic] = pData;
m_setBoundOutlineGraphics.insert(pGraphic);
_connectOutline(pGraphic, pData);
if (m_pDataMgr) {
m_pDataMgr->notifyGeometryListChanged();
}
}
// 从文件加载,绑定已有边界数据到已有图元
void nmPlotGraphicBinder::bindOutlineToGraphic(nmObjBase* pGraphic, nmDataOutline* pData)
{
if (!pGraphic || !pData) return;
m_mapOutlineData[pGraphic] = pData;
m_setBoundOutlineGraphics.insert(pGraphic);
pGraphic->setName(pData->getName());
_pushOutlineDataToGraphic(pGraphic, pData);
pGraphic->setVisible(pData->getPlotVisible());
if (!pData->hasVisualProps()) {
// 未打开Map就保存的边界没有有效视觉属性。保留新图元的默认样式,
// 并立即回填数据,保证下一次保存得到可重复恢复的有效样式。
syncOutlineVisual(pGraphic);
}
_connectOutline(pGraphic, pData);
}
// 删除边界图元前断开绑定,按调用方要求移除对应数据。
void nmPlotGraphicBinder::removeOutlineBinding(nmObjBase* pGraphic, bool removeData)
{
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
_disconnectOutline(pGraphic);
m_mapOutlineData.remove(pGraphic);
if (removeData && m_pDataMgr && pData != nullptr && m_pDataMgr->getOutlineData() == pData) {
m_pDataMgr->removeOutlineData();
}
}
// 查找边界图元对应的数据指针
nmDataOutline* nmPlotGraphicBinder::getOutlineDataFor(nmObjBase* pGraphic)
{
return m_mapOutlineData.value(pGraphic, nullptr);
}
// 名称同步:setName 不发信号,由图元在 paintBack 中调用
void nmPlotGraphicBinder::syncOutlineName(nmObjBase* pGraphic)
{
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (pData && pData->getName() != pGraphic->getName()) {
pData->setName(pGraphic->getName());
if (m_pDataMgr) {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
}
// 视觉属性兜底同步:paintBack 中调用,确保画笔、填充色、透明度与数据中心一致。
void nmPlotGraphicBinder::syncOutlineVisual(nmObjBase* pGraphic)
{
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPen(pGraphic->getPen());
// 填充背景色和透明度
QColor backgrdColor;
int backgrdAlpha = 0;
if (nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pGraphic)) {
backgrdColor = pRect->getBackgrdColor();
backgrdAlpha = pRect->getBackgrdAlpha();
} else if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
backgrdColor = pRound->getBackgrdColor();
backgrdAlpha = backgrdColor.alpha(); // 圆形透明度嵌入在 QColor 中
} else if (nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pGraphic)) {
backgrdColor = pPolygon->getBackgrdColor();
backgrdAlpha = pPolygon->getBackgrdAlpha();
}
if (pData->getBackgrdColor().rgb() != backgrdColor.rgb()) {
pData->setBackgrdColor(backgrdColor);
}
if (pData->getBackgrdAlpha() != backgrdAlpha) {
pData->setBackgrdAlpha(backgrdAlpha);
}
pData->setVisualPropsValid(true);
}
// 建立边界图元与数据的信号连接
void nmPlotGraphicBinder::_connectOutline(nmObjBase* pGraphic, nmDataOutline* pData)
{
QObject::connect(pGraphic, SIGNAL(sigOutlinePointsChanged()),
this, SLOT(onGraphicOutlinePointsChanged()), Qt::UniqueConnection);
QObject::connect(pGraphic, SIGNAL(sigOutlineFlowTypeChanged()),
this, SLOT(onGraphicOutlineFlowTypeChanged()), Qt::UniqueConnection);
QObject::connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicOutlineVisibleChanged(bool)), Qt::UniqueConnection);
QObject::connect(pGraphic, SIGNAL(sigMapPenChanged()),
this, SLOT(onGraphicOutlinePenChanged()), Qt::UniqueConnection);
QObject::connect(pData, SIGNAL(sigOutlineDataChanged()),
this, SLOT(onOutlineDataChanged()), Qt::UniqueConnection);
m_setBoundOutlineGraphics.insert(pGraphic);
// 注入 Binder 指针到图元
if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
pRound->setGraphicBinder(this);
} else if (nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pGraphic)) {
pRect->setGraphicBinder(this);
} else if (nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pGraphic)) {
pPolygon->setGraphicBinder(this);
}
}
// 断开边界图元与本 Binder 的信号连接
void nmPlotGraphicBinder::_disconnectOutline(nmObjBase* pGraphic)
{
QObject::disconnect(pGraphic, SIGNAL(sigOutlinePointsChanged()),
this, SLOT(onGraphicOutlinePointsChanged()));
QObject::disconnect(pGraphic, SIGNAL(sigOutlineFlowTypeChanged()),
this, SLOT(onGraphicOutlineFlowTypeChanged()));
QObject::disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicOutlineVisibleChanged(bool)));
QObject::disconnect(pGraphic, SIGNAL(sigMapPenChanged()),
this, SLOT(onGraphicOutlinePenChanged()));
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (pData != nullptr) {
QObject::disconnect(pData, SIGNAL(sigOutlineDataChanged()),
this, SLOT(onOutlineDataChanged()));
}
if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
pRound->setGraphicBinder(nullptr);
} else if (nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pGraphic)) {
pRect->setGraphicBinder(nullptr);
} else if (nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pGraphic)) {
pPolygon->setGraphicBinder(nullptr);
}
m_setBoundOutlineGraphics.remove(pGraphic);
}
// 从边界数据对象读取值,写入图元本地副本(加载及参数变更时用)
void nmPlotGraphicBinder::_pushOutlineDataToGraphic(nmObjBase* pGraphic, nmDataOutline* pData,
bool recordPointEdit)
{
bool bOldSignalsBlocked = pGraphic->blockSignals(true);
if (recordPointEdit) {
pGraphic->commitPointValues(pData->getOutlinePoints());
} else {
pGraphic->setAllValues(pData->getOutlinePoints());
}
QVector<int> flowTypes = pData->getFlowTypeList();
const bool bPushVisual = pData->hasVisualProps();
if (bPushVisual) {
pGraphic->setPen(pData->getPen(pGraphic->getPen()));
}
if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
pRound->m_vFlowTypeList = flowTypes;
if (bPushVisual) {
QColor clr = pData->getBackgrdColor();
clr.setAlpha(pData->getBackgrdAlpha());
pRound->setBackgrdColor(clr);
}
} else if (nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pGraphic)) {
pRect->m_vFlowTypeList = flowTypes;
if (bPushVisual) {
pRect->setBackgrdColor(pData->getBackgrdColor());
pRect->setBackgrdAlpha(pData->getBackgrdAlpha());
}
} else if (nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pGraphic)) {
pPolygon->m_vFlowTypeList = flowTypes;
if (bPushVisual) {
pPolygon->setBackgrdColor(pData->getBackgrdColor());
pPolygon->setBackgrdAlpha(pData->getBackgrdAlpha());
}
}
pGraphic->blockSignals(bOldSignalsBlocked);
pGraphic->update();
}
// ==================== 边界图元信号 → 数据同步 ====================
void nmPlotGraphicBinder::onGraphicOutlinePenChanged()
{
nmObjBase* pGraphic = qobject_cast<nmObjBase*>(sender());
if (nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr)) {
pData->setPen(pGraphic->getPen());
if (ZxPlot* plot = pGraphic->getPlot()) plot->setModified(true);
}
}
// 边界点坐标变更
void nmPlotGraphicBinder::onGraphicOutlinePointsChanged()
{
nmObjBase* pGraphic = qobject_cast<nmObjBase*>(sender());
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (!pData) return;
const int nOldPointCount = pData->getOutlinePointCount();
const QVector<QPointF> points = pGraphic->getAllValues();
pData->setOutlinePoints(points);
// 多边形插点会拆分边,坐标和对应流动类型必须在通知刷新前一起写回。
if (nmObjPolygonOutline* pPolygon = qobject_cast<nmObjPolygonOutline*>(pGraphic)) {
pData->setFlowTypeList(pPolygon->m_vFlowTypeList);
}
// 圆形边界额外同步 radius 和 center
if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
QVector<QPointF> pts = pRound->getAllValues();
if (pts.count() >= 3) {
double radius = qAbs(pts[2].y() - pts[0].y());
pData->setRadius(radius);
pData->setCenter(pts[0]);
}
}
if (m_pDataMgr) {
if (nOldPointCount != points.count()) {
m_pDataMgr->notifyGeometryListChanged();
} else {
m_pDataMgr->notifyDataChanged();
}
}
}
// 数据参数变更 -> 同步到图元
void nmPlotGraphicBinder::onOutlineDataChanged()
{
nmDataOutline* pData = qobject_cast<nmDataOutline*>(sender());
if (!pData) return;
nmObjBase* pGraphic = m_mapOutlineData.key(pData, nullptr);
if (pGraphic) {
_pushOutlineDataToGraphic(pGraphic, pData, true);
}
}
// 使用图元会话标识回放,切换分析或撤销删除后可定位重建的边界。
class nmPlotGraphicBinder::OutlineFlowTypeCommand : public QUndoCommand
{
public:
OutlineFlowTypeCommand(nmPlotGraphicBinder* binder, nmObjBase* graphic,
const QVector<int>& before, const QVector<int>& after)
: m_binder(binder), m_plot(graphic->getPlot()), m_id(graphic->historyId()),
m_before(before), m_after(after)
{
}
virtual void undo() override { apply(m_before); }
virtual void redo() override { apply(m_after); }
private:
// 回放阶段不再经过属性编辑入口。
void apply(const QVector<int>& types)
{
if (m_binder.isNull()) return;
if (nmObjBase* graphic = nmObjBase::findHistoryObject(m_plot.data(), m_id)) {
m_binder->applyOutlineFlowTypes(graphic, types);
}
}
QPointer<nmPlotGraphicBinder> m_binder; // 当前地图的绑定器。
QPointer<ZxPlot> m_plot; // 命令所属的画布。
QString m_id; // 边界重建时沿用的会话标识。
QVector<int> m_before; // 编辑前各边的流动类型。
QVector<int> m_after; // 编辑后各边的流动类型。
};
void nmPlotGraphicBinder::applyOutlineFlowTypes(nmObjBase* graphic, const QVector<int>& types)
{
nmDataOutline* data = m_mapOutlineData.value(graphic, nullptr);
if (data == nullptr || data->getFlowTypeList() == types) return;
data->setFlowTypeList(types);
if (nmObjRoundOutline* round = qobject_cast<nmObjRoundOutline*>(graphic)) {
round->m_vFlowTypeList = types;
refreshPropertyValue(round, "ObjPolygonOutline.Type", round->getCurOutlineFlowType());
} else if (nmObjRectOutline* rect = qobject_cast<nmObjRectOutline*>(graphic)) {
rect->m_vFlowTypeList = types;
if (types.size() >= 4) {
refreshPropertyValue(rect, "ObjRectOutline.TopOutline", types.at(0));
refreshPropertyValue(rect, "ObjRectOutline.RightOutline", types.at(1));
refreshPropertyValue(rect, "ObjRectOutline.BottomOutline", types.at(2));
refreshPropertyValue(rect, "ObjRectOutline.LeftOutline", types.at(3));
}
} else if (nmObjPolygonOutline* polygon = qobject_cast<nmObjPolygonOutline*>(graphic)) {
polygon->m_vFlowTypeList = types;
refreshPropertyValue(polygon, "ObjPolygonOutline.Type", polygon->getCurOutlineFlowType());
}
if (ZxPlot* plot = graphic->getPlot()) plot->setModified(true);
if (m_pDataMgr != nullptr) m_pDataMgr->notifyDataChanged();
}
// 边界流动类型变更
void nmPlotGraphicBinder::onGraphicOutlineFlowTypeChanged()
{
nmObjBase* pGraphic = qobject_cast<nmObjBase*>(sender());
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (!pData) return;
QVector<int> flowTypes;
if (nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pGraphic)) {
flowTypes = pRound->m_vFlowTypeList;
} else if (nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pGraphic)) {
flowTypes = pRect->m_vFlowTypeList;
} else if (nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pGraphic)) {
flowTypes = pPolygon->m_vFlowTypeList;
}
const QVector<int> previous = pData->getFlowTypeList();
if (previous == flowTypes) return;
nmPlotView* view = qobject_cast<nmPlotView*>(pGraphic->getView());
QUndoStack* stack = view != nullptr ? view->mapEditHistory() : nullptr;
if (stack != nullptr && pGraphic->getPlot() != nullptr) {
stack->push(new OutlineFlowTypeCommand(this, pGraphic, previous, flowTypes));
} else {
applyOutlineFlowTypes(pGraphic, flowTypes);
}
}
// 边界可见性变更
void nmPlotGraphicBinder::onGraphicOutlineVisibleChanged(bool bVisible)
{
nmObjBase* pGraphic = qobject_cast<nmObjBase*>(sender());
if (!pGraphic) return;
nmDataOutline* pData = m_mapOutlineData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPlotVisible(bVisible);
// 显隐只更新绘图状态,不改变网格或求解输入。
}
// ==================== 测量线图元 ====================
// 用户画完测量线后:获取数据对象并建立绑定
void nmPlotGraphicBinder::createMeasureForGraphic(nmObjLineMeasure* pGraphic)
{
if (!pGraphic || !m_pDataMgr) {
return;
}
// 获取测量数据单例
nmDataMeasure* pData = m_pDataMgr->getMeasureData();
// 同一图元再次绑定时先清除旧连接,避免初始化端点期间反向覆盖新线段。
removeMeasureBinding(pGraphic);
// 将图元坐标推入数据
QVector<QPointF> pts = pGraphic->getAllValues();
if (pts.count() >= 2) {
QPointF pStart = pts[0];
QPointF pEnd = pts[1];
double dLength = QLineF(pStart, pEnd).length();
// 单击测量也保存起终点,避免重绘时被尚未更新的原点坐标覆盖。
pData->setStartPoint(pStart);
pData->setEndPoint(pEnd);
pData->setCurrentPoint(pEnd == pStart ? pStart : QPointF(0, 0));
nmDataAttribute lenAttr = pData->getLength();
lenAttr.setValue(dLength);
pData->setLength(lenAttr);
}
// 建立映射
m_mapMeasureData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
// 对话框只修改模型;由绑定器负责把变更送回所属画布,不依赖偶然重绘。
// 测距通过测量数据自己的信号刷新,避免触发 PEBI 网格失效。
QObject::connect(pData, SIGNAL(sigMeasureDataChanged()),
this, SLOT(onMeasureDataChanged()), Qt::UniqueConnection);
}
// 删除测量线图元:移除映射(不删除数据对象,由 DataManager 管理)
void nmPlotGraphicBinder::removeMeasureBinding(nmObjLineMeasure* pGraphic)
{
if (!pGraphic) {
return;
}
nmDataMeasure* pData = m_mapMeasureData.take(pGraphic);
// 一个数据对象可能关联多个图元,仅在最后一个绑定移除后断开刷新。
if(pData != nullptr && !m_mapMeasureData.values().contains(pData)) {
QObject::disconnect(pData, SIGNAL(sigMeasureDataChanged()),
this, SLOT(onMeasureDataChanged()));
}
}
void nmPlotGraphicBinder::onMeasureDataChanged()
{
nmDataMeasure* pData = qobject_cast<nmDataMeasure*>(sender());
if(pData == nullptr) {
return;
}
QMap<nmObjLineMeasure*, nmDataMeasure*>::const_iterator it = m_mapMeasureData.constBegin();
for(; it != m_mapMeasureData.constEnd(); ++it) {
if(it.key() == nullptr || it.value() != pData) {
continue;
}
nmObjLineMeasure* pGraphic = it.key();
syncMeasurePoints(pGraphic);
ZxRenderView* pView = pGraphic->getView();
if(pView != nullptr) {
// 更新整个视口,覆盖拟合前后的线段区域,避免旧位置留下残影。
pView->viewport()->update();
}
}
}
// 同步端点但不触发重绘,避免 paintBack 中的兜底调用形成循环刷新。
void nmPlotGraphicBinder::syncMeasurePoints(nmObjLineMeasure* pGraphic)
{
if (!pGraphic || !m_pDataMgr) return;
nmDataMeasure* pData = m_mapMeasureData.value(pGraphic, nullptr);
if (!pData) return;
QPointF startPt = pData->getStartPoint();
QPointF endPt = pData->getEndPoint();
// 仅在坐标确实变化时才更新,避免每次绘制都无谓写入
QVector<QPointF> currentPts = pGraphic->getAllValues();
if (currentPts.count() >= 2 &&
currentPts[0] == startPt && currentPts[1] == endPt) {
return;
}
const bool bOldSignalsBlocked = pGraphic->blockSignals(true);
QVector<QPointF> pts;
pts << startPt << endPt;
pGraphic->setAllValues(pts);
pGraphic->blockSignals(bOldSignalsBlocked);
}
// ==================== 区域标记图元 ====================
namespace {
// 沿用六种半透明填充色,颜色顺序独立于区域归属规则。
const int regionMarkColorCount = 6;
QColor regionMarkColor(int index)
{
return QColor::fromHsv((index % regionMarkColorCount) * 60, 255, 255, 128).toRgb();
}
// 旧版自动填充包含固定的色相和透明度,匹配完整 RGBA 才作为迁移依据。
bool isRegionMarkPaletteColor(const QColor& color)
{
if (!color.isValid()) return false;
for (int i = 0; i < regionMarkColorCount; ++i) {
if (color.rgba() == regionMarkColor(i).rgba()) return true;
}
return false;
}
// 优先使用地图上尚未使用的颜色,六种颜色用完后循环。
QColor nextRegionMarkColor(const QVector<nmDataRegionMark*>& marks)
{
QSet<QRgb> usedColors;
foreach (const nmDataRegionMark* mark, marks) {
if (mark != nullptr && mark->getBackgroundColor().isValid()) {
usedColors.insert(mark->getBackgroundColor().rgba());
}
}
for (int i = 0; i < regionMarkColorCount; ++i) {
const QColor color = regionMarkColor(i);
if (!usedColors.contains(color.rgba())) return color;
}
return regionMarkColor(marks.size());
}
}
// 用户画完区域标记后:创建数据对象并建立绑定
void nmPlotGraphicBinder::createRegionMarkForGraphic(nmObjRegionMark* pGraphic)
{
if (!pGraphic || !m_pDataMgr || m_mapRegionMarkData.contains(pGraphic)) {
return;
}
// 创建时分配一次颜色。恢复已有数据时沿用原色。
const QColor color = nextRegionMarkColor(m_pDataMgr->getRegionMarkDataList());
nmDataRegionMark* pData = m_pDataMgr->createRegionMark();
pData->setBackgroundColor(color);
// 将图元值推入数据
pData->setRegionMarkName(pGraphic->getName());
QVector<QPointF> pts = pGraphic->getAllValues();
if (pts.count() >= 1) {
pData->setPtPos(pts[0]);
}
// 储层类型:int → 字符串
nmDataAttribute attr = pData->getReservoirType();
if (pGraphic->getResevoirType() == 0) {
attr.setValue("Homogeneous");
} else {
attr.setValue("Dual porosity pseudo steady state");
}
pData->setReservoirType(attr);
// 综合压缩系数、净毛比
nmDataAttribute comKrAttr = pData->getComKr();
comKrAttr.setValue(pGraphic->getComKr());
pData->setComKr(comKrAttr);
nmDataAttribute comWAttr = pData->getComW();
comWAttr.setValue(pGraphic->getComW());
pData->setComW(comWAttr);
nmDataAttribute ntgAttr = pData->getNetToGross();
ntgAttr.setValue(pGraphic->getNetToGross());
pData->setNetToGross(ntgAttr);
// 建立信号连接
_connectRegionMark(pGraphic, pData);
refreshRegionMarkAssignments();
m_pDataMgr->notifyGeometryListChanged();
}
// 从文件加载:绑定已有区域标记数据到已有图元
void nmPlotGraphicBinder::bindRegionMarkToGraphic(nmObjRegionMark* pGraphic, nmDataRegionMark* pData)
{
if (!pGraphic || !pData) {
return;
}
// 将数据值推到图元本地副本
_pushRegionMarkDataToGraphic(pGraphic, pData);
// 建立信号连接
pGraphic->setVisible(pData->getPlotVisible());
_connectRegionMark(pGraphic, pData);
}
// 删除区域标记图元:从数据中心移除数据并断开信号
void nmPlotGraphicBinder::removeRegionMarkBinding(nmObjRegionMark* pGraphic)
{
if (!pGraphic) {
return;
}
_disconnectRegionMark(pGraphic);
nmDataRegionMark* pData = m_mapRegionMarkData.take(pGraphic);
if (pData && m_pDataMgr) {
// 先重算归属,清理对即将销毁的标记数据的引用。
refreshRegionMarkAssignments();
m_pDataMgr->removeRegionMarkData(pData);
}
}
// 兜底同步框架管理的名称(由 paintBack 调用)。
void nmPlotGraphicBinder::syncRegionMarkData(nmObjRegionMark* pGraphic)
{
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getRegionMarkName() != pGraphic->getName()) {
pData->setRegionMarkName(pGraphic->getName());
if (m_pDataMgr) {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
}
void nmPlotGraphicBinder::syncRegionMarkMove(nmObjRegionMark* pGraphic)
{
nmDataRegionMark* data = m_mapRegionMarkData.value(pGraphic, nullptr);
if (data == nullptr) return;
const QVector<QPointF> points = pGraphic->getAllValues();
if (points.isEmpty() || data->getPtPos() == points.first()) return;
data->setPtPos(points.first());
refreshRegionMarkAssignments();
notifyDataChanged();
}
void nmPlotGraphicBinder::refreshRegionMarkAssignments()
{
if (m_pDataMgr == nullptr) return;
// 加载和恢复保留列表顺序,先创建且位于区域中的标记优先生效。
QSet<nmDataRegionMark*> boundMarks;
foreach (nmDataRegionMark* mark, m_mapRegionMarkData) boundMarks.insert(mark);
QVector<nmDataRegionMark*> orderedMarks;
foreach (nmDataRegionMark* mark, m_pDataMgr->getRegionMarkDataList()) {
if (boundMarks.contains(mark)) {
orderedMarks.append(mark);
mark->setSelectRegion(false);
}
}
// 同一个旧标记可能覆盖多个区域。只有已保存的色板颜色一致时,才由它反推标记颜色。
QMap<nmDataRegionMark*, QColor> legacyMarkColors;
for (auto it = m_mapRegionData.constBegin(); it != m_mapRegionData.constEnd(); ++it) {
nmDataRegion* regionData = it.value();
const QPolygonF polygon(regionData->getVecPts());
nmDataRegionMark* owner = nullptr;
foreach (nmDataRegionMark* candidate, orderedMarks) {
if (polygon.containsPoint(candidate->getPtPos(), Qt::OddEvenFill)) {
owner = candidate;
break;
}
}
regionData->setRegionMarkData(owner);
if (owner == nullptr) continue;
owner->setSelectRegion(true);
if (owner->getBackgroundColor().isValid() || regionData->getFillMode() != nmDataRegion::LegacyFill) {
continue;
}
const QColor savedFill = regionData->getBackgrdColor();
if (!isRegionMarkPaletteColor(savedFill)) continue;
const auto candidate = legacyMarkColors.constFind(owner);
if (candidate == legacyMarkColors.constEnd()) {
legacyMarkColors.insert(owner, savedFill);
} else if (candidate.value().isValid() && candidate.value().rgba() != savedFill.rgba()) {
legacyMarkColors[owner] = QColor();
}
}
for (int i = 0; i < orderedMarks.size(); ++i) {
nmDataRegionMark* mark = orderedMarks.at(i);
if (mark->getBackgroundColor().isValid()) continue;
const QColor inferredColor = legacyMarkColors.value(mark);
mark->setBackgroundColor(inferredColor.isValid() ? inferredColor : regionMarkColor(i));
}
for (auto it = m_mapRegionData.constBegin(); it != m_mapRegionData.constEnd(); ++it) {
nmObjRegion* region = it.key();
nmDataRegion* regionData = it.value();
nmDataRegionMark* owner = regionData->getRegionMarkData();
const QColor automaticFill = owner != nullptr ? owner->getBackgroundColor() : QColor(Qt::transparent);
if (regionData->getFillMode() == nmDataRegion::LegacyFill) {
// 存在多种候选色时保留各区域旧底色,其余情况按推导的自动色判定。
const auto legacyColor = legacyMarkColors.constFind(owner);
const bool ambiguous = legacyColor != legacyMarkColors.constEnd() && !legacyColor.value().isValid();
const bool useAutomaticFill = !ambiguous && regionData->getBackgrdColor().rgba() == automaticFill.rgba();
regionData->setFillMode(useAutomaticFill ? nmDataRegion::AutomaticFill : nmDataRegion::ManualFill);
}
if (regionData->getFillMode() == nmDataRegion::AutomaticFill) {
regionData->setBackgrdColor(automaticFill);
}
const QColor fill = regionData->getBackgrdColor();
if (region->getBackgrdColor() != fill) {
region->setBackgrdColor(fill);
refreshPropertyValue(region, "ObjRect.BackgrdColor", QVariant::fromValue(fill));
}
}
}
// 查找区域标记图元对应的数据指针
nmDataRegionMark* nmPlotGraphicBinder::getRegionMarkDataFor(nmObjRegionMark* pGraphic)
{
return m_mapRegionMarkData.value(pGraphic, nullptr);
}
// 图元信号 → 数据同步
void nmPlotGraphicBinder::onGraphicRegionMarkReservoirTypeChanged(int type)
{
nmObjRegionMark* pGraphic = qobject_cast<nmObjRegionMark*>(sender());
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
nmDataAttribute attr = pData->getReservoirType();
if (type == 0) {
attr.setValue("Homogeneous");
} else {
attr.setValue("Dual porosity pseudo steady state");
}
pData->setReservoirType(attr);
if (m_pDataMgr) {
m_pDataMgr->notifyDataChanged();
}
}
void nmPlotGraphicBinder::onGraphicRegionMarkComKrChanged(double comKr)
{
nmObjRegionMark* pGraphic = qobject_cast<nmObjRegionMark*>(sender());
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getComKr().getValue().toDouble() != comKr) {
pData->getComKr().setValue(comKr);
}
if (m_pDataMgr) {
m_pDataMgr->notifyDataChanged();
}
}
void nmPlotGraphicBinder::onGraphicRegionMarkComWChanged(double comW)
{
nmObjRegionMark* pGraphic = qobject_cast<nmObjRegionMark*>(sender());
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getComW().getValue().toDouble() != comW) {
pData->getComW().setValue(comW);
}
if (m_pDataMgr) {
m_pDataMgr->notifyDataChanged();
}
}
void nmPlotGraphicBinder::onGraphicRegionMarkNetToGrossChanged(double netToGross)
{
nmObjRegionMark* pGraphic = qobject_cast<nmObjRegionMark*>(sender());
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getNetToGross().getValue().toDouble() != netToGross) {
pData->getNetToGross().setValue(netToGross);
}
if (m_pDataMgr) {
m_pDataMgr->notifyDataChanged();
}
}
void nmPlotGraphicBinder::onGraphicRegionMarkVisibleChanged(bool bVisible)
{
nmObjRegionMark* pGraphic = qobject_cast<nmObjRegionMark*>(sender());
if (!pGraphic) return;
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPlotVisible(bVisible);
// 显隐只更新绘图状态,不改变网格或求解输入。
}
// 建立信号连接
void nmPlotGraphicBinder::_connectRegionMark(nmObjRegionMark* pGraphic, nmDataRegionMark* pData)
{
if (!pGraphic || !pData) return;
m_mapRegionMarkData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
if (m_setBoundRegionMarkGraphics.contains(pGraphic)) {
return;
}
connect(pGraphic, SIGNAL(sigResevoirTypeChanged(int)),
this, SLOT(onGraphicRegionMarkReservoirTypeChanged(int)));
connect(pGraphic, SIGNAL(sigPtsChanged()), this, SLOT(onGraphicRegionMarkPositionChanged()));
connect(pGraphic, SIGNAL(sigComKrChanged(double)),
this, SLOT(onGraphicRegionMarkComKrChanged(double)));
connect(pGraphic, SIGNAL(sigComWChanged(double)),
this, SLOT(onGraphicRegionMarkComWChanged(double)));
connect(pGraphic, SIGNAL(sigNetToGrossChanged(double)),
this, SLOT(onGraphicRegionMarkNetToGrossChanged(double)));
connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicRegionMarkVisibleChanged(bool)));
connect(pData, SIGNAL(sigRegionMarkDataChanged()),
this, SLOT(onRegionMarkDataChanged()), Qt::UniqueConnection);
m_setBoundRegionMarkGraphics.insert(pGraphic);
}
// 断开信号连接
void nmPlotGraphicBinder::_disconnectRegionMark(nmObjRegionMark* pGraphic)
{
if (!pGraphic) return;
if (!m_setBoundRegionMarkGraphics.contains(pGraphic)) {
return;
}
disconnect(pGraphic, SIGNAL(sigResevoirTypeChanged(int)),
this, SLOT(onGraphicRegionMarkReservoirTypeChanged(int)));
disconnect(pGraphic, SIGNAL(sigPtsChanged()), this, SLOT(onGraphicRegionMarkPositionChanged()));
disconnect(pGraphic, SIGNAL(sigComKrChanged(double)),
this, SLOT(onGraphicRegionMarkComKrChanged(double)));
disconnect(pGraphic, SIGNAL(sigComWChanged(double)),
this, SLOT(onGraphicRegionMarkComWChanged(double)));
disconnect(pGraphic, SIGNAL(sigNetToGrossChanged(double)),
this, SLOT(onGraphicRegionMarkNetToGrossChanged(double)));
disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicRegionMarkVisibleChanged(bool)));
nmDataRegionMark* pData = m_mapRegionMarkData.value(pGraphic, nullptr);
if (pData != nullptr) {
disconnect(pData, SIGNAL(sigRegionMarkDataChanged()),
this, SLOT(onRegionMarkDataChanged()));
}
m_setBoundRegionMarkGraphics.remove(pGraphic);
}
// 从数据对象读取值,写入图元本地副本(加载及参数变更时用)
void nmPlotGraphicBinder::_pushRegionMarkDataToGraphic(nmObjRegionMark* pGraphic, nmDataRegionMark* pData)
{
bool bOldSignalsBlocked = pGraphic->blockSignals(true);
// 储层类型:字符串 → int
if (pData->getReservoirType().getValue() == "Homogeneous") {
pGraphic->setResevoirType(0);
} else {
pGraphic->setResevoirType(1);
}
pGraphic->setComKr(pData->getComKr().getValue().toDouble());
pGraphic->setComW(pData->getComW().getValue().toDouble());
pGraphic->setNetToGross(pData->getNetToGross().getValue().toDouble());
// 位置
QVector<QPointF> pts;
pts << pData->getPtPos();
pGraphic->setAllValues(pts);
pGraphic->blockSignals(bOldSignalsBlocked);
refreshPropertyValue(pGraphic, "ObjRegionMark.dComW", pData->getComW().getValue());
refreshPropertyValue(pGraphic, "ObjRegionMark.dComKr", pData->getComKr().getValue());
refreshPropertyValue(pGraphic, "ObjRegionMark.NetToGross", pData->getNetToGross().getValue());
pGraphic->update();
}
// 数据参数变更 -> 同步到图元和左侧属性面板
void nmPlotGraphicBinder::onRegionMarkDataChanged()
{
nmDataRegionMark* pData = qobject_cast<nmDataRegionMark*>(sender());
if (!pData) return;
nmObjRegionMark* pGraphic = m_mapRegionMarkData.key(pData, nullptr);
if (pGraphic) {
const bool positionChanged = pGraphic->getPtCount() > 0 &&
pGraphic->getPtValueOf(0) != pData->getPtPos();
_pushRegionMarkDataToGraphic(pGraphic, pData);
if (positionChanged) refreshRegionMarkAssignments();
}
}
// ==================== 复合区图元 ====================
// 用户画完复合区后,创建数据并建立绑定
void nmPlotGraphicBinder::createRegionForGraphic(nmObjRegion* pGraphic)
{
if (!pGraphic || !m_pDataMgr) {
return;
}
// 创建数据对象
nmDataRegion* pData = m_pDataMgr->createRegion();
// 将图元值推入数据
pData->setRegionName(pGraphic->getName());
pData->setVecPts(pGraphic->getAllValues());
// 流动模型
nmDataAttribute flowModelAttr = pData->getRegionFlowModel();
flowModelAttr.setValue(pGraphic->getRegionFlowModel() == 0 ? "Leaky" : "Composite limit");
pData->setRegionFlowModel(flowModelAttr);
// 泄漏系数
nmDataAttribute leakageAttr = pData->getRegionLeakage();
leakageAttr.setValue(pGraphic->getRegionLeakage());
pData->setRegionLeakage(leakageAttr);
pData->setPenWidth(pGraphic->getPen().widthF());
pData->setBackgrdColor(pGraphic->getBackgrdColor());
if (pData->getBackgrdColor().alpha() != 0) {
// 有底色的区域样式模板等同于预先设置了手动底色。
pData->setFillMode(nmDataRegion::ManualFill);
}
// 建立映射
m_mapRegionData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
// 建立信号连接
_connectRegion(pGraphic, pData);
refreshRegionMarkAssignments();
m_pDataMgr->notifyGeometryListChanged();
}
// 从文件加载:绑定已有数据到已有图元
void nmPlotGraphicBinder::bindRegionToGraphic(nmObjRegion* pGraphic, nmDataRegion* pData)
{
if (!pGraphic || !pData) {
return;
}
m_mapRegionData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
_pushRegionDataToGraphic(pGraphic, pData);
pGraphic->setVisible(pData->getPlotVisible());
_connectRegion(pGraphic, pData);
}
// 删除复合区图元前,断开信号并清理映射
void nmPlotGraphicBinder::removeRegionBinding(nmObjRegion* pGraphic)
{
if (!pGraphic) {
return;
}
_disconnectRegion(pGraphic);
nmDataRegion* pData = m_mapRegionData.take(pGraphic);
if (pData && m_pDataMgr) {
refreshRegionMarkAssignments();
m_pDataMgr->removeRegionData(pData);
}
}
// 兜底同步框架管理的名称和画笔宽度(由 paintBack 调用)。
void nmPlotGraphicBinder::syncRegionData(nmObjRegion* pGraphic)
{
if (!pGraphic) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getRegoinName() != pGraphic->getName()) {
pData->setRegionName(pGraphic->getName());
if (m_pDataMgr) {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
QPen pen = pGraphic->getPen();
if (pData->getPenWidth() != pen.widthF()) {
pData->setPenWidth(pen.widthF());
}
}
void nmPlotGraphicBinder::setRegionManualFill(nmObjRegion* pGraphic, const QColor& color)
{
if (pGraphic == nullptr || pGraphic->isReadOnly()) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
nmPlotView* view = qobject_cast<nmPlotView*>(pGraphic->getView());
if (pData != nullptr && view != nullptr && view->mapEditHistory() != nullptr &&
pGraphic->getPlot() != nullptr) {
view->mapEditHistory()->push(new nmRegionFillCommand(this, pGraphic, *pData, color));
} else {
applyRegionFill(pGraphic, pData, nmDataRegion::ManualFill, color);
}
}
// 查找复合区图元对应的数据指针
nmDataRegion* nmPlotGraphicBinder::getRegionDataFor(nmObjRegion* pGraphic)
{
return m_mapRegionData.value(pGraphic, nullptr);
}
// 复合区图元信号 → 数据同步
void nmPlotGraphicBinder::onGraphicRegionPointsChanged()
{
nmObjRegion* pGraphic = qobject_cast<nmObjRegion*>(sender());
if (!pGraphic) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (!pData) return;
const QVector<QPointF> points = pGraphic->getAllValues();
if (pData->getVecPts() == points) return;
const bool pointCountChanged = pData->getVecPts().count() != points.count();
pData->setVecPts(points);
refreshRegionMarkAssignments();
if (m_pDataMgr) {
if (pointCountChanged) {
m_pDataMgr->notifyGeometryListChanged();
} else {
m_pDataMgr->notifyDataChanged();
}
}
}
void nmPlotGraphicBinder::onGraphicRegionFlowModelChanged(int model)
{
nmObjRegion* pGraphic = dynamic_cast<nmObjRegion*>(sender());
if (!pGraphic) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (!pData) return;
nmDataAttribute attr = pData->getRegionFlowModel();
if (model == 0)
attr.setValue("Leaky");
else
attr.setValue("Composite limit");
pData->setRegionFlowModel(attr);
}
void nmPlotGraphicBinder::onGraphicRegionLeakageChanged(double leakage)
{
nmObjRegion* pGraphic = dynamic_cast<nmObjRegion*>(sender());
if (!pGraphic) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (!pData) return;
if (pData->getRegionLeakage().getValue().toDouble() != leakage) {
pData->getRegionLeakage().setValue(leakage);
}
}
void nmPlotGraphicBinder::onGraphicRegionVisibleChanged(bool bVisible)
{
nmObjRegion* pGraphic = qobject_cast<nmObjRegion*>(sender());
if (!pGraphic) return;
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPlotVisible(bVisible);
}
// 建立信号连接
void nmPlotGraphicBinder::_connectRegion(nmObjRegion* pGraphic, nmDataRegion* pData)
{
if (!pGraphic || !pData) return;
if (m_setBoundRegionGraphics.contains(pGraphic)) return;
connect(pGraphic, SIGNAL(sigPtsChanged()),
this, SLOT(onGraphicRegionPointsChanged()), Qt::UniqueConnection);
connect(pGraphic, SIGNAL(sigRegionFlowModelChanged(int)),
this, SLOT(onGraphicRegionFlowModelChanged(int)));
connect(pGraphic, SIGNAL(sigRegionLeakageChanged(double)),
this, SLOT(onGraphicRegionLeakageChanged(double)));
connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicRegionVisibleChanged(bool)));
connect(pData, SIGNAL(sigRegionDataChanged()),
this, SLOT(onRegionDataChanged()), Qt::UniqueConnection);
m_setBoundRegionGraphics.insert(pGraphic);
}
// 断开信号连接
void nmPlotGraphicBinder::_disconnectRegion(nmObjRegion* pGraphic)
{
if (!pGraphic) return;
if (!m_setBoundRegionGraphics.contains(pGraphic)) return;
disconnect(pGraphic, SIGNAL(sigPtsChanged()),
this, SLOT(onGraphicRegionPointsChanged()));
disconnect(pGraphic, SIGNAL(sigRegionFlowModelChanged(int)),
this, SLOT(onGraphicRegionFlowModelChanged(int)));
disconnect(pGraphic, SIGNAL(sigRegionLeakageChanged(double)),
this, SLOT(onGraphicRegionLeakageChanged(double)));
disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicRegionVisibleChanged(bool)));
nmDataRegion* pData = m_mapRegionData.value(pGraphic, nullptr);
if (pData != nullptr) {
disconnect(pData, SIGNAL(sigRegionDataChanged()),
this, SLOT(onRegionDataChanged()));
}
m_setBoundRegionGraphics.remove(pGraphic);
}
// 从数据对象读取值,写入图元本地副本(加载及参数变更时用)
void nmPlotGraphicBinder::_pushRegionDataToGraphic(nmObjRegion* pGraphic, nmDataRegion* pData)
{
if (!pGraphic || !pData) return;
bool bOldSignalsBlocked = pGraphic->blockSignals(true);
// 流动模型:字符串 → int
if (pData->getRegionFlowModel().getValue() == "Leaky") {
pGraphic->setRegionFlowModel(0);
} else {
pGraphic->setRegionFlowModel(1);
}
pGraphic->setRegionLeakage(pData->getRegionLeakage().getValue().toDouble());
// 视觉属性:画笔宽度、填充背景色
QPen pen = pGraphic->getPen();
pen.setWidthF(pData->getPenWidth());
pGraphic->setPen(pen);
pGraphic->setBackgrdColor(pData->getBackgrdColor());
pGraphic->blockSignals(bOldSignalsBlocked);
refreshPropertyValue(pGraphic, "ObjRegion.Leakage", pData->getRegionLeakage().getValue());
pGraphic->update();
}
// 数据参数变更 -> 同步到图元和左侧属性面板
void nmPlotGraphicBinder::onRegionDataChanged()
{
nmDataRegion* pData = qobject_cast<nmDataRegion*>(sender());
if (!pData) return;
nmObjRegion* pGraphic = m_mapRegionData.key(pData, nullptr);
if (pGraphic) {
_pushRegionDataToGraphic(pGraphic, pData);
}
}
// ==================== 井图元 ====================
// 用户创建新井后,创建数据并建立绑定
nmDataWellBase* nmPlotGraphicBinder::createWellForGraphic(nmObjPointWell* pGraphic, NM_WELL_MODEL wellType)
{
if (!pGraphic || !m_pDataMgr) {
return nullptr;
}
nmDataWellBase* pData = m_pDataMgr->createWell(wellType);
// 建立图元到数值井数据的映射,图元后续只通过Binder访问井数据。
m_mapWellData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
pGraphic->markWellDataBound(wellType);
_connectWell(pGraphic, pData);
return pData;
}
// 从文件加载,绑定已有井数据到已有图元
void nmPlotGraphicBinder::bindWellToGraphic(nmObjPointWell* pGraphic, nmDataWellBase* pData, bool recordPositionEdit)
{
if (!pGraphic || !pData) {
return;
}
m_mapWellData[pGraphic] = pData;
pGraphic->setGraphicBinder(this);
_pushWellDataToGraphic(pGraphic, pData, recordPositionEdit);
_connectWell(pGraphic, pData);
}
void nmPlotGraphicBinder::updateWellDataMapping(
nmObjPointWell* pGraphic,
nmDataWellBase* pNewData)
{
if (!pGraphic || !pNewData) return;
// replaceWellData 已销毁旧井对象,其 QObject 连接会自动解除;这里补绑新对象。
m_mapWellData[pGraphic] = pNewData;
connect(pNewData, SIGNAL(sigWellDataChanged()),
this, SLOT(onWellDataChanged()), Qt::UniqueConnection);
}
// 删除井图元前,先校验可删除性并解除绑定,再由数据层销毁井对象。
bool nmPlotGraphicBinder::removeWellBinding(nmObjPointWell* pGraphic)
{
if (!pGraphic) {
return false;
}
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (!pData) {
_disconnectWell(pGraphic);
m_mapWellData.remove(pGraphic);
return true;
}
// removeWell()成功后会立即销毁数据对象,因此必须先解除全部连接和映射。
if (!m_pDataMgr || !m_pDataMgr->canRemoveWell(pData)) {
return false;
}
_disconnectWell(pGraphic);
m_mapWellData.remove(pGraphic);
if (!m_pDataMgr->removeWell(pData)) {
// 删除未发生时恢复完整绑定,避免图元与数据状态分叉。
m_mapWellData.insert(pGraphic, pData);
_connectWell(pGraphic, pData);
return false;
}
return true;
}
// 兜底同步:由井图元在 paintBack 中调用
// 同步图元名称、外观属性到数据中心,用于持久化保存。
void nmPlotGraphicBinder::syncWellData(nmObjPointWell* pGraphic)
{
if (!pGraphic) return;
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (!pData) return;
ZxDataWell* pWellData = pGraphic->getWellData();
// 属性面板改名会使图元名称与本分析的井名不同,只有这时才同步到工区。
const QString sName = pGraphic->getName();
if (!sName.isEmpty() && pData->getWellName() != sName) {
pData->setWellName(sName);
if (pWellData && pWellData->getName() != sName) {
pWellData->setName(sName);
pWellData->save();
}
if (m_pDataMgr) {
m_pDataMgr->notifyParameterObjectNameChanged();
}
}
// 同步图元外观属性到井数据(用于保存到 JSON)
ZxDot dot = pGraphic->getDot();
pData->setDotStyle(static_cast<int>(dot.style()));
QColor clr = dot.color();
pData->setDotColor(clr.red(), clr.green(), clr.blue());
pData->setDotRadius(dot.radius());
pData->setDotFilling(dot.isFilling());
pData->setShowSubObjs(pGraphic->isShowSubObjs());
}
// 查找井图元对应的数据指针
nmDataWellBase* nmPlotGraphicBinder::getWellDataFor(nmObjPointWell* pGraphic)
{
return m_mapWellData.value(pGraphic, nullptr);
}
bool nmPlotGraphicBinder::hasWellDataFor(nmObjPointWell* pGraphic) const
{
return m_mapWellData.value(pGraphic, nullptr) != nullptr;
}
bool nmPlotGraphicBinder::isPrimaryWellGraphic(
nmObjPointWell* pGraphic) const
{
if (!m_pDataMgr || !pGraphic) return false;
return m_pDataMgr->isPrimaryWell(
m_mapWellData.value(pGraphic, nullptr));
}
void nmPlotGraphicBinder::syncWellMoveFromGraphic(nmObjPointWell* pGraphic,
NM_WELL_MODEL wellType,
const QPointF& newLocation)
{
if (!pGraphic) return;
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (!pData) return;
QScopedValueRollback<nmDataWellBase*> positionScope(m_pWritingWellPosition);
m_pWritingWellPosition = pData;
// 每个分析有独立历史,回放仅更新该分析的井位和裂缝几何。
if (!pGraphic->isApplyingGeometryHistory()) {
if (ZxDataWell* pWellData = pGraphic->getWellData()) {
pWellData->setLocationX(newLocation.x());
pWellData->setLocationY(newLocation.y());
}
}
if (pData->getX().getValue().toDouble() != newLocation.x()) {
pData->getX().setValue(newLocation.x());
}
if (pData->getY().getValue().toDouble() != newLocation.y()) {
pData->getY().setValue(newLocation.y());
}
if (wellType == NM_WELL_MODEL::Vertical_Fractured_Well) {
// 裂缝井位置变化后,裂缝端点需要跟着重新计算。
if (nmDataVerticalFracturedWell* pVFWell = dynamic_cast<nmDataVerticalFracturedWell*>(pData)) {
pVFWell->setFracs();
}
} else if (wellType == NM_WELL_MODEL::Horizontal_Fractured_Well) {
// 水平裂缝井同样依赖井筒位置重新计算裂缝几何。
if (nmDataHorizontalFracturedWell* pHFWell = dynamic_cast<nmDataHorizontalFracturedWell*>(pData)) {
pHFWell->setFracs();
}
}
// 回写期间忽略数据通知,坐标和裂缝端点都更新后再重绘。
static_cast<nmObjBase*>(pGraphic)->update();
}
bool nmPlotGraphicBinder::ensureSelectedWellData(nmObjPointWell* pGraphic,
NM_WELL_MODEL& wellType)
{
if (!pGraphic) return false;
ZxDataWell* pWellData = pGraphic->getWellData();
if (!pWellData) return false;
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (pData != nullptr) {
// 已经绑定过的图元直接复用数据,避免重复创建数值井对象。
wellType = pData->getWellType();
return true;
}
// 选择井来自工程树,需要先把工程井类型转换成数值井类型。
const QString code = pWellData->getCode();
if (m_pDataMgr == nullptr || code.isEmpty() || m_pDataMgr->findWellByCode(code) != nullptr) return false;
QString wellClass = pWellData->getWellClassEn();
if(ZxBaseUtil::isSameStr(wellClass, "VerticalWell")) {
wellType = NM_WELL_MODEL::Vertical_Well;
} else if(ZxBaseUtil::isSameStr(wellClass, "VerticalFracturedWell")) {
wellType = NM_WELL_MODEL::Vertical_Fractured_Well;
} else if(ZxBaseUtil::isSameStr(wellClass, "HorizontalFracturedWell")
|| ZxBaseUtil::isSameStr(wellClass, "HorizontalMultiFracturedWell")) {
wellType = NM_WELL_MODEL::Horizontal_Fractured_Well;
} else {
return false;
}
QVector<nmPressureGaugeRecord> vecPressureRecords;
QVector<nmFlowGaugeRecord> vecFlowRecords;
NM_WELL_CATEGORY eWellCategory = NM_WellCategory_Unknown;
if(!nmDataAnalyzeManager::readFrameworkWellCurves(
pWellData,
vecPressureRecords,
vecFlowRecords,
eWellCategory)) {
return false;
}
pData = createWellForGraphic(pGraphic, wellType);
if (pData == nullptr) {
return false;
}
// 重新勾选井时在这里补建nmDataWell,并将工程树中的基础属性同步进去。
pData->setWellName(pWellData->getName());
pData->setWellCode(code);
pData->setWellCategory(eWellCategory);
{
QScopedValueRollback<nmDataWellBase*> positionScope(m_pWritingWellPosition);
m_pWritingWellPosition = pData;
nmDataAttribute x = pData->getX();
x.setValue(pWellData->getLocationX());
pData->setX(x);
nmDataAttribute y = pData->getY();
y.setValue(pWellData->getLocationY());
pData->setY(y);
applyWellGraphicPosition(pGraphic, pData, false);
}
nmDataAttribute tempAttr = pData->getRadius();
tempAttr.setValue(pWellData->getWellRadius());
pData->setRadius(tempAttr);
// 设置井的压力、流量记录列表,并按默认规则选中当前记录
nmDataAnalyzeManager::applyGaugeRecordsToWell(
pData, vecPressureRecords, vecFlowRecords);
if(pWellData != zxCurWell) {
// 非当前查看井仍默认选择井别参考相的最后一个真实段,索引保持一基。
pData->setIndexF(pData->getFlowSegmentCount());
}
if (wellType == NM_WELL_MODEL::Vertical_Fractured_Well) {
if (nmDataVerticalFracturedWell* pVFWell = dynamic_cast<nmDataVerticalFracturedWell*>(pData)) {
pVFWell->setFracs();
}
} else if (wellType == NM_WELL_MODEL::Horizontal_Fractured_Well) {
if (nmDataHorizontalFracturedWell* pHFWell = dynamic_cast<nmDataHorizontalFracturedWell*>(pData)) {
pHFWell->setFracs();
}
}
// 初始化历史压力、双对数和半对数数据,保证重新显示后可直接分析。
if(m_pDataMgr) {
m_pDataMgr->updateWellHistoryData(pData);
}
// 通知 PEBI 面板新增井分组
if (m_pDataMgr) {
m_pDataMgr->appendNmWellData(pData);
}
return true;
}
bool nmPlotGraphicBinder::editWellForGraphic(nmObjPointWell* pGraphic,
NM_WELL_MODEL& wellType,
ZxObjText* pNameLabel)
{
if (!pGraphic) return false;
if(!hasLayers()) {
QMessageBox::information(nullptr, tr("error"), tr("please setting layers Data!"));
return false;
}
nmPlotDialogContextProvider* pDialogProvider = nmPlotDialogContext::provider();
if(pDialogProvider == nullptr) {
return false;
}
nmDataWellBase* pOldData = m_mapWellData.value(pGraphic, nullptr);
if (pOldData == nullptr || m_pDataMgr == nullptr) {
return false;
}
// 第一步:Binder收集窗口所需上下文,编辑器不反向访问全局管理器。
QStringList listOtherWellNames;
QVector<nmDataWellBase*> vecWells = m_pDataMgr->getWellDataList();
for (int nWellIndex = 0; nWellIndex < vecWells.size(); ++nWellIndex) {
nmDataWellBase* pWell = vecWells[nWellIndex];
if (pWell != nullptr && pWell != pOldData) {
listOtherWellNames.append(pWell->getWellName());
}
}
nmWellEditContext oEditContext =
pDialogProvider->createWellEditContext(
pGraphic->getWellData(), pOldData, listOtherWellNames);
nmDataWellBase* pReturnWellData = nullptr;
// 第二步:窗口只操作独立工作副本,取消时不产生任何外部修改。
if(!pDialogProvider->editWell(nullptr, oEditContext, pReturnWellData)) {
return false;
}
if (pReturnWellData == nullptr) {
return false;
}
// 对比完整井参数和射孔数据,直接确认时保留已有网格与计算结果。
pReturnWellData->setWellCode(pOldData->getWellCode());
rapidjson::Document comparison;
if (pOldData->ToJsonValue(comparison.GetAllocator()) ==
pReturnWellData->ToJsonValue(comparison.GetAllocator())) {
delete pReturnWellData;
return false;
}
const QPointF position(pReturnWellData->getX().getValue().toDouble(),
pReturnWellData->getY().getValue().toDouble());
const bool positionChanged = position.x() != pOldData->getX().getValue().toDouble() ||
position.y() != pOldData->getY().getValue().toDouble();
const QString name = pReturnWellData->getWellName();
const bool nameChanged = name != pOldData->getWellName();
const double radius = pReturnWellData->getRadius().getValue().toDouble();
const bool radiusChanged = radius != pOldData->getRadius().getValue().toDouble();
// 数据中心接管新井后,再同步工区井和图元。
if (!m_pDataMgr->replaceWellData(pOldData, pReturnWellData)) {
delete pReturnWellData;
return false;
}
updateWellDataMapping(pGraphic, pReturnWellData);
// 数值井和图元独立提交,工区井存在时才同步共享属性。
ZxDataWell* pWellData = pGraphic->getWellData();
if (positionChanged) {
// 以图元原坐标记录历史,供本分析撤销和恢复。
pGraphic->commitPointValues(QVector<QPointF>(1, position));
if (pWellData != nullptr) {
pWellData->setLocationX(position.x());
pWellData->setLocationY(position.y());
}
}
if (nameChanged) {
pGraphic->setName(name);
if (pNameLabel != nullptr) pNameLabel->setText(name);
if (pWellData != nullptr) pWellData->setName(name);
}
if (radiusChanged && pWellData != nullptr) pWellData->setWellRadius(radius);
const NM_WELL_MODEL eWellType = pReturnWellData->getWellType();
if (pWellData != nullptr && eWellType != wellType) {
QString sWellClass;
if (eWellType == NM_WELL_MODEL::Vertical_Well) {
sWellClass = "VerticalWell";
} else if(eWellType == NM_WELL_MODEL::Vertical_Fractured_Well) {
sWellClass = "VerticalFracturedWell";
} else if(eWellType == NM_WELL_MODEL::Horizontal_Fractured_Well) {
sWellClass = "HorizontalFracturedWell";
}
pWellData->setWellClassCn(sWellClass);
}
wellType = eWellType;
return true;
}
nmPlotGraphicBinder::WellRenderData nmPlotGraphicBinder::getWellRenderData(nmObjPointWell* pGraphic) const
{
WellRenderData renderData;
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (!pData) {
return renderData;
}
// 图元绘制阶段只读取快照,不直接持有nmDataWell指针。
renderData.valid = true;
renderData.wellType = pData->getWellType();
renderData.x = pData->getX().getValue().toDouble();
renderData.y = pData->getY().getValue().toDouble();
renderData.radius = pData->getRadius().getValue().toDouble();
if (nmDataVerticalFracturedWell* pVFWell = dynamic_cast<nmDataVerticalFracturedWell*>(pData)) {
// 裂缝几何由数据对象预先计算,图元只负责坐标转换和绘制。
renderData.verticalFracs = pVFWell->getFracs();
} else if (nmDataHorizontalFracturedWell* pHFWell = dynamic_cast<nmDataHorizontalFracturedWell*>(pData)) {
// 水平井绘制需要井长、角度和多段裂缝几何。
renderData.wellLength = pHFWell->getWellLength().getValue().toDouble();
renderData.drainAngle = pHFWell->getDrainAngle().getValue().toDouble();
renderData.horizontalFracs = pHFWell->getFracs();
}
return renderData;
}
void nmPlotGraphicBinder::onGraphicWellVisibleChanged(bool bVisible)
{
nmObjPointWell* pGraphic = qobject_cast<nmObjPointWell*>(sender());
if (!pGraphic) return;
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (!pData) return;
pData->setPlotVisible(bVisible);
pGraphic->syncNameLabelVisibility();
}
void nmPlotGraphicBinder::onWellDataChanged()
{
nmDataWellBase* pData = qobject_cast<nmDataWellBase*>(sender());
if (pData == nullptr || pData == m_pWritingWellPosition) return;
nmObjPointWell* pGraphic = m_mapWellData.key(pData, nullptr);
if (pGraphic) {
if (applyWellGraphicPosition(pGraphic, pData, true)) {
// 批量参数窗口的原有提交会同步工区坐标,直接修改参数表仅写数值井。
nmPlotView* view = qobject_cast<nmPlotView*>(pGraphic->getView());
if (view != nullptr && view->mapGeometryEditGroup() != nullptr) {
syncWellMoveFromGraphic(pGraphic, pData->getWellType(), pGraphic->getPtValueOf(0));
}
if (ZxPlot* plot = pGraphic->getPlot()) plot->setModified(true);
}
// 保持与 nmGuiPlot 的现有调用方式一致,避免访问井类的 protected override。
static_cast<nmObjBase*>(pGraphic)->update();
}
}
bool nmPlotGraphicBinder::hasLayers() const
{
if (!m_pDataMgr) return false;
return !m_pDataMgr->getLayers().isEmpty();
}
nmDataWellBase* nmPlotGraphicBinder::getCurrentWellData() const
{
if (!m_pDataMgr) return nullptr;
return m_pDataMgr->getCurWellData();
}
void nmPlotGraphicBinder::setCurrentWellData(nmDataWellBase* pWellData)
{
if (!m_pDataMgr) return;
m_pDataMgr->setCurWellData(pWellData);
}
void nmPlotGraphicBinder::appendWellData(nmDataWellBase* pWellData)
{
if (!m_pDataMgr) return;
m_pDataMgr->appendNmWellData(pWellData);
}
void nmPlotGraphicBinder::removeWellData(nmDataWellBase* pWellData)
{
if (!m_pDataMgr || !pWellData) return;
m_pDataMgr->removeWell(pWellData);
}
void nmPlotGraphicBinder::notifyDataChanged()
{
if (!m_pDataMgr) return;
m_pDataMgr->notifyDataChanged();
}
// 建立信号连接
void nmPlotGraphicBinder::_connectWell(nmObjPointWell* pGraphic, nmDataWellBase* pData)
{
if (!pGraphic || !pData) return;
if (m_setBoundWellGraphics.contains(pGraphic)) return;
connect(pGraphic, SIGNAL(sigPtsChanged()), this, SLOT(onGraphicWellPositionChanged()));
connect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicWellVisibleChanged(bool)));
connect(pData, SIGNAL(sigWellDataChanged()),
this, SLOT(onWellDataChanged()), Qt::UniqueConnection);
m_setBoundWellGraphics.insert(pGraphic);
}
// 断开信号连接
void nmPlotGraphicBinder::_disconnectWell(nmObjPointWell* pGraphic)
{
if (!pGraphic) return;
if (!m_setBoundWellGraphics.contains(pGraphic)) return;
disconnect(pGraphic, SIGNAL(sigPtsChanged()), this, SLOT(onGraphicWellPositionChanged()));
disconnect(pGraphic, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onGraphicWellVisibleChanged(bool)));
nmDataWellBase* pData = m_mapWellData.value(pGraphic, nullptr);
if (pData) {
disconnect(pData, SIGNAL(sigWellDataChanged()),
this, SLOT(onWellDataChanged()));
}
m_setBoundWellGraphics.remove(pGraphic);
}
void nmPlotGraphicBinder::onGraphicWellPositionChanged()
{
nmObjPointWell* graphic = qobject_cast<nmObjPointWell*>(sender());
nmDataWellBase* data = m_mapWellData.value(graphic, nullptr);
if (data == nullptr || graphic->getPtCount() == 0) return;
const QPointF position = graphic->getPtValueOf(0);
// 参数窗口可能已更新数值井,相同坐标无需再次触发网格失效。
if (position == QPointF(data->getX().getValue().toDouble(), data->getY().getValue().toDouble())) return;
syncWellMoveFromGraphic(graphic, data->getWellType(), position);
if (ZxPlot* plot = graphic->getPlot()) plot->setModified(true);
notifyDataChanged();
}
void nmPlotGraphicBinder::onGraphicRegionMarkPositionChanged()
{
nmObjRegionMark* graphic = qobject_cast<nmObjRegionMark*>(sender());
if (graphic != nullptr) syncRegionMarkMove(graphic);
}
// 从井数据对象读取位置和外观,参数提交时同步记录位置编辑。
void nmPlotGraphicBinder::_pushWellDataToGraphic(nmObjPointWell* pGraphic, nmDataWellBase* pData, bool recordPositionEdit)
{
if (!pGraphic || !pData) return;
const bool wasBlocked = pGraphic->blockSignals(true);
pGraphic->markWellDataBound(pData->getWellType(), pData->getWellCode());
if (applyWellGraphicPosition(pGraphic, pData, recordPositionEdit) && recordPositionEdit) {
syncWellMoveFromGraphic(pGraphic, pData->getWellType(), pGraphic->getPtValueOf(0));
}
// 从井数据恢复图元外观属性(加载时从 JSON 恢复的属性设置到图元)
ZxDot dot = pGraphic->getDot();
dot.setStyle(static_cast<ZxDotType>(pData->getDotStyle()));
dot.setColor(QColor(pData->getDotColorR(), pData->getDotColorG(), pData->getDotColorB()));
dot.setRadius(pData->getDotRadius());
dot.setFilling(pData->getDotFilling());
pGraphic->setDot(dot);
pGraphic->setVisible(pData->getPlotVisible());
pGraphic->showSubObjs(pData->getShowSubObjs());
pGraphic->syncNameLabelVisibility();
pGraphic->blockSignals(wasBlocked);
}