1 #ifndef FLIGHTPLANCONTROLLER_HXX
2 #define FLIGHTPLANCONTROLLER_HXX
3 
4 #include <memory>
5 
6 #include <QObject>
7 
8 #include <Navaids/FlightPlan.hxx>
9 
10 #include "UnitsModel.hxx"
11 
12 class QmlPositioned;
13 class LegsModel;
14 class FPDelegate;
15 class LaunchConfig;
16 
17 class FlightPlanController : public QObject
18 {
19     Q_OBJECT
20 
21     Q_PROPERTY(bool enabled MEMBER _enabled NOTIFY enabledChanged)
22     Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
23 
24     Q_PROPERTY(QString callsign READ callsign WRITE setCallsign NOTIFY infoChanged)
25     Q_PROPERTY(QString remarks READ remarks WRITE setRemarks NOTIFY infoChanged)
26     Q_PROPERTY(QString aircraftType READ aircraftType WRITE setAircraftType NOTIFY infoChanged)
27 
28     Q_PROPERTY(LegsModel* legs READ legs CONSTANT)
29 
30     Q_PROPERTY(QString icaoRoute READ icaoRoute NOTIFY waypointsChanged)
31 
32     Q_ENUMS(FlightRules)
33     Q_ENUMS(FlightType)
34 
35     Q_PROPERTY(FlightRules flightRules READ flightRules WRITE setFlightRules NOTIFY infoChanged)
36     Q_PROPERTY(FlightType flightType READ flightType WRITE setFlightType NOTIFY infoChanged)
37 
38     // planned departure date + time
39 
40     Q_PROPERTY(QuantityValue totalDistanceNm READ totalDistanceNm NOTIFY infoChanged)
41 
42     Q_PROPERTY(int estimatedDurationMinutes READ estimatedDurationMinutes WRITE setEstimatedDurationMinutes NOTIFY infoChanged)
43 
44     Q_PROPERTY(QuantityValue cruiseAltitude READ cruiseAltitude WRITE setCruiseAltitude NOTIFY infoChanged)
45     Q_PROPERTY(QuantityValue cruiseSpeed READ cruiseSpeed WRITE setCruiseSpeed NOTIFY infoChanged)
46 
47     Q_PROPERTY(QmlPositioned* departure READ departure WRITE setDeparture NOTIFY infoChanged)
48     Q_PROPERTY(QmlPositioned* destination READ destination WRITE setDestination NOTIFY infoChanged)
49     Q_PROPERTY(QmlPositioned* alternate READ alternate WRITE setAlternate NOTIFY infoChanged)
50 
51     // equipment
52 public:
53     virtual ~FlightPlanController();
54 
55     // alias these enums to QML
56     enum FlightRules
57     {
58         VFR = 0,
59         IFR,
60         IFR_VFR,
61         VFR_IFR
62     };
63 
64     enum FlightType
65     {
66         Scheduled = 0,
67         NonScheduled,
68         GeneralAviation,
69         Military,
70         Other
71     };
72 
73     explicit FlightPlanController(QObject *parent,
74                                   LaunchConfig* config);
75 
76     bool loadFromPath(QString path);
77     bool saveToPath(QString path) const;
78 
79     QuantityValue cruiseAltitude() const;
80     void setCruiseAltitude(QuantityValue alt);
81 
82     QString description() const;
83 
84     QmlPositioned* departure() const;
85     QmlPositioned* destination() const;
86     QmlPositioned* alternate() const;
87 
88     QuantityValue cruiseSpeed() const;
89 
90     FlightRules flightRules() const;
91     FlightType flightType() const;
92 
93     QString callsign() const;
94     QString remarks() const;
95     QString aircraftType() const;
96 
97     int estimatedDurationMinutes() const;
98     QuantityValue totalDistanceNm() const;
99 
100     Q_INVOKABLE bool tryParseRoute(QString routeDesc);
101 
102     Q_INVOKABLE bool tryGenerateRoute();
103     Q_INVOKABLE void clearRoute();
104 
legs() const105     LegsModel* legs() const
106     { return _legs; }
107 
108     QString icaoRoute() const;
109 
flightplan() const110     flightgear::FlightPlanRef flightplan() const
111     { return _fp; }
112 
113     Q_INVOKABLE bool loadPlan();
114 signals:
115     void infoChanged();
116     void waypointsChanged();
117 
118     void enabledChanged(bool enabled);
119     void descriptionChanged(QString description);
120 
121 public slots:
122 
123     void setFlightType(FlightType ty);
124     void setFlightRules(FlightRules r);
125 
126     void setCallsign(QString s);
127     void setRemarks(QString r);
128     void setAircraftType(QString ty);
129 
130     void setDeparture(QmlPositioned* destinationAirport);
131     void setDestination(QmlPositioned* destinationAirport);
132     void setAlternate(QmlPositioned* apt);
133 
134     void setCruiseSpeed(QuantityValue cruiseSpeed);
135 
136     void setEstimatedDurationMinutes(int mins);
137 
138     void computeDuration();
139 
140     void clearPlan();
141     void savePlan();
142 private slots:
143     void onCollectConfig();
144     void onSave();
145     void onRestore();
146 
147 private:
148     friend class FPDelegate;
149 
150     flightgear::FlightPlanRef _fp;
151     LegsModel* _legs = nullptr;
152     std::unique_ptr<FPDelegate> _delegate;
153     LaunchConfig* _config = nullptr;
154     bool _enabled = false;
155 };
156 
157 #endif // FLIGHTPLANCONTROLLER_HXX
158