private void PreparePrinting()
        {
            GraphControl control = graphControl;
            // check if the rectangular region or the whole viewport should be printed
            bool  useRect = (bool)handler.GetValue(OUTPUT, PRINT_RECTANGLE);
            RectD bounds  = useRect ? exportRect.ToRectD() : graphControl.ContentRect;

            // check whether decorations (selection, handles, ...) should be hidden
            bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS);

            if (hide)
            {
                // if so, create a new graph control with the same graph
                control = new GraphControl {
                    Graph = graphControl.Graph, FlowDirection = graphControl.FlowDirection, Projection = graphControl.Projection
                };
            }

            // read CanvasPrintDocument options
            printDocument.Scale              = (double)Handler.GetValue(DOCUMENT_SETTINGS, SCALE);
            printDocument.CenterContent      = (bool)Handler.GetValue(DOCUMENT_SETTINGS, CENTER_CONTENT);
            printDocument.PageMarkPrinting   = (bool)Handler.GetValue(DOCUMENT_SETTINGS, PAGE_MARK_PRINTING);
            printDocument.ScaleDownToFitPage = (bool)Handler.GetValue(DOCUMENT_SETTINGS, SCALE_DOWN_TO_FIT_PAGE);
            printDocument.ScaleUpToFitPage   = (bool)Handler.GetValue(DOCUMENT_SETTINGS, SCALE_UP_TO_FIT_PAGE);
            // set GraphControl
            printDocument.Canvas = control;
            // set print area
            printDocument.PrintRectangle = bounds;
        }
Ejemplo n.º 2
0
        private void printButton_Click(object sender, EventArgs e)
        {
            GraphControl control = graphControl;
            // check if the rectangular region or the whole viewport should be printed
            bool  useRect = (bool)handler.GetValue(OUTPUT, EXPORT_RECTANGLE);
            RectD bounds  = useRect ? exportRect.ToRectD() : control.Viewport;

            // check whether decorations (selection, handles, ...) should be hidden
            bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS);

            if (hide)
            {
                // if so, create a new graphcontrol with the same graph
                control = new GraphControl {
                    Graph = graphControl.Graph, Projection = graphControl.Projection
                };
            }

            // read CanvasPrintDocument options
            printDocument.Scale              = (double)Handler.GetValue(DOCUMENT_SETTINGS, SCALE);
            printDocument.CenterContent      = (bool)Handler.GetValue(DOCUMENT_SETTINGS, CENTER_CONTENT);
            printDocument.PageMarkPrinting   = (bool)Handler.GetValue(DOCUMENT_SETTINGS, PAGE_MARK_PRINTING);
            printDocument.ScaleDownToFitPage = (bool)Handler.GetValue(DOCUMENT_SETTINGS, SCALE_DOWN_TO_FIT_PAGE);
            printDocument.ScaleUpToFitPage   = (bool)Handler.GetValue(DOCUMENT_SETTINGS, SCALE_UP_TO_FIT_PAGE);
            // set GraphControl
            printDocument.Canvas = control;
            // set print area
            printDocument.PrintRectangle = bounds;
            printDocument.Projection     = graphControl.Projection;

            // show new PrintPreviewDialog
            PrintPreviewDialog dialog = new PrintPreviewDialog {
                Document = printDocument
            };
            DialogResult result = dialog.ShowDialog(this);

            if (result == DialogResult.Cancel || result == DialogResult.Abort || result == DialogResult.No)
            {
                return;
            }
            // print
            printDocument.Print();
        }
        /// <summary>
        /// Creates the option handler for the label editing properties.
        /// </summary>
        /// <remarks>
        /// These options either delegate directly to properties of <see cref="GraphEditorInputMode" /> or set some global flag
        /// that is evaluated elsewhere.
        /// </remarks>
        private OptionHandler CreateOptionHandler()
        {
            var graphEditorInputMode = ((GraphEditorInputMode)GraphControl.InputMode);

            var handler = new OptionHandler("Labeling Options");

            OptionGroup currentGroup = handler.AddGroup("General");
            var         labelAddItem = currentGroup.AddBool("Label Creation", true);

            labelAddItem.PropertyChanged += delegate { graphEditorInputMode.AllowAddLabel = (bool)labelAddItem.Value; };

            var labelEditItem = currentGroup.AddBool("Label Editing", true);

            labelEditItem.PropertyChanged +=
                delegate { graphEditorInputMode.AllowEditLabel = (bool)labelEditItem.Value; };

            var hideItem = currentGroup.AddBool("Hide Label during Editing", true);

            hideItem.PropertyChanged += delegate {
                graphEditorInputMode.HideLabelDuringEditing = (bool)hideItem.Value;
            };

            var instantTypingItem = currentGroup.AddBool("Instant Typing", false);

            instantTypingItem.PropertyChanged += delegate { instantTypingEnabled = (bool)instantTypingItem.Value; };

            var useCustomHelperItem = currentGroup.AddBool("Custom Label Helper", false);

            useCustomHelperItem.PropertyChanged += delegate { customHelperEnabled = (bool)useCustomHelperItem.Value; };

            currentGroup = handler.AddGroup("Editable Items");

            // Disable the whole editable items group if neither label editing or adding allowed
            ConstraintManager cm = new ConstraintManager(handler);

            cm.SetEnabledOnCondition(
                ConstraintManager.LogicalCondition.Or(cm.CreateValueEqualsCondition(labelEditItem, true),
                                                      cm.CreateValueEqualsCondition(labelAddItem, true)), currentGroup);

            currentGroup.AddBool("Nodes", true).PropertyChanged += delegate {
                var editNodes = (bool)handler.GetValue("Editable Items", "Nodes");
                if (editNodes)
                {
                    graphEditorInputMode.LabelEditableItems |= GraphItemTypes.Node | GraphItemTypes.NodeLabel;
                }
                else
                {
                    graphEditorInputMode.LabelEditableItems &= ~(GraphItemTypes.Node | GraphItemTypes.NodeLabel);
                }
            };

            currentGroup.AddBool("Edges", true).PropertyChanged += delegate {
                var editEdges = (bool)handler.GetValue("Editable Items", "Edges");
                if (editEdges)
                {
                    graphEditorInputMode.LabelEditableItems |= GraphItemTypes.Edge | GraphItemTypes.EdgeLabel;
                }
                else
                {
                    graphEditorInputMode.LabelEditableItems &= ~(GraphItemTypes.Edge | GraphItemTypes.EdgeLabel);
                }
            };

            currentGroup = handler.AddGroup("Validation");
            var validationItem = currentGroup.AddBool("Enable Validation", false);

            validationItem.PropertyChanged += delegate { validationEnabled = (bool)validationItem.Value; };
            var patternItem = currentGroup.AddString("Pattern", DefaultValidationPattern);

            patternItem.PropertyChanged += delegate { validationPattern = new Regex((string)patternItem.Value, RegexOptions.Compiled); };

            // Editing the pattern doesn't make sense if validation is disabled
            cm.SetEnabledOnValueEquals(validationItem, true, patternItem);

            return(handler);
        }
        private void OnSnappingChanged(object sender, PropertyChangedEventArgs e)
        {
            snapContext.CollectNodePairCenterSnapLines = (bool)Handler.GetValue(CollectSnapLinesGroup, CollectNodePairCenterSnapLines);
            snapContext.CollectNodePairSnapLines       = (bool)Handler.GetValue(CollectSnapLinesGroup, CollectNodePairSnapLines);
            snapContext.CollectNodeSizes     = (bool)Handler.GetValue(SnappingElementsGroup, SnapNodes) && (bool)Handler.GetValue(CollectSnapLinesGroup, CollectSameSizeSnapLines);
            snapContext.CollectNodeSnapLines = (bool)Handler.GetValue(CollectSnapLinesGroup, CollectNodeSnapLines);
            snapContext.CollectEdgeSnapLines = (bool)Handler.GetValue(CollectSnapLinesGroup, CollectEdgeSnapLines);
            snapContext.CollectPortSnapLines = (bool)Handler.GetValue(CollectSnapLinesGroup, CollectPortSnapLines);

            snapContext.NodeToNodeDistance = (double)Handler.GetValue(CollectSnapLinesGroup + "." + SnappingDistancesGroup, NodeToNode);
            snapContext.NodeToEdgeDistance = (double)Handler.GetValue(CollectSnapLinesGroup + "." + SnappingDistancesGroup, NodeToEdge);
            snapContext.EdgeToEdgeDistance = (double)Handler.GetValue(CollectSnapLinesGroup + "." + SnappingDistancesGroup, EdgeToEdge);

            snapContext.SnapOrthogonalMovement = (bool)Handler.GetValue(CollectSnapLinesGroup, OrthogonalMovement);

            snapContext.SnapPortAdjacentSegments = (bool)Handler.GetValue(OrthogonalSnappingGroup, OrthogonalPorts);
            snapContext.SnapBendAdjacentSegments = (bool)Handler.GetValue(OrthogonalSnappingGroup, OrthogonalBends);

            snapContext.SnapNodesToSnapLines     = (bool)Handler.GetValue(SnappingElementsGroup, SnapNodes);
            snapContext.SnapBendsToSnapLines     = (bool)Handler.GetValue(SnappingElementsGroup, SnapBends);
            snapContext.SnapBendAdjacentSegments = (bool)Handler.GetValue(SnappingElementsGroup, SnapAdjacentBends);
            snapContext.SnapSegmentsToSnapLines  = (bool)Handler.GetValue(SnappingElementsGroup, SnapSegments);

            snapContext.GridSnapType = (GridSnapTypes)Handler.GetValue(GridGroup, GridSnapping);

            graphEditorInputMode.OrthogonalEdgeEditingContext.Enabled =
                (bool)Handler.GetValue(OrthogonalSnappingGroup, OrthogonalEdgeEditing);
            graphEditorInputMode.CreateEdgeInputMode.OrthogonalEdgeCreation =
                (bool)Handler.GetValue(OrthogonalSnappingGroup, OrthogonalEdgeCreation)
              ? OrthogonalEdgeEditingPolicy.Always
              : OrthogonalEdgeEditingPolicy.Never;
            UpdateGrid();
        }
Ejemplo n.º 5
0
        private ImageSource ImageExport()
        {
            GraphControl control = graphControl;
            // check if the rectangular region or the whole viewport should be exported
            bool  useRect = (bool)handler.GetValue(OUTPUT, EXPORT_RECTANGLE);
            RectD bounds  = useRect ? exportRect.ToRectD() : control.Viewport;

            // get the format
            string formatChoice = (string)Handler.GetValue(OUTPUT, FORMAT);
            string format       = Formats[formatChoice];
            // check whether decorations (selection, handles, ...) should be hidden
            bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS);

            if (hide)
            {
                // if so, create a new graph control with the same graph
                control = new GraphControl {
                    Graph         = graphControl.Graph,
                    FlowDirection = graphControl.FlowDirection,
                    Background    = graphControl.Background,
                    Projection    = graphControl.Projection
                };
            }
            IImageExporter      exporter;
            ContextConfigurator config = GetConfig(bounds, !useRect);

            var transparentBackground = (bool)Handler.GetValue(PNG, TRANSPARENT);

            if (format.Equals("XPS"))
            {
                // create the exporter
                XpsExporter xpsExporter  = new XpsExporter(config);
                string      tempFileName = Path.GetTempFileName();
                using (var fileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)) {
                    xpsExporter.Export(control, fileStream);
                }

                documentViewer.Visibility = Visibility.Visible;
                previewCanvas.Visibility  = Visibility.Hidden;
                documentViewer.Document   = new XpsDocument(tempFileName, FileAccess.Read).GetFixedDocumentSequence();
                return(null);
            }
            else
            {
                // create the exporter
                PixelImageExporter pixelImageExport = new PixelImageExporter(config);
                AddExportParameters(pixelImageExport, format);
                pixelImageExport.OutputFormat = format;
                // check if the format is transparent PNG
                if ((!format.Equals("image/png") || !transparentBackground))
                {
                    // if not, set the background color
                    pixelImageExport.Background = control.Background ?? Brushes.White;
                }
                exporter = pixelImageExport;
                var memoryStream = new MemoryStream();
                try {
                    exporter.Export(control, memoryStream);

                    // reset the stream
                    memoryStream.Position = 0;
                    // and read back the image for display
                    var bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memoryStream;
                    bitmapImage.EndInit();

                    if (previewCanvas.RootGroup.First != null)
                    {
                        previewCanvas.RootGroup.First.Remove();
                    }
                    documentViewer.Visibility = Visibility.Hidden;
                    previewCanvas.Visibility  = Visibility.Visible;
                    var image = new Image {
                        Source = bitmapImage, Width = bitmapImage.Width, Height = bitmapImage.Height
                    };
                    image.SetCanvasArrangeRect(new Rect(0, 0, image.Width, image.Height));
                    previewCanvas.RootGroup.AddChild(image, CanvasObjectDescriptors.Visual);
                    previewCanvas.ContentRect = new RectD(0, 0, bitmapImage.Width, bitmapImage.Height).GetEnlarged(20);

                    return(bitmapImage);
                } catch (IOException exception) {
                    MessageBox.Show(exception.Message, "I/O Error", MessageBoxButton.OK);
                    return(null);
                }
            }
        }
Ejemplo n.º 6
0
        private Image ImageExport()
        {
            GraphControl control = graphControl;
            // check if the rectangular region or the whole viewport should be exported
            bool  useRect = (bool)handler.GetValue(OUTPUT, EXPORT_RECTANGLE);
            RectD bounds  = useRect ? exportRect.ToRectD() : control.Viewport;

            // get the format
            string formatChoice = (string)Handler.GetValue(OUTPUT, FORMAT);
            string format       = Formats[formatChoice];
            // check whether decorations (selection, handles, ...) should be hidden
            bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS);

            if (hide)
            {
                // if so, create a new graph control with the same graph
                control = new GraphControl {
                    Graph      = graphControl.Graph,
                    BackColor  = graphControl.BackColor,
                    Projection = graphControl.Projection
                };
            }
            IImageExporter      exporter;
            ContextConfigurator config = GetConfig(bounds, !useRect);

            if (format.Equals("EMF"))
            {
                var transparentBackground = (bool)Handler.GetValue(EMF, TRANSPARENT);
                // create the exporter
                EmfImageExporter emfImageExporter = new EmfImageExporter(config);
                if (!transparentBackground)
                {
                    emfImageExporter.Background = new SolidBrush(graphControl.BackColor);
                }
                exporter = emfImageExporter;
                var memoryStream = new MemoryStream();
                exporter.Export(control, memoryStream);
                // reset the stream
                memoryStream.Position = 0;
                // and read back the metafile for display
                return(new Metafile(memoryStream));
            }
            else
            {
                // create the exporter
                PixelImageExporter pixelImageExport = new PixelImageExporter(config);
                AddExportParameters(pixelImageExport, format);
                pixelImageExport.OutputFormat = format;
                // check if the format is transparent PNG
                var transparentBackground = (bool)Handler.GetValue(PNG, TRANSPARENT);
                if ((!format.Equals("image/png") || !transparentBackground))
                {
                    // if not, set the background color
                    pixelImageExport.Background = new SolidBrush(control.BackColor);
                }
                exporter = pixelImageExport;
                var memoryStream = new MemoryStream();
                try {
                    exporter.Export(control, memoryStream);

                    // reset the stream
                    memoryStream.Position = 0;
                    // and read back the image for display
                    return(new Bitmap(memoryStream));
                } catch (IOException exception) {
                    MessageBox.Show(exception.Message, "I/O Error", MessageBoxButtons.OK);
                    return(null);
                }
            }
        }