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.
10 #include <simgear/compiler.h>
11 #include "SGBinding.hxx"
13 SGBinding::SGBinding()
15 _arg(new SGPropertyNode),
20 SGBinding::SGBinding(const SGPropertyNode* node, SGPropertyNode* root)
28 SGBinding::~SGBinding()
30 if(_arg && _arg->getParent())
31 _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex(), false);
35 SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root)
37 const SGPropertyNode * conditionNode = node->getChild("condition");
38 if (conditionNode != 0)
39 setCondition(sgReadCondition(root, conditionNode));
41 _command_name = node->getStringValue("command", "");
42 if (_command_name.empty()) {
43 SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
47 _arg = const_cast<SGPropertyNode*>(node);
52 SGBinding::fire () const
56 _command = SGCommandMgr::instance()->getCommand(_command_name);
58 SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
59 } else if (!(*_command)(_arg)) {
60 SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
67 SGBinding::fire (double offset, double max) const
70 _arg->setDoubleValue("offset", offset/max);
76 SGBinding::fire (double setting) const
79 // A value is automatically added to
81 if (_setting == 0) // save the setting node for efficiency
82 _setting = _arg->getChild("setting", 0, true);
83 _setting->setDoubleValue(setting);