Debian Codegraph @

Docs/README.commands

raw
1 FlightGear Commands Mini-HOWTO
2
3 David Megginson
4 Started: 2002-10-25
5 Last revised: 2007-12-01
6
7
8 In FlightGear, a *command* represents an action, while a *property*
9 represents a state. The trigger for a command can be any kind of user
10 input, including the keyboard, mouse, joystick, GUI, instrument panel,
11 or a remote network client.
12
13
14 XML Command Binding Markup
15 --------------------------
16
17 Most of the command-binding in FlightGear is handled through static
18 XML configuration files such as $FG_ROOT/keyboard.xml for the
19 keyboard, $FG_ROOT/mice.xml for the mouse, and
20 $FG_ROOT/gui/menubar.xml for the menubar. In all of these files, you
21 reference a command through a binding. This binding advances the
22 first throttle by 1%, up to a maximum value of 1.0:
23
24 <binding>
25 <command>property-adjust</command>
26 <property>/controls/throttle[0]</property>
27 <step type="double">0.01</step>
28 <max>1.0</max>
29 </binding>
30
31 A command binding always consists of the XML 'binding' element, with
32 one subelement named 'command' containing the command name (such as
33 'property-adjust'). All other subelements are named parameters to the
34 command: in this case, the parameters are 'property', 'step', and
35 'max'. Here is a simpler binding, with no parameters:
36
37 <binding>
38 <command>exit</command>
39 </binding>
40
41 Bindings always appear inside some other kind of markup, depending on
42 the input type. For example, here is the binding from keyboard.xml
43 that links the ESC key to the 'exit' command:
44
45 <key n="27">
46 <name>ESC</name>
47 <desc>Prompt and quit FlightGear.</desc>
48 <binding>
49 <command>exit</command>
50 </binding>
51 </key>
52
53 Usually, more than one binding is allowed for a single input trigger,
54 and bindings are executed in order from first to last. Bindings support
55 conditions (see README.conditions):
56
57 <key n="113">
58 <name>q</name>
59 <desc>Test</desc>
60
61 <binding>
62 <condition>
63 <property>/devices/status/mice/mouse/button[0]</property>
64 </condition>
65 <command>nasal</command>
66 <script>print("mouse button 0 pressed")</script>
67 </binding>
68 </key>
69
70 Keyboard definitions can embed bindings in tags <mod-up> (key released),
71 <mod-shift>, <mod-ctrl>, <mod-alt>, <mod-meta>, <mod-super>, and <mod-hyper>.
72 Nesting is supported. Meta, Super, and Hyper modifier tags are for local
73 use only, and must be supported by the operating system to work.
74
75 <key n="113">
76 <name>q</name>
77 <desc>Test</desc>
78 <binding>
79 <command>nasal</command>
80 <script>print("q pressed")</script>
81 </binding>
82
83 <mod-alt>
84 <binding>
85 <command>nasal</command>
86 <script>print("Alt-q pressed")</script>
87 </binding>
88
89 <mod-super>
90 <binding>
91 <command>nasal</command>
92 <script>print("Alt-Super-q pressed")</script>
93 </binding>
94
95 <mod-meta>
96 <binding>
97 <command>nasal</command>
98 <script>print("Alt-Super-Meta-q pressed")</script>
99 </binding>
100
101 </mod-meta>
102 </mod-super>
103 </mod-alt>
104 </key>
105
106
107
108 Built-in Commands
109 -----------------
110
111 As of the last revision date, the following commands were available
112 from inside FlightGear; the most commonly-used ones are the commands
113 that operate on property values (FlightGear's internal state):
114
115
116 null - do nothing
117
118 script - execute a PSL script
119 script: the PSL script to execute
120
121 exit - prompt and quit FlightGear
122
123 pause - pause/resume the simulation
124
125 load - load properties from an XML file
126 file: the name of the file to load, relative to the current
127 directory (defaults to "fgfs.sav")
128
129 save - save properties to an XML file
130 file: the name of the file to save, relative to the current
131 directory (defaults to "fgfs.sav").
132
133 loadxml - load XML file into property tree
134 filename: the path & filename of the file to load
135 targetnode: the target node within the property tree where to store the XML
136 file's structure. If targetnode isn't defined, then the data will be stored
137 in a node "data" under the argument branch.
138
139 savexml - save property tree node to XML file
140 filename: the path & filename for the file to be saved
141 sourcenode: the source node within the property tree where the XML file's
142 structure is assembled from. If sourcenode isn't defined, then savexml will
143 try to save data stored in a node "data" in the argument branch.
144
145 panel-load - (re)load the 2D instrument panel
146 path: the path of the XML panel file, relative to $FG_ROOT (defaults
147 to the value of /sim/panel/path if specified, or
148 "Panels/Default/default.xml" as a last resort.
149
150 panel-mouse-click - pass a mouse click to the instrument panel
151 button: the number of the mouse button (0-based)
152 is-down: true if the button is down, false if it is up
153 x-pos: the x position of the mouse click
154 y-pos: the y position of the mouse click
155
156 preferences-load - (re)load preferences
157 path: the file name to load preferences from, relative to $FG_ROOT.
158 Defaults to "preferences.xml".
159
160 view-cycle - cycle to the next viewpoint
161
162 screen-capture - capture the screen to a file
163
164 tile-cache-reload - reload the scenery tile cache
165
166 lighting-update - update FlightGear's lighting
167
168 property-toggle - swap a property value between true and false
169 property: the name of the property to toggle
170
171 property-assign - assign a value to a property
172 property[0]: the name of the property that will get the new value.
173 value: the new value for the property; or
174 property[1]: the name of the property holding the new value.
175
176 property-interpolate - assign a value to a property, interpolated
177 over time
178 property[0]: the name of the property that will get the new value
179 and defines the starting point of the interpolation
180 value: the new value for the property; or
181 property[1]: the name of the property holding the new value.
182 time: the time in seconds it takes for the transition from the
183 old value to the new value of property[0]; or
184 rate: the ammount of change per second the value of property[0] changes
185 to transition to the new value
186
187 property-adjust - adjust the value of a property
188 property: the name of the property to increment or decrement
189 step: the amount of the increment or decrement (defaults to 0)
190 offset: input offset distance (used for the mouse; multiplied by
191 factor)
192 factor: factor for multiplying offset distance (used for the mouse;
193 defaults to 1)
194 min: the minimum allowed value (default: no minimum)
195 max: the maximum allowed value (default: no maximum)
196 mask: 'integer' to apply only to the left of the decimal point;
197 'decimal' to apply only to the right of the decimal point; 'all'
198 to apply to the full value (defaults to 'all')
199 wrap: true if the value should be wrapped when it passes min or max;
200 both min and max must be specified (defaults to false)
201
202 property-multiply - multiply the value of a property
203 property: the name of the property to multiply
204 factor: the amount by which to multiply (defaults to 1.0)
205 min: the minimum allowed value (default: no minimum)
206 max: the maximum allowed value (default: no maximum)
207 mask: 'integer' to apply only to the left of the decimal point;
208 'decimal' to apply only to the right of the decimal point; 'all'
209 to apply to the full value (defaults to 'all')
210 wrap: true if the value should be wrapped when it passes min or max;
211 both min and max must be specified (defaults to false)
212
213 property-swap - swap the values of two properties
214 property[0]: the name of the first property
215 property[1]: the name of the second property
216
217 property-scale - set the value of a property based on an axis
218 property: the name of the property to set
219 setting: the current input setting (usually a joystick axis from -1
220 or 0 to 1)
221 offset: the offset to shift by, before applying the factor (defaults
222 to 0)
223 factor: the factor to multiply by (use negative to reverse; defaults
224 to 1.0)
225 squared: if true will square the resulting value (same as power=2)
226 power: the resulting value will be taken to the power of this integer
227 value (overrides squared; default=1)
228
229 property-cycle - cycle a property through a set of values
230 property: the name of the property to cycle
231 value[*]: all of the allowed values
232
233 dialog-new - create new dialog from the argument branch
234
235 dialog-show - show an XML-configured dialog box
236 dialog-name - the name of the dialog to show
237
238 dialog-close - close the active dialog box
239
240 dialog-update - copy values from FlightGear to the active dialog box
241 object-name: the name of the GUI object to update (defaults to all
242 objects)
243
244 dialog-apply - copy values from the active dialog box to FlightGear
245 object-name: the name of the GUI object to apply (defaults to all
246 objects)
247
248 presets-commit - commit preset values from /sim/presets
249
250 open-browser - open the web browser and show given file
251 path: name of the local file to be opened.
252 url: URL to be opened (http://..., ftp://...).
253
254 The following commands are temporary, and will soon disappear or be
255 renamed; do NOT rely on them:
256
257 old-save-dialog - offer to save a flight
258
259 old-load-dialog - offer to load a flight
260
261 old-reinit-dialog - offer to reinit FlightGear
262
263 old-hires-snapshot-dialog - save a hires screen shot
264
265 old-snapshot-dialog - save a screenshot
266
267 old-print-dialog - print the screen (Windows only)
268
269 old-pilot-offset-dialog - set pilot offsets graphically
270
271 old-hud-alpha-dialog - set the alpha value for the HUD
272
273 old-properties-dialog - display the property browser
274
275 old-preset-airport-dialog - set the default airport
276
277 old-preset-runway-dialog - set the default runway
278
279 old-preset-offset-distance-dialog - set the default offset distance
280
281 old-preset-altitude-dialog - set the default altitude
282
283 old-preset-glidescope-dialog - set the default glidescope
284
285 old-preset-airspeed-dialog - set the default airspeed
286
287 old-preset-commit-dialog - commit preset values
288
289 old-ap-add-waypoint-dialog - add a waypoint to the current route
290
291 old-ap-pop-waypoint-dialog - remove a waypoint from the current route
292
293 old-ap-clear-dialog - clear the current route
294
295 old-ap-adjust-dialog - adjust the autopilot settings
296
297 old-lat-lon-format-dialog - toggle the lat/lon format in the HUD
298
299
300 Adding New Commands in C++
301 --------------------------
302
303
304 To add a new command to FlightGear, you first need to create a
305 function that takes a single SGPropertyNode const pointer as an
306 argument:
307
308 void
309 do_something (SGPropertyNode * arg)
310 {
311 something();
312 }
313
314 Next, you need to register it with the command manager:
315
316 globals->get_commands()->addCommand("something", do_something);
317
318 Now, the command "something" is available to any mouse, joystick,
319 panel, or keyboard bindings. If the bindings pass any arguments, they
320 will be children of the SGPropertyNode passed in:
321
322 void
323 do_something (const SGPropertyNode * arg)
324 {
325 something(arg->getStringValue("foo"), arg->getDoubleValue("bar"));
326 }
327
328 That's pretty-much it. Apologies in advance for not making things any
329 more complicated.
330
331