logplus/DataOutput/src/TrainGenModuleDlg.cpp
2025-10-29 17:23:30 +08:00

361 lines
12 KiB
C++

#pragma warning(push,0)
// #include "Family.h"
#include <QMessageBox>
#include "TrainGenModuleDlg.h"
#include "ui_TrainGenModule.h"
#include "CStringType.h"
#include "LogIO.h"
#include "qfileinfo.h"
#include "qfileDialog.h"
#include <QTextStream>
#include "GeometryUtils.h"
#include "SetOutDepParDlg.h"
#include <QApplication>
#include "CheckHeadView.h"
#pragma warning(pop)
#define RESULTSTART_NUM 1
// using namespace pai::ios::welllog;
BEGIN_OSGGRAPHICS_NAMESPACE
CTrainGenModuleDlg::CTrainGenModuleDlg(QWidget * parent, Qt::WindowFlags flags) : QDialog(parent,flags)
,m_bFirstShowWellname(true)
,moduleNum(0)
,initDoubleSpinBox(true)
,outRlev(0)
,tgm_pUI(new Ui::TrainGenModule)
{
QString Ext[10]={"TXT","TXT","LAS","XLS","Wis","XTF","LIS","WLD","dat","dlis"};
for(int i=0;i<9;i++)ExtName[i]=Ext[i];
//tgm_pUI = new Ui_TrainGenModule();
tgm_pUI->setupUi(this);
tgm_pUI->well_tableWidget->setMouseTracking(true);
tgm_pUI->well_tableWidget->setColumnCount(3);
//tgm_pUI->well_tableWidget->setWindowTitle("Well Information");
//tgm_pUI->well_tableWidget->setColumnWidth(0, 200);
//for(int i = 1; i < 3; i++) tgm_pUI->well_tableWidget->setColumnWidth(i,72);
QStringList header;
header<<"Slf\n文件名"<<"适用\n起始深度"<<"适用\n结束深度";
tgm_pUI->well_tableWidget->setHorizontalHeaderLabels(header);
tgm_pUI->well_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
tgm_pUI->well_tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
tgm_pUI->well_tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
//tgm_pUI->well_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
initRESULTList();
initMLList();
connect(tgm_pUI->module_comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(mlChanged_SLOT(QString)));
//connect(tgm_pUI->sdep_doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(sdep_doubleSpinBox_SLOT(float)));
//connect(tgm_pUI->edep_doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(edep_doubleSpinBox_SLOT(float)));
//tgm_pUI->lineEdit->setText("待预测曲线名称");
tgm_pUI->moduleName_lineEdit->setText("Module");
connect(tgm_pUI->gen_pushButton, SIGNAL(clicked()), this, SLOT(genModule_SLOT()));
connect(tgm_pUI->canel_pushButton, SIGNAL(clicked()), this, SLOT(cancel_SLOT()));
}
void CTrainGenModuleDlg::initMLList()
{
QString ConfigName = ::GetConfPath()+"MLTable.ini";
QFile InFile(ConfigName);
if( !InFile.open(QIODevice::ReadOnly ) )
{
QMessageBox::warning(NULL,"提示","打开配置文件"+ConfigName+"错误");
return ;
}
QTextStream textstream( &InFile );
QString line;
int DefTabNum=0;
while(!textstream.atEnd())
{
line=textstream.readLine();
if(line.indexOf("//")>=0)continue;
if(line.indexOf("#")>=0)DefTabNum++;
}
if(!DefTabNum)
{
QMessageBox::warning(NULL,"提示","配置文件"+ConfigName+"中定义模型数为0");
return ;
}
moduleNum = DefTabNum;
mlTableList = new MLTABLE[DefTabNum+1];
InFile.seek(0);
line = textstream.readLine();
//line = line.toUpper();
QStringList DataList;
int curML = 0;
while(!textstream.atEnd())
{
while(line.indexOf("#")>=0)
{
line=line.replace("#","");
DataList = line.split(" ");
if(DataList.count() < 3)continue;
mlTableList[curML].Name = DataList.at(0);
mlTableList[curML].attrNum = DataList.at(1).toInt();
mlTableList[curML].outputNum = DataList.at(2).toInt();
int curN = 3;
for(int i = 0; i < mlTableList[curML].attrNum; i++)
mlTableList[curML].attrList.append(DataList.at(curN++));
for(int i = 0; i < mlTableList[curML].outputNum; i++)
mlTableList[curML].outputList.append(DataList.at(curN++));
mlTableList[curML].mlfilePath = DataList.at(curN++);
mlTableList[curML].mlfileName = DataList.at(curN++);
mlTableList[curML].mlModulePath = DataList.at(curN++);
mlTableList[curML].classNum = DataList.at(curN++).toInt();
for(int i = 0; i < mlTableList[curML].classNum; i++)
mlTableList[curML].classNames.append(DataList.at(curN++));
tgm_pUI->module_comboBox->addItem(mlTableList[curML].Name);
if(curML == 0)
reAttrTableWidget(0);
curML++;
line=textstream.readLine();
}
}
InFile.close();
}
void CTrainGenModuleDlg::initRESULTList()
{
QString ConfigName = ::GetConfPath()+"RESULT.ini";
QFile InFile(ConfigName);
if( !InFile.open(QIODevice::ReadOnly ) )
{
QMessageBox::warning(NULL,"提示","打开配置文件"+ConfigName+"错误");
return ;
}
QTextStream textstream( &InFile );
QString line;
InFile.seek(0);
line = textstream.readLine();
QStringList DataList;
int curML = 0;
while(!textstream.atEnd())
{
ResultList<<line;
line=textstream.readLine();
}ResultList<<line;
InFile.close();
}
void CTrainGenModuleDlg::SetDepInfo(QString wellname,int Row)
{
outsdep=99999,outedep=-99999,outrlev=0;
CLogIO mrw;
int op=mrw.Open(wellname.toStdString().c_str(),CSlfIO::modeRead);
if (!op)return;
int ObjectCount = mrw.GetObjectCount();
if (ObjectCount == 0)
{
mrw.Close();
return;
}
float minsdep = minedep = minrlev = 99999, maxsdep = maxedep = maxrlev = -99999;
for(int i = 0; i < ObjectCount; i++)
{
if(mrw.GetObjectStatus(i)==OBJECT_DISCARD||mrw.GetObjectStatus(i)==OBJECT_DELETE)continue;
char Name[200];
mrw.GetObjectName(i,Name);
if(strstr(Name,"%")==NULL)
{
if(mrw.GetObjectType(i)==CURVE_OBJECT)
{
int index=mrw.OpenCurve(Name);
Slf_CURVE pInfo;
mrw.GetCurveInfo(index,&pInfo);
if(minsdep > pInfo.StartDepth)minsdep = pInfo.StartDepth;
if(maxsdep < pInfo.StartDepth)maxsdep = pInfo.StartDepth;
if(minedep > pInfo.EndDepth)minedep = pInfo.EndDepth;
if(maxedep < pInfo.EndDepth)maxedep = pInfo.EndDepth;
if(minrlev > pInfo.DepLevel)minrlev = pInfo.DepLevel;
if(maxrlev < pInfo.DepLevel)maxrlev = pInfo.DepLevel;
}
else if(mrw.GetObjectType(i) == WAVE_OBJECT)
{
// int index=mrw.OpenCurve(Name);
int index=mrw.OpenWave(Name);
Slf_WAVE pInfo;
mrw.GetWaveInfo(index,&pInfo);
if(minsdep>pInfo.StartDepth)minsdep=pInfo.StartDepth;
if(maxsdep<pInfo.StartDepth)maxsdep=pInfo.StartDepth;
if(minedep>pInfo.EndDepth)minedep=pInfo.EndDepth;
if(maxedep<pInfo.EndDepth)maxedep=pInfo.EndDepth;
if(minrlev>pInfo.DepLevel)minrlev=pInfo.DepLevel;
if(maxrlev<pInfo.DepLevel)maxrlev=pInfo.DepLevel;
}
}
//pObjectEntry++;
}
//delete []pObjectEntry;
outsdep = minsdep; outedep = maxedep, outrlev = maxrlev;
mrw.Close();
//"Slf\n文件名"<<"最小\n起始深度"<<"最大\n起始深度"<<"最小\n结束深度"<<"最大\n结束深度"<<"最小\n采样间隔"<<"最大\n采样间隔"
tgm_pUI->well_tableWidget->setItem(Row,1,new QTableWidgetItem(QString("%1").arg(maxsdep)));
tgm_pUI->well_tableWidget->setItem(Row,2,new QTableWidgetItem(QString("%1").arg(minedep)));
//tgm_pUI->well_tableWidget->item(Row,1)->setTextColor(QColor(100,100,100));
//tgm_pUI->well_tableWidget->item(Row,2)->setTextColor(QColor(100,100,100));
setOutRlev(maxrlev);
setDepRange(maxsdep, minedep);
}
void CTrainGenModuleDlg::setDepRange(float s, float e)
{
/*
if(initDoubleSpinBox || s > tgm_pUI->edep_doubleSpinBox->minimum()){
//tgm_pUI->edep_doubleSpinBox->setMinimum(s);
//tgm_pUI->sdep_doubleSpinBox->setMinimum(s);
tgm_pUI->sdep_doubleSpinBox->setValue(s);
}
if(initDoubleSpinBox || e < tgm_pUI->edep_doubleSpinBox->maximum()){
//tgm_pUI->edep_doubleSpinBox->setMaximum(e);
//tgm_pUI->sdep_doubleSpinBox->setMaximum(e);
tgm_pUI->edep_doubleSpinBox->setValue(e);
}
*/
if(initDoubleSpinBox)
initDoubleSpinBox = false;
}
void CTrainGenModuleDlg::setOutRlev(float maxrlev)
{
outRlev = (outRlev < maxrlev) ? maxrlev : outRlev;
}
bool CTrainGenModuleDlg::set_slfNameList(const QStringList& nameList)
{
slfNameList = nameList;
return true;
}
int CTrainGenModuleDlg::getModuleNum()
{
return moduleNum;
}
int CTrainGenModuleDlg::getAttrNum(){
return tgm_pUI->attr_tableWidget->rowCount();
}
bool CTrainGenModuleDlg::reAttrTableWidget(int index)
{
tgm_pUI->attr_tableWidget->clear();
tgm_pUI->attr_tableWidget->setRowCount(mlTableList[index].attrNum);
tgm_pUI->attr_tableWidget->setColumnCount(2);
QStringList header;
header<<"所需\n特征"<<"对应\n曲线";
tgm_pUI->attr_tableWidget->setHorizontalHeaderLabels(header);
tgm_pUI->attr_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
tgm_pUI->attr_tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
tgm_pUI->attr_tableWidget_2->clear();
tgm_pUI->attr_tableWidget_2->setRowCount(mlTableList[index].outputNum);
tgm_pUI->attr_tableWidget_2->setColumnCount(3);
QStringList header2;
header2<<"所需\nLabel"<<"对应\n曲线"<<"分类\n数目";
tgm_pUI->attr_tableWidget_2->setHorizontalHeaderLabels(header2);
tgm_pUI->attr_tableWidget_2->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
tgm_pUI->attr_tableWidget_2->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
tgm_pUI->attr_tableWidget_2->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
tgm_pUI->class_tableWidget->clear();
tgm_pUI->class_tableWidget->setRowCount(mlTableList[index].classNum);
tgm_pUI->class_tableWidget->setColumnCount(2);
QStringList header3;
header3<<"所需\n类别名称"<<"对应\n类别数值";
tgm_pUI->class_tableWidget->setHorizontalHeaderLabels(header3);
tgm_pUI->class_tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
tgm_pUI->class_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
tgm_pUI->class_tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
for(int i = 0; i < mlTableList[index].attrNum; i++){
tgm_pUI->attr_tableWidget->setItem(i, 1, new QTableWidgetItem(mlTableList[index].attrList.at(i)));
QTableWidgetItem *item = new QTableWidgetItem(mlTableList[index].attrList.at(i));
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
tgm_pUI->attr_tableWidget->setItem(i, 0, item);
}
for(int i = 0; i < mlTableList[index].outputNum; i++){
tgm_pUI->attr_tableWidget_2->setItem(i, 1, new QTableWidgetItem(mlTableList[index].outputList.at(i)));
QTableWidgetItem *item = new QTableWidgetItem(mlTableList[index].outputList.at(i));
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
tgm_pUI->attr_tableWidget_2->setItem(i, 0, item);
QTableWidgetItem *class_item = new QTableWidgetItem(QString::number(mlTableList[index].classNum));
class_item->setFlags(class_item->flags() & (~Qt::ItemIsEditable));
tgm_pUI->attr_tableWidget_2->setItem(i, 2, class_item);
}
for(int i = 0; i < mlTableList[index].classNum; i++){
QTableWidgetItem *item = new QTableWidgetItem(mlTableList[index].classNames.at(i));
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
tgm_pUI->class_tableWidget->setItem(i, 0, item);
int resultIndex = ResultList.indexOf(mlTableList[index].classNames.at(i));
tgm_pUI->class_tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(resultIndex + RESULTSTART_NUM)));
}
return true;
}
void CTrainGenModuleDlg::mlChanged_SLOT(QString v)
{
int usingModuleIndex = tgm_pUI->module_comboBox->currentIndex();
if(usingModuleIndex >= moduleNum) return;
reAttrTableWidget(usingModuleIndex);
}
void CTrainGenModuleDlg::sdep_doubleSpinBox_SLOT(float v)
{
/*
float temp = tgm_pUI->edep_doubleSpinBox->value();
if(v > temp)
tgm_pUI->sdep_doubleSpinBox->setValue(temp);
*/
}
void CTrainGenModuleDlg::edep_doubleSpinBox_SLOT(float v)
{
/*
float temp = tgm_pUI->sdep_doubleSpinBox->value();
if(v < temp)
tgm_pUI->sdep_doubleSpinBox->setValue(temp);
*/
}
void CTrainGenModuleDlg::genModule_SLOT()
{
accept();
}
void CTrainGenModuleDlg::cancel_SLOT()
{
reject();
}
void CTrainGenModuleDlg::set_well_tableWidget_RowCount(const int colV)
{
tgm_pUI->well_tableWidget->clear();
tgm_pUI->well_tableWidget->setRowCount(colV);
}
END_OSGGRAPHICS_NAMESPACE