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

📄 pathplanview.cpp

📁 实现了波兰式的求解
💻 CPP
字号:
// PathPlanView.cpp : implementation of the CPathPlanView class
//

#include "stdafx.h"
#include "PathPlan.h"

#include "PathPlanDoc.h"
#include "PathPlanView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPathPlanView

IMPLEMENT_DYNCREATE(CPathPlanView, CView)

BEGIN_MESSAGE_MAP(CPathPlanView, CView)
	//{{AFX_MSG_MAP(CPathPlanView)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPathPlanView construction/destruction

CPathPlanView::CPathPlanView()
{
	// TODO: add construction code here

}

CPathPlanView::~CPathPlanView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPathPlanView drawing

void CPathPlanView::OnDraw(CDC* pDC)
{
	CPathPlanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CRect rect;
	GetClientRect(&rect);
	int width = rect.Width();
	int height = rect.Height();
	int SquareLength = width<height? width:height;
	int SmallSquareLength = SquareLength/12;
	pDoc->VerPoint[0].y = (rect.Height() - SquareLength)/2 + SmallSquareLength;
	pDoc->VerPoint[0].x = (rect.Width() - SquareLength)/2 + SmallSquareLength;
	for(int i=1; i<11; i++)
	{
		pDoc->VerPoint[i].x = pDoc->VerPoint[0].x + i*SmallSquareLength;
		pDoc->VerPoint[i].y = pDoc->VerPoint[0].y;
	}
	pDoc->HorPoint[0].x = pDoc->VerPoint[0].x;
	pDoc->HorPoint[0].y = pDoc->VerPoint[0].y;
	for(i=0; i<11; i++)
	{
		pDoc->HorPoint[i].x = pDoc->HorPoint[0].x;
		pDoc->HorPoint[i].y = pDoc->HorPoint[0].y + i*SmallSquareLength;
	}
	for(i=0;i<11;i++)
	{
		pDC->MoveTo(pDoc->VerPoint[i]);
		pDC->LineTo(pDoc->VerPoint[i].x,pDoc->VerPoint[i].y + SquareLength - 2*SmallSquareLength);
	}
	for(i=0;i<11;i++)
	{
		pDC->MoveTo(pDoc->HorPoint[i]);
		pDC->LineTo(pDoc->HorPoint[i].x + SquareLength - 2*SmallSquareLength,pDoc->HorPoint[i].y );
	}
	int col,row;
	CPen pen1(PS_SOLID,2,RGB(255,0,0));
	pDC->SelectObject(&pen1);
	for(i=0; i<100; i++)
	{
		if(pDoc->Barrier[i] == 1)
		{
			col = i%10;
			row = i/10;
			pDC->MoveTo(pDoc->VerPoint[col].x,pDoc->HorPoint[row].y);
			pDC->LineTo(pDoc->VerPoint[col+1].x,pDoc->HorPoint[row+1].y);
			pDC->MoveTo(pDoc->VerPoint[col].x,pDoc->HorPoint[row+1].y);
			pDC->LineTo(pDoc->VerPoint[col+1].x,pDoc->HorPoint[row].y);
		}
	}
	pDC->SelectStockObject(BLACK_PEN);
	CPen pen(PS_DOT,5,RGB(0,255,0));
	pDC->SelectObject(&pen);
	for(i=0; i<pDoc->nPathLength-1; i++)
	{
		col = pDoc->PathNode[i]%10;
		row = pDoc->PathNode[i]/10;
		pDC->MoveTo( (pDoc->VerPoint[col].x + pDoc->VerPoint[col+1].x) / 2,(pDoc->HorPoint[row].y + pDoc->HorPoint[row+1].y) / 2);
		col = pDoc->PathNode[i+1]%10;
		row = pDoc->PathNode[i+1]/10;
		pDC->LineTo( (pDoc->VerPoint[col].x + pDoc->VerPoint[col+1].x) / 2,(pDoc->HorPoint[row].y + pDoc->HorPoint[row+1].y) / 2);
	}

	
}

/////////////////////////////////////////////////////////////////////////////
// CPathPlanView diagnostics

#ifdef _DEBUG
void CPathPlanView::AssertValid() const
{
	CView::AssertValid();
}

void CPathPlanView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CPathPlanView message handlers

void CPathPlanView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CPathPlanDoc* pDoc = GetDocument();
	if(!(point.x < pDoc->VerPoint[0].x || point.x > pDoc->VerPoint[10].x || point.y<pDoc->HorPoint[0].y ||  point.y > pDoc->HorPoint[10].y))
	{
		int ID = pDoc->GetRectID(point);
		if(pDoc->Barrier[ID] == 1)
			pDoc->Barrier[ID] = 0;
		else
			pDoc->Barrier[ID] = 1;
		Invalidate();
	}	
	CView::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

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