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
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 if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
68 return LINE_STYLE::SOLID;
69 else
71 }
72
73 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
75
76 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
78
79 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
81
84 {
85 if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
86 return LINE_STYLE::SOLID;
87 else
89 }
90
91 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
93
94 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
95 bool StrokeColumns() const { return m_strokeColumns; }
96
97 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
98 bool StrokeRows() const { return m_strokeRows; }
99
100 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const override;
101
102 void SetPosition( const VECTOR2I& aPos ) override;
103 VECTOR2I GetPosition() const override;
104 VECTOR2I GetEnd() const;
105
106 // For property manager:
107 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
108 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
109 int GetPositionX() const { return GetPosition().x; }
110 int GetPositionY() const { return GetPosition().y; }
111
112 void SetColCount( int aCount ) { m_colCount = aCount; }
113 int GetColCount() const { return m_colCount; }
114
115 int GetRowCount() const
116 {
117 return m_cells.size() / m_colCount;
118 }
119
120 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
121
122 int GetColWidth( int aCol ) const
123 {
124 if( m_colWidths.count( aCol ) )
125 return m_colWidths.at( aCol );
126
127 return 0;
128 }
129
130 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
131
132 int GetRowHeight( int aRow ) const
133 {
134 if( m_rowHeights.count( aRow ) )
135 return m_rowHeights.at( aRow );
136
137 return 0;
138 }
139
140 PCB_TABLECELL* GetCell( int aRow, int aCol ) const
141 {
142 int idx = aRow * m_colCount + aCol;
143
144 if( idx < (int) m_cells.size() )
145 return m_cells[ idx ];
146 else
147 return nullptr;
148 }
149
150 std::vector<PCB_TABLECELL*> GetCells() const
151 {
152 return m_cells;
153 }
154
155 void AddCell( PCB_TABLECELL* aCell )
156 {
157 m_cells.push_back( aCell );
158 aCell->SetLayer( GetLayer() );
159 aCell->SetParent( this );
160 }
161
162 void InsertCell( int aIdx, PCB_TABLECELL* aCell )
163 {
164 m_cells.insert( m_cells.begin() + aIdx, aCell );
165 aCell->SetLayer( GetLayer() );
166 aCell->SetParent( this );
167 }
168
170 {
171 for( PCB_TABLECELL* cell : m_cells )
172 delete cell;
173
174 m_cells.clear();
175 }
176
178 {
180 []( PCB_TABLECELL* cell )
181 {
182 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
183 } );
184 }
185
186 void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
187 bool aSkipConnectivity = false ) override
188 {
189 wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
190 }
191
192 void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
193 {
194 wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
195 }
196
197 void Normalize() override;
198
199 void Move( const VECTOR2I& aMoveVector ) override;
200
201 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
202
203 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
204
205 const BOX2I GetBoundingBox() const override;
206
207 // @copydoc BOARD_ITEM::GetEffectiveShape
208 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
209 FLASHING aFlash = FLASHING::DEFAULT ) const override;
210
211 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
212 int aMaxError, ERROR_LOC aErrorLoc,
213 bool aIgnoreLineWidth = false ) const override;
214
215 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
216 const std::vector<KICAD_T>& aScanTypes ) override;
217
218 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
219 {
220 // Symbols are searchable via the child field and pin item text.
221 return false;
222 }
223
224 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
225
226 BITMAPS GetMenuImage() const override;
227
228 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
229
230 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
231
232 EDA_ITEM* Clone() const override
233 {
234 return new PCB_TABLE( *this );
235 }
236
237 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
238
239 double Similarity( const BOARD_ITEM& aOther ) const override;
240
241 bool operator==( const PCB_TABLE& aOther ) const;
242 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
243
244 static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
245
246#if defined(DEBUG)
247 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
248#endif
249
250protected:
251 virtual void swapData( BOARD_ITEM* aImage ) override;
252
253protected:
260
262 std::map<int, int> m_colWidths;
263 std::map<int, int> m_rowHeights;
264 std::vector<PCB_TABLECELL*> m_cells;
265};
266
267
268#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:239
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:128
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:259
bool StrokeRows() const
Definition: pcb_table.h:98
void ClearCells()
Definition: pcb_table.h:169
int GetRowCount() const
Definition: pcb_table.h:115
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:192
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:264
void SetColWidth(int aCol, int aWidth)
Definition: pcb_table.h:120
int m_colCount
Definition: pcb_table.h:261
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:257
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_table.cpp:181
int GetPositionY() const
Definition: pcb_table.h:110
bool StrokeColumns() const
Definition: pcb_table.h:95
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:91
bool m_strokeExternal
Definition: pcb_table.h:254
STROKE_PARAMS m_borderStroke
Definition: pcb_table.h:256
bool m_strokeColumns
Definition: pcb_table.h:258
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:80
void SetPositionX(int x)
Definition: pcb_table.h:107
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:140
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:150
int GetBorderWidth() const
Definition: pcb_table.h:62
COLOR4D GetBorderColor() const
Definition: pcb_table.h:74
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:113
void SetStrokeColumns(bool aDoStroke)
Definition: pcb_table.h:94
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: pcb_table.h:77
std::map< int, int > m_colWidths
Definition: pcb_table.h:262
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_table.cpp:73
int GetPositionX() const
Definition: pcb_table.h:109
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:155
const STROKE_PARAMS & GetBorderStroke() const
Definition: pcb_table.h:59
void SetPositionY(int y)
Definition: pcb_table.h:108
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:97
void InsertCell(int aIdx, PCB_TABLECELL *aCell)
Definition: pcb_table.h:162
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:186
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_table.h:232
bool m_strokeHeader
Definition: pcb_table.h:255
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:177
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
Definition: pcb_table.cpp:391
void SetColCount(int aCount)
Definition: pcb_table.h:112
int GetColWidth(int aCol) const
Definition: pcb_table.h:122
VECTOR2I GetPosition() const override
Definition: pcb_table.cpp:110
void SetSeparatorsWidth(int aWidth)
Definition: pcb_table.h:79
COLOR4D GetSeparatorsColor() const
Definition: pcb_table.h:92
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_table.h:218
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:83
void SetBorderColor(const COLOR4D &aColor)
Definition: pcb_table.h:73
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition: pcb_table.h:82
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition: pcb_table.h:76
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:130
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:132
std::map< int, int > m_rowHeights
Definition: pcb_table.h:263
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:94
int GetWidth() const
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
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:184
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:695