Exemple #1
0
        public void Invoke()
        {
            _lastStartFreq = _adapter.StartFreqInMHz;
            _lastEndFreq   = _adapter.EndFreqInMHz;
            var width     = _adapter.ScreenWidth;
            var factor    = new Func <double, double>(x => x * (_lastEndFreq - _lastStartFreq) / width + _lastStartFreq);
            var nextStart = factor.Invoke(_startX);
            var nextEnd   = factor.Invoke(_endX);

            _adapter.StartFreqInMHz = nextStart;
            _adapter.EndFreqInMHz   = nextEnd;
            _canvasView.InvokeAsync(_canvasView.ClearLine);
        }
        public DisplayAdapterV2([NotNull] CanvasView wavefromView, HorizontalAxisView horizontalAxisView,
                                VerticalAxisView verticalAxisView, TextBox tbXCoordinate, TextBox tbDistance, int dispPointNum,
                                double samplingRate, int startFreqInMHz,
                                int endFreqInMHz)
        {
            WavefromView = wavefromView;
            WavefromView.Reload(); // todo move out, and use a event
            DispPointsCnt = dispPointNum;

            Axis = new AxisBuilder(WavefromView);

            _horizontalAxisView = horizontalAxisView;
            VerticalAxisView    = verticalAxisView;
            SampleRateInMHz     = samplingRate / 1e6;
            StartFreqInMHz      = startFreqInMHz;
            EndFreqInMHz        = endFreqInMHz;

            var eventLayer = EventLayer.Setup(wavefromView.Canvas);

            eventLayer.ZoomEvent += (start, end, valid) => {
                if (valid)
                {
                    var zoomCommand = new ZoomCommand(start, end, WavefromView, this);
                    _cmdStack.Push(zoomCommand);
                    zoomCommand.Invoke();
                    ResetXYScales();
                }
                else
                {
                    WavefromView.ClearLine();
                }
            };
            TextBlock pop = null;

            eventLayer.FollowTraceEvent += (last, curr, mouseDown) => {
                var xOnAxis = GetXValueByPointPosition(curr.X);
                tbXCoordinate.Text = xOnAxis.ToString("F5");
                if (pop == null)
                {
                    pop = WavefromView.DrawText(curr.X + 4, curr.Y - 12, xOnAxis.ToString("F3"));
                }
                else
                {
                    Canvas.SetTop(pop, curr.Y - 12);
                    Canvas.SetLeft(pop, curr.X + 4);
                    pop.Text = xOnAxis.ToString("F3");
                }
                if (mouseDown)
                {
                    var xStart = GetXValueByPointPosition(eventLayer.MouseDownStart);
                    var xDelta = xOnAxis - xStart;
                    tbDistance.Text = xDelta.ToString("F5");
                }

                if (mouseDown)
                {
                    WavefromView.InvokeAsync(() => {
                        var pointCollection = new PointCollection(2)
                        {
                            last, curr
                        };
                        WavefromView.DrawLine(pointCollection, Colors.Yellow);
                    });
                }
            };
            eventLayer.AdjustYAxisEvent += ResetXYScales;
            eventLayer.UndoEvent        += () => {
                if (_cmdStack.IsEmpty())
                {
                    StartFreqInMHz = startFreqInMHz;
                    EndFreqInMHz   = endFreqInMHz; // todo hard coded
                }
                else
                {
                    var zoomCommand = _cmdStack.Pop();
                    zoomCommand.Undo();
                }
                ResetXYScales();
            };


            WavefromView.DrawGrid();
        }