Ejemplo n.º 1
0
        /// <summary>
        /// function which display Pentagon on canvas and add pentagon to data context
        /// </summary>
        public void Execute(object parameter)
        {
            var grid = parameter as Grid;

            _canvas = (Canvas)((Border)((ScrollViewer)grid?.Children[6])?.Content)?.Child;
            //_shapeCount = _dataContext.Manager.Shapes.Count;
            _pointCollection.Add(Mouse.GetPosition(_canvas));
            ++_count;
            if (_count == 5)
            {
                var listBox = (ListBox)((StackPanel)grid?.Children[5])?.Children[0];
                var name    = $"Pentagon{++_shapeCount}";
                var polygon = new Polygon
                {
                    Points          = _pointCollection.Clone(),
                    Stroke          = _dataContext.Settings.StrokeColorBrush,
                    StrokeThickness = _dataContext.Settings.StrokeThickness,
                    Fill            = _dataContext.Settings.FillColorBrush
                };
                EnableDrag(polygon);
                _canvas?.Children.Add(polygon);
                _pointCollection.Clear();
                _count = 0;
                _dataContext.Manager.Add(polygon, name);
                listBox?.Items.Refresh();
            }
        }
Ejemplo n.º 2
0
 public ArrowUtils(ArrowStyle pstyle, PointCollection pPoints)
 {
     points = pPoints.Clone();
     style  = pstyle;
     //
     // TODO: Add constructor logic here
     //
 }
Ejemplo n.º 3
0
        protected override void OnPreviewMouseRightButtonDown(MouseButtonEventArgs e)
        {
            ReleaseMouseCapture();
            if (pointsCollection.Count == 0)
            {
                NotifyToolFinished();
            }
            if (pointsCollection.Count > 1)
            {
                Polyline poly = new Polyline();
                Rect     b    = new Rect();
                b.Y     = b.X = System.Double.MaxValue;
                b.Width = b.Height = 0;
                foreach (Point p in pointsCollection)
                {
                    if (p.X < b.X)
                    {
                        b.X = p.X;
                    }
                    if (p.Y < b.Y)
                    {
                        b.Y = p.Y;
                    }
                    if (p.X > b.Width)
                    {
                        b.Width = p.X;
                    }
                    if (p.Y > b.Height)
                    {
                        b.Height = p.Y;
                    }
                }
                b.Width  -= b.X;
                b.Height -= b.Y;
                for (int i = 0; i < pointsCollection.Count; i++)
                {
                    Point pp = new Point();
                    pp.X = pointsCollection[i].X - b.X;
                    pp.Y = pointsCollection[i].Y - b.Y;
                    pointsCollection[i] = pp;;
                }

                poly.Points = pointsCollection.Clone();
                pointsCollection.Clear();
                Canvas.SetLeft(poly, b.X);
                Canvas.SetTop(poly, b.Y);
                poly.Width   = b.Width;
                poly.Height  = b.Height;
                poly.Stroke  = Brushes.Black;
                poly.Fill    = Brushes.Transparent;
                poly.Stretch = Stretch.Fill;
                NotifyObjectCreated(poly);
            }
            pointsCollection.Clear();
            objectPrview.RenderOpen().Close();
            e.Handled = true;
        }
Ejemplo n.º 4
0
        private void DoAdaptiveDownsampling(PointCollection points)
        {
            points.Add(RawPathPoints[0]);

            DownsampledPathPoints = RawPathPoints.Clone(); //don't use assign!!!


            //check every three pixels A, B, C. If the angle between AB and BC is larger than a threshold (ex., 178 degree)
            //then we drop pixel B.
            for (int i = 0; i < DownsampledPathPoints.Count - 2; i++)
            {
                Point A = DownsampledPathPoints[i];
                Point B = DownsampledPathPoints[i + 1];
                Point C = DownsampledPathPoints[i + 2];

                double c = Math.Sqrt((A.X - B.X) * (A.X - B.X) + (A.Y - B.Y) * (A.Y - B.Y));
                double a = Math.Sqrt((B.X - C.X) * (B.X - C.X) + (B.Y - C.Y) * (B.Y - C.Y));
                double b = Math.Sqrt((A.X - C.X) * (A.X - C.X) + (A.Y - C.Y) * (A.Y - C.Y));

                double ang;
                if (a * c != 0)
                {
                    ang = Math.Acos((a * a + c * c - b * b) / (2 * a * c));
                }
                else
                {
                    ang = Math.PI;
                }

                double s_tri = (a + b + c) / 2.0;
                double area  = Math.Sqrt(s_tri * (s_tri - a) * (s_tri - b) * (s_tri - c));


                //If the angle is small that means the curvature is large, we keep the point B
                if (ang < 175.0 / 180.0 * Math.PI && area > 10)
                {
                    points.Add(DownsampledPathPoints[i + 1]);
                }
                else
                {
                    DownsampledPathPoints.RemoveAt(i + 1);
                    if (i > 0) //roll back i
                    {
                        i--;
                    }
                }
            }
            //add rest points not checked
            points.Add(RawPathPoints[RawPathPoints.Count - 2]);
            points.Add(RawPathPoints[RawPathPoints.Count - 1]);
        }
Ejemplo n.º 5
0
        private static void SetUpGraph(BasicChart sender, IEnumerable ItemsSource)
        {
            List <PointCollection> ListOfChartCurves = new List <PointCollection>();
            List <double>          origianlValues    = new List <double>();

            if (ItemsSource == null)
            {
                return;
            }

            //Loop trough all the sources
            foreach (var ClassItem in ItemsSource)
            {
                PointCollection PointsOnChart = new PointCollection();
                int             X             = 0;

                // Get the Collection of dataitems from the current source
                IEnumerable MyCollectionItem = (IEnumerable)GetPropValue(ClassItem, sender.DataCollectionName);

                // For all the chart points, get the relevant Y values
                foreach (var item in MyCollectionItem)
                {
                    var YValues = GetPropValue(item, sender.DisplayMemberValues);

                    // No X value filters are applied
                    if (sender.XMin == sender.XMax)
                    {
                        if (YValues is double)
                        {
                            origianlValues.Add((double)YValues);
                            if (double.IsInfinity((double)YValues) || double.IsNaN((double)YValues) || double.IsNegativeInfinity((double)YValues) || double.IsPositiveInfinity((double)YValues))
                            {
                                PointsOnChart.Add(new Point(0, double.NaN));
                            }
                            else
                            {
                                double YValue = ((double)YValues - sender.YMin) / (sender.YMax - sender.YMin) * sender.PlotHeight;
                                PointsOnChart.Add(new Point(0, YValue));
                            }
                        }
                    }
                    else if (sender.XMin <= X && X <= sender.XMax)
                    {
                        if (YValues is double)
                        {
                            origianlValues.Add((double)YValues);
                            if (double.IsInfinity((double)YValues) || double.IsNaN((double)YValues) || double.IsNegativeInfinity((double)YValues) || double.IsPositiveInfinity((double)YValues))
                            {
                                PointsOnChart.Add(new Point(0, double.NaN));
                            }
                            else
                            {
                                double YValue = ((double)YValues - sender.YMin) / (sender.YMax - sender.YMin) * sender.PlotHeight;
                                PointsOnChart.Add(new Point(0, YValue));
                            }
                        }
                    }


                    X++;
                }
                ListOfChartCurves.Add(PointsOnChart);
            }

            ObservableCollection <FrameworkElement> items = new ObservableCollection <FrameworkElement>();


            for (int k = 0; k < ListOfChartCurves.Count; k++)
            {
                for (int i = 0; i < ListOfChartCurves[k].Count; i++)
                {
                    double pos = (double)i * sender.PlotWidth / (double)ListOfChartCurves[k].Count;
                    ListOfChartCurves[k][i] = new Point(pos, ListOfChartCurves[k][i].Y);

                    if (sender.ShowGraphPoints && sender.CurveVisibility[k].IsChecked)
                    {
                        Ellipse CurvePoint = new Ellipse();
                        CurvePoint.Width   = 10;
                        CurvePoint.Height  = 10;
                        CurvePoint.Fill    = DistinctColorList[k];
                        CurvePoint.ToolTip = origianlValues[i].ToString();
                        Canvas.SetLeft(CurvePoint, ListOfChartCurves[k][i].X - 5);
                        Canvas.SetTop(CurvePoint, ListOfChartCurves[k][i].Y - 5);
                        items.Add(CurvePoint);
                    }
                }
            }



            for (int k = 0; k < ListOfChartCurves.Count; k++)
            {
                if (sender.CurveVisibility[k].IsChecked)
                {
                    PointCollection        PointsOnChart     = ListOfChartCurves[k];
                    List <PointCollection> MyLines           = new List <PointCollection>();
                    PointCollection        CurrentCollection = new PointCollection();

                    // Create lines even if points are disjoint/missing
                    for (int i = 0; i < PointsOnChart.Count; i++)
                    {
                        // Current point is mission
                        if (double.IsNaN(PointsOnChart[i].Y))
                        {
                            // Any values that should be stored in previous points?
                            if (CurrentCollection.Count != 0)
                            {
                                MyLines.Add(CurrentCollection.Clone());
                            }

                            // Create a new line to store any new valid points found
                            CurrentCollection = new PointCollection();
                        }
                        else
                        {
                            // It's a valid point, add it to the current pointcollection
                            CurrentCollection.Add(PointsOnChart[i]);
                        }
                    }

                    // Add the last pontcollection, if it has any points in it.
                    if (CurrentCollection.Count != 0)
                    {
                        MyLines.Add(CurrentCollection.Clone());
                    }

                    //Draw all the lines found in the curve
                    foreach (PointCollection item in MyLines)
                    {
                        Polyline Curve = new Polyline();
                        if (sender.SmoothCurve)
                        {
                            Curve.Points = CatmullRomSpline(item, 0.01);
                        }
                        else
                        {
                            Curve.Points = item;
                        }

                        Curve.StrokeThickness = 2;
                        Curve.Stroke          = DistinctColorList[k];
                        items.Add(Curve);
                    }
                }
            }

            sender.PlotArea.ItemsSource = items;
        }
Ejemplo n.º 6
0
 public Panel(PointCollection points)
 {
     m_panelPoints = points.Clone();
     ShiftTo(0, 0);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates the measurements and message shown on the popup based on the in-progress
        /// geometry, including the passed-in point
        /// </summary>
        /// <param name="mapPoint"></param>
        private void updateMeasurements(MapPoint mapPoint)
        {
            if (_currentDrawVertices != null)
            {
                double length = 0d;
                double area   = 0d;

                string measurement1 = null;
                string measurement2 = null;

                switch (AssociatedObject.DrawMode)
                {
                case DrawMode.Freehand:
                    // Copy the set of vertices and add the passed-in point to it
                    PointCollection tmpPts = _currentDrawVertices.Clone();
                    tmpPts.Add(mapPoint.Clone());

                    // Check whether a polyline or polygon is being drawn
                    FreehandDrawMode freehandeMode = AttachedProperties.GetFreehandDrawMode(AssociatedObject);
                    if (freehandeMode == FreehandDrawMode.Polyline)
                    {
                        // Get the length of the line and update the measurement text
                        Polyline line = new Polyline()
                        {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        line.Paths.Add(tmpPts);
                        length       = line.Length();
                        measurement1 = string.Format(Strings.LengthLabelFormat, getLengthString(length));
                    }
                    else if (freehandeMode == FreehandDrawMode.Polygon)
                    {
                        // Close the polygon by duplicating the first vertex and adding it to the end
                        tmpPts.Add(tmpPts[0].Clone());
                        Polygon polygon = new Polygon {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        polygon.Rings.Add(tmpPts);

                        // Get the perimeter of the polygon and update the measurement text
                        length       = polygon.Perimeter();
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                    }
                    break;

                case DrawMode.Polyline:
                    // Create a line containing the segement of the polyline currently being drawn.

                    // First, get the most recently drawn point
                    tmpPts = new PointCollection();
                    tmpPts.Add(_currentDrawVertices[_currentDrawVertices.Count - 1].Clone());

                    // Add the passed-in point
                    tmpPts.Add(mapPoint.Clone());

                    // Create a polyline with the points
                    Polyline polyline = new Polyline()
                    {
                        SpatialReference = _currentDrawVertices[0].SpatialReference
                    };
                    polyline.Paths.Add(tmpPts);

                    // Calculate the length and update the segment measurement text
                    length       = polyline.Length();
                    measurement1 = string.Format(Strings.SegmentLengthLabelFormat, getLengthString(length));

                    // If there already two or more points in the polyline, calculate total length as well
                    if (_currentDrawVertices.Count > 1)
                    {
                        // Copy the current set of vertices and add the passed-in point
                        tmpPts = _currentDrawVertices.Clone();
                        tmpPts.Add(mapPoint.Clone());

                        // Create a polyline with the points
                        polyline = new Polyline()
                        {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        polyline.Paths.Add(tmpPts);

                        // Get the length
                        length = polyline.Length();
                    }

                    // Update measurement text showing the total length of the line
                    measurement2 = string.Format(Strings.TotalLengthLabelFormat, getLengthString(length));

                    break;

                case DrawMode.Rectangle:
                    // Create an envelope from the initial point and the passed-in piont
                    Envelope env = new Envelope(_currentDrawVertices[0], mapPoint)
                    {
                        SpatialReference = mapPoint.SpatialReference
                    };

                    // Get the perimeter and area of the envelope
                    length = env.Perimeter();
                    area   = env.Area();

                    // Update the measurement text
                    measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                    measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    break;

                case DrawMode.Circle:
                case DrawMode.Ellipse:
                    // Get the initial (center) point and the current point
                    tmpPts = new PointCollection();
                    tmpPts.Add(_currentDrawVertices[0].Clone());
                    //tmpPts.Add(_currentDrawVertices[_currentDrawVertices.Count - 1].Clone());
                    tmpPts.Add(mapPoint.Clone());

                    // Create a line with the points
                    polyline = new Polyline()
                    {
                        SpatialReference = _currentDrawVertices[0].SpatialReference
                    };
                    polyline.Paths.Add(tmpPts);

                    // Calculate the length of the line.  This is the radius.
                    length = polyline.Length();

                    // For circles, this info is sufficient to calculate perimeter anda area
                    if (AssociatedObject.DrawMode == DrawMode.Circle)
                    {
                        // Calculate perimeter (circumference) and area
                        double circumference = 2 * length * Math.PI;
                        area = Math.PI * Math.Pow(length, 2);

                        // Display measures
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(circumference));
                        measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    }
                    else     // Ellipse
                    {
                        // insufficient info for perimeter & area, so just display radius
                        measurement1 = string.Format(Strings.RadiusLabelFormat, getLengthString(length));
                    }
                    break;

                case DrawMode.Polygon:
                    // Can only calculate perimeter and area if there are already two or more
                    // vertices in the polygon
                    if (_currentDrawVertices.Count > 1)
                    {
                        // Copy the existing vertices and add the passed-in point
                        tmpPts = _currentDrawVertices.Clone();
                        tmpPts.Add(mapPoint.Clone());

                        // Create a polygon from the points
                        Polygon p = new Polygon()
                        {
                            SpatialReference = mapPoint.SpatialReference
                        };
                        p.Rings.Add(tmpPts);

                        // Calculate the perimeter as well as the area
                        length = p.Perimeter();
                        area   = p.Area();

                        // Update measurement text
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                        measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    }
                    break;

                default:
                    break;
                }

                // Update the draw popup with the measurement text
                if (measurement1 != null)
                {
                    PopupText = _drawInstructions + "\n" + measurement1;
                }

                if (measurement2 != null)
                {
                    PopupText += "\n" + measurement2;
                }
            }
        }
Ejemplo n.º 8
0
 protected Panel(PointCollection points)
 {
     m_panelPoints = points.Clone();
     Center();
 }