#include #include #include #include #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 xVec, yVec; switch ( iType ) { case 1: //正弦曲线 nPoint = 360; for(j=0; jxAxis->coordToPixel(tempValue) xVec.append(x); yVec.append(y); } // for(j=0; jstart->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; jstart->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; jstart->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; } }