Skip to content

Commit

Permalink
Removed the static member of FGLocation (issue #201).
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Dec 1, 2019
1 parent 7407d23 commit 2661d7c
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 183 deletions.
25 changes: 19 additions & 6 deletions src/FGFDMExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ FGFDMExec::~FGFDMExec()
}

for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
ChildFDMList.clear();

PropertyCatalog.clear();

SetGroundCallback(0);

if (FDMctr != 0) (*FDMctr)--;

Expand All @@ -210,6 +205,25 @@ FGFDMExec::~FGFDMExec()

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

double FGFDMExec::Setsim_time(double cur_time) {
sim_time = cur_time;
Inertial->SetTime(sim_time);
return sim_time;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

double FGFDMExec::IncrTime(void) {
if (!holding && !IntegrationSuspended()) {
sim_time += dT;
Inertial->SetTime(sim_time);
Frame++;
}
return sim_time;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

bool FGFDMExec::Allocate(void)
{
bool result=true;
Expand All @@ -221,7 +235,6 @@ bool FGFDMExec::Allocate(void)
// Note that this does not affect the order in which the models will be
// executed later.
Models[eInertial] = new FGInertial(this);
SetGroundCallback(new FGDefaultGroundCallback(static_cast<FGInertial*>(Models[eInertial])->GetRefRadius()));

// See the eModels enum specification in the header file. The order of the
// enums specifies the order of execution. The Models[] vector is the primary
Expand Down
33 changes: 4 additions & 29 deletions src/FGFDMExec.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,6 @@ class FGFDMExec : public FGJSBBase
@return true if successful */
bool RunIC(void);

/** Sets the ground callback pointer. For optimal memory management, a shared
pointer is used internally that maintains a reference counter. The calling
application must therefore use FGGroundCallback_ptr 'smart pointers' to
manage their copy of the ground callback.
@param gc A pointer to a ground callback object
@see FGGroundCallback
*/
void SetGroundCallback(FGGroundCallback* gc) { FGLocation::SetGroundCallback(gc); }

/** Loads an aircraft model.
@param AircraftPath path to the aircraft/ directory. For instance:
"aircraft". Under aircraft, then, would be directories for various
Expand Down Expand Up @@ -364,12 +355,6 @@ class FGFDMExec : public FGJSBBase
FGInput* GetInput(void) {return (FGInput*)Models[eInput];}
/// Returns the FGOutput pointer.
FGOutput* GetOutput(void) {return (FGOutput*)Models[eOutput];}
/** Get a pointer to the ground callback currently used. It is recommanded
to store the returned pointer in a 'smart pointer' FGGroundCallback_ptr.
@return A pointer to the current ground callback object.
@see FGGroundCallback
*/
FGGroundCallback* GetGroundCallback(void) {return FGLocation::GetGroundCallback();}
/// Retrieves the script object
FGScript* GetScript(void) {return Script;}
/// Returns a pointer to the FGInitialCondition object
Expand Down Expand Up @@ -539,17 +524,14 @@ class FGFDMExec : public FGJSBBase
/** Sets the current sim time.
@param cur_time the current time
@return the current simulation time. */
double Setsim_time(double cur_time) {
sim_time = cur_time;
GetGroundCallback()->SetTime(sim_time);
return sim_time;
}
double Setsim_time(double cur_time);

/** Sets the integration time step for the simulation executive.
@param delta_t the time step in seconds. */
void Setdt(double delta_t) { dT = delta_t; }

/** Sets the root directory where JSBSim starts looking for its system directories.
/** Sets the root directory where JSBSim starts looking for its system
directories.
@param rootDir the string containing the root directory. */
void SetRootDir(const SGPath& rootDir) {RootDir = rootDir;}

Expand All @@ -560,14 +542,7 @@ class FGFDMExec : public FGJSBBase
/** Increments the simulation time if not in Holding mode. The Frame counter
is also incremented.
@return the new simulation time. */
double IncrTime(void) {
if (!holding && !IntegrationSuspended()) {
sim_time += dT;
GetGroundCallback()->SetTime(sim_time);
Frame++;
}
return sim_time;
}
double IncrTime(void);

/** Retrieves the current frame count. */
unsigned int GetFrame(void) const {return Frame;}
Expand Down
23 changes: 11 additions & 12 deletions src/initialization/FGInitialCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void FGInitialCondition::ResetIC(double u0, double v0, double w0,

position.SetLongitude(lonRad0);
position.SetLatitude(latRad0);
position.SetAltitudeAGL(altAGLFt0);
fdmex->GetInertial()->SetAltitudeAGL(position, altAGLFt0);
lastLatitudeSet = setgeoc;
lastAltitudeSet = setagl;

Expand Down Expand Up @@ -643,9 +643,7 @@ void FGInitialCondition::SetWindDirDegIC(double dir)
void FGInitialCondition::SetTerrainElevationFtIC(double elev)
{
double agl = GetAltitudeAGLFtIC();
double sea_level = fdmex->GetInertial()->GetRefRadius();

fdmex->GetGroundCallback()->SetTerrainGeoCentRadius(elev + sea_level);
fdmex->GetInertial()->SetTerrainElevation(elev);

if (lastAltitudeSet == setagl)
SetAltitudeAGLFtIC(agl);
Expand All @@ -662,23 +660,24 @@ double FGInitialCondition::GetAltitudeASLFtIC(void) const

double FGInitialCondition::GetAltitudeAGLFtIC(void) const
{
return position.GetAltitudeAGL();
return fdmex->GetInertial()->GetAltitudeAGL(position);
}

//******************************************************************************

double FGInitialCondition::GetTerrainElevationFtIC(void) const
{
return position.GetTerrainRadius() - fdmex->GetInertial()->GetRefRadius();
FGLocation contact;
FGColumnVector3 normal, v, w;
fdmex->GetInertial()->GetContactPoint(position, contact, normal, v, w);
return contact.GetGeodAltitude();
}

//******************************************************************************

void FGInitialCondition::SetAltitudeAGLFtIC(double agl)
{
double terrainElevation = position.GetTerrainRadius()
- fdmex->GetInertial()->GetRefRadius();
SetAltitudeASLFtIC(agl + terrainElevation);
fdmex->GetInertial()->SetAltitudeAGL(position, agl);
lastAltitudeSet = setagl;
}

Expand Down Expand Up @@ -1085,8 +1084,7 @@ bool FGInitialCondition::Load_v2(Element* document)
FGColumnVector3 vOmegaEarth = fdmex->GetInertial()->GetOmegaPlanet();

if (document->FindElement("elevation")) {
double sea_level = fdmex->GetInertial()->GetRefRadius();
fdmex->GetGroundCallback()->SetTerrainGeoCentRadius(document->FindElementValueAsNumberConvertTo("elevation", "FT")+sea_level);
fdmex->GetInertial()->SetTerrainElevation(document->FindElementValueAsNumberConvertTo("elevation", "FT"));
}

// Initialize vehicle position
Expand All @@ -1111,7 +1109,8 @@ bool FGInitialCondition::Load_v2(Element* document)
if (position_el->FindElement("radius")) {
position.SetRadius(position_el->FindElementValueAsNumberConvertTo("radius", "FT"));
} else if (position_el->FindElement("altitudeAGL")) {
position.SetAltitudeAGL(position_el->FindElementValueAsNumberConvertTo("altitudeAGL", "FT"));
fdmex->GetInertial()->SetAltitudeAGL(position,
position_el->FindElementValueAsNumberConvertTo("altitudeAGL", "FT"));
} else if (position_el->FindElement("altitudeMSL")) {
position.SetPositionGeodetic(longitude, 0.0,
position_el->FindElementValueAsNumberConvertTo("altitudeMSL", "FT"));
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/FGTrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ void FGTrim::trimOnGround(void)

FGColumnVector3 normal, vDummy;
FGLocation lDummy;
double height = gearLoc.GetContactPoint(lDummy, normal, vDummy, vDummy);
double height = fdmex->GetInertial()->GetContactPoint(gearLoc, lDummy,
normal, vDummy,
vDummy);

if (gear->IsBogey() && !GroundReactions->GetSolid())
continue;
Expand Down
1 change: 1 addition & 0 deletions src/input_output/FGGroundCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ double FGDefaultGroundCallback::GetAGLevel(double t, const FGLocation& loc,
double loc_radius = loc.GetRadius(); // Get the radius of the given location
// (e.g. the CG)
double agl = loc_radius - mTerrainLevelRadius;
contact.SetEllipse(mSeaLevelRadius, mSeaLevelRadius);
contact = (mTerrainLevelRadius/loc_radius)*FGColumnVector3(loc);
return agl;
}
Expand Down
33 changes: 10 additions & 23 deletions src/input_output/FGGroundCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ SENTRY
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "simgear/structure/SGSharedPtr.hxx"

namespace JSBSim {

class FGLocation;
Expand All @@ -61,7 +59,7 @@ CLASS DOCUMENTATION
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

class FGGroundCallback : public SGReferenced
class FGGroundCallback
{
public:

Expand Down Expand Up @@ -97,32 +95,23 @@ class FGGroundCallback : public SGReferenced
FGColumnVector3& w) const
{ return GetAGLevel(time, location, contact, normal, v, w); }

/** Compute the local terrain radius
@param t simulation time
@param location location
*/
virtual double GetTerrainGeoCentRadius(double t, const FGLocation& location) const = 0;

/** Compute the local terrain radius
@param location location
*/
virtual double GetTerrainGeoCentRadius(const FGLocation& location) const
{ return GetTerrainGeoCentRadius(time, location); }

/** Set the local terrain radius.
/** Set the terrain elevation.
Only needs to be implemented if JSBSim should be allowed
to modify the local terrain radius (see the default implementation)
*/
virtual void SetTerrainGeoCentRadius(double radius) {}
virtual void SetTerrainElevation(double h) {}

/** Set the simulation time.
The elapsed time can be used by the ground callbck to assess the planet
rotation or the movement of objects.
@param _time elapsed time in seconds since the simulation started.
*/
void SetTime(double _time) { time = _time; }

protected:
double time;
};

typedef SGSharedPtr<FGGroundCallback> FGGroundCallback_ptr;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// The default sphere earth implementation:
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -138,10 +127,8 @@ class FGDefaultGroundCallback : public FGGroundCallback
FGColumnVector3& normal, FGColumnVector3& v,
FGColumnVector3& w) const override;

void SetTerrainGeoCentRadius(double radius) override
{ mTerrainLevelRadius = radius;}
double GetTerrainGeoCentRadius(double t, const FGLocation& location) const override
{ return mTerrainLevelRadius; }
void SetTerrainElevation(double h) override
{ mTerrainLevelRadius = mSeaLevelRadius + h; }

private:
double mSeaLevelRadius;
Expand Down
16 changes: 12 additions & 4 deletions src/math/FGLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ INCLUDES

namespace JSBSim {

// Set up the default ground callback object.
FGGroundCallback_ptr FGLocation::GroundCallback = nullptr;

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
Expand Down Expand Up @@ -137,7 +134,7 @@ FGLocation::FGLocation(const FGLocation& l)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

const FGLocation& FGLocation::operator=(const FGLocation& l)
FGLocation& FGLocation::operator=(const FGLocation& l)
{
mECLoc = l.mECLoc;
mCacheValid = l.mCacheValid;
Expand Down Expand Up @@ -267,6 +264,17 @@ void FGLocation::SetEllipse(double semimajor, double semiminor)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

double FGLocation::GetSeaLevelRadius(void) const
{
if (!mCacheValid) ComputeDerivedUnconditional();

double sinGeodLat = sin(mGeodLat);

return a/sqrt(1+e2*sinGeodLat*sinGeodLat/ec2);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGLocation::ComputeDerivedUnconditional(void) const
{
// The radius is just the Euclidean norm of the vector.
Expand Down
Loading

0 comments on commit 2661d7c

Please sign in to comment.