⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferview.cpp

📁 空间分析模型代码 实现缓冲分析和重叠分析下的集中情况
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// BufferView.cpp : implementation of the CBufferView class
//

#include "stdafx.h"
#include "Buffer.h"
#include "BUFFERDlg.h"
#include "BufferDoc.h"
#include "BufferView.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBufferView

IMPLEMENT_DYNCREATE(CBufferView, CScrollView)

BEGIN_MESSAGE_MAP(CBufferView, CScrollView)
	//{{AFX_MSG_MAP(CBufferView)
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(ID_BUFFER_POINT, OnBufferPoint)
	ON_COMMAND(ID_BUFFER_LINE, OnBufferLine)
	ON_WM_LBUTTONDBLCLK()
	ON_COMMAND(ID_BUFFER_POLYGON, OnBufferPolygon)
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_PBUFFER_CREATED, OnPbufferCreated)
	ON_COMMAND(ID_LBUFFER_CREATED, OnLbufferCreated)
	ON_COMMAND(ID_GBUFFER_CREATED, OnGbufferCreated)
	ON_COMMAND(ID_OVERLAP_POINT, OnOverlapPoint)
	ON_COMMAND(ID_OVERLAP_PPoly, OnOVERLAPPPoly)
	ON_COMMAND(ID_OVERLAP_POverLap, OnOVERLAPPOverLap)
	ON_COMMAND(ID_OVERLAP_DRAWPOLY1, OnOverlapDrawpoly1)
	ON_COMMAND(ID_OVERLAP_DRAWPOLY2, OnOverlapDrawpoly2)
	ON_COMMAND(ID_OVERLAP_UNION, OnOverlapUnion)
	ON_COMMAND(ID_OVERLAP_INSERT, OnOverlapInsert)
	ON_COMMAND(ID_OVERLAP_DIFFERENCE, OnOverlapDifference)
	ON_COMMAND(ID_OVERLAP_LLine, OnOVERLAPLLine)
	ON_COMMAND(ID_OVERLAP_LPOLY, OnOverlapLpoly)
	ON_COMMAND(ID_OVERLAP_LOverLap, OnOVERLAPLOverLap)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CBufferView construction/destruction

CBufferView::CBufferView()
{
	// TODO: add construction code here
  m_overlap=FALSE;
  m_buffer=FALSE;
  m_LBotton_point=FALSE;
  m_LBotton_line=FALSE;
  m_LBotton_polygon=FALSE;
  pp_created=FALSE;
  i=0;
  point_num=0;
  buffer_rad=0;
  m_lBDown=0;
  over_ppoints=0;
  m_o_pDrawPoint=FALSE;
  m_o_pDrawPoly=FALSE;
  drawpolyA=FALSE;
  drawpolyB=FALSE;
  over_union=FALSE;
  over_insert=FALSE;
  over_difference=FALSE;
  drawline=FALSE;
  drawpoly=FALSE;
  line_poly=FALSE;
}

CBufferView::~CBufferView()
{
}

BOOL CBufferView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBufferView drawing

void CBufferView::OnDraw(CDC* pDC)
{
	CBufferDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int n,j=0,k=0;
 
if (m_buffer) 
{


	if (buffer_rad!=0)
	{
       if ((m_BufferOperation==BufferPoint)&&m_points_point.GetSize()!=0)
          PointBuffer(pDC,m_points_point.GetData(),point_num,buffer_rad);
	   if ((m_BufferOperation==BufferLine)&&(m_bufferline.GetSize()!=0))
		  for (int i=0;i<m_bufferline.GetSize();i++)
		  {
			  DrawBuffer(pDC,m_bufferline[i].pStart,m_bufferline[i].pEnd,buffer_rad);
		  }
	   if ((m_BufferOperation==BufferPolygon)&&(m_bufferpolygon.GetSize()!=0))
	   {
		  for (int i=0;i<m_bufferpolygon.GetSize();i++)
		  {
			  DrawBuffer(pDC,m_bufferpolygon[i].pStart,m_bufferpolygon[i].pEnd,buffer_rad);
		  }
	   }
	   
	}
	if (m_LBotton_point) 
	{
		if(m_points_point.GetSize()!=0)
		{
			for (int i=0;i<point_num;i++)
			{
                  CPen pen(PS_SOLID,1,RGB(0,0,0));
                  pDC->SelectObject(pen);
		          int x=m_points_point[i].x;
	              int y=m_points_point[i].y;
	              pDC->SelectStockObject(BLACK_BRUSH);
	              pDC->Ellipse(x-2,y-2,x+2,y+2);
           
			}
		}
		
	}
	
	
	if (m_LBotton_line)
	{
        CPen pen(PS_SOLID,1,RGB(0,0,0));
        pDC->SelectObject(pen);
	   if (m_bufferline.GetSize()!=0)
        {
			  for (int i=0;i<m_bufferline.GetSize();i++)
			  {
				   Line(pDC,m_bufferline[i]);
			  }
        }
	}
	
	

	if(m_LBotton_polygon)
	{
	    CPen pen(PS_SOLID,1,RGB(0,0,0));
        pDC->SelectObject(pen);       
	   if (m_bufferpolygon.GetSize()!=0)
       {
			  for (int i=0;i<m_bufferpolygon.GetSize();i++)
			  {
				   Line(pDC,m_bufferpolygon[i]);
			  }
              
	   }
	}


	
	
}

if (m_overlap)
{
    
      if(m_o_pDrawPoly||m_o_pDrawPoint)
	  {
	       if (m_overlap_ppoints.GetSize()!=0)
		   {
              for (int i=0;i<over_ppoints;i++)
			  {
                   int x=m_overlap_ppoints[i].x;
	               int y=m_overlap_ppoints[i].y;
	               pDC->SelectStockObject(BLACK_BRUSH);
	               pDC->Ellipse(x-2,y-2,x+2,y+2);
           //
			  }
		   }
           if (m_overlap_ppoly.GetSize()!=0)
		   {
		       Polygon(pDC,m_overlap_ppoly.GetData(),m_overlap_ppoly.GetSize());
		   } 

	       if (pp_created)
		   {
               CBrush brush(RGB(255,0,0));
	           if (m_overlap_ppoints.GetSize()!=0)
			   {
		           for (int i=0;i<m_overlap_ppoints.GetSize();i++)
				   {
                        if (p_polygon.PtInRegion(m_overlap_ppoints[i]))
						{
                            pDC->SelectObject(&brush);
                            pDC->Ellipse(m_overlap_ppoints[i].x-2,m_overlap_ppoints[i].y-2,m_overlap_ppoints[i].x+2,m_overlap_ppoints[i].y+2);
						}
				   }
			   }
	           DeleteObject(brush);
		   }
	  }
	  if (drawpolyA||drawpolyB)
	  {
           if (m_overlap_polyA.GetSize()!=0)
		   {
		       Polygon(pDC,m_overlap_polyA.GetData(),m_overlap_polyA.GetSize());
		   }
	       if (m_overlap_polyB.GetSize()!=0)
		   {
		       Polygon(pDC,m_overlap_polyB.GetData(),m_overlap_polyB.GetSize());
		   }
		   if (over_union)
		   {
			   CRect rect1,rect2;
               CPoint pt;
			   long m_top,m_left,m_right,m_bottom;
			   p_polyA.GetRgnBox(rect1);
			   p_polyB.GetRgnBox(rect2);
			   if (rect1.top<rect2.top)
			       m_top=rect1.top;
			   else
				   m_top=rect2.top;
			   if (rect1.left<rect2.left)
			       m_left=rect1.left;
			   else
				   m_left=rect2.left;
			   if (rect1.right<rect2.right)
			       m_right=rect2.right;
			   else
				   m_right=rect1.right;
			   if (rect1.bottom<rect2.bottom)
			       m_bottom=rect2.bottom;
			   else
				   m_bottom=rect1.bottom;
			   for (long x=m_left;x<=m_right;x++)
			      for (long y=m_top;y<=m_bottom;y++)
			      {
					  pt.x=x;
					  pt.y=y;
					  if (p_polyA.PtInRegion(pt)||p_polyB.PtInRegion(pt))
					  {
						  pDC->SetPixel(pt,RGB(0,0,255));
					  }
			      }
			   
			   
		   }
		   if (over_insert)
		   {
			   CRect rect1,rect2;
               CPoint pt;
			   long m_top,m_left,m_right,m_bottom;
			   p_polyA.GetRgnBox(rect1);
			   p_polyB.GetRgnBox(rect2);
			   if (rect1.top<rect2.top)
			       m_top=rect1.top;
			   else
				   m_top=rect2.top;
			   if (rect1.left<rect2.left)
			       m_left=rect1.left;
			   else
				   m_left=rect2.left;
			   if (rect1.right<rect2.right)
			       m_right=rect2.right;
			   else
				   m_right=rect1.right;
			   if (rect1.bottom<rect2.bottom)
			       m_bottom=rect2.bottom;
			   else
				   m_bottom=rect1.bottom;
			   for (long x=m_left;x<=m_right;x++)
			      for (long y=m_top;y<=m_bottom;y++)
			      {
					  pt.x=x;
					  pt.y=y;
					  if (p_polyA.PtInRegion(pt)&&p_polyB.PtInRegion(pt))
					  {
						  pDC->SetPixel(pt,RGB(0,0,255));
					  }
			      }
		   }
		   if (over_difference)
		   {
			   CRect rect1,rect2;
               CPoint pt;
			   long m_top,m_left,m_right,m_bottom;
			   p_polyA.GetRgnBox(rect1);
			   p_polyB.GetRgnBox(rect2);
			   if (rect1.top<rect2.top)
			       m_top=rect1.top;
			   else
				   m_top=rect2.top;
			   if (rect1.left<rect2.left)
			       m_left=rect1.left;
			   else
				   m_left=rect2.left;
			   if (rect1.right<rect2.right)
			       m_right=rect2.right;
			   else
				   m_right=rect1.right;
			   if (rect1.bottom<rect2.bottom)
			       m_bottom=rect2.bottom;
			   else
				   m_bottom=rect1.bottom;
			   for (long x=m_left;x<=m_right;x++)
			      for (long y=m_top;y<=m_bottom;y++)
			      {
					  pt.x=x;
					  pt.y=y;
					  if ((p_polyA.PtInRegion(pt)||p_polyB.PtInRegion(pt))&&(!(p_polyA.PtInRegion(pt))||!(p_polyB.PtInRegion(pt))))
					  {
						  pDC->SetPixel(pt,RGB(0,0,255));
					  }
			      }
		   }
	  }
	  if (drawline||drawpoly)
	  {
           if (m_line.GetSize()!=0)
           {
			   for (int i=0;i<m_line.GetSize();i++)
			   {
				   Line(pDC,m_line[i]);
			   }
           }
           if (m_poly.GetSize()!=0)
           {
			   Polygon(pDC,m_poly.GetData(),m_poly.GetSize());
           }
		   if (line_poly)
		   {
			    CPen pen1(PS_SOLID,2,RGB(0,255,0));
                pDC->SelectObject(&pen1);
			   if (m_line_result.GetSize()!=0)
			   {
                  for (int j=0;j<m_line_result.GetSize();j++)
                  {
                       Line(pDC,m_line_result[j]);
                  }
			   }
		        
		   }

	  }
	  
}
}

void CBufferView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 1000;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CBufferView printing

BOOL CBufferView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBufferView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CBufferView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CBufferView diagnostics

#ifdef _DEBUG
void CBufferView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CBufferView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CBufferDoc* CBufferView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBufferDoc)));
	return (CBufferDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBufferView message handlers

void CBufferView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    CBufferDoc* pDoc = GetDocument();
    CDC *pDC=GetDC();
    if (m_buffer)
    {
         if(m_LBotton_point)
		 {
                m_points_point.Add(point);
	            point_num=m_points_point.GetSize();
                Invalidate(true);
		 }
	
	     if(m_LBotton_line)
		 {
		        LINE l;
			    if (i==0)
				{
                      m_points_line.Add(point);
                      i++;
	
				}
	            else
				{
        
		              m_points_line.Add(point);
			          l.pStart=m_points_line[m_points_line.GetSize()-2];
					  l.pEnd=m_points_line[m_points_line.GetSize()-1];
					  Line(pDC,l);
					  m_bufferline.Add(l); 
		
				}    
    
		 }


         if(m_LBotton_polygon)
		 {

			    LINE l;
			    if (i==0)
				{
                      m_points_line.Add(point);
	                  i++;
	                  pStart=point;
				}
	            else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -