Ejemplo n.º 1
0
        /// <summary>
        /// Validates the given cell state.
        /// </summary>
        public void UpdateEdgeState(mxCellState state, mxGeometry geo, mxCellState source, mxCellState target)
        {
            // This will remove edges with no terminals and no terminal points
            // as such edges are invalid and produce NPEs in the edge styles.
            // Also removes connected edges that have no visible terminals.
            if ((graph.Model.GetTerminal(state.Cell, true) != null && source == null) ||
                (source == null && geo.GetTerminalPoint(true) == null) ||
                (graph.Model.GetTerminal(state.Cell, false) != null && target == null) ||
                (target == null && geo.GetTerminalPoint(false) == null))
            {
                RemoveState(state.Cell, true);
            }
            else
            {
                UpdateFixedTerminalPoints(state, source, target);
                UpdatePoints(state, geo.Points, source, target);
                UpdateFloatingTerminalPoints(state, source, target);

                if (state.AbsolutePointCount() < 2 || state.AbsolutePoints[0] == null || state
                    .AbsolutePoints[state.AbsolutePointCount() - 1] == null)
                {
                    // This will remove edges with invalid points from the list of states in the view.
                    // Happens if the one of the terminals and the corresponding terminal point is null.
                    RemoveState(state.Cell, true);
                }
                else
                {
                    UpdateEdgeBounds(state);
                    state.AbsoluteOffset = GetPoint(state, geo);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the fixed source or target terminal point on the given edge.
        /// </summary>
        /// <param name="edge">State whose terminal point should be updated.</param>
        /// <param name="terminal">State which represents the actual terminal.</param>
        /// <param name="source">Boolean that specifies if the terminal is the source.</param>
        /// <param name="constraint">Constraint that specifies the connection.</param>
        public void UpdateFixedTerminalPoint(mxCellState edge, mxCellState terminal,
                                             bool source, mxConnectionConstraint constraint)
        {
            mxPoint pt = null;

            if (constraint != null)
            {
                pt = graph.GetConnectionPoint(terminal, constraint);
            }

            if (pt == null && terminal == null)
            {
                mxPoint    orig = edge.Origin;
                mxGeometry geo  = graph.GetCellGeometry(edge.Cell);
                pt = geo.GetTerminalPoint(source);

                if (pt != null)
                {
                    pt = new mxPoint(scale * (translate.X + pt.X + orig.X),
                                     scale * (translate.Y + pt.Y + orig.Y));
                }
            }

            edge.SetAbsoluteTerminalPoint(pt, source);
        }