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

338 lines
9.3 KiB
C++

// dispgrap2drsptdview.cpp : implementation file
//
#include "stdafx.h"
#include "geomative.h"
#include "dispgrap2drsptdview.h"
#include "TdChannel.h"
#include "RSP2DTdRecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDispGrap2DRSPTdView
extern int g_iUILanguage;
IMPLEMENT_DYNCREATE(CDispGrap2DRSPTdView, CView)
CDispGrap2DRSPTdView::CDispGrap2DRSPTdView()
{
m_ftTxt.CreatePointFont(90, _T("Tahoma"));
m_iStartPole = 1;
m_iEndPole = 1;
}
CDispGrap2DRSPTdView::~CDispGrap2DRSPTdView()
{
m_ftTxt.DeleteObject();
}
BEGIN_MESSAGE_MAP(CDispGrap2DRSPTdView, CView)
//{{AFX_MSG_MAP(CDispGrap2DRSPTdView)
ON_WM_MOUSEACTIVATE()
ON_WM_MOVE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDispGrap2DRSPTdView drawing
void CDispGrap2DRSPTdView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
CRsp2DTdRecord* pRsp2DTdRecord = NULL;
CBrush brush;
CPen lPen(PS_SOLID, 1, RGB(180, 180, 180));
CPen* pOldLPen = NULL;
CRect vRect;
CRect cRect;
int iIndex = (int)VAL_ZERO;
CString szLabel = _T("");
int iScaleX = (int)VAL_ZERO;
int iScaleY = (int)VAL_ZERO;
CFont *pOldFnt = NULL;
int iXEAmount = 0;
if (m_iStartPole < m_iEndPole)
{
iXEAmount = m_iEndPole - m_iStartPole + 1;
}
else if (m_pTdChannel != NULL)
{
iXEAmount = m_pTdChannel->m_iEAmount;
}
if ((this->m_pTdChannel != NULL) && (m_pTdChannel->m_tdRecArray.GetSize() > 0))
{
this->GetClientRect(vRect);
pDC->FillSolidRect(m_lRect, RGB(255, 255, 255));
DrawColorTable(pDC);
while (iScaleX < iXEAmount)
{
if ((0 == (iScaleX+1)%ELECTRODE_AMOUNT_PERCABLE) || (0 == iScaleX))
{
pDC->MoveTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.top-10);
pDC->LineTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.top);
cRect.SetRectEmpty();
cRect.left = m_lRect.left+(m_iSmWidth-1)*iScaleX-12;
cRect.top = m_lRect.top-22;
cRect.right = m_lRect.left+(m_iSmWidth-1)*iScaleX+13;
cRect.bottom = m_lRect.top-12;
szLabel.Empty();
szLabel.Format(_T("%d"), iScaleX+1+ m_iStartPole-1);
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(szLabel, &cRect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
pDC->SelectObject(pOldFnt);
pDC->MoveTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.bottom);
pDC->LineTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.bottom+10);
cRect.SetRectEmpty();
cRect.left = m_lRect.left+(m_iSmWidth-1)*iScaleX-12;
cRect.top = m_lRect.bottom+12;
cRect.right = m_lRect.left+(m_iSmWidth-1)*iScaleX+13;
cRect.bottom = m_lRect.bottom+22;
szLabel.Empty();
szLabel.Format(_T("%d"), iScaleX+1 + m_iStartPole-1);
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(szLabel, &cRect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
pDC->SelectObject(pOldFnt);
}
else
{
pDC->MoveTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.top-5);
pDC->LineTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.top);
pDC->MoveTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.bottom+5);
pDC->LineTo(m_lRect.left+(m_iSmWidth-1)*iScaleX, m_lRect.bottom-1);
}
iScaleX++;
}
while (iScaleY < this->m_pTdChannel->m_iMaxLevel)
{
if ((0 == (iScaleY+1)%5) || (0 == iScaleY))
{
pDC->MoveTo(m_lRect.left-10, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
pDC->LineTo(m_lRect.left, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
cRect.SetRectEmpty();
cRect.left = m_lRect.left-37;
cRect.top = m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1)-5;
cRect.right = m_lRect.left-12;
cRect.bottom = m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1)+5;
szLabel.Empty();
szLabel.Format(_T("%d"), iScaleY+1);
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(szLabel, &cRect, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
pDC->SelectObject(pOldFnt);
pDC->MoveTo(m_lRect.right, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
pDC->LineTo(m_lRect.right+10, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
cRect.SetRectEmpty();
cRect.left = m_lRect.right+12;
cRect.top = m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1)-5;
cRect.right = m_lRect.right+37;
cRect.bottom = m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1)+5;
szLabel.Empty();
szLabel.Format(_T("%d"), iScaleY+1);
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(szLabel, &cRect, DT_SINGLELINE | DT_VCENTER | DT_LEFT);
pDC->SelectObject(pOldFnt);
}
else
{
pDC->MoveTo(m_lRect.left-5, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
pDC->LineTo(m_lRect.left, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
pDC->MoveTo(m_lRect.right, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
pDC->LineTo(m_lRect.right+5, m_lRect.top+(m_iSmHeight-1)/2*(2*iScaleY+1));
}
iScaleY++;
}
brush.DeleteObject();
while (iIndex < this->m_pTdChannel->m_tdRecArray.GetSize())
{
pRsp2DTdRecord = (CRsp2DTdRecord*)this->m_pTdChannel->m_tdRecArray.GetAt(iIndex);
pDC->SelectStockObject(NULL_BRUSH);
pOldLPen = pDC->SelectObject(&lPen);
pDC->Rectangle(pRsp2DTdRecord->m_recPtArea);
pDC->SelectObject(pOldLPen);
if (pRsp2DTdRecord->m_colorREF != RGB(0xFF, 0xFF, 0xFF))
{
brush.CreateSolidBrush(pRsp2DTdRecord->m_colorREF);
}
else
{
pDC->SelectStockObject(NULL_BRUSH);
}
pDC->FillRect(pRsp2DTdRecord->m_recPtArea, &brush);
brush.DeleteObject();
iIndex++;
}
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(m_lRect);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDispGrap2DRSPTdView diagnostics
#ifdef _DEBUG
void CDispGrap2DRSPTdView::AssertValid() const
{
CView::AssertValid();
}
void CDispGrap2DRSPTdView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDispGrap2DRSPTdView message handlers
int CDispGrap2DRSPTdView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
{
return APP_SUCCESS;
}
void CDispGrap2DRSPTdView::OnMove(int x, int y)
{
CView::OnMove(x, y);
// TODO: Add your message handler code here
this->Invalidate();
}
void CDispGrap2DRSPTdView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CClientDC dc(this);
CRect vRect;
CRect lRect;
int iSmWidth = 0;
int iSmHeight = 0;
this->GetClientRect(vRect);
dc.FillSolidRect(vRect, RGB(0xFF,0xFF,0xFF));
if (NULL != m_pTdChannel)
{
// int iEAmount = m_pTdChannel->m_iEAmount;
// //如果不能被12所整除,那么需要多加12
// if (iEAmount%12 != 0)
// {
// iEAmount =12 * (1 + m_pTdChannel->m_iEAmount/12);
// }
m_pTdChannel->m_pMedium->SetValidPoleInfo(m_iStartPole,m_iEndPole);
m_pTdChannel->m_pMedium->CalculateTdPtLoc(vRect, m_pTdChannel->m_iEAmount, m_pTdChannel->m_iMaxLevel, lRect, iSmWidth, iSmHeight, &m_pTdChannel->m_tdRecArray);
this->m_lRect = lRect;
this->m_iSmWidth = iSmWidth;
this->m_iSmHeight = iSmHeight;
}
this->Invalidate();
}
void CDispGrap2DRSPTdView::DrawColorTable(CDC* pDC)
{
int iColorIndex = (int)VAL_ZERO;
COLORREF aColor[15]={RGB(0,0,0xFF),RGB(0,0x33,0xFF),RGB(0,0x66,0xFF),RGB(0,0x88,0xFF),RGB(0,0xCF,0xFE),RGB(0,0xFE,0xFF),RGB(0,0xFE,0x99),RGB(0,0xFE,0x33),RGB(0x99,0xFE,0),RGB(0xFF,0xFE,0),RGB(0xFE,0xCC,0),RGB(0xFE,0x98,0),RGB(0xFE,0x66,0),RGB(0xFE,0x33,0),RGB(0xFF,0,0)};
CBrush brush;
CRect tRect;
CRect txtRect;
CFont* pOldFnt = NULL;
iColorIndex = (int)VAL_ZERO;
float fMaxR0 = m_pTdChannel->m_fMaxR0;
float fMinR0 = m_pTdChannel->m_fMinR0;
float fSperate = (fMaxR0 - fMinR0)/15;
CString strText;
while (iColorIndex < 15)
{
tRect.SetRectEmpty();
tRect.left = 15;
tRect.top = 25 + iColorIndex * 23;
tRect.right = 35;
tRect.bottom = 48 + iColorIndex * 23;
//些数值范围
float fVal = fMinR0 + iColorIndex* fSperate;
strText.Format(_T("%d"),(int)fVal);
txtRect.left = tRect.right + 3;
txtRect.top = tRect.top - 5;
txtRect.right = txtRect.left + 75;
txtRect.bottom = txtRect.top + 10;
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(strText, &txtRect,DT_SINGLELINE | DT_VCENTER | DT_LEFT);
pDC->SelectObject(pOldFnt);
pDC->Rectangle(tRect);
brush.CreateSolidBrush(aColor[iColorIndex]);
pDC->FillRect(tRect, &brush);
brush.DeleteObject();
iColorIndex++;
}
strText.Format(_T("%d"),(int)fMaxR0);
txtRect.left = tRect.right + 3;
txtRect.top = tRect.bottom - 5;
txtRect.right = txtRect.left + 70;
txtRect.bottom = txtRect.top + 10;
pOldFnt = pDC->SelectObject(&m_ftTxt);
pDC->DrawText(strText, &txtRect,DT_SINGLELINE | DT_VCENTER | DT_LEFT);
pDC->SelectObject(pOldFnt);
}
void CDispGrap2DRSPTdView::SetValidPole(int iStartPole, int iEndPole)
{
if (iStartPole < 1 || iEndPole <= iStartPole)
{
CString str = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
str.Format(_T("设置有效的极点信息错误。start_pole = %d, end_pole = %d"), iStartPole, iEndPole);
AfxMessageBox(str);
}
else
{
str.Format(_T("Set Valid Pole information error. start_pole = %d, end_pole = %d"), iStartPole, iEndPole);
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return;
}
m_iStartPole = iStartPole;
m_iEndPole = iEndPole;
}