// Change the orientation of a control. Must be a crossing point. public static void ChangeControlOrientation(EventDB eventDB, Id<ControlPoint> controlId, float newOrientation) { ControlPoint control = eventDB.GetControl(controlId); Debug.Assert(control.kind == ControlPointKind.CrossingPoint); control = (ControlPoint) control.Clone(); control.orientation = newOrientation; eventDB.ReplaceControlPoint(controlId, control); }
// Change one of the symbols associated with a control. symbolNumber is a column numnber, 0=C, 1=D, etc. // newSymbol is the string id of the new symbol to put there. Use null as the newSymbol to indicate // no symbol there. public static void ChangeDescriptionSymbol(EventDB eventDB, Id<ControlPoint> controlId, int symbolNumber, string newSymbol) { ControlPoint controlPoint = eventDB.GetControl(controlId); controlPoint = (ControlPoint)controlPoint.Clone(); controlPoint.symbolIds[symbolNumber] = newSymbol; if (symbolNumber == 3) controlPoint.columnFText = null; // if a symbol is put in column F, then no text can be there. eventDB.ReplaceControlPoint(controlId, controlPoint); }
// Change the gaps of a control for a given scale. public static void ChangeControlGaps(EventDB eventDB, Id<ControlPoint> controlId, float scale, CircleGap[] newGaps) { ControlPoint control = eventDB.GetControl(controlId); control = (ControlPoint) control.Clone(); int scaleInt = (int) Math.Round(scale); // scale is stored as int in the gaps to prevent rounding problems. if (newGaps == null || newGaps.Length == 0) { if (control.gaps != null) control.gaps.Remove(scaleInt); } else { if (control.gaps == null) control.gaps = new Dictionary<int, CircleGap[]>(); control.gaps[scaleInt] = newGaps; } eventDB.ReplaceControlPoint(controlId, control); }
// Change the location of a control. Used when dragging a control to a new location, for example. public static void ChangeControlLocation(EventDB eventDB, Id<ControlPoint> controlId, PointF newLocation) { // Check to see if any legs exist that include this control, and if any of those legs have gaps. List<LegGapChange> legGapChangeList = new List<LegGapChange>(); foreach (Id<Leg> legId in eventDB.AllLegIds) { Leg leg = eventDB.GetLeg(legId); if ((leg.controlId1 == controlId || leg.controlId2 == controlId) && leg.gaps != null) legGapChangeList.Add(new LegGapChange(leg.controlId1, leg.controlId2, QueryEvent.GetLegPath(eventDB, leg.controlId1, leg.controlId2, legId))); } // Move the control. ControlPoint control = eventDB.GetControl(controlId); control = (ControlPoint) control.Clone(); control.location = newLocation; eventDB.ReplaceControlPoint(controlId, control); // If there are any leg gaps that need to be repositioned, do that. if (legGapChangeList.Count > 0) { foreach (LegGapChange legGapChange in legGapChangeList) { Id<Leg> legId = QueryEvent.FindLeg(eventDB, legGapChange.controlId1, legGapChange.controlId2); if (legId.IsNotNone) { Leg leg = (Leg) eventDB.GetLeg(legId).Clone(); SymPath newPath = QueryEvent.GetLegPath(eventDB, legGapChange.controlId1, legGapChange.controlId2, legId); LegGap[] newGaps = LegGap.MoveGapsToNewPath(leg.gaps, legGapChange.legPath, newPath); ChangeEvent.ChangeLegGaps(eventDB, legGapChange.controlId1, legGapChange.controlId2, newGaps); } } } }
// Change the text in colum F for a control. If a symbol is there, it is removed.Null means no text or symbol. public static void ChangeColumnFText(EventDB eventDB, Id<ControlPoint> controlId, string newText) { ControlPoint controlPoint = eventDB.GetControl(controlId); if (newText == "") newText = null; // empty string is equivalent to null. controlPoint = (ControlPoint) controlPoint.Clone(); controlPoint.symbolIds[3] = null; controlPoint.columnFText = newText; eventDB.ReplaceControlPoint(controlId, controlPoint); }
// Change the code for a control. Does not attempt to validate the code -- it may even be a duplicate, // which is useful if renaming multiple codes in a single go. The control must be a normal control. public static void ChangeCode(EventDB eventDB, Id<ControlPoint> controlId, string newCode) { Debug.Assert(newCode != null); ControlPoint controlPoint = eventDB.GetControl(controlId); Debug.Assert(controlPoint.kind == ControlPointKind.Normal); controlPoint = (ControlPoint) controlPoint.Clone(); controlPoint.code = newCode; eventDB.ReplaceControlPoint(controlId, controlPoint); }
// Change the number location for a control in the all controls collection. If customLocation is false, puts the number location at the angle specified. public static void ChangeAllControlsCodeLocation(EventDB eventDB, Id<ControlPoint> controlId, bool customLocation, float newAngle) { ControlPoint controlPoint = eventDB.GetControl(controlId); controlPoint = (ControlPoint) controlPoint.Clone(); controlPoint.customCodeLocation = customLocation; controlPoint.codeLocationAngle = newAngle; eventDB.ReplaceControlPoint(controlId, controlPoint); }
// Set all punch patterns, by code, for the event. public static void SetAllPunchPatterns(EventDB eventDB, Dictionary<string, PunchPattern> allPatterns) { foreach (KeyValuePair<string, PunchPattern> pair in allPatterns) { Id<ControlPoint> controlId = QueryEvent.FindCode(eventDB, pair.Key); if (controlId.IsNotNone) { ControlPoint controlPoint = (ControlPoint) eventDB.GetControl(controlId).Clone(); if (pair.Value == null) controlPoint.punches = null; else controlPoint.punches = (PunchPattern) pair.Value.Clone(); eventDB.ReplaceControlPoint(controlId, controlPoint); } } }
// Change a text line associated with a control public static void ChangeTextLine(EventDB eventDB, Id<ControlPoint> controlId, string textLine, bool above) { ControlPoint control = eventDB.GetControl(controlId); control = (ControlPoint) control.Clone(); if (textLine == "") textLine = null; if (above) control.descTextBefore = textLine; else control.descTextAfter = textLine; eventDB.ReplaceControlPoint(controlId, control); }