protected void UpdateEdges()
        {
            sceneComponents.AcceptEdge(edgeComponent => {
                AbstractGraphEdge edge      = edgeComponent.GetGraphEdge();
                AbstractGraphNode startNode = edge.GetStartGraphNode();
                AbstractGraphNode endNode   = edge.GetEndGraphNode();

                sceneComponents.GetNodeComponent(startNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(endNode.GetId()).Rb);
                sceneComponents.GetNodeComponent(endNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(startNode.GetId()).Rb);

                edgeComponent.UpdateGeometry(
                    sceneComponents.GetNodeComponent(startNode.GetId()).GetVisualComponent().transform.position,
                    sceneComponents.GetNodeComponent(endNode.GetId()).GetVisualComponent().transform.position);
            });

            float MostEdgesNodeCount = 0;

            foreach (var n in sceneComponents.nodeComponents)
            {
                if (n.ConnectedRb.Count > MostEdgesNodeCount)
                {
                    MostEdgesNodeCount = n.ConnectedRb.Count;
                }
            }
            foreach (var n in sceneComponents.nodeComponents)
            {
                if (n.ConnectedRb.Count == MostEdgesNodeCount)
                {
                    n.SetPosition(Vector3.zero);
                }
            }
        }
Esempio n. 2
0
        private void DrawGraphEdge(AbstractGraphEdge edge)
        {
            if (graphSceneComponents.HasEdgeComponent(edge))
            {
                return;
            }
            EdgeComponent edgeComponent = new EdgeComponent(edge, graphScenePrefabs.InstantiateEdge());

            graphSceneComponents.AddEdgeComponent(edgeComponent);

            NodeComponent startNode = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetStartGraphNode().GetId());
            NodeComponent endNode   = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetEndGraphNode().GetId());

            if (endNode == null)
            {
                return;
            }

            SpringJoint spring = endNode.GetVisualComponent().GetComponent <SpringJoint> ();

            spring.connectedBody = startNode.GetVisualComponent().GetComponent <Rigidbody> ();

            // checking if there is any other edge connecting the same nodes
            long sameNodeConnections = 0;

            graphSceneComponents.AcceptEdge(existingEdgeComponent => {
                AbstractGraphEdge existingEdge      = existingEdgeComponent.GetGraphEdge();
                AbstractGraphNode existingStartNode = existingEdge.GetStartGraphNode();
                AbstractGraphNode existingEndNode   = existingEdge.GetEndGraphNode();
                if (
                    existingStartNode.GetId() == startNode.GetGraphNode().GetId() && existingEndNode.GetId() == endNode.GetGraphNode().GetId() ||
                    existingStartNode.GetId() == endNode.GetGraphNode().GetId() && existingEndNode.GetId() == startNode.GetGraphNode().GetId()
                    )
                {
                    sameNodeConnections = sameNodeConnections + 1;
                }
            });
            if (sameNodeConnections > 1)
            {
                edgeComponent.MultiEdge = true;
            }
        }
Esempio n. 3
0
        public void AddEdgeComponent(EdgeComponent edgeComponent)
        {
            AbstractGraphEdge edge          = edgeComponent.GetGraphEdge();
            NodeComponent     edgeStartNode = GetNodeComponent(edge.GetStartGraphNode().GetId());

            if (edgeStartNode == null)
            {
                Debug.Log("Unable to find start node component.");
                return;
            }
            NodeComponent edgeEndNode = GetNodeComponent(edge.GetEndGraphNode().GetId());

            if (edgeEndNode == null)
            {
                Debug.Log("Unable to find end node component.");
                return;
            }
            edgeComponents.Add(edgeComponent);
            edgeComponent.UpdateGeometry(edgeStartNode.GetVisualComponent().transform.position, edgeEndNode.GetVisualComponent().transform.position);
        }
Esempio n. 4
0
        public void Update(float time)
        {
            graphSceneComponents.AcceptEdge(edgeComponent => {
                AbstractGraphEdge edge      = edgeComponent.GetGraphEdge();
                AbstractGraphNode startNode = edge.GetStartGraphNode();
                AbstractGraphNode endNode   = edge.GetEndGraphNode();

                NodeComponent startNodeComponent = graphSceneComponents.GetNodeComponent(startNode.GetId());
                NodeComponent endNodeComponent   = graphSceneComponents.GetNodeComponent(endNode.GetId());

                // ---- distance function start
                float distance = 1F / startNode.GetDegree();
                distance      *= 100;
                distance      *= 4;

                SpringJoint springJoint = endNodeComponent.GetVisualComponent().GetComponent <SpringJoint>();
                springJoint.maxDistance = distance;
                springJoint.minDistance = distance;

                SphereCollider collider = endNodeComponent.GetVisualComponent().GetComponent <SphereCollider>();
                collider.radius         = distance * 0.3F;

                endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>().mass = 5;
                // ---- distance function end

                // magic
                Rigidbody body     = endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>();
                body.inertiaTensor = new Vector3(0.01F, 0.01F, 0.01F);

                edgeComponent.UpdateGeometry(
                    startNodeComponent.GetVisualComponent().transform.position,
                    endNodeComponent.GetVisualComponent().transform.position);
            });



            // graphLayout.DoLayout (time);
        }
Esempio n. 5
0
 public void NotifyEdgeCreated(AbstractGraphEdge graphEdge)
 {
     listeners.ForEach(listener => {
         listener.GraphEdgeCreated(graphEdge);
     });
 }
Esempio n. 6
0
 public bool HasEdgeComponent(AbstractGraphEdge graphEdge)
 {
     return(edgeComponents.Exists(edgeComponent => {
         return edgeComponent.GetGraphEdge().GetId() == graphEdge.GetId();
     }));
 }
Esempio n. 7
0
 public void GraphEdgeCreated(AbstractGraphEdge graphEdge)
 {
     DrawGraphEdge(graphEdge);
 }
 public void GraphBackendEdgeCreated(AbstractGraphEdge graphEdge)
 {
     listeners.NotifyEdgeCreated(graphEdge);
 }
Esempio n. 9
0
 public EdgeComponent(AbstractGraphEdge graphEdge, GameObject visualComponent) : base(visualComponent)
 {
     this.graphEdge = graphEdge;
     InitializeEdgeComponent();
 }