📄 geodlg.cpp
字号:
// geodlg.cpp : implementation file
//
#include "stdafx.h"
#include "GeoCalc.h"
#include "geodlg.h"
#include "geo.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// play stuff
/*
inline double FACTORIAL(double x)
{
double result = x;
if (result > 1) result *= FACTORIAL(x-1);
return result;
}
inline double approx_sine(double a)
{
double r = a - pow(a,3)/FACTORIAL(3) + pow(a,5)/FACTORIAL(5) - pow(a,7)/FACTORIAL(7) +
pow(a,9)/FACTORIAL(9) - pow(a,11)/FACTORIAL(11) + pow(a,13)/FACTORIAL(13);// -
pow(a,15)/FACTORIAL(15) + pow(a,17)/FACTORIAL(17);
return r;
}
*/
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GeoDlg dialog
GeoDlg::GeoDlg(CWnd* pParent /*=NULL*/)
: CDialog(GeoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(GeoDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void GeoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(GeoDlg)
DDX_Control(pDX, IDC_LAT2DEG_EDIT, m_lat2deg_edit);
DDX_Control(pDX, IDC_LON2SEC_EDIT, m_lon2sec_edit);
DDX_Control(pDX, IDC_LON2MIN_EDIT, m_lon2min_edit);
DDX_Control(pDX, IDC_LON2DEG_EDIT, m_lon2deg_edit);
DDX_Control(pDX, IDC_LON2_COMBO, m_lon2_combo);
DDX_Control(pDX, IDC_LON1SEC_EDIT, m_lon1sec_edit);
DDX_Control(pDX, IDC_LON1MIN_EDIT, m_lon1min_edit);
DDX_Control(pDX, IDC_LON1DEG_EDIT, m_lon1deg_edit);
DDX_Control(pDX, IDC_LON1_COMBO, m_lon1_combo);
DDX_Control(pDX, IDC_LAT2SEC_EDIT, m_lat2sec_edit);
DDX_Control(pDX, IDC_LAT2MIN_EDIT, m_lat2min_edit);
DDX_Control(pDX, IDC_LAT2_COMBO, m_lat2_combo);
DDX_Control(pDX, IDC_LAT1SEC_EDIT, m_lat1sec_edit);
DDX_Control(pDX, IDC_LAT1MIN_EDIT, m_lat1min_edit);
DDX_Control(pDX, IDC_LAT1DEG_EDIT, m_lat1deg_edit);
DDX_Control(pDX, IDC_LAT1_COMBO, m_lat1_combo);
DDX_Control(pDX, IDC_GC_MI_EDIT, m_gc_mi_edit);
DDX_Control(pDX, IDC_GC_KM_EDIT, m_gc_km_edit);
DDX_Control(pDX, IDC_ELLIPSE_MI_EDIT, m_ellipse_mi_edit);
DDX_Control(pDX, IDC_ELLIPSE_KM_EDIT, m_ellipse_km_edit);
DDX_Control(pDX, IDC_AZRAD_EDIT, m_azrad_edit);
DDX_Control(pDX, IDC_AZDEG_EDIT, m_azdeg_edit);
DDX_Control(pDX, IDC_APPROX_MI_EDIT, m_approx_mi_edit);
DDX_Control(pDX, IDC_APPROX_KM_EDIT, m_approx_km_edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(GeoDlg, CDialog)
//{{AFX_MSG_MAP(GeoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_CALCULATE, OnCalculate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GeoDlg message handlers
BOOL GeoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_lat1_combo.SetCurSel(0);
m_lon1_combo.SetCurSel(1);
m_lat2_combo.SetCurSel(0);
m_lon2_combo.SetCurSel(1);
m_lat1deg_edit.LimitText(2);
m_lat1min_edit.LimitText(2);
m_lat1sec_edit.LimitText(4);
m_lon1deg_edit.LimitText(3);
m_lon1min_edit.LimitText(2);
m_lon1sec_edit.LimitText(4);
m_lat2deg_edit.LimitText(2);
m_lat2min_edit.LimitText(2);
m_lat2sec_edit.LimitText(4);
m_lon2deg_edit.LimitText(3);
m_lon2min_edit.LimitText(2);
m_lon2sec_edit.LimitText(4);
return TRUE; // return TRUE unless you set the focus to a control
}
void GeoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void GeoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR GeoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void GeoDlg::OnCalculate()
{
char text[256];
double lat1, lon1, lat2, lon2;
double dist, az;
double deg, min, sec;
CString msg = "";
memset(text,0,(size_t)256);
m_lat1deg_edit.GetWindowText(text,255);
deg = atof(text);
memset(text,0,(size_t)256);
m_lat1min_edit.GetWindowText(text,255);
min = atof(text);
memset(text,0,(size_t)256);
m_lat1sec_edit.GetWindowText(text,255);
sec = atof(text);
if ((deg < -90.0) || (deg > 90.0))
{
msg += "Latitude 1: degrees out of range, must be between (-90,90)\n";
}
if ((min < 0) || (min > 59))
{
msg += "Latitude 1: minutes out of range, must be between (0,59)\n";
}
if ((sec < 0) || (sec >= 60))
{
msg += "Latitude 1: seconds out of range, must be between (0,59)\n";
}
lat1 = deg + min/60.0 + sec/3600.0;
lat1 = (m_lat1_combo.GetCurSel()==0)?lat1:-lat1;
memset(text,0,(size_t)256);
m_lon1deg_edit.GetWindowText(text,255);
deg = atof(text);
memset(text,0,(size_t)256);
m_lon1min_edit.GetWindowText(text,255);
min = atof(text);
memset(text,0,(size_t)256);
m_lon1sec_edit.GetWindowText(text,255);
sec = atof(text);
lon1 = deg + min/60.0 + sec/3600.0;
lon1 = (m_lon1_combo.GetCurSel()==0)?lon1:-lon1;
if ((deg < -180.0) || (deg > 180.0))
{
msg += "Longitude 1: degrees out of range, must be between (-90,90)\n";
}
if ((min < 0) || (min > 59))
{
msg += "Longitude 1: minutes out of range, must be between (0,59)\n";
}
if ((sec < 0) || (sec >= 60))
{
msg += "Longitude 1: seconds out of range, must be between (0,59)\n";
}
memset(text,0,(size_t)256);
m_lat2deg_edit.GetWindowText(text,255);
deg = atof(text);
memset(text,0,(size_t)256);
m_lat2min_edit.GetWindowText(text,255);
min = atof(text);
memset(text,0,(size_t)256);
m_lat2sec_edit.GetWindowText(text,255);
sec = atof(text);
lat2 = deg + min/60.0 + sec/3600.0;
lat2 = (m_lat2_combo.GetCurSel()==0)?lat2:-lat2;
if ((deg < -90.0) || (deg > 90.0))
{
msg += "Latitude 2: degrees out of range, must be between (-90,90)\n";
}
if ((min < 0) || (min > 59))
{
msg += "Latitude 2: minutes out of range, must be between (0,59)\n";
}
if ((sec < 0) || (sec >= 60))
{
msg += "Latitude 2: seconds out of range, must be between (0,59)\n";
}
memset(text,0,(size_t)256);
m_lon2deg_edit.GetWindowText(text,255);
deg = atof(text);
memset(text,0,(size_t)256);
m_lon2min_edit.GetWindowText(text,255);
min = atof(text);
memset(text,0,(size_t)256);
m_lon2sec_edit.GetWindowText(text,255);
sec = atof(text);
lon2 = deg + min/60.0 + sec/3600.0;
lon2 = (m_lon2_combo.GetCurSel()==0)?lon2:-lon2;
if ((deg < -180.0) || (deg > 180.0))
{
msg += "Longitude 2: degrees out of range, must be between (-90,90)\n";
}
if ((min < 0) || (min > 59))
{
msg += "Longitude 2: minutes out of range, must be between (0,59)\n";
}
if ((sec < 0) || (sec >= 60))
{
msg += "Longitude 2: seconds out of range, must be between (0,59)\n";
}
if (msg.GetLength() > 0)
{
CString errmsg = "Please correct the following errors:\n\n";
errmsg += msg;
AfxMessageBox((LPCTSTR)errmsg,MB_ICONERROR);
return;
}
dist = GCDistance(lat1,lon1,lat2,lon2);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist);
m_gc_km_edit.SetWindowText(text);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist*GEO::KM2MI);
m_gc_mi_edit.SetWindowText(text);
dist = ApproxDistance(lat1,lon1,lat2,lon2);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist);
m_approx_km_edit.SetWindowText(text);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist*GEO::KM2MI);
m_approx_mi_edit.SetWindowText(text);
dist = EllipsoidDistance(lat1,lon1,lat2,lon2);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist);
m_ellipse_km_edit.SetWindowText(text);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",dist*GEO::KM2MI);
m_ellipse_mi_edit.SetWindowText(text);
az = GCAzimuth(lat1,lon1,lat2,lon2);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",az);
m_azdeg_edit.SetWindowText(text);
memset(text,0,(size_t)256);
sprintf(text,"%.5f",az*GEO::DE2RA);
m_azrad_edit.SetWindowText(text);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -