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