KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_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 (C) 2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef PCB_TABLE_H
25#define PCB_TABLE_H
26
27
28#include <pcb_tablecell.h>
29#include <board_item.h>
30
31
33{
34public:
35 PCB_TABLE( BOARD_ITEM* aParent, int aLineWidth );
36
37 PCB_TABLE( const PCB_TABLE& aTable );
38
39 ~PCB_TABLE();
40
41 static inline bool ClassOf( const EDA_ITEM* aItem )
42 {
43 return aItem && PCB_TABLE_T == aItem->Type();
44 }
45
46 virtual wxString GetClass() const override
47 {
48 return wxT( "PCB_TABLE" );
49 }
50
51 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
52 bool StrokeExternal() const { return m_strokeExternal; }
53
54 void SetStrokeHeader( bool aDoStroke ) { m_strokeHeader = aDoStroke; }
55 bool StrokeHeader() const { return m_strokeHeader; }
56
57 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
58 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
59
60 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
61 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
62
63 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
65
66 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
68
69 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
71
72 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
74
77
78 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
80
81 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
82 bool StrokeColumns() const { return m_strokeColumns; }
83
84 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
85 bool StrokeRows() const { return m_strokeRows; }
86
87 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const override;
88
89 void SetPosition( const VECTOR2I& aPos ) override;
90 VECTOR2I GetPosition() const override;
91 VECTOR2I GetEnd() const;
92
93 // For property manager:
94 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
95 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
96 int GetPositionX() const { return GetPosition().x; }
97 int GetPositionY() const { return GetPosition().y; }
98
99 void SetColCount( int aCount ) { m_colCount = aCount; }
100 int GetColCount() const { return m_colCount; }
101
102 int GetRowCount() const
103 {
104 return m_cells.size() / m_colCount;
105 }
106
107 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
108
109 int GetColWidth( int aCol ) const
110 {
111 if( m_colWidths.count( aCol ) )
112 return m_colWidths.at( aCol );
113
114 return 0;
115 }
116
117 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
118
119 int GetRowHeight( int aRow ) const
120 {
121 if( m_rowHeights.count( aRow ) )
122 return m_rowHeights.at( aRow );
123
124 return 0;
125 }
126
127 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
128 {
129 int idx = aRow * m_colCount + aCol;
130
131 if( idx < (int) m_cells.size() )
132 return m_cells[ idx ];
133 else
134 return nullptr;
135 }
136
137 std::vector<PCB_TABLECELL*> GetCells() const
138 {
139 return m_cells;
140 }
141
142 void AddCell( PCB_TABLECELL* aCell )
143 {
144 m_cells.push_back( aCell );
145 aCell->SetLayer( GetLayer() );
146 aCell->SetParent( this );
147 }
148
149 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
150 {
151 m_cells.insert( m_cells.begin() + aIdx, aCell );
152 aCell->SetLayer( GetLayer() );
153 aCell->SetParent( this );
154 }
155
157 {
158 for( PCB_TABLECELL* cell : m_cells )
159 delete cell;
160
161 m_cells.clear();
162 }
163
165 {
167 []( PCB_TABLECELL* cell )
168 {
169 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
170 } );
171 }
172
173 void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
174 bool aSkipConnectivity = false ) override
175 {
176 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
177 }
178
179 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
180 {
181 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
182 }
183
184 void Normalize() override;
185
186 void Move( const VECTOR2I& aMoveVector ) override;
187
188 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
189
190 void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
191
192 const BOX2I GetBoundingBox() const override;
193
194 // @copydoc BOARD_ITEM::GetEffectiveShape
195 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
196 FLASHING aFlash = FLASHING::DEFAULT ) const override;
197
198 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
199 int aMaxError, ERROR_LOC aErrorLoc,
200 bool aIgnoreLineWidth = false ) const override;
201
202 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
203 const std::vector<KICAD_T>& aScanTypes ) override;
204
205 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
206 {
207 // Symbols are searchable via the child field and pin item text.
208 return false;
209 }
210
211 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
212
213 BITMAPS GetMenuImage() const override;
214
215 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
216
217 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
218
219 EDA_ITEM* Clone() const override
220 {
221 return new PCB_TABLE( *this );
222 }
223
224 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
225
226 double Similarity( const BOARD_ITEM& aOther ) const override;
227
228 bool operator==( const BOARD_ITEM& aOther ) const override;
229
230 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
231
232#if defined(DEBUG)
233 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
234#endif
235
236protected:
237 virtual void swapData( BOARD_ITEM* aImage ) override;
238
239protected:
246
248 std::map<int, int> m_colWidths;
249 std::map<int, int> m_rowHeights;
250 std::vector<PCB_TABLECELL*> m_cells;
251};
252
253
254#endif /* PCB_TABLE_H */
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:103
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:129
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:314
VECTOR2I GetEnd() const
Definition: pcb_table.cpp:114
STROKE_PARAMS m_separatorsStroke
Definition: pcb_table.h:245
bool StrokeRows() const
Definition: pcb_table.h:85
void ClearCells()
Definition: pcb_table.h:156
bool operator==(const BOARD_ITEM &aOther) const override
Definition: pcb_table.cpp:420
int GetRowCount() const
Definition: pcb_table.h:102
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_table.h:41
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition: pcb_table.h:179
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_table.cpp:221
std::vector< PCB_TABLECELL * > m_cells
Definition: pcb_table.h:250
void SetColWidth(int aCol, int aWidth)
Definition: pcb_table.h:107
int m_colCount
Definition: pcb_table.h:247
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_table.cpp:349
bool m_strokeRows
Definition: pcb_table.h:243
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_table.cpp:177
int GetPositionY() const
Definition: pcb_table.h:97
bool StrokeColumns() const
Definition: pcb_table.h:82
void SetBorderStyle(const LINE_STYLE aStyle)
Definition: pcb_table.h:63
void SetStrokeHeader(bool aDoStroke)
Definition: pcb_table.h:54
void SetSeparatorsColor(const COLOR4D &aColor)
Definition: pcb_table.h:78
bool m_strokeExternal
Definition: pcb_table.h:240
STROKE_PARAMS m_borderStroke
Definition: pcb_table.h:242
bool m_strokeColumns
Definition: pcb_table.h:244
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_table.cpp:232
bool StrokeExternal() const
Definition: pcb_table.h:52
int GetSeparatorsWidth() const
Definition: pcb_table.h:73
void SetPositionX(int x)
Definition: pcb_table.h:94
void SetStrokeExternal(bool aDoStroke)
Definition: pcb_table.h:51
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: pcb_table.cpp:337
bool StrokeHeader() const
Definition: pcb_table.h:55
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition: pcb_table.h:127
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:137
int GetBorderWidth() const
Definition: pcb_table.h:61
COLOR4D GetBorderColor() const
Definition: pcb_table.h:67
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, 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...
Definition: pcb_table.cpp:312
int GetColCount() const
Definition: pcb_table.h:100
void SetStrokeColumns(bool aDoStroke)
Definition: pcb_table.h:81
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: pcb_table.h:70
std::map< int, int > m_colWidths
Definition: pcb_table.h:248
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_table.cpp:71
int GetPositionX() const
Definition: pcb_table.h:96
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
Definition: pcb_table.cpp:128
void AddCell(PCB_TABLECELL *aCell)
Definition: pcb_table.h:142
const STROKE_PARAMS & GetBorderStroke() const
Definition: pcb_table.h:58
void SetPositionY(int y)
Definition: pcb_table.h:95
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_table.cpp:343
void SetStrokeRows(bool aDoStroke)
Definition: pcb_table.h:84
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition: pcb_table.h:149
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
Definition: pcb_table.h:173
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_table.h:219
bool m_strokeHeader
Definition: pcb_table.h:241
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_table.cpp:446
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
Definition: pcb_table.cpp:295
LINE_STYLE GetBorderStyle() const
Definition: pcb_table.h:64
void DeleteMarkedCells()
Definition: pcb_table.h:164
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
Definition: pcb_table.cpp:379
void SetColCount(int aCount)
Definition: pcb_table.h:99
int GetColWidth(int aCol) const
Definition: pcb_table.h:109
VECTOR2I GetPosition() const override
Definition: pcb_table.cpp:108
void SetSeparatorsWidth(int aWidth)
Definition: pcb_table.h:72
COLOR4D GetSeparatorsColor() const
Definition: pcb_table.h:79
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_table.cpp:193
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_table.h:205
virtual wxString GetClass() const override
Return the class name.
Definition: pcb_table.h:46
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const override
Invoke a function on all children.
Definition: pcb_table.cpp:214
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_table.cpp:184
LINE_STYLE GetSeparatorsStyle() const
Definition: pcb_table.h:76
void SetBorderColor(const COLOR4D &aColor)
Definition: pcb_table.h:66
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition: pcb_table.h:75
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition: pcb_table.h:69
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.
Definition: pcb_table.cpp:372
void SetRowHeight(int aRow, int aHeight)
Definition: pcb_table.h:117
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_table.cpp:102
void SetBorderWidth(int aWidth)
Definition: pcb_table.h:60
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition: pcb_table.h:57
int GetRowHeight(int aRow) const
Definition: pcb_table.h:119
std::map< int, int > m_rowHeights
Definition: pcb_table.h:249
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
int GetWidth() const
Definition: stroke_params.h:91
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:81
#define STRUCT_DELETED
flag indication structures to be erased
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:149
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
Definition: kicad_algo.h:174
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588