1 /***************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Copyright (C) 2013 by David S. Register *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 **************************************************************************/
23
24 #ifdef __MINGW32__
25 #undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
26 #include <windows.h>
27 #endif
28
29 #include <wx/tokenzr.h>
30 #include <wx/intl.h>
31
32 #include <wx/statline.h>
33 #include "ConnectionParams.h"
34
35 #include "ocpn_plugin.h"
36 #include "chart1.h"
37 #include "options.h"
38
39 #if !wxUSE_XLOCALE && wxCHECK_VERSION(3,0,0)
40 #define wxAtoi(arg) atoi(arg)
41 #endif
42
43
ConnectionParams(const wxString & configStr)44 ConnectionParams::ConnectionParams(const wxString &configStr )
45 {
46 m_optionsPanel = NULL;
47 Deserialize( configStr );
48 }
49
Deserialize(const wxString & configStr)50 void ConnectionParams::Deserialize(const wxString &configStr)
51 {
52 Valid = true;
53 wxArrayString prms = wxStringTokenize( configStr, _T(";") );
54 if (prms.Count() < 18) {
55 Valid = false;
56 return;
57 }
58
59 Type = (ConnectionType)wxAtoi(prms[0]);
60 NetProtocol = (NetworkProtocol)wxAtoi(prms[1]);
61 NetworkAddress = prms[2];
62 NetworkPort = (ConnectionType)wxAtoi(prms[3]);
63 Protocol = (DataProtocol)wxAtoi(prms[4]);
64 Port = prms[5];
65 Baudrate = wxAtoi(prms[6]);
66 ChecksumCheck = !!wxAtoi(prms[7]);
67 int iotval = wxAtoi(prms[8]);
68 IOSelect=((iotval <= 2)?static_cast <dsPortType>(iotval):DS_TYPE_INPUT);
69 InputSentenceListType = (ListType)wxAtoi(prms[9]);
70 InputSentenceList = wxStringTokenize(prms[10], _T(","));
71 OutputSentenceListType = (ListType)wxAtoi(prms[11]);
72 OutputSentenceList = wxStringTokenize(prms[12], _T(","));
73 Priority = wxAtoi(prms[13]);
74 Garmin = !!wxAtoi(prms[14]);
75 GarminUpload = !!wxAtoi(prms[15]);
76 FurunoGP3X = !!wxAtoi(prms[16]);
77
78 bEnabled = true;
79 LastNetworkPort = 0;
80 b_IsSetup = false;
81 if (prms.Count() >= 18){
82 bEnabled = !!wxAtoi(prms[17]);
83 }
84 if (prms.Count() >= 19){
85 UserComment = prms[18];
86 }
87 if (prms.Count() >= 20){
88 AutoSKDiscover = !!wxAtoi(prms[19]);
89 }
90
91 }
92
Serialize() const93 wxString ConnectionParams::Serialize() const
94 {
95 wxString istcs;
96 for( size_t i = 0; i < InputSentenceList.Count(); i++ )
97 {
98 if (i > 0)
99 istcs.Append( _T(",") );
100 istcs.Append( InputSentenceList[i] );
101 }
102 wxString ostcs;
103 for( size_t i = 0; i < OutputSentenceList.Count(); i++ )
104 {
105 if (i > 0)
106 ostcs.Append( _T(",") );
107 ostcs.Append( OutputSentenceList[i] );
108 }
109 wxString ret = wxString::Format( _T("%d;%d;%s;%d;%d;%s;%d;%d;%d;%d;%s;%d;%s;%d;%d;%d;%d;%d;%s;%d"),
110 Type,
111 NetProtocol,
112 NetworkAddress.c_str(),
113 NetworkPort,
114 Protocol,
115 Port.c_str(),
116 Baudrate,
117 ChecksumCheck,
118 IOSelect,
119 InputSentenceListType,
120 istcs.c_str(),
121 OutputSentenceListType,
122 ostcs.c_str(),
123 Priority,
124 Garmin,
125 GarminUpload,
126 FurunoGP3X,
127 bEnabled,
128 UserComment.c_str(),
129 AutoSKDiscover
130 );
131
132 return ret;
133 }
134
ConnectionParams()135 ConnectionParams::ConnectionParams()
136 {
137 Type = SERIAL;
138 NetProtocol = TCP;
139 NetworkAddress = wxEmptyString;
140 NetworkPort = 0;
141 Protocol = PROTO_NMEA0183;
142 Port = wxEmptyString;
143 Baudrate = 4800;
144 ChecksumCheck = true;
145 Garmin = false;
146 FurunoGP3X = false;
147 IOSelect = DS_TYPE_INPUT;
148 InputSentenceListType = WHITELIST;
149 OutputSentenceListType = WHITELIST;
150 Priority = 0;
151 Valid = true;
152 bEnabled = true;
153 b_IsSetup = false;
154 m_optionsPanel = NULL;
155 AutoSKDiscover = false;
156 }
157
~ConnectionParams()158 ConnectionParams::~ConnectionParams()
159 {
160 //delete m_optionsPanel;
161 }
162
GetSourceTypeStr() const163 wxString ConnectionParams::GetSourceTypeStr() const
164 {
165 switch(Type) {
166 case SERIAL:
167 return _("Serial");
168 case NETWORK:
169 return _("Network");
170 case INTERNAL_GPS:
171 return _("GPS");
172 case INTERNAL_BT:
173 return _("BT");
174 default:
175 return _T("");
176 }
177 }
178
GetAddressStr() const179 wxString ConnectionParams::GetAddressStr() const
180 {
181 if ( Type == SERIAL )
182 return wxString::Format( _T("%s"), Port.c_str() );
183 else if ( Type == NETWORK )
184 return wxString::Format( _T("%s:%d"), NetworkAddress.c_str(), NetworkPort );
185 else if ( Type == INTERNAL_GPS )
186 return _("Internal");
187 else if ( Type == INTERNAL_BT )
188 return NetworkAddress;
189 else
190 return _T("");
191 }
192
193 // TODO: Make part of NetworkProtocol interface
NetworkProtocolToString(NetworkProtocol NetProtocol)194 static wxString NetworkProtocolToString(NetworkProtocol NetProtocol)
195 {
196 switch(NetProtocol) {
197 case TCP:
198 return _("TCP");
199 case UDP:
200 return _("UDP");
201 case GPSD:
202 return _("GPSD");
203 case SIGNALK:
204 return _("Signal K");
205 default:
206 return _("Undefined");
207 }
208 }
209
GetParametersStr() const210 wxString ConnectionParams::GetParametersStr() const
211 {
212 switch( Type ) {
213 case SERIAL:
214 return wxString::Format( _T("%d"), Baudrate );
215 case NETWORK:
216 return NetworkProtocolToString(NetProtocol);
217 case INTERNAL_GPS:
218 return _T("GPS");
219 case INTERNAL_BT:
220 return Port;
221 default:
222 return _T("");
223 }
224 }
225
GetIOTypeValueStr() const226 wxString ConnectionParams::GetIOTypeValueStr() const
227 {
228 if ( IOSelect == DS_TYPE_INPUT )
229 return _("Input");
230 else if ( IOSelect == DS_TYPE_OUTPUT )
231 return _("Output");
232 else
233 return _("In/Out");
234 }
235
FilterTypeToStr(ListType type,FilterDirection dir) const236 wxString ConnectionParams::FilterTypeToStr(ListType type, FilterDirection dir) const
237 {
238 if(dir == FILTER_INPUT) {
239 if ( type == BLACKLIST )
240 return _("Reject");
241 else
242 return _("Accept");
243 }
244 else {
245 if ( type == BLACKLIST )
246 return _("Drop");
247 else
248 return _("Send");
249 }
250 }
251
GetFiltersStr() const252 wxString ConnectionParams::GetFiltersStr() const
253 {
254 wxString istcs;
255 for( size_t i = 0; i < InputSentenceList.Count(); i++ )
256 {
257 if ( i > 0 )
258 istcs.Append( _T(",") );
259 istcs.Append( InputSentenceList[i] );
260 }
261 wxString ostcs;
262 for( size_t i = 0; i < OutputSentenceList.Count(); i++ )
263 {
264 if ( i > 0 )
265 ostcs.Append( _T(",") );
266 ostcs.Append( OutputSentenceList[i] );
267 }
268 wxString ret = wxEmptyString;
269 if ( istcs.Len() > 0 ){
270 ret.Append( _("In") );
271 ret.Append(wxString::Format( _T(": %s %s"),
272 FilterTypeToStr(InputSentenceListType, FILTER_INPUT).c_str(), istcs.c_str()) );
273 }
274 else
275 ret.Append( _("In: None") );
276
277 if ( ostcs.Len() > 0 ){
278 ret.Append( _T(", ") );
279 ret.Append( _("Out") );
280 ret.Append( wxString::Format( _T(": %s %s"),
281 FilterTypeToStr(OutputSentenceListType, FILTER_OUTPUT).c_str(), ostcs.c_str() ) );
282 }
283 else
284 ret.Append( _(", Out: None") );
285 return ret;
286 }
287
GetDSPort() const288 wxString ConnectionParams::GetDSPort() const
289 {
290 if ( Type == SERIAL )
291 return wxString::Format( _T("Serial:%s"), Port.c_str() );
292 else if( Type == NETWORK){
293 wxString proto = NetworkProtocolToString(NetProtocol);
294 return wxString::Format( _T("%s:%s:%d"), proto.c_str(), NetworkAddress.c_str(), NetworkPort );
295 }
296 else if( Type == INTERNAL_BT ){
297 return Port; //mac
298 }
299 else
300 return _T("");
301
302 }
303
GetLastDSPort() const304 wxString ConnectionParams::GetLastDSPort() const
305 {
306 if ( Type == SERIAL )
307 return wxString::Format( _T("Serial:%s"), Port.c_str() );
308 else
309 {
310 wxString proto = NetworkProtocolToString(LastNetProtocol);
311 return wxString::Format( _T("%s:%s:%d"), proto.c_str(), LastNetworkAddress.c_str(), LastNetworkPort );
312 }
313 }
314
315 extern "C" bool GetGlobalColor(wxString colorName, wxColour *pcolour);
316
BEGIN_EVENT_TABLE(ConnectionParamsPanel,wxPanel)317 BEGIN_EVENT_TABLE(ConnectionParamsPanel, wxPanel)
318 EVT_PAINT ( ConnectionParamsPanel::OnPaint )
319 EVT_ERASE_BACKGROUND(ConnectionParamsPanel::OnEraseBackground)
320 END_EVENT_TABLE()
321
322 ConnectionParamsPanel::ConnectionParamsPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size,
323 ConnectionParams *p_itemConnectionParams, options *pContainer)
324 :wxPanel(parent, id, pos, size, wxBORDER_NONE)
325 {
326 m_pContainer = pContainer;
327 m_pConnectionParams = p_itemConnectionParams;
328 m_bSelected = false;
329
330 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
331 SetFont( *dFont );
332
333 int refHeight = GetCharHeight();
334
335 // This controls the basic heght when later added to a vertical sizer
336 //SetMinSize(wxSize(-1, 6 * refHeight));
337
338 Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
339 CreateControls();
340
341 }
342
~ConnectionParamsPanel()343 ConnectionParamsPanel::~ConnectionParamsPanel()
344 {
345 if(m_pConnectionParams)
346 m_pConnectionParams->m_optionsPanel = nullptr;
347 }
348
OnSelected(wxMouseEvent & event)349 void ConnectionParamsPanel::OnSelected( wxMouseEvent &event )
350 {
351
352 if(!m_bSelected){
353 SetSelected( true );
354 m_pContainer->SetSelectedConnectionPanel( this );
355 }
356 else{
357 SetSelected( false );
358 m_pContainer->SetSelectedConnectionPanel( NULL );
359 }
360
361 }
362
SetSelected(bool selected)363 void ConnectionParamsPanel::SetSelected( bool selected )
364 {
365 m_bSelected = selected;
366 wxColour colour;
367 int refHeight = GetCharHeight();
368
369 if (selected)
370 {
371 GetGlobalColor(_T("UIBCK"), &colour);
372 m_boxColour = colour;
373 }
374 else
375 {
376 GetGlobalColor(_T("DILG0"), &colour);
377 m_boxColour = colour;
378 }
379
380
381 bool bUseSysColors = false;
382 #ifdef __WXOSX__
383 if( wxPlatformInfo::Get().CheckOSVersion(10, 14) )
384 bUseSysColors = true;
385 #endif
386 #ifdef __WXGTK__
387 bUseSysColors= true;
388 #endif
389
390 if(bUseSysColors){
391 wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
392 if( bg.Red() < 128 ) { // is Dark...
393 if(selected) {
394 m_boxColour=wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT/*wxSYS_COLOUR_WINDOW*/);
395 } else {
396 m_boxColour=wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
397 }
398 }
399 }
400
401
402
403 wxWindowList kids = GetChildren();
404 for( unsigned int i = 0; i < kids.GetCount(); i++ ) {
405 wxWindowListNode *node = kids.Item(i);
406 wxWindow *win = node->GetData();
407 win->SetBackgroundColour(m_boxColour);
408 }
409
410 GetSizer()->Layout();
411 Refresh( true );
412
413 }
414
OnEnableCBClick(wxCommandEvent & event)415 void ConnectionParamsPanel::OnEnableCBClick(wxCommandEvent &event){
416 if(m_pContainer){
417 m_pContainer->EnableConnection( m_pConnectionParams, event.IsChecked());
418 }
419 }
420
CreateControls(void)421 void ConnectionParamsPanel::CreateControls( void ){
422 int metric = GetCharHeight();
423
424 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
425 double font_size = dFont->GetPointSize() * 17/16;
426 wxFont *bFont = wxTheFontList->FindOrCreateFont( font_size, dFont->GetFamily(), dFont->GetStyle(), wxFONTWEIGHT_BOLD);
427
428 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
429 SetSizer(mainSizer);
430
431 mainSizer->AddSpacer( metric);
432
433 wxBoxSizer* panelSizer = new wxBoxSizer(wxHORIZONTAL);
434 mainSizer->Add(panelSizer, 0, wxLEFT, 5);
435
436 mainSizer->AddSpacer( metric);
437
438 // Enable cbox
439 wxBoxSizer* enableSizer = new wxBoxSizer(wxVERTICAL);
440 panelSizer->Add(enableSizer, 1, wxLEFT, metric);
441
442 m_cbEnable = new wxCheckBox(this, wxID_ANY, _("Enable"));
443 m_cbEnable->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
444 wxCommandEventHandler(ConnectionParamsPanel::OnEnableCBClick),
445 NULL, this);
446 m_cbEnable->SetValue( m_pConnectionParams->bEnabled);
447
448 enableSizer->Add(m_cbEnable, 1, wxLEFT | wxEXPAND, metric);
449
450 // Parms
451 wxBoxSizer* parmSizer = new wxBoxSizer(wxVERTICAL);
452 panelSizer->Add(parmSizer, 5, wxLEFT, metric);
453
454 if(m_pConnectionParams->Type == SERIAL){
455
456 wxFlexGridSizer *serialGrid = new wxFlexGridSizer(2, 7, 0, metric/2);
457 serialGrid->SetFlexibleDirection(wxHORIZONTAL);
458 parmSizer->Add(serialGrid, 0, wxALIGN_LEFT);
459
460 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
461
462 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
463 serialGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL );
464 t1->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
465
466 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
467 serialGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL );
468 t3->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
469
470 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
471 serialGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL );
472 t5->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
473
474 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _("Protocol"));
475 serialGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL );
476 t11->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
477
478 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _("Serial Port"));
479 serialGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL );
480 t13->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
481
482 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _("Baudrate"));
483 serialGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL );
484 t15->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
485
486 wxStaticText *t17 = new wxStaticText(this, wxID_ANY, _("Priority"));
487 serialGrid->Add(t17, 0, wxALIGN_CENTER_HORIZONTAL );
488 t17->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
489
490 //line 2
491 t2 = new wxStaticText(this, wxID_ANY, _("Serial"));
492 t2->SetFont(*bFont);
493 serialGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL );
494 t2->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
495
496 t4 = new wxStaticText(this, wxID_ANY, _T(""));
497 serialGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL );
498 t4->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
499
500 t6 = new wxStaticText(this, wxID_ANY, ioDir);
501 t6->SetFont(*bFont);
502 serialGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL );
503 t6->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
504
505 wxString proto;
506 switch(m_pConnectionParams->Protocol){
507 case PROTO_NMEA0183:
508 proto = _T("NMEA 0183"); break;
509 case PROTO_SEATALK:
510 proto = _T("SEATALK"); break;
511 case PROTO_NMEA2000:
512 proto = _T("NMEA 2000"); break;
513 default:
514 proto = _("Undefined"); break;
515 }
516
517 t12 = new wxStaticText(this, wxID_ANY, proto);
518 t12->SetFont(*bFont);
519 serialGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL );
520 t12->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
521
522 wxString serialPort = m_pConnectionParams->Port;
523 t14 = new wxStaticText(this, wxID_ANY, serialPort);
524 t14->SetFont(*bFont);
525 serialGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL );
526 t14->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
527
528 wxString baudRate; baudRate.Printf(_T("%d"), m_pConnectionParams->Baudrate);
529 t16 = new wxStaticText(this, wxID_ANY, baudRate);
530 t16->SetFont(*bFont);
531 serialGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL );
532 t16->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
533
534 wxString priority; priority.Printf(_T("%d"), m_pConnectionParams->Priority);
535 t18 = new wxStaticText(this, wxID_ANY, priority);
536 t18->SetFont(*bFont);
537 serialGrid->Add(t18, 0, wxALIGN_CENTER_HORIZONTAL );
538 t18->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
539
540 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
541 parmSizer->Add(line, 0, wxEXPAND);
542 line->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
543
544 t21 = new wxStaticText(this, wxID_ANY, _("Comment: ") + m_pConnectionParams->UserComment);
545 parmSizer->Add(t21, 0);
546 t21->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
547
548 }
549
550 else if(m_pConnectionParams->Type == NETWORK){
551 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
552
553 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 7, 0, metric/2);
554 netGrid->SetFlexibleDirection(wxHORIZONTAL);
555 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
556
557 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
558 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL );
559 t1->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
560
561 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
562 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL );
563 t3->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
564
565 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
566 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL );
567 t5->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
568
569 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _("Protocol"));
570 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL );
571 t11->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
572
573 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _("Network Address"));
574 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL );
575 t13->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
576
577 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _("Network Port"));
578 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL );
579 t15->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
580
581 wxStaticText *t17 = new wxStaticText(this, wxID_ANY, _("Priority"));
582 netGrid->Add(t17, 0, wxALIGN_CENTER_HORIZONTAL );
583 t17->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
584
585 //line 2
586 t2 = new wxStaticText(this, wxID_ANY, _("Network"));
587 t2->SetFont(*bFont);
588 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL );
589 t2->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
590
591 t4 = new wxStaticText(this, wxID_ANY, _T(""));
592 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL );
593 t4->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
594
595 t6 = new wxStaticText(this, wxID_ANY, ioDir);
596 t6->SetFont(*bFont);
597 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL );
598 t6->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
599
600 wxString proto;
601 switch(m_pConnectionParams->NetProtocol){
602 case UDP:
603 proto = _T("UDP"); break;
604 case TCP:
605 proto = _T("TCP"); break;
606 case GPSD:
607 proto = _T("GPSD"); break;
608 case SIGNALK:
609 proto = _T("Signal K"); break;
610 default:
611 proto = _("Undefined"); break;
612 }
613
614 t12 = new wxStaticText(this, wxID_ANY, proto);
615 t12->SetFont(*bFont);
616 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL );
617 t12->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
618
619 wxString address = m_pConnectionParams->NetworkAddress;
620 t14 = new wxStaticText(this, wxID_ANY, address);
621 t14->SetFont(*bFont);
622 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL );
623 t14->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
624
625 wxString port; port.Printf(_T("%d"), m_pConnectionParams->NetworkPort);
626 t16 = new wxStaticText(this, wxID_ANY, port);
627 t16->SetFont(*bFont);
628 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL );
629 t16->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
630
631 wxString priority; priority.Printf(_T("%d"), m_pConnectionParams->Priority);
632 t18 = new wxStaticText(this, wxID_ANY, priority);
633 t18->SetFont(*bFont);
634 netGrid->Add(t18, 0, wxALIGN_CENTER_HORIZONTAL );
635 t18->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
636
637 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
638 parmSizer->Add(line, 0, wxEXPAND);
639 line->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
640
641 t21 = new wxStaticText(this, wxID_ANY, _("Comment: ") + m_pConnectionParams->UserComment);
642 parmSizer->Add(t21, 0);
643 t21->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
644 }
645
646 else if(m_pConnectionParams->Type == INTERNAL_GPS){
647 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
648
649 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 7, 0, metric/2);
650 netGrid->SetFlexibleDirection(wxHORIZONTAL);
651 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
652
653 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
654 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL );
655 t1->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
656
657 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
658 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL );
659 t3->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
660
661 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
662 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL );
663 t5->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
664
665 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _T(""));
666 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL );
667 t11->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
668
669 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _T(""));
670 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL );
671 t13->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
672
673 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _T(""));
674 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL );
675 t15->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
676
677 wxStaticText *t17 = new wxStaticText(this, wxID_ANY, _("Priority"));
678 netGrid->Add(t17, 0, wxALIGN_CENTER_HORIZONTAL );
679 t17->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
680
681 //line 2
682 t2 = new wxStaticText(this, wxID_ANY, _("Built-in GPS"));
683 t2->SetFont(*bFont);
684 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL );
685 t2->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
686
687 t4 = new wxStaticText(this, wxID_ANY, _T(""));
688 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL );
689 t4->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
690
691 t6 = new wxStaticText(this, wxID_ANY, ioDir);
692 t6->SetFont(*bFont);
693 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL );
694 t6->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
695
696 wxString proto = _T("");
697
698 t12 = new wxStaticText(this, wxID_ANY, proto);
699 t12->SetFont(*bFont);
700 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL );
701 t12->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
702
703 wxString address;
704 t14 = new wxStaticText(this, wxID_ANY, address);
705 t14->SetFont(*bFont);
706 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL );
707 t14->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
708
709 wxString port;
710 t16 = new wxStaticText(this, wxID_ANY, port);
711 t16->SetFont(*bFont);
712 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL );
713 t16->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
714
715 wxString priority; priority.Printf(_T("%d"), m_pConnectionParams->Priority);
716 t18 = new wxStaticText(this, wxID_ANY, priority);
717 t18->SetFont(*bFont);
718 netGrid->Add(t18, 0, wxALIGN_CENTER_HORIZONTAL );
719 t18->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
720
721 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
722 parmSizer->Add(line, 0, wxEXPAND);
723 line->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
724
725 t21 = new wxStaticText(this, wxID_ANY, _("Comment: ") + m_pConnectionParams->UserComment);
726 parmSizer->Add(t21, 0);
727 t21->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
728
729 }
730 else if(m_pConnectionParams->Type == INTERNAL_BT){
731 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
732
733 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 7, 0, metric/2);
734 netGrid->SetFlexibleDirection(wxHORIZONTAL);
735 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
736
737 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
738 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL );
739 t1->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
740
741 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
742 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL );
743 t3->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
744
745 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
746 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL );
747 t5->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
748
749 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _T(""));
750 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL );
751 t11->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
752
753 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _T(""));
754 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL );
755 t13->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
756
757 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _T(""));
758 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL );
759 t15->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
760
761 wxStaticText *t17 = new wxStaticText(this, wxID_ANY, _("Priority"));
762 netGrid->Add(t17, 0, wxALIGN_CENTER_HORIZONTAL );
763 t17->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
764
765 //line 2
766 t2 = new wxStaticText(this, wxID_ANY, _("Built-in Bluetooth"));
767 t2->SetFont(*bFont);
768 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL );
769 t2->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
770
771 t4 = new wxStaticText(this, wxID_ANY, _T(""));
772 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL );
773 t4->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
774
775 t6 = new wxStaticText(this, wxID_ANY, ioDir);
776 t6->SetFont(*bFont);
777 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL );
778 t6->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
779
780 wxString proto = _T("");
781
782 t12 = new wxStaticText(this, wxID_ANY, proto);
783 t12->SetFont(*bFont);
784 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL );
785 t12->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
786
787 wxString address;
788 t14 = new wxStaticText(this, wxID_ANY, address);
789 t14->SetFont(*bFont);
790 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL );
791 t14->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
792
793 wxString port;
794 t16 = new wxStaticText(this, wxID_ANY, port);
795 t16->SetFont(*bFont);
796 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL );
797 t16->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
798
799 wxString priority; priority.Printf(_T("%d"), m_pConnectionParams->Priority);
800 t18 = new wxStaticText(this, wxID_ANY, priority);
801 t18->SetFont(*bFont);
802 netGrid->Add(t18, 0, wxALIGN_CENTER_HORIZONTAL );
803 t18->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
804
805 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
806 parmSizer->Add(line, 0, wxEXPAND);
807 line->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
808
809 t21 = new wxStaticText(this, wxID_ANY, _("Comment: ") + m_pConnectionParams->UserComment);
810 parmSizer->Add(t21, 0);
811 t21->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
812
813 }
814
815 }
816
Update(ConnectionParams * ConnectionParams)817 void ConnectionParamsPanel::Update( ConnectionParams *ConnectionParams)
818 {
819 m_pConnectionParams = ConnectionParams;
820
821 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
822 wxString priority; priority.Printf(_T("%d"), m_pConnectionParams->Priority);
823
824 if(m_pConnectionParams->Type == SERIAL){
825 wxString baudRate; baudRate.Printf(_T("%d"), m_pConnectionParams->Baudrate);
826
827 wxString proto;
828 switch(m_pConnectionParams->Protocol){
829 case PROTO_NMEA0183:
830 proto = _T("NMEA 0183"); break;
831 case PROTO_SEATALK:
832 proto = _T("SEATALK"); break;
833 case PROTO_NMEA2000:
834 proto = _T("NMEA 2000"); break;
835 default:
836 proto = _("Undefined"); break;
837 }
838
839 t2->SetLabel(_("Serial"));
840 t6->SetLabel(ioDir);
841 t12->SetLabel(proto);
842 t14->SetLabel(m_pConnectionParams->Port);
843 t16->SetLabel(baudRate);
844 t18->SetLabel(priority);
845
846 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
847 }
848 else if(m_pConnectionParams->Type == NETWORK){
849 wxString proto;
850 switch(m_pConnectionParams->NetProtocol){
851 case UDP:
852 proto = _T("UDP"); break;
853 case TCP:
854 proto = _T("TCP"); break;
855 case GPSD:
856 proto = _T("GPSD"); break;
857 case SIGNALK:
858 proto = _T("Signal K"); break;
859 default:
860 proto = _("Undefined"); break;
861 }
862 wxString port; port.Printf(_T("%d"), m_pConnectionParams->NetworkPort);
863
864
865 t2->SetLabel(_("Network"));
866 t6->SetLabel(ioDir);
867 t12->SetLabel(proto);
868 t14->SetLabel(m_pConnectionParams->NetworkAddress);
869 t16->SetLabel(port);
870 t18->SetLabel(priority);
871
872 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
873 }
874 else if(m_pConnectionParams->Type == INTERNAL_GPS){
875
876 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
877 }
878
879 else if(m_pConnectionParams->Type == INTERNAL_BT){
880
881 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
882 }
883
884 GetSizer()->Layout();
885 }
886
887
OnEraseBackground(wxEraseEvent & event)888 void ConnectionParamsPanel::OnEraseBackground( wxEraseEvent &event )
889 {
890 }
891
OnPaint(wxPaintEvent & event)892 void ConnectionParamsPanel::OnPaint( wxPaintEvent &event )
893 {
894 int width, height;
895 GetSize( &width, &height );
896 wxPaintDC dc( this );
897
898
899 dc.SetPen(*wxTRANSPARENT_PEN);
900 dc.SetBrush(wxBrush(GetBackgroundColour()));
901 dc.DrawRectangle(GetVirtualSize());
902
903 wxColour c;
904
905 wxString nameString = m_pConnectionParams->Serialize();
906
907 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
908
909
910 if(m_bSelected){
911 dc.SetBrush( wxBrush( m_boxColour ) );
912
913 GetGlobalColor( _T ( "UITX1" ), &c );
914 dc.SetPen( wxPen( wxColor(0xCE, 0xD5, 0xD6), 3 ));
915
916 dc.DrawRoundedRectangle( 0, 0, width-1, height-1, height / 10);
917
918 // Draw the thumbnail
919
920 dc.SetTextForeground(wxColour(0,0,0));
921 }
922 else{
923 dc.SetBrush( wxBrush( m_boxColour ) );
924
925 GetGlobalColor( _T ( "UITX1" ), &c );
926 dc.SetPen( wxPen( c, 1 ) );
927
928 int offset = height / 10;
929 dc.DrawRectangle( offset, offset, width - (2 * offset), height - (2 * offset));
930
931 dc.SetTextForeground(wxColour(128, 128, 128));
932 }
933
934
935 }
936
937
938