30 #include <wx/wxprec.h>
39 #include <wx/datetime.h>
41 #include "model/navutil_base.h"
42 #include "model/own_ship.h"
43 #include "model/route.h"
44 #include "model/routeman.h"
45 #include "model/wx28compat.h"
51 #include "ocpn_frame.h"
52 #include "OCPNPlatform.h"
58 extern bool g_bShowActiveRouteHighway;
61 bool g_bShowRouteTotal;
65 enum eMenuItems { ID_NAVLEG = 1, ID_NAVROUTE, ID_NAVHIGHWAY } menuItems;
71 EVT_PAINT(ConsoleCanvas::OnPaint)
72 EVT_SHOW(ConsoleCanvas::OnShow)
73 EVT_CONTEXT_MENU(ConsoleCanvas::OnContextMenu)
74 EVT_MENU(ID_NAVLEG, ConsoleCanvas::OnContextMenuSelection)
75 EVT_MENU(ID_NAVROUTE, ConsoleCanvas::OnContextMenuSelection)
76 EVT_MENU(ID_NAVHIGHWAY, ConsoleCanvas::OnContextMenuSelection)
82 m_speedUsed = SPEED_VMG;
86 long style = wxSIMPLE_BORDER | wxCLIP_CHILDREN | wxFRAME_FLOAT_ON_PARENT;
89 style |= wxFRAME_NO_TASKBAR;
92 wxFrame::Create(frame, wxID_ANY, _T(
""), wxDefaultPosition, wxDefaultSize,
97 m_pitemBoxSizerLeg =
new wxBoxSizer(wxVERTICAL);
99 pThisLegText =
new wxStaticText(
this, -1, _(
"This Leg"));
101 m_pitemBoxSizerLeg->Add(pThisLegText, 0, wxALIGN_CENTER_HORIZONTAL, 2);
103 wxFont* qFont = GetOCPNScaledFont(_(
"Dialog"));
105 wxFont* pThisLegFont = FontMgr::Get().FindOrCreateFont(
106 10, wxFONTFAMILY_DEFAULT, qFont->GetStyle(), wxFONTWEIGHT_BOLD,
false,
107 qFont->GetFaceName());
108 pThisLegText->SetFont(*pThisLegFont);
110 pXTE =
new AnnunText(
this, -1, _(
"Console Legend"), _(
"Console Value"));
111 pXTE->SetALabel(_T(
"XTE"));
112 m_pitemBoxSizerLeg->Add(pXTE, 1, wxALIGN_LEFT | wxALL, 2);
114 pBRG =
new AnnunText(
this, -1, _(
"Console Legend"), _(
"Console Value"));
115 pBRG->SetALabel(_T(
"BRG"));
116 m_pitemBoxSizerLeg->Add(pBRG, 1, wxALIGN_LEFT | wxALL, 2);
118 pVMG =
new AnnunText(
this, -1, _(
"Console Legend"), _(
"Console Value"));
119 pVMG->SetALabel(_T(
"VMG"));
120 m_pitemBoxSizerLeg->Add(pVMG, 1, wxALIGN_LEFT | wxALL, 2);
122 pRNG =
new AnnunText(
this, -1, _(
"Console Legend"), _(
"Console Value"));
123 pRNG->SetALabel(_T(
"RNG"));
124 m_pitemBoxSizerLeg->Add(pRNG, 1, wxALIGN_LEFT | wxALL, 2);
126 pTTG =
new AnnunText(
this, -1, _(
"Console Legend"), _(
"Console Value"));
127 pTTG->SetALabel(_T(
"TTG @VMG"));
128 m_pitemBoxSizerLeg->Add(pTTG, 1, wxALIGN_LEFT | wxALL, 2);
132 pCDI =
new CDI(
this, -1, wxSIMPLE_BORDER, _T(
"CDI"));
133 m_pitemBoxSizerLeg->AddSpacer(5);
134 m_pitemBoxSizerLeg->Add(pCDI, 0, wxALL | wxEXPAND, 2);
136 SetSizer(m_pitemBoxSizerLeg);
137 m_pitemBoxSizerLeg->SetSizeHints(
this);
141 if (g_bShowRouteTotal)
142 pThisLegText->SetLabel(_(
"Route"));
144 pThisLegText->SetLabel(_(
"This Leg"));
149 ConsoleCanvas::~ConsoleCanvas() {
delete pCDI; }
151 void ConsoleCanvas::SetColorScheme(ColorScheme cs) {
152 pbackBrush = wxTheBrushList->FindOrCreateBrush(
153 GetGlobalColor(_T(
"DILG1" )), wxBRUSHSTYLE_SOLID);
154 SetBackgroundColour(GetGlobalColor(_T(
"DILG1" )));
156 if (g_bShowRouteTotal)
157 pThisLegText->SetLabel(_(
"Route"));
159 pThisLegText->SetLabel(_(
"This Leg"));
163 pThisLegText->SetBackgroundColour(GetGlobalColor(_T(
"DILG1" )));
165 pXTE->SetColorScheme(cs);
166 pBRG->SetColorScheme(cs);
167 pRNG->SetColorScheme(cs);
168 pTTG->SetColorScheme(cs);
169 pVMG->SetColorScheme(cs);
171 pCDI->SetColorScheme(cs);
174 void ConsoleCanvas::OnPaint(wxPaintEvent& event) {
177 if (g_pRouteMan->GetpActiveRoute()) {
179 pThisLegText->Refresh();
180 m_bNeedClear =
false;
186 if (!g_bShowActiveRouteHighway) pCDI->Hide();
189 void ConsoleCanvas::OnShow(wxShowEvent& event) {
190 pCDI->Show(g_bShowActiveRouteHighway);
191 m_pitemBoxSizerLeg->SetSizeHints(
this);
194 void ConsoleCanvas::LegRoute() {
195 if (g_bShowRouteTotal)
196 pThisLegText->SetLabel(_(
"Route"));
198 pThisLegText->SetLabel(_(
"This Leg"));
200 pThisLegText->Refresh(
true);
201 RefreshConsoleData();
204 void ConsoleCanvas::OnContextMenu(wxContextMenuEvent& event) {
205 wxMenu* contextMenu =
new wxMenu();
206 wxMenuItem* btnLeg =
new wxMenuItem(contextMenu, ID_NAVLEG, _(
"This Leg"),
207 _T(
""), wxITEM_RADIO);
208 wxMenuItem* btnRoute =
new wxMenuItem(contextMenu, ID_NAVROUTE,
209 _(
"Full Route"), _T(
""), wxITEM_RADIO);
210 wxMenuItem* btnHighw =
new wxMenuItem(
211 contextMenu, ID_NAVHIGHWAY, _(
"Show Highway"), _T(
""), wxITEM_CHECK);
212 contextMenu->Append(btnLeg);
213 contextMenu->Append(btnRoute);
214 contextMenu->AppendSeparator();
215 contextMenu->Append(btnHighw);
217 btnLeg->Check(!g_bShowRouteTotal);
218 btnRoute->Check(g_bShowRouteTotal);
219 btnHighw->Check(g_bShowActiveRouteHighway);
221 PopupMenu(contextMenu);
226 void ConsoleCanvas::OnContextMenuSelection(wxCommandEvent& event) {
227 switch (event.GetId()) {
229 g_bShowRouteTotal =
false;
234 g_bShowRouteTotal =
true;
238 case ID_NAVHIGHWAY: {
239 g_bShowActiveRouteHighway = !g_bShowActiveRouteHighway;
240 if (g_bShowActiveRouteHighway) {
245 m_pitemBoxSizerLeg->SetSizeHints(
this);
251 void ConsoleCanvas::ToggleRouteTotalDisplay() {
252 if (m_speedUsed == SPEED_VMG) {
253 m_speedUsed = SPEED_SOG;
255 m_speedUsed = SPEED_VMG;
256 g_bShowRouteTotal = !g_bShowRouteTotal;
261 void ConsoleCanvas::UpdateRouteData() {
264 if (g_pRouteMan->GetpActiveRoute()) {
265 if (g_pRouteMan->m_bDataValid) {
267 float rng = g_pRouteMan->GetCurrentRngToActivePoint();
270 float dcog = g_pRouteMan->GetCurrentBrgToActivePoint();
271 if (dcog >= 359.5) dcog = 0;
275 cogstr << wxString::Format(wxString(
"%6.0f", wxConvUTF8), dcog);
277 cogstr << wxString::Format(wxString(
"%6.0f(M)", wxConvUTF8),
280 pBRG->SetAValue(cogstr);
283 if (!std::isnan(gCog) && !std::isnan(gSog)) {
285 BRG = g_pRouteMan->GetCurrentBrgToActivePoint();
286 double vmg = gSog * cos((BRG - gCog) * PI / 180.);
287 str_buf.Printf(_T(
"%6.2f"), toUsrSpeed(vmg));
289 if (m_speedUsed == SPEED_VMG) {
300 pVMG->SetAValue(str_buf);
302 if (!g_bShowRouteTotal) {
303 float nrng = g_pRouteMan->GetCurrentRngToActiveNormalArrival();
305 double deltarng = fabs(rng - nrng);
306 if ((deltarng > .01) && ((deltarng / rng) > .10) &&
311 srng.Printf(_T(
"%5.2f/%5.2f"), toUsrDistance(rng),
312 toUsrDistance(nrng));
314 srng.Printf(_T(
"%5.1f/%5.1f"), toUsrDistance(rng),
315 toUsrDistance(nrng));
318 srng.Printf(_T(
"%6.2f"), toUsrDistance(rng));
320 srng.Printf(_T(
"%6.1f"), toUsrDistance(rng));
324 pRNG->SetAValue(srng);
328 toUsrDistance(g_pRouteMan->GetCurrentXTEToActivePoint()));
329 pXTE->SetAValue(str_buf);
330 if (g_pRouteMan->GetXTEDir() < 0)
331 pXTE->SetALabel(wxString(_(
"XTE L")));
333 pXTE->SetALabel(wxString(_(
"XTE R")));
338 if ((speed > 0.) && !std::isnan(gCog) && !std::isnan(gSog)) {
339 float ttg_sec = (rng / speed) * 3600.;
340 wxTimeSpan ttg_span(0, 0,
long(ttg_sec), 0);
341 ttg_s = ttg_span.Format();
345 pTTG->SetAValue(ttg_s);
346 if (m_speedUsed == SPEED_VMG) {
347 pTTG->SetALabel(wxString(_(
"TTG @VMG")));
349 pTTG->SetALabel(wxString(_(
"TTG @SOG")));
355 Route* prt = g_pRouteMan->GetpActiveRoute();
356 wxRoutePointListNode* node = (prt->pRoutePointList)->GetFirst();
361 prp = node->GetData();
362 if (n_addflag) trng += prp->m_seg_len;
364 if (prp == prt->m_pRouteActivePoint) n_addflag++;
366 node = node->GetNext();
372 strng.Printf(_T(
"%6.2f"), toUsrDistance(trng));
374 strng.Printf(_T(
"%6.1f"), toUsrDistance(trng));
376 pRNG->SetAValue(strng);
382 wxTimeSpan tttg_span;
383 float tttg_sec = 0.0;
385 tttg_sec = (trng / gSog) * 3600.;
386 tttg_span = wxTimeSpan::Seconds((
long)tttg_sec);
388 tttg_s = tttg_sec > SECONDS_PER_DAY ? tttg_span.Format(_(
"%Dd %H:%M"))
389 : tttg_span.Format(
"%H:%M:%S");
391 tttg_span = wxTimeSpan::Seconds(0);
395 pTTG->SetAValue(tttg_s);
398 wxDateTime dtnow, eta;
399 dtnow.SetToCurrent();
400 eta = dtnow.Add(tttg_span);
405 seta = tttg_sec > SECONDS_PER_DAY ? eta.Format(_T(
"%d/%m %H:%M"))
406 : eta.Format(_T(
"%H:%M"));
410 pXTE->SetAValue(seta);
411 if (m_speedUsed == SPEED_VMG) {
412 pTTG->SetALabel(wxString(_(
"TTG @VMG")));
413 pXTE->SetALabel(wxString(_(
"ETA @VMG")));
415 pTTG->SetALabel(wxString(_(
"TTG @SOG")));
416 pXTE->SetALabel(wxString(_(
"ETA @SOG")));
429 void ConsoleCanvas::RefreshConsoleData(
void) {
440 void ConsoleCanvas::ShowWithFreshFonts(
void) {
445 gFrame->PositionConsole();
449 void ConsoleCanvas::UpdateFonts(
void) {
450 pBRG->RefreshFonts();
451 pXTE->RefreshFonts();
452 pTTG->RefreshFonts();
453 pRNG->RefreshFonts();
454 pVMG->RefreshFonts();
456 m_pitemBoxSizerLeg->SetSizeHints(
this);
467 EVT_PAINT(AnnunText::OnPaint)
468 EVT_MOUSE_EVENTS(AnnunText::MouseEvent)
472 const wxString& LegendElement,
473 const wxString& ValueElement)
474 : wxWindow(parent,
id, wxDefaultPosition, wxDefaultSize, wxNO_BORDER) {
475 m_label = _T(
"Label");
476 m_value = _T(
"-----");
478 m_plabelFont = FontMgr::Get().FindOrCreateFont(
479 14, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE,
480 wxString(_T(
"Arial Bold")));
481 m_pvalueFont = FontMgr::Get().FindOrCreateFont(
482 24, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE,
483 wxString(_T(
"helvetica")), wxFONTENCODING_ISO8859_1);
485 m_LegendTextElement = LegendElement;
486 m_ValueTextElement = ValueElement;
491 AnnunText::~AnnunText() {}
492 void AnnunText::MouseEvent(wxMouseEvent& event) {
493 if (event.RightDown()) {
494 wxContextMenuEvent cevt;
495 cevt.SetPosition(event.GetPosition());
498 if (ccp) ccp->OnContextMenu(cevt);
500 }
else if (event.LeftDown()) {
503 ccp->ToggleRouteTotalDisplay();
508 void AnnunText::CalculateMinSize(
void) {
517 GetTextExtent(_T(
"1234"), &wl, &hl, NULL, NULL, m_plabelFont);
520 GetTextExtent(_T(
"123.4567"), &wv, &hv, NULL, NULL, m_pvalueFont);
522 double pdifactor = g_BasePlatform->GetDisplayDIPMult(gFrame);
523 wl *= pdifactor; hl *= pdifactor;
524 wv *= pdifactor; hv *= pdifactor;
534 min.y = (int)((hl + hv) * 1.2);
540 if (style->consoleTextBackground.IsOk()) {
541 wxImage img = style->consoleTextBackground.ConvertToImage();
542 style->consoleTextBackground = wxBitmap(img.Rescale(min.x, min.y));
546 void AnnunText::SetColorScheme(ColorScheme cs) {
548 m_backBrush = *wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T(
"UBLCK")),
551 m_default_text_color = style->consoleFontColor;
555 void AnnunText::RefreshFonts() {
556 wxFont *pl = FontMgr::Get().GetFont(m_LegendTextElement);
557 m_plabelFont = FontMgr::Get().FindOrCreateFont(
558 pl->GetPointSize() / OCPN_GetWinDIPScaleFactor(),
559 pl->GetFamily(), pl->GetStyle(),
560 pl->GetWeight(), FALSE,
563 wxFont *pv = FontMgr::Get().GetFont(m_ValueTextElement);
564 m_pvalueFont = FontMgr::Get().FindOrCreateFont(
565 pv->GetPointSize() / OCPN_GetWinDIPScaleFactor(),
566 pv->GetFamily(), pv->GetStyle(),
567 pv->GetWeight(), FALSE,
570 m_legend_color = FontMgr::Get().GetFontColor(_(
"Console Legend"));
571 m_val_color = FontMgr::Get().GetFontColor(_(
"Console Value"));
577 if (m_backBrush.IsOk()) {
578 wxColour back_color = m_backBrush.GetColour();
580 wxColour legend_color = m_legend_color;
581 if ((abs(legend_color.Red() - back_color.Red()) < 5) &&
582 (abs(legend_color.Green() - back_color.Blue()) < 5) &&
583 (abs(legend_color.Blue() - back_color.Blue()) < 5))
584 m_legend_color = m_default_text_color;
586 wxColour value_color = m_val_color;
587 if ((abs(value_color.Red() - back_color.Red()) < 5) &&
588 (abs(value_color.Green() - back_color.Blue()) < 5) &&
589 (abs(value_color.Blue() - back_color.Blue()) < 5))
590 m_val_color = m_default_text_color;
594 void AnnunText::SetLegendElement(
const wxString& element) {
595 m_LegendTextElement = element;
598 void AnnunText::SetValueElement(
const wxString& element) {
599 m_ValueTextElement = element;
602 void AnnunText::SetALabel(
const wxString& l) { m_label = l; }
604 void AnnunText::SetAValue(
const wxString& v) { m_value = v; }
606 void AnnunText::OnPaint(wxPaintEvent& event) {
608 GetClientSize(&sx, &sy);
615 wxBitmap m_bitmap(sx, sy, -1);
616 mdc.SelectObject(m_bitmap);
617 mdc.SetBackground(m_backBrush);
620 if (style->consoleTextBackground.IsOk())
621 mdc.DrawBitmap(style->consoleTextBackground, 0, 0);
623 mdc.SetTextForeground(m_default_text_color);
626 mdc.SetFont(*m_plabelFont);
627 mdc.SetTextForeground(m_legend_color);
628 mdc.DrawText(m_label, 5, 2);
632 mdc.SetFont(*m_pvalueFont);
633 mdc.SetTextForeground(m_val_color);
636 mdc.GetTextExtent(m_value, &w, &h);
638 mdc.GetSize(&cw, &ch);
640 mdc.DrawText(m_value, cw - w - 2, ch - h - 2);
644 dc.Blit(0, 0, sx, sy, &mdc, 0, 0);
649 BEGIN_EVENT_TABLE(
CDI, wxWindow)
651 EVT_MOUSE_EVENTS(CDI::MouseEvent)
654 CDI::
CDI(wxWindow* parent, wxWindowID
id,
long style, const wxString& name)
655 : wxWindow(parent,
id, wxDefaultPosition, wxDefaultSize, style, name)
658 SetMinSize(wxSize(10, 150));
661 void CDI::MouseEvent(wxMouseEvent& event) {
663 if (event.RightDown()) {
664 qDebug() <<
"right down";
666 wxContextMenuEvent cevt;
667 cevt.SetPosition(event.GetPosition());
670 if (ccp) ccp->OnContextMenu(cevt);
675 void CDI::SetColorScheme(ColorScheme cs) {
676 m_pbackBrush = wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T(
"DILG2")),
678 m_proadBrush = wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T(
"DILG1")),
680 m_proadPen = wxThePenList->FindOrCreatePen(GetGlobalColor(_T(
"CHBLK")), 1,
686 GetClientSize(&sx, &sy);
692 wxBitmap m_bitmap(sx, sy, -1);
693 mdc.SelectObject(m_bitmap);
694 mdc.SetBackground(*m_pbackBrush);
698 int yp = sy * 9 / 10;
700 int path_length = sy * 3;
701 int pix_per_xte = 120;
703 if (g_pRouteMan->GetpActiveRoute()) {
704 double angle = 90 - (g_pRouteMan->GetCurrentSegmentCourse() - gCog);
706 double dy = path_length * sin(angle * PI / 180.);
707 double dx = path_length * cos(angle * PI / 180.);
710 xtedir = g_pRouteMan->GetXTEDir();
711 double xte = g_pRouteMan->GetCurrentXTEToActivePoint();
713 double ddy = xtedir * pix_per_xte * xte * sin((90 - angle) * PI / 180.);
714 double ddx = xtedir * pix_per_xte * xte * cos((90 - angle) * PI / 180.);
719 int xc1 = xp - (int)(dx / 2) + ddxi;
720 int yc1 = yp + (int)(dy / 2) + ddyi;
721 int xc2 = xp + (int)(dx / 2) + ddxi;
722 int yc2 = yp - (int)(dy / 2) + ddyi;
726 int road_top_width = 10;
727 int road_bot_width = 40;
729 road[0].x = xc1 - (int)(road_bot_width * cos((90 - angle) * PI / 180.));
730 road[0].y = yc1 - (int)(road_bot_width * sin((90 - angle) * PI / 180.));
732 road[1].x = xc2 - (int)(road_top_width * cos((90 - angle) * PI / 180.));
733 road[1].y = yc2 - (int)(road_top_width * sin((90 - angle) * PI / 180.));
735 road[2].x = xc2 + (int)(road_top_width * cos((90 - angle) * PI / 180.));
736 road[2].y = yc2 + (int)(road_top_width * sin((90 - angle) * PI / 180.));
738 road[3].x = xc1 + (int)(road_bot_width * cos((90 - angle) * PI / 180.));
739 road[3].y = yc1 + (int)(road_bot_width * sin((90 - angle) * PI / 180.));
741 mdc.SetBrush(*m_proadBrush);
742 mdc.SetPen(*m_proadPen);
743 mdc.DrawPolygon(4, road, 0, 0, wxODDEVEN_RULE);
747 mdc.DrawLine(0, yp, sx, yp);
748 mdc.DrawCircle(xp, yp, 6);
749 mdc.DrawLine(xp, yp + 5, xp, yp - 5);
753 dc.Blit(0, 0, sx, sy, &mdc, 0, 0);
void OnPaint(wxPaintEvent &event)
General purpose GUI support.