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>
31
32
34{
35public:
36 PCB_TABLE( BOARD_ITEM* aParent, int aLineWidth );
37
38 PCB_TABLE( const PCB_TABLE& aTable );
39
40 ~PCB_TABLE();
41
42 static inline bool ClassOf( const EDA_ITEM* aItem )
43 {
44 return aItem && PCB_TABLE_T == aItem->Type();
45 }
46
47 virtual wxString GetClass() const override
48 {
49 return wxT( "PCB_TABLE" );
50 }
51
52 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
53 bool StrokeExternal() const { return m_strokeExternal; }
54
55 void SetStrokeHeader( bool aDoStroke ) { m_strokeHeader = aDoStroke; }
56 bool StrokeHeader() const { return m_strokeHeader; }
57
58 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
59 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
60
61 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
62 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
63
64 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
66
67 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
69
70 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
72
73 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
75
78
79 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
81
82 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
83 bool StrokeColumns() const { return m_strokeColumns; }
84
85 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
86 bool StrokeRows() const { return m_strokeRows; }
87
88 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const override;
89
90 void SetPosition( const VECTOR2I& aPos ) override;
91 VECTOR2I GetPosition() const override;
92 VECTOR2I GetEnd() const;
93
94 // For property manager:
95 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
96 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
97 int GetPositionX() const { return GetPosition().x; }
98 int GetPositionY() const { return GetPosition().y; }
99
100 void SetOrientation( const EDA_ANGLE& aAngle ) { m_orientation = aAngle; }
102
103 void SetColCount( int aCount ) { m_colCount = aCount; }
104 int GetColCount() const { return m_colCount; }
105
106 int GetRowCount() const
107 {
108 return m_cells.size() / m_colCount;
109 }
110
111 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
112
113 int GetColWidth( int aCol ) const
114 {
115 if( m_colWidths.count( aCol ) )
116 return m_colWidths.at( aCol );
117
118 return 0;
119 }
120
121 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
122
123 int GetRowHeight( int aRow ) const
124 {
125 if( m_rowHeights.count( aRow ) )
126 return m_rowHeights.at( aRow );
127
128 return 0;
129 }
130
131 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
132 {
133 int idx = aRow * m_colCount + aCol;
134
135 if( idx < (int) m_cells.size() )
136 return m_cells[ idx ];
137 else
138 return nullptr;
139 }
140
141 std::vector<PCB_TABLECELL*> GetCells() const
142 {
143 return m_cells;
144 }
145
146 void AddCell( PCB_TABLECELL* aCell )
147 {
148 m_cells.push_back( aCell );
149 aCell->SetLayer( GetLayer() );
150 aCell->SetParent( this );
151 }
152
153 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
154 {
155 m_cells.insert( m_cells.begin() + aIdx, aCell );
156 aCell->SetLayer( GetLayer() );
157 aCell->SetParent( this );
158 }
159
161 {
162 for( PCB_TABLECELL* cell : m_cells )
163 delete cell;
164
165 m_cells.clear();
166 }
167
169 {
171 []( PCB_TABLECELL* cell )
172 {
173 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
174 } );
175 }
176
177 void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
178 bool aSkipConnectivity = false ) override
179 {
180 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
181 }
182
183 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
184 {
185 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
186 }
187
188 void Normalize() override;
189
190 void Move( const VECTOR2I& aMoveVector ) override;
191
192 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
193
194 void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
195
196 const BOX2I GetBoundingBox() const override;
197
198 // @copydoc BOARD_ITEM::GetEffectiveShape
199 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
200 FLASHING aFlash = FLASHING::DEFAULT ) const override;
201
202 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
203 int aMaxError, ERROR_LOC aErrorLoc,
204 bool aIgnoreLineWidth = false ) const override;
205
206 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
207 const std::vector<KICAD_T>& aScanTypes ) override;
208
209 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
210 {
211 // Symbols are searchable via the child field and pin item text.
212 return false;
213 }
214
215 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
216
217 BITMAPS GetMenuImage() const override;
218
219 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
220
221 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
222
223 EDA_ITEM* Clone() const override
224 {
225 return new PCB_TABLE( *this );
226 }
227
228 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
229
230 double Similarity( const BOARD_ITEM& aOther ) const override;
231
232 bool operator==( const PCB_TABLE& aOther ) const;
233 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
234
235 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
236
237#if defined(DEBUG)
238 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
239#endif
240
241protected:
242 virtual void swapData( BOARD_ITEM* aImage ) override;
243
244protected:
251
254 std::map<int, int> m_colWidths;
255 std::map<int, int> m_rowHeights;
256 std::vector<PCB_TABLECELL*> m_cells;
257};
258
259
260#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:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:240
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:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:130
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:317
VECTOR2I GetEnd() const
Definition: pcb_table.cpp:118
STROKE_PARAMS m_separatorsStroke
Definition: pcb_table.h:250
bool StrokeRows() const
Definition: pcb_table.h:86
void ClearCells()
Definition: pcb_table.h:160
int GetRowCount() const
Definition: pcb_table.h:106
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_table.h:42
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition: pcb_table.h:183
void SetOrientation(const EDA_ANGLE &aAngle)
Definition: pcb_table.h:100
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_table.cpp:242
std::vector< PCB_TABLECELL * > m_cells
Definition: pcb_table.h:256
void SetColWidth(int aCol, int aWidth)
Definition: pcb_table.h:111
int m_colCount
Definition: pcb_table.h:253
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:370
bool m_strokeRows
Definition: pcb_table.h:248
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_table.cpp:196
int GetPositionY() const
Definition: pcb_table.h:98
bool StrokeColumns() const
Definition: pcb_table.h:83
void SetBorderStyle(const LINE_STYLE aStyle)
Definition: pcb_table.h:64
void SetStrokeHeader(bool aDoStroke)
Definition: pcb_table.h:55
void SetSeparatorsColor(const COLOR4D &aColor)
Definition: pcb_table.h:79
bool m_strokeExternal
Definition: pcb_table.h:245
STROKE_PARAMS m_borderStroke
Definition: pcb_table.h:247
bool m_strokeColumns
Definition: pcb_table.h:249
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_table.cpp:358
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:253
bool StrokeExternal() const
Definition: pcb_table.h:53
int GetSeparatorsWidth() const
Definition: pcb_table.h:74
EDA_ANGLE m_orientation
Definition: pcb_table.h:252
void SetPositionX(int x)
Definition: pcb_table.h:95
void SetStrokeExternal(bool aDoStroke)
Definition: pcb_table.h:52
bool StrokeHeader() const
Definition: pcb_table.h:56
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition: pcb_table.h:131
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:141
int GetBorderWidth() const
Definition: pcb_table.h:62
COLOR4D GetBorderColor() const
Definition: pcb_table.h:68
bool operator==(const PCB_TABLE &aOther) const
Definition: pcb_table.cpp:452
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:333
int GetColCount() const
Definition: pcb_table.h:104
void SetStrokeColumns(bool aDoStroke)
Definition: pcb_table.h:82
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: pcb_table.h:71
std::map< int, int > m_colWidths
Definition: pcb_table.h:254
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_table.cpp:74
int GetPositionX() const
Definition: pcb_table.h:97
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
Definition: pcb_table.cpp:132
void AddCell(PCB_TABLECELL *aCell)
Definition: pcb_table.h:146
const STROKE_PARAMS & GetBorderStroke() const
Definition: pcb_table.h:59
void SetPositionY(int y)
Definition: pcb_table.h:96
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_table.cpp:364
void SetStrokeRows(bool aDoStroke)
Definition: pcb_table.h:85
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition: pcb_table.h:153
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:177
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_table.h:223
bool m_strokeHeader
Definition: pcb_table.h:246
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:494
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:316
LINE_STYLE GetBorderStyle() const
Definition: pcb_table.h:65
void DeleteMarkedCells()
Definition: pcb_table.h:168
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
Definition: pcb_table.cpp:400
void SetColCount(int aCount)
Definition: pcb_table.h:103
int GetColWidth(int aCol) const
Definition: pcb_table.h:113
VECTOR2I GetPosition() const override
Definition: pcb_table.cpp:112
void SetSeparatorsWidth(int aWidth)
Definition: pcb_table.h:73
COLOR4D GetSeparatorsColor() const
Definition: pcb_table.h:80
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_table.cpp:214
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_table.h:209
virtual wxString GetClass() const override
Return the class name.
Definition: pcb_table.h:47
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const override
Invoke a function on all children.
Definition: pcb_table.cpp:235
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_table.cpp:203
LINE_STYLE GetSeparatorsStyle() const
Definition: pcb_table.h:77
void SetBorderColor(const COLOR4D &aColor)
Definition: pcb_table.h:67
EDA_ANGLE GetOrientation() const
Definition: pcb_table.h:101
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition: pcb_table.h:76
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition: pcb_table.h:70
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:393
void SetRowHeight(int aRow, int aHeight)
Definition: pcb_table.h:121
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_table.cpp:106
void SetBorderWidth(int aWidth)
Definition: pcb_table.h:61
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition: pcb_table.h:58
int GetRowHeight(int aRow) const
Definition: pcb_table.h:123
std::map< int, int > m_rowHeights
Definition: pcb_table.h:255
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:82
#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< int32_t > VECTOR2I
Definition: vector2d.h:673