This patch is thanks to Melchior and Andy for their pointing me to the right places to learn about fg/nasal and for their advice while implementing it.
You will see (in the commented part of the dialog xml) that a second part is coming in the future, with a shorthand to import the airport from the COM frequencies. Enjoy. Index: src/Main/fg_init.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/source/src/Main/fg_init.cxx,v retrieving revision 1.132 diff -u -p -r1.132 fg_init.cxx --- src/Main/fg_init.cxx 12 Oct 2005 08:55:58 -0000 1.132 +++ src/Main/fg_init.cxx 18 Oct 2005 16:45:38 -0000 @@ -695,29 +695,42 @@ static bool fgSetPosFromAirportID( const } #endif +static void fgInitTowerLocationListener() { + struct TowerLocationListener : SGPropertyChangeListener { + void valueChanged(SGPropertyNode* node) { + const double hdg = fgGetDouble( "/orientation/heading-deg", 0); + const string id(node->getStringValue()); + fgSetTowerPosFromAirportID(id, hdg); + } -// Set current tower position lon/lat given an airport id -static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) { - FGAirport a; - // tower height hard coded for now... - float towerheight=50.0f; - - // make a little off the heading for 1 runway airports... - float fudge_lon = fabs(sin(hdg)) * .003f; - float fudge_lat = .003f - fudge_lon; - - if ( fgFindAirportID( id, &a ) ) { - fgSetDouble("/sim/tower/longitude-deg", a.getLongitude() + fudge_lon); - fgSetDouble("/sim/tower/latitude-deg", a.getLatitude() + fudge_lat); - fgSetDouble("/sim/tower/altitude-ft", a.getElevation() + towerheight); - return true; - } else { - return false; - } + // Set current tower position lon/lat given an airport id + static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) { + FGAirport a; + // tower height hard coded for now... + float towerheight=50.0f; + + // make a little off the heading for 1 runway airports... + float fudge_lon = fabs(sin(hdg)) * .003f; + float fudge_lat = .003f - fudge_lon; + + if ( fgFindAirportID( id, &a ) ) { + fgSetDouble("/sim/tower/longitude-deg", a.getLongitude() + fudge_lon); + fgSetDouble("/sim/tower/latitude-deg", a.getLatitude() + fudge_lat); + fgSetDouble("/sim/tower/altitude-ft", a.getElevation() + towerheight); + return true; + } else { + return false; + } + } + }; + fgGetNode("/sim/tower/airport-id", true) + ->addChangeListener( new TowerLocationListener() ); } + + // Set current_options lon/lat given an airport id and heading (degrees) static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) { FGRunway r; @@ -1178,12 +1191,15 @@ bool fgInitPosition() { string parkpos = fgGetString("/sim/presets/parkpos"); string fix = fgGetString("/sim/presets/fix"); + fgSetDouble( "/orientation/heading-deg", hdg ); + fgInitTowerLocationListener(); + if ( !set_pos && !apt.empty() && !rwy_no.empty() ) { // An airport + runway is requested if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) { // set tower position (a little off the heading for single // runway airports) - fgSetTowerPosFromAirportID( apt, hdg ); + fgSetString("/sim/tower/airport-id", apt.c_str()); set_pos = true; } } @@ -1193,7 +1209,7 @@ bool fgInitPosition() { if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) { // set tower position (a little off the heading for single // runway airports) - fgSetTowerPosFromAirportID( apt, hdg ); + fgSetString("/sim/tower/airport-id", apt.c_str()); set_pos = true; } } @@ -1237,8 +1253,6 @@ bool fgInitPosition() { fgGetDouble("/sim/presets/longitude-deg") ); fgSetDouble( "/position/latitude-deg", fgGetDouble("/sim/presets/latitude-deg") ); - fgSetDouble( "/orientation/heading-deg", - fgGetDouble("/sim/presets/heading-deg") ); // determine if this should be an on-ground or in-air start if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) { Index: data/gui/menubar.xml =================================================================== RCS file: /var/cvs/FlightGear-0.9/data/gui/menubar.xml,v retrieving revision 1.38 diff -u -p -r1.38 menubar.xml --- data/gui/menubar.xml 5 Jul 2005 08:51:18 -0000 1.38 +++ data/gui/menubar.xml 18 Oct 2005 16:47:26 -0000 @@ -196,6 +196,14 @@ </binding> </item> + <item> + <label>Tower position</label> + <binding> + <command>dialog-show</command> + <dialog-name>location-of-tower</dialog-name> + </binding> + </item> + </menu> <menu> --- /dev/null 2005-01-09 22:40:54.000000000 +0200 +++ data/gui/dialogs/location-of-tower.xml 2005-10-18 18:40:43.000000000 +0200 @@ -0,0 +1,152 @@ +<?xml version="1.0"?> +<PropertyList> + <name>location-of-tower</name> + <layout>vbox</layout> + + <text> + <label>Select tower for the Tower View</label> + </text> + + <hrule> + <pref-height>2</pref-height> + </hrule> + + <group> + <layout>table</layout> + + <text> + <row>0</row><col>0</col> + <label>Airport ID</label> + </text> + <input> + <name>airport-id</name> + <row>0</row><col>1</col> + <property>/sim/tower/airport-id</property> + </input> + <empty> + <row>0</row><col>3</col> + <stretch>true</stretch> + </empty> + + <!-- Commented out because the /instrumentation/comm[%d]/airport-id + are not filled in on the COM radio retuning... + I'm working on that part now. + <button> + <row>1</row><col>0</col> + <legend>COM1</legend> + <binding> + <command>property-assign</command> + <property>/sim/tower/airport-id</property> + <property>/instrumentation/comm[0]/airport-id</property> + </binding> + <binding> + <command>dialog-update</command> + <object-name>airport-id</object-name> + </binding> + </button> + <text> + <row>1</row><col>2</col> + <property>/instrumentation/comm[0]/frequencies/selected-mhz</property> + <label>MHz</label> + <format>%-0.2f</format> + </text> + <text> + <row>1</row><col>1</col> + <property>/instrumentation/comm[0]/airport-id</property> + </text> + <empty> + <row>1</row><col>3</col> + <stretch>true</stretch> + </empty> + + <button> + <row>2</row><col>0</col> + <legend>COM2</legend> + <binding> + <command>property-assign</command> + <property>/sim/tower/airport-id</property> + <property>/instrumentation/comm[1]/airport-id</property> + </binding> + <binding> + <command>dialog-update</command> + <object-name>airport-id</object-name> + </binding> + </button> + <text> + <row>2</row><col>2</col> + <property>/instrumentation/comm[1]/frequencies/selected-mhz</property> + <label>MHz</label> + <format>%-0.2f</format> + </text> + <text> + <row>2</row><col>1</col> + <property>/instrumentation/comm[1]/airport-id</property> + </text> + <empty> + <row>2</row><col>3</col> + <stretch>true</stretch> + </empty> + --> + + <button> + <legend>Preset</legend> + <row>3</row><col>0</col> + <!-- + Is there a way in the GUI (other than via a dynamic + NASAL dialog) to assign text to the widget rather + than to the underlying property and doing an update? + + The way it is now CANCEL doesn't undo PRESET :-( + --> + <binding> + <command>property-assign</command> + <property>/sim/tower/airport-id</property> + <property>/sim/presets/airport-id</property> + </binding> + <binding> + <command>dialog-update</command> + <object-name>airport-id</object-name> + </binding> + </button> + <text> + <row>3</row><col>1</col> + <property>/sim/presets/airport-id</property> + </text> + <empty> + <row>3</row><col>3</col> + <stretch>true</stretch> + </empty> + + + </group> + + <group> + <layout>hbox</layout> + <default-padding>10</default-padding> + <empty><stretch>true</stretch></empty> + + <button> + <legend>OK</legend> + <default>true</default> + <equal>true</equal> + <binding> + <command>dialog-apply</command> + </binding> + <binding> + <command>dialog-close</command> + </binding> + </button> + + <empty><stretch>true</stretch></empty> + + <button> + <legend>Cancel</legend> + <equal>true</equal> + <binding> + <command>dialog-close</command> + </binding> + </button> + + <empty><stretch>true</stretch></empty> + </group> +</PropertyList> _______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d