Example #1
0
        /// <summary>
        /// Causes a complete redrawing of the graph. The cached graph bitmap will be marked as dirty and a repainting of the graph area is triggered with Gui render priority.
        /// Note: it is save to call this function from non-Gui threads.
        /// </summary>
        private void StartCompleteRepaint()
        {
            var controller = Controller;

            if (null == controller)
            {
                return;
            }

            // rendering in the background
            Altaxo.Graph.Gdi.GraphDocumentRenderManager.Instance.AddTask(
                controller,
                controller.Doc,
                (graphDocument, token) =>
            {
                if (graphDocument.IsDisposeInProgress)
                {
                    return;
                }

                var size = _cachedGraphSize_Pixels;

                if (size.Width > 1 && size.Height > 1)
                {
                    if (!_gdiWpfBitmapManager.TryTake(size, out var bmp))
                    {
                        Current.Dispatcher.InvokeIfRequired((Action)(() => bmp = new GdiToWpfBitmap(size.Width, size.Height)));
                    }

                    var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp);
                    controller.ScaleForPaintingGraphDocument(grfx);
                    var cachedGraphImage = new CachedGraphImage {
                        ZoomFactor = controller.ZoomFactor, ViewPortsUpperLeftCornerInGraphCoordinates = controller.PositionOfViewportsUpperLeftCornerInGraphCoordinates, Size = _cachedGraphSize_96thInch, BitmapSize_Pixel = size
                    };

                    if (!graphDocument.IsDisposeInProgress)
                    {
                        graphDocument.Paint(grfx, false);
                    }

                    Current.Dispatcher.InvokeIfRequired(() =>
                    {
                        var bmpSource = bmp.WpfBitmapSource;
                        cachedGraphImage.CachedGraphImageSource = bmpSource;
                        _cachedGraphImage  = cachedGraphImage;
                        _graphImage.Source = bmpSource;
                        _isGraphUpToDate   = true;
                        grfx.Dispose();

                        var overlay          = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
                        _graphOverlay.Source = overlay;
                        cachedGraphImage.CachedOverlayImageSource = overlay;
                        _gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);

                        ShowCachedGraphImage();
                    });
                }
            }
                );
        }
Example #2
0
		/// <summary>
		/// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread.
		/// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
		/// </summary>
		private static ImageSource GetImageSourceByRenderingOverlay(GraphControllerWpf controller, GdiToWpfBitmap bmp, CachedGraphImage cachedGraphImage)
		{
			if (controller.IsOverlayPaintingRequired)
			{
				using (var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp))
				{
					controller.DoPaintOverlay(grfx, cachedGraphImage.ZoomFactor, cachedGraphImage.ViewPortsUpperLeftCornerInGraphCoordinates);
					return bmp.WpfBitmapSource;
				}
			}
			else
			{
				return null;
			}
		}
Example #3
0
		/// <summary>
		/// Causes a complete redrawing of the graph. The cached graph bitmap will be marked as dirty and a repainting of the graph area is triggered with Gui render priority.
		/// Note: it is save to call this function from non-Gui threads.
		/// </summary>
		private void StartCompleteRepaint()
		{
			var controller = Controller;
			if (null == controller)
				return;

			// rendering in the background
			Altaxo.Graph.Gdi.GraphDocumentRenderManager.Instance.AddTask(
				controller,
				controller.Doc,
				(graphDocument, token) =>
				{
					if (graphDocument.IsDisposeInProgress)
						return;

					var size = _cachedGraphSize_Pixels;

					if (size.Width > 1 && size.Height > 1)
					{
						GdiToWpfBitmap bmp;
						if (!_gdiWpfBitmapManager.TryTake(size, out bmp))
							Current.Gui.Execute(() => bmp = new GdiToWpfBitmap(size.Width, size.Height));

						var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp);
						controller.ScaleForPaintingGraphDocument(grfx);
						var cachedGraphImage = new CachedGraphImage { ZoomFactor = controller.ZoomFactor, ViewPortsUpperLeftCornerInGraphCoordinates = controller.PositionOfViewportsUpperLeftCornerInGraphCoordinates, Size = _cachedGraphSize_96thInch, BitmapSize_Pixel = size };

						if (!graphDocument.IsDisposeInProgress)
							graphDocument.Paint(grfx, false);

						Current.Gui.Execute(() =>
						{
							var bmpSource = bmp.WpfBitmapSource;
							cachedGraphImage.CachedGraphImageSource = bmpSource;
							_cachedGraphImage = cachedGraphImage;
							_graphImage.Source = bmpSource;
							_isGraphUpToDate = true;
							grfx.Dispose();

							var overlay = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
							_graphOverlay.Source = overlay;
							cachedGraphImage.CachedOverlayImageSource = overlay;
							_gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);

							ShowCachedGraphImage();
						});
					}
				}
				);
		}
Example #4
0
 /// <summary>
 /// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread.
 /// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
 /// </summary>
 private static ImageSource GetImageSourceByRenderingOverlay(GraphController controller, GdiToWpfBitmap bmp, CachedGraphImage cachedGraphImage)
 {
     if (controller.IsOverlayPaintingRequired)
     {
         using (var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp))
         {
             controller.DoPaintOverlay(grfx, cachedGraphImage.ZoomFactor, cachedGraphImage.ViewPortsUpperLeftCornerInGraphCoordinates);
             return(bmp.WpfBitmapSource);
         }
     }
     else
     {
         return(null);
     }
 }