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

📄 whatsnearbyframe.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/* *  Roadnav *  WhatsNearBy.cpp * *  Copyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net> * *  This program is free software; you can redistribute it and/or *  modify it under the terms of version 2 of the GNU General Public License *  as published by the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *////////////////////////////////////////////////////////////////////////////////// \file////// The what's nearby miniframe shows a list of landmarks that are near the/// current coordinates./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include <wx/wx.h>#include <wx/minifram.h>#include "libroadnav/MapControl.h"#include "WhatsNearByFrame.h"#include "libroadnav/MapRepresentations.h"#include "libroadnav/MapSupport.h"#include "libroadnav/Map.h"#include "Frame.h"#include <vector>using namespace std;//////////////////////////////////////////////////////////////////////////////////// button IDs/////////////////////////////////////////////////////////////////////////////////enum{	idListCtrl};BEGIN_EVENT_TABLE(WhatsNearByFrame, wxFrame)	EVT_LIST_ITEM_ACTIVATED(idListCtrl, WhatsNearByFrame::OnListDoubleClick)	EVT_CLOSE(WhatsNearByFrame::OnClose)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief WhatsNearByFrame constructor - Creates the various controls in /// the dialog box/////////////////////////////////////////////////////////////////////////////////WhatsNearByFrame::WhatsNearByFrame(MapFrame *parent, wxWindowID id, IMapControlData * pcMapControlData)             : wxFrame(parent, 					id, 					wxString(wxT("What's Nearby")),					wxDefaultPosition,					wxDefaultSize,					wxDEFAULT_FRAME_STYLE			 ){	wxBoxSizer * psizerWnd;		//////////////////////////////////////////////////////////////////////////	// Initialize variables	//////////////////////////////////////////////////////////////////////////		m_fMaxDistance = 10;	m_pfrmMap = parent;	m_pcMapControlData = pcMapControlData;	//////////////////////////////////////////////////////////////////////////	// Sizers	//////////////////////////////////////////////////////////////////////////	psizerWnd = new wxBoxSizer(wxVERTICAL);		//////////////////////////////////////////////////////////////////////////	// List control containing what's nearby 	//////////////////////////////////////////////////////////////////////////		m_pctlList = new wxListCtrl(									this, 								idListCtrl, 								wxDefaultPosition, 								wxSize(400, 200),								wxLC_REPORT	);		psizerWnd->Add(		m_pctlList,		1,		wxALL | wxGROW,		10	);		//////////////////////////////////////////////////////////////////////////	// Set up the sizer	//////////////////////////////////////////////////////////////////////////	//psizerWnd->Fit(this);	SetSizer(psizerWnd);	Layout();	psizerWnd->SetSizeHints(this);}//////////////////////////////////////////////////////////////////////////////////// \brief WhatsNearByFrame destructor - delete map control data/////////////////////////////////////////////////////////////////////////////////WhatsNearByFrame::~WhatsNearByFrame(){	delete m_pcMapControlData;}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetBackgroundColour calls down to m_pctlList/////////////////////////////////////////////////////////////////////////////////bool WhatsNearByFrame::SetBackgroundColour(const wxColour& colour){	m_pctlList->SetBackgroundColour(colour);	return wxFrame::SetBackgroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetForegroundColour calls down to m_pctlList/////////////////////////////////////////////////////////////////////////////////bool WhatsNearByFrame::SetForegroundColour(const wxColour& colour){	m_pctlList->SetForegroundColour(colour);	return wxFrame::SetForegroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetFont calls down to m_pctlList/////////////////////////////////////////////////////////////////////////////////bool WhatsNearByFrame::SetFont(const wxFont& font){	m_pctlList->SetFont(font);	return wxFrame::SetFont(font);}//////////////////////////////////////////////////////////////////////////////////// \brief Set the text in the specified row + col/////////////////////////////////////////////////////////////////////////////////void WhatsNearByFrame::SetItemText(int iRow, int iCol, wxString strText){	wxListItem liNew;		liNew.SetId(iRow);	liNew.SetColumn(iCol);	liNew.SetText(strText);	liNew.SetMask(wxLIST_MASK_TEXT);		while (m_pctlList->GetItemCount() <= iRow)		m_pctlList->InsertItem(m_pctlList->GetItemCount(), wxT(""));		m_pctlList->SetItem(liNew);}//////////////////////////////////////////////////////////////////////////////////// \brief Changes the center coordinates/////////////////////////////////////////////////////////////////////////////////void WhatsNearByFrame::SetCenter(Point ptCenter){	bool bVisibility[LAST_RECORD_TYPE + 1];	int iRT;	double fRadius = 0.1;	if (ptCenter == m_ptCenter)		return;	m_ptCenter = ptCenter;	// mark everything invisible, except landmarks	for (iRT = FIRST_RECORD_TYPE; iRT <= LAST_RECORD_TYPE; iRT++)		bVisibility[iRT] = (iRT == RecordTypeLandmark);	m_pcMapControlData->LoadRegion(m_ptCenter - Point(fRadius, fRadius), m_ptCenter + Point(fRadius, fRadius), bVisibility);	UpdateList();}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the center coordinates/////////////////////////////////////////////////////////////////////////////////Point WhatsNearByFrame::GetCenter(){	return m_ptCenter;}//////////////////////////////////////////////////////////////////////////////////// \brief Callback function used in sorting the list control items/////////////////////////////////////////////////////////////////////////////////int wxCALLBACK cmpfncSortByDistance(long item1, long item2, long sortData){	WhatsNearByFrame * pfrmWhatsNearBy = (WhatsNearByFrame *) sortData;	double fDistance1;	double fDistance2;		fDistance1 = Distance(pfrmWhatsNearBy->GetCenter(), pfrmWhatsNearBy->GetMapControlData()->GetRecord(item1)->psCoordinates[0]);	fDistance2 = Distance(pfrmWhatsNearBy->GetCenter(), pfrmWhatsNearBy->GetMapControlData()->GetRecord(item2)->psCoordinates[0]);		if (fDistance1 > fDistance2)		return 1;	if (fDistance1 < fDistance2)		return -1;			return 0;}//////////////////////////////////////////////////////////////////////////////////// \brief Update the what's nearby list/////////////////////////////////////////////////////////////////////////////////void WhatsNearByFrame::UpdateList(){	int iRec;		m_pctlList->ClearAll();	m_pctlList->InsertColumn(0, wxT("Dist"));	m_pctlList->InsertColumn(1, wxT("Name"));		for (iRec = 0; iRec < m_pcMapControlData->Count(); iRec++)	{		IMapControlDataEntry * psRec = m_pcMapControlData->GetRecord(iRec);				if (psRec->eType == RecordTypeLandmark)		{			double fDistance;						fDistance = Distance(m_ptCenter, psRec->psCoordinates[0]);						if (fDistance < m_fMaxDistance)			{				int iEntry = m_pctlList->GetItemCount();				SetItemText(iEntry, 0, FormatDistance(fDistance));				SetItemText(iEntry, 1, psRec->NameAndType());				m_pctlList->SetItemData(iEntry, iRec);			}		}	}	m_pctlList->SortItems(cmpfncSortByDistance, (long) this);	m_pctlList->SetColumnWidth(0, wxLIST_AUTOSIZE);	m_pctlList->SetColumnWidth(1, wxLIST_AUTOSIZE);}//////////////////////////////////////////////////////////////////////////////////// \brief User double clicked an item - notify parent/////////////////////////////////////////////////////////////////////////////////void WhatsNearByFrame::OnListDoubleClick(wxListEvent & event){	wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, GetId());	GetParent()->AddPendingEvent(ev);}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the g_cRecords record number of the focused item/////////////////////////////////////////////////////////////////////////////////Point WhatsNearByFrame::GetSelectedCoordinates(){	int iItem;	Point ptInvalid;	ptInvalid.SetInvalid();		iItem = m_pctlList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);		if (iItem >= 0)		return m_pcMapControlData->GetRecord(m_pctlList->GetItemData(iItem))->psCoordinates[0];	return ptInvalid;}//////////////////////////////////////////////////////////////////////////////////// \brief Program shutting down - close Whats Nearby window and save position+size/////////////////////////////////////////////////////////////////////////////////void WhatsNearByFrame::OnClose(wxCloseEvent& event){	Hide();	m_pfrmMap->OnWhatsNearByWindowHiding();}//////////////////////////////////////////////////////////////////////////////////// \brief Fetch the map control data associated with this window./////////////////////////////////////////////////////////////////////////////////IMapControlData * WhatsNearByFrame::GetMapControlData(){	return m_pcMapControlData;}

⌨️ 快捷键说明

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