2 * NavDataCache.hxx - defines a unified binary cache for navigation
3 * data, parsed from various text / XML sources.
6 // Written by James Turner, started 2012.
8 // Copyright (C) 2012 James Turner
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef FG_NAVDATACACHE_HXX
25 #define FG_NAVDATACACHE_HXX
29 #include <simgear/misc/strutils.hxx> // for string_list
30 #include <Navaids/positioned.hxx>
38 /// a pair of airport ID, runway ID
39 typedef std::pair<PositionedID, PositionedID> AirportRunwayPair;
41 typedef std::pair<FGPositioned::Type, PositionedID> TypedPositioned;
42 typedef std::vector<TypedPositioned> TypedPositionedVec;
44 // pair of airway ID, destination node ID
45 typedef std::pair<int, PositionedID> AirwayEdge;
46 typedef std::vector<AirwayEdge> AirwayEdgeVec;
59 static NavDataCache* instance();
62 * predicate - check if the cache needs to be rebuilt.
63 * This can happen is the cache file is missing or damaged, or one of the
64 ** global input files is changed.
66 bool isRebuildRequired();
69 * check if cached scenery paths have changed, and if so, drop scenery-
70 * dependant data such as ground-nets.
72 bool dropGroundnetsIfRequired();
75 * run the cache rebuild - returns true if rebuild is complete,
76 * otherwise keep going.
80 bool isCachedFileModified(const SGPath& path) const;
81 void stampCacheFile(const SGPath& path);
83 int readIntProperty(const std::string& key);
84 double readDoubleProperty(const std::string& key);
85 std::string readStringProperty(const std::string& key);
87 void writeIntProperty(const std::string& key, int value);
88 void writeStringProperty(const std::string& key, const std::string& value);
89 void writeDoubleProperty(const std::string& key, const double& value);
91 string_list readStringListProperty(const std::string& key);
92 void writeStringListProperty(const std::string& key, const string_list& values);
95 * retrieve an FGPositioned from the cache.
96 * This may be trivial if the object is previously loaded, or require actual
99 FGPositionedRef loadById(PositionedID guid);
101 PositionedID insertAirport(FGPositioned::Type ty, const std::string& ident,
102 const std::string& name);
103 void insertTower(PositionedID airportId, const SGGeod& pos);
104 PositionedID insertRunway(FGPositioned::Type ty, const std::string& ident,
105 const SGGeod& pos, PositionedID apt,
106 double heading, double length, double width, double displacedThreshold,
107 double stopway, int surfaceCode);
108 void setRunwayReciprocal(PositionedID runway, PositionedID recip);
109 void setRunwayILS(PositionedID runway, PositionedID ils);
111 PositionedID insertNavaid(FGPositioned::Type ty, const std::string& ident,
112 const std::string& name, const SGGeod& pos, int freq, int range, double multiuse,
113 PositionedID apt, PositionedID runway);
115 // Assign colocated DME to a navaid
116 void setNavaidColocated(PositionedID navaid, PositionedID colocatedDME);
118 PositionedID insertCommStation(FGPositioned::Type ty,
119 const std::string& name, const SGGeod& pos, int freq, int range,
121 PositionedID insertFix(const std::string& ident, const SGGeod& aPos);
123 PositionedID createPOI(FGPositioned::Type ty, const std::string& ident, const SGGeod& aPos);
125 bool removePOI(FGPositioned::Type ty, const std::string& aIdent);
127 void dropGroundnetFor(PositionedID aAirport);
130 * Remove all ground-nets globally from the cache.
131 * This includes parking and taxi-nodes and edges between them. It's useful
132 * when scenery paths change, since the ground-nets depend on the scenery.
133 * Using this we can avoid havind to rebuild the entire cache.
135 void dropAllGroundnets();
137 PositionedID insertParking(const std::string& name, const SGGeod& aPos,
138 PositionedID aAirport,
139 double aHeading, int aRadius, const std::string& aAircraftType,
140 const std::string& aAirlines);
142 void setParkingPushBackRoute(PositionedID parking, PositionedID pushBackNode);
144 PositionedID insertTaxiNode(const SGGeod& aPos, PositionedID aAirport, int aHoldType, bool aOnRunway);
146 void insertGroundnetEdge(PositionedID aAirport, PositionedID from, PositionedID to);
148 /// update the metar flag associated with an airport
149 void setAirportMetar(const std::string& icao, bool hasMetar);
152 * Modify the position of an existing item.
154 void updatePosition(PositionedID item, const SGGeod &pos);
156 FGPositionedList findAllWithIdent( const std::string& ident,
157 FGPositioned::Filter* filter,
159 FGPositionedList findAllWithName( const std::string& ident,
160 FGPositioned::Filter* filter,
163 FGPositionedRef findClosestWithIdent( const std::string& aIdent,
165 FGPositioned::Filter* aFilter );
169 * Helper to implement the AirportSearch widget. Optimised text search of
170 * airport names and idents, returning a list suitable for passing directly
173 char** searchAirportNamesAndIdents(const std::string& aFilter);
176 * Find the closest matching comm-station on a frequency, to a position.
177 * The filter with be used for both type ranging and to validate the result
180 FGPositionedRef findCommByFreq(int freqKhz, const SGGeod& pos, FGPositioned::Filter* filt);
183 * find all items of a specified type (or range of types) at an airport
185 PositionedIDVec airportItemsOfType(PositionedID apt, FGPositioned::Type ty,
186 FGPositioned::Type maxTy = FGPositioned::INVALID);
189 * find the first match item of the specified type and ident, at an airport
191 PositionedID airportItemWithIdent(PositionedID apt, FGPositioned::Type ty, const std::string& ident);
194 * Find all navaids matching a particular frequency, sorted by range from the
195 * supplied position. Type-range will be determined from the filter
197 PositionedIDVec findNavaidsByFreq(int freqKhz, const SGGeod& pos, FGPositioned::Filter* filt);
199 /// overload version of the above that does not consider positioned when
200 /// returning results. Only used by TACAN carrier search
201 PositionedIDVec findNavaidsByFreq(int freqKhz, FGPositioned::Filter* filt);
204 * Given a runway and type, find the corresponding navaid (ILS / GS / OM)
206 PositionedID findNavaidForRunway(PositionedID runway, FGPositioned::Type ty);
209 * given a navaid name (or similar) from apt.dat / nav.dat, find the
210 * corresponding airport and runway IDs.
211 * Such names look like: 'LHBP 31L DME-ILS' or 'UEEE 23L MM'
213 AirportRunwayPair findAirportRunway(const std::string& name);
216 * Given an aiport, and runway and ILS identifier, find the corresponding cache
217 * entry. This matches the data we get in the ils.xml files for airports.
219 PositionedID findILS(PositionedID airport, const std::string& runway, const std::string& navIdent);
222 * Given an Octree node ID, return a bit-mask defining which of the child
223 * nodes exist. In practice this means an 8-bit value be sufficent, but
224 * an int works fine too.
226 int getOctreeBranchChildren(int64_t octreeNodeId);
228 void defineOctreeNode(Octree::Branch* pr, Octree::Node* nd);
231 * given an octree leaf, return all its child positioned items and their types
233 TypedPositionedVec getOctreeLeafChildren(int64_t octreeNodeId);
236 int findAirway(int network, const std::string& aName);
239 * insert an edge between two positioned nodes, into the network.
240 * The airway identifier will be set accordingly. No reverse edge is created
241 * by this method - edges are directional so a reverses must be explicitly
244 void insertEdge(int network, int airwayID, PositionedID from, PositionedID to);
246 /// is the specified positioned a node on the network?
247 bool isInAirwayNetwork(int network, PositionedID pos);
250 * retrive all the destination points reachcable from a positioned
253 AirwayEdgeVec airwayEdgesFrom(int network, PositionedID pos);
256 PositionedIDVec groundNetNodes(PositionedID aAirport, bool onlyPushback);
257 void markGroundnetAsPushback(PositionedID nodeId);
259 PositionedID findGroundNetNode(PositionedID airport, const SGGeod& aPos,
260 bool onRunway, FGRunway* aRunway = NULL);
261 PositionedIDVec groundNetEdgesFrom(PositionedID pos, bool onlyPushback);
263 PositionedIDVec findAirportParking(PositionedID airport, const std::string& flightType,
270 Transaction(NavDataCache* cache);
275 NavDataCache* _instance;
279 bool isReadOnly() const;
283 friend class RebuildThread;
286 friend class Transaction;
288 void beginTransaction();
289 void commitTransaction();
290 void abortTransaction();
292 class NavDataCachePrivate;
293 std::auto_ptr<NavDataCachePrivate> d;
296 } // of namespace flightgear
298 #endif // of FG_NAVDATACACHE_HXX