KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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 SCH_TABLE_H
25#define SCH_TABLE_H
26
27
28#include <sch_tablecell.h>
29#include <sch_item.h>
30#include <algorithm>
31
32
33class SCH_TABLE : public SCH_ITEM
34{
35public:
36 SCH_TABLE( int aLineWidth = 0 );
37
38 SCH_TABLE( const SCH_TABLE& aTable );
39
40 ~SCH_TABLE();
41
42 static inline bool ClassOf( const EDA_ITEM* aItem )
43 {
44 return aItem && SCH_TABLE_T == aItem->Type();
45 }
46
47 virtual wxString GetClass() const override
48 {
49 return wxT( "SCH_TABLE" );
50 }
51
52 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
53 bool StrokeExternal() const { return m_strokeExternal; }
54
55 void SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
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
82 void SetSeparatorsStyle( const LINE_STYLE aStyle )
83 {
85 }
86
88 {
89 if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
90 return LINE_STYLE::SOLID;
91 else
93 }
94
95 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
97
98 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
99 bool StrokeColumns() const { return m_strokeColumns; }
100
101 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
102 bool StrokeRows() const { return m_strokeRows; }
103
104 void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode ) override;
105
106 bool operator<( const SCH_ITEM& aItem ) const override;
107
108 void SetPosition( const VECTOR2I& aPos ) override;
109 VECTOR2I GetPosition() const override;
110 VECTOR2I GetEnd() const;
111 VECTOR2I GetCenter() const;
112
113 // For property manager:
114 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
115 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
116 int GetPositionX() const { return GetPosition().x; }
117 int GetPositionY() const { return GetPosition().y; }
118
119 void SetColCount( int aCount ) { m_colCount = aCount; }
120 int GetColCount() const { return m_colCount; }
121
122 int GetRowCount() const
123 {
124 return m_cells.size() / m_colCount;
125 }
126
127 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
128
129 int GetColWidth( int aCol ) const
130 {
131 if( m_colWidths.count( aCol ) )
132 return m_colWidths.at( aCol );
133
134 return 0;
135 }
136
137 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
138
139 int GetRowHeight( int aRow ) const
140 {
141 if( m_rowHeights.count( aRow ) )
142 return m_rowHeights.at( aRow );
143
144 return 0;
145 }
146
147 SCH_TABLECELL* GetCell( int aRow, int aCol ) const
148 {
149 int idx = aRow * m_colCount + aCol;
150
151 if( idx < (int) m_cells.size() )
152 return m_cells[ idx ];
153 else
154 return nullptr;
155 }
156
157 std::vector<SCH_TABLECELL*> GetCells() const
158 {
159 return m_cells;
160 }
161
162 void AddCell( SCH_TABLECELL* aCell )
163 {
164 m_cells.push_back( aCell );
165 aCell->SetParent( this );
166 }
167
168 void InsertCell( int aIdx, SCH_TABLECELL* aCell )
169 {
170 m_cells.insert( m_cells.begin() + aIdx, aCell );
171 aCell->SetParent( this );
172 }
173
175 {
176 for( SCH_TABLECELL* cell : m_cells )
177 delete cell;
178
179 m_cells.clear();
180 }
181
183 {
184 std::erase_if( m_cells,
185 []( SCH_TABLECELL* cell )
186 {
187 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
188 } );
189 }
190
191 void Normalize();
192
193 void Move( const VECTOR2I& aMoveVector ) override;
194
195 void MirrorHorizontally( int aCenter ) override;
196 void MirrorVertically( int aCenter ) override;
197 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
198
199 const BOX2I GetBoundingBox() const override;
200
201 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
202 const std::vector<KICAD_T>& aScanTypes ) override;
203
204 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
205 {
206 // Symbols are searchable via the child field and pin item text.
207 return false;
208 }
209
210 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
211
212 BITMAPS GetMenuImage() const override;
213
214 std::vector<int> ViewGetLayers() 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 void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
221 const STROKE_PARAMS& aStroke )>& aCallback ) const;
222
223 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
224 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
225
226 EDA_ITEM* Clone() const override
227 {
228 return new SCH_TABLE( *this );
229 }
230
231 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
232
233 double Similarity( const SCH_ITEM& aOther ) const override;
234
235 bool operator==( const SCH_ITEM& aOther ) const override;
236
237#if defined(DEBUG)
238 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
239#endif
240
241protected:
242 void swapData( SCH_ITEM* aItem ) override;
243
250
252 std::map<int, int> m_colWidths;
253 std::map<int, int> m_rowHeights;
254 std::vector<SCH_TABLECELL*> m_cells;
255};
256
257
258#endif /* SCH_TABLE_H */
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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:98
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
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:121
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
void SetBorderWidth(int aWidth)
Definition: sch_table.h:61
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition: sch_table.h:82
LINE_STYLE GetSeparatorsStyle() const
Definition: sch_table.h:87
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_table.cpp:301
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_table.cpp:481
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_table.cpp:226
void SetRowHeight(int aRow, int aHeight)
Definition: sch_table.h:137
std::vector< SCH_TABLECELL * > m_cells
Definition: sch_table.h:254
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: sch_table.h:77
std::map< int, int > m_rowHeights
Definition: sch_table.h:253
bool m_strokeColumns
Definition: sch_table.h:248
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_table.cpp:307
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_table.cpp:253
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_table.cpp:205
void SetColCount(int aCount)
Definition: sch_table.h:119
bool StrokeExternal() const
Definition: sch_table.h:53
virtual wxString GetClass() const override
Return the class name.
Definition: sch_table.h:47
void InsertCell(int aIdx, SCH_TABLECELL *aCell)
Definition: sch_table.h:168
void SetBorderColor(const COLOR4D &aColor)
Definition: sch_table.h:73
bool m_strokeRows
Definition: sch_table.h:247
int GetPositionY() const
Definition: sch_table.h:117
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_table.cpp:289
void SetPositionX(int x)
Definition: sch_table.h:114
LINE_STYLE GetBorderStyle() const
Definition: sch_table.h:65
void SetSeparatorsColor(const COLOR4D &aColor)
Definition: sch_table.h:95
int GetRowHeight(int aRow) const
Definition: sch_table.h:139
void SetColWidth(int aCol, int aWidth)
Definition: sch_table.h:127
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
Definition: sch_table.cpp:246
COLOR4D GetSeparatorsColor() const
Definition: sch_table.h:96
std::vector< SCH_TABLECELL * > GetCells() const
Definition: sch_table.h:157
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_table.cpp:211
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: sch_table.cpp:264
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
Definition: sch_table.cpp:330
int GetColWidth(int aCol) const
Definition: sch_table.h:129
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition: sch_table.h:55
void AddCell(SCH_TABLECELL *aCell)
Definition: sch_table.h:162
void SetSeparatorsWidth(int aWidth)
Definition: sch_table.h:79
const STROKE_PARAMS & GetBorderStroke() const
Definition: sch_table.h:59
bool m_StrokeHeaderSeparator
Definition: sch_table.h:245
VECTOR2I GetCenter() const
Definition: sch_table.cpp:119
int m_colCount
Definition: sch_table.h:251
VECTOR2I GetPosition() const override
Definition: sch_table.cpp:113
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_table.cpp:79
void SetStrokeExternal(bool aDoStroke)
Definition: sch_table.h:52
VECTOR2I GetEnd() const
Definition: sch_table.cpp:133
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: sch_table.cpp:446
void SetPositionY(int y)
Definition: sch_table.h:115
STROKE_PARAMS m_separatorsStroke
Definition: sch_table.h:249
int GetColCount() const
Definition: sch_table.h:120
bool StrokeHeaderSeparator() const
Definition: sch_table.h:56
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_table.h:204
bool m_strokeExternal
Definition: sch_table.h:244
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_table.cpp:402
std::map< int, int > m_colWidths
Definition: sch_table.h:252
void SetStrokeColumns(bool aDoStroke)
Definition: sch_table.h:98
void DeleteMarkedCells()
Definition: sch_table.h:182
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition: sch_table.h:147
void ClearCells()
Definition: sch_table.h:174
int GetSeparatorsWidth() const
Definition: sch_table.h:80
bool StrokeColumns() const
Definition: sch_table.h:99
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_table.h:226
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition: sch_table.h:76
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_table.h:42
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_table.cpp:107
int GetPositionX() const
Definition: sch_table.h:116
bool StrokeRows() const
Definition: sch_table.h:102
STROKE_PARAMS m_borderStroke
Definition: sch_table.h:246
int GetRowCount() const
Definition: sch_table.h:122
void SetStrokeRows(bool aDoStroke)
Definition: sch_table.h:101
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition: sch_table.h:58
void SetBorderStyle(const LINE_STYLE aStyle)
Definition: sch_table.h:64
COLOR4D GetBorderColor() const
Definition: sch_table.h:74
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_table.cpp:295
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_table.cpp:455
int GetBorderWidth() const
Definition: sch_table.h:62
void Normalize()
Definition: sch_table.cpp:147
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_table.cpp:198
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_table.cpp:217
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
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
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
@ SCH_TABLE_T
Definition: typeinfo.h:166
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695