⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpstestview.cpp

📁 广宇GPS系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// GpsTestView.cpp : implementation of the CGpsTestView class
//

#include "stdafx.h"
#include "GpsTest.h"

#include "GpsTestDoc.h"
#include "GpsTestView.h"
#include "MainFrm.h"
#include "SendSms.h"
#include "ComSet.h"
#include "CarSet.h"
#include "StatusSelect.h"
#include "SerializePath.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define IDC_MAP 100
#define IDC_MOTOG18 101

WCHAR pwchLicenseKey[] =
{
	0x0075,	0x0051,	0x006E,	0x005A,	0x0069,	0x0032,	
		0x0073,	0x0046,	0x0077,	0x0032,	0x0032,	0x004C,	
		0x0030,	0x002D,	0x004D,	0x0052,	0x0061,	0x0038,	
		0x0070,	0x0059,	0x0058,	0x002D,	0x0032,	0x0045,	
		0x0036,	0x0050,	0x0031,	0x0030,	0x0037,	0x0037,	
		0x002D,	0x0033,	0x004E,	0x0036,	0x004D,	0x0030,	
		0x0034,	0x0039,	0x0039,	0x002D,	0x0035,	0x0043,	
		0x0030,	0x0033,	0x0038,	0x0032,	0x0032,	0x0033,	
		0x002D,	0x0031,	0x0030,	0x0038,	0x0038,	0x0034,	
		0x002D,	0x0031,	0x0032,	0x0038,	0x0030,	0x0032,	
		0x002D,	0x0033,	0x0036,	0x0038,	0x0038,	0x0032,	
		0x002D,	0x0038,	0x0030,	0x0032,	0x0039
};

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView
static char Char2Hex(char c)
{
	if(c>='0' && c<='9')
        c -= '0';
    else if(c>='A' && c<='F')
        c -= ('A' - 0x0a);
    else if(c>='a' && c<='f')
        c -= ('a' - 0x0a);
	
    return c;
}

IMPLEMENT_DYNCREATE(CGpsTestView, CView)

BEGIN_MESSAGE_MAP(CGpsTestView, CView)
	//{{AFX_MSG_MAP(CGpsTestView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_COMMAND(ID_MAP_TOOL_ARROW, OnMapToolArrow)
	ON_COMMAND(ID_MAP_TOOL_PAN, OnMapToolPan)
	ON_COMMAND(ID_MAP_TOOL_ZOOMIN, OnMapToolZoomin)
	ON_COMMAND(ID_MAP_TOOL_ZOOMOUT, OnMapToolZoomout)
	ON_COMMAND(ID_BUTTON_COMSET, OnButtonComset)
	ON_COMMAND(ID_BUTTON_START, OnButtonStart)
	ON_COMMAND(ID_BUTTON_STOP, OnButtonStop)
	ON_COMMAND(ID_MAP_TOOL_POINT, OnMapToolPoint)
	ON_COMMAND(ID_BUTTON_PATHRUN, OnButtonPathrun)
	ON_COMMAND(ID_BUTTON_PATHSTOP, OnButtonPathstop)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_COMMAND(ID_BUTTON_CARSET, OnButtonCarset)
	ON_COMMAND(ID_BUTTON_SIMULITE, OnButtonSimulite)
	ON_COMMAND(ID_BUTTON_UNSIMULITE, OnButtonUnsimulite)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_RECVDATA,AnalyseUdpData)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CGpsTestView, CView)
	//{{AFX_EVENTSINK_MAP(CTestMapDlg)
	ON_EVENT(CGpsTestView, IDC_MAP, -602 /* KeyDown */, OnKeyDownMap, VTS_PI2 VTS_I2)	
	ON_EVENT(CGpsTestView, IDC_MAP, -606 /* MouseMove */, OnMouseMoveMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
	ON_EVENT(CGpsTestView, IDC_MAP, -605 /* MouseDown*/ , OnMouseDownMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
	ON_EVENT(CGpsTestView, IDC_MAP, -600 /* Click */, OnClickMap, VTS_NONE)
	ON_EVENT(CGpsTestView, IDC_MAP, -601 /* DblClick */ , OnDblClickMap , VTS_NONE)
	ON_EVENT(CGpsTestView, IDC_MAP, 16/* AddFeatureToolUsed */, OnAddFeatureToolUsed, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
	ON_EVENT(CGpsTestView, IDC_MOTOG18, 1 /* RecvSms */, OnRecvSmsMotog18ctrl, VTS_BSTR VTS_BSTR VTS_DATE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView construction/destruction

CGpsTestView::CGpsTestView()
{
	// TODO: add construction code here
	MapX = 0.0;
	MapY = 0.0;
	nCommRate = 0;
	nCommPort = 0;
	m_dwBStart = 0;
	nCurrentPointNum = 0;
	nTimerSendSms = -1;
	nTimerFlash = -1;
	nTimerCheckCar = -1;
	m_bModemSel = FALSE;
	m_pMotoG18 = NULL;
	m_hPathThread = NULL;
	m_dwPathThread = 0;
	m_bRButtonClick = FALSE;
	m_bBackSpaceDown = FALSE;
	m_bIsRuning = FALSE;
	m_bCarIsRuning = FALSE;
	m_bContinue = FALSE;
	m_bDrowPoint = FALSE;
	m_bRecvQJ = FALSE;
	m_strStatus = "000000000000";
	dFirstX = 0.0;
	dFirstY = 0.0;
	fFirstx = 0.0;
	fFirsty = 0.0;
	m_nCarNum = 0;
	m_strCarPhoneNum = _T("");
	m_strServer = _T("");
}

CGpsTestView::~CGpsTestView()
{
}

void CGpsTestView::OnDestroy() 
{
	CView::OnDestroy();
	
	// TODO: Add your message handler code here
	int i;
	sms_content *smscont;
	for(i=0; i<=m_smsArray.GetUpperBound(); i++)
	{
		smscont = m_smsArray.GetAt(i);
		ASSERT(smscont);
		delete smscont;
	}
	m_smsArray.RemoveAll();
	
	for(i=0; i<=m_smsRunArray.GetUpperBound(); i++)
	{
		smscont = m_smsRunArray.GetAt(i);
		ASSERT(smscont);
		delete smscont;
	}
	m_smsRunArray.RemoveAll();

	CCar *car;
	for(i=0; i<=m_carArray.GetUpperBound(); i++)
	{
		car = m_carArray.GetAt(i);
		ASSERT(car);
		delete car;
	}
	m_carArray.RemoveAll();
	
	if (m_pMotoG18 != NULL)
	{
		delete m_pMotoG18;
		m_pMotoG18 = NULL;
	}
	
	if (nTimerSendSms != -1)
	{
		KillTimer(nTimerSendSms);
		nTimerSendSms = -1;
	}
	
	if (nTimerFlash != -1)
	{
		KillTimer(nTimerFlash);
		nTimerFlash = -1;
	}

	if (nTimerCheckCar != -1)
	{
		KillTimer(nTimerCheckCar);
		nTimerCheckCar = -1;
	}
	
	if (m_hPathThread != NULL)
	{
		ExitPathThread();
	}
}

BOOL CGpsTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView drawing

void CGpsTestView::OnDraw(CDC* pDC)
{
	CGpsTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView printing

BOOL CGpsTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGpsTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGpsTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView diagnostics

#ifdef _DEBUG
void CGpsTestView::AssertValid() const
{
	CView::AssertValid();
}

void CGpsTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGpsTestDoc* CGpsTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGpsTestDoc)));
	return (CGpsTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGpsTestView message handlers

int CGpsTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
		sizeof(pwchLicenseKey)/sizeof(WCHAR));
	m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,100,100), this, IDC_MAP, NULL, FALSE, bstrLicense);
	::SysFreeString(bstrLicense);
	
	CString strFileName;
	strFileName = g_strPath + "\\Maps\\广西广东\\map.gst";
	m_ctrlMapX.SetGeoSet(strFileName);
//	m_ctrlMapX.SetTitleText("深圳");
	m_ctrlMapX.GetTitle().SetVisible(FALSE);

	CMapXLayer lyrPoint;
	CMapXFields fldsPoint;
	CMapXLayerInfo lyinPoint;
	VARIANT vt;
	
	fldsPoint.CreateDispatch(fldsPoint.GetClsid());
	lyinPoint.CreateDispatch(lyinPoint.GetClsid());
	fldsPoint.AddIntegerField("RecordId");
	fldsPoint.AddStringField("State", 20);
	lyinPoint.SetType(miLayerInfoTypeTemp);
	
	BSTR  bstrName =  SysAllocString(L"Point Layer");
	vt.vt  =  VT_BSTR;
	vt.bstrVal  =  bstrName; 
	lyinPoint.AddParameter("Name",vt);
	SysFreeString(bstrName); 
	
	vt.vt = VT_DISPATCH;
	vt.pdispVal = fldsPoint.m_lpDispatch;
	lyinPoint.AddParameter("Fields",vt);
	
	lyrPoint = m_ctrlMapX.GetLayers().Add(lyinPoint,1);
	
// 	lyrPoint = m_ctrlMapX.GetLayers().Item("Point Layer");
	lyrPoint.SetEditable(TRUE);
	m_ctrlMapX.GetLayers().SetAnimationLayer(lyrPoint);
	m_ctrlMapX.GetLayers().SetInsertionLayer(lyrPoint);
	vt.vt = VT_DISPATCH;
	vt.pdispVal = lyrPoint.m_lpDispatch;
	m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vt);

	
	CMapXStyle stylPoint;
	stylPoint = lyrPoint.GetStyle();
	
	stylPoint.SetLineColor(RGB(255,0,0));
	stylPoint.SetLineStyle(63);
	if (stylPoint.GetLineSupportsInterleave() == TRUE)
		stylPoint.SetLineInterleaved(TRUE);
	stylPoint.SetLineWidthUnit(miStyleUnitTenthsOfPoint);
	stylPoint.SetLineWidth(5);
	
//	stylPoint.SetSymbolType(miSymbolTypeTrueTypeFont);
//	stylPoint.SetSymbolFontColor(RGB(0,0,255));
//	stylPoint.SetSymbolCharacter('H');
//	stylPoint.GetSymbolFont().SetName("MapInfo Transportation");
//	CY cc = stylPoint.GetSymbolFont().GetSize();
//	cc.int64 = 350000;
//	stylPoint.GetSymbolFont().SetSize(cc);

//	lyrPoint.GetLabelProperties().SetOffset(16);
	lyrPoint.SetShowNodes(TRUE);
	lyrPoint.SetAutoLabel(TRUE);
	lyrPoint.SetOverrideStyle(TRUE);
	lyrPoint.SetSelectable(TRUE);
	lyrPoint.SetEditable(TRUE);

//-----------------点闪烁层----------------------
	CMapXLayer lyrFlash;
	CMapXFields fldsFlash;
	CMapXLayerInfo lyinFlash;
	VARIANT vtf;
	
	fldsFlash.CreateDispatch(fldsFlash.GetClsid());
	lyinFlash.CreateDispatch(lyinFlash.GetClsid());
	fldsFlash.AddIntegerField("RecordId");
	fldsFlash.AddStringField("State", 50);
	lyinFlash.SetType(miLayerInfoTypeTemp);
	
	BSTR  bstrfName =  SysAllocString(L"Flash Layer");
	vtf.vt  =  VT_BSTR;
	vtf.bstrVal  =  bstrfName; 
	lyinFlash.AddParameter("Name",vtf);
	SysFreeString(bstrfName); 
	
	vtf.vt = VT_DISPATCH;
	vtf.pdispVal = fldsFlash.m_lpDispatch;
	lyinFlash.AddParameter("Fields",vtf);
	
	lyrFlash = m_ctrlMapX.GetLayers().Add(lyinFlash,0);
	
	lyrFlash.SetEditable(TRUE);
	m_ctrlMapX.GetLayers().SetAnimationLayer(lyrFlash);
//	m_ctrlMapX.GetLayers().SetInsertionLayer(lyrFlash);
	vtf.vt = VT_DISPATCH;
	vtf.pdispVal = lyrFlash.m_lpDispatch;
	m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtf);
	
	
	CMapXStyle stylFlash;
	stylFlash = lyrFlash.GetStyle();

//	stylFlash.SetSymbolType(miSymbolTypeVector);
//	stylFlash.SetSymbolCharacter('H');
//	stylFlash.SetSymbolVectorSize(15);
//	stylFlash.SetSymbolVectorColor(RGB(0,255,0));

	stylFlash.SetSymbolType(miSymbolTypeTrueTypeFont);
	stylFlash.SetSymbolFontColor(RGB(0,30,150));
	stylFlash.SetSymbolCharacter('M');
	stylFlash.GetSymbolFont().SetName("MapInfo Transportation");
	CY cc = stylFlash.GetSymbolFont().GetSize();
	cc.int64 = 350000;
	stylFlash.GetSymbolFont().SetSize(cc);
	
//	stylFlash.GetLabelProperties().SetOffset(16);
	lyrFlash.SetShowNodes(TRUE);
	lyrFlash.SetAutoLabel(TRUE);
	lyrFlash.SetOverrideStyle(TRUE);
	lyrFlash.SetSelectable(TRUE);
	lyrFlash.SetEditable(TRUE);

	m_pMotoG18 = new CMotoG18;
	ASSERT(m_pMotoG18 != NULL);
	m_pMotoG18->Create(NULL, 0, CRect(0,0,0,0), this, IDC_MOTOG18);
//	m_pMotoG18->SetAutoRecv(TRUE);
	
	return 0;
}

//-----------------------------------------------
void CGpsTestView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if (cx != 0 && cy != 0)
		m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
}

//-----------------------------------------------
void CGpsTestView::OnButtonComset() 
{
	// TODO: Add your command handler code here
	CComSet comDlg;
	if (comDlg.DoModal() != IDOK)
		return;
}

//-----------------------------------------------
void CGpsTestView::OnMapToolArrow() 
{
	// TODO: Add your command handler code here
	try
	{
		m_ctrlMapX.SetCurrentTool(miArrowTool);
	}
	catch(COleDispatchException* e)
	{
		e->ReportError();
		e->Delete();
	}
#if  0
	char temp[20];
	ZeroMemory(temp, 20);
	strncpy(temp, "Hello World!", 19);
	int len = strlen(temp);
	SendUdpData((char *)temp, len);
#endif
}

//-----------------------------------------------
void CGpsTestView::OnMapToolPan() 
{
	// TODO: Add your command handler code here
	try
	{
		m_ctrlMapX.SetCurrentTool(miPanTool);
	}
	catch(COleDispatchException* e)
	{
		e->ReportError();
		e->Delete();
	}
}

//-----------------------------------------------
void CGpsTestView::OnMapToolZoomin() 
{
	// TODO: Add your command handler code here
	try
	{
		m_ctrlMapX.SetCurrentTool(miZoomInTool);
	}
	catch(COleDispatchException* e)
	{
		e->ReportError();
		e->Delete();
	}
}

//-----------------------------------------------
void CGpsTestView::OnMapToolZoomout() 
{
	// TODO: Add your command handler code here
	try
	{
		m_ctrlMapX.SetCurrentTool(miZoomOutTool);
	}
	catch(COleDispatchException* e)
	{
		e->ReportError();
		e->Delete();
	}
}

//-----------------------------------------------
void CGpsTestView::OnMapToolPoint() 
{
	// TODO: Add your command handler code here
	try
	{
		m_ctrlMapX.SetCurrentTool(miAddPolylineTool);
	}
	catch(COleDispatchException* e)
	{
		e->ReportError();
		e->Delete();
	}
}

//-----------------------------------------------
void CGpsTestView::OnButtonCarset() 
{
	// TODO: Add your command handler code here
	int nRet;
	CCarSet carsetDlg;
	nRet = carsetDlg.DoModal();
	if (nRet != IDOK)
		return;
}

//-----------------------------------------------
int CGpsTestView::GetCarInfo()
{
	CCarSet carsetDlg;
	carsetDlg.GetCarConfig();
	m_nCarNum = atoi(carsetDlg.m_strCarNum);
	m_strCarPhoneNum = carsetDlg.m_strPhoneNum;
	m_strServer = carsetDlg.m_strServer;
	m_strServerPort = carsetDlg.m_strServerPort;
	m_strLocal = carsetDlg.m_strLocal;
	m_strLocalPort = carsetDlg.m_strLocalPort;

	return 0;
}

//-----------------------------------------------
void CGpsTestView::OnButtonSimulite() 
{
	// TODO: Add your command handler code here
	if (m_bCarIsRuning)
	{
		MessageBox("多车模拟正在运行...\r\n", "警告信息", MB_ICONWARNING);
		return;
	}

	CreateCarArray();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -