277 lines
8.0 KiB
C++
277 lines
8.0 KiB
C++
#include "ShowWave.h"
|
||
#include "ui_ShowWave.h"
|
||
#include <QPainter>
|
||
#include <QComboBox>
|
||
#include <QDebug>
|
||
#include <QMessageBox>
|
||
#include <QResizeEvent>
|
||
#include <QTextCodec>
|
||
ShowWave::ShowWave(QWidget *parent) :
|
||
QWidget(parent),
|
||
m_pUI(new Ui::ShowWave)
|
||
{
|
||
m_pUI->setupUi(this);
|
||
int w=width();
|
||
int h=height();
|
||
if(NULL != parent)
|
||
{
|
||
parent->setFixedSize(w,h);
|
||
}
|
||
connect(m_pUI->verticalSlider,SIGNAL(valueChanged(int)),this,SLOT(onVerDeptSliderValueChange(int)));
|
||
connect(m_pUI->horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(onHorTimeSliderValueChange(int)));
|
||
QObject::connect(m_pUI->checkBox, SIGNAL(clicked()), this, SLOT(slotCheck()));
|
||
connect(m_pUI->deptEdit->lineEdit_Depth, SIGNAL(textChanged( QString )),this,SLOT(slotChangeDepth(QString)));
|
||
connect(m_pUI->lineEdit_Time, SIGNAL(textChanged( QString )),this,SLOT(slotChangeTime(QString)));
|
||
connect(m_pUI->lineEdit_Value, SIGNAL(textChanged( QString )),this,SLOT(slotChangeValue(QString)));
|
||
connect(m_pUI->lineEdit_XGrid, SIGNAL(textChanged( QString )),this,SLOT(slotChangeXGrid(QString)));
|
||
connect(m_pUI->lineEdit_YGrid, SIGNAL(textChanged( QString )),this,SLOT(slotChangeYGrid(QString)));
|
||
memset(&waveinfo,0,sizeof(Slf_WAVE));
|
||
//QFile *waveFile;
|
||
val=NULL;
|
||
//int count;
|
||
sdep=0,edep=0,stime=0,etime=0,curTime=0,curDepth=0;
|
||
}
|
||
void ShowWave::init()
|
||
{
|
||
CLogIO *logio=new CLogIO();
|
||
if(!logio->Open(FileName.toStdString().c_str(),CSlfIO::modeRead)) {
|
||
delete logio;
|
||
return;
|
||
}
|
||
index=logio->OpenWave(WaveName.toStdString().c_str());
|
||
if(index==-1) {
|
||
delete logio;
|
||
return;
|
||
}
|
||
logio->GetWaveInfo(index,&waveinfo);
|
||
sdep=waveinfo.StartDepth;
|
||
edep=waveinfo.EndDepth;
|
||
stime=waveinfo.StartTime;
|
||
etime=waveinfo.StartTime+(waveinfo.SamplePoint-0)*waveinfo.ArrayNum*waveinfo.TimeLevel;//TimeSamples=SamplePoint*ArrayNum
|
||
curTime=waveinfo.StartTime+(etime-stime)/2.;
|
||
curDepth=sdep+(edep-sdep)/2.;
|
||
//X轴网格数
|
||
int xGrid=10;
|
||
for(int i=9;i>=5;i--)
|
||
{
|
||
if(int(etime-stime)%i==0)
|
||
{
|
||
xGrid=i;
|
||
break;
|
||
}
|
||
}
|
||
//count=(waveinfo.EndDepth-waveinfo.StartDepth)/waveinfo.DepLevel+1.5;
|
||
val=new float[waveinfo.SamplePoint*waveinfo.ArrayNum+1];
|
||
IsFirst=1;
|
||
bindViewData();
|
||
IsFirst=0;
|
||
//需要罗林解决的问题:
|
||
//1、"阵列曲线"显示乱码(已解决)
|
||
//2、时间及深度change函数不能刷新时间或深度slider,时间及深度值无效值没做任何处理(读数据起始深度都为0 造成 )
|
||
|
||
// QString title= QString::fromLocal8Bit("阵列曲线")+QString( waveinfo.Name);
|
||
QString title= QString::fromUtf8("阵列曲线")+QString( waveinfo.Name);
|
||
m_pUI->label_WfName->setText(title);
|
||
//m_pUI->label_WfName->setText(QString(QLatin1String(waveinfo.Name)));
|
||
m_pUI->label_StartTime->setText(QString::number(stime));
|
||
m_pUI->label_EndTime->setText(QString::number(etime));
|
||
m_pUI->label_StartDepth->setText(QString::number(sdep));
|
||
m_pUI->label_EndDepth->setText(QString::number(edep));
|
||
m_pUI->lineEdit_Time->setText(QString::number(curTime));
|
||
m_pUI->deptEdit->lineEdit_Depth->setText(QString::number(curDepth));
|
||
|
||
QPalette pal;
|
||
m_pUI->widgetPlot->setStyleSheet("background:lightgray");
|
||
m_pUI->widgetPlot->setPalette(pal);
|
||
m_view.setParent(m_pUI->widgetPlot);
|
||
m_view.setCount(waveinfo.SamplePoint);
|
||
m_view.m_Xmin=stime,m_view.m_Xmax=etime;
|
||
m_view.setXGrid(xGrid);
|
||
m_view.setYGrid(D_HOR_LIENS);
|
||
m_pUI->lineEdit_YGrid->setText(QString::number(D_HOR_LIENS));
|
||
m_pUI->lineEdit_XGrid->setText(QString::number(xGrid));
|
||
m_pUI->verticalSlider->setRange(0,100);
|
||
m_pUI->verticalSlider->setValue(50);
|
||
m_pUI->horizontalSlider->setRange(0,100);//(stime,etime);
|
||
m_pUI->horizontalSlider->setValue(50);//(curTime);
|
||
m_pUI->checkBox->setCheckState(Qt::Checked);
|
||
m_pUI->lineEdit_Ymin->setEnabled(0);
|
||
m_pUI->lineEdit_Ymax->setEnabled(0);
|
||
logio->CloseWave(index);
|
||
delete logio;
|
||
}
|
||
void ShowWave::slotCheck()
|
||
{
|
||
if(m_pUI->checkBox->checkState()==Qt::Unchecked)
|
||
{
|
||
m_pUI->lineEdit_Ymin->setEnabled(1);
|
||
m_pUI->lineEdit_Ymax->setEnabled(1);
|
||
}
|
||
else
|
||
{
|
||
m_pUI->lineEdit_Ymin->setEnabled(0);
|
||
m_pUI->lineEdit_Ymax->setEnabled(0);
|
||
}
|
||
bindViewData();
|
||
m_view.update();
|
||
}
|
||
void ShowWave::slotChangeXGrid(const QString &text)
|
||
{
|
||
int xGrid=text.toInt();
|
||
if(xGrid<1)
|
||
{
|
||
xGrid=1;
|
||
m_pUI->lineEdit_XGrid->setText(QString::number(xGrid));
|
||
}
|
||
if(xGrid>20)
|
||
{
|
||
xGrid=20;
|
||
m_pUI->lineEdit_XGrid->setText(QString::number(xGrid));
|
||
}
|
||
m_view.setXGrid(xGrid);
|
||
m_view.update();
|
||
}
|
||
void ShowWave::slotChangeYGrid(const QString &Text)
|
||
{
|
||
int yGrid=Text.toInt();
|
||
if(yGrid<1)
|
||
{
|
||
yGrid=1;
|
||
m_pUI->lineEdit_YGrid->setText(QString::number(yGrid));
|
||
}
|
||
if(yGrid>20)
|
||
{
|
||
yGrid=20;
|
||
m_pUI->lineEdit_YGrid->setText(QString::number(yGrid));
|
||
}
|
||
m_view.setYGrid(yGrid);
|
||
m_view.update();
|
||
}
|
||
void ShowWave::slotChangeDepth(const QString &text)
|
||
{
|
||
if(text.toFloat()<sdep||text.toFloat()>edep)
|
||
{
|
||
// m_pUI->lineEdit_Depth->setText(QString::number(curDepth));
|
||
return;
|
||
}
|
||
curDepth=text.toFloat();
|
||
//根据输入的深度,定位verticalSlider保证lineEdit_Depth与verticalSlider同步
|
||
//int location=100.*(text.toFloat()-stime)/(etime-stime);
|
||
//int pos=100.*(edep-curDepth)/(edep-sdep);
|
||
//m_pUI->verticalSlider->setValue(pos);
|
||
bindViewData();
|
||
m_view.update();
|
||
}
|
||
void ShowWave::slotChangeValue(const QString &text)
|
||
{
|
||
//if(text.toFloat()<stime||text.toFloat()>etime)return;
|
||
// curDepth=edep-value*(edep-sdep)/100;
|
||
//m_pUI->lineEdit_Depth->setText(QString::number(curDepth));
|
||
//bindViewData();
|
||
//m_view.update();
|
||
}
|
||
void ShowWave::slotChangeTime(const QString &text)
|
||
{
|
||
if(text.toFloat()<stime||text.toFloat()>etime)return;
|
||
//根据输入的时间,定位horizontalSlider保证lineEdit_Time与horizontalSlider同步
|
||
//int location=100.*(text.toFloat()-stime)/(etime-stime);
|
||
//m_pUI->horizontalSlider->setValue(location);
|
||
//
|
||
curTime=text.toFloat();
|
||
int pos=(curTime-stime)/waveinfo.TimeLevel;
|
||
m_pUI->lineEdit_Value->setText(QString::number(val[pos]));
|
||
m_view.setTime(pos);
|
||
m_view.update();
|
||
}
|
||
void ShowWave::resizeEvent(QResizeEvent *resize)
|
||
{
|
||
QSize orgsize=this->size();
|
||
QWidget::resizeEvent(resize);
|
||
|
||
if(resize->size().isValid())
|
||
{
|
||
QSize changeSize=resize->size();
|
||
int width=changeSize.width()-orgsize.width();
|
||
int height= changeSize.height()-orgsize.height();
|
||
|
||
m_view.resize(changeSize.width()-150,changeSize.height()-100);
|
||
m_view.initView();
|
||
m_view.update();
|
||
}
|
||
}
|
||
void ShowWave::onVerDeptSliderValueChange(int value)
|
||
{
|
||
curDepth=edep-value*(edep-sdep)/100;
|
||
m_pUI->deptEdit->lineEdit_Depth->setText(QString::number(curDepth));
|
||
bindViewData();
|
||
m_view.update();
|
||
}
|
||
|
||
void ShowWave::onHorTimeSliderValueChange(int value)
|
||
{
|
||
curTime=stime+value*(etime-stime)/100;
|
||
int pos=(curTime-stime)/waveinfo.TimeLevel;
|
||
curTime=pos*waveinfo.TimeLevel+stime;//此步计算为了保证显示的时间等于采样时间
|
||
m_pUI->lineEdit_Time->setText(QString::number(curTime));//value));
|
||
|
||
m_pUI->lineEdit_Value->setText(QString::number(val[pos]));
|
||
m_view.setTime(pos);
|
||
m_view.update();
|
||
}
|
||
|
||
void ShowWave::bindViewData()
|
||
{
|
||
readwave();
|
||
m_view.setValues(val);
|
||
if(m_pUI->checkBox->checkState()==Qt::Unchecked)
|
||
{
|
||
m_view.m_Ymin=m_pUI->lineEdit_Ymin->text().toFloat();
|
||
m_view.m_Ymax=m_pUI->lineEdit_Ymax->text().toFloat();
|
||
}
|
||
}
|
||
void ShowWave::showEvent(QShowEvent *sEvent)
|
||
{
|
||
QWidget::showEvent(sEvent);
|
||
|
||
QRect rec=m_pUI->widgetPlot->geometry();
|
||
qDebug()<<"value:"<<rec;
|
||
int w=rec.width();
|
||
int h=rec.height();
|
||
//m_view.widgetRec=QRect(0,0,w,h);
|
||
m_view.setGeometry(0,0,w,h);
|
||
|
||
m_view.initView();
|
||
//m_pUI->widgetPlot->update();
|
||
}
|
||
void ShowWave::readwave()
|
||
{
|
||
CLogIO *logio=new CLogIO();
|
||
if(logio->Open(FileName.toStdString().c_str(),CSlfIO::modeRead))
|
||
{
|
||
int index=logio->OpenWave(WaveName.toStdString().c_str());
|
||
if(index>-1)logio->ReadWave(index,curDepth,1,&val[0]);
|
||
}
|
||
delete logio;
|
||
vmax=vmin=val[0];
|
||
for(int i=1;i<waveinfo.SamplePoint;i++)
|
||
{
|
||
if(vmax<val[i])vmax=val[i];
|
||
if(vmin>val[i])vmin=val[i];
|
||
}
|
||
//vmin=10,vmax=110;
|
||
m_view.m_Ymax=vmax,m_view.m_Ymin=vmin;
|
||
if(IsFirst)
|
||
{
|
||
m_pUI->lineEdit_Ymax->setText(QString::number(vmax));
|
||
m_pUI->lineEdit_Ymin->setText(QString::number(vmin));
|
||
}
|
||
}
|
||
ShowWave::~ShowWave()
|
||
{
|
||
delete m_pUI;
|
||
//waveFile->close();
|
||
//delete waveFile;
|
||
delete []val;
|
||
}
|
||
|