// 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); } }
// Check the validate of the selected course view/selected object and update accordingly. void UpdateSelection() { // Check the selection validity. if (!activeCourseDesignator.IsAllControls && !eventDB.IsCoursePresent(activeCourseDesignator.CourseId)) { // Active course was deleted. Switch to all controls. activeCourseDesignator = CourseDesignator.AllControls; ClearSelection(); } // Check that variation still exists. if (activeCourseDesignator.IsVariation && QueryEvent.HasVariations(eventDB, activeCourseDesignator.CourseId)) { IEnumerable<VariationInfo> variations = QueryEvent.GetAllVariations(eventDB, activeCourseDesignator.CourseId); if (!variations.Any(v => v.Equals(activeCourseDesignator.VariationInfo))) activeCourseDesignator = activeCourseDesignator.WithAllVariations(); } // Does the current part still exist? int numberOfParts = QueryEvent.CountCourseParts(eventDB, activeCourseDesignator); if (!activeCourseDesignator.IsAllControls && !activeCourseDesignator.AllParts && (numberOfParts == 1 || activeCourseDesignator.Part >= numberOfParts)) { // No part that large any more. if (numberOfParts > 1) activeCourseDesignator = activeCourseDesignator.WithPart(numberOfParts - 1); else activeCourseDesignator = activeCourseDesignator.WithAllParts(); ClearSelection(); } if (selectedCourseControl.IsNotNone && !eventDB.IsCourseControlPresent(selectedCourseControl)) { // Selected course control is no longer there. selectedCourseControl = Id<CourseControl>.None; ClearSelection(); } if (selectedCourseControl.IsNotNone && activeCourseDesignator.IsNotAllControls && (!activeCourseDesignator.AllParts || activeCourseDesignator.IsVariation) && !QueryEvent.IsCourseControlInPart(eventDB, activeCourseDesignator, selectedCourseControl)) { // Selected course control is not in active part. // Could be allowed if it's the finish. Id<ControlPoint> controlId = eventDB.GetCourseControl(selectedCourseControl).control; if (!(eventDB.IsControlPresent(controlId) && eventDB.GetControl(controlId).kind == ControlPointKind.Finish && QueryEvent.GetPartOptions(eventDB, activeCourseDesignator).ShowFinish)) { selectedCourseControl = Id<CourseControl>.None; ClearSelection(); } } if (selectedCourseControl2.IsNotNone && !eventDB.IsCourseControlPresent(selectedCourseControl2)) { // Selected course control 2 is no longer there. selectedCourseControl2 = Id<CourseControl>.None; ClearSelection(); } if (selectedCourseControl2.IsNotNone && activeCourseDesignator.IsNotAllControls && !activeCourseDesignator.AllParts && !QueryEvent.IsCourseControlInPart(eventDB, activeCourseDesignator, selectedCourseControl2)) { // Selected course control 2 is not in active part. selectedCourseControl2 = Id<CourseControl>.None; ClearSelection(); } if (selectedControl.IsNotNone && !eventDB.IsControlPresent(selectedControl)) { // Selected control is no longer there. ClearSelection(); } if (selectedSpecial.IsNotNone && !eventDB.IsSpecialPresent(selectedSpecial)) { // Selected special is no longer there. ClearSelection(); } if (selectedSpecial.IsNotNone && !(activeCourseDesignator.IsAllControls || QueryEvent.CourseContainsSpecial(eventDB, activeCourseDesignator, selectedSpecial))) { // Selected special is not in current course ClearSelection(); } }