public void MouseUpHandler(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { if (rectW != 0 && rectH != 0 && currentPoint.X != 0 && currentPoint.Y != 0) { if (rectW < 0) { currentPoint.X = currentPoint.X + rectW; rectW = -rectW; } if (rectH < 0) { currentPoint.Y = currentPoint.Y + rectH; rectH = -rectH; } //RemoveTempMarker(); MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); tmpRect = DrawCanvas.Rect(currentPoint.X, currentPoint.Y, (int)rectW, (int)rectH, Brushes.Red, mv.CanvasDraw, 0.3); currentPoint = default(Point); rectW = 0; rectH = 0; } } }
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); } } }
private void OnRectMaskSelected(object sender, RectMaskEventArgs e) { if (e.Width == 0 && e.Height == 0 && e.ActuralW == 0 && e.ActuralH == 0) { RemoveTempMarker(); } else { RemoveTempMarker(); MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); double x = e.P.X / e.ActuralW * Width; double y = e.P.Y / e.ActuralH * Height; double w = e.Width * Width / e.ActuralW; double h = e.Height * Height / e.ActuralH; tmpRect = DrawCanvas.Rect(x, y, (int)w, (int)h, Brushes.Red, mv.CanvasDraw, 0.3); } }
public void DrawMarkedPoints() { MainWindow mv = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); DrawCanvas.Circle(10, 50, 5, 5, false, mv.CanvasDraw); }
void UpdateSummary() { View.PhosResultsWindow mw = (View.PhosResultsWindow)Application.Current.Windows.OfType <Window>().Last(); for (int i = 0; i < MarkerList.Count; i++) { if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement") && i == 0) { continue; } Tuple <System.Windows.Shapes.Ellipse, TextBlock, Point> t = MarkerList[i]; string savedEllipse = XamlWriter.Save(t.Item1); string savedText = XamlWriter.Save(t.Item2); System.Windows.Shapes.Ellipse ellipse = (System.Windows.Shapes.Ellipse)XamlReader.Load(XmlReader.Create(new StringReader(savedEllipse))); System.Windows.Controls.TextBlock txt = (TextBlock)XamlReader.Load(XmlReader.Create(new StringReader(savedText))); if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement")) { ellipse.Width *= 2; ellipse.Height *= 2; ellipse.Stroke = ColorLegendList[(int)DiamondResList[i - 1]]; txt.FontSize = 48; txt.Foreground = ColorLegendList[(int)DiamondResList[i - 1]]; } else { ellipse.Stroke = ColorLegendList[(int)DiamondResult]; } ellipse.SetValue(Canvas.LeftProperty, t.Item3.X - ellipse.Width / 2.0); ellipse.SetValue(Canvas.TopProperty, t.Item3.Y - ellipse.Height / 2.0); txt.SetValue(Canvas.LeftProperty, t.Item3.X - 15); txt.SetValue(Canvas.TopProperty, t.Item3.Y - 76); mw.CanvasSummary.Children.Add(ellipse); if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement")) { mw.CanvasSummary.Children.Add(txt); } if (!DisplayName.Equals("PhosResultsViewModelBatchMeasurement") && i == 0) { break; } } if (!mappingMeasure) { double x = 50; double y = 50; for (int i = 0; i < ColorLegendList.Count; i++) { DrawCanvas.Rect(x, y, 30, 30, ColorLegendList[i - 2], mw.CanvasSummary); DrawCanvas.Text(x + 50, y, ResultString(i - 2), true, ColorLegendList[i - 2], mw.CanvasSummary, false); y += 40; } } else { // rectangle mask double x = Canvas.GetLeft(RectMark); double y = Canvas.GetTop(RectMark); double w = RectMark.Width; double h = RectMark.Height; System.Windows.Shapes.Rectangle tmpRect = DrawCanvas.Rect(x, y, (int)w, (int)h, Brushes.Red, mw.CanvasSummary, 0.3); } }