362 lines
12 KiB
C++
362 lines
12 KiB
C++
#pragma warning(push,0)
|
||
// #include "Family.h"
|
||
#include <QMessageBox>
|
||
#include <QHeaderView>
|
||
#include "CurveComputerDlg.h"
|
||
#include "ui_CurveComputer.h"
|
||
#include "CStringType.h"
|
||
#include "DataHelper.h"
|
||
#include "MemRdWt.h"
|
||
// #include "ObjProject.h"
|
||
#include "Well.h"
|
||
#pragma warning(pop)
|
||
using namespace pai::ios::welllog;
|
||
BEGIN_OSGGRAPHICS_NAMESPACE
|
||
CCurveComputerDlg::CCurveComputerDlg(QWidget * parent, Qt::WindowFlags flags)
|
||
: QDialog(parent,flags)
|
||
{
|
||
m_pUI = new Ui_CurveComputer();
|
||
m_pUI->setupUi(this);
|
||
|
||
QObject::connect(m_pUI->pushButton_SetDepth, SIGNAL(clicked()), this, SLOT(slotSetDepth()));
|
||
QObject::connect(m_pUI->pushButton_SetFun, SIGNAL(clicked()), this, SLOT(slotSetFun()));
|
||
QObject::connect(m_pUI->okbtn, SIGNAL(clicked()), this, SLOT(slotSave()));
|
||
QObject::connect(m_pUI->cancelbtn, SIGNAL(clicked()), this, SLOT(slotCancel()));
|
||
}
|
||
|
||
void CCurveComputerDlg::slotSave()
|
||
{
|
||
//检查公式合理性
|
||
for(int i=0;i<m_pUI->tableWidget->rowCount();i++)
|
||
{
|
||
if(Qt::Checked!=m_pUI->tableWidget->item(i,0)->checkState())continue;
|
||
QString m_Function=m_pUI->tableWidget->item(i,0)->text();
|
||
m_Function=m_Function.toUpper();
|
||
Function fun;
|
||
int noi=fun.GetExpress(m_Function);//检查输入公式中是否存在:没有“=”号,或含有不能处理的字符
|
||
if(noi<0)return;
|
||
for(int j=0;j<noi;j++)
|
||
{
|
||
fun.val[j]=j+1;
|
||
}
|
||
fun.prog=fun.TempProg;
|
||
float CurveValue;
|
||
int re=fun.get_exp(&CurveValue);
|
||
if(re>0)
|
||
{
|
||
const static char *e[]={
|
||
"语法错误",//"syntax error.",
|
||
"不对称的括号",//"unbalanced parentheses",
|
||
"非法运算符"//"no expression present"
|
||
};
|
||
QMessageBox::warning(NULL,"提示",QString(QLatin1String(e[re-1]))+m_Function);
|
||
return;
|
||
}
|
||
}
|
||
//检查输入、输出曲线
|
||
CMemRdWt *mrw=new CMemRdWt();
|
||
char name[64];
|
||
if(!mrw->Open(FileName.toStdString().c_str(),CSlfIO::modeReadWrite))
|
||
{
|
||
delete mrw;
|
||
return;
|
||
}
|
||
Slf_FILE_MESSAGE msag;
|
||
mrw->GetFileMessage(msag);
|
||
for(int m=0;m<m_pUI->tableWidget->rowCount();m++)
|
||
{
|
||
if(Qt::Checked!=m_pUI->tableWidget->item(m,0)->checkState())continue;
|
||
QString m_Function=m_pUI->tableWidget->item(m,0)->text();
|
||
m_Function=m_Function.toUpper();
|
||
Function fun;
|
||
int noi=fun.GetExpress(m_Function);
|
||
strcpy(name,fun.csOutName.toStdString().c_str());
|
||
int in=mrw->FindObjectIndex(name);
|
||
if(in>=0)//检查输出曲线
|
||
{
|
||
short Attribute,SubAttribute;
|
||
mrw->GetObjectAttribute(in,&Attribute,&SubAttribute);
|
||
if(mrw->GetObjectStatus(in)!=0)//删除状态
|
||
{
|
||
if(Attribute==CHANNEL_OBJECT&&SubAttribute==CURVE_OBJECT)
|
||
{
|
||
QMessageBox::warning(NULL,"提示",fun.csOutName+"曲线已存在,但该曲线处于删除状态,无法进行计算 !!!");
|
||
delete mrw;
|
||
return ;
|
||
}
|
||
else
|
||
{
|
||
QMessageBox::warning(NULL,"提示","有一个非曲线对象"+fun.csOutName+"已存在,且该对象处于删除状态,无法进行计算 !!!");
|
||
delete mrw;
|
||
return ;
|
||
}
|
||
}
|
||
if (Attribute!=CHANNEL_OBJECT||SubAttribute!=CURVE_OBJECT)
|
||
{
|
||
QMessageBox::warning(NULL,"提示","输出曲线名称"+fun.csOutName+"已存在,但其属性不是曲线 !!!");
|
||
delete mrw;
|
||
return ;
|
||
}
|
||
}
|
||
//检查输入曲线
|
||
int index[20],indexout;
|
||
for(int i=0;i<noi;i++)
|
||
{
|
||
if(fun.csName[i]=="CURRENT_HD.DEP")continue;
|
||
if(mrw->FindObjectIndex(fun.csName[i].toStdString().c_str())<0)
|
||
{
|
||
QMessageBox::warning(NULL,"提示","输入曲线"+fun.csName[i]+"不存在,无法进行计算!!!");
|
||
delete mrw;
|
||
return ;
|
||
}
|
||
if(mrw->GetObjectType(fun.csName[i].toStdString().c_str())!=CURVE_OBJECT)
|
||
{
|
||
QMessageBox::warning(NULL,"提示","输入曲线"+fun.csName[i]+"不是曲线类型,不能进行计算!!!\r\n请参考常规曲线计算规则,输入正确的计算公式");
|
||
delete mrw;
|
||
return ;
|
||
}
|
||
}
|
||
}
|
||
QStringList CurveNames;
|
||
CurveNames.push_back(msag.WellName);
|
||
CurveNames.push_back(FileName);
|
||
//开始计算
|
||
for(int m=0;m<m_pUI->tableWidget->rowCount();m++)
|
||
{
|
||
if(Qt::Checked!=m_pUI->tableWidget->item(m,0)->checkState())continue;
|
||
QString m_Function=m_pUI->tableWidget->item(m,0)->text();
|
||
m_Function=m_Function.toUpper();
|
||
Function fun;
|
||
int noi=fun.GetExpress(m_Function);
|
||
strcpy(name,fun.csOutName.toStdString().c_str());
|
||
CurveNames.push_back(name);
|
||
for(int j=0;j<noi;j++)
|
||
{
|
||
fun.val[j]=j+1;
|
||
}
|
||
fun.prog=fun.TempProg;
|
||
float CurveValue;
|
||
//int re=fun.get_exp(&CurveValue);
|
||
int in=mrw->FindObjectIndex(name);
|
||
int index[20],indexout=-1;
|
||
float MinRlev=9999;
|
||
DWORD CurveSample[20];
|
||
float CurveRlev[20];
|
||
Slf_CURVE info;
|
||
for(int i=0;i<noi;i++)
|
||
{
|
||
if(fun.csName[i]=="CURRENT_HD.DEP")continue;
|
||
index[i]=mrw->OpenCurve(fun.csName[i].toStdString().c_str());
|
||
if(index[i]>-1)mrw->GetCurveInfo(index[i],&info);
|
||
if(MinRlev>info.DepLevel)MinRlev=info.DepLevel;
|
||
CurveRlev[i]=info.DepLevel;
|
||
}
|
||
if(MinRlev==9999)MinRlev=0.125;//表达式中没有实际曲线,只有CURRENT_HD.DEP“深度”标识
|
||
//生成输出曲线
|
||
indexout=mrw->OpenCurve(fun.csOutName.toStdString().c_str());
|
||
if(indexout>=0)mrw->GetCurveInfo(indexout,&info);
|
||
else
|
||
{//输出曲线不存在
|
||
indexout=-1;
|
||
for(int i=0;i<noi;i++)
|
||
{
|
||
if(fun.csName[i]=="CURRENT_HD.DEP")continue;
|
||
mrw->GetCurveInfo(index[i],&info);//根据第一条输入曲线的属性产生输出曲线
|
||
indexout=i;
|
||
break;
|
||
}
|
||
if(indexout==-1)//表达式中没有实际曲线
|
||
{
|
||
info.DepLevel=0.125;
|
||
info.CodeLen=4;
|
||
info.RepCode=4;
|
||
info.DefVal=-999.25;
|
||
info.MaxValue=100;
|
||
info.MinValue=0;
|
||
strcpy(info.DepthHZUnit,"米");
|
||
strcpy(info.DepthUnit,"m");
|
||
strcpy(info.Unit,"");
|
||
strcpy(info.AliasUnit,"");
|
||
}
|
||
sprintf(info.AliasName,"%s",fun.csOutName.toStdString().c_str());
|
||
sprintf(info.Name,"%s",fun.csOutName.toStdString().c_str());
|
||
info.StartDepth=m_pUI->tableWidget->item(m,1)->text().toFloat();
|
||
info.EndDepth=m_pUI->tableWidget->item(m,2)->text().toFloat();
|
||
indexout=mrw->OpenCurve(&info);
|
||
}
|
||
float rlev = info.DepLevel;
|
||
float sdep = m_pUI->tableWidget->item(m,1)->text().toFloat();
|
||
float edep = m_pUI->tableWidget->item(m,2)->text().toFloat();
|
||
if(MinRlev>rlev)MinRlev=rlev;
|
||
int sample=(int)((edep-sdep)/rlev+1.5);//0.5);
|
||
int sampleIn=(int)((edep-sdep)/MinRlev+1.5);//0.5);
|
||
float **indata,*outdata;
|
||
indata=new float*[noi];
|
||
outdata=new float[sample+10];
|
||
float *tDep,*aDep;
|
||
tDep=new float[sample];
|
||
for(int k=0; k<sample; k++) tDep[k]=sdep+k*rlev;
|
||
for(int j=0;j<noi;j++)
|
||
{
|
||
if(fun.csName[j]=="CURRENT_HD.DEP")continue;
|
||
indata[j]=new float[sampleIn];
|
||
//whp change 2018.10.15 保证读写一致
|
||
CurveSample[j]=(edep-sdep)/CurveRlev[j]+1.5;//0.5;
|
||
mrw->ReadCurve(index[j],sdep,CurveSample[j],&indata[j][0]);
|
||
if(fabs(CurveRlev[j]-rlev)/rlev>0.1)
|
||
{
|
||
aDep=new float[CurveSample[j]];
|
||
for(int k=0; k<CurveSample[j]; k++) aDep[k]=sdep+k*CurveRlev[j];
|
||
Resample::ReSampling(&indata[j][0],CurveSample[j],1,aDep,tDep,sample);
|
||
delete []aDep;
|
||
}
|
||
}
|
||
for (int i=0; i<sample; i++)
|
||
{
|
||
//sdep = sdeps + rlev * i;
|
||
for(int j=0;j<noi;j++)
|
||
{
|
||
if(fun.csName[j]=="CURRENT_HD.DEP")fun.val[j]=sdep+i*rlev;
|
||
else fun.val[j]=indata[j][i];
|
||
}
|
||
fun.prog=fun.TempProg;
|
||
fun.get_exp(&CurveValue);
|
||
outdata[i]=CurveValue;
|
||
//2013.11.20 whp add for 为曲线计算添加数值类型选项:常规,不控制数值大小;方位:控制到0-360
|
||
|
||
}
|
||
mrw->WriteCurve(indexout,sdep,sample,&outdata[0]);
|
||
delete []tDep;
|
||
|
||
for (int i=0; i<noi;i++)
|
||
{
|
||
if(fun.csName[i]=="CURRENT_HD.DEP")continue;
|
||
mrw->CloseCurve(index[i]);
|
||
}
|
||
mrw->CloseCurve(indexout);
|
||
|
||
for(int j=0;j<noi;j++)
|
||
{
|
||
if(fun.csName[j]=="CURRENT_HD.DEP")continue;
|
||
delete indata[j];
|
||
}
|
||
delete []indata;
|
||
delete []outdata;
|
||
}
|
||
delete mrw;
|
||
// PaiObject::m_EventAgent.ObjectPropertyChanged(GetProject(),"Compute",CurveNames);
|
||
QMessageBox::warning(NULL,"提示","完成曲线计算");
|
||
//accept();
|
||
}
|
||
/**
|
||
*@brief 取消槽函数
|
||
*/
|
||
void CCurveComputerDlg::slotCancel()
|
||
{
|
||
// reject ();
|
||
}
|
||
void CCurveComputerDlg::slotSetDepth()//用当前编辑的曲线深度为所有计算曲线设置深度
|
||
{
|
||
QString sdep=m_pUI->lineEdit_Sdep->text();
|
||
QString edep=m_pUI->lineEdit_Edep->text();
|
||
if(sdep>edep) sdep=edep;
|
||
for(int i=0;i<m_pUI->tableWidget->rowCount();i++)
|
||
{
|
||
m_pUI->tableWidget->setItem(i,1,new QTableWidgetItem(sdep));
|
||
m_pUI->tableWidget->setItem(i,2,new QTableWidgetItem(edep));
|
||
}
|
||
}
|
||
void CCurveComputerDlg::slotSetFun()
|
||
{
|
||
QString m_Function="X="+m_pUI->lineEdit_Fun->text();
|
||
m_Function=m_Function.toUpper();
|
||
m_Function.replace("\"DEPTH\"","CURRENT_HD.DEP");
|
||
Function fun;
|
||
vector <int>NameType;//输入曲线名类型
|
||
int noi=fun.GetExpress(m_Function);
|
||
QString m_FunctionR=m_Function.right(m_Function.length()-m_Function.indexOf('=')-1);
|
||
for (int i=0; i<noi; i++)
|
||
{
|
||
if(fun.csName[i]=="X")NameType.push_back(1);//和输出曲线同名
|
||
else if(fun.csName[i]=="CURRENT_HD.DEP")NameType.push_back(2);//深度变量
|
||
else NameType.push_back(0);//曲线名
|
||
}
|
||
|
||
for(int i=0;i<m_pUI->tableWidget->rowCount();i++)
|
||
{
|
||
QString m_Function0=m_pUI->tableWidget->item(i,0)->text();
|
||
m_Function0=m_Function0.toUpper();
|
||
QString outname=m_Function0.left(m_Function0.indexOf('='));
|
||
QString newfun=QString(QLatin1String(fun.TempProg));
|
||
newfun=newfun.simplified();
|
||
char name[2];
|
||
name[0]='A'+ i;
|
||
name[1]=0;
|
||
for (int j=0; j<noi; j++)
|
||
{
|
||
name[0]='A'+ j;
|
||
QString qname=QString(QLatin1String(name));
|
||
//if(NameType[j])
|
||
{
|
||
|
||
QString left=newfun.left(newfun.lastIndexOf(qname));
|
||
QString right=newfun.right(newfun.length()-newfun.lastIndexOf(qname)-1);
|
||
//right.replace(qname,outname);
|
||
QString ms=fun.csName[j];//曲线名
|
||
if(NameType[j]==1)ms=outname;//和输出曲线同名
|
||
else if(NameType[j]==2)ms="\"DEPTH\"";//深度变量
|
||
newfun=left+ms+right;
|
||
}
|
||
}
|
||
QString ss=outname+"="+newfun;
|
||
m_pUI->tableWidget->setItem(i,0,new QTableWidgetItem(ss));//QString(QLatin1String(fun.TempProg))));
|
||
m_pUI->tableWidget->item(i,0)->setCheckState(Qt::Checked);
|
||
}
|
||
}
|
||
void CCurveComputerDlg::init()//const QString& FileName,const QStringList& CurveNameList)//int row,int col,QStringList header)
|
||
{
|
||
m_pUI->tableWidget->setColumnCount(3);
|
||
QStringList header;
|
||
header<<"计算公式"<<"起始深度"<<"终止深度";//header<<"曲线名"<<"计算公式"<<"起始深度"<<"终止深度";
|
||
m_pUI->tableWidget->setHorizontalHeaderLabels(header);
|
||
m_pUI->tableWidget->setColumnWidth(1,200);
|
||
m_pUI->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
||
|
||
m_pUI->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||
m_pUI->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||
// m_pUI->tableWidget->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
|
||
m_pUI->tableWidget->setRowCount(CurveNameList.count());
|
||
float Mindep=99999,Maxdep=-99999;
|
||
for(int i=0;i<CurveNameList.count();i++)
|
||
{
|
||
QString CurveName=CurveNameList[i];
|
||
//m_pUI->tableWidget->setItem(i,0,new QTableWidgetItem(CurveName));
|
||
QString ss=CurveName+"=1.0*"+CurveName+"+0.0";
|
||
m_pUI->tableWidget->setItem(i,1-1,new QTableWidgetItem(ss));
|
||
CMemRdWt *logio=new CMemRdWt();
|
||
logio->Open(FileName.toStdString().c_str(),CSlfIO::modeReadWrite);
|
||
int index=logio->OpenCurve(CurveName.toStdString().c_str());
|
||
if(index<0) {
|
||
delete logio;
|
||
continue;
|
||
}
|
||
Slf_CURVE pInfo;
|
||
logio->GetCurveInfo(index,&pInfo);
|
||
m_pUI->tableWidget->setItem(i,2-1,new QTableWidgetItem(QString::number(pInfo.StartDepth)));
|
||
m_pUI->tableWidget->setItem(i,3-1,new QTableWidgetItem(QString::number(pInfo.EndDepth)));
|
||
if(Mindep>pInfo.StartDepth)Mindep=pInfo.StartDepth;
|
||
if(Mindep>pInfo.EndDepth)Mindep=pInfo.EndDepth;
|
||
if(Maxdep<pInfo.StartDepth)Maxdep=pInfo.StartDepth;
|
||
if(Maxdep<pInfo.EndDepth)Maxdep=pInfo.EndDepth;
|
||
logio->CloseCurve(index);
|
||
delete logio;
|
||
m_pUI->tableWidget->item(i,0)->setCheckState(Qt::Checked);
|
||
}
|
||
m_pUI->lineEdit_Sdep->setText(QString::number(Mindep));
|
||
m_pUI->lineEdit_Edep->setText(QString::number(Maxdep));
|
||
QString ss="1.0*x+0.0";
|
||
m_pUI->lineEdit_OutCurve->setText("x");
|
||
m_pUI->lineEdit_Fun->setText(ss);
|
||
}
|
||
END_OSGGRAPHICS_NAMESPACE
|