public void AddLegBend()
        {
            Setup("modes\\speciallegs.ppen");

            // Select course 1.
            controller.SelectTab(1);       // Course 1.
            CheckHighlightedLines(controller, -1, -1);

            // Click on leg to select it.
            MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(18.4F, 30.1F), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonClick(Pane.Map, new PointF(18.4F, 30.1F), 0.3F);

            // Begin the add bend mode.
            controller.BeginAddLegBend();

            // Should have crosshair cursor
            ui.MouseMoved(12.2F, 14.4F, 0.3F);
            Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(12.2F, 14.4F), 0.3F);

            Assert.AreSame(Cursors.Cross, cursor);

            // And the adding bend text.
            Assert.AreEqual(StatusBarText.AddingBend, controller.StatusText);


            // Check the highlights
            CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:3  course-control:3  scale:1  course-control2:4  path:N(9.1,10.27)--N(12,20)--N(23.65,38.6)",
                            highlights[0].ToString());

            // Click to add a bend.
            dragAction = controller.LeftButtonDown(Pane.Map, new PointF(12.2F, 14.4F), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.None, dragAction);


            // Check the status text
            Assert.AreEqual(StatusBarText.DragCorner, controller.StatusText);
            // Check the cursor
            cursor = controller.GetMouseCursor(Pane.Map, new PointF(12.2F, 14.4F), 0.3F);
            Assert.AreSame(Util.MoveHandleCursor, cursor);

            // Check the highlights
            highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual("Leg:            control:3  course-control:3  scale:1  course-control2:4  path:N(9.7,10.02)--N(12.2,14.4)--N(12,20)--N(23.65,38.6)",
                            highlights[0].ToString());

            // Make sure the leg has a new bend.
            Leg leg = eventDB.GetLeg(QueryEvent.FindLeg(eventDB, ControlId(3), ControlId(4)));

            Assert.AreEqual(2, leg.bends.Length);
            Assert.AreEqual(new PointF(12.2F, 14.4F), leg.bends[0]);
            Assert.AreEqual(new PointF(12, 20), leg.bends[1]);
            Assert.AreEqual(new PointF(12, 20), leg.flagStartStop);
        }
        public void AddLegGap3()
        {
            Setup("modes\\gappedlegs.coursescribe");

            // Select course 1.
            controller.SelectTab(1);       // Course 1.
            CheckHighlightedLines(controller, -1, -1);

            // Click on leg to select it.
            MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(20, -5), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonClick(Pane.Map, new PointF(20, -5), 0.3F);

            // Begin the add gap mode.
            controller.BeginAddGap();

            // Should have crosshair cursor
            ui.MouseMoved(32, -5, 0.3F);
            Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(32, -5), 0.3F);

            Assert.AreSame(Cursors.Cross, cursor);

            // And the adding leg gap text.
            Assert.AreEqual(StatusBarText.AddingLegGap, controller.StatusText);

            // Check the highlights
            CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(35.72,-20.39)--N(10.18,5.49)",
                            highlights[0].ToString());

            // Click to add a gap.
            dragAction = controller.LeftButtonDown(Pane.Map, new PointF(30, -11), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonClick(Pane.Map, new PointF(30, -11), 0.3F);

            // Check the status text
            ui.MouseMoved(12, -1, 0.1F);
            Assert.AreEqual(StatusBarText.DefaultStatus, controller.StatusText);
            // Check the cursor
            cursor = controller.GetMouseCursor(Pane.Map, new PointF(12, -1), 0.3F);
            Assert.AreSame(Cursors.Default, cursor);

            // Check the highlights
            highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(35.72,-20.39)--N(10.18,5.49)  gaps: (s:9.7,l:2)",
                            highlights[0].ToString());

            // Make sure the leg gap is added.
            Leg leg = eventDB.GetLeg(QueryEvent.FindLeg(eventDB, ControlId(2), ControlId(3)));

            Assert.AreEqual(1, leg.gaps.Length);
            Assert.AreEqual(12.52F, leg.gaps[0].distanceFromStart, 0.01F);
            Assert.AreEqual(2.0F, leg.gaps[0].length, 0.01F);
        }
        public void AddLegGap2()
        {
            Setup("modes\\gappedlegs.coursescribe");

            // Select course 1.
            controller.SelectTab(1);       // Course 1.
            CheckHighlightedLines(controller, -1, -1);

            // Click on leg to select it.
            MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(71, 0), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonClick(Pane.Map, new PointF(71, 0), 0.3F);

            // Begin the add gap mode.
            controller.BeginAddGap();

            // Should have crosshair cursor
            ui.MouseMoved(72, 10, 0.3F);
            Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(72, 10), 0.3F);

            Assert.AreSame(Cursors.Cross, cursor);

            // And the adding leg gap text.
            Assert.AreEqual(StatusBarText.AddingLegGap, controller.StatusText);

            // Check the highlights
            CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(73.43,10.02)--N(68,-22)--N(40.52,-22.36)  gaps: (s:2.96,l:3.5) (s:20.96,l:9)",
                            highlights[0].ToString());

            // Click and drag add a gap.
            dragAction = controller.LeftButtonDown(Pane.Map, new PointF(72, 10), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonEndDrag(Pane.Map, new PointF(50, -25), new PointF(72, 10), 0.3F);

            // Check the status text
            ui.MouseMoved(12, -1, 0.1F);
            Assert.AreEqual(StatusBarText.DefaultStatus, controller.StatusText);
            // Check the cursor
            cursor = controller.GetMouseCursor(Pane.Map, new PointF(12, -1), 0.3F);
            Assert.AreSame(Cursors.Default, cursor);

            // Check the highlights
            highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(73.43,10.02)--N(68,-22)--N(40.52,-22.36)  gaps: (s:0.25,l:50.26)",
                            highlights[0].ToString());

            // Make sure the leg gap is added.
            Leg leg = eventDB.GetLeg(QueryEvent.FindLeg(eventDB, ControlId(1), ControlId(2)));

            Assert.AreEqual(1, leg.gaps.Length);
            Assert.AreEqual(4.29F, leg.gaps[0].distanceFromStart, 0.01F);
            Assert.AreEqual(50.26F, leg.gaps[0].length, 0.01F);
        }
        public void RemoveLegBend()
        {
            Setup("modes\\speciallegs.ppen");

            // Select course 1.
            controller.SelectTab(1);       // Course 1.
            CheckHighlightedLines(controller, -1, -1);

            // Click on leg to select it.
            MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(18.4F, 30.1F), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction);
            controller.LeftButtonClick(Pane.Map, new PointF(18.4F, 30.1F), 0.3F);

            // Begin the remove bend mode.
            controller.BeginRemoveBend();

            // Should have arrow cursor
            ui.MouseMoved(12.2F, 14.4F, 0.3F);
            Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(12.2F, 14.4F), 0.3F);

            Assert.AreSame(Cursors.Arrow, cursor);

            // And the adding bend text.
            Assert.AreEqual(StatusBarText.DeletingBend, controller.StatusText);

            // Check the highlights
            CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual(@"Leg:            control:3  course-control:3  scale:1  course-control2:4  path:N(9.1,10.27)--N(12,20)--N(23.65,38.6)",
                            highlights[0].ToString());

            // move over an existing bend
            ui.MouseMoved(12.1F, 19.8F, 0.3F);
            cursor = controller.GetMouseCursor(Pane.Map, new PointF(12.1F, 19.8F), 0.3F);
            Assert.AreSame(Util.DeleteHandleCursor, cursor);

            // Click to remove the bend.
            dragAction = controller.LeftButtonDown(Pane.Map, new PointF(12.1F, 19.8F), 0.3F);
            Assert.AreEqual(MapViewer.DragAction.None, dragAction);

            // Check the highlights
            highlights = (CourseObj[])controller.GetHighlights(Pane.Map);
            Assert.AreEqual(1, highlights.Length);
            Assert.AreEqual("Leg:            control:3  course-control:3  scale:1  course-control2:4  path:N(9.57,10.08)--N(23.88,38.48)",
                            highlights[0].ToString());

            // Make sure the leg has the bend removed
            Leg leg = eventDB.GetLeg(QueryEvent.FindLeg(eventDB, ControlId(3), ControlId(4)));

            Assert.IsNull(leg.bends);
            Assert.AreEqual(FlaggingKind.All, leg.flagging);
        }
        // Describe a leg.
        private static TextPart[] DescribeLeg(EventDB eventDB, Id <CourseControl> courseControlId1, Id <CourseControl> courseControlId2, DescKind descKind)
        {
            Debug.Assert(descKind == DescKind.Tooltip || descKind == DescKind.DescPane);

            Id <ControlPoint> controlId1 = eventDB.GetCourseControl(courseControlId1).control;
            Id <ControlPoint> controlId2 = eventDB.GetCourseControl(courseControlId2).control;
            Id <Leg>          legId      = QueryEvent.FindLeg(eventDB, controlId1, controlId2);

            List <TextPart> list = new List <TextPart>();

            // Course name
            list.Add(new TextPart(TextFormat.Title, string.Format("{0} \u2013 {1}", Util.ControlPointName(eventDB, controlId1, NameStyle.Long), Util.ControlPointName(eventDB, controlId2, NameStyle.Long))));

            // Course length
            list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.Length));
            list.Add(new TextPart(TextFormat.SameLine,
                                  string.Format("{0:#,###} m", QueryEvent.ComputeLegLength(eventDB, controlId1, controlId2, legId))));

            // Which courses
            list.Add(new TextPart(TextFormat.Header, (descKind == DescKind.Tooltip ? SelectionDescriptionText.UsedIn : SelectionDescriptionText.UsedInCourses)));
            Id <Course>[] coursesUsingControl = QueryEvent.CoursesUsingLeg(eventDB, controlId1, controlId2);
            list.Add(new TextPart(descKind == DescKind.Tooltip ? TextFormat.SameLine : TextFormat.NewLine, CourseListText(eventDB, coursesUsingControl)));

            // What is the competitor load?
            int load = QueryEvent.GetLegLoad(eventDB, controlId1, controlId2);

            if (load >= 0)
            {
                list.Add(new TextPart(TextFormat.Header, (descKind == DescKind.Tooltip ? SelectionDescriptionText.Load : SelectionDescriptionText.CompetitorLoad)));
                list.Add(new TextPart(TextFormat.SameLine, string.Format("{0}", load)));
            }

            if (descKind == DescKind.DescPane)
            {
                // Flagging
                list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.Flagging + "  "));
                list.Add(new TextPart(TextFormat.SameLine, FlaggingType(eventDB, controlId1, controlId2, legId)));
            }

            return(list.ToArray());
        }