ControlPoint3DDlg.cpp
上传用户:zj_jiuzhou
上传日期:2022-06-20
资源大小:1859k
文件大小:9k
源码类别:
3D图形编程
开发平台:
Visual C++
- // ControlPoint3DDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ControlPoint3D.h"
- #include "ControlPoint3DDlg.h"
- #include "InputPoint.h"
- #include "stdlib.h"
- #include "math.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define PI 3.141592653
- /////////////////////////////////////////////////////////////////////////////
- // 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()
- /////////////////////////////////////////////////////////////////////////////
- // CControlPoint3DDlg dialog
- CControlPoint3DDlg::CControlPoint3DDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CControlPoint3DDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CControlPoint3DDlg)
- m_strPath = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_Sab=0;
- bCal = false;
- }
- void CControlPoint3DDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CControlPoint3DDlg)
- DDX_Control(pDX, IDC_LIST_INFO, m_ListContl_Info);
- DDX_Text(pDX, IDC_EDIT_PATH, m_strPath);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CControlPoint3DDlg, CDialog)
- //{{AFX_MSG_MAP(CControlPoint3DDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTN_READ, OnButnRead)
- ON_BN_CLICKED(IDC_BUTN_EXPORT, OnButnExport)
- ON_BN_CLICKED(IDC_BUTN_CAL, OnButnCal)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CControlPoint3DDlg message handlers
- BOOL CControlPoint3DDlg::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_ListContl_Info.InsertColumn(0," 点号",LVCFMT_LEFT,50,0);
- m_ListContl_Info.InsertColumn(1," X",LVCFMT_LEFT,100,0);
- m_ListContl_Info.InsertColumn(2," Y",LVCFMT_LEFT,100,0);
- m_ListContl_Info.InsertColumn(3," Z",LVCFMT_LEFT,100,0);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CControlPoint3DDlg::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 CControlPoint3DDlg::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 CControlPoint3DDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CControlPoint3DDlg::OnOK()
- {
- // TODO: Add extra validation here
- m_inPointList.RemoveAll();
- m_strPath=" ";
- m_ListContl_Info.DeleteAllItems();
- SetDlgItemText(IDC_STATIC_TIPS,"");
- UpdateData(FALSE);
- //CDialog::OnOK();
- }
- void CControlPoint3DDlg::OnButnRead()
- {
- // TODO: Add your control notification handler code here
- CFileDialog openFile(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt||",NULL);
- if (openFile.DoModal()==IDCANCEL)
- return ;
- m_strPath = openFile.GetPathName();
- UpdateData(false);
- //read data
- CInputPoint *pPoint;
- FILE * pInFile;
- pInFile = fopen(m_strPath,"r");
- if (pInFile!=NULL)
- {
- //第一行基线长度
- fscanf(pInFile,"%lf",&m_Sab);
- //第二行以后每行一个点的测量纪录
- while(!feof(pInFile))
- {
- int nOrderNum =0 ;//point order number
- double LeftHorizontalAngle = 0.0;//左站水平角
- double LeftZenithdistance = 0.0;//左站天顶距
- double RightHorizontalAngle = 0.0;//右站水平角
- double RightZenithdistance = 0.0;//右站天顶距
- fscanf(pInFile,"%d%lf%lf%lf%lf",&nOrderNum,&LeftHorizontalAngle,&LeftZenithdistance,
- &RightHorizontalAngle,&RightZenithdistance);
- pPoint = new CInputPoint();
- pPoint->m_nOrderNum = nOrderNum;
- pPoint->m_LeftHorizontalAngle = 2*PI - ConvertAngleToRadian(LeftHorizontalAngle);
- pPoint->m_LeftZenithdistance = PI/2 - ConvertAngleToRadian(LeftZenithdistance);
- pPoint->m_RightHorizontalAngle = PI/2 - ConvertAngleToRadian(RightHorizontalAngle);
- pPoint->m_RightZenithdistance = ConvertAngleToRadian(RightZenithdistance);
- m_inPointList.AddTail(pPoint);
- }
- fclose(pInFile);
- }
- else
- {
- MessageBox("Can't open the file");
- }
- }
- void CControlPoint3DDlg::OnButnExport()
- {
- // TODO: Add your control notification handler code here
- //输出控制点三维坐标
- if (m_strPath=="")
- {
- MessageBox("请先导入坐标文件!");
- return;
- }
- if (!bCal)
- {
- MessageBox("请先点击计算!");
- return;
- }
- CString strIndir = m_strPath.Left(m_strPath.ReverseFind('\'));//m_strPath.GetLength() -
- CString temp = "结果保存在:"+ strIndir + "\ControlPoint3D.txt";
- SetDlgItemText(IDC_STATIC_TIPS,temp);
- strIndir+="\ControlPoint3D.txt";
- FILE * fp_out;
- fp_out=fopen(strIndir,"w");
- fprintf(fp_out,"点号 X坐标 Y坐标 Z坐标n");
- CInputPoint * pPoint = new CInputPoint();
- POSITION ps = m_inPointList.GetHeadPosition();
- for (int i=0;i<m_inPointList.GetCount()-1;i++)
- {
- pPoint = m_inPointList.GetNext(ps);
- fprintf(fp_out,"%d %lf %lf %lfn",pPoint->m_nOrderNum,pPoint->X,pPoint->Y,pPoint->Z);
- }
- fclose(fp_out);
- }
- void CControlPoint3DDlg::OnButnCal()
- {
- // TODO: Add your control notification handler code here
- //清空列表中的内容
- m_ListContl_Info.DeleteAllItems();
- int PointNum = m_inPointList.GetCount();
- CInputPoint * pPoint = new CInputPoint();
- POSITION ps = m_inPointList.GetHeadPosition();
- CString tempConvert;
- //将结果写入表中
- for (int i=0;i<PointNum-1;i++)
- {
- pPoint = m_inPointList.GetNext(ps);
- //计算结果
- pPoint->Y = CalCordination(m_Sab,pPoint->m_LeftHorizontalAngle,pPoint->m_RightHorizontalAngle,&pPoint->X);
- pPoint->Z = CalElevation(0,0,pPoint->m_LeftZenithdistance,pPoint->m_RightZenithdistance,pPoint->X,pPoint->Y,m_Sab);
- //结果写入表中
- m_ListContl_Info.InsertItem(i,"");
- tempConvert.Format("%d",pPoint->m_nOrderNum);
- m_ListContl_Info.SetItemText(i,0,tempConvert);
- tempConvert.Format("%.5f",pPoint->X);
- m_ListContl_Info.SetItemText(i,1,tempConvert);
- tempConvert.Format("%.5f",pPoint->Y);
- m_ListContl_Info.SetItemText(i,2,tempConvert);
- tempConvert.Format("%.5f",pPoint->Z);
- m_ListContl_Info.SetItemText(i,3,tempConvert);
- }
- SetDlgItemText(IDC_STATIC_TIPS,"计算时以A为原点,n AB连线为Y轴,nA、B两点的高程均为0");
- bCal =true;
- }
- double CControlPoint3DDlg::CalCordination(double Sab, double lefth, double Righth, double *X)
- {
- *X = Sab/(1/tan(lefth) + 1/tan(Righth));
- return Sab/(1/tan(lefth) + 1/tan(Righth)) / tan(lefth);
- }
- double CControlPoint3DDlg::CalElevation(double Ha, double Hb,double AngleA,double AngleB, double X, double Y, double Sab)
- {
- double h1 = Ha + sqrt(X*X + Y* Y);
- h1 *= cos(AngleA);
- double h2 = Hb + sqrt( X*X+(Y-Sab)*(Y-Sab));
- h2 *=cos(AngleB);
- return (h1+h2)/2;
- }
- double CControlPoint3DDlg::ConvertAngleToRadian(double Angle)
- {
- int a,b,c;
- a=(int)Angle;
- b=int((Angle-a)*100);
- c=int(((Angle-a)*100-b)*100);
- return (a+b/60.0+c/3600.0)*PI/180;
- }