29#include "model/nav_object_database.h"
40 pSelectList =
new SelectableItemList;
50bool Select::IsSelectableRoutePointValid(
RoutePoint *pRoutePoint) {
55 if (pFindSel->m_seltype == SELTYPE_ROUTEPOINT &&
56 (
RoutePoint *)pFindSel->m_pData1 == pRoutePoint)
62bool Select::AddSelectableRoutePoint(
float slat,
float slon,
65 pSelItem->m_slat = slat;
66 pSelItem->m_slon = slon;
67 pSelItem->m_seltype = SELTYPE_ROUTEPOINT;
68 pSelItem->m_bIsSelected =
false;
69 pSelItem->m_pData1 = pRoutePointAdd;
72 pSelectList->push_back(pSelItem);
74 pSelectList->insert(pSelectList->begin(), pSelItem);
76 pRoutePointAdd->SetSelectNode(pSelItem);
81bool Select::AddSelectableRouteSegment(
float slat1,
float slon1,
float slat2,
86 pSelItem->m_slat = slat1;
87 pSelItem->m_slon = slon1;
88 pSelItem->m_slat2 = slat2;
89 pSelItem->m_slon2 = slon2;
90 pSelItem->m_seltype = SELTYPE_ROUTESEGMENT;
91 pSelItem->m_bIsSelected =
false;
92 pSelItem->m_pData1 = pRoutePointAdd1;
93 pSelItem->m_pData2 = pRoutePointAdd2;
94 pSelItem->m_pData3 = pRoute;
97 pSelectList->push_back(pSelItem);
99 pSelectList->insert(pSelectList->begin(), pSelItem);
104bool Select::DeleteAllSelectableRouteSegments(
Route *pr) {
108 auto node = pSelectList->begin();
110 while (node != pSelectList->end()) {
112 if (pFindSel->m_seltype == SELTYPE_ROUTESEGMENT &&
113 (
Route *)pFindSel->m_pData3 == pr) {
117 auto pos = std::find(pSelectList->begin(), pSelectList->end(), *d);
118 if (pos != pSelectList->end()) pSelectList->erase(pos);
127bool Select::DeleteAllSelectableRoutePoints(
Route *pr) {
131 auto node = pSelectList->begin();
133 while (node != pSelectList->end()) {
135 if (pFindSel->m_seltype == SELTYPE_ROUTEPOINT) {
138 bool is_restarted =
false;
139 for (
RoutePoint *prp : *pr->pRoutePointList) {
142 std::find(pSelectList->begin(), pSelectList->end(), pFindSel);
143 if (pos != pSelectList->end()) pSelectList->erase(pos);
145 prp->SetSelectNode(
nullptr);
146 node = pSelectList->begin();
151 if (!is_restarted) ++node;
159bool Select::AddAllSelectableRoutePoints(
Route *pr) {
161 for (
RoutePoint *prp : *pr->pRoutePointList) {
162 AddSelectableRoutePoint(prp->m_lat, prp->m_lon, prp);
169bool Select::AddAllSelectableRouteSegments(
Route *pr) {
171 float slat1, slon1, slat2, slon2;
183 AddSelectableRouteSegment(slat1, slon1, slat2, slon2, prp0, prp, pr);
194bool Select::AddAllSelectableTrackSegments(
Track *pr) {
196 float slat1, slon1, slat2, slon2;
198 if (pr->GetnPoints()) {
203 for (
int i = 1; i < pr->GetnPoints(); i++) {
208 AddSelectableTrackSegment(slat1, slon1, slat2, slon2, prp0, prp, pr);
219bool Select::UpdateSelectableRouteSegments(
RoutePoint *prp) {
222 if (pFindSel->m_seltype == SELTYPE_ROUTESEGMENT) {
223 if (pFindSel->m_pData1 == prp) {
224 pFindSel->m_slat = prp->m_lat;
225 pFindSel->m_slon = prp->m_lon;
227 }
else if (pFindSel->m_pData2 == prp) {
228 pFindSel->m_slat2 = prp->m_lat;
229 pFindSel->m_slon2 = prp->m_lon;
238SelectItem *Select::AddSelectablePoint(
float slat,
float slon,
239 const void *pdata,
int fseltype) {
242 pSelItem->m_slat = slat;
243 pSelItem->m_slon = slon;
244 pSelItem->m_seltype = fseltype;
245 pSelItem->m_bIsSelected =
false;
246 pSelItem->m_pData1 = pdata;
248 pSelectList->push_back(pSelItem);
263bool Select::DeleteSelectablePoint(
void *pdata,
int SeltypeToDelete) {
268 auto node = pSelectList->begin();
270 while (node != pSelectList->end()) {
272 if (pFindSel->m_seltype == SeltypeToDelete) {
273 if (pdata == pFindSel->m_pData1) {
275 std::find(pSelectList->begin(), pSelectList->end(), pFindSel);
276 if (pos != pSelectList->end()) pSelectList->erase(pos);
278 if (SELTYPE_ROUTEPOINT == SeltypeToDelete) {
280 prp->SetSelectNode(NULL);
292bool Select::DeleteAllSelectableTypePoints(
int SeltypeToDelete) {
296 auto node = pSelectList->begin();
298 while (node != pSelectList->end()) {
300 if (pFindSel->m_seltype == SeltypeToDelete) {
301 auto pos = std::find(pSelectList->begin(), pSelectList->end(), pFindSel);
302 if (pos != pSelectList->end()) pSelectList->erase(pos);
303 if (SELTYPE_ROUTEPOINT == SeltypeToDelete) {
305 prp->SetSelectNode(NULL);
308 node = pSelectList->begin();
316bool Select::DeleteSelectableRoutePoint(
RoutePoint *prp) {
317 if (!prp)
return false;
318 auto *pFindSel = (
SelectItem *)prp->GetSelectNode();
320 auto pos = std::find(pSelectList->begin(), pSelectList->end(), pFindSel);
321 if (pos != pSelectList->end()) pSelectList->erase(pos);
323 prp->SetSelectNode(
nullptr);
326 return DeleteSelectablePoint(prp, SELTYPE_ROUTEPOINT);
330bool Select::ModifySelectablePoint(
float lat,
float lon,
void *data,
331 int SeltypeToModify) {
336 if (pFindSel->m_seltype == SeltypeToModify) {
337 if (data == pFindSel->m_pData1) {
338 pFindSel->m_slat = lat;
339 pFindSel->m_slon = lon;
347bool Select::AddSelectableTrackSegment(
float slat1,
float slon1,
float slat2,
352 pSelItem->m_slat = slat1;
353 pSelItem->m_slon = slon1;
354 pSelItem->m_slat2 = slat2;
355 pSelItem->m_slon2 = slon2;
356 pSelItem->m_seltype = SELTYPE_TRACKSEGMENT;
357 pSelItem->m_bIsSelected =
false;
358 pSelItem->m_pData1 = pTrackPointAdd1;
359 pSelItem->m_pData2 = pTrackPointAdd2;
360 pSelItem->m_pData3 = pTrack;
362 if (pTrack->m_bIsInLayer)
363 pSelectList->push_back(pSelItem);
365 pSelectList->insert(pSelectList->begin(), pSelItem);
370bool Select::DeleteAllSelectableTrackSegments(
Track *pt) {
374 auto node = pSelectList->begin();
376 while (node != pSelectList->end()) {
378 if (pFindSel->m_seltype == SELTYPE_TRACKSEGMENT &&
379 (
Track *)pFindSel->m_pData3 == pt) {
383 auto pos = std::find(pSelectList->begin(), pSelectList->end(), *d);
384 if (pos != pSelectList->end()) pSelectList->erase(pos);
392bool Select::DeletePointSelectableTrackSegments(
TrackPoint *pt) {
396 auto node = pSelectList->begin();
398 while (node != pSelectList->end()) {
400 if (pFindSel->m_seltype == SELTYPE_TRACKSEGMENT &&
406 auto pos = std::find(pSelectList->begin(), pSelectList->end(), *d);
407 if (pos != pSelectList->end()) pSelectList->erase(pos);
415bool Select::IsSegmentSelected(
float a,
float b,
float c,
float d,
float slat,
421 if (a > 90.0) a -= 180.0;
422 if (b > 90.0) b -= 180.0;
423 if (c > 180.0) c -= 360.0;
424 if (d > 180.0) d -= 360.0;
425 if (slat > 90.0) slat -= 180.0;
426 if (slon > 180.0) slon -= 360.0;
431 DistanceBearingMercator(a, c, b, d, &brg, &dist);
445 if (slon < 0.) adder = 360.;
450 if ((slat >= (fmin(a, b) - selectRadius)) &&
451 (slat <= (fmax(a, b) + selectRadius)) &&
452 ((slon + adder) >= (fmin(c, d) - selectRadius)) &&
453 ((slon + adder) <= (fmax(c, d) + selectRadius))) {
459 toSM(a, c, 0., 0., &cp, &ap);
461 toSM(b, d, 0., 0., &dp, &bp);
463 toSM(slat, slon + adder, 0., 0., &slonp, &slatp);
470 double delta = vGetLengthOfNormal(&va, &vb, &vn);
471 if (fabs(delta) < (selectRadius * 1852 * 60))
return true;
476void Select::CalcSelectRadius(
SelectCtx &ctx) {
477 selectRadius = pixelRadius / (ctx.scale * 1852 * 60);
485 CalcSelectRadius(ctx);
490 if (pFindSel->m_seltype == fseltype) {
492 case SELTYPE_ROUTEPOINT:
493 case SELTYPE_TIDEPOINT:
494 case SELTYPE_CURRENTPOINT:
495 case SELTYPE_AISTARGET:
496 if ((fabs(slat - pFindSel->m_slat) < selectRadius) &&
497 (fabs(slon - pFindSel->m_slon) < selectRadius)) {
498 if (fseltype == SELTYPE_ROUTEPOINT) {
500 ->IsVisibleSelectable(ctx.chart_scale))
507 case SELTYPE_ROUTESEGMENT:
508 case SELTYPE_TRACKSEGMENT: {
509 a = pFindSel->m_slat;
510 b = pFindSel->m_slat2;
511 c = pFindSel->m_slon;
512 d = pFindSel->m_slon2;
514 if (IsSegmentSelected(a, b, c, d, slat, slon))
goto find_ok;
528bool Select::IsSelectableSegmentSelected(
SelectCtx &ctx,
float slat,
float slon,
532 if (pFindSel == si) {
538 if (valid ==
false) {
542 CalcSelectRadius(ctx);
544 float a = pFindSel->m_slat;
545 float b = pFindSel->m_slat2;
546 float c = pFindSel->m_slon;
547 float d = pFindSel->m_slon2;
549 return IsSegmentSelected(a, b, c, d, slat, slon);
553 if (ctx.show_nav_objects)
return true;
558 rte = FindRouteContainingWaypoint(wp);
559 if (rte && rte->IsActive())
return true;
564SelectableItemList Select::FindSelectionList(
SelectCtx &ctx,
float slat,
565 float slon,
int fseltype) {
568 SelectableItemList ret_list;
570 CalcSelectRadius(ctx);
575 if (pFindSel->m_seltype == fseltype) {
577 case SELTYPE_ROUTEPOINT:
578 if ((fabs(slat - pFindSel->m_slat) < selectRadius) &&
579 (fabs(slon - pFindSel->m_slon) < selectRadius))
580 if (is_selectable_wp(ctx, (
RoutePoint *)pFindSel->m_pData1))
582 ->IsVisibleSelectable(ctx.chart_scale))
583 ret_list.push_back(pFindSel);
585 case SELTYPE_TIDEPOINT:
586 case SELTYPE_CURRENTPOINT:
587 case SELTYPE_AISTARGET:
588 case SELTYPE_DRAGHANDLE:
589 if ((fabs(slat - pFindSel->m_slat) < selectRadius) &&
590 (fabs(slon - pFindSel->m_slon) < selectRadius)) {
591 if (is_selectable_wp(ctx, (
RoutePoint *)pFindSel->m_pData1))
592 ret_list.push_back(pFindSel);
595 case SELTYPE_ROUTESEGMENT:
596 case SELTYPE_TRACKSEGMENT: {
597 a = pFindSel->m_slat;
598 b = pFindSel->m_slat2;
599 c = pFindSel->m_slon;
600 d = pFindSel->m_slon2;
602 if (IsSegmentSelected(a, b, c, d, slat, slon)) {
603 if (ctx.show_nav_objects ||
604 (fseltype == SELTYPE_ROUTESEGMENT &&
605 ((
Route *)pFindSel->m_pData3)->m_bRtIsActive)) {
606 ret_list.push_back(pFindSel);
Represents a waypoint or mark within the navigation system.
bool m_bIsActive
Flag indicating if this waypoint is active for navigation.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
Represents a navigational route in the navigation system.
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
bool m_bIsInLayer
Flag indicating whether this route belongs to a layer.
Represents a single point in a track.
Represents a track, which is a series of connected track points.
Select * pSelect
Global instance.
Select * pSelectTC
Global instance.
Selected route, segment, waypoint, etc.
Recorded track abstraction.