Ejemplo n.º 1
0
        private void DrawZPlanShape()
        {
            Canvas_XY.Children.Clear();

            var xyplaninfos = DataGrid_Info.ItemsSource as ObservableCollection <ZPlanInfo>;

            if (xyplaninfos == null || xyplaninfos.Count == 0)
            {
                return;
            }
            PointCollection points = new PointCollection();

            foreach (var xyplaninfo in xyplaninfos)
            {
                var info = (ZPlanInfo)xyplaninfo;
                points.Add(new Point(info.X, info.Y));
            }
            var    maxpoinstx = points.Max(p => p.X);
            var    maxpoinsty = points.Max(p => p.Y);
            double scale      = 280 / Math.Max(maxpoinstx, maxpoinsty);

            PointCollection saclePointCollection = new PointCollection();

            foreach (var point in points)
            {
                saclePointCollection.Add(new Point(point.X * scale, point.Y * scale));
            }
            var polygon_drawing = new Polygon()
            {
                Points          = saclePointCollection,
                Stroke          = Brushes.Red,
                StrokeThickness = 2
            };

            Canvas_XY.Children.Add(polygon_drawing);
            Canvas.SetLeft(polygon_drawing, 10);
            Canvas.SetTop(polygon_drawing, 10);


            int i = 0;

            foreach (var point in saclePointCollection)
            {
                TextBlock text = new TextBlock()
                {
                    Text = i.ToString()
                };
                text.RenderTransform = new ScaleTransform(1, -1);
                Canvas_XY.Children.Add(text);
                Canvas.SetLeft(text, point.X + 11);
                Canvas.SetTop(text, point.Y + 11);
                i++;
            }
        }
Ejemplo n.º 2
0
        public ShapeWithPoints(PointCollection points)
        {
            double LowestY  = points.Min(x => x.Y);
            double HighestY = points.Max(x => x.Y);

            this.Height = HighestY - LowestY;
            double LowestX  = points.Min(x => x.X);
            double HighestX = points.Max(x => x.X);

            this.Width  = HighestX - LowestX;
            this.Points = points;
        }
Ejemplo n.º 3
0
        private void MouseMove(object sender, MouseEventArgs e)
        {
            Point position = e.GetPosition(M_FiguresCanvas);

            m_originalPoints.Add(position);
            m_polyline.Points = m_originalPoints;
            m_CurrentPoints.Add(CanvasToMsi(position));
            base.OriginStart          = new Point(m_originalPoints.Min((Point p) => p.X), m_originalPoints.Min((Point p) => p.Y));
            base.OriginEnd            = new Point(m_originalPoints.Max((Point p) => p.X), m_originalPoints.Max((Point p) => p.Y));
            base.CurrentStart         = CanvasToMsi(base.OriginStart);
            base.CurrentEnd           = CanvasToMsi(base.OriginEnd);
            base.TextBlock_info       = CalcMeasureInfo();
            base.AnnoControl.Tbk.Text = null;
            base.AnnoControl.Tbk.Text = CalcMeasureInfo();
        }
Ejemplo n.º 4
0
        private IEnumerable <Point> GetPolygonRegion(PointCollection points)
        {
            var maxX = Math.Floor(points.Max(p => p.X) / GRID_SIZE);
            var maxY = Math.Floor(points.Max(p => p.Y) / GRID_SIZE);
            var minX = Math.Floor(points.Min(p => p.X) / GRID_SIZE);
            var minY = Math.Floor(points.Min(p => p.Y) / GRID_SIZE);

            for (double x = minX; x <= maxX; x++)
            {
                for (double y = minY; y <= maxY; y++)
                {
                    yield return(new Point(x, y));
                }
            }
        }
Ejemplo n.º 5
0
        protected override void UpdateCenterPoint()
        {
            // If the polygon contains at least three points then...
            if (PointCollection.Count > 2)
            {
                // Get the minimum X coordinate
                double xMin = PointCollection.Min(point => point.X);

                // Get the maximum X coordinate
                double xMax = PointCollection.Max(point => point.X);

                // Get the minimum Y coordinate
                double yMin = PointCollection.Min(point => point.Y);

                // Get the maximum Y coordinate
                double yMax = PointCollection.Max(point => point.Y);

                // Calculate the center of the polygon
                CenterPoint.X = (xMax - xMin) / 2.0 + xMin;
                CenterPoint.Y = (yMax - yMin) / 2.0 + yMin;

                // Notify the view that the center has changed
                RaisePropertyChanged(nameof(CenterPoint));
            }

            // Update the point labels
            UpdatePointLabels();
        }
Ejemplo n.º 6
0
        void SetColumnSegments(int index, PathGeometry barChartGeometry)
        {
            double width = XStep * 0.5;
            double left  = _points[index].X - width / 2;
            double right = left + width;
            double max   = _points.Max(p => p.Y);
            double y1    = max;
            double y2    = _points[index].Y;

            barChartGeometry.Figures[index].StartPoint = new Point(left, y1);
            (barChartGeometry.Figures[index].Segments[0] as LineSegment).Point = new Point(right, y1);
            (barChartGeometry.Figures[index].Segments[1] as LineSegment).Point = new Point(right, y2);
            (barChartGeometry.Figures[index].Segments[2] as LineSegment).Point = new Point(left, y2);
            (barChartGeometry.Figures[index].Segments[3] as LineSegment).Point = new Point(left, y1);
        }
Ejemplo n.º 7
0
 public myPolyline(AnnotationBase ab)
 {
     m_originalPoints           = new PointCollection();
     m_CurrentPoints            = new PointCollection();
     base.Calibration           = ab.Calibration;
     base.SlideZoom             = ab.SlideZoom;
     base.AnnotationType        = AnnotationType.Polygon;
     base.AnnotationDescription = ab.AnnotationDescription;
     base.ControlName           = ab.ControlName;
     base.Zoom          = ab.Zoom;
     m_CurrentPoints    = ab.PointCollection;
     base.msi           = ab.msi;
     base.isMsVisble    = ab.isMsVisble;
     base.FiguresCanvas = ab.FiguresCanvas;
     base.objectlist    = ab.objectlist;
     base.AnnoControl   = ab.AnnoControl;
     foreach (Point currentPoint in m_CurrentPoints)
     {
         m_originalPoints.Add(MsiToCanvas(currentPoint));
     }
     base.OriginStart           = new Point(m_originalPoints.Min((Point p) => p.X), m_originalPoints.Min((Point p) => p.Y));
     base.OriginEnd             = new Point(m_originalPoints.Max((Point p) => p.X), m_originalPoints.Max((Point p) => p.Y));
     base.CurrentStart          = CanvasToMsi(base.OriginStart);
     base.CurrentEnd            = CanvasToMsi(base.OriginEnd);
     base.Size                  = ab.Size;
     base.BorderBrush           = ab.BorderBrush;
     base.isVisble              = ab.isVisble;
     base.isHidden              = ab.isHidden;
     base.AnnotationName        = ab.AnnotationName;
     base.isFinish              = true;
     m_polyline                 = new Polyline();
     m_polyline.StrokeThickness = base.Size;
     m_polyline.Stroke          = base.BorderBrush;
     m_polyline.Name            = base.ControlName;
     m_polyline.Points          = OriginalPoints;
     M_FiguresCanvas.Children.Add(m_polyline);
     base.objectlist.Insert(0, this);
     CreateMTextBlock();
     UpdateCB();
     CreateThumb();
     m_polyline.MouseLeftButtonDown += Select_MouseDown;
     m_polyline.MouseEnter          += GotFocus;
     base.UpadteTextBlock();
     IsActive(Visibility.Collapsed);
     base.AnnoControl.CB.SelectedIndex = -1;
 }
Ejemplo n.º 8
0
        PointCollection GetAreaPoints()
        {
            if (_points == null)
            {
                return(new PointCollection());
            }

            var max = _points.Max(p => p.Y);

            if (_points.Count > 0)
            {
                _points.Add(new Point(_points[_points.Count - 1].X, max));
                _points.Add(new Point(_points[0].X, max));
            }

            return(_points);
        }
Ejemplo n.º 9
0
        private void tableRefresh()
        {
            if (pointsource == null)
            {
                return;
            }
            else if (pointsource.Count == 0)
            {
                return;
            }

            PointRange[0] = pointsource.Min(u => u.X);
            PointRange[1] = pointsource.Max(u => u.X);
            if (PointRange[1] - PointRange[0] == 0)
            {
                PointRange[1] = PointRange[0] + 1;
            }
            PointRange[2] = pointsource.Min(u => u.Y);
            PointRange[3] = pointsource.Max(u => u.Y);
            if (PointRange[3] - PointRange[2] == 0)
            {
                PointRange[3] = PointRange[2] + 1;
            }

            double WidthStep_Concrete  = WidthStep;
            double HeightStep_Concrete = HeightStep;
            int    XD = (int)(RenderSize.Width / WidthStep) + 1;
            int    YD = (int)(RenderSize.Height / HeightStep) + 1;

            if (XYCount.Width != 0)
            {
                XD = (int)XYCount.Width;
                WidthStep_Concrete = RenderSize.Width / XD;
            }
            if (XYCount.Height != 0)
            {
                YD = (int)XYCount.Height;
                HeightStep_Concrete = RenderSize.Height / YD;
            }

            rootgrid.Children.Clear();

            var line = new Polyline();

            Grid.SetColumnSpan(line, XD);
            Grid.SetRowSpan(line, YD);
            line.HorizontalAlignment = HorizontalAlignment.Left;
            line.VerticalAlignment   = VerticalAlignment.Bottom;
            //line.Stroke = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush;
            line.Stroke          = new SolidColorBrush(Colors.Orchid);
            line.StrokeThickness = 3;
            double YP = RenderSize.Height / (PointRange[3] - PointRange[2]);
            double XP = RenderSize.Width / (PointRange[1] - PointRange[0]);

            pointdraw = new PointCollection();
            foreach (var p in pointsource)
            {
                pointdraw.Add(new Point()
                {
                    X = XP * (p.X - PointRange[0]), Y = YP * (p.Y - PointRange[2])
                });
            }
            line.Points         = pointdraw;
            line.StrokeLineJoin = PenLineJoin.Bevel;
            line.Stretch        = Stretch.Fill;
            rootgrid.Children.Add(line);

            rootgrid.RowDefinitions.Clear();
            YLabelGrid.RowDefinitions.Clear();
            YLabelGrid.Children.Clear();
            for (int i = 0; i < YD; ++i)
            {
                var RowDef = new RowDefinition();
                RowDef.Height = new GridLength(1, GridUnitType.Star);
                rootgrid.RowDefinitions.Add(RowDef);
                if (i % 2 != 0)
                {
                    var rect = new Rectangle();
                    Grid.SetRow(rect, i);
                    Grid.SetColumnSpan(rect, XD);
                    rect.Fill = Application.Current.Resources["SystemControlHighlightAltListAccentLowBrush"] as SolidColorBrush;
                    rootgrid.Children.Add(rect);
                }

                var RowDefYLabel = new RowDefinition();
                RowDefYLabel.Height = new GridLength(1, GridUnitType.Star);
                YLabelGrid.RowDefinitions.Add(RowDefYLabel);
                var YLabelText = new TextBlock();
                YLabelText.VerticalAlignment = VerticalAlignment.Bottom;
                var TextValue = (PointRange[2] + HeightStep_Concrete * i / YP);
                if (TextValue > PointRange[3] + HeightStep_Concrete / YP)
                {
                    YLabelText.Text = "";
                }
                else
                {
                    YLabelText.Text = TextValue.ToString("#0.00");
                }
                YLabelText.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush;
                Grid.SetRow(YLabelText, YD - 1 - i);
                YLabelGrid.Children.Add(YLabelText);
            }
            YMax.Text       = (PointRange[2] + HeightStep_Concrete * YD / YP).ToString("#0.00");
            YMax.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush;

            rootgrid.ColumnDefinitions.Clear();
            XLabelGrid.ColumnDefinitions.Clear();
            XLabelGrid.Children.Clear();
            for (int i = 0; i < XD; ++i)
            {
                var ColDef = new ColumnDefinition();
                ColDef.Width = new GridLength(1, GridUnitType.Star);
                rootgrid.ColumnDefinitions.Add(ColDef);
                var ColDefYLabel = new ColumnDefinition();
                ColDefYLabel.Width = new GridLength(1, GridUnitType.Star);
                XLabelGrid.ColumnDefinitions.Add(ColDefYLabel);
                var XLabelText = new TextBlock();
                XLabelText.HorizontalAlignment = HorizontalAlignment.Left;
                var TextValue = (PointRange[0] + WidthStep_Concrete * i / XP);
                if (TextValue > PointRange[1] + WidthStep_Concrete / XP)
                {
                    XLabelText.Text = "";
                }
                else
                {
                    XLabelText.Text = XStringFormatFunc(TextValue);
                }
                XLabelText.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush;
                Grid.SetColumn(XLabelText, i);
                XLabelGrid.Children.Add(XLabelText);

                var bord = new Border();
                Grid.SetColumn(bord, i);
                Grid.SetRowSpan(bord, YD);
                bord.BorderThickness = new Thickness(1, 1, 1, 1);
                bord.BorderBrush     = Application.Current.Resources["SystemControlHighlightAltListAccentHighBrush"] as SolidColorBrush;
                rootgrid.Children.Add(bord);
            }
            XMax.Text       = XStringFormatFunc(PointRange[0] + WidthStep_Concrete * XD / XP);
            XMax.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 曲线绘制,并填充色
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="colorBrush"></param>
        /// <param name="fillBrush">并填充色</param>
        /// <param name="startPoint"></param>
        /// <param name="points"></param>
        /// <returns></returns>
        public static Path DrawPolylineAndFill(this Canvas canvas,
                                               Color colorBrush,
                                               Brush fillBrush,
                                               Point startPoint,
                                               PointCollection points)
        {
            Path currPath = new Path();

            if (!points.Any())
            {
                return(currPath);
            }
            currPath.Stroke = Brushes.Black;

            var endpoint = new Point()
            {
                X = points.Last().X + 10, Y = startPoint.Y
            };
            var newStartPoint = new Point()
            {
                X = startPoint.X, Y = startPoint.Y
            };

            var maxX = points.Max(a => a.X);
            var maxY = points.Max(a => a.Y);

            GradientStopCollection gradientStops = new GradientStopCollection()
            {
                new GradientStop()
                {
                    Color = Colors.LightSeaGreen, Offset = 1
                },
                new GradientStop()
                {
                    Color = Colors.LightPink, Offset = 0.8
                },
                new GradientStop()
                {
                    Color = Colors.Black, Offset = 0.2
                }
            };
            LinearGradientBrush linearGradientBrush = new LinearGradientBrush(gradientStops, 90);

            PathFigure pathFigureArrow = new PathFigure();

            pathFigureArrow.IsClosed   = true;
            pathFigureArrow.StartPoint = newStartPoint;
            foreach (var item in points)
            {
                var toadd = new Point(item.X + 10, item.Y + 5);
                pathFigureArrow.Segments.Add(new LineSegment(toadd, false));
            }
            pathFigureArrow.Segments.Add(new LineSegment(endpoint, false));

            PathGeometry pathGeometryArrow = new PathGeometry();

            pathGeometryArrow.Figures.Add(pathFigureArrow);

            currPath.Data = pathGeometryArrow;

            currPath.Fill = fillBrush == null ? linearGradientBrush : fillBrush;

            Canvas.SetZIndex(currPath, -99);

            canvas.Children.Add(currPath);

            return(currPath);
        }