public static IAgStkObject AttachFacilityOptical(IAgStkObject parent, string radarName, OpticalParams rParams)
        {
            IAgStkObject sensorObj = CreatorFunctions.GetCreateSensor(parent, radarName);
            IAgSensor    sensor    = sensorObj as IAgSensor;

            sensor.Graphics.IsObjectGraphicsVisible = false;
            IAgSnSimpleConicPattern pattern = sensor.Pattern as IAgSnSimpleConicPattern;

            pattern.ConeAngle = Double.Parse(rParams.HalfAngle);

            IAgAccessConstraintCollection constraints = sensor.AccessConstraints;
            IAgAccessCnstrMinMax          elConstraint;
            IAgAccessCnstrMinMax          azConstraint;
            IAgAccessCnstrMinMax          rangeConstraint;
            IAgAccessCnstrMinMax          sunElConstraint;
            IAgAccessCnstrAngle           lunExConstraint;

            elConstraint = CreatorFunctions.GetElCnst(constraints);
            CreatorFunctions.SetCnstMinMax(elConstraint, Double.Parse(rParams.MinEl), Double.Parse(rParams.MaxEl));
            azConstraint = CreatorFunctions.GetAzCnst(constraints);
            CreatorFunctions.SetCnstMinMax(azConstraint, Double.Parse(rParams.MinAz), Double.Parse(rParams.MaxAz));

            sunElConstraint = CreatorFunctions.GetSunElCnst(constraints);
            CreatorFunctions.SetCnstMinMax(sunElConstraint, -90, Double.Parse(rParams.SunElAngle));

            rangeConstraint = CreatorFunctions.GetRangeCnst(constraints);
            CreatorFunctions.SetCnstMinMax(rangeConstraint, Double.Parse(rParams.MinRange), Double.Parse(rParams.MaxRange));

            lunExConstraint       = CreatorFunctions.GetLunExCnst(constraints);
            lunExConstraint.Angle = rParams.LunarExAngle;

            SetOpticalGraphics(sensor);

            return(sensorObj);
        }
 private void ToObjectType_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ToObjectType.SelectedIndex != -1)
     {
         CommonData.ToObjectNames.Clear();
         CreatorFunctions.PopulateObjectListByClass(ToObjectList, ToObjectType.Text);
         //if (ToObjectType.SelectedIndex == 0)
         //{
         //    PopulateObjectList(ToObjectList, "Satellite");
         //}
         //else if (ToObjectType.SelectedIndex == 1)
         //{
         //    PopulateObjectList(ToObjectList, "Aircraft");
         //}
         //else if (ToObjectType.SelectedIndex == 2)
         //{
         //    PopulateObjectList(ToObjectList, "Missile");
         //}
         //else if (ToObjectType.SelectedIndex == 3)
         //{
         //    PopulateObjectList(ToObjectList, "LaunchVehicle");
         //}
         //else if (ToObjectType.SelectedIndex == 4)
         //{
         //    PopulateObjectList(ToObjectList, "Constellation");
         //}
     }
 }
 private void FromObjectType_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (FromObjectType.SelectedIndex != -1)
     {
         CommonData.FromObjectNames.Clear();
         CreatorFunctions.PopulateObjectListByClass(FromObjectList, FromObjectType.Text);
         //if (FromObjectType.SelectedIndex == 0)
         //{
         //    PopulateObjectList(FromObjectList, "Facility");
         //}
         //else if (FromObjectType.SelectedIndex == 1)
         //{
         //    PopulateObjectList(FromObjectList, "Place");
         //}
         //else if (FromObjectType.SelectedIndex == 2)
         //{
         //    PopulateObjectList(FromObjectList, "Target");
         //}
         //else if (FromObjectType.SelectedIndex == 3)
         //{
         //    PopulateObjectList(FromObjectList, "Sensor");
         //}
         //else if (FromObjectType.SelectedIndex == 4)
         //{
         //    PopulateObjectList(FromObjectList, "Constellation");
         //}
     }
 }
        public static IAgStkObject AttachFacilityRadar(IAgStkObject parent, string radarName, RadarParams rParams)
        {
            IAgStkObject sensorObj = CreatorFunctions.GetCreateSensor(parent, radarName);
            IAgSensor    sensor    = sensorObj as IAgSensor;

            sensor.Graphics.IsObjectGraphicsVisible = false;
            IAgSnSimpleConicPattern pattern = sensor.Pattern as IAgSnSimpleConicPattern;

            pattern.ConeAngle = Double.Parse(rParams.HalfAngle);
            IAgSnPtFixed pointing = sensor.Pointing as IAgSnPtFixed;

            pointing.Orientation.AssignAzEl(Double.Parse(rParams.Az), Double.Parse(rParams.El), AGI.STKUtil.AgEAzElAboutBoresight.eAzElAboutBoresightRotate);

            IAgAccessConstraintCollection constraints = sensor.AccessConstraints;
            IAgAccessCnstrMinMax          elConstraint;
            IAgAccessCnstrMinMax          azConstraint;
            IAgAccessCnstrMinMax          rangeConstraint;
            IAgAccessCnstrAngle           solarExConstraint;

            elConstraint = CreatorFunctions.GetElCnst(constraints);
            CreatorFunctions.SetCnstMinMax(elConstraint, Double.Parse(rParams.MinEl), Double.Parse(rParams.MaxEl));
            azConstraint = CreatorFunctions.GetAzCnst(constraints);
            CreatorFunctions.SetCnstMinMax(azConstraint, Double.Parse(rParams.MinAz), Double.Parse(rParams.MaxAz));
            rangeConstraint = CreatorFunctions.GetRangeCnst(constraints);
            CreatorFunctions.SetCnstMinMax(rangeConstraint, Double.Parse(rParams.MinRange), Double.Parse(rParams.MaxRange));
            solarExConstraint       = CreatorFunctions.GetSunExCnst(constraints);
            solarExConstraint.Angle = rParams.SolarExAngle;

            SetRadarGraphics(sensor);

            return(sensorObj);
        }
 private void PopulatePlaneReferences()
 {
     CreatorFunctions.PopulateCbByClass(PlaneSatellite, "Satellite");
     if (PlaneSatellite.Items.Count > 0)
     {
         PlaneSatellite.SelectedIndex = 0;
     }
 }
 private void Generate_Click(object sender, EventArgs e)
 {
     if (CadanceList.FocusedItem != null && CadanceList.FocusedItem.Index != -1)
     {
         IAgStkObject     facObj;
         IAgFacility      fac;
         IAgConstellation optAssets = null;
         IAgConstellation radAssets = null;
         IAgStkObject     constObj;
         IAgStkObject     sensor;
         if (_cadances[CommonData.CadenceSelected].NumOptical > 0)
         {
             constObj  = CreatorFunctions.GetCreateConstellation(_cadances[CommonData.CadenceSelected].Name + "_Opt");
             optAssets = constObj as IAgConstellation;
             optAssets.Objects.RemoveAll();
         }
         if (_cadances[CommonData.CadenceSelected].NumRadars > 0)
         {
             constObj  = CreatorFunctions.GetCreateConstellation(_cadances[CommonData.CadenceSelected].Name + "_Rad");
             radAssets = constObj as IAgConstellation;
             radAssets.Objects.RemoveAll();
         }
         foreach (var item in _cadances[CommonData.CadenceSelected].FacilityList)
         {
             facObj = CreatorFunctions.GetCreateFacility(item.Name);
             fac    = facObj as IAgFacility;
             fac.Position.AssignGeodetic(Double.Parse(item.Latitude), Double.Parse(item.Longitude), Double.Parse(item.Altitude));
             fac.AltRef = AgEAltRefType.eWGS84;
             CreatorFunctions.ChangeObjectColor(facObj.Path, (CustomUserInterface.ColorOptions)Enum.Parse(typeof(CustomUserInterface.ColorOptions), _cadances[CommonData.CadenceSelected].CadenceColor));
             if (item.IsOpt)
             {
                 foreach (FCSensor fsensor in item.Sensors)
                 {
                     sensor = FacilityCreatorFunctions.AttachFacilityOptical(facObj, item.Name + "_" + fsensor.SensorName, fsensor.OParams);
                     if (!optAssets.Objects.Contains(sensor.Path))
                     {
                         optAssets.Objects.AddObject(sensor);
                     }
                 }
             }
             else
             {
                 foreach (FCSensor fsensor in item.Sensors)
                 {
                     sensor = FacilityCreatorFunctions.AttachFacilityRadar(facObj, item.Name + "_" + fsensor.SensorName, fsensor.RParams);
                     if (!optAssets.Objects.Contains(sensor.Path))
                     {
                         radAssets.Objects.AddObject(sensor);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
        public SatelliteEpochUpdatePlugin()
        {
            InitializeComponent();
            _satelliteUpdateList = new List <string>();
            ASTGRunCheck.Checked = false;
            _cScenario           = CommonData.StkRoot.CurrentScenario as IAgScenario;

            dtp_start.Value = Convert.ToDateTime(_cScenario.StartTime.ToString());
            dtp_end.Value   = Convert.ToDateTime(_cScenario.StopTime.ToString());

            CreatorFunctions.PopulateObjectListByClass(SatelliteList, "Satellite");
        }
 private void PopulateCrossingObjects(string classType)
 {
     CreatorFunctions.PopulateObjectListByClass(CrossingObjectsList, classType);
     //Remove plane reference satellite from list if required
     foreach (ListViewItem item in CrossingObjectsList.Items)
     {
         if (item.Text == PlaneSatellite.Text)
         {
             CrossingObjectsList.Items.Remove(item);
         }
     }
 }
Ejemplo n.º 9
0
 private void PopulateTargets()
 {
     TargetsList.Items.Clear();
     CommonData.SelectedTargets.Clear();
     if (TargetType.SelectedIndex == 0)
     {
         CreatorFunctions.PopulateObjectListByClass(TargetsList, "Satellite");
     }
     else if (TargetType.SelectedIndex == 1)
     {
         CreatorFunctions.PopulateObjectListByClass(TargetsList, "Missile");
     }
     else if (TargetType.SelectedIndex == 2)
     {
         CreatorFunctions.PopulateObjectListByClass(TargetsList, "Aircraft");
     }
 }
Ejemplo n.º 10
0
        private void Add_Click(object sender, EventArgs e)
        {
            SubObjectList.SmallImageList = imageList1;
            SubObject newSub = new SubObject();

            newSub.Type = "Unknown";
            if (CommonData.CurrentEvents[CommonData.EventSelectedIndex].SubObjects.Count != 0)
            {
                newSub.Name = "SubObject" + CommonData.CurrentEvents[CommonData.EventSelectedIndex].SubObjects.Count.ToString();
            }
            else
            {
                newSub.Name = "SubObject";
            }
            //Assign default values to class
            newSub.Latitude  = CommonData.CurrentEvents[CommonData.EventSelectedIndex].Latitude;
            newSub.Longitude = CommonData.CurrentEvents[CommonData.EventSelectedIndex].Longitude;
            newSub.ZoomLevel = "1000";
            CommonData.CurrentEvents[CommonData.EventSelectedIndex].SubObjects.Add(newSub);
            int index = GroundEventFunctions.GetSubObjectImageIndex(newSub);

            var listItem = new ListViewItem();

            listItem.ImageIndex       = index;
            listItem.SubItems[0].Text = newSub.Name;
            SubObjectList.Items.Add(listItem);
            SubObjectList.FocusedItem = listItem;
            CommonData.SubObjectIndex = SubObjectList.Items.Count - 1;

            SubObjectType.Enabled  = true;
            ZoomLevel.Enabled      = true;
            LatitudeValue.Enabled  = true;
            LongitudeValue.Enabled = true;
            NameValue.Enabled      = true;

            //Assign GUI values
            SubObjectType.SelectedIndex = 0;
            ZoomLevel.SelectedIndex     = 1;
            LongitudeValue.Text         = CommonData.CurrentEvents[CommonData.EventSelectedIndex].Longitude.ToString();
            LatitudeValue.Text          = CommonData.CurrentEvents[CommonData.EventSelectedIndex].Latitude.ToString();
            NameValue.Text = newSub.Name;

            //Create sub-object and change color to match higher level object
            GroundEventFunctions.CreateSubObject(CommonData.CurrentEvents[CommonData.EventSelectedIndex], newSub);
            CreatorFunctions.ChangeObjectColor("Place/" + CommonData.CurrentEvents[CommonData.EventSelectedIndex].Id + "-" + newSub.Name, (CustomUserInterface.ColorOptions)Enum.Parse(typeof(CustomUserInterface.ColorOptions), CommonData.CurrentEvents[CommonData.EventSelectedIndex].ColorOption));
        }
Ejemplo n.º 11
0
 private void PopulateObservers()
 {
     ObserversList.Items.Clear();
     CommonData.SelectedObservers.Clear();
     if (ObserverType.SelectedIndex == 0)
     {
         CreatorFunctions.PopulateObjectListByClass(ObserversList, "Satellite");
     }
     else if (ObserverType.SelectedIndex == 1)
     {
         CreatorFunctions.PopulateObjectListByClass(ObserversList, "Facility");
     }
     else if (ObserverType.SelectedIndex == 2)
     {
         CreatorFunctions.PopulateObjectListByClass(ObserversList, "Sensor");
     }
 }
Ejemplo n.º 12
0
        public ATManager()
        {
            InitializeComponent();
            AdditionType.Items.Add("Single");
            AdditionType.Items.Add("Group");
            AdditionType.SelectedIndex = 0;
            atNames = CreatorFunctions.PopulateListByClass("AreaTarget");
            string simpleName;

            foreach (var item in atNames)
            {
                simpleName = item.Split('/').Last();
                ATList.Items.Add(simpleName);
                SingleATName.Items.Add(simpleName);
            }
            if (atNames.Count > 0)
            {
                SingleATName.SelectedIndex = 0;
            }
        }
 private void Generate_Click(object sender, EventArgs e)
 {
     if (CadanceList.FocusedItem != null && CadanceList.FocusedItem.Index != -1)
     {
         IAgStkObject     facObj;
         IAgFacility      fac;
         IAgConstellation optAssets = null;
         IAgConstellation radAssets = null;
         IAgStkObject     constObj;
         IAgStkObject     sensor;
         if (_cadances[CommonData.CadenceSelected].NumOptical > 0)
         {
             constObj  = CreatorFunctions.GetCreateConstellation(_cadances[CommonData.CadenceSelected].Name + "_Opt");
             optAssets = constObj as IAgConstellation;
             optAssets.Objects.RemoveAll();
         }
         if (_cadances[CommonData.CadenceSelected].NumRadars > 0)
         {
             constObj  = CreatorFunctions.GetCreateConstellation(_cadances[CommonData.CadenceSelected].Name + "_Rad");
             radAssets = constObj as IAgConstellation;
             radAssets.Objects.RemoveAll();
         }
         foreach (var item in _cadances[CommonData.CadenceSelected].FacilityList)
         {
             facObj = CreatorFunctions.GetCreateFacility(item.Name);
             fac    = facObj as IAgFacility;
             fac.Position.AssignGeodetic(Double.Parse(item.Latitude), Double.Parse(item.Longitude), Double.Parse(item.Altitude));
             fac.AltRef = AgEAltRefType.eWGS84;
             if (item.IsOpt)
             {
                 sensor = CreatorFunctions.AttachFacilityOptical(facObj, item.Name + "_Opt", item.OParams);
                 optAssets.Objects.AddObject(sensor);
             }
             else
             {
                 sensor = CreatorFunctions.AttachFacilityRadar(facObj, item.Name + "_Radar", item.RParams);
                 radAssets.Objects.AddObject(sensor);
             }
         }
     }
 }
Ejemplo n.º 14
0
        public SensorBoresightUtility()
        {
            InitializeComponent();
            sensorPaths = CreatorFunctions.PopulateListByClass("Sensor");
            IAgSensor sensor;

            foreach (var item in sensorPaths)
            {
                sensor = CommonData.StkRoot.GetObjectFromPath(item) as IAgSensor;
                if (sensor.PatternType == AgESnPattern.eSnSimpleConic || sensor.PatternType == AgESnPattern.eSnRectangular || sensor.PatternType == AgESnPattern.eSnEOIR)
                {
                    SelectedSensor.Items.Add(((IAgStkObject)sensor).InstanceName);
                }
            }
            if (SelectedSensor.Items.Count > 0)
            {
                SelectedSensor.SelectedIndex = 0;
            }

            if (CommonData.SavedViewList != null)
            {
                foreach (var item in CommonData.SavedViewList)
                {
                    if (item.ViewType == "3D")
                    {
                        SelectedView.Items.Add(item.Name);
                    }
                }
                if (SelectedView.Items.Count > 0)
                {
                    SelectedView.SelectedIndex = 0;
                }
            }

            UpVector.Items.Add("X");
            UpVector.Items.Add("-X");
            UpVector.Items.Add("Y");
            UpVector.Items.Add("-Y");
            UpVector.SelectedIndex = 0;
        }
Ejemplo n.º 15
0
        private void Update_Click(object sender, EventArgs e)
        {
            int    errorCount = 0;
            string errorStr   = "Could not update epoch for the following objects: \n";

            foreach (var item in _satelliteUpdateList)
            {
                IAgSatellite sat = CommonData.StkRoot.GetObjectFromPath(item) as IAgSatellite;
                try
                {
                    CreatorFunctions.ChangeSatelliteInterval(sat, dtp_start.Value.ToString("dd MMM yyyy HH:mm:ss.000"), dtp_end.Value.ToString("dd MMM yyyy HH:mm:ss.000"), ASTGRunCheck.Checked);
                }
                catch (Exception)
                {
                    errorCount++;
                    errorStr += item + "\n";
                }
            }
            if (errorCount > 0)
            {
                MessageBox.Show(errorStr);
            }
        }
Ejemplo n.º 16
0
        private void DisplaySelected_Click(object sender, EventArgs e)
        {
            if (listView1.FocusedItem != null && listView1.FocusedItem.Index != -1)
            {
                if (CommonData.HasManeuvers)
                {
                    IAgStkObject passiveSatObj = CreatorFunctions.GetCreateSatellite("PassiveCheck");
                    IAgSatellite passiveSat    = passiveSatObj as IAgSatellite;
                    passiveSat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                    passiveSat.VO.OrbitSystems.RemoveAll();
                    passiveSat.VO.OrbitSystems.Add("Satellite/" + CommonData.TargetName + " VVLH System");
                    passiveSat.SetPropagatorType(AgEVePropagatorType.ePropagatorAstrogator);
                    IAgVADriverMCS passiveDriver = passiveSat.Propagator as IAgVADriverMCS;

                    IAgVAMCSInitialState          intState = passiveDriver.MainSequence[0] as IAgVAMCSInitialState;
                    IAgVAMCSPropagate             prop     = passiveDriver.MainSequence[1] as IAgVAMCSPropagate;
                    IAgVAStoppingConditionElement sc1      = prop.StoppingConditions[0];
                    IAgVAStoppingCondition        sc       = sc1.Properties as IAgVAStoppingCondition;
                    sc.Trip = CommonData.RunList[listView1.FocusedItem.Index].PropTime;

                    AgVAElementCartesian element = intState.Element as AgVAElementCartesian;
                    intState.OrbitEpoch = CommonData.RunList[listView1.FocusedItem.Index].ManeuverTime;
                    element.Vx          = CommonData.RunList[listView1.FocusedItem.Index].Vx;
                    element.Vy          = CommonData.RunList[listView1.FocusedItem.Index].Vy;
                    element.Vz          = CommonData.RunList[listView1.FocusedItem.Index].Vz;
                    element.X           = CommonData.RunList[listView1.FocusedItem.Index].X;
                    element.Y           = CommonData.RunList[listView1.FocusedItem.Index].Y;
                    element.Z           = CommonData.RunList[listView1.FocusedItem.Index].Z;

                    passiveDriver.RunMCS();
                }
                else
                {
                    MessageBox.Show("Actor satellite has no maneuvers. Visualization is simply the Actor's current trjectory");
                }
            }
        }
Ejemplo n.º 17
0
        private void CreateButton_Click(object sender, EventArgs e)
        {
            if (ManualSSR.Checked)
            {
                int fieldCheck = FieldCheck();
                if (fieldCheck == 0)
                {
                    GroundEvent current = new GroundEvent();
                    current.Id        = Regex.Replace(IDText.Text, @"[^0-9a-zA-Z_]+", "");
                    current.Country   = CountryText.Text;
                    current.Latitude  = Latitude.Text;
                    current.Longitude = Longitude.Text;
                    string start = ReadWrite.CheckTimeCell(StartTimeText.Text);
                    if (start == "Unspecified")
                    {
                        current.StartTime    = "Unspecified";
                        current.MilStartTime = "Unspecified";
                    }
                    else
                    {
                        current.MilStartTime = StartTimeText.Text;
                        current.StartTime    = StartTimeText.Text;
                    }

                    string stop = ReadWrite.CheckTimeCell(StopTimeText.Text);
                    if (stop == "Unspecified")
                    {
                        current.StopTime    = "Unspecified";
                        current.MilStopTime = "Unspecified";
                    }
                    else
                    {
                        current.MilStopTime = StopTimeText.Text;
                        current.StopTime    = StopTimeText.Text;
                    }
                    current.Description = DesciptionText.Text;
                    current.SsrType     = TypeSelect.Text;

                    if (!String.IsNullOrEmpty(_contactEvent.Poc))
                    {
                        current.Poc = _contactEvent.Poc;
                    }
                    if (!String.IsNullOrEmpty(_contactEvent.PocPhone))
                    {
                        current.PocPhone = _contactEvent.PocPhone;
                    }
                    if (!String.IsNullOrEmpty(_contactEvent.PocEmail))
                    {
                        current.PocEmail = _contactEvent.PocEmail;
                    }

                    current.ColorOption = ColorSelection.Text;
                    CommonData.CurrentEvents.Add(current);

                    GroundEventFunctions.CreateGroundEvent(current);
                    CreatorFunctions.ChangeObjectColor("Place/" + current.Id, (CustomUserInterface.ColorOptions)Enum.Parse(typeof(CustomUserInterface.ColorOptions), ColorSelection.Text));

                    ReadWrite.WriteEventFile(CommonData.EventFileStr);
                }
                CommonData.NewSsrCreated = true;
            }
            else if (SSRFromFile.Checked)
            {
                int importOption = 0;
                if (ImportAll.Checked)
                {
                    importOption = 1;
                }
                ReadWrite.ImportEventSheet(FileText.Text, importOption, SheetColor.Text);
                CommonData.NewSsrCreated = true;
            }
            this.Close();
        }
        private void GenerateSingle_Click(object sender, EventArgs e)
        {
            Tuple <int, string> check = FieldCheck();

            if (check.Item1 == 0)
            {
                if (ManualInput.Checked)
                {
                    try
                    {
                        IAgStkObject facObj = CreatorFunctions.GetCreateFacility(FacilityName.Text);
                        IAgFacility  fac    = facObj as IAgFacility;
                        IAgStkObject sensor = null;
                        fac.Position.AssignGeodetic(Double.Parse(Latitude.Text), Double.Parse(Longitude.Text), Double.Parse(Altitude.Text));
                        fac.AltRef = AgEAltRefType.eWGS84;
                        if (SensorType.SelectedIndex == 1)
                        {
                            OpticalParams oParams = new OpticalParams();
                            oParams.MinEl        = "0";
                            oParams.MaxEl        = "90";
                            oParams.MinRange     = "4800";
                            oParams.MaxRange     = "90000";
                            oParams.LunarExAngle = "10";
                            oParams.SunElAngle   = "-12";
                            oParams.HalfAngle    = "70";
                            oParams.MinAz        = "0";
                            oParams.MaxAz        = "360";
                            sensor = FacilityCreatorFunctions.AttachFacilityOptical(facObj, FacilityName.Text + "_Opt", oParams);
                        }
                        else if (SensorType.SelectedIndex == 2)
                        {
                            RadarParams rParams = new RadarParams();
                            rParams.MinEl        = "0";
                            rParams.MaxEl        = "90";
                            rParams.MinRange     = "1600";
                            rParams.MaxRange     = "40000";
                            rParams.SolarExAngle = "10";
                            rParams.HalfAngle    = "85";
                            rParams.MinAz        = "0";
                            rParams.MaxAz        = "360";
                            sensor = FacilityCreatorFunctions.AttachFacilityRadar(facObj, FacilityName.Text + "_Radar", rParams);
                        }
                        else
                        {
                        }
                        if (ConstType.SelectedIndex != 0)
                        {
                            IAgStkObject     constObj = null;
                            IAgConstellation constel  = null;
                            if (ConstType.SelectedIndex == 1)
                            {
                                constObj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                                constel  = constObj as IAgConstellation;
                            }
                            else if (ConstType.SelectedIndex == 2)
                            {
                                constObj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                                constel  = constObj as IAgConstellation;
                            }
                            if (SensorType.SelectedIndex == 0)
                            {
                                constel.Objects.AddObject(facObj);
                            }
                            else if (SensorType.SelectedIndex == 1 || SensorType.SelectedIndex == 2)
                            {
                                constel.Objects.AddObject(sensor);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not create facility");
                    }
                }
                else if (ImportFromFile.Checked)
                {
                    if (!String.IsNullOrEmpty(FilenameText.Text))
                    {
                        SensorCadance cad = new SensorCadance();
                        cad.FacilityList = new List <FcFacility>();
                        cad.CadenceColor = "Custom";
                        cad.Name         = "NewCadence";
                        IAgStkObject          facObj;
                        IAgFacility           fac;
                        IAgStkObject          sensor;
                        List <GroundLocation> locations = null;
                        if (FilenameText.Text.Contains(".json"))
                        {
                            try
                            {
                                List <SensorCadance> tempCadences = ReadWrite.ReadCadences(FilenameText.Text);
                                if (SaveData.Checked)
                                {
                                    foreach (var item in tempCadences)
                                    {
                                        CommonData.Cadences.Add(item);
                                    }
                                    ReadWrite.WriteCadenceDatabase();
                                    PopulateCadanceList();
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Json Error");
                            }
                        }
                        else
                        {
                            locations = ReadWrite.ReadFacilityFile(FilenameText.Text);
                            foreach (GroundLocation loc in locations)
                            {
                                FcFacility fcFac = new FcFacility();
                                fcFac.Name      = loc.LocationName;
                                fcFac.Latitude  = loc.Latitude.ToString();
                                fcFac.Longitude = loc.Longitude.ToString();
                                fcFac.Altitude  = loc.Altitude.ToString();
                                facObj          = CreatorFunctions.GetCreateFacility(loc.LocationName);
                                fac             = facObj as IAgFacility;
                                sensor          = null;
                                fac.Position.AssignGeodetic(loc.Latitude, loc.Longitude, loc.Altitude);
                                fac.AltRef = AgEAltRefType.eWGS84;

                                FCSensor fcSensor = new FCSensor();
                                fcSensor.SensorName = loc.LocationName + "_Opt";
                                if (SensorType.SelectedIndex == 0 || SensorType.SelectedIndex == 1)
                                {
                                    OpticalParams oParams = new OpticalParams();
                                    cad.Type             = "Opt";
                                    cad.NumOptical       = locations.Count;
                                    cad.NumRadars        = 0;
                                    fcFac.Type           = "Optical";
                                    fcFac.IsOpt          = true;
                                    oParams.MinEl        = "0";
                                    oParams.MaxEl        = "90";
                                    oParams.MinRange     = "4800";
                                    oParams.MaxRange     = "90000";
                                    oParams.LunarExAngle = "10";
                                    oParams.SunElAngle   = "-12";
                                    oParams.HalfAngle    = "70";
                                    oParams.MinAz        = "0";
                                    oParams.MaxAz        = "360";
                                    oParams.Az           = "0";
                                    oParams.El           = "90";
                                    fcSensor.OParams     = oParams;
                                    if (SensorType.SelectedIndex == 1)
                                    {
                                        sensor = FacilityCreatorFunctions.AttachFacilityOptical(facObj, loc.LocationName + "_Opt", oParams);
                                    }
                                }
                                else if (SensorType.SelectedIndex == 2)
                                {
                                    RadarParams rParams = new RadarParams();
                                    fcSensor.SensorName  = loc.LocationName + "_Rad";
                                    cad.Type             = "Rad";
                                    cad.NumOptical       = 0;
                                    cad.NumRadars        = locations.Count;
                                    fcFac.Type           = "Radar";
                                    fcFac.IsOpt          = false;
                                    rParams.MinEl        = "0";
                                    rParams.MaxEl        = "90";
                                    rParams.MinRange     = "1600";
                                    rParams.MaxRange     = "40000";
                                    rParams.SolarExAngle = "10";
                                    rParams.HalfAngle    = "85";
                                    rParams.MinAz        = "0";
                                    rParams.MaxAz        = "360";
                                    rParams.Az           = "0";
                                    rParams.El           = "90";
                                    fcSensor.RParams     = rParams;
                                    sensor = FacilityCreatorFunctions.AttachFacilityRadar(facObj, loc.LocationName + "_Radar", rParams);
                                }
                                else
                                {
                                }
                                fcFac.Sensors.Add(fcSensor);
                                cad.FacilityList.Add(fcFac);
                                if (ConstType.SelectedIndex != 0)
                                {
                                    IAgStkObject     constObj = null;
                                    IAgConstellation constel  = null;
                                    if (ConstType.SelectedIndex == 1)
                                    {
                                        constObj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                                        constel  = constObj as IAgConstellation;
                                    }
                                    else if (ConstType.SelectedIndex == 2)
                                    {
                                        constObj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                                        constel  = constObj as IAgConstellation;
                                    }
                                    if (SensorType.SelectedIndex == 0)
                                    {
                                        constel.Objects.AddObject(facObj);
                                    }
                                    else if (SensorType.SelectedIndex == 1 || SensorType.SelectedIndex == 2)
                                    {
                                        constel.Objects.AddObject(sensor);
                                    }
                                }
                            }
                            if (SaveData.Checked)
                            {
                                CommonData.Cadences.Add(cad);
                                ReadWrite.WriteCadenceDatabase();
                                PopulateCadanceList();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please choose a valid input file");
                    }
                }
            }
            else
            {
                MessageBox.Show(check.Item2);
            }
        }
        private void Generate_Click(object sender, EventArgs e)
        {
            string accessName = "";

            if (AccessName.Text != null && AccessName.Text != "")
            {
                accessName = AccessName.Text;
            }
            else
            {
                accessName = "NewAccess";
            }
            IAgConstellation fromConst = null;
            IAgConstellation toConst   = null;
            IAgChain         accessChain;
            string           cmd = null;

            //Add Objects to ToConst
            if (CommonData.ToObjectNames.Count > 0)
            {
                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + accessName + "_ToAccessConst");

                string objPath;
                if (ToObjectType.Text != "Constellation")
                {
                    if (result[0] == "0")
                    {
                        toConst = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, accessName + "_ToAccessConst");
                    }
                    else
                    {
                        toConst = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + accessName + "_ToAccessConst");
                        toConst.Objects.RemoveAll();
                    }
                    foreach (string item in CommonData.ToObjectNames)
                    {
                        toConst.Objects.Add(item);
                    }
                }
                else
                {
                    string constName = CommonData.ToObjectNames[0].Split('/').Last();
                    toConst = CreatorFunctions.GetCreateConstellation(constName) as IAgConstellation;
                }
            }
            //Add objects to FromConst
            if (CommonData.FromObjectNames.Count > 0)
            {
                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + accessName + "_FromAccessConst");
                string           objPath;
                if (FromObjectType.Text != "Constellation")
                {
                    if (result[0] == "0")
                    {
                        fromConst = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, accessName + "_FromAccessConst");
                    }
                    else
                    {
                        fromConst = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + accessName + "_FromAccessConst");
                        fromConst.Objects.RemoveAll();
                    }
                    foreach (string item in CommonData.FromObjectNames)
                    {
                        fromConst.Objects.Add(item);
                    }
                }
                else
                {
                    string constName = CommonData.FromObjectNames[0].Split('/').Last();
                    fromConst = CreatorFunctions.GetCreateConstellation(constName) as IAgConstellation;
                }
            }

            //Create Chain
            if (CommonData.ToObjectNames.Count > 0 && CommonData.FromObjectNames.Count > 0)
            {
                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Chain/" + accessName);
                if (result[0] == "0")
                {
                    accessChain = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eChain, accessName) as IAgChain;
                }
                else
                {
                    accessChain = (IAgChain)CommonData.StkRoot.GetObjectFromPath("Chain/" + accessName);
                    accessChain.AutoRecompute = false;
                    accessChain.ClearAccess();
                    accessChain.Objects.RemoveAll();
                }
                //Compute chain
                accessChain.Objects.AddObject((IAgStkObject)fromConst);
                accessChain.Objects.AddObject((IAgStkObject)toConst);
                accessChain.ComputeAccess();
                //Timeline
                IAgStkObject accessObject = accessChain as IAgStkObject;
                cmd = "";
                if (DataType.SelectedIndex == 0)
                {
                    cmd = "Timeline * TimeComponent Remove ContentView \"Scenario Availability\" \"Chain/" + accessName + " CompleteChainAccessIntervals Interval List\"";
                    try
                    {
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        cmd = "Timeline * TimeComponent Add ContentView \"Scenario Availability\" DisplayName \"" + accessName + "\"" + " \"Chain/" + accessName + " CompleteChainAccessIntervals Interval List\"";
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not generate timeline components");
                    }
                }
                else if (DataType.SelectedIndex == 1)
                {
                    string timeComponentName = null;
                    IAgCrdnEventIntervalCollection collection;
                    collection = accessObject.Vgt.EventIntervalCollections[1];
                    Array labels = collection.Labels;
                    IAgCrdnIntervalsVectorResult vecResult = collection.FindIntervalCollection();
                    int vecCount = vecResult.IntervalCollections.Count;
                    for (int i = 0; i < vecCount; i++)
                    {
                        timeComponentName = labels.GetValue(i).ToString();
                        cmd = "Timeline * TimeComponent Remove ContentView \"Scenario Availability\" \"Chain/" + accessName + " StrandAccessIntervals." + timeComponentName + " Interval List\"";
                        try
                        {
                            CommonData.StkRoot.ExecuteCommand(cmd);
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            cmd = "Timeline * TimeComponent Add ContentView \"Scenario Availability\" DisplayName \"" + timeComponentName + "\" \"Chain/" + accessName + " StrandAccessIntervals." + timeComponentName + " Interval List\"";
                            CommonData.StkRoot.ExecuteCommand(cmd);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                CommonData.StkRoot.ExecuteCommand("Timeline * Refresh");

                //Data Ouput
                if (ShowReport.Checked)
                {
                    cmd = "";
                    if (DataType.SelectedIndex == 0)
                    {
                        cmd = "ReportCreate */Chain/" + accessName + " Style \"Complete Chain Access\" Type Display";
                    }
                    else if (DataType.SelectedIndex == 1)
                    {
                        cmd = "ReportCreate */Chain/" + accessName + " Style \"Individual Strand Access\" Type Display";
                    }
                    try
                    {
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not show report");
                    }
                }
                if (GenerateGraph.Checked)
                {
                    cmd = "";
                    if (DataType.SelectedIndex == 0)
                    {
                        cmd = "GraphCreate */Chain/" + accessName + " Style \"Complete Chain Access\" Type Display";
                    }
                    else if (DataType.SelectedIndex == 1)
                    {
                        cmd = "GraphCreate */Chain/" + accessName + " Style \"Individual Strand Access\" Type Display";
                    }
                    try
                    {
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not show report");
                    }
                }
                if (ExportCSV.Checked)
                {
                    if (DataType.SelectedIndex == 0)
                    {
                        cmd = "ReportCreate */Chain/" + accessName + " Style \"Complete Chain Access\" Type Export File \"" + CommonData.DirectoryStr + "\\" + accessName + "_SavedAccessData.csv" + "\"";
                    }
                    else if (DataType.SelectedIndex == 1)
                    {
                        cmd = "ReportCreate */Chain/" + accessName + " Style \"Individual Strand Access\" Type Export File \"" + CommonData.DirectoryStr + "\\" + accessName + "_SavedAccessData.csv" + "\"";
                    }
                    try
                    {
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not save report");
                    }
                }
                MessageBox.Show("Computation Complete");
            }
            else
            {
                if (CommonData.ToObjectNames.Count == 0)
                {
                    MessageBox.Show("No To Objects selected");
                }
                if (CommonData.FromObjectNames.Count == 0)
                {
                    MessageBox.Show("No From Objects selected");
                }
            }
        }
Ejemplo n.º 20
0
        //Main Function
        private void Generate_Click(object sender, EventArgs e)
        {
            int check = FieldCheck();

            if (check == 0)
            {
                RemoveProximityGeometry();
                try
                {
                    CommonData.StkRoot.UnitPreferences.SetCurrentUnit("Distance", "km");
                    CommonData.RunList.Clear();
                    CommonData.TargetName = TargetSat.Text;
                    CommonData.ActorName  = ActorSat.Text;
                    //Set user bounds for safety
                    double userMinRange = Double.Parse(SphericalMag.Text) / 1000;
                    double userMinR     = Double.Parse(RMag.Text) / 1000;
                    double userMinI     = Double.Parse(IMag.Text) / 1000;
                    double userMinC     = Double.Parse(CMag.Text) / 1000;

                    IAgScenario  scenario = CommonData.StkRoot.CurrentScenario as IAgScenario;
                    IAgStkObject satObj   = CommonData.StkRoot.GetObjectFromPath("Satellite/" + ActorSat.Text);
                    IAgSatellite sat      = satObj as IAgSatellite;

                    //Get all maneuver end times for actor satellite
                    IAgDataProviderGroup   maneuverDpGroup = satObj.DataProviders["Astrogator Maneuver Ephemeris Block Final"] as IAgDataProviderGroup;
                    IAgDataPrvTimeVar      maneuverDp      = maneuverDpGroup.Group["Cartesian Elems"] as IAgDataPrvTimeVar;
                    IAgDrResult            result          = maneuverDp.Exec(scenario.StartTime, scenario.StopTime, 60);
                    IAgDrDataSetCollection maneuverData    = result.DataSets;



                    //If there is maneuvers, run iterations for each maneuver. If no maneuvers then just pull closest RIC data for entire trajectory
                    if (maneuverData.Count != 0)
                    {
                        CommonData.HasManeuvers = true;

                        //Get maneuver numbers
                        IAgDataPrvInterval summaryDp     = satObj.DataProviders["Maneuver Summary"] as IAgDataPrvInterval;
                        IAgDrResult        summaryResult = summaryDp.Exec(scenario.StartTime, scenario.StopTime);
                        Array maneuverNumbers            = summaryResult.DataSets.GetDataSetByName("Maneuver Number").GetValues();
                        int   maxManeuverNum             = maneuverNumbers.Length;

                        //Get handles to cartesian position and velocity to seed passive safety runs
                        IAgDataProviderGroup cartPos   = satObj.DataProviders["Cartesian Position"] as IAgDataProviderGroup;
                        IAgDataPrvTimeVar    cartPosDP = cartPos.Group["ICRF"] as IAgDataPrvTimeVar;

                        IAgDataProviderGroup cartVel   = satObj.DataProviders["Cartesian Velocity"] as IAgDataProviderGroup;
                        IAgDataPrvTimeVar    cartVelDP = cartVel.Group["ICRF"] as IAgDataPrvTimeVar;

                        //Create passive safety satellite. Set to Astrogator and pull handles to initial state and propagate segments
                        IAgStkObject passiveSatObj = CreatorFunctions.GetCreateSatellite("PassiveCheck");
                        IAgSatellite passiveSat    = passiveSatObj as IAgSatellite;
                        passiveSat.SetPropagatorType(AgEVePropagatorType.ePropagatorAstrogator);
                        IAgVADriverMCS passiveDriver = passiveSat.Propagator as IAgVADriverMCS;

                        IAgVAMCSInitialState          intState = passiveDriver.MainSequence[0] as IAgVAMCSInitialState;
                        IAgVAMCSPropagate             prop     = passiveDriver.MainSequence[1] as IAgVAMCSPropagate;
                        IAgVAStoppingConditionElement sc1      = prop.StoppingConditions[0];
                        IAgVAStoppingCondition        sc       = sc1.Properties as IAgVAStoppingCondition;
                        sc.Trip = PropTime.Text;

                        AgVAElementCartesian element = intState.Element as AgVAElementCartesian;
                        Array    epoch;
                        Array    vx;
                        Array    vy;
                        Array    vz;
                        Array    x;
                        Array    y;
                        Array    z;
                        String   epochCur;
                        DateTime dateCur;
                        //Assign cartesian elements to PassiveCheck satellite from actor maneuver maneuver data. Run each iteration to see if resulting trajectory violates constraints
                        for (int i = 0; i < maxManeuverNum; i++)
                        {
                            //Get maneuver time and offset in time by 0.25 sec to account for boundrary conditions around impulsive maneuvers
                            epoch    = maneuverData[0 + (i * 7)].GetValues();
                            epochCur = epoch.GetValue(0).ToString();
                            dateCur  = DateTime.Parse(epochCur);
                            dateCur  = dateCur.AddMilliseconds(250);
                            //dateCur = DateTime.ParseExact(epochCur, "dd MMM yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                            epochCur = dateCur.ToString("dd MMM yyyy HH:mm:ss.fff");

                            //Get cartesian state vector for given time
                            result = cartPosDP.ExecSingle(epochCur);
                            x      = result.DataSets.GetDataSetByName("x").GetValues();
                            y      = result.DataSets.GetDataSetByName("y").GetValues();
                            z      = result.DataSets.GetDataSetByName("z").GetValues();

                            result = cartVelDP.ExecSingle(epochCur);
                            vx     = result.DataSets.GetDataSetByName("x").GetValues();
                            vy     = result.DataSets.GetDataSetByName("y").GetValues();
                            vz     = result.DataSets.GetDataSetByName("z").GetValues();

                            //Create passive run output to be used in visualization
                            PassiveRun run = new PassiveRun();
                            run.UserMinRange    = Double.Parse(SphericalMag.Text) / 1000;
                            run.UserMinR        = Double.Parse(RMag.Text) / 1000;
                            run.UserMinI        = Double.Parse(IMag.Text) / 1000;
                            run.UserMinC        = Double.Parse(CMag.Text) / 1000;
                            intState.OrbitEpoch = epochCur;
                            element.Vx          = Double.Parse(vx.GetValue(0).ToString());
                            element.Vy          = Double.Parse(vy.GetValue(0).ToString());
                            element.Vz          = Double.Parse(vz.GetValue(0).ToString());
                            element.X           = Double.Parse(x.GetValue(0).ToString());
                            element.Y           = Double.Parse(y.GetValue(0).ToString());
                            element.Z           = Double.Parse(z.GetValue(0).ToString());

                            passiveDriver.RunMCS();

                            run.Vx       = Double.Parse(vx.GetValue(0).ToString());
                            run.Vy       = Double.Parse(vy.GetValue(0).ToString());
                            run.Vz       = Double.Parse(vz.GetValue(0).ToString());
                            run.X        = Double.Parse(x.GetValue(0).ToString());
                            run.Y        = Double.Parse(y.GetValue(0).ToString());
                            run.Z        = Double.Parse(z.GetValue(0).ToString());
                            run.PropTime = Double.Parse(PropTime.Text);

                            //Pull closest point to target for each iteration and save to passive run output
                            IAgDataProvider psatDp = passiveSatObj.DataProviders["RIC Coordinates"] as IAgDataProvider;
                            psatDp.PreData = "Satellite/" + TargetSat.Text;
                            IAgDataPrvTimeVar psatDpTimeVar = psatDp as IAgDataPrvTimeVar;
                            IAgDrResult       psatDp2       = psatDpTimeVar.Exec(scenario.StartTime, scenario.StopTime, Double.Parse(TimeStep.Text));
                            run.Range         = psatDp2.DataSets.GetDataSetByName("Range").GetValues();
                            run.Intrack       = psatDp2.DataSets.GetDataSetByName("In-Track").GetValues();
                            run.Crosstrack    = psatDp2.DataSets.GetDataSetByName("Cross-Track").GetValues();
                            run.Radial        = psatDp2.DataSets.GetDataSetByName("Radial").GetValues();
                            run.MinRange      = MathFunctions.ArrayMin(run.Range);
                            run.MinIntrack    = MathFunctions.ArrayMinAbs(run.Intrack);
                            run.MinCrosstrack = MathFunctions.ArrayMinAbs(run.Crosstrack);
                            run.MinRadial     = MathFunctions.ArrayMinAbs(run.Radial);
                            //run.ManeuverTime = epoch.GetValue(0).ToString();
                            run.ManeuverTime = epochCur;

                            //spherical
                            if (radioButton1.Checked)
                            {
                                run.IsSpherical = true;
                                if (run.MinRange < userMinRange)
                                {
                                    run.Safe = false;
                                }
                                else
                                {
                                    run.Safe = true;
                                }
                            }
                            //independent axis
                            else
                            {
                                run.IsSpherical = false;
                                if (Math.Abs(run.MinIntrack) < userMinI && Math.Abs(run.MinRadial) < userMinR && Math.Abs(run.MinCrosstrack) < userMinC)
                                {
                                    bool tripped = false;
                                    for (int j = 0; j < run.Range.Length; j++)
                                    {
                                        if (Math.Abs(Double.Parse(run.Intrack.GetValue(j).ToString())) < userMinI && Math.Abs(Double.Parse(run.Radial.GetValue(j).ToString())) < userMinR && Math.Abs(Double.Parse(run.Crosstrack.GetValue(j).ToString())) < userMinC)
                                        {
                                            run.Safe = false;
                                            tripped  = true;
                                            break;
                                        }
                                    }
                                    if (!tripped)
                                    {
                                        run.Safe = true;
                                    }
                                }
                                else
                                {
                                    run.Safe = true;
                                }
                            }

                            CommonData.RunList.Add(run);
                        }
                    }
                    else
                    {
                        CommonData.HasManeuvers = false;
                        PassiveRun      run   = new PassiveRun();
                        IAgDataProvider satDp = satObj.DataProviders["RIC Coordinates"] as IAgDataProvider;
                        satDp.PreData = "Satellite/" + TargetSat.Text;
                        IAgDataPrvTimeVar satDpTimeVar = satDp as IAgDataPrvTimeVar;
                        IAgDrResult       satDp2       = satDpTimeVar.Exec(scenario.StartTime, scenario.StopTime, Double.Parse(TimeStep.Text));
                        run.Range         = satDp2.DataSets.GetDataSetByName("Range").GetValues();
                        run.Intrack       = satDp2.DataSets.GetDataSetByName("In-Track").GetValues();
                        run.Crosstrack    = satDp2.DataSets.GetDataSetByName("Cross-Track").GetValues();
                        run.Radial        = satDp2.DataSets.GetDataSetByName("Radial").GetValues();
                        run.MinRange      = MathFunctions.ArrayMin(run.Range);
                        run.MinIntrack    = MathFunctions.ArrayMinAbs(run.Intrack);
                        run.MinCrosstrack = MathFunctions.ArrayMinAbs(run.Crosstrack);
                        run.MinRadial     = MathFunctions.ArrayMinAbs(run.Radial);
                        run.ManeuverTime  = "N/A";

                        //spherical
                        if (radioButton1.Checked)
                        {
                            run.IsSpherical = true;
                            if (run.MinRange < userMinRange)
                            {
                                run.Safe = false;
                            }
                            else
                            {
                                run.Safe = true;
                            }
                        }
                        //independent axis
                        else
                        {
                            run.IsSpherical = false;
                            if (Math.Abs(run.MinIntrack) < userMinI && Math.Abs(run.MinRadial) < userMinR && Math.Abs(run.MinCrosstrack) < userMinC)
                            {
                                bool tripped = false;
                                for (int j = 0; j < run.Range.Length; j++)
                                {
                                    if (Math.Abs(Double.Parse(run.Intrack.GetValue(j).ToString())) < userMinI && Math.Abs(Double.Parse(run.Radial.GetValue(j).ToString())) < userMinR && Math.Abs(Double.Parse(run.Crosstrack.GetValue(j).ToString())) < userMinC)
                                    {
                                        run.Safe = false;
                                        tripped  = true;
                                        break;
                                    }
                                }
                                if (!tripped)
                                {
                                    run.Safe = true;
                                }
                            }
                            else
                            {
                                run.Safe = true;
                            }
                        }

                        CommonData.RunList.Add(run);
                    }
                    CommonData.BeenRun = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("Passive Safety Check Failed");
                }
            }
        }
Ejemplo n.º 21
0
        private void Generate_Click(object sender, EventArgs e)
        {
            CommonData.StkRoot.ExecuteCommand("BatchGraphics * On");
            IAgConstellation myConst;

            if ((string)ImportType.SelectedItem == "TLE/TCE")
            {
                string      filepath      = TCEFile.Text;
                IAgScenario scenario      = (IAgScenario)CommonData.StkRoot.CurrentScenario;
                string      startTime     = scenario.StartTime;
                string      stopTime      = scenario.StopTime;
                string      constellation = null;
                string      cmd;

                try
                {
                    IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/Assets");
                    if ((string)ConstType.SelectedItem == "Default Constellation")
                    {
                        if (result[0] == "0")
                        {
                            IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, "Assets");
                        }
                        constellation = "Assets";
                    }
                    else if ((string)ConstType.SelectedItem == "Existing Constellation")
                    {
                        result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + ExistingConst.Text);
                        if (result[0] == "0")
                        {
                            IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ExistingConst.Text);
                        }
                        constellation = ExistingConst.Text;
                    }
                    else if ((string)ConstType.SelectedItem == "New Constellation")
                    {
                        result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + ConstName.Text);
                        if (result[0] == "0")
                        {
                            IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ConstName.Text);
                        }
                        constellation = ConstName.Text;
                    }
                    //must parse satellites into constellation because of bug associated with ImportTLEFile connect command
                    //Get list of sats prior to import
                    result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Satellite");
                    string[] prevSatArray = null;
                    if (result[0] != "None")
                    {
                        prevSatArray = result[0].Split(null);
                    }

                    //Import TLE
                    cmd = "ImportTLEFile * " + "\"" + filepath + "\"" + " AutoPropagate On TimeStep 30.0 StartStop " + "\"" + startTime + "\" " + "\"" + stopTime + "\"";
                    CommonData.StkRoot.ExecuteCommand(cmd);

                    myConst = CommonData.StkRoot.GetObjectFromPath("Constellation/" + constellation) as IAgConstellation;
                    IAgSatellite sat;
                    //Compare prev satellite list to new satellite list
                    result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Satellite");
                    string[] newSatArray = null;
                    if (result[0] != "None")
                    {
                        newSatArray = result[0].Split(null);
                    }
                    if (prevSatArray == null)
                    {
                        if (newSatArray != null)
                        {
                            foreach (var item in newSatArray)
                            {
                                if (item != "")
                                {
                                    string newItem = item.Split('/').Last();
                                    string objPath = "Satellite/" + newItem;
                                    myConst.Objects.Add(objPath);
                                    sat = CommonData.StkRoot.GetObjectFromPath(item.ToString()) as IAgSatellite;
                                    if (CoordSystem.SelectedIndex == 0)
                                    {
                                        sat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                                        sat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                                    }
                                    cmd = "VO */" + item.ToString() + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                                    CommonData.StkRoot.ExecuteCommand(cmd);
                                }
                            }
                        }
                    }
                    else
                    {
                        bool exists = false;
                        foreach (var newSat in newSatArray)
                        {
                            if (newSat != "")
                            {
                                exists = false;
                                foreach (var prevSat in prevSatArray)
                                {
                                    if (prevSat == newSat)
                                    {
                                        exists = true;
                                    }
                                }
                                if (exists != true)
                                {
                                    string newItem = newSat.Split('/').Last();
                                    string objPath = "Satellite/" + newItem;
                                    myConst.Objects.Add(objPath);
                                    sat = CommonData.StkRoot.GetObjectFromPath(objPath) as IAgSatellite;
                                    if (CoordSystem.SelectedIndex == 0)
                                    {
                                        sat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                                        sat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                                    }
                                    cmd = "VO */" + objPath + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                                    CommonData.StkRoot.ExecuteCommand(cmd);
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Could not load asset(s)");
                }
            }
            else if ((string)ImportType.SelectedItem == "Orbital Elements")
            {
                int check = FieldCheck();
                if (check == 0)
                {
                    int errorNum = 0;
                    try
                    {
                        errorNum = 1;
                        IAgStkObject sat   = CreatorFunctions.GetCreateSatellite(NameValue.Text);
                        IAgSatellite mySat = sat as IAgSatellite;
                        if (CoordSystem.SelectedIndex == 0)
                        {
                            mySat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                            mySat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                            string cmd = "VO */Satellite/" + NameValue.Text + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                            CommonData.StkRoot.ExecuteCommand(cmd);
                        }
                        ((IAgSatellite)mySat).SetPropagatorType(AgEVePropagatorType.ePropagatorJ2Perturbation);
                        IAgOrbitStateClassical keplerian;
                        keplerian = ((IAgOrbitStateClassical)((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).InitialState.Representation.ConvertTo(AgEOrbitStateType.eOrbitStateClassical));
                        keplerian.SizeShapeType = AgEClassicalSizeShape.eSizeShapeSemimajorAxis;
                        ((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).InitialState.Representation.AssignClassical(AgECoordinateSystem.eCoordinateSystemICRF, Double.Parse(SMAValue.Text), Double.Parse(EccValue.Text), Double.Parse(IncValue.Text), Double.Parse(AoPValue.Text), Double.Parse(RAANValue.Text), Double.Parse(TAValue.Text));
                        ((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).Propagate();
                        IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/Assets");
                        errorNum = 2;
                        if ((string)ConstType.SelectedItem == "Default Constellation")
                        {
                            IAgStkObject     conste = CreatorFunctions.GetCreateConstellation("Assets");
                            IAgConstellation assets = conste as IAgConstellation;

                            string objPath = "Satellite/" + NameValue.Text;
                            assets.Objects.Add(objPath);
                        }
                        else if ((string)ConstType.SelectedItem == "Existing Constellation")
                        {
                            IAgConstellation assets  = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + ExistingConst.Text);
                            string           objPath = "Satellite/" + NameValue.Text;
                            assets.Objects.Add(objPath);
                        }
                        else if ((string)ConstType.SelectedItem == "New Constellation")
                        {
                            IAgConstellation assets  = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ConstName.Text);
                            string           objPath = "Satellite/" + NameValue.Text;
                            assets.Objects.Add(objPath);
                        }
                    }
                    catch (Exception)
                    {
                        string errorMes = null;
                        if (errorNum == 1)
                        {
                            errorMes = "Could not load satellite- Improper Orbital Elements";
                        }
                        else if (errorNum == 2)
                        {
                            errorMes = "Could not add satellite to constellation";
                        }
                        MessageBox.Show(errorMes);
                    }
                }
            }
            else if ((string)ImportType.SelectedItem == "Satellite Database")
            {
                string           sscString = null;
                string           satName   = null;
                int              errorNum  = 0;
                string           errorSsc  = null;
                string           objPath   = null;
                IAgSatellite     mySat     = null;
                IAgConstellation assets    = null;
                IAgScenario      scenario  = CommonData.StkRoot.CurrentScenario as IAgScenario;
                string           startTime = scenario.StartTime;
                string           stopTime  = scenario.StopTime;
                string           cmd;
                int              errorId = 0;
                CommonData.StkRoot.ExecuteCommand("BatchGraphics * On");
                foreach (var item in _selectedSatList)
                {
                    //Determine the proper satellite name based on catalog
                    errorId = 5;
                    int        index      = CommonData.SatCatItemList.IndexOf(CommonData.SatCatItemList.Where(p => p.Ssc == item).FirstOrDefault());
                    SatCatItem currentSat = CommonData.SatCatItemList[index];
                    if (currentSat.OtherName != "Unspecified")
                    {
                        string otherName = currentSat.OtherName.Replace(" ", "_");
                        otherName = Regex.Replace(otherName, @"[^0-9a-zA-Z_]+", "");
                        //CommonData.StkRoot.ExecuteCommand("Rename */" + objPath + " " + otherName);
                        objPath = "Satellite/" + otherName;
                        satName = otherName;
                    }
                    else if (currentSat.CommonName != "Unspecified")
                    {
                        string commonName = currentSat.CommonName.Replace(" ", "_");
                        commonName = Regex.Replace(commonName, @"[^0-9a-zA-Z_]+", "");
                        objPath    = "Satellite/" + commonName;
                        satName    = commonName;
                    }
                    else
                    {
                        objPath = "Satellite/" + item;
                        satName = item;
                    }

                    //SSCString = "SSCNumber " + item + " ";
                    //cmd = "ImportTLEFile * " + "\"" + CommonData.SatDatabaseLocation + "\"" +SSCString+ "AutoPropagate On TimeStep 30.0 StartStop " + "\"" + startTime + "\" " + "\"" + stopTime + "\"";
                    try
                    {
                        errorId = 1;
                        //Create or get handle to satellite based on given name
                        mySat = (IAgSatellite)CreatorFunctions.GetCreateSatellite(satName);
                        //Erase old TLE data and replace it with new data from specified file
                        mySat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4);
                        IAgVePropagatorSGP4 tleprop = mySat.Propagator as IAgVePropagatorSGP4;
                        tleprop.Segments.RemoveAllSegs();//clear before adding new
                        tleprop.CommonTasks.AddSegsFromFile(item, CommonData.Preferences.SatDatabaseLocation);
                        tleprop.Propagate();
                        mySat.Graphics.Resolution.Orbit = 20;
                        //Change trajectory representation to fixed if required. Inertial by default
                        if (CoordSystem.SelectedIndex == 0)
                        {
                            mySat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                            mySat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                            string cmd1 = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                            CommonData.StkRoot.ExecuteCommand(cmd1);
                        }
                        else if (CoordSystem.SelectedIndex == 1)
                        {
                            mySat.VO.OrbitSystems.FixedByWindow.IsVisible    = false;
                            mySat.VO.OrbitSystems.InertialByWindow.IsVisible = true;
                            string cmd1 = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                            CommonData.StkRoot.ExecuteCommand(cmd1);
                        }

                        //Get handle to constellation or create if necessary. Add satellite to constellation
                        if ((string)ConstType.SelectedItem == "Default Constellation")
                        {
                            errorId = 2;
                            assets  = CreatorFunctions.GetCreateConstellation("Assets") as IAgConstellation;
                        }
                        else if ((string)ConstType.SelectedItem == "Existing Constellation")
                        {
                            errorId = 3;
                            assets  = CreatorFunctions.GetCreateConstellation(ExistingConst.Text) as IAgConstellation;
                        }
                        else if ((string)ConstType.SelectedItem == "New Constellation")
                        {
                            errorId = 4;
                            assets  = CreatorFunctions.GetCreateConstellation(ConstName.Text) as IAgConstellation;
                        }

                        if (!assets.Objects.Contains("Satellite/" + satName))
                        {
                            objPath = "Satellite/" + satName;
                            assets.Objects.Add(objPath);
                        }

                        errorId = 8;
                        CreatorFunctions.ChangeSatColor(objPath, index);

                        //Create sensor if applicable. Place sensor in appropiate constellation for sensors
                        if (currentSat.Fov != 0 && SensorToggle.Checked)
                        {
                            try
                            {
                                errorId = 6;
                                IAgStkObject assetsObject = assets as IAgStkObject;
                                IAgStkObject sat          = CommonData.StkRoot.GetObjectFromPath(objPath);
                                IAgSensor    sensor       = CreatorFunctions.GetCreateSensor(sat, sat.InstanceName + "_Sensor") as IAgSensor;
                                IAgStkObject sensorObject = sensor as IAgStkObject;
                                sensor.CommonTasks.SetPatternSimpleConic(currentSat.Fov / 2, 1);
                                sensor.VO.ProjectionType      = AgESnVOProjectionType.eProjectionEarthIntersections;
                                sensor.VO.PercentTranslucency = 70;

                                errorId = 7;
                                assets  = CreatorFunctions.GetCreateConstellation(assetsObject.InstanceName + "_Sensors") as IAgConstellation;
                                try
                                {
                                    assets.Objects.AddObject(sensorObject);
                                }
                                catch (Exception)
                                {
                                    //Likely already in the constellation
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {
                        string errorIdString = null;
                        if (errorId == 1)
                        {
                            errorIdString = "- Could not load from database";
                        }
                        else if (errorId == 2)
                        {
                            errorIdString = "- Could not add to Default constellation";
                        }
                        else if (errorId == 3)
                        {
                            errorIdString = "- Could not add to existing constellation";
                        }
                        else if (errorId == 4)
                        {
                            errorIdString = "- Could not add to new constellation";
                        }
                        else if (errorId == 5)
                        {
                            errorIdString = "- Could not change satellite name";
                        }
                        else if (errorId == 6)
                        {
                            errorIdString = "- Could not load sensor or update sensor properties";
                        }
                        else if (errorId == 7)
                        {
                            errorIdString = "- Could not add sensor to constellation";
                        }
                        else if (errorId == 8)
                        {
                            errorIdString = "- Could not change satellite color";
                        }
                        errorSsc = errorSsc + item + errorIdString + "\n\r";
                        errorNum++;
                    }
                }
                if (errorNum != 0)
                {
                    MessageBox.Show("Error loading the following satellites: \n\r" + errorSsc);
                }
                CommonData.StkRoot.ExecuteCommand("BatchGraphics * Off");
            }
            else if ((string)ImportType.SelectedItem == "Ephemeris")
            {
                try
                {
                    IAgConstellation assets        = null;
                    string           constellation = null;
                    if ((string)ConstType.SelectedItem == "Default Constellation")
                    {
                        IAgStkObject obj = CreatorFunctions.GetCreateConstellation("Assets");
                        assets        = obj as IAgConstellation;
                        constellation = "Assets";
                    }
                    else if ((string)ConstType.SelectedItem == "Existing Constellation")
                    {
                        IAgStkObject obj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                        assets        = obj as IAgConstellation;
                        constellation = ExistingConst.Text;
                    }
                    else if ((string)ConstType.SelectedItem == "New Constellation")
                    {
                        IAgStkObject obj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                        assets        = obj as IAgConstellation;
                        constellation = ConstName.Text;
                    }
                    string   filepath   = TCEFile.Text;
                    string[] separator1 = { "\\" };
                    string[] separator2 = { "." };
                    string   fileName   = filepath.Split(separator1, StringSplitOptions.None).Last();
                    string   satName    = fileName.Split(separator2, StringSplitOptions.None).First();
                    satName = Regex.Replace(satName, @"[^0-9a-zA-Z_]+", "");
                    IAgStkObject satObj = CreatorFunctions.GetCreateSatellite(satName);
                    IAgSatellite sat    = satObj as IAgSatellite;
                    sat.SetPropagatorType(AgEVePropagatorType.ePropagatorStkExternal);
                    IAgVePropagatorStkExternal prop = sat.Propagator as IAgVePropagatorStkExternal;
                    prop.Filename = filepath;
                    if (TimeSlip.Checked)
                    {
                        try
                        {
                            prop.Override = true;
                            prop.EphemerisStartEpoch.SetExplicitTime(SlipTime.Text);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Could not apply time slip");
                        }
                    }
                    prop.Propagate();
                    try
                    {
                        assets.Objects.AddObject(satObj);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not add to constellation");
                    }

                    if (CoordSystem.SelectedIndex == 0)
                    {
                        sat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                        sat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                        string cmd = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Error loading ephemeris");
                }
            }
            CommonData.StkRoot.ExecuteCommand("BatchGraphics * Off");
            PopulateExistingConstellations();
        }
Ejemplo n.º 22
0
        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));
            }
        }
Ejemplo n.º 23
0
        //create satellite function
        private void CreateSatellite(string objId, string source, string fpath)
        {
            IAgStkObject sat = null;

            try
            {
                string sname = objId + "_" + source.Replace(' ', '_').Trim();

                //create new if non-existant or get handle
                sat = CreatorFunctions.GetCreateSatellite(sname);

                //handle to satellite
                IAgSatellite zsat = sat as IAgSatellite;
                //Erase old TLE data and replace it with new data from specified file
                zsat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4);
                IAgVePropagatorSGP4 tleprop = zsat.Propagator as IAgVePropagatorSGP4;
                tleprop.Segments.RemoveAllSegs();//clear before adding new
                tleprop.CommonTasks.AddSegsFromFile(objId, fpath);
                tleprop.Propagate();
                zsat.Graphics.Resolution.Orbit = 10;


                if (CoordSystem.SelectedIndex == 0)
                {
                    zsat.VO.OrbitSystems.FixedByWindow.IsVisible    = true;
                    zsat.VO.OrbitSystems.InertialByWindow.IsVisible = false;
                    string cmd = "VO */Satellite/" + sname + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000";
                    try
                    {
                        CommonData.StkRoot.ExecuteCommand(cmd);
                    }
                    catch (Exception)
                    {
                    }
                }

                //Place into constellation
                IAgConstellation assets = null;
                if ((string)ConstType.SelectedItem == "Default Constellation")
                {
                    IAgStkObject conste = CreatorFunctions.GetCreateConstellation("Assets");
                    assets = conste as IAgConstellation;
                }
                else if ((string)ConstType.SelectedItem == "Existing Constellation")
                {
                    assets = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + ExistingConst.Text);
                }
                else if ((string)ConstType.SelectedItem == "New Constellation")
                {
                    IAgStkObject conste = CreatorFunctions.GetCreateConstellation(ConstName.Text.Replace(" ", "_"));
                    assets = conste as IAgConstellation;
                }
                string objPath = "Satellite/" + sname;
                if (assets.Objects.IndexOf(objPath) == -1 && assets != null)
                {
                    assets.Objects.Add(objPath);
                }
            }
            catch (Exception ex)
            {
                //Identify the satellite with an issue
                MessageBox.Show(ex.Message + "\n" + "SSC: " + objId);
                //unload satellite if possible so there is not an empty object in STK from an error
                //try
                //{
                //    sat.Unload();
                //}
                //catch (Exception)
                //{
                //}
            }
        }
        private void GenerateSingle_Click(object sender, EventArgs e)
        {
            Tuple <int, string> check = FieldCheck();

            if (check.Item1 == 0)
            {
                try
                {
                    IAgStkObject facObj = CreatorFunctions.GetCreateFacility(FacilityName.Text);
                    IAgFacility  fac    = facObj as IAgFacility;
                    IAgStkObject sensor = null;
                    fac.Position.AssignGeodetic(Double.Parse(Latitude.Text), Double.Parse(Longitude.Text), Double.Parse(Altitude.Text));
                    fac.AltRef = AgEAltRefType.eWGS84;
                    if (SensorType.SelectedIndex == 1)
                    {
                        OpticalParams oParams = new OpticalParams();
                        oParams.MinEl        = "0";
                        oParams.MaxEl        = "90";
                        oParams.MinRange     = "4800";
                        oParams.MaxRange     = "90000";
                        oParams.LunarExAngle = "10";
                        oParams.SunElAngle   = "-12";
                        oParams.HalfAngle    = "70";
                        sensor = CreatorFunctions.AttachFacilityOptical(facObj, FacilityName.Text + "_Opt", oParams);
                    }
                    else if (SensorType.SelectedIndex == 2)
                    {
                        RadarParams rParams = new RadarParams();
                        rParams.MinEl        = "0";
                        rParams.MaxEl        = "90";
                        rParams.MinRange     = "1600";
                        rParams.MaxRange     = "40000";
                        rParams.SolarExAngle = "10";
                        rParams.HalfAngle    = "85";
                        sensor = CreatorFunctions.AttachFacilityRadar(facObj, FacilityName.Text + "_Radar", rParams);
                    }
                    else
                    {
                    }
                    if (ConstType.SelectedIndex != 0)
                    {
                        IAgStkObject     constObj = null;
                        IAgConstellation constel  = null;
                        if (ConstType.SelectedIndex == 1)
                        {
                            constObj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                            constel  = constObj as IAgConstellation;
                        }
                        else if (ConstType.SelectedIndex == 2)
                        {
                            constObj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                            constel  = constObj as IAgConstellation;
                        }
                        if (SensorType.SelectedIndex == 0)
                        {
                            constel.Objects.AddObject(facObj);
                        }
                        else if (SensorType.SelectedIndex == 1 || SensorType.SelectedIndex == 2)
                        {
                            constel.Objects.AddObject(sensor);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Could not create facility");
                }
            }
            else
            {
                MessageBox.Show(check.Item2);
            }
        }
        private void Calculate_Click(object sender, EventArgs e)
        {
            int check = FieldCheck();

            if (check == 0)
            {
                compComplete = false;
                AllPlaneCrossingsList.Clear();
                IAgCrdnPlaneNormal orbitPlane;
                IAgStkObject       crossObj;
                IAgCrdnProvider    crossVgt;
                IAgStkObject       satRefObj = CreatorFunctions.GetCreateSatellite(PlaneSatellite.Text);
                IAgSatellite       satRef    = (IAgSatellite)satRefObj;
                IAgCrdnProvider    vgtPrv    = satRefObj.Vgt;

                //Create reference plane
                string planeName = PlaneSatellite.Text + "_OrbitPlane";
                orbitPlane = AWBFunctions.GetCreatePlaneNormal(vgtPrv, vgtPrv.Points["Center"], vgtPrv.Vectors["Velocity"], vgtPrv.Vectors["Orbit_Normal"], planeName, "Orbit plane referencing orbit normal");

                //Loop for each crossing object. Create angle, calc scalar, extrema time array, and conditionals if required
                string angleName;
                string extremaName;
                string conditionName;
                string cScalName;
                string condEventArrayName;
                foreach (var cObject in crossingObjects)
                {
                    //Initialize new plane crossing group
                    PlaneCrossingGroup crossingGroup = new PlaneCrossingGroup();
                    IAgScenario        scenario      = CommonData.StkRoot.CurrentScenario as IAgScenario;
                    crossingGroup.AnalysisStartTime        = scenario.StartTime;
                    crossingGroup.AnalysisStopTime         = scenario.StopTime;
                    crossingGroup.PlaneReferenceObjectName = satRefObj.InstanceName;
                    crossingGroup.CrossingObjectName       = cObject;

                    //Compute required VGT component names
                    crossObj           = CommonData.StkRoot.GetObjectFromPath(ObjectClass.Text + "/" + cObject);
                    crossVgt           = crossObj.Vgt;
                    angleName          = crossObj.InstanceName + "x" + satRefObj.InstanceName + "_Angle";
                    cScalName          = angleName;
                    extremaName        = crossObj.InstanceName + "x" + satRefObj.InstanceName + "_CrossingTimes";
                    conditionName      = crossObj.InstanceName + "x" + satRefObj.InstanceName + "_CrossingBounds";
                    condEventArrayName = crossObj.InstanceName + "x" + satRefObj.InstanceName + "_BoundedCrossingTimes";

                    //Create angle from current crossing object position to reference plane
                    IAgCrdnAngleToPlane planeAngle = AWBFunctions.GetCreateAngleToPlane(crossVgt, vgtPrv.Planes[planeName], crossVgt.Vectors["Position"], angleName, "Angle from satellite position to" + satRefObj.InstanceName + "orbit plane");

                    //Create calc scalar of angle
                    IAgCrdnCalcScalarAngle calcScalarAngle = AWBFunctions.GetCreateAngleCalcScalar(crossVgt, (IAgCrdnAngle)planeAngle, cScalName);

                    //Create Extrema time array to find exact crossing times
                    IAgCrdnEventArrayExtrema extrema = AWBFunctions.GetCreateEventArrayExtrema(crossVgt, (IAgCrdnCalcScalar)calcScalarAngle, extremaName, AgECrdnExtremumConstants.eCrdnExtremumMinimum, false);

                    //If conditional then create condition and condition crossing event
                    IAgCrdnEventArrayConditionCrossings conditionCrossings = null;
                    if (ConditionalCrossing.Checked)
                    {
                        //create condition
                        IAgCrdnConditionScalarBounds condition = AWBFunctions.GetCreateConditionScalarBounds(crossVgt, (IAgCrdnCalcScalar)calcScalarAngle, conditionName, AgECrdnConditionThresholdOption.eCrdnConditionThresholdOptionInsideMinMax);
                        AWBFunctions.SetAngleConditionScalarBounds(condition, Double.Parse(ConditionalLB.Text), Double.Parse(ConditionalUB.Text));

                        //Create condition crossing event
                        if (crossVgt.EventArrays.Contains(condEventArrayName))
                        {
                            conditionCrossings = (IAgCrdnEventArrayConditionCrossings)crossVgt.EventArrays[condEventArrayName];
                        }
                        else
                        {
                            conditionCrossings = (IAgCrdnEventArrayConditionCrossings)crossVgt.EventArrays.Factory.CreateEventArrayConditionCrossings(condEventArrayName, "");
                        }
                        conditionCrossings.Condition            = condition as IAgCrdnCondition;
                        conditionCrossings.SatisfactionCrossing =
                            AgECrdnSatisfactionCrossing.eCrdnSatisfactionCrossingNone;
                        //if (OffOnSat.Checked && OnOffSat.Checked)
                        //{
                        //    conditionCrossings.SatisfactionCrossing =
                        //        AgECrdnSatisfactionCrossing.eCrdnSatisfactionCrossingNone;
                        //}
                        //else if (OffOnSat.Checked && !OnOffSat.Checked)
                        //{
                        //    conditionCrossings.SatisfactionCrossing =
                        //        AgECrdnSatisfactionCrossing.eCrdnSatisfactionCrossingIn;
                        //}
                        //else if (!OffOnSat.Checked && OnOffSat.Checked)
                        //{
                        //    conditionCrossings.SatisfactionCrossing =
                        //        AgECrdnSatisfactionCrossing.eCrdnSatisfactionCrossingOut;
                        //}
                    }
                    //Extract Data
                    IAgCrdnEventArray      extremaArray = (IAgCrdnEventArray)extrema;
                    IAgCrdnFindTimesResult extremaTimes = extremaArray.FindTimes();
                    IAgCrdnEventArray      boundedArray = null;
                    IAgCrdnFindTimesResult boundedTimes = null;
                    if (extremaTimes.IsValid)
                    {
                        int numTimes = extremaTimes.Times.Length;
                        if (ConditionalCrossing.Checked)
                        {
                            boundedArray = conditionCrossings as IAgCrdnEventArray;
                            boundedTimes = boundedArray.FindTimes();
                            if (boundedTimes.Times.Length != 2 * numTimes)
                            {
                                MessageBox.Show("A bounded crossing time may be outside the analysis interval. Check results.");
                            }
                        }
                        PlaneCrossing crossing;
                        for (int i = 0; i < numTimes; i++)
                        {
                            crossing = new PlaneCrossing();
                            crossing.CrossingTime = extremaTimes.Times.GetValue(i).ToString();
                            if (ConditionalCrossing.Checked)
                            {
                                crossing.IsBounded  = true;
                                crossing.LowerBound = Double.Parse(ConditionalLB.Text);
                                crossing.UpperBound = Double.Parse(ConditionalUB.Text);

                                if (boundedTimes.Times.Length != 2 * numTimes)
                                {
                                    try
                                    {
                                        crossing.LowerBoundCrossingTime = boundedTimes.Times.GetValue(2 * i).ToString();
                                        crossing.UpperBoundCrossingTime = boundedTimes.Times.GetValue(2 * i + 1).ToString();
                                    }
                                    catch (Exception) //Index out of range
                                    {
                                        crossing.LowerBoundCrossingTime = "";
                                        crossing.UpperBoundCrossingTime = "";
                                    }
                                }
                                else
                                {
                                    crossing.LowerBoundCrossingTime = boundedTimes.Times.GetValue(2 * i).ToString();
                                    crossing.UpperBoundCrossingTime = boundedTimes.Times.GetValue(2 * i + 1).ToString();
                                }
                            }
                            crossingGroup.PlaneCrossings.Add(crossing);
                        }
                    }
                    AllPlaneCrossingsList.Add(crossingGroup);
                    compComplete = true;

                    //Add components to timeline view
                    if (AddToTimeline.Checked)
                    {
                        string cmd1 = null;
                        string cmd2 = null;
                        if (ConditionalCrossing.Checked)
                        {
                            cmd1 = "Timeline * TimeComponent Remove ContentView \"Scenario Availability\"" + " \"" + ObjectClass.Text + "/" + crossObj.InstanceName + " " + condEventArrayName + " Time Array\"";
                            cmd2 = "Timeline * TimeComponent Add ContentView \"Scenario Availability\" DisplayName \"" + condEventArrayName + "\"" + " \"" + ObjectClass.Text + "/" + crossObj.InstanceName + " " + condEventArrayName + " Time Array\"";
                        }
                        else
                        {
                            cmd1 = "Timeline * TimeComponent Remove ContentView \"Scenario Availability\"" + " \"" + ObjectClass.Text + "/" + crossObj.InstanceName + " " + extremaName + " Time Array\"";
                            cmd2 = "Timeline * TimeComponent Add ContentView \"Scenario Availability\" DisplayName \"" + extremaName + "\"" + " \"" + ObjectClass.Text + "/" + crossObj.InstanceName + " " + extremaName + " Time Array\"";
                        }

                        try
                        {
                            CommonData.StkRoot.ExecuteCommand(cmd1);
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            CommonData.StkRoot.ExecuteCommand(cmd2);
                            CommonData.StkRoot.ExecuteCommand("Timeline * Refresh");
                        }
                        catch (Exception exception)
                        {
                            //likely no timeline exists
                        }
                    }
                }

                //Export options
                if (compComplete && ExportToTxt.Checked)
                {
                    ReadWrite.WritePlaneCrossingOutput(satRefObj.InstanceName, AllPlaneCrossingsList);
                }
                MessageBox.Show("Computation Complete!");
            }
        }
        private void GenerateSingle_Click(object sender, EventArgs e)
        {
            Tuple <int, string> check = FieldCheck();

            if (check.Item1 == 0)
            {
                if (ManualInput.Checked)
                {
                    try
                    {
                        IAgStkObject facObj = CreatorFunctions.GetCreateFacility(FacilityName.Text);
                        IAgFacility  fac    = facObj as IAgFacility;
                        IAgStkObject sensor = null;
                        fac.Position.AssignGeodetic(Double.Parse(Latitude.Text), Double.Parse(Longitude.Text), Double.Parse(Altitude.Text));
                        fac.AltRef = AgEAltRefType.eWGS84;
                        if (SensorType.SelectedIndex == 1)
                        {
                            OpticalParams oParams = new OpticalParams();
                            oParams.MinEl        = "0";
                            oParams.MaxEl        = "90";
                            oParams.MinRange     = "4800";
                            oParams.MaxRange     = "90000";
                            oParams.LunarExAngle = "10";
                            oParams.SunElAngle   = "-12";
                            oParams.HalfAngle    = "70";
                            oParams.MinAz        = "0";
                            oParams.MaxAz        = "360";
                            sensor = FacilityCreatorFunctions.AttachFacilityOptical(facObj, FacilityName.Text + "_Opt", oParams);
                        }
                        else if (SensorType.SelectedIndex == 2)
                        {
                            RadarParams rParams = new RadarParams();
                            rParams.MinEl        = "0";
                            rParams.MaxEl        = "90";
                            rParams.MinRange     = "1600";
                            rParams.MaxRange     = "40000";
                            rParams.SolarExAngle = "10";
                            rParams.HalfAngle    = "85";
                            rParams.MinAz        = "0";
                            rParams.MaxAz        = "360";
                            sensor = FacilityCreatorFunctions.AttachFacilityRadar(facObj, FacilityName.Text + "_Radar", rParams);
                        }
                        else
                        {
                        }
                        if (ConstType.SelectedIndex != 0)
                        {
                            IAgStkObject     constObj = null;
                            IAgConstellation constel  = null;
                            if (ConstType.SelectedIndex == 1)
                            {
                                constObj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                                constel  = constObj as IAgConstellation;
                            }
                            else if (ConstType.SelectedIndex == 2)
                            {
                                constObj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                                constel  = constObj as IAgConstellation;
                            }
                            if (SensorType.SelectedIndex == 0)
                            {
                                constel.Objects.AddObject(facObj);
                            }
                            else if (SensorType.SelectedIndex == 1 || SensorType.SelectedIndex == 2)
                            {
                                constel.Objects.AddObject(sensor);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not create facility");
                    }
                }
                else if (ImportFromFile.Checked)
                {
                    if (!String.IsNullOrEmpty(FilenameText.Text))
                    {
                        IAgStkObject          facObj;
                        IAgFacility           fac;
                        IAgStkObject          sensor;
                        List <GroundLocation> locations = ReadWrite.ReadFacilityFile(FilenameText.Text);
                        foreach (GroundLocation loc in locations)
                        {
                            facObj = CreatorFunctions.GetCreateFacility(loc.LocationName);
                            fac    = facObj as IAgFacility;
                            sensor = null;
                            fac.Position.AssignGeodetic(loc.Latitude, loc.Longitude, loc.Altitude);
                            fac.AltRef = AgEAltRefType.eWGS84;
                            if (SensorType.SelectedIndex == 1)
                            {
                                OpticalParams oParams = new OpticalParams();
                                oParams.MinEl        = "0";
                                oParams.MaxEl        = "90";
                                oParams.MinRange     = "4800";
                                oParams.MaxRange     = "90000";
                                oParams.LunarExAngle = "10";
                                oParams.SunElAngle   = "-12";
                                oParams.HalfAngle    = "70";
                                oParams.MinAz        = "0";
                                oParams.MaxAz        = "360";
                                sensor = FacilityCreatorFunctions.AttachFacilityOptical(facObj, FacilityName.Text + "_Opt", oParams);
                            }
                            else if (SensorType.SelectedIndex == 2)
                            {
                                RadarParams rParams = new RadarParams();
                                rParams.MinEl        = "0";
                                rParams.MaxEl        = "90";
                                rParams.MinRange     = "1600";
                                rParams.MaxRange     = "40000";
                                rParams.SolarExAngle = "10";
                                rParams.HalfAngle    = "85";
                                rParams.MinAz        = "0";
                                rParams.MaxAz        = "360";
                                sensor = FacilityCreatorFunctions.AttachFacilityRadar(facObj, FacilityName.Text + "_Radar", rParams);
                            }
                            else
                            {
                            }
                            if (ConstType.SelectedIndex != 0)
                            {
                                IAgStkObject     constObj = null;
                                IAgConstellation constel  = null;
                                if (ConstType.SelectedIndex == 1)
                                {
                                    constObj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text);
                                    constel  = constObj as IAgConstellation;
                                }
                                else if (ConstType.SelectedIndex == 2)
                                {
                                    constObj = CreatorFunctions.GetCreateConstellation(ConstName.Text);
                                    constel  = constObj as IAgConstellation;
                                }
                                if (SensorType.SelectedIndex == 0)
                                {
                                    constel.Objects.AddObject(facObj);
                                }
                                else if (SensorType.SelectedIndex == 1 || SensorType.SelectedIndex == 2)
                                {
                                    constel.Objects.AddObject(sensor);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please choose a valid input file");
                    }
                }
            }
            else
            {
                MessageBox.Show(check.Item2);
            }
        }
Ejemplo n.º 27
0
        private void PopulateTable(List <ObjectData> data)
        {
            List <string> temp = new List <string>();

            temp = CreatorFunctions.PopulateListByClass("Satellite");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();

            temp = CreatorFunctions.PopulateListByClass("Aircraft");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();

            temp = CreatorFunctions.PopulateListByClass("Ship");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();

            temp = CreatorFunctions.PopulateListByClass("LaunchVehicle");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();

            temp = CreatorFunctions.PopulateListByClass("GroundVehicle");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();

            temp = CreatorFunctions.PopulateListByClass("Missile");
            foreach (var item in temp)
            {
                int index = data.IndexOf(data.Where(p => p.SimplePath.Contains(item)).FirstOrDefault());
                if (index != -1)
                {
                    PopulateObjectRow(data[index]);
                }
            }
            temp.Clear();
        }