26#include <wx/datetime.h>
27#include <wx/dynarray.h>
29#include <wx/tokenzr.h>
31#include "model/base_platform.h"
32#include "model/cutil.h"
33#include "model/georef.h"
34#include "model/navutil_base.h"
35#include "model/route.h"
36#include "model/routeman.h"
37#include "model/route_point.h"
38#include "model/select.h"
40#include <wx/listimpl.cpp>
42WX_DEFINE_LIST(RoutePointList);
44wxColour g_colourWaypointRangeRingsColour;
51 [](unsigned,
const unsigned *) { assert(
true); };
53RoutePoint::RoutePoint() {
87 m_GUID = pWayPointMan->CreateGUID(
this);
89 m_IconName = wxEmptyString;
91 m_MarkName = wxEmptyString;
104 m_ScaMin = g_iWpt_ScaMin;
107 b_UseScamin = g_bUseWptScaMin;
110 m_bDrawDragHandle =
false;
111 m_dragIconTexture = 0;
112 m_draggingOffsetx = m_draggingOffsety = 0;
120 m_MarkName = orig->GetName();
137 SetShared(orig->IsShared());
146 m_ScaMin = orig->m_ScaMin;
147 m_ScaMax = orig->m_ScaMax;
149 m_IconName = orig->m_IconName;
154 m_GUID = pWayPointMan->CreateGUID(
this);
157 m_ManagerNode = NULL;
165 m_ScaMin = orig->m_ScaMin;
166 m_ScaMax = orig->m_ScaMax;
167 b_UseScamin = orig->b_UseScamin;
170 m_bDrawDragHandle =
false;
171 m_dragIconTexture = 0;
172 m_draggingOffsetx = m_draggingOffsety = 0;
175RoutePoint::RoutePoint(
double lat,
double lon,
const wxString &icon_ident,
176 const wxString &name,
const wxString &pGUID,
185 else if (m_lon > 180.)
211 m_bPreScaled =
false;
214 m_ManagerNode = NULL;
215 m_IconScaleFactor = 1.0;
216 m_ScaMin = MAX_INT_VAL;
223 if (!pGUID.IsEmpty())
226 m_GUID = pWayPointMan->CreateGUID(
this);
229 m_IconName = icon_ident;
236 if (bAddToList && NULL != pWayPointMan) pWayPointMan->
AddRoutePoint(
this);
241 SetWaypointArrivalRadius(g_n_arrival_circle_radius);
249 m_ScaMin = g_iWpt_ScaMin;
251 b_UseScamin = g_bUseWptScaMin;
254 m_bDrawDragHandle =
false;
255 m_dragIconTexture = 0;
256 m_draggingOffsetx = m_draggingOffsety = 0;
261RoutePoint::~RoutePoint() {
281void RoutePoint::SetName(
const wxString &name) {
287 CalculateNameExtents();
290void RoutePoint::CalculateNameExtents(
void) {
296 dc.GetTextExtent(m_MarkName, &w, &h, NULL, NULL,
m_pMarkFont);
306bool RoutePoint::IsVisibleSelectable(
double scale_val,
bool boverrideViz) {
316 if (g_bOverruleScaMin)
318 else if (scale_val >= (
double)(m_ScaMin + 1))
324bool RoutePoint::IsSharedInVisibleRoute() {
330 bool brp_viz =
false;
332 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
334 if (pr->IsVisible()) {
347void RoutePoint::SetPosition(
double lat,
double lon) {
352bool RoutePoint::IsSame(
RoutePoint *pOtherRP) {
355 if (this->m_MarkName == pOtherRP->m_MarkName) {
356 if (fabs(this->m_lat - pOtherRP->m_lat) < 1.e-6 &&
357 fabs(this->m_lon - pOtherRP->m_lon) < 1.e-6)
369 bool b_numeric =
false;
371 if (GetName().Len() >= 2) {
372 wxString substring = GetName().Left(2);
373 if (substring ==
"NM") {
374 substring = GetName().substr(2, 3);
376 substring = GetName().Left(3);
379 for (
unsigned int i = 0; i < substring.Len(); i++) {
380 if (b_numeric ==
true) {
381 b_numeric = wxIsdigit(substring[i]);
389double RoutePoint::GetWaypointArrivalRadius() {
391 SetWaypointArrivalRadius(g_n_arrival_circle_radius);
397int RoutePoint::GetWaypointRangeRingsNumber() {
399 return g_iWaypointRangeRingsNumber;
404float RoutePoint::GetWaypointRangeRingsStep() {
406 return g_fWaypointRangeRingsStep;
411int RoutePoint::GetWaypointRangeRingsStepUnits() {
413 return g_iWaypointRangeRingsStepUnits;
418void RoutePoint::SetScaMin(
long val) {
419 if (val < SCAMIN_MIN)
422 if (val < (
long)m_ScaMax * 5) val = (long)m_ScaMax * 5;
425void RoutePoint::SetScaMin(wxString str) {
427 if (!str.ToLong(&val)) val = MAX_INT_VAL;
431void RoutePoint::SetScaMax(
long val) {
432 if (val > (
int)m_ScaMin / 5)
433 m_ScaMax = (int)m_ScaMin /
436void RoutePoint::SetScaMax(wxString str) {
438 if (!str.ToLong(&val)) val = 0;
442void RoutePoint::SetPlannedSpeed(
double spd) {
443 if (spd >= 0.0 && spd <= 1000.0) m_PlannedSpeed = spd;
447 if (m_PlannedSpeed < 0.0001 &&
455 if (!s_vmg.ToDouble(&vmg)) {
457 SetPlannedSpeed(vmg);
460 return m_PlannedSpeed;
472 wxDateTime etd = wxInvalidDateTime;
476 const wxChar *parse_return = etd.ParseDateTime(s_etd);
478 wxString tz(parse_return);
480 if (tz.Find(_T(
"UT")) != wxNOT_FOUND) {
486 if (tz.Find(_T(
"LMT")) != wxNOT_FOUND) {
488 long lmt_offset = (long)((m_lon * 3600.) / 15.);
489 wxTimeSpan lmt(0, 0, (
int)lmt_offset, 0);
495 if (etd.IsValid() && (!
GetETA().IsValid() || etd >
GetETA())) {
505 return wxInvalidDateTime;
512 return wxInvalidDateTime;
519 return wxInvalidDateTime;
526 return wxEmptyString;
529void RoutePoint::SetETE(wxLongLong secs) {
m_seg_ete = secs; }
543 wxString::const_iterator end;
547 if (tmp.ParseISOCombined(ts)) {
550 }
else if (tmp.ParseDateTime(ts, &end)) {
Represents a waypoint or mark within the navigation system.
HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
wxColour m_wxcWaypointRangeRingsColour
Color for the range rings display.
wxString m_MarkDescription
Description text for the waypoint.
int m_iWaypointRangeRingsNumber
Number of range rings to display around the waypoint.
int m_NameLocationOffsetX
Horizontal offset for waypoint name placement relative to the icon.
void SetCreateTime(wxDateTime dt)
Sets the create time of this RoutePoint in UTC.
static std::function< void(unsigned, const unsigned *)> delete_gl_textures
Horrible Hack (tm).
bool m_bRPIsBeingEdited
Flag indicating if this waypoint is currently being edited.
wxRect CurrentRect_in_DC
Current rectangle occupied by the waypoint in the display.
unsigned int m_iTextTexture
Texture identifier for rendered text.
wxString m_GUID
Globally Unique Identifier for the waypoint.
wxDateTime GetETD()
Retrieves the Estimated Time of Departure for this waypoint, in UTC.
wxDateTime m_CreateTimeX
Creation timestamp for the waypoint, in UTC.
int m_NameLocationOffsetY
Vertical offset for waypoint name placement relative to the icon.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
bool m_pos_on_screen
Flag indicating if the waypoint is currently visible on screen.
bool m_bIsActive
Flag indicating if this waypoint is active for navigation.
wxDateTime GetManualETD()
Retrieves the manually set Estimated Time of Departure for this waypoint, in UTC.
wxDateTime m_seg_etd
Estimated Time of Departure from this waypoint, in UTC.
bool m_bIsInRoute
Flag indicating if this waypoint is part of a route.
bool m_IconIsDirty
Flag indicating if the waypoint icon needs to be reloaded or redrawn.
wxFont * m_pMarkFont
Font used for rendering the waypoint name.
double m_seg_len
Length of the leg from previous waypoint to this waypoint in nautical miles.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
wxString GetETE()
Retrieves the Estimated Time En route as a formatted string.
wxString m_timestring
String representation of the waypoint creation time.
bool m_bBlink
Flag indicating if the waypoint should blink when displayed.
double GetPlannedSpeed()
Return the planned speed associated with this waypoint.
bool m_bPtIsSelected
Flag indicating if this waypoint is currently selected.
bool m_bIsVisible
Flag indicating if the waypoint should be drawn on the chart.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
double m_WaypointArrivalRadius
Arrival radius in nautical miles.
bool m_btemp
Flag indicating if this is a temporary waypoint.
bool m_manual_etd
Flag indicating whether the ETD has been manually set by the user.
double m_seg_vmg
Planned speed for traveling FROM this waypoint TO the next waypoint.
wxSize m_NameExtents
Size of the waypoint name text when rendered.
wxDateTime m_seg_eta
Estimated Time of Arrival at this waypoint, in UTC.
int m_LayerID
Layer identifier if the waypoint belongs to a layer.
int m_iWaypointRangeRingsStepUnits
Units for the range rings step (0=nm, 1=km).
wxDateTime GetCreateTime(void)
Returns the Create Time of this RoutePoint in UTC.
float m_fWaypointRangeRingsStep
Distance between consecutive range rings.
wxLongLong m_seg_ete
Estimated Time Enroute for the leg leading to this waypoint.
wxString m_TideStation
Associated tide station identifier.
bool m_bShowWaypointRangeRings
Flag indicating if range rings should be shown around the waypoint.
void SetETD(const wxDateTime &etd)
Sets the Estimated Time of Departure for this waypoint, in UTC.
wxDateTime GetETA()
Retrieves the Estimated Time of Arrival for this waypoint, in UTC.
bool m_bIsListed
Flag indicating if the waypoint should appear in the Route Manager dialog's waypoint list.
Represents a navigational route in the navigation system.
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
bool AddRoutePoint(RoutePoint *prp)
Add a point to list which owns it.
bool RemoveRoutePoint(RoutePoint *prp)
Remove a routepoint from list if present, deallocate it all cases.