Example #1
0
        public void AddMarker(int traceIndex)
        {
            Trace  tr = Traces[traceIndex];
            double i  = Math.Floor(Convert.ToDouble((tr.TraceData.Select(x => x.X).Count()) / 2));
            //  Marker marker = new Marker() { DisplayName = tr.Title + "-" + "Marker" + tr.Markers.Count + 1, X = tr.TraceData[Convert.ToInt32(i)].X, Y = tr.TraceData[Convert.ToInt32(i)].Y };
            Marker marker = new Marker();

            NationalInstruments.Controls.Cursor cursor = GetCursor();
            tr.Cursors.Add(cursor);
            tr.Markers.Add(marker);
            Plot p = graph.Plots[traceIndex];

            cursor.Plot = p;
            graph.Children.Add(cursor);
            double x1 = tr.TraceData.Select(x => x.X).Min();
            double x2 = tr.TraceData.Select(x => x.X).Max();

            cursor.SetDataPosition(new List <double>()
            {
                (marker.X - x1) / (x2 - x1), marker.Y
            });
            //  string xStr = Convert.ToString((new FreqStringConverter()).Convert(tr.TraceData[Convert.ToInt32(i)].X, null, null, null));
            cursor.Tag            = tr.TraceData[Convert.ToInt32(i)].X + "~" + tr.TraceData[Convert.ToInt32(i)].Y;
            cursor.LabelAlignment = PointAlignment.MiddleCenter;
            cursor.Label          = new Label()
            {
                Content = tr.Markers.Count, Foreground = (p.Renderer as LinePlotRenderer).Stroke
            };
            cursor.CrosshairBrush = (p.Renderer as LinePlotRenderer).Stroke;
            if (isSingleTrace && _SelectedPlot != null)
            {
                List <NationalInstruments.Controls.Cursor> cursors = new List <NationalInstruments.Controls.Cursor>();
                foreach (NationalInstruments.Controls.Cursor c in graph.Children)
                {
                    if (c.Plot != _SelectedPlot)
                    {
                        c.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        cursors.Add(c);
                    }
                }
                listMarker.ItemsSource = cursors;
            }
        }
Example #2
0
        public void SearchMarker(int traceIndex, MarkerSearchTypeEnum searchType)
        {
            double Y = 0;

            if (searchType == MarkerSearchTypeEnum.Max)
            {
                Y = Traces[traceIndex].TraceData.Select(y => y.Y).Max();
            }
            else if (searchType == MarkerSearchTypeEnum.Min)
            {
                Y = Traces[traceIndex].TraceData.Select(y => y.Y).Min();
            }
            double x1 = Traces[traceIndex].TraceData.Select(x => x.X).Min();
            double x2 = Traces[traceIndex].TraceData.Select(x => x.X).Max();

            Point[] points = Traces[traceIndex].TraceData.Where(data => data.Y == Y).ToArray();
            if (x1 != x2)
            {
                _SelectedCursor.SetDataPosition(new List <double>()
                {
                    (points[0].X - x1) / (x2 - x1), Y
                });
            }
        }
Example #3
0
        /// <summary>
        /// 更新trace中的数据
        /// </summary>
        public void UpdateData()
        {
            if (Traces.Count == 0)
            {
                return;
            }
            isCouple.IsChecked       = false;
            graph.RenderMode         = RenderMode.Hardware;
            this.lstYxis.ItemsSource = Traces;
            List <Point[]>    dataSource = new List <Point[]>();
            List <AxisDouble> axisDouble = new List <AxisDouble>();
            int i = 0;

            foreach (var tr in Traces)
            {
                if (i > 7)
                {
                    i = 0;
                }
                dataSource.Add(ProcessData(tr.TraceData));
                Plot p = new Plot()
                {
                    Renderer = new LinePlotRenderer()
                    {
                        Stroke = Brushes[i], StrokeThickness = 1.5
                    }
                };
                tr.Color = (SolidColorBrush)(p.Renderer as LinePlotRenderer).Stroke;
                AxisDouble axis = getAxis(tr.Title);
                graph.Axes.Add(axis);
                p.VerticalScale = axis;
                graph.Plots.Add(p);
                foreach (Marker marker in tr.Markers)
                {
                    NationalInstruments.Controls.Cursor cursor = GetCursor();
                    cursor.Plot = p;

                    graph.Children.Add(cursor);
                    double x1 = tr.TraceData.Select(x => x.X).Min();
                    double x2 = tr.TraceData.Select(x => x.X).Max();
                    cursor.SetDataPosition(new List <double>()
                    {
                        (marker.X - x1) / (x2 - x1), marker.Y
                    });
                    cursor.Tag   = marker.DisplayName;
                    cursor.Label = new Label()
                    {
                        Content = tr.Markers.Count, Foreground = (p.Renderer as LinePlotRenderer).Stroke
                    };
                    cursor.CrosshairBrush = (p.Renderer as LinePlotRenderer).Stroke;
                }
                i++;
            }

            listMarker.ItemsSource = graph.Children;
            getlimitPoint(Traces[SelectedIndex]);
            _LastSelectedTrace = Traces[SelectedIndex];
            if (_limitPointlist.Count() > 0)
            {
                foreach (var points in _limitPointlist)
                {
                    dataSource.Add(ProcessData(points));
                    Plot p = new Plot()
                    {
                        Renderer = new LinePlotRenderer()
                        {
                            Stroke = new SolidColorBrush(Colors.Red)
                        }
                    };
                    graph.Plots.Add(p);
                }
            }
            graph.DataSource = dataSource;
            //for (int traceIndex = 0; traceIndex < Traces.Count; traceIndex++)
            //{
            //    lstYxis.SelectedIndex = traceIndex;
            //}
            _LastSelectedTrace    = Traces[SelectedIndex];
            lstYxis.SelectedIndex = SelectedIndex;
            graph.AllScales.Last().Visibility = Visibility.Collapsed;
            this.lstAxis.ItemsSource = XAxisList;
            isCouple.IsChecked       = true;
            scaleCouple();
        }
Example #4
0
        /// <summary>
        /// 只更新数据源
        /// </summary>
        public void UpdatePointData(int traceIndex)
        {
            if (Traces.Count() == 0)
            {
                return;
            }
            isCouple.IsChecked       = false;
            graph.RenderMode         = RenderMode.Hardware;
            this.lstYxis.ItemsSource = Traces;
            List <Point[]>    dataSource = new List <Point[]>();
            List <AxisDouble> axisDouble = new List <AxisDouble>();

            listMarker.ItemsSource = null;
            int index = 0;

            foreach (var tr in Traces)
            {
                if (index > 7)
                {
                    index = 0;
                }
                dataSource.Add(ProcessData(tr.TraceData));
                Plot p = new Plot()
                {
                    Renderer = new LinePlotRenderer()
                    {
                        Stroke = Brushes[index], StrokeThickness = 1.5
                    }
                };
                tr.Color = (SolidColorBrush)(p.Renderer as LinePlotRenderer).Stroke;
                graph.Plots.Add(p);
                foreach (Marker marker in tr.Markers)
                {
                    NationalInstruments.Controls.Cursor cursor = GetCursor();
                    cursor.Plot = p;

                    graph.Children.Add(cursor);
                    double x1 = tr.TraceData.Select(x => x.X).Min();
                    double x2 = tr.TraceData.Select(x => x.X).Max();
                    cursor.SetDataPosition(new List <double>()
                    {
                        (marker.X - x1) / (x2 - x1), marker.Y
                    });
                    cursor.Tag   = marker.DisplayName;
                    cursor.Label = new Label()
                    {
                        Content = tr.Markers.IndexOf(marker), Foreground = (p.Renderer as LinePlotRenderer).Stroke
                    };
                    cursor.CrosshairBrush = (p.Renderer as LinePlotRenderer).Stroke;
                }
                p.VerticalScale = graph.Axes[traceIndex];
                index++;
            }
            getlimitPoint(Traces[traceIndex]);
            listMarker.ItemsSource = graph.Children;
            _LastSelectedTrace     = Traces[traceIndex];
            if (_limitPointlist.Count() > 0)
            {
                foreach (var points in _limitPointlist)
                {
                    dataSource.Add(ProcessData(points));
                    Plot p = new Plot()
                    {
                        Renderer = new LinePlotRenderer()
                        {
                            Stroke = new SolidColorBrush(Colors.Red)
                        }
                    };
                    graph.Plots.Add(p);
                }
            }
            graph.DataSource     = dataSource;
            lstYxis.SelectedItem = Traces[traceIndex];
            isCouple.IsChecked   = true;
        }