// COption2DGeometryDlg.cpp : 实现文件 // #include "stdafx.h" #include "GeoMative.h" #include "crossHole/COption2DGeometryDlg.h" #include "crossHole/COption2DBoreholeDlg.h" #include "crossHole/COption2DSurfaceDlg.h" #include "crossHole/CCrosshole2dDrawingBoardDlg.h" #include "crossHole/C2DSimulationDlg.h" #include "FileOperTools.h" #include "afxdialogex.h" // COption2DGeometryDlg 对话框 IMPLEMENT_DYNAMIC(COption2DGeometryDlg, CDialog) COption2DGeometryDlg::COption2DGeometryDlg(CWnd* pParent /*=NULL*/) : CDialog(COption2DGeometryDlg::IDD, pParent) { } COption2DGeometryDlg::~COption2DGeometryDlg() { } void COption2DGeometryDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST_GEOMETRY, m_geometryList); } BEGIN_MESSAGE_MAP(COption2DGeometryDlg, CDialog) ON_BN_CLICKED(ID_BTN_SORT, &COption2DGeometryDlg::OnBnClickedBtnSort) ON_BN_CLICKED(ID_BTN_SAVE_GEOMETRY, &COption2DGeometryDlg::OnBnClickedSaveGeometry) ON_BN_CLICKED(ID_BTN_CLEAR_ALL, &COption2DGeometryDlg::OnBnClickedBtnClearAll) END_MESSAGE_MAP() COption2DGeometryDlg* COption2DGeometryDlg::GetInstance() { static COption2DGeometryDlg optionGeometryDlg; return &optionGeometryDlg; } BOOL COption2DGeometryDlg::OnInitDialog() { CDialog::OnInitDialog(); int iColIndex = 0; m_geometryList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES); m_geometryList.InsertColumn(iColIndex++, _T("ID"), LVCFMT_LEFT, 60); m_geometryList.InsertColumn(iColIndex++, _T("Addr"), LVCFMT_CENTER, 60); m_geometryList.InsertColumn(iColIndex++, _T("X(m)"), LVCFMT_CENTER, 60); m_geometryList.InsertColumn(iColIndex++, _T("Z(m)"), LVCFMT_CENTER, 60); m_geometryList.InsertColumn(iColIndex++, _T("Y(m)"), LVCFMT_CENTER, 60); // TODO: 在此添加额外的初始化 if (LANG_ZHCN == g_iUILanguage) { SetDlgItemTextA(ID_BTN_SORT,_T("排序")); SetDlgItemTextA(ID_BTN_SAVE_GEOMETRY, _T("保存坐标")); SetDlgItemTextA(ID_BTN_CLEAR_ALL, _T("清空")); } return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void COption2DGeometryDlg::OnBnClickedBtnSort() { // TODO: 在此添加控件通知处理程序代码 } void COption2DGeometryDlg::OnBnClickedSaveGeometry() { // TODO: 在此添加控件通知处理程序代码 CFileDialog cfd(FALSE, _T(".geomative"), _T("*.geomative"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("geomative Files(*.geomative)|*.txt||"), NULL); if (IDOK == cfd.DoModal()) { CString strFilePath; strFilePath.Format(_T("%s"), cfd.GetPathName()); CFile cf; BOOL bRes = false; CString strRawContent; bRes = cf.Open(strFilePath, CFile::modeCreate|CFile::modeReadWrite); if (bRes) { int iItemCount = m_geometryList.GetItemCount(); for (int i = 0; i < iItemCount; i++) { //Addr,x,z strRawContent.Format(_T("%s,%s,%s\r\n"), m_geometryList.GetItemText(i, 1), m_geometryList.GetItemText(i, 2), m_geometryList.GetItemText(i, 3)); cf.Write(strRawContent, strRawContent.GetLength()); } cf.Close(); if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("保存文件成功")); else MessageBoxEx(NULL, _T("Save file successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } } // COption2DGeometryDlg 消息处理程序 void COption2DGeometryDlg::OnBnClickedBtnClearAll() { // TODO: 在此添加控件通知处理程序代码 DeleteCoordinatesPoint(); C2DSimulationDlg::GetInstance()->DeleteCoordinatesPoint(); C2DSimulationDlg::GetInstance()->ShowWindow(SW_HIDE); CCrosshole2dDrawingBoardDlg::GetInstance()->DeleteCoordinatesPoint(); CCrosshole2dDrawingBoardDlg::GetInstance()->ShowWindow(SW_SHOW); } void COption2DGeometryDlg::AddCoordinatesPoints(EN_COORDINATES_TYPE eType, std::vector vecNewPoints) { std::vector::iterator iter = vecNewPoints.begin(); for (; iter != vecNewPoints.end(); iter++) { m_vecNoSortAllPoints.push_back(*iter); } ShowCoordinatesPoints(); //添加到集合 switch (eType) { case EN_BOREHOLE_TYPE: AddBoreholePointToVector(vecNewPoints); break; case EN_SURFACE_TYPE: AddSurfacePointsToVector(vecNewPoints); break; default: break; } } void COption2DGeometryDlg::AddNoSortCoordinatesFromFile(std::vector vecNewPoints) { m_vecNoSortAllPoints.clear(); m_vecNoSortAllPoints = vecNewPoints; ShowCoordinatesPoints(); } void COption2DGeometryDlg::DeleteCoordinatesPoint() { m_geometryList.DeleteAllItems(); m_vecNoSortAllPoints.clear(); //删除集合 DeletePointsToVector(); } void COption2DGeometryDlg::ShowCoordinatesPoints() { m_geometryList.DeleteAllItems(); CString strText; int iColIndex = 0; vector::iterator iter = m_vecNoSortAllPoints.begin(); for (; iter != m_vecNoSortAllPoints.end(); iter++) { m_geometryList.InsertItem(iColIndex, _T("")); strText.Format(_T("%d"), iter->uiID); m_geometryList.SetItemText(iColIndex, 0, strText); strText.Format(_T("%d"), iter->uiElecID); m_geometryList.SetItemText(iColIndex, 1, strText); strText.Format(_T("%.2f"), iter->fX);//孔,X坐标固定 m_geometryList.SetItemText(iColIndex, 2, strText); strText.Format(_T("%.2f"), iter->fZ); m_geometryList.SetItemText(iColIndex, 3, strText); strText.Format(_T("%.2f"), iter->fY); m_geometryList.SetItemText(iColIndex, 4, strText); iColIndex++; } } //地表 void COption2DGeometryDlg::AddSurfacePointsToVector(std::vector vecNewPoints) { std::vector::iterator iter = vecNewPoints.begin(); for (; iter != vecNewPoints.end(); iter++) { m_vecSurfaceCoordinates.push_back(*iter); } //打印当前X轴坐标 /*CString strLog; iter = m_vecSurfaceCoordinates.begin(); OutputDebugString(_T("打印当前X轴坐标\n")); for (; iter != m_vecSurfaceCoordinates.end(); iter++) { strLog.Format(_T("x=%f\n"),iter->fX); OutputDebugString(strLog); }*/ /*if (m_vecSurfaceCoordinates.size() <= 0) { m_vecSurfaceCoordinates = vecNewPoints; } else { //新加入的逐个比较 int i = 0; BOOL bAppend = TRUE; std::vector::iterator newIter = vecNewPoints.begin(); for (; newIter != vecNewPoints.end(); newIter++) { bAppend = TRUE; for (i = 0; i < m_vecSurfaceCoordinates.size(); i++) { if (newIter->fX < m_vecSurfaceCoordinates[i].fX) { bAppend = FALSE; m_vecSurfaceCoordinates.insert(m_vecSurfaceCoordinates.begin() + i, *newIter); break; } } //集合中没有小于它的值 if (bAppend) { m_vecSurfaceCoordinates.push_back(*newIter); } } }*/ //将数据传递给画板井下 CCrosshole2dDrawingBoardDlg::GetInstance()->AddSurfacePointsToVector(m_vecSurfaceCoordinates); //将数据传给模拟井下 C2DSimulationDlg::GetInstance()->AddSurfacePointsToVector(m_vecSurfaceCoordinates); } //井下 void COption2DGeometryDlg::AddBoreholePointToVector(std::vector vecNewPoints) //将坐标点添加到集合 { /*CString strLog; int iExists = 0; float fCurX = vecNewPoints.at(0).fX; iExists = m_mapBoreholeCoordinates.count(fCurX); if (0 == iExists) { m_mapBoreholeCoordinates[fCurX] = vecNewPoints; } else { std::vector vecOldPoint; vecOldPoint = m_mapBoreholeCoordinates[fCurX]; m_mapBoreholeCoordinates.erase(fCurX); std::vector::iterator iter = vecNewPoints.begin(); for (; iter != vecNewPoints.end(); iter++) { vecOldPoint.push_back(*iter); } m_mapBoreholeCoordinates[fCurX] = vecOldPoint; } //将数据传递给画板井下 CCrosshole2dDrawingBoardDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates); //将数据传给模拟窗口井下 C2DSimulationDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates);*/ BOOL bExist = FALSE; STWellPoints stWellPoint; stWellPoint.fX = vecNewPoints.at(0).fX; stWellPoint.fY = vecNewPoints.at(0).fY; map>::iterator iter = m_mapBoreholeCoordinates.begin(); for (; iter != m_mapBoreholeCoordinates.end(); iter++) { if (iter->first.fX == stWellPoint.fX && iter->first.fY == stWellPoint.fY) { bExist = TRUE; break; } } if (bExist) { std::vector::iterator iterNew = vecNewPoints.begin(); for (; iterNew != vecNewPoints.end(); iterNew++) { iter->second.push_back(*iterNew); } } else { m_mapBoreholeCoordinates[stWellPoint] = vecNewPoints; } //CCrosshole2dDrawingBoardDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates); //将数据传递给画板井下 CCrosshole2dDrawingBoardDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates); //将数据传给模拟窗口井下 C2DSimulationDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates); } void COption2DGeometryDlg::DeletePointsToVector() //删除集合的数据 { m_mapBoreholeCoordinates.clear(); m_vecSurfaceCoordinates.clear(); }