📄 mstkruskalview.cpp
字号:
// MSTkruskalView.cpp : implementation of the CMSTkruskalView class
//
#include "stdafx.h"
#include "MSTkruskal.h"
#include "MSTkruskalDoc.h"
#include "MSTkruskalView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView
IMPLEMENT_DYNCREATE(CMSTkruskalView, CView)
BEGIN_MESSAGE_MAP(CMSTkruskalView, CView)
//{{AFX_MSG_MAP(CMSTkruskalView)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_GENERATEEDGE, OnGenerateedge)
ON_COMMAND(ID_GENERATEMST, OnGeneratemst)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView construction/destruction
CMSTkruskalView::CMSTkruskalView() : prePoint(0, 0), isMSTFound(false)
{
// TODO: add construction code here
}
CMSTkruskalView::~CMSTkruskalView()
{
}
BOOL CMSTkruskalView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView drawing
void CMSTkruskalView::OnDraw(CDC* pDC)
{
CMSTkruskalDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
const int d = 2;
for (int i = 0; i < m_grape.vp.size(); ++i)
{
pDC->Ellipse(m_grape.vp[i].x - d, m_grape.vp[i].y - d,
m_grape.vp[i].x + d, m_grape.vp[i].y + d);
}
if (isMSTFound)
{
for (i = 0; i < m_grape.vIDofMSTEdge.size(); ++i)
{
int id = m_grape.vIDofMSTEdge[i];
pDC->MoveTo(m_grape.ve[id].p1.x, m_grape.ve[id].p1.y);
pDC->LineTo(m_grape.ve[id].p2.x, m_grape.ve[id].p2.y);
}
}
else
{
for (i = 0; i < m_grape.ve.size(); ++i)
{
pDC->MoveTo(m_grape.ve[i].p1.x, m_grape.ve[i].p1.y);
pDC->LineTo(m_grape.ve[i].p2.x, m_grape.ve[i].p2.y);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView printing
BOOL CMSTkruskalView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMSTkruskalView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMSTkruskalView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView diagnostics
#ifdef _DEBUG
void CMSTkruskalView::AssertValid() const
{
CView::AssertValid();
}
void CMSTkruskalView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMSTkruskalDoc* CMSTkruskalView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMSTkruskalDoc)));
return (CMSTkruskalDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMSTkruskalView message handlers
void CMSTkruskalView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (point != prePoint)
{
m_grape.AddPoint(point);
}
Invalidate(TRUE);
CView::OnLButtonDown(nFlags, point);
}
void CMSTkruskalView::OnGenerateedge()
{
// TODO: Add your command handler code here
m_grape.GenerateEdge();
Invalidate(TRUE);
}
void CMSTkruskalView::OnGeneratemst()
{
// TODO: Add your command handler code here
m_grape.FindMST();
isMSTFound = true;
Invalidate(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -