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;
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 ) :
_name("unnamed autopilot"),
_serviceable(true),
_rootNode(rootNode)
{
map<string,FunctorBase<Component> *> componentForge;
componentForge["pid-controller"] = new CreateAndConfigureFunctor<PIDController,Component>();
componentForge["pi-simple-controller"] = new CreateAndConfigureFunctor<PISimpleController,Component>();
componentForge["predict-simple"] = new CreateAndConfigureFunctor<Predictor,Component>();

View file

@ -52,7 +52,7 @@ public:
bool is_serviceable() const { return _serviceable; }
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 );

View file

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

View file

@ -24,7 +24,6 @@
#ifndef _XMLAUTO_HXX
#define _XMLAUTO_HXX 1
/**
* @brief Model an autopilot system by implementing a SGSubsystemGroup
*
@ -33,6 +32,9 @@ class FGXMLAutopilotGroup : public SGSubsystemGroup
{
public:
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:
FGXMLAutopilotGroup() : SGSubsystemGroup() {}

View file

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

View file

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