logplus/common/geometryutils.cpp

1039 lines
28 KiB
C++
Raw Normal View History

2025-10-29 17:23:30 +08:00
#include "geometryutils.h"
#include <QCoreApplication>
#include <QDir>
#include <QDate>
#include <QComboBox>
#include <QSettings>
#include <QTextCodec>
#include <QTextStream>
#include <QMessageBox>
#include "LogIO.h"
QString OilField;
QString setdec(QString text,int dec,bool all)
{
if(text.size()==0) return text;
QString cs=text,digla="+-.1234567890";
cs=cs.trimmed();
QStringList strs;
if(!all) {
for(int i=0;i<cs.size();i++) if(digla.indexOf(cs.at(i))<0) return text;
}
{
int s=0,e=0,n=0;
for(int i=0;i<cs.size();i++) {
if(digla.indexOf(cs.at(i))<0||(cs.at(i)=='+'||cs.at(i)=='-')&&i){
if(e) {
strs.append(cs.mid(s,e));
int j=strs.size()-1;
int dot=strs[j].indexOf(".");
if(dot<0) {
strs[j]+=".";
for(int i=0;i<dec;i++) strs[j]+="0";
}
else {
QStringList css=strs[j].split(".");
int len=css[1].size();
for(int i=len;i<2;i++)
{
css[1]+="0";
}
if(len>2) css[1]=css[1].remove(2,len-2);
strs[j]=css.join(".");
}
s=i;
e=0;
n=1;
}
else n++;
if(i==cs.size()-1)strs.append(cs.mid(s,n));;
}
else
{
if(n){
strs.append(cs.mid(s,n));
n=0;
}
if(!e) s=i;
e++;
if(i==cs.size()-1){
strs.append(cs.mid(s,e));
int j=strs.size()-1;
int dot=strs[j].indexOf(".");
if(dot<0) {
strs[j]+=".";
for(int i=0;i<dec;i++) strs[j]+="0";
}
else {
QStringList css=strs[j].split(".");
int len=css[1].size();
for(int i=len;i<2;i++)
{
css[1]+="0";
}
if(len>2) css[1]=css[1].remove(2,len-2);
strs[j]=css.join(".");
}
}
}
}
}
text=strs.join("");
return text;
}
QString GetProjectFolder()
{
// 1.获取当前运行程序的目录路径
QString applicationDirPath = QCoreApplication::applicationDirPath();
//获取上级目录
int index = applicationDirPath.lastIndexOf("/");
int index1 = applicationDirPath.lastIndexOf("\\");
if(index1 > index)
{
index = index1;
}
//
QString strProjectDir;
strProjectDir = applicationDirPath.mid(0,index+1) + "/project/";
//
QDir dir(strProjectDir);
if( !dir.exists( strProjectDir ) )
{
dir.mkdir(strProjectDir);
}
return strProjectDir ;
}
QString GetLogdataPath()
{
// 1.获取当前运行程序的目录路径
QString applicationDirPath = QCoreApplication::applicationDirPath();
//获取上级目录
int index = applicationDirPath.lastIndexOf("/");
int index1 = applicationDirPath.lastIndexOf("\\");
if(index1 > index)
{
index = index1;
}
//
QString strImagePath;
strImagePath = applicationDirPath.mid(0,index+1) + "/Logdata/";
//
QDir dir(strImagePath);
if( !dir.exists( strImagePath ) )
{
dir.mkdir(strImagePath);
}
return strImagePath;
}
void GetWellNameAndPath(QString slf,QString &wellname,QString &path)
{
QString slffilename=QString("");
int ind=slf.lastIndexOf('\\');
int ind2=slf.lastIndexOf('/');
if(ind2>ind) ind=ind2;
if(ind>-1) {
slffilename=slf.mid(ind+1);
path=slf.left(ind);
ind=slffilename.lastIndexOf('.');
if(ind>0) wellname=slffilename.left(ind);
}
}
int chakan(QString path, QStringList &wellfs, QString strSuffix)
{
QDir dir(path);
QFileInfoList fileInfos = dir.entryInfoList(QStringList() << strSuffix, QDir::Files);
foreach(QFileInfo fileInfo, fileInfos)
{
wellfs.append(fileInfo.absoluteFilePath());
}
return 1;
}
QString GetImagePath()
{
static QString imgpath;
if(imgpath!="") return imgpath;
QString strImagePath;
{
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
QDir dir;
if( dir.exists( strPathTmp + "image" ) )
{
return strPathTmp + "image" + QDir::separator();
}else
{
strImagePath = strImagePath+".."+ "/LogPlus/image/";
}
}
imgpath=strImagePath;
return imgpath;
}
QString GetDate(time_t mDate)
{
QString cs;
char buf[100]="";
if(!mDate||mDate==-1) {
QDate td=QDate::currentDate();
sprintf(buf,"%4d年-%02d月-%02d日",td.year(),td.month(),td.day());
}
else {
time_t tm1=mDate;
struct tm *_Tm=localtime(&tm1);
if(!_Tm) {
QDate td=QDate::currentDate();
sprintf(buf,"%4d年-%02d月-%02d日",td.year(),td.month(),td.day());
}
else sprintf(buf,"%4d年-%02d月-%02d日",_Tm->tm_year+1900,_Tm->tm_mon+1,_Tm->tm_mday);
}
cs=buf;
return cs;
}
QMap<QString,QString> GetZoneOrder(bool isOilFile,QWidget *pW)
{
return GetZoneOrder(QString("RESULT"),isOilFile,pW);
}
QMap<QString,QString> GetZoneOrder(QString table,bool isOilFile,QWidget *pW)
{
QMap<QString,QString> zoneOrder;
//层序号根据层位名来配置文件在conf\\RESULT.txt
//初始化ZoneOrder
QString oilfield=GetOilFieldName();
QString configfile=GetConfPath();
if(isOilFile) configfile+=oilfield;
configfile+=table;
QDir ss1;
if(!ss1.exists(configfile))
{
if(!ss1.exists(configfile+".txt")) {
configfile+=".ini";
}
else configfile+=".txt";
}
QStringList lines;
QFile file( configfile );
if ( file.open( QIODevice::ReadOnly ) ) {
QTextStream stream( &file );
stream.setCodec("UTF-8"); // 设置UTF-8编码
2025-10-29 17:23:30 +08:00
QString line;
while ( !stream.atEnd() ) {
line = stream.readLine(); // 不包括“\n”的一行文本
lines += line;
}
file.close();
}
lines.removeAll("");
QStringList aaa;
for(int i=0;i<lines.size();i++){
if(aaa.indexOf(lines[i])<0)
{
aaa.append(lines[i]);
}
else {
QString ss=configfile+"\"";
ss+=lines[i];
ss+="\"符号重复!";
if(pW) QMessageBox::about(pW,"提示",ss);
}
if(lines[i].indexOf(" ")>-1)
{
QStringList strs=lines[i].split(" ");
zoneOrder.insert(strs[0],strs[1]);
}
else zoneOrder.insert(lines[i],QString::number(i+1));
}
return zoneOrder;
}
QString toString(QString cs)
{
int index=cs.indexOf(".");
if(index>=0) {
QStringList css=cs.split('e');
if(css.size()==1) {
if(cs.size()>1)
{
if(cs.indexOf("-",1)>-1) return cs;
}
}
if(css.size()>1) {
cs=css[0];
}
int len=cs.length();
int j=0;
for(int i=len-1;i>=index;i--) {
if(cs.at(i)=='0') j++;
else {
if(cs.at(i)=='.') j++;
break;
}
}
cs=cs.left(len-j);
if(css.size()>1) {
css[0]=cs;
cs=css.join("e");
}
}
return cs;
}
QString toString(int value,char f,int dem,bool iscut,bool ise)
{
if(ise&&(fabsf(value)>=1e4||(fabsf(value)<=1e-4&&value!=0))){
QString V=QString::number(value,'e',6);
V=toString(V);
return V;
}
QString cs=QString::number(value);
if(iscut) return toString(cs);
else return cs;
}
QString toString(float value,char f,int dem,bool iscut,bool ise)
{
if(ise&&(fabsf(value)>=1e4||(fabsf(value)<=1e-4&&value!=0))){
QString V=QString::number(value,'e',6);
V=toString(V);
return V;
}
QString cs="%";
char buf[100],format[100];
sprintf(format,"10.%d%c",dem,f);
cs+=format;
sprintf(buf,cs.toStdString().c_str(),value);
cs=buf;
cs=cs.trimmed();
if(iscut) return toString(cs);
else return cs;
}
QString toString(double value,char f,int dem,bool iscut,bool ise)
{
if(ise&&(fabsf(value)>=1e4||(fabsf(value)<=1e-4&&value!=0))){
QString V=QString::number(value,'e',6);
V=toString(V);
return V;
}
QString cs="%";
char buf[100],format[100];
sprintf(format,"10.%d%c",dem,f);
cs+=format;
cs=cs.trimmed();
sprintf(buf,cs.toStdString().c_str(),value);
cs=buf;
cs=cs.trimmed();
if(iscut) return toString(cs);
else return cs;
}
QStringList GetSimilarCurves(QString curvename,char *INI,bool isEqu)
{
QStringList vars,temps;
QString path=GetConfPath();
if(INI) {
QDir ss(INI);
if(ss.exists(INI)) path=INI;
else path+=INI;
}
else path+="StringName.ini";
QFile file(path);
if (!file.open(QIODevice::ReadOnly))
return vars;
QTextStream textstream(&file );
curvename=curvename.trimmed();
char Left[200];
int len=strlen(curvename.toStdString().c_str());
int len1=0,len2=0;
while (!textstream.atEnd())
{
QString va = textstream.readLine(1000);
if(va.indexOf("#")>-1) continue;
va=va.trimmed();
vars=va.split("=");
if(vars.size()>1) {
vars[0]=vars[0].trimmed();
if(vars[0].isEmpty()) continue;
strcpy(Left,curvename.toStdString().c_str());
if(!isEqu) {
len1=strlen(vars[0].toStdString().c_str());
if(curvename.indexOf(vars[0])>=0) {
if(len1>len2) {
strncpy(Left,curvename.toStdString().c_str(),len1);
Left[len1]=0;
len2=len1;
}
}
}
if(vars[0]==Left) {
va=vars[1];
if(va.indexOf("color(",0,Qt::CaseInsensitive)>-1) {
va.replace("COLOR","",Qt::CaseInsensitive);
va.replace("(","");
va.replace(")","");
}
// va.replace(" ","");
va.trimmed();
vars=va.split(",");
if(isEqu) return vars;
else temps=vars;
}
}
}
if(temps.size()) {
if(!isEqu) {
int i=temps[0].indexOf(" ");
if(i>-1) temps[0]=temps[0].replace(temps[0].left(i),curvename);
}
return temps;
}
vars.clear();
return vars;
}
//whp add 2020.3.14 for 检查井名合理性
bool IsValidWellName(QString wellname)
{
int nCount = wellname.count();
if(nCount<=0)return 0;
bool IsValidWellName=1;
for(int i = 0 ; i < nCount ; i++)
{
QChar cha = wellname.at(i);
ushort uni = cha.unicode();
if(i==0)
{//首字符必须是字母或汉字
if(cha>='0'&&cha<='9'||cha>=65&&cha<=90||cha>=97&&cha<=122||(uni >= 0x4E00 && uni <= 0x9FA5))continue;
else
{
IsValidWellName=0;break;
}
}
if(cha>=48&&cha<=57||cha>=65&&cha<=90||cha>=97&&cha<=122||cha==45||cha==46||cha==95)continue;
if(uni >= 0x4E00 && uni <= 0x9FA5)continue;
IsValidWellName=0;
break;
}
return IsValidWellName;
}
bool IsValidNmae(QString wellname)
{
int nCount = wellname.count();
if(nCount<=0)return 0;
bool IsValidWellName=1;
QString value="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789#_-*αβγδεζηθικλμνξοπρστυφχψ.";
for(int i = 0 ; i < nCount ; i++)
{
QChar cha = wellname.at(i);
ushort uni = cha.unicode();
if(i==0)
{//首字符必须是字母或汉字
if(value.indexOf(cha)>=0||(uni >= 0x4E00 && uni <= 0x9FA5)) continue;
}
else {
if(value.indexOf(cha)>=0||(uni >= 0x4E00 && uni <= 0x9FA5)) continue;
}
return false;
}
return true;
}
bool IsInvalidString(QString filename)
{
QStringList strs=GetSimilarCurves("InvalidFile");
bool isInvalid=false;
QString wellname;
int i=filename.lastIndexOf('\\');
int i0=filename.lastIndexOf('/');
if(i0>i) {
wellname=filename.mid(i0+1);
}
else {
wellname=filename.mid(i+1);
}
foreach(QString cname,strs) {
if(cname.size()&&(cname.at(0)=='.')||cname.indexOf('*')>-1) {
if(cname.indexOf('*')>-1) {
int i=cname.indexOf('*');
if(i>0) cname=cname.left(i);
else if(i==0) cname=cname.mid(i+1);
}
if(wellname.indexOf(cname)>-1) {
isInvalid=true;
break;
}
}
else if(wellname.compare(cname,Qt::CaseInsensitive)==0) {
isInvalid=true;
break;
}
}
return isInvalid;
}
QStatusBar* GetStatusBar()
{
static QStatusBar * pStatusBar = new QStatusBar;
return static_cast<QStatusBar*>(pStatusBar);
}
QString GetOutDataPath()
{
QString strProjectDir = QCoreApplication::applicationDirPath()+ QDir::separator() + "../Outdata";
QDir dir(strProjectDir);
if( !dir.exists( strProjectDir ) )
{
dir.mkdir(strProjectDir);
}
strProjectDir += QDir::separator();
return strProjectDir ;
}
QString ReadOilFieldName()
{
QString path=GetLogPlusPath();
path+="oilfield.ini";
FILE *fp=fopen(path.toStdString().c_str(),"rt");
char oilfield[200];
oilfield[0]=0;
if(fp) {
fscanf(fp,"%s\n",oilfield);
fclose(fp);
}
OilField=oilfield;
return OilField;
}
QString GetOilFieldName(QString c)
{
if(OilField.isEmpty())
{
ReadOilFieldName();
}
QString cs=OilField;
if(!cs.isEmpty()) return cs+c;
else return cs;
}
QString GetLogPlusPath()
{
QString strProjectDir = QCoreApplication::applicationDirPath()+ QDir::separator() + "..";
strProjectDir += QDir::separator();
return strProjectDir ;
}
QString GetConfPath()
{
QString strConfPath;
{
QString strPathTmp = QCoreApplication::applicationDirPath()+ QDir::separator() ;
strConfPath = QDir::toNativeSeparators( strPathTmp );
return strPathTmp + "conf" + QDir::separator();
}
return strConfPath;
}
bool RenameWellName(QString filename, QString strNewName)
{
QString path,wellname;
GetWellNameAndPath(filename,wellname,path);
QFileInfo f(filename);
QDir ss;
QString newname=path;
newname+="/"+strNewName+"."+f.suffix();
if(ss.rename(filename,newname)) {//.WELL文件改名
return true;
}
return false;
}
void ComboxFromConfigFile( QComboBox *aCombox ,QString configCategory)
{
if(aCombox==NULL) return;
if(configCategory=="") return;
static QString temp = ::GetConfPath()+"data.ini";
QSettings settings(temp,QSettings::IniFormat,0);
settings.setIniCodec(QTextCodec::codecForName("UTF-8"));
QStringList serials=settings.value(configCategory,0).toStringList();
aCombox->clear();
aCombox->addItems(serials);
}
2025-10-30 09:50:15 +08:00
QString GetDataPath()
{
static QString imgpath;
if(imgpath!="") return imgpath;
QString strImagePath;
{
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
QDir dir;
return strPathTmp + ".."+QDir::separator()+"Data" + QDir::separator();
}
imgpath=strImagePath;
return imgpath;
}
2025-10-29 17:23:30 +08:00
// get Decimal,such as "6.0003000040000" return "9"
unsigned short GetDecimal( double dValue )
{
unsigned short nMaxDecimal = 20;
double Zero = pow( 10.0,-nMaxDecimal );
for( unsigned short i = 0 ; i < nMaxDecimal ; ++i )
{
double dValueTmp = dValue * pow( 10.0 ,i );
qint64 nValueTmp = static_cast<qint64 >( qint64(dValueTmp ) );
if( fabs( dValueTmp - nValueTmp ) < Zero )
{
return i;
}
}
return 2;
}
QString DoubleToString(double dValue, int nDecimal,int *pReallyDecimal)
{
if( nDecimal < 0 )
{
nDecimal = GetDecimal( dValue );
}
QString str;
str.setNum( dValue , 'a' , nDecimal );
if( nDecimal>0 && !str.isEmpty() )
{
int iPos(0);
for( iPos = str.length()-1 ; iPos>=0 ; --iPos )
{
if( str[iPos] != '0' )
{
break;
}
--nDecimal;
}
if( str[iPos] =='.' ) --iPos;
str.truncate( iPos +1 );
}
if( pReallyDecimal )
{
*pReallyDecimal = qMax(0,nDecimal );
}
return str;
}
bool SystemIsExiting=false;
void SetSystemExisting(bool exiting)
{
SystemIsExiting=exiting;
}
bool SystemExiting(){return SystemIsExiting;}
//直方图获取当前工程下的slf
bool getAllSlf(QString prjname, QVector<QString> &vecSlfList, QVector<QString> &vecWellList)
{
//Logdata
QString folderPath;
folderPath = GetLogdataPath();
folderPath = folderPath + prjname;
folderPath = folderPath + "/";
//-------------------
QStringList listFolders;
QFileInfo mfi(folderPath);
if(!mfi.isDir())
{
//井文件 *.wwl
if(!mfi.isFile())
{
return false;
}
//listFiles.append(folderPath);
}
else
{
//井目录
//取当前当前目录内容
QDir dir(folderPath);
dir.setFilter(QDir::Dirs |QDir::NoDotAndDotDot |QDir::Files | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
int file_count = list.count();
if(file_count <= 0)//判断目录是否为空,空目录返回
{
return false;
}
//取当前目录内容,符合后缀文件
QStringList string_list;
for(int i=0; i<list.size();i++)
{
QFileInfo file_info = list.at(i);
if(file_info.isDir())
{
//#JPH-307
QString absolute_file_path = file_info.absoluteFilePath();
if(absolute_file_path.at(absolute_file_path.length()-1)==' ') {
dir.rmdir(absolute_file_path);
continue;
}
listFolders.append(absolute_file_path);
}
}
}
QStringList wellfiles;
foreach(QString wellFolder, listFolders )
{
QFileInfo w(wellFolder);//#JPH-307
if(w.isDir())
{
chakan(wellFolder, wellfiles, "*.well");
}
}
QStringList wellNames;
foreach(QString wellFile1, wellfiles )
{
QString filename=wellFile1;
//----------------
CLogIO * logio=new CLogIO();
if(!logio->Open(filename.toStdString().c_str(),CSlfIO::modeRead))
{
delete logio;
QString aa=filename+"文件打开失败,请检查!";
//qDebug() << aa;
//AppendConsole(pai::log::PAI_ERROR,aa);
continue;
}
//
QString wellname="";
Slf_FILE_MESSAGE mssage;
logio->GetFileMessage(mssage);
wellname=mssage.WellName;
wellname=wellname.toUpper();
if (wellname.isEmpty()||wellname.length()>64||wellname.indexOf('&')>-1)
{
//辨别井名是否有效,无效则采用文件名
QFileInfo fileInfo(filename);
QString strWellName = fileInfo.completeBaseName();
strWellName=strWellName.toUpper();
//
wellname=strWellName.toStdString().c_str();
int len=strlen(strWellName.toStdString().c_str());
if(len>sizeof(mssage.WellName)) len=sizeof(mssage.WellName);
strncpy(mssage.WellName,strWellName.toStdString().c_str(),len);
mssage.WellName[len]=0;
logio->SetFileMessage(mssage);
}
wellname=wellname.toUpper();
//查找是否已经存在该井和井次
if(wellNames.contains(wellname))
{
delete logio;
continue;
}
wellNames.append(wellname);
//
vecWellList.append(wellname);
//加载*.slf
QStringList slffiles;
QString pathTmp=GetLogdataPath();
pathTmp+=prjname+"/#"+wellname;
chakan(pathTmp, slffiles, "*.slf");
foreach(QString slfFile1, slffiles )
{
CLogIO * logioSLf=new CLogIO();
if(!logioSLf->Open(slfFile1.toStdString().c_str(),CSlfIO::modeRead))
{
delete logioSLf;
//QString aa=fileFull+"文件打开失败,请检查!";
//qDebug() << aa;
//AppendConsole(pai::log::PAI_ERROR,aa);
continue;
}
else
{
Slf_FILE_MESSAGE mssageSlf;
logioSLf->GetFileMessage(mssageSlf);
if(wellname != QString(mssageSlf.WellName))
{
delete logioSLf;
continue;
}
QString wellnameSLf=mssageSlf.Item;
if (wellnameSLf.isEmpty()||wellnameSLf.length()>64||wellnameSLf.indexOf('&')>-1)
{
QFileInfo fileinfo;
fileinfo = QFileInfo(slfFile1);
wellnameSLf = fileinfo.completeBaseName();
}
if(wellnameSLf != wellname)
{
//井次名称不一致
//qDebug() << "井次名称不一致";
delete logioSLf;
continue;
}
vecSlfList.append(slfFile1);
delete logioSLf;
}
}
}
return true;
}
bool getAliasNameFromIni(QString CurveName, QString &strAliasName, QString &strUnit)
{
QString curveFamilyFilePath = ::GetConfPath() + "CurveFamily_New.ini";
QFile curveFamilyFile(curveFamilyFilePath);
if(!curveFamilyFile.open(QIODevice::ReadOnly | QIODevice::Text)) return false;
bool finished = false;
while(!curveFamilyFile.atEnd())
{
QByteArray line = curveFamilyFile.readLine();
QString str(line);
QStringList strList = str.split("=");
if(strList[0] == CurveName && strList.size()>1)
{
QStringList strListSub = strList[1].split(",");
if(strListSub.size()>3)
{
strAliasName = strListSub[0]; //显示名
strUnit = strListSub[3]; //单位
}
// float minValue = strList[1].toFloat();
// float maxValue = strList[2].toFloat();
// if(minValue < -9999 || minValue > 9999) return false;
// if(maxValue < -9999 || maxValue > 9999) return false;
// if(maxValue <= minValue) return false;
finished = true;
break;
}
}
curveFamilyFile.close();
return finished;
}
int getSystemColorNumber(QStringList &names)
{
QString strImagePath;
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg";
FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt");
if(!fp1) return -1;
char buf[100];
QString str;
int i=0;
while(!feof(fp1)) {
fscanf(fp1,"%s",buf);
str=buf;
//读取全部
//if(str.indexOf("custom",Qt::CaseInsensitive)>=0) continue;
names.push_back(str);
i++;
}
fclose(fp1);
return i;
}
int getSystemColor(int nIndex,QVector<MyColorItem> &colorList,bool inpolation)
{
colorList.clear();
MyColorItem itemColor;
QString strImagePath;
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg";
FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt");
if(!fp1) return -1;
char buf[100];
QString str;
int i=0;
while(!feof(fp1)) {
fscanf(fp1,"%s",buf);
if(i>=nIndex) {
str=buf;
break;
}
i++;
}
fclose(fp1);
if(str.isEmpty()) return -1;
QString filename=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+str;
FILE *fp=fopen(filename.toStdString().c_str(),"rt");
if(!fp) return -1;
float r,g,b;
QStringList strs;
int colornum=0;
while(!feof(fp)) {
char *ret=fgets(buf,100,fp);
if(!ret) break;
str=buf;
str.replace("\r","");
str.replace("\n","");
str.replace("\t"," ");
if(str.indexOf("#")>-1) continue;
if(str.indexOf("=")>-1) continue;
if(str.indexOf("R",Qt::CaseInsensitive)>-1) continue;
if(str.indexOf("G",Qt::CaseInsensitive)>-1) continue;
if(str.indexOf("B",Qt::CaseInsensitive)>-1) continue;
strs=str.split(" ");
strs.removeAll("");
if(strs.size()!=3) continue;
r=strs[0].toFloat();
g=strs[1].toFloat();
b=strs[2].toFloat();
if(g<=1||b<=1) if(r>0&&r<=1) r*=255;
if(r<=1||b<=1) if(g>0&&g<=1) g*=255;
if(r<=1||g<=1) if(b>0&&b<=1) b*=255;
int rr=r,gg=g,bb=b;
colorList.push_back(MyColorItem(QColor(rr,gg,bb)));
colornum++;
}
fclose(fp);
if(colornum<PAITOTALCOLOR_MIN) colornum=PAITOTALCOLOR_MIN; // 最小总颜色数目
if(colornum>PAITOTALCOLOR_MAX) colornum=PAITOTALCOLOR_MAX; // 最大总颜色数目
if(inpolation)
{
colorList=myInpolation(colorList,colornum);//SYSTEM_INPOLATION);
}
return colorList.count();
}
QVector<MyColorItem> myInpolation(const QVector<MyColorItem> &colorList,int totalColorNum)
{
QVector<MyColorItem> newColorList;
// 填充新的颜色项目
for(int i=0;i<totalColorNum;i++)
newColorList.push_back(MyColorItem());
float gap=(colorList.count()-1)*1.0/(totalColorNum-1);
for(int i=0;i<totalColorNum;i++)
{
float pos=i*gap;
int index1=pos;
if(::fabs(pos-index1)<1.0e-10)
{
newColorList[i]=colorList[index1];
}
else
{
int index2=index1+1;
if(index2>=colorList.size()) index2=colorList.size()-1;
float flgap1=pos-index1;
float flgap2=index2-pos;
int r=colorList[index1].color.red()*flgap2+colorList[index2].color.red()*flgap1;
int g=colorList[index1].color.green()*flgap2+colorList[index2].color.green()*flgap1;
int b=colorList[index1].color.blue()*flgap2+colorList[index2].color.blue()*flgap1;
newColorList[i]=MyColorItem(QColor(r,g,b));
}
}
return newColorList;
}
// 读取定制的颜色方案
void ReadColorSettings(QList<SchemeColor> &shcemeLis)
{
MyColorItem itemColor;
QString strImagePath;
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
QString filecfg=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+"colortable.cfg";
FILE *fp1=fopen(filecfg.toStdString().c_str(),"rt");
if(!fp1) return;
char buf[100];
QString str,name;
int i=0;
while(!feof(fp1)) {
fscanf(fp1,"%s",buf);
name=buf;
if(name.indexOf("custom",Qt::CaseInsensitive)>=0) {
QString filename=strImagePath+"image"+QDir::separator()+"colortable"+QDir::separator()+name;
FILE *fp=fopen(filename.toStdString().c_str(),"rt");
if(!fp) return;
QVector<MyColorItem> colorList;
float r,g,b;
QStringList strs;
while(!feof(fp)) {
char *ret=fgets(buf,100,fp);
if(!ret) break;
str=buf;
str.replace("\r","");
str.replace("\n","");
if(str.indexOf("#")>-1) continue;
if(str.indexOf("=")>-1) continue;
if(str.indexOf("R",Qt::CaseInsensitive)>-1) continue;
if(str.indexOf("G",Qt::CaseInsensitive)>-1) continue;
if(str.indexOf("B",Qt::CaseInsensitive)>-1) continue;
strs=str.split(" ");
strs.removeAll("");
if(strs.size()!=3) continue;
r=strs[0].toFloat();
g=strs[1].toFloat();
b=strs[2].toFloat();
if((r>0&&r<=1)||(g>0&&g<=1)||(b>0&&b<=1)) {
r*=255;
g*=255;
b*=255;
}
int rr=r,gg=g,bb=b;
colorList.push_back(MyColorItem(QColor(rr,gg,bb)));
}
fclose(fp);
SchemeColor schemeItem;
name=name.mid(name.lastIndexOf("\\")+1);
if(name.lastIndexOf(".rgb",-1,Qt::CaseInsensitive)>-1)name=name.mid(0,name.lastIndexOf(".rgb",-1,Qt::CaseInsensitive));
schemeItem.schemeName=name;
schemeItem.colorList=colorList;
schemeItem.isDirty=false;
schemeItem.isCustom=true;
schemeItem.currentIndex=0;
shcemeLis.push_back(schemeItem);
}
}
fclose(fp1);
return;
}
QString GetSymbolDir(QString cs)
{
return GetImagePath()+GetOilFieldName("")+"符号库"+cs;
}
QString GetMudSymbolDir(QString cs)
{
return GetSymbolDir()+"录井岩性符号"+cs;
}
QString GetColorSymbolDir(QString cs)
{
return GetSymbolDir()+"颜色符号"+cs;
}
QString GetGasSymbolDir(QString cs)
{
return GetSymbolDir()+"油气符号"+cs;
}
QString GetGujingSymbolDir(QString cs)
{
return GetSymbolDir()+"固井结论符号"+cs;
}
QString GetLithSymbolDir(QString cs)
{
return GetSymbolDir()+"岩性符号"+cs;
}
QString GetOilSymbolDir(QString cs)
{
return GetSymbolDir()+"解释结论符号"+cs;
}