📄 utilitydlg.cpp
字号:
// utilityDlg.cpp : implementation file
//
#include "stdafx.h"
#include "utility.h"
#include "utilityDlg.h"
#include "valuSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CUtilityDlg dialog
CUtilityDlg::CUtilityDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUtilityDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUtilityDlg)
m_sel1 = 0;
m_sel2 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_ico1=AfxGetApp()->LoadIcon(IDI_ICON1);
m_ico2=AfxGetApp()->LoadIcon(IDI_ICON2);
ptran.InitValue();
tran.InitValue();
}
void CUtilityDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUtilityDlg)
DDX_Control(pDX, IDC_BUTTON2, m_but2);
DDX_Control(pDX, IDC_BUTTON1, m_but1);
DDX_Radio(pDX, IDC_RADIO1, m_sel1);
DDX_Radio(pDX, IDC_RADIO3, m_sel2);
//}}AFX_DATA_MAP
DDX_GridControl(pDX, IDC_LIST1, m_xyzList);
DDX_GridControl(pDX, IDC_LIST2, m_blhList);
}
BEGIN_MESSAGE_MAP(CUtilityDlg, CDialog)
//{{AFX_MSG_MAP(CUtilityDlg)
ON_WM_SYSCOMMAND()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_COMMAND(ID_VAL_SET, OnValSet)
ON_COMMAND(ID_FILE_SAVEDATA, OnFileSavedata)
ON_COMMAND(ID_FILE_SAVERES, OnFileSaveres)
ON_COMMAND(ID_PRINT_DATA, OnPrintData)
ON_COMMAND(ID_PRINT_RES, OnPrintRes)
ON_COMMAND(IDM_ABOUTBOX, OnAboutbox)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUtilityDlg message handlers
BOOL CUtilityDlg::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
// TODO: Add extra initialization here
m_but1.SetIcon(m_ico1);
m_but2.SetIcon(m_ico2);
// m_but1.EnableWindow(FALSE);
// m_but2.EnableWindow(FALSE);
InitXYZList();
InitBLHList();
return TRUE; // return TRUE unless you set the focus to a control
}
void CUtilityDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CUtilityDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CUtilityDlg::FillXYZList(CCoordTranBase * base)
{
int comax;
m_xyzList.EmptyAll();
InitXYZList();
comax=(m_xyzList.GetRowCount()>base->m_xyz.GetSize())?m_xyzList.GetRowCount():base->m_xyz.GetSize();
m_xyzList.SetRowCount(comax);
// fill rows/cols with text
for (int row = 0; row < base->m_xyz.GetSize(); row++)
for (int col = 0; col < m_xyzList.GetColumnCount(); col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row+1;
Item.col = col;
Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
if(col==0)
Item.szText.Format("%.10f",(base->m_xyz.GetAt(row).x));
else if(col==1)
Item.szText.Format("%.10f",(base->m_xyz.GetAt(row).y));
else
Item.szText.Format("%.10f",(base->m_xyz.GetAt(row).z));
m_xyzList.SetItem(&Item);
}
if(base->m_ntype==CPROJ_TRAN)
{
for(int i=0;i<comax;i++)
m_xyzList.SetItemState(i,2, m_blhList.GetItemState(1,1) | GVIS_READONLY);
}
//m_xyzList.AutoSizeColumns();
m_xyzList.RedrawWindow();
return row;
}
void CUtilityDlg::InitXYZList()
{
m_xyzList.SetEditable();
m_xyzList.SetListMode();
m_xyzList.EnableDragAndDrop();
m_xyzList.SetTextBkColor(RGB(255,255,255));
try {
m_xyzList.SetRowCount(50);
m_xyzList.SetColumnCount(3);
m_xyzList.SetFixedRowCount(1);
m_xyzList.SetFixedColumnCount(0);
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
return;
}
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = 0;
Item.col = 0;
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("X坐标:"),1);
m_xyzList.SetItem(&Item);
Item.col=1;
Item.szText.Format(_T("Y坐标:"),1);
m_xyzList.SetItem(&Item);
Item.col=2;
Item.szText.Format(_T("Z坐标:"),2);
m_xyzList.SetItem(&Item);
m_xyzList.EnableSelection(FALSE);
CRect rt;
m_xyzList.GetClientRect(rt);
int width=rt.Width()/m_xyzList.GetColumnCount();
for(int i=0;i<m_xyzList.GetColumnCount();i++)
m_xyzList.SetColumnWidth(i,width);
for(i=0;i<m_xyzList.GetRowCount();i++)
m_xyzList.SetRowHeight(i,20);
}
void CUtilityDlg::InitBLHList()
{
m_blhList.SetEditable();
m_blhList.SetListMode();
m_blhList.EnableDragAndDrop();
m_blhList.SetTextBkColor(RGB(255,255,255));
try {
m_blhList.SetRowCount(50);
m_blhList.SetColumnCount(3);
m_blhList.SetFixedRowCount(1);
m_blhList.SetFixedColumnCount(0);
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
return;
}
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = 0;
Item.col = 0;
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("B:"),1);
m_blhList.SetItem(&Item);
Item.col=1;
Item.szText.Format(_T("L:"),1);
m_blhList.SetItem(&Item);
Item.col=2;
Item.szText.Format(_T("H:"),2);
m_blhList.SetItem(&Item);
m_blhList.EnableSelection(FALSE);
// Make cell 1,1 read-only
//m_blhList.SetItemState(1,1, m_blhList.GetItemState(1,1) | GVIS_READONLY);
CRect rt;
m_blhList.GetClientRect(rt);
int width=rt.Width()/m_blhList.GetColumnCount();
for(int i=0;i<m_blhList.GetColumnCount();i++)
m_blhList.SetColumnWidth(i,width);
for(i=0;i<m_blhList.GetRowCount();i++)
m_blhList.SetRowHeight(i,20);
}
void CUtilityDlg::OnFileOpen()
{
UpdateData();
CString path;
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
{
path=dlg.GetPathName();
}
else
{
AfxMessageBox("do not open file");
}
if(m_sel1==0) //大地坐标正反算
{
tran.m_blh.RemoveAll();
tran.m_xyz.RemoveAll();
tran.ReadFile(path,m_sel2);
if(m_sel2==0) //X、Y、Z——B、L、H
FillXYZList(&tran);
else
FillBLHList(&tran);
}
else
{
ptran.m_blh.RemoveAll();
ptran.m_xyz.RemoveAll();
ptran.ReadFile(path,m_sel2);
if(m_sel2==0)
FillXYZList(&ptran);
else
FillBLHList(&ptran);
}
}
int CUtilityDlg::FillBLHList(CCoordTranBase * base)
{
int comax;
m_blhList.EmptyAll();
InitBLHList();
comax=(m_blhList.GetRowCount()>base->m_blh.GetSize())?m_blhList.GetRowCount():base->m_blh.GetSize();
m_blhList.SetRowCount(comax);
// fill rows/cols with text
for (int row = 0; row < base->m_blh.GetSize(); row++)
for (int col = 0; col < m_blhList.GetColumnCount(); col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row+1;
Item.col = col;
Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
if(col==0)
Item.szText.Format("%.10f",(base->m_blh.GetAt(row).b));
else if(col==1)
Item.szText.Format("%.10f",(base->m_blh.GetAt(row).l));
else
Item.szText.Format("%.10f",(base->m_blh.GetAt(row).h));
m_blhList.SetItem(&Item);
}
if(base->m_ntype==CPROJ_TRAN)
{
for(int i=0;i<comax;i++)
m_blhList.SetItemState(i,2, m_blhList.GetItemState(1,1) | GVIS_READONLY);
}
// m_blhList.AutoSizeColumns();
m_blhList.RedrawWindow();
return row;
}
void CUtilityDlg::OnButton1()
{
blh bltemp;
CString msg;
CString str;
UpdateData();
if(m_sel2==0)
{
AfxMessageBox("数据源选择错误!");
return;
}
if(m_sel1==0)
tran.m_blh.RemoveAll();
else
ptran.m_blh.RemoveAll();
for(int i=1;i<m_blhList.GetRowCount();i++)
{
str=m_blhList.GetItemText(i,0);
bltemp.b=atof(str);
str=m_blhList.GetItemText(i,1);
bltemp.l=atof(str);
str=m_blhList.GetItemText(i,2);
bltemp.h=atof(str);
if(bltemp.b==0 && bltemp.l==0 && bltemp.h==0)
break;
if(m_sel1==0)
tran.m_blh.Add(bltemp);
else
ptran.m_blh.Add(bltemp);
}
if(m_sel1==0)
{
tran.m_xyz.RemoveAll();
tran.DecToArc();
tran.InitValue(tran.m_Flag);
tran.blhTOxyz();
FillXYZList(&tran);
}
else
{
ptran.m_xyz.RemoveAll();
ptran.DecToArc();
ptran.InitValue(ptran.m_Flag);
ptran.GussCoordTranNormal();
FillXYZList(&ptran);
}
}
void CUtilityDlg::OnButton2()
{
xyz xytemp;
CString msg;
CString str;
UpdateData();
if(m_sel2==1)
{
AfxMessageBox("数据源选择错误!");
return;
}
if(m_sel1==0)
tran.m_xyz.RemoveAll();
else
ptran.m_xyz.RemoveAll();
for(int i=1;i<m_blhList.GetRowCount();i++)
{
str=m_xyzList.GetItemText(i,0);
xytemp.x=atof(str);
str=m_xyzList.GetItemText(i,1);
xytemp.y=atof(str);
str=m_xyzList.GetItemText(i,2);
xytemp.z=atof(str);
if(xytemp.x==0 && xytemp.y==0 && xytemp.z==0)
break;
if(m_sel1==0)
tran.m_xyz.Add(xytemp);
else
ptran.m_xyz.Add(xytemp);
}
if(m_sel1==0)
{
tran.m_blh.RemoveAll();
tran.InitValue(tran.m_Flag);
tran.xyzToblh();
tran.ArcToDec();
FillBLHList(&tran);
}
else
{
ptran.m_blh.RemoveAll();
ptran.InitValue(ptran.m_Flag);
ptran.GussCoordTranRevers();
ptran.ArcToDec();
FillBLHList(&ptran);
}
}
void CUtilityDlg::OnValSet()
{
UpdateData();
CValuSet dlg;
if(m_sel1==1)
{
dlg.m_vsel=ptran.m_Flag;
dlg.m_ed4flg=TRUE;
dlg.m_af=1/ptran.af;
dlg.m_lax=ptran.lax;
dlg.m_l0=ptran.ArcToDec(ptran.L0);
}
else
{
dlg.m_vsel=tran.m_Flag;
dlg.m_ed4flg=FALSE;
dlg.m_af=1/tran.af;
dlg.m_lax=tran.lax;
}
if(dlg.DoModal()==IDOK)
{
if(dlg.m_vsel==3)
{
tran.lax=dlg.m_lax;
ptran.lax=dlg.m_lax;
tran.af=1/dlg.m_af;
ptran.af=1/dlg.m_af;
tran.m_Flag=3;
ptran.m_Flag=3;
if(dlg.m_ed4flg)
ptran.L0=ptran.DecToArc(dlg.m_l0);
}
else
{
tran.m_Flag=dlg.m_vsel;
ptran.m_Flag=dlg.m_vsel;
tran.InitValue(tran.m_Flag);
ptran.InitValue(ptran.m_Flag);
if(dlg.m_ed4flg)
ptran.L0=ptran.DecToArc(dlg.m_l0);
}
}
}
void CUtilityDlg::OnFileSavedata()
{
UpdateData();
CString path;
CFileDialog dlg(FALSE);
if(dlg.DoModal()==IDOK)
{
path=dlg.GetPathName();
if(path.IsEmpty())
{
AfxMessageBox("文件名非法!");
return;
}
}
if(m_sel1==0)
{
tran.WriteFile(path,m_sel2);
}
else
{
ptran.WriteFile(path,m_sel2);
}
}
void CUtilityDlg::OnFileSaveres()
{
UpdateData();
CString path;
CFileDialog dlg(FALSE);
if(dlg.DoModal()==IDOK)
{
path=dlg.GetPathName();
if(path.IsEmpty())
{
AfxMessageBox("文件名非法!");
return;
}
}
if(m_sel1==0)
{
tran.WriteFile(path,1-m_sel2);
}
else
{
ptran.WriteFile(path,1-m_sel2);
}
}
void CUtilityDlg::OnPrintData()
{
UpdateData();
if(m_sel2==0)
m_xyzList.Print();
else
m_blhList.Print();
}
void CUtilityDlg::OnPrintRes()
{
UpdateData();
if(m_sel2==0)
m_blhList.Print();
else
m_xyzList.Print();
}
void CUtilityDlg::OnAboutbox()
{
CAboutDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -