初版本:http://www.javashuo.com/article/p-ujqexkkp-es.htmlgit
第二版本:首先打開一個dwg圖紙,而後在dwg上拾取一段有標註的多段線,把該多段線上的點的xy座標轉化成平面座標,導出到kml文件裏面,該kml文件能夠導入到谷歌地圖等裏面成圖.api
acrxEntryPoint.cppapp
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) { AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ; // 自動加載dwg CDwgDataToXml::OnLoadDWG(); return (retCode) ; } static void HHCDwgPt2XmlApp(void) { CCoordManageDlg pDlg; pDlg.DoModal(); } static void HHOpenDwg(void) { CDwgDataToXml::OnLoadDWG(); } IMPLEMENT_ARX_ENTRYPOINT(CDwgPt2KmlApp) //註冊命令 ACED_ARXCOMMAND_ENTRY_AUTO(CDwgPt2KmlApp,HH, OpenDwg, HHOPENDWG, ACRX_CMD_TRANSPARENT, NULL) ACED_ARXCOMMAND_ENTRY_AUTO(CDwgPt2KmlApp,HH, CDwgPt2XmlApp, HHDCKML, ACRX_CMD_TRANSPARENT, NULL)//座標轉換
具體實現:函數
座標轉換界面:ui
CoordManageDlg.hthis
#pragma once #include "Resource.h" #include "DHCT.h" #include <vector> class CKmlXmlns; class CCoordTransArr; struct CPoleData; struct CSevenParam { CString m_strCur; CString m_strTar; double m_dDX; double m_dDY; double m_dDZ; double m_dRX; double m_dRY; double m_dRZ; double m_dK; }; // CCoordManageDlg 座標轉換 對話框 2017.1.18 class CCoordManageDlg : public CDialog { DECLARE_DYNAMIC(CCoordManageDlg) public: CCoordManageDlg(CWnd* pParent = NULL); // 標準構造函數 virtual ~CCoordManageDlg(); // 對話框數據 enum { IDD = IDD_DLG_COORD_MG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() virtual BOOL OnInitDialog(); afx_msg void OnBnClickedBtnGetline();//拾取線路 afx_msg void OnBnClickedBtnSet();//設置 afx_msg void OnCbnSelchangeCmbTarcoordsystem();//目標座標系改變 afx_msg void OnCbnSelchangeCmbDecimalsnum();//小數點 afx_msg void OnLvnEndlabeleditListCoord(NMHDR *pNMHDR, LRESULT *pResult);//edit編輯結束 afx_msg void OnBnClickedBtnCoordtrans();//座標轉換 afx_msg void OnBnClickedOk();//導出klm afx_msg void OnBnClickedBtnCoord();//導出東北座標 afx_msg void OnNMRClickListCoord(NMHDR *pNMHDR, LRESULT *pResult);//右鍵菜單 afx_msg void OnMenuClickedAdd();//添加 afx_msg void OnMenuClickedModify();//修改 afx_msg void OnMenuClickDelete();//刪除 private: //初始化下拉框 void InitCombox(); //初始化參數轉換 void InitSevenParam(); //初始化表頭 void InitListHead(); //初始化xy座標 void InitListYX(bool bIsUpData = false); //初始化經緯度座標 void InitListBL(); //加載配置文件,獲得轉換參數 void LoadCoordParameter(); //保存7參數 void SaveSevenParam(); //寫入xml文件 bool WriteXml(CKmlXmlns& arrPointData); //獲取用戶選擇的路徑 bool GetUserSelectDir(CString & strPath); private: CComboBox m_cmbCurCoordSystem;//當前座標系 CComboBox m_cmbCoordType; //座標類型 CComboBox m_cmbDecimalsNum; //保留小數位數 CComboBox m_cmbCoordStyle; //座標風格 CEdit m_editLongitude; //中央經線 CStatic m_staticLongitude; //中央經線 CStatic m_staticZoning; //投影分帶 CComboBox m_cmbZoning; //投影分帶 CComboBox m_cmbTarCoordSystem;//目標座標系 CComboBox m_cmbTarCoordType; //座標類型 CComboBox m_cmbCoordParameter;//轉換參數 CEdit m_editLineName;//線路名稱 CListCtrl m_listCoord; std::vector<CPoleData> m_vecPoleData;//點位信息 std::map<CString,CSevenParam> m_mapSevenParam;//七參數 };
CoordManageDlg.cpp.net
// CoordManageDlg.cpp : 實現文件 // #include "stdafx.h" #include "CoordManageDlg.h" #include "afxdialogex.h" #include "PrjStruct.h" #include "DwgDataToXml.h" #include "CoordEditDlg.h" #include "ParameterManageDlg.h" #include "rxmfcapi.h" #include "Fun.h" #include "ExcelReaderLibXl.h" // CCoordManageDlg 對話框 IMPLEMENT_DYNAMIC(CCoordManageDlg, CDialog) CCoordManageDlg::CCoordManageDlg(CWnd* pParent /*=NULL*/) : CDialog(CCoordManageDlg::IDD, pParent) { } CCoordManageDlg::~CCoordManageDlg() { } void CCoordManageDlg::DoDataExchange(CDataExchange* pDX) { __super::DoDataExchange(pDX); DDX_Control(pDX, IDC_CMB_CURCOORDSYSTEM, m_cmbTarCoordSystem ); DDX_Control(pDX, IDC_CMB_TARCOORDSYSTEM, m_cmbCurCoordSystem); DDX_Control(pDX, IDC_CMB_COORDTYPE, m_cmbCoordType); DDX_Control(pDX, IDC_CMB_DECIMALSNUM, m_cmbDecimalsNum); DDX_Control(pDX, IDC_CMB_COORDSTYLE, m_cmbCoordStyle); DDX_Control(pDX, IDC_STATIC_LONGITUDE, m_staticLongitude); DDX_Control(pDX, IDC_EDIT_LONGITUDE, m_editLongitude); DDX_Control(pDX, IDC_STATIC_ZONING, m_staticZoning); DDX_Control(pDX, IDC_CMB_ZONING, m_cmbZoning); DDX_Control(pDX, IDC_LIST_COORD, m_listCoord); DDX_Control(pDX, IDC_CMB_TARCOORDTYPE, m_cmbTarCoordType); DDX_Control(pDX, IDC_CMB_COORDPARAMETER, m_cmbCoordParameter); DDX_Control(pDX, IDC_EDIT_NAME, m_editLineName); } BEGIN_MESSAGE_MAP(CCoordManageDlg, CDialog) ON_BN_CLICKED(IDOK, &CCoordManageDlg::OnBnClickedOk) ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST_COORD, &CCoordManageDlg::OnLvnEndlabeleditListCoord) ON_CBN_SELCHANGE(IDC_CMB_TARCOORDSYSTEM, &CCoordManageDlg::OnCbnSelchangeCmbTarcoordsystem) ON_BN_CLICKED(IDC_BTN_GETLINE, &CCoordManageDlg::OnBnClickedBtnGetline) ON_BN_CLICKED(IDC_BTN_COORDTRANS, &CCoordManageDlg::OnBnClickedBtnCoordtrans) ON_BN_CLICKED(IDC_BTN_SET, &CCoordManageDlg::OnBnClickedBtnSet) ON_NOTIFY(NM_RCLICK, IDC_LIST_COORD, &CCoordManageDlg::OnNMRClickListCoord) ON_COMMAND(ID_Add, &CCoordManageDlg::OnMenuClickedAdd) ON_COMMAND(ID_MODIFY, &CCoordManageDlg::OnMenuClickedModify) ON_COMMAND(ID_DELETE, &CCoordManageDlg::OnMenuClickDelete) ON_BN_CLICKED(IDC_BTN_COORD, &CCoordManageDlg::OnBnClickedBtnCoord) ON_CBN_SELCHANGE(IDC_CMB_DECIMALSNUM, &CCoordManageDlg::OnCbnSelchangeCmbDecimalsnum) END_MESSAGE_MAP() // CCoordManageDlg 消息處理程序 BOOL CCoordManageDlg::OnInitDialog() { __super::OnInitDialog(); //加載配置文件,獲得轉換參數 LoadCoordParameter(); //初始化下拉框 InitCombox(); //初始化表頭 InitListHead(); return TRUE; } void CCoordManageDlg::OnBnClickedOk() { UpdateData(FALSE); CString strLineName; m_editLineName.GetWindowText(strLineName); if (strLineName.IsEmpty()) { MessageBox(_T("請填寫當前線路的名稱!"), _T("提示框"), MB_OK | MB_ICONHAND ); return; } CString strName; CString strCoord; CString strTempName; CString strTempX; CString strTempY; CString strtempCoord; for (int nRow = 0; nRow < m_listCoord.GetItemCount(); ++nRow) { strTempName = m_listCoord.GetItemText(nRow,0); strTempX = m_listCoord.GetItemText(nRow,3); strTempY = m_listCoord.GetItemText(nRow,4); if (strTempX.IsEmpty() || strTempY.IsEmpty()) { AfxMessageBox(_T("還未進行座標轉換!")); return; } strtempCoord.Format(_T("%s,%s,0"),strTempX,strTempY); if (!strName.IsEmpty()) strName += _T(";"); strName += strTempName; if (!strCoord.IsEmpty()) strCoord += _T(" "); strCoord += strtempCoord; } CKmlXmlns arrPointData; arrPointData.m_Document.m_Placemark.m_strName = strLineName; arrPointData.m_Document.m_Placemark.m_Point.m_strName = strName; arrPointData.m_Document.m_Placemark.m_Point.m_strCoord = strCoord; //寫入kml文件 WriteXml(arrPointData); __super::OnOK(); } bool CCoordManageDlg::GetUserSelectDir( CString & strPath ) { strPath ='\0'; TCHAR szPath[MAX_PATH]; BROWSEINFO br; ITEMIDLIST * pItem; br.hwndOwner = GetSafeHwnd(); br.iImage = 0; br.pszDisplayName = 0; br.lParam = 0 ; br.lpfn = 0 ; br.lpszTitle = _T("請選擇存放kml路徑"); br.pidlRoot = 0 ; br.ulFlags = BIF_RETURNONLYFSDIRS|BIF_USENEWUI; pItem = SHBrowseForFolder(&br); if (SHGetPathFromIDList(pItem,szPath) != TRUE) { return false; } strPath = szPath; return true; } bool CCoordManageDlg::WriteXml(CKmlXmlns& arrPointData) { CString strPath; if (!GetUserSelectDir(strPath)) return true; CTime timeCurr = CTime::GetCurrentTime(); CString strXmlName; strXmlName.Format(_T("\\樁位點數據%d%d%d%d%d%d.kml"),timeCurr.GetYear(),timeCurr.GetMonth(),timeCurr.GetDay(), timeCurr.GetHour(),timeCurr.GetMinute(),timeCurr.GetSecond()); strPath+=strXmlName; strPath.Replace(_T("\\\\"), _T("\\")); if(arrPointData.SaveXMLFile(strPath)) AfxMessageBox(_T("導出成功!")); else AfxMessageBox(_T("寫kml失敗!")); return true; } void CCoordManageDlg::InitCombox() { //當前座標系 int nIndex = m_cmbCurCoordSystem.AddString(_T("1954北京座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,1); nIndex = m_cmbCurCoordSystem.AddString(_T("1980西安座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,2); nIndex = m_cmbCurCoordSystem.AddString(_T("WGS84座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,3); m_cmbCurCoordSystem.SetCurSel(1); //座標風格 nIndex = m_cmbCoordStyle.AddString(_T("米")); m_cmbCoordStyle.SetItemData(nIndex,1); m_cmbCoordStyle.SetCurSel(0); //中央經線 m_editLongitude.SetWindowText(_T("111")); //座標類型 nIndex = m_cmbCoordType.AddString(_T("平面座標")); m_cmbCoordType.SetItemData(nIndex,1); nIndex = m_cmbCoordType.AddString(_T("大地座標")); m_cmbCoordType.SetItemData(nIndex,2); m_cmbCoordType.SetCurSel(0); //保留小數 CString strNum; for (int nNum = 0; nNum < 7; ++nNum) { strNum.Format(_T("%d"), nNum); nIndex = m_cmbDecimalsNum.AddString(strNum); m_cmbDecimalsNum.SetItemData(nIndex,nNum); } m_cmbDecimalsNum.SetCurSel(4); //投影分帶 nIndex = m_cmbZoning.AddString(_T("3度分帶")); m_cmbZoning.SetItemData(nIndex,1); nIndex = m_cmbZoning.AddString(_T("6度分帶")); m_cmbZoning.SetItemData(nIndex,2); m_cmbZoning.SetCurSel(0); //目標座標系 nIndex = m_cmbTarCoordSystem.AddString(_T("WGS84座標系")); m_cmbTarCoordSystem.SetItemData(nIndex,1); m_cmbTarCoordSystem.SetCurSel(0); //座標類型 nIndex = m_cmbTarCoordType.AddString(_T("大地座標")); m_cmbTarCoordType.SetItemData(nIndex,1); m_cmbTarCoordType.SetCurSel(0); //轉換參數 InitSevenParam(); } void CCoordManageDlg::InitListHead() { CRect rect; m_listCoord.GetClientRect(&rect); m_listCoord.SetExtendedStyle(m_listCoord.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_listCoord.InsertColumn(0, _T("樁/塔名"), LVCFMT_CENTER, rect.Width()/5, 0); m_listCoord.InsertColumn(1, _T("東座標" ), LVCFMT_CENTER, rect.Width()/5, 1); m_listCoord.InsertColumn(2, _T("北座標" ), LVCFMT_CENTER, rect.Width()/5, 2); m_listCoord.InsertColumn(3, _T("經度" ), LVCFMT_CENTER, rect.Width()/5, 3); m_listCoord.InsertColumn(4, _T("緯度" ), LVCFMT_CENTER, rect.Width()/5, 4); } void CCoordManageDlg::OnCbnSelchangeCmbTarcoordsystem() { } void CCoordManageDlg::OnBnClickedBtnGetline() { // 隱藏對話框 acedGetAcadFrame()->EnableWindow(TRUE); ShowWindow(SW_HIDE); m_vecPoleData.clear(); CDwgDataToXml::Inlet(m_vecPoleData); // 顯示對話框 acedGetAcadFrame()->EnableWindow(FALSE); ShowWindow(SW_SHOW); EnableWindow(TRUE); if (m_vecPoleData.size() > 0) InitListYX(); } void CCoordManageDlg::InitListYX( bool bIsUpData) { //小數點位數 CString strNum; m_cmbDecimalsNum.GetWindowText(strNum); int nNum = _ttoi(strNum); CString strRow; CString strPoint; for (int nRow = 0; nRow < m_vecPoleData.size();++nRow) { CPoleData poleData = m_vecPoleData[nRow]; if (!bIsUpData) { strRow.Format(_T("%d"),nRow); m_listCoord.InsertItem(nRow, strRow); } m_listCoord.SetItemText(nRow, 0, poleData.strName); strPoint.Format(_T("%.*f"),nNum,poleData.ptPolePoint.x); m_listCoord.SetItemText(nRow, 1, strPoint); strPoint.Format(_T("%.*f"),nNum,poleData.ptPolePoint.y); m_listCoord.SetItemText(nRow, 2, strPoint); } } void CCoordManageDlg::InitListBL() { DHCOORDTRANSFORMPARAM mParam; CString strTemp; m_cmbCurCoordSystem.GetWindowText(strTemp); if (_T("1954北京座標系") == strTemp) mParam.nCoordMode = DHE3_COORMODE_BJ54; else if (_T("WGS84座標系") == strTemp) mParam.nCoordMode = DHE3_COORMODE_WGS84UTM; else mParam.nCoordMode = DHE3_COORMODE_XA80; m_cmbCoordParameter.GetWindowText(strTemp); CSevenParam SevenParam = m_mapSevenParam[strTemp]; mParam.nLongLatFormat = DHE3_LONGLAT_FORMAT_DU; m_editLongitude.GetWindowText(strTemp); mParam.dCenterLong = _ttol(strTemp); mParam.spSevenParam.dPitch = SevenParam.m_dRX; mParam.spSevenParam.dRoll = SevenParam.m_dRZ; mParam.spSevenParam.dScale = SevenParam.m_dK; mParam.spSevenParam.dXOffset = SevenParam.m_dDX; mParam.spSevenParam.dYaw = SevenParam.m_dRY; mParam.spSevenParam.dYOffset = SevenParam.m_dDY; mParam.spSevenParam.dZOffset = SevenParam.m_dDZ; double dLong(0.0l), dLat(0.0l), dH(0.0l); //小數點位數 CString strNum; m_cmbDecimalsNum.GetWindowText(strNum); int nNum = _ttoi(strNum); CString strRow; CString strPoint; for (int nRow = 0; nRow < m_vecPoleData.size();++nRow) { OnTransformToBLH(mParam.nCoordMode,true,mParam.dCenterLong,&mParam.spSevenParam,m_vecPoleData[nRow].ptPolePoint.x,m_vecPoleData[nRow].ptPolePoint.y, 0, dLong, dLat, dH); strRow.Format(_T("%d"),nRow); strPoint.Format(_T("%.*f"),nNum,dLong); m_listCoord.SetItemText(nRow, 3, strPoint); strPoint.Format(_T("%.*f"),nNum,dLat); m_listCoord.SetItemText(nRow, 4, strPoint); } } void CCoordManageDlg::OnLvnEndlabeleditListCoord( NMHDR *pNMHDR, LRESULT *pResult ) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR); *pResult = 0; CString strName = pDispInfo->item.pszText; int nSel = pDispInfo->item.iItem; m_listCoord.SetFocus(); if( ( ! strName.IsEmpty() ) && nSel >= 0 ) m_listCoord.SetItemText( nSel, 0, strName); } void CCoordManageDlg::OnBnClickedBtnCoordtrans() { if (m_vecPoleData.size() < 1) { AfxMessageBox(_T("沒有樁塔座標能夠轉換,請先拾取線路!")); return; } CString strTemp; m_cmbCoordParameter.GetWindowText(strTemp); if (strTemp.IsEmpty()) { AfxMessageBox(_T("轉換參數爲空,請先設置可用的七參數!")); return; } InitListBL(); } void CCoordManageDlg::OnBnClickedBtnSet() { CParameterManageDlg dlg(m_mapSevenParam,this); if (IDOK == dlg.DoModal()) { if (m_mapSevenParam.size() < 1) return; // 參數轉換 InitSevenParam(); //保存七參數 SaveSevenParam(); } } void CCoordManageDlg::LoadCoordParameter() { std::wstring strPath; bool bRet = CDwgDataToXml::GetUserConfigFilePath(_T("CoordTransPara.xml"), strPath); if (!bRet) return; //解析配置文件 CCoordTransArr CoordTransArr; CoordTransArr.LoadXMLFile(strPath.c_str()); for (int nIndex = 0; nIndex < CoordTransArr.size(); ++nIndex) { CSevenParam SevenParam; SevenParam.m_strCur = CoordTransArr[nIndex].m_strCur; SevenParam.m_strTar = CoordTransArr[nIndex].m_strTar; SevenParam.m_dDX = CoordTransArr[nIndex].m_dDX; SevenParam.m_dDY = CoordTransArr[nIndex].m_dDY; SevenParam.m_dDZ = CoordTransArr[nIndex].m_dDZ; SevenParam.m_dRX = CoordTransArr[nIndex].m_dRX; SevenParam.m_dRY = CoordTransArr[nIndex].m_dRY; SevenParam.m_dRZ = CoordTransArr[nIndex].m_dRZ; SevenParam.m_dK = CoordTransArr[nIndex].m_dK; m_mapSevenParam[CoordTransArr[nIndex].m_strName] = SevenParam; } } void CCoordManageDlg::InitSevenParam() { m_cmbCoordParameter.ResetContent(); int nIndex = 0; std::map<CString,CSevenParam>::iterator it = m_mapSevenParam.begin(); for(;it != m_mapSevenParam.end(); ++it) { nIndex = m_cmbCoordParameter.AddString(it->first); m_cmbCoordParameter.SetItemData(nIndex,1); m_cmbCoordParameter.SetCurSel(0); } } void CCoordManageDlg::SaveSevenParam() { CCoordTransArr CoordTransArr; std::map<CString,CSevenParam>::iterator it = m_mapSevenParam.begin(); for (; it != m_mapSevenParam.end(); ++it) { CCoordTrans CoordTrans; CoordTrans.m_strName = it->first; CoordTrans.m_strCur = it->second.m_strCur; CoordTrans.m_strTar = it->second.m_strTar; CoordTrans.m_dDX = it->second.m_dDX; CoordTrans.m_dDY = it->second.m_dDY; CoordTrans.m_dDZ = it->second.m_dDZ; CoordTrans.m_dRX = it->second.m_dRX; CoordTrans.m_dRY = it->second.m_dRY; CoordTrans.m_dRZ = it->second.m_dRZ; CoordTrans.m_dK = it->second.m_dK; CoordTransArr.push_back(CoordTrans); } std::wstring strPath; CDwgDataToXml::GetUserConfigFilePath(_T("CoordTransPara.xml"),strPath); CoordTransArr.SaveXMLFile(strPath.c_str()); } void CCoordManageDlg::OnNMRClickListCoord(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); // TODO: 在此添加控件通知處理程序代碼 *pResult = 0; POINT point; GetCursorPos(&point); ScreenToClient(&point); if (point.x == -1 && point.y == -1) //判斷是否在窗口外面 { CRect rect; m_listCoord.GetClientRect(rect); //獲得窗口客戶區的大小 m_listCoord.ClientToScreen(rect); //轉化爲屏幕座標 point = rect.TopLeft();//獲取左上角座標 //point.Offset(5, 5); //座標偏移5,5 } CMenu menu;//聲明菜單對象 menu.LoadMenu(IDR_MENU1);//從應用程序的可執行文件中加載菜單資源 CMenu* pPopup = NULL; pPopup= menu.GetSubMenu(0); //得到第一個彈出菜單的指針,也就是菜單中的第一個彈出菜單 if (NULL == pPopup) return; // 將座標值由客戶座標轉換爲屏幕座標 ClientToScreen(&point); ASSERT(pPopup != NULL); //p斷言不爲空 CWnd* pWndPopupOwner = this;//當前類的指針 //下面就是彈出菜單 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); } void CCoordManageDlg::OnMenuClickedAdd() { // 增長 int nSel=m_listCoord.GetSelectionMark(); CString strName,strXCoord,strYCoord,strLong,strLat; CCoordEditDlg dlg(strName,strXCoord,strYCoord,strLong,strLat); if (dlg.DoModal() != IDOK) return; dlg.GetData(strName,strXCoord,strYCoord,strLong,strLat); CString strCurID; strCurID.Format (_T("%d"),nSel + 1); m_listCoord.InsertItem(nSel + 1, strCurID); m_listCoord.SetItemText(nSel + 1, 0, strName); m_listCoord.SetItemText(nSel + 1, 1, strXCoord); m_listCoord.SetItemText(nSel + 1, 2, strYCoord); m_listCoord.SetItemText(nSel + 1, 3, strLong); m_listCoord.SetItemText(nSel + 1, 4, strLat); } void CCoordManageDlg::OnMenuClickedModify() { int nSel=m_listCoord.GetSelectionMark(); CString strName = m_listCoord.GetItemText(nSel,0); CString strXCoord = m_listCoord.GetItemText(nSel,1); CString strYCoord = m_listCoord.GetItemText(nSel,2); CString strLong = m_listCoord.GetItemText(nSel,3); CString strLat = m_listCoord.GetItemText(nSel,4); CCoordEditDlg dlg(strName,strXCoord,strYCoord,strLong,strLat); if (dlg.DoModal() != IDOK) return; dlg.GetData(strName,strXCoord,strYCoord,strLong,strLat); m_listCoord.SetItemText(nSel, 0, strName); m_listCoord.SetItemText(nSel, 1, strXCoord); m_listCoord.SetItemText(nSel, 2, strYCoord); m_listCoord.SetItemText(nSel, 3, strLong); m_listCoord.SetItemText(nSel, 4, strLat); } void CCoordManageDlg::OnMenuClickDelete() { int nSel=m_listCoord.GetSelectionMark(); m_listCoord.DeleteItem(nSel); } void CCoordManageDlg::OnBnClickedBtnCoord() { //獲得模板表格 std::wstring strTempPath; if (!(CDwgDataToXml::GetUserConfigFilePath(_T("東北座標導出模板.xls"), strTempPath))) { AfxMessageBox(_T("沒有 東北座標導出模板.xls 模板!")); return; } //用戶選擇路徑 CString strPath; if (!GetUserSelectDir(strPath)) return; strPath += _T("\\樁位表.xls"); BOOL bRet = CopyFile(strTempPath.c_str(),strPath,FALSE); CExcelReaderLibXl xlsReader; if ( !xlsReader.Open(strPath)) return; //把座標填充到表格 CString strTempName; CString strTempX; CString strTempY; for (int nRow = 0; nRow < m_listCoord.GetItemCount(); ++nRow) { strTempName = m_listCoord.GetItemText(nRow,0); xlsReader.WirteCellText( 0 ,nRow + 1,0,strTempName); strTempX = m_listCoord.GetItemText(nRow,1); xlsReader.WirteCellText( 0 ,nRow + 1,1,strTempX); strTempY = m_listCoord.GetItemText(nRow,2); xlsReader.WirteCellText( 0 ,nRow + 1,2,strTempY); } xlsReader.Save(); if (_taccess(strPath, 0) == -1) AfxMessageBox(_T("導出失敗")); else AfxMessageBox(_T("導出成功!")); } void CCoordManageDlg::OnCbnSelchangeCmbDecimalsnum() { InitListYX(true); }
拾取線路:3d
DwgDataToXml.h指針
#pragma once #include <vector> #include "PrjStruct.h" struct CPoleData { AcGePoint3d ptPolePoint;//樁位點 CString strName;//標註名稱 }; //把dwg中的點位數據整理成kml文件 class CDwgDataToXml { public: CDwgDataToXml(void); ~CDwgDataToXml(void); public: //外部入口 static void Inlet(std::vector<CPoleData>& vecPoleData); //加載dwg圖紙 static void OnLoadDWG(); //讀取用戶配置文件路徑 static bool GetUserConfigFilePath(LPCTSTR lpFileName, std::wstring& strFilePath); //獲得樁名對應位置 std::vector<CPoleData> GetPoleData(AcGePoint3dArray vecXYPoint); //獲得上一級目錄 void GetParentPath(CString & strPath); //設置圖層名 void SetLayerName(CString strLayerName); private: // 由選擇集獲得實體ID BOOL GetIdArrayFromSS(ads_name selectSet,AcDbObjectIdArray &idArray); //經過實體id得到座標點和圖層 bool GetPosAndLayerFromId(const AcDbObjectId &polyId,AcGePoint3dArray &vecPoint,CString &strLayer); //獲得離點最近的標註 CString GetNearestLable(const AcGePoint3d ptPoint); //經過標註id獲得標註名稱和位置 bool GetLableDataFromId(AcDbObjectId &Id); //經過選擇集獲得標註信息 bool GetLabelFromXZJ(CString& strLayer); //獲得樁位XY座標點和圖層 bool GetXYPoints(AcGePoint3dArray &vecPoint,CString& strLayer); //獲得dwg圖紙路徑 CString GetDwgPath(); //打開dwg圖紙 BOOL OpenDwg(CString &strPath); private: std::map<CString,AcGePoint3d> m_mapLable;//標註名稱的位置 CString m_strLayerName;//圖層名稱 std::vector<CPoleData> m_vecPoleData;//樁位數據 };
DwgDataToXml.cpprest
#include "StdAfx.h" #import <MSXML.DLL> named_guids #include "DwgDataToXml.h" #include <afxdlgs.h> #include "CoordManageDlg.h" #include <winuser.h> #include <tchar.h> CDwgDataToXml::CDwgDataToXml(void) { } CDwgDataToXml::~CDwgDataToXml(void) { } void CDwgDataToXml::Inlet(std::vector<CPoleData>& vecPoleData) { //1.選擇實體,獲得多段線的點和圖層 CDwgDataToXml dwgDataToxml; AcGePoint3dArray vecXYPoint;//樁位XY座標點 CString strLayer;//圖層名稱 dwgDataToxml.GetXYPoints(vecXYPoint,strLayer); if (vecXYPoint.length() <= 0) { AfxMessageBox(_T("選擇實體不正確!,請選擇多段線")); return; } //2.經過選擇集獲得標註位置和名稱 dwgDataToxml.GetLabelFromXZJ(strLayer); //3.獲得杆的位置和座標 vecPoleData = dwgDataToxml.GetPoleData(vecXYPoint); if (vecPoleData.size() < 1) AfxMessageBox(_T("未提取到正確的線路,請從新提取!")); } BOOL CDwgDataToXml::GetIdArrayFromSS( ads_name selectSet,AcDbObjectIdArray &idArray ) { idArray.setLogicalLength(0); long len = 0; acedSSLength(selectSet,&len); if (acedSSLength(selectSet,&len) != RTNORM) return FALSE; for(long i = 0; i < len; i++) { ads_name en_SS; if (acedSSName(selectSet,i,en_SS) != RTNORM) return FALSE; AcDbObjectId enId_SS; if (acdbGetObjectId(enId_SS,en_SS) != Acad::eOk) return FALSE; if (!enId_SS.isNull() && !idArray.contains(enId_SS)) { idArray.append(enId_SS); } } return TRUE; } bool CDwgDataToXml::GetPosAndLayerFromId( const AcDbObjectId &polyId,AcGePoint3dArray &vecPoint,CString &strLayer) { //獲得實體 AcDbEntity* pEnt = NULL; Acad::ErrorStatus es = acdbOpenObject(pEnt,polyId,AcDb::kForRead); if (es != Acad::eOk) return false; //獲得圖層 ACHAR* pTemp = pEnt->layer(); if (NULL != pTemp) strLayer = pTemp; if (pEnt->isA() == AcDbPolyline::desc())//多段線 { AcDbPolyline *pPolyline = AcDbPolyline::cast(pEnt); for (int i = 0; i < pPolyline->numVerts(); i++) { AcGePoint3d pt; pPolyline->getPointAt(i,pt); vecPoint.append(pt); } pPolyline = NULL; } return true; } void CDwgDataToXml::OnLoadDWG() { //獲得dwg圖紙路徑 CDwgDataToXml dwgDataToxml; CString strPath = dwgDataToxml.GetDwgPath(); //打開dwg圖紙 if(!dwgDataToxml.OpenDwg(strPath)) acdbFail(_T("打開dwg圖紙失敗")); } void CDwgDataToXml::GetParentPath( CString & strPath ) { int nPos = strPath.ReverseFind(_T('\\')); strPath = strPath.Left(nPos); //strPath.TrimRight(_T("\\")); } CString CDwgDataToXml::GetDwgPath() { TCHAR szFilePath[MAX_PATH+1]; memset(szFilePath, 0, MAX_PATH+1); GetModuleFileName(_hdllInstance, szFilePath, MAX_PATH); CString strPath(szFilePath); GetParentPath(strPath); GetParentPath(strPath); GetParentPath(strPath); strPath = strPath + _T("\\Dwg\\CAD選線成果樣例1.dwg"); if (_taccess(strPath, 0) != -1) { //用戶選擇dwg CFileDialog dlg(TRUE, _T("*.dwg"), NULL, OFN_HIDEREADONLY, _T("AutoCAD File(*.dwg)|*.dwg||"),NULL); if ( dlg.DoModal() == IDOK ) strPath = dlg.GetPathName(); } return strPath; } BOOL CDwgDataToXml::OpenDwg( CString &strPath ) { //判斷文件是否存在 TCHAR fullpath[356]; if (acedFindFile(strPath,fullpath) != RTNORM) { acdbFail(_T("工程文件沒有找到!")); return TRUE; } //打開文件 if (!acDocManager->isApplicationContext()) return FALSE; // 查看文件是否已經打開,打開則不做處理 AcApDocument *pDocOld; CString strFileName; AcApDocumentIterator *pIter = acDocManager->newAcApDocumentIterator(); Acad::ErrorStatus es = Acad::eOk; for(; !pIter->done(); pIter->step()) { pDocOld = pIter->document(); strFileName = pDocOld->fileName(); if(strFileName.CompareNoCase(strPath) == 0) { delete pIter; es = acDocManager->setCurDocument(pDocOld,AcAp::kNone,true); return TRUE; } } delete pIter; // 沒有打開 if (!acDocManager->isApplicationContext()) return FALSE; es = acDocManager->appContextOpenDocument((const TCHAR*)fullpath); if(es != Acad::eOk && es != Acad::eFilerError) //注意!!!!若是是系統加載的時候會返回eFilerError return FALSE; return TRUE; } bool CDwgDataToXml::GetXYPoints(AcGePoint3dArray &vecPoint,CString& strLayer ) { //選擇實體 acutPrintf(_T("\n請選擇實體:\n")); struct resbuf eb; TCHAR sbuf[20]; eb.restype=0; //實體名 _tcscpy_s(sbuf,_T("LWPOLYLINE")); eb.resval.rstring=sbuf; eb.rbnext=NULL; //無其餘內容 ads_name selectset; int rc = acedSSGet(_T(":S"),NULL,NULL,&eb,selectset);// :S表示單選 if (rc == RTCAN)//用戶取消請求 { acedSSFree(selectset); return false; } else if (rc != RTNORM) { acutPrintf(_T("\n選擇實體不正確:\n")); acedSSFree(selectset); return false; } //得到實體ID AcDbObjectIdArray arrMemberId; BOOL bRet = GetIdArrayFromSS(selectset,arrMemberId); acedSSFree(selectset); if (!bRet) return false; //得到實體的座標點 if (arrMemberId.length() == 1) GetPosAndLayerFromId(arrMemberId[0], vecPoint,strLayer); return true; } bool CDwgDataToXml::GetLabelFromXZJ(CString& strLayer) { //圖層 struct resbuf* eb = NULL; eb = acutBuildList(-4, _T("<or"), 8, strLayer, -4, _T("or>"),NULL); ads_name SelName; int rc = acedSSGet(_T("X"), NULL, NULL,eb, SelName); acutRelRb(eb); if (rc != RTNORM) { acedSSFree(SelName); return false; } long len = 0; acedSSLength(SelName,&len); for (long i = 0; i < len; i++) { ads_name entName; if (acedSSName(SelName, i, entName) != RTNORM) continue; AcDbObjectId eid = AcDbObjectId::kNull; acdbGetObjectId(eid, entName); if (eid == AcDbObjectId::kNull) continue; GetLableDataFromId(eid); } acedSSFree(SelName); return true; } bool CDwgDataToXml::GetLableDataFromId( AcDbObjectId &Id) { //獲得實體 AcDbEntity* pEnt = NULL; Acad::ErrorStatus es = acdbOpenObject(pEnt,Id,AcDb::kForRead); if (es != Acad::eOk || NULL == pEnt) return false; bool bRet = true; AcGePoint3d ptPoint;//點位置 CString strName;//標註 if (pEnt->isA() == AcDbText::desc())//單文本 { //標註 AcDbText *pText = AcDbText::cast(pEnt); if (NULL == pText) bRet = false; else { strName = pText->textString(); ptPoint = pText->position(); pText->close(); } } else if (pEnt->isA() == AcDbMText::desc())//多文本 { AcDbMText *pText = AcDbMText::cast(pEnt); if (NULL == pText) bRet = false; else { strName = pText->text(); ptPoint = pText->location(); pText->close(); } } else bRet = false; if (!bRet) { pEnt->close(); return true; } m_mapLable[strName] = ptPoint; pEnt->close(); return true; } CString CDwgDataToXml::GetNearestLable(const AcGePoint3d ptPoint) { double dCurDistance = 0.0; std::map<CString,AcGePoint3d>::iterator it = m_mapLable.begin(); CString strName = it->first; double dMinDistance = (ptPoint - m_mapLable[strName]).length(); for (; it != m_mapLable.end(); ++it) { dCurDistance = (ptPoint - m_mapLable[it->first]).length(); if(dCurDistance < dMinDistance) { dMinDistance = dCurDistance; strName = it->first; } } return strName; } std::vector<CPoleData> CDwgDataToXml::GetPoleData(AcGePoint3dArray vecXYPoint) { m_vecPoleData.clear(); if (m_mapLable.size() < 1) return m_vecPoleData; for (int nIndex = 0; nIndex < vecXYPoint.length(); ++nIndex) { CPoleData poleData; poleData.ptPolePoint = vecXYPoint[nIndex]; poleData.strName = GetNearestLable(vecXYPoint[nIndex]); m_vecPoleData.push_back(poleData); } return m_vecPoleData; } bool CDwgDataToXml::GetUserConfigFilePath( LPCTSTR lpFileName, std::wstring& strFilePath ) { strFilePath.clear(); // 取得APP Data的路徑 TCHAR szFilePath[MAX_PATH+1]; memset(szFilePath, 0, MAX_PATH+1); GetModuleFileName(_hdllInstance, szFilePath, MAX_PATH); CString strPath(szFilePath); CDwgDataToXml kml; kml.GetParentPath(strPath); kml.GetParentPath(strPath); kml.GetParentPath(strPath); // 在用戶路徑下查找文件 std::wstring strUFilePath = strPath + _T("\\Config\\") + lpFileName; if (-1 != _taccess(strUFilePath.c_str(), 0)) { strFilePath = strUFilePath; return true; } return !strFilePath.empty(); } void CDwgDataToXml::SetLayerName( CString strLayerName ) { m_strLayerName = strLayerName; }
設置7參數界面:
ParameterManageDlg.h
#pragma once #include "resource.h" #include "CoordManageDlg.h" // CParameterManageDlg 參數管理 對話框 2017.10.18 class CParameterManageDlg : public CDialog { DECLARE_DYNAMIC(CParameterManageDlg) public: CParameterManageDlg(std::map<CString,CSevenParam>& mapSevenParam,CWnd* pParent = NULL); // 標準構造函數 virtual ~CParameterManageDlg(); // 對話框數據 enum { IDD = IDD_DLG_PARAMETER_MG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() virtual BOOL OnInitDialog(); afx_msg void OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult);//單擊事件 afx_msg void OnBnClickedBtnClear();//清除 afx_msg void OnBnClickedBtnSave();//保存 afx_msg void OnBnClickedOk();//肯定 private: //初始化下拉框 void InitCombox(); //初始化表 void InitList(); //清除小數點和多餘的0 CString ClearZero(double dValue); //校驗是否添加列表(返回false,名稱重複,返回true,nrow大於-1時修改現有list,不然增長一行) bool CheckIsAddList(CString strName,CString strCur,CString strTar,int &nRow ); private: CComboBox m_cmbCurCoordSystem; CComboBox m_cmbTarCoordSystem; CEdit m_editName; CEdit m_editDX; CEdit m_editDY; CEdit m_editDZ; CEdit m_editK; CEdit m_editRX; CEdit m_editRY; CEdit m_editRZ; CListCtrl m_list; std::map<CString,CSevenParam>& m_mapSevenParam; };
ParameterManageDlg.cpp
// ParameterManageDlg.cpp : 實現文件 // #include "stdafx.h" #include "ParameterManageDlg.h" #include "afxdialogex.h" #include "PrjStruct.h" // CParameterManageDlg 對話框 IMPLEMENT_DYNAMIC(CParameterManageDlg, CDialog) CParameterManageDlg::CParameterManageDlg(std::map<CString,CSevenParam>& mapSevenParam,CWnd* pParent /*=NULL*/) : CDialog(CParameterManageDlg::IDD, pParent) ,m_mapSevenParam(mapSevenParam) { } CParameterManageDlg::~CParameterManageDlg() { } void CParameterManageDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_CMB_CURCOORDSYSTEM, m_cmbCurCoordSystem); DDX_Control(pDX, IDC_CMB_TARCOORDSYSTEM, m_cmbTarCoordSystem); DDX_Control(pDX, IDC_EDIT_NAME, m_editName); DDX_Control(pDX, IDC_EDIT_DX, m_editDX); DDX_Control(pDX, IDC_EDIT_DY, m_editDY); DDX_Control(pDX, IDC_EDIT_DZ, m_editDZ); DDX_Control(pDX, IDC_EDIT_K , m_editK ); DDX_Control(pDX, IDC_EDIT_RX, m_editRX); DDX_Control(pDX, IDC_EDIT_RY, m_editRY); DDX_Control(pDX, IDC_EDIT_RZ, m_editRZ); DDX_Control(pDX, IDC_LIST, m_list); } BEGIN_MESSAGE_MAP(CParameterManageDlg, CDialog) ON_BN_CLICKED(IDC_BTN_CLEAR, &CParameterManageDlg::OnBnClickedBtnClear) ON_BN_CLICKED(IDC_BTN_SAVE, &CParameterManageDlg::OnBnClickedBtnSave) ON_BN_CLICKED(IDOK, &CParameterManageDlg::OnBnClickedOk) ON_NOTIFY(NM_CLICK, IDC_LIST, &CParameterManageDlg::OnNMClickList) END_MESSAGE_MAP() // CParameterManageDlg 消息處理程序 BOOL CParameterManageDlg::OnInitDialog() { __super::OnInitDialog(); InitCombox(); InitList(); return TRUE; } void CParameterManageDlg::InitCombox() { //當前座標系 int nIndex = m_cmbCurCoordSystem.AddString(_T("1954北京座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,1); nIndex = m_cmbCurCoordSystem.AddString(_T("1980西安座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,2); nIndex = m_cmbCurCoordSystem.AddString(_T("WGS84座標系")); m_cmbCurCoordSystem.SetItemData(nIndex,3); m_cmbCurCoordSystem.SetCurSel(0); //當前座標系 nIndex = m_cmbTarCoordSystem.AddString(_T("1954北京座標系")); m_cmbTarCoordSystem.SetItemData(nIndex,1); nIndex = m_cmbTarCoordSystem.AddString(_T("1980西安座標系")); m_cmbTarCoordSystem.SetItemData(nIndex,2); nIndex = m_cmbTarCoordSystem.AddString(_T("WGS84座標系")); m_cmbTarCoordSystem.SetItemData(nIndex,3); m_cmbTarCoordSystem.SetCurSel(2); } void CParameterManageDlg::OnBnClickedBtnClear() { CString strTemp = _T(""); m_editName.SetWindowText(strTemp); m_editDX.SetWindowText(strTemp); m_editDY.SetWindowText(strTemp); m_editDZ.SetWindowText(strTemp); m_editRX.SetWindowText(strTemp); m_editRY.SetWindowText(strTemp); m_editRZ.SetWindowText(strTemp); m_editK.SetWindowText(strTemp); } void CParameterManageDlg::OnBnClickedBtnSave() { CString strError; CString strName; m_editName.GetWindowText(strName); if (strName.IsEmpty()) strError = _T("名稱"); CString strDX; m_editDX.GetWindowText(strDX); if (strDX.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("DX"); } CString strDY; m_editDY.GetWindowText(strDY); if (strDY.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("DY"); } CString strDZ; m_editDZ.GetWindowText(strDZ); if (strDZ.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("DZ"); } CString strRX; m_editRX.GetWindowText(strRX); if (strRX.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("RX"); } CString strRY; m_editRY.GetWindowText(strRY); if (strRY.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("RY"); } CString strRZ; m_editRZ.GetWindowText(strRZ); if (strRZ.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("RZ"); } CString strK; m_editK.GetWindowText(strK); if (strK.IsEmpty()) { if (!strError.IsEmpty()) strError += _T(","); strError += _T("K"); } if (!strError.IsEmpty()) { CString strTemp; strTemp.Format(_T("%s爲空,請先填寫完整!"),strError); AfxMessageBox(strTemp); return; } int nRow = -1; CString strCur; m_cmbCurCoordSystem.GetWindowText(strCur); CString strTar; m_cmbTarCoordSystem.GetWindowText(strTar); if (!CheckIsAddList(strName,strCur,strTar,nRow)) return; //加入表格 CString strRow; if (-1 == nRow) { nRow = m_list.GetItemCount(); strRow.Format(_T("%d"),nRow); m_list.InsertItem(nRow, strRow); } m_list.SetItemText(nRow, 0, strCur); m_list.SetItemText(nRow, 1, strTar); m_list.SetItemText(nRow, 2, strDX); m_list.SetItemText(nRow, 3, strDY); m_list.SetItemText(nRow, 4, strDZ); m_list.SetItemText(nRow, 5, strRX); m_list.SetItemText(nRow, 6, strRY); m_list.SetItemText(nRow, 7, strRZ); m_list.SetItemText(nRow, 8, strK); m_list.SetItemText(nRow, 9, strName); } void CParameterManageDlg::InitList() { CRect rect; m_list.GetClientRect(&rect); m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_list.InsertColumn(0, _T("源座標系"), LVCFMT_CENTER, rect.Width()/9, 0); m_list.InsertColumn(1, _T("目標座標系" ), LVCFMT_CENTER, rect.Width()/9, 1); m_list.InsertColumn(2, _T("DX" ), LVCFMT_CENTER, rect.Width()/9, 2); m_list.InsertColumn(3, _T("DY" ), LVCFMT_CENTER, rect.Width()/9, 3); m_list.InsertColumn(4, _T("DZ" ), LVCFMT_CENTER, rect.Width()/9, 4); m_list.InsertColumn(5, _T("RX" ), LVCFMT_CENTER, rect.Width()/9, 5); m_list.InsertColumn(6, _T("RY" ), LVCFMT_CENTER, rect.Width()/9, 6); m_list.InsertColumn(7, _T("RZ" ), LVCFMT_CENTER, rect.Width()/9, 7); m_list.InsertColumn(8, _T("K" ), LVCFMT_CENTER, rect.Width()/9, 8); m_list.InsertColumn(9,_T("名稱"),LVCFMT_CENTER,0,9); CString strTemp; CString strRow; std::map<CString,CSevenParam>::iterator it = m_mapSevenParam.begin(); for (int nRow = 0; it != m_mapSevenParam.end(); ++it,++nRow) { strRow.Format(_T("%d"),nRow); m_list.InsertItem(nRow, strRow); m_list.SetItemText(nRow, 0, it->second.m_strCur); m_list.SetItemText(nRow, 1, it->second.m_strTar); m_list.SetItemText(nRow, 2, ClearZero(it->second.m_dDX)); m_list.SetItemText(nRow, 3, ClearZero(it->second.m_dDY)); m_list.SetItemText(nRow, 4, ClearZero(it->second.m_dDZ)); m_list.SetItemText(nRow, 5, ClearZero(it->second.m_dRX)); m_list.SetItemText(nRow, 6, ClearZero(it->second.m_dRY)); m_list.SetItemText(nRow, 7, ClearZero(it->second.m_dRZ)); m_list.SetItemText(nRow, 8, ClearZero(it->second.m_dK)); m_list.SetItemText(nRow, 9, it->first); } } bool CParameterManageDlg::CheckIsAddList(CString strName, CString strCur,CString strTar,int &nRow ) { UpdateData(FALSE); CString strText; for (int row = 0; row < m_list.GetItemCount(); ++row) { strText = m_list.GetItemText(row,0); if (strText == strCur) { strText = m_list.GetItemText(row,1); if (strText == strTar) { nRow = row; break; } } } //校驗名稱 for (int row = 0; row < m_list.GetItemCount(); ++row) { if (nRow == row) continue; strText = m_list.GetItemText(row,9); if (strText == strName) { strText.Format(_T("%s名稱已經存在,不能保存!"),strName); AfxMessageBox(strText); return false; } } return true; } void CParameterManageDlg::OnBnClickedOk() { m_mapSevenParam.clear(); CString strText; for (int nRow = 0; nRow < m_list.GetItemCount(); ++nRow) { CSevenParam SevenParam; strText = m_list.GetItemText(nRow,9); SevenParam.m_strCur = m_list.GetItemText(nRow,0); SevenParam.m_strTar = m_list.GetItemText(nRow,1); CString str = m_list.GetItemText(nRow,2); SevenParam.m_dDX = _tstof(m_list.GetItemText(nRow,2)); SevenParam.m_dDY = _tstof(m_list.GetItemText(nRow,3)); SevenParam.m_dDZ = _tstof(m_list.GetItemText(nRow,4)); SevenParam.m_dRX = _tstof(m_list.GetItemText(nRow,5)); SevenParam.m_dRY = _tstof(m_list.GetItemText(nRow,6)); SevenParam.m_dRZ = _tstof(m_list.GetItemText(nRow,7)); SevenParam.m_dK = _tstof(m_list.GetItemText(nRow,8)); m_mapSevenParam[strText] = SevenParam; } __super::OnOK(); } void CParameterManageDlg::OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); // TODO: 在此添加控件通知處理程序代碼 *pResult = 0; int nSel=m_list.GetSelectionMark(); CString strCur = m_list.GetItemText(nSel,0); m_cmbCurCoordSystem.SetWindowText(strCur); CString strTar = m_list.GetItemText(nSel,1); m_cmbTarCoordSystem.SetWindowText(strTar); CString strDX = m_list.GetItemText(nSel,2); m_editDX.SetWindowText(strDX); CString strDY = m_list.GetItemText(nSel,3); m_editDY.SetWindowText(strDY); CString strDZ = m_list.GetItemText(nSel,4); m_editDZ.SetWindowText(strDZ); CString strRX = m_list.GetItemText(nSel,5); m_editRX.SetWindowText(strRX); CString strRY = m_list.GetItemText(nSel,6); m_editRY.SetWindowText(strRY); CString strRZ = m_list.GetItemText(nSel,7); m_editRZ.SetWindowText(strRZ); CString strK = m_list.GetItemText(nSel,8); m_editK.SetWindowText(strK); CString strName = m_list.GetItemText(nSel,9); m_editName.SetWindowText(strName); } CString CParameterManageDlg::ClearZero( double dValue ) { CString strValue ; strValue.Format(_T("%.20f"),dValue); strValue.TrimRight(_T("0")); strValue.TrimRight(_T(".")); return strValue; }
7參數是保存到配置文件裏的, XMLExt.cpp 用的仍是初版本的, PrjStruct.h 中把xml改成了kml,以及7參數的保存的xml,xml生成的相關代碼看博客:https://my.oschina.net/u/2930533/blog/1829743
座標列表添加了右鍵菜單
CoordEditDlg.h
#pragma once #include "Resource.h" #include "afxwin.h" // CCoordEditDlg 對話框 class CCoordEditDlg : public CDialog { DECLARE_DYNAMIC(CCoordEditDlg) public: CCoordEditDlg(CString& strName,CString& strXCoord, CString& strYCoord,CString& strLong, CString& strLat,CWnd* pParent = NULL); // 標準構造函數 virtual ~CCoordEditDlg(); // 對話框數據 enum { IDD = IDD_DLG_COORDEDIT }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() virtual BOOL OnInitDialog(); afx_msg void OnBnClickedOk();//肯定 public: void GetData(CString& strName,CString& strXCoord, CString& strYCoord,CString& strLong, CString& strLat); private: CEdit m_editName; CString m_strName;//名稱 CEdit m_editXCoord; CString m_strXCoord;//東座標 CEdit m_editYCoord; CString m_strYCoord;//北座標 CEdit m_editLong; CString m_strLong;//經度 CEdit m_editLat; CString m_strLat;//緯度 };
CoordEditDlg.cpp
// CoordEditDlg.cpp : 實現文件 // #include "stdafx.h" #include "CoordEditDlg.h" #include "afxdialogex.h" // CCoordEditDlg 對話框 IMPLEMENT_DYNAMIC(CCoordEditDlg, CDialog) CCoordEditDlg::CCoordEditDlg(CString& strName,CString& strXCoord, CString& strYCoord,CString& strLong, CString& strLat,CWnd* pParent /*=NULL*/) : CDialog(CCoordEditDlg::IDD, pParent) ,m_strName(strName) ,m_strXCoord(strXCoord) ,m_strYCoord(strYCoord) ,m_strLong(strLong) ,m_strLat(strLat) { } CCoordEditDlg::~CCoordEditDlg() { } void CCoordEditDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDITNAME, m_editName); DDX_Control(pDX, IDC_EDITLONG, m_editLong); DDX_Control(pDX, IDC_EDITLAT, m_editLat); DDX_Control(pDX, IDC_EDIT_XCOORD, m_editXCoord); DDX_Control(pDX, IDC_EDIT_YCOORD, m_editYCoord); } BEGIN_MESSAGE_MAP(CCoordEditDlg, CDialog) ON_BN_CLICKED(IDOK, &CCoordEditDlg::OnBnClickedOk) END_MESSAGE_MAP() void CCoordEditDlg::OnBnClickedOk() { m_editName.GetWindowText(m_strName); m_editXCoord.GetWindowText(m_strXCoord); m_editYCoord.GetWindowText(m_strYCoord); m_editLong.GetWindowText(m_strLong); m_editLat.GetWindowText(m_strLat); if (m_strName.IsEmpty() || m_strLong.IsEmpty() || m_strLat.IsEmpty() || m_strXCoord.IsEmpty() || m_strYCoord.IsEmpty()) { MessageBox(_T("請將信息填寫完整!"), _T("提示框"), MB_OK | MB_ICONHAND ); return; } __super::OnOK(); } BOOL CCoordEditDlg::OnInitDialog() { __super::OnInitDialog(); m_editName.ReplaceSel(m_strName); m_editXCoord.ReplaceSel(m_strXCoord); m_editYCoord.ReplaceSel(m_strYCoord); m_editLong.ReplaceSel(m_strLong); m_editLat.ReplaceSel(m_strLat); return TRUE; } void CCoordEditDlg::GetData( CString& strName,CString& strXCoord, CString& strYCoord,CString& strLong, CString& strLat ) { strName = m_strName; strXCoord = m_strXCoord; strYCoord = m_strYCoord; strLong = m_strLong; strLat = m_strLat; }
導出Excel其中用到了Excel相關的類,具體請看另一篇博客,的方法2:http://www.javashuo.com/article/p-aoxtndls-n.html