JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGModel.cpp

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002 
00003  Module:       FGModel.cpp
00004  Author:       Jon Berndt
00005  Date started: 11/11/98
00006  Purpose:      Base class for all models
00007  Called by:    FGSimExec, et. al.
00008 
00009  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
00010 
00011  This program is free software; you can redistribute it and/or modify it under
00012  the terms of the GNU Lesser General Public License as published by the Free Software
00013  Foundation; either version 2 of the License, or (at your option) any later
00014  version.
00015 
00016  This program is distributed in the hope that it will be useful, but WITHOUT
00017  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00019  details.
00020 
00021  You should have received a copy of the GNU Lesser General Public License along with
00022  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00023  Place - Suite 330, Boston, MA  02111-1307, USA.
00024 
00025  Further information about the GNU Lesser General Public License can also be found on
00026  the world wide web at http://www.gnu.org.
00027 
00028 FUNCTIONAL DESCRIPTION
00029 --------------------------------------------------------------------------------
00030 This base class for the FGAerodynamics, FGPropagate, etc. classes defines methods
00031 common to all models.
00032 
00033 HISTORY
00034 --------------------------------------------------------------------------------
00035 11/11/98   JSB   Created
00036 
00037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00038 INCLUDES
00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00040 
00041 #include <iostream>
00042 #include "FGModel.h"
00043 #include "FGFDMExec.h"
00044 
00045 using namespace std;
00046 
00047 namespace JSBSim {
00048 
00049 static const char *IdSrc = "$Id: FGModel.cpp,v 1.21 2013/01/14 22:44:52 bcoconni Exp $";
00050 static const char *IdHdr = ID_MODEL;
00051 
00052 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00053 GLOBAL DECLARATIONS
00054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00055 
00056 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00057 CLASS IMPLEMENTATION
00058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00059 
00060 FGModel::FGModel(FGFDMExec* fdmex)
00061 {
00062   FDMExec     = fdmex;
00063 
00064   //in order for FGModel derived classes to self-bind (that is, call
00065   //their bind function in the constructor, the PropertyManager pointer
00066   //must be brought up now.
00067   PropertyManager = FDMExec->GetPropertyManager();
00068 
00069   exe_ctr     = 1;
00070   rate        = 1;
00071 
00072   if (debug_lvl & 2) cout << "              FGModel Base Class" << endl;
00073 }
00074 
00075 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00076 
00077 FGModel::~FGModel()
00078 {
00079   if (debug_lvl & 2) cout << "Destroyed:    FGModel" << endl;
00080 }
00081 
00082 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00083 
00084 bool FGModel::InitModel(void)
00085 {
00086   exe_ctr = 1;
00087   return true;
00088 }
00089 
00090 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00091 
00092 bool FGModel::Run(bool Holding)
00093 {
00094   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
00095 
00096   if (rate == 1) return false; // Fast exit if nothing to do
00097 
00098   if (exe_ctr >= rate) exe_ctr = 0;
00099 
00100   if (exe_ctr++ == 1) return false;
00101   else              return true;
00102 }
00103 
00104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00105 //    The bitmasked value choices are as follows:
00106 //    unset: In this case (the default) JSBSim would only print
00107 //       out the normally expected messages, essentially echoing
00108 //       the config files as they are read. If the environment
00109 //       variable is not set, debug_lvl is set to 1 internally
00110 //    0: This requests JSBSim not to output any messages
00111 //       whatsoever.
00112 //    1: This value explicity requests the normal JSBSim
00113 //       startup messages
00114 //    2: This value asks for a message to be printed out when
00115 //       a class is instantiated
00116 //    4: When this value is set, a message is displayed when a
00117 //       FGModel object executes its Run() method
00118 //    8: When this value is set, various runtime state variables
00119 //       are printed out periodically
00120 //    16: When set various parameters are sanity checked and
00121 //       a message is printed out when they go out of bounds
00122 
00123 void FGModel::Debug(int from)
00124 {
00125   if (debug_lvl <= 0) return;
00126 
00127   if (debug_lvl & 1) { // Standard console startup message output
00128     if (from == 0) { // Constructor
00129 
00130     }
00131   }
00132   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
00133     if (from == 0) cout << "Instantiated: FGModel" << endl;
00134     if (from == 1) cout << "Destroyed:    FGModel" << endl;
00135   }
00136   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
00137   }
00138   if (debug_lvl & 8 ) { // Runtime state variables
00139   }
00140   if (debug_lvl & 16) { // Sanity checking
00141   }
00142   if (debug_lvl & 64) {
00143     if (from == 0) { // Constructor
00144       cout << IdSrc << endl;
00145       cout << IdHdr << endl;
00146     }
00147   }
00148 }
00149 }