logplus/WellLogModule/src/PELibraryModule.cpp
DESKTOP-450PEFP\mainc 0e4a8b664a 修改窗口布局,处理方法模块显示在窗口右侧,不是对话框弹窗
修改插件模块,双击进入插件后,获取插件里面的QAction控件显示在Plugin ToolBar
2026-03-20 09:35:26 +08:00

2283 lines
67 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "PELibraryModule.h"
#include "MemRdWt.h"
#include "ModuleParameter.h"
// #include "ConsoleOutputWidget.h"
#include <QTextStream>
#include <ObjWelllogINP.h>
#include "DepthProgress.h"
#include <QDir>
#include "GeometryUtils.h"
// #include "LogPlusClient.h"
// #include "ObjectEvent.h"
// #include "ObjProject.h"
#include "ObjWell.h"
#include "ObjWellLogTABLE.h"
#include "ObjWelllogRound.h"
#include "ParameterItem.h"
#include <QTextCodec>
#include <QAction>
// void OSGFRAMEWORK_EXPORT AppendConsole(pai::log::Priority priority,const QString &output);
using namespace pai::module;
PELibraryModule::PELibraryModule(void)
{
DefaultCon=new CON_STRU();
RunCon=new CON_STRU();
LoadedDefaultParams=false;
iscreatemem=0;
m_libraryfilename="";
strDLLFun="";
//m_slfFileName="r:\\xmac.slf";
Inc=NULL;
Outc=NULL;
Inp=NULL;
Outp=NULL;
Conc=NULL;
Con=NULL;
isEditCard=false;
parDialog=NULL;
Hd=NULL;
pLogType=NULL;
errorinf=NULL;
m_pMemRdWt=NULL;
m_pCardpEdit=NULL;
}
PELibraryModule::~PELibraryModule(void)
{
delete RunCon;
RunCon=NULL;
delete DefaultCon;
DefaultCon=NULL;
if(parDialog)
{
parDialog->setParent(NULL);
delete parDialog;
parDialog=NULL;
}
if(iscreatemem&&m_pMemRdWt)
{
delete m_pMemRdWt;
m_pMemRdWt=NULL;
}
Methodlib.unload();
}
bool PELibraryModule::ToUnicode(char* szStr)
{
QString qstr;;
qstr = qstr.fromLocal8Bit(szStr);
std::string stdStr = qstr.toStdString();
strcpy(szStr,stdStr.c_str());
return true;
}
QStringList PELibraryModule::GetNames(std::string names,char split,bool removeblank)
{
QString incname;
incname=incname.fromStdString(names);
QStringList result;
int commaindex=names.find(split);
if(commaindex>=0)
{
result= incname.split(split);
for(int i=0;i<result.size();i++) {
result[i]=result[i].trimmed();
int pos=0,pos1=0;
if((pos=result[i].indexOf("^"))>-1&&(pos1=result[i].indexOf("^",pos+1))>-1) {
QString str=result[i].mid(pos,pos1-pos+1);
QStringList fh=GetSimilarCurves(str);
if(fh.size())result[i].replace(str,fh[0]);
}
pos=0,pos1=0;
if((pos=result[i].indexOf("!"))>-1&&(pos1=result[i].indexOf("!",pos+1))>-1) {
QString str=result[i].mid(pos,pos1-pos+1);
QStringList fh=GetSimilarCurves(str);
if(fh.size())result[i].replace(str,fh[0]);
}
}
}
else
result= incname.split(' ');
if(!removeblank) return result;
for(int i=result.size()-1;i>=0;i--)
{
if(result.at(i)=="") result.removeAt(i);
}
return result;
}
QStringList PELibraryModule::GetParamOPTIONS(int no)
{
QStringList vl1;
if(!Conc) return vl1;
QStringList vl=GetNames(Conc->Options,';',false);
if(vl.size()>no) {
vl1=vl[no].split(",");
for(int i=0;i<vl1.size();i++) {
vl1[i]=vl1[i].trimmed();
}
}
return vl1;
}
QStringList PELibraryModule::GetParamCNNames()
{
if(!Conc) return QStringList();
return GetNames(Conc->Script,';',true);
}
float PELibraryModule::GetFloatParam(CModuleParameter * pModulePara,QString &paramName,QString &str)
{
CParameterItem* item_val=nullptr;//pModulePara->GetParameterItem(paramName.toStdString());
if(item_val)
{
if(item_val->GetInputType()==CHECKBOX) {
QString val=item_val->GetStringValue().c_str();
QString str1=item_val->GetInputMetaData().c_str();
QStringList strlst=str1.split("/");
int no=strlst.indexOf(val);
if(no<0) {
AfxMessageBox("设计错误:选择项"+val+"不存在!");
no=0;
}
str=QString::number(no);
return no;
}
else if(item_val->GetInputType()==COMBOX) {
QString val=item_val->GetStringValue().c_str();
QString str1=item_val->GetInputMetaData().c_str();
QStringList strlst=str1.split("/");
int no=strlst.indexOf(val);
if(no<0) {
str=val;
// AfxMessageBox("设计错误:选择项"+val+"不存在!");
no=0;
}
else str=QString::number(no);
return no;
}
else {
QString cs=item_val->GetStringValue().c_str();
cs=cs.trimmed();
str=cs;
if(cs.isEmpty()) return 0;
if((cs.at(0)>='0'&&cs.at(0)<='9')||cs.at(0)=='.'||cs.at(0)=='-') {
return cs.toFloat();
}
else {
return -999999;
}
}
}
else {
QString name=paramName;
int i=paramName.lastIndexOf(".");
if(i>-1) name=paramName.mid(i+1);
// AfxMessageBox("参数"+name+"不存在!");
str="0";
return 0.0;
}
}
float PELibraryModule::GetFloatParamInZone(CModuleParameter * pModulePara,QString& paramName,QString &str)
{
return GetFloatParam(pModulePara,paramName,str);
}
void PELibraryModule::GetParamValueByNameInZone( int iZoneIndex,const QStringList& strNameList,const QStringList &strGroupList,CON_STRU &sCON)
{
CModuleParameter * pModulePara=GetModuleParameter();
QString strPartIndex = "Zones[" + QString::number(iZoneIndex) + "].";
int nSize = strNameList.size();
QString itemname;
strcpy(sCON.stryy,"");
QString str;
for (int i=0;i<nSize;i++)
{
str="";
if(i>=strGroupList.size()) itemname=strPartIndex+strNameList[i];
else itemname=strPartIndex+strGroupList[i]+"."+strNameList[i];
float val=GetFloatParam(pModulePara,itemname,str);
if(val==-99999) {
sCON.yy[i]=0;
}
else {
sCON.yy[i] =val;
}
str=str.trimmed();
str+=",";
strcat(sCON.stryy,str.toStdString().c_str());
}
}
bool PELibraryModule::LoadParamFromInpFile(QString InpParamFile)
{
//加载
QStringList lines;
QFile file( InpParamFile );
if ( file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString line;
int n = 1;
while ( !stream.atEnd() ) {
line = stream.readLine(); // 不包括“\n”的一行文本
//printf( "%3d: %s\n", n++, line.latin1() );
if(line=="end"||line=="END"||line=="/*") break;
lines += line;
}
file.close();
}
LoadParamFromLines(lines);
return true;
}
bool PELibraryModule::LoadParamFromLines(QStringList lines)
{
if((Conc&&!Conc->Noc)&&(Inc&&!Inc->Noi)&&(Outc&&!Outc->Noo))
{
return true;
}
if(lines.size()>0&&lines[0]==""&&(lines[1]=="END"||lines[1]=="/*"))
{
lines[0]="0 0";
}
CModuleParameter * pModulePara = GetModuleParameter();
CCompositeParameterItem* Zones=(CCompositeParameterItem*)(GetModuleParameter()->GetParameterItem("Zones"));
if(Zones==NULL) return false;
//加载
int zones=Zones->GetChildCount();
for(int i=zones-1;i>=0;i--){
stringstream ss;
ss<<i;
std::string strPartIndex = "Zones[" +ss.str() + "]";
Zones->RemoveParameterItem(strPartIndex);
}
*RunCon=*DefaultCon;
//分段
QString zone="";
QString zoneparam="";
bool isnewzone;
DepthProgress dsp;
dsp.CreatProgress(0,lines.size(),"更新可视化参数...");
int flag=0;
for(int i=0;i<lines.size();i++)
{
dsp.SetDepth(i+1);
QString line=lines[i].remove("\n");
line=line.remove("\r");
line=line.toUpper();
line.replace(" "," ");
if(line=="END"||line=="/*") {
if(zone.size()&&isnewzone) {
AddZone(Zones,zone,zoneparam);
flag=1;
}
break;
}
if(line.contains(">")){
QStringList outcurves=line.split(">");
CParameterItem* pItem=pModulePara->GetParameterItem(outcurves[0].trimmed().toStdString());
if(pItem) {
pItem->SetStringValue(outcurves[1].toStdString());
}
}
else if(line.contains("<"))
{
QStringList incurves=line.split("<");
CParameterItem* pItem=pModulePara->GetParameterItem(incurves[0].trimmed().toStdString());
if(pItem) {
pItem->SetStringValue(incurves[1].toStdString());
}
}
else if(line.contains("=")){
zoneparam=zoneparam+line;
isnewzone=false;
}
else{
isnewzone=true;
line=line.trimmed();
if(line.size()<1) continue;
QStringList str=line.split(' ');
str.removeAll("");
if(str.size()!=2) continue;
if(zone.size()&&(zoneparam!=""||str.size()==2))
{
AddZone(Zones,zone,zoneparam);
zoneparam="";
flag=1;
}
zone=line;
}
}
if(zoneparam!=""){
AddZone(Zones,zone,zoneparam);
flag=1;
}
if(!flag)
{
AfxMessageBox("错误,参数卡为空或无效值!\n请修改参数卡保存后,执行刷新参数或重新打开处理模块!");
}
return true;
}
void PELibraryModule::ChangeZone(CParameterItem *clonedZone)
{
CCompositeParameterItem* cparam=static_cast<CCompositeParameterItem *>(clonedZone);
if(cparam&&cparam->GetChildCount()<500) {
int count=cparam->GetChildCount();
for(int i=0;i<count;i++) {
CParameterItem* param=cparam->GetParameterItem(i);
ChangeZone(param);
}
}
QString id=QString::fromStdString(clonedZone->GetId());
id=id.right(id.size()-id.lastIndexOf(".")-1);
clonedZone->SetId(id.toStdString());
}
CParameterItem* PELibraryModule::GetZoneParameterItem(CParameterItem *clonedZone,QString index,QString Name)
{
CCompositeParameterItem* cparam=static_cast<CCompositeParameterItem *>(clonedZone);
if(cparam&&cparam->GetChildCount()<500) {
int count=cparam->GetChildCount();
for(int i=0;i<count;i++) {
CParameterItem* param=cparam->GetParameterItem(i);
CParameterItem* param1=GetZoneParameterItem(param,index,Name);
if(param1) return param1;
}
}
QString id=QString::fromStdString(clonedZone->GetId());
QString id1=id.left(id.lastIndexOf("."));
id=id.right(id.size()-id.lastIndexOf(".")-1);
bool a=true;
if(id1.indexOf(".")>0) {
id1=id1.left(id1.lastIndexOf("."));
if(id1==index) a=true;
else a=false;
}
if(a&&id==Name) return clonedZone;
return NULL;
}
void PELibraryModule::AddLastClonedZone(CCompositeParameterItem* Zones)
{
// CCompositeParameterItem* Zones=(CCompositeParameterItem*)(GetModuleParameter()->GetParameterItem("Zones"));
if(Zones==NULL) return;
CCompositeParameterItem* Zone=
(CCompositeParameterItem*)(Zones->GetParameterItem(Zones->GetChildCount()-1));
CCompositeParameterItem clonedZone(*Zone);
// char buf[100];
// sprintf(buf,"Zones[%d]",Zones->GetChildCount());
clonedZone.SetId("Zone");//buf);
ChangeZone(&clonedZone);
Zones->AddParameterItem(clonedZone);
}
void PELibraryModule::AddDefaultZone(CCompositeParameterItem* Zones)
{
// CCompositeParameterItem* Zones=(CCompositeParameterItem*)(GetModuleParameter()->GetParameterItem("Zones"));
if(Zones==NULL) return;
if(!Conc) return;
////////////////////////////////
// Zones
// zone
// sdep
// edep
// param...
// zone
// ..
QStringList paramnames=GetParamNames();
QStringList paramcnnames=GetParamCNNames();
QStringList paramOptions;
if(Conc) paramOptions=GetNames(Conc->Options,';',false);
for(int i=0;i<paramnames.size();i++)
{
paramnames[i]=paramnames[i].trimmed();
if(i<paramcnnames.size()) paramcnnames[i]=paramcnnames[i].trimmed();
if(i<paramOptions.size()) paramOptions[i]=paramOptions[i].trimmed();
}
QStringList paramGroups=GetNames(Conc->ValType,';',false);
for(int i=0;i<paramGroups.size();i++) {
paramGroups[i]=paramGroups[i].trimmed();
}
if(paramGroups.size()==1&&paramGroups[0]=="") paramGroups.clear();
QStringList Groups;
QStringList paramGroupstemp=paramGroups;
bool cflag=0;
while(paramGroupstemp.size()) {
QString cs=paramGroupstemp[0];
cs=cs.trimmed();
if(cs!="")cflag=true;
Groups.append(cs);
paramGroupstemp.removeAll(paramGroupstemp[0]);
}
if(!cflag) Groups.clear();
CCompositeParameterItem Zoneitem;
Zoneitem.SetId("");
Zoneitem.SetName(QString("井段"));
Zoneitem.SetType(ParmType_CUSTOM);//CUSTOM
Zoneitem.SetInputType(NONEINPUT);
Zoneitem.SetCategory("Zone");
Zoneitem.SetInputMetaData("");
Zoneitem.SetInputData("HasDeleteButton;");//处理"删除按钮"的出现与消失
CParameterItem ZoneTopitem;
ZoneTopitem.SetId("ZoneTop");
ZoneTopitem.SetName(QString("井段顶深"));
ZoneTopitem.SetType(pai::module::ParmType_FLOAT);
ZoneTopitem.SetCategory("Parameter");
Zoneitem.AddParameterItem(ZoneTopitem);
CParameterItem ZoneBottomitem;
ZoneBottomitem.SetId("ZoneBottom");
ZoneBottomitem.SetName(QString("井段底深"));
ZoneBottomitem.SetType(pai::module::ParmType_FLOAT);
ZoneBottomitem.SetCategory("Parameter");
Zoneitem.AddParameterItem(ZoneBottomitem);
QString strYY=RunCon->stryy;
QStringList stryy=strYY.split(",");
if(stryy.size()==1&&stryy[0]=="") stryy.clear();
int GroupCount=Groups.size();
if(GroupCount) {
for(int j=0;j<GroupCount;j++) {
CCompositeParameterItem Groupitem;
Groupitem.SetId(Groups[j].toStdString());
Groupitem.SetName(Groups[j].toStdString());
Groupitem.SetType(ParmType_CUSTOM);//CUSTOM
Groupitem.SetInputType(NONEINPUT);
Groupitem.SetCategory(Groups[j].toStdString());
QString aa=Groups[j];
int paramGroupscount=paramGroups.size();
for (int i=0;i<paramnames.size();i++)
{
int pos=i;
if(paramGroupscount>i) {
QString bb=paramGroups[pos];
if(aa!=bb) continue;
}
CParameterItem aparamitem;
aparamitem.SetId(paramnames[i].toStdString());
if(paramcnnames.size()>i){
aparamitem.SetName(paramcnnames.at(i));
}
else
aparamitem.SetName(paramnames[i]);
if(paramGroups.size()>i)
{
aparamitem.SetCategory(paramGroups[pos].toStdString());
}
else
{
aparamitem.SetCategory("Parameter");
}
if(paramOptions.size()>i&&!paramOptions[i].isEmpty()) {
QString str=paramOptions[i];
QStringList paramOPTIONS=str.split(",");
for(int k=0;k<paramOPTIONS.size();k++) {
paramOPTIONS[k]=paramOPTIONS[k].trimmed();
}
paramOPTIONS.removeAll("");
if(paramOPTIONS.size()>1)
{
aparamitem.SetType(pai::module::ParmType_STRING);
if(str.indexOf("CHECKBOX",0,Qt::CaseInsensitive)>-1) {
aparamitem.SetInputType(SPLIT);
paramOPTIONS.removeAt(0);
str=paramOPTIONS.join("/");
aparamitem.SetInputMetaData(str.toStdString());
QString val=QString::number(RunCon->yy[pos]);
int nn=RunCon->yy[pos];
QString val1;
for(int i=0;i<val.length();i++) {
int no=nn%10;
nn=nn/10;
if(no<1||no>9||no>paramOPTIONS.size()) continue;
val1+=paramOPTIONS[no-1];
if(i!=val.length()-1) val1+=",";
}
aparamitem.SetStringValue(val1.toStdString());
}
else {
aparamitem.SetInputType(COMBOX);
str=paramOPTIONS.join("/");
aparamitem.SetInputMetaData(str.toStdString());
int index=RunCon->yy[pos];
if(index<0) index=0;
if(index>=paramOPTIONS.size()) {
index=paramOPTIONS.size()-1;
if(index<0) index=0;
}
if(index<paramOPTIONS.size()) {
aparamitem.SetStringValue(paramOPTIONS[index].toStdString());
aparamitem.SetDefault(paramOPTIONS[index].toStdString());
aparamitem.SetDisplayValue(paramOPTIONS[index].toStdString());
}
else {
QString vs=QString::number(RunCon->yy[pos]);
QString vs1="index="+vs+"超界,错误!";
aparamitem.SetValue(vs1.toStdString().c_str());
}
}
}
else {
aparamitem.SetType(pai::module::ParmType_STRING);//FLOAT);
aparamitem.SetStringValue(QString::number(RunCon->yy[pos]).toStdString());
}
}
else {
if(RunCon->yy[pos]||stryy.size()<=pos||!stryy[pos].isEmpty()) {
aparamitem.SetType(pai::module::ParmType_FLOAT);
aparamitem.SetValue(RunCon->yy[pos]);
}
else {
QChar ch=QChar();
if(stryy[pos].length()) ch=stryy[pos].at(0);
if(ch==QChar()||ch=='.'||ch=='-'||(ch>='0'&&ch<='9')) {
aparamitem.SetType(pai::module::ParmType_FLOAT);
aparamitem.SetValue(RunCon->yy[pos]);
}
else {
aparamitem.SetType(pai::module::ParmType_STRING);
aparamitem.SetStringValue(stryy[pos].toStdString());
aparamitem.SetValue(RunCon->yy[pos]);
}
}
}
Groupitem.AddParameterItem(aparamitem);
}
Zoneitem.AddParameterItem(Groupitem);
}
}
else {
for (int i=0;i<paramnames.size();i++)
{
int pos=i;
CParameterItem aparamitem;
aparamitem.SetId(paramnames[i].toStdString());
if(paramcnnames.size()>i)
aparamitem.SetName(paramcnnames[i].trimmed().toStdString());
else
aparamitem.SetName(paramnames[i].toStdString());
if(paramGroups.size()>pos)
{
aparamitem.SetCategory(paramGroups[pos].toStdString());
}
else
{
aparamitem.SetCategory("Parameter");
}
if(paramOptions.size()>pos) {
QString str=paramOptions[pos];
QStringList paramOPTIONS=str.split(",");
for(int k=0;k<paramOPTIONS.size();k++) {
paramOPTIONS[k]=paramOPTIONS[k].trimmed();
}
paramOPTIONS.removeAll("");
if(paramOPTIONS.size()>1)
{
aparamitem.SetType(pai::module::ParmType_STRING);
if(str.indexOf("CHECKBOX",0,Qt::CaseInsensitive)>-1) {
aparamitem.SetInputType(SPLIT);
paramOPTIONS.removeAt(0);
str=paramOPTIONS.join("/");
aparamitem.SetInputMetaData(str.toStdString());
QString val=QString::number(RunCon->yy[pos]);
int nn=RunCon->yy[pos];
QString val1;
for(int i=0;i<val.length();i++) {
int no=nn%10;
nn=nn/10;
if(no<1||no>9||no>=paramOPTIONS.size()) continue;
val1+=paramOPTIONS[no-1];
if(i!=val.length()-1) val1+=",";
}
aparamitem.SetStringValue(val1.toStdString());
}
else {
aparamitem.SetInputType(COMBOX);
str=paramOPTIONS.join("/");
aparamitem.SetInputMetaData(str.toStdString());
int index=RunCon->yy[pos];
if(index<0) index=0;
if(index>=paramOPTIONS.size()) {
index=paramOPTIONS.size()-1;
if(index<0) index=0;
}
if(index<paramOPTIONS.size()) {
aparamitem.SetStringValue(paramOPTIONS[index].toStdString());
aparamitem.SetDefault(paramOPTIONS[index].toStdString());
aparamitem.SetDisplayValue(paramOPTIONS[index].toStdString());
}
else {
QString vs=QString::number(RunCon->yy[pos]);
QString vs1="index="+vs+"超界,错误!";
aparamitem.SetValue(vs1.toStdString().c_str());
}
}
}
else {
aparamitem.SetType(pai::module::ParmType_FLOAT);
aparamitem.SetValue(RunCon->yy[pos]);
}
}
else {
if(RunCon->yy[pos]||stryy.size()<=pos||!stryy[pos].isEmpty()) {
aparamitem.SetType(pai::module::ParmType_FLOAT);
aparamitem.SetValue(RunCon->yy[pos]);
}
else {
QChar ch=QChar();
if(stryy[pos].length()) ch=stryy[pos].at(0);
if(ch==QChar()||ch=='.'||ch=='-'||(ch>='0'&&ch<='9')) {
aparamitem.SetType(pai::module::ParmType_FLOAT);
aparamitem.SetValue(RunCon->yy[pos]);
}
else {
aparamitem.SetType(pai::module::ParmType_STRING);
aparamitem.SetStringValue(stryy[pos].toStdString());
aparamitem.SetValue(RunCon->yy[pos]);
}
}
}
Zoneitem.AddParameterItem(aparamitem);
}
}
Zones->AddParameterItem(Zoneitem);
}
void PELibraryModule::AddZone(CCompositeParameterItem* Zones,QString zone,QString ZoneParam)
{
// qDebug()<<"onezone:"<<zone<<" "<<ZoneParam;
// CCompositeParameterItem* Zones=(CCompositeParameterItem*)(GetModuleParameter()->GetParameterItem("Zones"));
if(Zones==NULL) return;
int zonecount=Zones->GetChildCount();
if(zonecount<=0)
{
//创建第一个默认zone
AddDefaultZone(Zones);
}
else
{
AddLastClonedZone(Zones);
}
stringstream ss;
ss<<Zones->GetChildCount()-1;
std::string strPartIndex = "Zones[" +ss.str() + "]";
CCompositeParameterItem* Zone=(CCompositeParameterItem*)(Zones->GetParameterItem(strPartIndex));
if(!Zone) return;
//修改起止深度 可以以逗号、空格分隔、TAB
zone=zone.trimmed();
QStringList zonetopbottom=zone.split(" ");
if(zonetopbottom.size()<2)
zonetopbottom=zone.split(",");
if(zonetopbottom.size()<2) zonetopbottom=zone.split("\t");
if(zonetopbottom.size()<2) return;
float sdep=zonetopbottom[0].toFloat();
float edep=zonetopbottom[1].toFloat();
QString zonename="井段("
+QString::fromStdString(toString(sdep,'f',3,true,false).toStdString())+
"~"
+QString::fromStdString(toString(edep,'f',3,true,false).toStdString())+
")";
Zone->SetCategory(zonename.toStdString());
// Zone->SetId(strPartIndex);
//设置深度段
CParameterItem *pItem=Zones->GetParameterItem(strPartIndex+".ZoneTop");
// qDebug()<<"------x"<<rTime.elapsed()/1000.0;
if(pItem)pItem->SetValue(zonetopbottom[0].toFloat());
pItem=Zones->GetParameterItem(strPartIndex+".ZoneTop");
if(pItem)pItem->SetName(QString("井段顶深"));
pItem=Zones->GetParameterItem(strPartIndex+".ZoneBottom");
if(pItem)pItem->SetValue(zonetopbottom[1].toFloat());
pItem=Zones->GetParameterItem(strPartIndex+".ZoneBottom");
if(pItem)pItem->SetName(QString("井段底深"));
//修改参数值
QStringList zoneparams=ZoneParam.split(",");
for(int i=0;i<zoneparams.size();i++)
{
QStringList keyvalue=zoneparams[i].split("=");
if(keyvalue.size()<2) continue;
CParameterItem* aparm=GetZoneParameterItem(Zone,strPartIndex.c_str(),keyvalue[0].toUpper().toStdString().c_str());
if(aparm) {
QString val=keyvalue[1];
val=val.trimmed();
if(aparm->GetInputType()==SPLIT) {
int nn=val.toFloat();
QString str=aparm->GetInputMetaData().c_str();
QStringList strlst=str.split("/");
QString val1;
for(int i=0;i<val.length();i++) {
int no=nn%10;
nn=nn/10;
if(no<1||no>9||no>strlst.size()) continue;
val1+=strlst[no-1];
if(i!=val.length()-1) val1+=",";
}
aparm->SetStringValue(val1.toStdString());
}
else if(aparm->GetInputType()==COMBOX) {
int no=val.toFloat();
QString str=aparm->GetInputMetaData().c_str();
QStringList strlst=str.split("/");
if(no<0) no=0;
if(no>=strlst.size()) {
aparm->SetStringValue(val.toStdString());
no=strlst.size()-1;
}
else {
aparm->SetStringValue(strlst[no].toStdString());
}
}
else aparm->SetStringValue(val.toStdString());//SetValue(val.toFloat());
}
// qDebug()<<"------y"<<ryTime.elapsed()/1000.0;
}
}
bool PELibraryModule::InitProcessMessage(struct INC_STRU *Inc,struct OUTC_STRU *Outc,struct CONC_STRU *Conc,struct CON_STRU *Con)
{
//TODO 部分模块自定义参数界面,可以没有各类参数
CModuleParameter* param = this->GetModuleParameter();
//输入曲线
QStringList incnames=GetInPutCurveNames();
if(Inc&&incnames.size()!=Inc->Noi) {
QString anames=incnames.join(",");
QString errorMsg=QString::fromStdString(GetMetaData()->GetName())+m_libraryfilename+"_"+strDLLFun+":模块编写不正常,其输入曲线定义与数目不匹配:"+"\n";
errorMsg=errorMsg+"输入曲线名为:"+ anames +"\n" +"输入曲线数目为:"+QString::number(Inc->Noi);
AfxMessageBox(errorMsg);
// AppendConsole(pai::log::PAI_WARN,errorMsg);
return false;
}
// QTextCodec *codec = QTextCodec::codecForName("UTF8");
//输入曲线中文名
QStringList incnames_cn=GetNames(Inc->Script,';',true);
if(Inc)for (int i=0;i<Inc->Noi;i++)
{
param->AddParameterItem(incnames[i],pai::module::ParmType_STRING,"");
param->GetParameterItem(incnames[i].toStdString())->SetCategory("输入曲线");
if(incnames.size()==incnames_cn.size()){
// QString cs=codec->toUnicode(incnames_cn[i].toStdString().c_str());
param->GetParameterItem(incnames[i].toStdString())->SetName(incnames_cn[i]);
}
param->GetParameterItem(incnames[i].toStdString())->SetStringValue(incnames[i].toStdString());
}
//输出曲线
QStringList outcnames=GetOutPutCurveNames();
//输出曲线中文名
QStringList outcnames_cn;
if(Outc)outcnames_cn=GetNames(Outc->Script,';',true);
if(Outc&&outcnames.size()!=Outc->Noo) {
QString anames=outcnames.join(",");
QString errorMsg=QString::fromStdString(GetMetaData()->GetName())+m_libraryfilename+"_"+strDLLFun+":模块编写异常,其输出曲线定义与数目不匹配:"+"\n";
errorMsg=errorMsg+"输出曲线名为:"+ anames +"\n" +"输出曲线数为:"+QString::number(Outc->Noo);
// AppendConsole(pai::log::PAI_WARN,errorMsg);
AfxMessageBox(errorMsg);
return false;
}
if(Outc){
for (int i=0;i<Outc->Noo;i++)
{
param->AddParameterItem(outcnames[i],pai::module::ParmType_STRING,"");
param->GetParameterItem(outcnames[i].toStdString())->SetCategory("输出曲线");
if(outcnames.size()==outcnames_cn.size()){
param->GetParameterItem(outcnames[i].toStdString())->SetName(outcnames_cn[i].trimmed());
param->GetParameterItem(outcnames[i].toStdString())->SetStringValue(outcnames[i].toStdString());
}
}
}
//默认配置一个输入点一个输出点,供模块之间连接
Port inPort;
inPort.type = PORT_INPUT;
inPort.order = 0;
inPort.name ="inmodule";
inPort.connectedModuleType ="TRACE";
inPort.optional =true;
this->GetMetaData()->AddPort(inPort);
Port outPort;
outPort.type = PORT_OUTPUT;
outPort.order = 0;
outPort.name ="outmodule";
outPort.connectedModuleType ="TRACE";
outPort.optional =true;
this->GetMetaData()->AddPort(outPort);
/*
//参数
QStringList concnames=GetParamNames();
for(int i=0;i<concnames.size();i++) {
concnames[i]=concnames[i].trimmed();
}
//参数中文名
QStringList concnames_cn=GetNames(Conc->Script,';',true);
for(int i=0;i<concnames_cn.size();i++) {
concnames_cn[i]=concnames_cn[i].trimmed();
}
*/
///// 深度段控制行
CCompositeParameterItem Zonesitem;
Zonesitem.SetId("Zones");
Zonesitem.SetName(QString("井段"));//
Zonesitem.SetType(ParmType_ARRAY);//阵列对象,组合型,含一个列表选择对象及按钮
Zonesitem.SetInputType(NONEINPUT);//无输入框,只有选择框
Zonesitem.SetCategory("处理井段");
Zonesitem.SetInputMetaData("Add,ButtonText:添加;HasDeleteButton,ButtonText:删除;Fresh,ButtonText:收拢;");//按钮框类型为button型标签名称为“添加井段”
param->AddParameterItem(Zonesitem);
return 1;
}
void PELibraryModule::refreshParamsByConfigFile(QStringList &paramSetting)
{
QString fun=QString::fromStdString(GetMetaData()->GetID());
int i=fun.indexOf("_");
if(i>-1) fun=fun.mid(i+1);
QString paramSettingFileName=QCoreApplication::applicationDirPath() + QDir::separator() +"app"+QDir::separator()
+fun+".config";
QFile file( paramSettingFileName );
if (file.exists()&& file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString amoduleConfig;
int n = 1;
while ( !stream.atEnd() ) {
amoduleConfig = stream.readLine(); // 不包括“\n”的一行文本
//printf( "%3d: %s\n", n++, line.latin1() );
if(amoduleConfig.trimmed()!="")
paramSetting += amoduleConfig;
}
file.close();
}
if(paramSetting.size()<=0) return;
}
void PELibraryModule::GetDepthAndMX(QString curvename,QVector<float> &sdeps,QVector<float>&edeps,QVector<float>&minVs,QVector<float> &maxVs)
{
CCompositeParameterItem* Zones=(CCompositeParameterItem*)(GetModuleParameter()->GetParameterItem("Zones"));
if(Zones==NULL) return;
int zonecount=Zones->GetChildCount();
sdeps.clear();
edeps.clear();
maxVs.clear();
minVs.clear();
for(int i=0;i<zonecount;i++) {
CCompositeParameterItem* Zone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(i));
if(Zone) {
CParameterItem *pItem1=Zone->GetParameterItem(0);
if(!pItem1) continue;
CParameterItem *pItem2=Zone->GetParameterItem(1);
if(!pItem2) continue;
sdeps.append(atof(pItem1->GetStringValue().c_str()));
edeps.append(atof(pItem2->GetStringValue().c_str()));
std::vector<CParameterItem> vecLeafItems;
Zone->GetAllLeafParameterItems(vecLeafItems);
int count=vecLeafItems.size();
for(int j=2;j<count;j++) {
QString paramName=QString::fromStdString(vecLeafItems[j].GetId());
paramName=paramName.right(paramName.size()-paramName.lastIndexOf(".")-1);
int no=-1;
char strTmp[16] = "visualParam.txt";
QStringList pars=GetSimilarCurves(curvename,strTmp,true);
if(pars.size()){
if(pars.indexOf(paramName,0)==-1) continue;
}
else if(curvename=="VSH"||curvename=="SH") {
if(paramName!="SHCT") continue;
}
else if(paramName!="SHFG") continue;
if(vecLeafItems[j].GetInputType()==SPLIT){
QString str;
str=vecLeafItems[j].GetInputMetaData().c_str();
QStringList strlst=str.split("/");
no=strlst.indexOf(curvename);
if(no<0) {
for(int n=0;n<9;n++) {
QString tem=QString::number(n)+curvename;
no=strlst.indexOf(tem);
if(no>-1) break;
}
}
}
else if(vecLeafItems[j].GetInputType()==COMBOX){
QString str;
str=vecLeafItems[j].GetInputMetaData().c_str();
QStringList strlst=str.split("/");
no=strlst.indexOf(curvename);
for(int n=0;n<9;n++) {
QString tem=QString::number(n)+curvename;
no=strlst.indexOf(tem);
if(no>-1) break;
}
}
else {
no=atof(vecLeafItems[j].GetStringValue().c_str());
}
if(no<0||no>9) {
if(paramName=="SHFG") continue;
}
//else
{
QString Gmn="GMN"+QString::number(no+1);
QString Gmx="GMX"+QString::number(no+1);
if(pars.size()>1) {
Gmn=pars.at(0);
Gmx=pars.at(1);
}
else if(pars.size()>0) {
Gmn="rwrwrwr";
Gmx=pars.at(0);
}
if(curvename=="SH"||curvename=="VSH") {
Gmn="rwrwrwr";
Gmx="SHCT";
}
int num=0;
for(int k=2;k<count;k++) {
QString paramName0=QString::fromStdString(vecLeafItems[k].GetId());
QString paramName1=paramName0.right(paramName0.size()-paramName0.lastIndexOf(".")-1);
if(paramName1==Gmn){
minVs.append(atof(vecLeafItems[k].GetStringValue().c_str()));
num++;
}
else if(paramName1==Gmx){
maxVs.append(atof(vecLeafItems[k].GetStringValue().c_str()));
num++;
}
if(pars.size()&&num>=pars.size()) break;
if(curvename=="SH"||curvename=="VSH") {
if(num) break;
}
else if(num>1) break;
}
}
break;
}
}
}
}
unsigned short PELibraryModule::GetZoneCount()
{
CModuleParameter * pModulePara = GetModuleParameter();
if(pModulePara->GetParameterItem("Zones")) {
unsigned short parts_num = (reinterpret_cast<CCompositeParameterItem*> (pModulePara->GetParameterItem("Zones")))->GetChildCount();
return parts_num;
}
else return 0;
}
UINT PELibraryModule::ProcessDLL1(LPVOID pPram,float sdep,float edep)//只用公式计算的模块DLL
{
typedef int (* LPFNDLLFUNC)();
LPFNDLLFUNC lpfnDllFunc,lpfnInitDllFunc;
lpfnDllFunc = (LPFNDLLFUNC)(Methodlib.resolve(strDLLFun.toStdString().c_str()));//strDLLFun.toStdString().c_str())
if(!lpfnDllFunc)
{
AfxMessageBox("处理函数"+strDLLFun+"不存在,请检查配置文件!");
m_pMemRdWt->Close();
return 0;
//入口函数不存在
}
m_pMemRdWt->ZoneSdep=sdep;
m_pMemRdWt->ZoneEdep=edep;
if(m_pMemRdWt->Const()<0) {
AfxMessageBox("参数卡有误,运行被停止!");
m_pMemRdWt->Close();
return 0;
}
m_pMemRdWt->In();
if(errorinf) {
if(errorinf->ErrorNo<0)
{
AfxMessageBox(errorinf->ErrorStr);
m_pMemRdWt->Close();
return 0;
}
}
m_pMemRdWt->Out();
if(sdep!=-99999) Hd->StartDep=sdep;
if(edep!=-99999) Hd->EndDep=edep;
////////////////////////////////
//
// 逐点循环运行
//
//DepthProgress mDP;
if(Hd->Endep==0) Hd->Endep=Hd->EndDep;
//mDP.CreatProgress(Hd->Stdep,Hd->Endep);
DepthProgress DepthProgress;
DepthProgress.CreatProgress(Hd->Stdep,Hd->Endep,"数据处理中....");
CString cs;
int flag=1;
while ( 1 )
{
m_pMemRdWt->In();
DepthProgress.SetDepth(Hd->Dep);
int i = lpfnDllFunc();
if ( i < 0 ||errorinf->ErrorNo<0) //运算出错
{
if ( errorinf->ErrorNo <=0 )
{
cs.Format("提示 : %s ",errorinf->ErrorStr);
if(i<0)flag=i;
else flag=errorinf->ErrorNo;
break;
}
else {
// AppendConsole(pai::log::PAI_INFO,errorinf->ErrorStr);
cs="处理异常终止!";
}
flag=i;
break;
}
m_pMemRdWt->Out();
int j=(int)(Hd->Edep/Hd->Rlev+0.5);
float dep1=j*Hd->Rlev;
if ( Hd->Dep >Hd->Edep ) {
break;
}
if(Hd->Dep>Hd->EndDep) break;
//mDP.SetDepth(Hd->Dep);
}
QString slf=m_pMemRdWt->GetWellName().GetString();
QStringList Names;
int Noo=m_pMemRdWt->GetOutCurveCount();
for(int i=0;i<Noo;i++)
{
char name[200];
m_pMemRdWt->GetOutCurveName(i,name);
Names.append(name);
}
m_pMemRdWt->Close();
// for(int i=0;i<Noo;i++)
// {
// GetObjectEvent().OnDeAttchData(slf,Names[i]);
// }
// for(int i=0;i<Noo;i++)
// {
// GetObjectEvent().OnDeAttchData(slf,Names[i]);
// GetObjectEvent().OnRefreshData(slf,Names[i]);
// }
DepthProgress.DelProgress();
if(flag>=0) {
cs="处理完毕!";
}
else AfxMessageBox(cs);
return flag;
}
UINT PELibraryModule::ProcessDLL2(LPVOID pPram,float sdep,float edep)//自控模块DLL
{
typedef int (* LPFNDLLFUNC)();
LPFNDLLFUNC lpfnDllFunc,lpfnInitDllFunc;
lpfnDllFunc = (LPFNDLLFUNC)(Methodlib.resolve(strDLLFun.toStdString().c_str()));//strDLLFun.toStdString().c_str())
if(!lpfnDllFunc)
{
AfxMessageBox("处理函数"+strDLLFun+"不存在,请检查配置文件!");
//入口函数不存在
m_pMemRdWt->Close();
return 0;
}
////////////////////////////////
//
// 逐点循环运行
//
//DepthProgress mDP;
if(Hd->Endep==0) Hd->Endep=Hd->EndDep;
//mDP.CreatProgress(Hd->Stdep,Hd->Endep);
int flag=0;
m_pMemRdWt->ZoneSdep=sdep;
m_pMemRdWt->ZoneEdep=edep;
if(m_pMemRdWt->Const()<0) {
AfxMessageBox("参数卡有误,运行被停止!");
m_pMemRdWt->Close();
return 0;
}
if(sdep!=-99999) Hd->StartDep=sdep;
if(edep!=-99999) Hd->EndDep=edep;
int i = lpfnDllFunc();
CString cs;
if ( i < 0||(errorinf&&errorinf->ErrorNo<0) ) //运算出错
{
if ( errorinf&&errorinf->ErrorNo <=0 )
{
cs.Format("提示 : %s ",errorinf->ErrorStr);
if(i<0)flag=i;
else flag=errorinf->ErrorNo;
}
else {
// if(errorinf)AppendConsole(pai::log::PAI_INFO,errorinf->ErrorStr);
}
}
else {
cs="处理完毕!";
flag=1;
}
QString slf=m_pMemRdWt->GetWellName().GetString();
QStringList Names;
Names.clear();
int Noo=m_pMemRdWt->GetOutCurveCount();
for(int j=0;j<Noo;j++)
{
char name[200];
m_pMemRdWt->GetOutCurveName(j,name);
Names.append(name);
}
m_pMemRdWt->Close();
// for(int j=0;j<Noo;j++)
// {
// GetObjectEvent().OnDeAttchData(slf,Names[j]);
// }
// for(int j=0;j<Noo;j++)
// {
// GetObjectEvent().OnDeAttchData(slf,Names[j]);
// GetObjectEvent().OnRefreshData(slf,Names[j]);
// }
if(flag>=0) {
}
else AfxMessageBox(cs);
return flag;
}
pai::module::STATUS PELibraryModule::Run()
{
return Run(-99999.0,-99999.0);
}
pai::module::STATUS PELibraryModule::Run(double sdep,double edep,char*Zone)
{
int flag=0;
if(InitMemRdWt(sdep,edep,Zone,true)) {
m_pMemRdWt->BackUpFile();
// QFileInfo FileInfo(GetLibraryfilename());
// QString DLL=FileInfo.baseName();
// LogPlusClient ss(DLL,"Sripe","v1.0",/*"127.0.0.1"*/"10.225.14.93",10020);
if(runBrunch==1) flag=ProcessDLL1(NULL,sdep,edep);
else if(runBrunch==2)flag=ProcessDLL2(NULL,sdep,edep);
m_pMemRdWt->Close();
{
typedef int (* LPFNDLLFUNC)();
LPFNDLLFUNC lpfnInitDllFunc;
char InitDll[300];
///////////////
//初始化信息
//
strcpy(InitDll,"Finish");
lpfnInitDllFunc = (LPFNDLLFUNC)Methodlib.resolve(InitDll);
if(lpfnInitDllFunc) lpfnInitDllFunc();
}
}
return (pai::module::STATUS)flag;
}
QStringList PELibraryModule::GetInPutCurveNames()
{
if(OriginInNames.size()<=0)
{
std::string names(Inc->Name);
OriginInNames=GetNames(names);
}
return OriginInNames;
}
QStringList PELibraryModule::GetOutPutCurveNames()
{
if(OriginOutNames.size()<=0&&Outc)
{
std::string names(Outc->Name);
OriginOutNames=GetNames(names);
}
return OriginOutNames;
}
QStringList PELibraryModule::GetParamNames()
{
if(!Conc) return QStringList();
std::string names(Conc->Name);
return GetNames(names);
}
bool PELibraryModule::validate(CModuleCheckResult& moduleCheckResult)
{
return true;
}
bool PELibraryModule::validate()
{
typedef int (* LPFNDLLFUNC)();
LPFNDLLFUNC lpfnInitDllFunc;
char InitDll[300];
///////////////
//初始化信息
//
strcpy(InitDll,"Init");
lpfnInitDllFunc = (LPFNDLLFUNC)Methodlib.resolve(InitDll);
if(!lpfnInitDllFunc) {
strcat(InitDll,strDLLFun.toStdString().c_str());
lpfnInitDllFunc = (LPFNDLLFUNC)Methodlib.resolve(InitDll);
}
if(lpfnInitDllFunc) lpfnInitDllFunc();
m_pMemRdWt->ChangeName(Inc,Outc,Conc,Con);
*DefaultCon=*Con;
*RunCon=*Con;
return TRUE;
}
bool PELibraryModule::InitModule(QWidget*pWidget)
{
typedef QDialog *(* LPDDIALOG)(QWidget*pWidget);
typedef void* (*LPD_ACTION_FUNC)(int* count);
typedef int (* LPFNDLLFUNC)();
LPFNDLLFUNC lpfnDllFunc,lpfnInitDllFunc;
LPDDIALOG m_parDialog;
if(parDialog)
{
parDialog->setParent(NULL);
parDialog=NULL;
}
if(m_pMemRdWt&&iscreatemem) {
delete m_pMemRdWt;
m_pMemRdWt=NULL;
iscreatemem=0;
}
if(Methodlib.isLoaded()) {
Methodlib.unload();
}
//2.如果dll无法正常加载则退出
Methodlib.setFileName(m_libraryfilename); //声明所用到的dll文件
if(!Methodlib.load()){
return false;
//动态库加载失败
}
m_pMemRdWt = (CMemRdWt *)Methodlib.resolve("MemRdWt");
if(!m_pMemRdWt) {
m_pMemRdWt=new CMemRdWt;
iscreatemem=1;
}
const char *wellname1 = GetSlfFileName().toStdString().c_str();
QString wellname2 = QString::fromLocal8Bit(GetSlfFileName().toStdString().c_str());
QString wellname3 = GetSlfFileName();
/*GetSlfFileName().toStdString().c_str())*/
// if(!m_pMemRdWt->Open("D:/jiayl0909/logPlus/build/Logdata/JPH-307.slf"))
if(!m_pMemRdWt->Open(wellname3.toStdString().c_str()))
{
if(iscreatemem) delete m_pMemRdWt;
m_pMemRdWt=NULL;
Methodlib.unload();
iscreatemem=0;
return false;
}
///
errorinf = (struct ErrorInf *)Methodlib.resolve("ErrorInf");
if(!errorinf) errorinf = (struct ErrorInf *)Methodlib.resolve("errorinf");
if(!errorinf) errorinf = (struct ErrorInf *)Methodlib.resolve("ERRORINF");
///////////////
//初始化窗口信息
//
char InitDllw[300];
strcpy(InitDllw,"InitDialog");
m_parDialog = (LPDDIALOG)Methodlib.resolve(InitDllw);
if(!m_parDialog){
strcpy(InitDllw,"Initw");
m_parDialog = (LPDDIALOG)Methodlib.resolve(InitDllw);
}
if(m_parDialog) {
if(errorinf) errorinf->ErrorNo=0;
parDialog=m_parDialog(pWidget);
LPD_ACTION_FUNC ACT_Func = (LPD_ACTION_FUNC)Methodlib.resolve("getAction_CApi");
if (ACT_Func)
{
int ncount = 0;
QAction** actArr = (QAction**)ACT_Func(&ncount);
for (int i = 0; i < ncount; i++)
{
QAction* pAct = actArr[i];
QString s = pAct->property("icon_v").toString();
m_listAct << actArr[i];
}
}
if(errorinf) {
if(errorinf->ErrorNo<0) {
if(parDialog) {
parDialog->setParent(NULL);
delete parDialog;
}
parDialog=NULL;
if(iscreatemem) delete m_pMemRdWt;
m_pMemRdWt=NULL;
if(strlen(errorinf->ErrorStr))
{
AfxMessageBox(errorinf->ErrorStr);
}
Methodlib.unload();
iscreatemem=0;
return false;
}
}
}
/////////////////
Hd = (struct HD_STRU *)Methodlib.resolve("HD");
Inc = (struct INC_STRU *)Methodlib.resolve("INC");
Outc = (struct OUTC_STRU *)Methodlib.resolve("OUTC");
Inp = (struct INP_STRU *)Methodlib.resolve("INP");
Outp = (struct OUTP_STRU *)Methodlib.resolve("OUTP");
Conc = (struct CONC_STRU *)Methodlib.resolve("CONC");
Con = (struct CON_STRU *)Methodlib.resolve("CON");
// 显示乱码进行字符串转码
if (strlen(Inc->Script)==0&&strlen(Inc->Name)>0)// m_pMemRdWt->ChangeName函数会用Inc->Name生成Inc->Scrip防止重复转换字符串格式暂时先这样判断是否转换过格式
{
ToUnicode(Inc->Name);
ToUnicode(Inc->Script);
ToUnicode(Inc->Unit);
ToUnicode(Conc->Name);
ToUnicode(Conc->Script);
ToUnicode(Conc->Unit);
ToUnicode(Conc->Options);
ToUnicode(Conc->ValType);
ToUnicode(Outc->Name);
ToUnicode(Outc->Script);
ToUnicode(Outc->Unit);
}
if(paramCardNameInSlf.isEmpty()) {
if(Hd){
paramCardNameInSlf=Hd->Param;
SetParamCardfilename(paramCardNameInSlf);
}
}
else if(Hd){
strcpy(Hd->Param,paramCardNameInSlf.toStdString().c_str());
}
char InitDll[300];
///////////////
//初始化信息
//
strcpy(InitDll,"Init");
lpfnInitDllFunc = (LPFNDLLFUNC)Methodlib.resolve(InitDll);
if(!lpfnInitDllFunc)
{
strcat(InitDll,strDLLFun.toStdString().c_str());
lpfnInitDllFunc = (LPFNDLLFUNC)Methodlib.resolve(InitDll);
}
if(lpfnInitDllFunc) lpfnInitDllFunc();
///
errorinf = (struct ErrorInf *)Methodlib.resolve("ErrorInf");
if(!errorinf) errorinf = (struct ErrorInf *)Methodlib.resolve("errorinf");
if(!errorinf) errorinf = (struct ErrorInf *)Methodlib.resolve("ERRORINF");
pLogType = (struct LogType *)Methodlib.resolve("LogType");
if(!pLogType) pLogType = (struct LogType *)Methodlib.resolve("Logtype");
if(!pLogType) pLogType = (struct LogType *)Methodlib.resolve("logtype");
if(!pLogType) pLogType = (struct LogType *)Methodlib.resolve("LOGTYPE");
//3.如果dll中的输入曲线条数和名称数对不上则退出
// 如果dll中的输出曲线条数和名称数对不上则退出
// 如果dll中的参数个数和名称数对不上则退出
if(!Conc) {
// AfxMessageBox("处理模块缺少参数名结构CONC_STRCT");
if(parDialog)
{
parDialog->setParent(NULL);
parDialog=NULL;
}
if(iscreatemem) {
delete m_pMemRdWt;
m_pMemRdWt=NULL;
iscreatemem=0;
Methodlib.unload();
}
return false;
}
m_pMemRdWt->ChangeName(Inc,Outc,Conc,Con);
*DefaultCon=*Con;
*RunCon=*Con;
if(!InitProcessMessage(Inc,Outc,Conc,Con))
{
if(parDialog)
{
parDialog->setParent(NULL);
parDialog=NULL;
}
if(iscreatemem) {
delete m_pMemRdWt;
m_pMemRdWt=NULL;
iscreatemem=0;
Methodlib.unload();
}
return false;
}
m_pMemRdWt->Close();
return true;
}
//得到重定向后的所有输入曲线名,如果没有重定向则采用初始的曲线名
std::string PELibraryModule::GetRedirectInputCurveNames()
{
CModuleParameter * pModulePara = GetModuleParameter();
QStringList incnames=GetInPutCurveNames();
std::string innames="";
for(int inputindex=0;inputindex<incnames.size();inputindex++)
{
std::string ss=incnames.at(inputindex).toStdString();
CParameterItem* pItem=pModulePara->GetParameterItem(ss);
std::string strCurveName ="";
if(pItem) {
strCurveName =pItem->GetStringValue();
}
if(strCurveName=="")//说明没有输入,采用默认值
strCurveName=incnames.at(inputindex).toStdString();
innames=innames+strCurveName;
/*
for(int i=strlen(strCurveName.c_str());i<8;i++) {
innames+=" ";
}
*/
innames+=" ";
}
return innames;
}
//得到重定向后的所有输出曲线名,如果没有重定向则采用初始的曲线名
std::string PELibraryModule::GetRedirectOutputCurveNames()
{
CModuleParameter * pModulePara = GetModuleParameter();
QStringList outcnames=GetOutPutCurveNames();
std::string outnames="";
for(int outputindex=0;outputindex<outcnames.size();outputindex++)
{
std::string strCurveName="";
CParameterItem* pItem=pModulePara->GetParameterItem(outcnames.at(outputindex).toStdString());
if(pItem) {
strCurveName = pItem->GetStringValue();
}
if(strCurveName=="")//说明没有输入,采用默认值
strCurveName=outcnames.at(outputindex).toStdString();
outnames=outnames+strCurveName+" ";
for(int i=strlen(strCurveName.c_str());i<8;i++) outnames+=" ";
}
return outnames;
}
QTextEdit *PELibraryModule::GetEdit()
{
return m_pCardpEdit;
}
void PELibraryModule::SetEdit(QTextEdit *pEdit)
{
m_pCardpEdit=pEdit;
}
CObjWell* GetObjWellFromFileName(QString wellname,CObjWelllogRound*&pObjWelllogRound)
{
wellname.replace("\\","/");
while(wellname.indexOf("/..")>-1) {
int ii=wellname.indexOf("/..");
QString cs=wellname.left(ii);
int ii1=cs.lastIndexOf("/");
cs=cs.left(ii1);
wellname=cs+wellname.mid(ii+3);
}
// CObjProject *pPrj=::GetProject();
// if(!pPrj) return NULL;
// PaiObject *pObj=pPrj->GetObjectByType(GetClassID_WellsFolder());
// if(!pObj) return NULL;
// QList<PaiObject *> childs;
// pObj->GetChildren(childs);
// foreach(PaiObject *pChild,childs) {
// CObjWell *pWell=dynamic_cast<CObjWell*>(pChild);
// if(pWell) {
// int count=pWell->GetWellRoundCount();
// QList<PaiObject*>chs;
// pWell->GetAllWellRound(chs);
// for(int i=0;i<count;i++) {
// CObjWelllogRound*pR=dynamic_cast<CObjWelllogRound*>(chs[i]);
// if(pR)
// {
// QString ss=pR->GetSlfFileName();
// ss.replace("\\","/");
// while(ss.indexOf("/..")>-1) {
// int ii=ss.indexOf("/..");
// QString cs=ss.left(ii);
// int ii1=cs.lastIndexOf("/");
// cs=cs.left(ii1);
// ss=cs+ss.mid(ii+3);
// }
// if(ss.compare(wellname,Qt::CaseInsensitive)==0) {
// pObjWelllogRound=pR;
// return pWell;
// }
// }
// }
// }
// }
return NULL;
}
QString PELibraryModule::GetINPParamCard(CMemRdWt *pMemrdWt,char *p,bool isSaveToEdit )
{
bool toTable=1;
QStringList paramSetting;
refreshParamsByConfigFile(paramSetting);
QString result="";
QTextEdit *pEdit=GetEdit();
if(isEditCard&&pEdit) {
result=pEdit->toPlainText();
result.replace(" "," ");
result.replace("",",");
result.replace(", ",",");
result.replace("\r\n","\n");
result.replace("\r","\n");
result.replace(" \n","\n");
result.replace("\n","\r\n");
return result;
}
int zoneCount=GetZoneCount();
if(zoneCount<=0) return "";
CModuleParameter * pModulePara = GetModuleParameter();
if(!pModulePara) return "";
CCompositeParameterItem *Zones=dynamic_cast<CCompositeParameterItem *>(pModulePara->GetParameterItem("Zones"));
if(!Zones) return "";
QStringList incnames=GetInPutCurveNames();
std::string innames="";
for(int inputindex=0;inputindex<incnames.size();inputindex++)
{
std::string ss=incnames.at(inputindex).toStdString();
CParameterItem* pItem=pModulePara->GetParameterItem(ss);
std::string strCurveName ="";
if(pItem) {
strCurveName =pItem->GetStringValue();
}
if(strCurveName=="")//说明没有输入,采用默认值
strCurveName=incnames.at(inputindex).toStdString();
if(ss!=strCurveName) {
result+=ss.c_str();
result+="<";
result+=strCurveName.c_str();
result+="\r\n";
}
}
QStringList outcnames=GetOutPutCurveNames();
std::string outnames="";
for(int outputindex=0;outputindex<outcnames.size();outputindex++)
{
std::string ss=outcnames.at(outputindex).toStdString();
std::string strCurveName="";
CParameterItem* pItem=pModulePara->GetParameterItem(outcnames.at(outputindex).toStdString());
if(pItem) {
strCurveName = pItem->GetStringValue();
}
if(strCurveName=="")//说明没有输入,采用默认值
strCurveName=outcnames.at(outputindex).toStdString();
if(ss!=strCurveName) {
result+=ss.c_str();
result+=">";
result+=strCurveName.c_str();
result+="\r\n";
}
}
bool flag=false;//标志参数是否提取成功
QStringList Options=GetNames(Conc->Options,';',false);
QStringList paramGroups=GetNames(Conc->ValType,';',false);
QStringList ParamNames=GetParamNames();
if(paramGroups.size()==1&&paramGroups[0]=="") paramGroups.clear();
CON_STRU tempcon=*DefaultCon;
DepthProgress dps;
dps.CreatProgress(0,zoneCount,"生成参数卡..");
QString tablename=Hd->Param;
char *bufval=NULL;
if(tablename.indexOf(".")>-1)
{
int pos=tablename.indexOf(".");
tablename=tablename.left(pos);
}
QString tab_param=tablename+"_PARAM_TAB";
QString tab_main=tablename+"_PARAM_CTRL";
QString tab_add=tablename+"_PARAM_ADD";
QStringList vs=GetSimilarCurves(tab_param);
QStringList vs_main=GetSimilarCurves(tab_main);
QStringList vs_add=GetSimilarCurves(tab_add);
if(!vs.size()) {
vs=GetSimilarCurves("PARAM_TAB");
tablename="PARAM_TAB";
}
else {
tablename+="_TAB";
}
if(!vs_main.size()) vs_main=GetSimilarCurves("PARAM_CTRL");
if(!vs_add.size()) vs_add=GetSimilarCurves("PARAM_ADD");
// if(m_pMemRdWt)
if(!pMemrdWt) pMemrdWt=m_pMemRdWt;
int iIndex=-1;
if(toTable){
iIndex=pMemrdWt->OpenTable(tablename.toStdString().c_str());
if (iIndex < 0)
{
char name[1000];
strcpy(name,"SDEP,EDEP,");
char type[1000]="4,4,";
char leng[1000]="4,4,";
char res[1000]="0,0,";
for(int j=0;j<vs.size();j++)
{
strcat(name,vs[j].toStdString().c_str());
// if(j!=Conc->Noc-1)
strcat(name,",");
strcat(leng,"20");
// if(j!=Conc->Noc-1)
strcat(leng,",");
strcat(type,"6");
// if(j!=Conc->Noc-1)
strcat(type,",");
strcat(res,"0");
// if(j!=Conc->Noc-1)
strcat(res,",");
}
iIndex=pMemrdWt->Open_Set_Table(tablename.toStdString().c_str(),0,vs.size()+2,
name,leng,type,res);
CObjWelllogRound *pWelllogRound=NULL;
CObjWell*pWell=GetObjWellFromFileName(GetSlfFileName(),pWelllogRound);
if(pWelllogRound) {
// PaiObject*pBase=pWelllogRound->GetObjectByName(tablename,GetClassID_WellLogTABLE());
// if(!dynamic_cast<CObjWellLogTABLE *>(pBase)){
// CObjWellLog * acurve=new CObjWellLogTABLE();
// if(acurve) {
// acurve->m_ObjectType=TABLEE_OBJECT;
// acurve->SetName(tablename);
// acurve->SetAliasName(tablename);
// acurve->SetSlfFileName(GetSlfFileName());
// acurve->SetWell(pWelllogRound->GetWell());
// pWelllogRound->AddChild(acurve);
// }
// }
}
}
pMemrdWt->SetTableRecordCount(iIndex,0);
int tablen=m_pMemRdWt->GetTableRecordLength(iIndex);
bufval=new char[tablen];
memset(bufval,0,tablen);
}
int linenum=0;
float eedep=0;
QStringList parms_val;
QStringList parms_add;
for(int i=0;i<zoneCount;i++)
{
QString stryy;
dps.SetDepth(i+1);
if(toTable){
if(!linenum) {
for(int j=0;j<vs.size();j++){
int pos=ParamNames.indexOf(vs[j]);
char str[21];
sprintf(str,"%g",tempcon.yy[pos]);
// if(pos>-1) pMemrdWt->SetTableFieldData(iIndex,(char*)vs[j].toStdString().c_str(),(char*)&tempcon.yy[pos],linenum+1);
if(pos>-1) pMemrdWt->SetTableFieldData(iIndex,(char*)vs[j].toStdString().c_str(),str,linenum+1);
}
for(int j=0;j<vs_add.size();j++){
int pos=ParamNames.indexOf(vs_add[j]);
char str[21];
sprintf(str,"%g",tempcon.yy[pos]);
if(pos>-1) {
int pos1=parms_add.indexOf(vs_add[j]);
if(pos1<0) {
parms_add.append(vs_add.at(j));
QStringList cs;
QString str1=str;
for(int n=0;n<str1.size();n++)
{
if(cs.indexOf(str1.at(n))<0) cs.append(str1.at(n));
}
cs.removeAll("");
cs.sort();
parms_val.append(cs.join(","));
}
}
}
}
else pMemrdWt->WriteTable(iIndex,linenum+1,bufval);
}
stringstream stream;
stream.str("");
stream << i;
std::string strPartIndex = "Zones[" + stream.str() + "]";
CCompositeParameterItem * azone=dynamic_cast<CCompositeParameterItem*>(Zones->GetParameterItem(strPartIndex));
if(azone)
{
int count=azone->GetChildCount();
if(count>=2)
{
flag=true;
//每一zone的顶底深度
CParameterItem *pItem1=azone->GetParameterItem(0);
CParameterItem *pItem2=azone->GetParameterItem(1);
float sdep=atof(pItem1->GetStringValue().c_str());
float edep=atof(pItem2->GetStringValue().c_str());
eedep=edep;
result=result+" "+toString(sdep,'f',2,true,false)+" "+toString(edep,'f',2,true,false)+"\r\n";
int num=0;
int isneq=0;
for(int j=2;j<count;j++)
{
CParameterItem *pItem=azone->GetParameterItem(j);
CCompositeParameterItem *pLeafs=dynamic_cast<CCompositeParameterItem*>(pItem);
if(pLeafs) {
int nleaf=pLeafs->GetChildCount();
for(int k=0;k<nleaf;k++) {
CParameterItem *pItem1=pLeafs->GetParameterItem(k);
QString paramName=QString::fromStdString(pItem1->GetId());
paramName=paramName.right(paramName.size()-paramName.lastIndexOf(".")-1);
QString val=QString::fromStdString(pItem1->GetStringValue());
QString str;
if(pItem1->GetInputType()==SPLIT) {
str=pItem1->GetInputMetaData().c_str();
QStringList strlst=str.split("/");
QStringList vallst=val.split(',');
int iii=0;
for(int jj=0;jj<vallst.size();jj++) {
int no=strlst.indexOf(vallst[jj]);
if(no<0) continue;
iii*=10;
iii+=no+1;
}
str=QString::number(iii);
}
else if(pItem1->GetInputType()==COMBOX) {
str=pItem1->GetInputMetaData().c_str();
QStringList strlst=str.split("/");
int no=strlst.indexOf(val);
if(no>-1) {
str=QString::number(no);
}
else str=val;
}
else str=val;
float val1=str.toFloat();
int pos1=ParamNames.indexOf(paramName);
int pos2=paramSetting.indexOf(paramName);
int pos3=vs_main.indexOf(paramName);
int pos4=parms_add.indexOf(paramName);
if(pos1>-1&&((str.toFloat()!=tempcon.yy[pos1])||(pos2>-1&&!i)))
{
if(num&&num%20==0)result+="\r\n";
result=result+paramName+"="+str+",";
num++;
if(pos3>-1) {
isneq++;
// if(toTable)pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)&val1,linenum+1);
if(toTable)pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)str.toStdString().c_str(),linenum+1);
}
if(pos4>-1) {
QStringList cs=parms_val[pos4].split(',');
for(int n=0;n<str.size();n++)
{
if(cs.indexOf(str.at(n))<0) cs.append(str.at(n));
}
cs.removeAll("");
cs.sort();
parms_val[pos4]=cs.join(",");
pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)parms_val[pos4].toStdString().c_str(),1);
}
}
tempcon.yy[pos1]=str.toFloat();
stryy+=str;
stryy+=",";
}
}
else {
QString paramName=QString::fromStdString(pItem->GetId());
paramName=paramName.right(paramName.size()-paramName.lastIndexOf(".")-1);
QString val=QString::fromStdString(pItem->GetStringValue());
QString str;
if(pItem->GetInputType()==COMBOX) {
str=pItem->GetInputMetaData().c_str();
QStringList strlst=str.split("/");
int no=strlst.indexOf(val);
if(no>-1)str=QString::number(no);
else str=val;
}
else str=val;
float val1=str.toFloat();
int pos1=ParamNames.indexOf(paramName);
int pos2=paramSetting.indexOf(paramName);
int pos3=vs_main.indexOf(paramName);
int pos4=parms_add.indexOf(paramName);
if(pos1>-1&&((str.toFloat()!=tempcon.yy[pos1])||(pos2>-1&&!i)))
{
if(num&&num%7==0)result+="\r\n";
result=result+paramName+"="+str+",";
num++;
if(pos3>-1) {
// if(toTable)pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)&val1,linenum+1);
if(toTable)pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)str.toStdString().c_str(),linenum+1);
isneq++;
}
if(pos4>-1) {
QStringList cs=parms_val[pos4].split(',');
for(int n=0;n<str.size();n++)
{
if(cs.indexOf(str.at(n))<0) cs.append(str.at(n));
}
cs.removeAll("");
cs.sort();
parms_val[pos4]=cs.join(",");
pMemrdWt->SetTableFieldData(iIndex,(char*)paramName.toStdString().c_str(),(char*)parms_val[pos4].toStdString().c_str(),1);
}
}
tempcon.yy[pos1]=str.toFloat();
stryy+=str;
stryy+=",";
}
}
int len=result.length();
if(len&&result.at(len-1)==',') result=result.left(len-1);
len=result.length();
if(len&&result.at(len-1)!='\n')result=result+"\r\n";
if(isneq) {
if(toTable){
char strSDEPTmp[5] = "SDEP";
char strEDEPTmp[5] = "EDEP";
pMemrdWt->SetTableFieldData(iIndex,strSDEPTmp,(char*)&sdep,linenum+1);
if(linenum)pMemrdWt->SetTableFieldData(iIndex,strEDEPTmp,(char*)&sdep,linenum);
}
linenum++;
}
if(i==zoneCount-1) eedep=edep;
}
strcpy(tempcon.stryy,stryy.toStdString().c_str());
}
else AfxMessageBox("内部错误:井段"+QString(strPartIndex.c_str()));
}
if(toTable){
char strTmp[5] = "EDEP";
if(linenum) pMemrdWt->SetTableFieldData(iIndex,strTmp,(char*)&eedep,linenum);
pMemrdWt->SetTableRecordCount(iIndex,linenum);
pMemrdWt->CloseTable(iIndex);
}
if(bufval) delete bufval;
if(zoneCount<1)
{
result="0 0\r\n";
if(Conc->Noc>0) AfxMessageBox("可视化参数为空!");
}
result=result+"END\r\n";
if(isSaveToEdit&&pEdit) {
result.replace(",",", ");
pEdit->setText(result);
SetCardParamColor(pEdit);
}
return result;
}
// quick sort
void qsort(QStringList &datx,QStringList &daty,int left,int right,int idx)
{
if(right<left+1) return;
int i,j;
float x,y;
i=left;
j=right;
x=datx[(left+right)/2].length();
do
{
if(idx==0)
{
while(datx[i].length()<x && i<right) i++;
while(datx[j].length()>x && j>left ) j--;
}
else
{
while(datx[i].length()>x && i<right) i++;
while(datx[j].length()<x && j>left ) j--;
}
if(i<=j)
{
QString yy=datx[i];
datx[i]=datx[j];
datx[j]=yy;
yy=daty[i];
daty[i]=daty[j];
daty[j]=yy;
i++;j--;
}
} while(i<=j);
if(left<j) qsort(datx,daty,left,j,idx);
if(i<right) qsort(datx,daty,i,right,idx);
}
void setInsertTextColor(QTextEdit *m_pEdtParamCard,QString search_text,const QColor &color)
{
QTextDocument *document =m_pEdtParamCard->document();
bool found = false;
QTextCursor highlight_cursor(document);
QTextCursor cursor(document);
//开始
cursor.beginEditBlock();
QTextCharFormat color_format(highlight_cursor.charFormat());
color_format.setForeground(color);
while (!highlight_cursor.isNull() && !highlight_cursor.atEnd()) {
//查找指定的文本,匹配整个单词
highlight_cursor = document->find(search_text, highlight_cursor);//, QTextDocument::FindBackward);
if (!highlight_cursor.isNull()) {
if(!found)
found = true;
highlight_cursor.mergeCharFormat(color_format);
}
}
highlight_cursor.setPosition(0);
color_format.setForeground(QColor(0,0,0));
highlight_cursor.mergeCharFormat(color_format);
cursor.endEditBlock();
}
void PELibraryModule::SetCardParamColor(QTextEdit *pEdit)
{
if(!pEdit) return;
//TODO处理汉化问题
QStringList paramnames=GetParamNames();
QStringList paramcnnames=GetParamCNNames();
for(int i=0;i<paramnames.size();i++)
{
paramnames[i]=paramnames[i].trimmed();
}
for(int i=0;i<paramcnnames.size();i++)
{
paramcnnames[i]=paramcnnames[i].trimmed();
}
QStringList paramGroups;
if(Conc) paramGroups=GetNames(Conc->ValType,';',false);
for(int i=0;i<paramGroups.size();i++) {
paramGroups[i]=paramGroups[i].trimmed();
}
if(paramGroups.size()==1&&paramGroups[0]=="") paramGroups.clear();
QStringList Groups;
QStringList paramGroupstemp=paramGroups;
bool cflag=0;
while(paramGroupstemp.size()) {
QString cs=paramGroupstemp[0];
cs=cs.trimmed();
if(cs!="")cflag=true;
Groups.append(cs);
paramGroupstemp.removeAll(paramGroupstemp[0]);
}
if(!cflag) Groups.clear();
QColor colors[16]={
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128),
QColor(0,0,128)
};
int GroupCount=Groups.size();
if(GroupCount) {
qsort(paramnames,paramGroups,0,paramnames.size()-1,0);
int i=0;
for(int j=0;j<paramnames.size();j++) {
i=Groups.indexOf(paramGroups[j]);
if(i<0) continue;
setInsertTextColor(pEdit,paramnames[j],colors[i%16]);
}
}
}
bool PELibraryModule::GetPARAM_TAB()
{
if(!m_pMemRdWt) return false;
if(GetSlfFileName()=="")
{
m_pMemRdWt->Close();
return false;
}
if(!m_pMemRdWt->Open(GetSlfFileName().toStdString().c_str()))
{
//AfxMessageBox("您还没有选择井文件或井文件不存在!在您运行之前,请选择井文件!");
return false;
}
QString parmacard=GetINPParamCard(NULL,NULL,false);
m_pMemRdWt->Close();
return true;
}
bool PELibraryModule::InitMemRdWt(double sdep,double edep,char*Zone,bool isSaveCard)
{
if(!m_pMemRdWt) return false;
if(GetSlfFileName()=="")
{
m_pMemRdWt->Close();
return false;
}
if(!m_pMemRdWt->Open(GetSlfFileName().toStdString().c_str()))
{
//AfxMessageBox("您还没有选择井文件或井文件不存在!在您运行之前,请选择井文件!");
return false;
}
if(Hd){
Hd->Dep=0;
Hd->Depo=0;
Hd->Rlev=0;
Hd->StartDep=0;
Hd->EndDep=0;
}
if(errorinf) {
errorinf->ErrorNo=0;
errorinf->ErrorStr[0]=0;
}
if(Con) *Con=*DefaultCon;
//初始化变量
validate();
//将输入曲线重定向后的名字给模块
if(Inc)strcpy(Inc->Name,GetRedirectInputCurveNames().c_str());
//将输出曲线重定向后的名字给模块
if(Outc)strcpy(Outc->Name,GetRedirectOutputCurveNames().c_str());
//TODO参数卡给模块
QString parmacard;
if(!parDialog) parmacard=GetINPParamCard(NULL,NULL,isSaveCard);
if(!isSaveCard)
{
}
m_pMemRdWt->SetStruct(Inc,Outc,Inp,Outp,Conc,Con,Hd,pLogType,errorinf);
strcpy(Hd->Param,paramCardNameInSlf.toStdString().c_str());
if(m_pMemRdWt->OpenStream(Hd->Param) < 0 ) // 参数卡片不存在
{
m_pMemRdWt->OpenCord(Hd->Param);
}
if(parmacard.size()){
char *buff=new char[parmacard.size()+10];
if(Zone)//sdep!=-99999&&edep!=-99999)
{
int n=parmacard.indexOf('\n');
if(n<0) n=parmacard.indexOf('\r');
if(n>0) {
char bu[100];
sprintf(bu,"%g %g\r\n",sdep,edep);
strcpy(buff,bu);
strcat(buff,parmacard.mid(n+1).toStdString().c_str());
}
}
else strcpy(buff,parmacard.toStdString().c_str());
m_pMemRdWt->SaveCord(Hd->Param,buff);
delete buff;
}
return true;
}
QString PELibraryModule::ReadParamCardFromSLF(CMemRdWt *pMemRdWt,char *pParamName)
{
if(!pMemRdWt) pMemRdWt=m_pMemRdWt;
if(!pParamName) pParamName=Hd->Param;
if(pMemRdWt&&pMemRdWt->mFile)
{
if( pMemRdWt->OpenStream(pParamName) < 0 ) // 参数卡片不存在
{
QString cs;
QStringList paramnames1=GetParamNames();
QStringList paramcnnames1=GetParamCNNames();
QStringList paramOptions1=GetNames(Conc->Options,';',false);
for(int i=0;i<paramnames1.size();i++)
{
paramnames1[i]=paramnames1[i].trimmed();
if(i<paramcnnames1.size()) paramcnnames1[i]=paramcnnames1[i].trimmed();
if(i<paramOptions1.size()) paramOptions1[i]=paramOptions1[i].trimmed();
}
QStringList paramnames;
QStringList paramcnnames;
QStringList paramOptions;
QString fun=QString::fromStdString(GetMetaData()->GetID());
int i=fun.indexOf("_");
if(i>-1) fun=fun.mid(i+1);
QString paramSettingFileName=QCoreApplication::applicationDirPath() + QDir::separator() +"app"+QDir::separator()
+fun+".config";
QFile file( paramSettingFileName );
if(!file.exists()) {
// AfxMessageBox(paramSettingFileName+"常用参数配置文件不存在!");
}
if (file.exists()&& file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString amoduleConfig;
int n = 1;
while ( !stream.atEnd() ) {
amoduleConfig = stream.readLine(); // 不包括“\n”的一行文本
amoduleConfig = amoduleConfig.trimmed();
if(amoduleConfig.isEmpty()) continue;
int pos=paramnames1.indexOf(amoduleConfig);
if(pos>-1) {
paramnames.append(amoduleConfig);
if(cs!="") cs+=",";
else cs="0 0\r\n";
cs+=amoduleConfig;
cs+="=";
char buf[1000];
sprintf(buf,"%g",Con->yy[pos]);
cs+=buf;
if(pos<paramcnnames1.size()) paramcnnames.append(paramcnnames1.at(pos));
if(pos<paramOptions1.size()) paramOptions.append(paramOptions1.at(pos));
}
}
file.close();
}
else {
cs+="0 0";
}
cs+="\r\nEND\r\n";
char *buf=new char[cs.size()+1];
strcpy(buf,cs.toStdString().c_str());
pMemRdWt->SaveCord(pParamName,buf);
delete buf;
return cs;
}
int index=pMemRdWt->OpenStream(pParamName);
if(index<0) return "";
int length=pMemRdWt->GetStreamLength(index);
int BytesRead=0;
char *buffer=new char[length+1];
pMemRdWt->ReadStream(index,length,(LPDWORD)&BytesRead,buffer);
QString cs=buffer;
delete buffer;
return cs;
}
return "";
}
QString PELibraryModule::CreateParamCardFromConfig()
{
QString cs;
QStringList paramnames1=GetParamNames();
QStringList paramcnnames1=GetParamCNNames();
QStringList paramOptions1;
if(Conc) paramOptions1=GetNames(Conc->Options,';',false);
for(int i=0;i<paramnames1.size();i++)
{
paramnames1[i]=paramnames1[i].trimmed();
if(i<paramcnnames1.size()) paramcnnames1[i]=paramcnnames1[i].trimmed();
if(i<paramOptions1.size()) paramOptions1[i]=paramOptions1[i].trimmed();
}
QStringList paramnames;
QStringList paramcnnames;
QStringList paramOptions;
QString fun=QString::fromStdString(GetMetaData()->GetID());
int i=fun.indexOf("_");
if(i>-1) fun=fun.mid(i+1);
QString paramSettingFileName=QCoreApplication::applicationDirPath() + QDir::separator() +"app"+QDir::separator()
+fun+".config";
QFile file( paramSettingFileName );
if (file.exists()&& file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
QString amoduleConfig;
int n = 1;
while ( !stream.atEnd() ) {
amoduleConfig = stream.readLine(); // 不包括“\n”的一行文本
amoduleConfig = amoduleConfig.trimmed();
if(amoduleConfig.isEmpty()) continue;
int pos=paramnames1.indexOf(amoduleConfig);
if(pos>-1) {
paramnames.append(amoduleConfig);
if(cs!="") cs+=",";
else cs="0 0\r\n";
cs+=amoduleConfig;
cs+="=";
char buf[1000];
sprintf(buf,"%g",Con->yy[pos]);
cs+=buf;
if(pos<paramcnnames1.size()) paramcnnames.append(paramcnnames1.at(pos));
if(pos<paramOptions1.size()) paramOptions.append(paramOptions1.at(pos));
}
}
file.close();
}
cs+="\r\nEND\r\n";
return cs;
}
QString PELibraryModule::GetINPCardName()
{
if(Hd) return Hd->Param;
else return "";
}
QString PELibraryModule::LoadINPParamCardFromSLF(CMemRdWt *pMemRdWt,char *pParamName)
{
QString result="";
if(!pMemRdWt) pMemRdWt=m_pMemRdWt;
if(!pParamName) pParamName=Hd->Param;
if(pMemRdWt&&Hd)
{
CObjWellLogINP * anINP=new CObjWellLogINP;
anINP->SetName(Hd->Param);
anINP->SetSlfFileName(GetSlfFileName());
anINP->isLoad=false;
if(anINP->LoadFromSLF()) result=anINP->paramcard;
if(result.isEmpty()) {
if(!pMemRdWt->mFile) {
QString a=GetSlfFileName();
if(pMemRdWt->Open(a.toStdString().c_str()))
{
int index=pMemRdWt->FindObjectName(pParamName);
if(index<0) {
pMemRdWt->SetStruct(Inc,Outc,Inp,Outp,Conc,Con,Hd,pLogType);
result=ReadParamCardFromSLF(pMemRdWt,pParamName);
}
else {
result=pMemRdWt->OpenCord(pParamName);
}
m_pMemRdWt->Close();
}
}
else {
result=ReadParamCardFromSLF(pMemRdWt,pParamName);
}
}
delete anINP;
}
return result;
}
void PELibraryModule::WriteHistory()
{
//如果该模块需要注册数据历史,请在这里实现该函数。否则留空!
}
CModule* PELibraryModule::Clone()
{
PELibraryModule* aPeModule=new PELibraryModule();
aPeModule->GetMetaData()->SetID(GetMetaData()->GetID());
aPeModule->GetMetaData()->SetName(GetMetaData()->GetName());
aPeModule->GetMetaData()->SetCategory(GetMetaData()->GetCategory());
aPeModule->strDLLFun=strDLLFun;
aPeModule->strPlot=strPlot;
aPeModule->paramCardNameInSlf=paramCardNameInSlf;
aPeModule->runBrunch=runBrunch;
aPeModule->SetLibraryfilename(m_libraryfilename);
aPeModule->OriginInNames=OriginInNames;
aPeModule->OriginOutNames=OriginOutNames;
return aPeModule;
}