399 lines
13 KiB
C++
399 lines
13 KiB
C++
// C2DSimulationDlg.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "GeoMative.h"
|
||
#include "crossHole/C2DSimulationDlg.h"
|
||
#include "afxdialogex.h"
|
||
|
||
extern CGeoMativeApp theApp;
|
||
// C2DSimulationDlg 对话框
|
||
|
||
IMPLEMENT_DYNAMIC(C2DSimulationDlg, CDialog)
|
||
|
||
C2DSimulationDlg::C2DSimulationDlg(CWnd* pParent /*=NULL*/)
|
||
: CDialog(C2DSimulationDlg::IDD, pParent)
|
||
{
|
||
m_bStopSimulation = TRUE;
|
||
m_iTimeInterval = 1000;
|
||
}
|
||
|
||
C2DSimulationDlg::~C2DSimulationDlg()
|
||
{
|
||
}
|
||
|
||
void C2DSimulationDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(C2DSimulationDlg, CDialog)
|
||
ON_WM_PAINT()
|
||
END_MESSAGE_MAP()
|
||
|
||
C2DSimulationDlg* C2DSimulationDlg::GetInstance()
|
||
{
|
||
static C2DSimulationDlg simulationBoardDlg;
|
||
return &simulationBoardDlg;
|
||
}
|
||
|
||
BOOL C2DSimulationDlg::OnInitDialog()
|
||
{
|
||
CDialog::OnInitDialog();
|
||
|
||
GetParent()->GetClientRect(&m_rcWnd);
|
||
m_rcBrush.left = m_rcWnd.left + 50;
|
||
m_rcBrush.right = m_rcWnd.right - 50;
|
||
m_rcBrush.top = m_rcWnd.top + 50;
|
||
m_rcBrush.bottom = m_rcWnd.bottom - 50;
|
||
// TODO: 在此添加额外的初始化
|
||
|
||
return TRUE; // return TRUE unless you set the focus to a control
|
||
// 异常: OCX 属性页应返回 FALSE
|
||
}
|
||
|
||
void C2DSimulationDlg::OnPaint()
|
||
{
|
||
CPaintDC dc(this); // device context for painting
|
||
dc.FillSolidRect(m_rcWnd, RGB(255, 255, 255));
|
||
|
||
CPen pen;
|
||
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
|
||
dc.SelectObject(pen);
|
||
CString strlog;
|
||
CBrush cBlackBrush, *pBrush, cRedBrush, cBlueBrush;
|
||
cBlackBrush.CreateSolidBrush(RGB(0, 0, 0));
|
||
cRedBrush.CreateSolidBrush(RGB(255, 0, 0));
|
||
cBlueBrush.CreateSolidBrush(RGB(0, 0, 255));
|
||
pBrush = dc.SelectObject(&cBlackBrush);
|
||
//水平布线,判断是否需要绘制
|
||
int iSurfaceCount = m_vecSurfacePoints.size();
|
||
int iBoreholeCount = m_mapBoreholePoints.size();
|
||
float* pBoreholeXValue = NULL;
|
||
float fDrawBoradMaxLength = 0; //整个画板最大长度
|
||
if (iBoreholeCount > 0)
|
||
{
|
||
pBoreholeXValue = new float[iBoreholeCount];
|
||
std::map<STWellPoints, std::vector<STBoreHolePoints>>::iterator iter = m_mapBoreholePoints.begin();
|
||
for (int i = 0; i<iBoreholeCount, iter != m_mapBoreholePoints.end(); i++, iter++)
|
||
{
|
||
pBoreholeXValue[i] = iter->first.fX;
|
||
if (iter->second.at(iter->second.size() - 1).fZ < fDrawBoradMaxLength)
|
||
{
|
||
fDrawBoradMaxLength = iter->second.at(iter->second.size() - 1).fZ;
|
||
}
|
||
if (abs(fDrawBoradMaxLength) < iter->first.fX)
|
||
{
|
||
fDrawBoradMaxLength = iter->first.fX;
|
||
}
|
||
}
|
||
if (pBoreholeXValue != NULL)
|
||
{
|
||
delete[] pBoreholeXValue;
|
||
pBoreholeXValue = NULL;
|
||
}
|
||
}
|
||
fDrawBoradMaxLength = abs(fDrawBoradMaxLength);
|
||
if (iSurfaceCount > 0)
|
||
{
|
||
if (m_vecSurfacePoints[iSurfaceCount - 1].fX > fDrawBoradMaxLength)
|
||
fDrawBoradMaxLength = m_vecSurfacePoints[iSurfaceCount - 1].fX;
|
||
}
|
||
|
||
strlog.Format(_T("整个画板最大刻度fDrawBoradMaxLength=%f\n"), fDrawBoradMaxLength);
|
||
OutputDebugString(strlog);
|
||
|
||
//如果要求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;
|
||
}
|
||
|
||
//绘制地表线
|
||
CClientDC fdc(this);
|
||
RECT rcText;
|
||
CFont font;
|
||
if (iSurfaceCount > 0)
|
||
{
|
||
int iPointX = m_rcBrush.left;
|
||
int iPointY = m_rcBrush.top;
|
||
//如果没有孔,在中间绘制
|
||
if (iBoreholeCount <= 0)
|
||
{
|
||
iPointY = m_rcBrush.top + (m_rcBrush.bottom - m_rcBrush.top) / 2;
|
||
}
|
||
else
|
||
{
|
||
//确定起点X坐标
|
||
iPointX = m_rcBrush.left + iEachSmallSize*m_vecSurfacePoints[0].fX;
|
||
}
|
||
|
||
//绘制一条总线
|
||
dc.MoveTo(iPointX, iPointY);
|
||
dc.LineTo(iPointX + iEachSmallSize*(m_vecSurfacePoints[iSurfaceCount - 1].fX - m_vecSurfacePoints[0].fX), iPointY);
|
||
strlog.Format(_T("地表 起点x=%d,y=%d,终点x=%d,y=%d\n"), iPointX, iPointY, iPointX + iEachSmallSize*m_vecSurfacePoints[iSurfaceCount - 1].fX, iPointY);
|
||
OutputDebugString(strlog);
|
||
|
||
iPointX = m_rcBrush.left;
|
||
|
||
//遍历集合的每一个元素
|
||
for (int i = 0; i < iSurfaceCount; i++)
|
||
{
|
||
strlog.Format(_T("X轴绘制点m_vecSurfacePoints[%d].fX值为%f,fEachSmallSize=%d,m_vecSurfacePoints[i].fX=%d x1=%d,y1=%d,x2=%d,y2=%d\n"), i, m_vecSurfacePoints[i].fX, iEachSmallSize, m_vecSurfacePoints[i].fX, iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 2, iPointY - 2, iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize + 2, iPointY + 2);
|
||
OutputDebugString(strlog);
|
||
if (m_vecSurfacePoints[i].uiElecID == m_iA || m_vecSurfacePoints[i].uiElecID == m_iB)
|
||
{
|
||
pBrush = dc.SelectObject(&cRedBrush);
|
||
dc.Ellipse(iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 5, iPointY - 5, iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize + 5, iPointY + 5);
|
||
}
|
||
else if (m_vecSurfacePoints[i].uiElecID == m_iM || m_vecSurfacePoints[i].uiElecID == m_iN)
|
||
{
|
||
pBrush = dc.SelectObject(&cBlueBrush);
|
||
dc.Ellipse(iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 5, iPointY - 5, iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize + 5, iPointY + 5);
|
||
}
|
||
else
|
||
{
|
||
pBrush = dc.SelectObject(&cBlackBrush);
|
||
dc.Ellipse(iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 2, iPointY - 2, iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize + 2, iPointY + 2);
|
||
}
|
||
|
||
|
||
//标识电极编号,电极位置重复,后面的覆盖前面的
|
||
strlog.Format(_T("%d"), m_vecSurfacePoints[i].uiElecID);
|
||
rcText.left = iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 3;
|
||
rcText.top = iPointY - 20;
|
||
rcText.right = rcText.left + 20;
|
||
rcText.bottom = iPointY - 1;
|
||
font.CreatePointFont(70, _T(""), &fdc);
|
||
fdc.SelectObject(&font);
|
||
fdc.DrawText(strlog, &rcText, DT_WORDBREAK | DT_BOTTOM);
|
||
//dc.TextOutA(iPointX + m_vecSurfacePoints[i].fX*iEachSmallSize - 4, iPointY - 20, strlog);
|
||
}
|
||
}
|
||
|
||
//绘制孔线
|
||
if (iBoreholeCount > 0)
|
||
{
|
||
int iPointY = m_rcBrush.top;
|
||
int iPointX = m_rcBrush.left;
|
||
int iDrawBoreholeWidth = 0;//实际绘制孔的宽度
|
||
//没有地表线
|
||
/*if (iSurfaceCount <= 0)
|
||
{
|
||
//只有一个孔,居中
|
||
if (iBoreholeCount == 1)
|
||
{
|
||
iPointX = m_rcBrush.left + (m_rcBrush.right - m_rcBrush.left) / 2;
|
||
}
|
||
else
|
||
{
|
||
//先计算所有孔绘制出来后需要的宽度,然后再从中心对称的方式求出X轴起点
|
||
if (pBoreholeXValue != NULL)
|
||
{
|
||
iDrawBoreholeWidth = (pBoreholeXValue[iBoreholeCount - 1] - pBoreholeXValue[0])*iEachSmallSize;
|
||
iPointX = m_rcBrush.left + (m_rcBrush.right - m_rcBrush.left) / 2 - iDrawBoreholeWidth / 2;
|
||
}
|
||
}
|
||
}*/
|
||
|
||
int iCurOneBoreHoleCount = 0;
|
||
int i = 0;
|
||
//遍历每一孔
|
||
std::map<STWellPoints, std::vector<STBoreHolePoints>>::iterator iter = m_mapBoreholePoints.begin();
|
||
for (int iBoreholeIndex = 0; iBoreholeIndex < iBoreholeCount, iter != m_mapBoreholePoints.end(); iBoreholeIndex++, iter++)
|
||
{
|
||
iCurOneBoreHoleCount = iter->second.size();
|
||
//绘制一个孔的主线
|
||
/*if (iSurfaceCount <= 0)
|
||
{
|
||
if (iBoreholeIndex > 0)
|
||
{
|
||
iPointX = iPointX + (pBoreholeXValue[iBoreholeIndex] - pBoreholeXValue[iBoreholeIndex - 1])*iEachSmallSize;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//同一个孔的X值相等
|
||
iPointX = m_rcBrush.left + iter->second.at(0).fX*iEachSmallSize;
|
||
}*/
|
||
iPointX = m_rcBrush.left + iter->second.at(0).fX*iEachSmallSize;
|
||
|
||
dc.MoveTo(iPointX, m_rcBrush.top);
|
||
dc.LineTo(iPointX, m_rcBrush.top + iEachSmallSize*abs(iter->second.at(iCurOneBoreHoleCount - 1).fZ));
|
||
strlog.Format(_T("第%d口井起点x=%d,y=%d,终点x=%d,y=%d\n"), iBoreholeIndex + 1, iPointX, m_rcBrush.top, iPointX, m_rcBrush.top + iEachSmallSize*abs(iter->second.at(iCurOneBoreHoleCount - 1).fZ));
|
||
OutputDebugString(strlog);
|
||
|
||
//遍历集合的每一个元素
|
||
for (i = 0; i < iCurOneBoreHoleCount; i++)
|
||
{
|
||
strlog.Format(_T("Z轴绘制点vecCurBoreHolePoint[%d].fZ值为%f,fEachSmallSize=%d,j=%d x1=%d,y1=%d,x2=%d,y2=%d\n"), i, iter->second[i].fZ, iEachSmallSize, abs(iter->second[i].fZ), iPointX - 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 2, iPointX + 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize + 2);
|
||
OutputDebugString(strlog);
|
||
|
||
|
||
if (iter->second[i].uiElecID == m_iA || iter->second[i].uiElecID == m_iB)
|
||
{
|
||
pBrush = dc.SelectObject(&cRedBrush);
|
||
dc.Ellipse(iPointX - 5, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 5, iPointX + 5, iPointY + abs(iter->second[i].fZ)*iEachSmallSize + 5);
|
||
}
|
||
else if (iter->second[i].uiElecID == m_iM || iter->second[i].uiElecID == m_iN)
|
||
{
|
||
pBrush = dc.SelectObject(&cBlueBrush);
|
||
dc.Ellipse(iPointX - 5, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 5, iPointX + 5, iPointY + abs(iter->second[i].fZ)*iEachSmallSize + 5);
|
||
}
|
||
else
|
||
{
|
||
pBrush = dc.SelectObject(&cBlackBrush);
|
||
dc.Ellipse(iPointX - 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 2, iPointX + 2, iPointY + abs(iter->second[i].fZ)*iEachSmallSize + 2);
|
||
}
|
||
|
||
//标识电极编号,电极位置重复,后面的覆盖前面的
|
||
strlog.Format(_T("%d"), iter->second[i].uiElecID);
|
||
rcText.left = iPointX + 4;
|
||
rcText.right = rcText.left + 20;
|
||
rcText.top = iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 8;
|
||
rcText.bottom = rcText.top + 15;
|
||
//dc.TextOutA(iPointX + 4, iPointY + abs(iter->second[i].fZ)*iEachSmallSize - 8, strlog);
|
||
//dc.DrawText(strlog, &rcText, DT_WORDBREAK | DT_LEFT);
|
||
font.CreatePointFont(70, _T(""), &fdc);
|
||
fdc.SelectObject(&font);
|
||
fdc.DrawText(strlog, &rcText, DT_WORDBREAK | DT_LEFT);
|
||
}
|
||
}
|
||
}
|
||
dc.SelectObject(pBrush);
|
||
// TODO: 在此处添加消息处理程序代码
|
||
// 不为绘图消息调用 CDialog::OnPaint()
|
||
}
|
||
|
||
|
||
//将坐标点添加到井下集合
|
||
void C2DSimulationDlg::AddBoreholePointToVector(std::map<STWellPoints, std::vector<STBoreHolePoints>> mapNewPoints)
|
||
{
|
||
m_mapBoreholePoints.clear();
|
||
m_mapBoreholePoints = mapNewPoints;
|
||
RedrawWindow();
|
||
}
|
||
|
||
//将坐标点添加到地表集合
|
||
void C2DSimulationDlg::AddSurfacePointsToVector(std::vector<STBoreHolePoints> vecNewPoints)
|
||
{
|
||
m_vecSurfacePoints.clear();
|
||
|
||
m_vecSurfacePoints = vecNewPoints;
|
||
RedrawWindow();
|
||
|
||
}
|
||
|
||
//清空所有的线
|
||
void C2DSimulationDlg::DeleteCoordinatesPoint()
|
||
{
|
||
m_mapBoreholePoints.clear();
|
||
m_vecSurfacePoints.clear();
|
||
RedrawWindow();
|
||
}
|
||
|
||
void C2DSimulationDlg::SetTimeInterval(int iTimeInterval)
|
||
{
|
||
m_iTimeInterval = iTimeInterval;
|
||
}
|
||
|
||
void C2DSimulationDlg::SetSingleChannelSimulationRunMethod(vector<STDatabaseABMNInfo> vecAllBoreholeABMNInfo)
|
||
{
|
||
m_vecAllBoreholeABMNInfo.clear();
|
||
m_vecAllBoreholeABMNInfo = vecAllBoreholeABMNInfo;
|
||
}
|
||
|
||
void C2DSimulationDlg::SetMultiChannelSimulationRunMethod(map<int, map<int, map<int, STDatabaseABMNInfo>>> mapPointsSortedByABMN)
|
||
{
|
||
m_mapPointsSortedByABMN.clear();
|
||
m_mapPointsSortedByABMN = mapPointsSortedByABMN;
|
||
}
|
||
|
||
//开始模拟
|
||
BOOL C2DSimulationDlg::StartSimulation()
|
||
{
|
||
m_bStopSimulation = FALSE;
|
||
HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SimulateScriptRunMethodThread, this, 0, 0);
|
||
if (INVALID_HANDLE_VALUE == hThread)
|
||
{
|
||
CFileOperTools::GetInstance()->WriteComLog(_T("Create Thread failed to simulate script run method"));
|
||
}
|
||
CloseHandle(hThread);
|
||
return TRUE;
|
||
}
|
||
|
||
//上传设备市场数据到云端
|
||
UINT C2DSimulationDlg::SimulateScriptRunMethodThread(LPVOID lParam)
|
||
{
|
||
C2DSimulationDlg* pThis = (C2DSimulationDlg*)lParam;
|
||
if (pThis == NULL)
|
||
return 1;
|
||
|
||
//CString strLog;
|
||
//theApp.m_ucIsMultiChannel 0:单通道;1:多通道
|
||
if (EN_MULTI_CHANNEL == theApp.m_ucIsMultiChannel)
|
||
{
|
||
map<int, map<int, map<int, STDatabaseABMNInfo>>>::iterator iterA = pThis->m_mapPointsSortedByABMN.begin();
|
||
map<int, map<int, STDatabaseABMNInfo>>::iterator iterB;
|
||
map<int, STDatabaseABMNInfo>::iterator iterM;
|
||
int iTSN = 0;
|
||
for (; iterA != pThis->m_mapPointsSortedByABMN.end(); iterA++)
|
||
{
|
||
for (iterB = iterA->second.begin(); iterB != iterA->second.end(); iterB++)
|
||
{
|
||
for (iterM = iterB->second.begin(); iterM != iterB->second.end(); iterM++)
|
||
{
|
||
if (pThis->m_bStopSimulation)
|
||
{
|
||
break;
|
||
}
|
||
pThis->m_iA = iterM->second.uiAElecID;
|
||
pThis->m_iB = iterM->second.uiBElecID;
|
||
pThis->m_iM = iterM->second.uiMElecID;
|
||
pThis->m_iN = iterM->second.uiNElecID;
|
||
pThis->RedrawWindow();
|
||
//strLog.Format(_T("******************************C2DSimulationDlg::SimulateScriptRunMethodThread a=%d,b=%d,m=%d,n=%d\n"), pThis->m_iA, pThis->m_iB, pThis->m_iM, pThis->m_iN);
|
||
//OutputDebugString(strLog);
|
||
Sleep(pThis->m_iTimeInterval);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (0 == theApp.m_ucIsMultiChannel)
|
||
{
|
||
int iPointCount = pThis->m_vecAllBoreholeABMNInfo.size();
|
||
for (int i = 0; i < iPointCount; i++)
|
||
{
|
||
if (pThis->m_bStopSimulation)
|
||
{
|
||
break;
|
||
}
|
||
pThis->m_iA = pThis->m_vecAllBoreholeABMNInfo[i].uiAElecID;
|
||
pThis->m_iB = pThis->m_vecAllBoreholeABMNInfo[i].uiBElecID;
|
||
pThis->m_iM = pThis->m_vecAllBoreholeABMNInfo[i].uiMElecID;
|
||
pThis->m_iN = pThis->m_vecAllBoreholeABMNInfo[i].uiNElecID;
|
||
pThis->RedrawWindow();
|
||
//strLog.Format(_T("******************************C2DSimulationDlg::SimulateScriptRunMethodThread a=%d,b=%d,m=%d,n=%d\n"), pThis->m_iA, pThis->m_iB, pThis->m_iM, pThis->m_iN);
|
||
//OutputDebugString(strLog);
|
||
Sleep(pThis->m_iTimeInterval);
|
||
}
|
||
}
|
||
|
||
::SendMessage(pThis->GetParent()->GetParent()->GetSafeHwnd(), WM_MSG_UPDATE_CROSSHOLEMAINWND_BTN, NULL, NULL);
|
||
return 0;
|
||
}
|
||
|
||
//结束模拟
|
||
BOOL C2DSimulationDlg::StopSimulation()
|
||
{
|
||
m_bStopSimulation = TRUE;
|
||
return TRUE;
|
||
}
|
||
|
||
//是否正在模拟中
|
||
BOOL C2DSimulationDlg::IsSimulating()
|
||
{
|
||
return !m_bStopSimulation;
|
||
} |