1 // fg_commands.cxx - internal FGFS commands.
3 #include "fg_commands.hxx"
5 #include <simgear/debug/logstream.hxx>
6 #include <simgear/misc/commands.hxx>
7 #include <simgear/misc/props.hxx>
11 #include "fg_props.hxx"
13 #include "globals.hxx"
17 * Built-in command: exit FlightGear.
19 * TODO: show a confirm dialog.
22 do_exit (const SGPropertyNode * arg)
31 * Built-in command: cycle view.
34 do_view_cycle (const SGPropertyNode * arg)
36 globals->get_current_view()->set_view_offset(0.0);
37 globals->set_current_view(globals->get_viewmgr()->next_view());
38 // fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
44 * Built-in command: capture screen.
47 do_screen_capture (const SGPropertyNode * arg)
55 * Built-in command: toggle a bool property value.
57 * property: The name of the property to toggle.
60 do_property_toggle (const SGPropertyNode * arg)
62 string propname = arg->getStringValue("property", "");
66 SGPropertyNode * node = fgGetNode(propname);
67 return node->setBoolValue(!node->getBoolValue());
72 * Built-in command: assign a value to a property.
74 * property: the name of the property to assign.
75 * value: the value to assign.
78 do_property_assign (const SGPropertyNode * arg)
80 string propname = arg->getStringValue("property", "");
84 SGPropertyNode * node = fgGetNode(propname, true);
86 switch (node->getType()) {
88 return node->setBoolValue(arg->getBoolValue("value"));
90 return node->setIntValue(arg->getIntValue("value"));
92 return node->setLongValue(arg->getLongValue("value"));
94 return node->setFloatValue(arg->getFloatValue("value"));
96 return node->setDoubleValue(arg->getDoubleValue("value"));
98 return node->setStringValue(arg->getStringValue("value"));
100 return node->setUnknownValue(arg->getStringValue("value"));
106 * Built-in command: increment or decrement a property value.
108 * property: the name of the property to increment or decrement.
109 * step: the amount of the increment or decrement.
112 do_property_adjust (const SGPropertyNode * arg)
114 string propname = arg->getStringValue("property", "");
118 SGPropertyNode * node = fgGetNode(propname, true);
120 switch (node->getType()) {
122 if (arg->getBoolValue("step"))
123 return node->setBoolValue(!node->getBoolValue());
127 return node->setIntValue(node->getIntValue()
128 + arg->getIntValue("step"));
130 return node->setLongValue(node->getLongValue()
131 + arg->getLongValue("step"));
133 return node->setFloatValue(node->getFloatValue()
134 + arg->getFloatValue("step"));
135 case SGValue::DOUBLE:
136 return node->setDoubleValue(node->getDoubleValue()
137 + arg->getDoubleValue("step"));
138 default: // doesn't make sense with strings
145 * Built-in command: swap two property values.
147 * property[0]: the name of the first property.
148 * property[1]: the name of the second property.
151 do_property_swap (const SGPropertyNode * arg)
153 string propname1 = arg->getStringValue("property[0]", "");
154 string propname2 = arg->getStringValue("property[1]", "");
155 if (propname1 == "" || propname2 == "")
158 SGPropertyNode * node1 = fgGetNode(propname1, true);
159 SGPropertyNode * node2 = fgGetNode(propname2, true);
160 string tmp = node1->getStringValue();
161 return (node1->setUnknownValue(node2->getStringValue()) &&
162 node2->setUnknownValue(tmp));
168 * Table of built-in commands.
170 * New commands do not have to be added here; any module in the application
171 * can add a new command using globals->get_commands()->addCommand(...).
175 SGCommandMgr::command_t command;
178 "view-cycle", do_view_cycle,
179 "screen-capture", do_screen_capture,
180 "property-toggle", do_property_toggle,
181 "property-assign", do_property_assign,
182 "property-adjust", do_property_adjust,
183 "property-swap", do_property_swap,
184 0, 0 // zero-terminated
189 * Initialize the default built-in commands.
191 * Other commands may be added by other parts of the application.
196 SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
197 for (int i = 0; built_ins[i].name != 0; i++) {
198 SG_LOG(SG_GENERAL, SG_INFO, " " << built_ins[i].name);
199 globals->get_commands()->addCommand(built_ins[i].name,
200 built_ins[i].command);
204 // end of fg_commands.hxx