Ejemplo n.º 1
0
        /// <summary>
        /// Copies the current graph as an bitmap image to the clipboard in native bmp format.
        /// </summary>
        /// <param name="doc">Graph to copy to the clipboard.</param>
        /// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
        /// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
        /// <param name="pixelformat">Specify the pixelformat here.</param>
        public static void CopyToClipboardAsBitmap(this GraphDocument doc, int dpiResolution, Altaxo.Graph.Gdi.BrushX backbrush, PixelFormat pixelformat)
        {
            var dao = Current.Gui.GetNewClipboardDataObject();

            System.Drawing.Bitmap bitmap = GraphDocumentExportActions.RenderAsBitmap(doc, backbrush, pixelformat, dpiResolution, dpiResolution);
            dao.SetImage(bitmap);
            Current.Gui.SetClipboardDataObject(dao);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try to paste the entire GraphDocument from the clipboard using the specified paste options.
        /// </summary>
        /// <param name="doc">The graph document to paste into.</param>
        /// <param name="options">The options used for paste into that graph.</param>
        public static void PasteFromClipboard(this GraphDocument doc, GraphCopyOptions options)
        {
            object from = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphDocumentAsXml");

            if (from is GraphDocument)
            {
                doc.CopyFrom((GraphDocument)from, options);
            }
        }
Ejemplo n.º 3
0
        public static void PasteFromClipboardAsNewLayer(this GraphDocument doc)
        {
            object o     = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphLayerAsXml");
            var    layer = o as XYZPlotLayer;

            if (null != layer)
            {
                doc.RootLayer.Layers.Add(layer);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the graph into a stream.
        /// </summary>
        /// <param name="doc">The graph document to export.</param>
        /// <param name="stream">The stream to render inot.</param>
        /// <param name="backbrush1">First brush used to fill the background of the image (normally used with 24bbp bitmap formats to make the background opaque. Can be <c>null</c>.</param>
        /// <param name="backbrush2">Second brush used to fill the background of the image. Can be <c>null</c>.</param>
        /// <param name="pixelformat">Specify the pixelformat here.</param>
        /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
        /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
        /// <returns>The pixel dimensions of the image if the rendering was successful. The tuple (0,0) is returned if the rendering was unsuccessful, e.g. if no exporter was available.</returns>
        public static (int PixelsX, int PixelsY) RenderToStream(this GraphDocument doc, System.IO.Stream stream, Altaxo.Graph.Gdi.BrushX backbrush1, Altaxo.Graph.Gdi.BrushX backbrush2, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
        {
            var exportOptions = new Altaxo.Graph.Gdi.GraphExportOptions();

            exportOptions.TrySetImageAndPixelFormat(ImageFormat.Png, PixelFormat.Format32bppArgb);
            exportOptions.SourceDpiResolution      = sourceDpiResolution;
            exportOptions.DestinationDpiResolution = destinationDpiResolution;
            exportOptions.BackgroundBrush          = backbrush1;
            return(RenderToStream(doc, stream, exportOptions));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Pastes a layer on the clipboard as new layer after the layer at index <paramref name="currentActiveLayerNumber"/>.
        /// </summary>
        /// <param name="doc">Graph document to paste to.</param>
        /// <param name="currentActiveLayerNumber">Index of the layer after which to paste the layer from the clipboard.</param>
        public static void PasteFromClipboardAsNewLayerAfterLayerNumber(this GraphDocument doc, IEnumerable <int> currentActiveLayerNumber)
        {
            object o     = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphLayerAsXml");
            var    layer = o as XYZPlotLayer;

            if (null != layer)
            {
                doc.RootLayer.InsertAfter(currentActiveLayerNumber, layer);
            }
        }
Ejemplo n.º 6
0
        public static Bitmap RenderAsBitmap(this GraphDocument document, EmbeddedObjectRenderingOptions renderingOptions, PixelFormat pixelFormat = PixelFormat.Format32bppArgb)
        {
            BrushX opaqueGround = null;

            if (!GraphExportOptions.HasPixelFormatAlphaChannel(pixelFormat))
            {
                opaqueGround = new BrushX(renderingOptions.BackgroundColorForFormatsWithoutAlphaChannel);
            }

            return(RenderAsBitmap(document, opaqueGround, renderingOptions.BackgroundBrush, pixelFormat, renderingOptions.SourceDpiResolution, renderingOptions.SourceDpiResolution * renderingOptions.OutputScalingFactor));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Shows the copy page options dialog and stores the result as the static field <see cref="P:ClipboardRenderingOptions.CopyPageOptions"/> here in this class
        /// </summary>
        /// <param name="doc">Ignored. Can be set to null.</param>
        /// <returns>True when the dialog was successfully closed, false otherwise.</returns>
        public static bool ShowCopyPageOptionsDialog(this GraphDocument doc)
        {
            object resultobj = ClipboardRenderingOptions.CopyPageOptions;

            if (Current.Gui.ShowDialog(ref resultobj, "Set copy page options"))
            {
                ClipboardRenderingOptions.CopyPageOptions = (ClipboardRenderingOptions)resultobj;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Pastes a layer on the clipboard as new layer after the layer at index <paramref name="currentActiveLayerNumber"/>.
        /// </summary>
        /// <param name="doc">Graph document to paste to.</param>
        /// <param name="currentActiveLayerNumber">Index of the layer after which to paste the layer from the clipboard.</param>
        public static void PasteFromClipboardAsNewChildLayerOfLayerNumber(this GraphDocument doc, IEnumerable <int> currentActiveLayerNumber)
        {
            object o     = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphLayerAsXml");
            var    layer = o as XYZPlotLayer;

            if (null != layer)
            {
                var parentLayer = doc.RootLayer.ElementAt(currentActiveLayerNumber);
                parentLayer.Layers.Insert(0, layer);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Saves the graph as into a stream.
        /// </summary>
        /// <param name="doc">The graph document to export.</param>
        /// <param name="stream">The stream to render inot.</param>
        /// <param name="exportOptions">The export options to use.</param>
        /// <returns>The dimensions of the image in pixels). If the rendering was unsuccessful, e.g. because no exporter was available, the tuple (0,0) is returned.</returns>
        public static (int pixelsX, int pixelsY) RenderToStream(this GraphDocument doc, System.IO.Stream stream, Altaxo.Graph.Gdi.GraphExportOptions exportOptions)
        {
            var imageExporter = Current.ProjectService.GetProjectItemImageExporter(doc);

            if (null == imageExporter)
            {
                return(0, 0);
            }
            else
            {
                return(imageExporter.ExportAsImageToStream(doc, exportOptions, stream));
            }
        }
Ejemplo n.º 10
0
 public void Deserialize(GraphDocument s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
 {
     s._name            = info.GetString("Name");
     s._graphIdentifier = info.GetString("GraphIdentifier");
     s._creationTime    = info.GetDateTime("CreationTime").ToUniversalTime();
     s._lastChangeTime  = info.GetDateTime("LastChangeTime").ToUniversalTime();
     s._notes.Text      = info.GetString("Notes");
     s.RootLayer        = (HostLayer)info.GetValue("RootLayer", s);
     s.PropertyBag      = (Main.Properties.PropertyBag)info.GetValue("Properties", s);
     s.Lighting         = (LightSettings)info.GetValue("Lighting", s);
     s.Camera           = (CameraBase)info.GetValue("Camera", s);
     //s._defaultCamera = (CameraBase)info.GetValue("DefaultCamera", s);
 }
Ejemplo n.º 11
0
        public GraphDocument(GraphDocument from)
        {
            using (var suppressToken = SuspendGetToken())
            {
                _creationTime = _lastChangeTime = DateTime.UtcNow;
                RootLayer     = new HostLayer(null, new ItemLocationDirect {
                    SizeX = RADouble.NewAbs(DefaultRootLayerSizeX), SizeY = RADouble.NewAbs(DefaultRootLayerSizeY), SizeZ = RADouble.NewAbs(DefaultRootLayerSizeZ)
                });

                CopyFrom(from, Altaxo.Graph.Gdi.GraphCopyOptions.All);

                suppressToken.ResumeSilently();
            }
        }
Ejemplo n.º 12
0
        public static void PasteFromClipboardAsTemplateForLayer(GraphDocument doc, IEnumerable <int> layerNumber, GraphCopyOptions options)
        {
            object o = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphLayerAsXml");

            if (null == o)
            {
                return;
            }
            var layer = o as XYZPlotLayer;

            if (null != layer)
            {
                doc.RootLayer.ElementAt(layerNumber).CopyFrom(layer, options);
            }
        }
Ejemplo n.º 13
0
        public void CopyFrom(GraphDocument from, Altaxo.Graph.Gdi.GraphCopyOptions options)
        {
            if (object.ReferenceEquals(this, from))
            {
                return;
            }

            using (var suspendToken = SuspendGetToken())
            {
                Camera   = from.Camera;   // Camera is immutable
                Lighting = from.Lighting; // lighting is immutable

                if (0 != (options & Altaxo.Graph.Gdi.GraphCopyOptions.CloneNotes))
                {
                    ChildCopyToMember(ref _notes, from._notes);
                }

                if (0 != (options & Altaxo.Graph.Gdi.GraphCopyOptions.CloneProperties))
                {
                    // Clone also the graph properties
                    if (from._graphProperties != null && from._graphProperties.Count > 0)
                    {
                        PropertyBagNotNull.CopyFrom(from._graphProperties);
                    }
                    else
                    {
                        _graphProperties = null;
                    }
                }

                // the order is important here: clone the layers only before setting the printable graph bounds and other
                // properties, otherwise some errors will happen
                var newRootLayer = RootLayer;
                if (Altaxo.Graph.Gdi.GraphCopyOptions.CopyLayerAll == (options & Altaxo.Graph.Gdi.GraphCopyOptions.CopyLayerAll))
                {
                    newRootLayer = (HostLayer)from._rootLayer.Clone();
                }
                else if (0 != (options & Altaxo.Graph.Gdi.GraphCopyOptions.CopyLayerAll))
                {
                    // don't clone the layers, but copy the style of each each of the souce layers to the destination layers - this has to be done recursively
                    newRootLayer.CopyFrom(from._rootLayer, options);
                }
                RootLayer = newRootLayer;

                suspendToken.Resume();
            }
        }
Ejemplo n.º 14
0
        public static void PasteFromClipboardAsTemplateForLayer(this GraphDocument doc, IEnumerable <int> layerNumber)
        {
            /*
             *                object options = new PasteLayerOptions() { PastePlotStyles = true, PastePlotItems = true };
             *                if (false == Current.Gui.ShowDialog(ref options, "Choose what to paste"))
             *                        return;
             *                        PasteFromClipboardAsTemplateForLayer(doc, layerNumber, (options as PasteLayerOptions).GetCopyOptions());
             *
             */

            GraphCopyOptions options = _lastChoosenGraphLayerPasteOptions;

            System.Enum options1 = options;
            if (Current.Gui.ShowDialogForEnumFlag(ref options1, "Choose paste options"))
            {
                options = (GraphCopyOptions)options1;
                _lastChoosenGraphLayerPasteOptions = options;
                PasteFromClipboardAsTemplateForLayer(doc, layerNumber, options);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Try to paste the entire GraphDocument from the clipboard.
        /// </summary>
        /// <param name="doc">The graph document to paste into.</param>
        /// <param name="showOptionsDialog">If <c>true</c>, shows the user an option dialog for choise of specific items to paste.</param>
        public static void PasteFromClipboardAsGraphStyle(this GraphDocument doc, bool showOptionsDialog)
        {
            object from = ClipboardSerialization.GetObjectFromClipboard("Altaxo.Graph.Graph3D.GraphDocumentAsXml");

            if (from is GraphDocument)
            {
                GraphCopyOptions options = DefaultGraphDocumentPasteOptions;
                if (showOptionsDialog)
                {
                    System.Enum o = _lastChoosenGraphDocumentPasteOptions;
                    if (!Current.Gui.ShowDialogForEnumFlag(ref o, "Choose options for pasting"))
                    {
                        return;
                    }
                    _lastChoosenGraphDocumentPasteOptions = (GraphCopyOptions)o;
                    options = _lastChoosenGraphDocumentPasteOptions;
                }
                PasteFromClipboard(doc, options);
            }
        }
Ejemplo n.º 16
0
 /// <summary>Initializes a new instance of the <see cref="GraphViewOptions"/> class.</summary>
 /// <param name="graphDocument">The graph document.</param>
 /// <param name="rootLayerMarkersVisibility">The visibility of the root layer markers.</param>
 public GraphViewOptions(GraphDocument graphDocument, RootLayerMarkersVisibility?rootLayerMarkersVisibility)
 {
     _graphDocument = graphDocument;
     _rootLayerMarkersVisibility = rootLayerMarkersVisibility;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Saves the graph as an bitmap file and returns the bitmap.
 /// </summary>
 /// <param name="doc">The graph document to export.</param>
 /// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
 /// <param name="pixelformat">Specify the pixelformat here.</param>
 /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
 /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
 /// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
 public static Bitmap RenderAsBitmap(this GraphDocument doc, Altaxo.Graph.Gdi.BrushX backbrush, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
 {
     return(RenderAsBitmap(doc, backbrush, null, pixelformat, sourceDpiResolution, destinationDpiResolution));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Saves the graph as an bitmap file and returns the bitmap.
        /// </summary>
        /// <param name="doc">The graph document to export.</param>
        /// <param name="backbrush1">First brush used to fill the background of the image (normally used with 24bbp bitmap formats to make the background opaque. Can be <c>null</c>.</param>
        /// <param name="backbrush2">Second brush used to fill the background of the image. Can be <c>null</c>.</param>
        /// <param name="pixelformat">Specify the pixelformat here.</param>
        /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
        /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
        /// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
        public static Bitmap RenderAsBitmap(this GraphDocument doc, Altaxo.Graph.Gdi.BrushX backbrush1, Altaxo.Graph.Gdi.BrushX backbrush2, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
        {
            var imageExporter = Current.ProjectService.GetProjectItemImageExporter(doc);

            if (null == imageExporter)
            {
                return(null);
            }

            Bitmap bitmap = null;

            using (var memStream = new System.IO.MemoryStream())
            {
                var exportOptions = new Altaxo.Graph.Gdi.GraphExportOptions();
                exportOptions.TrySetImageAndPixelFormat(ImageFormat.Png, PixelFormat.Format32bppArgb);
                exportOptions.SourceDpiResolution      = sourceDpiResolution;
                exportOptions.DestinationDpiResolution = destinationDpiResolution;
                exportOptions.BackgroundBrush          = backbrush1;
                imageExporter.ExportAsImageToStream(doc, exportOptions, memStream);

                memStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap = (Bitmap)Bitmap.FromStream(memStream);
            }

            int bmpWidth  = bitmap.Width;
            int bmpHeight = bitmap.Height;

            /*
             *                double outputScaling = sourceDpiResolution / destinationDpiResolution;
             *                bitmap.SetResolution((float)(bmpWidth / (outputScaling * doc.Size.X / 72)), (float)(bmpHeight / (outputScaling * doc.Size.Y / 72)));
             *
             *                using (Graphics grfx = Graphics.FromImage(bitmap))
             *                {
             *                        // Set everything to high quality
             *                        grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
             *                        grfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
             *
             *                        // 2014-10-10 Setting InterpolationMode to HighQualityBicubic and PixelOffsetMode to HighQuality
             *                        // causes problems when rendering small bitmaps (at a large magnification, for instance the density image legend):
             *                        // the resulting image seems a litte soft, the colors somehow distorted, so I decided not to use them here any more
             *
             *                        //		grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             *                        //		grfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
             *
             *                        grfx.PageUnit = GraphicsUnit.Point;
             *                        grfx.ScaleTransform((float)outputScaling, (float)outputScaling);
             *                        grfx.SetClip(new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *
             *                        if (null != backbrush1)
             *                        {
             *                                backbrush1.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
             *                                grfx.FillRectangle(backbrush1, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *                        }
             *
             *                        if (null != backbrush2)
             *                        {
             *                                backbrush2.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
             *                                grfx.FillRectangle(backbrush2, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *                        }
             *                }
             */

            bitmap.SetResolution((float)destinationDpiResolution, (float)destinationDpiResolution);

            return(bitmap);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Puts the layer with index <paramref name="layerNumber"/> to the clipboard in XML format.
 /// </summary>
 /// <param name="doc">Graph document to copy.</param>
 /// <param name="layerNumber">Number of the layer to copy.</param>
 public static void CopyToClipboardLayerAsNative(this GraphDocument doc, IEnumerable <int> layerNumber)
 {
     ClipboardSerialization.PutObjectToClipboard("Altaxo.Graph.Graph3D.GraphLayerAsXml", doc.RootLayer.ElementAt(layerNumber));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Puts the entire graph to the clipboard in XML format.
 /// </summary>
 /// <param name="doc">Graph to copy to the clipboard.</param>
 public static void CopyToClipboardAsNative(this GraphDocument doc)
 {
     ClipboardSerialization.PutObjectToClipboard("Altaxo.Graph.Graph3D.GraphDocumentAsXml", doc);
 }