public static void CreateCoverage(AgStkObjectRoot root, TLE tle) { try { IAgCoverageDefinition covDef = root.CurrentScenario.Children.New(AgESTKObjectType.eCoverageDefinition, "CovDef") as IAgCoverageDefinition; // add all target objects as assets IAgStkObjectElementCollection allChildrenOfType = root.CurrentScenario.Children.GetElements(AgESTKObjectType.eTarget); IAgCvAssetListCollection assetCollection = covDef.AssetList; foreach (IAgStkObject o in allChildrenOfType) { string satAssetName = "Target/" + o.InstanceName; assetCollection.Add(satAssetName); } covDef.Graphics.Static.IsPointsVisible = false; // set the grid resolution IAgCvGrid cvGrid = covDef.Grid; cvGrid.ResolutionType = AgECvResolution.eResolutionLatLon; IAgCvResolutionLatLon res = cvGrid.Resolution as IAgCvResolutionLatLon; res.LatLon = 1; // set the points altitude IAgCvPointDefinition pointDefinition = covDef.PointDefinition; pointDefinition.AltitudeMethod = AgECvAltitudeMethod.eAltitude; pointDefinition.Altitude = 20.0; covDef.PointDefinition.GroundAltitudeMethod = AgECvGroundAltitudeMethod.eCvGroundAltitudeMethodUsePointAlt; // set the start/stop time DateTime startDate = tle.GetTleEpoch(); DateTime stopDate = startDate.AddMilliseconds(1); covDef.Interval.AnalysisInterval.SetExplicitInterval(startDate.ToString("dd MMM yyyy hh:mm:ss.fff"), stopDate.ToString("dd MMM yyyy hh:mm:ss.fff")); covDef.Advanced.AutoRecompute = false; covDef.ComputeAccesses(); IAgFigureOfMerit fom = root.CurrentScenario.Children["CovDef"].Children.New(AgESTKObjectType.eFigureOfMerit, "Likelihood") as IAgFigureOfMerit; fom.SetDefinitionType(AgEFmDefinitionType.eFmNAssetCoverage); fom.Graphics.Animation.IsVisible = false; fom.Graphics.Static.FillTranslucency = 20; IAgFmGfxContours contours = fom.Graphics.Static.Contours; contours.IsVisible = true; contours.ContourType = AgEFmGfxContourType.eSmoothFill; contours.ColorMethod = AgEFmGfxColorMethod.eExplicit; contours.LevelAttributes.RemoveAll(); IAgFmGfxLevelAttributesElement level1 = contours.LevelAttributes.AddLevel(1); IAgFmGfxLevelAttributesElement level2 = contours.LevelAttributes.AddLevel(2); IAgFmGfxLevelAttributesElement level3 = contours.LevelAttributes.AddLevel(3); IAgFmGfxLevelAttributesElement level4 = contours.LevelAttributes.AddLevel(4); level1.Color = Color.Khaki; level2.Color = Color.Gold; level3.Color = Color.Orange; level4.Color = Color.Red; root.ExecuteCommand("Graphics */CoverageDefinition/CovDef/FigureOfMerit/Likelihood SmoothFillParameters NNSampleMode Smooth"); } catch (Exception) { throw new Exception(); } }
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; //} }