# include <windows.h>
#endif
-// #include <stdlib.h>
-
-// #include <simgear/constants.h>
-// #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/commands.hxx>
#include <simgear/misc/sg_path.hxx>
-// #include <Include/general.hxx>
-
-// #include <GL/glut.h>
-// #include <GL/gl.h>
-
-#include <Airports/simple.hxx>
-#include <FDM/flight.hxx>
-#include <Main/fg_init.hxx>
#include <Main/fg_props.hxx>
-#include <Scenery/tilemgr.hxx>
#include "gui.h"
#include "preset_dlg.hxx"
void fgPresetCommit(puObject *)
{
- static const SGPropertyNode *longitude
- = fgGetNode("/sim/presets/longitude-deg");
- static const SGPropertyNode *latitude
- = fgGetNode("/sim/presets/latitude-deg");
- static const SGPropertyNode *master_freeze
- = fgGetNode("/sim/freeze/master");
-
- SGPath path( globals->get_fg_root() );
- path.append( "Airports" );
- path.append( "simple.mk4" );
- FGAirports airports( path.c_str() );
-
- FGAirport a;
-
- bool freeze = master_freeze->getBoolValue();
- if ( !freeze ) {
- fgSetBool("/sim/freeze/master", true);
- }
-
- // unbind the current fdm state so property changes
- // don't get lost when we subsequently delete this fdm
- // and create a new one.
- cur_fdm_state->unbind();
-
- // invalidate lon/lat if an airport is specified in the presets
- string apt = fgGetString("/sim/presets/airport-id");
- if ( !apt.empty() ) {
- fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
- fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
- }
-
- // set position from presets
- fgInitPosition();
-
- // BusyCursor(0);
- fgReInitSubsystems();
-
- cout << "before tile_mgr init " << longitude->getDoubleValue() << " "
- << latitude->getDoubleValue() << endl;
-
- double visibility_meters = fgGetDouble("/environment/visibility-m");
- global_tile_mgr.update( visibility_meters );
- // BusyCursor(1);
-
- if ( !freeze ) {
- fgSetBool("/sim/freeze/master", false);
+ SGPropertyNode args;
+ if ( !globals->get_commands()->execute("presets_commit", &args) )
+ {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets_commit failed.");
}
}
#include <simgear/misc/commands.hxx>
#include <simgear/misc/props.hxx>
-#include <GUI/gui.h>
-#include <GUI/new_gui.hxx>
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
+#include <FDM/flight.hxx>
+#include <GUI/gui.h>
+#include <GUI/new_gui.hxx>
#include <Scenery/tilemgr.hxx>
#include <Time/tmp.hxx>
+#include "fg_init.hxx"
#include "fg_commands.hxx"
SG_USING_STD(string);
}
+/**
+ * Built-in command: commit presets (read from in /sim/presets/)
+ */
+static bool
+do_presets_commit (const SGPropertyNode * arg)
+{
+ // unbind the current fdm state so property changes
+ // don't get lost when we subsequently delete this fdm
+ // and create a new one.
+ cur_fdm_state->unbind();
+
+ // set position from presets
+ fgInitPosition();
+
+ // BusyCursor(0);
+ fgReInitSubsystems();
+
+ global_tile_mgr.update( fgGetDouble("/environment/visibility-m") );
+
+ if ( ! fgGetBool("/sim/presets/onground") ) {
+ fgSetBool( "/sim/freeze/master", true );
+ fgSetBool( "/sim/freeze/clock", true );
+ }
+
+ return true;
+}
+
+
\f
////////////////////////////////////////////////////////////////////////
// Command setup.
{ "property-swap", do_property_swap },
{ "property-scale", do_property_scale },
{ "gui", do_gui },
+ { "presets_commit", do_presets_commit },
{ 0, 0 } // zero-terminated
};
}
+// get airport elevation
+static double fgGetAirportElev( const string& id ) {
+ FGAirport a;
+ // double lon, lat;
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Finding elevation for airport: " << id );
+
+ if ( fgFindAirportID( id, &a ) ) {
+ return a.elevation;
+ } else {
+ return -9999.0;
+ }
+}
+
+
// Preset lon/lat given an airport id
static bool fgSetPosFromAirportID( const string& id ) {
FGAirport a;
} else {
return false;
}
-
}
-
// Set current tower position lon/lat given an airport id
static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
FGAirport a;
static void fgSetDistOrAltFromGlideSlope() {
+ string apt_id = fgGetString("/sim/presets/airport-id");
double gs = fgGetDouble("/sim/presets/glideslope-deg")
* SG_DEGREES_TO_RADIANS ;
double od = fgGetDouble("/sim/presets/offset-distance");
double alt = fgGetDouble("/sim/presets/altitude-ft");
-
+
+ double apt_elev = 0.0;
+ if ( ! apt_id.empty() ) {
+ apt_elev = fgGetAirportElev( apt_id );
+ if ( apt_elev < -9990.0 ) {
+ apt_elev = 0.0;
+ }
+ } else {
+ apt_elev = 0.0;
+ }
+
if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
// set altitude from glideslope and offset-distance
od *= SG_NM_TO_METER * SG_METER_TO_FEET;
- alt = fabs(od*tan(gs));
+ alt = fabs(od*tan(gs)) + apt_elev;
fgSetDouble("/sim/presets/altitude-ft", alt);
fgSetBool("/sim/presets/onground", false);
SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt << " ft");
} else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
// set offset-distance from glideslope and altitude
- od = alt/tan(gs);
+ od = (alt - apt_elev) / tan(gs);
od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
fgSetDouble("/sim/presets/offset-distance", od);
SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: "
"Glideslope given but not altitude or offset-distance." );
SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
fgSetDouble("/sim/presets/glideslope-deg", 0);
+ fgSetBool("/sim/presets/onground", true);
}
}
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
#include <simgear/math/sg_types.hxx>
+#include <simgear/misc/commands.hxx>
#include <simgear/misc/props.hxx>
#include <Main/fg_props.hxx>
server = new HttpdServer( port );
- set_hz( 5 ); // default to processing requests @ 5Hz
+ set_hz( 15 ); // default to processing requests @ 15Hz
set_enabled( true );
return true;
string a = arg.substr( 0, apos );
string b = arg.substr( apos + 1 );
printf(" a = %s b = %s\n", a.c_str(), b.c_str() );
- if ( a == "value" ) {
- fgSetString( request.c_str(), urlDecode(b).c_str() );
- }
+ if ( request == "/run.cgi" ) {
+ // execute a command
+ if ( a == "value" ) {
+ SGPropertyNode args;
+ if ( !globals->get_commands()
+ ->execute(urlDecode(b).c_str(), &args) )
+ {
+ SG_LOG( SG_GENERAL, SG_ALERT,
+ "Command " << urlDecode(b)
+ << " failed.");
+ }
+
+ }
+ } else {
+ if ( a == "value" ) {
+ // update a property value
+ fgSetString( request.c_str(),
+ urlDecode(b).c_str() );
+ }
+ }
}
}
} else {