logplus/common/geometryutils.cpp

1074 lines
27 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 <QPainter>
2025-10-29 17:23:30 +08:00
#include "LogIO.h"
#include "MemRdWt.h"
2025-10-29 17:23:30 +08:00
float mLineWidth=0.75;
2025-10-29 17:23:30 +08:00
QString OilField;
2026-02-05 14:53:44 +08:00
QString getUUid()
{
QUuid id = QUuid::createUuid();
QString strId = id.toString();
strId.replace("{", "");
strId.replace("}", "");
strId.replace("-", "");
//qDebug() << strId;
return strId;
}
2026-02-05 14:53:44 +08:00
double GetData(int RepCode, char *buffer)
{
double yy;
if (!buffer) return 0;
switch (RepCode)
{
case REPR_INT: //0
yy = (double)(*((int*)buffer));
break;
case REPR_SHORT: //1
yy = (double)(*((short *)buffer));
break;
case REPR_LONG://2
yy = (double)(*((long *)buffer));
break;
case REPR_FLOAT://3
yy = (double)(*((float *)buffer));
break;
case REPR_DOUBLE://4
yy = (double)(*((double *)buffer));
break;
case REPR_CHAR://5
yy = (double)(*((char *)buffer));
break;
case REPR_UCHAR://6
yy = (double)(*((unsigned char *)buffer));
break;
case REPR_USHORT://7
yy = (double)(*((unsigned short *)buffer));
break;
case REPR_UINT://8
yy = (double)(*((unsigned int *)buffer));
break;
case REPR_ULONG://9
yy = (double)(*((unsigned long *)buffer));
break;
case REPR_STRING://10
yy = -99999;
break;
}
return yy;
}
2025-10-29 17:23:30 +08:00
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/";
2025-10-29 17:23:30 +08:00
//
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/";
2025-10-29 17:23:30 +08:00
//
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 ;
}
2026-01-16 17:18:41 +08:00
QString GetTemplatePath()
{
QString strImagePath;
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
strImagePath = QDir::toNativeSeparators( strPathTmp );
return strPathTmp + "../template" + QDir::separator();
}
QString GetWorkflowTemplatePath()
{
QString strtemplatePath=GetTemplatePath();
return strtemplatePath+"/workflow"+QDir::separator();
}
2025-10-29 17:23:30 +08:00
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)
{
return CMemRdWt::getPrjAllSlf(prjname, vecSlfList, vecWellList);
2025-10-29 17:23:30 +08:00
}
int GetCurvInfo(QString strSlfName, QString strLineName, double &sdep, double &edep, double &rlev)
{
//初始化
sdep = 0;
edep = 0;
rlev = 0;
//
CLogIO *logio=new CLogIO();
logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead);
//
int index=logio->OpenCurve(strLineName.toStdString().c_str());
if(index<0) {
delete logio;
return -1;
}
Slf_CURVE curveinfo;
logio->GetCurveInfo(index,&curveinfo);
//
sdep=curveinfo.StartDepth;
edep=curveinfo.EndDepth;
rlev=curveinfo.DepLevel;
logio->CloseCurve(index);
delete logio;
return 1;
}
2026-02-03 14:40:58 +08:00
int GetCurvValue(QString strSlfName, QString strLineName, QList<double> new_DepthList, QList<double> &new_ValueList)
{
CLogIO *logio=new CLogIO();
logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead);
//
int index=logio->OpenCurve(strLineName.toStdString().c_str());
if(index<0) {
delete logio;
return -1;
}
float fValue=-9999;
for(int i=0; i<new_DepthList.size(); i++)
{
logio->ReadCurve(index, 0-new_DepthList[i], 1, &fValue);
new_ValueList.append(fValue);
}
//
logio->CloseCurve(index);
delete logio;
return 1;
}
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;
}
2026-03-13 17:34:02 +08:00
QString GetImageSymbolDir(QString cs)
{
return GetSymbolDir()+"岩心照片符号"+cs;
}
QString GetLithSymbolDir(QString cs)
{
return GetSymbolDir()+"岩性符号"+cs;
}
QString GetOilSymbolDir(QString cs)
{
return GetSymbolDir()+"解释结论符号"+cs;
}
int GetLineWidth(QPainter * painter,int flWidth)
{
float mScale=0.1;
// 线宽1=0.75磅
float temp;
// 1磅 = 1/72英寸
//if(painter->device()&&painter->device()->devType()==QInternal::Printer)
{
float dpi=painter->device()->logicalDpiX();
if(!dpi) dpi=painter->device()->physicalDpiX();
temp = flWidth*mLineWidth/72.*dpi;//GetZoomXRatio();
//0.75
}
/*else
{
temp=flWidth;
}
*/
if(flWidth==3&&abs(temp)<3) temp=3;
else if(flWidth==2&&abs(temp)<2) temp=2;
else if(abs(temp)<=1) temp=1;
return (int)temp;
}
QString GBKToUTF8(const QByteArray& gbkData) {
QTextCodec* gbkCodec = QTextCodec::codecForName("GBK");
if (!gbkCodec) {
return QString();
}
// 将GBK编码的字节转换为Unicode QString
QString unicodeStr = gbkCodec->toUnicode(gbkData);
return unicodeStr;
}
// UTF-8 转 GBK
QByteArray UTF8ToGBK(const QString& utf8Str) {
QTextCodec* gbkCodec = QTextCodec::codecForName("GBK");
if (!gbkCodec) {
return QByteArray();
}
// 将Unicode QString转换为GBK编码的字节
return gbkCodec->fromUnicode(utf8Str);
}
int extractNumbers(QString strExp, const QString& input) {
QRegularExpression re(strExp);
QRegularExpressionMatch match = re.match(input);
int number = -1;
if (match.hasMatch()) {
QString numberStr = match.captured(1); // 获取括号内匹配的内容
number = numberStr.toInt();
}
return number;
}