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

📄 scpattrdlg.cpp

📁 这是书上的代码
💻 CPP
字号:
// ScpAttrDlg.cpp : implementation file
//

#include "stdafx.h"
#include "const.h"
#include "painted.h"
#include "paintobj.h"
#include "paintdoc.h"
#include "ScpAttrDlg.h"
#include "Nodeattr.h"
#include "ObstacleDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScpAttrDlg dialog


CScpAttrDlg::CScpAttrDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScpAttrDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScpAttrDlg)
	m_dAngle = 0.0;
	m_uEndId = 0;
	m_uId = 0;
	m_nGuide = -1;
	m_nHead = -1;
	m_dLimit = 0.0;
	m_uStartId = 0;
	//}}AFX_DATA_INIT
}


void CScpAttrDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScpAttrDlg)
	DDX_Text(pDX, IDC_ANGLE, m_dAngle);
	DDX_Text(pDX, IDC_ENDID, m_uEndId);
	DDX_Text(pDX, IDC_ID, m_uId);
	DDX_Radio(pDX, IDC_RADIO1, m_nGuide);
	DDX_Radio(pDX, IDC_RADIO4, m_nHead);
	DDX_Text(pDX, IDC_SPEEDLIMIT, m_dLimit);
	DDX_Text(pDX, IDC_STARTID, m_uStartId);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScpAttrDlg, CDialog)
	//{{AFX_MSG_MAP(CScpAttrDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScpAttrDlg message handlers

void CScpAttrDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
loop2:
	CPnt point1;
	CNodeattr  Nodeattr;	
			
	point1=m_pActive1->returnattr1();
	Nodeattr.m_fNodex=point1.x;
	Nodeattr.m_fNodey=point1.y;				
	Nodeattr.m_uNodeId=m_pActive1->m_uStartNodeId;
	UINT id=m_pActive1->m_uStartNodeId;
	Nodeattr.m_fHeading=m_pActive1->m_fStartHeading;
	UINT type=m_pActive1->m_uStartNodeType;				
	if(type&0x01) Nodeattr.m_bCheck1=TRUE;
	if(type&0x02) Nodeattr.m_bCheck2=TRUE;
	if(type&0x04) Nodeattr.m_bCheck3=TRUE;
	if(type&0x08) Nodeattr.m_bCheck4=TRUE;				
	int result=Nodeattr.DoModal();				
	if(result==IDOK)
	{	
		//如果更改了节点号,不能与某存在的节点号相同
		//必须定义新的节点号
		CPainted*	pPainter;
		if(id!=Nodeattr.m_uNodeId)
		{
			BOOL breturn=FALSE;
			int nShapes = m_pDoc->NumShapes();
			for (int index = 0; index < nShapes; index++)
			{
				pPainter =m_pDoc->GetShape(index);
				if(pPainter->m_uStartNodeId==Nodeattr.m_uNodeId||pPainter->m_uEndNodeId==Nodeattr.m_uNodeId)
				{
					CString str="更改后的节点号不能与某存在的节点号相同,必须重新定义新的节点号!";
					AfxMessageBox(str);
					breturn=TRUE;
					break;
				}
			}
			if(breturn)	{goto loop2;}
		}
		//节点编号更改了以后,应与m_uCurNodeIdMax
		//比较,大则要更新m_uCurNodeIdMax
		int nShapes = m_pDoc->NumShapes();
		for (int index = 0; index < nShapes; index++)
		{
			pPainter =m_pDoc->GetShape(index);
			if(pPainter->m_uStartNodeId==id)
			{ 
				pPainter->m_uStartNodeId=Nodeattr.m_uNodeId;
				pPainter->m_fStartHeading=Nodeattr.m_fHeading;					
				type=0;
				if(Nodeattr.m_bCheck1) type|=0x01;
				if(Nodeattr.m_bCheck2) type|=0x02;
				if(Nodeattr.m_bCheck3) type|=0x04;
				if(Nodeattr.m_bCheck4) type|=0x08;
				pPainter->m_uStartNodeType=type;							
			}
			else if(pPainter->m_uEndNodeId==id)
			{
				pPainter->m_uEndNodeId=Nodeattr.m_uNodeId;
				pPainter->m_fEndHeading=Nodeattr.m_fHeading;					
				type=0;
				if(Nodeattr.m_bCheck1) type|=0x01;
				if(Nodeattr.m_bCheck2) type|=0x02;
				if(Nodeattr.m_bCheck3) type|=0x04;
				if(Nodeattr.m_bCheck4) type|=0x08;
				pPainter->m_uEndNodeType=type;
			}
		}
		m_pDoc->GetNodeIdMax();//更新m_uCurNodeIdMax
	}
	m_uStartId=Nodeattr.m_uNodeId;
	UpdateData(FALSE);
}

void CScpAttrDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
loop3:
	CPnt point1;
	CNodeattr  Nodeattr;	
			
	point1=m_pActive1->returnattr2();
	Nodeattr.m_fNodex=point1.x;
	Nodeattr.m_fNodey=point1.y;				
	Nodeattr.m_uNodeId=m_pActive1->m_uEndNodeId;
	UINT id=m_pActive1->m_uEndNodeId;
	Nodeattr.m_fHeading=m_pActive1->m_fEndHeading;
	UINT type=m_pActive1->m_uEndNodeType;				
	if(type&0x01) Nodeattr.m_bCheck1=TRUE;
	if(type&0x02) Nodeattr.m_bCheck2=TRUE;
	if(type&0x04) Nodeattr.m_bCheck3=TRUE;
	if(type&0x08) Nodeattr.m_bCheck4=TRUE;				
	int result=Nodeattr.DoModal();				
	if(result==IDOK)
	{	
		//如果更改了节点号,不能与某存在的节点号相同
		//必须定义新的节点号
		CPainted*	pPainter;
		if(id!=Nodeattr.m_uNodeId)
		{
			BOOL breturn=FALSE;
			int nShapes = m_pDoc->NumShapes();
			for (int index = 0; index < nShapes; index++)
			{
				pPainter =m_pDoc->GetShape(index);
				if(pPainter->m_uStartNodeId==Nodeattr.m_uNodeId||pPainter->m_uEndNodeId==Nodeattr.m_uNodeId)
				{
					CString str="更改后的节点号不能与某存在的节点号相同,必须重新定义新的节点号!";
					AfxMessageBox(str);
					breturn=TRUE;
					break;
				}
			}
			if(breturn)	{goto loop3;}
		}
		//节点编号更改了以后,应与m_uCurNodeIdMax
		//比较,大则要更新m_uCurNodeIdMax
		int nShapes = m_pDoc->NumShapes();
		for (int index = 0; index < nShapes; index++)
		{
			pPainter =m_pDoc->GetShape(index);
			if(pPainter->m_uStartNodeId==id)
			{ 
				pPainter->m_uStartNodeId=Nodeattr.m_uNodeId;
				pPainter->m_fStartHeading=Nodeattr.m_fHeading;					
				type=0;
				if(Nodeattr.m_bCheck1) type|=0x01;
				if(Nodeattr.m_bCheck2) type|=0x02;
				if(Nodeattr.m_bCheck3) type|=0x04;
				if(Nodeattr.m_bCheck4) type|=0x08;
				pPainter->m_uStartNodeType=type;							
			}
			else if(pPainter->m_uEndNodeId==id)
			{
				pPainter->m_uEndNodeId=Nodeattr.m_uNodeId;
				pPainter->m_fEndHeading=Nodeattr.m_fHeading;					
				type=0;
				if(Nodeattr.m_bCheck1) type|=0x01;
				if(Nodeattr.m_bCheck2) type|=0x02;
				if(Nodeattr.m_bCheck3) type|=0x04;
				if(Nodeattr.m_bCheck4) type|=0x08;
				pPainter->m_uEndNodeType=type;
			}
		}
		m_pDoc->GetNodeIdMax();//更新m_uCurNodeIdMax
	}
	m_uEndId=Nodeattr.m_uNodeId;
	UpdateData(FALSE);
}

void CScpAttrDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	CObstacleDlg ObsDlg;
	UINT ObsMode;
	ObsMode=m_pActive1->m_uPathObstacle;
	ObsDlg.m_nObstMode=ObsMode;
	int result=ObsDlg.DoModal();				
	if(result==IDOK)
	{
		m_pActive1->m_uPathObstacle=ObsDlg.m_nObstMode;
	}
}

⌨️ 快捷键说明

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