?? trajfileaccess.cpp
字號:
// TrajFileAccess.cpp: implementation of the CTrajFileAccess class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RADIO.h"
#include "TrajFileAccess.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTrajFileAccess::CTrajFileAccess()
{m_bFileInitialized=FALSE;
}
CTrajFileAccess::~CTrajFileAccess()
{
}
BOOL CTrajFileAccess::InitializeFileAccess(LPCTSTR lpszFileName)
{//初始化時讀了一個時間點的數據,文件位置也在第一個數據包之后
CFileException fileExcep;
m_fileTraj.Open(lpszFileName, CFile::modeRead,&fileExcep);
if(fileExcep.m_cause!=CFileException::none)
{ fileExcep.ReportError();
return FALSE;
}
int pbuf[1];
TRY{
m_fileTraj.SeekToBegin();
m_fileTraj.Read(pbuf, sizeof(int));}
CATCH(CFileException, pEx){
m_fileTraj.Close();
pEx->ReportError();
}
END_CATCH
m_npackageCount=pbuf[0];
m_nCurrentPackageIndex=1;
if (m_npackageCount<=0){
AfxMessageBox("航跡數據文件格式錯誤!");
return FALSE;
}
DWORD dwFileLength;
TRY{
dwFileLength=m_fileTraj.GetLength();
}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
DWORD dwLength=m_npackageCount*sizeof(TRAJ)+sizeof(int);
if(dwLength!=dwFileLength){
AfxMessageBox("航跡數據文件格式錯誤!");
return FALSE;
}
TRY{
m_fileTraj.Read(&m_CurrentPackageData, sizeof(TRAJ));}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
m_bFileInitialized=TRUE;
//計算航跡時間周期
TRAJ secondPackageData;
TRY{
m_fileTraj.Read(&secondPackageData, sizeof(TRAJ));
}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
m_dPeroid=secondPackageData.t-m_CurrentPackageData.t;
if(m_dPeroid<=0){
AfxMessageBox("航跡數據文件格式錯誤!");
return FALSE;
}
TRY{
m_fileTraj.Seek(-(LONG)sizeof(TRAJ),CFile::current);
}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
return TRUE;
}
void CTrajFileAccess::EndFileAccess()
{
TRY{
if(m_fileTraj.m_hFile!=CFile::hFileNull) {
m_fileTraj.Close();
m_fileTraj.m_hFile=CFile::hFileNull;
}
}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
}
BOOL CTrajFileAccess::RefreshCurrentPackageByStep(LONG step)
//更新當前TRAJ數據包,step可以為正也可以為負,index超出了范圍則返回FALSE,更新成功返回TRUE
{
if(!m_bFileInitialized) {
AfxMessageBox("文件未初始化錯誤!");
return FALSE;
}
if(step==0) return TRUE;
LONG lIndex=m_nCurrentPackageIndex+step;
if (lIndex<=0 ) {
AfxMessageBox("數據包索引溢出!");
return FALSE;
}
if((DWORD)lIndex>m_npackageCount){
return FALSE;
}
TRY{
m_fileTraj.Seek((LONG)((step-1)*sizeof(TRAJ)),CFile::current);
}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
TRY{
m_fileTraj.Read(&m_CurrentPackageData, sizeof(TRAJ));}
CATCH(CFileException, pEx){
pEx->ReportError();
}
END_CATCH
m_nCurrentPackageIndex+=step;
return TRUE;
}
BOOL CTrajFileAccess::RefreshCurrentPackageByTime(double time)
{ if(!m_bFileInitialized) {
AfxMessageBox("文件未初始化錯誤!");
return FALSE;
}
if(time<0) {
AfxMessageBox("時間索引錯誤!");
return FALSE;
}
double previouTime=m_CurrentPackageData.t;
double eTime=time-previouTime;
double dStep=eTime/m_dPeroid;
LONG lStep;
if(dStep>1.0e-6){
lStep=(LONG)(dStep+.5);//加0.5是四舍五入
}
else if(dStep<-1.0e-6){
lStep=-(LONG)(-dStep+.5);
}else{
lStep=0;
}
return RefreshCurrentPackageByStep(lStep);
}
TRAJ CTrajFileAccess::GetCurrentPackageData()
{
return m_CurrentPackageData;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -