Beispiel #1
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            base.ElementAdded(e);

            DiagramHasLinkShapes con = e.ModelElement as DiagramHasLinkShapes;

            if (con != null)
            {
                LinkShape linkShape = con.LinkShape;
                Diagram   diagram   = con.Diagram;

                if (linkShape != null && diagram != null)
                {
                    if (linkShape.IsDeleted)
                    {
                        return;
                    }

                    if (linkShape.SourceAnchor == null || linkShape.TargetAnchor == null)
                    {
                        throw new InvalidOperationException("LinkShape needs to have from and to anchors.");
                    }

                    if (linkShape.SourceAnchor.FromShape == null || linkShape.TargetAnchor.ToShape == null)
                    {
                        throw new InvalidOperationException("LinkShape anchors need to have from and to shape.");
                    }

                    diagram.AddToShapeMapping(linkShape);

                    if (linkShape.EdgePoints.Count == 0)
                    {
                        linkShape.Layout(FixedGeometryPoints.None);
                    }
                    else
                    {
                        linkShape.UpdateLinkPlacement();

                        if (!con.Store.InSerializationTransaction)
                        {
                            linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the position of a link shape.
        /// </summary>
        /// <param name="linkShape">Link shape.</param>
        /// <param name="shape">Graphical dependency shape.</param>
        /// <param name="mainShape">Node shape.</param>
        /// <param name="bSource">True if graphical dependency shape is source.</param>
        public void UpdateLinkShapePosition(LinkShape linkShape, GraphicalDependencyShape shape, NodeShape mainShape, bool bSource)
        {
            if (linkShape == null)
            {
                return;
            }

            if (bSource)
            {
                linkShape.SourceAnchor.AbsoluteLocation = new PointD(shape.AbsoluteBounds.Right + LinkAnchorMargin, shape.AbsoluteBounds.Center.Y);
                linkShape.TargetAnchor.AbsoluteLocation = new PointD(mainShape.AbsoluteBounds.Left - LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y);
                linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
            }
            else
            {
                linkShape.SourceAnchor.AbsoluteLocation = new PointD(mainShape.AbsoluteBounds.Right + LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y);
                linkShape.TargetAnchor.AbsoluteLocation = new PointD(shape.AbsoluteBounds.Left - LinkAnchorMargin, shape.AbsoluteBounds.Center.Y);
                linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
            }

            /*
             * if (bSource)
             * {
             *  linkShape.SourceAnchor.AbsoluteLocation = LinkShape.CalculateLocation(
             *      LinkPlacement.Right, shape.AbsoluteBounds, new PointD(shape.AbsoluteBounds.Right + LinkAnchorMargin, shape.AbsoluteBounds.Center.Y));
             *  linkShape.TargetAnchor.AbsoluteLocation = LinkShape.CalculateLocation(
             *      LinkPlacement.Left, mainShape.AbsoluteBounds, new PointD(mainShape.AbsoluteBounds.Left - LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y));
             * }
             * else
             * {
             *  linkShape.SourceAnchor.AbsoluteLocation = LinkShape.CalculateLocation(LinkPlacement.Right,
             *      mainShape.AbsoluteBounds, new PointD(mainShape.AbsoluteBounds.Right + LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y));
             *  linkShape.TargetAnchor.AbsoluteLocation = LinkShape.CalculateLocation(LinkPlacement.Left, shape.AbsoluteBounds,
             *      new PointD(shape.AbsoluteBounds.Left - LinkAnchorMargin, shape.AbsoluteBounds.Center.Y));
             * }
             */
        }
            public virtual void AddRSShapesForElement(DomainModelElement sourceElement, DomainModelElement targetElement, ModelElement con, Guid shapeType)
            {
                List <Guid> shapeIdsSource = DiagramsShapeStore.GetFromStore(sourceElement.Id);
                List <Guid> shapeIdsTarget = DiagramsShapeStore.GetFromStore(targetElement.Id);

                if (shapeIdsSource == null || shapeIdsTarget == null)
                {
                    return;
                }
                if (shapeIdsSource.Count == 0 || shapeIdsTarget.Count == 0)
                {
                    return;
                }

                IDomainModelServices topMost = sourceElement.GetDomainModelServices().TopMostService;

                foreach (Guid sourceShapeId in shapeIdsSource)
                {
                    NodeShape sourceShape = con.Store.ElementDirectory.FindElement(sourceShapeId) as NodeShape;
                    if (sourceShape == null)
                    {
                        continue;
                    }
                    foreach (Guid targetShapeId in shapeIdsTarget)
                    {
                        NodeShape targetShape = con.Store.ElementDirectory.FindElement(targetShapeId) as NodeShape;
                        if (targetShape != null)
                        {
                            if (sourceShape.Diagram == targetShape.Diagram)
                            {
                                if (!DiagramHelper.IsLinkDisplayedOn(sourceShape.Diagram, shapeType, con.Id, sourceShape.Id, targetShape.Id))
                                {
                                    LinkShape shape = topMost.ShapeProvider.CreateShapeForElementLink(shapeType, con, sourceShape, targetShape) as LinkShape;
                                    sourceShape.Diagram.LinkShapes.Add(shape);
                                    shape.Layout(FixedGeometryPoints.None);
                                }
                            }
                        }
                    }
                }
            }
Beispiel #4
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            if (e.ModelElement == null)
            {
                return;
            }

            if (e.ModelElement.Store.InSerializationTransaction)
            {
                return;
            }

            LinkShape linkShape = e.ModelElement as LinkShape;

            if (linkShape != null)
            {
                if (e.DomainProperty.Id == LinkShape.RoutingModeDomainPropertyId)
                {
                    linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
                }
            }
        }
        /// <summary>
        /// Updates the position of a link shape.
        /// </summary>
        /// <param name="linkShape">Link shape.</param>
        /// <param name="shape">Graphical dependency shape.</param>
        /// <param name="mainShape">Node shape.</param>
        /// <param name="bSource">True if graphical dependency shape is source.</param>
        public void UpdateLinkShapePosition(LinkShape linkShape, GraphicalDependencyShape shape, NodeShape mainShape, bool bSource)
        {
            if (linkShape == null)
                return;

            if (bSource)
            {
                linkShape.SourceAnchor.AbsoluteLocation = new PointD(shape.AbsoluteBounds.Right + LinkAnchorMargin, shape.AbsoluteBounds.Center.Y);
                linkShape.TargetAnchor.AbsoluteLocation = new PointD(mainShape.AbsoluteBounds.Left - LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y);
                linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
            }
            else
            {
                linkShape.SourceAnchor.AbsoluteLocation = new PointD(mainShape.AbsoluteBounds.Right + LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y);
                linkShape.TargetAnchor.AbsoluteLocation = new PointD(shape.AbsoluteBounds.Left - LinkAnchorMargin, shape.AbsoluteBounds.Center.Y);
                linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
            }

            /*
            if (bSource)
            {
                linkShape.SourceAnchor.AbsoluteLocation = LinkShape.CalculateLocation(
                    LinkPlacement.Right, shape.AbsoluteBounds, new PointD(shape.AbsoluteBounds.Right + LinkAnchorMargin, shape.AbsoluteBounds.Center.Y));
                linkShape.TargetAnchor.AbsoluteLocation = LinkShape.CalculateLocation(
                    LinkPlacement.Left, mainShape.AbsoluteBounds, new PointD(mainShape.AbsoluteBounds.Left - LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y));
            }
            else
            {
                linkShape.SourceAnchor.AbsoluteLocation = LinkShape.CalculateLocation(LinkPlacement.Right,
                    mainShape.AbsoluteBounds, new PointD(mainShape.AbsoluteBounds.Right + LinkAnchorMargin, mainShape.AbsoluteBounds.Center.Y));
                linkShape.TargetAnchor.AbsoluteLocation = LinkShape.CalculateLocation(LinkPlacement.Left, shape.AbsoluteBounds,
                    new PointD(shape.AbsoluteBounds.Left - LinkAnchorMargin, shape.AbsoluteBounds.Center.Y));
            }
            */
        }