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;
588 if (CURRENT_PLOT == m_plot_type)
589 tcv[i] = toUsrSpeed(tcv[i]);
594 if (tcv[i] > tcmax) tcmax = tcv[i];
595 if (tcv[i] < tcmin) tcmin = tcv[i];
597 if (TIDE_PLOT == m_plot_type) {
598 if (!((tcv[i] > val) == wt) && (i > 0)) {
601 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
602 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
604 if (tctime > tt_localtz) {
608 tcd.Set(tctime - (m_diff_mins * 60));
609 if (m_tzoneDisplay == 0)
610 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
612 s.Printf(tcd.Format(
"%H:%M "));
616 double tcvalue_converted = tcvalue;
620 int unit_c = TCDataFactory::findunit(pmsd->unit);
624 TCDataFactory::known_units[unit_c].conv_factor;
627 if (CURRENT_PLOT == m_plot_type)
628 tcvalue_converted = toUsrSpeed(tcvalue_converted);
630 tcvalue_converted =
toUsrHeight(tcvalue_converted);
633 s1.Printf(
"%05.2f ", tcvalue_converted);
637 (wt) ? s.Append(_(
"HW")) : s.Append(_(
"LW"));
640 li.SetId(list_index);
641 li.SetAlign(wxLIST_FORMAT_LEFT);
644 m_tList->InsertItem(li);
651 if (CURRENT_PLOT == m_plot_type) {
654 thx.Set((time_t)tt - (m_diff_mins * 60));
655 if (m_tzoneDisplay == 0)
656 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
658 s.Printf(thx.Format(
"%H:%M "));
662 s.Append(getUsrSpeedUnit());
663 s1.Printf(
" %03.0f", dir);
667 li.SetId(list_index);
668 li.SetAlign(wxLIST_FORMAT_LEFT);
671 m_tList->InsertItem(li);
679 if (CURRENT_PLOT == m_plot_type) {
680 it = std::max(abs((
int)tcmin - 1), abs((
int)tcmax + 1));
683 m_plot_y_offset = m_graph_rect.height / 2;
687 if (tcmin < 0) ib -= 1;
690 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
697 dc.GetTextExtent(
"1", NULL, &height_stext);
698 float available_lines = (float)m_graph_rect.height / height_stext;
699 i_skip = (int)ceil(im / available_lines);
701 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
709 for (
auto it = m_sList.begin(); it != m_sList.end(); it++)
delete (*it);
712 for (i = 0; i < 26; i++) {
713 wxPoint *pp =
new wxPoint;
714 pp->x = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
715 pp->y = m_graph_rect.y + (m_plot_y_offset) -
716 (
int)((tcv[i] - val_off) * m_graph_rect.height / im);
717 m_sList.push_back(pp);
724 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
729 int yd = m_graph_rect.y + (m_plot_y_offset) -
730 ((i - val_off) * m_graph_rect.height / im);
731 if ((m_plot_y_offset + m_graph_rect.y) == yd)
732 dc.SetPen(*pblack_2);
734 dc.SetPen(*pblack_1);
736 dc.DrawLine(m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd);
737 if ((yd < m_graph_rect.height * 48 / 100) ||
738 (yd > m_graph_rect.height * 52 / 100)) {
739 snprintf(sbuf, 99,
"%d", i);
740 dc.DrawText(wxString(sbuf, wxConvUTF8), m_graph_rect.x - 20, yd - 5);
747 for (
auto &p : m_sList) list.Append(p);
751 dc.DrawSpline(&list);
757 if (m_tzoneDisplay == 0) {
758 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
759 int h = station_offset / 60;
760 int m = station_offset - (h * 60);
761 if (m_graphday.IsDST()) h += 1;
762 m_stz.Printf(
"UTC %+03d:%02d", h, m);
766 double lat =
ptcmgr->GetStationLat(pIDX);
769 switch (
ptcmgr->GetStationTimeOffset(pIDX)) {
781 if (m_graphday.IsDST()) mtz[1] =
'D';
791 dc.GetTextExtent(m_stz, &w, &h);
793 dc.DrawText(m_stz, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
794 m_graph_rect.y + m_graph_rect.height + (2 * h));
797 if (g_locale ==
"en_US")
798 sdate = m_graphday.Format(
"%A %b %d, %Y");
800 sdate = m_graphday.Format(
"%A %d %b %Y");
803 dc.GetTextExtent(sdate, &w, &h);
805 dc.DrawText(sdate, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
806 m_graph_rect.y + m_graph_rect.height + (5 * h / 2));
810 if (CURRENT_PLOT == m_plot_type) {
812 wxString speed_unit = getUsrSpeedUnit();
813 dc.GetTextExtent(speed_unit, &w, &h);
814 dc.DrawRotatedText(speed_unit, 0,
815 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
819 dc.GetTextExtent(height_unit, &w, &h);
820 dc.DrawRotatedText(height_unit, 0,
821 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
830 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
831 m_graph_rect.y + m_graph_rect.height * 1 / 4);
835 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
836 m_graph_rect.y + m_graph_rect.height * 3 / 4);
840 if ((m_button_height * 15) < x && cur_time) {
842 int day = m_graphday.GetDayOfYear();
843 if (m_graphday.GetYear() == this_now.GetYear()) {
844 if (day == this_now.GetDayOfYear())
845 sday.Append(_(
"Today"));
846 else if (day == this_now.GetDayOfYear() + 1)
847 sday.Append(_(
"Tomorrow"));
849 sday.Append(m_graphday.GetWeekDayName(m_graphday.GetWeekDay()));
850 }
else if (m_graphday.GetYear() == this_now.GetYear() + 1 &&
851 day == this_now.Add(wxTimeSpan::Day()).GetDayOfYear())
852 sday.Append(_(
"Tomorrow"));
855 dc.GetTextExtent(sday, &w, &h);
857 dc.DrawText(sday, m_graph_rect.x,
858 m_graph_rect.y + m_graph_rect.height + (2 * h));
862 double spotDim = 4 * g_Platform->GetDisplayDPmm();
863 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"YELO1"),
864 wxBRUSHSTYLE_SOLID));
865 dc.SetPen(wxPen(GetGlobalColor(
"URED"),
866 wxMax(2, 0.5 * g_Platform->GetDisplayDPmm())));
867 dc.DrawRoundedRectangle(xSpot - spotDim / 2, ySpot - spotDim / 2, spotDim,
868 spotDim, spotDim / 2);
870 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"UBLCK"),
871 wxBRUSHSTYLE_SOLID));
872 dc.SetPen(wxPen(GetGlobalColor(
"UBLCK"), 1));
873 double ispotDim = spotDim / 5.;
874 dc.DrawRoundedRectangle(xSpot - ispotDim / 2, ySpot - ispotDim / 2, ispotDim,
875 ispotDim, ispotDim / 2);
878 m_graph_rect = originalGraphRect;
881void TCWin::SetTimeFactors() {
883 wxDateTime this_now = gTimeSource;
884 bool cur_time = !gTimeSource.IsValid();
887 this_now = wxDateTime::Now();
889 wxDateTime this_gmt = this_now.ToGMT();
891#if wxCHECK_VERSION(2, 6, 2)
892 wxTimeSpan diff = this_now.Subtract(this_gmt);
894 wxTimeSpan diff = this_gmt.Subtract(this_now);
897 m_diff_mins = diff.GetMinutes();
902#if wxCHECK_VERSION(3, 0, 2)
903 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
906 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
908 m_stationOffset_mins = station_offset;
909 if (this_now.IsDST()) {
910 m_stationOffset_mins += 60;
916#if wxCHECK_VERSION(3, 0, 2)
923 m_graphday = this_gmt;
925 int day_gmt = this_gmt.GetDayOfYear();
927 time_t ttNow = this_now.GetTicks();
928 time_t tt_at_station =
929 ttNow - (m_diff_mins * 60) + (m_stationOffset_mins * 60);
930 wxDateTime atStation(tt_at_station);
931 int day_at_station = atStation.GetDayOfYear();
933 if (day_gmt > day_at_station) {
934 wxTimeSpan dt(24, 0, 0, 0);
935 m_graphday.Subtract(dt);
936 }
else if (day_gmt < day_at_station) {
937 wxTimeSpan dt(24, 0, 0, 0);
941 wxDateTime graphday_00 = m_graphday;
942 graphday_00.ResetTime();
943 time_t t_graphday_00 = graphday_00.GetTicks();
949 m_t_graphday_GMT = t_graphday_00;
954void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
955 m_tzoneDisplay = m_choiceTimezone->GetSelection();
961void TCWin::RecalculateSize() {
962 wxSize parent_size(2000, 2000);
963 if (pParent) parent_size = pParent->GetClientSize();
965 int unscaledheight = 600;
966 int unscaledwidth = 650;
972 g_tcwin_scale = wxMax(g_tcwin_scale, 10);
973 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
975 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
976 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
978 m_tc_size.x = wxMin(m_tc_size.x, parent_size.x);
979 m_tc_size.y = wxMin(m_tc_size.y, parent_size.y);
986 if ((m_x + 8 + m_tc_size.x) > parent_size.x) xc = xc - m_tc_size.x - 16;
987 if ((m_y + m_tc_size.y) > parent_size.y) yc = yc - m_tc_size.y;
993 if (pParent) pParent->ClientToScreen(&xc, &yc);
994 m_position = wxPoint(xc, yc);
1002void TCWin::OKEvent(wxCommandEvent &event) {
1006 if (pParent && pParent->pCwin ==
this) {
1007 pParent->pCwin = NULL;
1012 delete m_pTCRolloverWin;
1013 m_pTCRolloverWin = NULL;
1018 pParent->Refresh(
false);
1023 pConfig->SetPath(
"/Settings/Others");
1024 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
1030void TCWin::OnCloseWindow(wxCloseEvent &event) {
1034 if (pParent && pParent->pCwin ==
this) {
1035 pParent->pCwin = NULL;
1040 delete m_pTCRolloverWin;
1041 m_pTCRolloverWin = NULL;
1047 pConfig->SetPath(
"/Settings/Others");
1048 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
1054void TCWin::NXEvent(wxCommandEvent &event) {
1055 wxTimeSpan dt(24, 0, 0, 0);
1057 wxDateTime dm = m_graphday;
1059 wxDateTime graphday_00 = dm.ResetTime();
1060 time_t t_graphday_00 = graphday_00.GetTicks();
1062 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1063 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1065 m_t_graphday_GMT = t_graphday_00;
1071void TCWin::PREvent(wxCommandEvent &event) {
1072 wxTimeSpan dt(-24, 0, 0, 0);
1074 wxDateTime dm = m_graphday;
1076 wxDateTime graphday_00 = dm.ResetTime();
1077 time_t t_graphday_00 = graphday_00.GetTicks();
1079 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1080 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1082 m_t_graphday_GMT = t_graphday_00;
1088void TCWin::RePosition() {
1095 pParent->ClientToScreen(&r.x, &r.y);
1099void TCWin::OnPaint(wxPaintEvent &event) {
1111 dc.SetBrush(wxBrush(GetBackgroundColour()));
1112 dc.SetPen(wxPen(GetBackgroundColour()));
1113 wxSize size = GetClientSize();
1114 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
1120void TCWin::OnSize(wxSizeEvent &event) {
1121 if (!m_created)
return;
1128 m_chartPanel->Refresh();
1138void TCWin::MouseEvent(wxMouseEvent &event) {
1141 event.GetPosition(&curs_x, &curs_y);
1143 if (!m_TCWinPopupTimer.IsRunning())
1144 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1147void TCWin::HandleChartMouseMove(
int mainWindowX,
int mainWindowY,
1148 const wxPoint &chartPanelPos) {
1151 curs_x = mainWindowX;
1152 curs_y = mainWindowY;
1157 wxSize panelSize = m_chartPanel->GetClientSize();
1158 int left_margin = 50;
1159 int other_margins = 5;
1160 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
1161 int chart_height = panelSize.GetHeight() - (2 * other_margins);
1162 int bottom_text_space = 50;
1163 chart_height -= bottom_text_space;
1164 chart_width = wxMax(chart_width, 300);
1165 chart_height = wxMax(chart_height, 150);
1168 wxPoint chartPanelPos = m_chartPanel->GetPosition();
1170 wxRect(chartPanelPos.x + left_margin, chartPanelPos.y + other_margins,
1171 chart_width, chart_height);
1174 if (!m_TCWinPopupTimer.IsRunning())
1175 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1178void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1182 GetClientSize(&x, &y);
1183 wxRegion cursorarea(m_graph_rect);
1184 if (cursorarea.Contains(curs_x, curs_y)) {
1185 ShowRollover =
true;
1186 SetCursor(*pParent->pCursorCross);
1187 if (NULL == m_pTCRolloverWin) {
1188 m_pTCRolloverWin =
new RolloverWin(
this, -1,
false);
1192 m_pTCRolloverWin->SetMousePropogation(1);
1193 m_pTCRolloverWin->Hide();
1201 (float)(curs_x - m_graph_rect.x) / (float)m_graph_rect.width;
1202 t = relativeX * 25.0f;
1205 t = wxMax(0.0f, wxMin(25.0f, t));
1207 int tt = m_t_graphday_GMT + (int)(t * 3600);
1212 p.Printf(thd.Format(
"%Hh %Mmn"));
1217 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1219 int ttv = tt_localtz + (int)(t * 3600);
1220 if (m_tzoneDisplay == 0) {
1221 ttv -= m_stationOffset_mins * 60;
1230 double t_converted = (t < 0 && CURRENT_PLOT == m_plot_type) ? -t : t;
1234 int unit_c = TCDataFactory::findunit(pmsd->unit);
1237 t_converted * TCDataFactory::known_units[unit_c].conv_factor;
1240 if (CURRENT_PLOT == m_plot_type)
1241 t_converted = toUsrSpeed(t_converted);
1246 s.Printf(
"%3.2f ", t_converted);
1250 if (CURRENT_PLOT == m_plot_type)
1251 p.Append(getUsrSpeedUnit());
1256 if (CURRENT_PLOT == m_plot_type) {
1257 s.Printf(
"%3.0f%c", d, 0x00B0);
1264 win_size.Set(x * 90 / 100, y * 80 / 100);
1266 m_pTCRolloverWin->SetString(p);
1267 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1269 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1270 m_pTCRolloverWin->Refresh();
1271 m_pTCRolloverWin->Show();
1279 for (
int i = 0; i < 26; i++) {
1280 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1287 if (m_sList.size() > 0 && idx > 0 && idx < (int)m_sList.size()) {
1289 auto it_a = m_sList.begin();
1290 std::advance(it_a, idx - 1);
1291 auto it_b = m_sList.begin();
1292 std::advance(it_b, idx);
1297 float pct = (curs_x - a->x) / (
float)((b->x - a->x));
1298 float dy = pct * (b->y - a->y);
1305 ySpot = m_graph_rect.y + m_graph_rect.height / 2;
1311 SetCursor(*pParent->pCursorArrow);
1312 ShowRollover =
false;
1315 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1316 m_pTCRolloverWin->Hide();
1320void 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.