Exemplo n.º 1
0
        public Point NextFreePosition0(Point start, Size sizeNeeded, Dimension dimension, IEnumerable <TItem> ignore, double distance)
        {
            var result = new Rectangle(start, sizeNeeded);
            var loc    = new GraphSceneItemShapeLocator <TItem, TEdge> {
                GraphScene = this.GraphScene
            };
            var measure = new MeasureVisitBuilder <TItem> (loc);

            var iRect = result;

            while (!iRect.IsEmpty)
            {
                var elems = GraphScene.ElementsIn(iRect).Where(e => !(e is TEdge)).Except(ignore);
                if (!elems.Any())
                {
                    break;
                }
                Action <TItem> visit = null;
                var            frect = measure.Bounds(ref visit);
                foreach (var item in elems)
                {
                    visit(item);
                }
                iRect = frect();
                if (!iRect.IsEmpty)
                {
                    iRect  = new Rectangle(new Point(iRect.Right + distance, result.Top), sizeNeeded);
                    result = iRect;
                }
            }


            return(result.Location);
        }
Exemplo n.º 2
0
        IList <Rectangle> CalculateFreeSpace(Point start, Size sizeNeeded, Dimension dimension, IEnumerable <TItem> ignore, double distance)
        {
            var h     = dimension == Dimension.X ? sizeNeeded.Height : GraphScene.Shape.Size.Height;
            var w     = dimension == Dimension.X ? GraphScene.Shape.Size.Width : sizeNeeded.Width;
            var iRect = new Rectangle(start, new Size(w, h));

            var comparer = new PointComparer {
                Order = dimension == Dimension.X ? PointOrder.X : PointOrder.Y
            };
            var loc = new GraphSceneItemShapeLocator <TItem, TEdge> {
                GraphScene = this.GraphScene
            };
            var elems = GraphScene.ElementsIn(iRect)
                        .Where(e => !(e is TEdge)).Except(ignore).OrderBy(e => loc.GetLocation(e), comparer);

            return(new Rectangle[0]);
        }
Exemplo n.º 3
0
        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();
        }