private void computeAccess_Click(object sender, EventArgs e) { string accessToName = cbAccessTo.GetItemText(cbAccessTo.SelectedItem); string accessFromName = cbAccessTo.GetItemText(cbAccessFrom.SelectedItem); IAgStkObject toObj = CommonData.StkRoot.GetObjectFromPath(accessToName); IAgStkObject fromObj = CommonData.StkRoot.GetObjectFromPath(accessFromName); IAgStkAccess access = toObj.GetAccessToObject(fromObj); access.ComputeAccess(); // Get access results from data provider IAgIntervalCollection accessIntervals = access.ComputedAccessIntervalTimes; IAgDataPrvTimeVar accessDataProvider = access.DataProviders.GetDataPrvTimeVarFromPath("AER Data//Default"); Array dataProviderElements = new object[] { "Time", "Azimuth", "Elevation", "Range" }; dataGridViewAccess.Rows.Clear(); dataGridViewAccess.Rows.Add(); for (int i = 0; i < accessIntervals.Count; i++) { object startTime = null, stopTime = null; accessIntervals.GetInterval(i, out startTime, out stopTime); IAgDrResult dataProviderResult = accessDataProvider.ExecElements(startTime, stopTime, 1, ref dataProviderElements); Array timeValues = dataProviderResult.DataSets[0].GetValues(); Array azimuthValues = dataProviderResult.DataSets[1].GetValues(); Array elevationValues = dataProviderResult.DataSets[2].GetValues(); Array rangeValues = dataProviderResult.DataSets[3].GetValues(); for (int j = 0; j < timeValues.Length; j++) { DataGridViewRow row = (DataGridViewRow)dataGridViewAccess.Rows[0].Clone(); row.Cells[0].Value = timeValues.GetValue(j).ToString(); row.Cells[1].Value = azimuthValues.GetValue(j).ToString(); row.Cells[2].Value = elevationValues.GetValue(j).ToString(); row.Cells[3].Value = rangeValues.GetValue(j).ToString(); dataGridViewAccess.Rows.Add(row); } } ////Get built in Calucation object from Analysis Workbench //// Could put into another dataGridView //var parameterSets = access.Vgt.ParameterSets["From-To-AER(Body)"]; ////Get magnitude vector //IAgCrdnCalcScalar magnitude = ((IAgCrdn)parameterSets).EmbeddedComponents["From-To-AER(Body).Cartesian.Magnitude"] as IAgCrdnCalcScalar; ////Get times of the minimum value for each access interval //AgCrdnEventArrayExtrema minTimes = ((IAgCrdn)parameterSets).EmbeddedComponents["From-To-AER(Body).Cartesian.Magnitude.TimesOfLocalMin"] as AgCrdnEventArrayExtrema; //Array timeArray = minTimes.FindTimes().Times; //for (int i = 0; i < timeArray.Length; i++) //{ // double result = magnitude.Evaluate(timeArray.GetValue(i)).Value; //} }
private void RadioButtonOpen_CheckedChanged(object sender, EventArgs e) { if (radioButtonOpen.Checked.Equals(true)) { try { if (comboBoxSatellite.SelectedItem == null) { throw new Exception("No satellite selected."); } if (comboBoxFacility.SelectedItem == null) { throw new Exception("No facility selected."); } // Disable combo boxes for now comboBoxSatellite.Enabled = false; comboBoxFacility.Enabled = false; // Disable any previous events initialized try { m_root.OnAnimUpdate -= new IAgStkObjectRootEvents_OnAnimUpdateEventHandler(Root_OnAnimUpdate); } catch { } // Compute access IAgStkObject accessObject = m_root.GetObjectFromPath("Facility/" + comboBoxFacility.SelectedItem.ToString()); m_access = accessObject.GetAccess("Satellite/" + comboBoxSatellite.SelectedItem.ToString()); m_access.ComputeAccess(); // Get AER data provider m_accessProviderIntervals = m_access.DataProviders.GetDataPrvTimeVarFromPath("AER Data/Default"); // Add the event handler we will need m_root.OnAnimUpdate += new IAgStkObjectRootEvents_OnAnimUpdateEventHandler(Root_OnAnimUpdate); } catch (Exception exception) { radioButtonOpen.Checked = false; MessageBox.Show(exception.Message, "Error"); } } }
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); }