From: curt Date: Mon, 17 Nov 2003 21:10:47 +0000 (+0000) Subject: Added code to support a richer switch definition syntax. Currently we only X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9d33285ef0c5ca7351cf9c390eb3d51ffc3b0c16;p=flightgear.git Added code to support a richer switch definition syntax. Currently we only support an attached property name and an intial state, but this can easily be extended to configure a switch to be a circuit breaker with a max rating, etc. --- diff --git a/src/Systems/electrical.cxx b/src/Systems/electrical.cxx index 8e6cbc2b9..41396cc51 100644 --- a/src/Systems/electrical.cxx +++ b/src/Systems/electrical.cxx @@ -132,6 +132,33 @@ FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) { } +FGElectricalSwitch::FGElectricalSwitch( SGPropertyNode *node ) : + switch_node( NULL ), + rating_amps( 0.0f ), + circuit_breaker( false ) +{ + bool initial_state = true; + int i; + for ( i = 0; i < node->nChildren(); ++i ) { + SGPropertyNode *child = node->getChild(i); + string cname = child->getName(); + string cval = child->getStringValue(); + if ( cname == "prop" ) { + switch_node = fgGetNode( cval.c_str(), true ); + cout << "switch node = " << cval << endl; + } else if ( cname == "initial-state" ) { + if ( cval == "off" || cval == "false" ) { + initial_state = false; + } + cout << "initial state = " << initial_state << endl; + } + } + + switch_node->setBoolValue( initial_state ); + cout << " value = " << switch_node->getBoolValue() << endl; +} + + FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es ) { kind = FG_CONNECTOR; @@ -179,28 +206,14 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node, } else if ( cname == "switch" ) { // set default value of switch to true // cout << "Switch = " << child->getStringValue() << endl; - fgSetBool( child->getStringValue(), true ); - FGElectricalSwitch s( fgGetNode(child->getStringValue(), true), - 100.0f, - false ); + FGElectricalSwitch s( child ); + // FGElectricalSwitch s( fgGetNode(child->getStringValue(), true), + // 100.0f, + // false ); + // fgSetBool( child->getStringValue(), true ); add_switch( s ); } } - - // do a 2nd pass to pick up starting switch value if specified - for ( i = 0; i < node->nChildren(); ++i ) { - SGPropertyNode *child = node->getChild(i); - string cname = child->getName(); - string cval = child->getStringValue(); - // cout << " " << cname << " = " << cval << endl; - if ( cname == "initial-state" ) { - if ( cval == "off" ) { - set_switches( false ); - } else { - set_switches( true ); - } - } - } } diff --git a/src/Systems/electrical.hxx b/src/Systems/electrical.hxx index 16a86ba8e..1a0434222 100644 --- a/src/Systems/electrical.hxx +++ b/src/Systems/electrical.hxx @@ -178,11 +178,7 @@ private: public: - FGElectricalSwitch( SGPropertyNode *node, float rate, bool cb ) { - switch_node = node; - rating_amps = rate; - circuit_breaker = cb; - } + FGElectricalSwitch( SGPropertyNode *node ); ~FGElectricalSwitch() { };