/// <summary> /// Marker 동적으로 그리기 /// </summary> /// <param name="markerItem"></param> /// <param name="IsNormal"></param> /// <returns></returns> private StackPanel MakeMarkControl(MarkerItem markerItem, bool IsNormal) { StackPanel stackPanel = new StackPanel(); stackPanel.Width = 15; stackPanel.Height = 28; TextBlock textBlock = new TextBlock(); if (IsNormal == true) { textBlock.Text = markerItem.MarkerNum.ToString(); } else { textBlock.Text = markerItem.MarkerNum.ToString() + "R"; } textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(markerItem.Color)); textBlock.TextAlignment = TextAlignment.Center; stackPanel.Children.Add(textBlock); Polygon polygon = new Polygon(); polygon.Points.Add(new Point(0, 0)); polygon.Points.Add(new Point(10, 0)); polygon.Points.Add(new Point(5, 10)); polygon.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(markerItem.Color)); polygon.HorizontalAlignment = HorizontalAlignment.Center; stackPanel.Children.Add(polygon); lineCanvas.Children.Add(stackPanel); return(stackPanel); }
/// <summary> /// Delta Marker 추가 제거 /// </summary> private void OnMarkerNormalCommand() { MarkerItem markerItem = null; foreach (MarkerItem _item in MarkerItems) { if (_item.MarkerNum != this.Marker) { continue; } markerItem = _item; markerItem.IsDelta = IsMarkerDelta; break; } if (IsMarkerDelta == true) { markerItem.DeltaMarkerControl = MakeMarkControl(markerItem, false); markerItem.DeltaMarkerControl.IsHitTestVisible = false; this.lineCanvas.Dispatcher.Invoke((ThreadStart)(() => { }), DispatcherPriority.ApplicationIdle); Canvas.SetLeft(markerItem.DeltaMarkerControl, Canvas.GetLeft(markerItem.MarkerControl)); Canvas.SetTop(markerItem.DeltaMarkerControl, Canvas.GetTop(markerItem.MarkerControl)); } else { lineCanvas.Children.Remove(markerItem.DeltaMarkerControl); } }
/// <summary> /// Marker추가 /// </summary> private void OnMarkerOnCommand() { MarkerItem markerItem = null; foreach (MarkerItem _item in MarkerItems) { if (_item.MarkerNum != this.Marker) { continue; } markerItem = _item; break; } if (markerItem != null && IsMarkerOn == false) { IsMarkerDelta = false; MarkerItems.Remove(markerItem); lineCanvas.Children.Remove(markerItem.MarkerControl); lineCanvas.Children.Remove(markerItem.DeltaMarkerControl); } else if (markerItem == null && IsMarkerOn == true) { markerItem = new MarkerItem(); markerItem.MarkerNum = this.Marker; markerItem.Freq = ControlCenter; markerItem.IsDelta = false; MarkerItem.EMarkerColor eMarkerColor = MarkerItem.EMarkerColor.Mark1; markerItem.Color = eMarkerColor.FindEnumValue(markerItem.MarkerNum).ToDescription(); MarkerItems.Add(markerItem); markerItem.MarkerControl = MakeMarkControl(markerItem, true); markerItem.MarkerControl.MouseDown += StackPanel_MouseDown; this.lineCanvas.Dispatcher.Invoke((ThreadStart)(() => { }), DispatcherPriority.ApplicationIdle); MoveMarker(markerItem.MarkerControl, new Point(lineCanvas.ActualWidth / 2, 0)); } }
/// <summary> /// Y축 최댓값 위치로 Marker이동 /// </summary> private void OnMarkerPeakCommand() { Polyline polyline = null; foreach (UIElement element in lineCanvas.Children) { if (element is Polyline) { polyline = element as Polyline; } } MarkerItem markerItem = null; foreach (var item in MarkerItems) { if (item.MarkerNum != this.Marker) { return; } markerItem = item; break; } if (markerItem == null) { return; } PathGeometry pathGeometry = polyline.RenderedGeometry.GetFlattenedPathGeometry(); List <Tuple <Point, double> > closePoints = new List <Tuple <Point, double> >(); foreach (PathFigure pathFigure in pathGeometry.Figures) { Point current = pathFigure.StartPoint; foreach (PathSegment s in pathFigure.Segments) { PolyLineSegment segment = s as PolyLineSegment; LineSegment line = s as LineSegment; Point[] points; if (segment != null) { points = segment.Points.ToArray(); } else if (line != null) { points = new[] { line.Point }; } else { throw new InvalidOperationException("Unexpected segment type"); } foreach (Point next in points) { double d = (next - current).LengthSquared; closePoints.Add(new Tuple <Point, double>(next, d)); current = next; } } } Tuple <Point, double> point = closePoints.OrderBy(p => p.Item1.Y).First(); MoveMarker(markerItem.MarkerControl, point.Item1); }