Esempio n. 1
0
        /// <summary>
        /// Creates a shape for the specified model element.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected virtual NodeShape CreateShape(ModelElement element)
        {
            DiagramDomainDataDirectory data = this.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

            Guid domainClassId = element.GetDomainClass().Id;

            if (data.HasDependenciesShapeForElement(domainClassId))
            {
                return(this.ViewModelStore.TopMostStore.GetDomainModelServices().ShapeProvider.CreateDependenciesShapeForElement(domainClassId, element) as NodeShape);
            }

            NodeShape dShape = new NodeShape(this.Store);

            dShape.Element = element;
            dShape.SetLocation(new PointD(5, 5));
            dShape.SetSize(new SizeD(200, 40));

            return(dShape);
        }
        /// <summary>
        /// Layout a subgraph defined by a given shape by using the GLEE layout library.
        /// </summary>
        /// <param name="shape">Main shape.</param>
        /// <remarks>
        /// This method needs to be called within a modeling transaction.
        /// </remarks>
        private static void LayoutShape(NodeShape shape, List<LinkShape> edges, List<LinkShape> dEdges)
        {
            Dictionary<string, NodeShape> shapesMap = new Dictionary<string, NodeShape>();

            // create glee graph
            GleeGraph g = new GleeGraph();
            g.Margins = GraphMargins;
            g.MinNodeHeight = MinNodeHeight;
            g.MinNodeWidth = GraphMargins;

            // transform the information in the diagram into the glee graph
            List<LinkShape> edgesLocal = new List<LinkShape>();
            foreach (NodeShape childShape in shape.Children)
            {
                // layout shape if it has children
                if (childShape.Children.Count > 0)
                    LayoutShape(childShape, edges, dEdges);

                // collect edges on the same level
                foreach (LinkShape linkShape in childShape.OutgoingLinkShapes)
                {
                    if (linkShape.ToShape.Parent == shape)
                        edgesLocal.Add(linkShape);
                    else
                        dEdges.Add(linkShape);
                }

                AddNode(g, childShape, shapesMap);
            }

            // 2. add edges
            foreach (LinkShape linkShape in edgesLocal)
            {
                g.AddEdge(new Edge(
                    g.NodeMap[linkShape.FromShape.Id.ToString()],
                    g.NodeMap[linkShape.ToShape.Id.ToString()]));
            }
            edges.AddRange(edgesLocal);

            // layout graph
            g.CalculateLayout();

            // apply layout information to diagram
            if (shape.Children.Count > 0)   // we have no way of knowning what min size a shape has for now..
            {
                if (shape.ResizingBehaviour == ShapeResizingBehaviour.Normal)
                    shape.SetSize(new SizeD(g.Width + HostMargin, g.Height + HostMargin));
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedWidth)
                    shape.SetSize(new SizeD(shape.Size.Width, g.Height + HostMargin));
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedHeight)
                    shape.SetSize(new SizeD(g.Width + HostMargin, shape.Size.Height));
            }

            ApplyShapesLayout(g, shapesMap, g.Left, g.Top);

            // update absolute location of shapes
            UpdateAbsoluteLocation(shape);
        }
Esempio n. 3
0
        /// <summary>
        /// Layout a subgraph defined by a given shape by using the GLEE layout library.
        /// </summary>
        /// <param name="shape">Main shape.</param>
        /// <remarks>
        /// This method needs to be called within a modeling transaction.
        /// </remarks>
        private static void LayoutShape(NodeShape shape, List <LinkShape> edges, List <LinkShape> dEdges)
        {
            Dictionary <string, NodeShape> shapesMap = new Dictionary <string, NodeShape>();

            // create glee graph
            GleeGraph g = new GleeGraph();

            g.Margins       = GraphMargins;
            g.MinNodeHeight = MinNodeHeight;
            g.MinNodeWidth  = GraphMargins;

            // transform the information in the diagram into the glee graph
            List <LinkShape> edgesLocal = new List <LinkShape>();

            foreach (NodeShape childShape in shape.Children)
            {
                // layout shape if it has children
                if (childShape.Children.Count > 0)
                {
                    LayoutShape(childShape, edges, dEdges);
                }

                // collect edges on the same level
                foreach (LinkShape linkShape in childShape.OutgoingLinkShapes)
                {
                    if (linkShape.ToShape.Parent == shape)
                    {
                        edgesLocal.Add(linkShape);
                    }
                    else
                    {
                        dEdges.Add(linkShape);
                    }
                }

                AddNode(g, childShape, shapesMap);
            }

            // 2. add edges
            foreach (LinkShape linkShape in edgesLocal)
            {
                g.AddEdge(new Edge(
                              g.NodeMap[linkShape.FromShape.Id.ToString()],
                              g.NodeMap[linkShape.ToShape.Id.ToString()]));
            }
            edges.AddRange(edgesLocal);

            // layout graph
            g.CalculateLayout();

            // apply layout information to diagram
            if (shape.Children.Count > 0)   // we have no way of knowning what min size a shape has for now..
            {
                if (shape.ResizingBehaviour == ShapeResizingBehaviour.Normal)
                {
                    shape.SetSize(new SizeD(g.Width + HostMargin, g.Height + HostMargin));
                }
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedWidth)
                {
                    shape.SetSize(new SizeD(shape.Size.Width, g.Height + HostMargin));
                }
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedHeight)
                {
                    shape.SetSize(new SizeD(g.Width + HostMargin, shape.Size.Height));
                }
            }

            ApplyShapesLayout(g, shapesMap, g.Left, g.Top);

            // update absolute location of shapes
            UpdateAbsoluteLocation(shape);
        }