Example #1
0
        private IAgCrdnCalcScalar CreateScalar(IAgStkObject stkObject, string name, IAgCrdnAngle angle)
        {
            IAgCrdnCalcScalarFactory factory = stkObject.Vgt.CalcScalars.Factory;

            // Check if component exists.
            CheckExistingVgtComponent(stkObject.Vgt.CalcScalars, name);

            IAgCrdnCalcScalarAngle scalar = factory.CreateCalcScalarAngle(name, "") as IAgCrdnCalcScalarAngle;

            scalar.InputAngle = angle;
            return(scalar as IAgCrdnCalcScalar);
        }
        private void Calculate_Click(object sender, EventArgs e)
        {
            int check = FieldCheck();

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

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

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

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

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

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

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

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

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

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

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

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

                //Export options
                if (compComplete && ExportToTxt.Checked)
                {
                    ReadWrite.WritePlaneCrossingOutput(satRefObj.InstanceName, AllPlaneCrossingsList);
                }
                MessageBox.Show("Computation Complete!");
            }
        }
        private void 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");
            }
        }