NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
gridcellcoordscontainer.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2022 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef GRIDCELLCOORDSCONTAINER_HPP
20#define GRIDCELLCOORDSCONTAINER_HPP
21
28{
29 wxGridCellCoords m_topleft;
30 wxGridCellCoords m_bottomright;
31};
32
33
41{
42 private:
44 wxGridCellCoordsArray m_array;
45 wxArrayInt m_rowsOrCols;
47
48 public:
49
55
65 wxGridCellCoordsContainer(const wxGridCellCoords& topleft, const wxGridCellCoords& bottomright) : m_rowsSelected(false)
66 {
67 m_extent.m_topleft = topleft;
68 m_extent.m_bottomright = bottomright;
69 }
70
78 wxGridCellCoordsContainer(const wxGridCellCoordsArray& selected) : m_rowsSelected(false)
79 {
80 m_array = selected;
83
84 for (size_t n = 1; n < m_array.size(); n++)
85 {
86 m_extent.m_topleft.SetRow(std::min(m_extent.m_topleft.GetRow(), m_array[n].GetRow()));
87 m_extent.m_topleft.SetCol(std::min(m_extent.m_topleft.GetCol(), m_array[n].GetCol()));
88 m_extent.m_bottomright.SetRow(std::max(m_extent.m_bottomright.GetRow(), m_array[n].GetRow()));
89 m_extent.m_bottomright.SetCol(std::max(m_extent.m_bottomright.GetCol(), m_array[n].GetCol()));
90 }
91 }
92
103 wxGridCellCoordsContainer(const wxArrayInt& selectedRowsOrCols, int otherDim, bool rowsSelected = true) : m_rowsSelected(rowsSelected)
104 {
105 m_rowsOrCols = selectedRowsOrCols;
106 m_extent.m_topleft = m_rowsSelected ? wxGridCellCoords(m_rowsOrCols[0], 0) : wxGridCellCoords(0, m_rowsOrCols[0]);
107 m_extent.m_bottomright = m_rowsSelected ? wxGridCellCoords(m_rowsOrCols[0], otherDim) : wxGridCellCoords(otherDim, m_rowsOrCols[0]);
108
109 for (size_t n = 0; n < m_rowsOrCols.size(); n++)
110 {
111 if (m_rowsSelected)
112 {
115 }
116 else
117 {
120 }
121 }
122 }
123
132 {
133 return m_extent;
134 }
135
142 size_t getRows() const
143 {
144 return m_extent.m_bottomright.GetRow() - m_extent.m_topleft.GetRow()+1;
145 }
146
153 size_t getCols() const
154 {
155 return m_extent.m_bottomright.GetCol() - m_extent.m_topleft.GetCol()+1;
156 }
157
166 bool contains(const wxGridCellCoords& cell) const
167 {
168 if (isSparse())
169 {
170 for (size_t n = 0; n < m_array.size(); n++)
171 {
172 if (m_array[n] == cell)
173 return true;
174 }
175
176 return false;
177 }
178
179 if (m_rowsOrCols.size())
180 return std::find(m_rowsOrCols.begin(),
181 m_rowsOrCols.end(),
182 m_rowsSelected ? cell.GetRow() : cell.GetCol()) != m_rowsOrCols.end();
183
184 return cell.GetRow() >= m_extent.m_topleft.GetRow()
185 && cell.GetRow() <= m_extent.m_bottomright.GetRow()
186 && cell.GetCol() >= m_extent.m_topleft.GetCol()
187 && cell.GetCol() <= m_extent.m_bottomright.GetCol();
188 }
189
202 bool contains(int row, int col) const
203 {
204 return contains(wxGridCellCoords(row, col));
205 }
206
214 bool isBlock() const
215 {
216 if (isSparse())
217 return false;
218
219 if (m_rowsOrCols.size())
220 {
221 if (m_rowsSelected && m_rowsOrCols.size() != getRows())
222 return false;
223
224 if (!m_rowsSelected && m_rowsOrCols.size() != getCols())
225 return false;
226 }
227
228 return true;
229 }
230
238 bool columnsSelected() const
239 {
240 return m_rowsOrCols.size() && !m_rowsSelected;
241 }
242
250 bool isSparse() const
251 {
252 return m_array.size();
253 }
254
263 const wxGridCellCoordsArray& getArray() const
264 {
265 return m_array;
266 }
267};
268
269#endif // GRIDCELLCOORDSCONTAINER_HPP
270
A class to simplify the access to different types of grid cell coords. Especially useful in the conte...
wxGridCellCoordsContainer(const wxArrayInt &selectedRowsOrCols, int otherDim, bool rowsSelected=true)
Construct a wxGridCellCoordsContainer from a set of indices for complete rows or columns.
const wxGridCellsExtent & getExtent() const
Get the maximal needed enclosing box in terms of wxGridCellCoordinates.
wxGridCellCoordsContainer()=default
Construct an empty wxGridCellCoordsContainer.
bool isSparse() const
Returns true, if the contained coordinates form a sparse matrix.
wxGridCellCoordsContainer(const wxGridCellCoords &topleft, const wxGridCellCoords &bottomright)
Construct a wxGridCellCoordsContainer from an upperleft and a lowerright coordinate pair.
bool contains(const wxGridCellCoords &cell) const
Does this wxGridCellCoordsContainer contain the passed coordinates?
const wxGridCellCoordsArray & getArray() const
Get a reference to the internal wxGridCellCoordsArray (only available, if the contained coordinates f...
bool isBlock() const
Returns true, if the contained coordinates actually form a contigious block.
bool columnsSelected() const
Returns true, if the contained coordinates originated from complete columns.
wxGridCellCoordsContainer(const wxGridCellCoordsArray &selected)
Construct a wxGridCellCoordsContainer from a list of selected grid coordinates.
bool contains(int row, int col) const
Does this wxGridCellCoordsContainer contain the passed coordinates?
size_t getRows() const
Get the number of enclosed rows.
size_t getCols() const
Get the number of enclosed columns.
#define min(a, b)
Definition: resampler.cpp:34
#define max(a, b)
Definition: resampler.cpp:30
A simple structure to define the needed grid space to enclose all cells contained in the wxGridCellCo...
wxGridCellCoords m_bottomright