3 * Interface definition for encapsulated commands.
4 * Started Spring 2001 by David Megginson, david@megginson.com
5 * This code is released into the Public Domain.
11 # include <simgear_config.h>
14 #include <simgear/compiler.h>
15 #include "SGBinding.hxx"
17 #include <simgear/math/SGMath.hxx>
19 SGBinding::SGBinding()
21 _arg(new SGPropertyNode),
26 SGBinding::SGBinding(const SGPropertyNode* node, SGPropertyNode* root)
34 SGBinding::~SGBinding()
36 if(_arg && _arg->getParent())
37 _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex(), false);
41 SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root)
43 const SGPropertyNode * conditionNode = node->getChild("condition");
44 if (conditionNode != 0)
45 setCondition(sgReadCondition(root, conditionNode));
47 _command_name = node->getStringValue("command", "");
48 if (_command_name.empty()) {
49 SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
53 _arg = const_cast<SGPropertyNode*>(node);
58 SGBinding::fire () const
62 _command = SGCommandMgr::instance()->getCommand(_command_name);
64 SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
65 } else if (!(*_command)(_arg)) {
66 SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
73 SGBinding::fire (double offset, double max) const
76 _arg->setDoubleValue("offset", offset/max);
82 SGBinding::fire (double setting) const
85 // A value is automatically added to
87 if (_setting == 0) // save the setting node for efficiency
88 _setting = _arg->getChild("setting", 0, true);
89 _setting->setDoubleValue(setting);