]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBsim/FGModel.cpp
source tree reorganization prior to flightgear 0.7
[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 /*******************************************************************************
54 ************************************ CODE **************************************
55 *******************************************************************************/
56
57 FGModel::FGModel(FGFDMExec* fdmex)
58 {
59   FDMExec     = fdmex;
60   NextModel   = 0L;
61   
62   State       = 0;
63   Atmosphere  = 0;
64   FCS         = 0;
65   Aircraft    = 0;
66   Translation = 0;
67   Rotation    = 0;
68   Position    = 0;
69   Auxiliary   = 0;
70   Output      = 0;
71
72   exe_ctr     = 1;
73 }
74
75
76 FGModel::~FGModel()
77 {
78 }
79
80
81 bool FGModel::InitModel(void)
82 {
83   State       = FDMExec->GetState();
84   Atmosphere  = FDMExec->GetAtmosphere();
85   FCS         = FDMExec->GetFCS();
86   Aircraft    = FDMExec->GetAircraft();
87   Translation = FDMExec->GetTranslation();
88   Rotation    = FDMExec->GetRotation();
89   Position    = FDMExec->GetPosition();
90   Auxiliary   = FDMExec->GetAuxiliary();
91   Output      = FDMExec->GetOutput();
92
93   if (!State ||
94       !Atmosphere ||
95       !FCS ||
96       !Aircraft ||
97       !Translation ||
98       !Rotation ||
99       !Position ||
100       !Auxiliary ||
101       !Output) return(false);
102   else return(true);
103 }
104
105
106 bool FGModel::Run()
107 {
108   if (exe_ctr == 1) {
109     if (exe_ctr++ >= rate) exe_ctr = 1;
110     return false;
111   } else {
112     if (exe_ctr++ >= rate) exe_ctr = 1;
113     return true;
114   }
115 }
116
117