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 <map>
25#include <memory>
26#include <string>
27#include <vector>
28
30#include <pcb_table.h>
31
33
34
39{
40 std::string m_Key;
41 std::vector<wxString> m_Cells;
42};
43
44
49{
50 virtual ~GENERATED_TABLE_CONTENT() = default;
51
52 std::vector<GENERATED_TABLE_ROW> m_Rows;
53 std::vector<std::vector<wxString>> m_Trailer;
54};
55
56
66{
67public:
68 virtual const GENERATED_TABLE_SCHEMA& Schema() const = 0;
69
70 std::vector<GENERATED_TABLE_COLUMN>& Columns() { return m_columns; }
71 const std::vector<GENERATED_TABLE_COLUMN>& Columns() const { return m_columns; }
72
74 void SetUnits( GENERATED_TABLE_UNITS aUnits ) { m_units = aUnits; }
75
76 int GetPrecision() const { return m_precision; }
77
82 void SetPrecision( int aPrecision ) { m_precision = std::clamp( aPrecision, 0, 6 ); }
83
91 const std::map<int, std::string>& RowKeys() const { return m_rowKeys; }
92 std::map<int, std::string>& RowKeys() { return m_rowKeys; }
93
98 virtual bool IsStale( const BOARD& aBoard ) const;
99
108 void RebuildCells( const BOARD& aBoard, GENERATED_TABLE_REFRESH* aRefresh = nullptr );
109
113 virtual bool IsDataRow( int aRow ) const { return m_rowKeys.count( aRow ) > 0; }
114
115 INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData, const std::vector<KICAD_T>& aScanTypes ) override;
116
117protected:
118 PCB_GENERATED_TABLE( BOARD_ITEM* aParent, KICAD_T aType, int aLineWidth );
119
120 PCB_GENERATED_TABLE( const PCB_GENERATED_TABLE& aOther ) = default;
121
125 virtual std::unique_ptr<GENERATED_TABLE_CONTENT> generate( const BOARD& aBoard,
126 GENERATED_TABLE_REFRESH* aRefresh ) const = 0;
127
131 virtual void onRebuilt( const BOARD& aBoard, const GENERATED_TABLE_CONTENT& aContent ) {}
132
136 virtual void styleNewCell( PCB_TABLECELL* aCell, bool aIsHeading ) {}
137
138 void swapData( BOARD_ITEM* aImage ) override;
139
143 bool generatedEquals( const PCB_GENERATED_TABLE& aOther ) const;
144
145 std::vector<GENERATED_TABLE_COLUMN> m_columns;
148 std::map<int, std::string> m_rowKeys;
149
150private:
159 void migrateRows( int aRows, int aCols, const std::vector<std::string>& aNewRowKeys );
160};
161
162#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:84
friend class BOARD
Definition board_item.h:593
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
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 migrateRows(int aRows, int aCols, const std::vector< std::string > &aNewRowKeys)
Move each row's cells to the row that reports the same thing.
std::vector< GENERATED_TABLE_COLUMN > m_columns
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.
GENERATED_TABLE_UNITS m_units
PCB_GENERATED_TABLE(const PCB_GENERATED_TABLE &aOther)=default
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()
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.
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.
void SetPrecision(int aPrecision)
Clamped.
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()
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
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)
GENERATED_TABLE_UNITS GetUnits() const
void SetUnits(GENERATED_TABLE_UNITS aUnits)
std::map< int, std::string > m_rowKeys
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:55
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
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
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70