Example #1
0
        private void insertExternalNeighborLinks(IContainerNode parentContainerNode, GoLayoutForceDirectedNetwork net)
        {
            foreach (var childContainerNode in parentContainerNode.GetDirectChildren <IContainerNode>())
            {
                foreach (var neighborhoodNode in childContainerNode.GetLinkedNodes <INeighborhoodNode>())
                {
                    if (!parentContainerNode.ContainsChildNode(neighborhoodNode, true))
                    {
                        var  otherContainerNode = neighborhoodNode.GetOtherContainerNode(childContainerNode);
                        var  nodeOnBoundary     = new GoLayoutForceDirectedNode();
                        var  pos         = neighborhoodNode.Location;
                        bool pointExists = GoObject.GetNearestIntersectionPoint(parentContainerNode.Bounds, otherContainerNode.Center, childContainerNode.Center, out pos);

                        if (!pointExists)
                        {
                            continue;
                        }

                        //to be not deleted due to invisible node, seems to set also the position
                        nodeOnBoundary.GoObject  = neighborhoodNode as GoObject;
                        nodeOnBoundary.IsFixed   = true;
                        nodeOnBoundary.UserFlags = NodeLayoutType.REMOTE_CONTAINER_BOUNDARY_NODE;

                        //set Position after setting GoObject, because setting GoObject seems to set position
                        nodeOnBoundary.Position = pos;
                        net.AddNode(nodeOnBoundary);
                        net.LinkNodes(net.FindNode(childContainerNode as GoObject), nodeOnBoundary, neighborhoodNode as GoObject);
                    }
                }
            }
        }
Example #2
0
        protected override float GravitationalMass(GoLayoutForceDirectedNode pNode)
        {
            int group = pNode.UserFlags;

            if (group >= 0 && group < NUMBER_OF_GROUPS && Config.RelativeGravitationalMassOf[group].HasValue)
            {
                return(Config.BaseGravitationalMass * Config.RelativeGravitationalMassOf[group].Value);
            }
            return(Config.BaseGravitationalMass);
        }
Example #3
0
        protected override float ElectricalCharge(GoLayoutForceDirectedNode pNode)
        {
            int group = pNode.UserFlags;

            if (group >= 0 && group < NUMBER_OF_GROUPS && Config.RelativeElectricalChargeOf[group].HasValue)
            {
                float charge     = Config.BaseElectricalCharge * Config.RelativeElectricalChargeOf[group].Value;
                float sizefactor = (float)(Math.Sqrt(pNode.Width / 150F * pNode.Height / 50F));
                if (sizefactor > 40)
                {
                    sizefactor = 40F;
                }

                return(charge * sizefactor);
            }
            return(Config.BaseElectricalCharge);
        }
Example #4
0
        private string NodeText(GoLayoutForceDirectedNode netNode)
        {
            string text = "";

            if (netNode == null)
            {
                return("XXX");
            }
            var goNode = netNode.GoObject as GoNode;

            if (goNode != null)
            {
                text += goNode.Text;
            }
            text += ":" + netNode.UserFlags + (netNode.IsFixed ? "F" : "");               // F = fixed
            text += ((netNode.GoObject == null || !netNode.GoObject.Visible) ? "I" : ""); // i = invisible
            return(text);
        }
Example #5
0
        protected override float SpringLength(GoLayoutForceDirectedLink pLink)
        {
            GoLayoutForceDirectedNode pFromNode = pLink.FromNode;
            int fromGroup = pFromNode.UserFlags;
            GoLayoutForceDirectedNode pToNode = pLink.ToNode;
            int toGroup = pToNode.UserFlags;

            if (fromGroup >= 0 && fromGroup < NUMBER_OF_GROUPS && toGroup >= 0 && toGroup < NUMBER_OF_GROUPS &&
                Config.RelativeSpringLengthOf[fromGroup, toGroup].HasValue)
            {
                float length         = Config.BaseSpringLength * Config.RelativeSpringLengthOf[fromGroup, toGroup].Value;
                float fromSizefactor = pFromNode.Width / 150F * pFromNode.Height / 50F;
                float toSizefactor   = pToNode.Width / 150F * pToNode.Height / 50F;
                float sizefactor     = (float)(Math.Sqrt(fromSizefactor + toSizefactor));
                if (sizefactor > 40)
                {
                    sizefactor = 40F;
                }

                return(length * sizefactor);
            }
            return(Config.BaseSpringLength);
        }
Example #6
0
        public void PerformLayout(IContainerBase containerBase, IList <IHasLayoutInfo> freeNodes)
        {
            string text = "DiagramModel";
            var    containerBaseNode = containerBase as IContainerNode;

            if (containerBaseNode != null)
            {
                text = containerBaseNode.GetLongName();
            }
            if (Config.LogPositions)
            {
                Console.WriteLine("PerformLayout for " + text + " with Bounds " + containerBase.Bounds);
            }


            ContainerBaseBounds = containerBase.Bounds;
            var originalBounds   = containerBase.Bounds;
            var originalLocation = containerBase.Location;

            var net = CreateNetwork();

            net.AddNodesAndLinksFromCollection(containerBase as IGoCollection, true);

            foreach (var n in containerBase.GetDirectChildren <IContainerNode>())
            {
                if (n.Name == Captions.MoleculeProperties)
                {
                    _mpNode = net.FindNode((GoObject)n);
                    break;
                }
            }

            if (Config.LogPositions)
            {
                PrintNodes("<", net);
            }
            if (Config.LogPositions)
            {
                PrintLinks("<", net);
            }

            if (containerBaseNode != null)
            {
                insertExternalNeighborLinks(containerBaseNode, net);
            }

            if (Config.LogPositions)
            {
                PrintNodes("+extNeighborLinks ", net);
            }
            if (Config.LogPositions)
            {
                PrintLinks("+extNeighborLinks ", net);
            }

            // delete invisible nodes before replacing inner neighborhoods by links, to keep "end" neighbor nodes as nodes
            deleteInvisibleNodes(net);

            if (Config.LogPositions)
            {
                PrintNodes("-invisible ", net);
            }
            if (Config.LogPositions)
            {
                PrintLinks("-invisible ", net);
            }

            // Remove neighborhood nodes and neighbor links and insert direct links between the nodes they connect (ContainerNodes or PortNodes)
            replaceInnerNeighborhoodNodesByDirectLinks(containerBase, net);

            if (Config.LogPositions)
            {
                PrintNodes("+intNeighborLinks ", net);
            }
            if (Config.LogPositions)
            {
                PrintLinks("+intNeighborLinks ", net);
            }

            setNodeType(net, freeNodes);

            Network = net;

            if (Config.LogPositions)
            {
                PrintNodes("<", net);
            }
            if (Config.LogPositions)
            {
                PrintLinks("<", net);
            }


            if (net.NodeCount > 0)
            {
                base.PerformLayout();
            }
            if (Config.LogPositions)
            {
                PrintNodes(">", net);
            }

            if (Config.LogPositions)
            {
                Console.WriteLine(" Bounds " + containerBase.Bounds);
            }
            var newBounds = containerBase.CalculateBounds();

            if (Config.LogPositions)
            {
                Console.WriteLine(" After " + newBounds + "ComputeBounds: Bounds " + containerBase.Bounds);
            }


            if (containerBaseNode != null && containerBaseNode.LocationFixed)
            {
                containerBase.Location = originalLocation;
            }

            PointF containerTranslation = containerBase.Bounds.Location.Minus(originalBounds.Location);

            foreach (var netNode in net.Nodes)
            {
                netNode.GoObject.Position = netNode.GoObject.Position.Minus(containerTranslation);
            }

            if (Config.LogPositions)
            {
                Console.WriteLine(" Bounds " + containerBase.Bounds);
            }
        }
Example #7
0
 private string NodePosition(GoLayoutForceDirectedNode netNode)
 {
     return("[" + Convert.ToInt32(netNode.Position.X) + "|" + Convert.ToInt32(netNode.Position.Y) + "]");
 }