List <Point> CreatePointListFromRectMask(System.Windows.Shapes.Rectangle rect) { List <Point> pList = new List <Point>(); if (rect == null) { return(pList); } List <Point> refList = _xyzAxesVM.GetPositionList(); Point refP = refList[0]; pList.Add(refP); Tuple <System.Windows.Shapes.Ellipse, System.Windows.Controls.TextBlock, Point> refTuple = new Tuple <System.Windows.Shapes.Ellipse, System.Windows.Controls.TextBlock, Point>(null, null, refP); MarkerList.Add(refTuple); double xStepInPixel = GlobalVariables.motorSettings.XStep * GlobalVariables.motorSettings.XPixelInMM; double yStepInPixel = GlobalVariables.motorSettings.YStep * GlobalVariables.motorSettings.YPixelInMM; double x = System.Windows.Controls.Canvas.GetLeft(rect); double y = System.Windows.Controls.Canvas.GetTop(rect); int w = (int)(rect.Width / xStepInPixel) + 1; int h = (int)(rect.Height / yStepInPixel) + 1; MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); for (int i = 0; i < h; i++) { double Y = y + i * xStepInPixel; for (int j = 0; j < w; j++) { double X = x + j * yStepInPixel; Point p = new Point(X, Y); pList.Add(p); System.Windows.Shapes.Ellipse e = DrawCanvas.Circle(X, Y, 15, 15, false, mv.CanvasDraw); tempEllipseList.Add(e); string s = MarkerList.Count.ToString(); System.Windows.Controls.TextBlock t = DrawCanvas.Text(X, Y, s, false, null, mv.CanvasDraw); tempTBList.Add(t); Tuple <System.Windows.Shapes.Ellipse, System.Windows.Controls.TextBlock, Point> tuple = new Tuple <System.Windows.Shapes.Ellipse, System.Windows.Controls.TextBlock, Point>(e, t, p); MarkerList.Add(tuple); } } return(pList); }
public void OnMarkedPointsList(Point p, bool refPoint) { if (p.X >= 0) { MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); Ellipse e = DrawCanvas.Circle(p.X, p.Y, refPoint ? 30 : 15, refPoint ? 30 : 15, refPoint, mv.CanvasDraw); if (PointMarkerList.Count > 0) { if (refPoint) { TextBlock t = DrawCanvas.Text(p.X, p.Y, "0", refPoint, null, mv.CanvasDraw); Tuple <Ellipse, TextBlock, Point> tuple = new Tuple <Ellipse, TextBlock, Point>(e, t, p); mv.CanvasDraw.Children.Remove(PointMarkerList[0].Item1); mv.CanvasDraw.Children.Remove(PointMarkerList[0].Item2); PointMarkerList[0] = tuple; } else { string s = PointMarkerList.Count.ToString(); TextBlock t = DrawCanvas.Text(p.X, p.Y, s, refPoint, null, mv.CanvasDraw); Tuple <Ellipse, TextBlock, Point> tuple = new Tuple <Ellipse, TextBlock, Point>(e, t, p); PointMarkerList.Add(tuple); } } else { string s = PointMarkerList.Count.ToString(); TextBlock t = DrawCanvas.Text(p.X, p.Y, s, refPoint, null, mv.CanvasDraw); Tuple <Ellipse, TextBlock, Point> tuple = new Tuple <Ellipse, TextBlock, Point>(e, t, p); PointMarkerList.Add(tuple); } } else { // remove last marker if (PointMarkerList.Count > 0) { MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); mv.CanvasDraw.Children.Remove(PointMarkerList[PointMarkerList.Count - 1].Item1); mv.CanvasDraw.Children.Remove(PointMarkerList[PointMarkerList.Count - 1].Item2); PointMarkerList.RemoveAt(PointMarkerList.Count - 1); } } }
public void DrawMarkedPoints() { MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); DrawCanvas.Circle(10, 50, 5, 5, false, mv.CanvasDraw); }