// designsurveylinedlg.cpp : 实现文件 // #include "stdafx.h" #include "designsurveylinedlg.h" #include "afxdialogex.h" // DesignSurveyLineDlg 对话框 IMPLEMENT_DYNAMIC(DesignSurveyLineDlg, CBCGPDialog) DesignSurveyLineDlg::DesignSurveyLineDlg(CWnd* pParent /*=NULL*/) : CBCGPDialog(DesignSurveyLineDlg::IDD, pParent) { EnableVisualManagerStyle(TRUE, TRUE); bDrawRegion = false; } DesignSurveyLineDlg::~DesignSurveyLineDlg() { } void DesignSurveyLineDlg::DoDataExchange(CDataExchange* pDX) { CBCGPDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_BTN_SAVEREGION, m_btnSaveRegion); } BEGIN_MESSAGE_MAP(DesignSurveyLineDlg, CBCGPDialog) ON_BN_CLICKED(IDC_BTN_INPUTREGION, &DesignSurveyLineDlg::OnBnClickedBtnInputregion) ON_BN_CLICKED(IDC_BTN_DRAWREGION, &DesignSurveyLineDlg::OnBnClickedBtnDrawregion) ON_BN_CLICKED(IDC_BTN_SAVEREGION, &DesignSurveyLineDlg::OnBnClickedBtnSaveregion) ON_BN_CLICKED(IDC_BTN_BINDLINE, &DesignSurveyLineDlg::OnBnClickedBtnBindline) ON_BN_CLICKED(IDC_BTN_CALCULATELINE, &DesignSurveyLineDlg::OnBnClickedBtnCalculateline) ON_WM_CLOSE() END_MESSAGE_MAP() BOOL DesignSurveyLineDlg::OnInitDialog() { CBCGPDialog::OnInitDialog(); CenterWindow(); GetDlgItem( IDC_BTN_CALCULATELINE )->EnableWindow( false ); return TRUE; } //提取没有后缀名的文件名 CString DesignSurveyLineDlg::extractFileName(CString fileName) { // 查找最后一个点的位置 int dotIndex = fileName.ReverseFind(_T('.')); // 如果找到了点,并且点不是第一个字符 if (dotIndex != -1) { // 提取文件名,不包括后缀 CString fileNameWithoutExtension = fileName.Left(dotIndex); return fileNameWithoutExtension; } else { // 如果没有找到点,说明没有后缀,直接显示文件名 return fileName; } } //设置航测区域 void DesignSurveyLineDlg::SetSurveyRegion(const vector& lons,const vector& lats) { for (int i=0;iEnableWindow( true ); } //计算测绘航线 void DesignSurveyLineDlg::calculateSurveyLine(double lineInterval,vector&surveyLineLons,vector& surveyLineLats) { vector recLons; vector recLats; TopologicalAnalysis analysis; GeoCompute geocompute; analysis.GetBoundingBoxVertices(surveyRegionLons,surveyRegionLats,recLons,recLats); double lon1,lat1,lon2,lat2; //第一条切割线为航线间隔一半 geocompute.computeOffsetGeoPosition(recLons[0],recLats[0],180,lineInterval/2000,lon1,lat1); geocompute.computeOffsetGeoPosition(recLons[1],recLats[1],180,lineInterval/2000,lon2,lat2); Point2D pt1,pt2; pt1.x = lon1; pt1.y = lat1; pt2.x = lon2; pt2.y = lat2; vector result; analysis.linePolygonIntersections(pt1,pt2,surveyRegionLons,surveyRegionLats,result); while(lat1>recLats[2]){ //平移切割线 geocompute.computeOffsetGeoPosition(lon1,lat1,180,lineInterval/1000,lon1,lat1); geocompute.computeOffsetGeoPosition(lon2,lat2,180,lineInterval/1000,lon2,lat2); pt1.x = lon1; pt1.y = lat1; pt2.x = lon2; pt2.y = lat2; //计算交点 analysis.linePolygonIntersections(pt1,pt2,surveyRegionLons,surveyRegionLats,result); } //串联交点 int j = 1; for (int i=0;i&surveyLineLons,const vector& surveyLineLats,double height) { //写航线 CString filename; CString strRouteFileDir = GetSoftwareCurrentDirectory() + _T("\\Route\\") + _T("测绘航线\\"); //测绘航线文件夹不存在则创建 if (!SearchDirectory(strRouteFileDir)) { CreateDirectory(strRouteFileDir); } TCHAR s[10000]; s[0]=0; CString defaultName = g_regionFileName + "-测绘航线.route"; CFileDialog dlg(FALSE, _T(".route"), defaultName); dlg.m_ofn.lpstrTitle=_T("保存测绘航线文件"); /* dlg.m_ofn.lpstrFile=s; dlg.m_ofn.nMaxFile=sizeof(s)/sizeof(TCHAR);*/ TCHAR filter[500]=_T("测绘航线文件(*.route)\0*.route\0"); dlg.m_ofn.lpstrFilter=filter; dlg.m_ofn.Flags|=OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_CREATEPROMPT; dlg.m_ofn.lpstrInitialDir = strRouteFileDir; if (IDOK == dlg.DoModal()) { filename = dlg.GetPathName(); g_linePathName = filename; g_lineFileName = extractFileName(dlg.GetFileName()); FILE* fp = fopen(filename,"w"); int iLineNum = 5; fprintf(fp,"%d, 0, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum, 0.0, 0.0, 0.0); int i = 0; for (i;i&surveyRegionLons,const vector& surveyRegionLats) { //写航线 CString filename; CString strRouteFileDir = GetSoftwareCurrentDirectory() + _T("\\Route\\") + _T("测绘航线\\"); //测绘航线文件夹不存在则创建 if (!SearchDirectory(strRouteFileDir)) { CreateDirectory(strRouteFileDir); } TCHAR s[10000]; s[0]=0; CFileDialog dlg(FALSE, _T(".txt"), _T("测绘区域1.txt")); dlg.m_ofn.lpstrTitle=_T("保存测绘区域文件"); /* dlg.m_ofn.lpstrFile=s; dlg.m_ofn.nMaxFile=sizeof(s)/sizeof(TCHAR);*/ TCHAR filter[500]=_T("测绘区域文件(*.txt)\0*.txt\0"); dlg.m_ofn.lpstrFilter=filter; dlg.m_ofn.Flags|=OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_CREATEPROMPT; dlg.m_ofn.lpstrInitialDir = strRouteFileDir; if (IDOK == dlg.DoModal()) { filename = dlg.GetPathName(); g_regionPathName = filename; g_regionFileName = extractFileName(dlg.GetFileName()); FILE* fp = fopen(filename,"w"); int iLineNum = 5; fprintf(fp,"%d, 0, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum, 0.0, 0.0, 0.0); int i = 0; for (i;iEnableWindow( true ); } else { return; } } //绘制航测区 void DesignSurveyLineDlg::OnBnClickedBtnDrawregion() { bDrawRegion = true; } //保存航测区 void DesignSurveyLineDlg::OnBnClickedBtnSaveregion() { m_btnSaveRegion.EnableWindow(false); if (saveSurveyRegion(surveyRegionLons,surveyRegionLats)) { char* path = g_regionPathName.GetBuffer(); //发送消息到主程序,进行标绘 if (g_mapHwnd != NULL) { ::SendMessage(g_mapHwnd, WM_SEND_SHOWSURVEYREGION, (WPARAM)path, 0); } } m_btnSaveRegion.EnableWindow(true); } //装订测绘航线 void DesignSurveyLineDlg::OnBnClickedBtnBindline() { // TODO: 在此添加控件通知处理程序代码 } //生成航测航线 void DesignSurveyLineDlg::OnBnClickedBtnCalculateline() { if (surveyRegionLats.size()<3) { BCGPMessageBox("航测区域无效或缺少航测区域!"); return; } CString cstr; GetDlgItemText(IDC_EDIT_HEIGHT,cstr); double height = _ttof(cstr); if (height<=0||height>500) { BCGPMessageBox("航高范围为(0,500]m!"); return; } GetDlgItemText(IDC_EDIT_LINEINTERVAL,cstr); double lineInterval = _ttof(cstr); if (lineInterval < 1 ) { BCGPMessageBox("航线间隔必须大于1m"); return; } g_Height = height; //测绘航线坐标 vector surveyLineLons; vector surveyLineLats; //计算航测航线 calculateSurveyLine(lineInterval,surveyLineLons,surveyLineLats); //保存航测航线 saveSurveyLine(surveyLineLons,surveyLineLats,height); //发送消息到主程序,进行标绘 if (g_mapHwnd != NULL) { char* path = g_linePathName.GetBuffer(); ::SendMessage(g_mapHwnd, WM_SEND_SHOWSURVEYLINE, (WPARAM)path, 0); } } void DesignSurveyLineDlg::OnClose() { CBCGPDialog::OnClose(); //发送消息到主程序,进行显示 if (g_mapHwnd != NULL) { ::SendMessage(g_mapHwnd, WM_CLEAR_TMPSURVEYFEATURE, 0, 0); } }