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

📄 busresultdlg.cpp

📁 北京市交通mo+visual c++开发实例
💻 CPP
字号:
// BusResultDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NameGis.h"
#include "BusResultDlg.h"
#include "Mainfrm.h"
#include "NameGisView.h"
#include "HawkView.h"
#include "AppApi.h"
#include "MoLine.h"

// CBusResultDlg dialog

IMPLEMENT_DYNAMIC(CBusResultDlg, CDialog)
CBusResultDlg::CBusResultDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBusResultDlg::IDD, pParent)
{
	m_array = NULL;
}

CBusResultDlg::~CBusResultDlg()
{
}

void CBusResultDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BUSRESULT_RESULTLIST, m_ResultList);
}


BEGIN_MESSAGE_MAP(CBusResultDlg, CDialog)
	ON_WM_SIZE()
	ON_LBN_DBLCLK(IDC_BUSRESULT_RESULTLIST, OnLbnDblclkBusresultResultlist)
END_MESSAGE_MAP()


// CBusResultDlg message handlers
//-----------------------------------------------------------------------------------------
BOOL CBusResultDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	char szCount[20];
	itoa(m_array->GetCount(), szCount, 10);
	GetDlgItem(IDC_BUSRESULT_LABLE)->SetWindowText(
		"总共查询到" + CString(szCount) + "种方案");
	LoadListBox();

	return TRUE;  
}
//-----------------------------------------------------------------------------------------
void CBusResultDlg::LoadListBox()
{
	m_ResultList.ResetContent();
	int index = 1; 
	POSITION pos = m_array->GetHeadPosition();
	for (int i = 0; i <m_array->GetCount(); i ++)
	{
		PathNode node;
		node = (PathNode)m_array->GetNext(pos);
		CString str;
		char szI[20];
		itoa(i, szI, 10);
		str = "第" + CString(szI) + "方案:";
        
		for (int j = 0; j < node.nSegNumber; j ++)
		{
			if (j > 0)
				str += ",转车,坐";
			else
				str +="坐";

			str += node.szRoutineName[j];
			str += "车,从";
			str += node.szFromStationName[j];
			str += "到";
			str += node.szToStationName[j]; 
		}		
        
		m_ResultList.AddString(str);
		index ++;
	}
}
//-----------------------------------------------------------------------------------------
void CBusResultDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);

	if(m_ResultList)
	{
		CRect* pLabelRect = new CRect();
		GetDlgItem(IDC_BUSRESULT_LABLE)->GetClientRect(pLabelRect);

		CRect* pRect = new CRect();
		m_ResultList.GetClientRect(pRect);
		m_ResultList.MoveWindow(pRect->left, pLabelRect->Height() + 4,
			                        cx, cy - pLabelRect->Height() - 4);
		delete pRect;
		pRect = NULL;
		delete pLabelRect;
		pLabelRect = NULL;
	}
}
//-----------------------------------------------------------------------------------------
void CBusResultDlg::OnLbnDblclkBusresultResultlist()
{
	int nIndex = m_ResultList.GetCurSel();
	if(nIndex < 0)
		return;
	
	PathNode node = m_array->GetAt(m_array->FindIndex(nIndex));
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	CHawkView* pHawkView = (CHawkView*)(pMainWnd->m_wndSplitter2.GetPane(1,0));
	pMainWnd->m_environment.m_drawLine = new MLine[node.nSegNumber]; 
    
	pMainWnd->m_environment.m_buses = new Buses();
	int nCount = 0;
	bool bBus = true;
    
	for (int j = 0; j<node.nSegNumber; j ++)
	{
		CMoLine moline = pMainWnd->m_environment.GetLine( node.szRoutineName[j]);
		if (!moline)
		{
			pMainWnd->m_environment.m_drawLine = NULL;
			pMainWnd->m_environment.m_buses = NULL;
            
			pMapView->m_Map.SetExtent(pMapView->m_Map.GetExtent()); 
			return;
		}
		
		CMoPoint pt;
		MPoint pt1, pt2;
        
		pt = pMainWnd->m_environment.GetPoint(node.szFromStationName[j]);
		if (!pt)
		{
			pMainWnd->m_environment.m_drawLine = NULL;
			pMainWnd->m_environment.m_buses = NULL;
			pMapView->m_Map.SetExtent(pMapView->m_Map.GetExtent()); 
			return;
		}
		
		pt1.x = pt.GetX();
		pt1.y = pt.GetY();
        
		pt = pMainWnd->m_environment.GetPoint(node.szToStationName[j]);
		if(!pt)
		{
			pMainWnd->m_environment.m_drawLine = NULL;
			pMainWnd->m_environment.m_buses = NULL;
			pMapView->m_Map.SetExtent(pMapView->m_Map.GetExtent()); 
			return;
		}
        
		pt2.x = pt.GetX();
		pt2.y = pt.GetY();
        
		MLine* line = pMainWnd->m_environment.CreateLine(moline);
		CutLine(*line, pt1, pt2, &(pMainWnd->m_environment.m_drawLine[j])); 
        
		if (bBus)
			bBus = pMainWnd->m_environment.GetStation(&node, j, 
			          pMainWnd->m_environment.m_buses, &nCount); 				
	}	
    
	if (!bBus)
		pMainWnd->m_environment.m_buses = NULL;
	else
		pMainWnd->m_environment.m_buses->nNum = nCount;  
    
	pMapView->m_Map.CenterAt(pMainWnd->m_environment.m_drawLine[0].pPoint[0].x, 
		pMainWnd->m_environment.m_drawLine[0].pPoint[0].y);	    
	pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent()); 
}
//-----------------------------------------------------------------------------------------

⌨️ 快捷键说明

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