📄 myesupermapview.cpp
字号:
// MyeSuperMapView.cpp : implementation of the CMyeSuperMapView class
//
#include "stdafx.h"
#include "MyeSuperMap.h"
#include "MyeSuperMapDoc.h"
#include "MyeSuperMapView.h"
#include "CheckTower.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyeSuperMapView
IMPLEMENT_DYNCREATE(CMyeSuperMapView, CView)
BEGIN_MESSAGE_MAP(CMyeSuperMapView, CView)
//{{AFX_MSG_MAP(CMyeSuperMapView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_COMMAND(ID_MAP_ZOOMIN, OnMapZoomin)
ON_COMMAND(ID_MAP_REFRESH, OnMapRefresh)
ON_COMMAND(ID_MAP_ZOOMOUT, OnMapZoomout)
ON_COMMAND(ID_NEXT_PANE, OnNextPane)
ON_COMMAND(ID_MAP_PAN, OnMapPan)
ON_COMMAND(ID_MAP_VIEWENTIRE, OnMapViewentire)
ON_COMMAND(IDC_EDIT_ADDPOINT, OnEditAddpoint)
ON_COMMAND(ID_GPS_OPEN, OnGpsOpen)
ON_COMMAND(ID_GPS_CLOSE, OnGpsClose)
ON_COMMAND(ID_GPS_SHOW_ON_MAP, OnGpsShowOnMap)
ON_UPDATE_COMMAND_UI(ID_GPS_SHOW_ON_MAP, OnUpdateGpsShowOnMap)
ON_COMMAND(ID_GPS_SHOW_DATA, OnGpsShowData)
ON_UPDATE_COMMAND_UI(IDC_EDIT_ADDPOINT, OnUpdateEditAddpoint)
ON_COMMAND(IDC_WRITETOFILE, OnWritetofile)
ON_COMMAND(ID_ADD_TOWER, OnAddTower)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyeSuperMapView construction/destruction
CMyeSuperMapView::CMyeSuperMapView()
{
//初始化
m_bFileOpened = false;
m_bGPSOpened = false;
m_bShowGPSonMap = false;
m_strEditableLayer = "";
m_TowerNumber = 0;
}
CMyeSuperMapView::~CMyeSuperMapView()
{
}
BOOL CMyeSuperMapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyeSuperMapView drawing
void CMyeSuperMapView::OnDraw(CDC* pDC)
{
CMyeSuperMapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//读出txt文件
bool flag ;
CFile file;
WCHAR *pBuf = NULL;
DWORD dwLen;
if(file.Open(L"\\My Documents\\temp.txt",CFile::modeRead,NULL))
{
dwLen = file.GetLength();
pBuf = new WCHAR[dwLen];
if (NULL == pBuf)
{
file.Close();
dwLen = 0;
}
file.Read(pBuf, dwLen);
file.Close();
}
// delete[] pBuf; //pBuf指向的dwLen长的空间中,保存的就是读取的内容.
//{{显示地图
CRect rcClient,p;
GetClientRect( &rcClient );
// p.left = 0;
// p.right = rcClient.right;
// p.top = 0 ;
// p.bottom = 20;
// pDC->DrawText(L"巡线员1",p,NULL);
// p.top += 20;
// p.bottom += 20;
// pDC->DrawText(L"线路1",p,NULL);
CString str,str1,str2;
INT i = 1;
//f.Open(L"\\My Documents\\temp.txt",CFile::modeRead,NULL);
if(dwLen != 0)
{
p.left = 0;
p.right = rcClient.right;
p.top = 0 ;
p.bottom = 20;
str = L"巡线员";
while(flag)
{
if((pBuf[i] != ' ')&&(i<dwLen/2))
{
str1 += pBuf[i];
i++;
}
else
flag = false;
}
m_PersonNumber = str1;
str += str1;
pDC->DrawText(str,p,NULL);
p.top += 20;
p.bottom += 20;
str.Empty();
str = L"线路";
flag = true;
i++;
while(flag)
{
if(pBuf[i] != ' '&&i<dwLen/2)
{
str2 += pBuf[i];
i++;
}
else
flag = false;
}
m_LineNumber = str2;
str += str2;
pDC->DrawText(str,p,NULL);
str1.Empty();
str2.Empty();
for(i++; i<dwLen/2;i+=1)
{
p.top += 20;
p.bottom += 20;
str.Empty();
str = L"杆塔";
flag = true;
while(flag)
{
if(pBuf[i] != ' '&&i<dwLen/2)
{
str += pBuf[i];
i++;
}
else
flag = false;
}
//str.Format(L"线路%c",pBuf[i]);
//p.top += 20;
//p.bottom += 20;
m_TowerNumber++;
pDC->DrawText(str,p,NULL);
}
}
// p.top += 20;
//p.bottom += 20;
//str.Format(L"共有杆塔%d个",m_TowerNumber);
//pDC->DrawText(str,p,NULL);
delete []pBuf;
pDC->MoveTo(0,20);
pDC->LineTo(rcClient.right,20);
pDC->MoveTo(0,40);
pDC->LineTo(50,40);
pDC->MoveTo(50,20);
pDC->LineTo(50,rcClient.bottom);
rcClient.top = rcClient.top + 50;
rcClient.left = rcClient.left + 60;
if( m_bFileOpened )
{
m_MapWnd.OnDraw( pDC, rcClient, rcClient );
}
else
{
pDC->FillSolidRect( &rcClient, RGB(255,255,255) );
}
//}}显示地图
//在地图上显示当前位置--开始
if( m_bShowGPSonMap )
{
DrawGPSonMap( pDC );
}
//在地图上显示当前位置--结束
}
/////////////////////////////////////////////////////////////////////////////
// CMyeSuperMapView diagnostics
#ifdef _DEBUG
void CMyeSuperMapView::AssertValid() const
{
CView::AssertValid();
}
void CMyeSuperMapView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyeSuperMapDoc* CMyeSuperMapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyeSuperMapDoc)));
return (CMyeSuperMapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyeSuperMapView message handlers
void CMyeSuperMapView::OnFileOpen()
{
CFileDialog dlgFile( true, _T(""), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("WorkSpace Files (*.pmw)|*.pmw") );
//弹出对话框选择工作空间文件
if( dlgFile.DoModal() == IDOK )
{
//如果已经打开工作空间文件,则先关闭
if( theApp.m_WorkSpace.IsOpen() )
{
theApp.m_WorkSpace.Close();
m_MapWnd.Close();
m_bFileOpened = false;
}
//获得图形文件的完整路径及文件名
CString strFileName = dlgFile.GetPathName();
//打开工作空间
if( theApp.m_WorkSpace.Open( strFileName ) )
{
//与地图窗口关联
m_MapWnd.OnInitialUpdate( &theApp.m_WorkSpace, this );
//获取地图列表
CSeMaps *pMaps = theApp.m_WorkSpace.GetMaps();
if( pMaps )
{
if( pMaps->GetMapCount() > 0 )
{//如果有定义好的地图就打开第一个地图
CSeMapDef MapDef;
//打开地图方法一: 通过名字取地图
CString strMapName = pMaps->GetMapNameAt(0);
if( pMaps->GetMap( strMapName, MapDef ) )
{
if( m_MapWnd.OpenMap( MapDef ) )
{
m_MapWnd.Refresh();
}
}
}
else
{//没有地图,打开第一个数据源的第一个数据集作为当前地图
CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );
if( pDataSource && pDataSource->GetDatasetCount() > 0 )
{
//取第一个数据集添加到地图窗口中
CSeDataset *pDataset = pDataSource->GetDatasetAt( 0 );
if( pDataset )
{
m_MapWnd.AddLayer( pDataset );
m_MapWnd.Refresh();
}
}
}
}
m_bFileOpened = true;
}
}
}
void CMyeSuperMapView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_MapWnd.OnLButtonDown(nFlags, point);
CView::OnLButtonDown(nFlags, point);
}
void CMyeSuperMapView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MapWnd.OnLButtonUp(nFlags, point);
CView::OnLButtonUp(nFlags, point);
}
void CMyeSuperMapView::OnFileClose()
{
theApp.m_WorkSpace.Close();
m_MapWnd.Close();
m_bFileOpened = false;
m_MapWnd.Refresh();
}
//放大
void CMyeSuperMapView::OnMapZoomin()
{
m_MapWnd.SetAction( CSeDrawParameters::uaZoomIn );
}
//刷新
void CMyeSuperMapView::OnMapRefresh()
{
m_MapWnd.Refresh();
}
//缩小
void CMyeSuperMapView::OnMapZoomout()
{
m_MapWnd.SetAction( CSeDrawParameters::uaZoomOut );
}
void CMyeSuperMapView::OnNextPane()
{
// TODO: Add your command handler code here
}
//平移地图
void CMyeSuperMapView::OnMapPan()
{
m_MapWnd.SetAction( CSeDrawParameters::uaPan );
}
//整幅显示
void CMyeSuperMapView::OnMapViewentire()
{
m_MapWnd.ViewEntire();
}
void CMyeSuperMapView::OnEditAddpoint()
{//设置或取消用户操作为添加点对象
if( m_MapWnd.GetAction() == CSeDrawParameters::uaEditCreatePoint )
{
m_MapWnd.SetAction( CSeDrawParameters::uaNull );
}
else
{
m_MapWnd.SetAction( CSeDrawParameters::uaEditCreatePoint );
}
}
//打开GPS接收器
void CMyeSuperMapView::OnGpsOpen()
{
//如果已经打开过,就先关闭,然后再打开
if( m_bGPSOpened )
{
m_GPSReceiver.Close();
}
// 假定GPS设备参数为: 4800, 8, N, 1
CSeCommPortInfo CommPortInfo;
//CommPortInfo.dwBaudRate = 4800; //波特率 4800
CommPortInfo.dwBaudRate = 9600; //波特率 9600
CommPortInfo.btDataBits = 8; //数据位 8
CommPortInfo.btParity = SE_PARITY_NONE; //校验位 N
CommPortInfo.btStopBits = SE_STOPBITS_1; //停止位 1
// 假定PDA使用COM4为GPS设备的连接端口
CommPortInfo.btCommPort = 4; //端口位 COM4
// 假定GPS设备输出 NMEA0183 协议数据, 则选用NMEA0183协议解析器
CSeGPS::Type nPaserType = CSeGPS::NMEA0183;
m_bGPSOpened = m_GPSReceiver.Open( CommPortInfo, nPaserType );
if( m_bGPSOpened )
{
AfxMessageBox( _T("连接GPS成功!") );
//如果连接成功, 则设置Timer时间
//SetTimer();
}
else
{
AfxMessageBox( _T("连接GPS失败!") );
}
}
void CMyeSuperMapView::OnGpsClose()
{
//关闭GPS设备
if( m_bGPSOpened )
{
m_GPSReceiver.Close();
}
}
void CMyeSuperMapView::OnGpsShowOnMap()
{
//如果打开成功了才有可能取出解析好的GPS数据
if( m_bGPSOpened )
{
//如果获取数据成功, 就用某一种方式来表现他
if( m_GPSReceiver.GetData( m_GPSData ) )
{
//在这里,简单用一个字符串来表现。
//在具体的应用中,可以用一个对话框来显示各项GPS数据
//从GPS解析出来的经纬度数据以 0.01 秒为单位, 在此转成 与 数据源坐标系统一直的单位 0.001秒
m_pntGPS.x = m_GPSData.dwLongitude * 10;
m_pntGPS.y = m_GPSData.dwLatitude * 10;
m_bShowGPSonMap = !m_bShowGPSonMap;
//刷新地图
m_MapWnd.SetCenter( m_pntGPS );
m_MapWnd.Refresh();
}
else
{
AfxMessageBox( _T("读不到GPS数据") );
}
}
else
{
AfxMessageBox( _T("没有打开GPS设备") );
}
}
//显示一个红色方块表示当前点
void CMyeSuperMapView::DrawGPSonMap(CDC *pDC)
{
CPoint pntDraw( m_pntGPS );
//转换成屏幕坐标
m_MapWnd.GetDrawParam()->MapToClient( &pntDraw, 1 );
//在这里,简单绘制一个"红色方块"来表现。
//在具体的应用中,可以用一个有意义的图标来显示
pDC->FillSolidRect( pntDraw.x-3, pntDraw.y-3, 6, 6, RGB( 0, 255, 0 ) );
/*//显示导航信息
if( m_strNaviInfo.GetLength() > 0 )
{
CRect rc( 5, 30, 155, 50 );
pDC->DrawText( m_strNaviInfo, &rc, 0 );
}*/
}
void CMyeSuperMapView::OnUpdateGpsShowOnMap(CCmdUI* pCmdUI)
{
//在选中的菜单项上打勾以做标识
pCmdUI->SetCheck( m_bShowGPSonMap );
}
void CMyeSuperMapView::OnGpsShowData()
{
//如果打开成功了才有可能取出解析好的GPS数据
if( m_bGPSOpened )
{
//如果获取数据成功, 就用某一种方式来表现他
if( m_GPSReceiver.GetData( m_GPSData ) )
{
//在这里,简单用一个字符串来表现。
//在具体的应用中,可以用一个对话框来显示各项GPS数据
//从GPS解析出来的经纬度数据以 0.01 秒为单位
long nLongitudeDu = m_GPSData.dwLongitude / 360000;
long nLongitudeFen = ( m_GPSData.dwLongitude % 360000 ) / 6000;
long nLongitudeMiao = ( m_GPSData.dwLongitude % 360000 ) % 6000;
long nLatitudeDu = m_GPSData.dwLatitude / 360000;
long nLatitudeFen = ( m_GPSData.dwLatitude % 360000 ) / 6000;
long nLatitudeMiao = ( m_GPSData.dwLatitude % 360000 ) % 6000;
//从GPS解析出来的速度以 厘米/小时 为单位 --> 在此转为 米/秒
double dSpeed = m_GPSData.dwSpeed / 100.0 / 3600;
//从GPS解析出来的角度以 0.01度 为单位 --> 在此转为 度
double dDirection = m_GPSData.wBearing / 100.0;
CString strGPSMsg;
strGPSMsg.Format( _T(" 经度=%d:%d:%d\n 纬度=%d:%d:%d\n 速度=%.2f\n 方向=%.2f\n 可见卫星数=%d\n"),
nLongitudeDu, nLongitudeFen, nLongitudeMiao,
nLatitudeDu, nLatitudeFen, nLatitudeMiao,
dSpeed, dDirection, m_GPSData.btSatellites );
AfxMessageBox( strGPSMsg );
}
}
}
void CMyeSuperMapView::OnUpdateEditAddpoint(CCmdUI* pCmdUI)
{
//点数据集,添加点对象菜单才有效
CSeLayer *pLayer = m_MapWnd.GetLayer( m_strEditableLayer );
if( pLayer != NULL )
{
CSeDatasetVector *pDtV = ( CSeDatasetVector * )( pLayer->GetDataset() );
pCmdUI->Enable( pDtV->GetType() == CSeDatasetInfo::Point );
}
else
{
pCmdUI->Enable( false );
}
pCmdUI->SetCheck( m_MapWnd.GetAction() == CSeDrawParameters::uaEditCreatePoint );
}
//向文件里面写数据
void CMyeSuperMapView::OnWritetofile()
{
CFile fp;
CString temp = L"hello!";
fp.Open(L"\\My Documents\\jj.txt",CFile::modeReadWrite);
INT length = fp.GetLength();
length = temp.GetLength();
if(length > 0)
fp.SeekToEnd();
fp.Write(temp,temp.GetLength()*2);
fp.Close();
AfxMessageBox(temp);
}
void CMyeSuperMapView::OnAddTower()
{
CCheckTower ct;
if(ct.DoModal() != IDOK)
return;
UpdateData(TRUE);
CFile fp1;
CString temp1 = ct.m_TowerNumber;
fp1.Open(L"\\My Documents\\jj.txt",CFile::modeReadWrite);
INT length1 = fp1.GetLength();
length1 = temp1.GetLength();
if(length1 > 0)
fp1.SeekToEnd();
fp1.Write(temp1,temp1.GetLength()*2);
fp1.Close();
if(temp1 != L"")
AfxMessageBox(temp1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -