Пример #1
0
        // Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version.
        internal void CheckRenderMapStandardChange(string filename, Id <Course> id, DescriptionKind kind, string newDescStandard)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            symbolDB.Standard = eventDB.GetEvent().descriptionStandard;
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1);

            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_default", kind));

            undomgr.BeginCommand(71231, "change standard");
            symbolDB.Standard = newDescStandard;
            ChangeEvent.UpdateDescriptionToMatchStandard(eventDB, symbolDB);
            undomgr.EndCommand(71231);
            description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1);
            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_" + newDescStandard, kind));
        }
Пример #2
0
        public void CourseEquals()
        {
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            CourseView   courseView, courseView2;
            CourseLayout course, course2;

            eventDB.Load(TestUtil.GetTestFile("courselayout\\marymoor1.coursescribe"));
            eventDB.Validate();

            // Create the a course view and layout
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3)));
            course     = new CourseLayout();
            course.SetLayerColor(CourseLayer.Descriptions, 0, "Black", 0, 0, 0, 1F, false);
            course.SetLayerColor(CourseLayer.MainCourse, 12, "Purple", 0.2F, 1, 0, 0.1F, false);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, CourseLayer.MainCourse);

            // Create it again
            courseView2 = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3)));
            course2     = new CourseLayout();
            course2.SetLayerColor(CourseLayer.Descriptions, 0, "Black", 0, 0, 0, 1F, false);
            course2.SetLayerColor(CourseLayer.MainCourse, 12, "Purple", 0.2F, 1, 0, 0.1F, false);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView2, defaultCourseAppearance, course2, CourseLayer.MainCourse);

            // Make sure that they are equal.
            Assert.AreEqual(course, course, "CourseLayouts that are equivalent should compare equal.");
            Assert.AreEqual(course, course2, "CourseLayouts that are equivalent should compare equal.");
        }
Пример #3
0
        public void DisplayAllCourseViews()
        {
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));

            eventDB.Load(TestUtil.GetTestFile("courseview\\sampleevent1.coursescribe"));
            eventDB.Validate();

            foreach (Id <Course> courseId in QueryEvent.SortedCourseIds(eventDB))
            {
                CourseDesignator designator;
                if (QueryEvent.HasVariations(eventDB, courseId))
                {
                    var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First();
                    designator = new CourseDesignator(courseId, variationInfo);
                }
                else
                {
                    designator = new CourseDesignator(courseId);
                }

                CourseView courseView = CourseView.CreateViewingCourseView(eventDB, designator);
                DumpCourseView(courseView, Console.Out);
                Console.WriteLine();
            }
        }
        public void ClearTextAndSymbols()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe"));
            eventDB.Validate();

            CourseView           courseView    = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4)));
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(false);
            DescriptionFormatter.ClearTextAndSymbols(description);

            DescriptionFormatter.DumpDescription(symbolDB, description, writer);
            actual   = writer.ToString();
            expected =
                @"      |                                               |
      |                 |                 |           |
(  1) |     |     |     |     |     |     |     |     |
( 11) |     |     |     |     |     |     |     |     |
( 22) |                     :                         |
(  4) |     |     |     |     |     |     |     |     |
( 15) |                     :                         |
(  5) |     |     |     |     |     |     |     |     |
( 18) |     |     |     |     |     |     |     |     |
(  6) |                     :                         |
";
            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmap(string filename, Id <Course> id, DescriptionKind kind, int numColumns = 1)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols);

            Bitmap bmNew = DescriptionBrowser.RenderToBitmap(symbolDB, description, kind, numColumns);

            if (numColumns > 1)
            {
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_" + numColumns + "col", kind));
            }
            else
            {
                TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind));
            }
        }
Пример #6
0
        bool WriteCourse(Id <Course> courseId, int courseNumber)
        {
            // A course must have a start and a finish to be output.
            if (!QueryEvent.HasStartControl(eventDB, courseId))
            {
                return(false);
            }
            if (!QueryEvent.HasFinishControl(eventDB, courseId))
            {
                return(false);
            }

            Course course  = eventDB.GetCourse(courseId);
            bool   isScore = (course.kind == CourseKind.Score);

            string[]   classNames = GetClassNames(eventDB, courseId);
            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(courseId));

            WriteCourseGroupStart(course.name, courseNumber, classNames, isScore);

            WriteCourseVariations(courseId, course.name, courseNumber, classNames, isScore);

            WriteCourseGroupEnd();

            return(true);
        }
Пример #7
0
        public void SpecialLegs()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("courseview\\speciallegs.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(1)));

            DumpCourseView(courseView, writer);
            actual   = writer.ToString();
            expected =
                @"Name='Leggy', Kind='Normal', CourseId=1
Total Length=2242.8  Part Length=2242.8  Total Climb=-1  ScoreColumn=-1  Total Score=0  Total Controls=4
 0: [ 0] Ids:  1,  1
    Legs: (Next:1,Id:0,length:515.84)  
 1: [ 1] Ids:  2,  2
    Legs: (Next:2,Id:2,length:420.12)  
 2: [ 2] Ids:  3,  3
    Legs: (Next:3,Id:3,length:377.54)  
 3: [ 3] Ids:  4,  4
    Legs: (Next:4,Id:4,length:518.8)  
 4: [ 4] Ids:  5,  5
    Legs: (Next:5,Id:0,length:410.45)  
 5: [-1] Ids:  6,  6
";
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void HitTestRegular()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();
            CourseView           courseView    = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4)));
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[]   description         = descFormatter.CreateDescription(false);
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description = description;
            descriptionRenderer.CellSize    = 40;
            descriptionRenderer.Margin      = 5;

            descriptionRenderer.DescriptionKind = DescriptionKind.Symbols;

            CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40));
            CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalBox, 5, 5, 4, new RectangleF(165, 205, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalBox, 9, 9, 7, new RectangleF(285, 365, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.Directive, 4, 4, 0, new RectangleF(5, 165, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(328, 147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.Text;
            CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40));
            CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40));
            CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalText, 9, 9, -1, new RectangleF(85, 365, 240, 40));
            CheckHitTest(descriptionRenderer, new Point(59, 302), HitTestKind.NormalBox, 7, 7, 1, new RectangleF(45, 285, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.DirectiveText, 4, 4, -1, new RectangleF(5, 165, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(328, 147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40));


            descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText;
            CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40));
            CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalBox, 5, 5, 4, new RectangleF(165, 205, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalBox, 9, 9, 7, new RectangleF(285, 365, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.Directive, 4, 4, 0, new RectangleF(5, 165, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(431, 56), HitTestKind.None, 1, 1, -1, new RectangleF(325, 45, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(333, 131), HitTestKind.NormalText, 3, 3, -1, new RectangleF(325, 125, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(491, 252), HitTestKind.DirectiveText, 6, 6, -1, new RectangleF(325, 245, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(527, 433), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 520, 40));
        }
Пример #9
0
        public void HitTestAllControls()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();
            CourseView           courseView    = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[]   description         = descFormatter.CreateDescription(false);
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description = description;
            descriptionRenderer.CellSize    = 40;
            descriptionRenderer.Margin      = 5;

            descriptionRenderer.DescriptionKind = DescriptionKind.Symbols;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(259, 78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(68, 999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 320, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.Text;

            CheckHitTest(descriptionRenderer, new Point(311, 12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(16, 82), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(178, 76), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(182, 234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40));
            CheckHitTest(descriptionRenderer, new Point(60, 942), HitTestKind.DirectiveText, 23, 23, -1, new RectangleF(5, 925, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 320, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(259, 78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(380, 76), HitTestKind.None, 1, 1, -1, new RectangleF(325, 45, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(68, 999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(398, 554), HitTestKind.NormalText, 13, 13, -1, new RectangleF(325, 525, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(401, 934), HitTestKind.DirectiveText, 23, 23, -1, new RectangleF(325, 925, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 520, 40));
        }
Пример #10
0
        public void HitTestScore()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();
            CourseView           courseView    = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(5)));
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[]   description         = descFormatter.CreateDescription(false);
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description = description;
            descriptionRenderer.CellSize    = 40;
            descriptionRenderer.Margin      = 5;

            descriptionRenderer.DescriptionKind = DescriptionKind.Symbols;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(228, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 320, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.Text;

            CheckHitTest(descriptionRenderer, new Point(311, 12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40));
            CheckHitTest(descriptionRenderer, new Point(16, 112), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(178, 116), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(182, 234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(228, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 320, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40));
            CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40));
            CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(380, 116), HitTestKind.None, 2, 2, -1, new RectangleF(325, 85, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40));
            CheckHitTest(descriptionRenderer, new Point(398, 594), HitTestKind.NormalText, 14, 14, -1, new RectangleF(325, 565, 200, 40));
            CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0));
            CheckHitTest(descriptionRenderer, new Point(451, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 520, 40));
        }
Пример #11
0
        void CheckCourse(string filename, CourseDesignator courseDesignator, bool addAllControls, string testName, RectangleF rect, CourseAppearance appearance)
        {
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr      undomgr  = new UndoMgr(5);
            EventDB      eventDB  = new EventDB(undomgr);
            CourseView   courseView;
            CourseLayout course;

            eventDB.Load(TestUtil.GetTestFile(filename));
            eventDB.Validate();

            // Create the course
            courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator);
            course     = new CourseLayout();
            course.SetLayerColor(CourseLayer.Descriptions, 0, "Black", 0, 0, 0, 1F, false);
            course.SetLayerColor(CourseLayer.MainCourse, 11, "Purple", 0.2F, 1.0F, 0.0F, 0.07F, false);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, course, CourseLayer.MainCourse);

            // Add all controls if requested.
            if (addAllControls && courseDesignator.IsNotAllControls)
            {
                courseView = CourseView.CreateFilteredAllControlsView(eventDB, new CourseDesignator[] { courseDesignator }, ControlPointKind.None,
                                                                      new CourseViewOptions()
                {
                    showNonDescriptionSpecials = false, showDescriptionSpecials = true
                });
                course.SetLayerColor(CourseLayer.AllControls, 12, "LightPurple", 0.1F, 0.5F, 0.0F, 0.0F, false);
                CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, course, CourseLayer.AllControls);
            }

            // Render to a map
            Map map = course.RenderToMap(new CourseLayout.MapRenderOptions());

            // Render map to the graphics.
            Bitmap bm = new Bitmap(1000, 1000);

            using (Graphics g = Graphics.FromImage(bm)) {
                RenderOptions options = new RenderOptions();

                options.usePatternBitmaps = true;
                options.minResolution     = (float)(rect.Width / bm.Width);
                options.renderTemplates   = RenderTemplateOption.MapAndTemplates;

                g.ScaleTransform((float)(bm.Width / rect.Width), -(float)(bm.Height / rect.Height));
                g.TranslateTransform(-rect.Left, -rect.Top - rect.Height);

                g.Clear(Color.White);
                using (map.Read())
                    map.Draw(new GDIPlus_GraphicsTarget(g), rect, options, null);
            }

            TestUtil.CheckBitmapsBase(bm, "courserenderer\\" + testName);
        }
Пример #12
0
        private void WriteCourseTrack(Id <Course> courseId)
        {
            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(courseId));

            if (courseView.Kind != CourseView.CourseViewKind.Normal)
            {
                return;  // don't show score courses or variation courses.
            }
            xmlWriter.WriteStartElement("trk", gpxNamespace);
            xmlWriter.WriteElementString("name", gpxNamespace, courseView.CourseName);
            xmlWriter.WriteStartElement("trkseg", gpxNamespace);

            foreach (CourseView.ControlView controlView in courseView.ControlViews)
            {
                if (controlView.controlId.IsNone)
                {
                    continue;
                }
                if (!waypoints.ContainsKey(controlView.controlId))
                {
                    continue;
                }

                // Write the trackpoint.
                Waypoint wp = waypoints[controlView.controlId];
                WriteTrackPoint(wp);

                // If there are any bends in the next leg, write those.
                if (controlView.legId != null && controlView.legId.Length > 0 && controlView.legId[0].IsNotNone)
                {
                    Leg leg = eventDB.GetLeg(controlView.legId[0]);
                    if (leg.bends != null && leg.bends.Length > 0)
                    {
                        foreach (PointF bendPoint in leg.bends)
                        {
                            // Get the latitude and longitude.
                            double latitude, longitude;
                            if (!coordinateMapper.GetLatLong(bendPoint, out latitude, out longitude) ||
                                double.IsNaN(latitude) || double.IsNaN(longitude))
                            {
                                throw new Exception(MiscText.GpxReprojectFailure);
                            }

                            WriteTrackBendPoint(latitude, longitude);
                        }
                    }
                }
            }

            xmlWriter.WriteEndElement(); // end trkseg
            xmlWriter.WriteEndElement(); // end trk
        }
Пример #13
0
        public void HitTest()
        {
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr      undomgr  = new UndoMgr(5);
            EventDB      eventDB  = new EventDB(undomgr);
            CourseView   courseView;
            CourseLayout course;

            eventDB.Load(TestUtil.GetTestFile("courselayout\\marymoor1.coursescribe"));
            eventDB.Validate();

            // Create the all controls course
            courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);

            CheckHitTest(course, new PointF(9.0F, 12.4F), 0, null, "Water:          special:1  scale:1  location:(7.996275,12.34392)");
            CheckHitTest(course, new PointF(54.7F, 12.2F), 0, null, null);
            CheckHitTest(course, new PointF(0.5F, 9.0F), 0, null, "Control:        control:72  scale:1  location:(-0.7,10.3)  gaps:");
            CheckHitTest(course, new PointF(58.5F, -9.2F), 0, null, "Start:          control:1  scale:1  location:(56.8,-8.7)  orientation:0");
            CheckHitTest(course, new PointF(46.6F, -15.9F), 0, null, @"Code:           control:52  scale:1  text:52  top-left:(45.56,-12.18)
                font-name:Roboto Condensed  font-style:Bold  font-height:4.18");

            // Create course 3
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3)));
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);

            CheckHitTest(course, new PointF(-3.5F, 10.3F), 0, null, "Control:        control:72  course-control:305  scale:1  location:(-0.7,10.3)  gaps:");
            CheckHitTest(course, new PointF(35.6F, 17.7F), 0, null, null);
            CheckHitTest(course, new PointF(59.2F, 18.5F), 0, null, "Leg:            control:71  course-control:307  scale:1  course-control2:308  path:N(42.92,17.55)--N(71.88,19.05)");
            CheckHitTest(course, new PointF(72.1F, 33.5F), 0, null, @"ControlNumber:  control:75  course-control:311  scale:1  text:10  top-left:(66.57,37.12)
                font-name:Roboto  font-style:Regular  font-height:5.57");
            CheckHitTest(course, new PointF(50.2F, -2.9F), 0, null, @"Finish:         control:2  course-control:315  scale:1  location:(53.2,-2.8)  gaps:");

            // Add in all controls.  Test with true and false for all Layers.
            courseView = CourseView.CreateFilteredAllControlsView(eventDB, new CourseDesignator[] { Designator(3) }, ControlPointKind.Normal,
                                                                  new CourseViewOptions()
            {
                showNonDescriptionSpecials = false, showDescriptionSpecials = true
            });
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, CourseLayer.AllControls);

            CheckHitTest(course, new PointF(5.1F, -5.1F), CourseLayer.All, null, @"Control:        layer:12  control:76  scale:1  location:(5.6,-5.7)  gaps:");
            CheckHitTest(course, new PointF(5.1F, -5.1F), CourseLayer.MainCourse, null, null);

            // Test the type filter
            CheckHitTest(course, new PointF(59.2F, 18.5F), CourseLayer.MainCourse, (co => co is LegCourseObj), "Leg:            control:71  course-control:307  scale:1  course-control2:308  path:N(42.92,17.55)--N(71.88,19.05)");
            CheckHitTest(course, new PointF(59.2F, 18.5F), CourseLayer.MainCourse, (co => co is PointCourseObj), null);
            CheckHitTest(course, new PointF(-3.5F, 10.3F), CourseLayer.MainCourse, (co => co is PointCourseObj), "Control:        control:72  course-control:305  scale:1  location:(-0.7,10.3)  gaps:");
            CheckHitTest(course, new PointF(-3.5F, 10.3F), CourseLayer.MainCourse, (co => co is LineCourseObj), null);
        }
Пример #14
0
        protected override IPrintableRectangle[] GetDescriptionList()
        {
            List <IPrintableRectangle> rendererList = new List <IPrintableRectangle>();

            // Get the list of renderers for the descriptions we're printing.
            foreach (CourseDesignator designator in QueryEvent.EnumerateCourseDesignators(
                         eventDB, punchPrintSettings.CourseIds, punchPrintSettings.VariationChoicesPerCourse, false))
            {
                rendererList.Add(GetRenderer(CourseView.CreateViewingCourseView(eventDB, designator)));
            }

            return(rendererList.ToArray());
        }
Пример #15
0
        // Update the names of all course views, and get the active course view, based on the active course id.
        void UpdateCourseViews()
        {
            List<KeyValuePair<Id<Course>,string>> courseViewPairs = new List<KeyValuePair<Id<Course>,string>>(); // Holds the list of course views and names, for sorting. Does NOT include all controls.

            // Get all the pairs of course ids in sorted order.
            Id<Course>[] courseIds = QueryEvent.SortedCourseIds(eventDB);

            // Copy to the names and ids arrays, adding in All Controls as the first element.
            courseViewNames = new string[courseIds.Length + 1];
            courseViewIds = new Id<Course>[courseIds.Length + 1];
            courseViewNames[0] = MiscText.AllControls;
            courseViewIds[0] = Id<Course>.None;
            for (int i = 1; i < courseViewIds.Length; ++i) {
                courseViewNames[i] = eventDB.GetCourse(courseIds[i - 1]).name;
                courseViewIds[i] = courseIds[i-1];
            }

            // Figure out which course view is the active one. We have already validate that the active course id
            // is present.
            if (activeCourseDesignator.IsAllControls) {
                activeCourseViewIndex = 0;
                activeCourseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            }
            else {
                for (int i = 1; i < courseViewIds.Length; ++i) {
                    if (courseViewIds[i] == activeCourseDesignator.CourseId) {
                        activeCourseViewIndex = i;
                        activeCourseView = CourseView.CreateViewingCourseView(eventDB, activeCourseDesignator);
                    }
                }
            }

            // Get/create the topology course view. Not supported (null) for score and all controls. Always shows
            // all variations for a course with variations.
            if (activeCourseView.Kind == CourseView.CourseViewKind.Normal) {
                if (QueryEvent.HasVariations(activeCourseView.EventDB, activeCourseView.BaseCourseId) || !activeCourseView.CourseDesignator.AllParts) {
                    topologyCourseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(activeCourseView.BaseCourseId));
                }
                else {
                    topologyCourseView = activeCourseView;
                }
            }
            else if (activeCourseView.Kind == CourseView.CourseViewKind.AllVariations) {
                topologyCourseView = activeCourseView;
            }
            else {
                topologyCourseView = null;
            }
        }
Пример #16
0
        public void AllControlsCourseView()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("courseview\\sampleevent1.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);

            DumpCourseView(courseView, writer);
            actual   = writer.ToString();
            expected =
                @"Name='All controls', Kind='AllControls', CourseId=0
Total Length=0  Part Length=0  Total Climb=-1  ScoreColumn=-1  Total Score=0  Total Controls=17
 0: [-1] Ids:  1,  0
 1: [-1] Ids: 23,  0
 2: [-1] Ids:  2,  0
 3: [-1] Ids:  4,  0
 4: [-1] Ids: 12,  0
 5: [-1] Ids:  7,  0
 6: [-1] Ids: 10,  0
 7: [-1] Ids: 11,  0
 8: [-1] Ids:  8,  0
 9: [-1] Ids:  9,  0
10: [-1] Ids: 13,  0
11: [-1] Ids: 14,  0
12: [-1] Ids: 16,  0
13: [-1] Ids: 17,  0
14: [-1] Ids: 18,  0
15: [-1] Ids: 19,  0
16: [-1] Ids: 20,  0
17: [-1] Ids: 21,  0
18: [-1] Ids:  5,  0
19: [-1] Ids:  6,  0
20: [-1] Ids: 24,  0
21: [-1] Ids:  3,  0
22: [-1] Ids: 15,  0
23: [-1] Ids: 22,  0
Special 1 (FirstAid)
Special 2 (OptCrossing)
Special 4 (OOB)
";
            Assert.AreEqual(expected, actual);
        }
Пример #17
0
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmap(string filename, Id <Course> id, PunchcardFormat format)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(filename);
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id));

            Bitmap bmNew = RenderToBitmap(eventDB, courseView, format);

            TestUtil.CheckBitmapsBase(bmNew, GetBitmapFileName(eventDB, id, ""));
        }
Пример #18
0
        public void HitTestMultiLine()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent6.coursescribe"));
            eventDB.Validate();
            CourseView           courseView    = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, CourseId(1)));
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[]   description         = descFormatter.CreateDescription(false);
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description = description;
            descriptionRenderer.CellSize    = 40;
            descriptionRenderer.Margin      = 5;

            descriptionRenderer.DescriptionKind = DescriptionKind.Symbols;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80));
            CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80));
            CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.Text;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80));
            CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80));
            CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120));
            CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40));

            descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText;

            CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80));
            CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80));
            CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120));
            CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120));
            CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40));
        }
Пример #19
0
        public void BoundingRect()
        {
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr      undomgr  = new UndoMgr(5);
            EventDB      eventDB  = new EventDB(undomgr);
            CourseView   courseView;
            CourseLayout course;

            eventDB.Load(TestUtil.GetTestFile("courselayout\\marymoor1.coursescribe"));
            eventDB.Validate();

            // Create the all controls course
            courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
            RectangleF bounding = course.BoundingRect();
            RectangleF expected = new RectangleF(-16.41F, -34.3F, 152.17F, 79.95F);

            TestUtil.AssertEqualRect(expected, bounding, 0.01F, "Bounding rect all controls");

            // Try course 1
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(1)));
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
            bounding = course.BoundingRect();
            expected = new RectangleF(-2.11F, -32.9F, 64.73F, 60.43F);
            TestUtil.AssertEqualRect(expected, bounding, 0.1F, "Bounding rect course 1");

            // Try course with control descriptions on it.
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(10)));
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
            bounding = course.BoundingRect();
            expected = new RectangleF(6.0F, -40.1F, 121.94F, 77.22F);
            TestUtil.AssertEqualRect(expected, bounding, 0.1F, "Bounding rect course 10");

            // Do an empty course
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(11)));
            course     = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
            bounding = course.BoundingRect();
            expected = RectangleF.FromLTRB(0, 0, 0, 0);
            TestUtil.AssertEqualRect(expected, bounding, 0.001F, "Bounding rect blank course");
        }
Пример #20
0
        public void ScoreCourseView()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("courseview\\sampleevent1.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(5)));

            DumpCourseView(courseView, writer);
            actual   = writer.ToString();
            expected =
                @"Name='Score 4', Kind='Score', CourseId=5
Total Length=0  Part Length=0  Total Climb=-1  ScoreColumn=0  Total Score=155  Total Controls=11
 0: [-1] Ids:  1,101
 1: [-1] Ids: 17,109
 2: [-1] Ids:  2,113
 3: [-1] Ids:  7,114
 4: [-1] Ids: 11,102
 5: [-1] Ids:  8,115
 6: [-1] Ids: 20,112
 7: [-1] Ids:  5,107
 8: [-1] Ids:  4,105
 9: [-1] Ids: 16,108
10: [-1] Ids: 18,110
11: [-1] Ids: 19,111
12: [-1] Ids:  6,116
13: [-1] Ids:  3,104
14: [-1] Ids: 15,106
15: [-1] Ids: 22,103
Special 1 (FirstAid)
Special 3 (Boundary)
Special 4 (OOB)
";


            Assert.AreEqual(expected, actual);
        }
Пример #21
0
        private DescriptionLine[] GetDescription()
        {
            CourseItem  courseItem = (CourseItem)(listBoxCourses.SelectedItem);
            Id <Course> id;

            if (courseItem == null)
            {
                id = Id <Course> .None;
            }
            else
            {
                id = courseItem.id;
            }

            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForUI);

            return(descFormatter.CreateDescription(false));
        }
Пример #22
0
        // Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version.
        internal void CheckRenderBitmapPixelAtATime(Id <Course> id, DescriptionKind kind)
        {
            SymbolDB   symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr    undomgr  = new UndoMgr(5);
            EventDB    eventDB  = new EventDB(undomgr);
            CourseView courseView;

            eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe"));
            eventDB.Validate();

            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id));

            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(false);

            Bitmap bmNew = RenderToBitmapPixelAtATime(symbolDB, description, kind);

            TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind));
        }
Пример #23
0
        public void StandardCourseViewWithCustomFirstNumber()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("courseview\\sampleevent2.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, Designator(4));

            DumpCourseView(courseView, writer);
            actual   = writer.ToString();
            expected =
                @"Name='SampleCourse4', Kind='Normal', CourseId=4
Total Length=4667.3  Part Length=4667.3  Total Climb=173  ScoreColumn=-1  Total Score=0  Total Controls=4
 0: [ 0] Ids:  1, 11
    Legs: (Next:1,Id:0,length:340.1)  
 1: [ 3] Ids: 11, 12
    Legs: (Next:2,Id:0,length:537.76)  
 2: [-1] Ids: 22, 13
    Legs: (Next:3,Id:0,length:245.73)  
 3: [-1] Ids:  3, 14
    Legs: (Next:4,Id:0,length:112.54)  
 4: [ 4] Ids:  4, 15
    Legs: (Next:5,Id:0,length:280.23)  
 5: [-1] Ids: 15, 16
    Legs: (Next:6,Id:0,length:287.06)  
 6: [ 5] Ids:  5, 17
    Legs: (Next:7,Id:0,length:1440)  
 7: [ 6] Ids: 18, 18
    Legs: (Next:8,Id:0,length:1423.9)  
 8: [-1] Ids:  6, 19
Special 1 (FirstAid)
Special 4 (OOB)
Description 6 (Course 4)
";
            Assert.AreEqual(expected, actual);
        }
Пример #24
0
        public void GetViewBounds()
        {
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));

            eventDB.Load(TestUtil.GetTestFile("courseview\\sampleevent1.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            RectangleF bounds     = courseView.GetViewBounds();

            Assert.AreEqual(-51.4F, bounds.Left);
            Assert.AreEqual(-47.8F, bounds.Top);
            Assert.AreEqual(106.9F, bounds.Width);
            Assert.AreEqual(92.9F, bounds.Height, 0.0001);
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4)));
            Assert.AreEqual(new RectangleF(-51.4F, -39F, 96.8F, 84.1F), courseView.GetViewBounds());
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(5)));
            Assert.AreEqual(new RectangleF(-51.4F, -39F, 106.9F, 84.1F), courseView.GetViewBounds());
        }
        // Test the course description formatter with a given file and course
        private void TestCourseFormatter(string testFileName, CourseDesignator courseDesignator, bool createKey, string expected)
        {
            UndoMgr      undomgr  = new UndoMgr(5);
            EventDB      eventDB  = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer   = new StringWriter();
            string       actual;

            eventDB.Load(TestUtil.GetTestFile(testFileName));
            eventDB.Validate();

            CourseView courseView;

            courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator);
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);

            DescriptionLine[] description = descFormatter.CreateDescription(createKey);

            DescriptionFormatter.DumpDescription(symbolDB, description, writer);
            actual = writer.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void DisplayAllCourses()
        {
            UndoMgr              undomgr  = new UndoMgr(5);
            EventDB              eventDB  = new EventDB(undomgr);
            SymbolDB             symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            CourseView           courseView;
            DescriptionFormatter descFormatter;

            DescriptionLine[] description;

            eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe"));
            eventDB.Validate();

            foreach (Id <Course> courseId in QueryEvent.SortedCourseIds(eventDB))
            {
                CourseDesignator designator;
                if (QueryEvent.HasVariations(eventDB, courseId))
                {
                    var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First();
                    designator = new CourseDesignator(courseId, variationInfo);
                }
                else
                {
                    designator = new CourseDesignator(courseId);
                }
                courseView    = CourseView.CreateViewingCourseView(eventDB, designator);
                descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);
                description   = descFormatter.CreateDescription(false);
                DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out);
                Console.WriteLine();
            }

            courseView    = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting);
            description   = descFormatter.CreateDescription(false);
            DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out);
        }
Пример #27
0
        void WriteSingleCourseVariation(CourseDesignator courseDesignator, string courseName, int courseNumber, string[] classNames, bool isScore, int variationNumber, VariationInfo variationInfo)
        {
            float distanceThisLeg = 0;
            int   sequenceNumber  = 1;  // score courses need sequence #'s, even though there is no sequence.

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator);

            WriteCourseStart(courseView, courseName, courseNumber, classNames, isScore, variationNumber, variationInfo);

            // Go through the control views.
            int controlViewIndex = 0;

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

                WriteCourseControl(kind, controlView, isScore, ref sequenceNumber, ref distanceThisLeg);

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

                if (isScore)
                {
                    ++controlViewIndex;
                }
                else
                {
                    controlViewIndex = courseView.GetNextControl(controlViewIndex);
                }
            }

            WriteCourseEnd();
        }
        public void ScoreCourseFormatterNoScore()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent5.coursescribe"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, Designator(5));

            DescriptionLine[] description = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting).CreateDescription(false);

            DescriptionFormatter.DumpDescription(symbolDB, description, writer);
            actual   = writer.ToString();
            expected =
                @"      | Sample Event 1                                |   [Sample Event 1]
      | Score more!                                   |   [Score more!]
      |Score 4          |155 points                   |   [155 points]
(  1) |start|     |     |  2.8|  8.5|     |     |     |   [Start: open bare rock]
( 17) |    1|  302|     | 1.14|     |     |11.1S|     |   [S side of pit]
(  2) |    2|   31|  0.3|  2.4|     |   2m|     |     |   [Upper boulder, 2m high]
(  7) |    3|  189|     |  1.8|  1.8| 10.2|     |     |   [Small gully junction]
( 11) |    4|  191|     |  5.2|  5.2| 10.1|11.15|     |   [Between path crossings]
(  8) |    5|  210|     | 5.11| 5.20|     |11.15|     |   [Between building and statue]
( 20) |    6|  305|     |  2.7|     |  6x7|     | 12.4|   [Stony ground, 6m by 7m (manned)]
(  5) |    7|   GO| 0.1N|  5.5|  5.2| 10.1|11.1N| 12.3|   [N side of N power line and path crossing (radio)]
(  4) |    8|   32|     |  3.7|     |     |     | 12.1|   [very marshy spot]
( 16) |    9|  301|     | 1.14|  8.4|  3.0|     |     |   [Overgrown pit, 3m deep]
( 18) |   10|  303|     |  1.3|     |    4|     |     |   [Reentrant, 4m deep]
( 19) |   11|  304| 0.1S|     |  8.5|     |     |     |   [S ]
";
            Assert.AreEqual(expected, actual);
        }
Пример #29
0
        public void AllVariations()
        {
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            StringWriter writer = new StringWriter();
            string       actual, expected;

            eventDB.Load(TestUtil.GetTestFile("queryevent\\variations.ppen"));
            eventDB.Validate();

            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(1)));

            DumpCourseView(courseView, writer);
            actual   = writer.ToString();
            expected =
                @"Name='Course 1', Kind='AllVariations', CourseId=1
Total Length=4732.2  Part Length=4732.2  Total Climb=-1  ScoreColumn=-1  Total Score=0  Total Controls=21
 0: [-1] Ids:  1,  1
    Legs: (Next:1,Id:0,length:158.84)  
 1: [-1] Ids:  2,  2, 24
    Legs: (Next:3,Id:0,length:209.04)  (Next:2,Id:0,length:826.15)  
 2: [-1] Ids: 24, 12
    Legs: (Next:21,Id:0,length:1333.7)  
 3: [-1] Ids:  3,  3
    Legs: (Next:4,Id:0,length:209.04)  
 4: [-1] Ids:  4,  4, 25, 26, 27
    Legs: (Next:14,Id:0,length:236.21)  (Next:5,Id:0,length:292.06)  (Next:7,Id:0,length:266.23)  (Next:9,Id:0,length:301.32)  
 5: [-1] Ids: 12, 15
    Legs: (Next:6,Id:0,length:146.69)  
 6: [-1] Ids: 13, 16
    Legs: (Next:4,Id:0,length:262.42)  
 7: [-1] Ids: 14, 17
    Legs: (Next:8,Id:0,length:152.29)  
 8: [-1] Ids: 15, 18
    Legs: (Next:4,Id:0,length:374.25)  
 9: [-1] Ids: 16, 19
    Legs: (Next:10,Id:0,length:200.8)  
10: [-1] Ids: 18, 30, 21
    Legs: (Next:11,Id:0,length:158.77)  (Next:12,Id:0,length:155.02)  
11: [-1] Ids: 17, 20
    Legs: (Next:13,Id:0,length:142.48)  
12: [-1] Ids: 19, 22
    Legs: (Next:13,Id:0,length:140.25)  
13: [-1] Ids: 20, 23
    Legs: (Next:4,Id:0,length:260.01)  
14: [-1] Ids:  5,  5
    Legs: (Next:15,Id:0,length:187.87)  
15: [-1] Ids:  6,  6
    Legs: (Next:16,Id:0,length:248.72)  
16: [-1] Ids:  7,  7
    Legs: (Next:17,Id:0,length:206.65)  
17: [-1] Ids:  8,  8
    Legs: (Next:18,Id:0,length:212.08)  
18: [-1] Ids:  9,  9, 28, 29
    Legs: (Next:21,Id:0,length:159.1)  (Next:19,Id:0,length:153.82)  (Next:20,Id:0,length:121.19)  
19: [-1] Ids: 21, 13
    Legs: (Next:21,Id:0,length:155.63)  
20: [-1] Ids: 22, 14
    Legs: (Next:21,Id:0,length:139.25)  
21: [-1] Ids: 10, 10
    Legs: (Next:22,Id:0,length:196.93)  
22: [-1] Ids: 11, 11
";
            Assert.AreEqual(expected, actual);
        }
Пример #30
0
        void CheckCourse(string filename, CourseDesignator courseDesignator, string testName)
        {
            SymbolDB     symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr      undomgr = new UndoMgr(5);
            EventDB      eventDB = new EventDB(undomgr);
            CourseView   courseView, courseViewAllVariations;
            CourseLayout course;

            eventDB.Load(TestUtil.GetTestFile(filename));
            eventDB.Validate();

            // Create the course
            courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator);
            if (courseDesignator.IsVariation)
            {
                courseViewAllVariations = CourseView.CreateViewingCourseView(eventDB, courseDesignator.WithAllVariations());
            }
            else
            {
                courseViewAllVariations = courseView;
            }

            course = new CourseLayout();
            course.SetLayerColor(CourseLayer.AllVariations, 1, "Gray", 0, 0, 0, 0.4F, false);
            course.SetLayerColor(CourseLayer.MainCourse, 0, "Black", 0, 0, 0, 1F, false);
            course.SetLayerColor(CourseLayer.InvisibleObjects, 2, "DropTargets", 1F, 1F, 0, 0, false);
            TopologyFormatter formatter = new TopologyFormatter();
            RectangleF        rect      = formatter.FormatCourseToLayout(symbolDB, courseViewAllVariations, courseView, course, Id <CourseControl> .None, Id <CourseControl> .None, CourseLayer.AllVariations, CourseLayer.MainCourse);

            // Render to a map
            Map map = course.RenderToMap(new CourseLayout.MapRenderOptions());

            // Make drop targets visible.
            using (map.Write()) {
                foreach (SymDef symdef in map.AllSymdefs)
                {
                    if (symdef.SymbolId == "781")
                    {
                        map.SetSymdefVisible(symdef, true);
                    }
                }
            }

            // Render map to the graphics.
            Bitmap bm = new Bitmap((int)(1000 * rect.Width / rect.Height), 1000);

            using (Graphics g = Graphics.FromImage(bm)) {
                RenderOptions options = new RenderOptions();

                options.usePatternBitmaps = true;
                options.minResolution     = (float)(rect.Width / bm.Width);
                options.renderTemplates   = RenderTemplateOption.MapAndTemplates;

                g.ScaleTransform((float)(bm.Width / rect.Width), -(float)(bm.Height / rect.Height));
                g.TranslateTransform(-rect.Left, -rect.Top - rect.Height);

                g.Clear(Color.White);
                using (map.Read())
                    map.Draw(new GDIPlus_GraphicsTarget(g), rect, options, null);
            }

            TestUtil.CheckBitmapsBase(bm, "topologyformatter\\" + testName);
        }