]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGModel.cpp
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGModel.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGModel.cpp
4  Author:       Jon Berndt
5  Date started: 11/11/98
6  Purpose:      Base class for all models
7  Called by:    FGSimExec, et. al.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
19  details.
20
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This base class for the FGAerodynamics, FGPropagate, etc. classes defines methods
31 common to all models.
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 11/11/98   JSB   Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <iostream>
42 #include "FGModel.h"
43 #include "FGFDMExec.h"
44
45 using namespace std;
46
47 namespace JSBSim {
48
49 static const char *IdSrc = "$Id: FGModel.cpp,v 1.19 2011/05/22 12:44:30 jberndt Exp $";
50 static const char *IdHdr = ID_MODEL;
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 GLOBAL DECLARATIONS
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS IMPLEMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 FGModel::FGModel(FGFDMExec* fdmex)
61 {
62   FDMExec     = fdmex;
63
64   //in order for FGModel derived classes to self-bind (that is, call
65   //their bind function in the constructor, the PropertyManager pointer
66   //must be brought up now.
67   PropertyManager = FDMExec->GetPropertyManager();
68
69   exe_ctr     = 0;
70   rate        = 1;
71
72   if (debug_lvl & 2) cout << "              FGModel Base Class" << endl;
73 }
74
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 FGModel::~FGModel()
78 {
79   if (debug_lvl & 2) cout << "Destroyed:    FGModel" << endl;
80 }
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 bool FGModel::InitModel(void)
85 {
86   return true;
87 }
88
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91 bool FGModel::Run(bool Holding)
92 {
93   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
94
95   if (rate == 1) return false; // Fast exit if nothing to do
96
97   if (exe_ctr >= rate) exe_ctr = 0;
98
99   if (exe_ctr++ == 1) return false;
100   else              return true;
101 }
102
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 //    The bitmasked value choices are as follows:
105 //    unset: In this case (the default) JSBSim would only print
106 //       out the normally expected messages, essentially echoing
107 //       the config files as they are read. If the environment
108 //       variable is not set, debug_lvl is set to 1 internally
109 //    0: This requests JSBSim not to output any messages
110 //       whatsoever.
111 //    1: This value explicity requests the normal JSBSim
112 //       startup messages
113 //    2: This value asks for a message to be printed out when
114 //       a class is instantiated
115 //    4: When this value is set, a message is displayed when a
116 //       FGModel object executes its Run() method
117 //    8: When this value is set, various runtime state variables
118 //       are printed out periodically
119 //    16: When set various parameters are sanity checked and
120 //       a message is printed out when they go out of bounds
121
122 void FGModel::Debug(int from)
123 {
124   if (debug_lvl <= 0) return;
125
126   if (debug_lvl & 1) { // Standard console startup message output
127     if (from == 0) { // Constructor
128
129     }
130   }
131   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
132     if (from == 0) cout << "Instantiated: FGModel" << endl;
133     if (from == 1) cout << "Destroyed:    FGModel" << endl;
134   }
135   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
136   }
137   if (debug_lvl & 8 ) { // Runtime state variables
138   }
139   if (debug_lvl & 16) { // Sanity checking
140   }
141   if (debug_lvl & 64) {
142     if (from == 0) { // Constructor
143       cout << IdSrc << endl;
144       cout << IdHdr << endl;
145     }
146   }
147 }
148 }