OpenCPN Partial API docs
Loading...
Searching...
No Matches
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
34extern WayPointman* pWayPointMan;
35extern Routeman* g_pRouteMan;
36extern std::vector<Track*> g_TrackList;
37
38RouteCtx RouteCtxFactory() {
39 RouteCtx ctx;
40 ctx.find_route_by_guid = [](wxString guid) {
41 if (!g_pRouteMan) return static_cast<Route*>(0);
42 return g_pRouteMan->FindRouteByGUID(guid);
43 };
44 ctx.find_track_by_guid = [](wxString guid) {
45 if (!g_pRouteMan) return static_cast<Track*>(0);
46 return g_pRouteMan->FindTrackByGUID(guid);
47 };
48 ctx.find_wpt_by_guid = [](wxString guid) {
49 if (!pWayPointMan) return static_cast<RoutePoint*>(0);
50 return pWayPointMan->FindWaypointByGuid(guid.ToStdString());
51 };
52 ctx.delete_route = [](Route* route) {
53 if (!g_pRouteMan) return;
54 g_pRouteMan->DeleteRoute(route, NavObjectChanges::getInstance());
55 };
56 ctx.delete_track = [](Track* track) {
57 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), track);
58 if (it != g_TrackList.end()) {
59 g_TrackList.erase(it);
60 }
61 delete track;
62 };
63 ctx.delete_waypoint = [](RoutePoint* wpt) {
64 if (!pWayPointMan) return;
65 pWayPointMan->DestroyWaypoint(wpt);
66 };
67 return ctx;
68}
69#endif // _ROUTE_CTX_FACTORY_H__
Callbacks for handling routes and tracks.
Definition route.h:75
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:747
Represents a track, which is a series of connected track points.
Definition track.h:78