Пример #1
0
        private bool Allocate()
        {
            bool result = true;

            models = new Model[(int)eModels.eNumStandardModels];

            // First build the inertial model since some other models are relying on
            // the inertial model and the ground callback to build themselves.
            // Note that this does not affect the order in which the models will be
            // executed later.
            models[(int)eModels.eInertial] = new Inertial(this);

            // 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
            // storage array for the list of models.
            models[(int)eModels.ePropagate]       = new Propagate(this);
            models[(int)eModels.eInput]           = new Input(this);
            models[(int)eModels.eAtmosphere]      = new StandardAtmosphere(this);
            models[(int)eModels.eWinds]           = new Winds(this);
            models[(int)eModels.eSystems]         = new FlightControlSystem(this);
            models[(int)eModels.eMassBalance]     = new MassBalance(this);
            models[(int)eModels.eAuxiliary]       = new Auxiliary(this);
            models[(int)eModels.ePropulsion]      = new Propulsion(this);
            models[(int)eModels.eAerodynamics]    = new Aerodynamics(this);
            models[(int)eModels.eGroundReactions] = new GroundReactions(this);
            //PENDING new JSBSIM models[(int)eModels.eExternalReactions] = new ExternalReactions(this);
            //PENDING new JSBSIM models[(int)eModels.eBuoyantForces] = new BuoyantForces(this);
            models[(int)eModels.eAircraft]      = new Aircraft(this);
            models[(int)eModels.eAccelerations] = new Accelerations(this);
            models[(int)eModels.eOutput]        = new Output(this);

            // Assign the Model shortcuts for internal executive use only.
            propagate       = (Propagate)models[(int)eModels.ePropagate];
            inertial        = (Inertial)models[(int)eModels.eInertial];
            atmosphere      = (Atmosphere)models[(int)eModels.eAtmosphere];
            winds           = (Winds)models[(int)eModels.eWinds];
            FCS             = (FlightControlSystem)models[(int)eModels.eSystems];
            massBalance     = (MassBalance)models[(int)eModels.eMassBalance];
            auxiliary       = (Auxiliary)models[(int)eModels.eAuxiliary];
            propulsion      = (Propulsion)models[(int)eModels.ePropulsion];
            aerodynamics    = (Aerodynamics)models[(int)eModels.eAerodynamics];
            groundReactions = (GroundReactions)models[(int)eModels.eGroundReactions];
            //PENDING new JSBSIM  externalReactions = (ExternalReactions)models[(int)eModels.eExternalReactions];
            //PENDING new JSBSIM buoyantForces = (BuoyantForces)models[(int)eModels.eBuoyantForces];
            aircraft      = (Aircraft)models[(int)eModels.eAircraft];
            accelerations = (Accelerations)models[(int)eModels.eAccelerations];
            //PENDING new JSBSIM output = (Output)models[(int)eModels.eOutput];

            // Initialize planet (environment) constants
            LoadPlanetConstants();

            // Initialize models
            for (int i = 0; i < models.Length; i++)
            {
                // The Input/Output models must not be initialized prior to IC loading
                if (i == (int)eModels.eInput || i == (int)eModels.eOutput)
                {
                    continue;
                }

                //PENDING new JSBSIM LoadInputs(i);
                if (models[i] != null)
                {
                    models[i].InitModel();
                }
            }

            ic = new InitialCondition(this);
            ic.Bind(instance);

            modelLoaded = false;

            return(result);

            //---------------------- old code pending
#if DELETEME
            bool result = true;
            massBalance = new MassBalance(this);
            //output = new Output(this);
            input = new Input(this);
            //TODO groundCallback = new DefaultGroundCallback();
            state = new State(this); // This must be done here, as the State
            // class needs valid pointers to the above model classes


            // Initialize models so they can communicate with each other

            if (!atmosphere.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Atmosphere model init failed");
                }
                error += 1;
            }
            if (!FCS.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("FCS model init failed");
                }
                error += 2;
            }
            if (!propulsion.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propulsion model init failed");
                }
                error += 4;
            }
            if (!massBalance.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("MassBalance model init failed");
                }
                error += 8;
            }
            if (!aerodynamics.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aerodynamics model init failed");
                }
                error += 16;
            }
            if (!inertial.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Inertial model init failed");
                }
                error += 32;
            }
            if (!groundReactions.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Ground Reactions model init failed");
                }
                error += 64;
            }
            if (!aircraft.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aircraft model init failed");
                }
                error += 128;
            }
            if (!propagate.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propagate model init failed");
                }
                error += 256;
            }
            if (!auxiliary.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Auxiliary model init failed");
                }
                error += 512;
            }
            if (!input.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Intput model init failed");
                }
                error += 1024;
            }

            if (error > 0)
            {
                result = false;
            }

            ic = new InitialCondition(this);

            // Schedule a model. The second arg (the integer) is the pass number. For
            // instance, the atmosphere model gets executed every fifth pass it is called
            // by the executive. Everything else here gets executed each pass.
            // IC and Trim objects are NOT scheduled.

            Schedule(input, 1);
            Schedule(atmosphere, 1);
            Schedule(FCS, 1);
            Schedule(propulsion, 1);
            Schedule(massBalance, 1);
            Schedule(aerodynamics, 1);
            Schedule(inertial, 1);
            Schedule(groundReactions, 1);
            Schedule(aircraft, 1);
            Schedule(propagate, 1);
            Schedule(auxiliary, 1);
            //Schedule(output, 1);

            modelLoaded = false;
            return(result);
#endif
        }