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
        private NationalInstruments.Controls.Cursor GetCursor()
        {
            NationalInstruments.Controls.Cursor cursor = new NationalInstruments.Controls.Cursor();
            cursor.SnapToData = true;

            cursor.AllowablePlots            = NationalInstruments.Controls.PlotsToSearch.Single;
            cursor.LabelVisibility           = Visibility.Visible;
            cursor.ValueVisibility           = Visibility.Hidden;
            cursor.HorizontalCrosshairLength = 0;
            cursor.VerticalCrosshairLength   = 0;

            cursor.TargetShape                  = PointShape.OutwardTriangle;
            cursor.TargetSize                   = new Size(20, 20);
            cursor.PositionChanged             += Cursor_PositionChanged;
            cursor.PreviewMouseRightButtonDown += Cursor_PreViewMouseRightButtonDown;
            cursor.PreviewMouseLeftButtonDown  += Cursor_PreViewMouseLeftButtonDown;

            cursor.ContextMenu = cursorMenu;
            return(cursor);
        }
Example #3
0
 private void Cursor_PreViewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     _SelectedCursor = sender as NationalInstruments.Controls.Cursor;
     foreach (var item in graph.Children)
     {
         if (item as NationalInstruments.Controls.Cursor != null)
         {
             var cursor = item as NationalInstruments.Controls.Cursor;
             if (cursor.Equals(_SelectedCursor))
             {
                 _SelectedCursor.TargetShape = PointShape.InwardTriangle;
                 _SelectedCursor.ToolTip     = ">";
             }
             else
             {
                 cursor.TargetShape = PointShape.OutwardTriangle;
                 cursor.ToolTip     = "";
             }
         }
     }
 }
Example #4
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 #5
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;
        }
Example #6
0
 private void Cursor_PreViewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
     _SelectedCursor   = sender as NationalInstruments.Controls.Cursor;
     cursorMenu.IsOpen = true;
 }