OpenCPN Partial API docs
Loading...
Searching...
No Matches
go_to_position_dlg.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2013 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#include <wx/button.h>
25#include <wx/clipbrd.h>
26#include <wx/dialog.h>
27#include <wx/event.h>
28#include <wx/sizer.h>
29#include <wx/stattext.h>
30#include <wx/string.h>
31#include <wx/textctrl.h>
32#include <wx/wxprec.h>
33
34#include "go_to_position_dlg.h"
35
36#include "model/position_parser.h"
37#include "chcanv.h"
38#include "MarkInfo.h"
39#include "navutil.h"
40#include "ocpn_frame.h"
41
43
51BEGIN_EVENT_TABLE(GoToPositionDialog, wxDialog)
52
53
54
55EVT_BUTTON(ID_GOTOPOS_CANCEL, GoToPositionDialog::OnGoToPosCancelClick)
56EVT_BUTTON(ID_GOTOPOS_OK, GoToPositionDialog::OnGoToPosOkClick)
57EVT_COMMAND(ID_LATCTRL, EVT_LLCHANGE, GoToPositionDialog::OnPositionCtlUpdated)
58EVT_COMMAND(ID_LONCTRL, EVT_LLCHANGE, GoToPositionDialog::OnPositionCtlUpdated)
59
60
61
62END_EVENT_TABLE()
63
64
69
70GoToPositionDialog::GoToPositionDialog(wxWindow* parent, wxWindowID id,
71 const wxString& caption,
72 const wxPoint& pos, const wxSize& size,
73 long style) {
74 long wstyle =
75 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT;
76
77 Create(parent, id, caption, pos, size, wstyle);
78}
79
80GoToPositionDialog::~GoToPositionDialog() {
81 delete m_MarkLatCtl;
82 delete m_MarkLonCtl;
83}
84
89bool GoToPositionDialog::Create(wxWindow* parent, wxWindowID id,
90 const wxString& caption, const wxPoint& pos,
91 const wxSize& size, long style) {
92 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
93 wxDialog::Create(parent, id, caption, pos, size, style);
94
95 m_hostCanvas = NULL;
96
98 GetSizer()->SetSizeHints(this);
99 Centre();
100
101 return TRUE;
102}
103
109 GoToPositionDialog* itemDialog1 = this;
110
111 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
112 itemDialog1->SetSizer(itemBoxSizer2);
113
114 wxStaticBox* itemStaticBoxSizer4Static =
115 new wxStaticBox(itemDialog1, wxID_ANY, _("Position"));
116
117 wxStaticBoxSizer* itemStaticBoxSizer4 =
118 new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxVERTICAL);
119 itemBoxSizer2->Add(itemStaticBoxSizer4, 0, wxEXPAND | wxALL, 5);
120
121 wxStaticText* itemStaticText5 =
122 new wxStaticText(itemDialog1, wxID_STATIC, _("Latitude"),
123 wxDefaultPosition, wxDefaultSize, 0);
124 itemStaticBoxSizer4->Add(itemStaticText5, 0,
125 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
126
127 m_MarkLatCtl = new wxTextCtrl(itemDialog1, ID_LATCTRL, "", wxDefaultPosition,
128 wxSize(180, -1), 0);
129 itemStaticBoxSizer4->Add(
130 m_MarkLatCtl, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,
131 5);
132
133 wxStaticText* itemStaticText6 =
134 new wxStaticText(itemDialog1, wxID_STATIC, _("Longitude"),
135 wxDefaultPosition, wxDefaultSize, 0);
136 itemStaticBoxSizer4->Add(itemStaticText6, 0,
137 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
138
139 m_MarkLonCtl = new wxTextCtrl(itemDialog1, ID_LONCTRL, "", wxDefaultPosition,
140 wxSize(180, -1), 0);
141 itemStaticBoxSizer4->Add(
142 m_MarkLonCtl, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,
143 5);
144
145 wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
146 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
147
148 m_CancelButton = new wxButton(itemDialog1, ID_GOTOPOS_CANCEL, _("Cancel"),
149 wxDefaultPosition, wxDefaultSize, 0);
150 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
151
152 m_OKButton = new wxButton(itemDialog1, ID_GOTOPOS_OK, _("OK"),
153 wxDefaultPosition, wxDefaultSize, 0);
154 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
155 m_OKButton->SetDefault();
156
157 SetColorScheme((ColorScheme)0);
158}
159
160void GoToPositionDialog::SetColorScheme(ColorScheme cs) { DimeControl(this); }
161
162bool GoToPositionDialog::ShowToolTips() { return TRUE; }
163
164void GoToPositionDialog::OnGoToPosCancelClick(wxCommandEvent& event) {
165 Hide();
166 if (m_hostCanvas) m_hostCanvas->ReloadVP();
167
168 event.Skip();
169}
170
171void GoToPositionDialog::OnGoToPosOkClick(wxCommandEvent& event) {
172 double lat, lon;
173
174 if (m_MarkLatCtl->GetValue().Length() == 0) goto noGo;
175 if (m_MarkLonCtl->GetValue().Length() == 0) goto noGo;
176
177 lat = fromDMM(m_MarkLatCtl->GetValue());
178 lon = fromDMM(m_MarkLonCtl->GetValue());
179
180 if (lat == 0.0 && lon == 0.0) goto noGo;
181 if (lat > 80.0 || lat < -80.0) goto noGo;
182 if (lon > 180.0 || lon < -180.0) goto noGo;
183
184 if (m_hostCanvas)
185 gFrame->JumpToPosition(m_hostCanvas, lat, lon, m_hostCanvas->GetVPScale());
186 Hide();
187 event.Skip();
188 return;
189
190noGo:
191 wxBell();
192 event.Skip();
193 return;
194}
195
196void GoToPositionDialog::CheckPasteBufferForPosition() {
197 if (wxTheClipboard->Open()) {
198 wxTextDataObject data;
199 wxTheClipboard->GetData(data);
200 wxString pasteBuf = data.GetText();
201
202 PositionParser pparse(pasteBuf);
203
204 if (pparse.IsOk()) {
205 m_MarkLatCtl->SetValue(pparse.GetLatitudeString());
206 m_MarkLonCtl->SetValue(pparse.GetLongitudeString());
207 }
208 wxTheClipboard->Close();
209 }
210}
211
212void GoToPositionDialog::OnPositionCtlUpdated(wxCommandEvent& event) {
213 // We do not want to change the position on lat/lon now
214}
Generic Chart canvas base.
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
Definition chcanv.h:466
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?
GoToPositionDialog * pGoToPositionDialog
Global instance.
Go to position dialog...