32#include <wx/html/htmlwin.h>
34#include "model/ais_decoder.h"
36#include "model/ais_target_data.h"
37#include "model/ocpn_types.h"
38#include "model/ocpn_types.h"
39#include "model/route_point.h"
40#include "model/select.h"
42#include "AISTargetAlertDialog.h"
46#include "ocpn_frame.h"
47#include "OCPNPlatform.h"
48#include "routemanagerdialog.h"
53#include "androidUTIL.h"
56extern ColorScheme global_color_scheme;
59extern int g_ais_alert_dialog_y;
60extern wxString g_default_wp_icon;
78OCPN_AlertDialog::~OCPN_AlertDialog() {}
80void OCPN_AlertDialog::Init(
void) { m_pparent = NULL; }
82bool OCPN_AlertDialog::Create(wxWindow *parent, wxWindowID
id,
83 const wxString &caption,
const wxPoint &pos,
84 const wxSize &size,
long style)
87 long wstyle = wxDEFAULT_FRAME_STYLE;
89 wxSize size_min = size;
90 size_min.IncTo(wxSize(500, 600));
91 if (!wxDialog::Create(parent,
id, caption, pos, size_min, wstyle))
96 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
110EVT_CLOSE(AISTargetAlertDialog::OnClose)
111EVT_BUTTON(ID_ACKNOWLEDGE, AISTargetAlertDialog::OnIdAckClick)
112EVT_BUTTON(ID_SILENCE, AISTargetAlertDialog::OnIdSilenceClick)
113EVT_BUTTON(ID_JUMPTO, AISTargetAlertDialog::OnIdJumptoClick)
114EVT_BUTTON(ID_WPT_CREATE, AISTargetAlertDialog::OnIdCreateWPClick)
115EVT_MOVE(AISTargetAlertDialog::OnMove)
116EVT_SIZE(AISTargetAlertDialog::OnSize)
121AISTargetAlertDialog::~AISTargetAlertDialog() {}
123void AISTargetAlertDialog::Init() {
131bool AISTargetAlertDialog::Create(
int target_mmsi, wxWindow *parent,
133 bool b_createWP,
bool b_ack, wxWindowID
id,
134 const wxString &caption,
const wxPoint &pos,
135 const wxSize &size,
long style)
138 OCPN_AlertDialog::Create(parent,
id, caption, pos, size, style);
139 m_bjumpto = b_jumpto;
141 m_bcreateWP = b_createWP;
143 m_target_mmsi = target_mmsi;
144 m_pdecoder = pdecoder;
147 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
148 int font_size = wxMax(8, dFont->GetPointSize());
149 wxString face = dFont->GetFaceName();
151 face = _T(
"Monospace");
154 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, dFont->GetWeight(),
160 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
162 wxColor bg = GetBackgroundColour();
163 m_pAlertTextCtl->SetBackgroundColour(bg);
164 SetBackgroundColour(bg);
169void AISTargetAlertDialog::CreateControls() {
170 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
172 long style = wxHW_SCROLLBAR_AUTO;
173 if (g_btouch) style |= wxHW_NO_SELECTION;
176 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
178 m_pAlertTextCtl->GetHandle()->setStyleSheet(getQtStyleSheet());
181 m_pAlertTextCtl->SetBorders(5);
182 m_pAlertTextCtl->SetScrollRate(1, 1);
184 topSizer->Add(m_pAlertTextCtl, 1, wxALL | wxEXPAND, 5);
187 wxFlexGridSizer *AckBox =
new wxFlexGridSizer(2);
188 topSizer->Add(AckBox, 0, wxALL, 5);
191 if (g_bAIS_CPA_Alert_Audio) {
192 wxButton *silence =
new wxButton(
this, ID_SILENCE, _(
"&Silence Alert"),
193 wxDefaultPosition, wxDefaultSize, 0);
194 AckBox->Add(silence, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
198 wxButton *jumpto =
new wxButton(
this, ID_JUMPTO, _(
"&Jump To"),
199 wxDefaultPosition, wxDefaultSize, 0);
200 AckBox->Add(jumpto, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
204 wxButton *createWptBtn =
205 new wxButton(
this, ID_WPT_CREATE, _(
"Create Waypoint"),
206 wxDefaultPosition, wxDefaultSize, 0);
207 AckBox->Add(createWptBtn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
211 wxString acktext = _(
"&Acknowledge");
212 bool show_ack_button =
false;
213 if (m_bjumpto && m_bcreateWP) {
214 acktext = _(
"&Close Alert");
215 show_ack_button =
true;
217 if (m_back || show_ack_button) {
218 wxButton *ack =
new wxButton(
this, ID_ACKNOWLEDGE, acktext,
219 wxDefaultPosition, wxDefaultSize, 0);
220 AckBox->Add(ack, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
228bool AISTargetAlertDialog::GetAlertText() {
231 auto td_found = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
234 m_alert_text = td_found->BuildQueryResult();
242void AISTargetAlertDialog::UpdateText() {
243 if (GetAlertText()) {
246 m_pAlertTextCtl->GetViewStart(&x, &y);
248 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
249 wxString face = dFont->GetFaceName();
251 for (
int i = -2; i < 5; i++) {
252 sizes[i + 2] = dFont->GetPointSize() + i + (i > 0 ? i : 0);
256 wxColor bg = GetBackgroundColour();
257 wxColor fg = GetForegroundColour();
260 _T(
"<html><body bgcolor=#%02x%02x%02x><font ")
261 _T(
"color=#%02x%02x%02x><center>"),
262 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
264 html << m_alert_text;
265 html << _T(
"</center></font></body></html>");
267 m_pAlertTextCtl->SetFonts(face, face, sizes);
268 m_pAlertTextCtl->SetPage(html);
273 m_pAlertTextCtl->Scroll(x, y);
277 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
280void AISTargetAlertDialog::RecalculateSize(
void) {
284 while (i < m_alert_text.Length()) {
285 if (m_alert_text[i] ==
'\n') nline++;
289 if (nline > m_max_nline) m_max_nline = nline;
292 esize.x = GetCharWidth() * 45;
293 esize.y = GetCharHeight() * (m_max_nline + 4);
296 int height = m_pAlertTextCtl->GetInternalRepresentation()->GetHeight();
297 int adj_height = height + (GetCharHeight() * 6);
298 m_adj_height = wxMax(m_adj_height, adj_height);
300 esize.y = wxMin(esize.y, m_adj_height);
306 int textWidth = m_pAlertTextCtl->GetInternalRepresentation()->GetWidth();
307 wxSize gSize = GetClientSize();
308 int adjustedWidth = wxMax(GetClientSize().x, textWidth + GetCharHeight() * 2);
309 SetClientSize(adjustedWidth, esize.y);
313 wxSize wsize = m_pParent->GetSize();
314 SetSize(-1, wxMin(esize.y, wsize.y));
317 g_Platform->PositionAISAlert(
this);
320void AISTargetAlertDialog::SetColorScheme(
void) {
322 wxColor bg = GetBackgroundColour();
323 m_pAlertTextCtl->SetBackgroundColour(bg);
330 wxBitmap tbm(GetSize().x, GetSize().y, -1);
333 tdc.SetBackground(bg);
335 m_pAlertTextCtl->SetBackgroundImage(tbm);
339void AISTargetAlertDialog::OnClose(wxCloseEvent &event) {
342 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
344 if (AIS_ALERT_SET == td->n_alert_state) {
345 td->m_ack_time = wxDateTime::Now();
346 td->b_in_ack_timeout =
true;
348 if (td->b_isDSCtarget) {
349 td->b_isDSCtarget =
false;
350 if (td->n_alert_state) {
351 td->n_alert_state = AIS_NO_ALERT;
358 g_pais_alert_dialog_active = NULL;
361void AISTargetAlertDialog::OnIdAckClick(wxCommandEvent &event) {
364 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
366 if (AIS_ALERT_SET == td->n_alert_state) {
367 td->m_ack_time = wxDateTime::Now();
368 td->b_in_ack_timeout =
true;
370 if (td->b_isDSCtarget) {
371 td->b_isDSCtarget =
false;
372 if (td->n_alert_state) {
373 td->n_alert_state = AIS_NO_ALERT;
379 g_pais_alert_dialog_active = NULL;
381void AISTargetAlertDialog::OnIdCreateWPClick(wxCommandEvent &event) {
383 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
386 wxEmptyString, wxEmptyString);
388 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
389 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
391 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
392 pRouteManagerDialog->UpdateWptListCtrl();
393 if (gFrame->GetPrimaryCanvas()) {
394 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
395 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
396 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
397 gFrame->InvalidateAllGL();
404void AISTargetAlertDialog::OnIdSilenceClick(wxCommandEvent &event) {
407 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
408 if (td) td->b_suppress_audio =
true;
412void AISTargetAlertDialog::OnIdJumptoClick(wxCommandEvent &event) {
414 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
416 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), td->Lat, td->Lon,
417 gFrame->GetFocusCanvas()->GetVPScale());
421void AISTargetAlertDialog::OnMove(wxMoveEvent &event) {
423 g_ais_alert_dialog_x = GetPosition().x;
424 g_ais_alert_dialog_y = GetPosition().y;
429void AISTargetAlertDialog::OnSize(wxSizeEvent &event) {
431 wxSize p =
event.GetSize();
432 g_ais_alert_dialog_sx = p.x;
433 g_ais_alert_dialog_sy = p.y;
Global state for AIS decoder.
Dialog for displaying AIS target alerts.
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)
Gets 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.