📄 collegewizardview.cpp
字号:
// CollegeWizardView.cpp : implementation of the CCollegeWizardView class
//
#include "stdafx.h"
#include "CollegeWizard.h"
#include "CollegeWizardDoc.h"
#include "CollegeWizardView.h"
#include "InsertVertexDlg.h"
#include "InsertPathDlg.h"
#include "Vertex.h"
#include "Path.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView
IMPLEMENT_DYNCREATE(CCollegeWizardView, CScrollView)
BEGIN_MESSAGE_MAP(CCollegeWizardView, CScrollView)
//{{AFX_MSG_MAP(CCollegeWizardView)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_EDIT_INSERT_VERTEX, OnEditInsertVertex)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_EDIT_INSERT_PATH, OnEditInsertPath)
ON_COMMAND(ID_EDIT_UPDATE, OnEditUpdate)
ON_COMMAND(ID_VIEW_INFORMATION, OnViewInformation)
ON_COMMAND(ID_VIEW_ALLPATHS, OnViewAllpaths)
ON_COMMAND(ID_VIEW_SHORTESTPATH, OnViewShortestpath)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView construction/destruction
CCollegeWizardView::CCollegeWizardView()
{
// TODO: add construction code here
//m_pCmd = NULL;//清空命令类
g_pView = this;
m_cmdType = 0;
}
CCollegeWizardView::~CCollegeWizardView()
{
}
BOOL CCollegeWizardView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView drawing
void CCollegeWizardView::OnDraw(CDC* pDC)
{
CCollegeWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//调用文档类的绘图函数
pDoc->Draw(pDC);
}
void CCollegeWizardView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = 800;
sizeTotal.cy = 1200;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView printing
BOOL CCollegeWizardView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCollegeWizardView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCollegeWizardView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView diagnostics
#ifdef _DEBUG
void CCollegeWizardView::AssertValid() const
{
CScrollView::AssertValid();
}
void CCollegeWizardView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CCollegeWizardDoc* CCollegeWizardView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCollegeWizardDoc)));
return (CCollegeWizardDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCollegeWizardView message handlers
void CCollegeWizardView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//在状态栏显示鼠标当前位置
CMainFrame * pWnd = (CMainFrame *)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneInfo(2,ID_SEPARATOR,SBPS_NORMAL,45);
CString strInfo;
strInfo.Format("(%002d,%002d)",point.x,point.y);
pWnd->m_wndStatusBar.SetPaneText(2,strInfo);
CScrollView::OnMouseMove(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//相应鼠标左键单击
void CCollegeWizardView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CCollegeWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
switch(m_cmdType)
{
case ctInsertVertex://插入一新景点或建筑
{
//绘制点,将插入处的坐标变为红色
CDC* pDC = g_pView->GetDC();
pDC->SetPixel(point,RGB(255,0,0));
g_pView->ReleaseDC(pDC);//释放绘图设备指针
//延时等待
Sleep(250);
//为新景点或建筑申请新的空间
class CVertex* newVertex = new CVertex();
//弹出对话框输入新景点或建筑的初始数据
CInsertVertexDlg newVertexDlg;
if(IDOK == newVertexDlg.DoModal())
{//以后要把单选按钮设成有一个为默认得;
//如果对话框内 没有输入 内容会不会出错
if(newVertexDlg.m_isConstructure == -1)
//判断是景点或建筑,默认为建筑
newVertex->SetIsSight(FALSE);
else
newVertex->SetIsSight(newVertexDlg.m_isConstructure);
if(newVertexDlg.m_name.IsEmpty())
//如果用户没有输入景点或建筑名
newVertex->SetName("未知");
else
newVertex->SetName(newVertexDlg.m_name);
if(newVertexDlg.m_finishedTime.IsEmpty())
//如果用户没有输入景点或建筑完成时间
newVertex->SetFinishedTime("未知");
else
newVertex->SetFinishedTime(newVertexDlg.m_finishedTime);
if(newVertexDlg.m_information.IsEmpty())
//如果用户没有输入景点或建筑信息
newVertex->SetInformation("未知");
else
newVertex->SetInformation(newVertexDlg.m_information);
int serialNum = pDoc->nuaaWizard.GetTotalOfVertexs() + 1;
newVertex->SetSerialNum(serialNum); //自动为景点或建筑编号
newVertex->SetLocation(point); //存储景点或建筑位置坐标
//将该点插入nuaaWizard
pDoc->nuaaWizard.InsertVertex(newVertex);
}
Invalidate(true);
Clean(); //清空
break;
}
case ctInsertPath1:
{
//不用nuaaWizard的isLocatedIn(),只用CVertex的
//PATH中存储的CPoint为Vertex中的
//判断是否有景点或建筑被选中,如被选中则用vertex得到被选中目标
CVertex* vertex = g_pDoc->nuaaWizard.GetVertexList();
pDoc->m_path = NULL;
while(vertex)
{//判断vertexpoint是否落在vertex内
if(vertex->IsLocatedIn(point))
break;
vertex = vertex->GetNext();
}
if(vertex)//有景点或建筑被选中,vertex了得到被选中目标
{
pDoc->m_path = new CPath;//为新的道路申请空间
//设置新道路的第一个端点
pDoc->m_path->SetLocation1(vertex->GetLocation());
//设置命令标志
m_cmdType = ctInsertPath2;
//在状态栏显示提示信息
CMainFrame * pWnd = (CMainFrame *)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_NORMAL,625);
CString strInfo = "请在屏幕上选择您要插入道路的第二个端点(只能选择已经存在的景点或建筑):";
pWnd->m_wndStatusBar.SetPaneText(0,strInfo);
}
Invalidate(true);
break;
}
case ctInsertPath2:
{
//判断是否有景点或建筑被选中,如被选中则用vertex得到被选中目标
CVertex* vertex = pDoc->nuaaWizard.GetVertexList();
while(vertex)
{//判断vertexpoint是否落在vertex内
if(vertex->IsLocatedIn(point))
break;
vertex = vertex->GetNext();
}
if(vertex)//有景点或建筑被选中,vertex了得到被选中目标
{ //延时等待
Sleep(300);
//弹出对话框输入新道路的初始数据
CInsertPathDlg newpathDlg;
if(IDOK == newpathDlg.DoModal())
{
if(newpathDlg.m_name.IsEmpty())
pDoc->m_path->SetName("未知");
else
pDoc->m_path->SetName(newpathDlg.m_name);
//设置道路的第二个端点坐标
pDoc->m_path->SetLocation2(vertex->GetLocation());
//自动计算路径长度并存储
pDoc->m_path->SetLength();
//将新道路插入图中
pDoc->nuaaWizard.InsertPath(g_pDoc->m_path);
pDoc->m_path = NULL;//清空
//设置命令标志
m_cmdType = ctUnknown;
//在状态栏提示道路插入成功
CMainFrame * pWnd = (CMainFrame *)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_NORMAL,625);
CString strInfo = "已完成道路插入!";
pWnd->m_wndStatusBar.SetPaneText(0,strInfo);
}
else//点击右键取消
OnRButtonDown(nFlags,point);
}
Invalidate(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -