KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_generated_table.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef PCB_GENERATED_TABLE_H
21#define PCB_GENERATED_TABLE_H
22
23#include <algorithm>
24#include <functional>
25#include <map>
26#include <memory>
27#include <set>
28#include <string>
29#include <vector>
30
32#include <pcb_table.h>
33#include <pcb_tablecell.h>
34
36
37
42{
43 std::string m_Key;
44 std::vector<wxString> m_Cells;
45};
46
47
52{
53 virtual ~GENERATED_TABLE_CONTENT() = default;
54
55 std::vector<GENERATED_TABLE_ROW> m_Rows;
56 std::vector<std::vector<wxString>> m_Trailer;
57};
58
59
69{
70public:
71 virtual const GENERATED_TABLE_SCHEMA& Schema() const = 0;
72
77 std::vector<GENERATED_TABLE_COLUMN>& Columns() { return m_columns; }
78 const std::vector<GENERATED_TABLE_COLUMN>& Columns() const { return m_columns; }
79
83 std::vector<GENERATED_TABLE_COLUMN> AllColumns() const;
84
90 void SetColumns( std::vector<GENERATED_TABLE_COLUMN> aColumns );
91
96 void RestoreColumns( const std::vector<GENERATED_TABLE_COLUMN>& aColumns );
97
99 void SetUnits( GENERATED_TABLE_UNITS aUnits ) { m_units = aUnits; }
100
101 int GetPrecision() const { return m_precision; }
102
107 void SetPrecision( int aPrecision ) { m_precision = std::clamp( aPrecision, 0, GENERATED_TABLE_MAX_PRECISION ); }
108
114 int GetRowHeightProp() const;
115 void SetRowHeightProp( int aHeight );
116 bool RowHeightsDiffer() const;
117
121 void SetRowHeightToFit( int aRow, int aHeight );
122
126 wxString GetFontNameProp() const;
127 void SetFontNameProp( const wxString& aFontName );
128 bool FontNamesDiffer() const;
129
134 int GetFontSizeProp() const;
135 void SetFontSizeProp( int aSize );
136 bool FontSizesDiffer() const;
137
145 const std::map<int, std::string>& RowKeys() const { return m_rowKeys; }
146 std::map<int, std::string>& RowKeys() { return m_rowKeys; }
147
152 virtual bool IsStale( const BOARD& aBoard ) const;
153
162 void RebuildCells( const BOARD& aBoard, GENERATED_TABLE_REFRESH* aRefresh = nullptr );
163
170 virtual bool IsDataRow( int aRow ) const
171 {
172 if( m_rowKeys.empty() )
173 return aRow >= 1 && aRow < GetRowCount();
174
175 return m_rowKeys.count( aRow ) > 0;
176 }
177
178 INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData, const std::vector<KICAD_T>& aScanTypes ) override;
179
180 double Similarity( const BOARD_ITEM& aOther ) const override;
181
182 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
183
188 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
189
193 void CopyFrom( const BOARD_ITEM* aOther ) override;
194
199 virtual void ApplySettings( const PCB_GENERATED_TABLE& aOther );
200
201protected:
202 PCB_GENERATED_TABLE( BOARD_ITEM* aParent, KICAD_T aType, int aLineWidth );
203
205
209 virtual std::unique_ptr<GENERATED_TABLE_CONTENT> generate( const BOARD& aBoard,
210 GENERATED_TABLE_REFRESH* aRefresh ) const = 0;
211
215 virtual void onRebuilt( const BOARD& aBoard, const GENERATED_TABLE_CONTENT& aContent ) {}
216
221 virtual void onRowsMigrated() {}
222
226 virtual void styleNewCell( PCB_TABLECELL* aCell, bool aIsHeading ) {}
227
231 virtual void onColumnsReversed() {}
232
233 void swapData( BOARD_ITEM* aImage ) override;
234
241 void setAutosizedRowHeights( const std::vector<int>& aNeeded ) override;
242
246 bool generatedEquals( const PCB_GENERATED_TABLE& aOther ) const;
247
248 std::vector<GENERATED_TABLE_COLUMN> m_columns;
251 std::map<int, std::string> m_rowKeys;
252
253private:
258 {
260 int m_Position = 0;
261
262 bool operator==( const HIDDEN_COLUMN& aOther ) const = default;
263 };
264
265 enum class CELL_ORIGIN
266 {
270 };
271
276 {
277 int m_Rows = 0;
278 int m_OldCols = 0;
279 int m_NewCols = 0;
280 std::vector<PCB_TABLECELL*> m_Cells;
281 std::vector<CELL_ORIGIN> m_Origin;
282 std::vector<bool> m_Carried;
283 std::map<int, int> m_ColWidths;
284 };
285
289 void moveShownCells( const std::vector<GENERATED_TABLE_COLUMN>& aShown, COLUMN_REMAP& aRemap ) const;
290
295 void placeCells( COLUMN_REMAP& aRemap );
296
300 void styleCreatedCells( const std::vector<CELL_ORIGIN>& aOrigin );
301
305 std::vector<int> dataRows() const;
306
311 int metricRowHeight( int aRow ) const;
312
317 int minRowHeight( int aRow ) const;
318
322 const PCB_TABLECELL* nearestDataCell( int aRow, int aCol, const std::set<KIID>& aStyled ) const;
323
328 void styleFromColumn( PCB_TABLECELL* aCell, int aRow, int aCol, const std::set<KIID>& aStyled );
329
331 void forEachCell( const std::function<void( PCB_TABLECELL* )>& aFunc );
332
336 bool anyCell( const std::function<bool( const PCB_TABLECELL* )>& aTest ) const;
337
341 const PCB_TABLECELL* firstCell() const;
342
354 void migrateRows( int aRows, int aCols, const std::vector<std::string>& aNewRowKeys );
355
356 std::vector<HIDDEN_COLUMN> m_hidden;
357};
358
359#endif // PCB_GENERATED_TABLE_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
The base class for create windows for drawing purpose.
One pass of rebuilding tables.
The columns one generator (the drill chart, a stackup table, ...) can produce, and the units and prec...
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
void styleCreatedCells(const std::vector< CELL_ORIGIN > &aOrigin)
Style cells placeCells created from another cell in their row.
void SetFontNameProp(const wxString &aFontName)
void forEachCell(const std::function< void(PCB_TABLECELL *)> &aFunc)
Visit every shown cell.
int GetRowHeightProp() const
The first data row's height, with RowHeightsDiffer saying whether it speaks for every data row.
std::vector< HIDDEN_COLUMN > m_hidden
By position.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void migrateRows(int aRows, int aCols, const std::vector< std::string > &aNewRowKeys)
Move each row's cells to the row that reports the same thing.
void SetFontSizeProp(int aSize)
void placeCells(COLUMN_REMAP &aRemap)
Put every cell in the geometry its slot had, so the table stays where it was, creating those nothing ...
std::vector< GENERATED_TABLE_COLUMN > m_columns
const PCB_TABLECELL * nearestDataCell(int aRow, int aCol, const std::set< KIID > &aStyled) const
The nearest data cell in aCol among aStyled, or null when the column has none.
virtual void ApplySettings(const PCB_GENERATED_TABLE &aOther)
Take aOther's settings and placement but keep this table's cells, so formatting applied to them survi...
void setAutosizedRowHeights(const std::vector< int > &aNeeded) override
Row heights are the user's, carried by key through migrateRows.
std::vector< GENERATED_TABLE_COLUMN > AllColumns() const
Every column the table has been given, in order, with hidden ones marked by m_Visible.
virtual void onRebuilt(const BOARD &aBoard, const GENERATED_TABLE_CONTENT &aContent)
Called once the cells are laid out, with the content they were built from.
int metricRowHeight(int aRow) const
The height aRow needs by its cells' line count, line spacing, pen width and margins.
GENERATED_TABLE_UNITS m_units
const PCB_TABLECELL * firstCell() const
The first cell forEachCell visits, which the font getters speak for, or null.
void RestoreColumns(const std::vector< GENERATED_TABLE_COLUMN > &aColumns)
Replace the columns without touching any cell, for a loader whose cells already match the visible one...
void CopyFrom(const BOARD_ITEM *aOther) override
Copy everything a table of this kind holds, including what a subclass adds.
const std::map< int, std::string > & RowKeys() const
What each generated row reports on, by table row.
void RebuildCells(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh=nullptr)
Regenerate the cells from the board.
std::map< int, std::string > & RowKeys()
void styleFromColumn(PCB_TABLECELL *aCell, int aRow, int aCol, const std::set< KIID > &aStyled)
Give a new cell the text formatting of the nearest data cell in its column among aStyled,...
const std::vector< GENERATED_TABLE_COLUMN > & Columns() const
virtual std::unique_ptr< GENERATED_TABLE_CONTENT > generate(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh) const =0
The rows this table reports.
void moveShownCells(const std::vector< GENERATED_TABLE_COLUMN > &aShown, COLUMN_REMAP &aRemap) const
Carry each shown column's cells and width to its new position.
virtual bool IsDataRow(int aRow) const
True for a row that reports on the board, false for the heading and trailer rows.
virtual bool IsStale(const BOARD &aBoard) const
True when the cells no longer say what the board says.
std::vector< int > dataRows() const
The rows below the heading that IsDataRow accepts, in order.
void SetPrecision(int aPrecision)
Clamped.
virtual void onColumnsReversed()
Called once the columns have been reversed, for any column index a subclass keeps.
virtual void styleNewCell(PCB_TABLECELL *aCell, bool aIsHeading)
Called for each cell a rebuild creates, before its text is set.
std::vector< GENERATED_TABLE_COLUMN > & Columns()
The columns the table shows, which are the columns of its cells.
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
bool generatedEquals(const PCB_GENERATED_TABLE &aOther) const
Equality of the members this class owns and of the underlying PCB_TABLE.
void swapData(BOARD_ITEM *aImage) override
wxString GetFontNameProp() const
The first cell's font, with FontNamesDiffer saying whether it speaks for every shown cell.
void SetRowHeightProp(int aHeight)
void SetColumns(std::vector< GENERATED_TABLE_COLUMN > aColumns)
Replace the columns of a built table, moving each column's cells to where its id now sits so their fo...
virtual const GENERATED_TABLE_SCHEMA & Schema() const =0
INSPECT_RESULT Visit(INSPECTOR aInspector, void *aTestData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
PCB_GENERATED_TABLE(BOARD_ITEM *aParent, KICAD_T aType, int aLineWidth)
void SetRowHeightToFit(int aRow, int aHeight)
Set one row's height, no shorter than its text.
GENERATED_TABLE_UNITS GetUnits() const
@ MOVED
A shown column's cell, carried to its new column.
@ CREATED
New, including a cell in a column shown again.
@ EMPTY
Nothing filled the slot yet.
bool anyCell(const std::function< bool(const PCB_TABLECELL *)> &aTest) const
True when aTest holds for any cell forEachCell would visit, stopping at the first.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
PCB_TABLE::Flip reverses the columns in either direction, as it does for a plain table's text,...
virtual void onRowsMigrated()
Called once a rebuild has moved the rows to where the new content puts them, before anything asks whi...
int GetFontSizeProp() const
The first cell's text height, with FontSizesDiffer saying whether every shown cell has that size,...
void SetUnits(GENERATED_TABLE_UNITS aUnits)
int minRowHeight(int aRow) const
The smallest height aRow may take with its text still inside it.
std::map< int, std::string > m_rowKeys
int GetRowCount() const
Definition pcb_table.h:128
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:57
INSPECT_RESULT
Definition eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:91
GENERATED_TABLE_UNITS
constexpr int GENERATED_TABLE_MAX_PRECISION
The most digits a generated table prints after the decimal point.
FLIP_DIRECTION
Definition mirror.h:26
A column as a generated table actually carries it: what a row's cell in that column holds and how it ...
What a generated table reports, one entry per cell below the heading row.
virtual ~GENERATED_TABLE_CONTENT()=default
std::vector< std::vector< wxString > > m_Trailer
Unkeyed rows below the data, e.g. totals.
std::vector< GENERATED_TABLE_ROW > m_Rows
Keyed, below the heading row.
One data row of a generated table, and the identity its formatting follows across rebuilds.
std::vector< wxString > m_Cells
SetColumns' work in progress, laying the old cells out for the new columns.
std::vector< bool > m_Carried
Old cells that went somewhere, by old index.
std::vector< CELL_ORIGIN > m_Origin
Where each of m_Cells came from.
std::map< int, int > m_ColWidths
By new column.
std::vector< PCB_TABLECELL * > m_Cells
The new layout, row by row.
A hidden column and its place among all columns.
bool operator==(const HIDDEN_COLUMN &aOther) const =default
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708