31#include <wx/dcbuffer.h>
32#include <wx/listctrl.h>
56#include "user_colors.h"
58extern ColorScheme global_color_scheme;
64 SetMinSize(wxSize(400, 200));
65 Bind(wxEVT_PAINT, &TideChartPanel::OnPaint,
this);
66 Bind(wxEVT_MOTION, &TideChartPanel::OnMouseMove,
this);
67 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
74 dc.GetTextExtent(
"W", NULL, &text_height);
75 m_refTCWTextHeight = text_height;
79 void OnPaint(wxPaintEvent &event) {
83 dc.SetBackground(wxBrush(GetBackgroundColour()));
87 wxSize panelSize = GetClientSize();
88 if (panelSize.GetWidth() <= 0 || panelSize.GetHeight() <= 0) {
94 int other_margins = 5;
95 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
96 int chart_height = panelSize.GetHeight() - (2 * other_margins);
99 int bottom_text_space = 4 * m_refTCWTextHeight;
100 chart_height -= bottom_text_space;
101 chart_width = wxMax(chart_width, 300);
102 chart_height = wxMax(chart_height, 150);
103 wxRect chartRect(left_margin, other_margins, chart_width, chart_height);
106 m_tcWin->PaintChart(dc, chartRect);
109 void OnMouseMove(wxMouseEvent &event) {
110 wxPoint panelPos =
event.GetPosition();
111 wxPoint mainWindowPos = panelPos + GetPosition();
112 m_tcWin->HandleChartMouseMove(mainWindowPos.x, mainWindowPos.y, panelPos);
117 int m_refTCWTextHeight;
120enum { ID_TCWIN_NX, ID_TCWIN_PR };
122enum { TIDE_PLOT, CURRENT_PLOT };
124BEGIN_EVENT_TABLE(
TCWin, wxWindow)
125EVT_PAINT(TCWin::OnPaint)
126EVT_SIZE(TCWin::OnSize)
127EVT_MOTION(TCWin::MouseEvent)
128EVT_BUTTON(wxID_OK, TCWin::OKEvent)
129EVT_BUTTON(ID_TCWIN_NX, TCWin::NXEvent)
130EVT_BUTTON(ID_TCWIN_PR, TCWin::PREvent)
131EVT_CLOSE(TCWin::OnCloseWindow)
132EVT_TIMER(TCWININF_TIMER, TCWin::OnTCWinPopupTimerEvent)
133EVT_TIMER(TCWIN_TIME_INDICATOR_TIMER, TCWin::OnTimeIndicatorTimer)
142 m_pTCRolloverWin = NULL;
144 long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER |
145 wxFRAME_FLOAT_ON_PARENT;
155 pConfig->SetPath(
"/Settings/Others");
156 pConfig->Read(
"TCWindowTimeZone", &m_tzoneDisplay, 0);
159 wxFrame::Create(parent, wxID_ANY, wxString(
""), m_position, m_tc_size,
169 if (strchr(
"Tt", pIDX->IDX_type)) {
170 m_plot_type = TIDE_PLOT;
171 SetTitle(wxString(_(
"Tide")));
174 m_plot_type = CURRENT_PLOT;
175 SetTitle(wxString(_(
"Current")));
179 GetClientSize(&sx, &sy);
189 dc.GetTextExtent(
"W", NULL, &text_height);
190 m_refTextHeight = text_height;
194 m_graph_rect = wxRect(0, 0, 400, 200);
197 wxButton *test_button =
198 new wxButton(
this, wxID_OK, _(
"OK"), wxPoint(-1, -1), wxDefaultSize);
199 test_button->GetSize(&m_tsx, &m_tsy);
202 m_TCWinPopupTimer.SetOwner(
this, TCWININF_TIMER);
205 m_TimeIndicatorTimer.SetOwner(
this, TCWIN_TIME_INDICATOR_TIMER);
206 m_TimeIndicatorTimer.Start(60000,
false);
208 m_button_height = m_tsy;
212 wxFont *dlg_font = FontMgr::Get().
GetFont(_(
"Dialog"));
213 int dlg_font_size = dlg_font->GetPointSize();
214#if defined(__WXOSX__) || defined(__WXGTK3__)
216 dlg_font_size /= GetContentScaleFactor();
220 dlg_font_size - 2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
221 wxFONTWEIGHT_NORMAL, FALSE, wxString(
"Arial"));
223 dlg_font_size - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
224 wxFONTWEIGHT_NORMAL, FALSE, wxString(
"Arial"));
226 dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
227 FALSE, wxString(
"Arial"));
229 dlg_font_size + 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
230 wxFONTWEIGHT_BOLD, FALSE, wxString(
"Arial"));
233 pblack_1 = wxThePenList->FindOrCreatePen(
234 this->GetForegroundColour(), wxMax(1, (
int)(m_tcwin_scaler + 0.5)),
237 pblack_2 = wxThePenList->FindOrCreatePen(
238 this->GetForegroundColour(), wxMax(2, (
int)(2 * m_tcwin_scaler + 0.5)),
241 pblack_3 = wxThePenList->FindOrCreatePen(
242 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
243 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
246 pred_2 = wxThePenList->FindOrCreatePen(
247 wxColor(230, 54, 54), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
251 pred_time = wxThePenList->FindOrCreatePen(
252 wxColour(0, 100, 255), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
255 pltgray = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
258 pltgray2 = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
260 pgraph = wxThePenList->FindOrCreatePen(
261 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
262 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
267 InitializeStationText();
274 m_TimeIndicatorTimer.Stop();
275 pParent->Refresh(
false);
278void TCWin::CreateLayout() {
280 wxBoxSizer *mainSizer =
new wxBoxSizer(wxVERTICAL);
283 m_topPanel =
new wxPanel(
this, wxID_ANY);
284 wxBoxSizer *topSizer =
new wxBoxSizer(wxHORIZONTAL);
288 new wxTextCtrl(m_topPanel, -1,
"", wxDefaultPosition, wxDefaultSize,
289 wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
290 m_ptextctrl->SetMinSize(wxSize(
291 25 * m_refTextHeight, 7 * m_refTextHeight));
294 m_tList =
new wxListCtrl(m_topPanel, -1, wxDefaultPosition, wxDefaultSize,
295 wxLC_REPORT | wxLC_NO_HEADER);
297 wxSize(18 * m_refTextHeight,
298 4 * m_refTextHeight));
304 col0.SetAlign(wxLIST_FORMAT_LEFT);
305 col0.SetWidth(20 * m_refTextHeight);
306 m_tList->InsertColumn(0, col0);
309 topSizer->Add(m_ptextctrl, 2, wxEXPAND | wxALL,
311 topSizer->Add(m_tList, 1, wxEXPAND | wxALL, 5);
313 m_topPanel->SetSizer(topSizer);
316 m_chartPanel =
new TideChartPanel(
this);
319 m_buttonPanel =
new wxPanel(
this, wxID_ANY);
320 wxBoxSizer *buttonSizer =
new wxBoxSizer(wxHORIZONTAL);
323 PR_button =
new wxButton(m_buttonPanel, ID_TCWIN_PR, _(
"Prev"));
324 NX_button =
new wxButton(m_buttonPanel, ID_TCWIN_NX, _(
"Next"));
325 OK_button =
new wxButton(m_buttonPanel, wxID_OK, _(
"OK"));
328 wxString choiceOptions[] = {_(
"LMT@Station"), _(
"UTC")};
329 int numChoices =
sizeof(choiceOptions) /
sizeof(wxString);
330 m_choiceTimezone =
new wxChoice(m_buttonPanel, wxID_ANY, wxDefaultPosition,
331 wxDefaultSize, numChoices, choiceOptions);
332 m_choiceTimezone->SetSelection(m_tzoneDisplay);
333 m_choiceTimezone->SetToolTip(
334 _(
"Select whether tide times are shown in UTC or Local Mean Time (LMT) "
338 buttonSizer->Add(PR_button, 0, wxALL, 5);
339 buttonSizer->Add(NX_button, 0, wxALL, 5);
340 buttonSizer->AddStretchSpacer(1);
341 buttonSizer->Add(m_choiceTimezone, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
342 buttonSizer->AddSpacer(10);
343 buttonSizer->Add(OK_button, 0, wxALL, 5);
345 m_buttonPanel->SetSizer(buttonSizer);
348 mainSizer->Add(m_topPanel, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP,
350 mainSizer->Add(m_chartPanel, 1, wxEXPAND | wxLEFT | wxRIGHT,
352 mainSizer->Add(m_buttonPanel, 0, wxEXPAND | wxALL,
359 m_choiceTimezone->Connect(wxEVT_COMMAND_CHOICE_SELECTED,
360 wxCommandEventHandler(TCWin::TimezoneOnChoice),
364void TCWin::InitializeStationText() {
366 m_ptextctrl->Clear();
369 wxString locna, locnb;
370 if (locn.Contains(wxString(
","))) {
371 locna = locn.BeforeFirst(
',');
372 locnb = locn.AfterFirst(
',');
380 style.SetFont(*pLFont);
381 m_ptextctrl->SetDefaultStyle(style);
383 m_ptextctrl->AppendText(locna);
384 m_ptextctrl->AppendText(
"\n");
386 style.SetFont(*pSMFont);
387 m_ptextctrl->SetDefaultStyle(style);
389 if (!locnb.IsEmpty()) m_ptextctrl->AppendText(locnb);
390 m_ptextctrl->AppendText(
"\n");
397 m_ptextctrl->AppendText(_(
"Reference Station :"));
398 m_ptextctrl->AppendText(
"\n");
400 m_ptextctrl->AppendText(mref);
401 m_ptextctrl->AppendText(
"\n");
404 m_ptextctrl->AppendText(
"\n");
409 dsource.Prepend(
" ");
411 m_ptextctrl->AppendText(_(
"Data Source :"));
412 m_ptextctrl->AppendText(
"\n");
414 m_ptextctrl->AppendText(dsource);
416 m_ptextctrl->ShowPosition(0);
419void TCWin::PaintChart(wxDC &dc,
const wxRect &chartRect) {
425 wxRect originalGraphRect = m_graph_rect;
426 m_graph_rect = chartRect;
433 if (m_graph_rect.x == 0) {
434 m_graph_rect = originalGraphRect;
440 GetClientSize(&x, &y);
443 pblack_1->SetColour(this->GetForegroundColour());
444 pblack_2->SetColour(this->GetForegroundColour());
445 pltgray->SetColour(this->GetBackgroundColour());
446 pltgray2->SetColour(this->GetBackgroundColour());
448 GetGlobalColor(
"URED"));
449 pred_time->SetColour(
450 GetGlobalColor(
"UINFB"));
453 dc.SetPen(*pblack_1);
454 dc.SetBrush(*pltgray);
455 dc.DrawRectangle(m_graph_rect.x, m_graph_rect.y, m_graph_rect.width,
456 m_graph_rect.height);
461 const int hour_delta = 4;
463 const int hour_delta = 1;
470 for (i = 0; i < 25; i++) {
471 int xd = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
472 if (hour_delta != 1) {
473 if (i % hour_delta == 0) {
474 dc.SetPen(*pblack_2);
475 dc.DrawLine(xd, m_graph_rect.y, xd,
476 m_graph_rect.y + m_graph_rect.height + 5);
478 int hour_show = hour_start + i;
479 if (hour_show >= 24) hour_show -= 24;
480 sprintf(sbuf,
"%02d", hour_show);
482 dc.DrawText(wxString(sbuf, wxConvUTF8),
483 xd + x_shim + (m_graph_rect.width / 25) / 2,
484 m_graph_rect.y + m_graph_rect.height + 8);
486 dc.SetPen(*pblack_1);
487 dc.DrawLine(xd, m_graph_rect.y, xd,
488 m_graph_rect.y + m_graph_rect.height + 5);
491 dc.SetPen(*pblack_1);
492 dc.DrawLine(xd, m_graph_rect.y, xd,
493 m_graph_rect.y + m_graph_rect.height + 5);
495 sst.Printf(
"%02d", i);
496 dc.DrawRotatedText(sst, xd + (m_graph_rect.width / 25) / 2,
497 m_graph_rect.y + m_graph_rect.height + 8, 270.);
502 wxDateTime system_now = wxDateTime::Now();
503 wxDateTime this_now = gTimeSource;
504 bool cur_time = !gTimeSource.IsValid();
505 if (cur_time) this_now = wxDateTime::Now();
508 time_t t_system_now = system_now.GetTicks();
509 t_system_now -= m_diff_mins * 60;
510 if (m_tzoneDisplay == 0)
511 t_system_now += m_stationOffset_mins * 60;
513 float t_system_ratio =
514 m_graph_rect.width * (t_system_now - m_t_graphday_GMT) / (25 * 3600.0f);
515 int x_system = (t_system_ratio < 0 || t_system_ratio > m_graph_rect.width)
517 : m_graph_rect.x + (int)t_system_ratio;
521 dc.DrawLine(x_system, m_graph_rect.y, x_system,
522 m_graph_rect.y + m_graph_rect.height);
527 if (gTimeSource.IsValid()) {
528 time_t t_selected_time = gTimeSource.GetTicks();
529 if (abs(t_selected_time - t_system_now) > 300) {
530 t_selected_time -= m_diff_mins * 60;
531 if (m_tzoneDisplay == 0)
532 t_selected_time += m_stationOffset_mins * 60;
534 float t_selected_time_ratio = m_graph_rect.width *
535 (t_selected_time - m_t_graphday_GMT) /
537 int x_selected_time = (t_selected_time_ratio < 0 ||
538 t_selected_time_ratio > m_graph_rect.width)
540 : m_graph_rect.x + (int)t_selected_time_ratio;
542 if (x_selected_time >= 0) {
543 dc.SetPen(*pred_time);
544 dc.DrawLine(x_selected_time, m_graph_rect.y, x_selected_time,
545 m_graph_rect.y + m_graph_rect.height);
549 dc.SetPen(*pblack_1);
557 m_tList->DeleteAllItems();
565 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
567 if (m_tzoneDisplay == 0)
568 tt_localtz -= m_stationOffset_mins * 60;
571 ptcmgr->GetTideFlowSens(tt_localtz, BACKWARD_TEN_MINUTES_STEP,
574 for (i = 0; i < 26; i++) {
575 int tt = tt_localtz + (i * FORWARD_ONE_HOUR_STEP);
583 int unit_c = TCDataFactory::findunit(pmsd->unit);
585 tcv[i] = tcv[i] * TCDataFactory::known_units[unit_c].conv_factor;
591 if (tcv[i] > tcmax) tcmax = tcv[i];
592 if (tcv[i] < tcmin) tcmin = tcv[i];
594 if (TIDE_PLOT == m_plot_type) {
595 if (!((tcv[i] > val) == wt) && (i > 0)) {
598 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
599 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
601 if (tctime > tt_localtz) {
605 tcd.Set(tctime - (m_diff_mins * 60));
606 if (m_tzoneDisplay == 0)
607 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
609 s.Printf(tcd.Format(
"%H:%M "));
613 double tcvalue_converted = tcvalue;
617 int unit_c = TCDataFactory::findunit(pmsd->unit);
621 TCDataFactory::known_units[unit_c].conv_factor;
624 tcvalue_converted =
toUsrHeight(tcvalue_converted);
627 s1.Printf(
"%05.2f ", tcvalue_converted);
631 (wt) ? s.Append(_(
"HW")) : s.Append(_(
"LW"));
634 li.SetId(list_index);
635 li.SetAlign(wxLIST_FORMAT_LEFT);
638 m_tList->InsertItem(li);
645 if (CURRENT_PLOT == m_plot_type) {
648 thx.Set((time_t)tt - (m_diff_mins * 60));
649 if (m_tzoneDisplay == 0)
650 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
652 s.Printf(thx.Format(
"%H:%M "));
657 s1.Printf(
" %03.0f", dir);
661 li.SetId(list_index);
662 li.SetAlign(wxLIST_FORMAT_LEFT);
665 m_tList->InsertItem(li);
673 if (CURRENT_PLOT == m_plot_type) {
674 it = std::max(abs((
int)tcmin - 1), abs((
int)tcmax + 1));
677 m_plot_y_offset = m_graph_rect.height / 2;
681 if (tcmin < 0) ib -= 1;
684 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
691 dc.GetTextExtent(
"1", NULL, &height_stext);
692 float available_lines = (float)m_graph_rect.height / height_stext;
693 i_skip = (int)ceil(im / available_lines);
695 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
703 for (
auto it = m_sList.begin(); it != m_sList.end(); it++)
delete (*it);
706 for (i = 0; i < 26; i++) {
707 wxPoint *pp =
new wxPoint;
708 pp->x = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
709 pp->y = m_graph_rect.y + (m_plot_y_offset) -
710 (
int)((tcv[i] - val_off) * m_graph_rect.height / im);
711 m_sList.push_back(pp);
718 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
723 int yd = m_graph_rect.y + (m_plot_y_offset) -
724 ((i - val_off) * m_graph_rect.height / im);
725 if ((m_plot_y_offset + m_graph_rect.y) == yd)
726 dc.SetPen(*pblack_2);
728 dc.SetPen(*pblack_1);
730 dc.DrawLine(m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd);
731 if ((yd < m_graph_rect.height * 48 / 100) ||
732 (yd > m_graph_rect.height * 52 / 100)) {
733 snprintf(sbuf, 99,
"%d", i);
734 dc.DrawText(wxString(sbuf, wxConvUTF8), m_graph_rect.x - 20, yd - 5);
741 for (
auto &p : m_sList) list.Append(p);
745 dc.DrawSpline(&list);
751 if (m_tzoneDisplay == 0) {
752 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
753 int h = station_offset / 60;
754 int m = station_offset - (h * 60);
755 if (m_graphday.IsDST()) h += 1;
756 m_stz.Printf(
"UTC %+03d:%02d", h, m);
760 double lat =
ptcmgr->GetStationLat(pIDX);
763 switch (
ptcmgr->GetStationTimeOffset(pIDX)) {
775 if (m_graphday.IsDST()) mtz[1] =
'D';
785 dc.GetTextExtent(m_stz, &w, &h);
787 dc.DrawText(m_stz, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
788 m_graph_rect.y + m_graph_rect.height + (2 * h));
791 if (g_locale ==
"en_US")
792 sdate = m_graphday.Format(
"%A %b %d, %Y");
794 sdate = m_graphday.Format(
"%A %d %b %Y");
797 dc.GetTextExtent(sdate, &w, &h);
799 dc.DrawText(sdate, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
800 m_graph_rect.y + m_graph_rect.height + (5 * h / 2));
806 dc.GetTextExtent(height_unit, &w, &h);
807 dc.DrawRotatedText(height_unit, 0,
808 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
816 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
817 m_graph_rect.y + m_graph_rect.height * 1 / 4);
821 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
822 m_graph_rect.y + m_graph_rect.height * 3 / 4);
826 if ((m_button_height * 15) < x && cur_time) {
828 int day = m_graphday.GetDayOfYear();
829 if (m_graphday.GetYear() == this_now.GetYear()) {
830 if (day == this_now.GetDayOfYear())
831 sday.Append(_(
"Today"));
832 else if (day == this_now.GetDayOfYear() + 1)
833 sday.Append(_(
"Tomorrow"));
835 sday.Append(m_graphday.GetWeekDayName(m_graphday.GetWeekDay()));
836 }
else if (m_graphday.GetYear() == this_now.GetYear() + 1 &&
837 day == this_now.Add(wxTimeSpan::Day()).GetDayOfYear())
838 sday.Append(_(
"Tomorrow"));
841 dc.GetTextExtent(sday, &w, &h);
843 dc.DrawText(sday, m_graph_rect.x,
844 m_graph_rect.y + m_graph_rect.height + (2 * h));
848 double spotDim = 4 * g_Platform->GetDisplayDPmm();
849 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"YELO1"),
850 wxBRUSHSTYLE_SOLID));
851 dc.SetPen(wxPen(GetGlobalColor(
"URED"),
852 wxMax(2, 0.5 * g_Platform->GetDisplayDPmm())));
853 dc.DrawRoundedRectangle(xSpot - spotDim / 2, ySpot - spotDim / 2, spotDim,
854 spotDim, spotDim / 2);
856 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"UBLCK"),
857 wxBRUSHSTYLE_SOLID));
858 dc.SetPen(wxPen(GetGlobalColor(
"UBLCK"), 1));
859 double ispotDim = spotDim / 5.;
860 dc.DrawRoundedRectangle(xSpot - ispotDim / 2, ySpot - ispotDim / 2, ispotDim,
861 ispotDim, ispotDim / 2);
864 m_graph_rect = originalGraphRect;
867void TCWin::SetTimeFactors() {
869 wxDateTime this_now = gTimeSource;
870 bool cur_time = !gTimeSource.IsValid();
873 this_now = wxDateTime::Now();
875 wxDateTime this_gmt = this_now.ToGMT();
877#if wxCHECK_VERSION(2, 6, 2)
878 wxTimeSpan diff = this_now.Subtract(this_gmt);
880 wxTimeSpan diff = this_gmt.Subtract(this_now);
883 m_diff_mins = diff.GetMinutes();
888#if wxCHECK_VERSION(3, 0, 2)
889 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
892 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
894 m_stationOffset_mins = station_offset;
895 if (this_now.IsDST()) {
896 m_stationOffset_mins += 60;
902#if wxCHECK_VERSION(3, 0, 2)
909 m_graphday = this_gmt;
911 int day_gmt = this_gmt.GetDayOfYear();
913 time_t ttNow = this_now.GetTicks();
914 time_t tt_at_station =
915 ttNow - (m_diff_mins * 60) + (m_stationOffset_mins * 60);
916 wxDateTime atStation(tt_at_station);
917 int day_at_station = atStation.GetDayOfYear();
919 if (day_gmt > day_at_station) {
920 wxTimeSpan dt(24, 0, 0, 0);
921 m_graphday.Subtract(dt);
922 }
else if (day_gmt < day_at_station) {
923 wxTimeSpan dt(24, 0, 0, 0);
927 wxDateTime graphday_00 = m_graphday;
928 graphday_00.ResetTime();
929 time_t t_graphday_00 = graphday_00.GetTicks();
935 m_t_graphday_GMT = t_graphday_00;
940void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
941 m_tzoneDisplay = m_choiceTimezone->GetSelection();
947void TCWin::RecalculateSize() {
948 wxSize parent_size(2000, 2000);
949 if (pParent) parent_size = pParent->GetClientSize();
951 int unscaledheight = 600;
952 int unscaledwidth = 650;
958 g_tcwin_scale = wxMax(g_tcwin_scale, 10);
959 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
961 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
962 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
964 m_tc_size.x = wxMin(m_tc_size.x, parent_size.x);
965 m_tc_size.y = wxMin(m_tc_size.y, parent_size.y);
972 if ((m_x + 8 + m_tc_size.x) > parent_size.x) xc = xc - m_tc_size.x - 16;
973 if ((m_y + m_tc_size.y) > parent_size.y) yc = yc - m_tc_size.y;
979 if (pParent) pParent->ClientToScreen(&xc, &yc);
980 m_position = wxPoint(xc, yc);
988void TCWin::OKEvent(wxCommandEvent &event) {
992 if (pParent && pParent->pCwin ==
this) {
993 pParent->pCwin = NULL;
998 delete m_pTCRolloverWin;
999 m_pTCRolloverWin = NULL;
1004 pParent->Refresh(
false);
1009 pConfig->SetPath(
"/Settings/Others");
1010 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
1016void TCWin::OnCloseWindow(wxCloseEvent &event) {
1020 if (pParent && pParent->pCwin ==
this) {
1021 pParent->pCwin = NULL;
1026 delete m_pTCRolloverWin;
1027 m_pTCRolloverWin = NULL;
1033 pConfig->SetPath(
"/Settings/Others");
1034 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
1040void TCWin::NXEvent(wxCommandEvent &event) {
1041 wxTimeSpan dt(24, 0, 0, 0);
1043 wxDateTime dm = m_graphday;
1045 wxDateTime graphday_00 = dm.ResetTime();
1046 time_t t_graphday_00 = graphday_00.GetTicks();
1048 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1049 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1051 m_t_graphday_GMT = t_graphday_00;
1057void TCWin::PREvent(wxCommandEvent &event) {
1058 wxTimeSpan dt(-24, 0, 0, 0);
1060 wxDateTime dm = m_graphday;
1062 wxDateTime graphday_00 = dm.ResetTime();
1063 time_t t_graphday_00 = graphday_00.GetTicks();
1065 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1066 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1068 m_t_graphday_GMT = t_graphday_00;
1074void TCWin::RePosition() {
1081 pParent->ClientToScreen(&r.x, &r.y);
1085void TCWin::OnPaint(wxPaintEvent &event) {
1097 dc.SetBrush(wxBrush(GetBackgroundColour()));
1098 dc.SetPen(wxPen(GetBackgroundColour()));
1099 wxSize size = GetClientSize();
1100 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
1106void TCWin::OnSize(wxSizeEvent &event) {
1107 if (!m_created)
return;
1114 m_chartPanel->Refresh();
1124void TCWin::MouseEvent(wxMouseEvent &event) {
1127 event.GetPosition(&curs_x, &curs_y);
1129 if (!m_TCWinPopupTimer.IsRunning())
1130 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1133void TCWin::HandleChartMouseMove(
int mainWindowX,
int mainWindowY,
1134 const wxPoint &chartPanelPos) {
1137 curs_x = mainWindowX;
1138 curs_y = mainWindowY;
1143 wxSize panelSize = m_chartPanel->GetClientSize();
1144 int left_margin = 50;
1145 int other_margins = 5;
1146 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
1147 int chart_height = panelSize.GetHeight() - (2 * other_margins);
1148 int bottom_text_space = 50;
1149 chart_height -= bottom_text_space;
1150 chart_width = wxMax(chart_width, 300);
1151 chart_height = wxMax(chart_height, 150);
1154 wxPoint chartPanelPos = m_chartPanel->GetPosition();
1156 wxRect(chartPanelPos.x + left_margin, chartPanelPos.y + other_margins,
1157 chart_width, chart_height);
1160 if (!m_TCWinPopupTimer.IsRunning())
1161 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1164void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1168 GetClientSize(&x, &y);
1169 wxRegion cursorarea(m_graph_rect);
1170 if (cursorarea.Contains(curs_x, curs_y)) {
1171 ShowRollover =
true;
1172 SetCursor(*pParent->pCursorCross);
1173 if (NULL == m_pTCRolloverWin) {
1174 m_pTCRolloverWin =
new RolloverWin(
this, -1,
false);
1178 m_pTCRolloverWin->SetMousePropogation(1);
1179 m_pTCRolloverWin->Hide();
1187 (float)(curs_x - m_graph_rect.x) / (float)m_graph_rect.width;
1188 t = relativeX * 25.0f;
1191 t = wxMax(0.0f, wxMin(25.0f, t));
1193 int tt = m_t_graphday_GMT + (int)(t * 3600);
1198 p.Printf(thd.Format(
"%Hh %Mmn"));
1203 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1205 int ttv = tt_localtz + (int)(t * 3600);
1206 if (m_tzoneDisplay == 0) {
1207 ttv -= m_stationOffset_mins * 60;
1216 double t_converted = (t < 0 && CURRENT_PLOT == m_plot_type) ? -t : t;
1220 int unit_c = TCDataFactory::findunit(pmsd->unit);
1223 t_converted * TCDataFactory::known_units[unit_c].conv_factor;
1229 s.Printf(
"%3.2f ", t_converted);
1236 if (CURRENT_PLOT == m_plot_type) {
1237 s.Printf(
"%3.0f%c", d, 0x00B0);
1244 win_size.Set(x * 90 / 100, y * 80 / 100);
1246 m_pTCRolloverWin->SetString(p);
1247 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1249 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1250 m_pTCRolloverWin->Refresh();
1251 m_pTCRolloverWin->Show();
1259 for (
int i = 0; i < 26; i++) {
1260 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1267 if (m_sList.size() > 0 && idx > 0 && idx < (int)m_sList.size()) {
1269 auto it_a = m_sList.begin();
1270 std::advance(it_a, idx - 1);
1271 auto it_b = m_sList.begin();
1272 std::advance(it_b, idx);
1277 float pct = (curs_x - a->x) / (
float)((b->x - a->x));
1278 float dy = pct * (b->y - a->y);
1285 ySpot = m_graph_rect.y + m_graph_rect.height / 2;
1291 SetCursor(*pParent->pCursorArrow);
1292 ShowRollover =
false;
1295 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1296 m_pTCRolloverWin->Hide();
1300void TCWin::OnTimeIndicatorTimer(wxTimerEvent &event) {
Minimal ChartCanvas interfaces.
Generic Chart canvas base.
Minimal ChartCAnvas interface with very little dependencies.
ChartCanvas - Main chart display and interaction component.
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
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 an index entry for tidal and current data.
char IDX_type
Entry type identifier "TCtcIUu".
char IDX_reference_name[MAXNAMELEN]
Name of the reference station.
int IDX_flood_dir
Flood current direction (in degrees)
char IDX_station_name[MAXNAMELEN]
Name of the tidal or current station.
char source_ident[MAXNAMELEN]
Identifier of the source (typically file name)
int IDX_ebb_dir
Ebb current direction (in degrees)
double IDX_lat
Latitude of the station (in degrees, +North)
double IDX_lon
Longitude of the station (in degrees, +East)
Station_Data * pref_sta_data
Pointer to the reference station data.
int IDX_rec_num
Record number for multiple entries with same name.
Global variables stored in configuration file.
Extern C linked utilities.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MyConfig * pConfig
Global instance.
wxString getUsrHeightUnit(int unit)
Get the abbreviation for the preferred height unit.
double toUsrHeight(double m_height, int unit)
Convert height from meters to preferred height units.
Tide and current data container.
Tide and currents window.
TCMgr * ptcmgr
Global instance.
Tide and Current Manager @TODO Add original author copyright.
Timer identification constants.