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 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_TABLE_H
21#define PCB_TABLE_H
22
23
24#include <pcb_tablecell.h>
25#include <board_item.h>
27#include <algorithm>
28
29namespace KIGFX
30{
31class RENDER_SETTINGS;
32};
33
34
36{
37public:
38 PCB_TABLE( BOARD_ITEM* aParent, int aLineWidth );
39
40 PCB_TABLE( BOARD_ITEM* aParent );
41
42 PCB_TABLE( const PCB_TABLE& aTable );
43
44 ~PCB_TABLE();
45
46 // If implemented, would need to copy m_cells list.
47 PCB_TABLE& operator=( const PCB_TABLE& ) = delete;
48
49 static inline bool ClassOf( const EDA_ITEM* aItem )
50 {
51 return aItem && PCB_TABLE_T == aItem->Type();
52 }
53
54 virtual wxString GetClass() const override
55 {
56 return wxT( "PCB_TABLE" );
57 }
58
59 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
60 bool StrokeExternal() const { return m_strokeExternal; }
61
62 void SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
64
65 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
66 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
67
68 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
69 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
70
71 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
73 {
74 if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
75 return LINE_STYLE::SOLID;
76 else
77 return m_borderStroke.GetLineStyle();
78 }
79
80 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
81 COLOR4D GetBorderColor() const { return m_borderStroke.GetColor(); }
82
83 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
85
86 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
87 int GetSeparatorsWidth() const { return m_separatorsStroke.GetWidth(); }
88
89 void SetSeparatorsStyle( const LINE_STYLE aStyle ) { m_separatorsStroke.SetLineStyle( aStyle ); }
91 {
92 if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
93 return LINE_STYLE::SOLID;
94 else
95 return m_separatorsStroke.GetLineStyle();
96 }
97
98 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
99 COLOR4D GetSeparatorsColor() const { return m_separatorsStroke.GetColor(); }
100
101 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
102 bool StrokeColumns() const { return m_strokeColumns; }
103
104 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
105 bool StrokeRows() const { return m_strokeRows; }
106
107 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
108
109 void SetLayer( PCB_LAYER_ID aLayer ) override;
110 void SetPosition( const VECTOR2I& aPos ) override;
111 VECTOR2I GetPosition() const override;
112 VECTOR2I GetEnd() const;
113
114 // For property manager:
115 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
116 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
117 int GetPositionX() const { return GetPosition().x; }
118 int GetPositionY() const { return GetPosition().y; }
119
120 void SetColCount( int aCount ) { m_colCount = aCount; }
121 int GetColCount() const { return m_colCount; }
122
123 int GetRowCount() const
124 {
125 // Guarded because a hand-edited or third-party file can present a table with no
126 // columns, and dividing by it crashes the writer rather than failing the load
127 return m_colCount > 0 ? (int) m_cells.size() / m_colCount : 0;
128 }
129
130 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
131
132 int GetColWidth( int aCol ) const
133 {
134 if( m_colWidths.count( aCol ) )
135 return m_colWidths.at( aCol );
136
137 return 0;
138 }
139
140 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
141
142 int GetRowHeight( int aRow ) const
143 {
144 if( m_rowHeights.count( aRow ) )
145 return m_rowHeights.at( aRow );
146
147 return 0;
148 }
149
150 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
151 {
152 int idx = aRow * m_colCount + aCol;
153
154 if( idx < (int) m_cells.size() )
155 return m_cells[ idx ];
156 else
157 return nullptr;
158 }
159
160 std::vector<PCB_TABLECELL*> GetCells() const
161 {
162 return m_cells;
163 }
164
165 void AddCell( PCB_TABLECELL* aCell )
166 {
167 m_cells.push_back( aCell );
168 aCell->SetLayer( GetLayer() );
169 aCell->SetParent( this );
170 }
171
172 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
173 {
174 m_cells.insert( m_cells.begin() + aIdx, aCell );
175 aCell->SetLayer( GetLayer() );
176 aCell->SetParent( this );
177 }
178
185 void ResizeCells( int aRows, int aCols );
186
188 {
189 for( PCB_TABLECELL* cell : m_cells )
190 delete cell;
191
192 m_cells.clear();
193 }
194
196 {
197 std::erase_if( m_cells,
198 []( PCB_TABLECELL* cell )
199 {
200 if( cell->GetFlags() & STRUCT_DELETED )
201 {
202 delete cell;
203 return true;
204 }
205 return false;
206 } );
207 }
208
210 bool aSkipConnectivity = false ) override
211 {
212 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
213 }
214
215 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
216 {
217 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
218 }
219
220 void Normalize() override;
221
222 void Autosize();
223
224 void Move( const VECTOR2I& aMoveVector ) override;
225
226 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
227
228 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
229
230 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
231
232 void OnFootprintTransformed() override;
233
234 void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
235 const EDA_ANGLE& aParentRotate ) override;
236
237 const BOX2I GetBoundingBox() const override;
238
239 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
240
241 void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
242 const STROKE_PARAMS& aStroke )>& aCallback ) const;
243
244 // @copydoc BOARD_ITEM::GetEffectiveShape
245 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
247 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const override;
248
249 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
250 int aMaxError, ERROR_LOC aErrorLoc,
251 bool aIgnoreLineWidth = false ) const override;
252
264 int aClearance, int aError, ERROR_LOC aErrorLoc,
265 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const override;
266
270 void TransformGraphicItemsToPolySet( SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc,
271 KIGFX::RENDER_SETTINGS* aRenderSettings ) const;
272
273 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
274 const std::vector<KICAD_T>& aScanTypes ) override;
275
276 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
277 {
278 // Symbols are searchable via the child field and pin item text.
279 return false;
280 }
281
282 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
283
284 BITMAPS GetMenuImage() const override;
285
286 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
287
288 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
289
290 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
291
292 EDA_ITEM* Clone() const override
293 {
294 return new PCB_TABLE( *this );
295 }
296
297 BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const override;
298
299 void CopyFrom( const BOARD_ITEM* aOther ) override;
300
301 void Serialize( google::protobuf::Any &aContainer ) const override;
302 bool Deserialize( const google::protobuf::Any &aContainer ) override;
303
304 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
305
306 double Similarity( const BOARD_ITEM& aOther ) const override;
307
308 bool operator==( const PCB_TABLE& aOther ) const;
309 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
310
311 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
312
313#if defined(DEBUG)
314 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
315#endif
316
317protected:
321 PCB_TABLE( BOARD_ITEM* aParent, KICAD_T aType, int aLineWidth );
322
323 virtual void swapData( BOARD_ITEM* aImage ) override;
324
331
333 std::map<int, int> m_colWidths;
334 std::map<int, int> m_rowHeights;
335 std::vector<PCB_TABLECELL*> m_cells;
336};
337
338
339#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...
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
BOARD_ITEM_CONTAINER(BOARD_ITEM *aParent, KICAD_T aType)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const override
Create a copy of this BOARD_ITEM.
VECTOR2I GetEnd() const
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
STROKE_PARAMS m_separatorsStroke
Definition pcb_table.h:330
bool StrokeRows() const
Definition pcb_table.h:105
void ClearCells()
Definition pcb_table.h:187
int GetRowCount() const
Definition pcb_table.h:123
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_table.h:49
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition pcb_table.h:215
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void TransformGraphicItemsToPolySet(SHAPE_POLY_SET &aBuffer, int aMaxError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings) const
Convert graphic items (segments and texts) to a set of polygonal shapes.
std::vector< PCB_TABLECELL * > m_cells
Definition pcb_table.h:335
void SetColWidth(int aCol, int aWidth)
Definition pcb_table.h:130
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
int m_colCount
Definition pcb_table.h:332
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
bool m_strokeRows
Definition pcb_table.h:328
void Move(const VECTOR2I &aMoveVector) override
Move this object.
int GetPositionY() const
Definition pcb_table.h:118
bool StrokeHeaderSeparator() const
Definition pcb_table.h:63
bool StrokeColumns() const
Definition pcb_table.h:102
void SetBorderStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:71
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition pcb_table.h:62
void SetSeparatorsColor(const COLOR4D &aColor)
Definition pcb_table.h:98
bool m_strokeExternal
Definition pcb_table.h:325
STROKE_PARAMS m_borderStroke
Definition pcb_table.h:327
bool m_strokeColumns
Definition pcb_table.h:329
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void ResizeCells(int aRows, int aCols)
Grow or shrink to aRows x aCols, keeping the cells that already exist.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool StrokeExternal() const
Definition pcb_table.h:60
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
int GetSeparatorsWidth() const
Definition pcb_table.h:87
void SetPositionX(int x)
Definition pcb_table.h:115
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
void SetStrokeExternal(bool aDoStroke)
Definition pcb_table.h:59
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition pcb_table.h:150
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:160
void Autosize()
int GetBorderWidth() const
Definition pcb_table.h:69
COLOR4D GetBorderColor() const
Definition pcb_table.h:81
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const override
Convert the TABLE shape to a polyset.
bool operator==(const PCB_TABLE &aOther) const
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...
int GetColCount() const
Definition pcb_table.h:121
void SetStrokeColumns(bool aDoStroke)
Definition pcb_table.h:101
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition pcb_table.h:84
std::map< int, int > m_colWidths
Definition pcb_table.h:333
virtual void swapData(BOARD_ITEM *aImage) override
int GetPositionX() const
Definition pcb_table.h:117
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
void AddCell(PCB_TABLECELL *aCell)
Definition pcb_table.h:165
const STROKE_PARAMS & GetBorderStroke() const
Definition pcb_table.h:66
void SetPositionY(int y)
Definition pcb_table.h:116
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void SetStrokeRows(bool aDoStroke)
Definition pcb_table.h:104
bool m_StrokeHeaderSeparator
Definition pcb_table.h:326
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition pcb_table.h:172
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
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:209
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_table.h:292
PCB_TABLE & operator=(const PCB_TABLE &)=delete
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
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.
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
LINE_STYLE GetBorderStyle() const
Definition pcb_table.h:72
void DeleteMarkedCells()
Definition pcb_table.h:195
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
void SetColCount(int aCount)
Definition pcb_table.h:120
int GetColWidth(int aCol) const
Definition pcb_table.h:132
VECTOR2I GetPosition() const override
void SetSeparatorsWidth(int aWidth)
Definition pcb_table.h:86
COLOR4D GetSeparatorsColor() const
Definition pcb_table.h:99
void CopyFrom(const BOARD_ITEM *aOther) override
Definition pcb_table.cpp:94
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition pcb_table.h:276
virtual wxString GetClass() const override
Return the class name.
Definition pcb_table.h:54
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
LINE_STYLE GetSeparatorsStyle() const
Definition pcb_table.h:90
void SetBorderColor(const COLOR4D &aColor)
Definition pcb_table.h:80
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:55
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:89
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:83
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 SetRowHeight(int aRow, int aHeight)
Definition pcb_table.h:140
void SetPosition(const VECTOR2I &aPos) override
void SetBorderWidth(int aWidth)
Definition pcb_table.h:68
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:65
int GetRowHeight(int aRow) const
Definition pcb_table.h:142
std::map< int, int > m_rowHeights
Definition pcb_table.h:334
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
RECURSE_MODE
Definition eda_item.h:50
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
#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:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
FLIP_DIRECTION
Definition mirror.h:23
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
LINE_STYLE
Dashed line types.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683