1
0
Fork 0

Merge branch 'next' of gitorious.org:fg/flightgear into next

This commit is contained in:
Durk Talsma 2011-10-27 23:27:21 +02:00
commit 2da052d4ab
6 changed files with 74 additions and 37 deletions

View file

@ -41,12 +41,25 @@ using std::string;
using namespace FGXMLAutopilot; using namespace FGXMLAutopilot;
class ComponentForge : public map<string,FunctorBase<Component> *> {
public:
virtual ~ ComponentForge();
};
ComponentForge::~ComponentForge()
{
for( iterator it = begin(); it != end(); ++it )
delete it->second;
}
static ComponentForge componentForge;
Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode ) : Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode ) :
_name("unnamed autopilot"), _name("unnamed autopilot"),
_serviceable(true), _serviceable(true),
_rootNode(rootNode) _rootNode(rootNode)
{ {
map<string,FunctorBase<Component> *> componentForge;
componentForge["pid-controller"] = new CreateAndConfigureFunctor<PIDController,Component>(); componentForge["pid-controller"] = new CreateAndConfigureFunctor<PIDController,Component>();
componentForge["pi-simple-controller"] = new CreateAndConfigureFunctor<PISimpleController,Component>(); componentForge["pi-simple-controller"] = new CreateAndConfigureFunctor<PISimpleController,Component>();
componentForge["predict-simple"] = new CreateAndConfigureFunctor<Predictor,Component>(); componentForge["predict-simple"] = new CreateAndConfigureFunctor<Predictor,Component>();

View file

@ -52,7 +52,7 @@ public:
bool is_serviceable() const { return _serviceable; } bool is_serviceable() const { return _serviceable; }
std::string get_name() const { return _name; } std::string get_name() const { return _name; }
void set_name( std::string & name ) { _name = name; } void set_name( const std::string & name ) { _name = name; }
void add_component( Component * component ); void add_component( Component * component );

View file

@ -35,6 +35,7 @@
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <boost/foreach.hpp>
using std::vector; using std::vector;
using std::string; using std::string;
@ -43,6 +44,8 @@ using simgear::PropertyList;
class FGXMLAutopilotGroupImplementation : public FGXMLAutopilotGroup class FGXMLAutopilotGroupImplementation : public FGXMLAutopilotGroup
{ {
public: public:
virtual void addAutopilot( const std::string & name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config );
virtual void removeAutopilot( const std::string & name );
void init(); void init();
void reinit(); void reinit();
void update( double dt ); void update( double dt );
@ -52,6 +55,30 @@ private:
}; };
void FGXMLAutopilotGroupImplementation::addAutopilot( const std::string & name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config )
{
BOOST_FOREACH( std::string & n, _autopilotNames ) {
if( n == name ) {
SG_LOG(SG_ALL, SG_ALERT, "NOT adding duplicate property rule name " << name );
return;
}
}
FGXMLAutopilot::Autopilot * ap = new FGXMLAutopilot::Autopilot( apNode, config );
ap->set_name( name );
set_subsystem( name, ap );
_autopilotNames.push_back( name );
}
void FGXMLAutopilotGroupImplementation::removeAutopilot( const std::string & name )
{
FGXMLAutopilot::Autopilot * ap = (FGXMLAutopilot::Autopilot*)get_subsystem( name );
if( ap == NULL ) return; // ?
remove_subsystem( name );
delete ap;
}
void FGXMLAutopilotGroupImplementation::update( double dt ) void FGXMLAutopilotGroupImplementation::update( double dt )
{ {
// update all configured autopilots // update all configured autopilots
@ -63,10 +90,7 @@ void FGXMLAutopilotGroupImplementation::reinit()
SGSubsystemGroup::unbind(); SGSubsystemGroup::unbind();
for( vector<string>::size_type i = 0; i < _autopilotNames.size(); i++ ) { for( vector<string>::size_type i = 0; i < _autopilotNames.size(); i++ ) {
FGXMLAutopilot::Autopilot * ap = (FGXMLAutopilot::Autopilot*)get_subsystem( _autopilotNames[i] ); removeAutopilot( _autopilotNames[i] );
if( ap == NULL ) continue; // ?
remove_subsystem( _autopilotNames[i] );
delete ap;
} }
_autopilotNames.clear(); _autopilotNames.clear();
init(); init();
@ -90,21 +114,20 @@ void FGXMLAutopilotGroupImplementation::initFrom( SGPropertyNode_ptr rootNode, c
if( rootNode == NULL ) if( rootNode == NULL )
return; return;
PropertyList autopilotNodes = rootNode->getChildren(childName); BOOST_FOREACH( SGPropertyNode_ptr autopilotNode, rootNode->getChildren(childName) ) {
for( PropertyList::size_type i = 0; i < autopilotNodes.size(); i++ ) { SGPropertyNode_ptr pathNode = autopilotNode->getNode( "path" );
SGPropertyNode_ptr pathNode = autopilotNodes[i]->getNode( "path" );
if( pathNode == NULL ) { if( pathNode == NULL ) {
SG_LOG( SG_ALL, SG_WARN, "No configuration file specified for this property-rule!"); SG_LOG( SG_ALL, SG_WARN, "No configuration file specified for this property-rule!");
continue; continue;
} }
string apName; string apName;
SGPropertyNode_ptr nameNode = autopilotNodes[i]->getNode( "name" ); SGPropertyNode_ptr nameNode = autopilotNode->getNode( "name" );
if( nameNode != NULL ) { if( nameNode != NULL ) {
apName = nameNode->getStringValue(); apName = nameNode->getStringValue();
} else { } else {
std::ostringstream buf; std::ostringstream buf;
buf << "unnamed_autopilot_" << i; buf << "unnamed_autopilot_" << autopilotNode->getIndex();
apName = buf.str(); apName = buf.str();
} }
@ -120,31 +143,31 @@ void FGXMLAutopilotGroupImplementation::initFrom( SGPropertyNode_ptr rootNode, c
SG_LOG( SG_ALL, SG_WARN, "Duplicate property-rule configuration name " << name << ", renamed to " << apName ); SG_LOG( SG_ALL, SG_WARN, "Duplicate property-rule configuration name " << name << ", renamed to " << apName );
} }
SGPath config = globals->resolve_maybe_aircraft_path(pathNode->getStringValue()); addAutopilotFromFile( apName, autopilotNode, pathNode->getStringValue() );
}
}
void FGXMLAutopilotGroup::addAutopilotFromFile( const std::string & name, SGPropertyNode_ptr apNode, const char * path )
{
SGPath config = globals->resolve_maybe_aircraft_path(path);
if (config.isNull()) if (config.isNull())
{ {
SG_LOG( SG_ALL, SG_ALERT, "Cannot find property-rule configuration file '" << pathNode->getStringValue() << "'." ); SG_LOG( SG_ALL, SG_ALERT, "Cannot find property-rule configuration file '" << path << "'." );
return;
} }
else
{
SG_LOG( SG_ALL, SG_INFO, "Reading property-rule configuration from " << config.str() ); SG_LOG( SG_ALL, SG_INFO, "Reading property-rule configuration from " << config.str() );
try { try {
SGPropertyNode_ptr root = new SGPropertyNode(); SGPropertyNode_ptr configNode = new SGPropertyNode();
readProperties( config.str(), root ); readProperties( config.str(), configNode );
SG_LOG( SG_AUTOPILOT, SG_INFO, "adding property-rule subsystem " << apName ); SG_LOG( SG_AUTOPILOT, SG_INFO, "adding property-rule subsystem " << name );
FGXMLAutopilot::Autopilot * ap = new FGXMLAutopilot::Autopilot( autopilotNodes[i], root ); addAutopilot( name, apNode, configNode );
ap->set_name( apName );
set_subsystem( apName, ap );
_autopilotNames.push_back( apName );
} catch (const sg_exception& e) { } catch (const sg_exception& e) {
SG_LOG( SG_AUTOPILOT, SG_ALERT, "Failed to load property-rule configuration: " SG_LOG( SG_AUTOPILOT, SG_ALERT, "Failed to load property-rule configuration: "
<< config.str() << ":" << e.getMessage() ); << config.str() << ":" << e.getMessage() );
continue; return;
}
}
} }
} }

View file

@ -24,7 +24,6 @@
#ifndef _XMLAUTO_HXX #ifndef _XMLAUTO_HXX
#define _XMLAUTO_HXX 1 #define _XMLAUTO_HXX 1
/** /**
* @brief Model an autopilot system by implementing a SGSubsystemGroup * @brief Model an autopilot system by implementing a SGSubsystemGroup
* *
@ -33,6 +32,9 @@ class FGXMLAutopilotGroup : public SGSubsystemGroup
{ {
public: public:
static FGXMLAutopilotGroup * createInstance(); static FGXMLAutopilotGroup * createInstance();
void addAutopilotFromFile( const std::string & name, SGPropertyNode_ptr apNode, const char * path );
virtual void addAutopilot( const std::string & name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config ) = 0;
virtual void removeAutopilot( const std::string & name ) = 0;
protected: protected:
FGXMLAutopilotGroup() : SGSubsystemGroup() {} FGXMLAutopilotGroup() : SGSubsystemGroup() {}

View file

@ -35,8 +35,7 @@ public:
}; };
template <class TClass,class TBase> class CreateAndConfigureFunctor : template <class TClass,class TBase> class CreateAndConfigureFunctor :
public FunctorBase<TBase>, public FunctorBase<TBase> {
SGReferenced {
public: public:
virtual TBase * operator()( SGPropertyNode_ptr configNode ) { virtual TBase * operator()( SGPropertyNode_ptr configNode ) {
TBase * base = new TClass(); TBase * base = new TClass();

View file

@ -285,7 +285,7 @@ GLuint FGPanel::getInitDisplayList()
void void
FGPanel::update (double dt) FGPanel::update (double dt)
{ {
glCallList(getInitDisplayList()); /*glCallList*/(getInitDisplayList());
// Draw the instruments. // Draw the instruments.
// Syd Adams: added instrument clipping // Syd Adams: added instrument clipping