Ejemplo n.º 1
0
        public void ClickPlot(int pixelX, int pixelY)
        {
            _shell.AssertIsOnMainThread();

            if (LocatorMode)
            {
                var result = LocatorResult.CreateClicked(pixelX, pixelY);
                EndLocatorMode(result);
            }
        }
Ejemplo n.º 2
0
        public void ClickPlot(int pixelX, int pixelY)
        {
            _mainThread.Assert();

            if (LocatorMode)
            {
                var result = LocatorResult.CreateClicked(pixelX, pixelY);
                _plotManager.EndLocatorMode(_device, result);
            }
        }
Ejemplo n.º 3
0
 public LocatorResult Next()
 {
     if (_index < _points.Length)
     {
         var res = LocatorResult.CreateClicked(_points[_index].X, _points[_index].Y);
         _index++;
         return(res);
     }
     return(LocatorResult.CreateNotClicked());
 }
Ejemplo n.º 4
0
        public void EndLocatorMode(IRPlotDevice device, LocatorResult result)
        {
            device.LocatorMode = false;

            var tcs = _locatorTcs;

            _locatorTcs = null;
            tcs?.TrySetResult(result);

            _locatorCancelTokenRegistration.Dispose();
        }
Ejemplo n.º 5
0
        public async Task <LocatorResult> Locator(CancellationToken ct)
        {
            var historyProvider = _coreShell.ExportProvider.GetExportedValue <IPlotHistoryProvider>();
            var history         = historyProvider.GetPlotHistory(_session);

            if (history.PlotContentProvider.Locator != null)
            {
                return(await history.PlotContentProvider.Locator.StartLocatorModeAsync(ct));
            }
            return(LocatorResult.CreateNotClicked());
        }
Ejemplo n.º 6
0
        private void RootContainer_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (_locatorTcs != null)
            {
                var rootContainer = (FrameworkElement)sender;
                var pos           = e.GetPosition(rootContainer);
                var pixelSize     = WpfUnitsConversion.ToPixels(rootContainer as Visual, pos);

                var result = LocatorResult.CreateClicked((int)pixelSize.X, (int)pixelSize.Y);
                EndLocatorMode(result);
            }
        }
Ejemplo n.º 7
0
        public void EndLocatorMode(LocatorResult result)
        {
            _shell.AssertIsOnMainThread();

            var tcs = _locatorTcs;

            _locatorTcs = null;
            tcs?.SetResult(result);

            LocatorMode = false;
            LocatorModeChanged?.Invoke(this, EventArgs.Empty);

            _device.LocatorMode = LocatorMode;
        }
Ejemplo n.º 8
0
 public Task <LocatorResult> Locator(Guid deviceId, CancellationToken ct)
 {
     LocatorCalls.Add(ct);
     return(LocatorHandler != null?LocatorHandler(deviceId, ct) : Task.FromResult(LocatorResult.CreateNotClicked()));
 }
Ejemplo n.º 9
0
        Task <LocatorResult> IRCallbacks.Locator(Guid deviceId, CancellationToken ct)
        {
            var callback = _callback;

            return(callback != null?callback.Locator(deviceId, ct) : Task.FromResult(LocatorResult.CreateNotClicked()));
        }
Ejemplo n.º 10
0
        public async Task LocatorCommand()
        {
            _plotDeviceVisualComponentContainerFactory.DeviceProperties = new PlotDeviceProperties(360, 360, 96);

            await InitializeGraphicsDevice();

            await ExecuteAndWaitForPlotsAsync(new[] {
                "plot(0:10)",
            });

            var device = _plotManager.ActiveDevice;

            device.Should().NotBeNull();

            var deviceVC       = _plotManager.GetPlotVisualComponent(device);
            var deviceCommands = new RPlotDeviceCommands(_workflow, deviceVC);

            device.LocatorMode.Should().BeFalse();

            deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

            var firstLocatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
            var locatorTask          = ExecuteAndDoNotWaitForPlotsAsync(new[] {
                "res <- locator()",
            });
            await firstLocatorModeTask;

            var points = new Point[] {
                new Point(10, 10),
                new Point(100, 50),
                new Point(290, 90),
            };

            // R's high-level locator() function enters a loop that calls into
            // the graphics device low-level locator() API, which calls back into VS
            // to set locator mode and waits for either:
            // - a result with a click point
            // - a not clicked result
            // The high-level locator() function stops its loop when it gets
            // the not clicked result.
            foreach (var point in points)
            {
                device.LocatorMode.Should().BeTrue();
                deviceCommands.EndLocator.Should().BeEnabled();

                // Send a result with a click point, which will causes
                // locator mode to end and immediately start again
                var locatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
                _plotManager.EndLocatorMode(device, LocatorResult.CreateClicked((int)point.X, (int)point.Y));
                await locatorModeTask;

                device.LocatorMode.Should().BeFalse();
                deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

                locatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
                await locatorModeTask;
            }

            // Send a result with a not clicked result, which causes
            // locator mode to end, and the high-level locator() function
            // call will return.
            var lastLocatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
            await deviceCommands.EndLocator.InvokeAsync();

            await lastLocatorModeTask;

            device.LocatorMode.Should().BeFalse();
            deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

            string outputFilePath = _testFiles.GetDestinationPath("LocatorResult.csv");

            await ExecuteAndDoNotWaitForPlotsAsync(new[] {
                $"write.csv(res, {outputFilePath.ToRPath().ToRStringLiteral()})"
            });

            var x = new double[] { -2.48008095952895, 1.55378525638498, 10.0697250455366 };
            var y = new double[] { 14.4476461865435, 12.091623959219, 9.73560173189449 };

            CheckLocatorResult(outputFilePath, x, y);

            await locatorTask;
        }
Ejemplo n.º 11
0
        public void EndLocatorMode()
        {
            _shell.AssertIsOnMainThread();

            EndLocatorMode(LocatorResult.CreateNotClicked());
        }
Ejemplo n.º 12
0
 public Task <LocatorResult> Locator(Guid deviceId, CancellationToken ct) => Task.FromResult(LocatorResult.CreateNotClicked());
Ejemplo n.º 13
0
 public void EndLocatorMode()
 {
     EndLocatorMode(LocatorResult.CreateNotClicked());
 }
Ejemplo n.º 14
0
 public Task InvokeAsync()
 {
     InteractiveWorkflow.Plots.EndLocatorMode(VisualComponent.Device, LocatorResult.CreateNotClicked());
     return(Task.CompletedTask);
 }
Ejemplo n.º 15
0
        public Task <CommandResult> InvokeAsync()
        {
            InteractiveWorkflow.Plots.EndLocatorMode(VisualComponent.Device, LocatorResult.CreateNotClicked());

            return(Task.FromResult(CommandResult.Executed));
        }