24 #include <wx/colour.h>
25 #include <wx/datetime.h>
26 #include <wx/dynarray.h>
27 #include <wx/string.h>
28 #include <wx/tokenzr.h>
30 #include "model/base_platform.h"
31 #include "model/cutil.h"
32 #include "model/georef.h"
33 #include "model/navutil_base.h"
34 #include "model/route.h"
35 #include "model/routeman.h"
36 #include "model/route_point.h"
37 #include "model/select.h"
39 #include <wx/listimpl.cpp>
41 WX_DEFINE_LIST(RoutePointList);
43 wxColour g_colourWaypointRangeRingsColour;
50 = [](unsigned,
const unsigned*) { assert(
true); };
52 RoutePoint::RoutePoint() {
59 m_seg_etd = wxInvalidDateTime;
62 m_seg_eta = wxInvalidDateTime;
63 m_bDynamicName =
false;
64 m_bPtIsSelected =
false;
65 m_bRPIsBeingEdited =
false;
69 m_CreateTimeX = wxDateTime::Now();
70 m_bIsolatedMark =
false;
75 CurrentRect_in_DC = wxRect(0, 0, 0, 0);
76 m_NameLocationOffsetX = -10;
77 m_NameLocationOffsetY = 8;
85 m_HyperlinkList =
new HyperlinkList;
87 m_GUID = pWayPointMan->CreateGUID(
this);
89 m_IconName = wxEmptyString;
91 m_MarkName = wxEmptyString;
96 m_WaypointArrivalRadius = g_n_arrival_circle_radius;
98 m_bShowWaypointRangeRings = (bool)g_iWaypointRangeRingsNumber;
100 m_iWaypointRangeRingsNumber = g_iWaypointRangeRingsNumber;
101 m_fWaypointRangeRingsStep = g_fWaypointRangeRingsStep;
102 m_iWaypointRangeRingsStepUnits = g_iWaypointRangeRingsStepUnits;
103 m_wxcWaypointRangeRingsColour = g_colourWaypointRangeRingsColour;
104 m_ScaMin = g_iWpt_ScaMin;
105 m_bShowName = g_bShowWptName;
107 b_UseScamin = g_bUseWptScaMin;
109 m_pos_on_screen =
false;
110 m_bDrawDragHandle =
false;
111 m_dragIconTexture = 0;
112 m_draggingOffsetx = m_draggingOffsety = 0;
115 m_IconIsDirty =
true;
120 m_MarkName = orig->GetName();
123 m_seg_len = orig->m_seg_len;
124 m_seg_vmg = orig->m_seg_vmg;
126 m_seg_etd = orig->m_seg_etd;
127 m_manual_etd =
false;
129 m_bDynamicName = orig->m_bDynamicName;
130 m_bPtIsSelected = orig->m_bPtIsSelected;
131 m_bRPIsBeingEdited = orig->m_bRPIsBeingEdited;
132 m_bIsActive = orig->m_bIsActive;
133 m_bBlink = orig->m_bBlink;
134 m_bIsInRoute = orig->m_bIsInRoute;
135 m_CreateTimeX = orig->m_CreateTimeX;
136 m_bIsolatedMark = orig->m_bIsolatedMark;
137 m_bShowName = orig->m_bShowName;
138 SetShared(orig->IsShared());
139 m_bIsVisible = orig->m_bIsVisible;
140 m_bIsListed = orig->m_bIsListed;
141 CurrentRect_in_DC = orig->CurrentRect_in_DC;
142 m_NameLocationOffsetX = orig->m_NameLocationOffsetX;
143 m_NameLocationOffsetY = orig->m_NameLocationOffsetY;
144 m_pMarkFont = orig->m_pMarkFont;
145 m_MarkDescription = orig->m_MarkDescription;
146 m_btemp = orig->m_btemp;
147 m_ScaMin = orig->m_ScaMin;
148 m_ScaMax = orig->m_ScaMax;
149 m_HyperlinkList =
new HyperlinkList;
150 m_IconName = orig->m_IconName;
151 m_TideStation = orig->m_TideStation;
152 SetPlannedSpeed(orig->GetPlannedSpeed());
154 m_bIsInLayer = orig->m_bIsInLayer;
155 m_GUID = pWayPointMan->CreateGUID(
this);
158 m_ManagerNode = NULL;
160 m_WaypointArrivalRadius = orig->GetWaypointArrivalRadius();
161 m_bShowWaypointRangeRings = orig->m_bShowWaypointRangeRings;
162 m_iWaypointRangeRingsNumber = orig->m_iWaypointRangeRingsNumber;
163 m_fWaypointRangeRingsStep = orig->m_fWaypointRangeRingsStep;
164 m_iWaypointRangeRingsStepUnits = orig->m_iWaypointRangeRingsStepUnits;
165 m_wxcWaypointRangeRingsColour = orig->m_wxcWaypointRangeRingsColour;
166 m_ScaMin = orig->m_ScaMin;
167 m_ScaMax = orig->m_ScaMax;
168 b_UseScamin = orig->b_UseScamin;
169 m_IconIsDirty = orig->m_IconIsDirty;
171 m_bDrawDragHandle =
false;
172 m_dragIconTexture = 0;
173 m_draggingOffsetx = m_draggingOffsety = 0;
176 RoutePoint::RoutePoint(
double lat,
double lon,
const wxString &icon_ident,
177 const wxString &name,
const wxString &pGUID,
186 else if (m_lon > 180.)
193 m_seg_etd = wxInvalidDateTime;
194 m_manual_etd =
false;
196 m_bDynamicName =
false;
197 m_bPtIsSelected =
false;
198 m_bRPIsBeingEdited =
false;
201 m_bIsInRoute =
false;
202 m_CreateTimeX = wxDateTime::Now();
203 m_bIsolatedMark =
false;
208 CurrentRect_in_DC = wxRect(0, 0, 0, 0);
209 m_NameLocationOffsetX = -10;
210 m_NameLocationOffsetY = 8;
213 m_bPreScaled =
false;
216 m_ManagerNode = NULL;
217 m_IconScaleFactor = 1.0;
218 m_ScaMin = MAX_INT_VAL;
220 m_HyperlinkList =
new HyperlinkList;
221 m_IconIsDirty =
true;
225 if (!pGUID.IsEmpty())
228 m_GUID = pWayPointMan->CreateGUID(
this);
231 m_IconName = icon_ident;
238 if (bAddToList && NULL != pWayPointMan) pWayPointMan->AddRoutePoint(
this);
240 m_bIsInLayer =
false;
243 SetWaypointArrivalRadius(g_n_arrival_circle_radius);
245 m_bShowWaypointRangeRings = (bool)g_iWaypointRangeRingsNumber;
247 m_iWaypointRangeRingsNumber = g_iWaypointRangeRingsNumber;
248 m_fWaypointRangeRingsStep = g_fWaypointRangeRingsStep;
249 m_iWaypointRangeRingsStepUnits = g_iWaypointRangeRingsStepUnits;
250 m_wxcWaypointRangeRingsColour = g_colourWaypointRangeRingsColour;
251 m_ScaMin = g_iWpt_ScaMin;
253 b_UseScamin = g_bUseWptScaMin;
254 m_bShowName = g_bShowWptName;
256 m_bDrawDragHandle =
false;
257 m_dragIconTexture = 0;
258 m_draggingOffsetx = m_draggingOffsety = 0;
263 RoutePoint::~RoutePoint() {
265 if (NULL != pWayPointMan) pWayPointMan->RemoveRoutePoint(
this);
267 if (m_HyperlinkList) {
268 m_HyperlinkList->DeleteContents(
true);
269 delete m_HyperlinkList;
274 wxDateTime RoutePoint::GetCreateTime() {
275 if (!m_CreateTimeX.IsValid()) {
276 if (m_timestring.Len()) ParseGPXDateTime(m_CreateTimeX, m_timestring);
278 return m_CreateTimeX;
281 void RoutePoint::SetCreateTime(wxDateTime dt) { m_CreateTimeX = dt; }
283 void RoutePoint::SetName(
const wxString &name) {
284 if (m_iTextTexture) {
289 CalculateNameExtents();
292 void RoutePoint::CalculateNameExtents(
void) {
298 dc.GetTextExtent(m_MarkName, &w, &h, NULL, NULL, m_pMarkFont);
299 m_NameExtents = wxSize(w, h);
301 dc.SetFont(*m_pMarkFont);
302 m_NameExtents = dc.GetMultiLineTextExtent(m_MarkName);
305 m_NameExtents = wxSize(0, 0);
309 bool RoutePoint::IsVisibleSelectable(
double scale_val,
bool boverrideViz) {
319 if (g_bOverruleScaMin)
321 else if (scale_val >= (
double)(m_ScaMin + 1))
327 bool RoutePoint::IsSharedInVisibleRoute() {
330 wxArrayPtrVoid *proute_array = g_pRouteMan->GetRouteArrayContaining(
this);
333 bool brp_viz =
false;
335 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
337 if (pr->IsVisible()) {
349 void RoutePoint::SetPosition(
double lat,
double lon) {
354 bool RoutePoint::IsSame(
RoutePoint *pOtherRP) {
357 if (this->m_MarkName == pOtherRP->m_MarkName) {
358 if (fabs(this->m_lat - pOtherRP->m_lat) < 1.e-6 &&
359 fabs(this->m_lon - pOtherRP->m_lon) < 1.e-6)
365 double RoutePoint::GetWaypointArrivalRadius() {
366 if ((m_WaypointArrivalRadius >= 0) && (m_WaypointArrivalRadius < 0.001)) {
367 SetWaypointArrivalRadius(g_n_arrival_circle_radius);
368 return m_WaypointArrivalRadius;
370 return m_WaypointArrivalRadius;
373 int RoutePoint::GetWaypointRangeRingsNumber() {
374 if (m_iWaypointRangeRingsNumber == -1)
375 return g_iWaypointRangeRingsNumber;
377 return m_iWaypointRangeRingsNumber;
380 float RoutePoint::GetWaypointRangeRingsStep() {
381 if (m_fWaypointRangeRingsStep == -1)
382 return g_fWaypointRangeRingsStep;
384 return m_fWaypointRangeRingsStep;
387 int RoutePoint::GetWaypointRangeRingsStepUnits() {
388 if (m_iWaypointRangeRingsStepUnits == -1)
389 return g_iWaypointRangeRingsStepUnits;
391 return m_iWaypointRangeRingsStepUnits;
394 void RoutePoint::SetScaMin(
long val) {
395 if (val < SCAMIN_MIN)
398 if (val < (
long)m_ScaMax * 5) val = (long)m_ScaMax * 5;
401 void RoutePoint::SetScaMin(wxString str) {
403 if (!str.ToLong(&val)) val = MAX_INT_VAL;
407 void RoutePoint::SetScaMax(
long val) {
408 if (val > (
int)m_ScaMin / 5)
409 m_ScaMax = (int)m_ScaMin /
412 void RoutePoint::SetScaMax(wxString str) {
414 if (!str.ToLong(&val)) val = 0;
418 void RoutePoint::SetPlannedSpeed(
double spd) {
419 if (spd >= 0.0 && spd <= 1000.0) m_PlannedSpeed = spd;
422 double RoutePoint::GetPlannedSpeed() {
423 if (m_PlannedSpeed < 0.0001 &&
424 m_MarkDescription.Find(_T(
"VMG=")) != wxNOT_FOUND) {
428 (m_MarkDescription.Mid(m_MarkDescription.Find(_T(
"VMG=")) + 4))
431 if (!s_vmg.ToDouble(&vmg)) {
432 m_MarkDescription.Replace(_T(
"VMG=") + s_vmg +
";", wxEmptyString);
433 SetPlannedSpeed(vmg);
436 return m_PlannedSpeed;
439 wxDateTime RoutePoint::GetETD() {
440 if (m_seg_etd.IsValid()) {
441 if (!GetETA().IsValid() || m_seg_etd > GetETA()) {
447 if (m_MarkDescription.Find(_T(
"ETD=")) != wxNOT_FOUND) {
448 wxDateTime etd = wxInvalidDateTime;
450 (m_MarkDescription.Mid(m_MarkDescription.Find(_T(
"ETD=")) + 4))
452 const wxChar *parse_return = etd.ParseDateTime(s_etd);
454 wxString tz(parse_return);
456 if (tz.Find(_T(
"UT")) != wxNOT_FOUND) {
459 if (tz.Find(_T(
"LMT")) != wxNOT_FOUND) {
461 long lmt_offset = (long)((m_lon * 3600.) / 15.);
462 wxTimeSpan lmt(0, 0, (
int)lmt_offset, 0);
465 m_seg_etd = etd.ToUTC();
468 if (etd.IsValid() && (!GetETA().IsValid() || etd > GetETA())) {
469 m_MarkDescription.Replace(s_etd, wxEmptyString);
478 return wxInvalidDateTime;
481 wxDateTime RoutePoint::GetManualETD() {
482 if (m_manual_etd && m_seg_etd.IsValid()) {
485 return wxInvalidDateTime;
488 wxDateTime RoutePoint::GetETA() {
489 if (m_seg_eta.IsValid()) {
492 return wxInvalidDateTime;
495 wxString RoutePoint::GetETE() {
496 if (m_seg_ete != 0) {
497 return formatTimeDelta(m_seg_ete);
499 return wxEmptyString;
502 void RoutePoint::SetETE(wxLongLong secs) { m_seg_ete = secs; }
504 void RoutePoint::SetETD(
const wxDateTime &etd) {
509 bool RoutePoint::SetETD(
const wxString &ts) {
511 m_seg_etd = wxInvalidDateTime;
512 m_manual_etd =
false;
516 wxString::const_iterator end;
517 if (tmp.ParseISOCombined(ts)) {
520 }
else if (tmp.ParseDateTime(ts, &end)) {
static std::function< void(unsigned, const unsigned *)> delete_gl_textures
Horrible Hack (tm).