logplus/logPlus/formdraw.cpp

1635 lines
54 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "formdraw.h"
#include "ui_formdraw.h"
#include "CallManage.h"
#include <QDebug>
#include "geometryutils.h"
#include "ConsoleOutputWidget.h"
#include "DraggablePixmap.h"
#include "TransparentDraggableRect.h"
//以下参数从配置文件读取
extern int g_iIndex;
extern int g_iNum;
extern int g_iOneWidth; //道宽
extern int g_iHeadHigh; //道头高度
extern int g_iTitleHigh; //道对象高度
extern int g_iCurveHigh;//曲线高度
extern int g_iMove; //道头偏移
extern int g_iPointNum; // number of points in graph
extern int g_iLineNum; // number of Line
extern int g_iWidth; //道宽
//
extern int g_iX1;
extern int g_iX2;
extern int g_iY1;
extern int g_iY2;
extern int g_iCanZoom ;
//
extern double g_dPixelPerCm;//每厘米像素数
extern int g_iScale;
extern void AppendConsole(Priority priority, const QString &output);
//曲线绘制(多个)
FormDraw::FormDraw(QWidget *parent, QString strWellName, QString strTrackName) :
QWidget(parent),
ui(new Ui::FormDraw)
{
ui->setupUi(this);
setAcceptDrops(true);
m_strWellName = strWellName;
m_strTrackName = strTrackName;
connect(CallManage::getInstance(), SIGNAL(sig_AddLine(QString, QString, QString, QString, QString)), this, SLOT(s_addLine(QString, QString, QString, QString, QString)));
connect(CallManage::getInstance(), SIGNAL(sig_AddLine_Property(QString, QString, QString, QString, QString, double, double, QString, QColor, double, Qt::PenStyle)),
this, SLOT(s_AddLine_Property(QString, QString, QString, QString, QString, double, double, QString, QColor, double, Qt::PenStyle)));
connect(CallManage::getInstance(), SIGNAL(sig_delLine(QString, QString, QString, QString)), this, SLOT(s_delLine(QString, QString, QString, QString)));
connect(CallManage::getInstance(), SIGNAL(sig_MouseMove(QString, QString, QString, float)), this, SLOT(s_MouseMove(QString, QString, QString, float)));
//波列
connect(CallManage::getInstance(), SIGNAL(sig_AddWave(QString, QString, QString, QString, QString)), this, SLOT(s_addWave(QString, QString, QString, QString, QString)));
connect(CallManage::getInstance(), SIGNAL(sig_delWave(QString, QString, QString, QString)), this, SLOT(s_delWave(QString, QString, QString, QString)));
//表格曲线
connect(CallManage::getInstance(), SIGNAL(sig_AddTableLine(QString, QString, QString, QString, QString)), this, SLOT(s_addTableLine(QString, QString, QString, QString, QString)));
connect(CallManage::getInstance(), SIGNAL(sig_delTableLine(QString, QString, QString, QString)), this, SLOT(s_delTableLine(QString, QString, QString, QString)));
}
FormDraw::~FormDraw()
{
delete ui;
}
void FormDraw::paintEvent(QPaintEvent*)
{
// QPainter painter(this);
// QRect rect = this->rect();
// //背景透明
// painter.fillRect(rect.left(), rect.top(), rect.width(), rect.height(), QColor(0, 0, 0, 0)); //QColor(67, 67, 67, 100)
// painter.setPen(QPen(Qt::green,2,Qt::DashLine));
// //painter.setBrush(QBrush(Qt::red,Qt::SolidPattern));
//// QFont font1("微软雅黑", 10, false, false); //fontSize 10
//// painter.setFont(font1);
//// painter.setPen(QColor(0, 0, 0)); // fontColor QColor(220, 220, 220)
//// painter.drawText(rect.left() + 10, 10, QStringLiteral("画图")); // titleBarText QStringLiteral("动画")
// QRect rectRound(rect.left()+2,rect.top()+4, rect.width()-3, rect.height()-4);
// painter.drawRoundRect(rectRound);
}
void FormDraw::s_addLine(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
//AppendConsole(PAI_INFO, "FormDraw s_addLine");
if(m_listLineName.contains(strLineName))
{
qDebug() << "FormDraw strLineName already exist! " << strLineName;
return;
}
//
QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, strTrackName, strLineName);
curv->m_strUuid = m_strUuid;
//背景设置成透明色
curv->setBackground(Qt::transparent);
curv->setStyleSheet("background: transparent;");
//
//QRect rect = this->rect();
//curv->setGeometry(rect.left(),rect.top(), rect.width(), rect.height());
double dHight = 0;
dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm;
qDebug() << "FormDraw dHight=" << QString::number((int)dHight-3184);
if(dHight>32767)
{
dHight = 32767;
}
//curv->setMaximumHeight((int)dHight);
//curv->setViewport(QRect(0, 0, g_iOneWidth, (int)dHight));//7500-3184
curv->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184
//curv->resize(INT_MAX, INT_MAX); // 使用 INT_MAX 来避免16位整数的限制
// QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// curv->setSizePolicy(policy);
curv->show();
initForm(curv, strSlfName, strLineName);
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
//
m_listLineName.push_back(strLineName);
}
void FormDraw::s_AddLine_Property(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName,
double newLeftScale, double newRightScale, QString strScaleType, QColor lineColor, double width, Qt::PenStyle lineStyle)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
//qDebug() << "FormDraw s_AddLine_Property";
AppendConsole(PAI_INFO, "FormDraw s_AddLine_Property");
if(m_listLineName.contains(strLineName))
{
qDebug() << "FormDraw strLineName already exist! " << strLineName;
return;
}
//
QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, strTrackName, strLineName);
curv->m_strUuid = m_strUuid;
//背景设置成透明色
curv->setBackground(Qt::transparent);
curv->setStyleSheet("background: transparent;");
//
//QRect rect = this->rect();
//curv->setGeometry(rect.left(),rect.top(), rect.width(), rect.height());
double dHight = 0;
dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm;
qDebug() << "FormDraw dHight=" << QString::number((int)dHight-3184);
if(dHight>32767)
{
dHight = 32767;
}
//curv->setMaximumHeight((int)dHight);
//curv->setViewport(QRect(0, 0, g_iOneWidth, (int)dHight));//7500-3184
curv->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184
//curv->resize(INT_MAX, INT_MAX); // 使用 INT_MAX 来避免16位整数的限制
// QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// curv->setSizePolicy(policy);
curv->show();
initForm(curv, strSlfName, strLineName,
newLeftScale, newRightScale, strScaleType, lineColor, width, lineStyle);
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
//
m_listLineName.push_back(strLineName);
AppendConsole(PAI_INFO, "FormDraw s_AddLine_Property end");
}
void FormDraw::s_addWave(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strWaveName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
if(m_listWaveName.contains(strWaveName))
{
qDebug() << "FormDraw strLineName already exist! " << strWaveName;
return;
}
//
QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, strTrackName, strWaveName);
curv->m_strUuid = m_strUuid;
//背景设置成透明色
curv->setBackground(Qt::transparent);
curv->setStyleSheet("background: transparent;");
//
//QRect rect = this->rect();
//curv->setGeometry(rect.left(),rect.top(), rect.width(), rect.height());
double dHight = 0;
dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm;
qDebug() << "FormDraw dHight=" << QString::number((int)dHight-3184);
if(dHight>32767)
{
dHight = 32767;
}
//curv->setMaximumHeight((int)dHight);
//curv->setViewport(QRect(0, 0, g_iOneWidth, (int)dHight));//7500-3184
curv->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184
//curv->resize(INT_MAX, INT_MAX); // 使用 INT_MAX 来避免16位整数的限制
// QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// curv->setSizePolicy(policy);
curv->show();
initWave(curv, strSlfName, strWaveName);
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
//
m_listWaveName.push_back(strWaveName);
}
void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
if(m_listTableName.contains(strLineName))
{
qDebug() << "FormDraw strLineName already exist! " << strLineName;
return;
}
//
QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, strTrackName, strLineName);
curv->m_strUuid = m_strUuid;
//背景设置成透明色
curv->setBackground(Qt::transparent);
curv->setStyleSheet("background: transparent;");
//
//QRect rect = this->rect();
//curv->setGeometry(rect.left(),rect.top(), rect.width(), rect.height());
double dHight = 0;
dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm;
qDebug() << "FormDraw dHight=" << QString::number((int)dHight-3184);
if(dHight>32767)
{
dHight = 32767;
}
//curv->setMaximumHeight((int)dHight);
//curv->setViewport(QRect(0, 0, g_iOneWidth, (int)dHight));//7500-3184
curv->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184
//curv->resize(INT_MAX, INT_MAX); // 使用 INT_MAX 来避免16位整数的限制
// QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// curv->setSizePolicy(policy);
curv->show();
initTableLine(curv, strSlfName, strLineName);
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
//
m_listTableName.push_back(strLineName);
}
void FormDraw::s_mouseWheel(QWheelEvent *event)
{
emit CallManage::getInstance()->sig_mouseWheel(event);
}
void FormDraw::setRowHeight(double dHight, QProgressBar *progressBar, int iSplit)
{
int iBeginValue = progressBar->value();
// 获取当前widget的所有子控件
const QObjectList &children = this->children();
int columnCount = children.size();
int iSplitCurv = iSplit / columnCount;
int i=0;
// 遍历子控件列表
for (QObject *child : children) {
// 判断子控件是否为QWidget类型
if (QWidget *childWidget = qobject_cast<QWidget *>(child)) {
// 打印子控件的信息,使用缩进表示层级关系
//qDebug() << QString("%1").arg(childWidget->objectName());
QString strObjName = childWidget->objectName();
if(strObjName=="QMyCustomPlot")
{
//progressBar->setValue(iBeginValue+ i*iSplitCurv); // 更新进度条的值
//
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
form->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184
//深度改变
form->xAxis->setRange(g_iY1, g_iY2);
//emit CallManage::getInstance()->sig_ChangeLeftScale(m_strUuid, form->m_strSlfName, m_strWellName, m_strTrackName, form->m_strLineName, form->m_iX1);
form->replot();//屏蔽,缩减时间
}
}
i++;
}
}
void FormDraw::s_delLine(QString strUuid, QString strWellName, QString strTrackName, QString strLineName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
qDebug() << "FormDraw s_delLine";
if(m_listLineName.contains(strLineName))
{
}
else
{
qDebug() << "FormDraw strLineName not exist! " << strLineName;
return;
}
//
// 获取当前widget的所有子控件
const QObjectList &children = this->children();
// 遍历子控件列表
for (QObject *child : children) {
// 判断子控件是否为QWidget类型
if (QWidget *childWidget = qobject_cast<QWidget *>(child)) {
// 打印子控件的信息,使用缩进表示层级关系
//qDebug() << QString("%1").arg(childWidget->objectName());
QString strObjName = childWidget->objectName();
if(strObjName=="QMyCustomPlot")
{
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
if(form->m_strLineName == strLineName)
{
childWidget->deleteLater(); // 安排控件的删除,稍后执行
m_listLineName.removeOne(strLineName);
//break;
}
}
}
}
}
void FormDraw::s_delWave(QString strUuid, QString strWellName, QString strTrackName, QString strLineName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
qDebug() << "FormDraw s_delWave";
if(m_listWaveName.contains(strLineName))
{
}
else
{
qDebug() << "FormDraw strLineName not exist! " << strLineName;
return;
}
//
// 获取当前widget的所有子控件
const QObjectList &children = this->children();
// 遍历子控件列表
for (QObject *child : children) {
// 判断子控件是否为QWidget类型
if (QWidget *childWidget = qobject_cast<QWidget *>(child)) {
// 打印子控件的信息,使用缩进表示层级关系
//qDebug() << QString("%1").arg(childWidget->objectName());
QString strObjName = childWidget->objectName();
if(strObjName=="QMyCustomPlot")
{
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
if(form->m_strLineName == strLineName)
{
childWidget->deleteLater(); // 安排控件的删除,稍后执行
m_listWaveName.removeOne(strLineName);
//break;
}
}
}
}
}
void FormDraw::s_delTableLine(QString strUuid, QString strWellName, QString strTrackName, QString strLineName)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
qDebug() << "FormDraw s_delTableLine";
if(m_listTableName.contains(strLineName))
{
}
else
{
qDebug() << "FormDraw strLineName not exist! " << strLineName;
return;
}
//
// 获取当前widget的所有子控件
const QObjectList &children = this->children();
// 遍历子控件列表
for (QObject *child : children) {
// 判断子控件是否为QWidget类型
if (QWidget *childWidget = qobject_cast<QWidget *>(child)) {
// 打印子控件的信息,使用缩进表示层级关系
//qDebug() << QString("%1").arg(childWidget->objectName());
QString strObjName = childWidget->objectName();
if(strObjName=="QMyCustomPlot")
{
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
if(form->m_strLineName == strLineName)
{
childWidget->deleteLater(); // 安排控件的删除,稍后执行
m_listWaveName.removeOne(strLineName);
//break;
}
}
}
}
}
void FormDraw::s_MouseMove(QString strUuid, QString strWellName, QString strTrackName, float dep)
{
//井名&道名不一致
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
{
}
else
{
return;
}
//qDebug() << "FormDraw s_MouseMove";
//
QString sss=" depth:"+QString::number(dep);
float fValue=-9999;
// 获取当前widget的所有子控件
const QObjectList &children = this->children();
// 遍历子控件列表
for (QObject *child : children) {
// 判断子控件是否为QWidget类型
if (QWidget *childWidget = qobject_cast<QWidget *>(child)) {
// 打印子控件的信息,使用缩进表示层级关系
//qDebug() << QString("%1").arg(childWidget->objectName());
QString strObjName = childWidget->objectName();
if(strObjName=="QMyCustomPlot")
{
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
//
CLogIO *logio=new CLogIO();
logio->Open(form->m_strSlfName.toStdString().c_str(),CSlfIO::modeRead);
int index=logio->OpenCurve(form->m_strLineName.toStdString().c_str());
if(index<0) {
delete logio;
return;
}
logio->ReadCurve(index, dep, 1, &fValue);
logio->CloseCurve(index);
delete logio;
sss+=" " + form->m_strLineName + ":"+QString::number(fValue);
}
}
}
QStatusBar *pStatusbar = ::GetStatusBar();
if(pStatusbar)
{
pStatusbar->showMessage(sss);
}
}
void FormDraw::s_handleRectRangeChange(QCPRange newRange)
{
}
void FormDraw::setupLineStyleDemo(QMyCustomPlot *customPlot)
{
// customPlot->legend->setVisible(true);
// customPlot->legend->setFont(QFont("Helvetica", 9));
// QPen pen;
// QStringList lineNames;
// lineNames << "lsNone" << "lsLine" << "lsStepLeft" << "lsStepRight" << "lsStepCenter" << "lsImpulse";
// for (int i = QCPGraph::lsNone; i <= QCPGraph::lsImpulse; ++i)
// {
// customPlot->addGraph();
// pen.setColor(QColor(qSin(i*1+1.2)*80+80, qSin(i*0.3+0)*80+80, qSin(i*0.3+1.5)*80+80));
// customPlot->graph()->setPen(pen); // 设置图表的画笔
// customPlot->graph()->setName(lineNames.at(i-QCPGraph::lsNone));
// customPlot->graph()->setLineStyle((QCPGraph::LineStyle)i); // 设置图表线段的风格
// customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); // 设置图表散点图的样式
// QVector<double> x(15), y(15);
// for (int j=0; j<15; ++j)
// {
// x[j] = j/15.0 * 5*3.14 + 0.01;
// y[j] = 7*qSin(x[j])/x[j] - (i-QCPGraph::lsNone)*5 + (QCPGraph::lsImpulse)*5 + 2;
// }
// customPlot->graph()->setData(x, y);
// customPlot->graph()->rescaleAxes(true);
// }
// // 放大一点
// customPlot->yAxis->scaleRange(1.1, customPlot->yAxis->range().center());
// customPlot->xAxis->scaleRange(1.1, customPlot->xAxis->range().center());
// customPlot->xAxis->setTicks(true);
// customPlot->yAxis->setTicks(true);
// customPlot->xAxis->setTickLabels(true);
// customPlot->yAxis->setTickLabels(true);
// customPlot->axisRect()->setupFullAxesBox();
}
void FormDraw::setupSelectionDemo(QMyCustomPlot *customPlot)
{
//setupLineStyleDemo(customPlot);
customPlot->setInteractions(QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iMultiSelect); // 轴、图例、图表可以被选择,并且是多选的方式
customPlot->setSelectionRectMode(QCP::srmCustom); // 鼠标框选
//customPlot->setSelectionRectMode(QCP::srmSelect); // 鼠标框选
// customPlot->setMultiSelectModifier(Qt::ControlModifier); // 使用ctrl键来多选
// customPlot->xAxis->setSelectableParts(QCPAxis::spAxis | QCPAxis::spAxisLabel | QCPAxis::spTickLabels); // 轴的三个部分都可以被选择
// customPlot->yAxis->setSelectableParts(QCPAxis::spAxis | QCPAxis::spAxisLabel | QCPAxis::spTickLabels);
// customPlot->xAxis->setLabel("xAxis");
// customPlot->yAxis->setLabel("yAxis");
// customPlot->legend->setSelectableParts(QCPLegend::spItems); // 图例本身不能被选择,只有里面的项可以被选择
// customPlot->legend->setSelectedIconBorderPen(Qt::NoPen); // 设置图例里的项被选择时不显示Icon的边框
//选框黑色虚线
//customPlot->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));
//customPlot->selectionRect()->setBrush(QBrush(QColor(0,0,100,50)));
//
// QPen pen(Qt::NoPen); // 使用无画笔,这样就不会有边框了
// QBrush brush(Qt::transparent); // 使用透明刷子,这样就不会有填充颜色了
// customPlot->selectionRect()->setPen(pen); // 设置选择区域的画笔为无画笔
// customPlot->selectionRect()->setBrush(brush); // 设置选择区域的刷子为透明刷子
for (int i=0; i < customPlot->graphCount(); ++i) {
QCPGraph *graph = customPlot->graph(i);
graph->setSelectable(QCP::stDataRange);
}
//connect(customPlot->selectionRect(), SIGNAL(accepted(QRect, QMouseEvent*)), this, SLOT(s_selectionRectAccepted(QRect, QMouseEvent*)));
connect(customPlot->selectionRect(), &QCPSelectionRect::accepted, [customPlot](){
if(customPlot->m_bDrawRect == false)
{
customPlot->m_bDrawRect = true;
return;
}
// 当选择完成时,获取矩形范围并放大
QRectF rect = customPlot->selectionRect()->rect(); // 获取选择的矩形区域(像素坐标)
// 转换为坐标轴范围
double top = rect.top();
double bottom = rect.bottom();
double right_Hight = customPlot->xAxis->pixelToCoord(top);
double left_Low = customPlot->xAxis->pixelToCoord(bottom);
if(right_Hight-left_Low>5)
{
//添加图形
//emit CallManage::getInstance()->sig_addImageToPlot(customPlot, left_Low, right_Hight, ":/image/file.png");
customPlot->addImageToPlot(left_Low, right_Hight, ":/image/file.png");
}
});
// 连接QCustomPlot的信号selectionChangedByUser表明是由鼠标点击进行的选择
// 这里主要就是同步图表和图例的显示
connect(customPlot, &QMyCustomPlot::selectionChangedByUser, [customPlot](){
for (int i=0; i < customPlot->graphCount(); ++i) {
QCPGraph *graph = customPlot->graph(i);
QCPPlottableLegendItem *item = customPlot->legend->itemWithPlottable(graph);
if (item->selected() && !graph->selected())
{
graph->setSelection(QCPDataSelection(graph->data()->dataRange())); // 当图例项被选择时,选择图表全部的数据
}
else if (graph->selected())
{
item->setSelected(true);
QCPDataSelection selection = customPlot->graph(i)->selection();
// 遍历选中的数据范围
for (int j = 0; j < selection.dataRangeCount(); ++j)
{
QCPDataRange dataRange = selection.dataRange(j);
double left_Low = customPlot->graph(i)->data()->at(dataRange.begin())->key;
double right_Hight = customPlot->graph(i)->data()->at(dataRange.end())->key;
if(right_Hight-left_Low>1)
{
//添加图形
//emit CallManage::getInstance()->sig_addImageToPlot(customPlot, left_Low, right_Hight, ":/image/file.png");
customPlot->addImageToPlot(left_Low, right_Hight, ":/image/file.png");
}
}
/*QCPDataSelection selection = customPlot->graph(i)->selection();
// 遍历选中的数据范围
for (int j = 0; j < selection.dataRangeCount(); ++j)
{
QCPDataRange dataRange = selection.dataRange(j);
// 遍历选中范围内的数据点
for (int k = dataRange.begin(); k < dataRange.end(); ++k)
{
double key = customPlot->graph(i)->data()->at(k)->key;
double value = customPlot->graph(i)->data()->at(k)->value;
AppendConsole(PAI_INFO, QString("曲线 %1: (%2, %3)").arg(i).arg(key).arg(value));
}
}*/
}
}
});
}
void FormDraw::s_selectionRectAccepted(const QRect &rect, QMouseEvent *event)
{
// 转换为坐标轴范围
// double x1 = widget->xAxis->pixelToCoord(rect.left());
// double x2 = widget->xAxis->pixelToCoord(rect.right());
// double y1 = widget->yAxis->pixelToCoord(rect.top());
// double y2 = widget->yAxis->pixelToCoord(rect.bottom());
}
void FormDraw::initForm(QMyCustomPlot *widget, QString strSlfName, QString strLineName,
double newLeftScale, double newRightScale, QString strScaleType, QColor lineColor, double width, Qt::PenStyle lineStyle)
{
//AppendConsole(PAI_INFO, "FormDraw initForm");
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;
}
Slf_CURVE curveinfo;
float *val;
DWORD count;
float sdep,edep,rlev;
float vmax,vmin;
//
logio->GetCurveInfo(index,&curveinfo);
sdep=curveinfo.StartDepth;
edep=curveinfo.EndDepth;
rlev=curveinfo.DepLevel;
//
count=(curveinfo.EndDepth-curveinfo.StartDepth)/curveinfo.DepLevel+1.5;
val=new float[count];
logio->ReadCurve(index,curveinfo.StartDepth,count,&val[0]);
logio->CloseCurve(index);
delete logio;
QString strAliasName="";
QString strUnit="";
bool bFind = getAliasNameFromIni(strLineName, strAliasName, strUnit);//曲线别名
if(!bFind)
{
strAliasName=strLineName;
}
//最大值,最小值
vmax=vmin=val[0];
//slf文件读取曲线
QVector<double> x, y;
for(int i=0; i<count; i++)
{
if(newLeftScale==-9999)
{
if(vmax<val[i])vmax=val[i];
if(vmin>val[i])vmin=val[i];
}
//
x.append(-(sdep+ rlev*i));
y.append(val[i]);
}
if(newLeftScale!=-9999)
{
vmax = newRightScale;
vmin = newLeftScale;
}
//赋值
m_vmax = vmax;
m_vmin = vmin;
//AppendConsole(PAI_INFO, "FormDraw initForm ReadCurve end");
widget->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables);
//框选-----
// widget->setInteraction(QCP::iRangeDrag, false); // 关闭拖动
// widget->setSelectionRectMode(QCP::SelectionRectMode::srmSelect); // 启用框选放大
// //
// widget->selectionRect()->setPen(QPen(Qt::black, 1, Qt::DashLine)); // 虚线边框
// widget->selectionRect()->setBrush(QBrush(QColor(0,0,100,50))); // 半透明蓝色填充
// //
// QCPSelectionRect *selectionRect = new QCPSelectionRect(widget);
// connect(selectionRect, &QCPSelectionRect::accepted, [=]() {
// // 当选择完成时,获取矩形范围并放大
// QRectF rect = selectionRect->rect(); // 获取选择的矩形区域(像素坐标)
// // 转换为坐标轴范围
// double x1 = widget->xAxis->pixelToCoord(rect.left());
// double x2 = widget->xAxis->pixelToCoord(rect.right());
// double y1 = widget->yAxis->pixelToCoord(rect.top());
// double y2 = widget->yAxis->pixelToCoord(rect.bottom());
// });
widget->m_iX1 = vmin;
widget->m_iX2 = vmax;
widget->m_iY1 = g_iY1;
widget->m_iY2 = g_iY2;
//
widget->xAxis->setRange(vmin, vmax);
widget->yAxis->setRange(g_iY1, g_iY2);
widget->axisRect()->setupFullAxesBox();
//
widget->xAxis->ticker()->setTickCount(10);//x个主刻度
widget->yAxis->ticker()->setTickCount(60);//y个主刻度
//对调XY轴在最前面设置
QCPAxis *yAxis = widget->yAxis;
QCPAxis *xAxis = widget->xAxis;
widget->xAxis = yAxis;
widget->yAxis = xAxis;
//
if(strScaleType=="对数")
{
widget->yAxis->setScaleType(QCPAxis::stLogarithmic);
}
else //if(m_strScaleType=="线性")
{
widget->yAxis->setScaleType(QCPAxis::stLinear);
}
// //
// widget->yAxis->setRange(vmin, vmax);
// widget->xAxis->setRange(g_iY1, g_iY2);
// widget->axisRect()->setupFullAxesBox();
// //
// widget->yAxis->ticker()->setTickCount(10);//x个主刻度
// widget->xAxis->ticker()->setTickCount(60);//y个主刻度
// //slf文件读取曲线
// QVector<double> x, y;
// for(int i=0; i<count; i++)
// {
// x.append(-(sdep+ rlev*i));
// y.append(val[i]);
// }
if(newLeftScale!=-9999)
{
addRandomGraph(widget, x, y, strSlfName, strLineName, strAliasName, strUnit,
newLeftScale, newRightScale, strScaleType, lineColor, width, lineStyle);
}
else {
addRandomGraph(widget, x, y, strSlfName, strLineName, strAliasName, strUnit);
}
//支持框选
//setupSelectionDemo(widget);
//AppendConsole(PAI_INFO, "FormDraw setupSelectionDemo end");
//widget->rescaleAxes();
//widget->replot();//屏蔽,缩减时间
//AppendConsole(PAI_INFO, "FormDraw initForm end");
}
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;
}
void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWaveName)
{
CLogIO *logio=new CLogIO();
logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead);
//
int index=logio->OpenWave(strWaveName.toStdString().c_str());
if(index<0) {
delete logio;
return;
}
Slf_WAVE _wave;
logio->GetWaveInfo(index, &_wave);
float _SDep,_EDep,_Rlev;
_SDep = _wave.StartDepth;
_EDep = _wave.EndDepth;
// _SDep = 0.0 - g_iY2;
// _EDep = 0.0 - g_iY1;
_Rlev = _wave.DepLevel;
int m_Record=(float)(fabs((_EDep-_SDep)/_Rlev+0.5));
int _nSamples = _wave.TimeSamples;
char *value=new char[(_nSamples+1)*m_Record*_wave.CodeLen+1];
logio->ReadWave(index,_SDep,m_Record,(void *)value);
logio->CloseWave(index);
delete logio;
float vmax = -9999;//(float)_nSamples;
float vmin = -9999;
//
double** wavedata;
wavedata = new double*[_nSamples];
for(int kk = 0;kk<_nSamples;kk++){
wavedata[kk] = new double[m_Record];
}
for (int i=0; i<m_Record; i++)
{
for(int kk = 0;kk<_nSamples;kk++)
{
double val = GetData(_wave.RepCode,(char *)&value[(kk)*_wave.CodeLen+i*_nSamples*_wave.CodeLen]);
wavedata[kk][i] = val;
if(val==-9999)
{
continue;
}
//
if(vmax<val)vmax=val;
if(vmin>val)vmin=val;
}
}
delete[] value;
// g_iY1 = 0.0 -_EDep;
// g_iY2 = 0.0 -_SDep;
//------------------------
widget->m_iX1 = vmin;
widget->m_iX2 = vmax;
widget->m_iY1 = g_iY1;
widget->m_iY2 = g_iY2;
//
widget->xAxis->setRange(vmin, vmax);
widget->yAxis->setRange(g_iY1, g_iY2);
widget->axisRect()->setupFullAxesBox();
//
widget->xAxis->ticker()->setTickCount(10);//x个主刻度
widget->yAxis->ticker()->setTickCount(60);//y个主刻度
//对调XY轴在最前面设置
QCPAxis *yAxis = widget->yAxis;
QCPAxis *xAxis = widget->xAxis;
widget->xAxis = yAxis;
widget->yAxis = xAxis;
//-------------------
// set up the QCPColorMap:
QCPColorMap *colorMap = new QCPColorMap(widget->xAxis, widget->yAxis);
int nx = m_Record;
int ny = _nSamples;
colorMap->data()->setSize(nx, ny); // 我们希望彩色地图有nx*ny的数据点
//colorMap->data()->setRange(QCPRange(g_iY1, g_iY2), QCPRange(vmin, vmax)); // 并在键x和值y维上跨越坐标范围-4..4
colorMap->data()->setRange(QCPRange(0-_EDep, 0-_SDep), QCPRange(vmin, vmax));
// 现在我们通过访问颜色贴图的QCPColorMapData实例来分配一些数据
double x, y, z;
for (int xIndex=0; xIndex<nx; ++xIndex)
{
for (int yIndex=0; yIndex<ny; ++yIndex)
{
if(wavedata[yIndex][xIndex]==-9999)
{
colorMap->data()->setCell(nx-xIndex-1, yIndex, vmin);
continue;
}
//colorMap->data()->setCell(xIndex, yIndex, wavedata[yIndex][xIndex]);
colorMap->data()->setCell(nx-xIndex-1, yIndex, wavedata[yIndex][xIndex]);
}
}
// 添加色标:
QCPColorScale *colorScale = new QCPColorScale(widget);
colorMap->setColorScale(colorScale); // 将颜色图与色标关联
// 将颜色贴图的“颜色渐变”设置为其中一个预设
//colorMap->setGradient(QCPColorGradient::gpPolar);//gpJet);
// 我们还可以创建一个QCPColorGradient实例并向其中添加自己的颜色
// 渐变请参阅QCPColorGradient的文档以获取可能的效果.
int nIndex=11;
QVector<MyColorItem> colorList;
bool inpolation = true;
int iColorNum = getSystemColor(nIndex, colorList, inpolation);
//
QCPColorGradient gradient;
for(int i=0; i<iColorNum; i++)
{
double dbTmpIndex=(double)(i+1)/iColorNum;
gradient.setColorStopAt(dbTmpIndex, colorList[i].color); // x% 位置的颜色
}
colorMap->setGradient(gradient);
// 重新缩放数据维度(颜色),以使所有数据点都位于颜色渐变显示的范围内:
colorMap->rescaleDataRange();
//----调色板--------
// widget->plotLayout()->addElement(0, 1, colorScale); // 将其添加到主轴矩形的右侧
// colorScale->setType(QCPAxis::atRight); // 刻度应为垂直条,刻度线/坐标轴标签右侧(实际上,右侧已经是默认值)
// colorScale->axis()->setLabel("Magnetic Field Strength");
// //确保轴rect和色标同步其底边距和顶边距以便它们对齐:
// QCPMarginGroup *marginGroup = new QCPMarginGroup(widget);
// widget->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
// colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
// 重新缩放键x和值y以便可以看到整个颜色图
//widget->rescaleAxes();
QString strAliasName = "";
QString strUnit = "";
QColor newlineColor=QColor(0,0,0);
double width=2;
QString strScaleType = "";
//道-对象
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strWaveName, strAliasName, strUnit, newlineColor, width, _nSamples, 0, strScaleType, "waveObject");
}
void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strWaveName)
{
CLogIO *logio=new CLogIO();
logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead);
//
int index=logio->OpenWave(strWaveName.toStdString().c_str());
if(index<0) {
delete logio;
return;
}
Slf_WAVE _wave;
logio->GetWaveInfo(index, &_wave);
float _SDep,_EDep,_Rlev;
// _SDep = _wave.StartDepth;
// _EDep = _wave.EndDepth;
g_iY2 = 0 - _wave.StartDepth;
g_iY1 = 0 - _wave.EndDepth;
_SDep = 0.0 - g_iY2;
_EDep = 0.0 - g_iY1;
_Rlev = _wave.DepLevel;
int m_Record=(float)(fabs((_EDep-_SDep)/_Rlev+0.5));
int _nSamples = _wave.TimeSamples;
char *value=new char[(_nSamples+1)*m_Record*_wave.CodeLen+1];
logio->ReadWave(index,_SDep,m_Record,(void *)value);
logio->CloseWave(index);
delete logio;
float vmax = (float)_nSamples;
float vmin = 0;
//
double** wavedata;
wavedata = new double*[_nSamples];
for(int kk = 0;kk<_nSamples;kk++){
wavedata[kk] = new double[m_Record];
}
for (int i=0; i<m_Record; i++)
{
for(int kk = 0;kk<_nSamples;kk++)
{
double val = GetData(_wave.RepCode,(char *)&value[(kk)*_wave.CodeLen+i*_nSamples*_wave.CodeLen]);
wavedata[kk][i] = val;
if(val==-9999)
{
continue;
}
//
// if(vmax<val)vmax=val;
// if(vmin>val)vmin=val;
}
}
delete[] value;
// g_iY1 = 0.0 -_EDep;
// g_iY2 = 0.0 -_SDep;
//------------------------
widget->m_iX1 = vmin;
widget->m_iX2 = vmax;
widget->m_iY1 = g_iY1;
widget->m_iY2 = g_iY2;
//
widget->xAxis->setRange(vmin, vmax);
widget->yAxis->setRange(g_iY1, g_iY2);
widget->axisRect()->setupFullAxesBox();
//
widget->xAxis->ticker()->setTickCount(10);//x个主刻度
widget->yAxis->ticker()->setTickCount(60);//y个主刻度
//对调XY轴在最前面设置
// QCPAxis *yAxis = widget->yAxis;
// QCPAxis *xAxis = widget->xAxis;
// widget->xAxis = yAxis;
// widget->yAxis = xAxis;
float nPerHight = 50;//25
float nSpace = 1;
for (int i=0; i<m_Record; i++)
{
//--------------------------------
QVector<double> x;
QVector<double> y;
widget->addGraph();
QString strLineName = "";
if(strLineName=="")
{
strLineName = QString("曲线 %1").arg(widget->graphCount());
}
widget->graph()->setName(strLineName);
for(int kk = 0;kk<_nSamples;kk++)
{
//double val = wavedata[kk][m_Record-i-1];
double val = wavedata[kk][i];
if(val==-9999)
{
continue;
}
//x.append(_nSamples-kk-1);
float tempValue = -(_SDep + nPerHight*_Rlev*i + (val*200*2)/vmax);
x.append(kk);
//float tempValue = -(_SDep + nSpace*i + (val*nPerHight*_Rlev*2)/vmax);
y.append(tempValue);
}
widget->graph()->setData(x, y);
widget->graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线
widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1)));
//
QPen graphPen;
QColor newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10);
graphPen.setColor(newlineColor);
double width = 1;
graphPen.setWidthF(width);
graphPen.setStyle(Qt::SolidLine);//实线
widget->graph()->setPen(graphPen);
//widget->replot();
if(i>=20)
break;
}
}
//表格曲线
void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
{
m_Value2=NULL;
m_Value3=NULL;
//m_csUnit = "(°)";
m_bTableData=0;
m_LeftVal2=0;
m_RightVal2=360;
//m_csCurveDDIR="DDIR";
//m_csCurveDANG="DANG";
//m_csCurveGrad="GRAD";
m_nTailWidth=2;
m_crTail=qRgb(0,0,0);
m_crPointFill=qRgb(0,0,0);
m_nRadius = 4;
m_nTailLen = 8;
m_nCircleWidth=1;
m_flGrad1 = 10;
m_flGrad2 = 50;
//Table dip
m_qsTable="FRAC_HOLE.TABLE";
m_qsDIR=("DIR"); // 方位 曲线名
m_qsDIP=("DIPorS");//倾角
m_qsDepth="DEP";
m_qsID = "ID";
m_qsProperty=("ID");
m_iPrecision = 3;
//
ReadFracDef();
for (int i = 0 ; i < iFracType ; i++)
{
m_bTypeDraw[i] = false;
}
//
m_qsDIR=("DDIR"); // 方位 曲线名
m_qsDIP=("DANG");//倾角
m_qsDepth="DEPT";
m_qsID = "ID";
ReadData(strSlfName, strLineName);
//------------------------
int nPointNum = m_FracTabList.count();
if ( nPointNum < 1 )return ;
FRAC_TABLE frac = m_FracTabList.at(0);
float vmax = -9999;
float vmin = -9999;
//最大值,最小值
vmax=vmin=frac.DIR;
//slf文件读取曲线
for(int i=0; i<nPointNum; i++)
{
frac = m_FracTabList.at(i);
if(vmax<frac.DIR)vmax=frac.DIR;
if(vmin>frac.DIR)vmin=frac.DIR;
}
widget->m_iX1 = vmin;
widget->m_iX2 = vmax;
widget->m_iY1 = g_iY1;
widget->m_iY2 = g_iY2;
//
widget->xAxis->setRange(vmin, vmax);
widget->yAxis->setRange(g_iY1, g_iY2);
widget->axisRect()->setupFullAxesBox();
//
widget->xAxis->ticker()->setTickCount(10);//x个主刻度
widget->yAxis->ticker()->setTickCount(60);//y个主刻度
//对调XY轴在最前面设置
QCPAxis *yAxis = widget->yAxis;
QCPAxis *xAxis = widget->xAxis;
widget->xAxis = yAxis;
widget->yAxis = xAxis;
//
DrawTabDip(widget);
}
void FormDraw::DrawTabDip(QMyCustomPlot *widget)
{
float sdep,edep,flDepthScale,tempf,flVal;
int i,j,n,nPointNum=0,tempi;
QRectF rt,rtRect;
float x,y;
float dgtord,dr;
float flWidth[50];
FRAC_TABLE frac;
bool bDraw;
FRAC_DEF fd;
//CString cs;
if(m_iPrecision<0) m_iPrecision=0;
nPointNum = m_FracTabList.count();
if ( nPointNum < 1 )return ;
dgtord=3.14159265/180.;
//
m_nCircleWidth = 1;
m_nTailWidth = 1;
m_nRadius = 4;
m_crCircle = QColor(0,0,0);
m_crTail = QColor(0,0,0);
n = m_FracDefList.count();
for (i=0; i<nPointNum; i++)
{
frac = m_FracTabList.at(i);
bDraw = false;
for (j=0; j<n; j++)
{
fd = m_FracDefList.at(j);
// 裂缝描述表中未保存裂缝名称:
//比较裂缝名称比较准确,代码更改,如果比较代码会引起不一致性
if ( (int)(frac.ID) == fd.iCode )
{
bDraw = m_bTypeDraw[j];//fd.bDraw;
break;
}
}
//if ( bDraw )
{
QBrush cBrush(fd.crColor);
//圆圈
QPen pPen(m_crCircle);
pPen.setWidth(m_nCircleWidth);
//尾巴
QPen pPenTail(m_crTail);
pPenTail.setWidth(m_nTailWidth);
// 角度
//flVal = frac.DIPorS;
x = frac.DIPorS;
y = -frac.DEP;
// int LineWidth = m_nRadius;
// rtRect.setLeft(x - LineWidth);
// rtRect.setRight( x + LineWidth);
// rtRect.setBottom( y + LineWidth);
// rtRect.setTop(y - LineWidth);
// pDC->setPen(pPen);
// pDC->drawEllipse(rtRect.left(),rtRect.top(),rtRect.width(),rtRect.height());
// QPainterPath myPath;
// myPath.addEllipse(rtRect);
// pDC->fillPath(myPath,cBrush);
//CustomEllipse *qcpitemellipse = new CustomEllipse(widget);
QCPItemEllipse *qcpItemEllipse = new QCPItemEllipse(widget);
qcpItemEllipse->setPen(pPen);
qcpItemEllipse->m_bCustom = true;
qcpItemEllipse->m_nRadius = m_nRadius;
qcpItemEllipse->topLeft->setCoords(y, x);//圆心位置
qcpItemEllipse->bottomRight->setCoords(y, x);//圆心位置
//qcpItemEllipse->setBrush(cBrush);//填充圆的颜色
//方位
dr=frac.DIR *dgtord;
QCPItemLine *qcpItemLine = new QCPItemLine(widget);
qcpItemLine->setPen(pPenTail);
qcpItemLine->m_bCustom = true;
qcpItemLine->m_nTailLen = m_nTailLen; //尾长
qcpItemLine->m_nRadius = m_nRadius; //半径
qcpItemLine->m_dr = dr;
qcpItemLine->start->setCoords(y, x);//圆心位置
qcpItemLine->end->setCoords(y, x);//圆心位置
//break;
// x += m_nRadius*sin(dr);
// // 注意映射方式
// y -=m_nRadius*cos(dr);
// //pDC->moveto(x,y);
// float x1=x +m_nTailLen*sin(dr);
// // 注意映射方式
// float y1= y-m_nTailLen*cos(dr);
// pDC->setPen(pPenTail);
// pDC->drawLine(x,y,x1,y1);
// if ( m_bDrawValue ) //显示倾角、方位
// {
// rtRect.setTop(rtRect.top()-GetLineWidth(pDC,objViewInfo->GetLogUnitFont().pointSize()));
// rtRect.setBottom(rtRect.bottom()+GetLineWidth(pDC,objViewInfo->GetLogUnitFont().pointSize()));
// QString cs1 = QString::number(frac.DIPorS,'f',m_iPrecision);
// QString cs2 = QString::number(frac.DIR,'f',m_iPrecision);
// cs=cs1+"//"+cs2;
// cs.Replace((" "),"");
// if ( frac.DIPorS >= 30 )
// {
// x = 2.*(float)(GetLineWidth(pDC,m_nRadius));
// rtRect.setRight(rtRect.center().x() - x);
// rtRect.setLeft(mrt.left());
// pDC->drawText(rtRect,Qt::AlignVCenter|Qt::AlignHCenter,cs.GetString());
// }
// else
// {
// x = 2.*(float)(GetLineWidth(pDC,m_nRadius));
// rtRect.setLeft(rtRect.center().x() + x);
// rtRect.setRight(mrt.right());
// pDC->drawText(rtRect,Qt::AlignVCenter,cs.GetString());
// }
// }
}
}
}
//read config file: FRAC.CFG,save info into m_FracDef
void FormDraw::ReadFracDef()
{
m_FracDefList.clear();
FRAC_DEF fd;
//char path[MAX_PATH+1];
char str[512],name[512];
int r,g,b,id;
FILE *fp;
QString qs;
//sprintf(str,"%sconf\\FRAC.CFG",path);
QString fracFilePath = GetConfPath() + "FRAC_New.CFG";
fp = fopen(fracFilePath.toStdString().c_str(),"r");
if ( fp !=NULL )
{
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_FracDefList.append(fd);
if ( feof(fp))
break;
}
fclose(fp);
}
else
{
sprintf(name,"打开裂缝参数配置文件错误:%s!",str);
QMessageBox::information(nullptr, "读取文件失败", name);
}
}
//for table dip ,read FRAC_HOLE.TABLE
void FormDraw::ReadData(QString strSlfName, QString strLineName)
{
QString cs;
int nField,len;
FRAC_TABLE frac;
CMemRdWt mrw;
m_PointNum = 0 ;
char strFracTable[256];
int i,j,iIndex,nCount,iType=1;
char wellname2[512];
char *buffer;
Slf_TABLE_FIELD *Table_Field;
char bufField[1024];
float val;
//
m_FracTabList.clear();
if(m_qsTable=="AC"|| m_qsTable=="")
{
m_qsTable="FRAC_HOLE.TABLE";
}
//
if(strSlfName.isEmpty())
{
return;
}
//CString wellname(strSlfName);
if ( mrw.Open(strSlfName.toStdString().c_str()) ) // 打开井文件
{
//CString strFracTable(m_qsTable);
iIndex = mrw.OpenTable(m_qsTable.toStdString().c_str());
if (iIndex >= 0)
{
nField = mrw.GetTableFieldCount(iIndex);
Table_Field = new Slf_TABLE_FIELD[nField+1];
// 读取字段信息
mrw.GetTableFieldInfo(iIndex, Table_Field);
// 读取数据记录
nCount = mrw.GetTableRecordCount(iIndex);
i = mrw.GetTableRecordLength(iIndex);
buffer = new char[i+2];
m_PointNum = nCount;
for(i=0; i<nCount; i++)
{
memset(&frac, 0x00, sizeof(FRAC_TABLE));
mrw.ReadTable(iIndex, i+1, buffer);
frac.DEP = -9999;
len = 0;
for(j=0; j<nField; j++)
{
val = GetData(Table_Field[j].RepCode, &buffer[len]);
cs = Table_Field[j].Name;
if ( m_qsDepth.compare(cs)==0)
frac.DEP = val;
if ( m_qsDIP.compare(cs)==0)
frac.DIPorS = val;
if ( m_qsDIR.compare(cs)==0)
frac.DIR = val;
if ( m_qsID.compare(cs)==0)
frac.ID = (int)(val);
len += Table_Field[j].Length;
}
m_FracTabList.append(frac);
}
delete [] Table_Field;
delete [] buffer;
mrw.CloseTable(iIndex);
}
mrw.Close(); //关闭井文件
}
}
void FormDraw::addRandomGraph(QMyCustomPlot *widget, QVector<double> x, QVector<double> y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit,
double newLeftScale, double newRightScale, QString strScaleType, QColor newlineColor, double width, Qt::PenStyle lineStyle)
{
widget->addRandomGraph(x, y, strSlfName, strLineName, strAliasName, strUnit,
newLeftScale, newRightScale, strScaleType, newlineColor, width, lineStyle);
//道-对象
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_vmax, m_vmin, strScaleType, "curveObject");
//AppendConsole(PAI_INFO, "FormDraw addRandomGraph");
// widget->addGraph();
// if(strLineName=="")
// {
// strLineName = QString("曲线 %1").arg(widget->graphCount());
// }
// widget->graph()->setName(strLineName);
// //禁用自动重绘:在大量数据更新前禁用自动重绘
// //widget->setNotAntialiasedElements(QCP::aeAll);
// widget->graph()->setData(x, y);
// if(newLeftScale!=-9999)
// {
// widget->graph()->setLineStyle((QCPGraph::LineStyle)(lineStyle));//曲线
// widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1)));
// QPen graphPen;
// graphPen.setColor(newlineColor);
// graphPen.setWidthF(width);
// graphPen.setStyle(lineStyle);//实线
// widget->graph()->setPen(graphPen);
// }
// else
// {
// widget->graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线
// widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1)));
// // widget->graph()->setScatterStyle(QCPScatterStyle(QPixmap(":/image/file.png")));
// //widget->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
// QPen graphPen;
// newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10);
// graphPen.setColor(newlineColor);
// width = 2;
// graphPen.setWidthF(width);
// graphPen.setStyle(Qt::SolidLine);//实线
// widget->graph()->setPen(graphPen);
// //widget->replot();
// }
// //道-对象
// m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_vmax, m_vmin, strScaleType);
//AppendConsole(PAI_INFO, "FormDraw addRandomGraph end");
}
void FormDraw::dragEnterEvent(QDragEnterEvent* event)
{
qDebug() << "FormDraw dragEnterEvent";
const QMimeData* mimeData = event->mimeData();
// 检查拖拽的数据类型,确定是否接受拖拽
if (event->mimeData()->hasFormat("text/plain")) {
event->acceptProposedAction();
//QApplication::setOverrideCursor(Qt::PointingHandCursor); // 设置鼠标为可添加状态
}
else
{
event->ignore();
//QApplication::setOverrideCursor(Qt::ForbiddenCursor); // 设置鼠标为不可添加状态
}
}
void FormDraw::dragMoveEvent(QDragMoveEvent* event)
{
//qDebug() << "FormDraw dragMoveEvent";
// 可以在这里更新鼠标的位置,根据位置判断是否可以放置
// ...
//dragEnterEvent(event); // 可以使用相同的逻辑
//event->accept();
}
void FormDraw::dropEvent(QDropEvent* event)
{
qDebug() << "FormDraw dropEvent";
// 处理放置动作更新UI或数据
if (event->mimeData()->hasFormat("text/plain")) {
// 获取拖拽的数据
QString strExtern = event->mimeData()->text();
qDebug() << strExtern;
//
QStringList list = strExtern.split("#@@#");//QString字符串分割函数
if (list.size() > 3)
{
QString strSlfName = list[0];
QString strWellName = list[1];
QString strLineName = list[2];
QString strType = list[3];
qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName << " strLineName:" << strLineName << " strType:" << strType;
if(m_strWellName == strWellName)
{
if(strType=="curveObject")
{
//新建曲线
emit CallManage::getInstance()->sig_AddLine(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
}
else if(strType=="waveObject")
{
//新建波列
emit CallManage::getInstance()->sig_AddWave(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
}
else if(strType=="tableObject")
{
//新建表格曲线
emit CallManage::getInstance()->sig_AddTableLine(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
}
// 接受拖拽事件
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
// 如果井名不正确,不接受拖拽事件
event->ignore();
}
}
else
{
// 如果数据格式不正确,不接受拖拽事件
event->ignore();
}
}
else
{
// 如果数据格式不正确,不接受拖拽事件
event->ignore();
}
// 恢复鼠标光标
//QApplication::restoreOverrideCursor();
}