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

📄 gps_famdlg.cpp

📁 EVC下
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{
			strArrayLatDegree.Add(GPS_info.Mid(x1,2));
		}

		for(int y2=4;y2<GPS_info.GetLength();y2=y2+24)
		{
			strArrayLonMinute.Add(GPS_info.Mid(y2,7));
		}
		
		for(int x2=14;x2<GPS_info.GetLength();x2=x2+24)
		{
			strArrayLatMinute.Add(GPS_info.Mid(x2,7));
		}

		strLat=GPS_info.Mid(11,9);

		LatDegree=strLat.Left(2);
		LatMinute=strLat.Mid(2,7);
		
		double LatCtoD=CStringToFloat(LatDegree)+CStringToFloat(LatMinute)/60;

		double rad=LatCtoD/180;

		double Latdpm=(2*Pi*R)/(360*60);
		double Londpm=(2*Pi*R*cos(rad*Pi))/(360*60);

//		Latdpm=10000;
//		Londpm=10000;
		
		free(Buffer);

		CloseHandle(hOpenFile);

		double Lat[1000],Lon[1000];

		for(int z=0;z<PointCountArea;z++)
		{
			Lat[z]=(CStringToFloat(strArrayLatDegree.GetAt(z))*60+CStringToFloat(strArrayLatMinute.GetAt(z)))*Latdpm;
			Lon[z]=(CStringToFloat(strArrayLonDegree.GetAt(z))*60+CStringToFloat(strArrayLonMinute.GetAt(z)))*Londpm;	
		}

		Lat[PointCountArea]=Lat[0];
		Lon[PointCountArea]=Lon[0];

		double s=0;
		
		for(int k=0;k<PointCountArea;k++)
		{   
		s+=Lat[k]*Lon[k+1]-Lat[k+1]*Lon[k];
		}
		s=fabs(s)/2;

		m_Area.Format(L"%.2f 平方米",s);

		m_Bt_Re_Measure.EnableWindow(true);
		m_Bt_Area.EnableWindow(false);
			
		UpdateData(false);
}

void CGPS_FAMDlg::OnGirth() 
{
	// TODO: Add your control notification handler code here
	m_Bt_Restart.EnableWindow(false);
	
	TCHAR *Buffer;
	HANDLE hOpenFile;

	hOpenFile=CreateFile(TEXT("\\ResidentFlash\\Coordinate.txt"),GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	
	if(hOpenFile!=INVALID_HANDLE_VALUE)
	{
		int FileLen=GetFileSize(hOpenFile,NULL);
		
		Buffer=(TCHAR*)calloc(FileLen,sizeof(TCHAR));
		
		DWORD readLen;
		
		ReadFile(hOpenFile,Buffer,FileLen,&readLen,NULL);
	}
		CString GPS_info=Buffer;

		int PointCountGirth=0;
	
		for(int i=0;i<GPS_info.GetLength();i++)
		{
			if(GPS_info.GetAt(i)=='P')
			{
				PointCountGirth=PointCountGirth+1;	
			}
		}
		
		CStringArray strArrayLonDegree;
		CStringArray strArrayLatDegree;
		CStringArray strArrayLonMinute;
		CStringArray strArrayLatMinute;
		CString strLat,LatDegree,LatMinute;
			
		for(int y1=1;y1<GPS_info.GetLength();y1=y1+24)
		{
			strArrayLonDegree.Add(GPS_info.Mid(y1,3));
		}
		
		for(int x1=12;x1<GPS_info.GetLength();x1=x1+24)
		{
			strArrayLatDegree.Add(GPS_info.Mid(x1,2));
		}

		for(int y2=4;y2<GPS_info.GetLength();y2=y2+24)
		{
			strArrayLonMinute.Add(GPS_info.Mid(y2,7));
		}
		
		for(int x2=14;x2<GPS_info.GetLength();x2=x2+24)
		{
			strArrayLatMinute.Add(GPS_info.Mid(x2,7));
		}
		
		strLat=GPS_info.Mid(11,9);
		
		LatDegree=strLat.Left(2);
		LatMinute=strLat.Mid(2,7);
		
		double LatCtoD=CStringToFloat(LatDegree)+CStringToFloat(LatMinute)/60;

		double rad=LatCtoD/180;

		double Latdpm=(2*Pi*R)/(360*60);
		double Londpm=(2*Pi*R*cos(rad*Pi))/(360*60);

		free(Buffer);

		CloseHandle(hOpenFile);

		double Lat[1000],Lon[1000];

		for(int z=0;z<PointCountGirth;z++)
		{
			Lat[z]=(CStringToFloat(strArrayLatDegree.GetAt(z))*60+CStringToFloat(strArrayLatMinute.GetAt(z)))*Latdpm;
			Lon[z]=(CStringToFloat(strArrayLonDegree.GetAt(z))*60+CStringToFloat(strArrayLonMinute.GetAt(z)))*Londpm;	
		}

		Lat[PointCountGirth]=Lat[0];
		Lon[PointCountGirth]=Lon[0];

		double c=0;

		for(int k=0;k<PointCountGirth;k++)
		{   
		c+=sqrt((Lat[k]-Lat[k+1])*(Lat[k]-Lat[k+1])+(Lon[k]-Lon[k+1])*(Lon[k]-Lon[k+1]));
		}
	
		m_Girth.Format(L"%.2f 米",c);

		m_Bt_Re_Measure.EnableWindow(true);	
		m_Bt_Girth.EnableWindow(false);
		
		UpdateData(false);
}

void CGPS_FAMDlg::OnDisplay() 
{
	// TODO: Add your control notification handler code here
		m_Bt_Restart.EnableWindow(false);

		GetDlgItem(IDC_STATIC_INFO_1)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_STATIC_INFO_2)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_STATIC_INFO_3)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_STATIC_INFO_4)->ShowWindow(SW_HIDE);
		
		TCHAR *Buffer;
		HANDLE hOpenFile;
	
		hOpenFile=CreateFile(TEXT("\\ResidentFlash\\Coordinate.txt"),GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
		
		if(hOpenFile!=INVALID_HANDLE_VALUE)
		{
			int FileLen=GetFileSize(hOpenFile,NULL);
			
			Buffer=(TCHAR*)calloc(FileLen,sizeof(TCHAR));
			
			DWORD readLen;
			
			ReadFile(hOpenFile,Buffer,FileLen,&readLen,NULL);
		}
			
		CString GPS_info=Buffer;

		PointCountDisplay=0;
		
			for(int i=0;i<GPS_info.GetLength();i++)
			{
				if(GPS_info.GetAt(i)=='P')
				{
					PointCountDisplay=PointCountDisplay+1;	
				}
			}
			
			CStringArray strArrayLonDegree;
			CStringArray strArrayLatDegree;
			CStringArray strArrayLonMinute;
			CStringArray strArrayLatMinute;
			CString strLat,LatDegree,LatMinute;
			
			for(int y1=1;y1<GPS_info.GetLength();y1=y1+24)
			{
				strArrayLonDegree.Add(GPS_info.Mid(y1,3));
			}
			for(int x1=12;x1<GPS_info.GetLength();x1=x1+24)
			{
				strArrayLatDegree.Add(GPS_info.Mid(x1,2));
			}
			for(int y2=4;y2<GPS_info.GetLength();y2=y2+24)
			{
				strArrayLonMinute.Add(GPS_info.Mid(y2,7));
			}
			
			for(int x2=14;x2<GPS_info.GetLength();x2=x2+24)
			{
				strArrayLatMinute.Add(GPS_info.Mid(x2,7));
			}
			
			
			strLat=GPS_info.Mid(11,9);
	
			LatDegree=strLat.Left(2);
			LatMinute=strLat.Mid(2,7);
			
			double LatCtoD=CStringToFloat(LatDegree)+CStringToFloat(LatMinute)/60;
	
			double rad=LatCtoD/180;
	
			double Latdpm=(2*Pi*R)/(360*60);
			double Londpm=(2*Pi*R*cos(rad*Pi))/(360*60);
	
			free(Buffer);
	
			CloseHandle(hOpenFile);
		
			double min_x_temp = (CStringToFloat(strArrayLonDegree.GetAt(0))*60+CStringToFloat(strArrayLonMinute.GetAt(0)))*Londpm;
			double min_y_temp = (CStringToFloat(strArrayLatDegree.GetAt(0))*60+CStringToFloat(strArrayLatMinute.GetAt(0)))*Latdpm;
	
		CMyPoint *ptr1;  
		
		ptr1 = new CMyPoint[PointCountDisplay];
	
		for(int j = 0;j < PointCountDisplay;j++)
		{
			ptr1[j].x = (CStringToFloat(strArrayLonDegree.GetAt(j))*60+CStringToFloat(strArrayLonMinute.GetAt(j)))*Londpm;
	
			if (min_x_temp > ptr1[j].x)
			{
				min_x_temp = ptr1[j].x;
			}
			
			ptr1[j].y = (CStringToFloat(strArrayLatDegree.GetAt(j))*60+CStringToFloat(strArrayLatMinute.GetAt(j)))*Latdpm;

			if (min_y_temp > ptr1[j].y)
			{
				min_y_temp = ptr1[j].y;
			}
		
		}
		
	CMyPoint *ptr2;//转换成相对坐标
		
		ptr2 = new CMyPoint[PointCountDisplay];
		
		for(int k = 0;k < PointCountDisplay;k++)
		{		
			ptr2[k].x =ptr1[k].x - min_x_temp;
			ptr2[k].y =ptr1[k].y - min_y_temp;			
		}
		
		//再得到,220以内的最大数。
		double max_x=0,max_y=0;
		for (int t =0;t<PointCountDisplay;t++)
		{			
			if (ptr2[t].x>max_x)
			{
				max_x = ptr2[t].x;
			}
			if (ptr2[t].y>max_y)
			{
				max_y = ptr2[t].y;
			}			
		}
				
		//放大或缩小的陪数。		
		double times_x,times_y,
		double times;
		
//		if(max_x>max_y)
//		{
//			times = 190 / max_x;
//		}
//		else
//		{
//			times = 132 / max_y;
// 		}
						
		times_x = max_x / 190 ;
		times_y = max_y / 132 ;

		if(times_x > times_y)
		{
			times = times_x;
		}
		else
		{
			times = times_y;
		}
		//转换成相对坐标
		
		ptr3 = new CPoint[PointCountDisplay];
	
		for(int m=0;m<PointCountDisplay;m++)
		{
			
//		ptr3[m].x = ptr2[m].x * times +8+95-(max_x*times)/2;
//		ptr3[m].y = ptr2[m].y * times +36+66-(max_y*times)/2;

		ptr3[m].x = ptr2[m].x / times + 8 + 95 - (max_x / times)/2;
		ptr3[m].y = ptr2[m].y / times + 36 + 66 - (max_y / times)/2;
			
		}	
		
		//画图
		begin = true;

		InvalidateRect(CRect(0,0,320,240), true);

		m_Bt_Re_Measure.EnableWindow(true);
		m_Bt_Display.EnableWindow(false);
		
		delete [] ptr1;
		delete [] ptr2;	
}

void CGPS_FAMDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	if(begin)	
	{
		DisplayPolygon(dc);

	}
	// Do not call CDialog::OnPaint() for painting messages
}

void CGPS_FAMDlg::DisplayPolygon(CDC &pDC)
{
	pDC.Polygon(ptr3,PointCountDisplay);
	
	begin=false;
	
//	m_Bt_Display.EnableWindow(false);

}

void CGPS_FAMDlg::OnReMeasure() 
{
	// TODO: Add your control notification handler code here
	DeleteFile(TEXT("\\ResidentFlash\\Coordinate.txt"));
	
	m_Area="";
	m_Girth="";
	m_PointNum="";

	m_Info_1="";
	m_Info_2="";
	m_Info_3="";
	m_Info_4="";

	count=0;

	state=0;

	space_time=SetTime[1][0];

	i=1;

	m_Bt_Auto_Mode.LoadBitmaps(IDB_AUTO_MODE_UP);
	m_Bt_Manual_Mode.LoadBitmaps(IDB_MANUAL_MODE_UP);
	
	m_Bt_Area.EnableWindow(false);
	m_Bt_Girth.EnableWindow(false);
	m_Bt_Display.EnableWindow(false);
	m_Bt_Restart.EnableWindow(false);
	m_Bt_Re_Measure.EnableWindow(false);

	m_Bt_Auto_Mode.EnableWindow(true);
    m_Bt_Manual_Mode.EnableWindow(true);

	GetDlgItem(IDC_STATIC_INFO_1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_INFO_2)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_INFO_3)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC_INFO_4)->ShowWindow(SW_SHOW);

	InvalidateRect(CRect(0,0,320,240), true);

	delete [] ptr3;

	UpdateData(false);
}

void CGPS_FAMDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 1)//自动模式判断
	{	
		GetGPSinfo();
	}
	
	if(nIDEvent == 2)//手动模式判断
	{
		GetGPSinfo();
	}

	if (nIDEvent == 3)//自动取点
	{	
		GetGPSinfo();
	}
	
	if(nIDEvent == 4)
	{
		GetGPSinfo();
//		m_Bt_Auto_Start.EnableWindow(true);
//		m_Bt_Auto_Start.ShowWindow(SW_SHOW);
//		m_Bt_Add.EnableWindow(true);
// 		m_Bt_Sub.EnableWindow(true);
	}

	CDialog::OnTimer(nIDEvent);
}



int CGPS_FAMDlg::CStringToInt(CString str1)
{
	char *pBuffer = NULL;
	pBuffer = new char[str1.GetLength()+1];
	ZeroMemory(pBuffer, str1.GetLength()+1);
	int iLen = str1.GetLength();
	for(int i = 0; i < iLen; i++)
	pBuffer[i] = str1[i];
	pBuffer[i] ='\0';
	int n;
	n = atoi(pBuffer);
	delete[] pBuffer;
	return n;
}

double CGPS_FAMDlg::CStringToFloat(CString str2)
{
	char *pBuffer = NULL;
	pBuffer = new char[str2.GetLength()+1];
	ZeroMemory(pBuffer, str2.GetLength()+1);
	int iLen = str2.GetLength();
	for(int i = 0; i < iLen; i++)
	pBuffer[i] = str2[i];
	pBuffer[i] ='\0';
	double n;
	n = atof(pBuffer);
	delete[] pBuffer;
	return n;
}

HBRUSH CGPS_FAMDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor == CTLCOLOR_STATIC )
	{
	//	pDC->SetBkMode(TRANSPARENT);
		if(	pWnd->GetDlgCtrlID()==IDC_STATIC_INFO_1
			||pWnd->GetDlgCtrlID()==IDC_STATIC_INFO_2
			||pWnd->GetDlgCtrlID()==IDC_STATIC_INFO_3
			||pWnd->GetDlgCtrlID()==IDC_STATIC_INFO_4
			||pWnd->GetDlgCtrlID()==IDC_STATIC_POINT_NUM)
		{
			pDC->SetTextColor(RGB(255,255,255));
			pDC->SetBkColor(RGB(148,148,148));
			m_brMine = ::CreateSolidBrush(RGB(148,148,148));
			return m_brMine;
		}
		
		if( pWnd->GetDlgCtrlID()==IDC_STATIC_AREA
			||pWnd->GetDlgCtrlID()==IDC_STATIC_GIRTH)
		{
			pDC->SetTextColor(RGB(255,255,255));
			pDC->SetBkColor(RGB(0,0,0));

⌨️ 快捷键说明

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