// Normally if all its successors are deleted, it is deletable. // Regarding SymbolConstraint, it returns false. // Regarding SymbolGraphicState, it is deletable if all its predecessors are deleted. public virtual bool IsDeletable(FRList<Node> deletedNodeList) { if (deletedNodeList == null) return false; if (GetFragment() == null) return true; FRList<Node> immediateSuccessors = new FRList<Node>(); GetFragment().GetImmediateSuccessors(this, immediateSuccessors); foreach (Node item in immediateSuccessors) { if (!deletedNodeList.Contains(item)) return false; // Some one isn't deleted, I can't be deleted. } return true; }
public void GetImmediateSuccessors(Node node, FRList<Node> immediateSucs) { GraphVertex vertex = null; if (!m_NodeGraphVertexMap.ContainsKey(node)) return; vertex = m_NodeGraphVertexMap[node]; foreach (GraphEdge edge in vertex.GetSuccessorEdges()) { Node sucNode = edge.GetEndVertex().GetNode(); Debug.Assert(sucNode != node); if (!immediateSucs.Contains(sucNode)) immediateSucs.Add(sucNode); } }
public void GetImmediatePredecessors(Node node, FRList<Node> immediatePres) { GraphVertex vertex = null; if (!m_NodeGraphVertexMap.ContainsKey(node)) return; vertex = m_NodeGraphVertexMap[node]; foreach(GraphEdge edge in vertex.GetPredecessorEdges()) { Node preNode = edge.GetStartVertex().GetNode(); Debug.Assert(preNode != node); if (!immediatePres.Contains(preNode)) immediatePres.Add(preNode); } }
// bClearRelatedNodes indicates whether remove the related nodes // or just remove the input one. public void RemoveNode(Node node, bool bClearRelatedNodes) { if (!IsExist(node)) return; if(!bClearRelatedNodes) { m_NodeList.Remove(node); } else { FRList<Node> deletedNodeList = new FRList<Node>(); FRList<Node> dieNominateList = new FRList<Node>(); deletedNodeList.Add(node); dieNominateList.Add(node); while (dieNominateList.Count > 0) { Node tmpNode = dieNominateList[0]; dieNominateList.Remove(tmpNode); if (deletedNodeList.Contains(tmpNode) || tmpNode.IsDeletable(deletedNodeList)) { if (!deletedNodeList.Contains(tmpNode)) deletedNodeList.Add(tmpNode); FRList<Node> nodeNominates = new FRList<Node>(); tmpNode.GetDeleteNominates(nodeNominates); foreach (Node item in nodeNominates) { if (!dieNominateList.Contains(item)) dieNominateList.Add(item); } } } // Delete the nodes in the data model foreach (Node delNode in deletedNodeList) m_NodeList.Remove(delNode); } m_bIsGraphDirty = true; }