📄 gpsdoc.cpp
字号:
// GpsDoc.cpp : implementation of the CGpsDoc class
//
#include "stdafx.h"
#include "Gps.h"
#include "MainFrm.h"
#include "GpsDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGpsDoc
IMPLEMENT_DYNCREATE(CGpsDoc, CDocument)
BEGIN_MESSAGE_MAP(CGpsDoc, CDocument)
//{{AFX_MSG_MAP(CGpsDoc)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGpsDoc construction/destruction
CGpsDoc::CGpsDoc()
{
// TODO: add one-time construction code here
NodeNumber=0;
ESource=NULL;
NSource=NULL;
IDSource=NULL;
HSource=NULL;
Fwj=NULL;
HadFwj=false;
}
CGpsDoc::~CGpsDoc()
{
}
BOOL CGpsDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CGpsDoc serialization
void CGpsDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
}
}
/////////////////////////////////////////////////////////////////////////////
// CGpsDoc diagnostics
#ifdef _DEBUG
void CGpsDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CGpsDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGpsDoc commands
////////////////////////////////////////////////////////////////////////////
//把得到的方位角数据以DOC格式存盘
///////////////////////////////////////////////////////////////////////////
void CGpsDoc::OnFileSave()
{
// TODO: Add your command handler code here
CFile mFile;
CString mPath;
CFileDialog dlg(false,"DOC",NULL,NULL,"WORD file(*.doc)|*.doc|",NULL);
if(dlg.DoModal()==IDOK)
mPath=dlg.GetPathName();
else
return;
if(!mFile.Open(mPath,CFile::modeWrite|CFile::modeCreate))
return;
if(HadFwj==true)
{
CString strE,strN,strFwj,strOut;
for(long i=0;i<NodeNumber-1;i++)
{
strE.Format("%f ",ESource[i]);
strN.Format("%f ",NSource[i]);
strFwj.Format("%f\n",Fwj[i]);
strOut=IDSource[i]+" "+strE+strN+HSource[i]+" "+strFwj;
int iLen=strOut.GetLength();
mFile.Write(strOut,iLen);
}
}
}
//////////////////////////////////////////////////////////
//读取源数据文件
/////////////////////////////////////////////////////////
void CGpsDoc::OnFileOpen()
{
// TODO: Add your command handler code here
long BeforeLen=0;CString mPath;//BeforeLen存放文件头的字节数
CFile mFile;
CFileDialog dlg(true,"TXT",NULL,NULL,"TXT file(*.txt)|*.txt|",NULL);//只限读取文本文件
if(dlg.DoModal()==IDOK)
mPath=dlg.GetPathName();
else
return;
if(!mFile.Open(mPath,CFile::modeRead))
{
return;
}
long FileLen=mFile.GetLength();
CArchive ar(&mFile, CArchive::load);
CString st="",stE,stN;
ar.ReadString(st);//读取第一行
if(st!="Input:")//第一行不是“Input:”字符串,不是需要的数据文件
{
AfxMessageBox("非法文件");
return;
}
BeforeLen=BeforeLen+st.GetLength();
for(long i=1;i<15;i++) //读取文件头把文件指针指向第一行数据
{ //并求出文件头的长度
ar.ReadString(st);
BeforeLen=BeforeLen+st.GetLength();
}
ar.ReadString(st);
long strLen=st.GetLength()+2;//求出每行数据的长度
long BackRow=(FileLen-BeforeLen)/strLen;//BackRow数据的行数
NodeNumber=BackRow;//得到打点数
IDSource=new CString[BackRow];
ESource=new double[BackRow];
NSource=new double[BackRow];
HSource=new CString[BackRow];
i=0;
while(i<BackRow-1)//读取每行数据,得到各点的X,Y坐标
{
ar.ReadString(st);
IDSource[i]=st.Left(13);
HSource[i]=st.Right(6);
stE=st.Mid(16,10);
stN=st.Mid(28,11);
ESource[i]=atof((LPCTSTR)stE);
NSource[i]=atof((LPCTSTR)stN);
i++;
}
st.Format("共有 %d 个点的数据被调入",BackRow);
AfxMessageBox(st);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -