Exemple #1
0
        /// <summary>
        /// Run one route script with an IFR model aircraft
        /// </summary>
        /// <param name="route">A complete route script to run</param>
        /// <returns>True if OK</returns>
        private bool RunSimFromScript(CmdList route)
        {
            string routeName = route.Descriptor.Start_IcaoID + "_" + route.Descriptor.End_IcaoID;

            var virtAcft = new IFRvAcft(route); // use the Jet model
            var kmlFile  = new KmlFile( );
            var kmlLine  = new line {
                Name      = routeName,
                LineColor = LineStyle.LT_Blue
            };

            do
            {
                virtAcft.StepModel(m_stepLen_sec); // step the model at 2 sec until finished

                kmlLine.Add(new point {
                    Position    = new LatLon(virtAcft.LatLon),
                    Altitude_ft = virtAcft.Alt_ft,
                    Heading     = (int)virtAcft.TRK
                });
            } while (!virtAcft.Out);
            // setup Comm
            kmlFile.Lines.Add(kmlLine);
            kmlFile.WriteKML(routeName + ".kml");
            return(Valid);
        }
        private List <line> loadFixtures()
        {
            TextAsset   fixturesAsset = Resources.Load <TextAsset>("ChearRulerCs_fixtures");
            var         json          = JArray.Parse(fixturesAsset.text);
            List <line> fixtures      = new List <line>();

            foreach (var line in json)
            {
                line fixtureLine = new line();

                foreach (var coordinates in line)
                {
                    fixtureLine.Add(coordinates[0].Value <double>(), coordinates[1].Value <double>());
                }
                fixtures.Add(fixtureLine);
            }

            return(fixtures);
        }
        private List <line> loadFixtures()
        {
            string fixturePath = Application.dataPath + "/Mapbox/Core/cheap-ruler-cs/Tests/Editor/lines.json";
            string fixtureAsText;

            using (TextReader tw = new StreamReader(fixturePath, Encoding.UTF8)) { fixtureAsText = tw.ReadToEnd(); }

            var         json     = JArray.Parse(fixtureAsText);
            List <line> fixtures = new List <line>();

            foreach (var line in json)
            {
                line fixtureLine = new line();

                foreach (var coordinates in line)
                {
                    fixtureLine.Add(coordinates[0].Value <double>(), coordinates[1].Value <double>());
                }
                fixtures.Add(fixtureLine);
            }

            return(fixtures);
        }
Exemple #4
0
        /// <summary>
        /// Simulate the Model file given and write a kmlfile of the path
        /// same folder as the model file with the extension .kml
        /// </summary>
        /// <param name="vfrModelFile">The VFR Model File</param>
        /// <returns>True if successfull (else see Error content)</returns>
        public bool RunSimulation(string vfrModelFile, string fallBackRwy)
        {
            Error = "";
            Logger.Instance.Log($"VFRSimulation-SetupSimulation for: {vfrModelFile}");
            if (!Valid)
            {
                return(false);
            }

            var route = CmdReader.ReadCmdScript(vfrModelFile);

            if (!route.IsValid)
            {
                Valid = false;
                Error = "File not found or invalid content";
                Logger.Instance.Log(Error);
                return(false);
            }

            if (route.Descriptor.FlightType == CmdA.FlightT.Runway)
            {
                string rwID = route.Descriptor.RunwayPreference; // preferred one
                if (string.IsNullOrEmpty(rwID))
                {
                    rwID = fallBackRwy;
                }
                var rwy = RWYDB.GetSubtable(rwID); // search RWY
                if (rwy.Count < 1)
                {
                    Valid = false;
                    Error = $"Runway: {route.Descriptor.Start_IcaoID} not found in Runway database, cannot continue";
                    Logger.Instance.Log(Error);
                    return(false);
                }
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(rwy.ElementAt(0).Value.start_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromRunway(1, rwy.ElementAt(0).Value); // Complete the script
            }
            else if (route.Descriptor.FlightType == CmdA.FlightT.Airway)
            {
                return(false); // not supported - use the one above...
            }
            else if (route.Descriptor.FlightType == CmdA.FlightT.MsgRelative)
            {
                string rwID = route.Descriptor.RunwayPreference; // preferred one
                if (string.IsNullOrEmpty(rwID))
                {
                    rwID = fallBackRwy;
                }
                var rwy = RWYDB.GetSubtable(rwID); // search RWY
                if (rwy.Count < 1)
                {
                    Valid = false;
                    Error = $"Runway: {route.Descriptor.Start_IcaoID} not found in Runway database, cannot continue";
                    Logger.Instance.Log(Error);
                    return(false);
                }
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(rwy.ElementAt(0).Value.start_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromMsgRelative(1, rwy.ElementAt(0).Value, "SIM"); // Complete the script
            }

            else if (route.Descriptor.FlightType == CmdA.FlightT.MsgAbsolute)
            {
                // actually my position
                m_userAcft = new UserAcft( );
                m_userAcft.NewPos(route.Descriptor.StartPos_latlon);
                // the simulated aircraft
                route.Descriptor.InitFromMsgAbsolute(1, "SIM"); // Complete the script
            }

            var virtAcft = new VFRvAcft(route); // use the GA model
            var kmlFile  = new KmlFile( );
            var kmlLine  = new line {
                Name      = Path.GetFileNameWithoutExtension(vfrModelFile),
                LineColor = LineStyle.LT_Yellow
            };

            do
            {
                virtAcft.StepModel(m_stepLen_sec); // step the model at 2 sec until finished

                kmlLine.Add(new point {
                    Position    = new LatLon(virtAcft.LatLon),
                    Altitude_ft = virtAcft.Alt_ft,
                    Heading     = (int)virtAcft.TRK
                });
            } while (!virtAcft.Out);
            // setup Comm
            kmlFile.Lines.Add(kmlLine);
            kmlFile.WriteKML(vfrModelFile + ".kml");
            return(Valid);
        }