📄 demoview.cpp
字号:
// DemoView.cpp : 实现文件
//
#include "stdafx.h"
#include "GreedyTP.h"
#include "DemoView.h"
#include ".\demoview.h"
#include "MainFrm.h"
// CDemoView
IMPLEMENT_DYNCREATE(CDemoView, CView)
CDemoView::CDemoView()
{
memset(&m_nodeRect,0,sizeof(m_nodeRect));//初始化保存结点的矩形数组
memset(&m_NodeUsed,0,sizeof(m_NodeUsed));
memset(&m_PathUsed,0,sizeof(m_PathUsed));
// m_hasDrawn = FALSE;
m_pathNum = 0;
sourcePntNum = 0;
}
CDemoView::~CDemoView()
{
}
BEGIN_MESSAGE_MAP(CDemoView, CView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_REBULID, OnRebulid)
END_MESSAGE_MAP()
// CDemoView 绘图
void CDemoView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: 在此添加绘制代码
}
// CDemoView 诊断
#ifdef _DEBUG
void CDemoView::AssertValid() const
{
CView::AssertValid();
}
void CDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
// CDemoView 消息处理程序
void CDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
int a = ((CMainFrame*)AfxGetMainWnd())->m_NodeNum;
if(((CMainFrame*)AfxGetMainWnd())->m_Node)//画结点
{
//如果原来位置上有结点,则方圆70像素内不允许再画一新结点
CRect rectTemp;
for(int i=0;i<a;i++)
{
rectTemp.left = m_nodeRect[i].left -35 ;
rectTemp.top = m_nodeRect[i].top -35 ;
rectTemp.right = m_nodeRect[i].right +35 ;
rectTemp.bottom = m_nodeRect[i].bottom +35 ;
if(PtInRect(&rectTemp,point) )
return;
}
DrawNode(this,point,'A'+a);
//保存该结点
m_NodeUsed[a].nodepoint = point;
m_NodeUsed[a].c = 'A'+a;
m_NodeUsed[a].clked = false;
CRect rect;
rect.left = point.x - 10;
rect.top = point.y - 10;
rect.right = point.x + 10;
rect.bottom = point.y + 10;
if(a>=0&&a<50)
m_nodeRect[a] = rect;//保存该结点的矩形区域,为画路径用。
else
MessageBox("Wrong Node!","注意");
(((CMainFrame*)AfxGetMainWnd())->m_NodeNum)++;//结点个数加一
}
if(((CMainFrame*)AfxGetMainWnd())->m_Path)//画路径的步骤1
{
for(int i=0;i<a;i++)
{
if(PtInRect(&m_nodeRect[i],point) /*&& !m_hasDrawn*/)
{
sourcePnt = m_NodeUsed[i].nodepoint;
sourcePntNum = i;
// m_hasDrawn = TRUE;
break;
}
}
}
CView::OnLButtonDown(nFlags, point);
}
void CDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
int a = ((CMainFrame*)AfxGetMainWnd())->m_NodeNum;
if(((CMainFrame*)AfxGetMainWnd())->m_Path)
{
for(int i=0;i<a;i++)
{
if(PtInRect(&m_nodeRect[i],point) /*&& m_hasDrawn*/ && sourcePntNum!=i)
{
// m_hasDrawn = FALSE;
//记录下该条路径
((CMainFrame*)AfxGetMainWnd())->m_Matrix[sourcePntNum][i]=1;
m_PathUsed[m_pathNum].ndSource = m_NodeUsed[sourcePntNum];
m_PathUsed[m_pathNum].ndDest = m_NodeUsed[i];
DrawPath(this,sourcePnt,m_NodeUsed[i].nodepoint);
m_pathNum++;
break;
}
//else
// m_hasDrawn = FALSE;
}
}
CView::OnLButtonUp(nFlags, point);
}
void CDemoView::OnRebulid()
{
((CMainFrame*)AfxGetMainWnd())->m_Node = FALSE;
((CMainFrame*)AfxGetMainWnd())->m_Path = FALSE;
((CMainFrame*)AfxGetMainWnd())->m_NodeFst=TRUE;
((CMainFrame*)AfxGetMainWnd())->m_PathFst=FALSE;
((CMainFrame*)AfxGetMainWnd())->m_NodeNum = 0;
((CMainFrame*)AfxGetMainWnd())->m_candidateNum=0;
((CMainFrame*)AfxGetMainWnd())->m_VNum = 0;
memset(&((CMainFrame*)AfxGetMainWnd())->m_Matrix,0,sizeof(((CMainFrame*)AfxGetMainWnd())->m_Matrix));
memset(&((CMainFrame*)AfxGetMainWnd())->m_Candidate,-1,sizeof(((CMainFrame*)AfxGetMainWnd())->m_Candidate));
memset(&((CMainFrame*)AfxGetMainWnd())->m_V,-1,sizeof(((CMainFrame*)AfxGetMainWnd())->m_V));
memset(&((CMainFrame*)AfxGetMainWnd())->m_InDegree,0,sizeof(((CMainFrame*)AfxGetMainWnd())->m_InDegree));
memset(&m_nodeRect,0,sizeof(m_nodeRect));
memset(&m_NodeUsed,0,sizeof(m_NodeUsed));
memset(&m_PathUsed,0,sizeof(m_PathUsed));
sourcePntNum = 0;
m_pathNum = 0;
Invalidate(1);
((CMainFrame*)AfxGetMainWnd())->m_algview->Invalidate(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -