Ejemplo n.º 1
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point location = Location.Resolve(layout, layoutContext.Options);
            var   drawRect = new Rect(location, new Size(Width, Height));

            switch (layout.GetFlipType())
            {
            case FlipType.Horizontal:
                drawRect = new Rect(drawRect.X - Width, drawRect.Y, Width, Height);
                break;

            case FlipType.Vertical:
                drawRect = new Rect(drawRect.X, drawRect.Y - Height, Width, Height);
                break;

            case FlipType.Both:
                drawRect = new Rect(drawRect.X - Width, drawRect.Y - Height, Width, Height);
                break;
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawRectangle(Point.Add(drawRect.TopLeft, layout.Location), drawRect.Size, StrokeThickness, Fill);
            }
            else
            {
                drawingContext.DrawRectangle(drawRect.TopLeft, drawRect.Size, StrokeThickness, Fill);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the smallest rectangle that bounds all of the items</summary>
        /// <param name="layoutContext">Layout context</param>
        /// <param name="items">Items</param>
        /// <param name="bounds">Bounding rectangle (output parameter)</param>
        /// <returns>Rectangle that bounds all of the items</returns>
        public static BoundsSpecified GetBounds(this ILayoutContext layoutContext, IEnumerable <object> items, out Rect bounds)
        {
            BoundsSpecified resultFlags  = BoundsSpecified.None;
            Rect            resultBounds = Rect.Empty;

            foreach (object item in items)
            {
                Rect            itemBounds;
                BoundsSpecified itemFlags = layoutContext.GetBounds(item, out itemBounds);
                if (itemFlags == BoundsSpecified.All)
                {
                    if (resultBounds.IsEmpty)
                    {
                        resultBounds = itemBounds;
                        resultFlags  = itemFlags;
                    }
                    else
                    {
                        resultBounds = Rect.Union(resultBounds, itemBounds);
                        resultFlags &= itemFlags;
                    }
                }
            }

            bounds = resultBounds;
            return(resultFlags);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the smallest rectangle that bounds all of the items</summary>
        /// <param name="layoutContext">Layout context</param>
        /// <param name="items">Items</param>
        /// <param name="bounds">Bounding rectangle, in world coordinates (output parameter)</param>
        /// <returns>Rectangle that bounds all the items</returns>
        public static BoundsSpecified GetBounds(this ILayoutContext layoutContext, IEnumerable <object> items, out Rectangle bounds)
        {
            BoundsSpecified resultFlags  = BoundsSpecified.None;
            Rectangle       resultBounds = new Rectangle();
            bool            firstTime    = true;

            foreach (object item in items)
            {
                Rectangle       itemBounds;
                BoundsSpecified itemFlags = layoutContext.GetBounds(item, out itemBounds);
                if (itemFlags == BoundsSpecified.All)
                {
                    if (firstTime)
                    {
                        firstTime    = false;
                        resultBounds = itemBounds;
                        resultFlags  = itemFlags;
                    }
                    else
                    {
                        resultBounds = Rectangle.Union(resultBounds, itemBounds);
                        resultFlags &= itemFlags;
                    }
                }
            }

            bounds = resultBounds;
            return(resultFlags);
        }
Ejemplo n.º 4
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            var commands = new List <IPathCommand>(Commands.Count);
            var flipType = layout.GetFlipType();

            foreach (IPathCommand command in Commands)
            {
                var flippedCommand = command;
                if ((flipType & FlipType.Horizontal) == FlipType.Horizontal)
                {
                    flippedCommand = flippedCommand.Flip(true);
                }
                if ((flipType & FlipType.Vertical) == FlipType.Vertical)
                {
                    flippedCommand = flippedCommand.Flip(false);
                }
                commands.Add(flippedCommand);
            }

            Point start = Start.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawPath(start, commands, Thickness, Fill);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Moves the items so that their bounding boxes all have the Top (y) value of the
 /// top-most item</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignTops(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     foreach (object item in items)
     {
         layoutContext.SetBounds(item, bounds, BoundsSpecified.Y);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Top (y) value of the
        /// top-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignTops(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                layoutContext.SetBounds(item, bounds, BoundsSpecified.Y);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Moves the item, so that the center of its bounding box is at the given point</summary>
        /// <param name="layoutContext">Layout context containing item</param>
        /// <param name="item">Item to center</param>
        /// <param name="center">Centering point</param>
        public static void Center(this ILayoutContext layoutContext, object item, Point center)
        {
            Rect oldBounds;

            layoutContext.GetBounds(item, out oldBounds);
            Point topLeft = new Point(
                center.X - oldBounds.Width / 2,
                center.Y - oldBounds.Height / 2);

            layoutContext.SetBounds(item, oldBounds, new Rect(topLeft, oldBounds.Size), BoundsSpecified.Location);
        }
Ejemplo n.º 8
0
        private BoundsSpecified GetBoundsSpecified(ILayoutContext layoutContext, IEnumerable <object> items)
        {
            BoundsSpecified itemFlags = BoundsSpecified.None;

            foreach (object item in items)
            {
                itemFlags |= layoutContext.CanSetBounds(item);
            }

            return(itemFlags);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the height of all of the items to that of the tallest item</summary>
        /// <param name="items">Items to resize</param>
        /// <param name="layoutContext">Layout context of items to resize</param>
        public virtual void MakeHeightEqual(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Size maxSize = GetMaxSize(items, layoutContext);

            foreach (object item in items)
            {
                Rectangle bounds;
                layoutContext.GetBounds(item, out bounds);
                bounds.Height = maxSize.Height;
                layoutContext.SetBounds(item, bounds, BoundsSpecified.Height);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Centers items in canvas at point</summary>
        /// <param name="items">Items to center</param>
        /// <param name="p">Point at which to center items</param>
        public void Center(IEnumerable <object> items, Point p)
        {
            ILayoutContext layoutContext = this.As <ILayoutContext>();

            if (layoutContext != null)
            {
                // get bounds, convert to world coords
                Matrix transform = m_viewingContext.Control.As <ITransformAdapter>().Transform;
                p = GdiUtil.InverseTransform(transform, p);
                LayoutContexts.Center(layoutContext, items, p);
            }
        }
Ejemplo n.º 11
0
        public void Layout(ILayoutContext context)
        {
            // Pre-layout.
            //
            foreach (var extension in context.Extensions)
            {
                extension.PreLayout(context);
            }

            try
            {
                // Final step in binding that transfers (moves/copies) all files generated into the appropriate
                // location in the source image.
                if (context.FileTransfers?.Any() == true)
                {
                    this.Messaging.Write(VerboseMessages.LayingOutMedia());

                    var command = new TransferFilesCommand(this.Messaging, context.Extensions, context.FileTransfers, context.SuppressAclReset);
                    command.Execute();
                }

                if (context.TrackedFiles != null)
                {
                    this.CleanTempFiles(context.IntermediateFolder, context.TrackedFiles);
                }
            }
            finally
            {
                if (context.TrackedFiles != null)
                {
                    if (!String.IsNullOrEmpty(context.ContentsFile))
                    {
                        this.CreateContentsFile(context.ContentsFile, context.TrackedFiles);
                    }

                    if (!String.IsNullOrEmpty(context.OutputsFile))
                    {
                        this.CreateOutputsFile(context.OutputsFile, context.TrackedFiles);
                    }

                    if (!String.IsNullOrEmpty(context.BuiltOutputsFile))
                    {
                        this.CreateBuiltOutputsFile(context.BuiltOutputsFile, context.TrackedFiles);
                    }
                }
            }

            // Post-layout.
            foreach (var extension in context.Extensions)
            {
                extension.PostLayout();
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Moves the items so that their bounding boxes all have the Left (x) value
 /// of the left-most item</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignLefts(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.X = bounds.X;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
     }
 }
Ejemplo n.º 13
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            var centre = Centre.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawEllipse(Point.Add(centre, layout.Location), RadiusX, RadiusY, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawEllipse(centre, RadiusX, RadiusY, Thickness, Fill);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Bottom (y + Height) value
        /// of the bottom-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignBottoms(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                Rectangle itemBounds;
                layoutContext.GetBounds(item, out itemBounds);
                itemBounds.Y = bounds.Bottom - itemBounds.Height;
                layoutContext.SetBounds(item, itemBounds, BoundsSpecified.Y);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Layout the keyboard onto a Canvas.
        /// </summary>
        /// <param name="context">The layout context.</param>
        internal void Layout(ILayoutContext context)
        {
            var y = context.Top;

            foreach (var row in Rows)
            {
                var height = row.Height * context.KeySize;

                row.Layout(context, y, height);

                y += height;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Right (x + Width) value
        /// of the right-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignRights(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                Rectangle itemBounds;
                layoutContext.GetBounds(item, out itemBounds);
                itemBounds.X = bounds.Right - itemBounds.Width;
                layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
            }
        }
Ejemplo n.º 17
0
        private Size GetMaxSize(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Size size = new Size();

            foreach (object item in items)
            {
                Rectangle bounds;
                layoutContext.GetBounds(item, out bounds);
                size = new Size(
                    Math.Max(size.Width, bounds.Width),
                    Math.Max(size.Height, bounds.Height));
            }
            return(size);
        }
        internal void Layout(ILayoutContext context, double top, double height)
        {
            var x = context.Left;

            foreach (var key in Keys)
            {
                var width = context.KeySize * key.CalculateWidth();
                var y     = top + context.KeySize * key.CalculateTopOffset();

                key.Layout(context, x, y, width, height);

                x += width;
            }
        }
Ejemplo n.º 19
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            var start = Start.Resolve(layout, layoutContext.Options);
            var end   = End.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawLine(Point.Add(start, layout.Location), Point.Add(end, layout.Location), Thickness);
            }
            else
            {
                drawingContext.DrawLine(start, end, Thickness);
            }
        }
        public ILayoutAlgorithm <TVertex, TEdge, TGraph> CreateAlgorithm(string newAlgorithmType,
                                                                         ILayoutContext <TVertex, TEdge, TGraph> context, ILayoutParameters parameters)
        {
            var layoutContext = context as ContextualLayoutContext <TVertex, TEdge, TGraph>;

            switch (newAlgorithmType)
            {
            /*case "DoubleTree":
             *      return new DoubleTreeLayoutAlgorithm<TVertex, TEdge, TGraph>( layoutContext.Graph, layoutContext.Positions, layoutContext.Sizes, parameters as DoubleTreeLayoutParameters, layoutContext.SelectedVertex );
             * case "BalloonTree":
             *      return new BalloonTreeLayoutAlgorithm<TVertex, TEdge, TGraph>( layoutContext.Graph, layoutContext.Positions, layoutContext.Sizes, parameters as BalloonTreeLayoutParameters, layoutContext.SelectedVertex );*/
            default:
                return(null);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Checks whether the client can do the command, if it handles it</summary>
        /// <param name="commandTag">Command to be done</param>
        /// <returns>True iff client can do the command</returns>
        public virtual bool CanDoCommand(object commandTag)
        {
            bool canDo = false;

            ILayoutContext    layoutContext    = m_contextRegistry.GetActiveContext <ILayoutContext>();
            ISelectionContext selectionContext = m_contextRegistry.GetActiveContext <ISelectionContext>();

            if (layoutContext != null &&
                selectionContext != null)
            {
                BoundsSpecified itemFlags = GetBoundsSpecified(layoutContext, selectionContext.Selection);
                if (itemFlags != BoundsSpecified.None)
                {
                    switch ((StandardCommand)commandTag)
                    {
                    case StandardCommand.FormatAlignLefts:
                    case StandardCommand.FormatAlignCenters:     //horizontal middle
                    case StandardCommand.FormatAlignRights:
                        canDo = (itemFlags & BoundsSpecified.X) != 0;
                        break;

                    case StandardCommand.FormatAlignTops:
                    case StandardCommand.FormatAlignMiddles:     //vertical middle
                    case StandardCommand.FormatAlignBottoms:
                        canDo = (itemFlags & BoundsSpecified.Y) != 0;
                        break;

                    case StandardCommand.FormatMakeWidthEqual:
                        canDo = (itemFlags & BoundsSpecified.Width) != 0;
                        break;

                    case StandardCommand.FormatMakeHeightEqual:
                        canDo = (itemFlags & BoundsSpecified.Height) != 0;
                        break;

                    case StandardCommand.FormatMakeSizeEqual:
                        canDo = (itemFlags & BoundsSpecified.Size) == BoundsSpecified.Size;
                        break;
                    }
                }
            }

            return(canDo);
        }
        /// <inheritdoc />
        public ILayoutAlgorithm <TVertex, TEdge, TGraph> CreateAlgorithm(
            string algorithmType,
            ILayoutContext <TVertex, TEdge, TGraph> context,
            ILayoutParameters parameters)
        {
            if (algorithmType is null)
            {
                throw new ArgumentNullException(nameof(algorithmType));
            }
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var layoutContext = context as ContextualLayoutContext <TVertex, TEdge, TGraph>;

            if (layoutContext is null)
            {
                throw new ArgumentException(
                          $"Layout context must be a not null {nameof(ContextualLayoutContext<TVertex, TEdge, TGraph>)}.",
                          nameof(context));
            }

            switch (algorithmType)
            {
            case DoubleTreeAlgorithm:
                return(new DoubleTreeLayoutAlgorithm <TVertex, TEdge, TGraph>(
                           layoutContext.Graph,
                           layoutContext.Positions,
                           layoutContext.Sizes,
                           layoutContext.SelectedVertex,
                           parameters as DoubleTreeLayoutParameters));

            case BalloonTreeAlgorithm:
                return(new BalloonTreeLayoutAlgorithm <TVertex, TEdge, TGraph>(
                           layoutContext.Graph,
                           layoutContext.Positions,
                           layoutContext.SelectedVertex,
                           parameters as BalloonTreeLayoutParameters));
            }

            return(null);
        }
        /// <inheritdoc />
        public ILayoutAlgorithm <TVertex, TEdge, TGraph> CreateAlgorithm(
            string algorithmType,
            ILayoutContext <TVertex, TEdge, TGraph> context,
            ILayoutParameters parameters)
        {
            if (algorithmType is null)
            {
                throw new ArgumentNullException(nameof(algorithmType));
            }
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (context.Graph is null)
            {
                return(null);
            }

            return(CreateAlgorithmInternal(algorithmType, context, parameters));
        }
        internal override void Layout(ILayoutContext context, double left, double top, double width, double height)
        {
            // Collect together all the states.
            var availableStates = new HashSet <string>();

            foreach (var conditional in Conditionals)
            {
                var state = conditional.Name;
                if (state != null)
                {
                    availableStates.Add(state);
                }
            }

            foreach (var conditional in Conditionals)
            {
                if (conditional.Name == null)
                {
                    context.SetDefaultBinding(availableStates);
                }
                else
                {
                    context.SetNamedBinding(conditional.Name);
                }

                var x = left;
                foreach (var key in conditional.Keys)
                {
                    var keyWidth = context.KeySize * key.CalculateWidth();
                    var y        = top + context.KeySize * key.CalculateTopOffset();

                    key.Layout(context, x, y, keyWidth, height);

                    x += keyWidth;
                }

                context.ResetBinding();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Moves all items so that the center of their bounding box is at the given point</summary>
        /// <param name="layoutContext">Layout context containing item</param>
        /// <param name="items">Items to center</param>
        /// <param name="center">Centering point</param>
        public static void Center(this ILayoutContext layoutContext, IEnumerable <object> items, Point center)
        {
            Rect bounds;

            GetBounds(layoutContext, items, out bounds);

            // calculate offset
            Point offset = new Point(
                center.X - (bounds.Left + bounds.Width / 2),
                center.Y - (bounds.Top + bounds.Height / 2));

            foreach (object item in items)
            {
                Rect itemBounds;
                layoutContext.GetBounds(item, out itemBounds);

                Point topLeft = new Point(
                    itemBounds.Left + offset.X,
                    itemBounds.Top + offset.Y);

                layoutContext.SetBounds(item, itemBounds, new Rect(topLeft, itemBounds.Size), BoundsSpecified.Location);
            }
        }
Ejemplo n.º 26
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point location = Location.Resolve(layout, layoutContext.Options);
            var   drawRect = new Rect(location, new Size(Width, Height));

            if (layout.IsFlipped && layout.Orientation == Orientation.Horizontal)
            {
                drawRect = new Rect(drawRect.X - Width, drawRect.Y, Width, Height);
            }
            else if (layout.IsFlipped && layout.Orientation == Orientation.Vertical)
            {
                drawRect = new Rect(drawRect.X, drawRect.Y - Height, Width, Height);
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawRectangle(Point.Add(drawRect.TopLeft, layout.Location), drawRect.Size, StrokeThickness, Fill);
            }
            else
            {
                drawingContext.DrawRectangle(drawRect.TopLeft, drawRect.Size, StrokeThickness, Fill);
            }
        }
Ejemplo n.º 27
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            IList <IPathCommand> commands = Commands;

            if (layout.IsFlipped)
            {
                commands = new List <IPathCommand>(Commands.Count);
                foreach (IPathCommand command in Commands)
                {
                    commands.Add(command.Flip(layout.Orientation == Orientation.Horizontal));
                }
            }

            Point start = Start.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawPath(start, commands, Thickness, Fill);
            }
        }
 internal override void Layout(ILayoutContext context, double left, double top, double width, double height)
 {
     context.CreateActionKey(this, left, top, width, height);
 }
Ejemplo n.º 29
0
 private Size GetMaxSize(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Size size = new Size();
     foreach (object item in items)
     {
         Rectangle bounds;
         layoutContext.GetBounds(item, out bounds);
         size = new Size(
             Math.Max(size.Width, bounds.Width),
             Math.Max(size.Height, bounds.Height));
     }
     return size;
 }
Ejemplo n.º 30
0
        private BoundsSpecified GetBoundsSpecified(ILayoutContext layoutContext, IEnumerable<object> items)
        {
            BoundsSpecified itemFlags = BoundsSpecified.None;
            foreach (object item in items)
                itemFlags |= layoutContext.CanSetBounds(item);

            return itemFlags;
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Sets the height of all of the items to that of the tallest item</summary>
 /// <param name="items">Items to resize</param>
 /// <param name="layoutContext">Layout context of items to resize</param>
 public virtual void MakeHeightEqual(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Size maxSize = GetMaxSize(items, layoutContext);
     foreach (object item in items)
     {
         Rectangle bounds;
         layoutContext.GetBounds(item, out bounds);
         bounds.Height = maxSize.Height;
         layoutContext.SetBounds(item, bounds, BoundsSpecified.Height);
     }
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Moves the items up or down so that their bounding box centers all have the same
 /// Y value, which is the Y value of the center of the bounding box around the items'
 /// original positions</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignMiddles(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     int boundsMiddle = (bounds.Top + bounds.Bottom) / 2;
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.Y = boundsMiddle - itemBounds.Height / 2;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.Y);
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Moves the items left or right so that their bounding box centers all have the same
 /// X value, which is the X value of the center of the bounding box around the items'
 /// original positions</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignCenters(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     int boundsCenter = (bounds.Left + bounds.Right) / 2;
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.X = boundsCenter - itemBounds.Width / 2;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
     }
 }
        ILayoutAlgorithm <TVertex, TEdge, TGraph> ILayoutAlgorithmFactory <TVertex, TEdge, TGraph> .CreateAlgorithm(string newAlgorithmType, ILayoutContext <TVertex, TEdge, TGraph> context, ILayoutParameters parameters)
        {
            Contract.Requires(newAlgorithmType != null);
            Contract.Requires(context as ContextualLayoutContext <TVertex, TEdge, TGraph> != null);

            var laf = (ILayoutAlgorithmFactory <TVertex, TEdge, TGraph>) this;

            Contract.Requires(laf.AlgorithmTypes.Contains(newAlgorithmType));

            return(default(ILayoutAlgorithm <TVertex, TEdge, TGraph>));
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Does the command</summary>
        /// <param name="commandTag">Command to be done</param>
        public virtual void DoCommand(object commandTag)
        {
            ISelectionContext selectionContext = m_contextRegistry.GetActiveContext <ISelectionContext>();
            ILayoutContext    layoutContext    = m_contextRegistry.GetActiveContext <ILayoutContext>();

            if (layoutContext != null &&
                selectionContext != null)
            {
                IEnumerable <object> items     = selectionContext.Selection;
                BoundsSpecified      itemFlags = GetBoundsSpecified(layoutContext, selectionContext.Selection);
                if (itemFlags != BoundsSpecified.None)
                {
                    string commandName = null;
                    switch ((StandardCommand)commandTag)
                    {
                    case StandardCommand.FormatAlignLefts:
                        commandName = CommandInfo.FormatAlignLefts.MenuText;
                        break;

                    case StandardCommand.FormatAlignRights:
                        commandName = CommandInfo.FormatAlignRights.MenuText;
                        break;

                    case StandardCommand.FormatAlignCenters:     //horizontal middle
                        commandName = CommandInfo.FormatAlignCenters.MenuText;
                        break;

                    case StandardCommand.FormatAlignTops:     //horizontal middle
                        commandName = CommandInfo.FormatAlignTops.MenuText;
                        break;

                    case StandardCommand.FormatAlignBottoms:
                        commandName = CommandInfo.FormatAlignBottoms.MenuText;
                        break;

                    case StandardCommand.FormatAlignMiddles:     //vertical middle
                        commandName = CommandInfo.FormatAlignMiddles.MenuText;
                        break;

                    case StandardCommand.FormatMakeWidthEqual:
                        commandName = CommandInfo.FormatMakeWidthEqual.MenuText;
                        break;

                    case StandardCommand.FormatMakeHeightEqual:
                        commandName = CommandInfo.FormatMakeHeightEqual.MenuText;
                        break;

                    case StandardCommand.FormatMakeSizeEqual:
                        commandName = CommandInfo.FormatMakeSizeEqual.MenuText;
                        break;
                    }

                    ITransactionContext transactionContext = m_contextRegistry.GetActiveContext <ITransactionContext>();
                    transactionContext.DoTransaction(delegate
                    {
                        switch ((StandardCommand)commandTag)
                        {
                        case StandardCommand.FormatAlignLefts:
                            AlignLefts(items, layoutContext);
                            break;

                        case StandardCommand.FormatAlignRights:
                            AlignRights(items, layoutContext);
                            break;

                        case StandardCommand.FormatAlignCenters:         // horizontal center
                            AlignCenters(items, layoutContext);
                            break;

                        case StandardCommand.FormatAlignTops:
                            AlignTops(items, layoutContext);
                            break;

                        case StandardCommand.FormatAlignBottoms:
                            AlignBottoms(items, layoutContext);
                            break;

                        case StandardCommand.FormatAlignMiddles:         // vertical center
                            AlignMiddles(items, layoutContext);
                            break;

                        case StandardCommand.FormatMakeWidthEqual:
                            MakeWidthEqual(items, layoutContext);
                            break;

                        case StandardCommand.FormatMakeHeightEqual:
                            MakeHeightEqual(items, layoutContext);
                            break;

                        case StandardCommand.FormatMakeSizeEqual:
                            MakeSizeEqual(items, layoutContext);
                            break;
                        }
                    },
                                                     commandName);
                }
            }
        }
Ejemplo n.º 36
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point renderLocation = Location.Resolve(layout, layoutContext.Options);

            TextAlignment tempAlignment = Alignment;
            var           flipType      = layout.GetFlipType();

            if ((flipType & FlipType.Horizontal) == FlipType.Horizontal)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.BottomRight;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.CentreLeft:
                    tempAlignment = TextAlignment.CentreRight;
                    break;

                case TextAlignment.CentreRight:
                    tempAlignment = TextAlignment.CentreLeft;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.TopLeft;
                    break;
                }
            }

            if ((flipType & FlipType.Vertical) == FlipType.Vertical)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomCentre:
                    tempAlignment = TextAlignment.TopCentre;
                    break;

                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.TopLeft;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopCentre:
                    tempAlignment = TextAlignment.BottomCentre;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.BottomRight;
                    break;
                }
            }

            List <TextRun> renderTextRuns = new List <TextRun>(TextRuns.Count);

            // Build runs
            foreach (TextRun run in TextRuns)
            {
                // Resolve value
                string renderValue;
                if (run.Text.StartsWith("$"))
                {
                    renderValue = layoutContext.GetFormattedVariable(run.Text);
                }
                else
                {
                    renderValue = run.Text;
                }

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\\[uU]([0-9A-F]{4})");
                renderValue = regex.Replace(renderValue, match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString());

                renderTextRuns.Add(new TextRun(renderValue, run.Formatting));
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawText(Point.Add(renderLocation, layout.Location), tempAlignment, (int)Rotation * 90, renderTextRuns);
            }
            else
            {
                drawingContext.DrawText(renderLocation, tempAlignment, (int)Rotation * 90, renderTextRuns);
            }
        }
        public ILayoutAlgorithm <TVertex, TEdge, TGraph> CreateAlgorithm(string newAlgorithmType, ILayoutContext <TVertex, TEdge, TGraph> context, ILayoutParameters parameters)
        {
            if (context == null || context.Graph == null)
            {
                return(null);
            }

            if (context.Mode == LayoutMode.Simple)
            {
                switch (newAlgorithmType)
                {
                case "Tree":
                    return(new SimpleTreeLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                                  context.Sizes,
                                                                                  parameters as SimpleTreeLayoutParameters));

                case "Circular":
                    return(new CircularLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                                context.Sizes,
                                                                                parameters as CircularLayoutParameters));

                case "FR":
                    return(new FRLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                          parameters as FRLayoutParametersBase));

                case "BoundedFR":
                    return(new FRLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                          parameters as BoundedFRLayoutParameters));

                case "KK":
                    return(new KKLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                          parameters as KKLayoutParameters));

                case "ISOM":
                    return(new ISOMLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                            parameters as ISOMLayoutParameters));

                case "LinLog":
                    return(new LinLogLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Positions,
                                                                              parameters as LinLogLayoutParameters));

                case "EfficientSugiyama":
                    return(new EfficientSugiyamaLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph,
                                                                                         parameters as EfficientSugiyamaLayoutParameters,
                                                                                         context.Positions,
                                                                                         context.Sizes));

                case "Sugiyama":
                    return(new SugiyamaLayoutAlgorithm <TVertex, TEdge, TGraph>(context.Graph, context.Sizes,
                                                                                context.Positions,
                                                                                parameters as
                                                                                SugiyamaLayoutParameters,
                                                                                e => (e is TypedEdge <TVertex>
                                                                                      ?(e as TypedEdge <TVertex>).Type
                                                                                      : EdgeTypes.Hierarchical)));

                case "CompoundFDP":
                    return(new CompoundFDPLayoutAlgorithm <TVertex, TEdge, TGraph>(
                               context.Graph,
                               context.Sizes,
                               new Dictionary <TVertex, Thickness>(),
                               new Dictionary <TVertex, CompoundVertexInnerLayoutType>(),
                               context.Positions,
                               parameters as CompoundFDPLayoutParameters));

                default:
                    return(null);
                }
            }
            else if (context.Mode == LayoutMode.Compound)
            {
                var compoundContext = context as ICompoundLayoutContext <TVertex, TEdge, TGraph>;
                switch (newAlgorithmType)
                {
                case "CompoundFDP":
                    return(new CompoundFDPLayoutAlgorithm <TVertex, TEdge, TGraph>(
                               compoundContext.Graph,
                               compoundContext.Sizes,
                               compoundContext.VertexBorders,
                               compoundContext.LayoutTypes,
                               compoundContext.Positions,
                               parameters as CompoundFDPLayoutParameters));

                default:
                    return(null);
                }
            }
            return(null);
        }