//Constraint functions public static void SetCnstMinMax(IAgAccessCnstrMinMax constraint, double min, double max) { constraint.EnableMin = true; constraint.Min = min; constraint.EnableMax = true; constraint.Max = max; }
private void createSensorButton_Click(object sender, EventArgs e) { AgFacility facility = null; if (CommonData.StkRoot.CurrentScenario.Children.Contains(AgESTKObjectType.eFacility, facilityName.Text)) { facility = (AgFacility)CommonData.StkRoot.GetObjectFromPath("Facility/" + facilityName.Text); } else { facility = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eFacility, facilityName.Text) as AgFacility; } //Add child object (sensor) IAgSensor sensor = null; if (facility.Children.Contains(AgESTKObjectType.eSensor, "MySensor")) { sensor = (IAgSensor)CommonData.StkRoot.GetObjectFromPath("*/Facility/" + facilityName.Text + "/Sensor/MySensor"); } else { sensor = facility.Children.New(AgESTKObjectType.eSensor, "MySensor") as IAgSensor; } // Set Sensor type and shape double InnerConeHalfAngle = 50; double OuterConeHalfAngle = 90; double MinimumClockAngle = 0; double MaximumClockAngle = 90; sensor.SetPatternType(AgESnPattern.eSnComplexConic); sensor.CommonTasks.SetPatternComplexConic(InnerConeHalfAngle, OuterConeHalfAngle, MinimumClockAngle, MaximumClockAngle); //Add range constraint to sensor double rangeConstraintValue = 40; IAgAccessCnstrMinMax rangeConstraint = null; if (!sensor.AccessConstraints.IsConstraintActive(AgEAccessConstraints.eCstrRange)) { rangeConstraint = sensor.AccessConstraints.AddConstraint(AgEAccessConstraints.eCstrRange) as IAgAccessCnstrMinMax; } else { rangeConstraint = sensor.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrRange) as IAgAccessCnstrMinMax; } rangeConstraint.EnableMax = true; rangeConstraint.Max = rangeConstraintValue; }
private void Generate_Click(object sender, EventArgs e) { if (ExistingVolumes.SelectedIndex != -1 && ExistingVolumes.Items.Count > 0 && LocationList.SelectedIndex != -1) { IAgFacility place; IAgStkObject placeObj; placeObj = CreatorFunctions.GetCreateFacility(CommonData.LocationList[CommonData.LocationIndex].Name); place = placeObj as IAgFacility; place.Position.AssignGeodetic(Double.Parse(CommonData.LocationList[CommonData.LocationIndex].Latitude), Double.Parse(CommonData.LocationList[CommonData.LocationIndex].Longitude), 0); place.AltRef = AgEAltRefType.eWGS84; //Create complex conic sensor IAgStkObject sensorObj = CreatorFunctions.GetCreateSensor(placeObj, CommonData.VolumeList[CommonData.TvSelectedIndex].Name + "_" + CommonData.LocationList[CommonData.LocationIndex].Name); IAgSensor sensor = sensorObj as IAgSensor; sensor.SetPatternType(AgESnPattern.eSnComplexConic); IAgSnComplexConicPattern pattern = sensor.Pattern as IAgSnComplexConicPattern; pattern.OuterConeHalfAngle = 180.0; sensor.VO.PercentTranslucency = 70.0; IAgAccessConstraintCollection constraints = sensor.AccessConstraints; IAgAccessCnstrMinMax elConstraint; IAgAccessCnstrMinMax rangeConstraint; IAgAccessCnstrMinMax altConstraint; //Add elevation angle constraint if (constraints.IsConstraintActive(AgEAccessConstraints.eCstrElevationAngle)) { elConstraint = constraints.GetActiveConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrMinMax; } else { elConstraint = constraints.AddConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrMinMax; } elConstraint.EnableMin = true; elConstraint.Min = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MinEl); elConstraint.EnableMax = true; elConstraint.Max = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MaxEl); //Add range constraint if (constraints.IsConstraintActive(AgEAccessConstraints.eCstrRange)) { rangeConstraint = constraints.GetActiveConstraint(AgEAccessConstraints.eCstrRange) as IAgAccessCnstrMinMax; } else { rangeConstraint = constraints.AddConstraint(AgEAccessConstraints.eCstrRange) as IAgAccessCnstrMinMax; } rangeConstraint.EnableMin = true; rangeConstraint.Min = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MinRange); rangeConstraint.EnableMax = true; rangeConstraint.Max = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MaxRange); //Add altitude constraint if (constraints.IsConstraintActive(AgEAccessConstraints.eCstrAltitude)) { altConstraint = constraints.GetActiveConstraint(AgEAccessConstraints.eCstrAltitude) as IAgAccessCnstrMinMax; } else { altConstraint = constraints.AddConstraint(AgEAccessConstraints.eCstrAltitude) as IAgAccessCnstrMinMax; } altConstraint.EnableMin = true; altConstraint.Min = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MinAlt); altConstraint.EnableMax = true; altConstraint.Max = Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MaxAlt); //Add Azimuth Constraint IAgAccessCnstrMinMax azConstraint = CreatorFunctions.GetAzCnst(constraints); CreatorFunctions.SetCnstMinMax(azConstraint, Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MinAz), Double.Parse(CommonData.VolumeList[CommonData.TvSelectedIndex].MaxAz)); try { sensor.Graphics.Projection.UseConstraints = true; sensor.Graphics.Projection.EnableConstraint("ElevationAngle"); sensor.Graphics.Projection.EnableConstraint("AzimuthAngle"); CommonData.StkRoot.ExecuteCommand("Animate * Refresh"); } catch (Exception) { } CreatorFunctions.ChangeObjectColor(sensorObj.Path, (CustomUserInterface.ColorOptions)Enum.Parse(typeof(CustomUserInterface.ColorOptions), ColorSelection.Text)); } }