Пример #1
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();
            }
        }
Пример #2
0
        // Layout a course onto one or more pages.
        List <CoursePage> LayoutCourse(CourseDesignator courseDesignator)
        {
            List <CoursePage> pageList = new List <CoursePage>();

            // Get the area of the map we want to print, in map coordinates, and the ratio between print scale and map scale.
            float      scaleRatio;
            bool       landscape;
            PaperSize  paperSize;
            string     description;
            int        margins;
            RectangleF mapArea = GetPrintAreaForCourse(courseDesignator, out landscape, out paperSize, out margins, out scaleRatio, out description);

            // Get the available page size on the page.
            RectangleF printableArea     = GetPrintablePageArea(landscape, paperSize, margins);
            SizeF      pageSizeAvailable = printableArea.Size;

            // Layout both page dimensions, iterate through them to get all the pages we have.
            foreach (DimensionLayout verticalLayout in LayoutPageDimension(mapArea.Top, mapArea.Height, printableArea.Top, printableArea.Height, scaleRatio))
            {
                foreach (DimensionLayout horizontalLayout in LayoutPageDimension(mapArea.Left, mapArea.Width, printableArea.Left, printableArea.Width, scaleRatio))
                {
                    CoursePage page = new CoursePage();
                    page.courseDesignator = courseDesignator;
                    page.description      = description;
                    page.landscape        = landscape;
                    page.paperSize        = paperSize;
                    page.mapRectangle     = new RectangleF(horizontalLayout.startMap, verticalLayout.startMap, horizontalLayout.lengthMap, verticalLayout.lengthMap);
                    page.printRectangle   = new RectangleF(horizontalLayout.startPage, verticalLayout.startPage, horizontalLayout.lengthPage, verticalLayout.lengthPage);
                    pageList.Add(page);
                }
            }

            return(pageList);
        }
Пример #3
0
        // Create a single PDF file
        void CreateOneBitmap(string fileName, CourseDesignator courseDesignator)
        {
            RectangleF mapRectangle = controller.GetCurrentPrintAreaRectangle(courseDesignator);

            // Get the course view for the course we are printing.
            CourseView courseView = CourseView.CreatePrintingCourseView(eventDB, 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);

            ExportBitmap exportBitmap = new ExportBitmap(mapDisplay);

            exportBitmap.CreateBitmap(fileName, mapRectangle, GetImageFormat(), bitmapCreationSettings.Dpi,
                                      bitmapCreationSettings.WorldFile ? mapDisplay.CoordinateMapper : null);
        }
Пример #4
0
        CourseLayout activeTopologyCourseLayout;            // The active topology

        public SelectionMgr(EventDB eventDB, SymbolDB symbolDB, Controller controller)
        {
            this.eventDB = eventDB;
            this.symbolDB = symbolDB;
            this.controller = controller;
            this.activeCourseDesignator = CourseDesignator.AllControls;
        }
Пример #5
0
        // Get the controls the define where to insert the new control point.
        private void GetControlInsertionPoint(PointF pt, out CourseDesignator courseDesignator,
                                              out Id <CourseControl> courseControlId1, out Id <CourseControl> courseControlId2,
                                              out LegInsertionLoc legInsertionLoc)
        {
            SelectionMgr.SelectionInfo selection = selectionMgr.Selection;
            courseDesignator = selection.ActiveCourseDesignator;
            courseControlId1 = Id <CourseControl> .None;
            courseControlId2 = Id <CourseControl> .None;
            legInsertionLoc  = LegInsertionLoc.Normal;

            if (selection.SelectionKind == SelectionMgr.SelectionKind.Control &&
                (courseDesignator.IsAllControls || QueryEvent.IsCourseControlInPart(eventDB, courseDesignator, selection.SelectedCourseControl)))
            {
                courseControlId1 = selection.SelectedCourseControl;
            }
            else if (selection.SelectionKind == SelectionMgr.SelectionKind.Leg)
            {
                courseControlId1 = selection.SelectedCourseControl;
                courseControlId2 = selection.SelectedCourseControl2;
                legInsertionLoc  = selection.LegInsertionLoc;
            }
            else if (courseDesignator.IsNotAllControls)
            {
                // Not all control, and neight control or leg is selected. Use the closest leg.
                QueryEvent.LegInfo leg = QueryEvent.FindClosestLeg(eventDB, courseDesignator, pt);
                courseControlId1 = leg.courseControlId1;
                courseControlId2 = leg.courseControlId2;
            }

            if (courseDesignator.IsNotAllControls)
            {
                QueryEvent.FindControlInsertionPoint(eventDB, courseDesignator, ref courseControlId1, ref courseControlId2, ref legInsertionLoc);
            }
        }
Пример #6
0
        public override void LeftButtonEndDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded)
        {
            Debug.Assert(pane == Pane.Map);

            DragTo(location);

            PointF upperLeft  = new PointF(currentObj.rect.Left, currentObj.rect.Bottom);
            float  cellSize   = currentObj.CellSize;
            int    numColumns = currentObj.NumberOfColumns;

            // Create the new description, unless it's ridiculously small.
            if (cellSize > 0.5F)
            {
                CourseDesignator[] courses = null;
                courses = new CourseDesignator[] { courseDesignator.WithAllVariations() };

                undoMgr.BeginCommand(1522, CommandNameText.AddObject);
                Id <Special> specialId = ChangeEvent.AddDescription(eventDB, false, courses, upperLeft, cellSize, numColumns);
                undoMgr.EndCommand(1522);

                selectionMgr.SelectSpecial(specialId);
            }


            controller.DefaultCommandMode();
            displayUpdateNeeded = true;
        }
Пример #7
0
        // Create a single OCAD file.
        void CreateFile(CourseDesignator courseDesignator)
        {
            // Get the file name of the output.
            string outputFilename = CreateOutputFileName(courseDesignator);

            // Create the course view.
            CourseView courseView = CourseView.CreatePrintingCourseView(eventDB, courseDesignator);

            // Write the OCAD file.
            ExportMap(courseView, outputFilename);
        }
Пример #8
0
 private bool CheckFilter(CourseDesignator designator)
 {
     if (Filter == null)
     {
         return(true);
     }
     else
     {
         return(Filter(designator));
     }
 }
Пример #9
0
 public AddDescriptionMode(Controller controller, UndoMgr undoMgr, SelectionMgr selectionMgr, EventDB eventDB, SymbolDB symbolDB, CourseDesignator courseDesignator, DescriptionLine[] description, DescriptionKind kind)
 {
     this.controller       = controller;
     this.undoMgr          = undoMgr;
     this.selectionMgr     = selectionMgr;
     this.symbolDB         = symbolDB;
     this.eventDB          = eventDB;
     this.courseDesignator = courseDesignator;
     this.description      = description;
     this.kind             = kind;
 }
Пример #10
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);
        }
Пример #11
0
        private void courseTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            bool             courseHasVariations = false;
            CourseDesignator courseDesignator    = courseTreeView.SelectedNode.Tag as CourseDesignator;

            if (courseDesignator != null && courseDesignator.IsNotAllControls)
            {
                courseHasVariations = QueryEvent.HasVariations(eventDB, courseDesignator.CourseId);
            }

            buttonChooseVariations.Enabled = courseHasVariations;
        }
Пример #12
0
        private CoursePage PdfNonScaledPage(CourseDesignator designator)
        {
            RectangleF pageArea = new RectangleF(0, 0, Geometry.HundredthsInchesFromMm(mapBounds.Width), Geometry.HundredthsInchesFromMm(mapBounds.Height));

            return(new CoursePage()
            {
                courseDesignator = designator,
                landscape = false,
                mapRectangle = mapBounds,
                printRectangle = pageArea,
                paperSize = new PaperSize("", (int)Math.Round(pageArea.Width), (int)Math.Round(pageArea.Height))
            });
        }
Пример #13
0
        public void ScalingMethods()
        {
            CourseAppearance appearance = (CourseAppearance)defaultCourseAppearance.Clone();

            CourseDesignator courseDesignator = new CourseDesignator(CourseId(4));

            appearance.itemScaling = ItemScaling.None;
            CheckCourse("courserenderer\\scaling.ppen", courseDesignator, false, "scaling_noscale", new RectangleF(-22, -33, 160, 160), appearance);
            appearance.itemScaling = ItemScaling.RelativeToMap;
            CheckCourse("courserenderer\\scaling.ppen", courseDesignator, false, "scaling_maprelative", new RectangleF(-22, -33, 160, 160), appearance);
            appearance.itemScaling = ItemScaling.RelativeTo15000;
            CheckCourse("courserenderer\\scaling.ppen", courseDesignator, false, "scaling_15krelative", new RectangleF(-22, -33, 160, 160), appearance);
        }
Пример #14
0
        public CourseDesignator DesignatorFromCourseId(EventDB eventDB, Id <Course> courseId)
        {
            CourseDesignator designator;

            if (QueryEvent.HasVariations(eventDB, courseId))
            {
                var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First();
                designator = new CourseDesignator(courseId, variationInfo);
            }
            else
            {
                designator = new CourseDesignator(courseId);
            }
            return(designator);
        }
Пример #15
0
        public void ComplexVariationsOnePath()
        {
            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = new VariationInfo("AEFDCI", variationPath);

            CourseDesignator courseDesignator = new CourseDesignator(CourseId(1), variationInfo);
            CheckCourse("topologyformatter\\variations.ppen", courseDesignator, "complexvariations_onepath");
        }
Пример #16
0
        public void ComplexVariationsOnePath()
        {
            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = new VariationInfo("AEFDCI", variationPath);

            CourseDesignator courseDesignator = new CourseDesignator(CourseId(1), variationInfo);

            CheckCourse("topologyformatter\\variations.ppen", courseDesignator, "complexvariations_onepath");
        }
Пример #17
0
        public void AllControlsCourseDesignator()
        {
            CourseDesignator d1, d2;

            d1 = CourseDesignator.AllControls;
            d2 = new CourseDesignator(Id <Course> .None);

            Assert.IsTrue(d1.Equals(d2));
            Assert.IsFalse(d1.Equals(new CourseDesignator(CourseId(1))));

            Assert.IsTrue(d1.GetHashCode() == d2.GetHashCode());
            Assert.IsFalse(d1.GetHashCode() == new CourseDesignator(CourseId(1)).GetHashCode());

            Assert.IsTrue(d1.IsAllControls);
            Assert.IsTrue(d1.CourseId.IsNone);
            Assert.IsTrue(d1.AllParts);
        }
Пример #18
0
        public void AllControlsCourseDesignator()
        {
            CourseDesignator d1, d2;

            d1 = CourseDesignator.AllControls;
            d2 = new CourseDesignator(Id<Course>.None);

            Assert.IsTrue(d1.Equals(d2));
            Assert.IsFalse(d1.Equals(new CourseDesignator(CourseId(1))));

            Assert.IsTrue(d1.GetHashCode() == d2.GetHashCode());
            Assert.IsFalse(d1.GetHashCode() == new CourseDesignator(CourseId(1)).GetHashCode());

            Assert.IsTrue(d1.IsAllControls);
            Assert.IsTrue(d1.CourseId.IsNone);
            Assert.IsTrue(d1.AllParts);
        }
Пример #19
0
        public void HideVariationCode()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

            eventDB.Load(TestUtil.GetTestFile("courserenderer\\Fake Relay.ppen"));
            eventDB.Validate();

            VariationInfo[]  variationInfos   = QueryEvent.GetAllVariations(eventDB, CourseId(3)).ToArray();
            CourseDesignator courseDesignator = new CourseDesignator(CourseId(3), variationInfos.First(vi => vi.CodeString == "BD"));

            CheckCourseBothAppearances("courserenderer\\Fake Relay.ppen", courseDesignator, false, "relayvariations_hidecode_1", RectangleF.FromLTRB(-80, -160, 180, 100));

            variationInfos   = QueryEvent.GetAllVariations(eventDB, CourseId(2)).ToArray();
            courseDesignator = new CourseDesignator(CourseId(2), variationInfos.First(vi => vi.CodeString == "BD"));
            CheckCourseBothAppearances("courserenderer\\Fake Relay.ppen", courseDesignator, false, "relayvariations_hidecode_2", RectangleF.FromLTRB(-80, -160, 180, 100));
        }
Пример #20
0
        public void CourseDesignatorRegular()
        {
            CourseDesignator d1, d2, d3;

            d1 = new CourseDesignator(CourseId(2));
            d2 = new CourseDesignator(CourseId(2));
            d3 = new CourseDesignator(CourseId(3));

            Assert.IsTrue(d1.Equals(d2));
            Assert.IsFalse(d1.Equals(d3));

            Assert.IsTrue(d1.GetHashCode() == d2.GetHashCode());
            Assert.IsFalse(d1.GetHashCode() == d3.GetHashCode());

            Assert.IsFalse(d1.IsAllControls);
            Assert.IsTrue(d1.CourseId.id == 2);
            Assert.IsTrue(d1.AllParts);
        }
Пример #21
0
        // Select the course with the given id as the active tab, id==0 means all controls.
        public void SelectCourseView(CourseDesignator newDesignator)
        {
            UpdateState();
            if (activeCourseDesignator != newDesignator) {
                bool courseChanged = (activeCourseDesignator.CourseId != newDesignator.CourseId);
                ++selectionChangeNum;
                activeCourseDesignator = newDesignator;

                // For now, when switching tabs (but not parts) the selection is cleared.
                // CONSIDER: maybe change this later; e.g., keep the selected control if it is in common.
                if (courseChanged) {
                    ClearSelection();
                    extraCourses = null;
                }

                // CONSIDER: record a non-persistant command with the Undo Manager.
            }
        }
Пример #22
0
        private void buttonChooseVariations_Click(object sender, EventArgs e)
        {
            CourseDesignator courseDesignator = courseTreeView.SelectedNode.Tag as CourseDesignator;

            if (courseDesignator != null)
            {
                SelectVariations variationsDialog = new SelectVariations(eventDB, courseDesignator.CourseId);

                VariationChoices variationChoices;
                if (variationChoicesPerCourse.TryGetValue(courseDesignator.CourseId, out variationChoices))
                {
                    variationsDialog.VariationChoices = variationChoices;
                }

                if (variationsDialog.ShowDialog(this) == DialogResult.OK)
                {
                    variationChoicesPerCourse[courseDesignator.CourseId] = variationsDialog.VariationChoices;
                }
            }
        }
Пример #23
0
        // Do CheckCourse for normal and special appearances.
        void CheckCourseBothAppearances(string filename, CourseDesignator courseDesignator, bool addAllControls, string testName, RectangleF rect)
        {
            CourseAppearance specialAppearance;

            // Special appearance to test the usage of CourseAppearance.
            specialAppearance = new CourseAppearance();
            specialAppearance.controlCircleSize  = 1.6F; //big control circle
            specialAppearance.lineWidth          = 0.2F; // thin lines
            specialAppearance.numberHeight       = 2F;   // really big numbers.
            specialAppearance.numberBold         = true; // bold numbers
            specialAppearance.numberOutlineWidth = 0.13F;
            specialAppearance.autoLegGapSize     = 0.0F;
            specialAppearance.useDefaultPurple   = false;
            specialAppearance.purpleC            = 0.32F;
            specialAppearance.purpleY            = 1.00F;
            specialAppearance.purpleM            = 0;
            specialAppearance.purpleK            = 0.30F;

            CheckCourse(filename, courseDesignator, addAllControls, testName, rect, defaultCourseAppearance);
            CheckCourse(filename, courseDesignator, addAllControls, testName + "_special", rect, specialAppearance);
        }
Пример #24
0
        public void ScalingCircleGaps()
        {
            CourseAppearance appearance = (CourseAppearance)defaultCourseAppearance.Clone();

            CourseDesignator courseDesignator10K = new CourseDesignator(CourseId(1));
            CourseDesignator courseDesignator5K  = new CourseDesignator(CourseId(2));
            CourseDesignator courseDesignator15K = new CourseDesignator(CourseId(3));

            appearance.itemScaling = ItemScaling.None;
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator5K, false, "scaling_5k_noscale", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator10K, false, "scaling_10k_noscale", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator15K, false, "scaling_15k_noscale", new RectangleF(69, -80, 70, 70), appearance);

            appearance.itemScaling = ItemScaling.RelativeToMap;
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator5K, false, "scaling_5k_maprelative", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator10K, false, "scaling_10k_maprelative", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator15K, false, "scaling_15k_maprelative", new RectangleF(69, -80, 70, 70), appearance);

            appearance.itemScaling = ItemScaling.RelativeTo15000;
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator5K, false, "scaling_5k_15krelative", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator10K, false, "scaling_10k_15krelative", new RectangleF(69, -80, 70, 70), appearance);
            CheckCourse("courserenderer\\CircleGapScaling.ppen", courseDesignator15K, false, "scaling_15k_15krelative", new RectangleF(69, -80, 70, 70), appearance);
        }
        // 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);
        }
Пример #26
0
        // Get the full output file name. Uses the name of the course, removes bad characters,
        // checks for duplication of the map file name. Puts in the directory given in the creationSettings.
        string CreateOutputFileName(CourseDesignator courseDesignator)
        {
            string extension;

            if (creationSettings.fileFormat.kind == MapFileFormatKind.OpenMapper)
            {
                if (creationSettings.fileFormat.subKind == OpenMapperSubKind.XMap)
                {
                    extension = ".xmap";
                }
                else
                {
                    extension = ".omap";
                }
            }
            else
            {
                extension = ".ocd";
            }
            string basename = QueryEvent.CreateOutputFileName(eventDB, courseDesignator, creationSettings.filePrefix, "", extension);

            return(Path.GetFullPath(Path.Combine(creationSettings.outputDirectory, basename)));
        }
        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);
        }
Пример #28
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);
            }
        }
Пример #29
0
        public void SingleVariation()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr  undomgr  = new UndoMgr(5);
            EventDB  eventDB  = new EventDB(undomgr);

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

            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = new VariationInfo("AEFDCI", variationPath);

            CourseDesignator courseDesignator = new CourseDesignator(CourseId(1), variationInfo);

            CheckCourseBothAppearances("queryevent\\variations.ppen", courseDesignator, false, "singlevariation", new RectangleF(-15, -100, 230, 230));
        }
Пример #30
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();
        }
Пример #31
0
        public void GetDesignatorsFromVariationChoices()
        {
            Setup("queryevent\\variations.ppen");

            List<CourseDesignator> result;
            CourseDesignator[] expected;

            result = QueryEvent.GetDesignatorsFromVariationChoices(eventDB, CourseId(2), new VariationChoices() { Kind = VariationChoices.VariationChoicesKind.Combined }).ToList();
            expected = new[] { new CourseDesignator(CourseId(2)) };
            CollectionAssert.AreEqual(expected, result);

            result = QueryEvent.GetDesignatorsFromVariationChoices(eventDB, CourseId(2), new VariationChoices() { Kind = VariationChoices.VariationChoicesKind.AllVariations }).ToList();
            expected = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2)) select new CourseDesignator(CourseId(2), vi)).ToArray();
            CollectionAssert.AreEqual(expected, result);

            result = QueryEvent.GetDesignatorsFromVariationChoices(eventDB, CourseId(2), new VariationChoices() {
                Kind = VariationChoices.VariationChoicesKind.ChosenVariations,
                ChosenVariations = new List<string> { "AC", "BD"}
                }).ToList();
            expected = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2))
                        where vi.CodeString=="AC" || vi.CodeString == "BD"
                        select new CourseDesignator(CourseId(2), vi)).ToArray();
            CollectionAssert.AreEqual(expected, result);

            VariationInfo ac, ad, bc, bd;
            ac = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2))
                 where vi.CodeString == "AC"
                 select vi).First();
            ad = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2))
                  where vi.CodeString == "AD"
                  select vi).First();
            bc = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2))
                  where vi.CodeString == "BC"
                  select vi).First();
            bd = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(2))
                  where vi.CodeString == "BD"
                  select vi).First();
            expected = new CourseDesignator[] {
                new CourseDesignator(CourseId(2), new VariationInfo(bd.CodeString, bd.Path, 6, 1)),
                new CourseDesignator(CourseId(2), new VariationInfo(bc.CodeString, bc.Path, 6, 2)),
                new CourseDesignator(CourseId(2), new VariationInfo(ac.CodeString, ac.Path, 6, 3)),
                new CourseDesignator(CourseId(2), new VariationInfo(ad.CodeString, ad.Path, 6, 4)),
                new CourseDesignator(CourseId(2), new VariationInfo(ad.CodeString, ad.Path, 7, 1)),
                new CourseDesignator(CourseId(2), new VariationInfo(ac.CodeString, ac.Path, 7, 2)),
                new CourseDesignator(CourseId(2), new VariationInfo(bc.CodeString, bc.Path, 7, 3)),
                new CourseDesignator(CourseId(2), new VariationInfo(bd.CodeString, bd.Path, 7, 4))
            };
            result = QueryEvent.GetDesignatorsFromVariationChoices(eventDB, CourseId(2), new VariationChoices() {
                Kind = VariationChoices.VariationChoicesKind.ChosenTeams,
                FirstTeam = 6,
                LastTeam = 7
            }).ToList();

            CollectionAssert.AreEqual(expected, result);
        }
 public CourseDesignator DesignatorFromCourseId(EventDB eventDB, Id<Course> courseId)
 {
     CourseDesignator designator;
     if (QueryEvent.HasVariations(eventDB, courseId)) {
         var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First();
         designator = new CourseDesignator(courseId, variationInfo);
     }
     else {
         designator = new CourseDesignator(courseId);
     }
     return designator;
 }
Пример #33
0
        public void AddVariation2()
        {
            Setup("queryevent\\variations.ppen");

            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = (from vi in QueryEvent.GetAllVariations(eventDB, CourseId(1)) where vi.Path.Equals(variationPath) select vi).First();

            CourseDesignator designator = new CourseDesignator(CourseId(1), variationInfo);

            undomgr.BeginCommand(3413, "Add Variation");

            bool result = ChangeEvent.AddVariation(eventDB, designator, CourseControlId(3), true, 2);
            Assert.IsTrue(result);

            undomgr.EndCommand(3413);

            eventDB.Validate();

            CourseControl cc = eventDB.GetCourseControl(CourseControlId(3));
            Assert.IsTrue(cc.split);
            Assert.IsTrue(cc.loop);
            Assert.AreEqual(3, cc.splitCourseControls.Length);

            undomgr.Undo();
            eventDB.Validate();
        }
Пример #34
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);
        }
Пример #35
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);
        }
Пример #36
0
        public void AllVariations()
        {
            CourseDesignator courseDesignator = new CourseDesignator(CourseId(1));

            CheckCourseBothAppearances("queryevent\\variations.ppen", courseDesignator, false, "allvariations", new RectangleF(-15, -100, 230, 230));
        }
Пример #37
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();
            }
        }
Пример #38
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);
        }
Пример #39
0
        // Do CheckCourse for normal and special appearances.
        void CheckCourseBothAppearances(string filename, CourseDesignator courseDesignator, bool addAllControls, string testName, RectangleF rect)
        {
            CourseAppearance specialAppearance;

            // Special appearance to test the usage of CourseAppearance.
            specialAppearance = new CourseAppearance();
            specialAppearance.controlCircleSize = 1.6F;  //big control circle
            specialAppearance.lineWidth = 0.2F; // thin lines
            specialAppearance.numberHeight = 2F; // really big numbers.
            specialAppearance.numberBold = true; // bold numbers
            specialAppearance.numberOutlineWidth = 0.13F;
            specialAppearance.autoLegGapSize = 0.0F;
            specialAppearance.useDefaultPurple = false;
            specialAppearance.purpleC = 0.32F;
            specialAppearance.purpleY = 1.00F;
            specialAppearance.purpleM = 0;
            specialAppearance.purpleK = 0.30F;

            CheckCourse(filename, courseDesignator, addAllControls, testName, rect, defaultCourseAppearance);
            CheckCourse(filename, courseDesignator, addAllControls, testName + "_special", rect, specialAppearance);
        }
Пример #40
0
 string[] CodesInOrder(CourseDesignator designator)
 {
     return (from ccid in QueryEvent.EnumCourseControlIds(eventDB, designator)
             select eventDB.GetControl(eventDB.GetCourseControl(ccid).control).code).ToArray();
 }
Пример #41
0
        public void SingleVariation()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr undomgr = new UndoMgr(5);
            EventDB eventDB = new EventDB(undomgr);

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

            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = new VariationInfo("AEFDCI", variationPath);

            CourseDesignator courseDesignator = new CourseDesignator(CourseId(1), variationInfo);

            CheckCourseBothAppearances("queryevent\\variations.ppen", courseDesignator, false, "singlevariation", new RectangleF(-15, -100, 230, 230));
        }
Пример #42
0
        public void CourseDesignatorRegular()
        {
            CourseDesignator d1, d2, d3;

            d1 = new CourseDesignator(CourseId(2));
            d2 = new CourseDesignator(CourseId(2));
            d3 = new CourseDesignator(CourseId(3));

            Assert.IsTrue(d1.Equals(d2));
            Assert.IsFalse(d1.Equals(d3));

            Assert.IsTrue(d1.GetHashCode() == d2.GetHashCode());
            Assert.IsFalse(d1.GetHashCode() == d3.GetHashCode());

            Assert.IsFalse(d1.IsAllControls);
            Assert.IsTrue(d1.CourseId.id == 2);
            Assert.IsTrue(d1.AllParts);
        }
Пример #43
0
        public void CanAddVariation()
        {
            Setup("queryevent\\variations.ppen");

            bool result = QueryEvent.CanAddVariation(eventDB, CourseDesignator.AllControls, CourseControlId(2));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(3));
            Assert.IsTrue(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(2));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(11));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(4));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(25));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(19));
            Assert.IsTrue(result);

            result = QueryEvent.CanAddVariation(eventDB, Designator(1), CourseControlId(1));
            Assert.IsTrue(result);

            VariationInfo.VariationPath variationPath = new VariationInfo.VariationPath(new[] {
                CourseControlId(2),
                CourseControlId(27),
                CourseControlId(30),
                CourseControlId(26),
                CourseControlId(25),
                CourseControlId(4),
                CourseControlId(28),
            });
            VariationInfo variationInfo = new VariationInfo("AEFDCI", variationPath);

            CourseDesignator designator = new CourseDesignator(CourseId(1), variationInfo);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(3));
            Assert.IsTrue(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(2));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(11));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(4));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(25));
            Assert.IsFalse(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(19));
            Assert.IsTrue(result);

            result = QueryEvent.CanAddVariation(eventDB, designator, CourseControlId(1));
            Assert.IsTrue(result);
        }
Пример #44
0
        // Get the full output file name. Uses the name of the course, removes bad characters,
        // checks for duplication of the map file name. Puts in the directory given in the creationSettings.
        string CreateOutputFileName(CourseDesignator courseDesignator)
        {
            string basename = QueryEvent.CreateOutputFileName(eventDB, courseDesignator, coursePdfSettings.filePrefix, "", ".pdf");

            return(Path.GetFullPath(Path.Combine(coursePdfSettings.outputDirectory, basename)));
        }
        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);
                description = descFormatter.CreateDescription(false);
                DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out);
                Console.WriteLine();
            }

            courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls);
            descFormatter = new DescriptionFormatter(courseView, symbolDB);
            description = descFormatter.CreateDescription(false);
            DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out);
        }
        // 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);
            DescriptionLine[] description = descFormatter.CreateDescription(createKey);

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

            Assert.AreEqual(expected, actual);
        }