Exemple #1
0
        private static void GridChanged(DependencyObject d)
        {
            GridPattern g = d as GridPattern;

            if (g == null)
            {
                g = Diagram.FindParent <GridPattern>(d);
            }
            if (g != null)
            {
                g.InvalidateGrid();
                Part part = Part.FindAncestor <Part>(g);
                if (part != null)
                {
                    part.InvalidateVisual(g);
                }
            }
        }
Exemple #2
0
        private static void GridChanged(DependencyObject d)
        {
            GridPattern g = d as GridPattern;

            if (g == null)
            {
                g = Diagram.FindParent <GridPattern>(d);
            }
            if (g != null)
            {
                g.InvalidateGrid();
                Part part = Part.FindAncestor <Part>(g);
                if (part != null)
                {
                    part.InvalidateVisual(g);
                }
                else
                {
                    g.InvalidateMeasure();
                    //Diagram.Debug("GridChanged (not in Part) -- InvalidateMeasure");
                }
            }
        }
Exemple #3
0
        private UIElement GetPage(int pageNumber)
        {
            if (this.Diagram == null)
            {
                return(null);
            }
            DiagramPanel panel = this.Diagram.Panel;

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

            int  x     = pageNumber % this.EffectiveColumns;
            int  y     = pageNumber / this.EffectiveColumns;
            Rect b     = this.EffectiveBounds;
            Size sz    = this.EffectivePageSize;
            Rect viewb = new Rect(b.X + x * sz.Width,
                                  b.Y + y * sz.Height,
                                  Math.Min(sz.Width, Math.Max(1, b.Width - x * sz.Width)),
                                  Math.Min(sz.Height, Math.Max(1, b.Height - y * sz.Height)));

            double       sc     = this.EffectiveScale;
            Size         pixsz  = new Size(viewb.Width * sc, viewb.Height * sc);
            DiagramPanel ppanel = panel.GrabPrintingPanel(viewb, sc, this.PartsToPrint);

            Thickness th = this.Margin;

            if (Double.IsNaN(th.Left) || th.Left > pixsz.Width / 2)
            {
                th.Left = Math.Min(50, pixsz.Width / 2);
            }
            if (Double.IsNaN(th.Top) || th.Top > pixsz.Height / 2)
            {
                th.Top = Math.Min(50, pixsz.Height / 2);
            }

            PrintManager.PageInfo info = new PrintManager.PageInfo()
            {
                Diagram        = this.Diagram,
                Index          = pageNumber + 1,
                Count          = this.PageCount,
                Column         = x + 1,
                ColumnCount    = this.EffectiveColumns,
                Row            = y + 1,
                RowCount       = this.EffectiveRows,
                TotalBounds    = this.EffectiveBounds,
                ViewportBounds = viewb,
                Scale          = sc,
                Size           = this.PageSize,
                Viewport       = new Rect(th.Left, th.Top, pixsz.Width, pixsz.Height)
            };

            Canvas  root    = new Canvas();
            Diagram diagram = this.Diagram;

            if (diagram != null &&
                (this.PageOptions & PrintPageOptions.Background) != 0)
            {
                root.Background = diagram.Background;
            }

            DataTemplate backtemplate = this.BackgroundTemplate;

            if (backtemplate != null)
            {
                ContentPresenter back = new ContentPresenter();
                back.Content         = info;
                back.ContentTemplate = backtemplate;
                Canvas.SetLeft(back, th.Left);
                Canvas.SetTop(back, th.Top);
                root.Children.Add(back);
            }

            if (diagram != null && diagram.GridVisible && diagram.GridPattern != null &&
                (this.PageOptions & PrintPageOptions.Grid) != 0)
            {
                GridPattern grid = diagram.GridPattern;
                grid.DoUpdateBackgroundGrid(panel, new Rect(viewb.X, viewb.Y, sz.Width, sz.Height), sc, false);
                grid.Width  = viewb.Width;
                grid.Height = viewb.Height;
                Canvas.SetLeft(grid, th.Left);
                Canvas.SetTop(grid, th.Top);
                root.Children.Add(grid);
            }

            // instead of ppanel.UpdateScrollTransform(new Point(viewb.X, viewb.Y), sc, pixsz, false):
            var tg = new System.Windows.Media.TransformGroup();

            tg.Children.Add(new System.Windows.Media.TranslateTransform()
            {
                X = -viewb.X, Y = -viewb.Y
            });
            tg.Children.Add(new System.Windows.Media.ScaleTransform()
            {
                ScaleX = sc, ScaleY = sc
            });
            ppanel.RenderTransform = tg;

            // clip
            foreach (UIElement lay in ppanel.Children)
            {
                lay.Clip = new System.Windows.Media.RectangleGeometry()
                {
                    Rect = new Rect(viewb.X, viewb.Y, pixsz.Width / sc, pixsz.Height / sc)
                };
            }

            Canvas.SetLeft(ppanel, th.Left);
            Canvas.SetTop(ppanel, th.Top);
            root.Children.Add(ppanel);

            DataTemplate foretemplate = this.ForegroundTemplate;

            if (foretemplate != null)
            {
                ContentPresenter fore = new ContentPresenter();
                fore.Content         = info;
                fore.ContentTemplate = foretemplate;
                Canvas.SetLeft(fore, th.Left);
                Canvas.SetTop(fore, th.Top);
                root.Children.Add(fore);
            }

            root.Measure(this.PageSize);
            root.Arrange(new Rect(0, 0, this.PageSize.Width, this.PageSize.Height));
            return(root);
        }
Exemple #4
0
        private UIElement GetPage(int pageNumber)
        {
            if (this.Diagram == null)
            {
                return(null);
            }
            DiagramPanel panel = this.Diagram.Panel;

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

            int  x     = pageNumber % this.EffectiveColumns;
            int  y     = pageNumber / this.EffectiveColumns;
            Rect b     = this.EffectiveBounds;
            Size sz    = this.EffectivePageSize;
            Rect viewb = new Rect(b.X + x * sz.Width, b.Y + y * sz.Height, sz.Width, sz.Height);

            double       sc    = this.EffectiveScale;
            Size         pixsz = new Size(sz.Width * sc, sz.Height * sc);
            DiagramPanel img   = panel.GrabPrintingPanel(viewb, sc);
            Point        pos   = new Point(viewb.X, viewb.Y);

            //img.UpdateScrollTransform(pos, sc, pixsz, false);  // instead of UpdateScrollTransform, do:
            GridPattern grid    = null;
            Diagram     diagram = this.Diagram;

            if (diagram != null)
            {
                grid = diagram.GridPattern;
                if (grid != null && diagram.GridVisible)
                {
                    grid.DoUpdateBackgroundGrid(panel, new Rect(pos.X, pos.Y, sz.Width, sz.Height), sc, false);
                }
            }

            Canvas root = new Canvas();

            root.Children.Add(img);
            Thickness th = this.Margin;

            if (Double.IsNaN(th.Left) || th.Left > pixsz.Width / 2)
            {
                th.Left = Math.Min(50, pixsz.Width / 2);
            }
            if (Double.IsNaN(th.Top) || th.Top > pixsz.Height / 2)
            {
                th.Top = Math.Min(50, pixsz.Height / 2);
            }

            //Diagram.Debug("Page: " + pageNumber.ToString() + " " + Diagram.Str(b) + Diagram.Str(viewb) + Diagram.Str(sz) + Diagram.Str(pixsz) + th.ToString());
            var tg = new System.Windows.Media.TransformGroup();

            tg.Children.Add(new System.Windows.Media.TranslateTransform()
            {
                X = b.X - pos.X, Y = b.Y - pos.Y
            });
            tg.Children.Add(new System.Windows.Media.ScaleTransform()
            {
                ScaleX = sc, ScaleY = sc
            });
            tg.Children.Add(new System.Windows.Media.TranslateTransform()
            {
                X = th.Left, Y = th.Top
            });
            img.RenderTransform = tg;

            root.Clip = new System.Windows.Media.RectangleGeometry()
            {
                Rect = new Rect(th.Left, th.Top, pixsz.Width, pixsz.Height)
            };
            root.Measure(Geo.Unlimited);
            root.Arrange(new Rect(th.Left, th.Top, pixsz.Width, pixsz.Height));
            return(root);
        }