// Determine if we should include this control as a waypoint. We check if "all controls" was selected, or if the // control is in any selected course. private bool IncludeControl(Id <ControlPoint> controlId) { if (settings.CourseIds.Contains(Id <Course> .None)) { return(true); } foreach (Id <Course> courseId in settings.CourseIds) { if (courseId.IsNotNone) { if (QueryEvent.CourseUsesControl(eventDB, new CourseDesignator(courseId), controlId)) { return(true); } } } return(false); }
// Create the highlight, and put it at the given location. // Set displayUpdateNeeded to true if the highlight was just created or was moved. void SetHighlightLocation(PointF highlightLocation, float pixelSize, ref bool displayUpdateNeeded) { if (highlight != null && highlight.location == highlightLocation) { return; } PointF unused; Id <ControlPoint> existingControl = HitTestPoint(highlightLocation, pixelSize, out unused); // Get where the control is being inserted. CourseDesignator courseDesignator; Id <CourseControl> courseControl1, courseControl2; LegInsertionLoc legInsertionLoc; GetControlInsertionPoint(highlightLocation, out courseDesignator, out courseControl1, out courseControl2, out legInsertionLoc); // Note, we cannot changed this existing highlight because it is needed for erasing. additionalHighlights = null; switch (controlKind) { case ControlPointKind.Normal: highlight = new ControlCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, courseObjRatio, appearance, null, highlightLocation); if (courseDesignator.IsNotAllControls && !(exchangeAtControl && existingControl.IsNotNone && QueryEvent.CourseUsesControl(eventDB, courseDesignator, existingControl)) && eventDB.GetCourse(courseDesignator.CourseId).kind != CourseKind.Score) { // Show the legs to and from the control also as additional highlights. additionalHighlights = CreateLegHighlights(eventDB, highlightLocation, Id <ControlPoint> .None, controlKind, courseControl1, courseControl2, courseObjRatio, appearance); } break; case ControlPointKind.MapIssue: highlight = new MapIssueCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, courseObjRatio, appearance, 0, highlightLocation, MapIssueCourseObj.RenderStyle.WithTail); break; case ControlPointKind.Start: highlight = new StartCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, courseObjRatio, appearance, 0, highlightLocation, CrossHairOptions.HighlightCrossHair); break; case ControlPointKind.MapExchange: highlight = new StartCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, courseObjRatio, appearance, 0, highlightLocation, CrossHairOptions.HighlightCrossHair); if (courseDesignator.IsNotAllControls && eventDB.GetCourse(courseDesignator.CourseId).kind != CourseKind.Score) { // Show the legs to and from the control also as additional highlights. additionalHighlights = CreateLegHighlights(eventDB, highlightLocation, Id <ControlPoint> .None, controlKind, courseControl1, courseControl2, courseObjRatio, appearance); } break; case ControlPointKind.Finish: highlight = new FinishCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, courseObjRatio, appearance, null, highlightLocation, CrossHairOptions.HighlightCrossHair); break; case ControlPointKind.CrossingPoint: highlight = new CrossingCourseObj(Id <ControlPoint> .None, Id <CourseControl> .None, Id <Special> .None, courseObjRatio, appearance, 0, 0, highlightLocation); if (courseDesignator.IsNotAllControls && eventDB.GetCourse(courseDesignator.CourseId).kind != CourseKind.Score) { // Show the legs to and from the control also as additional highlights. additionalHighlights = CreateLegHighlights(eventDB, highlightLocation, Id <ControlPoint> .None, controlKind, courseControl1, courseControl2, courseObjRatio, appearance); } break; default: throw new Exception("bad control kind"); } highlight.location = highlightLocation; displayUpdateNeeded = true; }
public override void LeftButtonClick(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded) { if (pane != Pane.Map) { return; } // Create the new control! // Are we creating a new control point, or using existing one? PointF highlightLocation; Id <ControlPoint> controlId = HitTestPoint(location, pixelSize, out highlightLocation); bool createNewControl = controlId.IsNone; string commandString; switch (controlKind) { case ControlPointKind.MapIssue: commandString = CommandNameText.AddMapIssue; break; case ControlPointKind.Start: commandString = CommandNameText.AddStart; break; case ControlPointKind.Finish: commandString = CommandNameText.AddFinish; break; case ControlPointKind.CrossingPoint: commandString = CommandNameText.AddCrossingPoint; break; case ControlPointKind.MapExchange: commandString = CommandNameText.AddMapExchange; break; default: if (exchangeAtControl) { commandString = CommandNameText.AddMapExchange; } else { commandString = CommandNameText.AddControl; } break; } undoMgr.BeginCommand(1321, commandString); if (createNewControl) { // Creating a new control point. string newCode = null; if (controlKind == ControlPointKind.Normal) { newCode = QueryEvent.NextUnusedControlCode(eventDB); } controlId = ChangeEvent.AddControlPoint(eventDB, controlKind, newCode, highlightLocation, 0, mapIssueKind); if (controlKind == ControlPointKind.Finish) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "14.3"); // set finish to "navigate to finish". } else if (controlKind == ControlPointKind.CrossingPoint) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "13.3"); // set to mandatory crossing point. } else if (controlKind == ControlPointKind.MapIssue) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "13.6"); // Map issue point. } } if (allControls) { // select the new control. selectionMgr.SelectControl(controlId); } else { // Add the control to the current course. // Get where to add the control. CourseDesignator courseDesignator; Id <CourseControl> courseControl1, courseControl2; LegInsertionLoc legInsertionLoc; GetControlInsertionPoint(highlightLocation, out courseDesignator, out courseControl1, out courseControl2, out legInsertionLoc); // And add it. Id <CourseControl> courseControlId; if (controlKind == ControlPointKind.Start) { courseControlId = ChangeEvent.AddStartOrMapIssueToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.MapIssue) { courseControlId = ChangeEvent.AddStartOrMapIssueToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.Finish) { courseControlId = ChangeEvent.AddFinishToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.MapExchange) { courseControlId = ChangeEvent.AddCourseControl(eventDB, controlId, courseDesignator.CourseId, courseControl1, courseControl2, legInsertionLoc); ChangeEvent.ChangeControlExchange(eventDB, courseControlId, true); } else if (exchangeAtControl && QueryEvent.CourseUsesControl(eventDB, courseDesignator, controlId)) { // Selected control already on course, just add map exchange at that courseControl(s)). courseControlId = Id <CourseControl> .None; foreach (Id <CourseControl> courseControlBecomesExchange in QueryEvent.GetCourseControlsInCourse(eventDB, courseDesignator, controlId)) { ChangeEvent.ChangeControlExchange(eventDB, courseControlBecomesExchange, true); courseControlId = courseControlBecomesExchange; } } else { courseControlId = ChangeEvent.AddCourseControl(eventDB, controlId, courseDesignator.CourseId, courseControl1, courseControl2, legInsertionLoc); if (exchangeAtControl) { ChangeEvent.ChangeControlExchange(eventDB, courseControlId, true); } } // select the new control. selectionMgr.SelectCourseControl(courseControlId); } undoMgr.EndCommand(1321); controller.DefaultCommandMode(); }