コード例 #1
0
        public override IVisual CreateVisual(IRenderContext context)
        {
            VisualGroup container = new VisualGroup();

            var bounds     = Bounds;
            var width      = bounds.Width;
            var height     = bounds.Height;
            var cornerSize = Math.Min(width, height) * 0.4;

            var path = new GeneralPath();

            path.MoveTo(0, 0);
            path.LineTo(width - cornerSize, 0);
            path.LineTo(width, cornerSize);
            path.LineTo(width, height);
            path.LineTo(0, height);
            path.Close();
            container.Add(new GeneralPathVisual(path)
            {
                Brush = Brush, Pen = Pen
            });

            path = new GeneralPath();
            path.MoveTo(width - cornerSize, 0);
            path.LineTo(width - cornerSize, cornerSize);
            path.LineTo(width, cornerSize);
            container.Add(new GeneralPathVisual(path)
            {
                Brush = null, Pen = Pen
            });

            container.Transform = new Matrix(1, 0, 0, 1, (float)Bounds.X, (float)Bounds.Y);
            return(container);
        }
コード例 #2
0
        protected override Visual CreateVisual(IRenderContext context, INode node)
        {
            UpdateIcon(node);
            if (Icon == null)
            {
                return(null);
            }

            var bounds = node.Layout.ToRectD();

            Icon.SetBounds(new RectD(PointD.Origin, bounds.ToSizeD()));
            var visual = Icon.CreateVisual(context);

            var container = new VisualGroup();

            if (visual != null)
            {
                container.Add(visual);
            }
            container.SetCanvasArrangeRect(new Rect(bounds.TopLeft, bounds.BottomRight));
            container.SetRenderDataCache(new IconData {
                ModCount = ModCount, Bounds = bounds
            });

            return(container);
        }
コード例 #3
0
        public override Visual CreateVisual(IRenderContext context)
        {
            VisualGroup container = new VisualGroup();
            var         bounds    = Bounds;
            var         width     = bounds.Width;
            var         height    = bounds.Height;

            var path = new GeneralPath();

            path.MoveTo(0, TopLeftRadius);
            path.QuadTo(0, 0, TopLeftRadius, 0);
            path.LineTo(width - TopRightRadius, 0);
            path.QuadTo(width, 0, width, TopRightRadius);
            path.LineTo(width, height - BottomRightRadius);
            path.QuadTo(width, height, width - BottomRightRadius, height);
            path.LineTo(BottomLeftRadius, height);
            path.QuadTo(0, height, 0, height - BottomRightRadius);
            path.Close();

            var pathVisual = path.CreatePath(Brush, Pen, new Matrix2D(), FillMode.Always);

            container.Add(pathVisual);

            container.SetRenderDataCache(new PathIconState(width, height, Pen, Brush));
            container.SetCanvasArrangeRect(bounds.ToRectD());
            return(container);
        }
コード例 #4
0
        public override Visual CreateVisual(IRenderContext context)
        {
            VisualGroup container = new VisualGroup();

            var bounds     = Bounds;
            var width      = bounds.Width;
            var height     = bounds.Height;
            var cornerSize = Math.Min(width, height) * 0.4;

            var path = new GeneralPath();

            path.MoveTo(0, 0);
            path.LineTo(width - cornerSize, 0);
            path.LineTo(width, cornerSize);
            path.LineTo(width, height);
            path.LineTo(0, height);
            path.Close();
            container.Add(path.CreatePath(Brush, Pen, new Matrix2D(), FillMode.Always));

            path = new GeneralPath();
            path.MoveTo(width - cornerSize, 0);
            path.LineTo(width - cornerSize, cornerSize);
            path.LineTo(width, cornerSize);
            container.Add(path.CreatePath(null, Pen, new Matrix2D(), FillMode.Never));

            container.SetRenderDataCache(new PathIconState(width, height, Pen, Brush));
            container.SetCanvasArrangeRect(bounds.ToRectD());
            return(container);
        }
コード例 #5
0
        public override Visual UpdateVisual(IRenderContext context, Visual oldVisual)
        {
            VisualGroup container = oldVisual as VisualGroup;

            if (container == null || container.Children.Count != 1)
            {
                return(CreateVisual(context));
            }

            var path      = container.Children.ElementAt(0) as Path;
            var lastState = container.GetRenderDataCache <PathIconState>();

            if (path == null || lastState == null || lastState.width != Bounds.Width || lastState.height != Bounds.Height)
            {
                return(CreateVisual(context));
            }

            if (!Equals(lastState.pen, Pen))
            {
                path.SetPen(Pen);
            }
            if (!Equals(lastState.brush, Brush))
            {
                path.Fill = Brush;
            }

            // arrange visual
            container.SetCanvasArrangeRect(Bounds.ToRectD());
            return(container);
        }
コード例 #6
0
        public override Visual UpdateVisual(IRenderContext context, Visual oldVisual)
        {
            VisualGroup container = oldVisual as VisualGroup;

            if (container == null || container.Children.Count != 1)
            {
                return(CreateVisual(context));
            }
            var rectangle = container.Children.ElementAt(0) as Rectangle;
            var lastState = container.GetRenderDataCache <PathIconState>();

            if (rectangle == null || lastState == null)
            {
                container.Children.Clear();
                return(CreateVisual(context));
            }

            if (!lastState.Equals(Bounds.Width, Bounds.Height, Pen, Brush))
            {
                UpdateRectangle(rectangle);
                container.SetRenderDataCache(new PathIconState(Bounds.Width, Bounds.Height, Pen, Brush));
            }

            // arrange
            container.SetCanvasArrangeRect(Bounds.ToRectD());
            return(container);
        }
コード例 #7
0
        private void UpdateChildren()
        {
            VisualGroup contentHost = GetTemplateChild("visualGroup") as VisualGroup;

            if (contentHost != null)
            {
                var oldVisual = contentHost.Children.Count == 1 ? contentHost.Children.ElementAt(0) : null;
                var newVisual = GetVisual();


                if (newVisual == null)
                {
                    if (oldVisual != null)
                    {
                        contentHost.Children.Clear();
                    }
                }
                else
                {
                    if (oldVisual != null)
                    {
                        if (!newVisual.Equals(oldVisual))
                        {
                            contentHost.Children[0] = newVisual;
                        }
                    }
                    else
                    {
                        contentHost.Add(newVisual);
                    }
                }
            }
        }
コード例 #8
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            INode listBoxNode = value as INode;

            if (listBoxNode != null)
            {
                graphControl.Graph.Clear();

                var    size        = FlowChartNodeStyle.GetNodeTypeSize(listBoxNode);
                var    node        = graphControl.Graph.CreateNode(new RectD(0, 0, size.Width, size.Height), listBoxNode.Style, listBoxNode.Tag);
                double labelHeight = 0;
                foreach (var label in listBoxNode.Labels)
                {
                    graphControl.Graph.AddLabel(node, label.Text, label.LayoutParameter, label.Style, label.PreferredSize, label.Tag);
                    labelHeight = Math.Max(labelHeight, label.GetLayout().Height);
                }
                graphControl.FitGraphBounds(new InsetsD(5));
                ContextConfigurator cc             = new ContextConfigurator(graphControl.ContentRect);
                var       renderContext            = cc.CreateRenderContext(graphControl);
                Transform transform                = cc.CreateWorldToIntermediateTransform();
                System.Windows.Media.Geometry clip = cc.CreateClip();
                var visualContent = graphControl.ExportContent(renderContext);

                VisualGroup container = new VisualGroup()
                {
                    Transform = transform, Clip = clip, Children = { visualContent }
                };
                VisualBrush brush = new VisualBrush(container);
                return(new DrawingImage(new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, size.Width, size.Height + labelHeight)))));
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var graph = value as IGraph;

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

            graphControl.Graph = graph;
            graphControl.FitGraphBounds();
            var size = graphControl.ContentRect;
            var cc   = new ContextConfigurator(graphControl.ContentRect);

            cc.Scale = Math.Min(cc.CalculateScaleForWidth(size.Width), cc.CalculateScaleForHeight(size.Height));

            var       renderContext = cc.CreateRenderContext(graphControl);
            Transform transform     = cc.CreateWorldToIntermediateTransform();
            Geometry  clip          = cc.CreateClip();

            var visualContent = graphControl.ExportContent(renderContext);
            var container     = new VisualGroup {
                Transform = transform,
                Clip      = clip,
                Children  = { visualContent }
            };
            var brush = new VisualBrush(container);

            return(new DrawingImage(new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, size.Width, size.Height)))));
        }
コード例 #10
0
            /// <inheritdoc/>
            public Visual CreateVisual(IRenderContext context)
            {
                var container     = new VisualGroup();
                var delegateStyle = GetCurrentStyle(label, labelStyle);

                container.Add(delegateStyle.Renderer.GetVisualCreator(label, delegateStyle).CreateVisual(context));
                container.SetRenderDataCache(CreateRenderData());

                return(container);
            }
コード例 #11
0
        /// <summary>
        /// This method updates or replaces a previously created <see cref="IVisual"/> for inclusion
        /// in the <see cref="IRenderContext"/>.
        /// </summary>
        /// <param name="context">The context that describes where the visual will be used in.</param>
        /// <param name="oldVisual">The visual instance that had been returned the last time the <see cref="IVisualCreator.CreateVisual"/>
        /// method was called on this instance.</param>
        /// <returns>
        ///     <paramref name="oldVisual"/>, if this instance modified the visual, or a new visual that should replace the
        /// existing one in the canvas object visual tree.
        /// </returns>
        /// <remarks>
        /// The <see cref="CanvasControl"/> uses this method to give implementations a chance to
        /// update an existing Visual that has previously been created by the same instance during a call
        /// to <see cref="IVisualCreator.CreateVisual"/>. Implementation may update the <paramref name="oldVisual"/>
        /// and return that same reference, or create a new visual and return the new instance or <see langword="null"/>.
        /// </remarks>
        /// <seealso cref="IVisualCreator.CreateVisual"/>
        /// <seealso cref="ICanvasObjectDescriptor"/>
        /// <seealso cref="CanvasControl"/>
        public IVisual UpdateVisual(IRenderContext context, IVisual oldVisual)
        {
            VisualGroup p = oldVisual as VisualGroup;

            if (p != null)
            {
                p.Transform = (Matrix) new Matrix2D(direction.X, -direction.Y, +direction.Y, direction.X, anchor.X, anchor.Y);
                return(p);
            }
            return(((IVisualCreator)this).CreateVisual(context));
        }
コード例 #12
0
        /// <summary>
        /// This method is called by the framework to create a <see cref="IVisual"/>
        /// that will be included into the <see cref="IRenderContext"/>.
        /// </summary>
        /// <param name="context">The context that describes where the visual will be used.</param>
        /// <returns>
        /// The arrow visual to include in the canvas object visual tree./>.
        /// </returns>
        /// <seealso cref="UpdateVisual"/>
        IVisual IVisualCreator.CreateVisual(IRenderContext context)
        {
            icon.SetBounds(new RectD(-Bounds.Width, -Bounds.Height / 2, Bounds.Width, Bounds.Height));
            var visualGroup = new VisualGroup();

            visualGroup.Add(icon.CreateVisual(context));

            // Rotate arrow and move it to correct position
            visualGroup.Transform = new Matrix((float)direction.X, (float)direction.Y, (float)-direction.Y, (float)direction.X, (float)anchor.X, (float)anchor.Y);

            return(visualGroup);
        }
コード例 #13
0
        private static void UpdateChildVisual(IRenderContext context, VisualGroup container, int index, IVisualCreator icon)
        {
            var oldPathVisual = container.Children[index];
            var newPathVisual = icon.UpdateVisual(context, oldPathVisual);

            if (!oldPathVisual.Equals(newPathVisual))
            {
                newPathVisual = newPathVisual ?? new VisualGroup();
                container.Children.Remove(oldPathVisual);
                container.Children.Insert(index, newPathVisual);
            }
        }
コード例 #14
0
        public Visual UpdateVisual(IRenderContext context, Visual oldVisual)
        {
            VisualGroup cc = oldVisual as VisualGroup;

            if (cc == null)
            {
                cc = new VisualGroup();
            }

            var y     = bounds.Top;
            int count = 0;

            foreach (var divider in dividers)
            {
                Rectangle rectangle;
                if (cc.Children.Count <= count)
                {
                    cc.Children.Add(rectangle = new Rectangle());
                }
                else
                {
                    rectangle = (Rectangle)cc.Children[count];
                }
                float bottom = divider;
                rectangle.SetCanvasArrangeRect(new Rect(bounds.Left, y, bounds.Width, bottom - y));
                rectangle.Fill = count % 2 == 1 ? lightBrush : darkBrush;
                y = bottom;
                count++;
            }

            {
                Rectangle rectangle;
                if (cc.Children.Count <= count)
                {
                    cc.Children.Add(rectangle = new Rectangle());
                }
                else
                {
                    rectangle = (Rectangle)cc.Children[count];
                }
                rectangle.SetCanvasArrangeRect(new Rect(bounds.Left, y, bounds.Width, bounds.Bottom - y));
                rectangle.Fill = count % 2 == 1 ? lightBrush : darkBrush;
                count++;
            }

            while (cc.Children.Count > count)
            {
                cc.Children.RemoveAt(cc.Children.Count - 1);
            }
            return(cc);
        }
コード例 #15
0
        public override Visual CreateVisual(IRenderContext context)
        {
            VisualGroup container = new VisualGroup();

            var rectangle = new Rectangle {
                RadiusX = CornerRadius, RadiusY = CornerRadius
            };

            UpdateRectangle(rectangle);
            container.Add(rectangle);

            container.SetRenderDataCache(new PathIconState(Bounds.Width, Bounds.Height, Pen, Brush));
            container.SetCanvasArrangeRect(Bounds.ToRectD());
            return(container);
        }
コード例 #16
0
        public override Visual CreateVisual(IRenderContext context)
        {
            VisualGroup container = new VisualGroup();

            var matrix2D = new Matrix2D();

            matrix2D.Scale(Math.Max(0, Bounds.Width), Math.Max(0, Bounds.Height));

            Path visual = Path.CreatePath(Brush, Pen, matrix2D, FillMode.FillClosedFigures);

            container.Add(visual);

            container.SetRenderDataCache(new PathIconState(Bounds.Width, Bounds.Height, Pen, Brush));
            container.SetCanvasArrangeRect(Bounds.ToRectD());
            return(container);
        }
コード例 #17
0
            public Visual CreateVisual(IRenderContext context)
            {
                var canvasControl = context.CanvasControl as GraphControl;

                // Instantiate the GraphControl displaying the zoomed graph.
                var lensGraphControl = new GraphControl
                {
                    // Re-use the same graph, selection, and projection
                    Graph      = canvasControl.Graph,
                    Selection  = canvasControl.Selection,
                    Projection = canvasControl.Projection,

                    // Disable interaction and scrollbars
                    MouseWheelBehavior        = MouseWheelBehaviors.None,
                    AutoDrag                  = false,
                    IsHitTestVisible          = false,
                    HorizontalScrollBarPolicy = ScrollBarVisibility.Hidden,
                    VerticalScrollBarPolicy   = ScrollBarVisibility.Hidden,
                    // This is only necessary to show handles in the zoomed graph. Remove if not needed
                    InputMode = new GraphEditorInputMode(),

                    // Clip the overlay to circular
                    Clip       = new EllipseGeometry(),
                    Background = Brushes.White
                };

                // Arrange both the GraphControl and an outline
                var grid = new Grid
                {
                    Children =
                    {
                        lensGraphControl,
                        new Ellipse {
                            Stroke = Brushes.Gray,StrokeThickness           = 2
                        }
                    }
                };

                // VisualGroup for easier handling
                var visualGroup = new VisualGroup {
                    Children = { grid }
                };

                // Update all properties to their current values and ensure that the overlay is rendered where it should
                return(UpdateVisual(context, visualGroup));
            }
コード例 #18
0
            /// <inheritdoc/>
            public virtual Visual CreateVisual(IRenderContext context)
            {
                var container = new VisualGroup();

                if (style.Type != EdgeType.Conversation)
                {
                    container.Add(delegateRenderer.GetVisualCreator(this.edge, this.style.delegateStyle).CreateVisual(context));
                }
                else
                {
                    container.Add(delegateRenderer.GetVisualCreator(this.edge, this.style.delegateStyle).CreateVisual(context));
                    var oldPen = style.delegateStyle.Pen;
                    style.delegateStyle.Pen = style.innerPen;
                    container.Add(delegateRenderer.GetVisualCreator(this.edge, this.style.delegateStyle).CreateVisual(context));
                    style.delegateStyle.Pen = oldPen;
                }
                container.SetRenderDataCache(style.Type);
                return(container);
            }
コード例 #19
0
        public override IVisual CreateVisual(IRenderContext context)
        {
            if (Bounds == null)
            {
                return(null);
            }

            var container = new VisualGroup();

            double offset = 0;

            foreach (var pathIcon in icons)
            {
                pathIcon.SetBounds(new RectD(offset, 0, innerIconSize.Width, innerIconSize.Height));
                container.Add(pathIcon.CreateVisual(context));
                offset += innerIconSize.Width + gap;
            }
            container.Transform = new Matrix(1, 0, 0, 1, (float)Bounds.X, (float)Bounds.Y);

            return(container);
        }
コード例 #20
0
        public override Visual CreateVisual(IRenderContext context)
        {
            if (Bounds == null)
            {
                return(null);
            }
            var container = new VisualGroup();

            var iconBounds = new RectD(PointD.Origin, Bounds.ToSizeD());

            foreach (var icon in icons)
            {
                icon.SetBounds(iconBounds);
                container.Add(icon.CreateVisual(context));
            }

            container.SetCanvasArrangeRect(Bounds.ToRectD());
            container.SetRenderDataCache(Bounds.ToRectD());

            return(container);
        }
コード例 #21
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            INode listBoxNode = value as INode;

            if (listBoxNode == null)
            {
                return(null);
            }
            graphControl.Graph.Clear();

            var node = graphControl.Graph.CreateNode(listBoxNode.Layout.ToRectD(), listBoxNode.Style, listBoxNode.Tag);

            foreach (var label in listBoxNode.Labels)
            {
                graphControl.Graph.AddLabel(node, label.Text, label.LayoutParameter,
                                            label.Style, label.PreferredSize, label.Tag);
            }
            graphControl.FitGraphBounds();
            ContextConfigurator cc = new ContextConfigurator(graphControl.ContentRect);

            cc.Scale = Math.Min(cc.CalculateScaleForWidth(size.Width), cc.CalculateScaleForHeight(size.Height));

            var       renderContext = cc.CreateRenderContext(graphControl);
            Transform transform     = cc.CreateWorldToIntermediateTransform();

            System.Windows.Media.Geometry clip = cc.CreateClip();

            var         visualContent = graphControl.ExportContent(renderContext);
            VisualGroup container     = new VisualGroup
            {
                Transform = transform,
                Clip      = clip,
                Children  = { visualContent }
            };
            VisualBrush brush = new VisualBrush(container);

            return
                (new DrawingImage(new GeometryDrawing(brush, null,
                                                      new RectangleGeometry(new Rect(0, 0, size.Width, size.Height)))));
        }
コード例 #22
0
        public override Visual CreateVisual(IRenderContext context)
        {
            if (Bounds == null)
            {
                return(null);
            }

            var container = new VisualGroup();

            double offset = 0;

            foreach (var pathIcon in icons)
            {
                pathIcon.SetBounds(new RectD(offset, 0, innerIconSize.Width, innerIconSize.Height));
                container.Add(pathIcon.CreateVisual(context));
                offset += innerIconSize.Width + gap;
            }
            container.SetCanvasArrangeRect(Bounds.ToRectD());
            container.SetRenderDataCache(Bounds.GetTopLeft());

            return(container);
        }
コード例 #23
0
        protected override Visual CreateVisual(IRenderContext context, INode node)
        {
            var bounds    = node.Layout.ToRectD();
            var container = new VisualGroup();

            // task band
            var taskBandContainer = new VisualGroup();
            var bandIcon          = CreateTaskBandIcon(node);

            bandIcon.SetBounds(GetRelativeTaskNameBandBounds(node));
            taskBandContainer.Add(bandIcon.CreateVisual(context));
            taskBandContainer.SetRenderDataCache(bandIcon);
            container.Children.Add(taskBandContainer);

            var tpi = new List <IIcon>();
            // top participants
            double topOffset = 0;
            bool   first     = true;

            foreach (Participant participant in topParticipants)
            {
                var participantIcon = CreateParticipantIcon(participant, true, first);
                tpi.Add(participantIcon);
                var height = participant.GetSize();
                participantIcon.SetBounds(new RectD(0, topOffset, bounds.Width, height));
                container.Add(participantIcon.CreateVisual(context));
                topOffset += height;
                first      = false;
            }

            var bpi = new List <IIcon>();
            // bottom participants
            double bottomOffset = bounds.Height;

            first = true;
            foreach (Participant participant in bottomParticipants)
            {
                var participantIcon = CreateParticipantIcon(participant, false, first);
                bpi.Add(participantIcon);
                var height = participant.GetSize();
                bottomOffset -= height;
                participantIcon.SetBounds(new RectD(0, bottomOffset, bounds.Width, height));
                container.Add(participantIcon.CreateVisual(context));
                first = false;
            }

            // outline
            outlineIcon.SetBounds(new RectD(PointD.Origin, bounds.Size));
            container.Add(outlineIcon.CreateVisual(context));

            // messages
            if (InitiatingMessage)
            {
                UpdateInitiatingMessageIcon();
                var initiatingMessageIcon = InitiatingAtTop ? topInitiatingMessageIcon : bottomInitiatingMessageIcon;
                initiatingMessageIcon.SetBounds(new RectD(0, 0, bounds.Width, bounds.Height));
                container.Add(initiatingMessageIcon.CreateVisual(context));
            }
            if (ResponseMessage)
            {
                UpdateResponseMessageIcon();
                var responseMessageIcon = InitiatingAtTop ? bottomResponseMessageIcon : topResponseMessageIcon;
                responseMessageIcon.SetBounds(new RectD(0, 0, bounds.Width, bounds.Height));
                container.Add(responseMessageIcon.CreateVisual(context));
            }

            container.SetCanvasArrangeRect(new Rect(bounds.TopLeft, bounds.Size));
            container.SetRenderDataCache(new ChoreographyRenderData(bounds, ModCount + topParticipants.ModCount + bottomParticipants.ModCount)
            {
                TopParticipantIcons = tpi, BottomParticipantIcons = bpi
            });
            return(container);
        }