コード例 #1
0
        public static void RemoveFomLegends()
        {
            //Remove all legends for previous coverage definitions that were computed
            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class CoverageDefinition");

            string[] constArray = result[0].Split(null);
            foreach (var item in constArray)
            {
                string covName = item.Split('/').Last();
                try
                {
                    CommonData.StkRoot.ExecuteCommand("VO */CoverageDefinition/" + covName + "/FigureOfMerit/" + covName + "_FOM FOMAttributes StaticLegendShow Off");
                }
                catch (Exception)
                {
                }
                try
                {
                    CommonData.StkRoot.ExecuteCommand("VO */CoverageDefinition/" + covName + "/FigureOfMerit/" + covName + "_FOM FOMAttributes DynamicLegendShow Off");
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #2
0
        public static List <string> GetWindowNames(int windowType)
        {
            List <string>    windowNames = new List <string>();
            IAgExecCmdResult result      = null;

            if (windowType == 0)
            {
                result = CommonData.StkRoot.ExecuteCommand("MapID_R *");
            }
            else
            {
                result = CommonData.StkRoot.ExecuteCommand("VO_R * MapID");
            }
            string[] windowInfo = result[0].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in windowInfo)
            {
                if (item != null && item != " ")
                {
                    string[] windowInfoParts = item.Split(new string[] { " - " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    try
                    {
                        string newName = windowInfoParts[1].Replace("\n", "");
                        windowNames.Add(newName);
                    }
                    catch (Exception)
                    {
                        windowNames.Add(windowInfoParts[1]);
                    }
                }
            }
            return(windowNames);
        }
コード例 #3
0
        //populates some form values, gets scenario timeframe
        private void InitConnection()
        {
            if (!_stkconnected)
            {
                // Get reference to running STK instance
                _uiApp = System.Runtime.InteropServices.Marshal.GetActiveObject("STK11.Application") as AgUiApplication;

                // Get our IAgStkObjectRoot interface
                _stkRoot      = _uiApp.Personality2 as AgStkObjectRoot;
                _zscen        = _stkRoot.CurrentScenario as IAgScenario;
                _stkconnected = true;

                dtp_start.Value = DateTime.ParseExact(_zscen.StartTime, ParsingFormats, null, System.Globalization.DateTimeStyles.None);
                dtp_end.Value   = DateTime.ParseExact(_zscen.StopTime, ParsingFormats, null, System.Globalization.DateTimeStyles.None);

                //btn_refresh.BackColor = Color.LimeGreen;
            }
            else
            {
                //refresh scenario times
                dtp_start.Value = DateTime.ParseExact(_zscen.StartTime, ParsingFormats, null, System.Globalization.DateTimeStyles.None);
                dtp_end.Value   = DateTime.ParseExact(_zscen.StopTime, ParsingFormats, null, System.Globalization.DateTimeStyles.None);
            }


            if (string.IsNullOrEmpty(_workingUserDirectory))
            {
                //get user directory for working purposes
                IAgExecCmdResult conRes = _stkRoot.ExecuteCommand(@"GetDirectory / UserData");
                _workingUserDirectory = conRes[0];
            }

            SafelyUpdateLabel("Connected and using: " + Environment.NewLine + _workingUserDirectory);
        }
コード例 #4
0
        public void InitProjnFile(IAgUiPluginEmbeddedControlSite Site)
        {
            SetSite(Site);
            try
            {
                IAgStkObject     Scenario       = m_root.CurrentScenario;
                IAgExecCmdResult result         = m_root.ExecuteCommand("GetDirectory / Scenario");
                string           m_scenarioPath = string.Empty;
                if (result.IsSucceeded)
                {
                    m_scenarioPath = result[0];
                }
                // ADD SCENARIO PATH TO BINDING FILE CLASS
                projInfoFile = new bindingsFile(m_scenarioPath);
            }
            catch
            {
                MessageBox.Show("STK Instance does not exist or is lost! \n Make sure STK is open and the scenario is loaded ");
                //Environment.Exit(0);
            }

            try
            {
                projInfoFile.readInfofile();
                m_root.UnitPreferences.ResetUnits();
                WPFLoginLoadSavedInfo(projInfoFile);
            }

            catch
            { }
        }
コード例 #5
0
        public static int GetWindowId(string windowName, int windowType)
        {
            //window type is 0 for 2D and 1 for 3D
            int windowId             = -1;
            IAgExecCmdResult result  = null;
            string           newItem = null;

            if (windowType == 0)
            {
                result = CommonData.StkRoot.ExecuteCommand("MapID_R *");
            }
            else
            {
                result = CommonData.StkRoot.ExecuteCommand("VO_R * MapID");
            }
            string[] windowInfo = result[0].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in windowInfo)
            {
                if (item != null && item != " ")
                {
                    newItem = item.Replace("\n", "");
                    string[] windowInfoParts = newItem.Split(new string[] { " - " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (windowInfoParts[1] == windowName)
                    {
                        windowId = Int32.Parse(windowInfoParts[0]);
                    }
                }
            }
            if (windowId == -1)
            {
                windowId = 1;
            }
            return(windowId);
        }
コード例 #6
0
        public SensorViewClass(AgStkObjectRoot root, IAgStkObject selectedSensor)
        {
            m_root = root;
            sensor = (IAgSensor)selectedSensor;
            IAgExecCmdResult result = m_root.ExecuteCommand("GetDirectory / STKHome");

            installDir       = result[0];
            pluginInstallDir = installDir + @"Plugins\SensorBoresightView";
        }
コード例 #7
0
        //Uses a satellite object to create a time component if AWB is not available
        public static void CreateTimelineComponentNoAwb(GroundEvent currentGroundEvent)
        {
            IAgSatellite sat;
            string       mes     = null;
            bool         error   = false;
            string       satName = "z" + currentGroundEvent.Id + "-TimelineObject";

            try
            {
                string cmd1 = "Timeline * TimeComponent Remove ContentView \"Event_Timeline\" \"Satellite/" + satName + " AvailabilityTimeSpan Interval\"";
                CommonData.StkRoot.ExecuteCommand(cmd1);
            }
            catch (Exception)
            {
            }

            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Satellite/" + satName);

            if (result[0] == "0")
            {
                sat = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, satName) as IAgSatellite;
            }
            else
            {
                sat = CommonData.StkRoot.GetObjectFromPath("Satellite/" + satName) as IAgSatellite;
            }
            try
            {
                ((IAgSatellite)sat).SetPropagatorType(AgEVePropagatorType.ePropagatorJ2Perturbation);
                IAgVePropagatorJ2Perturbation prop = sat.Propagator as IAgVePropagatorJ2Perturbation;
                prop.EphemerisInterval.SetExplicitInterval(currentGroundEvent.StartTime, currentGroundEvent.StopTime);
                prop.Propagate();
            }
            catch (Exception)
            {
                error = true;
                mes   = "Error with " + currentGroundEvent.Id + ": Could not update or create time component- Error with Start or Stop Time";
            }

            sat.Graphics.IsObjectGraphicsVisible = false;
            try
            {
                string cmd = "Timeline * TimeComponent Add ContentView \"Event_Timeline\" DisplayName \"" + currentGroundEvent.Id + "-Interval\" \"Satellite/" + satName + " AvailabilityTimeSpan Interval\"";
                CommonData.StkRoot.ExecuteCommand(cmd);
            }
            catch (Exception)
            {
                error = true;
                mes   = "Error with " + currentGroundEvent.Id + ": Could not update or create time component- Error with Start or Stop Time";
            }
            CommonData.StkRoot.ExecuteCommand("Timeline * Refresh");
            if (error)
            {
                MessageBox.Show(mes);
            }
        }
コード例 #8
0
        public void setViewVGT()
        {
            IAgExecCmdResult result = m_root.ExecuteCommand("VectorTool_R * Exists \"CentralBody/Sun SunView Point\"");

            if (result[0].CompareTo("1") != 0)
            {
                m_root.ExecuteCommand("VectorTool * CentralBody/Sun Create Point SunView \"Fixed in System\" Cartesian 1e13 1e13 1e13 \"CentralBody/Sun J2000\"");
            }
            m_root.ExecuteCommand("VO * ViewFromTo Normal From \"CentralBody/Sun SunView Point\" to CentralBody/Sun");
        }
コード例 #9
0
 public void ExecuteCommand(string command)
 {
     try
     {
         IAgExecCmdResult result = m_root.ExecuteCommand(command);
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Command failed: " + command);
     }
 }
コード例 #10
0
 private void checkBox_epochTime_CheckedChanged(object sender, EventArgs e)
 {
     if (checkBox_epochTime.Checked)
     {
         textBox_epochTime.Text = time_dateTime[0].ToString(m_stkDateFormat);
     }
     else
     {
         IAgExecCmdResult execResult = m_root.ExecuteCommand("GetEpoch *");
         textBox_epochTime.Text = execResult[0].ToString();
     }
 }
コード例 #11
0
        /// <summary>
        ///为场景内卫星生成轨道数据
        /// </summary>
        public void GenerateSatelliteOrbit()
        {
            //setStatus("开始生成轨道文件");
            #region 1.获取场景内的卫星及载荷资源
            List <CoScheduling.Core.Model.STKObject> stkObjects = new List <CoScheduling.Core.Model.STKObject>();
            try
            {
                stkObjects = GetSTKObject();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("获取卫星资源错误!计算终止!");
                return;
            }
            #endregion 1.获取场景内的卫星及载荷资源

            #region 2.为每颗卫星生成报告
            //设置文件夹路径
            string filePath = CoScheduling.Core.DBUtility.PubConstant.GetFilePath("Scenario") + schemeID + "Orbit\\";
            //创建文件夹
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            string strStkcmd = "";  //stk命令字符串
            foreach (CoScheduling.Core.Model.STKObject stkObject in stkObjects)
            {
                string file = filePath + stkObject.SAT_STKNAME + ".txt";
                if (!File.Exists(file))
                {
                    strStkcmd = "Report_RM */Satellite/" + stkObject.SAT_STKNAME + " Style \"LLA Position\" TimeStep 1";
                    IAgExecCmdResult resultOne = root.ExecuteCommand(strStkcmd);
                    string[]         reports   = new string[resultOne.Count - 1];
                    for (int i = 0; i < resultOne.Count - 1; i++)
                    {
                        reports[i] = resultOne[i + 1];
                    }
                    string byrow = string.Join("\r\n", reports);
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(file, false, System.Text.Encoding.GetEncoding("utf-8"));
                    try
                    {
                        sw.Write(byrow);
                        sw.Flush();
                        sw.Close();
                    }
                    catch (IOException e)
                    {
                    }
                }
            }
            #endregion
            //setStatus("轨道文件生成成功!");
        }
コード例 #12
0
        //#####################################################################
        /// <summary>
        /// STK Connect Commands(返回错误,则显示对话框)
        /// </summary>
        public static void SendCommand(string command)
        {
            IAgExecCmdResult rVal = null;

            try
            {
                rVal = stkRoot.ExecuteCommand(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + command, "Connect指令出错!");
            }
        }
コード例 #13
0
 public void ExecuteCommand(string command, bool suppressErrorMessage = false)
 {
     try
     {
         IAgExecCmdResult cmdResult = CommonData.StkRoot.ExecuteCommand(command);
     }
     catch (Exception)
     {
         if (!suppressErrorMessage)
         {
             System.Windows.Forms.MessageBox.Show("Command failed: " + command);
         }
     }
 }
コード例 #14
0
        //#####################################################################
        /// <summary>
        /// STK Connect Commands(返回错误,则显示对话框)
        /// </summary>
        public static IAgExecCmdResult SendCommand_Rlt(string command)
        {
            IAgExecCmdResult rVal = null;

            try
            {
                rVal = stkRoot.ExecuteCommand(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(rVal);
        }
コード例 #15
0
        private void PopulateCurrentPaths()
        {
            AddPathName.Items.Clear();
            IAgExecCmdResult result    = CommonData.StkRoot.ExecuteCommand("VO_R * CameraControl GetPaths");
            string           resultStr = result[0].Replace("\"", "");

            string[] pathNames = resultStr.Split(null);
            foreach (var path in pathNames)
            {
                AddPathName.Items.Add(path);
            }
            if (pathNames.Length != 0)
            {
                AddPathName.SelectedIndex = 0;
            }
        }
コード例 #16
0
        public static void CreateSubObject(GroundEvent currentGroundEvent, SubObject currentSub)
        {
            string           placeName = currentGroundEvent.Id + "-" + currentSub.Name;
            IAgPlace         place;
            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Place/" + placeName);

            if (result[0] == "0")
            {
                place = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.ePlace, placeName) as IAgPlace;
            }
            else
            {
                place = CommonData.StkRoot.GetObjectFromPath("Place/" + placeName) as IAgPlace;
            }
            place.Position.AssignGeodetic(Double.Parse(currentSub.Latitude), Double.Parse(currentSub.Longitude), 0);
            string filePath = GetImagePath(currentSub.Type);
            string cmd      = "VO */Place/" + placeName + " marker show on markertype imagefile imagefile \"" + filePath + "\" Transparent Off Size 32";

            if (filePath != null)
            {
                try
                {
                    CommonData.StkRoot.ExecuteCommand(cmd);
                }
                catch (Exception)
                {
                    MessageBox.Show("Could not update image. Check image file path in settings");
                }
            }
            string zoom = currentSub.ZoomLevel + "000";

            try
            {
                cmd = "VO */Place/" + placeName + " ModelDetail Set ModelLabel " + zoom + " MarkerLabel " + zoom + " Marker " + zoom + " Point " + zoom;
                CommonData.StkRoot.ExecuteCommand(cmd);
            }
            catch (Exception)
            {
                string mes = "Could not Modify Zoom for SubObject";
                MessageBox.Show(mes);
            }
        }
コード例 #17
0
        public static IAgStkObject GetCreateAircraft(string objectName)
        {
            IAgStkObject obj = null;

            try
            {
                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Aircraft/" + objectName);
                if (result[0] == "0")
                {
                    obj = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eAircraft, objectName);
                }
                else
                {
                    obj = CommonData.StkRoot.GetObjectFromPath("Aircraft/" + objectName);
                }
            }
            catch (Exception)
            {
            }
            return(obj);
        }
コード例 #18
0
        public static IAgStkObject GetCreateFigureOfMerit(IAgStkObject parent, string objectName)
        {
            IAgStkObject obj       = null;
            string       className = parent.ClassName;

            try
            {
                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */" + className + "/" + parent.InstanceName + "/FigureOfMerit/" + objectName);
                if (result[0] == "0")
                {
                    obj = parent.Children.New(AgESTKObjectType.eFigureOfMerit, objectName);
                }
                else
                {
                    obj = CommonData.StkRoot.GetObjectFromPath(className + "/" + parent.InstanceName + "/FigureOfMerit/" + objectName);
                }
            }
            catch (Exception)
            {
            }
            return(obj);
        }
コード例 #19
0
        public bool TryExecuteCommand(string command, out string result)
        {
            bool success;

            result = "";
            try
            {
                IAgExecCmdResult cmdResult = CommonData.StkRoot.ExecuteCommand(command);
                if (cmdResult.Count > 0)
                {
                    for (int i = 0; i < cmdResult.Count; i++)
                    {
                        result += cmdResult[i];
                    }
                }
                success = cmdResult.IsSucceeded;
            }
            catch (Exception ex)
            {
                result  = ex.Message;
                success = false;
            }
            return(success);
        }
コード例 #20
0
        public static void CreateGroundEvent(GroundEvent currentGroundEvent)
        {
            IAgPlace         place;
            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Place/" + currentGroundEvent.Id);

            if (result[0] == "0")
            {
                place = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.ePlace, currentGroundEvent.Id) as IAgPlace;
            }
            else
            {
                place = CommonData.StkRoot.GetObjectFromPath("Place/" + currentGroundEvent.Id) as IAgPlace;
            }
            place.Position.AssignGeodetic(Double.Parse(currentGroundEvent.Latitude), Double.Parse(currentGroundEvent.Longitude), 0);
            string filePath = GetImagePath(currentGroundEvent.SsrType);
            string cmd      = "VO */Place/" + currentGroundEvent.Id + " marker show on markertype imagefile imagefile \"" + filePath + "\" Transparent Off Size 32";

            if (filePath != null)
            {
                try
                {
                    CommonData.StkRoot.ExecuteCommand(cmd);
                }
                catch (Exception)
                {
                    MessageBox.Show("Could not update image. Check image file path in settings");
                }
            }
            if (currentGroundEvent.StartTime == "Unspecified" || currentGroundEvent.StopTime == "Unspecified")
            {
            }
            else
            {
                CreateTimelineComponent(currentGroundEvent);
            }
        }
コード例 #21
0
        public string GetScenarioDirectory()
        {
            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("GetDirectory / Scenario");

            return(result[0].ToString());
        }
コード例 #22
0
        public List <Waypoint> BoundingParallelTrackWaypointGenerator(
            string areaTargetPath, double speed, double altitude, double turnRadius, SwathWidthType swathType, double swathParameter)
        {
            List <Waypoint> waypoints = new List <Waypoint>();

            IAgStkObject         areaTarget       = root.GetObjectFromPath(areaTargetPath);
            IAgDataProviderGroup boundingProvider = areaTarget.DataProviders["Bounding Rectangle"] as IAgDataProviderGroup;
            IAgDataPrvFixed      dpElements       = boundingProvider.Group["Corner Points"] as IAgDataPrvFixed;
            IAgDrResult          atDataPrvResult  = dpElements.Exec();

            Array atLats = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lat").GetValues();
            Array atLons = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lon").GetValues();

            IAgExecCmdResult cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " +
                                                             atLats.GetValue(0).ToString() + " " + atLons.GetValue(0).ToString()
                                                             + " " + atLats.GetValue(1).ToString() + " " + atLons.GetValue(1).ToString());

            double regionWidth = double.Parse(cmdResult[0]);

            int numPasses = DetermineNumPasses(swathType, swathParameter, altitude, regionWidth, null);

            if (numPasses < 1)
            {
                MessageBox.Show("No Passes.  Try Adjusting Swath Width Parameters");
                return(waypoints);
            }

            double topStepLat    = (((double)atLats.GetValue(1) - (double)atLats.GetValue(0)) / (double)numPasses);
            double bottomStepLat = (((double)atLats.GetValue(2) - (double)atLats.GetValue(3)) / (double)numPasses);
            double topStepLon    = (((double)atLons.GetValue(1) - (double)atLons.GetValue(0)) / (double)numPasses);
            double bottomStepLon = (((double)atLons.GetValue(2) - (double)atLons.GetValue(3)) / (double)numPasses);

            double topLat0    = (double)atLats.GetValue(0);
            double topLon0    = (double)atLons.GetValue(0);
            double bottomLat0 = (double)atLats.GetValue(3);
            double bottomLon0 = (double)atLons.GetValue(3);

            Waypoint waypoint = new Waypoint();

            for (int i = 0; i <= numPasses; ++i)
            {
                int test = i % 2;

                double latTopEnroute = topLat0 + (double)i * topStepLat;
                double lonTopEnroute = topLon0 + (double)i * topStepLon;

                double latBottomEnroute = bottomLat0 + (double)i * bottomStepLat;
                double lonBottomEnroute = bottomLon0 + (double)i * bottomStepLon;


                if (test == 0)
                {
                    waypoint                 = new Waypoint();
                    waypoint.Latitude        = latTopEnroute;
                    waypoint.Longitude       = lonTopEnroute;
                    waypoint.Altitude        = altitude;
                    waypoint.SurfaceAltitude = 0;
                    waypoint.Speed           = speed;
                    waypoint.TurnRadius      = turnRadius;
                    waypoints.Add(waypoint);

                    waypoint            = new Waypoint();
                    waypoint.Latitude   = latBottomEnroute;
                    waypoint.Longitude  = lonBottomEnroute;
                    waypoint.Altitude   = altitude;
                    waypoint.Speed      = speed;
                    waypoint.TurnRadius = turnRadius;
                    waypoints.Add(waypoint);
                }
                else
                {
                    waypoint                 = new Waypoint();
                    waypoint.Latitude        = latBottomEnroute;
                    waypoint.Longitude       = lonBottomEnroute;
                    waypoint.Altitude        = altitude;
                    waypoint.SurfaceAltitude = 0;
                    waypoint.Speed           = speed;
                    waypoint.TurnRadius      = turnRadius;
                    waypoints.Add(waypoint);

                    waypoint            = new Waypoint();
                    waypoint.Latitude   = latTopEnroute;
                    waypoint.Longitude  = lonTopEnroute;
                    waypoint.Altitude   = altitude;
                    waypoint.Speed      = speed;
                    waypoint.TurnRadius = turnRadius;
                    waypoints.Add(waypoint);
                }
            }

            return(waypoints);
        }
コード例 #23
0
        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");
                }
            }
        }
コード例 #24
0
        private void parseFile()
        {
//#if DEBUG
//            System.Diagnostics.Debugger.Break();
//#endif
            //set the epoch time to the scenario epoch time
            IAgExecCmdResult execResult = m_root.ExecuteCommand("GetEpoch *");

            textBox_epochTime.Text = execResult[0].ToString();


            //clear the list arrays before each run
            Time.Clear();
            time_dateTime.Clear();
            Lat.Clear();
            Lon.Clear();
            Alt.Clear();
            LatRate.Clear();
            LonRate.Clear();
            AltRate.Clear();
            Yaw.Clear();
            Pitch.Clear();
            Roll.Clear();
            textBox_formattedData.Clear();
            CalcScalar.Clear();

            //get the data from the text box
            this.textBox_data.Text = fileContent;

            //create an array of strings for each line
            string[] lines = fileContent.Split('\n');

            int lineCounter  = 1;
            int epochCounter = 1;

            //set the column delimiter

            char delimiter = ',';

            if (comboBox_delimiters.Text == "Comma")
            {
                delimiter = ',';
            }
            else if (comboBox_delimiters.Text == "Tab")
            {
                delimiter = '\t';
            }
            else if (comboBox_delimiters.Text == "Space")
            {
                delimiter = ' ';
            }
            else if (comboBox_delimiters.Text == "Semicolon")
            {
                delimiter = ';';
            }
            else if (comboBox_delimiters.Text == "Period")
            {
                delimiter = '.';
            }

            //Read the file to find the number of columns

            //loop through each line in the data file

            foreach (string line in lines)
            {
                //split each line into elements in an array by the selected delimiter
                string[] entries = line.Split(delimiter);

                //make sure that there are at least 2 columns of data
                if (entries.Length > 1)
                {
                    //parse the data for the user selected columns and store into list arrays

                    if (entries.Length < 4 && comboBox_outputType.Text == "Ephemeris")
                    {
                        MessageBox.Show("Not enough columns of data (" + entries.Length + ") to create an Ephemeris file.\n\n  Please change output type.");

                        return;



                        //if (MessageBox.Show("Not enough columns of data to create an Ephemeris file.\n\n  Would you like to change file type to Calculation Scalar?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                        //{
                        //    //m_pEmbeddedControlSite.Window.Close();
                        //}
                        //else
                        //{
                        //    //comboBox_outputType.Text = "Calculation_Scalar";
                        //    comboBox_outputType.SelectedItem = "Calculation_Scalar";

                        //}
                    }

                    if (comboBox_units_1.Text == "Date Time")
                    {
                        //try to parse date time, and if that doesn't work, try to use epoch seconds

                        try
                        {
                            DateTime time = DateTime.Parse(entries[Convert.ToInt32(comboBox_col_1.Text) - 1]);

                            string time_string = System.Convert.ToString(time);
                            Time.Add(time_string);
                            time_dateTime.Add(time);

                            //populate the epoch text box on the user form with the first time in the file.
                            if (epochCounter < 2 && checkBox_epochTime.Checked == true)
                            {
                                string epochTime = time.ToString(m_stkDateFormat);
                                textBox_epochTime.Text = epochTime;
                                epochCounter++;
                            }
                        }
                        catch (FormatException)
                        {
                            if (MessageBox.Show("Unable to read time in line " + lineCounter.ToString() + ":\n\n" + entries[Convert.ToInt32(comboBox_col_1.Text) - 1] + "\n\n  Would you like to change units to epoch seconds?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                //m_pEmbeddedControlSite.Window.Close();
                            }
                            else
                            {
                                comboBox_units_1.Text = "Epoch Seconds";
                            }
                        }
                    }

                    if (comboBox_units_1.Text == "Epoch Seconds")
                    {
                        try
                        {
                            Time.Add(entries[Convert.ToInt32(comboBox_col_1.Text) - 1]);
                        }
                        catch (FormatException)
                        {
                            if (MessageBox.Show("Unable to read time in line " + lineCounter.ToString() + ":\n\n" + entries[Convert.ToInt32(comboBox_col_1.Text) - 1] + "\n\n  Would you like to change units to epoch seconds?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                            }
                            else
                            {
                                comboBox_units_1.Text = "Date Time";
                            }
                        }
                    }

                    if (comboBox_outputType.Text == "Calculation_Scalar")
                    {
                        try
                        {
                            double calc1 = Double.Parse(entries[Convert.ToInt32(comboBox_col_2.Text) - 1]);
                            CalcScalar.Add(calc1.ToString());
                        }
                        catch (Exception ex)
                        {
                            if (MessageBox.Show("Unable to read line " + lineCounter.ToString() + ":\n\n" + line + "\n\n  Would you like to ignore line and continue?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                            else
                            {
                            }
                        }
                    }
                    else if (comboBox_outputType.Text == "Ephemeris")
                    {
                        try
                        {
                            double pos1 = Double.Parse(entries[Convert.ToInt32(comboBox_col_2.Text) - 1]);
                            double pos2 = Double.Parse(entries[Convert.ToInt32(comboBox_col_3.Text) - 1]);
                            double pos3 = Double.Parse(entries[Convert.ToInt32(comboBox_col_4.Text) - 1]);
                            double mot1 = Double.Parse(entries[Convert.ToInt32(comboBox_col_5.Text) - 1]);
                            double mot2 = Double.Parse(entries[Convert.ToInt32(comboBox_col_6.Text) - 1]);
                            double mot3 = Double.Parse(entries[Convert.ToInt32(comboBox_col_7.Text) - 1]);

                            Lat.Add(pos1.ToString());
                            Lon.Add(pos2.ToString());
                            Alt.Add(pos3.ToString());
                            LatRate.Add(mot1.ToString());
                            LonRate.Add(mot2.ToString());
                            AltRate.Add(mot3.ToString());
                        }
                        catch (Exception ex)
                        {
                            if (MessageBox.Show("Unable to read line " + lineCounter.ToString() + ":\n\n" + line + "\n\n  Would you like to ignore line and continue?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                            else
                            {
                            }
                        }
                    }

                    else if (comboBox_outputType.Text == "Attitude")
                    {
                        try
                        {
                            double ang1 = Double.Parse(entries[Convert.ToInt32(comboBox_col_2.Text) - 1]);
                            double ang2 = Double.Parse(entries[Convert.ToInt32(comboBox_col_3.Text) - 1]);
                            double ang3 = Double.Parse(entries[Convert.ToInt32(comboBox_col_4.Text) - 1]);

                            Yaw.Add(ang1.ToString());
                            Pitch.Add(ang2.ToString());
                            Roll.Add(ang3.ToString());
                        }
                        catch (Exception ex)
                        {
                            if (MessageBox.Show("Unable to read line " + lineCounter.ToString() + ":\n\n" + line + "\n\n  Would you like to ignore line and continue?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                            else
                            {
                            }
                        }
                    }
                }

                lineCounter++;
            }

            //MessageBox.Show("format data");

            //loop through the list arrays and populate the formatted text box with the appropriate data for the user selected data format.

            for (int i = 0; i < Time.Count; i++)
            {
                string time = (Time[i] + "                             ").Substring(0, 22);

                if (comboBox_dataFormat.Text == "Time_LLA")
                {
                    string lat      = ("  " + Lat[i] + "                             ").Substring(0, 9);
                    string lon      = ("  " + Lon[i] + "                             ").Substring(0, 9);
                    string alt      = ("  " + Alt[i] + "                             ").Substring(0, 9);
                    string dataLine = String.Format(time + lat + lon + alt);
                    textBox_formattedData.AppendText(dataLine + "\n");
                }
                else if (comboBox_dataFormat.Text == "Time_LLA_Rates")
                {
                    string lat      = ("  " + Lat[i] + "                             ").Substring(0, 9);
                    string lon      = ("  " + Lon[i] + "                             ").Substring(0, 9);
                    string alt      = ("  " + Alt[i] + "                             ").Substring(0, 9);
                    string lat_r    = ("  " + LatRate[i] + "                             ").Substring(0, 9);
                    string lon_r    = ("  " + LonRate[i] + "                             ").Substring(0, 9);
                    string alt_r    = ("  " + AltRate[i] + "                             ").Substring(0, 9);
                    string dataLine = String.Format(time + lat + lon + alt + lat_r + lon_r + alt_r);
                    textBox_formattedData.AppendText(dataLine + "\n");
                }
                else if (comboBox_dataFormat.Text == "Time_YPR")
                {
                    string yaw      = ("  " + Yaw[i] + "                             ").Substring(0, 9);
                    string pitch    = ("  " + Pitch[i] + "                             ").Substring(0, 9);
                    string roll     = ("  " + Roll[i] + "                             ").Substring(0, 9);
                    string dataLine = String.Format(time + yaw + pitch + roll);
                    textBox_formattedData.AppendText(dataLine + "\n");
                }
                else if (comboBox_dataFormat.Text == "Calculation_Scalar")
                {
                    string calcScalar = ("  " + CalcScalar[i] + "                             ").Substring(0, 9);
                    string dataLine   = String.Format(time + calcScalar);
                    textBox_formattedData.AppendText(dataLine + "\n");
                }
            }

            textBox_formattedData.SelectionStart = 0;
            textBox_formattedData.ScrollToCaret();
        }
コード例 #25
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            int check = FieldCheck();

            if (check == 0)
            {
                IAgStkObject obj = null;
                IAgStkObject tar = null;
                foreach (var observer in CommonData.SelectedObservers)
                {
                    foreach (var target in CommonData.SelectedTargets)
                    {
                        if (observer != target)
                        {
                            if (TargetType.SelectedIndex == 0)
                            {
                                tar = CommonData.StkRoot.GetObjectFromPath("Satellite/" + target);
                            }
                            else if (TargetType.SelectedIndex == 1)
                            {
                                tar = CommonData.StkRoot.GetObjectFromPath("Missile/" + target);
                            }
                            else if (TargetType.SelectedIndex == 2)
                            {
                                tar = CommonData.StkRoot.GetObjectFromPath("Aircraft/" + target);
                            }

                            if (ObserverType.SelectedIndex == 0)
                            {
                                obj = CommonData.StkRoot.GetObjectFromPath("Satellite/" + observer);
                            }
                            else if (ObserverType.SelectedIndex == 1)
                            {
                                obj = CommonData.StkRoot.GetObjectFromPath("Facility/" + observer);
                            }
                            else
                            {
                                IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Sensor");
                                if (result[0] != "None")
                                {
                                    string[] sensorArray = result[0].Split(null);
                                    foreach (var item in sensorArray)
                                    {
                                        if (item.Contains(observer))
                                        {
                                            int scenarioPos          = item.LastIndexOf("/Scenario/");
                                            int scenarioNameSlashPos = item.IndexOf("/", scenarioPos + 10);
                                            item.Remove(0, scenarioNameSlashPos);
                                            obj = CommonData.StkRoot.GetObjectFromPath(item);
                                        }
                                    }
                                }
                            }
                            IAgCrdnProvider            objVgtPrv  = obj.Vgt;
                            IAgCrdnProvider            tarVgt     = tar.Vgt;
                            IAgCrdnAngleBetweenVectors angle      = null;
                            IAgCrdnVectorDisplacement  dispVector = AWBFunctions.GetCreateDisplacementVector(objVgtPrv, objVgtPrv.Points["Center"], tarVgt.Points["Center"], "To_" + target);

                            //Create either solar phase or beta angle depending on user specified selection
                            string angleName = null;
                            if (AngleType.SelectedIndex == 0)
                            {
                                angleName = "To_" + target + "BetaAngle";
                                angle     = AWBFunctions.GetCreateAngleBetweenVectors(objVgtPrv, dispVector as IAgCrdnVector, objVgtPrv.Vectors["Sun"], angleName, "");
                            }
                            else if (AngleType.SelectedIndex == 1)
                            {
                                angleName = "To_" + target + "SolarPhaseAngle";
                                angle     = AWBFunctions.GetCreateAngleBetweenVectors(objVgtPrv, dispVector as IAgCrdnVector, tarVgt.Vectors["Sun"], angleName, "");
                            }
                            //Create Calc Scalar of angle
                            IAgCrdnCalcScalarAngle cScalar = AWBFunctions.GetCreateAngleCalcScalar(objVgtPrv, angle as IAgCrdnAngle, angleName);

                            //If a conditional is requested, then create it here
                            if (EnableConstraint.Checked)
                            {
                                IAgCrdnConditionScalarBounds condition = AWBFunctions.GetCreateConditionScalarBounds(objVgtPrv, cScalar as IAgCrdnCalcScalar, angleName + "_Condition", AgECrdnConditionThresholdOption.eCrdnConditionThresholdOptionInsideMinMax);
                                AWBFunctions.SetAngleConditionScalarBounds(condition, Double.Parse(ConstraintMin.Text), Double.Parse(ConstraintMax.Text));
                            }
                        }
                    }
                }
                MessageBox.Show("Component Creation Completed");
            }
        }
コード例 #26
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();
        }
コード例 #27
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            IAgStkObject obj = null;
            IAgStkObject tar = null;

            foreach (var observer in CommonData.SelectedObservers)
            {
                foreach (var target in CommonData.SelectedTargets)
                {
                    if (observer != target)
                    {
                        if (TargetType.SelectedIndex == 0)
                        {
                            tar = CommonData.StkRoot.GetObjectFromPath("Satellite/" + target);
                        }
                        else if (TargetType.SelectedIndex == 1)
                        {
                            tar = CommonData.StkRoot.GetObjectFromPath("Missile/" + target);
                        }
                        else if (TargetType.SelectedIndex == 2)
                        {
                            tar = CommonData.StkRoot.GetObjectFromPath("Aircraft/" + target);
                        }

                        if (ObserverType.SelectedIndex == 0)
                        {
                            obj = CommonData.StkRoot.GetObjectFromPath("Satellite/" + observer);
                        }
                        else if (ObserverType.SelectedIndex == 1)
                        {
                            obj = CommonData.StkRoot.GetObjectFromPath("Facility/" + observer);
                        }
                        else
                        {
                            IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Sensor");
                            if (result[0] != "None")
                            {
                                string[] sensorArray = result[0].Split(null);
                                foreach (var item in sensorArray)
                                {
                                    if (item.Contains(observer))
                                    {
                                        int scenarioPos          = item.LastIndexOf("/Scenario/");
                                        int scenarioNameSlashPos = item.IndexOf("/", scenarioPos + 10);
                                        item.Remove(0, scenarioNameSlashPos);
                                        obj = CommonData.StkRoot.GetObjectFromPath(item);
                                    }
                                }
                            }
                        }
                        IAgCrdnProvider           objVgtPrv = obj.Vgt;
                        IAgCrdnProvider           tarVgt    = tar.Vgt;
                        IAgCrdnVectorDisplacement dispVector;
                        if (objVgtPrv.Vectors.Contains("To_" + target))
                        {
                            dispVector = objVgtPrv.Vectors["To_" + target] as IAgCrdnVectorDisplacement;
                        }
                        else
                        {
                            dispVector = objVgtPrv.Vectors.Factory.CreateDisplacementVector("To_" + target, objVgtPrv.Points["Center"], tarVgt.Points["Center"]);
                        }
                        if (!objVgtPrv.Angles.Contains("To_" + target + "SolarPhaseAngle"))
                        {
                            IAgCrdnAngleBetweenVectors angle = (IAgCrdnAngleBetweenVectors)objVgtPrv.Angles.Factory.Create("To_" + target + "SolarPhaseAngle", "", AgECrdnAngleType.eCrdnAngleTypeBetweenVectors);
                            angle.FromVector.SetVector(dispVector as IAgCrdnVector);
                            angle.ToVector.SetVector(objVgtPrv.Vectors["Sun"]);
                        }
                    }
                }
            }
        }