/// <summary> /// Prepares the layout execution. /// </summary> public void InitializeLayout() { // prepare undo/redo oldClearRect = clearRect.ToRectD(); layoutEdit = Graph.BeginEdit("Clear Area", "Clear Area"); resetToOriginalGraphStageData = CreateGivenCoordinateStageData(); executor = CreateDraggingLayoutExecutor(); }
private void ImageExportToPreview() { Image image = ImageExport(); ImageVisual imageVisual = new ImageVisual(image); if (previewCanvas.RootGroup.First != null) { previewCanvas.RootGroup.First.Remove(); } previewCanvas.RootGroup.AddChild(imageVisual, CanvasObjectDescriptors.Visual); previewCanvas.ContentRect = exportRect.ToRectD().GetEnlarged(20); }
private void Update() { if (!invalid) { return; } rectangle.Width = -1; rectangle.Height = -1; rectangle.X = 0; rectangle.Y = 0; foreach (var node in nodes) { rectangle.SetToUnion(rectangle, node.Layout); } tightRect = rectangle.ToRectD(); rectangle.X -= margins.Left; rectangle.Y -= margins.Top; rectangle.Width += margins.Left + margins.Right; rectangle.Height += margins.Top + margins.Bottom; invalid = false; }
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; }
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> /// Registers a callback function as decorator that provides a custom /// <see cref="INodeSizeConstraintProvider"/> for each node. /// </summary> /// <remarks> /// This callback function is called whenever a node in the graph is queried /// for its <see cref="INodeSizeConstraintProvider"/>. In this case, the 'node' parameter will be set /// to that node. /// </remarks> public void RegisterSizeConstraintProvider(MutableRectangle boundaryRectangle) { // One shared instance that will be used by all blue nodes var blueSizeConstraintProvider = new BlueSizeConstraintProvider(); var nodeDecorator = graphControl.Graph.GetDecorator().NodeDecorator; nodeDecorator.SizeConstraintProviderDecorator.SetFactory( node => { // Obtain the tag from the node object nodeTag = node.Tag; // Check if it is a known tag and choose the respective implementation. // Fallback to the default behavior otherwise. if (!(nodeTag is Color)) { return(null); } else if (Color.RoyalBlue.Equals(nodeTag)) { return(blueSizeConstraintProvider); } else if (Color.Green.Equals(nodeTag)) { return(new GreenSizeConstraintProvider()); } else if (Color.Orange.Equals(nodeTag)) { return(new NodeSizeConstraintProvider( new SizeD(50, 50), new SizeD(300, 300), boundaryRectangle.ToRectD())); } else { return(null); } }); }
/// <summary> /// Prepares the rectangle that is actually used to limit the node /// position, besides the base functionality. Since a position handler /// works on points, the actual rectangle must be a limit for the upper /// left corner of the node and not for the node's bounding box. /// </summary> protected override void OnInitialized(IInputModeContext context, PointD originalLocation) { base.OnInitialized(context, originalLocation); // Shrink the retangle by the node size to get the limits for the upper left node corner boundaryPositionRectangle = boundaryRectangle.ToRectD() + new InsetsD(0, 0, -node.Layout.Width, -node.Layout.Height); }
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); } } }