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