/// <summary> /// Returns the number of incoming or outgoing edges, ignoring the given /// edge. /// </summary> /// <param name="model">Graph model that contains the connection data.</param> /// <param name="cell">Cell whose edges should be counted.</param> /// <param name="outgoing">Boolean that specifies if the number of outgoing or /// incoming edges should be returned.</param> /// <param name="ignoredEdge">Object that represents an edge to be ignored.</param> /// <returns>Returns the number of incoming or outgoing edges.</returns> public static int GetDirectedEdgeCount(mxIGraphModel model, Object cell, bool outgoing, Object ignoredEdge) { int count = 0; int edgeCount = model.GetEdgeCount(cell); for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(cell, i); if (edge != ignoredEdge && model.GetTerminal(edge, outgoing) == cell) { count++; } } return(count); }
/// <summary> /// Returns all edges between the given source and target mxCells. If the /// optional boolean directed argument is false, then a matching edge is /// returned regardless of its direction. /// </summary> /// <param name="model">The graph model that contains the graph.</param> /// <param name="source">mxCell that defines the source terminal of the edge to be /// returned.</param> /// <param name="target">mxCell that defines the target terminal of the edge to be /// returned.</param> /// <param name="directed">Optional boolean that specifies if the direction of the /// edge should be taken into account. Default is true.</param> /// <returns></returns> public static Object[] GetEdgesBetween(mxIGraphModel model, Object source, Object target, bool directed) { int tmp1 = model.GetEdgeCount(source); int tmp2 = model.GetEdgeCount(target); // Assumes the source has less connected edges Object terminal = source; int edgeCount = tmp1; // Uses the smaller array of connected edges // for searching the edge if (tmp2 < tmp1) { edgeCount = tmp2; terminal = target; } List <Object> result = new List <Object>(); // Checks if the edge is connected to the correct // cell and returns the first match for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(terminal, i); Object src = model.GetTerminal(edge, true); Object trg = model.GetTerminal(edge, false); bool isSource = src == source; if (isSource && trg == target || (!directed && model.GetTerminal(edge, !isSource) == target)) { result.Add(edge); } } return(result.ToArray()); }
/// <summary> /// Returns all distinct edges connected to this cell. If at least one of /// incoming or outgoing is true, then loops are ignored, otherwise if both /// are false, then all edges connected to the given cell are returned /// including loops. /// </summary> /// <param name="model">Model that contains the connection information</param> /// <param name="cell">Cell whose connections should be returned</param> /// <param name="incoming">Specifies if incoming edges should be returned</param> /// <param name="outgoing">Specifies if outgoing edges should be returned</param> /// <param name="includeLoops">Specifies if loops should be returned</param> /// <returns>Returns the array of connected edges for the given cell</returns> public static Object[] GetEdges(mxIGraphModel model, Object cell, bool incoming, bool outgoing, bool includeLoops) { int edgeCount = model.GetEdgeCount(cell); List <Object> result = new List <Object>(edgeCount); for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(cell, i); Object source = model.GetTerminal(edge, true); Object target = model.GetTerminal(edge, false); if ((includeLoops && source == target) || ((source != target) && ((incoming && target == cell) || (outgoing && source == cell)))) { result.Add(edge); } } return(result.ToArray()); }
/// <summary> /// Returns all edges between the given source and target mxCells. If the /// optional boolean directed argument is false, then a matching edge is /// returned regardless of its direction. /// </summary> /// <param name="model">The graph model that contains the graph.</param> /// <param name="source">mxCell that defines the source terminal of the edge to be /// returned.</param> /// <param name="target">mxCell that defines the target terminal of the edge to be /// returned.</param> /// <param name="directed">Optional boolean that specifies if the direction of the /// edge should be taken into account. Default is true.</param> /// <returns></returns> public static Object[] GetEdgesBetween(mxIGraphModel model, Object source, Object target, bool directed) { int tmp1 = model.GetEdgeCount(source); int tmp2 = model.GetEdgeCount(target); // Assumes the source has less connected edges Object terminal = source; int edgeCount = tmp1; // Uses the smaller array of connected edges // for searching the edge if (tmp2 < tmp1) { edgeCount = tmp2; terminal = target; } List<Object> result = new List<Object>(); // Checks if the edge is connected to the correct // cell and returns the first match for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(terminal, i); Object src = model.GetTerminal(edge, true); Object trg = model.GetTerminal(edge, false); bool isSource = src == source; if (isSource && trg == target || (!directed && model.GetTerminal(edge, !isSource) == target)) { result.Add(edge); } } return result.ToArray(); }
/// <summary> /// Returns all distinct edges connected to this cell. If at least one of /// incoming or outgoing is true, then loops are ignored, otherwise if both /// are false, then all edges connected to the given cell are returned /// including loops. /// </summary> /// <param name="model">Model that contains the connection information</param> /// <param name="cell">Cell whose connections should be returned</param> /// <param name="incoming">Specifies if incoming edges should be returned</param> /// <param name="outgoing">Specifies if outgoing edges should be returned</param> /// <param name="includeLoops">Specifies if loops should be returned</param> /// <returns>Returns the array of connected edges for the given cell</returns> public static Object[] GetEdges(mxIGraphModel model, Object cell, bool incoming, bool outgoing, bool includeLoops) { int edgeCount = model.GetEdgeCount(cell); List<Object> result = new List<Object>(edgeCount); for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(cell, i); Object source = model.GetTerminal(edge, true); Object target = model.GetTerminal(edge, false); if ((includeLoops && source == target) || ((source != target) && ((incoming && target == cell) || (outgoing && source == cell)))) { result.Add(edge); } } return result.ToArray(); }
/// <summary> /// Returns the number of incoming or outgoing edges, ignoring the given /// edge. /// </summary> /// <param name="model">Graph model that contains the connection data.</param> /// <param name="cell">Cell whose edges should be counted.</param> /// <param name="outgoing">Boolean that specifies if the number of outgoing or /// incoming edges should be returned.</param> /// <param name="ignoredEdge">Object that represents an edge to be ignored.</param> /// <returns>Returns the number of incoming or outgoing edges.</returns> public static int GetDirectedEdgeCount(mxIGraphModel model, Object cell, bool outgoing, Object ignoredEdge) { int count = 0; int edgeCount = model.GetEdgeCount(cell); for (int i = 0; i < edgeCount; i++) { Object edge = model.GetEdgeAt(cell, i); if (edge != ignoredEdge && model.GetTerminal(edge, outgoing) == cell) { count++; } } return count; }