public void AddLine(string lineName) { if (!_lines.ContainsKey(lineName)) { var polylineItem = new PolylineItem() { Visible = true, LineName = lineName }; polylineItem.Initialize(_actualDrawWidth, _sampleRate); _lines.Add(lineName, polylineItem); } }
private void DrawLineHelper(PolylineItem lineItem) { if (lineItem.line == null) { var prop = _linePropertyDictionary[lineItem.LineName]; lineItem.line = new Polyline() { Stroke = new SolidColorBrush(prop.LineColor), StrokeThickness = prop.StrokeThickness }; Border lineControl = (Border)CreateLineControlBorder(prop); lineControl.MouseLeftButtonDown += (sender, args) => { if (lineItem.Visible) { //var tmp = (Border) lineControl; //var label = (Label) tmp.Child; lineControl.Background = Brushes.DarkGray; lineItem.Visible = false; lineItem.line.Visibility = Visibility.Hidden; } else { //var tmp = (Border)lineControl; //var label = (Label)tmp.Child; lineControl.Background = new SolidColorBrush(prop.LineColor); lineItem.Visible = true; lineItem.line.Visibility = Visibility.Visible; } }; LinesStackPanel.Children.Add(lineControl); // 判断双击 int mouseLeftClickCnt = 0; DateTime lastClickTime = DateTime.Now; // 标记高亮 //bool highlightPolyline = false; lineItem.line.MouseLeftButtonDown += (sender, args) => { if (mouseLeftClickCnt == 0) { lastClickTime = DateTime.Now; } if (mouseLeftClickCnt > 0 && mouseLeftClickCnt % 2 == 0 && (DateTime.Now - lastClickTime).TotalMilliseconds < 500) { var pos = args.GetPosition(lineItem.line); var point = lineItem._showableDataPointsBuffer[(int)(pos.X - _originPoint.X)]; EventPointWindow tmpWindowForPoint = new EventPointWindow(); tmpWindowForPoint.LoadEventData(null); // GetPosition参数为null,则默认取全局的绝对坐标(显示屏幕),直接画点即可 var tmpPos = Mouse.GetPosition(null); tmpWindowForPoint.Left = tmpPos.X; tmpWindowForPoint.Top = tmpPos.Y; if (tmpWindowForPoint.ShowDialog().Value) { DrawEventPointHelper(tmpWindowForPoint.CurrentData); } } else { lastClickTime = DateTime.Now; if (!_highlightPolyline) { _highlightPolyline = true; lineItem.line.Stroke = Brushes.Aqua; lineItem.line.StrokeThickness = 1.5; var pos = args.GetPosition(lineItem.line); var point = lineItem._showableDataPointsBuffer[(int)pos.X]; _currentSelectPolylineItem = lineItem; } else { lineItem.line.Stroke = new SolidColorBrush(prop.LineColor); lineItem.line.StrokeThickness = prop.StrokeThickness; } } mouseLeftClickCnt++; }; ////鼠标碰线 //_wave.MouseEnter += (sender, args) => //{ // _wave.Stroke = Brushes.Aqua; // _wave.StrokeThickness = 1.5; // var pos = args.GetPosition(_wave); // var point = _showableDataPointsBuffer[(int) pos.X]; //}; //// 鼠标离开 //_wave.MouseLeave += (sender, args) => //{ // //if (_showPointWindow == false) // //{ // _wave.Stroke = Brushes.Black; // _wave.StrokeThickness = 1; // //_tmpWindowForPoint.Hide(); // //_tmpWindowForPoint.Visibility = Visibility.Hidden; // //} //}; //_wave.MouseMove += (sender, args) => //{ // var pos = args.GetPosition(BasePart); // var point = _showableDataPointsBuffer[(int) (pos.X - _originPoint.X)]; // _tmpWindowForPoint.LoadDataPoint(point); //}; var index = BasePart.Children.Add(lineItem.line); //_wave = new ComponentItem<Polyline>(index, polyLine); //_wave = polyLine; } // 全屏刷新时每次显示全部的buffer数据点内容 // 删除事件点 foreach (var eventPoint in _eventPoints) { BasePart.Children.Remove(eventPoint); } _eventPoints.Clear(); // 画线 lineItem._displayOffset = 0; var tmpPoints = new PointCollection(); foreach (var dataPoint in lineItem._showableDataPointsBuffer) { if (dataPoint != null) { tmpPoints.Add(DrawPointHelper(dataPoint, lineItem._displayOffset++)); } } lineItem.line.Points = tmpPoints; }