5#include <wx/listctrl.h>
8#include <wx/dcbuffer.h>
16#include "model/cutil.h"
18#include "model/wx28compat.h"
19#include "OCPNPlatform.h"
20#include "RolloverWin.h"
23#include "ocpn_frame.h"
29 SetMinSize(wxSize(400, 200));
30 Bind(wxEVT_PAINT, &TideChartPanel::OnPaint,
this);
31 Bind(wxEVT_MOTION, &TideChartPanel::OnMouseMove,
this);
32 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
36 void OnPaint(wxPaintEvent &event) {
40 dc.SetBackground(wxBrush(GetBackgroundColour()));
44 wxSize panelSize = GetClientSize();
45 if (panelSize.GetWidth() <= 0 || panelSize.GetHeight() <= 0) {
51 int other_margins = 5;
52 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
53 int chart_height = panelSize.GetHeight() - (2 * other_margins);
56 int bottom_text_space = 50;
57 chart_height -= bottom_text_space;
58 chart_width = wxMax(chart_width, 300);
59 chart_height = wxMax(chart_height, 150);
60 wxRect chartRect(left_margin, other_margins, chart_width, chart_height);
63 m_tcWin->PaintChart(dc, chartRect);
66 void OnMouseMove(wxMouseEvent &event) {
67 wxPoint panelPos =
event.GetPosition();
68 wxPoint mainWindowPos = panelPos + GetPosition();
69 m_tcWin->HandleChartMouseMove(mainWindowPos.x, mainWindowPos.y, panelPos);
76extern ColorScheme global_color_scheme;
79extern wxString g_locale;
86enum { ID_TCWIN_NX, ID_TCWIN_PR };
88enum { TIDE_PLOT, CURRENT_PLOT };
90BEGIN_EVENT_TABLE(
TCWin, wxWindow)
91EVT_PAINT(TCWin::OnPaint)
92EVT_SIZE(TCWin::OnSize)
93EVT_MOTION(TCWin::MouseEvent)
94EVT_BUTTON(wxID_OK, TCWin::OKEvent)
95EVT_BUTTON(ID_TCWIN_NX, TCWin::NXEvent)
96EVT_BUTTON(ID_TCWIN_PR, TCWin::PREvent)
97EVT_CLOSE(TCWin::OnCloseWindow)
98EVT_TIMER(TCWININF_TIMER, TCWin::OnTCWinPopupTimerEvent)
99EVT_TIMER(TCWIN_TIME_INDICATOR_TIMER, TCWin::OnTimeIndicatorTimer)
103extern wxDateTime gTimeSource;
109 m_pTCRolloverWin = NULL;
111 long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER |
112 wxFRAME_FLOAT_ON_PARENT;
122 pConfig->SetPath(_T (
"/Settings/Others" ));
123 pConfig->Read(_T (
"TCWindowTimeZone" ), &m_tzoneDisplay, 0);
126 wxFrame::Create(parent, wxID_ANY, wxString(_T (
"" )), m_position, m_tc_size,
136 if (strchr(
"Tt", pIDX->IDX_type)) {
137 m_plot_type = TIDE_PLOT;
138 SetTitle(wxString(_(
"Tide")));
141 m_plot_type = CURRENT_PLOT;
142 SetTitle(wxString(_(
"Current")));
146 GetClientSize(&sx, &sy);
154 m_graph_rect = wxRect(0, 0, 400, 200);
157 wxButton *test_button =
158 new wxButton(
this, wxID_OK, _(
"OK"), wxPoint(-1, -1), wxDefaultSize);
159 test_button->GetSize(&m_tsx, &m_tsy);
162 m_TCWinPopupTimer.SetOwner(
this, TCWININF_TIMER);
165 m_TimeIndicatorTimer.SetOwner(
this, TCWIN_TIME_INDICATOR_TIMER);
166 m_TimeIndicatorTimer.Start(60000,
false);
171 dc.GetTextExtent(
"W", NULL, &text_height);
172 m_refTextHeight = text_height;
173 m_button_height = m_tsy;
177 wxFont *dlg_font = FontMgr::Get().
GetFont(_(
"Dialog"));
178 int dlg_font_size = dlg_font->GetPointSize();
179#if defined(__WXOSX__) || defined(__WXGTK3__)
181 dlg_font_size /= GetContentScaleFactor();
185 dlg_font_size - 2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
186 wxFONTWEIGHT_NORMAL, FALSE, wxString(_T (
"Arial" )));
188 dlg_font_size - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
189 wxFONTWEIGHT_NORMAL, FALSE, wxString(_T (
"Arial" )));
191 dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
192 FALSE, wxString(_T (
"Arial" )));
194 dlg_font_size + 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
195 wxFONTWEIGHT_BOLD, FALSE, wxString(_T (
"Arial" )));
198 pblack_1 = wxThePenList->FindOrCreatePen(
199 this->GetForegroundColour(), wxMax(1, (
int)(m_tcwin_scaler + 0.5)),
202 pblack_2 = wxThePenList->FindOrCreatePen(
203 this->GetForegroundColour(), wxMax(2, (
int)(2 * m_tcwin_scaler + 0.5)),
206 pblack_3 = wxThePenList->FindOrCreatePen(
207 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
208 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
210 pred_2 = wxThePenList->FindOrCreatePen(
211 wxColor(230, 54, 54), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
214 pred_time = wxThePenList->FindOrCreatePen(
215 wxColour(0, 100, 255), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
218 pltgray = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
221 pltgray2 = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
223 pgraph = wxThePenList->FindOrCreatePen(
224 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
225 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
230 InitializeStationText();
234 m_TimeIndicatorTimer.Stop();
235 pParent->Refresh(
false);
238void TCWin::CreateLayout() {
240 wxBoxSizer *mainSizer =
new wxBoxSizer(wxVERTICAL);
243 m_topPanel =
new wxPanel(
this, wxID_ANY);
244 wxBoxSizer *topSizer =
new wxBoxSizer(wxHORIZONTAL);
248 new wxTextCtrl(m_topPanel, -1,
"", wxDefaultPosition, wxDefaultSize,
249 wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
250 m_ptextctrl->SetMinSize(wxSize(200, 120));
253 m_tList =
new wxListCtrl(m_topPanel, -1, wxDefaultPosition, wxDefaultSize,
254 wxLC_REPORT | wxLC_NO_HEADER);
255 m_tList->SetMinSize(wxSize(150, 120));
261 col0.SetAlign(wxLIST_FORMAT_LEFT);
263 m_tList->InsertColumn(0, col0);
266 topSizer->Add(m_ptextctrl, 2, wxEXPAND | wxALL,
268 topSizer->Add(m_tList, 1, wxEXPAND | wxALL, 5);
270 m_topPanel->SetSizer(topSizer);
273 m_chartPanel =
new TideChartPanel(
this);
276 m_buttonPanel =
new wxPanel(
this, wxID_ANY);
277 wxBoxSizer *buttonSizer =
new wxBoxSizer(wxHORIZONTAL);
280 PR_button =
new wxButton(m_buttonPanel, ID_TCWIN_PR, _(
"Prev"));
281 NX_button =
new wxButton(m_buttonPanel, ID_TCWIN_NX, _(
"Next"));
282 OK_button =
new wxButton(m_buttonPanel, wxID_OK, _(
"OK"));
285 wxString choiceOptions[] = {_(
"LMT@Station"), _(
"UTC")};
286 int numChoices =
sizeof(choiceOptions) /
sizeof(wxString);
287 m_choiceTimezone =
new wxChoice(m_buttonPanel, wxID_ANY, wxDefaultPosition,
288 wxDefaultSize, numChoices, choiceOptions);
289 m_choiceTimezone->SetSelection(m_tzoneDisplay);
290 m_choiceTimezone->SetToolTip(
291 _(
"Select whether tide times are shown in UTC or Local Mean Time (LMT) "
295 buttonSizer->Add(PR_button, 0, wxALL, 5);
296 buttonSizer->Add(NX_button, 0, wxALL, 5);
297 buttonSizer->AddStretchSpacer(1);
298 buttonSizer->Add(m_choiceTimezone, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
299 buttonSizer->AddSpacer(10);
300 buttonSizer->Add(OK_button, 0, wxALL, 5);
302 m_buttonPanel->SetSizer(buttonSizer);
305 mainSizer->Add(m_topPanel, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP,
307 mainSizer->Add(m_chartPanel, 1, wxEXPAND | wxLEFT | wxRIGHT,
309 mainSizer->Add(m_buttonPanel, 0, wxEXPAND | wxALL,
316 m_choiceTimezone->Connect(wxEVT_COMMAND_CHOICE_SELECTED,
317 wxCommandEventHandler(TCWin::TimezoneOnChoice),
321void TCWin::InitializeStationText() {
323 m_ptextctrl->Clear();
326 wxString locna, locnb;
327 if (locn.Contains(wxString(_T (
"," )))) {
328 locna = locn.BeforeFirst(
',');
329 locnb = locn.AfterFirst(
',');
337 style.SetFont(*pLFont);
338 m_ptextctrl->SetDefaultStyle(style);
340 m_ptextctrl->AppendText(locna);
341 m_ptextctrl->AppendText(
"\n");
343 style.SetFont(*pSMFont);
344 m_ptextctrl->SetDefaultStyle(style);
346 if (!locnb.IsEmpty()) m_ptextctrl->AppendText(locnb);
347 m_ptextctrl->AppendText(
"\n");
354 m_ptextctrl->AppendText(_(
"Reference Station :"));
355 m_ptextctrl->AppendText(
"\n");
357 m_ptextctrl->AppendText(mref);
358 m_ptextctrl->AppendText(
"\n");
361 m_ptextctrl->AppendText(
"\n");
366 dsource.Prepend(
" ");
368 m_ptextctrl->AppendText(_(
"Data Source :"));
369 m_ptextctrl->AppendText(
"\n");
371 m_ptextctrl->AppendText(dsource);
373 m_ptextctrl->ShowPosition(0);
376void TCWin::PaintChart(wxDC &dc,
const wxRect &chartRect) {
382 wxRect originalGraphRect = m_graph_rect;
383 m_graph_rect = chartRect;
390 if (m_graph_rect.x == 0) {
391 m_graph_rect = originalGraphRect;
397 GetClientSize(&x, &y);
400 pblack_1->SetColour(this->GetForegroundColour());
401 pblack_2->SetColour(this->GetForegroundColour());
402 pltgray->SetColour(this->GetBackgroundColour());
403 pltgray2->SetColour(this->GetBackgroundColour());
404 pred_2->SetColour(GetDimedColor(wxColor(230, 54, 54)));
405 pred_time->SetColour(GetDimedColor(wxColour(0, 100, 255)));
408 dc.SetPen(*pblack_1);
409 dc.SetBrush(*pltgray);
410 dc.DrawRectangle(m_graph_rect.x, m_graph_rect.y, m_graph_rect.width,
411 m_graph_rect.height);
416 const int hour_delta = 4;
418 const int hour_delta = 1;
425 for (i = 0; i < 25; i++) {
426 int xd = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
427 if (hour_delta != 1) {
428 if (i % hour_delta == 0) {
429 dc.SetPen(*pblack_2);
430 dc.DrawLine(xd, m_graph_rect.y, xd,
431 m_graph_rect.y + m_graph_rect.height + 5);
433 int hour_show = hour_start + i;
434 if (hour_show >= 24) hour_show -= 24;
435 sprintf(sbuf,
"%02d", hour_show);
437 dc.DrawText(wxString(sbuf, wxConvUTF8),
438 xd + x_shim + (m_graph_rect.width / 25) / 2,
439 m_graph_rect.y + m_graph_rect.height + 8);
441 dc.SetPen(*pblack_1);
442 dc.DrawLine(xd, m_graph_rect.y, xd,
443 m_graph_rect.y + m_graph_rect.height + 5);
446 dc.SetPen(*pblack_1);
447 dc.DrawLine(xd, m_graph_rect.y, xd,
448 m_graph_rect.y + m_graph_rect.height + 5);
450 sst.Printf(
"%02d", i);
451 dc.DrawRotatedText(sst, xd + (m_graph_rect.width / 25) / 2,
452 m_graph_rect.y + m_graph_rect.height + 8, 270.);
457 wxDateTime system_now = wxDateTime::Now();
458 wxDateTime this_now = gTimeSource;
459 bool cur_time = !gTimeSource.IsValid();
460 if (cur_time) this_now = wxDateTime::Now();
463 time_t t_system_now = system_now.GetTicks();
464 t_system_now -= m_diff_mins * 60;
465 if (m_tzoneDisplay == 0)
466 t_system_now += m_stationOffset_mins * 60;
468 float t_system_ratio =
469 m_graph_rect.width * (t_system_now - m_t_graphday_GMT) / (25 * 3600.0f);
470 int x_system = (t_system_ratio < 0 || t_system_ratio > m_graph_rect.width)
472 : m_graph_rect.x + (int)t_system_ratio;
476 dc.DrawLine(x_system, m_graph_rect.y, x_system,
477 m_graph_rect.y + m_graph_rect.height);
482 if (gTimeSource.IsValid()) {
483 time_t t_selected_time = gTimeSource.GetTicks();
484 if (abs(t_selected_time - t_system_now) > 300) {
485 t_selected_time -= m_diff_mins * 60;
486 if (m_tzoneDisplay == 0)
487 t_selected_time += m_stationOffset_mins * 60;
489 float t_selected_time_ratio = m_graph_rect.width *
490 (t_selected_time - m_t_graphday_GMT) /
492 int x_selected_time = (t_selected_time_ratio < 0 ||
493 t_selected_time_ratio > m_graph_rect.width)
495 : m_graph_rect.x + (int)t_selected_time_ratio;
497 if (x_selected_time >= 0) {
498 dc.SetPen(*pred_time);
499 dc.DrawLine(x_selected_time, m_graph_rect.y, x_selected_time,
500 m_graph_rect.y + m_graph_rect.height);
504 dc.SetPen(*pblack_1);
512 m_tList->DeleteAllItems();
520 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
522 if (m_tzoneDisplay == 0)
523 tt_localtz -= m_stationOffset_mins * 60;
526 ptcmgr->GetTideFlowSens(tt_localtz, BACKWARD_TEN_MINUTES_STEP,
529 for (i = 0; i < 26; i++) {
530 int tt = tt_localtz + (i * FORWARD_ONE_HOUR_STEP);
531 ptcmgr->GetTideOrCurrent(tt, pIDX->
IDX_rec_num, tcv[i], dir);
533 if (tcv[i] > tcmax) tcmax = tcv[i];
534 if (tcv[i] < tcmin) tcmin = tcv[i];
536 if (TIDE_PLOT == m_plot_type) {
537 if (!((tcv[i] > val) == wt) && (i > 0)) {
540 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
541 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
543 if (tctime > tt_localtz) {
547 tcd.Set(tctime - (m_diff_mins * 60));
548 if (m_tzoneDisplay == 0)
549 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
551 s.Printf(tcd.Format(
"%H:%M "));
552 s1.Printf(
"%05.2f ", tcvalue);
555 if (pmsd) s.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
557 (wt) ? s.Append(_(
"HW")) : s.Append(_(
"LW"));
560 li.SetId(list_index);
561 li.SetAlign(wxLIST_FORMAT_LEFT);
564 m_tList->InsertItem(li);
571 if (CURRENT_PLOT == m_plot_type) {
574 thx.Set((time_t)tt - (m_diff_mins * 60));
575 if (m_tzoneDisplay == 0)
576 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
578 s.Printf(thx.Format(
"%H:%M "));
579 s1.Printf(
"%05.2f ", fabs(tcv[i]));
582 if (pmsd) s.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
583 s1.Printf(
" %03.0f", dir);
587 li.SetId(list_index);
588 li.SetAlign(wxLIST_FORMAT_LEFT);
591 m_tList->InsertItem(li);
599 if (CURRENT_PLOT == m_plot_type) {
600 it = std::max(abs((
int)tcmin - 1), abs((
int)tcmax + 1));
603 m_plot_y_offset = m_graph_rect.height / 2;
607 if (tcmin < 0) ib -= 1;
610 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
617 dc.GetTextExtent(
"1", NULL, &height_stext);
618 float available_lines = (float)m_graph_rect.height / height_stext;
619 i_skip = (int)ceil(im / available_lines);
621 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
629 for (
auto it = m_sList.begin(); it != m_sList.end(); it++)
delete (*it);
632 for (i = 0; i < 26; i++) {
633 wxPoint *pp =
new wxPoint;
634 pp->x = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
635 pp->y = m_graph_rect.y + (m_plot_y_offset) -
636 (
int)((tcv[i] - val_off) * m_graph_rect.height / im);
637 m_sList.push_back(pp);
644 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
649 int yd = m_graph_rect.y + (m_plot_y_offset) -
650 ((i - val_off) * m_graph_rect.height / im);
651 if ((m_plot_y_offset + m_graph_rect.y) == yd)
652 dc.SetPen(*pblack_2);
654 dc.SetPen(*pblack_1);
656 dc.DrawLine(m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd);
657 snprintf(sbuf, 99,
"%d", i);
658 dc.DrawText(wxString(sbuf, wxConvUTF8), m_graph_rect.x - 20, yd - 5);
664 for (
auto &p : m_sList) list.Append(p);
668 dc.DrawSpline(&list);
674 if (m_tzoneDisplay == 0) {
675 int station_offset = ptcmgr->GetStationTimeOffset(pIDX);
676 int h = station_offset / 60;
677 int m = station_offset - (h * 60);
678 if (m_graphday.IsDST()) h += 1;
679 m_stz.Printf(
"UTC %+03d:%02d", h, m);
683 double lat = ptcmgr->GetStationLat(pIDX);
686 switch (ptcmgr->GetStationTimeOffset(pIDX)) {
698 if (m_graphday.IsDST()) mtz[1] =
'D';
708 dc.GetTextExtent(m_stz, &w, &h);
710 dc.DrawText(m_stz, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
711 m_graph_rect.y + m_graph_rect.height + 35);
714 if (g_locale ==
"en_US")
715 sdate = m_graphday.Format(
"%A %b %d, %Y");
717 sdate = m_graphday.Format(
"%A %d %b %Y");
720 dc.GetTextExtent(sdate, &w, &h);
722 dc.DrawText(sdate, m_graph_rect.x + (m_graph_rect.width / 2) - (w / 2),
723 m_graph_rect.y + m_graph_rect.height + 15);
727 dc.GetTextExtent(wxString(pmsd->units_conv, wxConvUTF8), &w, &h);
728 dc.DrawRotatedText(wxString(pmsd->units_conv, wxConvUTF8), 5,
729 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
737 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
738 m_graph_rect.y + m_graph_rect.height * 1 / 4);
742 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
743 m_graph_rect.y + m_graph_rect.height * 3 / 4);
747 if ((m_button_height * 15) < x && cur_time) {
749 int day = m_graphday.GetDayOfYear();
750 if (m_graphday.GetYear() == this_now.GetYear()) {
751 if (day == this_now.GetDayOfYear())
752 sday.Append(_(
"Today"));
753 else if (day == this_now.GetDayOfYear() + 1)
754 sday.Append(_(
"Tomorrow"));
756 sday.Append(m_graphday.GetWeekDayName(m_graphday.GetWeekDay()));
757 }
else if (m_graphday.GetYear() == this_now.GetYear() + 1 &&
758 day == this_now.Add(wxTimeSpan::Day()).GetDayOfYear())
759 sday.Append(_(
"Tomorrow"));
762 dc.GetTextExtent(sday, &w, &h);
764 dc.DrawText(sday, m_graph_rect.x,
765 m_graph_rect.y + m_graph_rect.height + 15);
769 double spotDim = 4 * g_Platform->GetDisplayDPmm();
770 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"YELO1"),
771 wxBRUSHSTYLE_SOLID));
772 dc.SetPen(wxPen(GetGlobalColor(
"URED"),
773 wxMax(2, 0.5 * g_Platform->GetDisplayDPmm())));
774 dc.DrawRoundedRectangle(xSpot - spotDim / 2, ySpot - spotDim / 2, spotDim,
775 spotDim, spotDim / 2);
777 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetGlobalColor(
"UBLCK"),
778 wxBRUSHSTYLE_SOLID));
779 dc.SetPen(wxPen(GetGlobalColor(
"UBLCK"), 1));
780 double ispotDim = spotDim / 5.;
781 dc.DrawRoundedRectangle(xSpot - ispotDim / 2, ySpot - ispotDim / 2, ispotDim,
782 ispotDim, ispotDim / 2);
785 m_graph_rect = originalGraphRect;
788void TCWin::SetTimeFactors() {
790 wxDateTime this_now = gTimeSource;
791 bool cur_time = !gTimeSource.IsValid();
794 this_now = wxDateTime::Now();
796 wxDateTime this_gmt = this_now.ToGMT();
798#if wxCHECK_VERSION(2, 6, 2)
799 wxTimeSpan diff = this_now.Subtract(this_gmt);
801 wxTimeSpan diff = this_gmt.Subtract(this_now);
804 m_diff_mins = diff.GetMinutes();
809#if wxCHECK_VERSION(3, 0, 2)
810 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
813 int station_offset = ptcmgr->GetStationTimeOffset(pIDX);
815 m_stationOffset_mins = station_offset;
816 if (this_now.IsDST()) {
817 m_stationOffset_mins += 60;
823#if wxCHECK_VERSION(3, 0, 2)
830 m_graphday = this_gmt;
832 int day_gmt = this_gmt.GetDayOfYear();
834 time_t ttNow = this_now.GetTicks();
835 time_t tt_at_station =
836 ttNow - (m_diff_mins * 60) + (m_stationOffset_mins * 60);
837 wxDateTime atStation(tt_at_station);
838 int day_at_station = atStation.GetDayOfYear();
840 if (day_gmt > day_at_station) {
841 wxTimeSpan dt(24, 0, 0, 0);
842 m_graphday.Subtract(dt);
843 }
else if (day_gmt < day_at_station) {
844 wxTimeSpan dt(24, 0, 0, 0);
848 wxDateTime graphday_00 = m_graphday;
849 graphday_00.ResetTime();
850 time_t t_graphday_00 = graphday_00.GetTicks();
856 m_t_graphday_GMT = t_graphday_00;
861void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
862 m_tzoneDisplay = m_choiceTimezone->GetSelection();
868void TCWin::RecalculateSize() {
869 wxSize parent_size(2000, 2000);
870 if (pParent) parent_size = pParent->GetClientSize();
872 int unscaledheight = 600;
873 int unscaledwidth = 650;
879 g_tcwin_scale = wxMax(g_tcwin_scale, 10);
880 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
882 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
883 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
885 m_tc_size.x = wxMin(m_tc_size.x, parent_size.x);
886 m_tc_size.y = wxMin(m_tc_size.y, parent_size.y);
893 if ((m_x + 8 + m_tc_size.x) > parent_size.x) xc = xc - m_tc_size.x - 16;
894 if ((m_y + m_tc_size.y) > parent_size.y) yc = yc - m_tc_size.y;
900 if (pParent) pParent->ClientToScreen(&xc, &yc);
901 m_position = wxPoint(xc, yc);
909void TCWin::OKEvent(wxCommandEvent &event) {
913 if (pParent && pParent->pCwin ==
this) {
914 pParent->pCwin = NULL;
919 delete m_pTCRolloverWin;
920 m_pTCRolloverWin = NULL;
925 pParent->Refresh(
false);
930 pConfig->SetPath(_T (
"/Settings/Others" ));
931 pConfig->Write(_T (
"TCWindowTimeZone" ), m_tzoneDisplay);
937void TCWin::OnCloseWindow(wxCloseEvent &event) {
941 if (pParent && pParent->pCwin ==
this) {
942 pParent->pCwin = NULL;
947 delete m_pTCRolloverWin;
948 m_pTCRolloverWin = NULL;
954 pConfig->SetPath(_T (
"/Settings/Others" ));
955 pConfig->Write(_T (
"TCWindowTimeZone" ), m_tzoneDisplay);
961void TCWin::NXEvent(wxCommandEvent &event) {
962 wxTimeSpan dt(24, 0, 0, 0);
964 wxDateTime dm = m_graphday;
966 wxDateTime graphday_00 = dm.ResetTime();
967 time_t t_graphday_00 = graphday_00.GetTicks();
969 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
970 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
972 m_t_graphday_GMT = t_graphday_00;
978void TCWin::PREvent(wxCommandEvent &event) {
979 wxTimeSpan dt(-24, 0, 0, 0);
981 wxDateTime dm = m_graphday;
983 wxDateTime graphday_00 = dm.ResetTime();
984 time_t t_graphday_00 = graphday_00.GetTicks();
986 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
987 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
989 m_t_graphday_GMT = t_graphday_00;
995void TCWin::RePosition(
void) {
1002 pParent->ClientToScreen(&r.x, &r.y);
1006void TCWin::OnPaint(wxPaintEvent &event) {
1018 dc.SetBrush(wxBrush(GetBackgroundColour()));
1019 dc.SetPen(wxPen(GetBackgroundColour()));
1020 wxSize size = GetClientSize();
1021 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
1027void TCWin::OnSize(wxSizeEvent &event) {
1028 if (!m_created)
return;
1035 m_chartPanel->Refresh();
1045void TCWin::MouseEvent(wxMouseEvent &event) {
1048 event.GetPosition(&curs_x, &curs_y);
1050 if (!m_TCWinPopupTimer.IsRunning())
1051 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1054void TCWin::HandleChartMouseMove(
int mainWindowX,
int mainWindowY,
1055 const wxPoint &chartPanelPos) {
1058 curs_x = mainWindowX;
1059 curs_y = mainWindowY;
1064 wxSize panelSize = m_chartPanel->GetClientSize();
1065 int left_margin = 50;
1066 int other_margins = 5;
1067 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
1068 int chart_height = panelSize.GetHeight() - (2 * other_margins);
1069 int bottom_text_space = 50;
1070 chart_height -= bottom_text_space;
1071 chart_width = wxMax(chart_width, 300);
1072 chart_height = wxMax(chart_height, 150);
1075 wxPoint chartPanelPos = m_chartPanel->GetPosition();
1077 wxRect(chartPanelPos.x + left_margin, chartPanelPos.y + other_margins,
1078 chart_width, chart_height);
1081 if (!m_TCWinPopupTimer.IsRunning())
1082 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1085void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1089 GetClientSize(&x, &y);
1090 wxRegion cursorarea(m_graph_rect);
1091 if (cursorarea.Contains(curs_x, curs_y)) {
1092 ShowRollover =
true;
1093 SetCursor(*pParent->pCursorCross);
1094 if (NULL == m_pTCRolloverWin) {
1095 m_pTCRolloverWin =
new RolloverWin(
this, -1,
false);
1099 m_pTCRolloverWin->SetMousePropogation(1);
1100 m_pTCRolloverWin->Hide();
1108 (float)(curs_x - m_graph_rect.x) / (float)m_graph_rect.width;
1109 t = relativeX * 25.0f;
1112 t = wxMax(0.0f, wxMin(25.0f, t));
1114 int tt = m_t_graphday_GMT + (int)(t * 3600);
1119 p.Printf(thd.Format(
"%Hh %Mmn"));
1124 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1126 int ttv = tt_localtz + (int)(t * 3600);
1127 if (m_tzoneDisplay == 0) {
1128 ttv -= m_stationOffset_mins * 60;
1134 ptcmgr->GetTideOrCurrent(tts, pIDX->
IDX_rec_num, t, d);
1135 s.Printf(
"%3.2f ", (t < 0 && CURRENT_PLOT == m_plot_type)
1142 if (pmsd) p.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
1145 if (CURRENT_PLOT == m_plot_type) {
1146 s.Printf(
"%3.0f%c", d, 0x00B0);
1153 win_size.Set(x * 90 / 100, y * 80 / 100);
1155 m_pTCRolloverWin->SetString(p);
1156 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1158 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1159 m_pTCRolloverWin->Refresh();
1160 m_pTCRolloverWin->Show();
1168 for (
int i = 0; i < 26; i++) {
1169 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1176 if (m_sList.size() > 0 && idx > 0 && idx < (int)m_sList.size()) {
1178 auto it_a = m_sList.begin();
1179 std::advance(it_a, idx - 1);
1180 auto it_b = m_sList.begin();
1181 std::advance(it_b, idx);
1186 float pct = (curs_x - a->x) / (
float)((b->x - a->x));
1187 float dy = pct * (b->y - a->y);
1194 ySpot = m_graph_rect.y + m_graph_rect.height / 2;
1200 SetCursor(*pParent->pCursorArrow);
1201 ShowRollover =
false;
1204 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1205 m_pTCRolloverWin->Hide();
1209void TCWin::OnTimeIndicatorTimer(wxTimerEvent &event) {
Generic Chart canvas base.
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)
Gets 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.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.