📄 wgl_32doc.cpp
字号:
// wgl_32Doc.cpp : implementation of the CWgl_32Doc class
//
#include "stdafx.h"
#include "wgl_32.h"
#include <math.h>
#include "wgl_32Doc.h"
#include "Wgl_32View.h"
#include "Segment.h"
#include "CurveColor.h"
#include "ViewLine.h"
#include "ChildFrm.h"
#include "TreeDisp.h"
#include "righView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWgl_32Doc
const WORD CWgl_32Doc::ShortWidth = 4;
IMPLEMENT_DYNCREATE(CWgl_32Doc, CDocument)
BEGIN_MESSAGE_MAP(CWgl_32Doc, CDocument)
//{{AFX_MSG_MAP(CWgl_32Doc)
ON_COMMAND(ID_EDIT_SEGMENT, OnEditSegment)
ON_COMMAND(ID_CHANGECURVECOLOR, OnChangeCurveColor)
ON_COMMAND(ID_VIEW_GROUPSHOW, OnViewGroupShow)
ON_COMMAND(ID_VIEW_WHICHVALUE, OnViewWhichValue)
ON_UPDATE_COMMAND_UI(ID_VIEW_WHICHVALUE, OnUpdateViewWhichValue)
ON_COMMAND(ID_VIRTUE_VALUE, OnVirtueValue)
ON_UPDATE_COMMAND_UI(ID_VIRTUE_VALUE, OnUpdateVirtueValue)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWgl_32Doc construction/destruction
CWgl_32Doc::CWgl_32Doc()
{
bReadError = TRUE;
bFirstValue = FALSE;
bShowSubCurve = FALSE;
bDelSubCurve = FALSE;
m_ChannelNum = 0;
EndSampNum = 0;
m_StationName=_T("");
m_pChannel=NULL;
m_pSampRates=NULL;
SampleIndex=NULL;
RelateTime=NULL;
PSamplData=NULL;
m_pChannelIndex = NULL;
HalfCurveHeigh = 25;
m_ViewChannel = 0;
PageFromSampNum = 0;
m_XSizeFactor = 1.0;
nWhichCurve = -1;
LCursor = RCursor = 0;
LCursorA = RCursorA = 0.0;
DblVVT = DblAAT = 1.0;
DblVT = DblAT = 2.0;
bVirtualValue = FALSE;
ShortNodeNum = 2;
m_pShortNode = new ShortNode[ShortNodeNum];
m_pShortNode[0].bShow = 1;
m_pShortNode[0].lend = 0;
}
CWgl_32Doc::~CWgl_32Doc()
{
int i;
if(m_pShortNode)
delete[] m_pShortNode;
if(m_pChannel)
delete[] m_pChannel;
if(m_pChannelIndex)
{
for(i=0; i<m_ChannelNum; i++)
if(m_pChannelIndex[i].pSub)
delete[] m_pChannelIndex[i].pSub;
delete[] m_pChannelIndex;
}
if(m_pSampRates)
delete[] m_pSampRates;
if(SampleIndex)
delete[] SampleIndex;
if(RelateTime)
delete[] RelateTime;
if(PSamplData) {
for(i=0; i<m_ChannelNum; i++)
if(PSamplData[i])
delete PSamplData[i];
delete PSamplData;
}
}
/////////////////////////////////////////////////////////////////////////////
// CWgl_32Doc serialization
BOOL CWgl_32Doc::SetInitShowStatus(char *FileName)
{
if(FileName)
{
}
else
{
const COLORREF CurveColor[4] =
{ RGB(255,255,0), RGB(0,255,0), RGB(255,0,0), RGB(255,255,255) };
m_pShortNode[ShortNodeNum-1].bShow = 1;
m_pShortNode[ShortNodeNum-1].lend = EndSampNum;
mNumViewChannel = m_ChannelNum;
m_ViewChannelMax = m_ChannelNum-1;
m_ViewChannelMin = 0;
for(int i=0; i < m_ChannelNum; i++)
{
m_pChannelIndex[i].YFactor = 1.0;
m_pChannelIndex[i].Color = CurveColor[i%4];
m_pChannelIndex[i].bShow = 1;
m_pChannelIndex[i].No = i;
m_pChannelIndex[i].nNumb = 0;
m_pChannelIndex[i].pSub = NULL;
}
}
return TRUE;
}
BOOL CWgl_32Doc::LocateChr( const char *str, char ch, int& find, int* len, int from)
{
int leng;
if(len==NULL)
leng=strlen(str);
else
leng=*len;
while(from<leng)
if(str[from++]==ch) {
find=from-1;
return TRUE;
}
return FALSE;
}
BOOL CWgl_32Doc::OpenRelateConFig( const char *cfgFileName )
{
CStdioFile cfgFile;
if( !cfgFile.Open(cfgFileName,CFile::modeRead|CFile::typeText) )
{
bReadError = TRUE;
AfxMessageBox(_T("Can NOT open config file"), MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
WORD i;
const char ch=',';
int ind,len;
CString strTemp;
if( !cfgFile.ReadString(strTemp) ) goto reterror;
len=strTemp.GetLength();
LocateChr( strTemp, ch, ind, &len );
m_StationName = strTemp.Left(ind);
m_StationNum = strTemp.Right(len-ind-1);
if( !cfgFile.ReadString(strTemp) ) goto reterror;
if(sscanf(strTemp,"%u",&m_ChannelNum)!=1) goto reterror;
len=strTemp.GetLength();
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
if(sscanf(strTemp,"%u",&m_AnaNum)!=1) goto reterror;
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
if(sscanf(strTemp,"%u",&m_DigNum)!=1) goto reterror;
m_pChannel = new Channel[m_ChannelNum];
if(m_pChannel == NULL) goto reterror;
m_pChannelIndex = new ChannelNumber[m_ChannelNum];
if(m_pChannelIndex==NULL) goto reterror;
for(i=0; i < m_ChannelNum; i++)
{
WORD ChannelNum;
CString ChannelName;
if(!cfgFile.ReadString(strTemp)) goto reterror;
if(sscanf(strTemp,"%u",&ChannelNum)!=1) goto reterror;
len=strTemp.GetLength();
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
LocateChr( strTemp, ch, ind, &len );
ChannelName = strTemp.Left(ind);
len = len-ind-1;
strTemp = strTemp.Right(len);
m_pChannel[i].ChannelNum = ChannelNum;
m_pChannel[i].ChannelName = ChannelName;
long tempLong;
if( LocateChr( strTemp, ch, ind, &len ) )
{
m_pChannel[i].Phase = strTemp.Left(ind);
len = len-ind-1;
strTemp = strTemp.Right(len);
LocateChr( strTemp, ch, ind, &len );
m_pChannel[i].Monitor = strTemp.Left(ind);
len = len-ind-1;
strTemp = strTemp.Right(len);
LocateChr( strTemp, ch, ind, &len );
m_pChannel[i].Unit = strTemp.Left(ind);
m_pChannel[i].Unit.TrimLeft();
m_pChannel[i].Unit.TrimRight();
m_pChannel[i].Unit.FreeExtra();
if(m_pChannel[i].Unit == _T("V") || m_pChannel[i].Unit == _T("v")
|| m_pChannel[i].Unit == _T("KV") || m_pChannel[i].Unit == _T("kv")
|| m_pChannel[i].Unit == _T("kV") || m_pChannel[i].Unit == _T("Kv"))
m_pChannel[i].VAD = 1;
else
m_pChannel[i].VAD = 0;
len = len-ind-1;
strTemp = strTemp.Right(len);
double tempDouble;
if( sscanf(strTemp,"%lf",&tempDouble) != 1 ) goto reterror;
m_pChannel[i].a = tempDouble;
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
if( sscanf(strTemp,"%lf",&tempDouble) != 1 ) goto reterror;
m_pChannel[i].b = tempDouble;
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
if( sscanf(strTemp,"%lf",&tempDouble) != 1 ) goto reterror;
m_pChannel[i].skew = tempDouble;
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
if( sscanf(strTemp,"%ld",&tempLong) != 1 ) goto reterror;
m_pChannel[i].min = tempLong;
LocateChr( strTemp, ch, ind, &len );
len = len-ind-1;
strTemp = strTemp.Right(len);
long tempLongA;
if( sscanf(strTemp,"%ld",&tempLongA) != 1 ) goto reterror;
m_pChannel[i].max = tempLongA;
if(tempLongA == tempLong) goto reterror;
}
else //DigChannel
{
m_pChannel[i].VAD = -1;
if(sscanf(strTemp,"%ld",&tempLong)!=1) goto reterror;
m_pChannel[i].min = tempLong;
}
}
for(i=0; i<m_ChannelNum; i++)
{
m_pChannel[i].ChannelName.TrimLeft();
m_pChannel[i].ChannelName.TrimRight();
m_pChannel[i].ChannelName.FreeExtra();
if(m_pChannel[i].VAD>=0)
{
m_pChannel[i].Phase.TrimLeft();
m_pChannel[i].Phase.TrimRight();
m_pChannel[i].Phase.FreeExtra();
m_pChannel[i].Monitor.TrimLeft();
m_pChannel[i].Monitor.TrimRight();
m_pChannel[i].Monitor.FreeExtra();
}
}
if(!cfgFile.ReadString(strTemp)) goto reterror;
if(sscanf(strTemp,"%f",&m_FreqPhase)!=1) goto reterror;
if(!cfgFile.ReadString(strTemp)) goto reterror;
if(sscanf(strTemp,"%u",&m_NumRates)!=1) goto reterror;
m_pSampRates = new SampRates[m_NumRates];
if(m_pSampRates==NULL) goto reterror;
for(i=0; i<m_NumRates; i++)
{
float SampRate;
if(!cfgFile.ReadString(strTemp)) goto reterror;
if(sscanf(strTemp,"%f,%lu",&SampRate,&EndSampNum)!=2) goto reterror;
m_pSampRates[i].SampRate = SampRate;
m_pSampRates[i].EndSampNum = EndSampNum;
}
if(!cfgFile.ReadString(DateTime1)) goto reterror;
if(!cfgFile.ReadString(DateTime2)) goto reterror;
if(!cfgFile.ReadString(strTemp)) goto reterror;
strncpy(FileType,strTemp,9);
DateTime1.TrimLeft();
DateTime1.TrimRight();
DateTime1.FreeExtra();
DateTime2.TrimLeft();
DateTime2.TrimRight();
DateTime2.FreeExtra();
cfgFile.Close();
i = 0;
while(i < m_ChannelNum)
if(m_pChannel[i].VAD == 0)
if(m_pChannel[i].max==999999)
continue;
else
break;
else
i++;
if(i < m_ChannelNum)
{
maxA = m_pChannel[i].max;
minA = m_pChannel[i].min;
double r1,r2;
r1 = maxA-minA;
nWhichA = i;
i++;
for(; i < m_ChannelNum; i++)
if(m_pChannel[i].VAD == 0)
{
if(m_pChannel[i].max==999999)
continue;
r2 = m_pChannel[i].max-m_pChannel[i].min;
if(r1 < r2)
{
r1 = r2;
maxA = m_pChannel[i].max;
minA = m_pChannel[i].min;
nWhichA = i;
}
}
}
i = 0;
while(i < m_ChannelNum)
if(m_pChannel[i].VAD == 1)
if(m_pChannel[i].max==999999)
continue;
else
break;
else
i++;
if(i < m_ChannelNum)
{
maxV = m_pChannel[i].max;
minV = m_pChannel[i].min;
double r1,r2;
r1 = maxV-minV;
nWhichV = i;
i++;
for(; i < m_ChannelNum; i++)
if(m_pChannel[i].VAD == 1)
{
if(m_pChannel[i].max==999999)
continue;
r2 = m_pChannel[i].max-m_pChannel[i].min;
if(r1 < r2)
{
r1 = r2;
maxV = m_pChannel[i].max;
minV = m_pChannel[i].min;
nWhichV = i;
}
}
}
return TRUE;
reterror:
cfgFile.Close();
return FALSE;
}
typedef long* m_pmylong;
BOOL CWgl_32Doc::ReadThisDataFile( CArchive& ar )
{
char *pdest1,*pdest2;
unsigned long i;
SampleIndex=new double[EndSampNum];
if(SampleIndex==NULL) return FALSE;
RelateTime=new double[EndSampNum];
if(RelateTime==NULL)
return FALSE;
PSamplData=new m_pmylong[m_ChannelNum];
for(WORD wi=0; wi<m_ChannelNum; wi++)
PSamplData[wi] = NULL;
for(wi=0; wi<m_ChannelNum; wi++)
{
PSamplData[wi] = new long[EndSampNum];
if(PSamplData[wi]==NULL)
return FALSE;
}
CString strTemp;
for(i=0; i<EndSampNum; i++)
{
if(!ar.ReadString( strTemp )) return FALSE;
sscanf(strTemp,"%lf,%lf",&SampleIndex[i],&RelateTime[i]);
pdest1 = strchr(strTemp, ',');
for(wi=0; wi<m_ChannelNum; wi++)
{
pdest2 = strchr(pdest1+1, ',');
sscanf(pdest2+1,"%ld",&PSamplData[wi][i]);
pdest1 = pdest2;
}
}
return TRUE;
}
void CWgl_32Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
}
else
{
char cfgFileName[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
m_strRecordPath.Empty();
strcpy(cfgFileName,ar.m_strFileName);
_splitpath(cfgFileName,drive,dir,fname,ext);
strcpy(ext,"cfg");
_makepath(cfgFileName,drive,dir,fname,ext);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -