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 SetColCount( int aCount ) { m_colCount = aCount; }
101 int GetColCount() const { return m_colCount; }
102
103 int GetRowCount() const
104 {
105 return m_cells.size() / m_colCount;
106 }
107
108 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
109
110 int GetColWidth( int aCol ) const
111 {
112 if( m_colWidths.count( aCol ) )
113 return m_colWidths.at( aCol );
114
115 return 0;
116 }
117
118 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
119
120 int GetRowHeight( int aRow ) const
121 {
122 if( m_rowHeights.count( aRow ) )
123 return m_rowHeights.at( aRow );
124
125 return 0;
126 }
127
128 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
129 {
130 int idx = aRow * m_colCount + aCol;
131
132 if( idx < (int) m_cells.size() )
133 return m_cells[ idx ];
134 else
135 return nullptr;
136 }
137
138 std::vector<PCB_TABLECELL*> GetCells() const
139 {
140 return m_cells;
141 }
142
143 void AddCell( PCB_TABLECELL* aCell )
144 {
145 m_cells.push_back( aCell );
146 aCell->SetLayer( GetLayer() );
147 aCell->SetParent( this );
148 }
149
150 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
151 {
152 m_cells.insert( m_cells.begin() + aIdx, aCell );
153 aCell->SetLayer( GetLayer() );
154 aCell->SetParent( this );
155 }
156
158 {
159 for( PCB_TABLECELL* cell : m_cells )
160 delete cell;
161
162 m_cells.clear();
163 }
164
166 {
168 []( PCB_TABLECELL* cell )
169 {
170 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
171 } );
172 }
173
174 void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
175 bool aSkipConnectivity = false ) override
176 {
177 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
178 }
179
180 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
181 {
182 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
183 }
184
185 void Normalize() override;
186
187 void Move( const VECTOR2I& aMoveVector ) override;
188
189 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
190
191 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
192
193 const BOX2I GetBoundingBox() const override;
194
195 // @copydoc BOARD_ITEM::GetEffectiveShape
196 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
197 FLASHING aFlash = FLASHING::DEFAULT ) const override;
198
199 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
200 int aMaxError, ERROR_LOC aErrorLoc,
201 bool aIgnoreLineWidth = false ) const override;
202
203 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
204 const std::vector<KICAD_T>& aScanTypes ) override;
205
206 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
207 {
208 // Symbols are searchable via the child field and pin item text.
209 return false;
210 }
211
212 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
213
214 BITMAPS GetMenuImage() const override;
215
216 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
217
218 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
219
220 EDA_ITEM* Clone() const override
221 {
222 return new PCB_TABLE( *this );
223 }
224
225 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
226
227 double Similarity( const BOARD_ITEM& aOther ) const override;
228
229 bool operator==( const PCB_TABLE& aOther ) const;
230 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
231
232 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
233
234#if defined(DEBUG)
235 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
236#endif
237
238protected:
239 virtual void swapData( BOARD_ITEM* aImage ) override;
240
241protected:
248
250 std::map<int, int> m_colWidths;
251 std::map<int, int> m_rowHeights;
252 std::vector<PCB_TABLECELL*> m_cells;
253};
254
255
256#endif /* PCB_TABLE_H */
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
Definition: approximation.h:32
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:237
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:170
VECTOR2I GetEnd() const
Definition: pcb_table.cpp:116
STROKE_PARAMS m_separatorsStroke
Definition: pcb_table.h:247
bool StrokeRows() const
Definition: pcb_table.h:86
void ClearCells()
Definition: pcb_table.h:157
int GetRowCount() const
Definition: pcb_table.h:103
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:180
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_table.cpp:233
std::vector< PCB_TABLECELL * > m_cells
Definition: pcb_table.h:252
void SetColWidth(int aCol, int aWidth)
Definition: pcb_table.h:108
int m_colCount
Definition: pcb_table.h:249
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:361
bool m_strokeRows
Definition: pcb_table.h:245
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_table.cpp:181
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:242
STROKE_PARAMS m_borderStroke
Definition: pcb_table.h:244
bool m_strokeColumns
Definition: pcb_table.h:246
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_table.cpp:349
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:244
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_table.cpp:205
bool StrokeExternal() const
Definition: pcb_table.h:53
int GetSeparatorsWidth() const
Definition: pcb_table.h:74
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:128
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:138
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:443
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:324
int GetColCount() const
Definition: pcb_table.h:101
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:250
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_table.cpp:73
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:130
void AddCell(PCB_TABLECELL *aCell)
Definition: pcb_table.h:143
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:355
void SetStrokeRows(bool aDoStroke)
Definition: pcb_table.h:85
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition: pcb_table.h:150
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:174
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_table.h:220
bool m_strokeHeader
Definition: pcb_table.h:243
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:482
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:307
LINE_STYLE GetBorderStyle() const
Definition: pcb_table.h:65
void DeleteMarkedCells()
Definition: pcb_table.h:165
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
Definition: pcb_table.cpp:391
void SetColCount(int aCount)
Definition: pcb_table.h:100
int GetColWidth(int aCol) const
Definition: pcb_table.h:110
VECTOR2I GetPosition() const override
Definition: pcb_table.cpp:110
void SetSeparatorsWidth(int aWidth)
Definition: pcb_table.h:73
COLOR4D GetSeparatorsColor() const
Definition: pcb_table.h:80
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_table.h:206
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:226
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_table.cpp:188
LINE_STYLE GetSeparatorsStyle() const
Definition: pcb_table.h:77
void SetBorderColor(const COLOR4D &aColor)
Definition: pcb_table.h:67
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:384
void SetRowHeight(int aRow, int aHeight)
Definition: pcb_table.h:118
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_table.cpp:104
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:120
std::map< int, int > m_rowHeights
Definition: pcb_table.h:251
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
int GetWidth() const
Definition: stroke_params.h:89
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:93
void SetWidth(int aWidth)
Definition: stroke_params.h:90
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:96
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:92
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:95
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
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
FLIP_DIRECTION
Definition: mirror.h:27
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:46
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691