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

📄 simulategpsview.cpp

📁 GPS电子狗数据采集、测试软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	DD = dt.GetDay();

	xx = m_pCurPnts[m_PlayIdx].x / 3600000.0;
	yy = m_pCurPnts[m_PlayIdx].y / 3600000.0;
	x = (int)xx;
	y = (int)yy;
	xx -= x;
	yy -= y;
	xx *= 60;
	yy *= 60;

	if( m_PlayIdx==0 ){
		Angle = 0; // 度
		Speed = theApp.m_Speed / 1.852; // 海里/小时
	}else{
		Angle = atan2( m_pCurPnts[m_PlayIdx].y - m_pCurPnts[m_PlayIdx-1].y, 
			m_pCurPnts[m_PlayIdx].x - m_pCurPnts[m_PlayIdx-1].x );
		/*
		if( Angle>=0 && Angle<1.5707963 )
		{
			Angle = 1.5707963 - Angle;
		}else if( Angle<0 && Angle>=-1.5707963 ){
			Angle = 1.5707963 - Angle;
		}else if( Angle<-1.5707963 && Angle>=-3.1415926 ){
			Angle = 1.5707963 - Angle;
		}else if( Angle<3.1415926 && Angle>=1.5707963 ){
			Angle = 1.5707963 - Angle;
		}
		if( Angle>=0 ){
			Angle -= 1.5707963;
			if( Angle<0 )Angle+= 2*3.1415926;
		}else{
			Angle += 2*3.1415926;
			Angle -= 1.5707963;
		}*/
		Angle = 1.5707963 - Angle;
		if( Angle<0 )Angle+= 2*3.1415926;

		Angle = Angle * 180 / 3.1415926;
		Speed = (m_pCurPnts[m_PlayIdx].y-m_pCurPnts[m_PlayIdx-1].y)*
				(m_pCurPnts[m_PlayIdx].y-(double)m_pCurPnts[m_PlayIdx-1].y) + 
				(m_pCurPnts[m_PlayIdx].x-m_pCurPnts[m_PlayIdx-1].x)*
				(m_pCurPnts[m_PlayIdx].x-(double)m_pCurPnts[m_PlayIdx-1].x);

		Speed = pow( Speed, 0.5 );
		Speed *= 0.03; //M
		Speed *= 2;
	}
	//<1>定位时UTC时间hhmmss 格式
    //<2>状态A=定位V=不定位
    //<3>纬度ddmm.mmmm格式
    //<4>纬度方向N 或S
    //<5>经度dddmm.mmmm 
    //<6>经度方向E或W
    //<7>速率  海里/小时
    //<8>方位角度(二维方向指向,相当于二维罗盘) 度,正北为0,逆时针递增
    //<9>当前UTC日期ddmmyy 格式
    //<10>太阳方位
    //<11>太阳方向
	CString GPRMC;
	GPRMC.Format( "$GPRMC,%02d%02d%02d,A,%02d%07.4f,N,%03d%07.4f,E,%05.1f,%05.1f,%02d%02d%02d,,*0D\n", 
		hh, mm, ss, y, yy, x, xx, Speed, Angle, DD, MM, YY );
	
//	COleDateTimeSpan span( 0, 0, 0, 1 );
//	m_dt += span;
	theApp.m_PlaySerial.SendData( GPRMC, strlen(GPRMC) );
	

	m_MapWnd.m_TrackingLayer.ReleaseAll();
	CSeGeoPoint *pGeoPnt = new CSeGeoPoint();
	pGeoPnt->SetPoint( m_pCurPnts[m_PlayIdx].x, m_pCurPnts[m_PlayIdx].y );
	m_MapWnd.m_TrackingLayer.AddEvent( pGeoPnt, "" );
	CPoint pnt( m_pCurPnts[m_PlayIdx].x, m_pCurPnts[m_PlayIdx].y );
	if( !(m_MapWnd.GetDrawParam()->IsVisible(&(m_pCurPnts[m_PlayIdx]))) )
	{
		m_MapWnd.SetCenter( pnt );
	}
	m_MapWnd.Refresh();


	m_PlayIdx++;

	if( m_PlayIdx==m_Count )
	{
		m_pRSSel->MoveNext();
		if( !GetSelGeo() )
		{
			m_pRSSel->GetDataset()->ReleaseRecordset( m_pRSSel );
			KillTimer(1);
			MessageBox("播放完毕!");
		}
	}
}


//flag=0 保留原节点 flag=1 不保留原节点
//pPnts 保存产生的点
//total pPnts的大小
//PntCount产生的点的个数
int CSimulateGPSView::MyResampleLine(CSeGeoLine *pLine, double dist, 
									  CPoint *&pPnts, int &total, 
									  int &PntCount, int flag )
{
	int count = pLine->GetPointCount();
	CSePoint2D *pGeoPnts = pLine->GetPoints();
	double curdist;
	CPoint tmpPnt,from;
	int ret;
	
	PntCount = 0;
	AddPoint( pPnts, total, PntCount, pGeoPnts[0] );
	curdist = dist;
	from = pGeoPnts[0];
	for( int i=1; i<count; i++ )
	{
		do
		{
			ret = GetPoint( from, pGeoPnts[i], curdist, flag, tmpPnt );
			if( ret==0 || ret==2 )
			{
				AddPoint( pPnts, total, PntCount, tmpPnt );
				curdist = dist;
				from = tmpPnt;
			}else from = pGeoPnts[i];
		}while( ret==2 );
	}
	//最后一个点应该加入
	if( ret==1 )AddPoint( pPnts, total, PntCount, pGeoPnts[count-1] );
	return 0;
}

int CSimulateGPSView::AddPoint(CPoint *&pPnts, int &total, int &count, CPoint &pnt)
{
	if( count>=total )
	{
		total += 100;
		pPnts = (CPoint *)realloc( pPnts, sizeof(CPoint)*total );
		if( pPnts==NULL )return -1;
	}
	pPnts[count].x = pnt.x;
	pPnts[count].y = pnt.y;
	count++;
	return 0;
}


//0 - 完成并获得点
//1 - 完成未获得点
//2 - 未完成获得点
int CSimulateGPSView::GetPoint(CPoint from, CPoint to, double &dist, int flag, CPoint &pnt)
{
	double distance = CSeOperator::Distance( from, to );

	if( distance<dist*1.1 && distance>dist*0.9 )
	{
		pnt = to;
		return 0;
	}else if( distance<dist ){
		if( flag==0 )//保留原节点
		{
			pnt = to;
			return 0;
		}else{
			dist -= distance;
			return 1;	//不能改变curdist
		}
	}else{
		double angle = atan2( to.y-from.y, to.x-from.x );

		double xx = dist * cos( angle );
		double yy = dist * sin( angle );
		pnt.x = from.x + xx;
		pnt.y = from.y + yy;
		return 2;
	}
}


void CSimulateGPSView::OnRcvCommStr(WPARAM wParam, LPARAM lParam)
{
	int length = wParam & 0xFFFFFF;
	BYTE *pRcvData = (BYTE *)lParam;
	int id;

	for( int i=0; i<length-3; i++ )
	{
		if( memcmp( "$VAL38", pRcvData, 6 )==0 )
		{
			id = m_PlayIdx-2;
			if( id<0 )id = 0; 
			AddScout( m_pCurPnts[id] );
			break;
		}
	}
	
}

void CSimulateGPSView::OnToolSetup() 
{
	CDlgSetup dlg;

	dlg.DoModal();
}

void CSimulateGPSView::AddScout(CPoint pnt)
{
	CSeDatasetVector *pDSV;
	CSeRecordset *pRS;
	CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );

	pDSV = (CSeDatasetVector *)pDataSource->GetDataset( LAYER_SCOUT );
	pRS = pDSV->QueryByGeneral();
	if( pRS ){
		CSeGeoPoint GeoPoint;

		GeoPoint.SetPoint( pnt.x, pnt.y );
		pRS->AddNew( &GeoPoint );
		pRS->Update();
		pDSV->ReleaseRecordset( pRS );
	}
}

void CSimulateGPSView::OnToolWorklayer() 
{
	if( !m_bFileOpened )
	{
		MessageBox("请先打开相应的电子地图!");
		return;
	}

	CSeLayer *pLayer;
	CString LayerName;

	int count = m_MapWnd.GetLayerCount();
	CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );
	if( pDataSource )
	{
		CString dsName = pDataSource->GetAlias();
		CSeDatasetVector *pDataset = (CSeDatasetVector *)pDataSource->GetDataset( LAYER_TRACK );
		if( !pDataset )pDataset = CreateTracks();
		LayerName.Format( "%s@%s", LAYER_TRACK, dsName );
		if( pDataset ){
			pLayer = m_MapWnd.GetLayer(LayerName);
			if( pLayer==NULL ){
				pLayer = m_MapWnd.AddLayer( pDataset );
				pLayer->m_pStyle->m_nPenColor = RGB(0,0,255);
				pLayer->m_pStyle->m_nPenWidth = 5;
			}
		}

		pDataset = (CSeDatasetVector *)pDataSource->GetDataset( LAYER_LINES );
		if( !pDataset )pDataset = CreateLine();
		LayerName.Format( "%s@%s", LAYER_LINES, dsName );
		if( pDataset ){
			pLayer = m_MapWnd.GetLayer(LayerName);
			if( pLayer==NULL ){
				pLayer = m_MapWnd.AddLayer( pDataset );
				pLayer->m_pStyle->m_nPenColor = RGB(255,0,192);
				pLayer->m_pStyle->m_nPenWidth = 10;
			}
		}

		pDataset = (CSeDatasetVector *)pDataSource->GetDataset( LAYER_SCOUT );
		if( !pDataset )pDataset = CreateScouts();
		LayerName.Format( "%s@%s", LAYER_SCOUT, dsName );
		if( pDataset ){
			pLayer = m_MapWnd.GetLayer(LayerName);
			if( pLayer==NULL ){
				pLayer = m_MapWnd.AddLayer( pDataset );
				pLayer->m_pStyle->m_nPenColor = RGB(255,192,0);
				pLayer->m_pStyle->m_nPenWidth = 10;
			}
		}
		m_MapWnd.Refresh(); 
	}
}

bool CSimulateGPSView::HaveAllLayer()
{
	if( theApp.m_WorkSpace.IsOpen() )
	{ 
		CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );
		if( pDataSource && pDataSource->GetDatasetCount() > 0 )
		{
			CSeDataset *pDataset = pDataSource->GetDataset( LAYER_LINES );
			if( pDataset )
			{
				pDataset = pDataSource->GetDataset( LAYER_TRACK );
				if( pDataset )
				{
					pDataset = pDataSource->GetDataset( LAYER_SCOUT );
					if( pDataset )return true;
				}
			}
		}
	}
	return false;
}

CSeDatasetVector * CSimulateGPSView::CreateLine()
{
	CSeDatasetVector *pDtv;
	CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );

	CString strName = LAYER_LINES;      //指定数据集的名字。
	CSeDatasetInfo::Type nType = CSeDatasetInfo::Line;
	long nOptions = CSeDataset::Default;    //创建选项,暂时没有使用。

	CSeRect2D rcBounds;   //事先指定数据集的范围。

	if( pDataSource->GetDatasetCount() > 0 ){
		rcBounds = pDataSource->GetDatasetAt(0)->GetBound();
	}else rcBounds.SetRect( 192528200,65527000, 266085200, 48356800 );

	pDtv =(CSeDatasetVector *)pDataSource->CreateDataset(strName ,nType ,rcBounds, nOptions);
	if( pDtv==NULL ){
		MessageBox( "创建数据集失败!" );
		return NULL;
	}
	CSeFieldInfo fieldInfo;

	fieldInfo.m_strName = _T("Speed");
	fieldInfo.m_lFieldType = seLong;
	fieldInfo.m_lFieldSize = 4;
	fieldInfo.m_strDefaultValue = "80";
	fieldInfo.m_lAttributes = seRequired;
	pDtv->CreateField( fieldInfo );

	fieldInfo.m_strName = _T("Direct");
	fieldInfo.m_lFieldType = seByte;
	fieldInfo.m_lFieldSize = 1;
	fieldInfo.m_strDefaultValue = "0";
	fieldInfo.m_lAttributes = seRequired;
	pDtv->CreateField( fieldInfo );
	return pDtv;
}

CSeDatasetVector * CSimulateGPSView::CreateScouts()
{
	CSeDatasetVector *pDtv;
	CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );

	CString strName = LAYER_SCOUT;      //指定数据集的名字。
	CSeDatasetInfo::Type nType = CSeDatasetInfo::Point;
	long nOptions = CSeDataset::Default;    //创建选项,暂时没有使用。

	CSeRect2D rcBounds;   //事先指定数据集的范围。

	if( pDataSource->GetDatasetCount() > 0 ){
		rcBounds = pDataSource->GetDatasetAt(0)->GetBound();
	}else rcBounds.SetRect( 192528200,65527000, 266085200, 48356800 );

	pDtv =(CSeDatasetVector *)pDataSource->CreateDataset(strName ,nType ,rcBounds, nOptions);
	if( pDtv==NULL ){
		MessageBox( "创建数据集失败!" );
		return NULL;
	}
	CSeFieldInfo fieldInfo;

	fieldInfo.m_strName = _T("Type");
	fieldInfo.m_lFieldType = seByte;
	fieldInfo.m_lFieldSize = 1;
	fieldInfo.m_strDefaultValue = "0";
	fieldInfo.m_lAttributes = seRequired;
	pDtv->CreateField( fieldInfo );
	return pDtv;
}

CSeDatasetVector * CSimulateGPSView::CreateTracks()
{
	CSeDatasetVector *pDtv;
	CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );

	CString strName = LAYER_TRACK;      //指定数据集的名字。
	CSeDatasetInfo::Type nType = CSeDatasetInfo::Line;
	long nOptions = CSeDataset::Default;    //创建选项,暂时没有使用。

	CSeRect2D rcBounds;   //事先指定数据集的范围。

	if( pDataSource->GetDatasetCount() > 0 ){
		rcBounds = pDataSource->GetDatasetAt(0)->GetBound();
	}else rcBounds.SetRect( 192528200,65527000, 266085200, 48356800 );

	pDtv =(CSeDatasetVector *)pDataSource->CreateDataset(strName ,nType ,rcBounds, nOptions);
	if( pDtv==NULL ){
		MessageBox( "创建数据集失败!" );
		return NULL;
	}
	return pDtv;
}

⌨️ 快捷键说明

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