Example #1
0
        public void WriteXml(string filename, RelayVariations relayVariations, EventDB eventDB, Id<Course> courseId)
        {
            this.relayVariations = relayVariations;
            this.eventDB = eventDB;
            this.courseId = courseId;
            this.modificationDate = DateTimeOffset.Now;
            this.courseName = eventDB.GetCourse(courseId).name;

            // Create the XML writer.
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.Encoding = new UTF8Encoding(false);
            xmlWriter = XmlWriter.Create(filename, settings);

            WriteStart();

            for (int teamNumber = 1; teamNumber < relayVariations.NumberOfTeams; ++teamNumber) {
                WriteTeam(teamNumber);
            }

            WriteEnd();

            // And done.
            xmlWriter.Close();
            eventDB = null;
            xmlWriter = null;
        }
        // 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;
        }
 public DescriptionPrinting(EventDB eventDB, SymbolDB symbolDB, Controller controller, DescriptionPrintSettings descPrintSettings)
     : base(QueryEvent.GetEventTitle(eventDB, " "), controller, descPrintSettings.PageSettings, descPrintSettings.BoxSize, descPrintSettings.CountKind, descPrintSettings.Count)
 {
     this.eventDB = eventDB;
     this.symbolDB = symbolDB;
     this.descPrintSettings = descPrintSettings;
 }
Example #4
0
        // Add a new course control to a course. Adds a new CourseControl referencing controlId into courseId. The place to insert is
        // given by courseControl1 and courseControl2. These control should have been gotten by calling FindControlInsertionPoint.
        public static Id<CourseControl> AddCourseControl(EventDB eventDB, Id<ControlPoint> controlId, Id<Course> courseId, Id<CourseControl> courseControl1, Id<CourseControl> courseControl2)
        {
            CourseControl newCourseControl;
            Id<CourseControl> newCourseControlId;

            // When adding a new course controls, they fit into variations fine because we are never adding or changing an split, just
            // fitting into existing splits.

            if (courseControl1.IsNone) {
                // Adding at start.
                Course course = (Course) eventDB.GetCourse(courseId).Clone();
                Debug.Assert(courseControl2 == course.firstCourseControl);
                newCourseControl = new CourseControl(controlId, course.firstCourseControl);
                newCourseControlId = eventDB.AddCourseControl(newCourseControl);
                course.firstCourseControl = newCourseControlId;
                eventDB.ReplaceCourse(courseId, course);
            }
            else {
                // Adding after courseControl1.
                CourseControl before = (CourseControl) eventDB.GetCourseControl(courseControl1).Clone();
                Debug.Assert(courseControl2 == before.nextCourseControl);
                newCourseControl = new CourseControl(controlId, before.nextCourseControl);
                newCourseControlId = eventDB.AddCourseControl(newCourseControl);
                before.nextCourseControl = newCourseControlId;
                eventDB.ReplaceCourseControl(courseControl1, before);
            }

            return newCourseControlId;
        }
Example #5
0
 public RelayVariations(EventDB eventDB, Id<Course> courseId, int numberTeams, int numberLegs)
 {
     this.eventDB = eventDB;
     this.courseId = courseId;
     this.numberTeams = numberTeams;
     this.numberLegs = numberLegs;
 }
Example #6
0
        public PrintCourses(EventDB eventDB, bool enableMultipart)
        {
            InitializeComponent();
            courseSelector.EventDB = eventDB;

            checkBoxMergeParts.Visible = enableMultipart;
        }
Example #7
0
        public SelectVariations(EventDB eventDB, Id<Course> courseId)
        {
            InitializeComponent();

            this.eventDB = eventDB;
            this.courseId = courseId;

            Course course = eventDB.GetCourse(courseId);
            if (course.relayTeams > 0)
                lastTeam = course.relayTeams;
            else
                lastTeam = null;

            comboBoxVariations.SelectedIndex = 0;
            if (lastTeam.HasValue) {
                upDownFirstTeam.Maximum = upDownLastTeam.Maximum = lastTeam.Value;
                upDownFirstTeam.Minimum = upDownLastTeam.Minimum = 1;
                upDownFirstTeam.Value = 1;
                upDownLastTeam.Value = lastTeam.Value;

                labelNumberOfTeams.Text = string.Format(labelNumberOfTeams.Text, lastTeam.Value);
            }

            UpdateControls();
        }
Example #8
0
 public OcadCreation(SymbolDB symbolDB, EventDB eventDB, Controller controller, CourseAppearance courseAppearance, OcadCreationSettings creationSettings)
 {
     this.symbolDB = symbolDB;
     this.eventDB = eventDB;
     this.controller = controller;
     this.courseAppearance = courseAppearance;
     this.creationSettings = creationSettings;
 }
 public ExportRouteGadget(SymbolDB symbolDB, EventDB eventDB, MapDisplay mapDisplay)
 {
     this.symbolDB = symbolDB;
     this.eventDB = eventDB;
     this.mapDisplay = mapDisplay.CloneToFullIntensity();
     this.mapDisplay.SetCourse(null);
     this.mapDisplay.SetPrintArea(null);
 }
Example #10
0
        // Do all courses have loads set?
        public static bool AllCoursesHaveLoads(EventDB eventDB)
        {
            foreach (Course course in eventDB.AllCourses) {
                if (course.load < 0)
                    return false;
            }

            return true;
        }
Example #11
0
 public AddRectangleMode(Controller controller, UndoMgr undoMgr, SelectionMgr selectionMgr, EventDB eventDB, float aspectRatio, Func<RectangleF, CourseObj> createCourseObj, Func<RectangleF, Id<Special>> createSpecial)
 {
     this.controller = controller;
     this.undoMgr = undoMgr;
     this.selectionMgr = selectionMgr;
     this.eventDB = eventDB;
     this.aspectRatio = aspectRatio;
     this.createCourseObj = createCourseObj;
     this.createSpecial = createSpecial;
 }
Example #12
0
 // If a course control is the beginning of a variation split, return all course controls assigned to that variation split.
 // Otherwise, return just that course control.
 public static IEnumerable<Id<CourseControl>> AllVariationsOfCourseControl(EventDB eventDB, Id<CourseControl> courseControlId)
 {
     CourseControl courseControl = eventDB.GetCourseControl(courseControlId);
     if (courseControl.split) {
         return courseControl.splitCourseControls;
     }
     else {
         return new[] { courseControlId };
     }
 }
 public TopologyDragControlMode(Controller controller, EventDB eventDB, SelectionMgr selectionMgr, CourseObj courseObject, PointF startDrag, PointF currentLocation)
 {
     this.controller = controller;
     this.eventDB = eventDB;
     this.selectionMgr = selectionMgr;
     this.courseObjectStart = courseObject;
     this.courseObjectDrag = (CourseObj)(courseObject.Clone());
     this.startDrag = startDrag;
     this.currentLocation = currentLocation;
     this.dropTargetHighlight = null;
 }
 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;
 }
Example #15
0
 public AddControlMode(Controller controller, SelectionMgr selectionMgr, UndoMgr undoMgr, EventDB eventDB, SymbolDB symbolDB, bool allControls, ControlPointKind controlKind, bool exchangeAtControl)
 {
     this.controller = controller;
     this.selectionMgr = selectionMgr;
     this.undoMgr = undoMgr;
     this.eventDB = eventDB;
     this.symbolDB = symbolDB;
     this.allControls = allControls;
     this.controlKind = controlKind;
     this.exchangeAtControl = exchangeAtControl;
     this.scaleRatio = selectionMgr.ActiveCourseView.ScaleRatio;
     this.appearance = controller.GetCourseAppearance();
 }
Example #16
0
 public AddTextMode(Controller controller, UndoMgr undoMgr, SelectionMgr selectionMgr, EventDB eventDB, string text, string fontName, bool fontBold, bool fontItalic, SpecialColor fontColor)
 {
     this.controller = controller;
     this.undoMgr = undoMgr;
     this.selectionMgr = selectionMgr;
     this.eventDB = eventDB;
     this.text = text;
     this.fontName = fontName;
     this.fontBold = fontBold;
     this.fontItalic = fontItalic;
     this.fontColor = fontColor;
     this.displayText = CourseFormatter.ExpandText(eventDB, selectionMgr.ActiveCourseView, text);
 }
Example #17
0
        // Create a single object associated with the leg from courseControlId1 to courseControlId2. Does not consider
        // flagging (but does consider bends and gaps.) Used for highlighting on the map.
        public static CourseObj CreateSimpleLeg(EventDB eventDB, float scaleRatio, CourseAppearance appearance, Id<CourseControl> courseControlId1, Id<CourseControl> courseControlId2)
        {
            Id<ControlPoint> controlId1 = eventDB.GetCourseControl(courseControlId1).control;
            Id<ControlPoint> controlId2 = eventDB.GetCourseControl(courseControlId2).control;
            ControlPoint control1 = eventDB.GetControl(controlId1);
            ControlPoint control2 = eventDB.GetControl(controlId2);
            LegGap[] gaps;

            SymPath legPath = GetLegPath(eventDB, control1.location, control1.kind, controlId1, control2.location, control2.kind, controlId2, scaleRatio, appearance, out gaps);
            if (legPath == null)
                return null;

            return new LegCourseObj(controlId1, courseControlId1, courseControlId2, scaleRatio, appearance, legPath, gaps);
        }
Example #18
0
        // CONSIDER: shouldn't take an eventDB. Should instead take a pair of CourseViewData/name or some such.
        public CreateOcadFiles(EventDB eventDB, MapFileFormatKind restrictToFormat, string title)
        {
            InitializeComponent();

            this.Text = title;
            courseSelector.EventDB = eventDB;

            // Initialize the items list in the file format. Only put in items matching "restrictToFormat".
            fileFormatCombo.Items.Clear();

            for (int i = 0; i < fileFormatDescriptors.Length; ++i) {
                if (restrictToFormat == MapFileFormatKind.None || restrictToFormat == fileFormatDescriptors[i].kind) {
                    fileFormatCombo.Items.Add(fileFormatStrings[i]);
                }
            }
        }
Example #19
0
        // mapDisplay is a MapDisplay that contains the correct map. All other features of the map display need to be customized.
        public CoursePrinting(EventDB eventDB, SymbolDB symbolDB, Controller controller, MapDisplay mapDisplay, CoursePrintSettings coursePrintSettings, CourseAppearance appearance)
            : base(QueryEvent.GetEventTitle(eventDB, " "), controller, coursePrintSettings.PageSettings, coursePrintSettings.PrintingColorModel)
        {
            this.eventDB = eventDB;
            this.symbolDB = symbolDB;
            this.controller = controller;
            this.mapDisplay = mapDisplay;
            this.coursePrintSettings = coursePrintSettings;
            this.appearance = appearance;

            // Set default features for printing.
            mapDisplay.MapIntensity = 1.0F;
            mapDisplay.AntiAlias = false;
            mapDisplay.Printing = true;
            mapDisplay.ColorModel = base.colorModel;
        }
Example #20
0
        public string CreateCourseSummaryReport(EventDB eventDB)
        {
            InitReport();

            // Header.
            WriteH1(string.Format(ReportText.CourseSummary_Title, QueryEvent.GetEventTitle(eventDB, " ")));

            // Table of all courses.
            BeginTable("", 4, "leftalign", "rightalign", "rightalign", "rightalign");
            WriteTableHeaderRow(ReportText.ColumnHeader_Course, ReportText.ColumnHeader_Controls, ReportText.ColumnHeader_Length, ReportText.ColumnHeader_Climb);

            // Enumerate all courses.
            Id<Course>[] courseIds = QueryEvent.SortedCourseIds(eventDB);

            // Write row for each course.
            foreach (Id<Course> courseId in courseIds) {
                BeginTableRow();
                CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(courseId));

                // Course name
                WriteTableCell(courseView.CourseName);

                // # of normal controls
                WriteTableCell(Util.RangeIfNeeded(courseView.MinNormalControls, courseView.MaxNormalControls));

                // Length (empty for score course)
                if (courseView.Kind == CourseView.CourseViewKind.Score)
                    WriteTableCell("");
                else
                    WriteTableCell(Util.GetLengthInKm(courseView.MinTotalLength, courseView.MaxTotalLength, 1));

                // Climb (empty for score course or no climb defined)
                if (courseView.Kind == CourseView.CourseViewKind.Score || courseView.TotalClimb < 0)
                    WriteTableCell("");
                else
                    WriteTableCell(Convert.ToString(Math.Round(courseView.TotalClimb / 5, MidpointRounding.AwayFromZero) * 5.0) + " m");

                EndTableRow();
            }

            EndTable();

            return FinishReport();
        }
Example #21
0
        // Get the angle from the given control index to the next control.
        public static double ComputeAngleOut(EventDB eventDB, CourseView courseView, int controlIndex)
        {
            PointF pt1 = eventDB.GetControl(courseView.ControlViews[controlIndex].controlId).location;

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

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

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

            return Math.Atan2(pt2.Y - pt1.Y, pt2.X - pt1.X);
        }
Example #22
0
        // mapDisplay is a MapDisplay that contains the correct map. All other features of the map display need to be customized.
        public CoursePdf(EventDB eventDB, SymbolDB symbolDB, Controller controller, MapDisplay mapDisplay, 
            CoursePdfSettings coursePdfSettings, CourseAppearance appearance)
        {
            this.eventDB = eventDB;
            this.symbolDB = symbolDB;
            this.controller = controller;
            this.mapDisplay = mapDisplay;
            this.coursePdfSettings = coursePdfSettings;
            this.appearance = appearance;

            // Set default features for printing.
            mapDisplay.MapIntensity = 1.0F;
            mapDisplay.AntiAlias = false;
            mapDisplay.Printing = true;
            mapDisplay.ColorModel = coursePdfSettings.ColorModel;

            mapBounds = mapDisplay.MapBounds;

            if (mapDisplay.MapType == MapType.PDF) {
                // For PDF maps, we remove the PDF map from the MapDisplay and add it in separately.
                sourcePdfMapFileName = mapDisplay.FileName;
            }
        }
Example #23
0
        CourseView topologyCourseView; // The active course view, but: null if all controls or score, plus always shows all variations and parts.

        #endregion Fields

        #region Constructors

        public SelectionMgr(EventDB eventDB, SymbolDB symbolDB, Controller controller)
        {
            this.eventDB = eventDB;
            this.symbolDB = symbolDB;
            this.controller = controller;
            this.activeCourseDesignator = CourseDesignator.AllControls;
        }
Example #24
0
        public GpxFile(EventDB eventDB, CoordinateMapper coordinateMapper, GpxCreationSettings settings)
        {
            this.eventDB = eventDB;
            this.settings = settings;
            this.coordinateMapper = coordinateMapper;

            if (coordinateMapper == null)
                throw new Exception("The map file must be an OCAD file to use GPX files.");
        }
Example #25
0
 internal void SetEventDB(EventDB eventDB)
 {
     this.eventDB = eventDB;
 }
Example #26
0
        // Create the normal view onto a score course
        private static CourseView CreateScoreCourseView(EventDB eventDB, CourseDesignator courseDesignator)
        {
            Course course = eventDB.GetCourse(courseDesignator.CourseId);
            CourseView courseView = new CourseView(eventDB, courseDesignator);
            Id<CourseControl> courseControlId;

            courseView.courseName = course.name;
            courseView.scoreColumn = course.scoreColumn;

            courseControlId = course.firstCourseControl;

            while (courseControlId.IsNotNone) {
                ControlView controlView = new ControlView();
                CourseControl courseControl = eventDB.GetCourseControl(courseControlId);

                controlView.courseControlIds = new[] { courseControlId };
                controlView.controlId = courseControl.control;

                // Ordinals assigned after sorting.
                controlView.ordinal = -1;

                controlView.joinIndex = -1;

                // Move to the next control.
                courseView.controlViews.Add(controlView);
                courseControlId = courseControl.nextCourseControl;
            }

            // Sort the control views: first by kind, then by score, then by code.
            courseView.controlViews.Sort(delegate(ControlView view1, ControlView view2) {
                ControlPoint control1 = eventDB.GetControl(view1.controlId);
                ControlPoint control2 = eventDB.GetControl(view2.controlId);
                CourseControl courseControl1 = eventDB.GetCourseControl(view1.courseControlIds[0]);
                CourseControl courseControl2 = eventDB.GetCourseControl(view2.courseControlIds[0]);

                if (control1.kind < control2.kind)
                    return -1;
                else if (control1.kind > control2.kind)
                    return 1;

                if (courseControl1.points != courseControl2.points)
                    return courseControl1.points.CompareTo(courseControl2.points);
                int result = Util.CompareCodes(control1.code, control2.code);
                if (result != 0)
                    return result;

                return view1.controlId.id.CompareTo(view2.controlId.id);
            });

            // Assign ordinals, if applicable. If scores in column A, then no ordinals will be assigned.
            if (courseView.scoreColumn != 0) {
                int ordinal = course.firstControlOrdinal;
                foreach (ControlView control in courseView.controlViews) {
                    if (eventDB.GetControl(control.controlId).kind == ControlPointKind.Normal)
                        control.ordinal = ordinal++;
                }
            }

            courseView.Finish();
            return courseView;
        }
Example #27
0
        //  -----------  Static methods to create a new CourseView.  -----------------
        // Create a normal course view -- the standard view in order, from start control to finish control. courseId may NOT be None.
        private static CourseView CreateCourseView(EventDB eventDB, CourseDesignator courseDesignator, bool addNonDescriptionSpecials, bool addDescriptionSpecials)
        {
            Debug.Assert(! courseDesignator.IsAllControls);

            Course course = eventDB.GetCourse(courseDesignator.CourseId);
            CourseView courseView;
            if (course.kind == CourseKind.Score)
                courseView = CreateScoreCourseView(eventDB, courseDesignator);
            else if (course.kind == CourseKind.Normal) {
                if (QueryEvent.HasVariations(eventDB, courseDesignator.CourseId) && !courseDesignator.IsVariation)
                    courseView = CreateAllVariationsCourseView(eventDB, courseDesignator);
                else
                    courseView = CreateStandardCourseView(eventDB, courseDesignator);
            }
            else {
                Debug.Fail("Bad course kind"); return null;
            }

            courseView.AddSpecials(courseDesignator, addNonDescriptionSpecials, addDescriptionSpecials);

            return courseView;
        }
Example #28
0
        // Create the view of all variations of a course with variations. Cannot be a single part of a multi-part course.
        // Does not contain ordinals.
        private static CourseView CreateAllVariationsCourseView(EventDB eventDB, CourseDesignator courseDesignator)
        {
            Course course = eventDB.GetCourse(courseDesignator.CourseId);

            if (!courseDesignator.AllParts)
                throw new ApplicationException("Cannot create all variations of a single part");

            CourseView courseView = new CourseView(eventDB, courseDesignator);

            courseView.courseName = course.name;
            courseView.scoreColumn = -1;

            // To get the ordinals correct, we get the course control ids for all parts.
            List<Id<CourseControl>> courseControls = QueryEvent.EnumCourseControlIds(eventDB, courseDesignator).ToList();

            for (int index = 0; index < courseControls.Count; ++index) {
                Id<CourseControl> courseControlId = courseControls[index];
                CourseControl courseControl = eventDB.GetCourseControl(courseControlId);

                // We add each split control only once, even though it has multiple variations. Check to see if we have already
                // handled it.
                bool alreadyHandled = false;
                if (courseControl.split) {
                    foreach (ControlView cv in courseView.controlViews) {
                        if (cv.courseControlIds.Contains(courseControlId))
                            alreadyHandled = true;
                    }
                }

                if (!alreadyHandled) {
                    ControlView controlView = new ControlView();

                    controlView.controlId = courseControl.control;

                    // Set the ordinal number. All variations does not include an ordinal.
                    controlView.ordinal = -1;

                    // Set all course control ids associated with split control, or a single one for a non-split control.
                    // Set the legTo array with the next courseControlID(s). This is later updated
                    // to the indices.
                    if (courseControl.split) {
                        controlView.courseControlIds = QueryEvent.AllVariationsOfCourseControl(eventDB, courseControlId).ToArray();
                        if (courseControl.nextCourseControl.IsNotNone) {
                            controlView.legTo = new int[controlView.courseControlIds.Length];
                            for (int i = 0; i < controlView.legTo.Length; ++i) {
                                controlView.legTo[i] = eventDB.GetCourseControl(controlView.courseControlIds[i]).nextCourseControl.id;
                            }
                        }
                        if (courseControl.loop)
                            controlView.joinIndex = courseControlId.id;
                        else
                            controlView.joinIndex = courseControl.splitEnd.id;
                    }
                    else {
                        controlView.courseControlIds = new[] { courseControlId };
                        if (courseControl.nextCourseControl.IsNotNone)
                            controlView.legTo = new int[1] { courseControl.nextCourseControl.id };   // legTo initially holds course control ids, later changed.
                        controlView.joinIndex = -1;
                    }

                    // Add the controlview.
                    courseView.controlViews.Add(controlView);
                }
            }

            courseView.Finish();
            return courseView;
        }
Example #29
0
 // Create the All Controls view -- show all controls, sorted.
 private static CourseView CreateAllControlsView(EventDB eventDB)
 {
     return CreateFilteredAllControlsView(eventDB, null, ControlPointKind.None, true, true);
 }
Example #30
0
 // Create a course view for normal viewing.
 public static CourseView CreateViewingCourseView(EventDB eventDB, CourseDesignator courseDesignator)
 {
     if (courseDesignator.IsAllControls)
         return CourseView.CreateAllControlsView(eventDB);
     else
         return CourseView.CreateCourseView(eventDB, courseDesignator, true, true);
 }