📄 raderview.cpp
字号:
ASSERT(pDoc->m_dwWidth != 0);
ASSERT(pDoc->m_dwHeight != 0);
//打开文件
CFile f;
CFileException e;
if(!f.Open(pDoc->m_szFilePath,CFile::modeRead,&e))
{
AfxMessageBox("Cannot Open file!");
return;
}
UNDATA* pLineData = new UNDATA[dwWidth];
CMainFrame* pMainFrame = ((CMainFrame*)AfxGetMainWnd());
pMainFrame->SetStatusBarText(0, "Sampling...");
pMainFrame->OnProcessBegin();
DWORD dwTheY;
DWORD dwTheX;
UNDATA dwTemp;
for(DWORD i=0 ; i<m_pWholeMapDlg->m_dwThisHeight ; i++)
{
pMainFrame->OnProcessUpdate(i, m_pWholeMapDlg->m_dwThisHeight);
dwTheY = (DWORD)(i*fRatio+0.5);
f.Seek(dwTheY * dwWidth * sizeof(UNDATA), CFile::begin);
VERIFY(f.Read(pLineData, dwWidth * sizeof(UNDATA)));
for(DWORD j=0 ; j<m_pWholeMapDlg->m_dwThisWidth ; j++)
{
dwTheX = (DWORD)(j*fRatio+0.5);
if(sizeof(UNDATA) == sizeof(DWORD))
dwTemp = (UNDATA)(pLineData[dwTheX] / pow(2, 24));//UNDATA
else if(sizeof(UNDATA) == sizeof(unsigned short))
dwTemp = (UNDATA)(pLineData[dwTheX] / pow(2, 8));//UNDATA
else if(sizeof(UNDATA) == sizeof(BYTE))
dwTemp = (UNDATA)(pLineData[dwTheX]);
else
ASSERT(FALSE);
ASSERT(dwTemp < 256);
m_pWholeMapDlg->m_pDisplayData[(m_pWholeMapDlg->m_dwThisHeight-i-1)*dwSampleCol+j] = (BYTE)dwTemp;
}
}
pMainFrame->OnProcessEnd(i, m_pWholeMapDlg->m_dwThisHeight);
pMainFrame->SetStatusBarText(0, "");
delete[] pLineData;
f.Close();
RECT Rect;
RECT clientRect;
GetClientRect(&clientRect);
CPoint point = GetScrollPosition();
m_pWholeMapDlg->m_dwWidth = (DWORD)(dwWidth * pDoc->m_dZoomedRatio);
m_pWholeMapDlg->m_dwHeight = (DWORD)(dwHeight * pDoc->m_dZoomedRatio);
Rect.left = point.x;
Rect.top = point.y;
Rect.right = (clientRect.right-clientRect.left)>(int)m_pWholeMapDlg->m_dwWidth?
(int)m_pWholeMapDlg->m_dwWidth:(clientRect.right-clientRect.left)+Rect.left;
Rect.bottom = (clientRect.bottom-clientRect.top)>(int)m_pWholeMapDlg->m_dwHeight?
(int)m_pWholeMapDlg->m_dwHeight:(clientRect.bottom-clientRect.top)+Rect.top;
m_pWholeMapDlg->m_Rect = Rect;
float Ratio = (float)m_pWholeMapDlg->m_dwThisWidth/m_pWholeMapDlg->m_dwWidth;
m_pWholeMapDlg->m_NewRect.left = (int)(Rect.left*Ratio);
m_pWholeMapDlg->m_NewRect.top = (int)(Rect.top*Ratio);
m_pWholeMapDlg->m_NewRect.right = (int)(Rect.right*Ratio);
m_pWholeMapDlg->m_NewRect.bottom = (int)(Rect.bottom*Ratio);
m_pWholeMapDlg->m_OldRect = m_pWholeMapDlg->m_NewRect;
m_pWholeMapDlg->Create();
int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
int TitleHeight = GetSystemMetrics(SM_CYCAPTION);
int BorderWidth = GetSystemMetrics(SM_CXBORDER);
int BorderHeight = GetSystemMetrics(SM_CYBORDER);
int cx = m_pWholeMapDlg->m_dwThisWidth+2*BorderWidth;
int cy = m_pWholeMapDlg->m_dwThisHeight+3*BorderWidth+TitleHeight;
int x = ScreenWidth-cx-100;
int y = ScreenHeight-cy;
m_pWholeMapDlg->SetWindowPos(NULL,x,y,cx,cy,SWP_NOZORDER);
m_pWholeMapDlg->ShowWindow(SW_SHOW);
m_bViewPosition = TRUE;
}
void CRaderView::OnUpdateViewWholemap(CCmdUI* pCmdUI)
{
CRaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc->m_bHasReady)
pCmdUI->Enable(FALSE);
else
{
pCmdUI->Enable(TRUE);
if(m_bViewPosition)
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
}
void CRaderView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.NormalizeRect();
CRect rect(0,0,rectClient.Width(),rectClient.Height());
InvalidateRect(&rect, FALSE);
if(m_pLeeDlg)
m_pLeeDlg->InvalidateDlg();
}
void CRaderView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.NormalizeRect();
CRect rect(0,0,rectClient.Width(),rectClient.Height());
InvalidateRect(&rect, FALSE);
if(m_pLeeDlg)
m_pLeeDlg->InvalidateDlg();
}
void CRaderView::OnLfilterTwo()
{
if(m_pLeeDlg)
{
m_pLeeDlg->DestroyWindow();
delete m_pLeeDlg;
m_pLeeDlg = NULL;
return;
}
CRaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_pLeeDlg = new LFilterDlg(this);
m_pLeeDlg->Create();
m_pLeeDlg->SetWindowText(pDoc->GetTitle() + " [Local Image]");
CRect rect;
GetWindowRect(&rect);
m_pLeeDlg->SetWindowPos(NULL,
rect.left + 310,
rect.top-23,
rect.Width() + 10,
rect.Height() + 150,
SWP_NOZORDER);
m_pLeeDlg->ShowWindow(SW_SHOW);
}
void CRaderView::OnUpdateLfilterTwo(CCmdUI* pCmdUI)
{
CRaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc->m_bHasReady)
pCmdUI->Enable(FALSE);
else
{
pCmdUI->Enable(TRUE);
if(m_pLeeDlg)
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
}
void CRaderView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
m_bSized = TRUE;
}
void CRaderView::OnFileExport()
{
m_bExport = !m_bExport;
}
void CRaderView::OnUpdateFileExport(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bExport);
}
BOOL CRaderView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CScrollView::OnSetCursor(pWnd, nHitTest, message);
if ( pWnd != this || nHitTest != HTCLIENT ) return TRUE;
if(m_bExport)
SetCursor( AfxGetApp()->LoadCursor( IDC_EXPORT));
else
SetCursor(AfxGetApp()->LoadStandardCursor( IDC_ARROW ) );
return true;
}
void CRaderView::DrawSelectRegion(CDC* pDC, const CPoint point, CRect& rectOut)
{
ASSERT_VALID(pDC);
CRect rect;
CPoint PrePoint, NextPoint;
//int dDistance;
rect.SetRect((int)m_ptMouseDown.x, (int)m_ptMouseDown.y, (int)point.x, (int)point.y);
rect.NormalizeRect();
pDC->Rectangle(&rect);
rectOut = rect;//.SetRect((int)(rect.left ) / pDoc->m_dZoomRate),
//(int)(rect.top - pDoc->m_ptOriginPos.y) / pDoc->m_dZoomRate),
//(int)(rect.right - pDoc->m_ptOriginPos.x) / pDoc->m_dZoomRate),
//(int)(rect.bottom - pDoc->m_ptOriginPos.y) / pDoc->m_dZoomRate));
if(rectOut.Width() == 0)
rectOut.InflateRect( 1, 0);
if(rectOut.Height() == 0)
rectOut.InflateRect( 0, 1);
return;
}
void CRaderView::OnLButtonDown(UINT nFlags, CPoint point)
{
if(!m_bExport)
return;
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rect;
CPen pen ;
CPen* poldpen = NULL ;
int oldROP2;
m_bMouseDown = TRUE;
m_ptMouseDown = point;
m_ptMouseMove = point;
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0) ) ;
poldpen = dc.SelectObject(&pen);
oldROP2 = dc.GetROP2();
dc.SetROP2(R2_NOTXORPEN);
// 绘制新的矩形。
DrawSelectRegion(&dc, m_ptMouseMove, rect);
if( NULL != poldpen ) dc.SelectObject(poldpen);
dc.SetROP2(oldROP2);
pen.DeleteObject();
CScrollView::OnLButtonDown(nFlags, point);
}
void CRaderView::OnMouseMove(UINT nFlags, CPoint point)
{
CRaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc->m_bHasReady) return;
CMainFrame* pMainFrame = ((CMainFrame*)AfxGetMainWnd());
char szText[32];
sprintf(szText,"(%d,%d)",point.x, point.y);
pMainFrame->SetStatusBarText(1, szText);
//sprintf(szText,"(%d,%d)",abs(point.x-m_ptMouseDown.x), abs(point.y-m_ptMouseDown.y));
//pMainFrame->SetStatusBarText(2, szText);
/*
CRSMap *pRsMap = pDoc->m_pRsMap;
int nHeight = pRsMap->m_nHeight;
int nBmpCol;
if(pRsMap->m_nImageType==IMAGE_SINGLEBAND)
{
BYTE cGray;
nBmpCol = (pRsMap->m_nWidth+3)/4*4;
cGray = pRsMap->m_pImageData[(nHeight-nAbsY-1)*nBmpCol+nAbsX];
sprintf(szText,"Value = %d",(int)cGray);
((CMainFrame *)(theApp->m_pMainWnd))->m_wndStatusBar.SetPaneText(3,szText);
}
*/
CClientDC dc(this);
OnPrepareDC(&dc);
CPen pen ;
CPen* poldpen = NULL ;
CRect rect;
int oldROP2;
if(!m_bExport)
return;
if(m_bMouseDown)
{
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0) ) ;
poldpen = dc.SelectObject(&pen);
oldROP2 = dc.GetROP2();
dc.SetROP2(R2_NOTXORPEN);
// 隐藏已有的矩形。
DrawSelectRegion(&dc, m_ptMouseMove, rect);
m_ptMouseMove = point;
// 绘制新的矩形。
DrawSelectRegion(&dc, m_ptMouseMove, rect);
if( NULL != poldpen ) dc.SelectObject(poldpen);
dc.SetROP2(oldROP2);
pen.DeleteObject();
}
CScrollView::OnMouseMove(nFlags, point);
}
void CRaderView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(!m_bExport)
return;
m_bMouseDown = FALSE;
CPen pen ;
CPen* poldpen = NULL;
int oldROP2;
CRect rect;
CClientDC dc(this);
OnPrepareDC(&dc);
m_ptMouseMove = point;
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0) ) ;
poldpen = dc.SelectObject(&pen);
oldROP2 = dc.GetROP2();
dc.SetROP2(R2_NOTXORPEN);
DrawSelectRegion(&dc, m_ptMouseMove, rect);
if( NULL != poldpen ) dc.SelectObject(poldpen);
dc.SetROP2(oldROP2);
pen.DeleteObject();
CRect rectTemp(0, 0, m_dwWidth, m_dwHeight);
rectTemp.NormalizeRect();
rect.NormalizeRect();
rect.IntersectRect(rect, rectTemp);
CRaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFileDialog dlg( FALSE, "*.dat", NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Radar Image(*.dat) | *.dat"
"||");
if(IDOK != dlg.DoModal())
{
return;
}
BeginWaitCursor();
pDoc->ExportRect(dlg.GetPathName(), rect);
EndWaitCursor();
Invalidate();
CScrollView::OnLButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -