Garmin Fleet Management Controller  2.19.0
CWaypointDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CWaypointDlg.cpp
5 *
6 * Copyright 2009-2012 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "CFmiApplication.h"
13 #include "CWaypointDlg.h"
14 #include "Event.h"
15 
16 IMPLEMENT_DYNAMIC( CWaypointDlg, CDialog )
17 
18 BEGIN_MESSAGE_MAP( CWaypointDlg, CDialog )
19  ON_BN_CLICKED( IDOK, OnBnClickedOk )
20  ON_BN_CLICKED( IDC_WPT_BTN_SEND, OnBnClickedWptBtnSend )
21  ON_EN_CHANGE( IDC_WPT_EDIT_WPT_ID, OnEnChangeWptEdit )
22  ON_EN_CHANGE( IDC_WPT_EDIT_WPT_NAME, OnEnChangeWptEdit )
23  ON_MESSAGE( WM_EVENT( EVENT_FMI_WAYPOINT_LIST_CHANGED ), OnWaypointListChanged )
24  ON_MESSAGE( WM_EVENT( EVENT_FMI_CATEGORY_LIST_CHANGED ), OnCategoryListChanged )
25  ON_BN_CLICKED( IDC_WPT_BTN_DELETE, OnBnClickedWptBtnDelete )
26  ON_BN_CLICKED( IDC_WPT_BTN_DELETE_CAT, OnBnClickedWptBtnDeleteCat )
27  ON_BN_CLICKED( IDC_WPT_BTN_CREATE_CAT, OnBnClickedWptBtnCreateCat )
28 END_MESSAGE_MAP()
29 
30 //----------------------------------------------------------------------
34 //----------------------------------------------------------------------
35 CWaypointDlg::CWaypointDlg
36  (
37  CWnd * aParent,
38  FmiApplicationLayer & aCom
39  )
40  : CDialog( IDD_WAYPOINT, aParent )
41  , mCom( aCom )
42  , mWptId( 0 )
43  , mLat( 0 )
44  , mLon( 0 )
45  , mSymbol( 0 )
46  , mCat( _T("") )
47  , mName( _T("") )
48  , mComment( _T("") )
49  , mCatId( 0 )
50 {
51 }
52 
53 //----------------------------------------------------------------------
55 //----------------------------------------------------------------------
57 {
58 }
59 
60 //----------------------------------------------------------------------
63 //----------------------------------------------------------------------
65  (
66  CDataExchange * aDataExchange
67  )
68 {
69  CDialog::DoDataExchange( aDataExchange );
70  DDX_Text( aDataExchange, IDC_WPT_EDIT_WPT_ID, mWptId );
71  DDX_Text( aDataExchange, IDC_WPT_EDIT_WPT_NAME, mName );
72  DDX_Text( aDataExchange, IDC_WPT_EDIT_CAT_NAME, mCat );
73  DDX_Text( aDataExchange, IDC_WPT_EDIT_CAT_ID, mCatId );
74  DDX_Text( aDataExchange, IDC_WPT_EDIT_LAT, mLat );
75  DDX_Text( aDataExchange, IDC_WPT_EDIT_LON, mLon );
76  DDX_Text( aDataExchange, IDC_WPT_EDIT_SYM_ID, mSymbol );
77  DDX_Text( aDataExchange, IDC_WPT_EDIT_WPT_COMMENT, mComment );
78  DDX_Control( aDataExchange, IDC_WPT_LST_WAYPOINTS, mListBox );
79  DDX_Control( aDataExchange, IDC_WPT_LST_CATEGORIES, mCatBox );
80 }
81 
82 //----------------------------------------------------------------------
85 //----------------------------------------------------------------------
87 {
88  CDialog::PostNcDestroy();
90 } /* PostNcDestroy() */
91 
92 //----------------------------------------------------------------------
98 //----------------------------------------------------------------------
100 {
101  CDialog::OnInitDialog();
102 
103  SetWindowPos( NULL, 700, 35, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
104 
105  updateCatBox();
106  updateListBox();
107 
108  GetDlgItem( IDC_WPT_BTN_SEND )->EnableWindow( FALSE );
109 
110  return TRUE;
111 } /* OnInitDialog() */
112 
113 //----------------------------------------------------------------------
115 //----------------------------------------------------------------------
117 {
118  CString temp;
119 
120  //must keep track of where the list was scrolled to
121  //since we reset content we must reinitialize these
122  int selectedIndex = mListBox.GetCurSel();
123  int topIndex = mListBox.GetTopIndex();
124 
125  //reset content and add current canned messages to list
126  mListBox.ResetContent();
128 
129  for( it = mCom.mWaypoints.begin();
130  it != mCom.mWaypoints.end();
131  it++ )
132  {
133  if( it->second.isValid() )
134  {
135  temp.Format( _T("%d - %s"), it->first, it->second.getCurrentName() );
136  mListBox.AddString( temp );
137  }
138  }
139  //reset scroll and selection
140  mListBox.SetCurSel( selectedIndex );
141  mListBox.SetTopIndex( topIndex );
142 } /* updateListBox() */
143 
144 //----------------------------------------------------------------------
146 //----------------------------------------------------------------------
148 {
149  CString temp;
150 
151  //must keep track of where the list was scrolled to
152  //since we reset content we must reinitialize these
153  int selectedIndex = mCatBox.GetCurSel();
154  int topIndex = mCatBox.GetTopIndex();
155 
156  //reset content and add current canned messages to list
157  mCatBox.ResetContent();
159 
160  for( it = mCom.mCategories.begin();
161  it != mCom.mCategories.end();
162  it++ )
163  {
164  if( it->second.isValid() )
165  {
166  temp.Format( _T("%d - %s"), it->first, it->second.getCurrentName() );
167  mCatBox.AddString( temp );
168  }
169  }
170  //reset scroll and selection
171  mCatBox.SetCurSel( selectedIndex );
172  mCatBox.SetTopIndex( topIndex );
173 }
174 
175 //----------------------------------------------------------------------
178 //----------------------------------------------------------------------
179 afx_msg LPARAM CWaypointDlg::OnWaypointListChanged( WPARAM, LPARAM )
180 {
181  updateListBox();
182  return 0;
183 }
184 
185 //----------------------------------------------------------------------
188 //----------------------------------------------------------------------
189 afx_msg LPARAM CWaypointDlg::OnCategoryListChanged( WPARAM, LPARAM )
190 {
191  updateCatBox();
192  return 0;
193 }
194 
195 //----------------------------------------------------------------------
202 //----------------------------------------------------------------------
204 {
205  uint16 selIds = 0;
206  int selList[16];
207  int count;
208  count = mCatBox.GetSelItems( 16, selList );
209 
210  for( int i = 0; i < count; ++i )
211  {
212  int selectedIndex = selList[i];
213  uint8 catId = (uint8) mCom.mCategories.getKeyAt( selectedIndex );
214  selIds |= setbit( catId );
215  }
216 
217  return selIds;
218 }
219 
220 // CWaypointDlg message handlers
221 
222 //----------------------------------------------------------------------
225 //----------------------------------------------------------------------
227 {
228  DestroyWindow();
229 }
230 
231 //----------------------------------------------------------------------
234 //----------------------------------------------------------------------
236 {
237  UpdateData( TRUE );
238 
240 }
241 
242 //----------------------------------------------------------------------
246 //----------------------------------------------------------------------
248 {
249  UpdateData( TRUE );
250  if( mName != "" )
251  {
252  GetDlgItem( IDC_WPT_BTN_SEND )->EnableWindow( TRUE );
253  }
254  else
255  {
256  GetDlgItem( IDC_WPT_BTN_SEND )->EnableWindow( FALSE );
257  }
258 }
259 
260 //----------------------------------------------------------------------
263 //----------------------------------------------------------------------
265 {
266  UpdateData( TRUE );
267  int selIdx = mListBox.GetCurSel();
268  if( selIdx >= 0 )
269  {
271  }
272 }
273 
274 //----------------------------------------------------------------------
277 //----------------------------------------------------------------------
279 {
280  UpdateData( TRUE );
281 
283 }
284 
285 //----------------------------------------------------------------------
288 //----------------------------------------------------------------------
290 {
291  UpdateData( TRUE );
293 }
CString mComment
Waypoint comment entered by the user.
Definition: CWaypointDlg.h:80
#define IDC_WPT_EDIT_WPT_ID
Definition: resource.h:357
CListBox mCatBox
List box containing waypoint categories sent to the client.
Definition: CWaypointDlg.h:86
#define IDC_WPT_BTN_SEND
Definition: resource.h:350
const_iterator begin()
Iterator positioned at the first element in the map.
Definition: FileBackedMap.h:59
UINT mWptId
Waypoint ID entered by the user.
Definition: CWaypointDlg.h:62
CString mCat
Waypoint category entered by the user.
Definition: CWaypointDlg.h:74
uint16 getCatIds()
Get category bit field value for the selected category IDs.
#define IDC_WPT_BTN_CREATE_CAT
Definition: resource.h:347
const_iterator end()
Iterator positioned after the last element in the map.
Definition: FileBackedMap.h:67
afx_msg void OnEnChangeWptEdit()
Edit handler for the waypoint edit boxes on this dialog.
#define IDD_WAYPOINT
Definition: resource.h:45
FmiApplicationLayer & mCom
Reference to the FMI communication controller.
Definition: CWaypointDlg.h:58
CString mName
Waypoint name entered by the user.
Definition: CWaypointDlg.h:77
#define FALSE
Definition: garmin_types.h:46
void sendCreateWaypointCat(uint8 aCatId, CString &aCatName)
Create waypoint category.
#define IDC_WPT_EDIT_CAT_ID
Definition: resource.h:351
afx_msg void OnBnClickedOk()
Handler for the OK button.
void sendWaypoint(uint16 aUniqueId, double aLat, double aLon, uint16 aSymbol, CString &aName, uint16 aCat, CString &aComment)
Send a waypoint.
#define IDC_WPT_BTN_DELETE_CAT
Definition: resource.h:349
#define TRUE
Definition: garmin_types.h:45
afx_msg LPARAM OnCategoryListChanged(WPARAM, LPARAM)
Handler for EVENT_FMI_CATEGORY_LIST_CHANGED event.
Modeless dialog allowing the user to manage waypoints.
Definition: CWaypointDlg.h:24
unsigned int mCatId
Waypoint category ID entered by the user.
Definition: CWaypointDlg.h:89
virtual ~CWaypointDlg()
Destructor.
#define setbit(_b)
A bit mask with one bit set and the rest cleared.
Definition: util_macros.h:30
#define IDC_WPT_EDIT_LAT
Definition: resource.h:353
afx_msg void OnBnClickedWptBtnDeleteCat()
Handler for the Delete Category button.
afx_msg LPARAM OnWaypointListChanged(WPARAM, LPARAM)
Handler for EVENT_FMI_WAYPOINT_LIST_CHANGED event.
UINT mSymbol
Waypoint symbol entered by the user.
Definition: CWaypointDlg.h:71
#define IDC_WPT_EDIT_SYM_ID
Definition: resource.h:355
Serial communication controller for Garmin and FMI packets.
#define IDC_WPT_EDIT_WPT_COMMENT
Definition: resource.h:356
#define IDC_WPT_LST_CATEGORIES
Definition: resource.h:369
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
void sendDeleteWaypointCat(uint16 aCatIdx)
Delete waypoint category.
void PostNcDestroy()
Perform final cleanup.
const key_type & getKeyAt(uint32 aIndex) const
Get the key for the item at a given list index.
afx_msg void OnBnClickedWptBtnCreateCat()
Handler for the Create Category button.
afx_msg void OnBnClickedWptBtnSend()
Handler for the Send Waypoint button.
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
FileBackedMap< ClientListItem > mCategories
Map of waypoint category IDs to names.
void sendDeleteWaypoint(uint16 aUniqueId)
Delete a waypoint.
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
CListBox mListBox
List box containing waypoints sent to the client.
Definition: CWaypointDlg.h:83
#define IDC_WPT_LST_WAYPOINTS
Definition: resource.h:370
#define IDC_WPT_EDIT_LON
Definition: resource.h:354
BOOL OnInitDialog()
Initialize the dialog.
void updateListBox()
Update the waypoint list box from the map owned by Com.
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
#define IDC_WPT_EDIT_CAT_NAME
Definition: resource.h:352
#define IDC_WPT_EDIT_WPT_NAME
Definition: resource.h:358
void updateCatBox()
Update the waypoint list box from the map owned by Com.
afx_msg void OnBnClickedWptBtnDelete()
Handler for the Delete Waypoint button.
double mLat
Waypoint latitude in decimal degrees.
Definition: CWaypointDlg.h:65
FileBackedMap< WaypointListItem > mWaypoints
Map of waypoint IDs to names.
static void post(EventId aEventId, uint32 aEventData=0, void *aEventDataPtr=NULL, BOOL handleNow=FALSE)
Posts a message to all windows that have registered to get events.
Definition: Event.cpp:67
#define IDC_WPT_BTN_DELETE
Definition: resource.h:348
double mLon
Waypoint longitude in decimal degrees.
Definition: CWaypointDlg.h:68