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

📄 snpathplanning.cpp

📁 基于超图sne开发的一个详细的例子。提供查询
💻 CPP
字号:
// SNPathPlanning.cpp: implementation of the SNPathPlanning class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Navigator.h"
#include "SNPathPlanning.h"

#include "Geometry/UGGeoText.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SNPathPlanning::SNPathPlanning()
{
	m_pDatasource = NULL;
	m_bPathInit = FALSE;
	m_arrPntStart.RemoveAll();
	m_arrPntEnd.RemoveAll();
}

SNPathPlanning::~SNPathPlanning()
{

}

void SNPathPlanning::SetDatasource( UGNdfDataSource* pDatasource )
{
	if (!pDatasource)
	{
		return;
	}
	
	m_pDatasource = pDatasource;	
}

void SNPathPlanning::AddDeparture(UGPoint2D pntStart)
{
	m_arrPntStart.Add(pntStart);
}

void SNPathPlanning::AddDestination(UGPoint2D pntEnd)
{
	m_arrPntEnd.Add(pntEnd);
}

UGbool SNPathPlanning::Init()
{
	if ( !m_bPathInit )
	{
		// 定义路径规划初始化参数
		UGSearchParam searchParam(m_pDatasource);		
		// 设置路径搜索策略为快速搜索
		searchParam.m_emSearchStrategy = UGSearchParam::SearchStrategy::Quick;
		// 初始化路径规划引擎
		UGbool bInit = m_routeAnalyst.Init(searchParam);
		
		if (!bInit)
		{
			MessageBox(NULL, TEXT("Fail to initialize route analyst engine!"), NULL, MB_OK);
			return FALSE;
		}		
		m_bPathInit= TRUE;		
	}
	
	// 设置路径规划的起点	
	int iStartPointCount = m_arrPntStart.GetSize();	
	if (iStartPointCount>0)
	{
		m_routeAnalyst.SetStartPoint(m_arrPntStart);
	}	
	else
	{
		MessageBox(NULL, TEXT("No Departure!"), NULL, MB_OK);
		return FALSE;
	}
	
	// 设置路径规划的终点
	int iEndPointCount = m_arrPntEnd.GetSize();
	if ( iEndPointCount>0 )
	{
		m_routeAnalyst.SetEndPoint(m_arrPntEnd);
	}
	else
	{
		MessageBox(NULL, TEXT("No Destination!"), NULL, MB_OK);
		return FALSE;
	}
	
	// 不进行道路规避
	m_searchInput.m_bIsAvoid = FALSE;
	// 设置路径搜索模式为距离最短
	m_searchInput.m_emSearchMode = UGSearchInput::SearchMode::MinLength;	
	// 设置道路还原模式为精细还原
	m_searchInput.m_emRecoveryMode = UGSearchInput::RecoveryMode::Detailed;

	return TRUE;
}

UGbool SNPathPlanning::pathPlanning()
{
	// 执行路径搜索
	UGbool bSearch = m_routeAnalyst.Search(m_searchInput, m_searchOutput);
	return bSearch;
}

void SNPathPlanning::OnDrawRoute(UGMapWnd* pMapWnd)
{
	if (!pMapWnd)
	{
		return;
	}
	
	UGRect2D rcBound = pMapWnd->GetBounds();
	// 设置跟踪层的地理范围
	pMapWnd->m_Map.m_TrackingLayer.SetBound(rcBound);
	
	//////////////////////////////////////////////////////////////////////////
	// 跟踪层上绘制起始/终止端线
	//设置线的风格
	UGStyle lineStyle;
	// 设置线宽
	lineStyle.SetLineWidth(2.0);
	// 设置线的颜色
	lineStyle.SetLineColor(RGB(0, 255, 128));
	// 设置线对象的显示风格
	m_searchOutput.m_BgnLine.SetStyle(&lineStyle);
	m_searchOutput.m_EndLine.SetStyle(&lineStyle);
	
	
	// 添加几何对象到跟踪层
	pMapWnd->m_Map.m_TrackingLayer.AddEvent(&m_searchOutput.m_BgnLine, "BG_LINE");
	pMapWnd->m_Map.m_TrackingLayer.AddEvent(&m_searchOutput.m_EndLine, "END_LINE");
	//////////////////////////////////////////////////////////////////////////
	
	pMapWnd->m_Map.m_TrackingLayer.SetFixedStyle(FALSE);
	
	pMapWnd->m_Map.m_TrackingLayer.Refresh();

	return;
}


void SNPathPlanning::HightLightRoute(UGMapWnd* pMapWnd)
{
	if (!pMapWnd)
	{
		return;
	}
	// 清空选择集
	pMapWnd->m_Map.m_Selection.RemoveAll();
	
	Path* pPath;
	UGint iPathCount;	
	UEPathElem* pPathElement;
	UGint iPathElement;
	
	// 获取路径规划结果的显示信息
	m_searchOutput.GetDisplayInfo(pPath, iPathCount, pPathElement, iPathElement);
	
	// 计算所有子线的范围
	UGRect2D rect2d = pPath[0].rtBound;
	for (int i=1; i<iPathCount; i++)
	{
		UGRect2D rect = pPath[i].rtBound;
		rect2d.Union(rect);
	}
	
	if (!rect2d.IsNull())
	{
		// 获取选择集的查询定义
		UGQueryDef queryDef = pMapWnd->m_Map.m_Selection.GetQueryDef();
		// 清空原有设置
		queryDef.m_arPth.RemoveAll();
		queryDef.m_arPathElem.RemoveAll();
		
		// 设置查询范围
		queryDef.m_rc2Bounds = rect2d;
		// 重新赋值
		queryDef.m_arPth.Append(pPath, iPathCount);
		queryDef.m_arPathElem.Append(pPathElement,iPathElement);
		
		// 设置选择集的查询定义
		pMapWnd->m_Map.m_Selection.SetQueryDef(queryDef);
		
		// 设置地图的显示范围,使规划路径满屏显示
		pMapWnd->SetViewBounds(rect2d);		
		// 刷新地图
		pMapWnd->Refresh();
	}	
	return;
}

void SNPathPlanning::OnClean(UGMapWnd* pMapWnd)
{
	if (!pMapWnd)
	{
		return;
	}	
	// 清空跟踪层
	pMapWnd->m_Map.m_TrackingLayer.Clean();

	// 清空选择集
	// 获取选择集的查询定义
	UGQueryDef queryDef = pMapWnd->m_Map.m_Selection.GetQueryDef();
	// 清空查询对象设置
	queryDef.m_arPth.RemoveAll();
	queryDef.m_arPathElem.RemoveAll();
	pMapWnd->m_Map.m_Selection.SetQueryDef(queryDef);
	
	// 清空选择集显示子线序列的内存
	pMapWnd->m_Map.m_Selection.ClearPathMemory();

	// 清空起点、终点数组
	m_arrPntStart.RemoveAll();
	m_arrPntEnd.RemoveAll();

	// 刷新地图
	pMapWnd->Refresh();
	return;
}

⌨️ 快捷键说明

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