Files
coco df489d5640 a
2026-07-03 16:05:30 +08:00

396 lines
12 KiB
C++

// COption3DGeometryDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "GeoMative.h"
#include "crossHole/COption3DGeometryDlg.h"
#include "crossHole/COption3DBoreholeDlg.h"
#include "crossHole/COption3DSurfaceDlg.h"
#include "crossHole/CCrosshole3dDrawingBoardDlg.h"
#include "crossHole/C3DSimulationDlg.h"
#include "FileOperTools.h"
#include "afxdialogex.h"
// COption3DGeometryDlg 对话框
IMPLEMENT_DYNAMIC(COption3DGeometryDlg, CDialog)
COption3DGeometryDlg::COption3DGeometryDlg(CWnd* pParent /*=NULL*/)
: CDialog(COption3DGeometryDlg::IDD, pParent)
{
}
COption3DGeometryDlg::~COption3DGeometryDlg()
{
}
void COption3DGeometryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_GEOMETRY, m_geometryList);
}
BEGIN_MESSAGE_MAP(COption3DGeometryDlg, CDialog)
ON_BN_CLICKED(ID_BTN_SORT, &COption3DGeometryDlg::OnBnClickedBtnSort)
ON_BN_CLICKED(ID_BTN_SAVE_GEOMETRY, &COption3DGeometryDlg::OnBnClickedSaveGeometry)
ON_BN_CLICKED(ID_BTN_CLEAR_ALL, &COption3DGeometryDlg::OnBnClickedBtnClearAll)
END_MESSAGE_MAP()
COption3DGeometryDlg* COption3DGeometryDlg::GetInstance()
{
static COption3DGeometryDlg optionGeometryDlg;
return &optionGeometryDlg;
}
BOOL COption3DGeometryDlg::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("Y(m)"), LVCFMT_CENTER, 60);
m_geometryList.InsertColumn(iColIndex++, _T("Z(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 COption3DGeometryDlg::OnBnClickedBtnSort()
{
// TODO: 在此添加控件通知处理程序代码
}
void COption3DGeometryDlg::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,y,z
strRawContent.Format(_T("%s,%s,%s,%s\r\n"), \
m_geometryList.GetItemText(i, 1), \
m_geometryList.GetItemText(i, 2), \
m_geometryList.GetItemText(i, 3), \
m_geometryList.GetItemText(i, 4));
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));
}
}
}
// COption3DGeometryDlg 消息处理程序
void COption3DGeometryDlg::OnBnClickedBtnClearAll()
{
// TODO: 在此添加控件通知处理程序代码
DeleteCoordinatesPoint();
C3DSimulationDlg::GetInstance()->DeleteCoordinatesPoint();
C3DSimulationDlg::GetInstance()->ShowWindow(SW_HIDE);
CCrosshole3dDrawingBoardDlg::GetInstance()->DeleteCoordinatesPoint();
CCrosshole3dDrawingBoardDlg::GetInstance()->ShowWindow(SW_SHOW);
}
void COption3DGeometryDlg::AddCoordinatesPoints(EN_COORDINATES_TYPE eType, std::vector<STBoreHolePoints> vecNewPoints)
{
std::vector<STBoreHolePoints>::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 COption3DGeometryDlg::AddNoSortCoordinatesFromFile(std::vector<STBoreHolePoints> vecNewPoints)
{
m_vecNoSortAllPoints.clear();
m_vecNoSortAllPoints = vecNewPoints;
ShowCoordinatesPoints();
}
void COption3DGeometryDlg::DeleteCoordinatesPoint()
{
m_geometryList.DeleteAllItems();
m_vecNoSortAllPoints.clear();
//删除集合
DeletePointsToVector();
}
void COption3DGeometryDlg::ShowCoordinatesPoints()
{
m_geometryList.DeleteAllItems();
CString strText;
int iColIndex = 0;
vector<STBoreHolePoints>::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->fY);//孔,Y坐标
m_geometryList.SetItemText(iColIndex, 3, strText);
strText.Format(_T("%.2f"), iter->fZ);//孔,Z坐标
m_geometryList.SetItemText(iColIndex, 4, strText);
iColIndex++;
}
}
//地表
void COption3DGeometryDlg::AddSurfacePointsToVector(std::vector<STBoreHolePoints> vecNewPoints)
{
/*std::vector<STBoreHolePoints>::iterator iter = vecNewPoints.begin();
for (; iter != vecNewPoints.end(); iter++)
{
m_vecSurfaceCoordinates.push_back(*iter);
}*/
EN_CABLE_DIRECTION_TYPE eCableDirection = COption3DSurfaceDlg::GetInstance()->GetCableDirectionType();
switch (eCableDirection)
{
case EN_CABLE_DIRECTION_X:
{
CString strLog;
int iExists = 0;
//X方向的电缆,Y有几个值就有几条线
float fCurY = vecNewPoints.at(0).fY;
iExists = m_mapSurfaceXCoordinates.count(fCurY);
if (0 == iExists)
{
m_mapSurfaceXCoordinates[fCurY] = vecNewPoints;
//////////////////////////////////////////////////////////////////////////
//打印日志
/*strLog.Format(_T("之前不存在孔\n"));
OutputDebugString(strLog);
std::vector<STBoreHolePoints>::iterator iter = vecNewPoints.begin();
for (; iter != vecNewPoints.end(); iter++)
{
strLog.Format(_T("x=%f,z=%f\n"), iter->fX,iter->fZ);
OutputDebugString(strLog);
}*/
}
else
{
std::vector<STBoreHolePoints> vecOldPoint;
vecOldPoint = m_mapSurfaceXCoordinates[fCurY];
m_mapSurfaceXCoordinates.erase(fCurY);
std::vector<STBoreHolePoints>::iterator iter = vecNewPoints.begin();
for (; iter != vecNewPoints.end(); iter++)
{
vecOldPoint.push_back(*iter);
}
m_mapSurfaceXCoordinates[fCurY] = vecOldPoint;
//////////////////////////////////////////////////////////////////////////
//打印日志
strLog.Format(_T("***************************X的测线\n"));
OutputDebugString(strLog);
iter = vecOldPoint.begin();
for (; iter != vecOldPoint.end(); iter++)
{
strLog.Format(_T("x=%.2f,y=%.2f,z=%.2f\n"), iter->fX, iter->fY, iter->fZ);
OutputDebugString(strLog);
}
}
CCrosshole3dDrawingBoardDlg::GetInstance()->AddSurfaceXPointsToVector(m_mapSurfaceXCoordinates);
C3DSimulationDlg::GetInstance()->AddSurfaceXPointsToVector(m_mapSurfaceXCoordinates);
}
break;
case EN_CABLE_DIRECTION_Y:
{
CString strLog;
int iExists = 0;
//Y方向的电缆,X有几个值就有几条线
float fCurX = vecNewPoints.at(0).fX;
iExists = m_mapSurfaceYCoordinates.count(fCurX);
if (0 == iExists)
{
m_mapSurfaceYCoordinates[fCurX] = vecNewPoints;
//////////////////////////////////////////////////////////////////////////
//打印日志
/*strLog.Format(_T("之前不存在孔\n"));
OutputDebugString(strLog);
std::vector<STBoreHolePoints>::iterator iter = vecNewPoints.begin();
for (; iter != vecNewPoints.end(); iter++)
{
strLog.Format(_T("x=%f,z=%f\n"), iter->fX,iter->fZ);
OutputDebugString(strLog);
}*/
}
else
{
std::vector<STBoreHolePoints> vecOldPoint;
vecOldPoint = m_mapSurfaceYCoordinates[fCurX];
m_mapSurfaceYCoordinates.erase(fCurX);
std::vector<STBoreHolePoints>::iterator iter = vecNewPoints.begin();
for (; iter != vecNewPoints.end(); iter++)
{
vecOldPoint.push_back(*iter);
}
m_mapSurfaceYCoordinates[fCurX] = vecOldPoint;
//////////////////////////////////////////////////////////////////////////
//打印日志
strLog.Format(_T("---------------------Y的测线\n"));
OutputDebugString(strLog);
iter = vecOldPoint.begin();
for (; iter != vecOldPoint.end(); iter++)
{
strLog.Format(_T("x=%.2f,y=%.2f,z=%.2f\n"), iter->fX, iter->fY, iter->fZ);
OutputDebugString(strLog);
}
}
CCrosshole3dDrawingBoardDlg::GetInstance()->AddSurfaceYPointsToVector(m_mapSurfaceYCoordinates);
C3DSimulationDlg::GetInstance()->AddSurfaceYPointsToVector(m_mapSurfaceYCoordinates);
}
break;
default:
break;
}
//打印当前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<STBoreHolePoints>::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);
}
}
}*/
//将数据传递给画板井下,暂时这么传递
//CDrawingBoardDlg::GetInstance()->AddSurfacePointsToVector(m_mapSurfaceXCoordinates);
//CDrawingBoardDlg::GetInstance()->AddSurfacePointsToVector(m_mapSurfaceYCoordinates);
//将数据传给模拟井下
//C3DSimulationDlg::GetInstance()->AddSurfacePointsToVector(m_vecSurfaceCoordinates);
}
//井下
void COption3DGeometryDlg::AddBoreholePointToVector(std::vector<STBoreHolePoints> vecNewPoints) //将坐标点添加到集合
{
BOOL bExist = FALSE;
STWellPoints stWellPoint;
stWellPoint.fX = vecNewPoints.at(0).fX;
stWellPoint.fY = vecNewPoints.at(0).fY;
map<STWellPoints, vector<STBoreHolePoints>>::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<STBoreHolePoints>::iterator iterNew = vecNewPoints.begin();
for (; iterNew != vecNewPoints.end(); iterNew++)
{
iter->second.push_back(*iterNew);
}
}
else
{
m_mapBoreholeCoordinates[stWellPoint] = vecNewPoints;
}
CCrosshole3dDrawingBoardDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates);
C3DSimulationDlg::GetInstance()->AddBoreholePointToVector(m_mapBoreholeCoordinates);
}
void COption3DGeometryDlg::DeletePointsToVector() //删除集合的数据
{
m_mapBoreholeCoordinates.clear();
m_mapSurfaceXCoordinates.clear();
m_mapSurfaceYCoordinates.clear();
m_vecAllElecCoordinatesInfo.clear();
//m_vecSurfaceCoordinates.clear();
}