]> git.mxchange.org Git - flightgear.git/blob - src/Environment/presets.cxx
#84: John Denker: Set correct file modes
[flightgear.git] / src / Environment / presets.cxx
1 // presets.cxx -- Wrap environment presets
2 //
3 // Written by Torsten Dreyer, January 2011
4 //
5 // Copyright (C) 2010  Torsten Dreyer Torsten(at)t3r(dot)de
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25 #include "presets.hxx"
26
27 #include <simgear/math/SGMisc.hxx>
28 #include <Main/fg_props.hxx>
29
30 namespace Environment {
31 namespace Presets {
32
33 PresetBase::PresetBase( const char * overrideNodePath )
34     : _overrideNodePath( overrideNodePath ) 
35 {
36 }
37
38 void PresetBase::setOverride( bool value ) 
39
40     /*
41     Don't initialize node in constructor because the class is used as a singleton
42     and created as a static variable in the initialization sequence when globals()
43     is not yet initialized and returns null.
44     */
45     if( _overrideNode == NULL ) 
46         _overrideNode = fgGetNode( _overrideNodePath.c_str(), true );
47     _overrideNode->setBoolValue( value ); 
48 }
49
50
51 Wind::Wind() : 
52     PresetBase("/environment/config/presets/wind-override")
53 {
54 }
55
56
57 void Wind::preset( double min_hdg, double max_hdg, double speed_kt, double gust_kt )
58 {
59     // see: PresetBase::setOverride()
60
61     //TODO: handle variable wind and gusts
62     if( _fromNorthNode == NULL )
63         _fromNorthNode = fgGetNode("/environment/config/presets/wind-from-north-fps", true );
64     
65     if( _fromEastNode == NULL )
66         _fromEastNode = fgGetNode("/environment/config/presets/wind-from-east-fps", true );
67
68     double avgHeading_rad = 
69       SGMiscd::normalizeAngle2(
70         (SGMiscd::normalizeAngle(min_hdg*SG_DEGREES_TO_RADIANS) + 
71          SGMiscd::normalizeAngle(max_hdg*SG_DEGREES_TO_RADIANS))/2);
72
73     double speed_fps = speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET / 3600.0;
74     _fromNorthNode->setDoubleValue( speed_fps * cos(avgHeading_rad) );
75     _fromEastNode->setDoubleValue( speed_fps * sin(avgHeading_rad) );
76     setOverride( true );
77 }
78
79 Visibility::Visibility() : 
80     PresetBase("/environment/config/presets/visibility-m-override")
81 {
82 }
83
84 void Visibility::preset( double visibility_m )
85 {
86     // see: PresetBase::setOverride()
87     if( _visibilityNode == NULL )
88         _visibilityNode = fgGetNode("/environment/config/presets/visibility-m", true );
89
90     _visibilityNode->setDoubleValue(visibility_m );
91     setOverride( true );
92 }
93
94 Turbulence::Turbulence() : 
95     PresetBase("/environment/config/presets/turbulence-magnitude-norm-override")
96 {
97 }
98
99
100 void Turbulence::preset(double magnitude_norm)
101 {
102     // see: PresetBase::setOverride()
103     if( _magnitudeNode == NULL )
104         _magnitudeNode = fgGetNode("/environment/config/presets/turbulence-magnitude-norm", true );
105
106     _magnitudeNode->setDoubleValue( magnitude_norm );
107     setOverride( true );
108 }
109
110 Ceiling::Ceiling() : 
111     PresetBase("/environment/config/presets/ceiling-override")
112 {
113 }
114
115
116 void Ceiling::preset( double elevation, double thickness )
117 {
118     // see: PresetBase::setOverride()
119     if( _elevationNode == NULL )
120         _elevationNode = fgGetNode("/environment/config/presets/ceiling-elevation-ft", true);
121
122     if( _thicknessNode == NULL )
123         _thicknessNode = fgGetNode("/environment/config/presets/ceiling-elevation-ft", true);
124
125     _elevationNode->setDoubleValue( elevation );
126     _thicknessNode->setDoubleValue( thickness );
127     setOverride( true );
128 }
129
130 } // namespace Presets
131 } // namespace Environment
132