📄 dlgprojection.cpp
字号:
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project
//
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
//
#include "stdafx.h"
#include "nrdb.h"
#include "DlgProjection.h"
#include "viewmap.h"
#include "docmap.h"
#include "dlgutm.h"
#include "projctns.h"
#include "definitions.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
#define ELLIPSOIDDP 3
/////////////////////////////////////////////////////////////////////////////
inline void swap(double& d1, double& d2)
{
double dTemp = d1;
d1 = d2;
d2 = dTemp;
}
/////////////////////////////////////////////////////////////////////////////
// CDlgProjection dialog
CDlgProjection::CDlgProjection(CWnd* pParent /*=NULL*/)
: CDialog(CDlgProjection::IDD, pParent)
{
m_lMaxId = 0;
m_lDefaultId = 0;
m_bLatLon = FALSE;
m_bUpdate = FALSE;
m_bUTMTip = FALSE;
//{{AFX_DATA_INIT(CDlgProjection)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgProjection::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgProjection)
DDX_Control(pDX, IDC_COORDASLATLON, m_ckCoordAsLatLon);
DDX_Control(pDX, IDC_ELLIPSOID, m_cbEllipsoid);
DDX_Control(pDX, IDC_MINNORTHING, m_eMinNorthing);
DDX_Control(pDX, IDC_MINEASTING, m_eMinEasting);
DDX_Control(pDX, IDC_MAXNORTHING, m_eMaxNorthing);
DDX_Control(pDX, IDC_MAXEASTING, m_eMaxEasting);
DDX_Control(pDX, IDC_SEMIMINORAXIS, m_eSemiMinorAxis);
DDX_Control(pDX, IDC_SEMIMAJORAXIS, m_eSemiMajorAxis);
DDX_Control(pDX, IDC_SCALEFACTOR, m_eScaleFactor);
DDX_Control(pDX, IDC_LONGITUDEORIGIN, m_eLongitudeOrigin);
DDX_Control(pDX, IDC_LATITUDEORIGIN, m_eLatitudeOrigin);
DDX_Control(pDX, IDC_FALSENORTHING, m_eFalseNorthing);
DDX_Control(pDX, IDC_FALSEEASTING, m_eFalseEasting);
DDX_Control(pDX, IDC_EDITNAME, m_eName);
DDX_Control(pDX, IDC_NAME, m_cbProjections);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgProjection, CDialog)
//{{AFX_MSG_MAP(CDlgProjection)
ON_CBN_SELCHANGE(IDC_NAME, OnSelchangeName)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_UPDATE, OnEdit)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_SETEXTENT, OnSetExtent)
ON_CBN_SELCHANGE(IDC_ELLIPSOID, OnSelchangeEllipsoid)
ON_EN_CHANGE(IDC_EDITNAME, OnChange)
ON_EN_CHANGE(IDC_FALSEEASTING, OnChange)
ON_EN_CHANGE(IDC_FALSENORTHING, OnChange)
ON_EN_CHANGE(IDC_LATITUDEORIGIN, OnChange)
ON_EN_CHANGE(IDC_LONGITUDEORIGIN, OnChange)
ON_EN_CHANGE(IDC_MAXEASTING, OnChange)
ON_EN_CHANGE(IDC_MAXNORTHING, OnChange)
ON_EN_CHANGE(IDC_MINEASTING, OnChange)
ON_EN_CHANGE(IDC_MINNORTHING, OnChange)
ON_EN_CHANGE(IDC_SCALECOORDS, OnChange)
ON_EN_CHANGE(IDC_SCALEFACTOR, OnChange)
ON_EN_CHANGE(IDC_SEMIMAJORAXIS, OnChange)
ON_EN_CHANGE(IDC_SEMIMINORAXIS, OnChange)
ON_MESSAGE(WM_UTMTIP, OnUTMTip)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgProjection message handlers
BOOL CDlgProjection::OnInitDialog()
{
CDialog::OnInitDialog();
if (BDGetTransLevel(BDHandle()) > 0) BDCommit(BDHandle());
ASSERT(BDGetTransLevel(BDHandle()) == 0);
// Fill list of projections (skip UTM)
for (int i = 1; i < sizeof(CEllipsoid::m_aEllipsoids)/sizeof(ELLIPSOID); i++)
{
int index = m_cbEllipsoid.AddString(CEllipsoid::m_aEllipsoids[i].m_psName);
m_cbEllipsoid.SetItemData(index, i);
}
Update();
// If no projection then set to UTM scale factor to 1
if (m_lDefaultId == 0)
{
if (!m_bUTMTip) PostMessage(WM_UTMTIP);
}
// Display the default format for coordinates
m_ckCoordAsLatLon.SetCheck(BDGetSettings().m_bCoordAsLatLon);
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
void CDlgProjection::Update(BOOL bInit)
{
m_cbProjections.ResetContent();
// List available projections
CBDProjection projection;
BOOL bFound = BDProjection(BDHandle(), &projection, BDGETINIT);
while (bFound)
{
int index = m_cbProjections.AddString(projection.m_sName);
m_cbProjections.SetItemData(index, projection.m_nID);
if (projection.m_bDefault)
{
if (bInit)
{
m_lDefaultId = projection.m_nID;
};
m_cbProjections.SetCurSel(index);
};
m_lMaxId = max(m_lMaxId, projection.m_nID);
bFound = BDGetNext(BDHandle());
}
BDEnd(BDHandle());
OnSelchangeName();
}
/////////////////////////////////////////////////////////////////////////////
void CDlgProjection::OnSelchangeName()
{
CBDProjection projection;
// Determine selected value
int index = m_cbProjections.GetCurSel();
if (index != CB_ERR)
{
// Retrieve value from the database
projection.m_nID = m_cbProjections.GetItemData(index);
if (BDProjection(BDHandle(), &projection, BDSELECT))
{
// Determine if the elipsoid parameters match any of the defaults
for (index = 0; index < m_cbEllipsoid.GetCount(); index++)
{
int i = m_cbEllipsoid.GetItemData(index);
CEllipsoid* pEllipsoid = (CEllipsoid*)(&CEllipsoid::m_aEllipsoids[i]);
// Match Ellipsoid
if (fabs(projection.m_dSemiMajorAxis - pEllipsoid->GetSemiMajorAxis()) < 0.001 &&
fabs(projection.m_dSemiMinorAxis - pEllipsoid->GetSemiMinorAxis()) < 0.001)
{
m_cbEllipsoid.SetCurSel(index);
OnSelchangeEllipsoid();
break;
}
// Latitude / Longitude
if (fabs(projection.m_dSemiMajorAxis - pEllipsoid->GetSemiMajorAxis()) < 0.001 &&
fabs(projection.m_dSemiMajorAxis - LATLON_ID) < 0.001)
{
m_cbEllipsoid.SetCurSel(index);
OnSelchangeEllipsoid();
break;
}
// Default
if (fabs(pEllipsoid->GetSemiMajorAxis()) < 0.001)
{
m_cbEllipsoid.SetCurSel(index);
}
}
// Update controls
m_eName.SetWindowText(projection.m_sName);
m_eSemiMajorAxis.SetValue(projection.m_dSemiMajorAxis, ELLIPSOIDDP);
m_eSemiMinorAxis.SetValue(projection.m_dSemiMinorAxis, ELLIPSOIDDP);
m_eLatitudeOrigin.SetValue(projection.m_dLatitudeOrigin, 1);
m_eLongitudeOrigin.SetValue(projection.m_dLongitudeOrigin, 1);
m_eFalseNorthing.SetValue(projection.m_dFalseNorthing, 1);
m_eFalseEasting.SetValue(projection.m_dFalseEasting, 1);
m_eScaleFactor.SetValue(projection.m_dScaleFactorAtOrigin, 10);
// Display min/max easting/northing as latitude/longitude
double dMinEasting = projection.m_dMinEasting;
double dMaxEasting = projection.m_dMaxEasting;
double dMinNorthing = projection.m_dMinNorthing;
double dMaxNorthing = projection.m_dMaxNorthing;
int nDP = 0;
if (m_bLatLon)
{
BDProjection()->TransMercatorToLatLon(dMinEasting, dMinNorthing, &dMinNorthing, &dMinEasting);
BDProjection()->TransMercatorToLatLon(dMaxEasting, dMaxNorthing, &dMaxNorthing, &dMaxEasting);
nDP = -1;
}
m_eMinEasting.SetValue(dMinEasting,nDP);
m_eMaxEasting.SetValue(dMaxEasting,nDP);
m_eMinNorthing.SetValue(dMinNorthing,nDP);
m_eMaxNorthing.SetValue(dMaxNorthing,nDP);
}
BDEnd(BDHandle());
}
// Update the default conversion
UpdateDefault();
m_bUpdate = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CDlgProjection::OnUTMTip(WPARAM, LPARAM)
{
CDlgUTM dlg;
if (dlg.DoModal() == IDOK)
{
CString s;
s.Format("%i", -177+(abs(dlg.GetZone())-1)*6);
CProjection projection;
projection.m_bDefault = TRUE;
projection.m_nID = 1;
projection.m_dFalseEasting = 500000;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -