Exemplo n.º 1
0
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private static RenderDataCache CreateRenderDataCache(IRenderContext context, ILabel edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

            bool selected = selection != null && selection.IsSelected(edge);

            return(new RenderDataCache(selected));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private RenderDataCache CreateRenderDataCache(IRenderContext context, IEdge edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

            bool selected = selection != null && selection.IsSelected(edge);

            return(new RenderDataCache(PathThickness, selected, GetPath(edge), Arrows));
        }
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private RenderDataCache CreateRenderDataCache(IRenderContext context, IEdge edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

            bool selected = selection != null && selection.IsSelected(edge);

            //////////////// New in this sample ////////////////
            // The RenderDataCache now also holds information about the bridges (the obstacle hash)
            // so the edge will be re-rendered after the bridges have changed
            // Note that the cached path is the edge path *without* bridges
            return(new RenderDataCache(PathThickness, selected, GetPath(edge), Arrows, GetObstacleHash(context)));
        }
        /// <summary>
        /// Collect all <see cref="IGraphSelection.SelectedNodes">selected nodes</see> and their descendents.
        /// </summary>
        private IList <INode> CollectReshapeNodes(IGraph graph, IGraphSelection selection)
        {
            var nodes = new HashSet <INode>();

            foreach (var node in selection.SelectedNodes)
            {
                if (nodes.Add(node) && graph.IsGroupNode(node))
                {
                    foreach (var descendant in graph.GetGroupingSupport().GetDescendants(node))
                    {
                        nodes.Add(descendant);
                    }
                }
            }
            return(nodes.ToList());
        }
 public DemoEdgeStyleRenderer(IGraphSelection selection, bool highlight)
 {
     this.selection = selection;
     this.highlight = highlight;
 }
        protected override VisualGroup CreateVisual(IRenderContext context, ILabel label)
        {
            // Updates the dummy label which is internally used for rendering with the properties of the given label.
            UpdateDummyLabel(context, label);

            // creates the container for the visual and sets a transform for view coordinates
            var container       = new VisualGroup();
            var toViewTransform = context.WorldTransform.Clone();

            toViewTransform.Invert();
            // ReSharper disable once PossibleUnintendedReferenceComparison
            if (container.Transform != toViewTransform)
            {
                container.Transform = toViewTransform;
            }

            var creator = InnerLabelStyle.Renderer.GetVisualCreator(dummyLabel, InnerLabelStyle);

            // create a new IRenderContext with a zoom of 1
            // TODO: Projections
            var innerContext = new RenderContext(context.Graphics, context.CanvasControl)
            {
                ViewTransform = context.ViewTransform, WorldTransform = context.WorldTransform, Zoom = 1
            };

            //The wrapped style should always think it's rendering with zoom level 1
            var visual = creator.CreateVisual(innerContext);

            if (visual == null)
            {
                return(container);
            }

            // add the created visual to the container
            container.Children.Add(visual);


            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

            bool selected = selection != null && selection.IsSelected(label);

            // if the label is selected, add the selection visualization, too.

            if (selected)
            {
                //The selection descriptor performs its own calculation in the view coordinate system, so
                //the size and the position of the visualization would be wrong and need to be converted back into world
                //coordinates
                var layout          = dummyLabel.GetLayout();
                var p1              = context.CanvasControl.ToWorldCoordinates(layout.GetAnchorLocation());
                var selectionLayout = new OrientedRectangle
                {
                    Anchor = p1,
                    Width  = layout.Width / context.Zoom,
                    Height = layout.Height / context.Zoom
                };

                selectionLayout.SetUpVector(layout.UpX, layout.UpY);
                var selectionVisual = new OrientedRectangleIndicatorInstaller().Template;
                container.Children.Add(selectionVisual);
            }
            return(container);
        }