Esempio n. 1
0
        public void TestRemoveEdgeDoesntRemoveNodes()
        {
            GraphData g      = new GraphData("scope");
            Node      source = new Node("Source");
            Node      target = new Node("Target");
            Edge      edge   = new Edge(source, target);

            g.AddNode(source);
            g.AddNode(target);
            g.AddEdge(edge);

            if (!g.ContainsEdge(edge))
            {
                Assert.Inconclusive("Edge not found in the collection after adding it.");
            }

            g.RemoveEdge(edge);

            if (g.ContainsEdge(edge))
            {
                Assert.Inconclusive("Edge still found in the collection after removing it.");
            }

            Assert.IsTrue(g.ContainsNode(source));
            Assert.IsTrue(g.ContainsNode(target));
        }
Esempio n. 2
0
        //TODO:  WE SHOULD HAVE EVENTS FOR WHEN NODE VIEWMODELS ARE REMOVED OR ADDED

        #region Edge View Models

        /// <summary>
        /// Creates a new EdgeViewModel
        /// </summary>
        /// <param name="edge">The IEdge instance that is responsible
        /// for the edge view model being created</param>
        private void CreateEdgeViewModel(IEdge edge)
        {
            IEdgeViewModel edgeViewModel;
            bool           isNew = true;

            // Check if the edge view model already exists
            if (edgeToEdgeViewModel.ContainsKey(edge))
            {
                isNew = false;
            }

            // Make sure that the edge exists in the graph data structure
            if (!graphData.ContainsEdge(edge))
            {
                // Since the edge doesn't exist in the graph
                // data structure, we need to add it
                graphData.AddEdge(edge);
            }

            // Create a new edge viewmodel
            if (isNew)
            {
                edgeViewModel = EdgeViewModelBase.GetEdgeViewModel(edge, graphData.Scope);
            }
            else
            {
                edgeViewModel = edgeToEdgeViewModel[edge];
            }

            // Get the source node view model
            INodeShape sourceNodeViewModel = null;
            INodeShape targetNodeViewModel = null;

            nodeToNodeViewModel.TryGetValue(edgeViewModel.ParentEdge.Source, out sourceNodeViewModel);
            nodeToNodeViewModel.TryGetValue(edgeViewModel.ParentEdge.Target, out targetNodeViewModel);

            if (sourceNodeViewModel != null)
            {
                edgeViewModel.X1 = sourceNodeViewModel.CenterPoint.X;
                edgeViewModel.Y2 = sourceNodeViewModel.CenterPoint.Y;
            }

            if (targetNodeViewModel != null)
            {
                edgeViewModel.X1 = targetNodeViewModel.CenterPoint.X;
                edgeViewModel.Y2 = targetNodeViewModel.CenterPoint.Y;
            }

            // If this is a new node, add it
            if (isNew)
            {
                // Add the edge to the edge/edgeviewmodel collection
                edgeToEdgeViewModel.Add(edge, edgeViewModel);

                // Fire the EdgeViewModelRemoved event
                OnEdgeViewModelAdded(new EdgeViewModelEventArgs(edgeViewModel, this.scope));
            }
        }
Esempio n. 3
0
        public void TestAddEdge()
        {
            GraphData g      = new GraphData("scope");
            Node      source = new Node("Source");
            Node      target = new Node("Target");
            Edge      edge   = new Edge(source, target);

            g.AddNode(source);
            g.AddNode(target);
            g.AddEdge(edge);

            Assert.IsTrue(g.ContainsEdge(edge));
        }
Esempio n. 4
0
        public void TestAddEdge()
        {
            GraphData g = new GraphData("scope");
            Node source = new Node("Source");
            Node target = new Node("Target");
            Edge edge = new Edge(source, target);

            g.AddNode(source);
            g.AddNode(target);
            g.AddEdge(edge);

            Assert.IsTrue(g.ContainsEdge(edge));
        }
Esempio n. 5
0
        public static void deleteNodeFromGraph(GraphData fgdGraphData, Node nNodeToDelete, bool bPopulateXRefs)
        {
            String sNodeToDelete = nNodeToDelete.Id;
            Graph g = fgdGraphData.gGraph;
            if (fgdGraphData.gGraph.NodeMap.ContainsKey(sNodeToDelete))
            {
                List<Node> lnNodeCalls = (fgdGraphData.dNodeCalls.ContainsKey(sNodeToDelete))
                                             ? fgdGraphData.dNodeCalls[sNodeToDelete]
                                             : new List<Node>();
                List<Node> lnNodeIsCalledBy = (fgdGraphData.dNodeIsCalledBy.ContainsKey(sNodeToDelete))
                                                  ? fgdGraphData.dNodeIsCalledBy[sNodeToDelete]
                                                  : new List<Node>();
                // List<Nodes> lnNodeIsCalledBy = fgdGraphData.dNodeIsCalledBy[sNodeToDelete]
                foreach (Node nCallsCurrentNode in lnNodeIsCalledBy)
                    foreach (Node nIsCalledByCurrentNode in lnNodeCalls)
                        if (nCallsCurrentNode.Id != nIsCalledByCurrentNode.Id) // don't add a call to itself
                        {
                            // if (nIsCalledByCurrentNode != null && nCallsCurrentNode != null)
                            //if (false == fgdGraphData.dNodeCalls.ContainsKey(nCallsCurrentNode.Id))
                            if (false == fgdGraphData.ContainsEdge(nCallsCurrentNode.Id, nIsCalledByCurrentNode.Id))
                            {
                                //fgdGraphData.dEdges_SourceTarget.Add(nCallsCurrentNode.Id, new List<Edge>());
                                //fgdGraphData.dEdges_SourceTarget[nCallsCurrentNode.Id].Add((Edge)

                                var eNewEdge =
                                    (Edge)
                                    fgdGraphData.gGraph.AddEdge(nCallsCurrentNode.Id, "", nIsCalledByCurrentNode.Id);
                                fgdGraphData.lsEdges.Add(fgdGraphData.getEdgeString(eNewEdge));
                            }
                        }

                if (fgdGraphData.dEdges_SourceTarget.ContainsKey(sNodeToDelete))
                    foreach (Edge eEdge_NodeCalls in fgdGraphData.dEdges_SourceTarget[sNodeToDelete])
                        fgdGraphData.gGraph.Edges.Remove(eEdge_NodeCalls);

                if (fgdGraphData.dEdges_TargetSource.ContainsKey(sNodeToDelete))
                    foreach (Edge eEdge_IsCalledBy in fgdGraphData.dEdges_TargetSource[sNodeToDelete])
                        fgdGraphData.gGraph.Edges.Remove(eEdge_IsCalledBy);

                fgdGraphData.gGraph.NodeMap.Remove(sNodeToDelete);
                if (bPopulateXRefs)
                    fgdGraphData.populateXrefDictionaries(); // check for performance probs in big graphs
            }
            /* 
            if (g.NodeMap.ContainsKey(deleteNodeName))
            {
                //remove node
                g.NodeMap.Remove(deleteNodeName);
                //find all edges referring to the deleted node
                ArrayList removePositions = new ArrayList();
                foreach (Edge edge in g.Edges)
                {
                    if (edge.Source == deleteNodeName || edge.Target == deleteNodeName)
                    {
                        int pos = g.Edges.IndexOf(edge);
                        removePositions.Add(pos);
                    }
                }

                //remove all found edges
                int count = 0;
                foreach (int pos in removePositions)
                {
                    g.Edges.RemoveAt(pos - count);
                    count++;
                }
            } */
        }
Esempio n. 6
0
        public static void deleteNodeFromGraph(GraphData fgdGraphData, Node nNodeToDelete, bool bPopulateXRefs)
        {
            String sNodeToDelete = nNodeToDelete.Id;
            Graph  g             = fgdGraphData.gGraph;

            if (fgdGraphData.gGraph.NodeMap.ContainsKey(sNodeToDelete))
            {
                List <Node> lnNodeCalls = (fgdGraphData.dNodeCalls.ContainsKey(sNodeToDelete))
                                             ? fgdGraphData.dNodeCalls[sNodeToDelete]
                                             : new List <Node>();
                List <Node> lnNodeIsCalledBy = (fgdGraphData.dNodeIsCalledBy.ContainsKey(sNodeToDelete))
                                                  ? fgdGraphData.dNodeIsCalledBy[sNodeToDelete]
                                                  : new List <Node>();
                // List<Nodes> lnNodeIsCalledBy = fgdGraphData.dNodeIsCalledBy[sNodeToDelete]
                foreach (Node nCallsCurrentNode in lnNodeIsCalledBy)
                {
                    foreach (Node nIsCalledByCurrentNode in lnNodeCalls)
                    {
                        if (nCallsCurrentNode.Id != nIsCalledByCurrentNode.Id) // don't add a call to itself
                        {
                            // if (nIsCalledByCurrentNode != null && nCallsCurrentNode != null)
                            //if (false == fgdGraphData.dNodeCalls.ContainsKey(nCallsCurrentNode.Id))
                            if (false == fgdGraphData.ContainsEdge(nCallsCurrentNode.Id, nIsCalledByCurrentNode.Id))
                            {
                                //fgdGraphData.dEdges_SourceTarget.Add(nCallsCurrentNode.Id, new List<Edge>());
                                //fgdGraphData.dEdges_SourceTarget[nCallsCurrentNode.Id].Add((Edge)

                                var eNewEdge =
                                    (Edge)
                                    fgdGraphData.gGraph.AddEdge(nCallsCurrentNode.Id, "", nIsCalledByCurrentNode.Id);
                                fgdGraphData.lsEdges.Add(fgdGraphData.getEdgeString(eNewEdge));
                            }
                        }
                    }
                }

                if (fgdGraphData.dEdges_SourceTarget.ContainsKey(sNodeToDelete))
                {
                    foreach (Edge eEdge_NodeCalls in fgdGraphData.dEdges_SourceTarget[sNodeToDelete])
                    {
                        fgdGraphData.gGraph.Edges.Remove(eEdge_NodeCalls);
                    }
                }

                if (fgdGraphData.dEdges_TargetSource.ContainsKey(sNodeToDelete))
                {
                    foreach (Edge eEdge_IsCalledBy in fgdGraphData.dEdges_TargetSource[sNodeToDelete])
                    {
                        fgdGraphData.gGraph.Edges.Remove(eEdge_IsCalledBy);
                    }
                }

                fgdGraphData.gGraph.NodeMap.Remove(sNodeToDelete);
                if (bPopulateXRefs)
                {
                    fgdGraphData.populateXrefDictionaries(); // check for performance probs in big graphs
                }
            }

            /*
             * if (g.NodeMap.ContainsKey(deleteNodeName))
             * {
             *  //remove node
             *  g.NodeMap.Remove(deleteNodeName);
             *  //find all edges referring to the deleted node
             *  ArrayList removePositions = new ArrayList();
             *  foreach (Edge edge in g.Edges)
             *  {
             *      if (edge.Source == deleteNodeName || edge.Target == deleteNodeName)
             *      {
             *          int pos = g.Edges.IndexOf(edge);
             *          removePositions.Add(pos);
             *      }
             *  }
             *
             *  //remove all found edges
             *  int count = 0;
             *  foreach (int pos in removePositions)
             *  {
             *      g.Edges.RemoveAt(pos - count);
             *      count++;
             *  }
             * } */
        }
Esempio n. 7
0
        public void TestRemoveEdgeDoesntRemoveNodes()
        {
            GraphData g = new GraphData("scope");
            Node source = new Node("Source");
            Node target = new Node("Target");
            Edge edge = new Edge(source, target);

            g.AddNode(source);
            g.AddNode(target);
            g.AddEdge(edge);

            if (!g.ContainsEdge(edge))
            {
                Assert.Inconclusive("Edge not found in the collection after adding it.");
            }

            g.RemoveEdge(edge);

            if (g.ContainsEdge(edge))
            {
                Assert.Inconclusive("Edge still found in the collection after removing it.");
            }

            Assert.IsTrue(g.ContainsNode(source));
            Assert.IsTrue(g.ContainsNode(target));
        }