/// <summary> /// Updates the given cell state. /// </summary> /// <param name="state"></param> public void UpdateCellState(mxCellState state, mxCellState source, mxCellState target) { state.AbsoluteOffset.X = 0; state.AbsoluteOffset.Y = 0; state.Origin.X = 0; state.Origin.Y = 0; state.Length = 0; mxIGraphModel model = graph.Model; mxCellState pState = GetState(model.GetParent(state.Cell)); if (pState != null) { state.Origin.X += pState.Origin.X; state.Origin.Y += pState.Origin.Y; } mxPoint offset = graph.GetChildOffsetForCell(state.Cell); if (offset != null) { state.Origin.X += offset.X; state.Origin.Y += offset.Y; } mxGeometry geo = graph.GetCellGeometry(state.Cell); if (geo != null) { if (!model.IsEdge(state.Cell)) { mxPoint origin = state.Origin; offset = geo.Offset; if (offset == null) { offset = EMPTY_POINT; } if (geo.Relative && pState != null) { if (model.IsEdge(pState.Cell)) { mxPoint orig = GetPoint(pState, geo); if (orig != null) { origin.X += (orig.X / scale) - pState.Origin.X - translate.X; origin.Y += (orig.Y / scale) - pState.Origin.Y - translate.Y; } } else { origin.X += geo.X * pState.Width / scale + offset.X; origin.Y += geo.Y * pState.Height / scale + offset.Y; } } else { state.AbsoluteOffset = new mxPoint(scale * offset.X, scale * offset.Y); origin.X += geo.X; origin.Y += geo.Y; } } 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(state.Cell)) { UpdateVertexState(state, geo); } if (model.IsEdge(state.Cell)) { UpdateEdgeState(state, geo, source, target); } } }
/// <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)); } } }