Пример #1
0
        private ProductionGraphViewer CreateViewer(
            ProductionGraphViewModel graph, double scale, Thickness margin)
        {
            var viewer = new ProductionGraphViewer();

            RenderOptions.SetBitmapScalingMode(viewer, BitmapScalingMode.Fant);
            TextOptions.SetTextFormattingMode(viewer, TextFormattingMode.Display);
            viewer.SnapsToDevicePixels = true;
            viewer.UseLayoutRounding   = true;

            viewer.DataContext = graph;
            if (!TransparencyCheckBox.IsChecked == true)
            {
                viewer.Background = Brushes.White;
            }

            viewer.UpdateLayout();
            viewer.Dispatcher.Flush(DispatcherPriority.Render);

            Rect bounds = Rect.Empty;

            foreach (var node in graph.Elements.OfType <NodeElement>())
            {
                bounds.Union(new Rect(node.Position - (Vector)node.RenderSize / 2, node.RenderSize));
            }

            bounds.X      *= scale;
            bounds.Y      *= scale;
            bounds.X      -= margin.Left;
            bounds.Y      -= margin.Top;
            bounds.Width  *= scale;
            bounds.Height *= scale;
            bounds.Width  += margin.Left + margin.Right;
            bounds.Height += margin.Top + margin.Bottom;

            graph.Offset  = new Vector(bounds.X, bounds.Y);
            viewer.Width  = bounds.Width;
            viewer.Height = bounds.Height;
            viewer.UpdateLayout();

            return(viewer);
        }
Пример #2
0
        private BitmapSource RenderGraph(ProductionGraphViewModel graph, double scale)
        {
            double oldScale  = graph.Scale;
            Vector oldOffset = graph.Offset;

            graph.Scale  = scale;
            graph.Offset = new Vector();

            BitmapSource bitmap;

            try {
                var graphViewer = CreateViewer(graph, scale, new Thickness(10));

                bitmap = RenderElement(graphViewer);

                graphViewer.DataContext = null;
            } finally {
                graph.Scale  = oldScale;
                graph.Offset = oldOffset;
            }

            return(bitmap);
        }
Пример #3
0
 public ImageExportDialog(ProductionGraphViewModel sourceModel)
 {
     InitializeComponent();
     this.sourceModel = sourceModel;
 }