logplus/logPlus/PickFrac.cpp
2026-01-06 16:03:55 +08:00

249 lines
7.6 KiB
C++

#include <math.h>
#include <cassert>
#include <QApplication>
#include <QDebug>
#include "MemRdWt.h"
#include "PickFrac.h"
#include "geometryutils.h"
CPickFrac::CPickFrac(QMyCustomPlot *myCustomPlot, QString strSlfName, QString csCurve, int iMyWidth)
{
m_myCustomPlot = myCustomPlot;
m_iMyWidth = iMyWidth;
m_Name="Frac_Hole.Table";
m_strDevi = "DEVI";
m_strHazi = "HAZI";
ReadFracDef();
for (int i = 0 ; i < iFracType ; i++)
{
m_bTypeDraw[i] = true;
}
//支持框选------------------
//myCustomPlot->m_bDrawCore_PHYSICS = true;
ReadData(strSlfName, csCurve);
// myCustomPlot->setSelectionRectMode(QCP::SelectionRectMode::srmSelect);
// myCustomPlot->graph(0)->setSelectable(QCP::SelectionType::stMultipleDataRanges);// stSingleData
// myCustomPlot->setInteractions(QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iMultiSelect); // 轴、图例、图表可以被选择,并且是多选的方式
}
CPickFrac::~CPickFrac(void)
{
m_FracDef.clear();
}
void CPickFrac::ReadFracDef()
{
m_FracDef.clear();
QString fracFilePath = GetConfPath() + "FRAC.CFG";
//
FRAC_DEF_Crack fd;
char str[512],name[512];
int r,g,b,id;
FILE *fp;
QString qs;
fp = fopen(fracFilePath.toStdString().c_str(),"r");
if ( fp != nullptr )
{
fgets(str,256,fp); // 跳过第一行
while (!feof(fp))
{
fgets(str,256,fp);
qs = str;
qs.trimmed();
if (qs.length() < 8) break ;
//代码 名称 形状代码(1:正弦曲线 2:连线 3:封闭区域) 颜色(红 绿 蓝) 线宽度
sscanf(str,"%d %s %d %d %d %d %d",&fd.iCode,name,&fd.iType,&r,&g,&b,&fd.nLineWidth);
fd.crColor = QColor(r,g,b);//RGB(r,g,b);
fd.csName = name;
fd.csName = fd.csName.trimmed();//.Trim();
fd.bDraw = 0;
m_FracDef.append(fd);
if ( feof(fp))
break;
}
fclose(fp);
}
else
{
sprintf(name,"打开裂缝参数配置文件错误:%s!",str);
QMessageBox::information(nullptr, "读取文件失败", name);
}
}
void CPickFrac::ReadData(QString strSlfName, QString csCurve)
{
if(strSlfName.isEmpty()) return;
if(csCurve=="AC"||csCurve=="")
{
csCurve="Frac_Hole.Table";
}
QString cs;
int nLineWidth=2;
int nField;
QColor crColor(255,0,0);
FRAC_TABLE_Crack frac;
FRAC_TABLE_OLD_Crack fracold;
CMemRdWt mrw;
char strFracTable[256];
int i,j,iIndex,nCount,iType=1;
if (mrw.Open(strSlfName.toStdString().c_str()) ) // 打开井文件
{
QString name(csCurve);
iIndex=mrw.OpenTable(name.toStdString().c_str());
if(iIndex>=0)
{
nField=mrw.GetTableFieldCount(iIndex);
nCount=mrw.GetTableRecordCount(iIndex);
cs ="";
for(i=0;i<nCount;i++)
{
if ( nField == 7 ) //老的裂缝表
{
mrw.ReadTable(iIndex,i+1,(void*)&fracold);
frac.AorX = fracold.AorX;
frac.DEP = fracold.DEP;
frac.DIPorS = fracold.DIPorS;
frac.DIR = fracold.DIR;
frac.W = fracold.W;
frac.ID = fracold.ID;
frac.XETAorH = fracold.XETAorH;
frac.NUM = 0;
for (j=0; j<16; j++)
frac.point[j].x = frac.point[j].y = 0;
}
else{
// 扩充后的裂缝表
mrw.ReadTable(iIndex,i+1,(void*)&frac);
}
for (j=0; j<m_FracDef.count(); j++)
{
if ( m_FracDef[j].iCode == frac.ID )
{
cs = m_FracDef[j].csName;
iType = m_FracDef[j].iType;
nLineWidth = m_FracDef[j].nLineWidth;
crColor = m_FracDef[j].crColor;
//
drawOne(frac, cs, iType, nLineWidth, crColor);
break;
}
}
}
mrw.CloseTable(iIndex);
}
mrw.Close(); //关闭井文件
}
}
//
void CPickFrac::drawOne(FRAC_TABLE_Crack frac, QString cs, int iType, int nLineWidth, QColor crColor)
{
int j,nPoint=360;
float x,y,h,oy;
float PI,xScale,xx;
PI=2.*3.14159265/(float)nPoint;
h = frac.AorX/2.0;
oy = -(frac.DEP+h);
xScale=(float)(nPoint)/(float)(m_iMyWidth);
QPen pPen(crColor, nLineWidth);
QVector<double> xVec, yVec;
switch ( iType )
{
case 1: //正弦曲线
nPoint = 360;
for(j=0; j<nPoint; j++)
{
x=(float)(j)/xScale;
float tempValue = oy - (float)(h)*cos((j-frac.XETAorH)*PI);
y=tempValue;//m_myCustomPlot->xAxis->coordToPixel(tempValue)
xVec.append(x);
yVec.append(y);
}
// for(j=0; j<nPoint-1; j++)
// {
// QCPItemLine *qcpItemLine = new QCPItemLine(m_myCustomPlot);
// qcpItemLine->start->setCoords(yVec[j], xVec[j]);
// qcpItemLine->end->setCoords(yVec[j+1], xVec[j+1]);
// qcpItemLine->setPen(pPen);
// }
{
//
m_myCustomPlot->addGraph();
QString strLineName = "";
if(strLineName=="")
{
strLineName = QString("曲线 %1").arg(m_myCustomPlot->graphCount());
}
m_myCustomPlot->graph()->setName(strLineName);
m_myCustomPlot->graph()->setData(xVec, yVec);
m_myCustomPlot->graph()->setLineStyle((QCPGraph::LineStyle)(QCPGraph::lsLine));//lsNone 曲线 lsLine
m_myCustomPlot->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(QCPScatterStyle::ssDot)));//ssNone点ssDot
//
QPen graphPen;
graphPen.setColor(crColor);
graphPen.setWidthF(nLineWidth);
graphPen.setStyle(Qt::SolidLine);//实线
m_myCustomPlot->graph()->setPen(graphPen);
}
break;
case 2: //连线
nPoint = frac.NUM;
for(j=0; j<nPoint-1; j++)
{
QCPItemLine *qcpItemLine = new QCPItemLine(m_myCustomPlot);
qcpItemLine->start->setCoords(frac.point[j].x, -frac.point[j].y);
qcpItemLine->end->setCoords(frac.point[j+1].x, -frac.point[j+1].y);
qcpItemLine->setPen(pPen);
j++;//j+2
}
break;
case 3: // 封闭区域
nPoint = frac.NUM;
for(j=0; j<nPoint; j++)
{
QCPItemLine *qcpItemLine = new QCPItemLine(m_myCustomPlot);
qcpItemLine->start->setCoords(frac.point[j].x, -frac.point[j].y);
if(j>=(nPoint-1))
{
qcpItemLine->end->setCoords(frac.point[0].x, -frac.point[0].y);
}
else
{
qcpItemLine->end->setCoords(frac.point[j+1].x, -frac.point[j+1].y);
}
qcpItemLine->setPen(pPen);
}
break;
case 4: //直线
nPoint = frac.NUM;
if(nPoint>=2)
{
QCPItemStraightLine *qcpItemLine = new QCPItemStraightLine(m_myCustomPlot);
qcpItemLine->point1->setCoords(frac.point[0].x, -frac.point[0].y);//位置
qcpItemLine->point2->setCoords(frac.point[1].x, -frac.point[1].y);//位置
qcpItemLine->setPen(pPen);
}
break;
}
}