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( const PCB_TABLE& aTable );
41
42 ~PCB_TABLE();
43
44 // If implemented, would need to copy m_cells list.
45 PCB_TABLE& operator=( const PCB_TABLE& ) = delete;
46
47 static inline bool ClassOf( const EDA_ITEM* aItem )
48 {
49 return aItem && PCB_TABLE_T == aItem->Type();
50 }
51
52 virtual wxString GetClass() const override
53 {
54 return wxT( "PCB_TABLE" );
55 }
56
57 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
58 bool StrokeExternal() const { return m_strokeExternal; }
59
60 void SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
62
63 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
64 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
65
66 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
67 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
68
69 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
71 {
72 if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
73 return LINE_STYLE::SOLID;
74 else
75 return m_borderStroke.GetLineStyle();
76 }
77
78 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
79 COLOR4D GetBorderColor() const { return m_borderStroke.GetColor(); }
80
81 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
83
84 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
85 int GetSeparatorsWidth() const { return m_separatorsStroke.GetWidth(); }
86
87 void SetSeparatorsStyle( const LINE_STYLE aStyle ) { m_separatorsStroke.SetLineStyle( aStyle ); }
89 {
90 if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
91 return LINE_STYLE::SOLID;
92 else
93 return m_separatorsStroke.GetLineStyle();
94 }
95
96 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
97 COLOR4D GetSeparatorsColor() const { return m_separatorsStroke.GetColor(); }
98
99 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
100 bool StrokeColumns() const { return m_strokeColumns; }
101
102 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
103 bool StrokeRows() const { return m_strokeRows; }
104
105 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
106
107 void SetLayer( PCB_LAYER_ID aLayer ) override;
108 void SetPosition( const VECTOR2I& aPos ) override;
109 VECTOR2I GetPosition() const override;
110 VECTOR2I GetEnd() const;
111
112 // For property manager:
113 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
114 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
115 int GetPositionX() const { return GetPosition().x; }
116 int GetPositionY() const { return GetPosition().y; }
117
118 void SetColCount( int aCount ) { m_colCount = aCount; }
119 int GetColCount() const { return m_colCount; }
120
121 int GetRowCount() const
122 {
123 return m_cells.size() / m_colCount;
124 }
125
126 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
127
128 int GetColWidth( int aCol ) const
129 {
130 if( m_colWidths.count( aCol ) )
131 return m_colWidths.at( aCol );
132
133 return 0;
134 }
135
136 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
137
138 int GetRowHeight( int aRow ) const
139 {
140 if( m_rowHeights.count( aRow ) )
141 return m_rowHeights.at( aRow );
142
143 return 0;
144 }
145
146 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
147 {
148 int idx = aRow * m_colCount + aCol;
149
150 if( idx < (int) m_cells.size() )
151 return m_cells[ idx ];
152 else
153 return nullptr;
154 }
155
156 std::vector<PCB_TABLECELL*> GetCells() const
157 {
158 return m_cells;
159 }
160
161 void AddCell( PCB_TABLECELL* aCell )
162 {
163 m_cells.push_back( aCell );
164 aCell->SetLayer( GetLayer() );
165 aCell->SetParent( this );
166 }
167
168 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
169 {
170 m_cells.insert( m_cells.begin() + aIdx, aCell );
171 aCell->SetLayer( GetLayer() );
172 aCell->SetParent( this );
173 }
174
176 {
177 for( PCB_TABLECELL* cell : m_cells )
178 delete cell;
179
180 m_cells.clear();
181 }
182
184 {
185 std::erase_if( m_cells,
186 []( PCB_TABLECELL* cell )
187 {
188 if( cell->GetFlags() & STRUCT_DELETED )
189 {
190 delete cell;
191 return true;
192 }
193 return false;
194 } );
195 }
196
198 bool aSkipConnectivity = false ) override
199 {
200 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
201 }
202
203 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
204 {
205 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
206 }
207
208 void Normalize() override;
209
210 void Autosize();
211
212 void Move( const VECTOR2I& aMoveVector ) override;
213
214 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
215
216 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
217
218 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
219
220 void OnFootprintTransformed() override;
221
222 void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
223 const EDA_ANGLE& aParentRotate ) override;
224
225 const BOX2I GetBoundingBox() const override;
226
227 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
228
229 void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
230 const STROKE_PARAMS& aStroke )>& aCallback ) const;
231
232 // @copydoc BOARD_ITEM::GetEffectiveShape
233 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
234 FLASHING aFlash = FLASHING::DEFAULT ) const override;
235
236 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
237 int aMaxError, ERROR_LOC aErrorLoc,
238 bool aIgnoreLineWidth = false ) const override;
239
251 int aClearance, int aError, ERROR_LOC aErrorLoc,
252 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const override;
253
257 void TransformGraphicItemsToPolySet( SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc,
258 KIGFX::RENDER_SETTINGS* aRenderSettings ) const;
259
260 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
261 const std::vector<KICAD_T>& aScanTypes ) override;
262
263 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
264 {
265 // Symbols are searchable via the child field and pin item text.
266 return false;
267 }
268
269 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
270
271 BITMAPS GetMenuImage() const override;
272
273 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
274
275 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
276
277 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
278
279 EDA_ITEM* Clone() const override
280 {
281 return new PCB_TABLE( *this );
282 }
283
284 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
285
286 double Similarity( const BOARD_ITEM& aOther ) const override;
287
288 bool operator==( const PCB_TABLE& aOther ) const;
289 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
290
291 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
292
293#if defined(DEBUG)
294 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
295#endif
296
297protected:
298 virtual void swapData( BOARD_ITEM* aImage ) override;
299
300protected:
307
309 std::map<int, int> m_colWidths;
310 std::map<int, int> m_rowHeights;
311 std::vector<PCB_TABLECELL*> m_cells;
312};
313
314
315#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:918
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:81
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:83
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:155
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
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.
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:306
bool StrokeRows() const
Definition pcb_table.h:103
void ClearCells()
Definition pcb_table.h:175
int GetRowCount() const
Definition pcb_table.h:121
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_table.h:47
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition pcb_table.h:203
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:311
void SetColWidth(int aCol, int aWidth)
Definition pcb_table.h:126
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:308
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:304
void Move(const VECTOR2I &aMoveVector) override
Move this object.
int GetPositionY() const
Definition pcb_table.h:116
bool StrokeHeaderSeparator() const
Definition pcb_table.h:61
bool StrokeColumns() const
Definition pcb_table.h:100
void SetBorderStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:69
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition pcb_table.h:60
void SetSeparatorsColor(const COLOR4D &aColor)
Definition pcb_table.h:96
bool m_strokeExternal
Definition pcb_table.h:301
STROKE_PARAMS m_borderStroke
Definition pcb_table.h:303
bool m_strokeColumns
Definition pcb_table.h:305
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
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.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool StrokeExternal() const
Definition pcb_table.h:58
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
int GetSeparatorsWidth() const
Definition pcb_table.h:85
void SetPositionX(int x)
Definition pcb_table.h:113
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:57
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition pcb_table.h:146
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:156
void Autosize()
int GetBorderWidth() const
Definition pcb_table.h:67
COLOR4D GetBorderColor() const
Definition pcb_table.h:79
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:119
void SetStrokeColumns(bool aDoStroke)
Definition pcb_table.h:99
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition pcb_table.h:82
std::map< int, int > m_colWidths
Definition pcb_table.h:309
virtual void swapData(BOARD_ITEM *aImage) override
Definition pcb_table.cpp:75
int GetPositionX() const
Definition pcb_table.h:115
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
void AddCell(PCB_TABLECELL *aCell)
Definition pcb_table.h:161
const STROKE_PARAMS & GetBorderStroke() const
Definition pcb_table.h:64
void SetPositionY(int y)
Definition pcb_table.h:114
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void SetStrokeRows(bool aDoStroke)
Definition pcb_table.h:102
bool m_StrokeHeaderSeparator
Definition pcb_table.h:302
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition pcb_table.h:168
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:197
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_table.h:279
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:70
void DeleteMarkedCells()
Definition pcb_table.h:183
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
void SetColCount(int aCount)
Definition pcb_table.h:118
int GetColWidth(int aCol) const
Definition pcb_table.h:128
VECTOR2I GetPosition() const override
void SetSeparatorsWidth(int aWidth)
Definition pcb_table.h:84
COLOR4D GetSeparatorsColor() const
Definition pcb_table.h:97
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition pcb_table.h:263
virtual wxString GetClass() const override
Return the class name.
Definition pcb_table.h:52
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
LINE_STYLE GetSeparatorsStyle() const
Definition pcb_table.h:88
void SetBorderColor(const COLOR4D &aColor)
Definition pcb_table.h:78
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:35
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:87
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:81
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:136
void SetPosition(const VECTOR2I &aPos) override
void SetBorderWidth(int aWidth)
Definition pcb_table.h:66
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:63
int GetRowHeight(int aRow) const
Definition pcb_table.h:138
std::map< int, int > m_rowHeights
Definition pcb_table.h:310
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.
RECURSE_MODE
Definition eda_item.h:48
INSPECT_RESULT
Definition eda_item.h:42
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:89
#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:29
LINE_STYLE
Dashed line types.
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:87
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683