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/nmSubWxs/nmWxIncludeOtherWells.cpp

357 lines
11 KiB
C++

#include "nmWxIncludeOtherWells.h"
#include "ZxDataWell.h"
#include "ZxDataProject.h"
#include "zxSysUtils.h"
#include "ZxDataGaugeP.h"
#include "ZxDataGaugeF.h"
#include "ZxBaseUtil.h"
#include "nmDataAnalyzeManager.h"
#include <QCheckBox>
#include <QWidget>
#include <QHBoxLayout>
nmWxIncludeOtherWells::nmWxIncludeOtherWells(QWidget* pParent)
: iDlgBase(pParent), m_pTableWidget(nullptr),
m_pOkButton(nullptr), m_pCancelButton(nullptr),
m_pButtonLayout(nullptr), m_pMainLayout(nullptr)
{
this->initUI();
}
nmWxIncludeOtherWells::~nmWxIncludeOtherWells()
{
// Qt的对象父子关系会自动处理内存释放
}
void nmWxIncludeOtherWells::initUI()
{
this->setupTable();
this->setupButtons();
this->setupLayouts();
this->setupConnections();
this->setWindowTitle(tr("Include Other Wells"));
this->resize(772, 339);
}
void nmWxIncludeOtherWells::setupTable()
{
m_pTableWidget = new QTableWidget(this);
ZxDataObjectList wellList;
if(zxCurProject != nullptr) {
wellList = zxCurProject->getChildren(iDataModelType::sTypeWell);
}
// 设置行列数
m_pTableWidget->setColumnCount(6);
m_pTableWidget->setRowCount(wellList.size());
m_pTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
m_pTableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
m_pTableWidget->setStyleSheet(
"QTableWidget::item:focus {"
" background: transparent;"
" color: black;"
"}"
);
// 设置水平表头(列标题)
QStringList headers;
headers << tr("Name") << tr("Included") << tr("Oil production")
<< tr("Gas production") << tr("Water production") << tr("Pressure");
m_pTableWidget->setHorizontalHeaderLabels(headers);
// 确保水平表头可见
m_pTableWidget->horizontalHeader()->setVisible(true);
// 设置垂直表头(行标题)属性
m_pTableWidget->verticalHeader()->setVisible(true); // 保持垂直表头可见(用于行选择视觉反馈)
m_pTableWidget->verticalHeader()->setMinimumWidth(16); // 最小宽度
// 隐藏垂直表头的数字(设置为空文本)
QStringList emptyRowHeaders;
for(int i = 0; i < m_pTableWidget->rowCount(); ++i) {
emptyRowHeaders << "";
}
m_pTableWidget->setVerticalHeaderLabels(emptyRowHeaders);
// 加载数据
QString currentWell;
nmDataWellBase* pCurrentWell = nmDataAnalyzeManager::getCurrentInstance()->getCurWellData();
if (pCurrentWell != nullptr)
{
currentWell = pCurrentWell->getWellName();
}
int displayRow = 0;
for(int i = 0; i < wellList.size(); i++) {
ZxDataWell* pWellObj = dynamic_cast<ZxDataWell*>(wellList[i]);
if(!pWellObj || pWellObj->getName() == currentWell) {
continue;
}
WellDataRow wellRow;
wellRow.sName = pWellObj->getName();
// 查看数据中心是否已经添加到里面
nmDataWellBase* pWell =nmDataAnalyzeManager::getCurrentInstance()->findWellByName(pWellObj->getName());
if (pWell != nullptr) {
wellRow.bIsIncluded = true;
} else {
wellRow.bIsIncluded = false;
}
// 获取压力数据
ZxDataObjectList gaugePList = pWellObj->getChildren(iDataModelType::sTypeDataGaugeP);
wellRow.sPressure = gaugePList.isEmpty() ? "None" : "History";
// 获取流量数据
ZxDataObjectList gaugeFList = pWellObj->getChildren(iDataModelType::sTypeDataGaugeF);
wellRow.sOilProd = gaugeFList.isEmpty() ? "None" : "Rate";
// 气相和水相暂时设为None
wellRow.sGasProd = "None";
wellRow.sWaterProd = "None";
// 添加到数据列表和表格
m_wellData.append(wellRow);
addWellDataToTable(wellRow, displayRow);
displayRow++;
}
m_pTableWidget->setRowCount(displayRow); // 调整实际显示的行数
m_pTableWidget->horizontalHeader()->setStretchLastSection(true);
m_pTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
}
void nmWxIncludeOtherWells::addWellDataToTable(const WellDataRow& data, int row)
{
// Name列 - 不可编辑
QTableWidgetItem* nameItem = new QTableWidgetItem(data.sName);
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
nameItem->setData(Qt::UserRole, row); // 存储数据索引
m_pTableWidget->setItem(row, 0, nameItem);
// Included列 - 使用自定义复选框组件
QWidget* pWidget = new QWidget();
QCheckBox* pCheckBox = new QCheckBox();
QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
pLayout->addWidget(pCheckBox);
pLayout->setAlignment(Qt::AlignCenter);
pLayout->setContentsMargins(0, 0, 0, 0);
pWidget->setLayout(pLayout);
pCheckBox->setChecked(data.bIsIncluded);
pCheckBox->setEnabled(data.hasValidData());
pCheckBox->setProperty("row", row); // 存储行索引
// 连接复选框信号
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxStateChanged(int)));
// 设置单元格控件
m_pTableWidget->setCellWidget(row, 1, pWidget);
// 其他列 - 不可编辑
QStringList listOtherData;
listOtherData.append(data.sOilProd);
listOtherData.append(data.sGasProd);
listOtherData.append(data.sWaterProd);
listOtherData.append(data.sPressure);
for(int col = 2; col < 6; col++) {
QTableWidgetItem* item = new QTableWidgetItem(listOtherData[col-2]);
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
item->setData(Qt::UserRole, row);
m_pTableWidget->setItem(row, col, item);
}
}
void nmWxIncludeOtherWells::onCheckBoxStateChanged(int state)
{
QCheckBox* pCheckBox = qobject_cast<QCheckBox*>(sender());
if (!pCheckBox) return;
int row = pCheckBox->property("row").toInt();
if (row >= 0 && row < m_wellData.size())
{
m_wellData[row].bIsIncluded = (state == Qt::Checked);
// 选中当前行
m_pTableWidget->selectRow(row);
// 如果选中了井,并且井有有效数据,则进行处理
if (state == Qt::Checked && m_wellData[row].hasValidData())
{
/*
QString wellName = m_wellData[row].sName;
// 1. 获取 ZxDataWell 对象
ZxDataObjectList wellList = zxCurProject->getChildren(iDataModelType::sTypeWell);
ZxDataWell* pZxWell = nullptr;
for(int i = 0; i < wellList.size(); i++)
{
ZxDataWell* pWell = dynamic_cast<ZxDataWell*>(wellList[i]);
if(pWell && pWell->getName() == wellName)
{
pZxWell = pWell;
break;
}
}
if(!pZxWell)
{
return;
}
// 2. 检查数据中心是否已经存在该井
nmDataAnalyzeManager* pManager = nmDataAnalyzeManager::getCurrentInstance();
nmDataWellBase* pExistingWell = pManager->findWellByName(wellName);
if(pExistingWell != nullptr)
{
// 井已存在,无需重复处理
return;
}
// 3. 创建对应的 nmDataWellBase 对象
QString wellClass = pZxWell->getWellClass();
nmDataWellBase* pNewWell = nullptr;
// 根据井类型创建对应的井对象
if(ZxBaseUtil::isSameStr(wellClass, "VerticalWell")) {
pNewWell = pManager->createWell(NM_WELL_MODEL::Vertical_Well);
} else if(ZxBaseUtil::isSameStr(wellClass, "VerticalFracturedWell")) {
pNewWell = pManager->createWell(NM_WELL_MODEL::Vertical_Fractured_Well);
} else if(ZxBaseUtil::isSameStr(wellClass, "HorizontalFracturedWell")) {
pNewWell = pManager->createWell(NM_WELL_MODEL::Horizontal_Fractured_Well);
}
if(!pNewWell) {
return;
}
// 4. 设置井的基本属性
pNewWell->setWellName(pZxWell->getName());
nmDataAttribute tempAttr = pNewWell->getX();
tempAttr.setValue(pZxWell->getLocationX());
pNewWell->setX(tempAttr);
tempAttr = pNewWell->getY();
tempAttr.setValue(pZxWell->getLocationY());
pNewWell->setY(tempAttr);
tempAttr = pNewWell->getRadius();
tempAttr.setValue(pZxWell->getWellRadius());
pNewWell->setRadius(tempAttr);
// 5. 获取并设置压力、流量数据
QVector<QPointF> vecPtsP, vecPtsF;
// 获取压力数据
ZxDataObjectList m_listGaugeP = pZxWell->getChildren(iDataModelType::sTypeDataGaugeP);
if(!m_listGaugeP.isEmpty()) {
ZxDataGaugeP* pGaugeP = dynamic_cast<ZxDataGaugeP*>(m_listGaugeP[0]);
if(pGaugeP) {
VecDouble vecX, vecY;
if(pGaugeP->getDataVecXY(vecX, vecY)) {
for(int i = 0; i < vecX.size() && i < vecY.size(); ++i) {
vecPtsP.append(QPointF(vecX[i], vecY[i]));
}
}
}
}
// 获取流量数据
ZxDataObjectList m_listGaugeF = pZxWell->getChildren(iDataModelType::sTypeDataGaugeF);
if(!m_listGaugeF.isEmpty()) {
ZxDataGaugeF* pGaugeF = dynamic_cast<ZxDataGaugeF*>(m_listGaugeF[0]);
if(pGaugeF) {
VecDouble vecX, vecY;
if(pGaugeF->getDataVecXY(vecX, vecY)) {
for(int i = 0; i < vecX.size() && i < vecY.size(); ++i) {
vecPtsF.append(QPointF(vecX[i], vecY[i]));
}
}
}
}
// 设置压力和流量数据
pNewWell->setPressurePoints(vecPtsP);
pNewWell->setFlowPoints(vecPtsF);
int nIndexF; //当前井的流动段索引
// 更新当前井的流动段的索引,默认为最后一段
nIndexF = vecPtsF.count() - 1;
// 设置流量段索引
pNewWell->setIndexF(nIndexF);
// 6. 如果是裂缝井,设置裂缝信息
if(wellClass.contains("Fractured")) {
nmDataVerticalFracturedWell* pVFWell = dynamic_cast<nmDataVerticalFracturedWell*>(pNewWell);
if(pVFWell) {
pVFWell->setFracs();
}
nmDataHorizontalFracturedWell* pHFWell = dynamic_cast<nmDataHorizontalFracturedWell*>(pNewWell);
if(pHFWell) {
pHFWell->setFracs();
}
}
// 7. 调用 calculationLogData 计算历史数据
QVector<QVector<double>> vvecHistoryPressureData;
QVector<QVector<double>> vvecHistoryLogData;
QVector<QVector<double>> vvecHistorySemiLogData;
pManager->calculationLogData(pNewWell, vvecHistoryPressureData, vvecHistoryLogData, vvecHistorySemiLogData);
// 8. 存储历史数据到井对象
pNewWell->setHistoryPressure(vvecHistoryPressureData);
pNewWell->setHistoryLogLog(vvecHistoryLogData);
pNewWell->setHistorySemiLog(vvecHistorySemiLogData);
*/
}
}
}
void nmWxIncludeOtherWells::onItemClicked(QTableWidgetItem* item)
{
}
QVector<WellDataRow> nmWxIncludeOtherWells::getWellData() const
{
return m_wellData;
}
void nmWxIncludeOtherWells::setupButtons()
{
// 创建确定和取消按钮
m_pOkButton = new QPushButton(tr("OK"), this);
m_pCancelButton = new QPushButton(tr("Cancel"), this);
}
void nmWxIncludeOtherWells::setupLayouts()
{
// 创建按钮布局并添加按钮
m_pButtonLayout = new QHBoxLayout();
m_pButtonLayout->addStretch(); // 添加伸缩项使按钮靠右
m_pButtonLayout->addWidget(m_pOkButton);
m_pButtonLayout->addWidget(m_pCancelButton);
// 创建主布局并添加控件
m_pMainLayout = new QVBoxLayout(this);
m_pMainLayout->addWidget(m_pTableWidget);
m_pMainLayout->addLayout(m_pButtonLayout);
setLayout(m_pMainLayout);
}
void nmWxIncludeOtherWells::setupConnections()
{
connect(m_pOkButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(m_pCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_pTableWidget, SIGNAL(itemClicked(QTableWidgetItem*)),
this, SLOT(onItemClicked(QTableWidgetItem*)));
}