/// <summary> /// Toggles the start side of a polygon. /// </summary> public void ToggleStartSide() { // Get first view model point PolygonPointViewModel point1 = PointCollection[0]; // Remove the first view model point PointCollection.Remove(point1); // Add the point to the end of the point collection PointCollection.Add(point1); // Get the first model point PolygonPoint pt1 = Polygon.Points[0]; // Remove the first model point Polygon.Points.Remove(pt1); // Add the point to the end of the point collection Polygon.Points.Add(pt1); // Update the green line segment Segments[0] = new LineSegmentViewModel(PointCollection[0], PointCollection[1]); Segments[0].Color = Colors.Lime; // Tell the view to refresh NotifyPointCollectionChanged(); }
/// <summary> /// Deletes the specified polygon point. /// </summary> public void DeletePoint(PolygonPointViewModel pt) { // Remove the point from the polygon PointCollection.Remove(pt); Polygon.Points.Remove(pt.PolygonPoint); // Update the green line segment Segments[0] = new LineSegmentViewModel(PointCollection[0], PointCollection[1]); Segments[0].Color = Colors.Lime; // Raise the collection Property changed event so that the converters in the view run NotifyPointCollectionChanged(); }
/// <summary> /// Adds the specified point to the point collection. /// </summary> /// <param name="position">Position of the new point</param> public override void AddPoint(Point position) { // Create the new model point PolygonPoint modelPoint = new PolygonPoint(); // Add the model point to the model's point collection Polygon.Points.Add(modelPoint); // Create the new view model point PolygonPointViewModel viewModelPoint = new PolygonPointViewModel(modelPoint, this); // Initialize the position of the point viewModelPoint.X = position.X; viewModelPoint.Y = position.Y; // Add the point to the view model point collection PointCollection.Add(viewModelPoint); // If there are at least two points on the polygon then... if (PointCollection.Count > 1) { // Create a segment between the points LineSegmentViewModel segment = new LineSegmentViewModel( viewModelPoint, PointCollection[PointCollection.Count - 2]); // Add the segment Segments.Add(segment); } // If there are two or more points then... if (PointCollection.Count >= 2) { // If the mouse is over the first polygon point then... if (IsMouseOverFirstPolygonPoint(position)) { // Remove the last point since we are going to connect up to the first point PointCollection.Remove(PointCollection[PointCollection.Count - 1]); Polygon.Points.Remove(Polygon.Points[Polygon.Points.Count - 1]); // Make the WPF polygon visible ClosePolygon(); } } }
/// <summary> /// Toggles the start side of a polygon. /// </summary> public void ToggleStartSide() { // Get first view model point PolygonPointViewModel point1 = PointCollection[0]; // Remove the first view model point PointCollection.Remove(point1); // Add the point to the end of the point collection PointCollection.Add(point1); // Get the first model point PolygonPoint pt1 = Ellipse.Points[0]; // Remove the first model point Ellipse.Points.Remove(pt1); // Add the point to the end of the point collection Ellipse.Points.Add(pt1); // Increment the start side Ellipse.StartSideRotation++; // If we are past the last side then... if (Ellipse.StartSideRotation > 3) { // Wrap around to the first side Ellipse.StartSideRotation = 0; } // Update the green line segment Segments[0] = new LineSegmentViewModel(PointCollection[0], PointCollection[1]); Segments[0].Color = Colors.Lime; // Force the view converters to run NotifyPointCollectionChanged(); }