Esempio n. 1
0
        /// <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
            Line.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 the line is complete then...
            if (PointCollection.Count == 2)
            {
                // Calculate the center of the line
                UpdateCenterPoint();

                // Color the first point green
                PointCollection[0].DeselectedColor = Colors.Lime;
                PointCollection[0].Color           = PointCollection[0].DeselectedColor;

                // Make the line visible
                Visibility = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Toggles the start point of a wipe line.
        /// </summary>
        public void ToggleStartPoint()
        {
            // Create temporary references to the view model points
            PolygonPointViewModel tempStart = StartPoint;
            PolygonPointViewModel tempEnd   = EndPoint;

            // Create temporary references to the model points
            PolygonPoint startPoint = Line.Points[0];
            PolygonPoint endPoint   = Line.Points[1];

            // Swap the colors on the points
            tempStart.DeselectedColor = Colors.DodgerBlue;
            tempEnd.DeselectedColor   = Colors.Lime;

            // Swap the points on the view model
            PointCollection.Clear();
            StartPoint = tempEnd;
            EndPoint   = tempStart;
            PointCollection.Add(StartPoint);
            PointCollection.Add(EndPoint);

            // Swap the points on the model
            Line.Points.Clear();
            Line.Points.Add(endPoint);
            Line.Points.Add(startPoint);

            // Fire the collection changed event
            NotifyPointCollectionChanged();
        }
Esempio n. 3
0
        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
            Ellipse.Points.Add(modelPoint);

            // Create the new view model point
            PolygonPointViewModel viewModelPoint = new PolygonPointViewModel(modelPoint, null);

            // 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 this is complete polygon then...
            if (Ellipse.Points.Count >= 3)
            {
                // Calculate the center of the polygon
                UpdateCenterPoint();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ellipseModel">Ellipse model</param>
        /// <param name="labelVisible">Determines if the label is visible</param>
        public EllipseViewModel(Ellipse ellipseModel, bool labelVisible) :
            base(labelVisible)
        {
            // Store off the model
            Ellipse = ellipseModel;

            // Default the ellipse to visible
            Visibility = true;

            // Create the center point of the ellipse
            CenterPoint = new PolygonPointViewModel(ellipseModel.Center, null);

            // Loop over all the points in the ellipse model
            foreach (PolygonPoint pt in ellipseModel.Points)
            {
                // Add a view model point for each model point
                PointCollection.Add(new PolygonPointViewModel(pt, null));
            }

            // If the ellipse has points then...
            if (ellipseModel.Points.Count > 0)
            {
                // Initialize the start side for when the ellipse is in wipe mode
                InitializeGreenLine();
            }

            // Update the position of the center point
            UpdateCenterPoint();

            // Fire the property changed event so the converters run
            NotifyPointCollectionChanged();
        }
Esempio n. 5
0
        /// <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();
        }
Esempio n. 6
0
        /// <summary>
        /// Selects the specified point.
        /// </summary>
        /// <param name="point">Point to select</param>
        public void SelectPoint(PolygonPointViewModel point)
        {
            // Mark the point as selected
            point.Selected = true;

            // Store off the selected point
            SelectedVertex = point;
        }
Esempio n. 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="point1">First point of the line segment</param>
        /// <param name="point2">Second point of the line segment</param>
        public LineSegmentViewModel(PolygonPointViewModel point1, PolygonPointViewModel point2)
        {
            // Store off the line segment points
            Point1 = point1;
            Point2 = point2;

            // Set the line segment color to blue
            Color = Colors.DodgerBlue;
        }
Esempio n. 8
0
        /// <summary>
        /// Calculates the center of the line.
        /// </summary>
        /// <returns>Center of the ;ome.</returns>
        private PolygonPointViewModel GetCenterOfLine()
        {
            // Create a new polygon point view model object; not giving it a model object
            PolygonPointViewModel centerPoint = new PolygonPointViewModel(null, null);

            // Calculate the center of the line
            centerPoint.X = (PointCollection[0].X + PointCollection[1].X) / 2.0;
            centerPoint.Y = (PointCollection[0].Y + PointCollection[1].Y) / 2.0;

            // Return the center of the line
            return(centerPoint);
        }
Esempio n. 9
0
        /// <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();
        }
Esempio n. 10
0
        /// <summary>
        /// Intialize the snapshot time bar pointer at the specified position.
        /// </summary>
        /// <param name="position">Initial position of the time bar pointer</param>
        public void Initialize(int position)
        {
            // Store off the position
            Time = position;

            const int HeightOfPointer   = 25;
            const int HeightOfRectangle = 20;

            //
            // Initialize the time bar points
            //

            // Bottom Left Corner
            PolygonPointViewModel p1 = new PolygonPointViewModel(new PolygonPoint(), null);

            p1.X = Time - HalfWidth;
            p1.Y = HeightOfRectangle;

            // Center Pointer
            PolygonPointViewModel p2 = new PolygonPointViewModel(new PolygonPoint(), null);

            p2.X = Time;
            p2.Y = HeightOfPointer;

            // Bottom Right Corner
            PolygonPointViewModel p3 = new PolygonPointViewModel(new PolygonPoint(), null);

            p3.X = Time + HalfWidth;
            p3.Y = HeightOfRectangle;

            // Top Right Corner
            PolygonPointViewModel p4 = new PolygonPointViewModel(new PolygonPoint(), null);

            p4.X = Time + HalfWidth;
            p4.Y = 0;

            // Top Left Corner
            PolygonPointViewModel p5 = new PolygonPointViewModel(new PolygonPoint(), null);

            p5.X = Time - HalfWidth;
            p5.Y = 0;

            // Add the points to the point collection
            PointCollection.Add(p1);
            PointCollection.Add(p2);
            PointCollection.Add(p3);
            PointCollection.Add(p4);
            PointCollection.Add(p5);
            PointCollection.Add(p1);
        }
Esempio n. 11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="polygon">Model polygon</param>
        /// <param name="labelVisible">Whether the label is visible</param>
        public PolygonViewModel(Polygon polygon, bool labelVisible) :
            base(labelVisible)
        {
            // Store off the model
            Polygon = polygon;

            // The WPF polygon is not shown until the polygon is closed
            Visibility = false;

            // By default the polygon starts with no points, so we are in point mode
            PolygonClosed = false;

            // Create the center point but set the parent to null so that it doesn't
            // fire property change events on both the X and Y coordinates.
            // One event is done for the pair when the point is updated.
            CenterPoint = new PolygonPointViewModel(new PolygonPoint(), null);

            // Loop over all the points in the polygon model
            foreach (PolygonPoint pt in Polygon.Points)
            {
                // Add a view model point for each model point
                PointCollection.Add(new PolygonPointViewModel(pt, this));
            }

            // If this is complete polygon then...
            if (Polygon.Points.Count >= 3)
            {
                // Calculate the center of the polygon
                UpdateCenterPoint();

                // Add the line segment to the collection
                Segments.Add(new LineSegmentViewModel(PointCollection[0], PointCollection[1]));

                // Make the WPF polygon visible
                ClosePolygon();

                // Display the green line if the fill type is a wipe
                SegmentsVisible = (Polygon.FillType == PolygonFillType.Wipe);
            }

            // Register for the collection changed event
            PointCollection.CollectionChanged += PointCollection_CollectionChanged;

            // Create a collection of line segments
            LineSegments = new List <PolygonLineSegment>();

            // Mark the polygon as dirty, this causes the line segments to get refreshed
            Dirty = true;
        }
Esempio n. 12
0
        /// <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();
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Inserts a polygon point at the specified position and at the specified index in the point collection.
        /// </summary>
        /// <param name="position">Position of the point</param>
        /// <param name="insertPosition">Index into the point collection</param>
        public void InsertPoint(Point position, int insertPosition)
        {
            // Create a new polygon point model object
            PolygonPoint modelPoint = new PolygonPoint();

            // Create a new view model polygon point object
            PolygonPointViewModel viewModelPoint = new PolygonPointViewModel(modelPoint, this);

            // Insert the model point into the model point collection
            Polygon.Points.Insert(insertPosition, modelPoint);

            // Insert the view model point into the point collection
            PointCollection.Insert(insertPosition, viewModelPoint);

            // Initialize the position of the point
            viewModelPoint.X = position.X;
            viewModelPoint.Y = position.Y;
        }
Esempio n. 14
0
        /// <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();
        }