+
+void FGElectricalSystem::update (double dt) {
+}
+
+
+bool FGElectricalSystem::build () {
+ SGPropertyNode *node;
+ int i, j;
+
+ int count = config_props->nChildren();
+ for ( i = 0; i < count; ++i ) {
+ node = config_props->getChild(i);
+ string name = node->getName();
+ // cout << name << endl;
+ if ( name == "supplier" ) {
+ FGElectricalSupplier *s =
+ new FGElectricalSupplier( node->getStringValue("name"),
+ node->getStringValue("kind"),
+ node->getDoubleValue("volts"),
+ node->getDoubleValue("amps") );
+ suppliers.push_back( s );
+ } else if ( name == "bus" ) {
+ FGElectricalBus *b =
+ new FGElectricalBus( node->getStringValue("name") );
+ buses.push_back( b );
+ } else if ( name == "output" ) {
+ FGElectricalOutput *o =
+ new FGElectricalOutput( node->getStringValue("name") );
+ outputs.push_back( o );
+ } else if ( name == "connector" ) {
+ FGElectricalConnector *c =
+ new FGElectricalConnector();
+ connectors.push_back( c );
+ SGPropertyNode *child;
+ int ccount = node->nChildren();
+ for ( j = 0; j < ccount; ++j ) {
+ child = node->getChild(j);
+ string cname = child->getName();
+ string cval = child->getStringValue();
+ // cout << " " << cname << " = " << cval << endl;
+ if ( cname == "input" ) {
+ FGElectricalComponent *s = find( child->getStringValue() );
+ if ( s != NULL ) {
+ c->add_input( s );
+ if ( s->get_kind() == FG_SUPPLIER ) {
+ ((FGElectricalSupplier *)s)->add_output( c );
+ } else if ( s->get_kind() == FG_BUS ) {
+ ((FGElectricalBus *)s)->add_output( c );
+ } else {
+ SG_LOG( SG_ALL, SG_ALERT,
+ "Attempt to connect to something that can't provide an output: "
+ << child->getStringValue() );
+ return false;
+ }
+ } else {
+ SG_LOG( SG_ALL, SG_ALERT,
+ "Can't find named source: "
+ << child->getStringValue() );
+ return false;
+ }
+ } else if ( cname == "output" ) {
+ FGElectricalComponent *s = find( child->getStringValue() );
+ if ( s != NULL ) {
+ c->add_output( s );
+ if ( s->get_kind() == FG_BUS ) {
+ ((FGElectricalBus *)s)->add_input( c );
+ } else if ( s->get_kind() == FG_OUTPUT ) {
+ ((FGElectricalOutput *)s)->add_input( c );
+ } else {
+ SG_LOG( SG_ALL, SG_ALERT,
+ "Attempt to connect to something that can't provide an input: "
+ << child->getStringValue() );
+ return false;
+ }
+ } else {
+ SG_LOG( SG_ALL, SG_ALERT,
+ "Can't find named source: "
+ << child->getStringValue() );
+ return false;
+ }
+ } else if ( cname == "switch" ) {
+ c->add_switch( child->getStringValue() );
+ }
+ }
+ } else {
+ SG_LOG( SG_ALL, SG_ALERT, "Unknown component type specified: "
+ << name );
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+// search for the named component and return a pointer to it, NULL otherwise
+FGElectricalComponent *FGElectricalSystem::find ( const string &name ) {
+ unsigned int i;
+ string s;
+
+ // search suppliers
+ for ( i = 0; i < suppliers.size(); ++i ) {
+ s = ((FGElectricalSupplier *)suppliers[i])->get_name();
+ // cout << " " << s << endl;
+ if ( s == name ) {
+ return suppliers[i];
+ }
+ }
+
+ // then search buses
+ for ( i = 0; i < buses.size(); ++i ) {
+ s = ((FGElectricalBus *)buses[i])->get_name();
+ // cout << " " << s << endl;
+ if ( s == name ) {
+ return buses[i];
+ }
+ }
+
+ // then search outputs
+ for ( i = 0; i < outputs.size(); ++i ) {
+ s = ((FGElectricalOutput *)outputs[i])->get_name();
+ // cout << " " << s << endl;
+ if ( s == name ) {
+ return outputs[i];
+ }
+ }
+
+ // nothing found
+ return NULL;