]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/dclgps.hxx
Merge branch 'ehofman/sound'
[flightgear.git] / src / Instrumentation / dclgps.hxx
index 5ae64b35ce8ad99a56024ab9dafffdd3453c6b8a..295a7ad6436d8402db30461a5e09592e9b430b52 100644 (file)
@@ -5,7 +5,7 @@
 //
 // Written by David Luff, started 2005.
 //
-// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
+// Copyright (C) 2005 - David C Luff:  daveluff --AT-- ntlworld --D0T-- com
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 #include <vector>
 #include <map>
 
-#include <Navaids/navrecord.hxx>
-#include <Navaids/navlist.hxx>
-#include <Navaids/fixlist.hxx>
-#include <Airports/simple.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
+#include <Navaids/positioned.hxx>
 
-using namespace std;
+class SGTime;
+class FGPositioned;
+
+// XXX fix me
+class FGNavRecord;
+class FGAirport;
+class FGFix;
 
 enum GPSDistanceUnits {
        GPS_DIST_UNITS_NM = 0,
@@ -89,6 +92,11 @@ ostream& operator << (ostream& os, GPSAppWpType type);
 
 struct GPSWaypoint {
     GPSWaypoint();
+  
+  GPSWaypoint(const std::string& aIdent, float lat, float lon, GPSWpType aType);
+  
+  static GPSWaypoint* createFromPositioned(const FGPositioned* aFix);
+  
     ~GPSWaypoint();
        string GetAprId();      // Returns the id with i, f, m or h added if appropriate. (Initial approach fix, final approach fix, etc)
        string id;
@@ -118,9 +126,9 @@ public:
        virtual ~FGIAP() = 0;
 //protected:
 
-       string _id;             // The ID of the airport this approach is for
-       string _name;   // The approach name, eg "VOR/DME OR GPS-B"
-       string _abbrev; // The abbreviation the GPS unit uses - eg "VOR/D" in this instance.  Possibly GPS model specific.
+       string _aptIdent;       // The ident of the airport this approach is for
+       string _ident;  // The approach ident.
+       string _name;   // The full approach name.
        string _rwyStr; // The string used to specify the rwy - eg "B" in this instance.
        bool _precision;        // True for precision approach, false for non-precision.
 };
@@ -132,89 +140,68 @@ public:
        ~FGNPIAP();
 //private:
 public:
-       vector<GPSWaypoint*> _IAF;      // The initial approach fix(es)
+       vector<GPSFlightPlan*> _approachRoutes; // The approach route(s) from the IAF(s) to the IF.
+                                                                                       // NOTE: It is an assumption in the code that uses this that there is a unique IAF per approach route.
        vector<GPSWaypoint*> _IAP;      // The compulsory waypoints of the approach procedure (may duplicate one of the above).
-                                                               // _IAP includes the FAF and MAF.
-       vector<GPSWaypoint*> _MAP;      // The missed approach procedure (doesn't include the MAF).
+                                                               // _IAP includes the FAF and MAF, and the missed approach waypoints.
 };
 
 typedef vector < FGIAP* > iap_list_type;
 typedef map < string, iap_list_type > iap_map_type;
 typedef iap_map_type::iterator iap_map_iterator;
 
-// ------------------------------------------------------------------------------
-
-class DCLGPS;
+//     A class to encapsulate hr:min representation of time. 
 
-class GPSPage {
-       
+class ClockTime {
 public:
-       GPSPage(DCLGPS* parent);
-       virtual ~GPSPage() = 0;
-       virtual void Update(double dt);
-       virtual void Knob1Left1();
-       virtual void Knob1Right1();     
-       virtual void Knob2Left1();
-       virtual void Knob2Right1();     
-       virtual void CrsrPressed();
-       virtual void EntPressed();
-       virtual void ClrPressed();
-       virtual void DtoPressed();
-       virtual void NrstPressed();
-       virtual void AltPressed();
-       virtual void OBSPressed();
-       virtual void MsgPressed();
-       
-       // Sometimes a page needs to maintain state for some return paths,
-       // but change it for others.  The CleanUp function can be used for
-       // changing state for non-ENT return  paths in conjunction with
-       // GPS::_cleanUpPage
-       virtual void CleanUp();
-       
-       // The LooseFocus function is called when a page or subpage looses focus
-       // and allow pages to clean up state that is maintained whilst focus is
-       // retained, but lost on return.
-       virtual void LooseFocus();
-       
-       // Allows pages that display info for a given ID to have it set/get if they implement these functions.
-       virtual void SetId(const string& s);
-       virtual const string& GetId()=0;
-       
-       inline int GetSubPage() { return(_subPage); }
-       
-       inline int GetNSubPages() { return(_nSubPages); }
-       
-       inline const string& GetName() { return(_name); }
-       
-protected:
-       DCLGPS* _parent;
-       string _name;   // eg. "APT", "NAV" etc
-       int _nSubPages;
-       // _subpage is zero based
-       int _subPage;   // The subpage gets remembered when other pages are displayed
-       string GPSitoa(int n);
-};
+    ClockTime();
+    ClockTime(int hr, int min);
+    ~ClockTime();
+    inline void set_hr(int hr) { _hr = hr; }
+    inline int hr() const { return(_hr); } 
+    inline void set_min(int min) { _min = min; }
+    inline int min() const { return(_min); }
+    
+    ClockTime operator+ (const ClockTime& t) {
+        int cumMin = _hr * 60 + _min + t.hr() * 60 + t.min();
+        ClockTime t2(cumMin / 60, cumMin % 60);
+        return(t2);
+    }
+    // Operator - has a max difference of 23:59,
+    // and assumes the day has wrapped if the second operand
+    // is larger that the first.
+    // eg. 2:59 - 3:00 = 23:59
+    ClockTime operator- (const ClockTime& t) {
+        int diff = (_hr * 60 + _min) - (t.hr() * 60 + t.min());
+        if(diff < 0) { diff += 24 * 60; }
+        ClockTime t2(diff / 60, diff % 60);
+        return(t2);
+    }
+    friend ostream& operator<< (ostream& out, const ClockTime& t);
 
-/*-----------------------------------------------------------------------*/
+private:
+    int _hr;
+    int _min;
+};
 
-typedef vector<GPSPage*> gps_page_list_type;
-typedef gps_page_list_type::iterator gps_page_list_itr;
+// ------------------------------------------------------------------------------
 
 // TODO - merge generic GPS functions instead and split out KLN specific stuff.
 class DCLGPS : public SGSubsystem {
        
-       friend class GPSPage;
-       
 public:
        DCLGPS(RenderArea2D* instrument);
        virtual ~DCLGPS() = 0;
        
-       virtual void draw();
+       virtual void draw(osg::State& state);
        
        virtual void init();
        virtual void bind();
        virtual void unbind();
        virtual void update(double dt);
+       
+       // Expand a SIAP ident to the full procedure name.
+       string ExpandSIAPIdent(const string& ident);
 
        // Render string s in display field field at position x, y
        // WHERE POSITION IS IN CHARACTER UNITS!
@@ -224,18 +211,7 @@ public:
        // Render a char at a given position as above
        virtual void DrawChar(char c, int field, int px, int py, bool bold = false);
        
-       virtual void Knob1Right1();
-       virtual void Knob1Left1();
-       virtual void Knob2Right1();
-       virtual void Knob2Left1();
-       virtual void CrsrPressed();
-       virtual void EntPressed();
-       virtual void ClrPressed();
-       virtual void DtoPressed();
-       virtual void NrstPressed();
-       virtual void AltPressed();
-       virtual void OBSPressed();
-       virtual void MsgPressed();
+       virtual void ToggleOBSMode();
        
        // Set the number of fields
        inline void SetNumFields(int n) { _nFields = (n > _maxFields ? _maxFields : (n < 1 ? 1 : n)); }
@@ -267,7 +243,7 @@ public:
        
        void SetOBSFromWaypoint();
        
-       inline GPSWaypoint* GetActiveWaypoint() { return &_activeWaypoint; }
+       GPSWaypoint* GetActiveWaypoint();
        // Get the (zero-based) position of the active waypoint in the active flightplan
        // Returns -1 if no active waypoint.
        int GetActiveWaypointIndex();
@@ -275,7 +251,7 @@ public:
        int GetWaypointIndex(const string& id);
        
        // Returns meters
-       inline float GetDistToActiveWaypoint() { return _dist2Act; }
+       float GetDistToActiveWaypoint();
        // Returns degrees (magnetic)
        float GetHeadingToActiveWaypoint();
        // Returns degrees (magnetic)
@@ -311,7 +287,7 @@ public:
        inline bool GetToFlag() const { return(_headingBugTo); }
        
        // Initiate Direct To operation to the supplied ID.
-       void DtoInitiate(const string& id);
+       virtual void DtoInitiate(const string& id);
        // Cancel Direct To operation
        void DtoCancel();
        
@@ -341,14 +317,6 @@ protected:
        // 2D rendering area
        RenderArea2D* _instrument;
        
-       // The actual pages
-       gps_page_list_type _pages;
-       
-       // The currently active page
-       GPSPage* _activePage;
-       // And a facility to save the immediately preceeding active page
-       GPSPage* _lastActivePage;
-       
        // Units
        GPSSpeedUnits _velUnits;
        GPSDistanceUnits _distUnits;
@@ -371,14 +339,13 @@ protected:
        // 
        
        // Data and lookup functions
-       // All waypoints mapped by id.
-       gps_waypoint_map _waypoints;
-private:
-       // Worker function for the below.
-       const GPSWaypoint* ActualFindFirstById(const string& id, bool exact = false);
+
+
 protected:
        // Find first of any type of waypoint by id.  (TODO - Possibly we should return multiple waypoints here).
-       const GPSWaypoint* FindFirstById(const string& id, bool &multi, bool exact = false); 
+       GPSWaypoint* FindFirstById(const string& id) const;
+       GPSWaypoint* FindFirstByExactId(const string& id) const;
+   
        FGNavRecord* FindFirstVorById(const string& id, bool &multi, bool exact = false);
        FGNavRecord* FindFirstNDBById(const string& id, bool &multi, bool exact = false);
        const FGAirport* FindFirstAptById(const string& id, bool &multi, bool exact = false);
@@ -386,6 +353,9 @@ protected:
        // Find the closest VOR to a position in RADIANS.
        FGNavRecord* FindClosestVor(double lat_rad, double lon_rad);
 
+       // helper to implement the above FindFirstXXX methods
+       FGPositioned* FindTypedFirstById(const std::string& id, FGPositioned::Type ty, bool &multi, bool exact);
+
        // Position, orientation and velocity.
        // These should be read from FG's built-in GPS logic if possible.
        // Use the property node pointers below to do this.
@@ -484,6 +454,20 @@ protected:
        bool _departed;         // Set when groundspeed first exceeds 30kts.
        string _departureTimeString;    // Ditto.
        double _elapsedTime;    // Elapsed time in seconds since departure
+       ClockTime _powerOnTime;         // Time (hr:min) of unit power-up.
+       bool _powerOnTimerSet;          // Indicates that we have set the above following power-up.
+       void SetPowerOnTimer();
+public:
+       void ResetPowerOnTimer();
+       // Set the alarm to go off at a given time.
+       inline void SetAlarm(int hr, int min) {
+               _alarmTime.set_hr(hr);
+               _alarmTime.set_min(min);
+               _alarmSet = true;
+       }
+protected:
+       ClockTime _alarmTime;
+       bool _alarmSet;
        
        // Configuration that affects flightplan operation
        bool _turnAnticipationEnabled;