예제 #1
0
        public void SelectCourseObjectNormalCourse()
        {
            CourseObj courseobject;
            bool      success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\marymoor1.coursescribe"), true);

            Assert.IsTrue(success);

            selectionMgr.SelectCourseView(Designator(3));
            CourseLayout course = selectionMgr.CourseLayout;

            courseobject = course[0];
            Assert.IsTrue(courseobject.controlId.id == 1);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(2, 2);

            courseobject = course[6];
            Assert.IsTrue(courseobject.controlId.id == 41);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(5, 5);

            courseobject = course[30];
            Assert.IsTrue(courseobject.controlId.id == 53);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(4, 4);
        }
예제 #2
0
        public void AllControlsEquals()
        {
            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 all controls course
            courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            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 the all controls course again
            courseView2 = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            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 SelectCourseObjectAllControls()
        {
            bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\marymoor1.coursescribe"), true);

            Assert.IsTrue(success);

            selectionMgr.SelectCourseView(Designator(0));
            CourseLayout course = selectionMgr.CourseLayout;

            CourseObj courseobject = course[4];

            Assert.IsTrue(courseobject.controlId.id == 38);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(6, 6);

            courseobject = course[0];
            Assert.IsTrue(courseobject.controlId.id == 1);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(2, 2);

            courseobject = course[37];
            Assert.IsTrue(courseobject.controlId.id == 2);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(39, 39);

            courseobject = course[41];
            Assert.IsTrue(courseobject.controlId.id == 38);
            selectionMgr.SelectCourseObject(courseobject);
            CheckSelectedLines(6, 6);
        }
예제 #4
0
        // Format the given CourseView into a bunch of course objects, and add it to the given course Layout
        public RectangleF FormatCourseToLayout(SymbolDB symbolDB, CourseView courseViewAllVariations, CourseView specificVariation, CourseLayout courseLayout, CourseLayer layerAllVariations, CourseLayer layerSpecificVariation)
        {
            this.eventDB = courseViewAllVariations.EventDB;
            this.symbolDB = symbolDB;
            this.courseLayout = courseLayout;
            this.courseLayerAllVariationsAndParts = layerAllVariations;
            this.courseLayerSpecificVariation = layerSpecificVariation;
            this.controlViewsAllVariationsAndParts = courseViewAllVariations.ControlViews;
            this.controlViewsSpecificVariation = specificVariation.ControlViews;
            this.controlPositions = new ControlPosition[controlViewsAllVariationsAndParts.Count];
            this.courseControlIdsSpecificVariation = QueryEvent.EnumCourseControlIds(eventDB, specificVariation.CourseDesignator).ToArray();
            this.variationMap = QueryEvent.GetVariantCodeMapping(eventDB, courseViewAllVariations.CourseDesignator);

            SizeF totalAbstractSize = AssignControlPositions(0, controlViewsAllVariationsAndParts.Count, 0, 0);

            // Now create objects now that the positions have been created.
            scaleRatio = 1.0F;
            appearance = new CourseAppearance();

            for (int index = 0; index < controlViewsAllVariationsAndParts.Count; ++index) {
                CreateObjectsForControlView(controlViewsAllVariationsAndParts[index], controlPositions[index]);
            }

            PointF bottomCenter = LocationFromAbstractPosition(0, 0);
            SizeF size = SizeFromAbstractSize(totalAbstractSize);
            RectangleF rect = new RectangleF(bottomCenter.X - size.Width / 2, bottomCenter.Y - size.Height, size.Width, size.Height);
            rect.Inflate(widthUnit, heightUnit);
            return rect;
        }
예제 #5
0
        public void SelectLegTestObj()
        {
            bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent4.coursescribe"), true);

            Assert.IsTrue(success);

            selectionMgr.SelectCourseView(Designator(4));
            CourseLayout course = selectionMgr.CourseLayout;

            foreach (CourseObj courseobj in course)
            {
                if (courseobj is LegCourseObj && courseobj.courseControlId == CourseControlId(13) &&
                    ((LegCourseObj)courseobj).courseControlId2 == CourseControlId(14))
                {
                    selectionMgr.SelectCourseObject(courseobj);
                    break;
                }
            }

            SelectionMgr.SelectionInfo selectionInfo = selectionMgr.Selection;
            Assert.AreEqual(SelectionMgr.SelectionKind.Leg, selectionInfo.SelectionKind);
            Assert.AreEqual(22, selectionInfo.SelectedControl.id);
            Assert.AreEqual(13, selectionInfo.SelectedCourseControl.id);
            Assert.AreEqual(14, selectionInfo.SelectedCourseControl2.id);
            Assert.AreEqual(0, selectionInfo.SelectedSpecial.id);

            CourseObj[] selectedObjects = selectionMgr.SelectedCourseObjects;
            Assert.AreEqual(1, selectedObjects.Length);
            Assert.AreEqual(@"Leg:            control:22  course-control:13  scale:1  course-control2:14  path:N(17.24,5.42)--N(13.76,-5.42)", selectedObjects[0].ToString());
        }
예제 #6
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.");
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
        void CheckHitTest(CourseLayout course, PointF point, CourseLayer layerFilter, Predicate <CourseObj> filter, string expectedObject)
        {
            CourseObj courseobj = course.HitTest(point, 0.1F, layerFilter, filter);

            if (courseobj == null)
            {
                Assert.IsNull(expectedObject);
            }
            else
            {
                Console.WriteLine(courseobj);
                Assert.AreEqual(expectedObject, courseobj.ToString());
            }
        }
예제 #10
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");
        }
예제 #11
0
        public void SelectSpecialCourseObj()
        {
            bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent4.coursescribe"), true);

            Assert.IsTrue(success);

            // Select a special in all controls.
            selectionMgr.SelectCourseView(Designator(0));
            CourseLayout course       = selectionMgr.CourseLayout;
            CourseObj    courseobject = course[1];

            Assert.IsTrue(courseobject.specialId.id == 4);
            selectionMgr.SelectCourseObject(courseobject);

            CheckSelectedLines(-1, -1);
            SelectionMgr.SelectionInfo selectionInfo = selectionMgr.Selection;
            Assert.AreEqual(SelectionMgr.SelectionKind.Special, selectionInfo.SelectionKind);
            Assert.AreEqual(0, selectionInfo.SelectedControl.id);
            Assert.AreEqual(0, selectionInfo.SelectedCourseControl.id);
            Assert.AreEqual(4, selectionInfo.SelectedSpecial.id);

            CourseObj[] selectedObjects = selectionMgr.SelectedCourseObjects;
            Assert.AreEqual(1, selectedObjects.Length);
            Assert.AreEqual(@"OOB:            special:4  scale:1  path:N(3,7)--N(11,2)--N(0,-7)--N(-12,-3)--N(3,7)", selectedObjects[0].ToString());

            // Select a special in a course view
            selectionMgr.SelectCourseView(Designator(3));
            course       = selectionMgr.CourseLayout;
            courseobject = course[2];
            Assert.IsTrue(courseobject.specialId.id == 3);
            selectionMgr.SelectCourseObject(courseobject);

            CheckSelectedLines(-1, -1);
            selectionInfo = selectionMgr.Selection;
            Assert.AreEqual(SelectionMgr.SelectionKind.Special, selectionInfo.SelectionKind);
            Assert.AreEqual(0, selectionInfo.SelectedControl.id);
            Assert.AreEqual(0, selectionInfo.SelectedCourseControl.id);
            Assert.AreEqual(3, selectionInfo.SelectedSpecial.id);

            selectedObjects = selectionMgr.SelectedCourseObjects;
            Assert.AreEqual(1, selectedObjects.Length);
            Assert.AreEqual(@"Boundary:       special:3  scale:0.6666667  path:N(11,2)--N(0,-7)--N(-12,-3)", selectedObjects[0].ToString());
        }
예제 #12
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, false, 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();

            // 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);
        }
예제 #13
0
        // Get the area of the map we want to print, in map coordinates, and the print scale.
        // if the courseId is None, do all controls.
        // If asked for, crop to a single page size.
        RectangleF GetPrintAreaForCourse(CourseDesignator courseDesignator, out bool landscape, out PaperSize paperSize, out int margins, out float scaleRatio, out string description)
        {
            // Get the course view to get the scale ratio.
            CourseView courseView = CourseView.CreatePositioningCourseView(eventDB, courseDesignator);
            scaleRatio = courseView.ScaleRatio;
            description = courseView.CourseFullName;

            RectangleF printRectangle = controller.GetCurrentPrintAreaRectangle(courseDesignator);
            PrintArea printArea = controller.GetCurrentPrintArea(courseDesignator);
            landscape = printArea.pageLandscape;
            paperSize = new PaperSize("", printArea.pageWidth, printArea.pageHeight);
            margins = printArea.pageMargins;

            if (cropLargePrintArea) {
                // Crop the print area to a single page, portrait or landscape.
                // Try to keep CourseObjects in view as much as possible.
                CourseLayout layout = new CourseLayout();
                CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, layout, 0);
                RectangleF courseObjectsArea = layout.BoundingRect();
                courseObjectsArea.Intersect(printRectangle);

                // We may need to crop the print area to fit.
                float areaCovered;
                RectangleF printableArea = GetPrintablePageArea(landscape, paperSize, margins);
                RectangleF croppedRectangle = CropPrintArea(printRectangle, courseObjectsArea, GetScaledPrintableSizeInMapUnits(printableArea, scaleRatio), out areaCovered);

                return croppedRectangle;
            }
            else {
                return printRectangle;
            }
        }
예제 #14
0
        CourseLayout CreateCourseLayout(CourseView courseView)
        {
            // Create the CourseLayout.
            CourseLayout courseLayout = new CourseLayout();
            courseLayout.SetLayerColor(CourseLayer.Descriptions, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
            courseLayout.SetLayerColor(CourseLayer.MainCourse, NormalCourseAppearance.courseOcadId, NormalCourseAppearance.courseColorName,
                creationSettings.cyan, creationSettings.magenta, creationSettings.yellow, creationSettings.black, creationSettings.purpleOverprint);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, courseAppearance, courseLayout, CourseLayer.MainCourse);

            return courseLayout;
        }
예제 #15
0
        // The core printing routine. The origin of the graphics is the upper-left of the margins,
        // and the printArea in the size to draw into (in hundreths of an inch).
        protected override void DrawPage(IGraphicsTarget graphicsTarget, int pageNumber, SizeF printArea, float dpi)
        {
            CoursePage page = pages[pageNumber];

            // Get the course view for the course we are printing.
            CourseView courseView = CourseView.CreatePrintingCourseView(eventDB, page.courseDesignator);

            // Get the correct purple color to print the course in.
            short ocadId;
            float purpleC, purpleM, purpleY, purpleK;
            bool purpleOverprint;
            FindPurple.GetPurpleColor(mapDisplay, appearance, out ocadId, out purpleC, out purpleM, out purpleY, out purpleK, out purpleOverprint);

            // Create a course layout from the view.
            CourseLayout layout = new CourseLayout();
            layout.SetLayerColor(CourseLayer.Descriptions, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
            layout.SetLayerColor(CourseLayer.MainCourse, ocadId, NormalCourseAppearance.courseColorName, purpleC, purpleM, purpleY, purpleK, purpleOverprint);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, layout, CourseLayer.MainCourse);

            // Set the course layout into the map display
            mapDisplay.SetCourse(layout);
            this.mapDisplay.SetPrintArea(null);

            // Collecting garbage should make out of memory less common.
            GC.Collect();

            if (graphicsTarget is GDIPlus_GraphicsTarget) {
                // We print to intermediate bands of bitmaps. This is the only way to get purple blending correct.
                // Other code ensure that if purple blending is on, we always take this code path.

                GDIPlus_GraphicsTarget gdiGraphicsTarget = ((GDIPlus_GraphicsTarget)graphicsTarget);
                Graphics g = gdiGraphicsTarget.Graphics;
                // Save and restore state so we can mess with stuff.
                GraphicsState graphicsState = g.Save();

                // Printing via a bitmap. Works best with some print drivers.
                dpi = AdjustDpi(dpi);

                const long MAX_PIXELS_PER_BAND = 20000000;    // 20M pixels = 60M bytes (3 bytes per pixel).
                List<CoursePage> bands = BandPageToLimitBitmapSize(page, dpi, MAX_PIXELS_PER_BAND);

                // Create the bitmap. Can do this once because each band is the same size.
                int bitmapWidth = (int) Math.Round(bands[0].printRectangle.Width * dpi / 100F);
                int bitmapHeight = (int) Math.Round(bands[0].printRectangle.Height * dpi / 100F);
                Bitmap bitmap = new Bitmap(bitmapWidth, bitmapHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                foreach (CoursePage band in bands) {
                    // Set the transform
                    Matrix transform = Geometry.CreateInvertedRectangleTransform(band.mapRectangle, new RectangleF(0, 0, bitmapWidth, bitmapHeight));
                    mapDisplay.Draw(bitmap, transform);

                    // Draw the bitmap on the printer.
                    g.DrawImage(bitmap, band.printRectangle);
                }

                // restore state.
                g.Restore(graphicsState);
                bitmap.Dispose();
            }
            else {
                // Print directly. Used only when prerasterization is off.
                // Set the transform, and the clip.
                Matrix transform = Geometry.CreateInvertedRectangleTransform(page.mapRectangle, page.printRectangle);
                PushRectangleClip(graphicsTarget, page.printRectangle);
                graphicsTarget.PushTransform(transform);
                // Determine the resolution in map coordinates.
                Matrix inverseTransform = transform.Clone();
                inverseTransform.Invert();
                float minResolutionPage = 100F / dpi;
                float minResolutionMap = Geometry.TransformDistance(minResolutionPage, inverseTransform);

                // And draw.
                mapDisplay.Draw(graphicsTarget, page.mapRectangle, minResolutionMap);

                graphicsTarget.PopTransform();
                graphicsTarget.PopClip();
            }
        }
예제 #16
0
        public void DisplayAllCourses()
        {
            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("courseformat\\marymoor1.coursescribe"));
            eventDB.Validate();

            foreach (Id<Course> courseId in QueryEvent.SortedCourseIds(eventDB)) {
                courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(courseId));
                course = new CourseLayout();
                CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
                course.Dump(Console.Out);
                Console.WriteLine();
            }

            courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            course = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, 0);
            course.Dump(Console.Out);
        }
예제 #17
0
        // Update the course
        void UpdateCourse()
        {
            CourseAppearance appearance = controller.GetCourseAppearance();

            // Get purple color.
            short purpleOcadId;
            float purpleC, purpleM, purpleY, purpleK;
            bool purpleOverprint;
            controller.GetPurpleColor(out purpleOcadId, out purpleC, out purpleM, out purpleY, out purpleK, out purpleOverprint);

            // Place the active course in the layout.
            activeCourse = new CourseLayout();
            activeCourse.SetLayerColor(CourseLayer.Descriptions, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
            activeCourse.SetLayerColor(CourseLayer.MainCourse, NormalCourseAppearance.courseOcadId, NormalCourseAppearance.courseColorName, purpleC, purpleM, purpleY, purpleK, purpleOverprint);
            CourseFormatter.FormatCourseToLayout(symbolDB, activeCourseView, appearance, activeCourse, CourseLayer.MainCourse);

            if (showAllControls && !activeCourseDesignator.IsAllControls) {
                // Create the all controls view.
                CourseView allControlsView = CourseView.CreateFilteredAllControlsView(eventDB, new CourseDesignator[] { activeCourseDesignator }, allControlsFilter, false, true);

                // Add it to the CourseLayout.
                activeCourse.SetLayerColor(CourseLayer.AllControls, NormalCourseAppearance.allControlsOcadId, NormalCourseAppearance.allControlsColorName,
                    NormalCourseAppearance.allControlsColorC, NormalCourseAppearance.allControlsColorM, NormalCourseAppearance.allControlsColorY, NormalCourseAppearance.allControlsColorK, purpleOverprint);
                CourseFormatter.FormatCourseToLayout(symbolDB, allControlsView, appearance, activeCourse, CourseLayer.AllControls);
            }
        }
예제 #18
0
 // Check this leg and add cuts to it if needed.
 private static void AutoCutLeg(EventDB eventDB, CourseAppearance appearance, CourseDesignator courseDesignator, LineCourseObj legObj, CourseLayout courseLayout)
 {
     foreach (CourseObj courseObj in courseLayout) {
         if (courseObj != legObj && courseObj.layer == legObj.layer && (courseObj is LegCourseObj || courseObj is FlaggedLegCourseObj))
             CutLegWithRespectTo(eventDB, appearance, courseDesignator, legObj, (LineCourseObj)courseObj);
         if (courseObj != legObj && courseObj.layer == legObj.layer && courseObj is PointCourseObj)
             CutLegWithRespectTo(eventDB, appearance, courseDesignator, legObj, (PointCourseObj)courseObj);
     }
 }
예제 #19
0
        // Cut any overlapping legs in the given layer.
        private static void AutoCutLegs(EventDB eventDB, CourseAppearance appearance, CourseDesignator courseDesignator, CourseLayout courseLayout, CourseLayer layer)
        {
            if (appearance.autoLegGapSize <= 0)
                return;     // No cutting requested.

            foreach (CourseObj courseObj in courseLayout) {
                if (courseObj.layer == layer && (courseObj is LegCourseObj || courseObj is FlaggedLegCourseObj))
                    AutoCutLeg(eventDB, appearance, courseDesignator, (LineCourseObj)courseObj, courseLayout);
            }
        }
예제 #20
0
 // Check this control and add cuts to it if needed.
 private static void AutoCutControl(PointCourseObj controlObj, CourseLayout courseLayout)
 {
     foreach (CourseObj courseObj in courseLayout) {
         if (courseObj != controlObj && courseObj.layer == controlObj.layer && courseObj is PointCourseObj)
             CutControlWithRespectTo(controlObj, (PointCourseObj)courseObj);
     }
 }
예제 #21
0
 // Cut any overlapping control circles in the given layer.
 private static void AutoCutCircles(CourseLayout courseLayout, CourseLayer layer)
 {
     foreach (CourseObj courseObj in courseLayout) {
         if (courseObj.layer == layer && (courseObj is ControlCourseObj || courseObj is FinishCourseObj))
             AutoCutControl((PointCourseObj) courseObj, courseLayout);
     }
 }
예제 #22
0
        // Format the given CourseView into a bunch of course objects, and add it to the given course Layout
        public static void FormatCourseToLayout(SymbolDB symbolDB, CourseView courseView, CourseAppearance appearance, CourseLayout courseLayout, CourseLayer layer)
        {
            EventDB eventDB = courseView.EventDB;
            CourseView.CourseViewKind kind = courseView.Kind;
            ControlLabelKind labelKind = courseView.ControlLabelKind;
            float scaleRatio = courseView.ScaleRatio;
            List<CourseView.ControlView> controlViews = courseView.ControlViews;
            CourseObj courseObj;

            // Go through all the specials in the view and process them to create course objects
            foreach(Id<Special> specialId in courseView.SpecialIds) {
                courseObj = CreateSpecial(eventDB, courseView, scaleRatio, appearance, specialId, layer);
                if (courseObj != null)
                    courseLayout.AddCourseObject(courseObj);
            }

            // Go through all the descriptions in the view and process them to create course objects
            foreach (CourseView.DescriptionView descriptionView in courseView.DescriptionViews) {
                // The layer depends on "descriptions in purple" setting in the course appearance.
                courseObj = CreateDescriptionSpecial(eventDB, symbolDB, descriptionView, appearance.descriptionsPurple ? layer : CourseLayer.Descriptions);
                if (courseObj != null)
                    courseLayout.AddCourseObject(courseObj);
            }

            // Go through all the controls in the view and process them to create controls and legs.
            for (int controlIndex = 0; controlIndex < controlViews.Count; ++controlIndex) {
                CourseView.ControlView controlView = controlViews[controlIndex];

                if (!controlView.hiddenControl) {

                    // Get the angles of the legs into and out of this control, in radians.
                    double angleOut = ComputeAngleOut(eventDB, courseView, controlIndex);

                    // Get the normal course object associated with this control.
                    courseObj = CreateCourseObject(eventDB, scaleRatio, appearance, courseView.PrintScale, controlView, angleOut);
                    if (courseObj != null) {
                        courseObj.layer = layer;
                        courseLayout.AddCourseObject(courseObj);
                    }

                    // If this course-control indicates custom placement, place the number/code now (so it influences auto-placed numbers).
                    if (CustomPlaceNumber(eventDB, controlView)) {
                        if (kind == CourseView.CourseViewKind.AllControls)
                            courseObj = CreateCode(eventDB, scaleRatio, appearance, controlView, courseLayout);
                        else if (kind == CourseView.CourseViewKind.AllVariations)
                            courseObj = CreateControlNumber(eventDB, scaleRatio, appearance, ControlLabelKind.Code, controlView, courseView, courseLayout);
                        else
                            courseObj = CreateControlNumber(eventDB, scaleRatio, appearance, labelKind, controlView, courseView, courseLayout);

                        if (courseObj != null) {
                            courseObj.layer = layer;
                            courseLayout.AddCourseObject(courseObj);
                        }
                    }
                }

                if (kind == CourseView.CourseViewKind.Normal || kind == CourseView.CourseViewKind.AllVariations) {
                    // Get the object(s) associated with the leg(s) to the next control.
                    if (controlView.legTo != null) {
                        for (int leg = 0; leg < controlView.legTo.Length; ++leg) {
                            CourseObj[] courseObjs = CreateLeg(eventDB, scaleRatio, appearance, controlView.courseControlIds[leg], controlView, controlViews[controlView.legTo[leg]], controlView.legId[leg]);
                            if (courseObjs != null) {
                                foreach (CourseObj o in courseObjs) {
                                    o.layer = layer;
                                    courseLayout.AddCourseObject(o);
                                }
                            }
                        }
                    }
                }
            }

            // Add any additional controls
            foreach (Id<CourseControl> extraCourseControl in courseView.ExtraCourseControls) {
                courseLayout.AddCourseObject(CreateCourseObject(eventDB, scaleRatio, appearance, courseView.PrintScale,
                                                                eventDB.GetCourseControl(extraCourseControl).control, extraCourseControl, double.NaN));
            }

            // No go through each control again and add an automatically placed number/code to each. We do this last so that the placement
            // of all fixed-position objects influences the auto-positioned numbers so that they don't interfere.
            for (int controlIndex = 0; controlIndex < controlViews.Count; ++controlIndex) {
                CourseView.ControlView controlView = controlViews[controlIndex];

                // Only place numbers WITHOUT custom number placement. Those with custom placement were done previously above.
                if (!controlView.hiddenControl && ! CustomPlaceNumber(eventDB, controlView)) {
                    if (kind == CourseView.CourseViewKind.AllControls)
                        courseObj = CreateCode(eventDB, scaleRatio, appearance, controlView, courseLayout);
                    else if (kind == CourseView.CourseViewKind.AllVariations)
                        courseObj = CreateControlNumber(eventDB, scaleRatio, appearance, ControlLabelKind.Code, controlView, courseView, courseLayout);
                    else
                        courseObj = CreateControlNumber(eventDB, scaleRatio, appearance, labelKind, controlView, courseView, courseLayout);

                    if (courseObj != null) {
                        courseObj.layer = layer;
                        courseLayout.AddCourseObject(courseObj);
                    }
                }
            }

            // Automatically add cuts to close control circles in the layout.
            if (courseView.Kind != CourseView.CourseViewKind.AllControls) {
                AutoCutCircles(courseLayout, layer);
                AutoCutLegs(eventDB, appearance, courseView.CourseDesignator, courseLayout, layer);
            }
        }
예제 #23
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);
        }
예제 #24
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);
            TopologyFormatter formatter = new TopologyFormatter();
            RectangleF rect = formatter.FormatCourseToLayout(symbolDB, courseViewAllVariations, courseView, course, CourseLayer.AllVariations, CourseLayer.MainCourse);

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

            // 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);
        }
예제 #25
0
        // Set the courses being displayed.
        public void SetCourse(CourseLayout newCourse)
        {
            if (! object.Equals(course, newCourse)) {
                course = newCourse;
                if (course == null)
                    courseMap = null;
                else
                    courseMap = course.RenderToMap();

                RaiseChanged(null);
            }
        }
예제 #26
0
        public void SetAllControlsDisplay()
        {
            StringWriter writer  = new StringWriter();
            bool         success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent3.coursescribe"), true);

            Assert.IsTrue(success);

            selectionMgr.SelectCourseView(Designator(1));
            CourseLayout course = selectionMgr.CourseLayout;

            course.Dump(writer);
            Assert.AreEqual(
                @"
Start:          control:1  course-control:1  scale:1  location:(5,0)  orientation:333.43
Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(6.81,3.61)--N(8.74,7.47)
Control:        control:2  course-control:2  scale:1  location:(10,10)  gaps:
Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(11.36,7.52)--N(28.7,-24.19)
Finish:         control:6  course-control:3  scale:1  location:(30.3,-27.11)  gaps:
ControlNumber:  control:2  course-control:2  scale:1  text:1  top-left:(7.54,20.12)
                font-name:Roboto  font-style:Regular  font-height:5.57
", writer.ToString());

            selectionMgr.SetAllControlsDisplay(true, ControlPointKind.None);

            writer = new StringWriter();
            course = selectionMgr.CourseLayout;
            course.Dump(writer);
            Assert.AreEqual(
                @"
Start:          control:1  course-control:1  scale:1  location:(5,0)  orientation:333.43
Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(6.81,3.61)--N(8.74,7.47)
Control:        control:2  course-control:2  scale:1  location:(10,10)  gaps:
Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(11.36,7.52)--N(28.7,-24.19)
Finish:         control:6  course-control:3  scale:1  location:(30.3,-27.11)  gaps:
ControlNumber:  control:2  course-control:2  scale:1  text:1  top-left:(7.54,20.12)
                font-name:Roboto  font-style:Regular  font-height:5.57
Start:          layer:12  control:7  scale:1  location:(0,5)  orientation:0
Control:        layer:12  control:3  scale:1  location:(20,-10.5)  gaps:56.25:67.5
Control:        layer:12  control:4  scale:1  location:(35.4,-22.5)  gaps:
Code:           layer:12  control:3  scale:1  text:32  top-left:(12.79,-10.93)
                font-name:Roboto Condensed  font-style:Bold  font-height:4.18
Code:           layer:12  control:4  scale:1  text:GO  top-left:(38.29,-16.89)
                font-name:Roboto Condensed  font-style:Bold  font-height:4.18
", writer.ToString());

            selectionMgr.SetAllControlsDisplay(true, ControlPointKind.Start);

            writer = new StringWriter();
            course = selectionMgr.CourseLayout;
            course.Dump(writer);
            Assert.AreEqual(
                @"
Start:          control:1  course-control:1  scale:1  location:(5,0)  orientation:333.43
Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(6.81,3.61)--N(8.74,7.47)
Control:        control:2  course-control:2  scale:1  location:(10,10)  gaps:
Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(11.36,7.52)--N(28.7,-24.19)
Finish:         control:6  course-control:3  scale:1  location:(30.3,-27.11)  gaps:
ControlNumber:  control:2  course-control:2  scale:1  text:1  top-left:(7.54,20.12)
                font-name:Roboto  font-style:Regular  font-height:5.57
Start:          layer:12  control:7  scale:1  location:(0,5)  orientation:0
", writer.ToString());


            selectionMgr.SetAllControlsDisplay(false, ControlPointKind.None);

            writer = new StringWriter();
            course = selectionMgr.CourseLayout;
            course.Dump(writer);
            Assert.AreEqual(
                @"
Start:          control:1  course-control:1  scale:1  location:(5,0)  orientation:333.43
Leg:            control:1  course-control:1  scale:1  course-control2:2  path:N(6.81,3.61)--N(8.74,7.47)
Control:        control:2  course-control:2  scale:1  location:(10,10)  gaps:
Leg:            control:2  course-control:2  scale:1  course-control2:3  path:N(11.36,7.52)--N(28.7,-24.19)
Finish:         control:6  course-control:3  scale:1  location:(30.3,-27.11)  gaps:
ControlNumber:  control:2  course-control:2  scale:1  text:1  top-left:(7.54,20.12)
                font-name:Roboto  font-style:Regular  font-height:5.57
", writer.ToString());
        }
예제 #27
0
        void CheckCourse(string testfileName, Id<Course> courseId, CourseLayer layer, string expected)
        {
            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(testfileName));
            eventDB.Validate();

            // Create the course
            courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(courseId));
            course = new CourseLayout();
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, layer);

            // Dump it to a string.
            StringWriter writer = new StringWriter();
            course.Dump(writer);

            // Check that the string is correct.
            string actual = writer.ToString();
            if (expected != actual) {
                for (int i = 0; i < Math.Min(expected.Length, actual.Length); ++i)
                    if (actual[i] != expected[i]) {
                        Console.WriteLine("Difference at -->{0}", actual.Substring(i, 30));
                        break;
                    }
            }

            Assert.AreEqual(expected, writer.ToString());
        }
예제 #28
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.05F, -34.22F, 151.44F, 79.67F);
            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 = RectangleF.FromLTRB(-2.1F, -32.6F, 62.6F, 27.3F);
            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 = RectangleF.FromLTRB(6.0F, -40.1F, 127.9F, 36.9F);
            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");
        }
예제 #29
0
        // The core printing routine.
        void DrawPage(IGraphicsTarget graphicsTarget, CoursePage page)
        {
            // Get the course view for the course we are printing.
            CourseView courseView = CourseView.CreatePrintingCourseView(eventDB, page.courseDesignator);

            // Get the correct purple color to print the course in.
            short ocadId;
            float purpleC, purpleM, purpleY, purpleK;
            bool purpleOverprint;
            FindPurple.GetPurpleColor(mapDisplay, appearance, out ocadId, out purpleC, out purpleM, out purpleY, out purpleK, out purpleOverprint);

            // Create a course layout from the view.
            CourseLayout layout = new CourseLayout();
            layout.SetLayerColor(CourseLayer.Descriptions, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
            layout.SetLayerColor(CourseLayer.MainCourse, ocadId, NormalCourseAppearance.courseColorName, purpleC, purpleM, purpleY, purpleK, purpleOverprint);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, layout, CourseLayer.MainCourse);

            // Set the course layout into the map display
            mapDisplay.SetCourse(layout);
            mapDisplay.SetPrintArea(null);

            // Set the transform, and the clip.
            Matrix transform = Geometry.CreateInvertedRectangleTransform(page.mapRectangle, page.printRectangle);
            PushRectangleClip(graphicsTarget, page.printRectangle);
            graphicsTarget.PushTransform(transform);
            // Determine the resolution in map coordinates.
            Matrix inverseTransform = transform.Clone();
            inverseTransform.Invert();
            float minResolutionPage = 100F / 2400F;  // Assume 2400 DPI as the base resolution, to get very accurate print.
            float minResolutionMap = Geometry.TransformDistance(minResolutionPage, inverseTransform);

            // And draw.
            mapDisplay.Draw(graphicsTarget, page.mapRectangle, minResolutionMap);

            graphicsTarget.PopTransform();
            graphicsTarget.PopClip();
        }
예제 #30
0
 // Get the area that encloses the given courseId.
 private RectangleF GetCourseArea(Id<Course> courseId)
 {
     // The default route gadget is the union of the bounding rectangle of the course objects, not including specials, inflated by 2cm.
     CourseView courseView = CourseView.CreateControlsOnlyPositioningCourseView(eventDB, new CourseDesignator(courseId));
     CourseLayout layout = new CourseLayout();
     CourseFormatter.FormatCourseToLayout(symbolDB, courseView, eventDB.GetEvent().courseAppearance, layout, 0);
     RectangleF courseObjects = RectangleF.Inflate(layout.BoundingRect(), 20.0F, 20.0F);
     return courseObjects;
 }
예제 #31
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.66,-12.22)
                font-name:Arial Narrow  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.61,36.87)
                font-name:Arial  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, false, true);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, defaultCourseAppearance, course, CourseLayer.AllControls);

            CheckHitTest(course, new PointF(5.1F, -5.1F), CourseLayer.All, null, @"Control:        layer:2  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);
        }
예제 #32
0
 void CheckHitTest(CourseLayout course, PointF point, CourseLayer layerFilter, Predicate<CourseObj> filter, string expectedObject)
 {
     CourseObj courseobj = course.HitTest(point, 0.1F, layerFilter, filter);
     if (courseobj == null) {
         Assert.IsNull(expectedObject);
     }
     else {
         Console.WriteLine(courseobj);
         Assert.AreEqual(expectedObject, courseobj.ToString());
     }
 }
예제 #33
0
 // Update the topology
 void UpdateTopology()
 {
     if (topologyCourseView == null) {
         activeTopologyCourseLayout = null;
     }
     else {
         // Place the active course in the layout.
         activeTopologyCourseLayout = new CourseLayout();
         activeTopologyCourseLayout.SetLayerColor(CourseLayer.AllVariations, 1, NormalCourseAppearance.blackColorName, 0, 0, 0, 0.55F, false);
         activeTopologyCourseLayout.SetLayerColor(CourseLayer.MainCourse, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
         TopologyFormatter formatter = new TopologyFormatter();
         formatter.FormatCourseToLayout(symbolDB, topologyCourseView, activeCourseView, activeTopologyCourseLayout, CourseLayer.AllVariations, CourseLayer.MainCourse);
     }
 }
예제 #34
0
        // Is there an all controls layer?
        internal static bool IsAllControlsLayer(CourseLayout courseLayout)
        {
            foreach (CourseObj obj in courseLayout) {
                if (obj.layer == CourseLayer.AllControls)
                    return true;
            }

            return false;
        }