Exemple #1
0
        public void TestBoundingBoxBezierRectangle()
        {
            var curve = new BezierTestData {
                Matrix = new Matrix {
                    OffsetX = 50, OffsetY = offsetY
                }
            }
            .RoundedRectBezier;

            ReportPainter.PushPaint(c => {
                c.SetLineWidth(1);
                var bb = BezierExtensions.BezierBoundingBox(curve);
                c.SetColor(Colors.SpringGreen);
                c.Rectangle(bb);
                c.Stroke();

                c.SetColor(Colors.Blue);
                c.SetLineWidth(2);
                ContextPainterExtensions.DrawBezier(c, curve);
                c.Stroke();
            });

            WritePainter();

            offsetY += 200;
        }
Exemple #2
0
        public void TestBezierRectangleShapeResize()
        {
            var rect  = new Rectangle(10, 10, 200, 100);
            var shape = new BezierRectangleShape(rect);

            ReportPainter.PushPaint(c => {
                c.SetLineWidth(1);
                c.SetColor(Colors.Red);
                c.Rectangle(shape.Data);
                c.Stroke();

                c.SetColor(Colors.Blue);
                ContextPainterExtensions.DrawBezier(c, shape.BezierPoints);
                c.Stroke();

                c.SetColor(Colors.Yellow);
                c.Rectangle(shape.BoundsRect);
                c.Stroke();
            });

            Action <Point, Size> prove = (l, s) => {
                Assert.AreEqual(shape.BoundsRect.Location, shape.Location);
                Assert.AreEqual(shape.BoundsRect.Size, shape.Size);
                Assert.AreEqual(shape.DataSize, shape.Data.Size);
                Assert.AreEqual(l, shape.Location);
                Assert.AreEqual(s, shape.Size);
            };

            Assert.AreEqual(shape.DataSize, rect.Size);
            prove(shape.BoundsRect.Location, shape.BoundsRect.Size);

            Action <Rectangle> proveResize = (r) => {
                var reset       = shape.Data;
                var resetBounds = shape.BoundsRect;
                shape.Location = r.Location;
                prove(r.Location, shape.Size);

                shape.Size = r.Size;
                prove(r.Location, r.Size);

                shape.Data = reset;
                prove(resetBounds.Location, resetBounds.Size);

                shape.Location = r.Location;
                shape.Size     = r.Size;
                prove(r.Location, r.Size);
            };

            var resize = shape.BoundsRect.Inflate(3, 3);

            proveResize(resize);

            resize = shape.BoundsRect.Inflate(-7, -7);
            proveResize(resize);

            WritePainter();
        }
        public void TestExpand()
        {
            var options = new AlignerOptions {
                AlignX     = Alignment.Start,
                AlignY     = Alignment.Center,
                Dimension  = Dimension.X,
                PointOrder = PointOrder.XY,
            };

            var worker = SceneWorkerWithTestData2(3, options);

            options.Distance = worker.Layout.Distance;

            var origins   = new IVisual [] { worker.Scene.Focused };
            var aligner   = new Aligner <IVisual, IVisualEdge> (worker.Scene, worker.Layout);
            var deep      = false;
            var graphView = worker.Scene.Graph as SubGraph <IVisual, IVisualEdge>;

            var affected = new SubGraphWorker <IVisual, IVisualEdge>
                               (graphView).Expand(origins, deep);

            var walk = graphView.Walk();

            origins.ForEach(origin => {
                var route = (deep ? walk.DeepWalk(origin, 1) : walk.ExpandWalk(origin, 1))
                            .Where(l => !(l.Node is IVisualEdge)).ToArray();
                var bounds         = new Rectangle(aligner.Locator.GetLocation(origin), aligner.Locator.GetSize(origin));
                options.Collisions = Collisions.None;
                var cols           = aligner.MeasureWalk(route, ref bounds, options);
                var removeCol      = cols.Dequeue();

                if (options.Dimension == Dimension.X)
                {
                    var adjust      = options.AlignY.Delta(bounds.Height, removeCol.Item2.Height);
                    bounds.Location = new Point(bounds.X + removeCol.Item2.Width + options.Distance.Width, bounds.Y - adjust);
                }
                else
                {
                    var adjust      = options.AlignX.Delta(bounds.Width, removeCol.Item2.Width);
                    bounds.Location = new Point(bounds.X + adjust, bounds.Y + removeCol.Item2.Height + options.Distance.Height);
                }
                options.Collisions = Collisions.NextFree | Collisions.PerColumn | Collisions.Toggle;
                aligner.LocateColumns(cols, bounds, options);
            });

            aligner.Commit();
            worker.Modeller.Perform();
            worker.Modeller.Finish();

            ReportPainter.PushPaint(ctx => worker.Painter.Paint(ctx));

            WritePainter();
        }
Exemple #4
0
        public void TestPaintDocumentNaviatator()
        {
            var engine = ReportPainter.Switch();

            var bounds = new Rectangle(10, 10, 500, 100);

            var iconeria = new AwesomeIconeria {
                Fill = true, FillColor = Colors.Black
            };

            var utils = Registry.Pooled <IDrawingUtils>();
            var style = Registry.Pooled <StyleSheets>().DefaultStyleSheet.ItemStyle.DefaultStyle.Clone() as IStyle;

            // points = pixels * 72 / g.DpiX;
            style.Font = Font.FromName(style.Font.Family).WithSize((bounds.Height - bounds.Height / 10) * 72 / utils.ScreenResolution().Width);

            var pageNr     = "XXXX";
            var pageNrSize = utils.GetTextDimension(pageNr, style);

            ReportPainter.PushPaint(ctx => {
                ctx.SetLineWidth(1);
                ctx.SetColor(Colors.Blue);

                ContextPainterExtensions.DrawRoundedRect(ctx, bounds, 45);
                ctx.ClosePath();
                ctx.Stroke();
                var iconSize = bounds.Height;

                iconeria.PaintIcon(ctx, iconSize, bounds.X + iconSize / 2, bounds.Y, c => {
                    c.Scale(-1, 1);
                    iconeria.FaPlay(c);
                });

                iconeria.PaintIcon(ctx, iconSize, bounds.Right - ((iconSize * .7)), bounds.Y, c => {
                    iconeria.FaPlay(c);
                });

                var textBounds      = new Rectangle(new Point(), pageNrSize);
                textBounds.Location = new Point(
                    bounds.Location.X + (bounds.Width - textBounds.Width) / 2,
                    bounds.Location.Y + (bounds.Height - textBounds.Height) / 2);

                ContextPainterExtensions.DrawText(ctx, textBounds, "123", style.Font, style.TextColor);

                ctx.SetColor(Colors.Aqua);
                ctx.Rectangle(textBounds);
                ctx.Stroke();
            });
            WritePainter();

            ReportPainter.Restore(engine);
        }
Exemple #5
0
        private void PaintSegments(IList <Point> curve)
        {
            var segments = BezierExtensions.BezierSegments(curve);
            var cols     = new Color[] {
                Colors.Blue,
                Colors.Red,
                Colors.BlueViolet,
                Colors.OrangeRed,
                Colors.AliceBlue,
                Colors.Orange,
                Colors.Aquamarine,
                Colors.DodgerBlue
            };


            ReportPainter.PushPaint(c => {
                var iCol = 0;
                foreach (var seg in segments)
                {
                    c.SetLineWidth(1);
                    var bb = BezierExtensions.BezierBoundingBox(seg.Start, seg.Cp1, seg.Cp2, seg.End);
                    c.SetColor(Colors.SpringGreen);
                    c.Rectangle(bb);
                    c.Stroke();

                    c.SetColor(cols[iCol++]);
                    c.SetLineWidth(2);
                    ContextPainterExtensions.DrawBezier(c, seg);
                    c.Stroke();

                    var med = BezierExtensions.BezierPoint(seg.Start, seg.Cp1, seg.Cp2, seg.End, .5);
                    c.SetColor(Colors.DarkGray);
                    c.Arc(med.X, med.Y, 5, 0, 360);
                    c.Stroke();
                }
            });

            WritePainter();
        }
        public void BlockAlgin()
        {
            var options = new AlignerOptions {
                AlignX     = Alignment.Start,
                AlignY     = Alignment.Start,
                Dimension  = Dimension.X,
                PointOrder = PointOrder.XY,
                Collisions = Collisions.None,
            };

            var scene = SceneWithTestData(3, 1);

            var worker = new GraphSceneContextVisualizer <IVisual, IVisualEdge> ();

            worker.Compose(scene, new VisualsRenderer());
            worker.StyleSheet.BackColor = Colors.WhiteSmoke;
            worker.Layout.SetOptions(options);

            worker.Folder.AddRaw(scene.Graph.RootSource()?.Source);
            worker.Modeller.Perform();
            worker.Modeller.Finish();

            var origins = scene.Graph.FindRoots(null);

            scene.Focused = origins.First();

            options.Distance = worker.Layout.Distance;
            var visualComparer = new VisualComparer();
            var aligner        = new Aligner <IVisual, IVisualEdge> (worker.Scene, worker.Layout);

            var graphView = worker.Scene.Graph as SubGraph <IVisual, IVisualEdge>;

            graphView.Edges().ForEach(e => e.Data = "");

            // var roots = new IVisual [] { worker.Scene.Focused };

            var walk = new Walker1 <IVisual, IVisualEdge> (graphView);

            //walk.Trace = true;
            walk.Comparer = visualComparer;

            var startPoint = (Point)worker.Layout.Border;

            foreach (var origin in origins)
            {
                ReportDetail($"-> {origin}\t{startPoint}");
                var bounds = AlignByPath(walk.DeepWalk(origin, 1, null, false), options, aligner, startPoint);
                startPoint.Y += bounds.Height + options.Distance.Height;
            }

            aligner.Commit();
            worker.Modeller.Perform();
            worker.Modeller.Finish();

            ReportPainter.PushPaint(ctx => worker.Painter.Paint(ctx));
            foreach (var r in TrackBounds.Where(r => !r.IsEmpty))
            {
                ReportPainter.PushPaint(ctx => {
                    var translate = worker.Painter.Viewport.ClipOrigin;
                    ctx.Save();
                    ctx.Translate(-translate.X, -translate.Y);

                    ctx.SetColor(Colors.Red);
                    ctx.SetLineWidth(0.5);
                    ctx.SetLineDash(0, 2, 5);
                    ctx.Rectangle(r);
                    ctx.ClosePath();
                    ctx.Stroke();
                    ctx.Restore();
                });
            }
            WritePainter();
        }
        public void TestCollisions0()
        {
            var options = new AlignerOptions {
                AlignX     = Alignment.Start,
                AlignY     = Alignment.Center,
                Dimension  = Dimension.X,
                PointOrder = PointOrder.XY
            };

            var worker = SceneWorkerWithTestData2(0, options);

            options.Distance = worker.Layout.Distance;

            var scene = worker.Scene;

            ILocator <IVisual> locator = new GraphSceneItemShapeLocator <IVisual, IVisualEdge> {
                GraphScene = scene
            };


            Action <IEnumerable <IVisual> >         reportElems  = elms => ReportElems(scene, elms, locator, options);
            Func <IEnumerable <IVisual>, Rectangle> reportExtent = elms => ReportExtent(elms, locator, options);

            var visibleItems  = new HashSet <IVisual> (scene.Elements.Where(e => !(e is IVisualEdge)));
            var visibleBounds = locator.Bounds(visibleItems);

            reportElems(visibleItems);
            reportExtent(visibleItems);


            IEnumerable <IVisual> itemsToPlace = ((scene.Graph as SubGraph <IVisual, IVisualEdge>).Source).Walk()
                                                 .DeepWalk(scene.Focused, 0)
                                                 .Select(l => l.Node)
                                                 .ToArray();

            scene.Focused.Location = Point.Zero + worker.Layout.Distance;
            itemsToPlace.ForEach(e => scene.Graph.Add(e));

            itemsToPlace = itemsToPlace.Where(e => !(e is IVisualEdge));
            var aligner = new Aligner <IVisual, IVisualEdge> (scene, worker.Layout);

            aligner.Columns(scene.Focused, itemsToPlace, options);
            locator = aligner.Locator;
            reportElems(itemsToPlace);
            var bounds = reportExtent(itemsToPlace);
            var free   = aligner.NextFreeSpace(bounds.Location, bounds.Size, itemsToPlace, options.Dimension, options.Distance);

            ReportDetail("Next free space {0}", free);
            var free2 = aligner.NearestNextFreeSpace(bounds.Location, bounds.Size, itemsToPlace, false, options.Dimension, options.Distance);

            ReportDetail("Nearest Next free space {0}", free);

            var dist = new Size(bounds.Location.X - free2.Location.X, bounds.Location.Y - free2.Location.Y);

            itemsToPlace.ForEach(e => aligner.Locator.SetLocation(e, aligner.Locator.GetLocation(e) - dist));

            aligner.Commit();
            worker.Modeller.Perform();
            worker.Modeller.Finish();

            ReportPainter.PushPaint(ctx => worker.Painter.Paint(ctx));

            ReportPainter.PushPaint(ctx => {
                var translate = worker.Painter.Viewport.ClipOrigin;
                ctx.Save();
                ctx.Translate(-translate.X, -translate.Y);
                ctx.SetLineWidth(.5);
                ctx.SetColor(Colors.Black);
                ctx.Rectangle(visibleBounds);
                ctx.Stroke();
                ctx.SetColor(Colors.Red);
                ctx.Rectangle(bounds);
                ctx.Stroke();

                ctx.SetColor(Colors.Green);
                ctx.Rectangle(free);
                ctx.Stroke();

                ctx.SetColor(Colors.LawnGreen);
                ctx.Rectangle(free2);
                ctx.Stroke();
                ctx.Restore();
                ctx.SetColor(Colors.White);
            });

            WritePainter();
        }
        public void TestShowAllData()
        {
            var options = new AlignerOptions {
                AlignX     = Alignment.Center,
                AlignY     = Alignment.Start,
                Dimension  = Dimension.X,
                PointOrder = PointOrder.XY,
                //Collisions = Collisions.NextFree
            };

            var scene     = SceneWithTestData(0);
            var graphView = scene.Graph as SubGraph <IVisual, IVisualEdge>;
            var graph     = graphView.Source;

            for (int i = 1; i < 6; i++)
            {
                (SceneWithTestData(i).Graph as SubGraph <IVisual, IVisualEdge>)
                .Source.ForEach(item => graph.Add(item));
            }

            var worker = new GraphSceneContextVisualizer <IVisual, IVisualEdge> ();

            worker.Compose(scene, new VisualsRenderer());
            worker.StyleSheet.BackColor = Colors.WhiteSmoke;
            worker.Layout.SetOptions(options);
            options.Distance = worker.Layout.Distance;

            Action allData = () => {
                var roots = new Queue <IVisual> (graph.FindRoots(null));

                var walk = graph.Walk();

                roots.ForEach(root => walk.DeepWalk(root, 0).ForEach(item => graphView.Sink.Add(item.Node)));

                walk = graphView.Walk();

                var aligner = new Aligner <IVisual, IVisualEdge> (scene, worker.Layout);
                //var bounds = new Rectangle(worker.Layout.Border.Width, worker.Layout.Border.Height, 0, 0);
                var pos = new Point(worker.Layout.Border.Width, worker.Layout.Border.Height);
                roots.ForEach(root => {
                    var steps  = walk.DeepWalk(root, 1).Where(l => !(l.Node is IVisualEdge)).ToArray();
                    var bounds = new Rectangle(pos, Size.Zero);
                    var cols   = aligner.MeasureWalk(steps, ref bounds, options);
                    //bounds = aligner.NextFreeSpace(bounds.Location, bounds.Size, walk.Select(t => t.Node), Dimension.Y, options.Distance);
                    pos = new Point(pos.X, pos.Y + bounds.Size.Height + options.Distance.Height);
                    aligner.LocateColumns(cols, bounds, options);
                    //bounds.Top = bounds.Bottom + options.Distance.Height;
                });

                aligner.Commit();
                worker.Modeller.Perform();
                worker.Modeller.Finish();
            };

            allData();
            allData();

            ReportPainter.PushPaint(ctx => worker.Painter.Paint(ctx));

            WritePainter();
        }