OpenCPN Partial API docs
Loading...
Searching...
No Matches
tc_win.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2013 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24// For compilers that support precompilation, includes "wx.h".
25#include <wx/wxprec.h>
26
27#include <wx/button.h>
28#include <wx/choice.h>
29#include <wx/font.h>
30#include <wx/panel.h>
31#include <wx/dcbuffer.h>
32#include <wx/listctrl.h>
33#include <wx/utils.h>
34
35#include "tc_win.h"
36
37#include "model/cutil.h"
38#include "model/config_vars.h"
39#include "model/gui_vars.h"
40
41#include "abstract_chart_canv.h"
42#include "chcanv.h"
43#include "dychart.h"
44#include "font_mgr.h"
45#include "ocpn_platform.h"
46#include "rollover_win.h"
47#include "navutil.h"
48#include "gui_lib.h"
49#include "navutil.h"
50#include "ocpn_platform.h"
51#include "rollover_win.h"
52#include "tc_data_factory.h"
53#include "tcmgr.h"
54#include "tide_time.h"
55#include "timers.h"
56#include "user_colors.h"
57
58extern ColorScheme global_color_scheme; // library dependence
59
60// Custom chart panel class definition
61class TCWin::TideChartPanel : public wxPanel {
62public:
63 TideChartPanel(TCWin *parent) : wxPanel(parent, wxID_ANY), m_tcWin(parent) {
64 SetMinSize(wxSize(400, 200));
65 Bind(wxEVT_PAINT, &TideChartPanel::OnPaint, this);
66 Bind(wxEVT_MOTION, &TideChartPanel::OnMouseMove, this);
67 SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Prevent flicker
68
69 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
70 SetFont(*qFont);
71 wxScreenDC dc;
72 int text_height;
73 dc.SetFont(*qFont);
74 dc.GetTextExtent("W", NULL, &text_height);
75 m_refTCWTextHeight = text_height;
76 }
77
78private:
79 void OnPaint(wxPaintEvent &event) {
80 wxPaintDC dc(this);
81
82 // Clear the background
83 dc.SetBackground(wxBrush(GetBackgroundColour()));
84 dc.Clear();
85
86 // Calculate chart rectangle within this panel
87 wxSize panelSize = GetClientSize();
88 if (panelSize.GetWidth() <= 0 || panelSize.GetHeight() <= 0) {
89 return;
90 }
91
92 // Use larger left margin for Y-axis labels and units
93 int left_margin = 50; // Space for Y-axis numbers and units
94 int other_margins = 5; // Smaller margins for top, right, bottom
95 int chart_width = panelSize.GetWidth() - left_margin - other_margins;
96 int chart_height = panelSize.GetHeight() - (2 * other_margins);
97
98 // Reserve space at bottom for date/time text
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);
104
105 // Delegate chart painting to parent TCWin
106 m_tcWin->PaintChart(dc, chartRect);
107 }
108
109 void OnMouseMove(wxMouseEvent &event) {
110 wxPoint panelPos = event.GetPosition();
111 wxPoint mainWindowPos = panelPos + GetPosition();
112 m_tcWin->HandleChartMouseMove(mainWindowPos.x, mainWindowPos.y, panelPos);
113 event.Skip();
114 }
115
116 TCWin *m_tcWin;
117 int m_refTCWTextHeight;
118};
119
120enum { ID_TCWIN_NX, ID_TCWIN_PR };
121
122enum { TIDE_PLOT, CURRENT_PLOT };
123
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)
134END_EVENT_TABLE()
135
136// Define a constructor
137TCWin::TCWin(ChartCanvas *parent, int x, int y, void *pvIDX) {
138 m_created = false;
139 xSpot = 0;
140 ySpot = 0;
141
142 m_pTCRolloverWin = NULL;
143
144 long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER |
145 wxFRAME_FLOAT_ON_PARENT;
146
147 pParent = parent;
148 m_x = x;
149 m_y = y;
150
151 RecalculateSize();
152
153 // Read the config file to get the user specified time zone.
154 if (pConfig) {
155 pConfig->SetPath("/Settings/Others");
156 pConfig->Read("TCWindowTimeZone", &m_tzoneDisplay, 0);
157 }
158
159 wxFrame::Create(parent, wxID_ANY, wxString(""), m_position, m_tc_size,
160 wstyle);
161
162 m_created = true;
163 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
164 SetFont(*qFont);
165
166 pIDX = (IDX_entry *)pvIDX;
167
168 // Set up plot type
169 if (strchr("Tt", pIDX->IDX_type)) {
170 m_plot_type = TIDE_PLOT;
171 SetTitle(wxString(_("Tide")));
172
173 } else {
174 m_plot_type = CURRENT_PLOT;
175 SetTitle(wxString(_("Current")));
176 }
177
178 int sx, sy;
179 GetClientSize(&sx, &sy);
180
181 SetTimeFactors();
182
183 btc_valid = false;
184
185 // Establish a "reference" text hieght value, for layout assistance
186 wxScreenDC dc;
187 int text_height;
188 dc.SetFont(*qFont);
189 dc.GetTextExtent("W", NULL, &text_height);
190 m_refTextHeight = text_height;
191
192 CreateLayout();
193 Layout();
194 m_graph_rect = wxRect(0, 0, 400, 200);
195
196 // Measure the size of a generic button, with label
197 wxButton *test_button =
198 new wxButton(this, wxID_OK, _("OK"), wxPoint(-1, -1), wxDefaultSize);
199 test_button->GetSize(&m_tsx, &m_tsy);
200 delete test_button;
201
202 m_TCWinPopupTimer.SetOwner(this, TCWININF_TIMER);
203
204 // Timer for refreshing time indicators (red line moves with current time)
205 m_TimeIndicatorTimer.SetOwner(this, TCWIN_TIME_INDICATOR_TIMER);
206 m_TimeIndicatorTimer.Start(60000, false); // Refresh every 60 seconds
207
208 m_button_height = m_tsy;
209
210 // Build graphics tools
211
212 wxFont *dlg_font = FontMgr::Get().GetFont(_("Dialog"));
213 int dlg_font_size = dlg_font->GetPointSize();
214#if defined(__WXOSX__) || defined(__WXGTK3__)
215 // Support scaled HDPI displays.
216 dlg_font_size /= GetContentScaleFactor();
217#endif
218
219 pSFont = FontMgr::Get().FindOrCreateFont(
220 dlg_font_size - 2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
221 wxFONTWEIGHT_NORMAL, FALSE, wxString("Arial"));
222 pSMFont = FontMgr::Get().FindOrCreateFont(
223 dlg_font_size - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
224 wxFONTWEIGHT_NORMAL, FALSE, wxString("Arial"));
225 pMFont = FontMgr::Get().FindOrCreateFont(
226 dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
227 FALSE, wxString("Arial"));
228 pLFont = FontMgr::Get().FindOrCreateFont(
229 dlg_font_size + 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
230 wxFONTWEIGHT_BOLD, FALSE, wxString("Arial"));
231
232 // Secondary grid
233 pblack_1 = wxThePenList->FindOrCreatePen(
234 this->GetForegroundColour(), wxMax(1, (int)(m_tcwin_scaler + 0.5)),
235 wxPENSTYLE_SOLID);
236 // Primary grid
237 pblack_2 = wxThePenList->FindOrCreatePen(
238 this->GetForegroundColour(), wxMax(2, (int)(2 * m_tcwin_scaler + 0.5)),
239 wxPENSTYLE_SOLID);
240 // Tide hours outline
241 pblack_3 = wxThePenList->FindOrCreatePen(
242 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
243 wxMax(1, (int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
244 // System time vertical line - solid red line showing current system time
245 // position on tide/current chart
246 pred_2 = wxThePenList->FindOrCreatePen(
247 wxColor(230, 54, 54), wxMax(4, (int)(4 * m_tcwin_scaler + 0.5)),
248 wxPENSTYLE_SOLID);
249 // Selected time vertical line - dotted blue line showing timeline widget or
250 // GRIB time selection on chart
251 pred_time = wxThePenList->FindOrCreatePen(
252 wxColour(0, 100, 255), wxMax(4, (int)(4 * m_tcwin_scaler + 0.5)),
253 wxPENSTYLE_DOT);
254 // Graph background
255 pltgray = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
256 wxBRUSHSTYLE_SOLID);
257 // Tide hours background
258 pltgray2 = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
259 wxBRUSHSTYLE_SOLID);
260 pgraph = wxThePenList->FindOrCreatePen(
261 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
262 wxMax(1, (int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
263
264 DimeControl(this);
265
266 // Initialize the station text now that fonts are available
267 InitializeStationText();
268}
269
270TCWin::TCWin(AbstractChartCanvas *parent, int x, int y, void *pvIDX)
271 : TCWin(dynamic_cast<ChartCanvas *>(parent), x, y, pvIDX) {}
272
273TCWin::~TCWin() {
274 m_TimeIndicatorTimer.Stop();
275 pParent->Refresh(false);
276}
277
278void TCWin::CreateLayout() {
279 // Create main sizer
280 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
281
282 // ROW 1: Top panel for station info and tide list (two cells)
283 m_topPanel = new wxPanel(this, wxID_ANY);
284 wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
285
286 // Left cell: Station info text control with minimum size
287 m_ptextctrl =
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)); // Minimum readable size
292
293 // Right cell: Tide list (LW/HW) with minimum size
294 m_tList = new wxListCtrl(m_topPanel, -1, wxDefaultPosition, wxDefaultSize,
295 wxLC_REPORT | wxLC_NO_HEADER);
296 m_tList->SetMinSize(
297 wxSize(18 * m_refTextHeight,
298 4 * m_refTextHeight)); // Minimum to show a few entries
299
300 // Add first column to tide list
301 wxListItem col0;
302 col0.SetId(0);
303 col0.SetText("");
304 col0.SetAlign(wxLIST_FORMAT_LEFT);
305 col0.SetWidth(20 * m_refTextHeight);
306 m_tList->InsertColumn(0, col0);
307
308 // Add controls to top sizer (first row: two cells)
309 topSizer->Add(m_ptextctrl, 2, wxEXPAND | wxALL,
310 5); // Left cell: 2/3 of width
311 topSizer->Add(m_tList, 1, wxEXPAND | wxALL, 5); // Right cell: 1/3 of width
312
313 m_topPanel->SetSizer(topSizer);
314
315 // ROW 2: Chart panel (expandable - gets remaining space)
316 m_chartPanel = new TideChartPanel(this);
317
318 // ROW 3: Button panel (fixed height at bottom)
319 m_buttonPanel = new wxPanel(this, wxID_ANY);
320 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
321
322 // Create buttons
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"));
326
327 // Create timezone choice
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) "
335 "at the station"));
336
337 // Layout buttons: Prev/Next on left, timezone/OK on right
338 buttonSizer->Add(PR_button, 0, wxALL, 5);
339 buttonSizer->Add(NX_button, 0, wxALL, 5);
340 buttonSizer->AddStretchSpacer(1); // Push timezone and OK to the right
341 buttonSizer->Add(m_choiceTimezone, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
342 buttonSizer->AddSpacer(10); // Small space between timezone and OK
343 buttonSizer->Add(OK_button, 0, wxALL, 5);
344
345 m_buttonPanel->SetSizer(buttonSizer);
346
347 // Add all rows to main sizer with proper proportions
348 mainSizer->Add(m_topPanel, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP,
349 5); // Row 1: Fixed height, no overlap
350 mainSizer->Add(m_chartPanel, 1, wxEXPAND | wxLEFT | wxRIGHT,
351 5); // Row 2: Expandable, gets remaining space
352 mainSizer->Add(m_buttonPanel, 0, wxEXPAND | wxALL,
353 5); // Row 3: Fixed height at bottom
354
355 // Set the main sizer
356 SetSizer(mainSizer);
357
358 // Connect timezone choice event
359 m_choiceTimezone->Connect(wxEVT_COMMAND_CHOICE_SELECTED,
360 wxCommandEventHandler(TCWin::TimezoneOnChoice),
361 NULL, this);
362}
363
364void TCWin::InitializeStationText() {
365 // Fill station information in text control
366 m_ptextctrl->Clear();
367
368 wxString locn(pIDX->IDX_station_name, wxConvUTF8);
369 wxString locna, locnb;
370 if (locn.Contains(wxString(","))) {
371 locna = locn.BeforeFirst(',');
372 locnb = locn.AfterFirst(',');
373 } else {
374 locna = locn;
375 locnb.Empty();
376 }
377
378 // write the first line
379 wxTextAttr style;
380 style.SetFont(*pLFont);
381 m_ptextctrl->SetDefaultStyle(style);
382
383 m_ptextctrl->AppendText(locna);
384 m_ptextctrl->AppendText("\n");
385
386 style.SetFont(*pSMFont);
387 m_ptextctrl->SetDefaultStyle(style);
388
389 if (!locnb.IsEmpty()) m_ptextctrl->AppendText(locnb);
390 m_ptextctrl->AppendText("\n");
391
392 // Reference to the master station
393 if (('t' == pIDX->IDX_type) || ('c' == pIDX->IDX_type)) {
394 wxString mref(pIDX->IDX_reference_name, wxConvUTF8);
395 mref.Prepend(" ");
396
397 m_ptextctrl->AppendText(_("Reference Station :"));
398 m_ptextctrl->AppendText("\n");
399
400 m_ptextctrl->AppendText(mref);
401 m_ptextctrl->AppendText("\n");
402
403 } else {
404 m_ptextctrl->AppendText("\n");
405 }
406
407 // Show the data source
408 wxString dsource(pIDX->source_ident, wxConvUTF8);
409 dsource.Prepend(" ");
410
411 m_ptextctrl->AppendText(_("Data Source :"));
412 m_ptextctrl->AppendText("\n");
413
414 m_ptextctrl->AppendText(dsource);
415
416 m_ptextctrl->ShowPosition(0);
417}
418
419void TCWin::PaintChart(wxDC &dc, const wxRect &chartRect) {
420 if (!IsShown()) {
421 return;
422 }
423
424 // Store the original graph rectangle and use the provided chartRect
425 wxRect originalGraphRect = m_graph_rect;
426 m_graph_rect = chartRect;
427
428 int i;
429 char sbuf[100];
430 int w;
431 float tcmax, tcmin;
432
433 if (m_graph_rect.x == 0) {
434 m_graph_rect = originalGraphRect;
435 return;
436 }
437
438 // Get client size for positioning date/timezone text below chart
439 int x, y;
440 GetClientSize(&x, &y);
441
442 // Adjust colors with current color scheme
443 pblack_1->SetColour(this->GetForegroundColour());
444 pblack_2->SetColour(this->GetForegroundColour());
445 pltgray->SetColour(this->GetBackgroundColour());
446 pltgray2->SetColour(this->GetBackgroundColour());
447 pred_2->SetColour(
448 GetGlobalColor("URED")); // System time indicator - universal red
449 pred_time->SetColour(
450 GetGlobalColor("UINFB")); // Selected time indicator - information blue
451
452 // Box the graph
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);
457
458 // On some platforms, we cannot draw rotated text.
459 // So, reduce the complexity of horizontal axis time labels
460#ifndef __WXMSW__
461 const int hour_delta = 4;
462#else
463 const int hour_delta = 1;
464#endif
465
466 int hour_start = 0;
467
468 // Horizontal axis
469 dc.SetFont(*pSFont);
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);
477 char sbuf[16];
478 int hour_show = hour_start + i;
479 if (hour_show >= 24) hour_show -= 24;
480 sprintf(sbuf, "%02d", hour_show);
481 int x_shim = -20;
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);
485 } else {
486 dc.SetPen(*pblack_1);
487 dc.DrawLine(xd, m_graph_rect.y, xd,
488 m_graph_rect.y + m_graph_rect.height + 5);
489 }
490 } else {
491 dc.SetPen(*pblack_1);
492 dc.DrawLine(xd, m_graph_rect.y, xd,
493 m_graph_rect.y + m_graph_rect.height + 5);
494 wxString sst;
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.);
498 }
499 }
500
501 // Time indicators - system time and "selected" time (e.g. GRIB time)
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();
506
507 // Always draw system time indicator (solid red line)
508 time_t t_system_now = system_now.GetTicks();
509 t_system_now -= m_diff_mins * 60;
510 if (m_tzoneDisplay == 0) // LMT @ Station
511 t_system_now += m_stationOffset_mins * 60;
512
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)
516 ? -1
517 : m_graph_rect.x + (int)t_system_ratio;
518
519 if (x_system >= 0) {
520 dc.SetPen(*pred_2); // solid red line for system time
521 dc.DrawLine(x_system, m_graph_rect.y, x_system,
522 m_graph_rect.y + m_graph_rect.height);
523 }
524
525 // Draw "selected time" indicator (from timeline widget) if different from
526 // system time.
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) // LMT @ Station
532 t_selected_time += m_stationOffset_mins * 60;
533
534 float t_selected_time_ratio = m_graph_rect.width *
535 (t_selected_time - m_t_graphday_GMT) /
536 (25 * 3600.0f);
537 int x_selected_time = (t_selected_time_ratio < 0 ||
538 t_selected_time_ratio > m_graph_rect.width)
539 ? -1
540 : m_graph_rect.x + (int)t_selected_time_ratio;
541
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);
546 }
547 }
548 }
549 dc.SetPen(*pblack_1);
550
551 // Build the array of values, capturing max and min and HW/LW list
552 if (!btc_valid) {
553 float dir;
554 tcmax = -10;
555 tcmin = 10;
556 float val = -100;
557 m_tList->DeleteAllItems();
558 int list_index = 0;
559 bool wt = false;
560
561 wxBeginBusyCursor();
562
563 // The tide/current modules calculate values based on PC local time
564 // We want UTC, so adjust accordingly
565 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
566 // then eventually we could need LMT at station
567 if (m_tzoneDisplay == 0)
568 tt_localtz -= m_stationOffset_mins * 60; // LMT at station
569
570 // get tide flow sens ( flood or ebb ? )
571 ptcmgr->GetTideFlowSens(tt_localtz, BACKWARD_TEN_MINUTES_STEP,
572 pIDX->IDX_rec_num, tcv[0], val, wt);
573
574 for (i = 0; i < 26; i++) {
575 int tt = tt_localtz + (i * FORWARD_ONE_HOUR_STEP);
576 ptcmgr->GetTideOrCurrent(tt, pIDX->IDX_rec_num, tcv[i], dir);
577 tt_tcv[i] = tt; // store the corresponding time_t value
578
579 // Convert tide values from station units to user's height units
580 Station_Data *pmsd = pIDX->pref_sta_data;
581 if (pmsd) {
582 // Convert from station units to meters first
583 int unit_c = TCDataFactory::findunit(pmsd->unit);
584 if (unit_c >= 0) {
585 tcv[i] = tcv[i] * TCDataFactory::known_units[unit_c].conv_factor;
586 }
587 // Now convert from meters to preferred height units
588 tcv[i] = toUsrHeight(tcv[i]);
589 }
590
591 if (tcv[i] > tcmax) tcmax = tcv[i];
592 if (tcv[i] < tcmin) tcmin = tcv[i];
593
594 if (TIDE_PLOT == m_plot_type) {
595 if (!((tcv[i] > val) == wt) && (i > 0)) { // if tide flow sense change
596 float tcvalue; // look backward for HW or LW
597 time_t tctime;
598 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
599 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
600 pIDX->IDX_rec_num, tcvalue, tctime);
601 if (tctime > tt_localtz) { // Only show events visible in graphic
602 // presently shown
603 wxDateTime tcd; // write date
604 wxString s, s1;
605 tcd.Set(tctime - (m_diff_mins * 60));
606 if (m_tzoneDisplay == 0) // LMT @ Station
607 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
608
609 s.Printf(tcd.Format("%H:%M "));
610
611 // Convert tcvalue to preferred height units (it comes from
612 // GetHightOrLowTide in station units)
613 double tcvalue_converted = tcvalue;
614 Station_Data *pmsd = pIDX->pref_sta_data;
615 if (pmsd) {
616 // Convert from station units to meters first
617 int unit_c = TCDataFactory::findunit(pmsd->unit);
618 if (unit_c >= 0) {
619 tcvalue_converted =
620 tcvalue_converted *
621 TCDataFactory::known_units[unit_c].conv_factor;
622 }
623 // Now convert from meters to preferred height units
624 tcvalue_converted = toUsrHeight(tcvalue_converted);
625 }
626
627 s1.Printf("%05.2f ", tcvalue_converted); // write converted value
628 s.Append(s1);
629 s.Append(getUsrHeightUnit());
630 s.Append(" ");
631 (wt) ? s.Append(_("HW")) : s.Append(_("LW")); // write HW or LT
632
633 wxListItem li;
634 li.SetId(list_index);
635 li.SetAlign(wxLIST_FORMAT_LEFT);
636 li.SetText(s);
637 li.SetColumn(0);
638 m_tList->InsertItem(li);
639 list_index++;
640 }
641 wt = !wt; // change tide flow sens
642 }
643 val = tcv[i];
644 }
645 if (CURRENT_PLOT == m_plot_type) {
646 wxDateTime thx; // write date
647 wxString s, s1;
648 thx.Set((time_t)tt - (m_diff_mins * 60));
649 if (m_tzoneDisplay == 0) // LMT @ Station
650 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
651
652 s.Printf(thx.Format("%H:%M "));
653 s1.Printf("%05.2f ",
654 fabs(tcv[i])); // tcv[i] is already converted to height units
655 s.Append(s1);
656 s.Append(getUsrHeightUnit());
657 s1.Printf(" %03.0f", dir); // write direction
658 s.Append(s1);
659
660 wxListItem li;
661 li.SetId(list_index);
662 li.SetAlign(wxLIST_FORMAT_LEFT);
663 li.SetText(s);
664 li.SetColumn(0);
665 m_tList->InsertItem(li);
666 list_index++;
667 }
668 }
669
670 wxEndBusyCursor();
671
672 // Set up the vertical parameters based on Tide or Current plot
673 if (CURRENT_PLOT == m_plot_type) {
674 it = std::max(abs((int)tcmin - 1), abs((int)tcmax + 1));
675 ib = -it;
676 im = 2 * it;
677 m_plot_y_offset = m_graph_rect.height / 2;
678 val_off = 0;
679 } else {
680 ib = (int)tcmin;
681 if (tcmin < 0) ib -= 1;
682 it = (int)tcmax + 1;
683 im = it - ib;
684 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
685 val_off = ib;
686 }
687
688 // Arrange to skip some lines and legends if there are too many for the
689 // vertical space we have
690 int height_stext;
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);
694
695 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
696 // Adjust steps so slack current "0" line is always drawn on graph
697 ib -= it % i_skip;
698 it = -ib;
699 im = 2 * it;
700 }
701
702 // Build spline list of points
703 for (auto it = m_sList.begin(); it != m_sList.end(); it++) delete (*it);
704 m_sList.clear();
705
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);
712 }
713
714 btc_valid = true;
715 }
716
717 // Graph legend
718 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
719
720 // Vertical Axis
721 i = ib;
722 while (i < it + 1) {
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);
727 else
728 dc.SetPen(*pblack_1);
729
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);
735 }
736 i += i_skip;
737 }
738
739 // Draw the Value curve
740 wxPointList list;
741 for (auto &p : m_sList) list.Append(p);
742
743 dc.SetPen(*pgraph);
744#if wxUSE_SPLINES
745 dc.DrawSpline(&list);
746#else
747 dc.DrawLines(&list);
748#endif
749
750 // More Info - positioned below chart panel
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);
757
758 // Make the "nice" (for the US) station time-zone string, brutally by
759 // hand
760 double lat = ptcmgr->GetStationLat(pIDX);
761 if (lat > 20.0) {
762 wxString mtz;
763 switch (ptcmgr->GetStationTimeOffset(pIDX)) {
764 case -240:
765 mtz = "AST";
766 break;
767 case -300:
768 mtz = "EST";
769 break;
770 case -360:
771 mtz = "CST";
772 break;
773 }
774 if (mtz.Len()) {
775 if (m_graphday.IsDST()) mtz[1] = 'D';
776 m_stz = mtz;
777 }
778 }
779 } else {
780 m_stz = "UTC";
781 }
782
783 int h;
784 dc.SetFont(*pSFont);
785 dc.GetTextExtent(m_stz, &w, &h);
786 // Position timezone text below the chart, centered horizontally
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));
789
790 wxString sdate;
791 if (g_locale == "en_US")
792 sdate = m_graphday.Format("%A %b %d, %Y");
793 else
794 sdate = m_graphday.Format("%A %d %b %Y");
795
796 dc.SetFont(*pMFont);
797 dc.GetTextExtent(sdate, &w, &h);
798 // Position date text below the chart, centered horizontally
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));
801
802 Station_Data *pmsd = pIDX->pref_sta_data;
803 if (pmsd) {
804 // Use user's height unit for Y-axis label instead of station units
805 wxString height_unit = getUsrHeightUnit();
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.);
809 }
810
811 // Show flood and ebb directions
812 if ((strchr("c", pIDX->IDX_type)) || (strchr("C", pIDX->IDX_type))) {
813 dc.SetFont(*pSFont);
814 wxString fdir;
815 fdir.Printf("%03d", pIDX->IDX_flood_dir);
816 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
817 m_graph_rect.y + m_graph_rect.height * 1 / 4);
818
819 wxString edir;
820 edir.Printf("%03d", pIDX->IDX_ebb_dir);
821 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
822 m_graph_rect.y + m_graph_rect.height * 3 / 4);
823 }
824
825 // Today or tomorrow
826 if ((m_button_height * 15) < x && cur_time) { // large enough horizontally?
827 wxString sday;
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"));
834 else
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"));
839
840 dc.SetFont(*pSFont);
841 dc.GetTextExtent(sday, &w, &h);
842 // Position day text at the left side of the chart, below it
843 dc.DrawText(sday, m_graph_rect.x,
844 m_graph_rect.y + m_graph_rect.height + (2 * h));
845 }
846
847 // Render "Spot of interest"
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);
855
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);
862
863 // Restore original graph rectangle
864 m_graph_rect = originalGraphRect;
865}
866
867void TCWin::SetTimeFactors() {
868 // Figure out this computer timezone minute offset
869 wxDateTime this_now = gTimeSource;
870 bool cur_time = !gTimeSource.IsValid();
871
872 if (cur_time) {
873 this_now = wxDateTime::Now();
874 }
875 wxDateTime this_gmt = this_now.ToGMT();
876
877#if wxCHECK_VERSION(2, 6, 2)
878 wxTimeSpan diff = this_now.Subtract(this_gmt);
879#else
880 wxTimeSpan diff = this_gmt.Subtract(this_now);
881#endif
882
883 m_diff_mins = diff.GetMinutes();
884
885 // Correct a bug in wx3.0.2
886 // If the system TZ happens to be GMT, with DST active (e.g.summer in
887 // London), then wxDateTime returns incorrect results for toGMT() method
888#if wxCHECK_VERSION(3, 0, 2)
889 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
890#endif
891
892 int station_offset = ptcmgr->GetStationTimeOffset(pIDX);
893
894 m_stationOffset_mins = station_offset;
895 if (this_now.IsDST()) {
896 m_stationOffset_mins += 60;
897 }
898
899 // Correct a bug in wx3.0.2
900 // If the system TZ happens to be GMT, with DST active (e.g.summer in
901 // London), then wxDateTime returns incorrect results for toGMT() method
902#if wxCHECK_VERSION(3, 0, 2)
903// if( this_now.IsDST() )
904// m_corr_mins +=60;
905#endif
906
907 // Establish the inital drawing day as today, in the timezone of the
908 // station
909 m_graphday = this_gmt;
910
911 int day_gmt = this_gmt.GetDayOfYear();
912
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();
918
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);
924 m_graphday.Add(dt);
925 }
926
927 wxDateTime graphday_00 = m_graphday; // this_gmt;
928 graphday_00.ResetTime();
929 time_t t_graphday_00 = graphday_00.GetTicks();
930
931 // Correct a Bug in wxWidgets time support
932 // if( !graphday_00.IsDST() && m_graphday.IsDST() ) t_graphday_00 -= 3600;
933 // if( graphday_00.IsDST() && !m_graphday.IsDST() ) t_graphday_00 += 3600;
934
935 m_t_graphday_GMT = t_graphday_00;
936
937 btc_valid = false; // Force re-calculation
938}
939
940void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
941 m_tzoneDisplay = m_choiceTimezone->GetSelection();
942 SetTimeFactors();
943
944 Refresh();
945}
946
947void TCWin::RecalculateSize() {
948 wxSize parent_size(2000, 2000);
949 if (pParent) parent_size = pParent->GetClientSize();
950
951 int unscaledheight = 600;
952 int unscaledwidth = 650;
953
954 // value of m_tcwin_scaler should be about unity on a 100 dpi display,
955 // when scale parameter g_tcwin_scale is 100
956 // parameter g_tcwin_scale is set in config file as value of
957 // TideCurrentWindowScale
958 g_tcwin_scale = wxMax(g_tcwin_scale, 10); // sanity check on g_tcwin_scale
959 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
960
961 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
962 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
963
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);
966
967 int xc = m_x + 8;
968 int yc = m_y;
969
970 // Arrange for tcWindow to be always totally visible
971 // by shifting left and/or up
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;
974
975 // Don't let the window origin move out of client area
976 if (yc < 0) yc = 0;
977 if (xc < 0) xc = 0;
978
979 if (pParent) pParent->ClientToScreen(&xc, &yc);
980 m_position = wxPoint(xc, yc);
981
982 if (m_created) {
983 SetSize(m_tc_size);
984 Move(m_position);
985 }
986}
987
988void TCWin::OKEvent(wxCommandEvent &event) {
989 Hide();
990
991 // Ensure parent pointer is cleared before any potential deletion
992 if (pParent && pParent->pCwin == this) {
993 pParent->pCwin = NULL;
994 }
995
996 // Clean up global tide window counter and associated resources
997 --gpIDXn;
998 delete m_pTCRolloverWin;
999 m_pTCRolloverWin = NULL;
1000 delete m_tList;
1001 m_tList = NULL;
1002
1003 if (pParent) {
1004 pParent->Refresh(false);
1005 }
1006
1007 // Update the config file to set the user specified time zone.
1008 if (pConfig) {
1009 pConfig->SetPath("/Settings/Others");
1010 pConfig->Write("TCWindowTimeZone", m_tzoneDisplay);
1011 }
1012
1013 Destroy(); // that hurts
1014}
1015
1016void TCWin::OnCloseWindow(wxCloseEvent &event) {
1017 Hide();
1018
1019 // Ensure parent pointer is cleared before any potential deletion
1020 if (pParent && pParent->pCwin == this) {
1021 pParent->pCwin = NULL;
1022 }
1023
1024 // Clean up global tide window counter and associated resources
1025 --gpIDXn;
1026 delete m_pTCRolloverWin;
1027 m_pTCRolloverWin = NULL;
1028 delete m_tList;
1029 m_tList = NULL;
1030
1031 // Update the config file to set the user specified time zone.
1032 if (pConfig) {
1033 pConfig->SetPath("/Settings/Others");
1034 pConfig->Write("TCWindowTimeZone", m_tzoneDisplay);
1035 }
1036
1037 Destroy(); // that hurts
1038}
1039
1040void TCWin::NXEvent(wxCommandEvent &event) {
1041 wxTimeSpan dt(24, 0, 0, 0);
1042 m_graphday.Add(dt);
1043 wxDateTime dm = m_graphday;
1044
1045 wxDateTime graphday_00 = dm.ResetTime();
1046 time_t t_graphday_00 = graphday_00.GetTicks();
1047
1048 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1049 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1050
1051 m_t_graphday_GMT = t_graphday_00;
1052
1053 btc_valid = false;
1054 Refresh();
1055}
1056
1057void TCWin::PREvent(wxCommandEvent &event) {
1058 wxTimeSpan dt(-24, 0, 0, 0);
1059 m_graphday.Add(dt);
1060 wxDateTime dm = m_graphday;
1061
1062 wxDateTime graphday_00 = dm.ResetTime();
1063 time_t t_graphday_00 = graphday_00.GetTicks();
1064
1065 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
1066 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
1067
1068 m_t_graphday_GMT = t_graphday_00;
1069
1070 btc_valid = false;
1071 Refresh();
1072}
1073
1074void TCWin::RePosition() {
1075 // Position the window
1076 double lon = pIDX->IDX_lon;
1077 double lat = pIDX->IDX_lat;
1078
1079 wxPoint r;
1080 pParent->GetCanvasPointPix(lat, lon, &r);
1081 pParent->ClientToScreen(&r.x, &r.y);
1082 Move(r);
1083}
1084
1085void TCWin::OnPaint(wxPaintEvent &event) {
1086 if (!IsShown()) {
1087 return;
1088 }
1089
1090 // With the new sizer-based layout, the main OnPaint method is simplified.
1091 // Chart rendering is now handled by the TideChartPanel's OnPaint method,
1092 // which delegates to our PaintChart() method.
1093
1094 wxPaintDC dc(this);
1095
1096 // Clear the background
1097 dc.SetBrush(wxBrush(GetBackgroundColour()));
1098 dc.SetPen(wxPen(GetBackgroundColour()));
1099 wxSize size = GetClientSize();
1100 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
1101
1102 // Note: Chart painting is now handled by TideChartPanel::OnPaint()
1103 // which calls our PaintChart() method. This eliminates the need for
1104}
1105
1106void TCWin::OnSize(wxSizeEvent &event) {
1107 if (!m_created) return;
1108
1109 // With sizer-based layout, we don't need manual positioning.
1110 // The sizers automatically handle layout when the window is resized.
1111
1112 // Force chart panel to refresh with new size
1113 if (m_chartPanel) {
1114 m_chartPanel->Refresh();
1115 }
1116
1117 // Invalidate cached chart data to force recalculation
1118 btc_valid = false;
1119
1120 // Allow sizers to handle the layout
1121 event.Skip();
1122}
1123
1124void TCWin::MouseEvent(wxMouseEvent &event) {
1125 // This is now mainly for compatibility.
1126 // Chart mouse events are handled by HandleChartMouseMove
1127 event.GetPosition(&curs_x, &curs_y);
1128
1129 if (!m_TCWinPopupTimer.IsRunning())
1130 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1131}
1132
1133void TCWin::HandleChartMouseMove(int mainWindowX, int mainWindowY,
1134 const wxPoint &chartPanelPos) {
1135 // Store the main window coordinates for compatibility with existing rollover
1136 // code
1137 curs_x = mainWindowX;
1138 curs_y = mainWindowY;
1139
1140 // Also store the chart panel relative coordinates for calculations
1141 if (m_chartPanel) {
1142 // Calculate the chart rectangle within the chart panel
1143 wxSize panelSize = m_chartPanel->GetClientSize();
1144 int left_margin = 50; // Space for Y-axis numbers and units
1145 int other_margins = 5; // Smaller margins for top, right, bottom
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; // Increased space for date display
1149 chart_height -= bottom_text_space;
1150 chart_width = wxMax(chart_width, 300);
1151 chart_height = wxMax(chart_height, 150);
1152
1153 // Update the graph rectangle to match the current chart panel layout
1154 wxPoint chartPanelPos = m_chartPanel->GetPosition();
1155 m_graph_rect =
1156 wxRect(chartPanelPos.x + left_margin, chartPanelPos.y + other_margins,
1157 chart_width, chart_height);
1158 }
1159
1160 if (!m_TCWinPopupTimer.IsRunning())
1161 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1162}
1163
1164void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1165 int x, y;
1166 bool ShowRollover;
1167
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);
1175 // doesn't really work, mouse positions are relative to rollover window
1176 // not this window.
1177 // effect: hide rollover window if mouse on rollover
1178 m_pTCRolloverWin->SetMousePropogation(1);
1179 m_pTCRolloverWin->Hide();
1180 }
1181 float t, d;
1182 wxString p, s;
1183
1184 // Calculate time based on actual chart rectangle position
1185 // t represents hours into the 25-hour display (0-25)
1186 float relativeX =
1187 (float)(curs_x - m_graph_rect.x) / (float)m_graph_rect.width;
1188 t = relativeX * 25.0f; // 25 hours displayed across the width
1189
1190 // Clamp to valid range
1191 t = wxMax(0.0f, wxMin(25.0f, t));
1192
1193 int tt = m_t_graphday_GMT + (int)(t * 3600);
1194 time_t ths = tt;
1195
1196 wxDateTime thd;
1197 thd.Set(ths);
1198 p.Printf(thd.Format("%Hh %Mmn"));
1199 p.Append("\n");
1200
1201 // The tide/current modules calculate values based on PC local time
1202 // We want UTC, so adjust accordingly
1203 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1204
1205 int ttv = tt_localtz + (int)(t * 3600);
1206 if (m_tzoneDisplay == 0) {
1207 ttv -= m_stationOffset_mins * 60; // LMT at station
1208 }
1209
1210 time_t tts = ttv;
1211
1212 // set tide level or current speed at that time
1213 ptcmgr->GetTideOrCurrent(tts, pIDX->IDX_rec_num, t, d);
1214
1215 // Convert tide/current value to preferred height units
1216 double t_converted = (t < 0 && CURRENT_PLOT == m_plot_type) ? -t : t;
1217 Station_Data *pmsd = pIDX->pref_sta_data;
1218 if (pmsd) {
1219 // Convert from station units to meters first
1220 int unit_c = TCDataFactory::findunit(pmsd->unit);
1221 if (unit_c >= 0) {
1222 t_converted =
1223 t_converted * TCDataFactory::known_units[unit_c].conv_factor;
1224 }
1225 // Now convert from meters to preferred height units
1226 t_converted = toUsrHeight(t_converted);
1227 }
1228
1229 s.Printf("%3.2f ", t_converted);
1230 p.Append(s);
1231
1232 // set unit - use preferred height unit abbreviation
1233 p.Append(getUsrHeightUnit());
1234
1235 // set current direction
1236 if (CURRENT_PLOT == m_plot_type) {
1237 s.Printf("%3.0f%c", d, 0x00B0);
1238 p.Append("\n");
1239 p.Append(s);
1240 }
1241
1242 // set rollover area size
1243 wxSize win_size;
1244 win_size.Set(x * 90 / 100, y * 80 / 100);
1245
1246 m_pTCRolloverWin->SetString(p);
1247 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1248 win_size);
1249 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1250 m_pTCRolloverWin->Refresh();
1251 m_pTCRolloverWin->Show();
1252
1253 // Mark the actual spot on the curve
1254 // x value is clear...
1255 // Find the point in the window that is used for the curve rendering,
1256 // rounding as necessary
1257
1258 int idx = 1; // in case m_graph_rect.width is weird ie ppx never > curs_x
1259 for (int i = 0; i < 26; i++) {
1260 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1261 if (ppx > curs_x) {
1262 idx = i;
1263 break;
1264 }
1265 }
1266
1267 if (m_sList.size() > 0 && idx > 0 && idx < (int)m_sList.size()) {
1268 // Use iterator to access elements in std::list
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);
1273
1274 wxPoint *a = *it_a;
1275 wxPoint *b = *it_b;
1276
1277 float pct = (curs_x - a->x) / (float)((b->x - a->x));
1278 float dy = pct * (b->y - a->y);
1279
1280 ySpot = a->y + dy;
1281 xSpot = curs_x;
1282 } else {
1283 // Fallback if we can't find the curve point
1284 xSpot = curs_x;
1285 ySpot = m_graph_rect.y + m_graph_rect.height / 2;
1286 }
1287
1288 Refresh(true);
1289
1290 } else {
1291 SetCursor(*pParent->pCursorArrow);
1292 ShowRollover = false;
1293 }
1294
1295 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1296 m_pTCRolloverWin->Hide();
1297 }
1298}
1299
1300void TCWin::OnTimeIndicatorTimer(wxTimerEvent &event) {
1301 // Refresh to update the red line (system time indicator)
1302 Refresh(false);
1303}
Minimal ChartCanvas interfaces.
Generic Chart canvas base.
Minimal ChartCAnvas interface with very little dependencies.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:173
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
Definition chcanv.cpp:4571
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.
Definition font_mgr.cpp:442
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Definition font_mgr.cpp:193
Represents an index entry for tidal and current data.
Definition idx_entry.h:48
char IDX_type
Entry type identifier "TCtcIUu".
Definition idx_entry.h:60
char IDX_reference_name[MAXNAMELEN]
Name of the reference station.
Definition idx_entry.h:81
int IDX_flood_dir
Flood current direction (in degrees)
Definition idx_entry.h:72
char IDX_station_name[MAXNAMELEN]
Name of the tidal or current station.
Definition idx_entry.h:62
char source_ident[MAXNAMELEN]
Identifier of the source (typically file name)
Definition idx_entry.h:56
int IDX_ebb_dir
Ebb current direction (in degrees)
Definition idx_entry.h:73
double IDX_lat
Latitude of the station (in degrees, +North)
Definition idx_entry.h:64
double IDX_lon
Longitude of the station (in degrees, +East)
Definition idx_entry.h:63
Station_Data * pref_sta_data
Pointer to the reference station data.
Definition idx_entry.h:96
int IDX_rec_num
Record number for multiple entries with same name.
Definition idx_entry.h:59
Definition tc_win.h:46
Global variables stored in configuration file.
Extern C linked utilities.
Font list manager.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:61
General purpose GUI support.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MyConfig * pConfig
Global instance.
Definition navutil.cpp:118
Utility functions.
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.
OpenCPN Platform specific support utilities.
Tide and current data container.
Tide and currents window.
TCMgr * ptcmgr
Global instance.
Definition tcmgr.cpp:42
Tide and Current Manager @TODO Add original author copyright.
Timer identification constants.