示例#1
0
        public static object[] GetTimeOfMinAndValue(IAgCrdnVector vector)
        {
            IAgStkObject parentObject = StkAssistant.Root.GetObjectFromPath("*/" + (vector as IAgCrdn).QualifiedPath.Split(' ')[0]);
            //Create new scalar to monitor Vector Magnitude value
            string            newVgtBaseName        = (vector as IAgCrdn).Name;
            string            scalarVectorMagName   = StkAssistant.GetUniqueAWBName(newVgtBaseName, parentObject, AgECrdnKind.eCrdnKindCalcScalar);
            IAgCrdnCalcScalar vectorMagnitudeScalar = parentObject.Vgt.CalcScalars.Factory.Create(
                scalarVectorMagName, "temp", AgECrdnCalcScalarType.eCrdnCalcScalarTypeVectorMagnitude);

            (vectorMagnitudeScalar as IAgCrdnCalcScalarVectorMagnitude).InputVector = vector;

            IAgCrdnCalcScalar minRange       = (vectorMagnitudeScalar as IAgCrdn).EmbeddedComponents[(vectorMagnitudeScalar as IAgCrdn).Name + ".Min"] as IAgCrdnCalcScalar;
            IAgCrdnEvent      timeOfMinRange = (vectorMagnitudeScalar as IAgCrdn).EmbeddedComponents[(vectorMagnitudeScalar as IAgCrdn).Name + ".TimeOfMin"] as IAgCrdnEvent;
            string            tca            = timeOfMinRange.FindOccurrence().Epoch.ToString();
            double            minRangeValue  = minRange.Evaluate(tca).Value;

            return(new object[] { tca, minRangeValue });
        }
示例#2
0
        private void Link_Click(object sender, EventArgs e)
        {
            if (IncrementCheck.Checked && String.IsNullOrWhiteSpace(IncrementStepValue.Text))
            {
                MessageBox.Show("IncrementStep Value Required");
            }
            else if (Events.SelectedIndex == -1)
            {
                MessageBox.Show("Please select Interval List");
            }
            else
            {
                int index = Events.SelectedIndex;
                IAgCrdnEventIntervalList currentList;
                List <string>            startTimes = new List <string>();
                List <string>            stopTimes  = new List <string>();
                string listName;

                if (cbStkObjects.Text.Contains("Access"))
                {
                    currentList = accessEventIntervalsCollections[index];
                    IAgCrdn currentListRe = accessEventIntervalsCollections[index] as IAgCrdn;
                    listName = currentListRe.Name;
                }
                else
                {
                    currentList = eventIntervalsCollections[index];
                    IAgCrdn currentListRe = eventIntervalsCollections[index] as IAgCrdn;
                    listName = currentListRe.Name;
                }
                IAgCrdnIntervalListResult intervals = currentList.FindIntervals();
                int numIntervals = intervals.Intervals.Count;
                for (int i = 0; i < numIntervals; i++)
                {
                    IAgCrdnInterval interval = intervals.Intervals[i];
                    string          startStr = interval.Start.ToString();
                    string          stopStr  = interval.Stop.ToString();
                    startTimes.Add(startStr);
                    stopTimes.Add(stopStr);
                }
                CommonData.sectionList[CommonData.selectedArtic].linkedToList = true;
                string linkedText;
                string line1 = "BEGIN SMARTEPOCH \n";
                string line2 = "BEGIN EVENT \n";
                string line3 = "Type EVENT_LINKTO \n";
                string line4 = null;
                string line5 = null;
                linkedText = line1 + line2 + line3;


                if (typeEnum == 0)
                {
                    if (cbStkObjects.Text.Contains("Access"))
                    {
                        for (int i = 0; i < startTimes.Count; i++)
                        {
                            string name = "ArticCreatorList_" + listName + "_" + "StartTime" + i.ToString();
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name);
                            IAgCrdnEvent timeEvent = null;
                            if (access.Vgt.Events.Contains(name))
                            {
                                foreach (IAgCrdnEvent @event in access.Vgt.Events)
                                {
                                    // All events implement IAgCrdn interface which provides
                                    // information about the event instance and its type.
                                    IAgCrdn crdn = @event as IAgCrdn;
                                    if (crdn.Name == name)
                                    {
                                        timeEvent = @event;
                                    }
                                }
                            }
                            else
                            {
                                timeEvent = access.Vgt.Events.Factory.CreateEventEpoch(name, "Description");
                            }
                            IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch;
                            asEpoch.Epoch = startTimes[i];
                            IAgCrdn currentEvent = (IAgCrdn)timeEvent;
                            string  eventName    = currentEvent.Name;
                            string  pathStr      = currentEvent.Path;
                            line4 = "Name " + eventName + " \n";
                            line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n";
                            string line6 = "END EVENT" + " \n";
                            string line7 = "END SMARTEPOCH" + " \n";

                            string linkedTextFinal = linkedText + line4 + line5 + line6 + line7;
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < startTimes.Count; i++)
                        {
                            string name = "ArticCreatorList_" + listName + "_" + "StartTime" + i.ToString();
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name);
                            IAgCrdnEvent timeEvent = null;
                            if (obj.Vgt.Events.Contains(name))
                            {
                                foreach (IAgCrdnEvent @event in obj.Vgt.Events)
                                {
                                    // All events implement IAgCrdn interface which provides
                                    // information about the event instance and its type.
                                    IAgCrdn crdn = @event as IAgCrdn;
                                    if (crdn.Name == name)
                                    {
                                        timeEvent = @event;
                                    }
                                }
                            }
                            else
                            {
                                timeEvent = obj.Vgt.Events.Factory.CreateEventEpoch(name, "Description");
                            }

                            IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch;
                            asEpoch.Epoch = startTimes[i];

                            IAgCrdn currentEvent = (IAgCrdn)timeEvent;
                            string  eventName    = currentEvent.Name;
                            string  pathStr      = currentEvent.Path;
                            line4 = "Name " + eventName + " \n";
                            line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n";
                            string line6 = "END EVENT" + " \n";
                            string line7 = "END SMARTEPOCH" + " \n";

                            string linkedTextFinal = linkedText + line4 + line5 + line6 + line7;
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal);
                        }
                    }
                }
                else if (typeEnum == 1)
                {
                    if (cbStkObjects.Text.Contains("Access"))
                    {
                        for (int i = 0; i < stopTimes.Count; i++)
                        {
                            string name = "ArticCreatorList_" + listName + "_" + "StopTime" + i.ToString();
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name);
                            IAgCrdnEvent timeEvent = null;
                            if (access.Vgt.Events.Contains(name))
                            {
                                foreach (IAgCrdnEvent @event in access.Vgt.Events)
                                {
                                    // All events implement IAgCrdn interface which provides
                                    // information about the event instance and its type.
                                    IAgCrdn crdn = @event as IAgCrdn;
                                    if (crdn.Name == name)
                                    {
                                        timeEvent = @event;
                                    }
                                }
                            }
                            else
                            {
                                timeEvent = access.Vgt.Events.Factory.CreateEventEpoch(name, "Description");
                            }
                            IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch;
                            asEpoch.Epoch = stopTimes[i];

                            IAgCrdn currentEvent = (IAgCrdn)timeEvent;
                            string  eventName    = currentEvent.Name;
                            string  pathStr      = currentEvent.Path;
                            line4 = "Name " + eventName + " \n";
                            line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n";
                            string line6 = "END EVENT" + " \n";
                            string line7 = "END SMARTEPOCH" + " \n";

                            string linkedTextFinal = linkedText + line4 + line5 + line6 + line7;
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < startTimes.Count; i++)
                        {
                            string name = "ArticCreatorList_" + listName + "_" + "StopTime" + i.ToString();
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name);
                            IAgCrdnEvent timeEvent = null;
                            if (obj.Vgt.Events.Contains(name))
                            {
                                foreach (IAgCrdnEvent @event in obj.Vgt.Events)
                                {
                                    // All events implement IAgCrdn interface which provides
                                    // information about the event instance and its type.
                                    IAgCrdn crdn = @event as IAgCrdn;
                                    if (crdn.Name == name)
                                    {
                                        timeEvent = @event;
                                    }
                                }
                            }
                            else
                            {
                                timeEvent = obj.Vgt.Events.Factory.CreateEventEpoch(name, "Description");
                            }
                            IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch;
                            asEpoch.Epoch = stopTimes[i];
                            IAgCrdn currentEvent = (IAgCrdn)timeEvent;
                            string  eventName    = currentEvent.Name;
                            string  pathStr      = currentEvent.Path;
                            line4 = "Name " + eventName + " \n";
                            line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n";
                            string line6 = "END EVENT" + " \n";
                            string line7 = "END SMARTEPOCH" + " \n";

                            string linkedTextFinal = linkedText + line4 + line5 + line6 + line7;
                            CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal);
                        }
                    }
                }
                if (IncrementCheck.Checked)
                {
                    CommonData.sectionList[CommonData.selectedArtic].isIncremented = true;
                    int    numSections     = intervals.Intervals.Count;
                    double startValueOG    = Convert.ToDouble(CommonData.sectionList[CommonData.selectedArtic].startValue);
                    double stepValueDouble = Convert.ToDouble(IncrementStepValue.Text);
                    for (int i = 0; i < numSections; i++)
                    {
                        LinkedListSection current = new LinkedListSection();

                        current.startValue = Convert.ToString((startValueOG + i * stepValueDouble));
                        current.endValue   = Convert.ToString((startValueOG + (i + 1) * stepValueDouble));

                        current.startTimeValue = CommonData.sectionList[CommonData.selectedArtic].startTimeValue;
                        current.durationValue  = CommonData.sectionList[CommonData.selectedArtic].durationValue;
                        current.deadbandValue  = CommonData.sectionList[CommonData.selectedArtic].deadbandValue;
                        current.accelValue     = CommonData.sectionList[CommonData.selectedArtic].accelValue;
                        current.dutyValue      = CommonData.sectionList[CommonData.selectedArtic].dutyValue;
                        current.decelValue     = CommonData.sectionList[CommonData.selectedArtic].decelValue;
                        current.periodValue    = CommonData.sectionList[CommonData.selectedArtic].periodValue;
                        current.sectionName    = CommonData.sectionList[CommonData.selectedArtic].sectionName;
                        string section = ArticFunctions.CreateSection(CommonData.sectionList[CommonData.selectedArtic].objectName, CommonData.sectionList[CommonData.selectedArtic].articName, current.startTimeValue, current.durationValue, current.startValue, current.endValue, current.deadbandValue, current.accelValue, current.decelValue, current.dutyValue, current.periodValue, current.sectionName);
                        current.sectionText = section;

                        CommonData.sectionList[CommonData.selectedArtic].linkedListSections.Add(current);
                    }
                }
                ArticFunctions.CreateFile(CommonData.fileStr);
                this.Close();
            }
        }
        //get start times from event or interval list
        public static List <double> GetStartTimes(Section item)
        {
            List <IAgCrdn> events     = new List <IAgCrdn>();
            List <double>  startTimes = new List <double>();

            if (item.isLinked && !item.linkedToList)
            {
                events = GetAllEventInstances();
                int eventCount = events.Count;

                for (int i = 0; i < eventCount; i++)
                {
                    IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[i];
                    if (events[i].Name == item.linkTimeInstanceName)
                    {
                        IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence();
                        double epoch    = epochResult.Epoch;
                        string epochStr = epoch.ToString();
                        try
                        {
                            string epochInEpSec = CommonData.StkRoot.ExecuteCommand("Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"").ToString();
                            if (startTimes.Contains(Convert.ToDouble(epochInEpSec)))
                            {
                            }
                            else
                            {
                                startTimes.Add(Convert.ToDouble(epochInEpSec));
                            }
                        }
                        catch (Exception)
                        {
                            if (startTimes.Contains(epoch))
                            {
                            }
                            else
                            {
                                startTimes.Add(epoch);
                            }
                        }
                    }
                }
            }
            else if (item.linkedToList)
            {
                events = GetAllEventInstances();
                int eventCount = events.Count;
                for (int i = 0; i < item.linkedToListInstantNames.Count; i++)
                {
                    for (int j = 0; j < eventCount; j++)
                    {
                        IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[j];
                        if (events[j].Name == item.linkedToListInstantNames[i])
                        {
                            IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence();
                            double epoch    = epochResult.Epoch;
                            string epochStr = epoch.ToString();
                            try
                            {
                                string epochStrTry = CommonData.StkRoot.ExecuteCommand("Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"").ToString();
                                if (startTimes.Contains(Convert.ToDouble(epochStrTry)))
                                {
                                }
                                else
                                {
                                    startTimes.Add(Convert.ToDouble(epochStrTry));
                                }
                            }
                            catch (Exception)
                            {
                                if (startTimes.Contains(epoch))
                                {
                                }
                                else
                                {
                                    startTimes.Add(epoch);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                startTimes.Add(Convert.ToDouble(item.startTimeValue));
            }
            //sort start times in ascending order
            double temp1 = 0.0;
            double temp2 = 0.0;

            for (int i = 0; i < startTimes.Count; i++)
            {
                temp1 = startTimes[i];
                for (int j = 0; j < startTimes.Count; j++)
                {
                    temp2 = startTimes[j];
                    if (temp1 == temp2)
                    {
                    }
                    else if (temp2 < temp1 && j > i)
                    {
                        startTimes[i] = temp2;
                        startTimes[j] = temp1;
                        temp1         = startTimes[i];
                    }
                    else
                    {
                    }
                }
            }


            return(startTimes);
        }
        //get start time and timestep to pull attitude data
        public static Tuple <int, double, double> GetStartTimeAndMinimumTimeStep()
        {
            int            count            = 0;
            double         timeStep1        = 1.0;
            double         timeStepCurrent  = 1.0;
            double         startTime        = 10000000000;
            double         currentStartTime = 0.0;
            string         startTimeStr     = null;
            List <IAgCrdn> events           = new List <IAgCrdn>();
            IAgCrdn        accessEvents;

            foreach (Section item in CommonData.sectionList)
            {
                count++;
                if (item.linkedToAttitude && item.objectName == CommonData.MainBody)
                {
                    if (item.isLinked && !item.linkedToList)
                    {
                        events = GetAllEventInstances();
                        int eventCount = events.Count;

                        for (int i = 0; i < eventCount; i++)
                        {
                            IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[i];
                            if (events[i].Name == item.linkTimeInstanceName)
                            {
                                IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence();
                                double epoch    = epochResult.Epoch;
                                string epochStr = epoch.ToString();
                                try
                                {
                                    string cmd          = "Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"";
                                    string epochInEpSec = CommonData.StkRoot.ExecuteCommand(cmd).ToString();
                                    currentStartTime = Convert.ToDouble(epochInEpSec);
                                    timeStepCurrent  = GetTimestep(epochInEpSec);
                                }
                                catch (Exception)
                                {
                                    currentStartTime = Convert.ToDouble(epoch);

                                    timeStepCurrent = GetTimestep(epochStr);
                                }
                            }
                        }
                    }
                    else if (item.linkedToList)
                    {
                        double listCurrentStart    = startTime;
                        double listCurrentTimestep = timeStepCurrent;
                        events = GetAllEventInstances();
                        int eventCount = events.Count;
                        for (int i = 0; i < item.linkedToListInstantNames.Count; i++)
                        {
                            for (int j = 0; j < eventCount; j++)
                            {
                                IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[j];
                                if (events[j].Name == item.linkedToListInstantNames[i])
                                {
                                    IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence();
                                    double epoch    = epochResult.Epoch;
                                    string epochStr = epoch.ToString();
                                    try
                                    {
                                        string cmd = "Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"";
                                        epochStr         = CommonData.StkRoot.ExecuteCommand(cmd).ToString();
                                        listCurrentStart = Convert.ToDouble(epochStr);
                                        timeStepCurrent  = GetTimestep(epochStr);
                                    }
                                    catch (Exception)
                                    {
                                        listCurrentStart = Convert.ToDouble(epoch);

                                        timeStepCurrent = GetTimestep(epochStr);
                                    }
                                    if (count == 1)
                                    {
                                        currentStartTime = listCurrentStart;
                                    }
                                    else if (listCurrentStart < currentStartTime)
                                    {
                                        currentStartTime = listCurrentStart;
                                    }
                                    count++;

                                    //check decimals to get timestep
                                    if (listCurrentTimestep < timeStepCurrent)
                                    {
                                        timeStepCurrent = listCurrentTimestep;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        startTimeStr     = item.startTimeValue;
                        timeStepCurrent  = GetTimestep(startTimeStr);
                        currentStartTime = Convert.ToDouble(item.startTimeValue);
                    }

                    //Check timestep from this articulation to the previous ones to get the smallest one
                    if (timeStepCurrent < timeStep1)
                    {
                        timeStep1 = timeStepCurrent;
                    }
                    //Check current startime to previous ones to get the first one
                    if (count == 1)
                    {
                        startTime = currentStartTime;
                    }
                    else if (currentStartTime < startTime)
                    {
                        startTime = currentStartTime;
                    }
                }
            }
            Tuple <int, double, double> timestepValues = new Tuple <int, double, double>(count, timeStep1, startTime);

            return(timestepValues);
        }