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);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void CreateConstellation(string constName, int satNumber)
        {
            AgStkObjectRoot root;
            AgUiApplication app;

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

            // define the const object
            IAgConstellation constell = (IAgConstellation)root.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, constName);

            for (int i = 0; i < satNumber; i++)
            {
                constell.Objects.Add("Satellite/" + constName + "_" + (i + 1));
            }
        }
 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);
             }
         }
     }
 }
        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");
                }
            }
        }
        //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)
            {
                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);
            }
        }
Exemplo n.º 7
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();
        }
        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 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 PopulateList()
        {
            ObjectList.Nodes.Clear();
            _data = CommonData.CurrentViewObjectData;
            string parentStr        = null;
            string parentSimpleName = null;
            int    parentCount      = 0;
            int    childCount       = 0;

            if (FilterType.SelectedIndex == 0)
            {
                for (int i = 0; i < _data.Count; i++)
                {
                    if (parentStr == null)
                    {
                        parentStr        = _data[i].SimplePath;
                        parentSimpleName = _data[i].SimpleName;
                        ObjectList.Nodes.Add(_data[i].SimpleName);
                        if (_data[i].HideShow)
                        {
                            ObjectList.Nodes[0].Checked = true;
                        }
                        parentCount++;
                    }
                    else if (_data[i].SimplePath.Contains(parentStr))
                    {
                        ObjectList.Nodes[parentCount - 1].Nodes.Add(_data[i].SimpleName);
                        if (_data[i].HideShow)
                        {
                            ObjectList.Nodes[parentCount - 1].Nodes[childCount].Checked = true;
                        }
                        childCount++;
                    }
                    else
                    {
                        parentStr        = _data[i].SimplePath;
                        parentSimpleName = _data[i].SimpleName;
                        ObjectList.Nodes.Add(_data[i].SimpleName);
                        parentCount++;
                        if (_data[i].HideShow)
                        {
                            ObjectList.Nodes[parentCount - 1].Checked = true;
                        }
                        childCount = 0;
                    }
                }
            }
            else if (FilterType.SelectedIndex == 1)
            {
                IAgExecCmdResult  result;
                StkObjectsLibrary mStkObjectsLibrary = new StkObjectsLibrary();
                List <string>     usedObjects        = new List <string>();
                result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Constellation");
                if (result[0] != "None")
                {
                    string[] constArray = result[0].Split(null);
                    foreach (var item in constArray)
                    {
                        string simplePath = mStkObjectsLibrary.SimplifiedObjectPath(item);
                        string newItem    = item.Split('/').Last();
                        if (newItem != "" && newItem != null)
                        {
                            ObjectList.Nodes.Add(newItem);
                            parentCount++;
                            IAgConstellation        currentConst = CommonData.StkRoot.GetObjectFromPath(simplePath) as IAgConstellation;
                            IAgObjectLinkCollection objects      = currentConst.Objects;
                            childCount = 0;
                            if (objects.Count != 0)
                            {
                                foreach (IAgObjectLink thing in objects)
                                {
                                    ObjectList.Nodes[parentCount - 1].Nodes.Add(thing.Name);
                                    childCount++;
                                    ObjectData element = _data.Find(p => p.SimpleName == thing.Name);
                                    if (element != null)
                                    {
                                        if (element.HideShow)
                                        {
                                            ObjectList.Nodes[parentCount - 1].Nodes[childCount - 1].Checked = true;
                                        }
                                    }
                                    usedObjects.Add(thing.Name);
                                }
                            }
                        }
                    }
                    ObjectList.Nodes.Add("No Known Constellation");
                    parentCount++;
                    childCount = 0;
                    foreach (var item in _data)
                    {
                        if (!usedObjects.Contains(item.SimpleName))
                        {
                            ObjectList.Nodes[parentCount - 1].Nodes.Add(item.SimpleName);
                            childCount++;
                            if (item.HideShow)
                            {
                                ObjectList.Nodes[parentCount - 1].Nodes[childCount - 1].Checked = true;
                            }
                        }
                    }
                }
            }
        }