diff --git a/Include/nmNum/nmSubWxs/nmWxIncludeOtherWells.h b/Include/nmNum/nmSubWxs/nmWxIncludeOtherWells.h index d349a0b..28cf3d4 100644 --- a/Include/nmNum/nmSubWxs/nmWxIncludeOtherWells.h +++ b/Include/nmNum/nmSubWxs/nmWxIncludeOtherWells.h @@ -93,6 +93,9 @@ private: void refreshRowEditors(int row); /** @brief 校正一行的分相状态及一基流动段索引。 */ void normalizeFlowSelection(WellDataRow& data) const; + /** @brief 保存旧记录的流动段,并恢复新记录自己的流动段。 */ + void switchRowFlowGaugeCode(WellDataRow& data, + const QString& sGaugeCode) const; /** @brief 更新包含复选框;没有有效分相选择时自动取消包含。 */ void updateIncludeCheckBox(int row); /** @brief 填充一列分相流量记录选项。 */ diff --git a/Src/nmNum/nmSubWxs/nmWxIncludeOtherWells.cpp b/Src/nmNum/nmSubWxs/nmWxIncludeOtherWells.cpp index adb52e9..1f3b4cd 100644 --- a/Src/nmNum/nmSubWxs/nmWxIncludeOtherWells.cpp +++ b/Src/nmNum/nmSubWxs/nmWxIncludeOtherWells.cpp @@ -95,6 +95,21 @@ const nmFlowGaugeRecord* findFlowRecord( return nullptr; } +nmFlowGaugeRecord* findMutableFlowRecord( + QVector& vecRecords, + const QString& sGaugeCode) +{ + if(sGaugeCode.isEmpty()) { + return nullptr; + } + for(int nIndex = 0; nIndex < vecRecords.size(); ++nIndex) { + if(vecRecords[nIndex].sGaugeCode == sGaugeCode) { + return &vecRecords[nIndex]; + } + } + return nullptr; +} + // 压力曲线至少需要两个点才能用于历史曲线计算。 bool isSelectablePressureRecord(const nmPressureGaugeRecord& oRecord) { @@ -623,6 +638,38 @@ void nmWxIncludeOtherWells::normalizeFlowSelection(WellDataRow& data) const data.m_nFlowSegmentIndex = nSegmentCount; } } + nmFlowGaugeRecord* pMutableRecord = findMutableFlowRecord( + data.m_vecFlowRecords, data.m_sFlowGaugeCode); + if(pMutableRecord != nullptr) { + pMutableRecord->nIndexF = data.m_nFlowSegmentIndex; + } +} + +void nmWxIncludeOtherWells::switchRowFlowGaugeCode( + WellDataRow& data, const QString& sGaugeCode) const +{ + // 行数据是对话框工作副本,切换前先保存当前记录自己的流动段。 + nmFlowGaugeRecord* pOldRecord = findMutableFlowRecord( + data.m_vecFlowRecords, data.m_sFlowGaugeCode); + if(pOldRecord != nullptr) { + pOldRecord->nIndexF = data.m_nFlowSegmentIndex; + } + + data.m_sFlowGaugeCode = sGaugeCode; + nmFlowGaugeRecord* pNewRecord = findMutableFlowRecord( + data.m_vecFlowRecords, data.m_sFlowGaugeCode); + if(pNewRecord == nullptr || + pNewRecord->eStatus != NM_GaugeRecord_Usable) { + data.m_nFlowSegmentIndex = 0; + return; + } + + const int nSegmentCount = flowRecordSegmentCount(*pNewRecord); + data.m_nFlowSegmentIndex = pNewRecord->nIndexF; + if(data.m_nFlowSegmentIndex < 1 || + data.m_nFlowSegmentIndex > nSegmentCount) { + data.m_nFlowSegmentIndex = nSegmentCount; + } } void nmWxIncludeOtherWells::populateRateCombo( @@ -794,6 +841,10 @@ void nmWxIncludeOtherWells::onRateSourceChanged(int nIndex) const QString sGaugeCode = pComboBox->itemData(nIndex).toString(); if(sGaugeCode.isEmpty()) { setRowPhaseUsed(oData, ePhase, false); + if(!oData.m_bUseOilRate && !oData.m_bUseGasRate && + !oData.m_bUseWaterRate) { + switchRowFlowGaugeCode(oData, QString()); + } } else { const nmFlowGaugeRecord* pRecord = findFlowRecord( oData.m_vecFlowRecords, sGaugeCode); @@ -802,8 +853,7 @@ void nmWxIncludeOtherWells::onRateSourceChanged(int nIndex) return; } if(oData.m_sFlowGaugeCode != sGaugeCode) { - oData.m_sFlowGaugeCode = sGaugeCode; - oData.m_nFlowSegmentIndex = pRecord->nIndexF; + switchRowFlowGaugeCode(oData, sGaugeCode); } setRowPhaseUsed(oData, ePhase, true); } @@ -839,8 +889,13 @@ void nmWxIncludeOtherWells::onFlowSegmentChanged(int nIndex) if(nRow < 0 || nRow >= m_vecWellData.size()) { return; } - m_vecWellData[nRow].m_nFlowSegmentIndex = - pComboBox->itemData(nIndex).toInt(); + WellDataRow& oData = m_vecWellData[nRow]; + oData.m_nFlowSegmentIndex = pComboBox->itemData(nIndex).toInt(); + nmFlowGaugeRecord* pRecord = findMutableFlowRecord( + oData.m_vecFlowRecords, oData.m_sFlowGaugeCode); + if(pRecord != nullptr) { + pRecord->nIndexF = oData.m_nFlowSegmentIndex; + } pComboBox->setToolTip(pComboBox->currentText()); } diff --git a/Src/nmNum/nmSubWxs/nmWxNumericalDesign.cpp b/Src/nmNum/nmSubWxs/nmWxNumericalDesign.cpp index 6f9f356..ff8bb5c 100644 --- a/Src/nmNum/nmSubWxs/nmWxNumericalDesign.cpp +++ b/Src/nmNum/nmSubWxs/nmWxNumericalDesign.cpp @@ -1147,8 +1147,7 @@ void nmWxNumericalDesign::onOptionsIconClicked() pWellData->getUseWaterRate() != oWellRow.m_bUseWaterRate || pWellData->getIndexF() != oWellRow.m_nFlowSegmentIndex; - // 先切换公共流量记录,再写入分相开关和该记录的一基流动段索引。 - // 这样 switchSelectedFlowGaugeCode() 可以先保存旧记录自己的段索引。 + // 先让真实井保存原当前记录,再用对话框工作副本覆盖完整记录级索引。 pWellData->selectPressureGaugeCode( oWellRow.m_sPressureGaugeCode); if(pWellData->getSelectedFlowGaugeCode() != @@ -1156,6 +1155,7 @@ void nmWxNumericalDesign::onOptionsIconClicked() pWellData->switchSelectedFlowGaugeCode( oWellRow.m_sFlowGaugeCode); } + pWellData->setFlowRecords(oWellRow.m_vecFlowRecords); pWellData->setUseOilRate(oWellRow.m_bUseOilRate); pWellData->setUseGasRate(oWellRow.m_bUseGasRate); pWellData->setUseWaterRate(oWellRow.m_bUseWaterRate);