public static Range From(Position startPosition, int rowCount, int colCount) { var range = new Range(startPosition); range.RowsCount = rowCount; range.ColumnsCount = colCount; return range; }
/// <summary> /// Расширить выделенный диапазон на все столбцы. Выделяет все столбцы выбранного диапазона строк. /// т.е. если выбрана одна колонка из строки, то выделяет все колонки строк. /// </summary> /// <param name="sg">FBA.GridFBA</param> private void SourceGridSelectAll(FBA.GridFBA sg) { sg.Selection.ResetSelection(false); var range = new SourceGrid.Range(0, 0, sg.Rows.Count - 1, sg.Columns.Count - 1); sg.Selection.SelectRange(range, true); }
public void MyRowSelector_4(CellContext context) { SourceGrid.Range r1_1 = new SourceGrid.Range(new Position(context.Position.Row, 4), new Position(context.Position.Row, context.Grid.Columns.Count)); SourceGrid.Range r2_2 = new SourceGrid.Range(new Position(0, 0), new Position(context.Grid.Rows.Count, context.Grid.Columns.Count)); context.Grid.Selection.SelectRange(r2_2, false); context.Grid.Selection.SelectRange(r1_1, true); }
public void Update(Range oldRange, Range newRange) { var range = base.QueryFirst(oldRange.Start); if (range == null) throw new RangeNotFoundException(); Remove(oldRange); Insert(newRange); }
/// <summary> /// Выделяет ячейку /// </summary> public static void CellSelector(SourceGrid.CellContext context) { if (context.Grid != null) { SourceGrid.Range range = new SourceGrid.Range(new SourceGrid.Position(0, 0), new SourceGrid.Position(context.Grid.Rows.Count, context.Grid.Columns.Count)); context.Grid.Selection.SelectRange(range, false); context.Grid.Selection.SelectCell(context.Position, true); } }
/// <summary> /// Updates range whose start position matches. /// If no matches found, an exception is thrown /// </summary> /// <param name="newRange"></param> public void Update(Range newRange) { Range? index = this.SpannedRangesCollection.FindRangeWithStart(newRange.Start); if (index == null) throw new ArgumentException(string.Format( "Could not find a spanned cell range with the same starting point as {0}", newRange.Start)); this.SpannedRangesCollection.Update(index.Value, newRange); }
public void AddEmptyCells(Range range) { for (int i = range.Start.Row; i <= range.End.Row; i++) for (int i1 = range.Start.Column; i1 <= range.End.Column; i1++) { if (this.Grid[i, i1] == null) Grid[i, i1] = new Cell(); } }
/// <summary> /// Расширить выделенный диапазон на все столбцы. /// </summary> /// <param name="sg">FBA.GridFBA</param> private void SourceGridSelectRows(FBA.GridFBA sg) { int[] selectedRows = sg.Selection.GetSelectionRegion().GetRowsIndex(); sg.Selection.ResetSelection(false); int rowFirst = selectedRows[0]; int rowLast = selectedRows[selectedRows.Length - 1]; var range = new SourceGrid.Range(rowFirst, 0, rowLast, sg.Columns.Count - 1); sg.Selection.SelectRange(range, true); }
/// <summary> /// Adds or updates given range. /// Updates range only when existing range with given start position is found /// </summary> /// <param name="newRange"></param> public void UpdateOrAdd(Range newRange) { if (newRange.Equals(Range.Empty)) throw new ArgumentException("Range can not be empty"); Range? index = this.SpannedRangesCollection.FindRangeWithStart(newRange.Start); if (index == null) this.SpannedRangesCollection.Add(newRange); else this.SpannedRangesCollection.Update(Range.FromPosition(newRange.Start), newRange); }
/// <summary> /// Расширить выделенный диапазон на все столбцы. /// </summary> /// <param name="sg">FBA.GridFBA</param> private void SourceGridSelectColumns(FBA.GridFBA sg) { int[] SelectedColumns = sg.Selection.GetSelectionRegion().GetColumnsIndex(); sg.Selection.ResetSelection(false); int columnFirst = SelectedColumns[0]; int columnLast = SelectedColumns[SelectedColumns.Length - 1]; var range = new SourceGrid.Range(0, columnFirst, sg.Rows.Count - 1, columnLast); sg.Selection.SelectRange(range, true); }
public void MoveUpSpannedRanges(int startIndex, int moveCount) { foreach (var range in this.SpannedRangesCollection.ToArray()) { if (range.Start.Row <= startIndex) continue; var newRange = new Range(range.Start.Row - moveCount, range.Start.Column, range.End.Row - moveCount, range.End.Column); this.SpannedRangesCollection.Update(range, newRange); } }
/// <summary> /// Выделяет строку /// </summary> public static void RowSelector(SourceGrid.CellContext context) { if (context.Grid != null) { int c = 0; for (c = 0; c < context.Grid.Columns.Count; c++) { if (!(context.Grid.GetCell(context.Position.Row, c) is ColumnHeader || context.Grid.GetCell(context.Position.Row, c) is SourceGrid.Cells.RowHeader)) { break; } } SourceGrid.Range r1 = new SourceGrid.Range(new SourceGrid.Position(context.Position.Row, c), new SourceGrid.Position(context.Position.Row, context.Grid.Columns.Count)); SourceGrid.Range r2 = new SourceGrid.Range(new SourceGrid.Position(0, 0), new SourceGrid.Position(context.Grid.Rows.Count, context.Grid.Columns.Count)); context.Grid.Selection.SelectRange(r2, false); context.Grid.Selection.SelectRange(r1, true); } }
public RowInfoCollectoinHiddenRowCoordinator(RowInfoCollection rows) : base(rows) { // when rows are removed, check if some of them were hidden // if yes, inform hidden row coordinator that they were removed rows.RowsRemoving += delegate(object sender, IndexRangeEventArgs e) { for (int i = 0 ; i < e.Count; i ++) { var index = i + e.StartIndex; if (rows.IsRowVisible(index) == false) base.m_totalHiddenRows -= 1; } var range = new Range(e.StartIndex, 0, e.StartIndex + e.Count, 1); base.m_rowMerger.RemoveRange(range); }; }
/// <summary> /// Draw the highlighted cells. /// </summary> /// <param name="graphics"></param> /// <param name="drawingRange">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param> protected virtual void DrawHighlight(DevAge.Drawing.GraphicsCache graphics, Range drawingRange) { if (Region.IsEmpty() || Region.IntersectsWith(drawingRange) == false) return; System.Drawing.Brush brush = graphics.BrushsCache.GetBrush(BackColor); foreach (Range rng in Region.GetRanges()) { System.Drawing.Rectangle rectToDraw = Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.RectangleF contentRect = Border.GetContentRectangle(rectToDraw); graphics.Graphics.FillRectangle(brush, contentRect); Border.Draw(graphics, rectToDraw); } }
/// <summary> /// Снимает выделение со всех ячеек /// </summary> /// <param name="f"></param> public static void ClearAllSelection(Form1 f) { for (int t = 1; t < 4; t++) { foreach (TabControl tc in f.Controls.Find("tabControl" + t, true)) { for (int i = 0; i < tc.TabCount + 20; i++) { foreach (SourceGrid.Grid SGrid in tc.Controls.Find("grid" + i, true)) { SourceGrid.Range R = new SourceGrid.Range(0, 0, SGrid.Rows.Count, SGrid.Columns.Count); SGrid.Selection.SelectRange(R, false); } foreach (SourceGrid.Grid SGrid in tc.Controls.Find("grid" + i + "Mill", true)) { SourceGrid.Range R = new SourceGrid.Range(0, 0, SGrid.Rows.Count, SGrid.Columns.Count); SGrid.Selection.SelectRange(R, false); } } } } }
public StandardHiddenRowCoordinator(RowsBase rows) { this.m_rows = rows; rows.RowVisibilityChanged += delegate(int rowIndex, bool becameVisible) { var range = new Range(rowIndex, 0, rowIndex, 1); if (becameVisible) m_rowMerger.RemoveRange(range); else m_rowMerger.AddRange(range); }; rows.RowVisibilityChanged += delegate(int rowIndex, bool becameVisible) { if (becameVisible == true) m_totalHiddenRows -= 1; else m_totalHiddenRows += 1; if (m_totalHiddenRows < 0) throw new SourceGridException("Total hidden rows becamse less than 0. This indicates a bug"); }; }
public Range? QueryFirst(Range area) { return m_root.QueryFirst(area); }
/// <summary> /// Query the QuadTree, returning the items that are in the given area /// </summary> /// <param name="area"></param> /// <returns></returns> public List<Range> Query(Range area) { return m_root.Query(area); }
public QuadTree Remove(Range range) { m_root.Remove(range); return this; }
/// <summary> /// Constructor /// </summary> public RangeLoader(Range range) { mRange = range; }
static Range() { Empty = new Range(Position.Empty, Position.Empty, false); }
/// <summary> /// /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public bool Equals(Range p_Range) { return (Start.Equals(p_Range.Start) && End.Equals(p_Range.End)); }
/// <summary> /// Insert the feature into the QuadTree /// </summary> /// <param name="item"></param> public QuadTree Insert(Range item) { m_root.Insert(item); return this; }
/// <summary> /// Returns true if the specified range intersects (one or more cells) with the current range. /// If one of the range is empty then the return is false. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static bool IntersectsWith(Range p_Range1, Range p_Range2) { return Intersect(p_Range1, p_Range2).IsEmpty() == false; }
/// <summary> /// Выделяет ячейку /// </summary> /// <param name="context"></param> public void MyCellSelector(CellContext context) { SourceGrid.Range r3 = new SourceGrid.Range(new Position(0, 0), new Position(context.Grid.Rows.Count, context.Grid.Columns.Count)); context.Grid.Selection.SelectRange(r3, false); context.Grid.Selection.SelectCell(context.Position, true); }
public bool Remove(Range range) { // if the item is not contained in this quad, there's a problem if (!m_bounds.Contains(range)) { throw new ArgumentException("range is out of the bounds of this quadtree node"); } // for each subnode: // if the node contains the item, add the item to that node and return // this recurses into the node that is just large enough to fit this item foreach (QuadTreeNode node in m_nodes) { if (node.Bounds.Contains(range)) { return node.Remove(range); } } for (int i = 0; i < Contents.Count; i++ ) { if (Contents[i].Equals(range)) { Contents.RemoveAt(i); return true; } } return false; }
private void EnsureNoSpannedCellsExist(int row, int col, Cells.ICell p_cell) { var spanRange = new Range(row, col, row + p_cell.RowSpan - 1, col + p_cell.ColumnSpan - 1); var ranges = spannedCellReferences.SpannedRangesCollection.GetRanges( spanRange); if (ranges.Count == 0) return; var start = new Position(row, col); foreach (var range in ranges) { if (start.Equals(range.Start) == true) continue; Cells.ICell existingSpannedCell = this[range.Start]; if (existingSpannedCell == null) throw new ArgumentException("internal error. please report this bug to developers"); throw new OverlappingCellException(string.Format( "Given cell at position ({0}, {1}), " + "intersects with another cell " + "at position ({2}, {3}) '{4}'", row, col, existingSpannedCell.Row.Index, existingSpannedCell.Column.Index, existingSpannedCell.DisplayText)); } }
/// <summary> /// Insert an item to this node /// </summary> /// <param name="item"></param> public void Insert(Range item) { // if the item is not contained in this quad, there's a problem if (!m_bounds.Contains(item)) { throw new ArgumentException("range is out of the bounds of this quadtree node"); } // if the subnodes are null create them. may not be sucessfull: see below // we may be at the smallest allowed size in which case the subnodes will not be created if (m_nodes.Count == 0) QuadTree.QuadTreeNodeDivider.CreateSubNodes(this); // for each subnode: // if the node contains the item, add the item to that node and return // this recurses into the node that is just large enough to fit this item foreach (QuadTreeNode node in m_nodes) { if (node.Bounds.Contains(item)) { node.Insert(item); return; } } // if we make it to here, either // 1) none of the subnodes completely contained the item. or // 2) we're at the smallest subnode size allowed // add the item to this node's contents. this.Contents.Add(item); }
/// <summary> /// Double ocuppied space by adding one more root level node. /// Current root will go under the new root /// </summary> public void Grow() { this.m_root = this.QuadTreeNodeDivider.CreateNewRoot(m_root); this.m_rectangle = m_root.Bounds; }
/// <summary> /// Returns true if the specified range intersects (one or more cells) with the current range. /// If one of the range is empty then the return is false. /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public bool IntersectsWith(Range p_Range) { return IntersectsWith(this, p_Range); }
/// <summary> /// /// </summary> /// <param name="rectangle"></param> public QuadTree(Range rectangle) { m_rectangle = rectangle; m_root = new QuadTreeNode(m_rectangle, 0, this); QuadTreeNodeDivider = new ProportioanteSizeNodeDivider(); }
/// <summary> /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells) /// </summary> /// <param name="range"></param> /// <returns></returns> public RangeRegion Exclude(Range range) { RangeRegion excluded; Range intersection = Intersect(range); if (intersection.IsEmpty()) { excluded = new RangeRegion(this); } else { excluded = new RangeRegion(); //Top Left if (this.Start.Row < intersection.Start.Row && this.Start.Column < intersection.Start.Column) excluded.Add( new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1) ); //Top if (this.Start.Row < intersection.Start.Row) excluded.Add( new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column) ); //Top Right if (this.Start.Row < intersection.Start.Row && this.End.Column > intersection.End.Column) excluded.Add( new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row -1, this.End.Column) ); //---------- //Left if (this.Start.Column < intersection.Start.Column) excluded.Add( new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column -1) ); //Right if (this.End.Column > intersection.End.Column) excluded.Add( new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column) ); //-------- //Bottom Left if (this.End.Row > intersection.End.Row && this.Start.Column < intersection.Start.Column) excluded.Add( new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1) ); //Bottom if (this.End.Row > intersection.End.Row) excluded.Add( new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column) ); //Bottom Right if (this.End.Row > intersection.End.Row && this.End.Column > intersection.End.Column) excluded.Add( new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column) ); } return excluded; }
/// <summary> /// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static Range Intersect(Range p_Range1, Range p_Range2) { if (p_Range1.IsEmpty() || p_Range2.IsEmpty()) return Range.Empty; Position startNew = Position.Max(p_Range1.Start, p_Range2.Start); Position endNew = Position.Min(p_Range1.End, p_Range2.End); if (startNew.Column > endNew.Column || startNew.Row > endNew.Row) return Range.Empty; else return new Range(startNew, endNew, false); }
/// <summary> /// Returns true if the specified range is present in the current range. /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public bool Contains(Range p_Range) { return (Contains(p_Range.Start) && Contains(p_Range.End)); }
/// <summary> /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static RangeRegion Union(Range p_Range1, Range p_Range2) { RangeRegion range = new RangeRegion(); range.Add(p_Range1); range.Add(p_Range2); return range; }
/// <summary> /// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty. /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public Range Intersect(Range p_Range) { return Intersect(this, p_Range); }
/// <summary> /// This method converts a Position to the real range of the cell. This is usefull when RowSpan or ColumnSpan is greater than 1. /// </summary> /// <returns></returns> public override Range RangeToCellRange(Range range) { int x = range.Start.Column; int x1 = range.End.Column; int y = range.Start.Row; int y1 = range.End.Row; for (int x2 = range.Start.Column; x2 <= range.End.Column; x2++) { for (int y2 = range.Start.Row; y2 <= range.End.Row; y2++) { var p = new Position(y2, x2); Range range2 = PositionToCellRange(p); if (range2.IsEmpty()) range2 = new Range(p, p); if (range2.Start.Column < x) x = range2.Start.Column; if (range2.End.Column > x1) x1 = range2.End.Column; if (range2.Start.Row < y) y = range2.Start.Row; if (range2.End.Row > y1) y1 = range2.End.Row; } } return new Range(y, x, y1, x1); }
/// <summary> /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static Range GetBounds(Range p_Range1, Range p_Range2) { if (p_Range1.IsEmpty()) return p_Range2; else if (p_Range2.IsEmpty()) return p_Range1; else return new Range(Position.Min(p_Range1.Start, p_Range2.Start), Position.Max(p_Range1.End, p_Range2.End), false); }