GetNextControl() public method

public GetNextControl ( int controlIndex ) : int
controlIndex int
return int
コード例 #1
0
        // Get the angle from the given control index to the next control.
        public static double ComputeAngleOut(EventDB eventDB, CourseView courseView, int controlIndex)
        {
            PointF pt1 = eventDB.GetControl(courseView.ControlViews[controlIndex].controlId).location;

            // Get index of next control.
            int nextControlIndex = courseView.GetNextControl(controlIndex);
            if (nextControlIndex < 0)
                return double.NaN;

            // By default, the location of the next control is the direction.
            PointF pt2 = eventDB.GetControl(courseView.ControlViews[nextControlIndex].controlId).location;

            // If there is a custom leg, then use the location of the first bend instead.
            Id<Leg> legId = QueryEvent.FindLeg(eventDB, courseView.ControlViews[controlIndex].controlId, courseView.ControlViews[nextControlIndex].controlId);
            if (legId.IsNotNone) {
                Leg leg = eventDB.GetLeg(legId);
                if (leg.bends != null && leg.bends.Length > 0)
                    pt2 = leg.bends[0];
            }

            return Math.Atan2(pt2.Y - pt1.Y, pt2.X - pt1.X);
        }
コード例 #2
0
ファイル: Reports.cs プロジェクト: petergolde/PurplePen
        private void WriteLegLengthTable(EventDB eventDB, CourseView courseView)
        {
            BeginTable("", 3, "leftalign", "leftalign", "rightalign");
            WriteTableHeaderRow(ReportText.ColumnHeader_Leg, ReportText.ColumnHeader_Controls, ReportText.ColumnHeader_Length);

            // Go through the control views.
            int controlViewIndex = 0;
            float distanceThisLeg = 0;
            float totalLegs = 0;
            int legNumber = 1;
            Id<ControlPoint> controlIdPrev = Id<ControlPoint>.None;

            while (controlViewIndex >= 0 && controlViewIndex < courseView.ControlViews.Count) {
                CourseView.ControlView controlView = courseView.ControlViews[controlViewIndex];
                ControlPointKind kind = eventDB.GetControl(controlView.controlId).kind;

                // Don't report crossing points.
                if (kind != ControlPointKind.CrossingPoint) {
                    if (controlIdPrev.IsNotNone) {
                        string legText = string.Format("{0}\u2013{1}", Util.ControlPointName(eventDB, controlIdPrev, NameStyle.Medium), Util.ControlPointName(eventDB, controlView.controlId, NameStyle.Medium));
                        WriteTableRow(Convert.ToString(legNumber), legText, string.Format("{0} m", Math.Round(distanceThisLeg)));
                        totalLegs += distanceThisLeg;
                        legNumber += 1;
                    }

                    controlIdPrev = controlView.controlId;
                    distanceThisLeg = 0;
                }

                if (controlView.legLength != null)
                    distanceThisLeg += controlView.legLength[0];

                controlViewIndex = courseView.GetNextControl(controlViewIndex);
            }

            // Write average row
            if (legNumber > 1) {
                BeginTableRow("summaryrow");
                WriteSpannedTableCell(2, ReportText.LegLength_Average);
                WriteTableCell(string.Format("{0} m", Convert.ToString(Math.Round(totalLegs / (float) (legNumber - 1)))));
                EndTableRow();
            }

            EndTable();
        }