www.pudn.com > DEM_TDS.rar > MapViewAttrib.cpp, change:2007-06-20,size:5986b


// MapViewAttrib.cpp: implementation of the MapViewAttrib class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "DEM.h" 
#include "MapViewAttrib.h" 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
//构造函数 
MapViewAttrib::MapViewAttrib() 
{ 
 
} 
 
//析构函数 
MapViewAttrib::~MapViewAttrib() 
{ 
 
} 
 
//获取视口 
CPoint MapViewAttrib::GetViewExt() 
{ 
	return ViewportExt; 
} 
 
//获取窗口 
CPoint MapViewAttrib::GetWindowOrg() 
{ 
	return WindowOrg; 
} 
 
//设置地图显示比例 
void MapViewAttrib::SetMapView() 
{ 
 
} 
 
//将显示比例重置为100% 
void MapViewAttrib::ReFlesh(CRect clientrect,int Size_X,int Size_Y) 
{ 
	ViewportOrg.x=0; 
	ViewportOrg.y=0; 
	ViewportExt.x=clientrect.Width(); 
	ViewportExt.y=clientrect.Height(); 
 
	scalex=(float)ViewportExt.x/(float)Size_X; 
	scaley=(float)ViewportExt.y/(float)Size_Y; 
	scale=scalex<scaley?scalex:scaley; 
 
	WindowExt.x=int((float)Size_X*scale); 
	WindowExt.y=int((float)Size_Y*scale); 
 
	WindowOrg.x=(ViewportExt.x-WindowExt.x)/2; 
	WindowOrg.y=(ViewportExt.y-WindowExt.y)/2; 
 
	showscale=1.0; 
	CMainFrame* pMFrm=(CMainFrame *)AfxGetMainWnd(); 
	CString cs; 	cs.Format("%f%c",showscale*scale*100,'%'); 
	pMFrm->drawtoolbar.showscalecombox.SetWindowText(cs); 
} 
 
//显示窗口转换 
void MapViewAttrib::ViewportChange(CRect clientrect,int Size_X,int Size_Y) 
{ 
	ViewportOrg.x=0; 
	ViewportOrg.y=0; 
	ViewportExt.x=clientrect.Width(); 
	ViewportExt.y=clientrect.Height(); 
 
	scalex=(float)ViewportExt.x/(float)Size_X; 
	scaley=(float)ViewportExt.y/(float)Size_Y; 
	scale=scalex<scaley?scalex:scaley; 
 
	WindowExt.x=int((float)Size_X*scale); 
	WindowExt.y=int((float)Size_Y*scale); 
 
	CPoint point(ViewportExt.x/2,ViewportExt.y/2); 
	SetShowScale(showscale,point); 
} 
 
//放大 
void MapViewAttrib::ZoomIn() 
{ 
	CPoint point(ViewportExt.x/2,ViewportExt.y/2); 
	SetShowScale(showscale*2,point); 
} 
 
//缩小 
void MapViewAttrib::ZoomOut() 
{ 
	CPoint point(ViewportExt.x/2,ViewportExt.y/2); 
	SetShowScale(showscale/2,point); 
} 
 
//将窗口中心移动到点point(即将地图中point所对应的点设置为窗口中心) 
void MapViewAttrib::WindowMove(CPoint point) 
{ 
	WindowOrg.x+=(ViewportExt.x/2-point.x); 
	WindowOrg.y+=(ViewportExt.y/2-point.y); 
} 
 
void MapViewAttrib::SetOldPoint(CPoint point) 
{ 
	oldpoint=point; 
} 
 
//拖动 
void MapViewAttrib::MoveWithMouse(CPoint point) 
{ 
	WindowOrg.x+=(point.x-oldpoint.x); 
	WindowOrg.y+=(point.y-oldpoint.y); 
	oldpoint=point; 
} 
 
 
//显示框选放大 
void MapViewAttrib::ShowRect(CPoint point) 
{ 
	CPoint centerpoint; 
	float crectx,crecty; 
	float scalex,scaley; 
	float scale; 
	centerpoint.x=(point.x+oldpoint.x)/2; 
	centerpoint.y=(point.y+oldpoint.y)/2; 
	WindowMove(centerpoint); 
	crectx=(float)abs(point.x-oldpoint.x); 
	crecty=(float)abs(point.y-oldpoint.y); 
	scalex=(float)ViewportExt.x/crectx; 
	scaley=(float)ViewportExt.y/crecty; 
	scale=scalex<scaley?scalex:scaley; 
 
	CPoint point1(ViewportExt.x/2,ViewportExt.y/2); 
	SetShowScale(showscale*scale,point1); 
} 
 
 
//框选放大框的绘制 
void MapViewAttrib::DrawCret(CPoint point,CDC *pDC,bool firstdraw) 
{ 
	CPen pen(PS_DOT,0,RGB(255,0,0)); 
	pDC->SelectObject(&pen); 
	CBrush brush(RGB(255,255,255)); 
	pDC->SelectObject(&brush); 
	pDC->SetROP2(R2_NOTXORPEN); 
 
	CPoint oldLPpoint=oldpoint; 
	pDC->DPtoLP(&oldLPpoint); 
	pDC->DPtoLP(&point); 
	if(!firstdraw)pDC->Rectangle(oldLPpoint.x,oldLPpoint.y,currentpoint.x,currentpoint.y); 
	currentpoint=point; 
	pDC->Rectangle(oldLPpoint.x,oldLPpoint.y,point.x,point.y); 
 
} 
 
 
void MapViewAttrib::SetCurrentPoint(CPoint point) 
{ 
	currentpoint=point; 
} 
 
 
//滚动放大缩小 
void MapViewAttrib::WheelZoom(int zoomadd,CPoint pt) 
{    
   float scale; 
   if(showscale<5.0)scale=(float)zoomadd*(float)0.1; 
   else if(showscale<10.0)scale=(float)zoomadd*(float)0.5; 
   else if(showscale<50.0)scale=(float)zoomadd*(float)2.5; 
   else if(showscale<100.0)scale=(float)zoomadd*(float)5; 
   else	scale=(float)zoomadd*(float)10; 
 
 
 //  SetShowScale(scale+showscale,pt); 
   CPoint point(ViewportExt.x/2,ViewportExt.y/2); 
   SetShowScale(showscale+scale,point); 
} 
 
//获取显示比例 
float MapViewAttrib::GetShowScale() 
{ 
 return showscale; 
} 
 
//设置显示比例 
void MapViewAttrib::SetShowScale(float newscale,CPoint unmovept) 
{ 
	if(newscale*scale>65) 
	{ 
		AfxMessageBox("已达最大显示比例!", MB_OK); 
		newscale=65/scale; 
	} 
 
	if(newscale*scale<0.03125) 
	{ 
		AfxMessageBox("已达最小显示比例!", MB_OK); 
		newscale=0.03125/scale; 
	} 
 
	WindowOrg.x-=(int)((unmovept.x-WindowOrg.x)*(newscale/showscale-1)); 
	WindowOrg.y-=(int)((unmovept.y-WindowOrg.y)*(newscale/showscale-1)); 
	showscale=newscale; 
	 
	CMainFrame* pMFrm=(CMainFrame *)AfxGetMainWnd(); 
	CString cs; 	cs.Format("%f%c",showscale*scale*100,'%'); 
	pMFrm->drawtoolbar.showscalecombox.SetWindowText(cs); 
} 
 
 
CPoint MapViewAttrib::GetWindowExt() 
{ 
	return WindowExt; 
} 
 
CPoint MapViewAttrib::GetPointNumber(CPoint point) 
{ 
	CPoint point1; 
	point1.x=int((float)(point.x-WindowOrg.x)/showscale/scale); 
	point1.y=int((float)(point.y-WindowOrg.y)/showscale/scale); 
	return point1; 
} 
 
void MapViewAttrib::DrawGrad(CDC *pDC,int Size_X, int Size_Y) 
{ 
	CPen pen(PS_SOLID,0,RGB(0,0,0)); 
	pDC->SelectObject(pen); 
	pDC->SetROP2(R2_COPYPEN); 
	for(int i=0;i<=Size_X;i++) 
	  { 
		  pDC->MoveTo(WindowOrg.x+int(i*showscale*scale),WindowOrg.y); 
		  pDC->LineTo(WindowOrg.x+int(i*showscale*scale),WindowOrg.y+int(Size_Y*showscale*(scale-0.0021))); 
	  } 
	for(int j=0;j<=Size_Y;j++) 
	  { 
		  pDC->MoveTo(WindowOrg.x,WindowOrg.y+int(j*showscale*(scale-0.0021))); 
		  pDC->LineTo(WindowOrg.x+int(Size_X*showscale*scale),WindowOrg.y+int(j*showscale*(scale-0.0021))); 
	  } 
}