Exemplo n.º 1
0
        /// <summary>
        /// Returns all opposite vertices wrt terminal for the given edges, only$
        /// returning sources and/or targets as specified. The result is returned as
        /// an array of mxCells.
        /// </summary>
        /// <param name="model">Model that contains the graph.</param>
        /// <param name="edges">Array of edges to be examined.</param>
        /// <param name="terminal">Cell that specifies the known end of the edges.</param>
        /// <param name="sources">Boolean that specifies if source terminals should
        /// be contained in the result. Default is true.</param>
        /// <param name="targets">Boolean that specifies if target terminals should
        /// be contained in the result. Default is true.</param>
        /// <returns>Returns the array of opposite terminals for the given edges.</returns>
        public static Object[] GetOpposites(mxIGraphModel model, Object[] edges,
                                            Object terminal, bool sources, bool targets)
        {
            List <Object> terminals = new List <Object>();

            if (edges != null)
            {
                for (int i = 0; i < edges.Length; i++)
                {
                    Object source = model.GetTerminal(edges[i], true);
                    Object target = model.GetTerminal(edges[i], false);

                    // Checks if the terminal is the source of
                    // the edge and if the target should be
                    // stored in the result
                    if (source == terminal && target != null && target != terminal &&
                        targets)
                    {
                        terminals.Add(target);
                    }

                    // Checks if the terminal is the taget of
                    // the edge and if the source should be
                    // stored in the result
                    else if (target == terminal && source != null &&
                             source != terminal && sources)
                    {
                        terminals.Add(source);
                    }
                }
            }

            return(terminals.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the nearest ancestor terminal that is visible. The edge appears
        /// to be connected to this terminal on the display.
        /// </summary>
        /// <param name="edge">Cell whose visible terminal should be returned.</param>
        /// <param name="source">Boolean that specifies if the source or target terminal
        /// should be returned.</param>
        /// <returns>Returns the visible source or target terminal.</returns>
        public Object GetVisibleTerminal(Object edge, bool source)
        {
            mxIGraphModel model  = graph.Model;
            Object        result = model.GetTerminal(edge, source);
            Object        best   = result;

            while (result != null)
            {
                if (!graph.IsCellVisible(best) ||
                    graph.IsCellCollapsed(result))
                {
                    best = result;
                }

                result = model.GetParent(result);
            }

            // Checks if the result is not a layer
            if (model.GetParent(best) == model.Root)
            {
                best = null;
            }

            return(best);
        }
Exemplo n.º 3
0
        /// <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());
        }
Exemplo n.º 4
0
        /// <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());
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns all opposite vertices wrt terminal for the given edges, only$
        /// returning sources and/or targets as specified. The result is returned as
        /// an array of mxCells.
        /// </summary>
        /// <param name="model">Model that contains the graph.</param>
        /// <param name="edges">Array of edges to be examined.</param>
        /// <param name="terminal">Cell that specifies the known end of the edges.</param>
        /// <param name="sources">Boolean that specifies if source terminals should
        /// be contained in the result. Default is true.</param>
        /// <param name="targets">Boolean that specifies if target terminals should
        /// be contained in the result. Default is true.</param>
        /// <returns>Returns the array of opposite terminals for the given edges.</returns>
        public static Object[] GetOpposites(mxIGraphModel model, Object[] edges,
                Object terminal, bool sources, bool targets)
        {
            List<Object> terminals = new List<Object>();

            if (edges != null)
            {
                for (int i = 0; i < edges.Length; i++)
                {
                    Object source = model.GetTerminal(edges[i], true);
                    Object target = model.GetTerminal(edges[i], false);

                    // Checks if the terminal is the source of
                    // the edge and if the target should be
                    // stored in the result
                    if (source == terminal && target != null && target != terminal
                            && targets)
                    {
                        terminals.Add(target);
                    }

                    // Checks if the terminal is the taget of
                    // the edge and if the source should be
                    // stored in the result
                    else if (target == terminal && source != null
                            && source != terminal && sources)
                    {
                        terminals.Add(source);
                    }
                }
            }

            return terminals.ToArray();
        }
Exemplo n.º 7
0
        /// <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();
        }
Exemplo n.º 8
0
        /// <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();
        }
Exemplo n.º 9
0
        /// <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;
        }