Ejemplo n.º 1
0
        public static void SetColorSingle(string satName, Color color)
        {
            AgStkObjectRoot root;
            AgUiApplication app;

            // initialize variables
            app = System.Runtime.InteropServices.Marshal.GetActiveObject("STK11.Application") as AGI.Ui.Application.AgUiApplication;
            root = (AgStkObjectRoot)app.Personality2;

            // define the sat object
            IAgSatellite sat = (IAgSatellite)root.CurrentScenario.Children[satName];

            // set color               
            sat.Graphics.SetAttributesType(AgEVeGfxAttributes.eAttributesBasic);
            IAgVeGfxAttributesBasic basicAttributes = (IAgVeGfxAttributesBasic)sat.Graphics.Attributes;
            basicAttributes.Line.Width = AgELineWidth.e2;
            basicAttributes.Color = color;
        }
Ejemplo n.º 2
0
        public static void ChangeSatColor(string satPath, int satCatIndex)
        {
            string                  fofo     = CommonData.SatCatItemList[satCatIndex].Fofo;
            IAgSatellite            sat      = CommonData.StkRoot.GetObjectFromPath(satPath) as IAgSatellite;
            IAgVeGfxAttributesBasic graphics = sat.Graphics.Attributes as IAgVeGfxAttributesBasic;
            string                  colorRgb = null;
            string                  colorBgr = null;

            if (fofo == "Blue")
            {
                colorRgb       = "00ffff";
                graphics.Color = System.Drawing.Color.Cyan;
            }
            else if (fofo == "Red")
            {
                colorRgb       = "ff0000";
                graphics.Color = System.Drawing.Color.Red;
            }
            else if (fofo == "Grey")
            {
                colorRgb       = "ffffff";
                graphics.Color = System.Drawing.Color.White;
            }
            else if (fofo == "Green")
            {
                colorRgb       = "00ff00";
                graphics.Color = System.Drawing.Color.Green;
            }
            else
            {
                colorRgb       = "ffff00";
                graphics.Color = System.Drawing.Color.Yellow;
            }
            //colorBGR = colorRGB.Substring(4, 5) +colorRGB.Substring(2,3)+colorRGB.Substring(0,1);
            //int decColor = Convert.ToInt32(colorBGR, 16);
        }
Ejemplo n.º 3
0
        public List <Waypoint> RasterSearchWaypointGenerator(
            string areaTargetPath, string heading, double speed, double altitude, double turnRadius,
            SwathWidthType swathType, double swathParameter)
        {
            List <Waypoint> waypoints = new List <Waypoint>();

            IAgStkObject areaTarget = root.GetObjectFromPath(areaTargetPath);

            IAgAreaTarget areaTargetObj      = (IAgAreaTarget)areaTarget;
            bool          areaTargetElActive = areaTarget.AccessConstraints.IsConstraintActive(AgEAccessConstraints.eCstrElevationAngle);
            double        restoreAngle       = 0;

            if (!areaTargetElActive)
            {
                IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.AddConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle;
                root.UnitPreferences["Angle"].SetCurrentUnit("deg");
                elevationMin.Angle = 90;
            }
            else
            {
                IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle;
                root.UnitPreferences["Angle"].SetCurrentUnit("deg");
                restoreAngle       = (double)elevationMin.Angle;
                elevationMin.Angle = 90;
            }

            double minLat = 90;
            double maxLat = -90;
            double minLon = 180;
            double maxLon = -180;

            root.UnitPreferences["Angle"].SetCurrentUnit("deg");
            switch (areaTargetObj.AreaType)
            {
            case AgEAreaType.eEllipse:
                IAgDataProviderGroup boundingProvider = areaTarget.DataProviders["Bounding Rectangle"] as IAgDataProviderGroup;
                IAgDataPrvFixed      dpElements       = boundingProvider.Group["Corner Points"] as IAgDataPrvFixed;
                IAgDrResult          atDataPrvResult  = dpElements.Exec();

                Array atLats = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lat").GetValues();
                Array atLons = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lon").GetValues();
                foreach (object item in atLats)
                {
                    if ((double)item > maxLat)
                    {
                        maxLat = (double)item;
                    }
                    if ((double)item < minLat)
                    {
                        minLat = (double)item;
                    }
                }
                foreach (object item in atLons)
                {
                    if ((double)item > maxLon)
                    {
                        maxLon = (double)item;
                    }
                    if ((double)item < minLon)
                    {
                        minLon = (double)item;
                    }
                }
                break;

            case AgEAreaType.ePattern:
                IAgAreaTypePatternCollection boundary = areaTargetObj.AreaTypeData as IAgAreaTypePatternCollection;

                foreach (IAgAreaTypePattern item in boundary)
                {
                    if ((double)item.Lat > maxLat)
                    {
                        maxLat = (double)item.Lat;
                    }
                    if ((double)item.Lat < minLat)
                    {
                        minLat = (double)item.Lat;
                    }

                    if ((double)item.Lon > maxLon)
                    {
                        maxLon = (double)item.Lon;
                    }
                    if ((double)item.Lon < minLon)
                    {
                        minLon = (double)item.Lon;
                    }
                }

                break;

            default:
                break;
            }
            double deltaLat = maxLat - minLat;
            double deltaLon = maxLon - minLon;

            IAgExecCmdResult cmdResult;

            switch (heading)
            {
            case "NorthSouth":
                cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " +
                                                minLat + " " + minLon + " " + minLat + " " + maxLon);
                break;

            case "EastWest":
                cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " +
                                                minLat + " " + minLon + " " + maxLat + " " + minLon);
                break;

            default:
                cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " +
                                                minLat + " " + minLon + " " + maxLat + " " + minLon);
                break;
            }



            double regionWidth = double.Parse(cmdResult[0]);

            int numPasses = DetermineNumPasses(swathType, swathParameter, altitude, regionWidth, null);

            if (numPasses < 1)
            {
                MessageBox.Show("No Passes.  Try Adjusting Swath Width Parameters");
                return(waypoints);
            }
            root.BeginUpdate();

            string           gvName        = uniqueName("gridTester", AgESTKObjectType.eGroundVehicle);
            IAgGroundVehicle groundVehicle = root.CurrentScenario.Children.New(AgESTKObjectType.eGroundVehicle, gvName) as IAgGroundVehicle;

            groundVehicle.Graphics.SetAttributesType(AgEVeGfxAttributes.eAttributesBasic);
            IAgVeGfxAttributesBasic gvGfx = groundVehicle.Graphics.Attributes as IAgVeGfxAttributesBasic;

            gvGfx.Inherit   = false;
            gvGfx.IsVisible = false;

            IAgVePropagatorGreatArc route = groundVehicle.Route as IAgVePropagatorGreatArc;

            //route.ArcGranularity = 51.333;
            route.SetAltitudeRefType(AgEVeAltitudeRef.eWayPtAltRefWGS84);
            route.Method = AgEVeWayPtCompMethod.eDetermineTimeAccFromVel;

            Waypoint waypoint1 = new Waypoint();
            Waypoint waypoint2 = new Waypoint();
            bool     headEast  = true;


            double loopMin;
            double loopMax;
            double gridAngleStep;

            switch (heading)
            {
            case "NorthSouth":
                loopMin       = minLon;
                loopMax       = maxLon;
                gridAngleStep = (maxLon - minLon) / numPasses;
                break;

            case "EastWest":
                loopMin       = minLat;
                loopMax       = maxLat;
                gridAngleStep = (maxLat - minLat) / numPasses;
                break;

            default:
                loopMin       = minLat;
                loopMax       = maxLat;
                gridAngleStep = .95 * (maxLat - minLat) / numPasses;
                break;
            }

            for (double eval = loopMin; eval <= loopMax; eval += gridAngleStep)
            {
                route.Waypoints.RemoveAll();
                IAgVeWaypointsElement thisWaypoint1;
                IAgVeWaypointsElement thisWaypoint2;
                switch (heading)
                {
                case "NorthSouth":
                    thisWaypoint1           = route.Waypoints.Add();
                    thisWaypoint1.Latitude  = minLat - gridAngleStep;
                    thisWaypoint1.Longitude = eval;
                    thisWaypoint1.Altitude  = 0;

                    thisWaypoint2           = route.Waypoints.Add();
                    thisWaypoint2.Latitude  = maxLat + gridAngleStep;
                    thisWaypoint2.Longitude = eval;
                    thisWaypoint2.Altitude  = 0;
                    break;

                case "EastWest":
                default:
                    thisWaypoint1           = route.Waypoints.Add();
                    thisWaypoint1.Latitude  = eval;
                    thisWaypoint1.Longitude = minLon - gridAngleStep;
                    thisWaypoint1.Altitude  = 0;

                    thisWaypoint2           = route.Waypoints.Add();
                    thisWaypoint2.Latitude  = eval;
                    thisWaypoint2.Longitude = maxLon + gridAngleStep;
                    thisWaypoint2.Altitude  = 0;
                    break;
                }
                route.Propagate();

                IAgStkAccess access = areaTarget.GetAccessToObject((IAgStkObject)groundVehicle);
                access.ComputeAccess();

                IAgDataPrvInterval dpAccess = access.DataProviders["Access Data"] as IAgDataPrvInterval;
                IAgScenario        scen     = root.CurrentScenario as IAgScenario;
                IAgDrResult        result   = dpAccess.Exec(scen.StartTime, scen.StopTime);


                if (result.DataSets.Count > 0)
                {
                    Array startTimes = result.DataSets.GetDataSetByName("Start Time").GetValues();
                    Array stopTimes  = result.DataSets.GetDataSetByName("Stop Time").GetValues();

                    string startTime = (string)startTimes.GetValue(0);
                    string stopTime  = (string)stopTimes.GetValue(stopTimes.GetLength(0) - 1);

                    IAgDataProviderGroup dpLLA         = ((IAgStkObject)groundVehicle).DataProviders["LLA State"] as IAgDataProviderGroup;
                    IAgDataPrvTimeVar    dpElements    = dpLLA.Group["Fixed"] as IAgDataPrvTimeVar;
                    IAgDrResult          DataPrvResult = dpElements.ExecSingle(startTime);

                    Array Lats = DataPrvResult.DataSets.GetDataSetByName("Lat").GetValues();
                    Array Lons = DataPrvResult.DataSets.GetDataSetByName("Lon").GetValues();

                    waypoint1                 = new Waypoint();
                    waypoint1.Latitude        = (double)Lats.GetValue(0);
                    waypoint1.Longitude       = (double)Lons.GetValue(0);
                    waypoint1.Altitude        = altitude;
                    waypoint1.SurfaceAltitude = 0;
                    waypoint1.Speed           = speed;
                    waypoint1.TurnRadius      = turnRadius;


                    IAgDataProviderGroup dpLLA1         = ((IAgStkObject)groundVehicle).DataProviders["LLA State"] as IAgDataProviderGroup;
                    IAgDataPrvTimeVar    dpElements1    = dpLLA1.Group["Fixed"] as IAgDataPrvTimeVar;
                    IAgDrResult          DataPrvResult1 = dpElements1.ExecSingle(stopTime);

                    Array Lats1 = DataPrvResult1.DataSets.GetDataSetByName("Lat").GetValues();
                    Array Lons1 = DataPrvResult1.DataSets.GetDataSetByName("Lon").GetValues();

                    waypoint2                 = new Waypoint();
                    waypoint2.Latitude        = (double)Lats1.GetValue(0);
                    waypoint2.Longitude       = (double)Lons1.GetValue(0);
                    waypoint2.Altitude        = altitude;
                    waypoint2.SurfaceAltitude = 0;
                    waypoint2.Speed           = speed;
                    waypoint2.TurnRadius      = turnRadius;


                    if (headEast)
                    {
                        waypoints.Add(waypoint1);
                        waypoints.Add(waypoint2);
                    }
                    else
                    {
                        waypoints.Add(waypoint2);
                        waypoints.Add(waypoint1);
                    }
                    headEast = !headEast;
                }
                access.RemoveAccess();
            }

            ((IAgStkObject)groundVehicle).Unload();

            if (!areaTargetElActive)
            {
                areaTarget.AccessConstraints.RemoveConstraint(AgEAccessConstraints.eCstrElevationAngle);
            }
            else
            {
                IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle;
                root.UnitPreferences["Angle"].SetCurrentUnit("deg");
                elevationMin.Angle = restoreAngle;
            }

            root.EndUpdate();
            root.UnitPreferences.ResetUnits();
            return(waypoints);
        }
Ejemplo n.º 4
0
        public static void CreateScenarioFromTle(ref AgStkObjectRoot root, double duration, ref InitialState initState, TLE currentTle)
        {
            root.NewScenario(currentTle.GetSatNumber() + "_Reentry");
            DateTime startDate = currentTle.GetTleEpoch();
            DateTime stopDate  = startDate.AddDays(duration);

            IAgScenario scenario = root.CurrentScenario as IAgScenario;

            // Set scenario start and stop times
            scenario.SetTimePeriod(startDate.ToString("dd MMM yyyy hh:mm:ss.fff"), stopDate.ToString("dd MMM yyyy hh:mm:ss.fff"));

            // remove the terrain option
            root.ExecuteCommand("Terrain * TerrainServer UseTerrainForAnalysis No");

            // create the SGP4 object from the TLE
            IAgSatellite decayingSat = (IAgSatellite)root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, currentTle.GetSatNumber());

            decayingSat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4);
            IAgVePropagatorSGP4 sgp4 = decayingSat.Propagator as IAgVePropagatorSGP4;

            sgp4.CommonTasks.AddSegsFromFile(currentTle.GetSatNumber(), currentTle.GetFilePath());
            IAgVeGfxAttributesBasic att = decayingSat.Graphics.Attributes as IAgVeGfxAttributesBasic;

            att.Color = Color.Yellow;

            // Configure time period
            sgp4.EphemerisInterval.SetExplicitInterval(scenario.StartTime, scenario.StopTime);
            sgp4.Step = 60.0;
            // Propagate
            sgp4.Propagate();

            // change the 3D model
            try
            {
                root.ExecuteCommand("VO */Satellite/" + currentTle.GetSatNumber() + " Model File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Models\\Misc\\explosion.mdl\"");
            }
            catch (Exception)
            {
            }

            //// get the initial state from the TLE
            initState.Epoch = scenario.StartTime;

            IAgDataPrvTimeVar      dpPos       = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Position//ICRF");
            IAgDrResult            resultPos   = dpPos.Exec(scenario.StartTime, scenario.StartTime, 60.0);
            IAgDrDataSetCollection datasetsPos = resultPos.DataSets;

            if (resultPos.DataSets.Count > 0)
            {
                initState.CartesianPosX = datasetsPos[1].GetValues().GetValue(0).ToString();
                initState.CartesianPosY = datasetsPos[2].GetValues().GetValue(0).ToString();
                initState.CartesianPosZ = datasetsPos[3].GetValues().GetValue(0).ToString();
            }

            IAgDataPrvTimeVar      dpVel       = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Velocity//ICRF");
            IAgDrResult            resultVel   = dpVel.Exec(scenario.StartTime, scenario.StartTime, 60.0);
            IAgDrDataSetCollection datasetsVel = resultVel.DataSets;

            if (resultVel.DataSets.Count > 0)
            {
                initState.CartesianVelX = datasetsVel[1].GetValues().GetValue(0).ToString();
                initState.CartesianVelY = datasetsVel[2].GetValues().GetValue(0).ToString();
                initState.CartesianVelZ = datasetsVel[3].GetValues().GetValue(0).ToString();
            }

            // configure the 2D graphics
            root.ExecuteCommand("Graphics * BackgroundImage Show Off");
            root.ExecuteCommand("MapDetails * LatLon Lon On 15");
            root.ExecuteCommand("MapDetails * Map RWDB2_Islands State On Color green");
            root.ExecuteCommand("MapDetails * Map RWDB2_International_Borders State On ");
            root.ExecuteCommand("MapDetails * Map RWDB2_Lakes State On");

            try
            {
                root.ExecuteCommand("VO * Globe Show On File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Globes\\Earth\\WhiteOnBlue.glb\"");
            }
            catch (Exception)
            {
            }

            // configure the 3D graphics
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Coastlines ShowDetail On");
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Islands ShowDetail On DetailColor green");
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Lakes ShowDetail On DetailColor lightblue");


            //dynamic uiApp = System.Runtime.InteropServices.Marshal.GetActiveObject("STK11.Application");
            //try
            //{
            //    foreach (dynamic window in uiApp.Windows)
            //    {
            //        string windowCaption = (string)window.Caption;
            //        if (windowCaption.Contains("2D"))
            //        {
            //            window.DockStyle = 3;
            //        }
            //    }

            //}
            //catch (Exception ex)
            //{
            //    string error = ex.Message;
            //}
        }
Ejemplo n.º 5
0
        public static TLE CreateScenarioFromSatcat(ref AgStkObjectRoot root, double duration, ref InitialState initState, string satId)
        {
            root.NewScenario(satId + "_Reentry");
            //DateTime startDate = currentTle.GetTleEpoch();
            //DateTime stopDate = startDate.AddDays(duration);

            IAgScenario scenario = root.CurrentScenario as IAgScenario;

            // remove the terrain option
            root.ExecuteCommand("Terrain * TerrainServer UseTerrainForAnalysis No");

            // import the satellite from the catalog
            root.ExecuteCommand("ImportFromDB * Satellite AGIServer Propagate On TimePeriod UseScenarioInterval SSCNumber " + satId + " \"");

            // get the satellite start time
            IAgStkObject        satObj      = root.CurrentScenario.Children[0];
            IAgSatellite        decayingSat = satObj as IAgSatellite;
            IAgVePropagatorSGP4 sgp4        = decayingSat.Propagator as IAgVePropagatorSGP4;
            //IAgCrdnEventSmartEpoch startEpoch = sgp4.EphemerisInterval.GetStartEpoch();
            dynamic startEpoch = sgp4.Segments[0].SwitchTime;
            // Set scenario start and stop times
            DateTime startDate = STK.GetDateTimeFromStkTimeFormat(Convert.ToString(startEpoch));
            DateTime stopDate  = startDate.AddDays(duration);

            scenario.SetTimePeriod(startDate.ToString("dd MMM yyyy hh:mm:ss.fff"), stopDate.ToString("dd MMM yyyy hh:mm:ss.fff"));

            // get the TLE data back from STK
            TLE tle = new TLE(startDate, sgp4.Segments[0].SSCNum, Convert.ToString(sgp4.Segments[0].Inclination),
                              Convert.ToString(sgp4.Segments[0].Eccentricity), Convert.ToString(sgp4.Segments[0].RevNumber),
                              Convert.ToString(sgp4.Segments[0].MeanMotion));

            IAgVeGfxAttributesBasic att = decayingSat.Graphics.Attributes as IAgVeGfxAttributesBasic;

            att.Color = Color.Yellow;

            // Configure time period
            sgp4.EphemerisInterval.SetExplicitInterval(scenario.StartTime, scenario.StopTime);
            sgp4.Step = 60.0;

            // change the 3D model
            try
            {
                root.ExecuteCommand("VO */Satellite/" + root.CurrentScenario.Children[0].InstanceName + " Model File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Models\\Misc\\explosion.mdl\"");
            }
            catch (Exception)
            {
            }

            //// get the initial state from the TLE
            initState.Epoch = scenario.StartTime;

            IAgDataPrvTimeVar      dpPos       = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Position//ICRF");
            IAgDrResult            resultPos   = dpPos.Exec(scenario.StartTime, scenario.StartTime, 60.0);
            IAgDrDataSetCollection datasetsPos = resultPos.DataSets;

            if (resultPos.DataSets.Count > 0)
            {
                initState.CartesianPosX = datasetsPos[1].GetValues().GetValue(0).ToString();
                initState.CartesianPosY = datasetsPos[2].GetValues().GetValue(0).ToString();
                initState.CartesianPosZ = datasetsPos[3].GetValues().GetValue(0).ToString();
            }

            IAgDataPrvTimeVar      dpVel       = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Velocity//ICRF");
            IAgDrResult            resultVel   = dpVel.Exec(scenario.StartTime, scenario.StartTime, 60.0);
            IAgDrDataSetCollection datasetsVel = resultVel.DataSets;

            if (resultVel.DataSets.Count > 0)
            {
                initState.CartesianVelX = datasetsVel[1].GetValues().GetValue(0).ToString();
                initState.CartesianVelY = datasetsVel[2].GetValues().GetValue(0).ToString();
                initState.CartesianVelZ = datasetsVel[3].GetValues().GetValue(0).ToString();
            }

            // configure the 2D graphics
            root.ExecuteCommand("Graphics * BackgroundImage Show Off");
            root.ExecuteCommand("MapDetails * LatLon Lon On 15");
            root.ExecuteCommand("MapDetails * Map RWDB2_Islands State On Color green");
            root.ExecuteCommand("MapDetails * Map RWDB2_International_Borders State On ");
            root.ExecuteCommand("MapDetails * Map RWDB2_Lakes State On");

            try
            {
                root.ExecuteCommand("VO * Globe Show On File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Globes\\Earth\\WhiteOnBlue.glb\"");
            }
            catch (Exception)
            {
            }

            // configure the 3D graphics
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Coastlines ShowDetail On");
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Islands ShowDetail On DetailColor green");
            root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Lakes ShowDetail On DetailColor lightblue");


            return(tle);
        }