📄 path.cpp
字号:
// Path.cpp: implementation of the CPath class.
//
//////////////////////////////////////////////////////////////////////
//如果想要串行化还要再加入宏
#include "stdafx.h"
#include "CollegeWizard.h"
#include "CollegeWizardDoc.h"
#include "CollegeWizardView.h"
#include "InsertPathDlg.h"
#include <afx.h>//包含类CObject
#include <math.h>
#include "Path.h"
#define DISTANCE 10//如果坐标到直线的距离小于等于DISTANCE,则认为已选中该直线
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPath::CPath()
{
CString m_name = "/0"; //道路名称,"/0"代表不可用
m_bIsVisited = g_pDoc->nuaaWizard.GetVisitedTag();//是否已经被访问过
m_path1 = NULL;
m_path2 = NULL;
m_length = NULL;
}
CPath::CPath(CString name, //道路名称
CPoint location1, //本路径景点或建筑的位置
CPoint location2, //本路径景点或建筑的位置
CPath * path1, //以m_serialNum1为顶点的另一条道路
CPath * path2) //以m_serialNum2为顶点的另一条道路
{
m_bIsVisited = g_pDoc->nuaaWizard.GetVisitedTag();//是否已经被访问过
strcpy(m_name,name);
m_location1 = location1;
m_path1 = path1;
m_location2 = location2;
m_path2 = path2;
//计算道路长度
m_length = sqrt((m_location1.x - m_location2.x) * (m_location1.x - m_location2.x)
+ (m_location1.y - m_location2.y) * (m_location1.y - m_location2.y));
}
CPath::~CPath()
{
}
//////////////////////////////////////////////////////////////////////
// 操作函数
//////////////////////////////////////////////////////////////////////
BOOL CPath::GetIsVisited()
{
return m_bIsVisited;
}
void CPath::SetIsVisited()
{
m_bIsVisited = g_pDoc->nuaaWizard.GetVisitedTag();
}
CString CPath::GetName()
{
return m_name;
}
void CPath::SetName(CString name)
{
strcpy(m_name,name);
}
double CPath::GetLength()
{
return m_length;
}
void CPath::SetLength()
{
m_length = sqrt((m_location1.x - m_location2.x) * (m_location1.x - m_location2.x)
+ (m_location1.y - m_location2.y) * (m_location1.y - m_location2.y));
}
CPoint CPath::GetLocation1()
{
return m_location1;
}
void CPath::SetLocation1(CPoint location1)
{
m_location1 = location1;
}
CPath * CPath::GetPath1()
{
return m_path1;
}
void CPath::SetPath1(CPath *path1)
{
m_path1 = path1;
}
CPoint CPath::GetLocation2()
{
return m_location2;
}
void CPath::SetLocation2(CPoint location2)
{
m_location2 = location2;
}
CPath * CPath::GetPath2()
{
return m_path2;
}
void CPath::SetPath2(CPath *path2)
{
m_path2 = path2;
}
//////////////////////////////////////////////////////////////////////
//如果坐标到直线的距离小于等于DISTANCE,则认为已选中该直线
CPath* CPath::IsLocatedIn(CPoint point)
{
double num1 = abs((point.x-m_location2.x) * (m_location1.y-m_location2.y) - (point.y-m_location2.y) * (m_location1.x-m_location2.x));
double num2 = sqrt((m_location1.y-m_location2.y) * (m_location1.y-m_location2.y) + (m_location1.x-m_location2.x) * (m_location1.x-m_location2.x));
if(num1 / num2 <= DISTANCE)
{
CDC* pDC = g_pView->GetDC();
COLORREF color = RGB(255,0,0);//定义一个颜色变量
CPen pen(PS_INSIDEFRAME,2,color);
CPen* oldPen = pDC->SelectObject(&pen);
pDC->MoveTo(m_location1);
pDC->LineTo(m_location2);
pDC->SelectObject(oldPen);
g_pView->ReleaseDC(pDC);
return this;
}
return NULL;
}
//////////////////////////////////////////////////////////////////////
//绘制道路
void CPath::Draw(CDC *pDC)
{
COLORREF color = RGB(0,0,192);//定义一个颜色变量
CPen pen(PS_INSIDEFRAME,2,color);
CPen* oldPen = pDC->SelectObject(&pen);
pDC->MoveTo(m_location1);
pDC->LineTo(m_location2);
pDC->SelectObject(oldPen);
}
//////////////////////////////////////////////////////////////////////
//显示道路信息
void CPath::ShowInformation()
{
CString name = "道路名称: ";
name += m_name;
CString length;
length.Format("%f",m_length);
name += "\n道路长度: " + length + " 米";
AfxMessageBox(name);
}
//////////////////////////////////////////////////////////////////////
//显示对话框以输入新的信息
void CPath::Update()
{
CInsertPathDlg pathDlg;
if(IDOK == pathDlg.DoModal())
{
strcpy(m_name,pathDlg.m_name);
}
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -