📄 geogisview.cpp
字号:
// GeoGisView.cpp : implementation of the CGeoGisView class
//
#include "stdafx.h"
#include "GeoGis.h"
#include "GeoGisDoc.h"
#include "GeoGisView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CGraphPara *p_GraphPara;
CGeoGisView *p_View;
extern DPtoVP(float x,float y,int *X,int *Y);
extern VPtoDP(int x,int y,float *X,float *Y);
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView
IMPLEMENT_DYNCREATE(CGeoGisView, CScrollView)
BEGIN_MESSAGE_MAP(CGeoGisView, CScrollView)
//{{AFX_MSG_MAP(CGeoGisView)
ON_WM_SIZE()
ON_WM_PAINT()
ON_COMMAND(ID_DRAW_POINT, OnDrawPoint)
ON_UPDATE_COMMAND_UI(ID_DRAW_POINT, OnUpdateDrawPoint)
ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
ON_COMMAND(ID_DRAW_PLINE, OnDrawPline)
ON_UPDATE_COMMAND_UI(ID_DRAW_PLINE, OnUpdateDrawPline)
ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView construction/destruction
CGeoGisView::CGeoGisView()
{
m_xStart=0.0;
m_yStart=0.0;
blc=1.0;
}
CGeoGisView::~CGeoGisView()
{
}
BOOL CGeoGisView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView drawing
void CGeoGisView::VPtoDP(int x, int y, float *X, float *Y)
{
*X = m_xStart +x*blc;
if(m_MapMode==1)
*Y= m_yStart +blc* (m_hScreen-y);
else
*Y = m_yStart+blc*(y+m_hScreen);
}
void CGeoGisView::DPtoVP(float x, float y, int *X, int *Y)
{
*X= (int)((x-m_xStart)/blc);
if(m_MapMode==1)
*Y = m_hScreen-(int)((y-m_yStart)/blc);
else
*Y= (int)((y-m_yStart)/blc)-m_hScreen;
}
float CGeoGisView::VLtoDL(int l)
{
return blc*l;
}
int CGeoGisView::DLtoVL(float l)
{
return (int)(l/blc);
}
void CGeoGisView::OnDraw(CDC* pDC)
{
CGeoGisDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
DrawBack(pDC);
pDoc->Draw(pDC,0,0,m_bColor);
}
void CGeoGisView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView printing
BOOL CGeoGisView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGeoGisView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGeoGisView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView diagnostics
#ifdef _DEBUG
void CGeoGisView::AssertValid() const
{
CScrollView::AssertValid();
}
void CGeoGisView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CGeoGisDoc* CGeoGisView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeoGisDoc)));
return (CGeoGisDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGeoGisView message handlers
void CGeoGisView::OnSize(UINT nType, int cx, int cy)
{
m_wScreen=cx;
m_hScreen=cy;
CScrollView::OnSize(nType, cx, cy);
}
void CGeoGisView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
p_View = this;
CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CGeoGisView::OnPaint()
{
CPaintDC dc(this); // device context for painting
OnPrepareDC(&dc);
OnDraw(&dc);
}
void CGeoGisView::DrawBack(CDC *pDC)
{
CBrush brush(p_GraphPara->GetColor(m_bColor));
CBrush *pOldBrush=pDC->SelectObject(&brush);
pDC->PatBlt(0,0,m_wScreen,m_hScreen,PATCOPY);
pDC->SelectObject(pOldBrush);
}
void CGeoGisView::OnDrawPoint()
{
// TODO: Add your command handler code here
PushNumb = 0;
m_DrawCurrent = 0;
}
void CGeoGisView::OnUpdateDrawPoint(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI ->SetCheck(m_DrawCurrent==0);
}
void CGeoGisView::OnDrawLine()
{
PushNumb = 0;
m_DrawCurrent = 1;
}
void CGeoGisView::OnUpdateDrawLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI ->SetCheck(m_DrawCurrent==1);
}
void CGeoGisView::OnDrawPline()
{
// TODO: Add your command handler code here
PushNumb = 0;
m_DrawCurrent = 2;
}
void CGeoGisView::OnUpdateDrawPline(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI ->SetCheck(m_DrawCurrent==2);
}
void CGeoGisView::OnDrawCircle()
{
// TODO: Add your command handler code here
PushNumb = 0;
m_DrawCurrent = 3;
}
void CGeoGisView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI ->SetCheck(m_DrawCurrent==3);
}
void CGeoGisView::OnLButtonDown(UINT nFlags, CPoint point)
{
CGeoGisDoc *pDoc = GetDocument();
CClientDC dc(this);
float r;
float xx1,yy1,xx2,yy2;
//int x1,y1,x2,y2,id_only,Lb,Index,pbh;
int id_only;
BOOL m_Fill;
if(m_DrawCurrent==1)//绘制点point;
{
if(PushNumb==0)
{
PushNumb++;
mPointOrign=point;
mPointOld=point;
SetCapture();
}
else if(PushNumb==1)
{
VPtoDP(mPointOrign.x,mPointOrign.y,&xx1,&yy1);
id_only=pDoc->GetGraphID(1);
pDoc->AddPoint(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,xx1,yy1)
->Draw(&dc,0,0,m_bColor);
PushNumb=0;
ReleaseCapture();
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CGeoGisView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnMouseMove(nFlags, point);
}
void CGeoGisView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnLButtonUp(nFlags, point);
}
void CGeoGisView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnRButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -