Ejemplo n.º 1
0
        /// <summary>
        /// Recursively creates the cell state for the given cell if visible is true and
        /// the given cell is visible. If the cell is not visible but the state exists
        /// then it is removed using removeState.
        /// </summary>
        /// <param name="cell">Cell whose cell state should be created.</param>
        /// <param name="visible">Boolean indicating if the cell should be visible.</param>
        public Object ValidateCell(Object cell, Boolean visible)
        {
            if (cell != null)
            {
                visible = visible && graph.IsCellVisible(cell);
                mxCellState state = GetState(cell, visible);

                if (state != null && !visible)
                {
                    RemoveState(cell);
                }
                else
                {
                    mxIGraphModel model      = graph.Model;
                    int           childCount = model.GetChildCount(cell);

                    for (int i = 0; i < childCount; i++)
                    {
                        ValidateCell(
                            model.GetChildAt(cell, i),
                            visible && !graph.IsCellCollapsed(cell));
                    }
                }
            }

            return(cell);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates the bounds of the given parent's child using the given parent
        /// state as the origin for the child. The validation is carried out
        /// recursively for all non-collapsed descendants.
        /// </summary>
        /// <param name="parentState">Cell state for the given parent.</param>
        /// <param name="cell">Cell for which the bounds in the state should be updated.</param>
        public void ValidateBounds(mxCellState parentState, Object cell)
        {
            mxIGraphModel model = graph.Model;
            mxCellState   state = GetState(cell, true);

            if (state != null)
            {
                if (!graph.IsCellVisible(cell))
                {
                    RemoveState(cell);
                }
                else if (parentState != null)
                {
                    state.AbsoluteOffset.X = 0;
                    state.AbsoluteOffset.Y = 0;
                    state.Origin           = new mxPoint(parentState.Origin.X,
                                                         parentState.Origin.Y);
                    mxGeometry geo = graph.GetCellGeometry(cell);

                    if (geo != null)
                    {
                        if (!model.IsEdge(cell))
                        {
                            mxPoint origin = state.Origin;
                            mxPoint offset = geo.Offset;

                            if (offset == null)
                            {
                                offset = EMPTY_POINT;
                            }

                            if (geo.Relative)
                            {
                                origin.X += geo.X * parentState.Width /
                                            Scale + offset.X;
                                origin.Y += geo.Y * parentState.Height /
                                            Scale + offset.Y;
                            }
                            else
                            {
                                state.AbsoluteOffset = new mxPoint(
                                    scale * offset.X,
                                    scale * offset.Y);
                                origin.X += geo.X;
                                origin.Y += geo.Y;
                            }
                        }

                        // Updates the cell state's bounds
                        state.X      = scale * (translate.X + state.Origin.X);
                        state.Y      = scale * (translate.Y + state.Origin.Y);
                        state.Width  = scale * geo.Width;
                        state.Height = scale * geo.Height;

                        if (model.IsVertex(cell))
                        {
                            UpdateVertexLabelOffset(state);
                        }
                    }
                }

                // Applies child offset to origin
                mxPoint childOffset = graph.GetChildOffsetForCell(cell);

                if (childOffset != null)
                {
                    state.Origin.X += childOffset.X;
                    state.Origin.Y += childOffset.Y;
                }
            }

            // Recursively validates the child bounds
            if (state != null &&
                !graph.IsCellCollapsed(cell))
            {
                int childCount = model.GetChildCount(cell);

                for (int i = 0; i < childCount; i++)
                {
                    ValidateBounds(state, model.GetChildAt(cell, i));
                }
            }
        }