/// <summary> /// Restores the state of this <see cref="VerticesControlGraphic"/>. /// </summary> /// <param name="memento">The object that was originally created with <see cref="VerticesControlGraphic.CreateMemento"/>.</param> public override void SetMemento(object memento) { PointsMemento pointsMemento = memento as PointsMemento; if (pointsMemento == null) { throw new ArgumentException("The provided memento is not the expected type.", "memento"); } _suspendSubjectPointChangeEvents = true; this.Subject.CoordinateSystem = CoordinateSystem.Source; try { int numPoints = Math.Min(this.Subject.Points.Count, pointsMemento.Count); for (int n = 0; n < numPoints; n++) { this.Subject.Points[n] = pointsMemento[n]; } for (int n = numPoints; n < this.Subject.Points.Count; n++) { this.Subject.Points.RemoveAt(numPoints); } for (int n = numPoints; n < pointsMemento.Count; n++) { this.Subject.Points.Add(pointsMemento[n]); } } finally { this.Subject.ResetCoordinateSystem(); _suspendSubjectPointChangeEvents = false; this.OnSubjectPointsChanged(this, new EventArgs()); } }
/// <summary> /// Captures the current state of this <see cref="BoundableStretchControlGraphic"/>. /// </summary> public override object CreateMemento() { PointsMemento pointsMemento = new PointsMemento(); this.Subject.CoordinateSystem = CoordinateSystem.Source; try { pointsMemento.Add(this.Subject.TopLeft); pointsMemento.Add(this.Subject.BottomRight); } finally { this.Subject.ResetCoordinateSystem(); } return(pointsMemento); }
/// <summary> /// Captures the current state of this <see cref="VerticesControlGraphic"/>. /// </summary> public override object CreateMemento() { PointsMemento pointsMemento = new PointsMemento(); this.Subject.CoordinateSystem = CoordinateSystem.Source; try { foreach (PointF point in this.Subject.Points) { pointsMemento.Add(point); } } finally { this.Subject.ResetCoordinateSystem(); } return(pointsMemento); }
/// <summary> /// Restores the state of this <see cref="BoundableStretchControlGraphic"/>. /// </summary> /// <param name="memento">The object that was originally created with <see cref="BoundableStretchControlGraphic.CreateMemento"/>.</param> public override void SetMemento(object memento) { PointsMemento pointsMemento = memento as PointsMemento; if (pointsMemento == null || pointsMemento.Count != 2) { throw new ArgumentException("The provided memento is not the expected type.", "memento"); } this.Subject.CoordinateSystem = CoordinateSystem.Source; try { this.Subject.TopLeft = pointsMemento[0]; this.Subject.BottomRight = pointsMemento[1]; } finally { this.Subject.ResetCoordinateSystem(); } }
public bool Equals(PointsMemento other) { if (this == other) { return(true); } if (other == null || this.Count != other.Count) { return(false); } for (int i = 0; i < this.Count; i++) { if (this[i] != other[i]) { return(false); } } return(true); }