OpenCPN Partial API docs
GoToPositionDialog.cpp
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 
25 #include <wx/wxprec.h>
26 #include <wx/sizer.h>
27 #include <wx/stattext.h>
28 #include <wx/button.h>
29 #include <wx/textctrl.h>
30 #include <wx/clipbrd.h>
31 
32 #include "GoToPositionDialog.h"
33 #include "model/position_parser.h"
34 #include "MarkInfo.h"
35 #include "navutil.h"
36 #include "chcanv.h"
37 #include "ocpn_frame.h"
38 
39 extern MyFrame* gFrame;
40 
45 IMPLEMENT_DYNAMIC_CLASS(GoToPositionDialog, wxDialog)
49 BEGIN_EVENT_TABLE(GoToPositionDialog, wxDialog)
50 
51 
53 EVT_BUTTON(ID_GOTOPOS_CANCEL, GoToPositionDialog::OnGoToPosCancelClick)
54 EVT_BUTTON(ID_GOTOPOS_OK, GoToPositionDialog::OnGoToPosOkClick)
55 EVT_COMMAND(ID_LATCTRL, EVT_LLCHANGE, GoToPositionDialog::OnPositionCtlUpdated)
56 EVT_COMMAND(ID_LONCTRL, EVT_LLCHANGE, GoToPositionDialog::OnPositionCtlUpdated)
57 
58 
60 END_EVENT_TABLE()
61 
62 
67 
68 GoToPositionDialog::GoToPositionDialog(wxWindow* parent, wxWindowID id,
69  const wxString& caption,
70  const wxPoint& pos, const wxSize& size,
71  long style) {
72  long wstyle =
73  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT;
74 
75  Create(parent, id, caption, pos, size, wstyle);
76 }
77 
78 GoToPositionDialog::~GoToPositionDialog() {
79  delete m_MarkLatCtl;
80  delete m_MarkLonCtl;
81 }
82 
87 bool GoToPositionDialog::Create(wxWindow* parent, wxWindowID id,
88  const wxString& caption, const wxPoint& pos,
89  const wxSize& size, long style) {
90  SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
91  wxDialog::Create(parent, id, caption, pos, size, style);
92 
93  m_hostCanvas = NULL;
94 
96  GetSizer()->SetSizeHints(this);
97  Centre();
98 
99  return TRUE;
100 }
101 
107  GoToPositionDialog* itemDialog1 = this;
108 
109  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
110  itemDialog1->SetSizer(itemBoxSizer2);
111 
112  wxStaticBox* itemStaticBoxSizer4Static =
113  new wxStaticBox(itemDialog1, wxID_ANY, _("Position"));
114 
115  wxStaticBoxSizer* itemStaticBoxSizer4 =
116  new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxVERTICAL);
117  itemBoxSizer2->Add(itemStaticBoxSizer4, 0, wxEXPAND | wxALL, 5);
118 
119  wxStaticText* itemStaticText5 =
120  new wxStaticText(itemDialog1, wxID_STATIC, _("Latitude"),
121  wxDefaultPosition, wxDefaultSize, 0);
122  itemStaticBoxSizer4->Add(itemStaticText5, 0,
123  wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
124 
125  m_MarkLatCtl = new wxTextCtrl(itemDialog1, ID_LATCTRL, _T(""),
126  wxDefaultPosition, wxSize(180, -1), 0);
127  itemStaticBoxSizer4->Add(
128  m_MarkLatCtl, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,
129  5);
130 
131  wxStaticText* itemStaticText6 =
132  new wxStaticText(itemDialog1, wxID_STATIC, _("Longitude"),
133  wxDefaultPosition, wxDefaultSize, 0);
134  itemStaticBoxSizer4->Add(itemStaticText6, 0,
135  wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
136 
137  m_MarkLonCtl = new wxTextCtrl(itemDialog1, ID_LONCTRL, _T(""),
138  wxDefaultPosition, wxSize(180, -1), 0);
139  itemStaticBoxSizer4->Add(
140  m_MarkLonCtl, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,
141  5);
142 
143  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
144  itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
145 
146  m_CancelButton = new wxButton(itemDialog1, ID_GOTOPOS_CANCEL, _("Cancel"),
147  wxDefaultPosition, wxDefaultSize, 0);
148  itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
149 
150  m_OKButton = new wxButton(itemDialog1, ID_GOTOPOS_OK, _("OK"),
151  wxDefaultPosition, wxDefaultSize, 0);
152  itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
153  m_OKButton->SetDefault();
154 
155  SetColorScheme((ColorScheme)0);
156 }
157 
158 void GoToPositionDialog::SetColorScheme(ColorScheme cs) { DimeControl(this); }
159 
160 bool GoToPositionDialog::ShowToolTips() { return TRUE; }
161 
162 void GoToPositionDialog::OnGoToPosCancelClick(wxCommandEvent& event) {
163  Hide();
164  if (m_hostCanvas) m_hostCanvas->ReloadVP();
165 
166  event.Skip();
167 }
168 
169 void GoToPositionDialog::OnGoToPosOkClick(wxCommandEvent& event) {
170  double lat, lon;
171 
172  if (m_MarkLatCtl->GetValue().Length() == 0) goto noGo;
173  if (m_MarkLonCtl->GetValue().Length() == 0) goto noGo;
174 
175  lat = fromDMM(m_MarkLatCtl->GetValue());
176  lon = fromDMM(m_MarkLonCtl->GetValue());
177 
178  if (lat == 0.0 && lon == 0.0) goto noGo;
179  if (lat > 80.0 || lat < -80.0) goto noGo;
180  if (lon > 180.0 || lon < -180.0) goto noGo;
181 
182  if (m_hostCanvas)
183  gFrame->JumpToPosition(m_hostCanvas, lat, lon, m_hostCanvas->GetVPScale());
184  Hide();
185  event.Skip();
186  return;
187 
188 noGo:
189  wxBell();
190  event.Skip();
191  return;
192 }
193 
194 void GoToPositionDialog::CheckPasteBufferForPosition() {
195  if (wxTheClipboard->Open()) {
196  wxTextDataObject data;
197  wxTheClipboard->GetData(data);
198  wxString pasteBuf = data.GetText();
199 
200  PositionParser pparse(pasteBuf);
201 
202  if (pparse.IsOk()) {
203  m_MarkLatCtl->SetValue(pparse.GetLatitudeString());
204  m_MarkLonCtl->SetValue(pparse.GetLongitudeString());
205  }
206  wxTheClipboard->Close();
207  }
208 }
209 
210 void GoToPositionDialog::OnPositionCtlUpdated(wxCommandEvent& event) {
211  // We do not want to change the position on lat/lon now
212 }
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_GOTOPOS_IDNAME, const wxString &caption=SYMBOL_GOTOPOS_TITLE, const wxPoint &pos=SYMBOL_GOTOPOS_POSITION, const wxSize &size=SYMBOL_GOTOPOS_SIZE, long style=SYMBOL_GOTOPOS_STYLE)
Creation.
GoToPositionDialog()
Constructors.
static bool ShowToolTips()
Should we show tooltips?