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 (C) 2023 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
31
32class SCH_TABLE : public SCH_ITEM
33{
34public:
35 SCH_TABLE( int aLineWidth = 0 );
36
37 SCH_TABLE( const SCH_TABLE& aTable );
38
39 ~SCH_TABLE();
40
41 static inline bool ClassOf( const EDA_ITEM* aItem )
42 {
43 return aItem && SCH_TABLE_T == aItem->Type();
44 }
45
46 virtual wxString GetClass() const override
47 {
48 return wxT( "SCH_TABLE" );
49 }
50
51 void SwapData( SCH_ITEM* aItem ) override;
52
53 void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
54 bool StrokeExternal() const { return m_strokeExternal; }
55
56 void SetStrokeHeader( bool aDoStroke ) { m_strokeHeader = aDoStroke; }
57 bool StrokeHeader() const { return m_strokeHeader; }
58
59 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
60 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
61
62 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
63 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
64
65 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
67
68 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
70
71 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
73
74 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
76
79
80 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
82
83 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
84 bool StrokeColumns() const { return m_strokeColumns; }
85
86 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
87 bool StrokeRows() const { return m_strokeRows; }
88
89 void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
90
91 bool operator<( const SCH_ITEM& aItem ) const override;
92
93 void SetPosition( const VECTOR2I& aPos ) override;
94 VECTOR2I GetPosition() const override;
95 VECTOR2I GetEnd() const;
96
97 // For property manager:
98 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
99 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
100 int GetPositionX() const { return GetPosition().x; }
101 int GetPositionY() const { return GetPosition().y; }
102
103 void SetColCount( int aCount ) { m_colCount = aCount; }
104 int GetColCount() const { return m_colCount; }
105
106 int GetRowCount() const
107 {
108 return m_cells.size() / m_colCount;
109 }
110
111 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
112
113 int GetColWidth( int aCol ) const
114 {
115 if( m_colWidths.count( aCol ) )
116 return m_colWidths.at( aCol );
117
118 return 0;
119 }
120
121 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
122
123 int GetRowHeight( int aRow ) const
124 {
125 if( m_rowHeights.count( aRow ) )
126 return m_rowHeights.at( aRow );
127
128 return 0;
129 }
130
131 SCH_TABLECELL* GetCell( int aRow, int aCol ) const
132 {
133 int idx = aRow * m_colCount + aCol;
134
135 if( idx < (int) m_cells.size() )
136 return m_cells[ idx ];
137 else
138 return nullptr;
139 }
140
141 std::vector<SCH_TABLECELL*> GetCells() const
142 {
143 return m_cells;
144 }
145
146 void AddCell( SCH_TABLECELL* aCell )
147 {
148 m_cells.push_back( aCell );
149 aCell->SetParent( this );
150 }
151
152 void InsertCell( int aIdx, SCH_TABLECELL* aCell )
153 {
154 m_cells.insert( m_cells.begin() + aIdx, aCell );
155 aCell->SetParent( this );
156 }
157
159 {
160 for( SCH_TABLECELL* cell : m_cells )
161 delete cell;
162
163 m_cells.clear();
164 }
165
167 {
169 []( SCH_TABLECELL* cell )
170 {
171 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
172 } );
173 }
174
175 void Normalize();
176
177 void Move( const VECTOR2I& aMoveVector ) override;
178
179 void MirrorHorizontally( int aCenter ) override;
180 void MirrorVertically( int aCenter ) override;
181 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
182
183 const BOX2I GetBoundingBox() const override;
184
185 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
186 const std::vector<KICAD_T>& aScanTypes ) override;
187
188 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
189 {
190 // Symbols are searchable via the child field and pin item text.
191 return false;
192 }
193
194 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
195
196 BITMAPS GetMenuImage() const override;
197
198 void ViewGetLayers( int aLayers[], int& aCount ) const override;
199
200 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
201
202 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
203
204 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
205 const VECTOR2I& offset, bool aForceNoFill, bool aDimmed ) override;
206
207 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
208 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
209
210 EDA_ITEM* Clone() const override
211 {
212 return new SCH_TABLE( *this );
213 }
214
215 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
216
217 double Similarity( const SCH_ITEM& aOther ) const override;
218
219 bool operator==( const SCH_ITEM& aOther ) const override;
220
221#if defined(DEBUG)
222 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
223#endif
224
225protected:
232
234 std::map<int, int> m_colWidths;
235 std::map<int, int> m_rowHeights;
236 std::vector<SCH_TABLECELL*> m_cells;
237};
238
239
240#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:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:103
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:129
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:104
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:172
void SetBorderWidth(int aWidth)
Definition: sch_table.h:62
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition: sch_table.h:77
LINE_STYLE GetSeparatorsStyle() const
Definition: sch_table.h:78
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:575
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_table.cpp:212
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &offset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_table.cpp:239
void SetRowHeight(int aRow, int aHeight)
Definition: sch_table.h:121
std::vector< SCH_TABLECELL * > m_cells
Definition: sch_table.h:236
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: sch_table.h:72
std::map< int, int > m_rowHeights
Definition: sch_table.h:235
bool m_strokeColumns
Definition: sch_table.h:230
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:419
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_table.cpp:79
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_table.cpp:362
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_table.cpp:398
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_table.cpp:191
void SetColCount(int aCount)
Definition: sch_table.h:103
bool StrokeExternal() const
Definition: sch_table.h:54
virtual wxString GetClass() const override
Return the class name.
Definition: sch_table.h:46
void InsertCell(int aIdx, SCH_TABLECELL *aCell)
Definition: sch_table.h:152
void SetBorderColor(const COLOR4D &aColor)
Definition: sch_table.h:68
bool m_strokeRows
Definition: sch_table.h:229
int GetPositionY() const
Definition: sch_table.h:101
void SetPositionX(int x)
Definition: sch_table.h:98
bool m_strokeHeader
Definition: sch_table.h:227
LINE_STYLE GetBorderStyle() const
Definition: sch_table.h:66
void SetSeparatorsColor(const COLOR4D &aColor)
Definition: sch_table.h:80
int GetRowHeight(int aRow) const
Definition: sch_table.h:123
void SetColWidth(int aCol, int aWidth)
Definition: sch_table.h:111
COLOR4D GetSeparatorsColor() const
Definition: sch_table.h:81
void SetStrokeHeader(bool aDoStroke)
Definition: sch_table.h:56
std::vector< SCH_TABLECELL * > GetCells() const
Definition: sch_table.h:141
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_table.cpp:197
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_table.cpp:410
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:373
int GetColWidth(int aCol) const
Definition: sch_table.h:113
void AddCell(SCH_TABLECELL *aCell)
Definition: sch_table.h:146
void SetSeparatorsWidth(int aWidth)
Definition: sch_table.h:74
const STROKE_PARAMS & GetBorderStroke() const
Definition: sch_table.h:60
int m_colCount
Definition: sch_table.h:233
VECTOR2I GetPosition() const override
Definition: sch_table.cpp:115
void SetStrokeExternal(bool aDoStroke)
Definition: sch_table.h:53
VECTOR2I GetEnd() const
Definition: sch_table.cpp:121
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:542
void SetPositionY(int y)
Definition: sch_table.h:99
STROKE_PARAMS m_separatorsStroke
Definition: sch_table.h:231
int GetColCount() const
Definition: sch_table.h:104
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_table.h:188
bool m_strokeExternal
Definition: sch_table.h:226
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:442
std::map< int, int > m_colWidths
Definition: sch_table.h:234
void SetStrokeColumns(bool aDoStroke)
Definition: sch_table.h:83
void DeleteMarkedCells()
Definition: sch_table.h:166
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition: sch_table.h:131
void ClearCells()
Definition: sch_table.h:158
int GetSeparatorsWidth() const
Definition: sch_table.h:75
bool StrokeColumns() const
Definition: sch_table.h:84
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_table.h:210
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition: sch_table.h:71
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_table.h:41
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_table.cpp:109
int GetPositionX() const
Definition: sch_table.h:100
bool StrokeRows() const
Definition: sch_table.h:87
STROKE_PARAMS m_borderStroke
Definition: sch_table.h:228
int GetRowCount() const
Definition: sch_table.h:106
void SetStrokeRows(bool aDoStroke)
Definition: sch_table.h:86
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition: sch_table.h:59
void SetBorderStyle(const LINE_STYLE aStyle)
Definition: sch_table.h:65
COLOR4D GetBorderColor() const
Definition: sch_table.h:69
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_table.cpp:404
bool StrokeHeader() const
Definition: sch_table.h:57
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_table.cpp:549
int GetBorderWidth() const
Definition: sch_table.h:63
void Normalize()
Definition: sch_table.cpp:135
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_table.cpp:184
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_table.cpp:203
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_table.cpp:232
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
int GetWidth() const
Definition: stroke_params.h:91
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:81
#define STRUCT_DELETED
flag indication structures to be erased
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:48
@ SCH_TABLE_T
Definition: typeinfo.h:165
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588