]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGModel.cpp
Latest round of JSBSim updates.
[flightgear.git] / src / FDM / JSBSim / 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 (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU 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 General Public License for more
19  details.
20
21  You should have received a copy of the GNU 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 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 FGAero, FGRotational, 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 "FGModel.h"
42 #include "FGState.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51 #include "FGOutput.h"
52
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_MODEL;
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 GLOBAL DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 extern short debug_lvl;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS IMPLEMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 FGModel::FGModel(FGFDMExec* fdmex)
67 {
68   FDMExec     = fdmex;
69   NextModel   = 0L;
70
71   State       = 0;
72   Atmosphere  = 0;
73   FCS         = 0;
74   Propulsion  = 0;
75   Aircraft    = 0;
76   Translation = 0;
77   Rotation    = 0;
78   Position    = 0;
79   Auxiliary   = 0;
80   Output      = 0;
81
82   exe_ctr     = 1;
83
84   if (debug_lvl & 2) cout << "              FGModel Base Class" << endl;
85 }
86
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 FGModel::~FGModel()
90 {
91   if (debug_lvl & 2) cout << "Destroyed:    FGModel" << endl;
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 bool FGModel::InitModel(void)
97 {
98   State       = FDMExec->GetState();
99   Atmosphere  = FDMExec->GetAtmosphere();
100   FCS         = FDMExec->GetFCS();
101   Propulsion  = FDMExec->GetPropulsion();
102   Aircraft    = FDMExec->GetAircraft();
103   Translation = FDMExec->GetTranslation();
104   Rotation    = FDMExec->GetRotation();
105   Position    = FDMExec->GetPosition();
106   Auxiliary   = FDMExec->GetAuxiliary();
107   Output      = FDMExec->GetOutput();
108
109   if (!State ||
110       !Atmosphere ||
111       !FCS ||
112       !Propulsion ||
113       !Aircraft ||
114       !Translation ||
115       !Rotation ||
116       !Position ||
117       !Auxiliary ||
118       !Output) return(false);
119   else return(true);
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 bool FGModel::Run()
125 {
126   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
127
128   if (exe_ctr == 1) {
129     if (exe_ctr++ >= rate) exe_ctr = 1;
130     return false;
131   } else {
132     if (exe_ctr++ >= rate) exe_ctr = 1;
133     return true;
134   }
135 }
136
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139 void FGModel::Debug(void)
140 {
141     //TODO: Add your source code here
142 }
143