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);
71 void OnPaint(wxPaintEvent &event) {
75 dc.SetBackground(wxBrush(GetBackgroundColour()));
79 wxSize panelSize = GetClientSize();
80 if (panelSize.GetWidth() <= 0 || panelSize.GetHeight() <= 0) {
86 int other_margins = 5;
87 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
88 int chart_height = panelSize.GetHeight() - (2 * other_margins);
91 int bottom_text_space = 50;
92 chart_height -= bottom_text_space;
93 chart_width = wxMax(chart_width, 300);
94 chart_height = wxMax(chart_height, 150);
95 wxRect chartRect(left_margin, other_margins, chart_width, chart_height);
98 m_tcWin->PaintChart(dc, chartRect);
101 void OnMouseMove(wxMouseEvent &event) {
102 wxPoint panelPos =
event.GetPosition();
103 wxPoint mainWindowPos = panelPos + GetPosition();
104 m_tcWin->HandleChartMouseMove(mainWindowPos.x, mainWindowPos.y, panelPos);
111enum { ID_TCWIN_NX, ID_TCWIN_PR };
113enum { TIDE_PLOT, CURRENT_PLOT };
115BEGIN_EVENT_TABLE(
TCWin, wxWindow)
116EVT_PAINT(TCWin::OnPaint)
117EVT_SIZE(TCWin::OnSize)
118EVT_MOTION(TCWin::MouseEvent)
119EVT_BUTTON(wxID_OK, TCWin::OKEvent)
120EVT_BUTTON(ID_TCWIN_NX, TCWin::NXEvent)
121EVT_BUTTON(ID_TCWIN_PR, TCWin::PREvent)
122EVT_CLOSE(TCWin::OnCloseWindow)
123EVT_TIMER(TCWININF_TIMER, TCWin::OnTCWinPopupTimerEvent)
124EVT_TIMER(TCWIN_TIME_INDICATOR_TIMER, TCWin::OnTimeIndicatorTimer)
133 m_pTCRolloverWin = NULL;
135 long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER |
136 wxFRAME_FLOAT_ON_PARENT;
146 pConfig->SetPath(
"/Settings/Others");
147 pConfig->Read(
"TCWindowTimeZone", &m_tzoneDisplay, 0);
150 wxFrame::Create(parent, wxID_ANY, wxString(
""), m_position, m_tc_size,
160 if (strchr(
"Tt", pIDX->IDX_type)) {
161 m_plot_type = TIDE_PLOT;
162 SetTitle(wxString(_(
"Tide")));
165 m_plot_type = CURRENT_PLOT;
166 SetTitle(wxString(_(
"Current")));
170 GetClientSize(&sx, &sy);
178 m_graph_rect = wxRect(0, 0, 400, 200);
181 wxButton *test_button =
182 new wxButton(
this, wxID_OK, _(
"OK"), wxPoint(-1, -1), wxDefaultSize);
183 test_button->GetSize(&m_tsx, &m_tsy);
186 m_TCWinPopupTimer.SetOwner(
this, TCWININF_TIMER);
189 m_TimeIndicatorTimer.SetOwner(
this, TCWIN_TIME_INDICATOR_TIMER);
190 m_TimeIndicatorTimer.Start(60000,
false);
195 dc.GetTextExtent(
"W", NULL, &text_height);
196 m_refTextHeight = text_height;
197 m_button_height = m_tsy;
201 wxFont *dlg_font = FontMgr::Get().
GetFont(_(
"Dialog"));
202 int dlg_font_size = dlg_font->GetPointSize();
203#if defined(__WXOSX__) || defined(__WXGTK3__)
205 dlg_font_size /= GetContentScaleFactor();
209 dlg_font_size - 2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
210 wxFONTWEIGHT_NORMAL, FALSE, wxString(
"Arial"));
212 dlg_font_size - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
213 wxFONTWEIGHT_NORMAL, FALSE, wxString(
"Arial"));
215 dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
216 FALSE, wxString(
"Arial"));
218 dlg_font_size + 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
219 wxFONTWEIGHT_BOLD, FALSE, wxString(
"Arial"));
222 pblack_1 = wxThePenList->FindOrCreatePen(
223 this->GetForegroundColour(), wxMax(1, (
int)(m_tcwin_scaler + 0.5)),
226 pblack_2 = wxThePenList->FindOrCreatePen(
227 this->GetForegroundColour(), wxMax(2, (
int)(2 * m_tcwin_scaler + 0.5)),
230 pblack_3 = wxThePenList->FindOrCreatePen(
231 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
232 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
235 pred_2 = wxThePenList->FindOrCreatePen(
236 wxColor(230, 54, 54), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
240 pred_time = wxThePenList->FindOrCreatePen(
241 wxColour(0, 100, 255), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
244 pltgray = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
247 pltgray2 = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
249 pgraph = wxThePenList->FindOrCreatePen(
250 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
251 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
256 InitializeStationText();
263 m_TimeIndicatorTimer.Stop();
264 pParent->Refresh(
false);
267void TCWin::CreateLayout() {
269 wxBoxSizer *mainSizer =
new wxBoxSizer(wxVERTICAL);
272 m_topPanel =
new wxPanel(
this, wxID_ANY);
273 wxBoxSizer *topSizer =
new wxBoxSizer(wxHORIZONTAL);
277 new wxTextCtrl(m_topPanel, -1,
"", wxDefaultPosition, wxDefaultSize,
278 wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
279 m_ptextctrl->SetMinSize(wxSize(200, 120));
282 m_tList =
new wxListCtrl(m_topPanel, -1, wxDefaultPosition, wxDefaultSize,
283 wxLC_REPORT | wxLC_NO_HEADER);
284 m_tList->SetMinSize(wxSize(150, 120));
290 col0.SetAlign(wxLIST_FORMAT_LEFT);
292 m_tList->InsertColumn(0, col0);
295 topSizer->Add(m_ptextctrl, 2, wxEXPAND | wxALL,
297 topSizer->Add(m_tList, 1, wxEXPAND | wxALL, 5);
299 m_topPanel->SetSizer(topSizer);
302 m_chartPanel =
new TideChartPanel(
this);
305 m_buttonPanel =
new wxPanel(
this, wxID_ANY);
306 wxBoxSizer *buttonSizer =
new wxBoxSizer(wxHORIZONTAL);
309 PR_button =
new wxButton(m_buttonPanel, ID_TCWIN_PR, _(
"Prev"));
310 NX_button =
new wxButton(m_buttonPanel, ID_TCWIN_NX, _(
"Next"));
311 OK_button =
new wxButton(m_buttonPanel, wxID_OK, _(
"OK"));
314 wxString choiceOptions[] = {_(
"LMT@Station"), _(
"UTC")};
315 int numChoices =
sizeof(choiceOptions) /
sizeof(wxString);
316 m_choiceTimezone =
new wxChoice(m_buttonPanel, wxID_ANY, wxDefaultPosition,
317 wxDefaultSize, numChoices, choiceOptions);
318 m_choiceTimezone->SetSelection(m_tzoneDisplay);
319 m_choiceTimezone->SetToolTip(
320 _(
"Select whether tide times are shown in UTC or Local Mean Time (LMT) "
324 buttonSizer->Add(PR_button, 0, wxALL, 5);
325 buttonSizer->Add(NX_button, 0, wxALL, 5);
326 buttonSizer->AddStretchSpacer(1);
327 buttonSizer->Add(m_choiceTimezone, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
328 buttonSizer->AddSpacer(10);
329 buttonSizer->Add(OK_button, 0, wxALL, 5);
331 m_buttonPanel->SetSizer(buttonSizer);
334 mainSizer->Add(m_topPanel, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP,
336 mainSizer->Add(m_chartPanel, 1, wxEXPAND | wxLEFT | wxRIGHT,
338 mainSizer->Add(m_buttonPanel, 0, wxEXPAND | wxALL,
345 m_choiceTimezone->Connect(wxEVT_COMMAND_CHOICE_SELECTED,
346 wxCommandEventHandler(TCWin::TimezoneOnChoice),
350void TCWin::InitializeStationText() {
352 m_ptextctrl->Clear();
355 wxString locna, locnb;
356 if (locn.Contains(wxString(
","))) {
357 locna = locn.BeforeFirst(
',');
358 locnb = locn.AfterFirst(
',');
366 style.SetFont(*pLFont);
367 m_ptextctrl->SetDefaultStyle(style);
369 m_ptextctrl->AppendText(locna);
370 m_ptextctrl->AppendText(
"\n");
372 style.SetFont(*pSMFont);
373 m_ptextctrl->SetDefaultStyle(style);
375 if (!locnb.IsEmpty()) m_ptextctrl->AppendText(locnb);
376 m_ptextctrl->AppendText(
"\n");
383 m_ptextctrl->AppendText(_(
"Reference Station :"));
384 m_ptextctrl->AppendText(
"\n");
386 m_ptextctrl->AppendText(mref);
387 m_ptextctrl->AppendText(
"\n");
390 m_ptextctrl->AppendText(
"\n");
395 dsource.Prepend(
" ");
397 m_ptextctrl->AppendText(_(
"Data Source :"));
398 m_ptextctrl->AppendText(
"\n");
400 m_ptextctrl->AppendText(dsource);
402 m_ptextctrl->ShowPosition(0);
405void TCWin::PaintChart(wxDC &dc,
const wxRect &chartRect) {
411 wxRect originalGraphRect = m_graph_rect;
412 m_graph_rect = chartRect;
419 if (m_graph_rect.x == 0) {
420 m_graph_rect = originalGraphRect;
426 GetClientSize(&x, &y);
429 pblack_1->SetColour(this->GetForegroundColour());
430 pblack_2->SetColour(this->GetForegroundColour());
431 pltgray->SetColour(this->GetBackgroundColour());
432 pltgray2->SetColour(this->GetBackgroundColour());
434 GetGlobalColor(
"URED"));
435 pred_time->SetColour(
436 GetGlobalColor(
"UINFB"));
439 dc.SetPen(*pblack_1);
440 dc.SetBrush(*pltgray);
441 dc.DrawRectangle(m_graph_rect.x, m_graph_rect.y, m_graph_rect.width,
442 m_graph_rect.height);
447 const int hour_delta = 4;
449 const int hour_delta = 1;
456 for (i = 0; i < 25; i++) {
457 int xd = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
458 if (hour_delta != 1) {
459 if (i % hour_delta == 0) {
460 dc.SetPen(*pblack_2);
461 dc.DrawLine(xd, m_graph_rect.y, xd,
462 m_graph_rect.y + m_graph_rect.height + 5);
464 int hour_show = hour_start + i;
465 if (hour_show >= 24) hour_show -= 24;
466 sprintf(sbuf,
"%02d", hour_show);
468 dc.DrawText(wxString(sbuf, wxConvUTF8),
469 xd + x_shim + (m_graph_rect.width / 25) / 2,
470 m_graph_rect.y + m_graph_rect.height + 8);
472 dc.SetPen(*pblack_1);
473 dc.DrawLine(xd, m_graph_rect.y, xd,
474 m_graph_rect.y + m_graph_rect.height + 5);
477 dc.SetPen(*pblack_1);
478 dc.DrawLine(xd, m_graph_rect.y, xd,
479 m_graph_rect.y + m_graph_rect.height + 5);
481 sst.Printf(
"%02d", i);
482 dc.DrawRotatedText(sst, xd + (m_graph_rect.width / 25) / 2,
483 m_graph_rect.y + m_graph_rect.height + 8, 270.);
488 wxDateTime system_now = wxDateTime::Now();
489 wxDateTime this_now = gTimeSource;
490 bool cur_time = !gTimeSource.IsValid();
491 if (cur_time) this_now = wxDateTime::Now();
494 time_t t_system_now = system_now.GetTicks();
495 t_system_now -= m_diff_mins * 60;
496 if (m_tzoneDisplay == 0)
497 t_system_now += m_stationOffset_mins * 60;
499 float t_system_ratio =
500 m_graph_rect.width * (t_system_now - m_t_graphday_GMT) / (25 * 3600.0f);
501 int x_system = (t_system_ratio < 0 || t_system_ratio > m_graph_rect.width)
503 : m_graph_rect.x + (int)t_system_ratio;
507 dc.DrawLine(x_system, m_graph_rect.y, x_system,
508 m_graph_rect.y + m_graph_rect.height);
513 if (gTimeSource.IsValid()) {
514 time_t t_selected_time = gTimeSource.GetTicks();
515 if (abs(t_selected_time - t_system_now) > 300) {
516 t_selected_time -= m_diff_mins * 60;
517 if (m_tzoneDisplay == 0)
518 t_selected_time += m_stationOffset_mins * 60;
520 float t_selected_time_ratio = m_graph_rect.width *
521 (t_selected_time - m_t_graphday_GMT) /
523 int x_selected_time = (t_selected_time_ratio < 0 ||
524 t_selected_time_ratio > m_graph_rect.width)
526 : m_graph_rect.x + (int)t_selected_time_ratio;
528 if (x_selected_time >= 0) {
529 dc.SetPen(*pred_time);
530 dc.DrawLine(x_selected_time, m_graph_rect.y, x_selected_time,
531 m_graph_rect.y + m_graph_rect.height);
535 dc.SetPen(*pblack_1);
543 m_tList->DeleteAllItems();
551 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
553 if (m_tzoneDisplay == 0)
554 tt_localtz -= m_stationOffset_mins * 60;
557 ptcmgr->GetTideFlowSens(tt_localtz, BACKWARD_TEN_MINUTES_STEP,
560 for (i = 0; i < 26; i++) {
561 int tt = tt_localtz + (i * FORWARD_ONE_HOUR_STEP);
569 int unit_c = TCDataFactory::findunit(pmsd->unit);
571 tcv[i] = tcv[i] * TCDataFactory::known_units[unit_c].conv_factor;
577 if (tcv[i] > tcmax) tcmax = tcv[i];
578 if (tcv[i] < tcmin) tcmin = tcv[i];
580 if (TIDE_PLOT == m_plot_type) {
581 if (!((tcv[i] > val) == wt) && (i > 0)) {
584 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
585 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
587 if (tctime > tt_localtz) {
591 tcd.Set(tctime - (m_diff_mins * 60));
592 if (m_tzoneDisplay == 0)
593 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
595 s.Printf(tcd.Format(
"%H:%M "));
599 double tcvalue_converted = tcvalue;
603 int unit_c = TCDataFactory::findunit(pmsd->unit);
607 TCDataFactory::known_units[unit_c].conv_factor;
610 tcvalue_converted =
toUsrHeight(tcvalue_converted);
613 s1.Printf(
"%05.2f ", tcvalue_converted);
617 (wt) ? s.Append(_(
"HW")) : s.Append(_(
"LW"));
620 li.SetId(list_index);
621 li.SetAlign(wxLIST_FORMAT_LEFT);
624 m_tList->InsertItem(li);
631 if (CURRENT_PLOT == m_plot_type) {
634 thx.Set((time_t)tt - (m_diff_mins * 60));
635 if (m_tzoneDisplay == 0)
636 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
638 s.Printf(thx.Format(
"%H:%M "));
643 s1.Printf(
" %03.0f", dir);
647 li.SetId(list_index);
648 li.SetAlign(wxLIST_FORMAT_LEFT);
651 m_tList->InsertItem(li);
659 if (CURRENT_PLOT == m_plot_type) {
660 it = std::max(abs((
int)tcmin - 1), abs((
int)tcmax + 1));
663 m_plot_y_offset = m_graph_rect.height / 2;
667 if (tcmin < 0) ib -= 1;
670 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
677 dc.GetTextExtent(
"1", NULL, &height_stext);
678 float available_lines = (float)m_graph_rect.height / height_stext;
679 i_skip = (int)ceil(im / available_lines);
681 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
689 for (
auto it = m_sList.begin(); it != m_sList.end(); it++)
delete (*it);
692 for (i = 0; i < 26; i++) {
693 wxPoint *pp =
new wxPoint;
694 pp->x = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
695 pp->y = m_graph_rect.y + (m_plot_y_offset) -
696 (
int)((tcv[i] - val_off) * m_graph_rect.height / im);
697 m_sList.push_back(pp);
704 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
709 int yd = m_graph_rect.y + (m_plot_y_offset) -
710 ((i - val_off) * m_graph_rect.height / im);
711 if ((m_plot_y_offset + m_graph_rect.y) == yd)
712 dc.SetPen(*pblack_2);
714 dc.SetPen(*pblack_1);
716 dc.DrawLine(m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd);
717 snprintf(sbuf, 99,
"%d", i);
718 dc.DrawText(wxString(sbuf, wxConvUTF8), m_graph_rect.x - 20, yd - 5);
724 for (
auto &p : m_sList) list.Append(p);
728 dc.DrawSpline(&list);
734 if (m_tzoneDisplay == 0) {
735 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
736 int h = station_offset / 60;
737 int m = station_offset - (h * 60);
738 if (m_graphday.IsDST()) h += 1;
739 m_stz.Printf(
"UTC %+03d:%02d", h, m);
743 double lat =
ptcmgr->GetStationLat(pIDX);
746 switch (
ptcmgr->GetStationTimeOffset(pIDX)) {
758 if (m_graphday.IsDST()) mtz[1] =
'D';
768 dc.GetTextExtent(m_stz, &w, &h);
770 dc.DrawText(m_stz, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
771 m_graph_rect.y + m_graph_rect.height + 35);
774 if (g_locale ==
"en_US")
775 sdate = m_graphday.Format(
"%A %b %d, %Y");
777 sdate = m_graphday.Format(
"%A %d %b %Y");
780 dc.GetTextExtent(sdate, &w, &h);
782 dc.DrawText(sdate, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
783 m_graph_rect.y + m_graph_rect.height + 15);
789 dc.GetTextExtent(height_unit, &w, &h);
790 dc.DrawRotatedText(height_unit, 5,
791 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
799 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
800 m_graph_rect.y + m_graph_rect.height * 1 / 4);
804 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
805 m_graph_rect.y + m_graph_rect.height * 3 / 4);
809 if ((m_button_height * 15) < x && cur_time) {
811 int day = m_graphday.GetDayOfYear();
812 if (m_graphday.GetYear() == this_now.GetYear()) {
813 if (day == this_now.GetDayOfYear())
814 sday.Append(_(
"Today"));
815 else if (day == this_now.GetDayOfYear() + 1)
816 sday.Append(_(
"Tomorrow"));
818 sday.Append(m_graphday.GetWeekDayName(m_graphday.GetWeekDay()));
819 }
else if (m_graphday.GetYear() == this_now.GetYear() + 1 &&
820 day == this_now.Add(wxTimeSpan::Day()).GetDayOfYear())
821 sday.Append(_(
"Tomorrow"));
824 dc.GetTextExtent(sday, &w, &h);
826 dc.DrawText(sday, m_graph_rect.x,
827 m_graph_rect.y + m_graph_rect.height + 15);
831 double spotDim = 4 * g_Platform->GetDisplayDPmm();
832 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"YELO1"),
833 wxBRUSHSTYLE_SOLID));
834 dc.SetPen(wxPen(GetGlobalColor(
"URED"),
835 wxMax(2, 0.5 * g_Platform->GetDisplayDPmm())));
836 dc.DrawRoundedRectangle(xSpot - spotDim / 2, ySpot - spotDim / 2, spotDim,
837 spotDim, spotDim / 2);
839 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"UBLCK"),
840 wxBRUSHSTYLE_SOLID));
841 dc.SetPen(wxPen(GetGlobalColor(
"UBLCK"), 1));
842 double ispotDim = spotDim / 5.;
843 dc.DrawRoundedRectangle(xSpot - ispotDim / 2, ySpot - ispotDim / 2, ispotDim,
844 ispotDim, ispotDim / 2);
847 m_graph_rect = originalGraphRect;
850void TCWin::SetTimeFactors() {
852 wxDateTime this_now = gTimeSource;
853 bool cur_time = !gTimeSource.IsValid();
856 this_now = wxDateTime::Now();
858 wxDateTime this_gmt = this_now.ToGMT();
860#if wxCHECK_VERSION(2, 6, 2)
861 wxTimeSpan diff = this_now.Subtract(this_gmt);
863 wxTimeSpan diff = this_gmt.Subtract(this_now);
866 m_diff_mins = diff.GetMinutes();
871#if wxCHECK_VERSION(3, 0, 2)
872 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
875 int station_offset =
ptcmgr->GetStationTimeOffset(pIDX);
877 m_stationOffset_mins = station_offset;
878 if (this_now.IsDST()) {
879 m_stationOffset_mins += 60;
885#if wxCHECK_VERSION(3, 0, 2)
892 m_graphday = this_gmt;
894 int day_gmt = this_gmt.GetDayOfYear();
896 time_t ttNow = this_now.GetTicks();
897 time_t tt_at_station =
898 ttNow - (m_diff_mins * 60) + (m_stationOffset_mins * 60);
899 wxDateTime atStation(tt_at_station);
900 int day_at_station = atStation.GetDayOfYear();
902 if (day_gmt > day_at_station) {
903 wxTimeSpan dt(24, 0, 0, 0);
904 m_graphday.Subtract(dt);
905 }
else if (day_gmt < day_at_station) {
906 wxTimeSpan dt(24, 0, 0, 0);
910 wxDateTime graphday_00 = m_graphday;
911 graphday_00.ResetTime();
912 time_t t_graphday_00 = graphday_00.GetTicks();
918 m_t_graphday_GMT = t_graphday_00;
923void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
924 m_tzoneDisplay = m_choiceTimezone->GetSelection();
930void TCWin::RecalculateSize() {
931 wxSize parent_size(2000, 2000);
932 if (pParent) parent_size = pParent->GetClientSize();
934 int unscaledheight = 600;
935 int unscaledwidth = 650;
941 g_tcwin_scale = wxMax(g_tcwin_scale, 10);
942 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
944 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
945 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
947 m_tc_size.x = wxMin(m_tc_size.x, parent_size.x);
948 m_tc_size.y = wxMin(m_tc_size.y, parent_size.y);
955 if ((m_x + 8 + m_tc_size.x) > parent_size.x) xc = xc - m_tc_size.x - 16;
956 if ((m_y + m_tc_size.y) > parent_size.y) yc = yc - m_tc_size.y;
962 if (pParent) pParent->ClientToScreen(&xc, &yc);
963 m_position = wxPoint(xc, yc);
971void TCWin::OKEvent(wxCommandEvent &event) {
975 if (pParent && pParent->pCwin ==
this) {
976 pParent->pCwin = NULL;
981 delete m_pTCRolloverWin;
982 m_pTCRolloverWin = NULL;
987 pParent->Refresh(
false);
992 pConfig->SetPath(
"/Settings/Others");
993 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
999void TCWin::OnCloseWindow(wxCloseEvent &event) {
1003 if (pParent && pParent->pCwin ==
this) {
1004 pParent->pCwin = NULL;
1009 delete m_pTCRolloverWin;
1010 m_pTCRolloverWin = NULL;
1016 pConfig->SetPath(
"/Settings/Others");
1017 pConfig->Write(
"TCWindowTimeZone", m_tzoneDisplay);
1023void TCWin::NXEvent(wxCommandEvent &event) {
1024 wxTimeSpan dt(24, 0, 0, 0);
1026 wxDateTime dm = m_graphday;
1028 wxDateTime graphday_00 = dm.ResetTime();
1029 time_t t_graphday_00 = graphday_00.GetTicks();
1031 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1032 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1034 m_t_graphday_GMT = t_graphday_00;
1040void TCWin::PREvent(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::RePosition() {
1064 pParent->ClientToScreen(&r.x, &r.y);
1068void TCWin::OnPaint(wxPaintEvent &event) {
1080 dc.SetBrush(wxBrush(GetBackgroundColour()));
1081 dc.SetPen(wxPen(GetBackgroundColour()));
1082 wxSize size = GetClientSize();
1083 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
1089void TCWin::OnSize(wxSizeEvent &event) {
1090 if (!m_created)
return;
1097 m_chartPanel->Refresh();
1107void TCWin::MouseEvent(wxMouseEvent &event) {
1110 event.GetPosition(&curs_x, &curs_y);
1112 if (!m_TCWinPopupTimer.IsRunning())
1113 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1116void TCWin::HandleChartMouseMove(
int mainWindowX,
int mainWindowY,
1117 const wxPoint &chartPanelPos) {
1120 curs_x = mainWindowX;
1121 curs_y = mainWindowY;
1126 wxSize panelSize = m_chartPanel->GetClientSize();
1127 int left_margin = 50;
1128 int other_margins = 5;
1129 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
1130 int chart_height = panelSize.GetHeight() - (2 * other_margins);
1131 int bottom_text_space = 50;
1132 chart_height -= bottom_text_space;
1133 chart_width = wxMax(chart_width, 300);
1134 chart_height = wxMax(chart_height, 150);
1137 wxPoint chartPanelPos = m_chartPanel->GetPosition();
1139 wxRect(chartPanelPos.x + left_margin, chartPanelPos.y + other_margins,
1140 chart_width, chart_height);
1143 if (!m_TCWinPopupTimer.IsRunning())
1144 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1147void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1151 GetClientSize(&x, &y);
1152 wxRegion cursorarea(m_graph_rect);
1153 if (cursorarea.Contains(curs_x, curs_y)) {
1154 ShowRollover =
true;
1155 SetCursor(*pParent->pCursorCross);
1156 if (NULL == m_pTCRolloverWin) {
1157 m_pTCRolloverWin =
new RolloverWin(
this, -1,
false);
1161 m_pTCRolloverWin->SetMousePropogation(1);
1162 m_pTCRolloverWin->Hide();
1170 (float)(curs_x - m_graph_rect.x) / (float)m_graph_rect.width;
1171 t = relativeX * 25.0f;
1174 t = wxMax(0.0f, wxMin(25.0f, t));
1176 int tt = m_t_graphday_GMT + (int)(t * 3600);
1181 p.Printf(thd.Format(
"%Hh %Mmn"));
1186 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1188 int ttv = tt_localtz + (int)(t * 3600);
1189 if (m_tzoneDisplay == 0) {
1190 ttv -= m_stationOffset_mins * 60;
1199 double t_converted = (t < 0 && CURRENT_PLOT == m_plot_type) ? -t : t;
1203 int unit_c = TCDataFactory::findunit(pmsd->unit);
1206 t_converted * TCDataFactory::known_units[unit_c].conv_factor;
1212 s.Printf(
"%3.2f ", t_converted);
1219 if (CURRENT_PLOT == m_plot_type) {
1220 s.Printf(
"%3.0f%c", d, 0x00B0);
1227 win_size.Set(x * 90 / 100, y * 80 / 100);
1229 m_pTCRolloverWin->SetString(p);
1230 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1232 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1233 m_pTCRolloverWin->Refresh();
1234 m_pTCRolloverWin->Show();
1242 for (
int i = 0; i < 26; i++) {
1243 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1250 if (m_sList.size() > 0 && idx > 0 && idx < (int)m_sList.size()) {
1252 auto it_a = m_sList.begin();
1253 std::advance(it_a, idx - 1);
1254 auto it_b = m_sList.begin();
1255 std::advance(it_b, idx);
1260 float pct = (curs_x - a->x) / (
float)((b->x - a->x));
1261 float dy = pct * (b->y - a->y);
1268 ySpot = m_graph_rect.y + m_graph_rect.height / 2;
1274 SetCursor(*pParent->pCursorArrow);
1275 ShowRollover =
false;
1278 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1279 m_pTCRolloverWin->Hide();
1283void 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.