27#include <wx/html/htmlwin.h>
49extern ColorScheme global_color_scheme;
50extern wxString g_default_wp_icon;
58#define xID_WPT_CREATE 10010
59#define xID_TRK_CREATE 10011
63EVT_BUTTON(xID_OK, AISTargetQueryDialog::OnIdOKClick)
64EVT_BUTTON(xID_WPT_CREATE, AISTargetQueryDialog::OnIdWptCreateClick)
65EVT_BUTTON(xID_TRK_CREATE, AISTargetQueryDialog::OnIdTrkCreateClick)
66EVT_CLOSE(AISTargetQueryDialog::OnClose)
67EVT_MOVE(AISTargetQueryDialog::OnMove)
68EVT_SIZE(AISTargetQueryDialog::OnSize)
69EVT_CHAR_HOOK(AISTargetQueryDialog::OnKey)
77 const wxString &caption,
79 const wxSize &size,
long style) {
81 Create(parent,
id, caption, pos, size, style);
84AISTargetQueryDialog::~AISTargetQueryDialog() {
delete m_pQueryTextCtl; }
88 m_pQueryTextCtl = NULL;
90 m_colorscheme = (ColorScheme)(-1);
92 m_bautoCentre =
false;
95void AISTargetQueryDialog::OnClose(wxCloseEvent &event) {
100void AISTargetQueryDialog::OnIdOKClick(wxCommandEvent &event) { Close(); }
102void AISTargetQueryDialog::OnKey(wxKeyEvent &ke) {
103 if (ke.GetKeyCode() == WXK_ESCAPE)
109void AISTargetQueryDialog::OnIdWptCreateClick(wxCommandEvent &event) {
111 auto td =
g_pAIS->Get_Target_Data_From_MMSI(m_MMSI);
113 wxString n0 = wxString::Format(
"%s", td->ShipName);
114 n0.Replace(
"@",
" ");
116 wxString mmsi = wxString::Format(
"%i ", td->MMSI);
117 wxString n =
"\"" + n0 +
"\" " + mmsi;
118 n.append(wxDateTime::Now().Format(
"%H:%M"));
122 new RoutePoint(td->Lat, td->Lon, g_default_wp_icon, n, wxEmptyString);
124 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
126 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
128 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
129 pRouteManagerDialog->UpdateWptListCtrl();
130 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
131 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
132 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
138void AISTargetQueryDialog::OnIdTrkCreateClick(wxCommandEvent &event) {
140 auto td =
g_pAIS->Get_Target_Data_From_MMSI(m_MMSI);
142 if (td->b_PersistTrack)
145 td->b_PersistTrack =
false;
146 g_pAIS->m_persistent_tracks.erase(td->MMSI);
147 m_createTrkBtn->SetLabel(_(
"Record Track"));
148 td->b_show_track = td->b_show_track_old;
155 t->SetName(wxString::Format(
"AIS %s (%u) %s %s",
156 td->GetFullName().c_str(), td->MMSI,
157 wxDateTime::Now().FormatISODate().c_str(),
158 wxDateTime::Now().FormatISOTime().c_str()));
160 vector2D point(ptrack_point.m_lon, ptrack_point.m_lat);
161 tp1 = t->AddNewPoint(point, wxDateTime(ptrack_point.m_time).ToUTC());
163 pSelect->AddSelectableTrackSegment(tp->m_lat, tp->m_lon, tp1->m_lat,
164 tp1->m_lon, tp, tp1, t);
171 NavObj_dB::GetInstance().InsertTrack(t);
173 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
174 pRouteManagerDialog->UpdateTrkListCtrl();
180 _(
"The recently captured track of this target has been "
181 "recorded.\nDo you want to continue recording until the end "
182 "of the current OpenCPN session?"),
183 _(
"OpenCPN Info"), wxYES_NO | wxCENTER, 60)) {
184 td->b_PersistTrack =
true;
185 g_pAIS->m_persistent_tracks[td->MMSI] = t;
186 td->b_show_track_old = td->b_show_track;
187 td->b_show_track =
true;
195 const wxString &caption,
const wxPoint &pos,
196 const wxSize &size,
long style) {
197 long wstyle = AIS_TARGET_QUERY_STYLE;
199 if (!wxFrame::Create(parent,
id, caption, pos, size, wstyle))
return false;
203 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetQuery"));
204 int font_size = wxMax(8, dFont->GetPointSize());
205 wxString face = dFont->GetFaceName();
209 m_basefont = FontMgr::Get().
FindOrCreateFont(font_size, wxFONTFAMILY_MODERN,
211 dFont->GetWeight(),
false, face);
212 m_adjustedFontSize = dFont->GetPointSize();
213 m_control_font_size = dFont->GetPointSize();
214 SetFont(*m_basefont);
218 SetColorScheme(global_color_scheme);
222 SetSizeHints(50, 50, sz.x - 20, sz.y - 40);
227 SetSize(-1, m_adjustedFontSize * 30);
233void AISTargetQueryDialog::SetMMSI(
int mmsi) {
236 auto td =
g_pAIS->Get_Target_Data_From_MMSI(m_MMSI);
237 AdjustBestSize(td.get());
240void AISTargetQueryDialog::RecalculateSize() {
241 auto td =
g_pAIS->Get_Target_Data_From_MMSI(m_MMSI);
242 AdjustBestSize(td.get());
246void AISTargetQueryDialog::SetColorScheme(ColorScheme cs) {
248 wxColor bg = GetBackgroundColour();
249 m_pQueryTextCtl->SetBackgroundColour(bg);
256 wxBitmap tbm(GetSize().x, GetSize().y, -1);
259 tdc.SetBackground(bg);
261 m_pQueryTextCtl->SetBackgroundImage(tbm);
264 if (cs != m_colorscheme) {
270void AISTargetQueryDialog::CreateControls() {
271 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
275 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
276 wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION);
277 m_pQueryTextCtl->SetBorders(1);
278 m_pQueryTextCtl->SetFont(*m_basefont);
279 topSizer->Add(m_pQueryTextCtl, 1, wxALL | wxEXPAND, 5);
281 wxSizer *opt =
new wxBoxSizer(wxHORIZONTAL);
282 m_createWptBtn =
new wxButton(
this, xID_WPT_CREATE, _(
"Create Waypoint"),
283 wxDefaultPosition, wxDefaultSize, 0);
284 opt->Add(m_createWptBtn, 0, wxALL | wxEXPAND, 5);
286 m_createTrkBtn =
new wxButton(
this, xID_TRK_CREATE, _(
"Record Track"),
287 wxDefaultPosition, wxDefaultSize, 0);
288 opt->Add(m_createTrkBtn, 0, wxALL | wxEXPAND, 5);
289 topSizer->Add(opt, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
291 topSizer->Add(
new wxButton(
this, xID_OK, _(
"OK")), 0,
292 wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
297void AISTargetQueryDialog::UpdateText() {
300 if (!m_pQueryTextCtl)
return;
302 int scroll_x, scroll_y;
303 m_pQueryTextCtl->GetViewStart(&scroll_x, &scroll_y);
305 auto td =
g_pAIS->Get_Target_Data_From_MMSI(m_MMSI);
309 wxColor bg = GetBackgroundColour();
310 m_pQueryTextCtl->SetBackgroundColour(bg);
311 SetBackgroundColour(bg);
314 if (td->b_PersistTrack)
315 m_createTrkBtn->SetLabel(_(
"Save Track"));
317 m_createTrkBtn->SetLabel(_(
"Record Track"));
319 m_createWptBtn->Enable(td->b_positionOnceValid);
321 if (td->Class == AIS_METEO || td->Class == AIS_BASE)
322 m_createTrkBtn->Disable();
324 m_createTrkBtn->Enable();
326 RenderHTMLQuery(td.get());
330 SetColorScheme(m_colorscheme);
333 m_pQueryTextCtl->Scroll(scroll_x, scroll_y);
336void AISTargetQueryDialog::OnMove(wxMoveEvent &event) {
338 wxPoint p =
event.GetPosition();
339 g_ais_query_dialog_x = p.x;
340 g_ais_query_dialog_y = p.y;
345void AISTargetQueryDialog::OnSize(wxSizeEvent &event) {
event.Skip(); }
347void AISTargetQueryDialog::AdjustBestSize(
AisTargetData *td) {
350 wxSize origSize = GetSize();
362 wxSize szv = m_pQueryTextCtl->GetVirtualSize();
363 if (szv.x > m_pQueryTextCtl->GetSize().x) {
364 while ((szv.x > m_pQueryTextCtl->GetSize().x) &&
365 (m_adjustedFontSize > 8)) {
366 m_adjustedFontSize--;
369 m_pQueryTextCtl->Refresh();
370 m_pQueryTextCtl->Update();
372 szv = m_pQueryTextCtl->GetVirtualSize();
375 m_adjustedFontSize--;
377 target_x = szv.x * 12 /
381 wxSize szv = m_pQueryTextCtl->GetVirtualSize();
384 if (szv.x > m_pQueryTextCtl->GetSize().x) target_x = szv.x;
386 target_x = szv.x * 12 /
398 if (m_createWptBtn && m_createTrkBtn) {
403 m_control_font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
404 m_basefont->GetWeight(),
false, m_basefont->GetFaceName());
407 wxSize tsz = dc.GetTextExtent(m_createWptBtn->GetLabel() +
408 m_createTrkBtn->GetLabel());
410 float totalButtonWidth = tsz.x;
412 if (totalButtonWidth * 1.5 > psz.x) {
413 float delta = (float)totalButtonWidth * 2. / psz.x;
415 float font_size = m_control_font_size / delta;
418 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
419 m_basefont->GetWeight(),
false, m_basefont->GetFaceName());
421 m_createWptBtn->SetFont(*fp_font);
422 m_createTrkBtn->SetFont(*fp_font);
424 m_control_font_size = font_size;
434 if (m_createWptBtn) yb = m_createWptBtn->GetSize().y * 4;
436 wxSize szyv = m_pQueryTextCtl->GetVirtualSize();
438 if ((szyv.y + yb) < csz) {
439 if (szyv.y > m_pQueryTextCtl->GetSize().y) target_y = szyv.y * 12 / 10 + yb;
443 SetSize(target_x, target_y);
445 wxSize nowSize = GetSize();
447 if (nowSize != origSize) {
448 if (m_bautoCentre) Centre();
452void AISTargetQueryDialog::RenderHTMLQuery(
AisTargetData *td) {
453 int font_size = m_adjustedFontSize;
455 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
456 m_basefont->GetWeight(),
false, m_basefont->GetFaceName());
461 for (
int i = -2; i < 5; i++) {
462 sizes[i + 2] = fp_font->GetPointSize() + i + (i > 0 ? i : 0);
466 wxColor bg = GetBackgroundColour();
467 wxColor fg = GetForegroundColour();
470 "<html><body bgcolor=#%02x%02x%02x><font "
471 "color=#%02x%02x%02x><center>",
472 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
474 html << td->BuildQueryResult();
476 html <<
"</center></font></body></html>";
478 m_pQueryTextCtl->SetFonts(fp_font->GetFaceName(), fp_font->GetFaceName(),
481 wxCharBuffer buf = html.ToUTF8();
483 m_pQueryTextCtl->SetPage(html);
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Global state for AIS decoder.
Class AISTargetQueryDialog.
AISTargetQueryDialog * g_pais_query_dialog_active
Global instance.
Generic Chart canvas base.
Dialog for querying detailed information about an AIS target.
AISTargetQueryDialog()
Constructors.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Object Query"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=AIS_TARGET_QUERY_STYLE)
Creation.
void Init()
Initialise our variables.
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Represents a waypoint or mark within the navigation system.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Represents a single point in a track.
Represents a track, which is a series of connected track points.
MySQL based storage for routes, tracks, etc.
Waypoint or mark abstraction.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.
std::vector< Track * > g_TrackList
Global instance.
Recorded track abstraction.