#include "PELibraryModule.h" #include "MemRdWt.h" #include "ModuleParameter.h" // #include "ConsoleOutputWidget.h" #include #include #include "DepthProgress.h" #include #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 #include // 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-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;iScript,';',true); } float PELibraryModule::GetFloatParam(CModuleParameter * pModulePara,QString ¶mName,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=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<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")){ 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(clonedZone); if(cparam&&cparam->GetChildCount()<500) { int count=cparam->GetChildCount(); for(int i=0;iGetParameterItem(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(clonedZone); if(cparam&&cparam->GetChildCount()<500) { int count=cparam->GetChildCount(); for(int i=0;iGetParameterItem(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;iValType,';',false); for(int i=0;istryy; QStringList stryy=strYY.split(","); if(stryy.size()==1&&stryy[0]=="") stryy.clear(); int GroupCount=Groups.size(); if(GroupCount) { for(int j=0;ji) { 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;k1) { 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;i9||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(indexyy[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;ii) 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;k1) { 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;i9||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(indexyy[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:"<GetParameterItem("Zones")); if(Zones==NULL) return; int zonecount=Zones->GetChildCount(); if(zonecount<=0) { //创建第一个默认zone AddDefaultZone(Zones); } else { AddLastClonedZone(Zones); } stringstream ss; ss<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"<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;iGetInputType()==SPLIT) { int nn=val.toFloat(); QString str=aparm->GetInputMetaData().c_str(); QStringList strlst=str.split("/"); QString val1; for(int i=0;i9||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"<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;iNoi;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;iNoo;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;iScript,';',true); for(int i=0;iAddParameterItem(Zonesitem); return 1; } void PELibraryModule::refreshParamsByConfigFile(QStringList ¶mSetting) { 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 &sdeps,QVector&edeps,QVector&minVs,QVector &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(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 vecLeafItems; Zone->GetAllLeafParameterItems(vecLeafItems); int count=vecLeafItems.size(); for(int j=2;j-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=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 (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;iGetOutCurveName(i,name); Names.append(name); } m_pMemRdWt->Close(); // for(int i=0;i=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;jGetOutCurveName(j,name); Names.append(name); } m_pMemRdWt->Close(); // for(int j=0;j=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;inputindexGetParameterItem(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;outputindexGetParameterItem(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 childs; // pObj->GetChildren(childs); // foreach(PaiObject *pChild,childs) { // CObjWell *pWell=dynamic_cast(pChild); // if(pWell) { // int count=pWell->GetWellRoundCount(); // QListchs; // pWell->GetAllWellRound(chs); // for(int i=0;i(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(pModulePara->GetParameterItem("Zones")); if(!Zones) return ""; QStringList incnames=GetInPutCurveNames(); std::string innames=""; for(int inputindex=0;inputindexGetParameterItem(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;outputindexGetParameterItem(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&¶mGroups[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;jNoc-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(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-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-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;nWriteTable(iIndex,linenum+1,bufval); } stringstream stream; stream.str(""); stream << i; std::string strPartIndex = "Zones[" + stream.str() + "]"; CCompositeParameterItem * azone=dynamic_cast(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;jGetParameterItem(j); CCompositeParameterItem *pLeafs=dynamic_cast(pItem); if(pLeafs) { int nleaf=pLeafs->GetChildCount(); for(int k=0;kGetParameterItem(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;jjGetInputType()==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;nSetTableFieldData(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;nSetTableFieldData(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(rightx && j>left ) j--; } else { while(datx[i].length()>x && ileft ) 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(leftdocument(); 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;iValType,';',false); for(int i=0;iClose(); 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;iGetID()); 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(posSaveCord(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;iGetID()); 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(posParam; 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; }