357 lines
14 KiB
C++
357 lines
14 KiB
C++
// CCrosshole3dDrawingBoardDlg.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "GeoMative.h"
|
||
#include "crossHole/CCrosshole3dDrawingBoardDlg.h"
|
||
#include "afxdialogex.h"
|
||
|
||
#define DRAW_ARROW_LENGTH (5)
|
||
#define DRAW_BOARD_TO_SIDE_DISTANCE (50)
|
||
#define DRAW_X_Y_Z_EXTESION_LINES_LEN (20) //绘制延长线长度
|
||
#define DRAW_FONT_SIZE (100) //字体大小
|
||
|
||
// CCrosshole3dDrawingBoardDlg 对话框
|
||
|
||
IMPLEMENT_DYNAMIC(CCrosshole3dDrawingBoardDlg, CDialog)
|
||
|
||
CCrosshole3dDrawingBoardDlg::CCrosshole3dDrawingBoardDlg(CWnd* pParent /*=NULL*/)
|
||
: CDialog(CCrosshole3dDrawingBoardDlg::IDD, pParent)
|
||
{
|
||
m_pFont = NULL;
|
||
}
|
||
|
||
CCrosshole3dDrawingBoardDlg::~CCrosshole3dDrawingBoardDlg()
|
||
{
|
||
if (m_pFont != NULL)
|
||
{
|
||
delete m_pFont;
|
||
m_pFont = NULL;
|
||
}
|
||
}
|
||
|
||
void CCrosshole3dDrawingBoardDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CCrosshole3dDrawingBoardDlg, CDialog)
|
||
ON_WM_PAINT()
|
||
END_MESSAGE_MAP()
|
||
|
||
CCrosshole3dDrawingBoardDlg* CCrosshole3dDrawingBoardDlg::GetInstance()
|
||
{
|
||
static CCrosshole3dDrawingBoardDlg drawingBoardDlg;
|
||
return &drawingBoardDlg;
|
||
}
|
||
|
||
BOOL CCrosshole3dDrawingBoardDlg::OnInitDialog()
|
||
{
|
||
CDialog::OnInitDialog();
|
||
|
||
GetParent()->GetClientRect(&m_rcWnd);
|
||
m_rcBrush.left = m_rcWnd.left + DRAW_BOARD_TO_SIDE_DISTANCE;
|
||
m_rcBrush.right = m_rcWnd.right - DRAW_BOARD_TO_SIDE_DISTANCE;
|
||
m_rcBrush.top = m_rcWnd.top + DRAW_BOARD_TO_SIDE_DISTANCE;
|
||
m_rcBrush.bottom = m_rcWnd.bottom - DRAW_BOARD_TO_SIDE_DISTANCE;
|
||
// TODO: 在此添加额外的初始化
|
||
|
||
m_pFont = new CFont();
|
||
m_pFont->CreatePointFont(DRAW_FONT_SIZE, _T("楷体"));
|
||
return TRUE; // return TRUE unless you set the focus to a control
|
||
// 异常: OCX 属性页应返回 FALSE
|
||
}
|
||
|
||
float CCrosshole3dDrawingBoardDlg::CalcMaxCableLength()
|
||
{
|
||
float fDrawBoradMaxLength = 0;
|
||
STWellPoints* pstWellPoint = NULL;
|
||
|
||
int iSurfaceXCount = m_mapSurfaceXPoints.size();
|
||
int iSurfaceYCount = m_mapSurfaceYPoints.size();
|
||
int iBoreholeCount = m_mapBoreholePoints.size();
|
||
map<int, std::vector<STBoreHolePoints>>::iterator iter;
|
||
if (iBoreholeCount > 0)
|
||
{
|
||
float fTempDepth = 0.0;
|
||
pstWellPoint = new STWellPoints[iBoreholeCount];
|
||
map<STWellPoints, vector<STBoreHolePoints>>::iterator iter = m_mapBoreholePoints.begin();
|
||
for (int i = 0; i < iBoreholeCount, iter != m_mapBoreholePoints.end(); i++, iter++)
|
||
{
|
||
pstWellPoint[i] = iter->first;
|
||
//Z方向
|
||
fTempDepth = abs(iter->second.at(iter->second.size() - 1).fZ) + sqrt(pow(iter->second.at(iter->second.size() - 1).fY, 2) / 2);
|
||
if (fTempDepth > fDrawBoradMaxLength)
|
||
{
|
||
fDrawBoradMaxLength = fTempDepth;
|
||
}
|
||
|
||
//X方向
|
||
fTempDepth = iter->second.at(iter->second.size() - 1).fX + sqrt(pow(iter->second.at(iter->second.size() - 1).fY, 2) / 2);
|
||
if (fTempDepth > fDrawBoradMaxLength)
|
||
{
|
||
fDrawBoradMaxLength = fTempDepth;
|
||
}
|
||
}
|
||
|
||
if (pstWellPoint != NULL)
|
||
{
|
||
delete[] pstWellPoint;
|
||
pstWellPoint = NULL;
|
||
}
|
||
}
|
||
|
||
fDrawBoradMaxLength = abs(fDrawBoradMaxLength);
|
||
if (iSurfaceXCount > 0)
|
||
{
|
||
int iWellSize = 0;
|
||
for (iter = m_mapSurfaceXPoints.begin(); iter != m_mapSurfaceXPoints.end(); iter++)
|
||
{
|
||
iWellSize = iter->second.size();
|
||
if (iter->second[iWellSize - 1].fX > fDrawBoradMaxLength)
|
||
fDrawBoradMaxLength = iter->second[iWellSize - 1].fX;
|
||
}
|
||
}
|
||
|
||
if (iSurfaceYCount > 0)
|
||
{
|
||
int iWellSize = 0;
|
||
float fCurMaxXValue = 0.0;
|
||
for (iter = m_mapSurfaceYPoints.begin(); iter != m_mapSurfaceYPoints.end(); iter++)
|
||
{
|
||
iWellSize = iter->second.size();
|
||
fCurMaxXValue = iter->second[iWellSize - 1].fX + sqrt(pow(iter->second[iWellSize - 1].fY, 2) / 2);
|
||
if (fCurMaxXValue > fDrawBoradMaxLength)
|
||
fDrawBoradMaxLength = fCurMaxXValue;
|
||
}
|
||
}
|
||
|
||
return fDrawBoradMaxLength;
|
||
}
|
||
|
||
void CCrosshole3dDrawingBoardDlg::OnPaint()
|
||
{
|
||
CPaintDC dc(this); // device context for painting
|
||
dc.FillSolidRect(m_rcWnd, RGB(255, 255, 255));
|
||
dc.SelectObject(m_pFont);
|
||
CPen pen,penEx,penBlue;
|
||
pen.CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
|
||
penEx.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
|
||
penBlue.CreatePen(PS_SOLID, 2, RGB(81,81,255));
|
||
dc.SelectObject(pen);
|
||
|
||
CString strlog;
|
||
CBrush brush,blueBrush;
|
||
brush.CreateSolidBrush(RGB(0, 0, 0));
|
||
blueBrush.CreateSolidBrush(RGB(81, 81, 255));
|
||
dc.SelectObject(&brush);
|
||
//水平布线,判断是否需要绘制
|
||
int iSurfaceXCount = m_mapSurfaceXPoints.size();
|
||
int iSurfaceYCount = m_mapSurfaceYPoints.size();
|
||
int iBoreholeCount = m_mapBoreholePoints.size();
|
||
map<int, std::vector<STBoreHolePoints>>::iterator iter;
|
||
|
||
float fDrawBoradMaxLength = CalcMaxCableLength();
|
||
|
||
//如果要求X轴和Z轴的最小间距都是一样的,需要取实际长度中较小的一方来计算,防止绘制超过边界
|
||
int iEachSmallSize = (m_rcBrush.right - m_rcBrush.left) / fDrawBoradMaxLength;
|
||
if (m_rcBrush.bottom - m_rcBrush.top < m_rcBrush.right - m_rcBrush.left)
|
||
{
|
||
iEachSmallSize = (m_rcBrush.bottom - m_rcBrush.top) / fDrawBoradMaxLength-1;
|
||
}
|
||
|
||
//绘制带箭头维度体系
|
||
if (iBoreholeCount > 0 || iSurfaceXCount > 0 || iSurfaceYCount > 0)
|
||
{
|
||
dc.SelectObject(penEx);
|
||
//X
|
||
dc.MoveTo(m_rcBrush.left, m_rcBrush.top);
|
||
dc.LineTo(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, m_rcBrush.top);
|
||
//箭头
|
||
dc.MoveTo(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, m_rcBrush.top);
|
||
dc.LineTo(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN - DRAW_ARROW_LENGTH, m_rcBrush.top - DRAW_ARROW_LENGTH);
|
||
dc.MoveTo(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, m_rcBrush.top);
|
||
dc.LineTo(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN - DRAW_ARROW_LENGTH, m_rcBrush.top + DRAW_ARROW_LENGTH);
|
||
dc.TextOutA(m_rcBrush.left + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN + 5, m_rcBrush.top - DRAW_ARROW_LENGTH / 2, _T("X"));
|
||
//Y
|
||
dc.MoveTo(m_rcBrush.left, m_rcBrush.top);
|
||
dc.LineTo(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2), m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2));
|
||
dc.MoveTo(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2), m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2));
|
||
dc.LineTo(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2), m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2) - DRAW_ARROW_LENGTH);
|
||
dc.MoveTo(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2), m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2));
|
||
dc.LineTo(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2) - DRAW_ARROW_LENGTH, m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2));
|
||
dc.TextOutA(m_rcBrush.left + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2) + 5, m_rcBrush.top + sqrt(pow(iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN, 2) / 2) + 5, _T("Y"));
|
||
|
||
//Z
|
||
dc.MoveTo(m_rcBrush.left, m_rcBrush.top);
|
||
dc.LineTo(m_rcBrush.left, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN);
|
||
dc.MoveTo(m_rcBrush.left, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN);
|
||
dc.LineTo(m_rcBrush.left - DRAW_ARROW_LENGTH, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN - DRAW_ARROW_LENGTH);
|
||
dc.MoveTo(m_rcBrush.left, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN);
|
||
dc.LineTo(m_rcBrush.left + DRAW_ARROW_LENGTH, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN - DRAW_ARROW_LENGTH);
|
||
dc.TextOutA(m_rcBrush.left - DRAW_ARROW_LENGTH / 2, m_rcBrush.top + iEachSmallSize*fDrawBoradMaxLength + DRAW_X_Y_Z_EXTESION_LINES_LEN + 5, _T("Z"));
|
||
dc.SelectObject(pen);
|
||
}
|
||
|
||
//X方向电缆示意图
|
||
if (iSurfaceXCount > 0)
|
||
{
|
||
int i = 0;
|
||
int iPointX = m_rcBrush.left;
|
||
int iPointY = m_rcBrush.top;
|
||
for (iter = m_mapSurfaceXPoints.begin(); iter != m_mapSurfaceXPoints.end(); iter++)
|
||
{
|
||
iSurfaceXCount = iter->second.size();
|
||
//如果没有孔,在中间绘制
|
||
if (iBoreholeCount <= 0 && iSurfaceYCount <=0)
|
||
{
|
||
iPointY = m_rcBrush.top + (m_rcBrush.bottom - m_rcBrush.top) / 2;
|
||
}
|
||
else
|
||
{
|
||
//确定起点X坐标
|
||
iPointX = m_rcBrush.left + iEachSmallSize* iter->second[0].fX;
|
||
}
|
||
|
||
//绘制一条总线
|
||
dc.MoveTo(iPointX, iPointY);
|
||
dc.LineTo(iPointX + iEachSmallSize*(iter->second[iSurfaceXCount - 1].fX - iter->second[0].fX), iPointY);
|
||
//strlog.Format(_T("地表 起点x=%d,y=%d,终点x=%d,y=%d\n"), iPointX, iPointY, iPointX + iEachSmallSize*iter->second[iSurfaceXCount - 1].fX, iPointY);
|
||
//OutputDebugString(strlog);
|
||
|
||
iPointX = m_rcBrush.left;
|
||
|
||
//遍历集合的每一个元素
|
||
for (i = 0; i < iSurfaceXCount; i++)
|
||
{
|
||
//strlog.Format(_T("X轴绘制点iter->second[%d].fX值为%f,fEachSmallSize=%d,fEachSmallSize=%.2f,iter->second[i].fY=%.2f x1=%.2f,y1=%.2f,x2=%.2f,y2=%.2f\n\n"), i, iter->second[i].fX, iEachSmallSize, iter->second[i].fX, iPointX + iter->second[i].fX*iEachSmallSize - 2, iPointY - 2, iPointX + iter->second[i].fX*iEachSmallSize + 2, iPointY + 2);
|
||
//OutputDebugString(strlog);
|
||
dc.Ellipse(iPointX + iter->second[i].fX*iEachSmallSize - 2, iPointY - 2, iPointX + iter->second[i].fX*iEachSmallSize + 2, iPointY + 2);
|
||
|
||
//标识电极编号,电极位置重复,后面的覆盖前面的
|
||
strlog.Format(_T("%d"), iter->second[i].uiElecID);
|
||
dc.TextOutA(iPointX + iter->second[i].fX*iEachSmallSize - 3, iPointY - 20, strlog);
|
||
}
|
||
}
|
||
}
|
||
|
||
//Y方向电缆示意图
|
||
if (iSurfaceYCount > 0)
|
||
{
|
||
int i = 0;
|
||
float fYCellSize;
|
||
int iPointX = m_rcBrush.left;
|
||
int iPointY = m_rcBrush.top;
|
||
for (iter = m_mapSurfaceYPoints.begin(); iter != m_mapSurfaceYPoints.end(); iter++)
|
||
{
|
||
iSurfaceYCount = iter->second.size();
|
||
//确定起点X坐标
|
||
iPointX = m_rcBrush.left + iEachSmallSize* iter->second[0].fX;
|
||
|
||
//绘制一条总线
|
||
dc.MoveTo(iPointX, iPointY);
|
||
fYCellSize = iEachSmallSize*iter->second[iSurfaceYCount - 1].fY;
|
||
dc.LineTo(iPointX + sqrt(pow(fYCellSize, 2) / 2), iPointY + sqrt(pow(fYCellSize, 2) / 2));
|
||
//strlog.Format(_T("地表 起点x=%d,y=%d,终点x=%d,y=%d\n"), iPointX, iPointY, iPointX + fYCellSize, iPointY + fYCellSize);
|
||
//OutputDebugString(strlog);
|
||
|
||
//iPointX = m_rcBrush.left;
|
||
iPointY = m_rcBrush.top;
|
||
|
||
//遍历集合的每一个元素
|
||
for (i = 0; i < iSurfaceYCount; i++)
|
||
{
|
||
fYCellSize = sqrt(pow(iter->second[i].fY*iEachSmallSize, 2) / 2);
|
||
dc.Ellipse(iPointX + fYCellSize - 2, iPointY + fYCellSize - 2, iPointX + fYCellSize + 2, iPointY + fYCellSize + 2);
|
||
|
||
//标识电极编号,电极位置重复,后面的覆盖前面的
|
||
strlog.Format(_T("%d"), iter->second[i].uiElecID);
|
||
dc.TextOutA(iPointX + fYCellSize + 7, iPointY + fYCellSize - 7, strlog);
|
||
}
|
||
}
|
||
}
|
||
|
||
//井下电缆示意图
|
||
dc.SelectObject(&blueBrush);
|
||
dc.SelectObject(penBlue);
|
||
if (iBoreholeCount > 0)
|
||
{
|
||
int iPointY = m_rcBrush.top;
|
||
int iPointX = m_rcBrush.left;
|
||
int iLastPointX = 0;
|
||
int iDrawBoreholeWidth = 0;//实际绘制孔的宽度
|
||
float fWellYPoint = 0.0;
|
||
int iCurOneBoreHoleCount = 0;
|
||
int i = 0;
|
||
//遍历每一孔
|
||
map<STWellPoints, vector<STBoreHolePoints>>::iterator iter = m_mapBoreholePoints.begin();
|
||
for (int iBoreholeIndex = 0; iBoreholeIndex < iBoreholeCount, iter != m_mapBoreholePoints.end(); iBoreholeIndex++, iter++)
|
||
{
|
||
iCurOneBoreHoleCount = iter->second.size();
|
||
//同一个孔的X值相等
|
||
iLastPointX = iPointX = m_rcBrush.left + iter->second.at(0).fX*iEachSmallSize;
|
||
fWellYPoint = iEachSmallSize*iter->second.at(0).fY;
|
||
if (iter->second.at(0).fY > 0.000001)
|
||
{
|
||
iPointX += sqrt(pow(fWellYPoint, 2) / 2);
|
||
}
|
||
|
||
//绘制井口坐标到X、Y的距离
|
||
dc.MoveTo(iLastPointX, m_rcBrush.top);
|
||
dc.LineTo(iPointX, m_rcBrush.top + sqrt(pow(fWellYPoint, 2) / 2));
|
||
dc.MoveTo(m_rcBrush.left + sqrt(pow(fWellYPoint, 2) / 2), m_rcBrush.top + sqrt(pow(fWellYPoint, 2) / 2));
|
||
dc.LineTo(iPointX, m_rcBrush.top + sqrt(pow(fWellYPoint, 2) / 2));
|
||
|
||
//绘制井主线
|
||
dc.MoveTo(iPointX, m_rcBrush.top + sqrt(pow(fWellYPoint, 2) / 2));
|
||
dc.LineTo(iPointX, m_rcBrush.top + iEachSmallSize*abs(iter->second.at(iCurOneBoreHoleCount - 1).fZ) + sqrt(pow(fWellYPoint, 2) / 2));
|
||
|
||
//遍历集合的每一个元素
|
||
for (i = 0; i < iCurOneBoreHoleCount; i++)
|
||
{
|
||
dc.Ellipse(iPointX - 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 2 + sqrt(pow(fWellYPoint, 2) / 2), iPointX + 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize + 2 + sqrt(pow(fWellYPoint, 2) / 2));
|
||
|
||
//标识电极编号,电极位置重复,后面的覆盖前面的
|
||
strlog.Format(_T("%d"), iter->second[i].uiElecID);
|
||
dc.TextOutA(iPointX + 5, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 8 + sqrt(pow(fWellYPoint, 2) / 2), strlog);
|
||
}
|
||
}
|
||
}
|
||
// TODO: 在此处添加消息处理程序代码
|
||
// 不为绘图消息调用 CDialog::OnPaint()
|
||
}
|
||
|
||
//将坐标点添加到井下集合
|
||
void CCrosshole3dDrawingBoardDlg::AddBoreholePointToVector(map<STWellPoints, vector<STBoreHolePoints>> mapNewPoints)
|
||
{
|
||
m_mapBoreholePoints.clear();
|
||
m_mapBoreholePoints = mapNewPoints;
|
||
RedrawWindow();
|
||
}
|
||
|
||
//将坐标点添加到地表集合
|
||
void CCrosshole3dDrawingBoardDlg::AddSurfaceXPointsToVector(map<int, std::vector<STBoreHolePoints>> mapXNewPoints)
|
||
{
|
||
m_mapSurfaceXPoints.clear();
|
||
m_mapSurfaceXPoints = mapXNewPoints;
|
||
RedrawWindow();
|
||
|
||
}
|
||
|
||
//将坐标点添加到地表集合
|
||
void CCrosshole3dDrawingBoardDlg::AddSurfaceYPointsToVector(map<int, std::vector<STBoreHolePoints>> mapYNewPoints)
|
||
{
|
||
m_mapSurfaceYPoints.clear();
|
||
m_mapSurfaceYPoints = mapYNewPoints;
|
||
RedrawWindow();
|
||
}
|
||
|
||
//清空所有的线
|
||
void CCrosshole3dDrawingBoardDlg::DeleteCoordinatesPoint()
|
||
{
|
||
m_mapBoreholePoints.clear();
|
||
m_mapSurfaceXPoints.clear();
|
||
m_mapSurfaceYPoints.clear();
|
||
RedrawWindow();
|
||
} |