26 #include <wx/wxprec.h>
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"
52 #include "androidUTIL.h"
55 extern ColorScheme global_color_scheme;
56 extern bool g_bopengl;
58 extern int g_ais_alert_dialog_y;
59 extern wxString g_default_wp_icon;
77 OCPN_AlertDialog::~OCPN_AlertDialog() {}
79 void OCPN_AlertDialog::Init(
void) { m_pparent = NULL; }
81 bool OCPN_AlertDialog::Create(wxWindow *parent, wxWindowID
id,
82 const wxString &caption,
const wxPoint &pos,
83 const wxSize &size,
long style)
86 long wstyle = wxDEFAULT_FRAME_STYLE;
88 wxSize size_min = size;
89 size_min.IncTo(wxSize(500, 600));
90 if (!wxDialog::Create(parent,
id, caption, pos, size_min, wstyle))
95 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
109 EVT_CLOSE(AISTargetAlertDialog::OnClose)
110 EVT_BUTTON(ID_ACKNOWLEDGE, AISTargetAlertDialog::OnIdAckClick)
111 EVT_BUTTON(ID_SILENCE, AISTargetAlertDialog::OnIdSilenceClick)
112 EVT_BUTTON(ID_JUMPTO, AISTargetAlertDialog::OnIdJumptoClick)
113 EVT_BUTTON(ID_WPT_CREATE, AISTargetAlertDialog::OnIdCreateWPClick)
114 EVT_MOVE(AISTargetAlertDialog::OnMove)
115 EVT_SIZE(AISTargetAlertDialog::OnSize)
120 AISTargetAlertDialog::~AISTargetAlertDialog() {}
122 void AISTargetAlertDialog::Init() {
130 bool AISTargetAlertDialog::Create(
int target_mmsi, wxWindow *parent,
132 bool b_createWP,
bool b_ack, wxWindowID
id,
133 const wxString &caption,
const wxPoint &pos,
134 const wxSize &size,
long style)
137 OCPN_AlertDialog::Create(parent,
id, caption, pos, size, style);
138 m_bjumpto = b_jumpto;
140 m_bcreateWP = b_createWP;
142 m_target_mmsi = target_mmsi;
143 m_pdecoder = pdecoder;
146 wxFont *dFont = FontMgr::Get().GetFont(_(
"AISTargetAlert"), 12);
147 int font_size = wxMax(8, dFont->GetPointSize());
148 wxString face = dFont->GetFaceName();
150 face = _T(
"Monospace");
152 wxFont *fp_font = FontMgr::Get().FindOrCreateFont(
153 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, dFont->GetWeight(),
159 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
161 wxColor bg = GetBackgroundColour();
162 m_pAlertTextCtl->SetBackgroundColour(bg);
163 SetBackgroundColour(bg);
168 void AISTargetAlertDialog::CreateControls() {
169 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
171 long style = wxHW_SCROLLBAR_AUTO;
172 if (g_btouch) style |= wxHW_NO_SELECTION;
175 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
177 m_pAlertTextCtl->GetHandle()->setStyleSheet(getQtStyleSheet());
180 m_pAlertTextCtl->SetBorders(5);
181 m_pAlertTextCtl->SetScrollRate(1, 1);
183 topSizer->Add(m_pAlertTextCtl, 1, wxALL | wxEXPAND, 5);
186 wxFlexGridSizer *AckBox =
new wxFlexGridSizer(2);
187 topSizer->Add(AckBox, 0, wxALL, 5);
190 if (g_bAIS_CPA_Alert_Audio) {
191 wxButton *silence =
new wxButton(
this, ID_SILENCE, _(
"&Silence Alert"),
192 wxDefaultPosition, wxDefaultSize, 0);
193 AckBox->Add(silence, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
197 wxButton *jumpto =
new wxButton(
this, ID_JUMPTO, _(
"&Jump To"),
198 wxDefaultPosition, wxDefaultSize, 0);
199 AckBox->Add(jumpto, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
203 wxButton *createWptBtn =
204 new wxButton(
this, ID_WPT_CREATE, _(
"Create Waypoint"),
205 wxDefaultPosition, wxDefaultSize, 0);
206 AckBox->Add(createWptBtn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
210 wxString acktext = _(
"&Acknowledge");
211 bool show_ack_button =
false;
212 if (m_bjumpto && m_bcreateWP) {
213 acktext = _(
"&Close Alert");
214 show_ack_button =
true;
216 if (m_back || show_ack_button) {
217 wxButton *ack =
new wxButton(
this, ID_ACKNOWLEDGE, acktext,
218 wxDefaultPosition, wxDefaultSize, 0);
219 AckBox->Add(ack, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
227 bool AISTargetAlertDialog::GetAlertText() {
230 auto td_found = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
233 m_alert_text = td_found->BuildQueryResult();
241 void AISTargetAlertDialog::UpdateText() {
242 if (GetAlertText()) {
245 m_pAlertTextCtl->GetViewStart( &x, &y);
247 wxFont *dFont = FontMgr::Get().GetFont(_(
"AISTargetAlert"), 12);
248 wxString face = dFont->GetFaceName();
250 for (
int i = -2; i < 5; i++) {
251 sizes[i + 2] = dFont->GetPointSize() + i + (i > 0 ? i : 0);
255 wxColor bg = GetBackgroundColour();
256 wxColor fg = GetForegroundColour();
259 _T(
"<html><body bgcolor=#%02x%02x%02x><font ")
260 _T(
"color=#%02x%02x%02x><center>"),
261 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
263 html << m_alert_text;
264 html << _T(
"</center></font></body></html>");
266 m_pAlertTextCtl->SetFonts(face, face, sizes);
267 m_pAlertTextCtl->SetPage(html);
272 m_pAlertTextCtl->Scroll(x, y);
276 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
279 void AISTargetAlertDialog::RecalculateSize(
void) {
283 while (i < m_alert_text.Length()) {
284 if (m_alert_text[i] ==
'\n') nline++;
288 if (nline > m_max_nline) m_max_nline = nline;
291 esize.x = GetCharWidth() * 45;
292 esize.y = GetCharHeight() * (m_max_nline + 4);
295 int height = m_pAlertTextCtl->GetInternalRepresentation()->GetHeight();
296 int adj_height = height + (GetCharHeight() * 6);
297 m_adj_height = wxMax(m_adj_height, adj_height);
299 esize.y = wxMin(esize.y, m_adj_height);
305 int textWidth = m_pAlertTextCtl->GetInternalRepresentation()->GetWidth();
306 wxSize gSize = GetClientSize();
307 int adjustedWidth = wxMax(GetClientSize().x, textWidth + GetCharHeight() * 2);
308 SetClientSize(adjustedWidth, esize.y);
312 wxSize wsize = m_pParent->GetSize();
313 SetSize(-1, wxMin(esize.y, wsize.y));
316 g_Platform->PositionAISAlert(
this);
319 void AISTargetAlertDialog::SetColorScheme(
void) {
321 wxColor bg = GetBackgroundColour();
322 m_pAlertTextCtl->SetBackgroundColour(bg);
329 wxBitmap tbm(GetSize().x, GetSize().y, -1);
332 tdc.SetBackground(bg);
334 m_pAlertTextCtl->SetBackgroundImage(tbm);
338 void AISTargetAlertDialog::OnClose(wxCloseEvent &event) {
341 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
343 if (AIS_ALERT_SET == td->n_alert_state) {
344 td->m_ack_time = wxDateTime::Now();
345 td->b_in_ack_timeout =
true;
347 if (td->b_isDSCtarget) {
348 td->b_isDSCtarget =
false;
349 if (td->n_alert_state) {
350 td->n_alert_state = AIS_NO_ALERT;
357 g_pais_alert_dialog_active = NULL;
360 void AISTargetAlertDialog::OnIdAckClick(wxCommandEvent &event) {
363 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
365 if (AIS_ALERT_SET == td->n_alert_state ) {
366 td->m_ack_time = wxDateTime::Now();
367 td->b_in_ack_timeout =
true;
369 if (td->b_isDSCtarget) {
370 td->b_isDSCtarget =
false;
371 if (td->n_alert_state) {
372 td->n_alert_state = AIS_NO_ALERT;
378 g_pais_alert_dialog_active = NULL;
380 void AISTargetAlertDialog::OnIdCreateWPClick(wxCommandEvent &event) {
382 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
385 wxEmptyString, wxEmptyString);
386 pWP->m_bIsolatedMark =
true;
387 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
388 pConfig->AddNewWayPoint(pWP, -1);
390 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
391 pRouteManagerDialog->UpdateWptListCtrl();
392 if (gFrame->GetPrimaryCanvas()) {
393 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
394 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
395 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
396 gFrame->InvalidateAllGL();
403 void AISTargetAlertDialog::OnIdSilenceClick(wxCommandEvent &event) {
407 m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
408 if (td) td->b_suppress_audio =
true;
412 void AISTargetAlertDialog::OnIdJumptoClick(wxCommandEvent &event) {
415 m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
417 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), td->Lat, td->Lon,
418 gFrame->GetFocusCanvas()->GetVPScale());
422 void AISTargetAlertDialog::OnMove(wxMoveEvent &event) {
424 g_ais_alert_dialog_x = GetPosition().x;
425 g_ais_alert_dialog_y = GetPosition().y;
430 void AISTargetAlertDialog::OnSize(wxSizeEvent &event) {
432 wxSize p =
event.GetSize();
433 g_ais_alert_dialog_sx = p.x;
434 g_ais_alert_dialog_sy = p.y;
Global state for AIS decoder.