public void InsertGrid(PointF ptGridPt, eInsertGridMode insertMode) { switch (insertMode) { case eInsertGridMode.rowBefore: _flowContainer.GridSize = new Size(_flowContainer.GridSize.Width, _flowContainer.GridSize.Height + 1); foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.Y > ptGridPt.Y - 1) { flow.GridLoc = new PointF(flow.GridLoc.X, flow.GridLoc.Y + 1); ReconnectPathLine(ptGridPt, flow, insertMode); } } break; case eInsertGridMode.rowAfter: _flowContainer.GridSize = new Size(_flowContainer.GridSize.Width, _flowContainer.GridSize.Height + 1); foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.Y > ptGridPt.Y) { flow.GridLoc = new PointF(flow.GridLoc.X, flow.GridLoc.Y + 1); ReconnectPathLine(ptGridPt, flow, insertMode); } } break; case eInsertGridMode.columnBefore: _flowContainer.GridSize = new Size(_flowContainer.GridSize.Width + 1, _flowContainer.GridSize.Height); foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.X > ptGridPt.X - 1) { flow.GridLoc = new PointF(flow.GridLoc.X + 1, flow.GridLoc.Y); ReconnectPathLine(ptGridPt, flow, insertMode); } } break; case eInsertGridMode.columnAfter: _flowContainer.GridSize = new Size(_flowContainer.GridSize.Width + 1, _flowContainer.GridSize.Height); foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.X > ptGridPt.X) { flow.GridLoc = new PointF(flow.GridLoc.X + 1, flow.GridLoc.Y); ReconnectPathLine(ptGridPt, flow, insertMode); } } break; } // Set the size of the panel Size = GridToPixel(_flowContainer.GridSize); Rebuild(); Redraw(); }
private void ReconnectPathLine(PointF ptGridPt, SMFlowBase targetFlow, eInsertGridMode insertMode) { switch (insertMode) { case eInsertGridMode.rowBefore: foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.Y >= ptGridPt.Y) { continue; } foreach (SMPathOut pathOut in flow.PathArray) { if (pathOut.TargetID == targetFlow.Name) { SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Down); if (verticalSecment != null) { verticalSecment.GridDistance += 1; } } } foreach (SMPathOut pathOut in targetFlow.PathArray) { if (pathOut.TargetID == flow.Name) { SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Up); if (verticalSecment != null) { verticalSecment.GridDistance -= 1; } } } } break; case eInsertGridMode.rowAfter: foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.Y >= ptGridPt.Y + 1) { continue; } foreach (SMPathOut pathOut in flow.PathArray) { if (pathOut.TargetID == targetFlow.Name) { SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Down); if (verticalSecment != null) { verticalSecment.GridDistance += 1; } } } foreach (SMPathOut pathOut in targetFlow.PathArray) { if (pathOut.TargetID == flow.Name) { SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Up); if (verticalSecment != null) { verticalSecment.GridDistance -= 1; } } } } break; case eInsertGridMode.columnBefore: foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.X >= ptGridPt.X) { continue; } foreach (SMPathOut pathOut in flow.PathArray) { if (pathOut.TargetID == targetFlow.Name) { SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Right); if (horizontalSecment != null) { horizontalSecment.GridDistance += 1; } } } foreach (SMPathOut pathOut in targetFlow.PathArray) { if (pathOut.TargetID == flow.Name) { SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Left); if (horizontalSecment != null) { horizontalSecment.GridDistance -= 1; } } } } break; case eInsertGridMode.columnAfter: foreach (SMFlowBase flow in _flowContainer.ChildArray) { if (flow.GridLoc.X >= ptGridPt.X + 1) { continue; } foreach (SMPathOut pathOut in flow.PathArray) { if (pathOut.TargetID == targetFlow.Name) { SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Right); if (horizontalSecment != null) { horizontalSecment.GridDistance += 1; } } } foreach (SMPathOut pathOut in targetFlow.PathArray) { if (pathOut.TargetID == flow.Name) { SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Left); if (horizontalSecment != null) { horizontalSecment.GridDistance -= 1; } } } } break; default: break; } }