www.pudn.com > easygis.rar > EasyGisView.cpp


// EasyGisView.cpp : implementation of the CEasyGisView class 
// 
 
#include "stdafx.h" 
#include "EasyGis.h" 
 
#include "EasyGisDoc.h" 
#include "EasyGisView.h" 
#include "EG_DataStruct.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView 
 
IMPLEMENT_DYNCREATE(CEasyGisView, CView) 
 
BEGIN_MESSAGE_MAP(CEasyGisView, CView) 
	//{{AFX_MSG_MAP(CEasyGisView) 
	ON_COMMAND(ID_ZOOMAREA, OnZoomarea) 
	ON_COMMAND(ID_ZOOMEQUAL, OnZoomequal) 
	ON_COMMAND(ID_ZOOMIN, OnZoomin) 
	ON_COMMAND(ID_ZOOMMOVEON, OnZoommoveon) 
	ON_COMMAND(ID_ZOOMON, OnZoomon) 
	ON_WM_LBUTTONDOWN() 
	ON_WM_LBUTTONUP() 
	ON_WM_MOUSEMOVE() 
	ON_WM_MOUSEWHEEL() 
	ON_UPDATE_COMMAND_UI(ID_ZOOMMOVEON, OnUpdateZoommoveon) 
	ON_COMMAND(ID_MOVEREMOVE, OnMoveremove) 
	ON_UPDATE_COMMAND_UI(ID_MOVEREMOVE, OnUpdateMoveremove) 
	ON_UPDATE_COMMAND_UI(ID_ZOOMAREA, OnUpdateZoomarea) 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView construction/destruction 
 
CEasyGisView::CEasyGisView() 
{ 
	// TODO: add construction code here 
	m_ZoomValue=m_fangdaxishu=1.11; 
    //offsetX=60;offsetY=-60; 
	offset=1; 
	m_off.x=0; 
	m_off.y=0; 
	b_moveon = FALSE; 
	b_areazoom = FALSE; 
	b_QuerryRegion = FALSE; 
 
} 
 
CEasyGisView::~CEasyGisView() 
{ 
} 
 
BOOL CEasyGisView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView drawing 
 
void CEasyGisView::OnDraw(CDC* pDC) 
{ 
	CEasyGisDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	pDC->SetTextColor(RGB(255,0,0)); 
	// TODO: add draw code for native data here 
	//pDC->TextOut(490,20,"六系一队  龚辉"); 
	CTypedPtrList&WorkSpaceList 
		               =pDoc->m_WorkSpaceList; 
	POSITION pos=WorkSpaceList.GetHeadPosition(); 
	while(pos!=NULL) 
	{ 
		EGC_WorkSpace * pWorkSpaceList=WorkSpaceList.GetNext(pos); 
		CTypedPtrList&MapList 
		               =pWorkSpaceList->m_EGLMapList; 
		POSITION mpos=MapList.GetHeadPosition(); 
		while(mpos!=NULL) 
		{ 
			EGC_Map * pMapList=MapList.GetNext(mpos); 
			pDC->TextOut(500,2,pMapList->m_sMapName); 
			CTypedPtrList&LayerList 
		               =pMapList->m_EGLLayerList; 
			POSITION lpos=LayerList.GetHeadPosition(); 
			while(lpos!=NULL) 
			{ 
				EGC_Layer * pLayerList=LayerList.GetNext(lpos); 
				///////////////////画线////////////////////// 
				CTypedPtrList&LineList 
		                  =pLayerList->m_EGLLineInfoList; 
				POSITION linepos=LineList.GetHeadPosition(); 
				while(linepos!=NULL) 
				{ 
					EGC_LineInfo * pLineList=LineList.GetNext(linepos); 
                    pLineList->DrawLine(pDC,m_ZoomValue, offset,m_off); 
				} 
                ///////////////////画面////////////////////// 
				CTypedPtrList&RegionList 
		                  =pLayerList->m_EGLRegionInfoList; 
				POSITION rpos=RegionList.GetHeadPosition(); 
				while(rpos!=NULL) 
				{ 
					EGC_RegionInfo * pRegionList=RegionList.GetNext(rpos); 
                    pRegionList->DrawRegion(pDC, m_ZoomValue,offset,m_off,b_QuerryRegion); 
				} 
                //////////////////画矩形//////////////////// 
				CTypedPtrList&RectList 
		                  =pLayerList->m_EGLRectInfoList; 
				POSITION repos=RectList.GetHeadPosition(); 
				while(repos!=NULL) 
				{ 
					EGC_RectInfo * pRectList=RectList.GetNext(repos); 
                    pRectList->DrawRect(pDC, m_ZoomValue,offset,m_off); 
				} 
			} 
		}					 
	} 
	GetClientRect(&winRect); 
	winheight = winRect.Height(); 
	winwidth = winRect.Width(); 
	m_fangdaxishuX=(m_MaxX-m_MinX); 
    m_fangdaxishuY=(m_MaxX-m_MinY); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
BOOL EGC_PointInfo::DrawPoint(CDC * pDC) 
{ 
	return TRUE; 
} 
 
BOOL EGC_LineInfo::DrawLine(CDC * pDC,double m_ZoomValue,double offset,POINT m_off) 
{ 
	CPen PenLine; 
	if(!PenLine.CreatePen(PS_SOLID,2,RGB(0,120,120))) 
		return FALSE; 
	CPen *pOldPen=pDC->SelectObject(&PenLine); 
	pDC->MoveTo((int)((PtArray[0].X+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((PtArray[0].Y+(offset-1)*400)/m_ZoomValue+60-m_off.y)); 
	for(int i=0;iLineTo((int)((PtArray[i].X+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((PtArray[i].Y+(offset-1)*400)/m_ZoomValue+60-m_off.y)); 
	} 
	pDC->SelectObject(pOldPen); 
    return TRUE; 
} 
   
BOOL EGC_RegionInfo::DrawRegion(CDC * pDC,double m_ZoomValue,double offset,POINT m_off,bool b_QuerryRegion) 
{ 
	CPen PenRegion; 
	if(!PenRegion.CreatePen(PS_SOLID,1,RGB(0,0,255))) 
		return FALSE; 
	CBrush BrushRegion; 
    if(!BrushRegion.CreateHatchBrush(HS_BDIAGONAL,RGB(255,0,0))) 
		return FALSE; 
	CPen *pOldPen=pDC->SelectObject(&PenRegion); 
    CBrush *pOldBrush=pDC->SelectObject(&BrushRegion); 
	pDC->BeginPath(); 
	pDC->MoveTo((int)((PtArray[0].X+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((PtArray[0].Y+(offset-1)*400)/m_ZoomValue+60-m_off.y)); 
	for(int i=0;iLineTo((int)((PtArray[i].X+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((PtArray[i].Y+(offset-1)*400)/m_ZoomValue+60-m_off.y)); 
 
	} 
	pDC->EndPath(); 
	pDC->StrokeAndFillPath(); 
	pDC->SelectObject(pOldPen); 
    pDC->SelectObject(pOldBrush); 
	return TRUE; 
} 
 
BOOL EGC_RectInfo::DrawRect(CDC * pDC,double m_ZoomValue,double offset,POINT m_off) 
{ 
	CPen PenRect; 
	if(!PenRect.CreatePen(PS_SOLID,1,RGB(0,0,255))) 
		return FALSE; 
	CBrush BrushRect; 
    if(!BrushRect.CreateHatchBrush(HS_BDIAGONAL,RGB(255,0,0))) 
		return FALSE; 
	CPen *pOldPen=pDC->SelectObject(&PenRect); 
    CBrush *pOldBrush=pDC->SelectObject(&BrushRect); 
 
	pDC->Rectangle((int)((RectArray.X1+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((RectArray.Y1+(offset-1)*400)/m_ZoomValue+60-m_off.y),(int)((RectArray.X2+(offset-1)*600)/m_ZoomValue+60+m_off.x),700-(int)((RectArray.Y2+(offset-1)*400)/m_ZoomValue+60-m_off.y)); 
	 
	pDC->SelectObject(pOldPen); 
    pDC->SelectObject(pOldBrush); 
	return TRUE; 
} 
 
BOOL EGC_Layer::DrawLayer(CDC * pDC) 
{ 
	return TRUE; 
} 
 
BOOL EGC_Map::DrawMap(CDC * pDC) 
{ 
	return TRUE; 
} 
 
BOOL EGC_WorkSpace::DrawWorkSpace(CDC * pDC) 
{ 
 
	 
	return TRUE; 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView printing 
 
BOOL CEasyGisView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CEasyGisView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CEasyGisView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView diagnostics 
 
#ifdef _DEBUG 
void CEasyGisView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CEasyGisView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CEasyGisDoc* CEasyGisView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEasyGisDoc))); 
	return (CEasyGisDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CEasyGisView message handlers 
//////////////////////////放大///////////////////////////////////////////////////////// 
void CEasyGisView::OnZoomon()  
{ 
	// TODO: Add your command handler code here 
	if(m_ZoomValue>0.1) 
	{ 
		m_ZoomValue=(m_ZoomValue/1.5); 
		offset=offset/1.45; 
	} 
	else  
		AfxMessageBox("已经放大十倍了,不能再放大了!"); 
	Invalidate(TRUE); 
} 
////////////////////////缩小/////////////////////////////////////////////////////////////// 
void CEasyGisView::OnZoomin()  
{ 
	// TODO: Add your command handler code here 
	if(m_ZoomValue<=6) 
	{ 
		m_ZoomValue=(m_ZoomValue*1.5); 
		offset=offset*1.45; 
	} 
	else  
		AfxMessageBox("已经缩小十倍了,不能再缩小了!"); 
     
    m_ZoomValue= m_ZoomValue; 
	offset=offset; 
	Invalidate(TRUE); 
} 
//////////////////////原始大小////////////////////////////////////////////////// 
void CEasyGisView::OnZoomequal()  
{ 
	// TODO: Add your command handler code here 
    m_ZoomValue=m_fangdaxishu=1.11; 
	offset=1; 
	m_off.x=0;m_off.y=0; 
	MakeAllFalse(); 
	Invalidate(TRUE); 
	 
} 
 
//////////////////////区域放大////////////////////////////////////////////////////// 
void CEasyGisView::OnZoomarea()  
{ 
	// TODO: Add your command handler code here 
	MakeAllFalse(); 
	b_areazoom = TRUE; 
	b_remove=FALSE; 
	m_cur_shape = 2; 
	 
} 
 
/////////////////////漫游/////////////////////////////////////////////////////////// 
void CEasyGisView::OnZoommoveon()  
{ 
	// TODO: Add your command handler code here 
	MakeAllFalse(); 
	b_moveon = TRUE; 
	b_remove=FALSE; 
	m_cur_shape = 1; 
	 
} 
 
 
void CEasyGisView::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	m_down = point; 
	if (b_moveon==TRUE)			//漫游 
	{ 
		m_cur_shape = 1; 
	} 
	if(b_areazoom == TRUE)		//区域缩放 
	{ 
		b_down = TRUE;			//左键按下 
	} 
	 
	CView::OnLButtonDown(nFlags, point); 
} 
 
 
void CEasyGisView::OnLButtonUp(UINT nFlags, CPoint point)  
 
{	// TODO: Add your message handler code here and/or call default 
	m_up = point; 
	if (b_moveon==TRUE)		//漫游 
	{ 
		m_off.x = m_off.x+m_up.x-m_down.x; 
		m_off.y = m_off.y+m_up.y-m_down.y; 
		Invalidate(TRUE); 
	} 
	if (b_areazoom == TRUE)		//区域放大 
	{ 
		b_down = FALSE;    //左键松开 
 
		m_rect.left = (long)  (m_up.xm_down.x)?m_up.x:m_down.x; 
		m_rect.top = (long)	(m_up.ym_down.y)?m_up.y:m_down.y; 
		if (m_rect.IsRectEmpty() == TRUE)  
		{ 
			return; 
		} 
		 
		//实现区域放大缩小算法 
		//以图像中心为中心缩放 
		m_rect.left = m_rect.left-m_off.x; 
		m_rect.right = m_rect.right-m_off.x; 
		m_rect.top = m_rect.top-m_off.y; 
		m_rect.bottom = m_rect.bottom-m_off.y; 
		double selzoom = (1.0*winRect.Height()/m_rect.Height()<1.0*winRect.Width()/1.0*m_rect.Width())?1.0*winRect.Height()/m_rect.Height():winRect.Width()/m_rect.Width(); 
		m_ZoomValue = m_ZoomValue/selzoom; 
		m_off.x =long (selzoom*(winRect.CenterPoint().x - m_rect.CenterPoint().x)-350); 
		m_off.y =long (selzoom*(winRect.CenterPoint().y - m_rect.CenterPoint().y)+100); 
 
		Invalidate(TRUE); 
		if(m_ZoomValue<0.1)	MessageBox("放大倍数已超过10,请单击正常显示按钮!"); 
	} 
	 
	CView::OnLButtonUp(nFlags, point); 
} 
 
 
void CEasyGisView::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
    if(m_cur_shape==1)	SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1)); 
	//上箭头鼠标---漫游使用 
	if(m_cur_shape==2)  SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS)); 
	//十字箭头 
	if(m_cur_shape==3)  SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); 
	//恢复箭头 
     
	if(b_areazoom==TRUE &&  b_down==TRUE)				//区域放大 
	{ 
		CRect rect; 
		CClientDC dc(this); 
		CPen pen; 
		pen.CreatePen(PS_DASH,1,RGB(123,123,0));      //创建画笔 
		dc.SelectObject(&pen);			        	  //选择画笔 
		long x1,y1,x2,y2; 
		x1 = (m_down.x>point.x)?m_down.x:point.x;	  //区域左上点 
		y1 = (m_down.y0)                      //鼠标滚轮向上滑实现放大 
		OnZoomon(); 
	if(zDelta<0)  
		OnZoomin();                   //鼠标滚轮向下滑实现缩小 
	 
	return CView::OnMouseWheel(nFlags, zDelta, pt); 
} 
 
 
void CEasyGisView::MakeAllFalse() 
{ 
	//开关关闭 
	b_moveon = FALSE;//漫游 
	b_areazoom = FALSE;//区域放大 
	b_QuerryLine = FALSE;//线查询 
	b_QuerryRegion=FALSE;//面查询 
 
} 
 
BOOL CEasyGisView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)  
{ 
	return TRUE; 
} 
 
void CEasyGisView::OnUpdateZoommoveon(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
    pCmdUI->SetCheck(b_moveon == TRUE); 
	 
} 
 
void CEasyGisView::OnMoveremove()  
{ 
	// TODO: Add your command handler code here 
	//恢复原尺寸 
	b_remove=TRUE; 
	MakeAllFalse(); 
	m_cur_shape = 3; 
//	OnSetCursor( pWnd, nHitTest, message) 
	 
} 
 
 
void CEasyGisView::OnUpdateMoveremove(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
		pCmdUI->SetCheck(b_remove==TRUE); 
	 
} 
 
void CEasyGisView::OnUpdateZoomarea(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
    pCmdUI->SetCheck(b_areazoom == TRUE); 
}