// LineSectDisAZDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "LineSectDisAZDlg.h"
//#include "afxdialogex.h"
#include "Globe.h"
#include <math.h>

// CLineSectDisAZDlg 对话框

IMPLEMENT_DYNAMIC(CLineSectDisAZDlg, CDialog)

CLineSectDisAZDlg::CLineSectDisAZDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLineSectDisAZDlg::IDD, pParent)
{

	m_strAZAngleFromOrg = _T("");
	m_strDistanceFromOrg = _T("");
	m_strSectAZAngle = _T("");
	m_strSectDistance = _T("");

	//航段起始点的经纬度
	m_sectStartLon = 0;   //经度
	m_sectStartLat = 0;   //纬度

	//航段结束点的经纬度
	m_sectEndLon = 0;    //经度
	m_sectEndLat = 0;    //纬度

	//是否已经完成航段设计,进入下一个航段编辑
	m_bFirstLineSectDesign = true;
}


CLineSectDisAZDlg::~CLineSectDisAZDlg()
{

}


void CLineSectDisAZDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_ORG_AZ_ANGLE, m_strAZAngleFromOrg);
	DDX_Text(pDX, IDC_EDIT_ORG_DISTANCE, m_strDistanceFromOrg);
	DDX_Text(pDX, IDC_EDIT_SECT_AZ_ANGLE, m_strSectAZAngle);
	DDX_Text(pDX, IDC_EDIT_SECT_DISTANCE, m_strSectDistance);
}


BEGIN_MESSAGE_MAP(CLineSectDisAZDlg, CDialog)
END_MESSAGE_MAP()


// CLineSectDisAZDlg 消息处理程序




BOOL CLineSectDisAZDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	//在制定的显示区域进行显示
	SetWindowPos( &CWnd::wndTop, m_rcShowArea.left, m_rcShowArea.top, 0, 0,	SWP_NOSIZE | SWP_NOACTIVATE | SWP_HIDEWINDOW );


	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}





//功能:已完成航段设计
void CLineSectDisAZDlg::SetLineSectStatus()
{
	if (m_bFirstLineSectDesign)
	{
		m_bFirstLineSectDesign = false;
	}

	m_sectStartLon = m_sectEndLon;
	m_sectStartLat = m_sectEndLat;
}



//功能:输入航点坐标
//输入:经度lon,纬度lat
void CLineSectDisAZDlg::InputPointCoordinate(const double lon, const double lat)
{
	double distance = 0;
	double angle = 0;	

	if (fabs(lon)<0.001 || fabs(lat)<0.001)
	{
		m_strDistanceFromOrg = _T("");
		m_strAZAngleFromOrg = _T("");

		m_strSectAZAngle = _T("");		 //航段的方位角
		m_strSectDistance = _T("");		 //航段的水平距离

		UpdateData(FALSE);

		return;
	}

	//显示航点距离地面站的距离和方位角
	ShowPtInfoFromGCS(lon, lat);

	//新航段设计
	if (m_bFirstLineSectDesign)
	{
		//航段起始点坐标
		m_sectStartLon = lon;
		m_sectStartLat = lat;
	
		//航段距离和方位角
		m_strSectAZAngle = _T("");		 //航段的方位角
		m_strSectDistance = _T("");		 //航段的水平距离
	}
	else  
	{
		//航段结束点坐标
		m_sectEndLon = lon;
		m_sectEndLat = lat;
	
		//显示航段的水平距离和方位角
		CalculateTwoPtsDistanceAzimuth(distance, angle, m_sectStartLon, m_sectStartLat, m_sectEndLon, m_sectEndLat, 3);

		//航段距离和方位角
		m_strSectDistance.Format(_T("%.1fm"),distance); 	    //航段的水平距离
		m_strSectAZAngle.Format( _T("%.1f"),angle);		    //航段的方位角
	}

	UpdateData(FALSE);
}



//功能:移动对话框到给定的显示区域
void CLineSectDisAZDlg::MoveToGivenArea(const CRect rcArea)
{
	m_rcShowArea.left = rcArea.right-190;
	m_rcShowArea.right = rcArea.right;

	m_rcShowArea.top = rcArea.top+20;
	m_rcShowArea.bottom = m_rcShowArea.top+100;
}



//功能;显示航点距离原点的距离和方位角
//输入:航点坐标,经度值—lon
//      航点坐标,纬度值—lat
void CLineSectDisAZDlg::ShowPtInfoFromGCS(const double lon, const double lat)
{
	//判断地面站位置的有效性
	if ((fabs(g_gcsLon) < 0.001) || (fabs(g_gcsLat) < 0.001) )
	{
		m_strDistanceFromOrg = _T("");
		m_strAZAngleFromOrg = _T("");

		return;
	}
	else
	{
		double distance = 0;
		double angle = 0;
		
		//显示航点距离地面站的水平距离和方位角
		CalculateTwoPtsDistanceAzimuth(distance, angle, g_gcsLon, g_gcsLat, lon, lat, 3);
		
		//水平距离
		m_strDistanceFromOrg.Format(_T("%.1fm"),distance);
		
		//方位角
		m_strAZAngleFromOrg.Format(_T("%.1f"),angle);	
	}
}