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

📄 nearestdlg.cpp

📁 程序编写环境为Visual Studio.NET 2002
💻 CPP
字号:
// NearestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NameGis.h"
#include "NearestDlg.h"
#include "MainFrm.h"
#include "NameGisView.h"
#include "MapControlView.h"
#include "MapObjects2.h"
// CNearestDlg dialog

IMPLEMENT_DYNAMIC(CNearestDlg, CDialog)
CNearestDlg::CNearestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNearestDlg::IDD, pParent)
{
}

CNearestDlg::~CNearestDlg()
{
}

void CNearestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_NEARESTDLG_MAINFILTER, m_MainFilter);
	DDX_Control(pDX, IDC_NEARESTDLG_CHILDFILTER, m_ChildFilter);
	DDX_Control(pDX, IDC_NEARESTDLG_DISTANCE, m_DistFilter);
}


BEGIN_MESSAGE_MAP(CNearestDlg, CDialog)
	ON_CBN_SELCHANGE(IDC_NEARESTDLG_MAINFILTER, OnCbnSelchangeNearestdlgMainfilter)
	ON_BN_CLICKED(IDC_NEARESTDLG_POSITION, OnBnClickedNearestdlgPosition)
	ON_BN_CLICKED(IDC_NEARESTDLG_NAMECONDT, OnBnClickedNearestdlgNamecondt)
	ON_BN_CLICKED(IDC_NEARESTDLG_EXECUTEBTN, OnBnClickedNearestdlgExecutebtn)
	ON_EN_CHANGE(IDC_NEARESTDLG_NAMEEDT, OnEnChangeNearestdlgNameedt)
END_MESSAGE_MAP()


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

	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	//初始化大类过滤器	
	pMapView->LoadFilter(&m_MainFilter);
	//初始化中类过滤器
	pMapView->LoadFilter2(&m_ChildFilter, "(全部类型)", false);
	m_DistFilter.SetCurSel(0);

	((CButton*)GetDlgItem(IDC_NEARESTDLG_POSITION))->SetCheck(BST_CHECKED);
	GetDlgItem(IDC_NEARESTDLG_NAMEEDT)->EnableWindow(FALSE);	

	return TRUE; 
}
//----------------------------------------------------------------------------------------------
void CNearestDlg::OnCbnSelchangeNearestdlgMainfilter()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));

	CString szType;
	m_MainFilter.GetLBText(m_MainFilter.GetCurSel(), szType);
	pMapView->LoadFilter2(&m_ChildFilter, szType, false);
	m_ChildFilter.SetCurSel(0);
}
//----------------------------------------------------------------------------------------------
void CNearestDlg::OnBnClickedNearestdlgPosition()
{
	GetDlgItem(IDC_NEARESTDLG_NAMEEDT)->EnableWindow(FALSE);		
	GetDlgItem(IDC_NEARESTDLG_EXECUTEBTN)->EnableWindow(TRUE);
}
//----------------------------------------------------------------------------------------------
void CNearestDlg::OnBnClickedNearestdlgNamecondt()
{
	GetDlgItem(IDC_NEARESTDLG_NAMEEDT)->EnableWindow(TRUE);
	CString str;
	GetDlgItem(IDC_NEARESTDLG_NAMEEDT)->GetWindowText(str);
	if(str == "")
		GetDlgItem(IDC_NEARESTDLG_EXECUTEBTN)->EnableWindow(FALSE);
	else
		GetDlgItem(IDC_NEARESTDLG_EXECUTEBTN)->EnableWindow(TRUE);
}
//----------------------------------------------------------------------------------------------
void CNearestDlg::OnBnClickedNearestdlgExecutebtn()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	CMapControlView* pCtrlView = (CMapControlView*)(pMainWnd->m_wndSplitter2.GetPane(0,0));

	CEnvironment* pEnv = &(pMainWnd->m_environment);
	switch(m_DistFilter.GetCurSel())
	{
	case 0:
		pEnv->m_dDistance = 0;
		break;
	case 1:
		pEnv->m_dDistance = 10.0;
		break;
	case 2:
		pEnv->m_dDistance = 20.0;
		break;
	case 3:
		pEnv->m_dDistance = 50.0;
		break;
	case 4:
		pEnv->m_dDistance = 100.0;
		break;
	case 5:
		pEnv->m_dDistance = 200.0;
		break;
	case 6:
		pEnv->m_dDistance = 500.0;
		break;
	case 7:
		pEnv->m_dDistance = 1000.0;
		break;
	default:
		pEnv->m_dDistance = 0.0;
		break;
	}

	CString szType;
	m_MainFilter.GetLBText(m_MainFilter.GetCurSel(), szType);
	CString szSubType;
	m_ChildFilter.GetLBText(m_ChildFilter.GetCurSel(), szSubType);  
	
	if (szSubType == "(全部子类型)")
	{
		if(szType == "(全部类型)")
		{
			for (int i = 0; i <pEnv->m_nLayerNum; i ++)
			{
				if (pEnv->m_layerInfos[i].bCanSelected)  
					pEnv->m_layerInfos[i].bSelected = true;
				else
					pEnv->m_layerInfos[i].bSelected = true;
			}
		}
		else
		{
			for (int i = 0; i < pEnv->m_nLayerNum; i ++)
			{
				if ( pEnv->m_layerInfos[i].szType == szType 
					&& pEnv->m_layerInfos[i].bCanSelected)   
					pEnv->m_layerInfos[i].bSelected = true; 
				else
					pEnv->m_layerInfos[i].bSelected = false;
			}
		}
	}
	else
	{
		for (int i = 0; i < pEnv->m_nLayerNum; i ++)
		{
			if (pEnv->m_layerInfos[i].szSubType == szSubType
				&& pEnv->m_layerInfos[i].bCanSelected)   
				pEnv->m_layerInfos[i].bSelected = true; 
			else
				pEnv->m_layerInfos[i].bSelected = false;
		}
	}

	if (((CButton*)GetDlgItem(IDC_NEARESTDLG_POSITION))->GetCheck())// 通过位置查找
	{
		pEnv->m_MapOpr = MO_SEACHBYDIST;
		pMapView->m_Map.SetMousePointer(moCross);
	}
	else	// 通过地名查找
	{ 
		CString strName;
		GetDlgItem(IDC_NEARESTDLG_NAMEEDT)->GetWindowText(strName);
		CString szTable = pEnv->GetTableName(strName, "地名索引");
		if ("" == szTable)
		{
			AfxMessageBox("属性库中无此地名!"); 
			return ;
		}

		pEnv->m_szPlaceName = strName;
		CString szLayer = pEnv->GetLayerName(strName, "地名索引");   
		
		int nIndex = pEnv->GetLayerIndexByName(szTable); 
		if (nIndex < 0)
			return;
        
		if (!pEnv->m_layerInfos[nIndex].bCanSelected)
			return;
        		
		CMoRecordset rs = pEnv->m_layerInfos[nIndex].layer.SearchExpression(
			                                     "名称='" + strName + "'"); 

		if (!rs)
		{
			AfxMessageBox("电子地图上没有这个地名!"); 
			return;
		}

		rs.MoveFirst();
 		if (rs.GetEof()) 
		{
			AfxMessageBox("电子地图上没有这个地名!"); 
			return;
		}

		CMoFields fields(rs.GetFields());
		CMoField  shapeField(fields.Item(COleVariant(TEXT("Shape"))));
		CMoPoint pt(shapeField.GetValue().pdispVal);		 		
		CWaitCursor waitCursor;
 
		long nCount = pEnv->SearchByDistance(pt.GetX(), pt.GetY(), 
			   pEnv->m_dDistance, &(pCtrlView->m_ResultListBox));
		pCtrlView->m_OperaTab.SetCurSel(2);
		pCtrlView->m_MapIndexTreeView.ModifyStyle(WS_VISIBLE, 0, 0);
		pCtrlView->m_LayerTreeView.ModifyStyle(WS_VISIBLE, 0, 0);
		pCtrlView->m_ResultListBox.ModifyStyle(0, WS_VISIBLE, 0);
		pCtrlView->m_ContentBtn.ModifyStyle(0, WS_VISIBLE, 0);
		pCtrlView->m_PositingBtn.ModifyStyle(0, WS_VISIBLE, 0);
		pCtrlView->Invalidate(TRUE);
					
		pEnv->m_MapOpr = MO_NULL;
		pMapView->m_Map.SetMousePointer(moArrow);
	}
}
//----------------------------------------------------------------------------------------------
void CNearestDlg::OnEnChangeNearestdlgNameedt()
{
	GetDlgItem(IDC_NEARESTDLG_EXECUTEBTN)->EnableWindow(TRUE);
}
//----------------------------------------------------------------------------------------------

⌨️ 快捷键说明

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