OpenCPN Partial API docs
route_ctx_factory.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Wrapper for creating a RouteCtx based on global vars
5  * Author: Alec Leamas
6  *
7  ***************************************************************************
8  * Copyright (C) 2023 by Alec Leamas
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  **************************************************************************/
25 #ifndef _ROUTE_CTX_FACTORY_H__
26 #define _ROUTE_CTX_FACTORY_H__
27 
28 #include <wx/string.h>
29 
30 #include "model/nav_object_database.h"
31 #include "model/routeman.h"
32 #include "model/track.h"
33 
34 extern WayPointman* pWayPointMan;
35 extern Routeman *g_pRouteMan;
36 extern std::vector<Track*> g_TrackList;
37 
38 RouteCtx RouteCtxFactory() {
39  RouteCtx ctx;
40  ctx.find_route_by_guid =
41  [](wxString guid) {
42  if (!g_pRouteMan) return static_cast<Route*>(0);
43  return g_pRouteMan->FindRouteByGUID(guid); };
44  ctx.find_track_by_guid =
45  [](wxString guid) {
46  if (!g_pRouteMan) return static_cast<Track*>(0);
47  return g_pRouteMan->FindTrackByGUID(guid); };
48  ctx.find_wpt_by_guid =
49  [](wxString guid) {
50  if (!pWayPointMan) return static_cast<RoutePoint*>(0);
51  return pWayPointMan->FindWaypointByGuid(guid.ToStdString()); };
52  ctx.delete_route =
53  [](Route* route) {
54  if (!g_pRouteMan) return;
55  g_pRouteMan->DeleteRoute(route, NavObjectChanges::getInstance()); };
56  ctx.delete_track =
57  [](Track* track) {
58  auto it = std::find(g_TrackList.begin(), g_TrackList.end(), track);
59  if (it != g_TrackList.end()) {
60  g_TrackList.erase(it);
61  }
62  delete track;
63  };
64  ctx.delete_waypoint =
65  [](RoutePoint* wpt) {
66  if (!pWayPointMan) return;
67  pWayPointMan->DestroyWaypoint(wpt); };
68  return ctx;
69 }
70 #endif // _ROUTE_CTX_FACTORY_H__
Callbacks for handling routes and tracks.
Definition: rest_server.h:115
Definition: route.h:75
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition: routeman.cpp:751
Definition: track.h:78