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 VECTOR2I GetCenter() const;
97
98 // For property manager:
99 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
100 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
101 int GetPositionX() const { return GetPosition().x; }
102 int GetPositionY() const { return GetPosition().y; }
103
104 void SetColCount( int aCount ) { m_colCount = aCount; }
105 int GetColCount() const { return m_colCount; }
106
107 int GetRowCount() const
108 {
109 return m_cells.size() / m_colCount;
110 }
111
112 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
113
114 int GetColWidth( int aCol ) const
115 {
116 if( m_colWidths.count( aCol ) )
117 return m_colWidths.at( aCol );
118
119 return 0;
120 }
121
122 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
123
124 int GetRowHeight( int aRow ) const
125 {
126 if( m_rowHeights.count( aRow ) )
127 return m_rowHeights.at( aRow );
128
129 return 0;
130 }
131
132 SCH_TABLECELL* GetCell( int aRow, int aCol ) const
133 {
134 int idx = aRow * m_colCount + aCol;
135
136 if( idx < (int) m_cells.size() )
137 return m_cells[ idx ];
138 else
139 return nullptr;
140 }
141
142 std::vector<SCH_TABLECELL*> GetCells() const
143 {
144 return m_cells;
145 }
146
147 void AddCell( SCH_TABLECELL* aCell )
148 {
149 m_cells.push_back( aCell );
150 aCell->SetParent( this );
151 }
152
153 void InsertCell( int aIdx, SCH_TABLECELL* aCell )
154 {
155 m_cells.insert( m_cells.begin() + aIdx, aCell );
156 aCell->SetParent( this );
157 }
158
160 {
161 for( SCH_TABLECELL* cell : m_cells )
162 delete cell;
163
164 m_cells.clear();
165 }
166
168 {
170 []( SCH_TABLECELL* cell )
171 {
172 return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
173 } );
174 }
175
176 void Normalize();
177
178 void Move( const VECTOR2I& aMoveVector ) override;
179
180 void MirrorHorizontally( int aCenter ) override;
181 void MirrorVertically( int aCenter ) override;
182 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
183
184 const BOX2I GetBoundingBox() const override;
185
186 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
187 const std::vector<KICAD_T>& aScanTypes ) override;
188
189 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
190 {
191 // Symbols are searchable via the child field and pin item text.
192 return false;
193 }
194
195 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
196
197 BITMAPS GetMenuImage() const override;
198
199 std::vector<int> ViewGetLayers() const override;
200
201 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
202
203 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
204
205 void PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
206 const VECTOR2I& aOffset, bool aDimmed ) override;
207
208 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
209 const VECTOR2I& offset, bool aForceNoFill, bool aDimmed ) override;
210
211 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
212 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
213
214 EDA_ITEM* Clone() const override
215 {
216 return new SCH_TABLE( *this );
217 }
218
219 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
220
221 double Similarity( const SCH_ITEM& aOther ) const override;
222
223 bool operator==( const SCH_ITEM& aOther ) const override;
224
225#if defined(DEBUG)
226 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
227#endif
228
229protected:
236
238 std::map<int, int> m_colWidths;
239 std::map<int, int> m_rowHeights;
240 std::vector<SCH_TABLECELL*> m_cells;
241};
242
243
244#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: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:130
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:105
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
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
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:434
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:596
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_table.cpp:228
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:263
void SetRowHeight(int aRow, int aHeight)
Definition: sch_table.h:122
std::vector< SCH_TABLECELL * > m_cells
Definition: sch_table.h:240
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: sch_table.h:72
std::map< int, int > m_rowHeights
Definition: sch_table.h:239
bool m_strokeColumns
Definition: sch_table.h:234
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:440
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:386
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_table.cpp:207
void SetColCount(int aCount)
Definition: sch_table.h:104
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:153
void SetBorderColor(const COLOR4D &aColor)
Definition: sch_table.h:68
bool m_strokeRows
Definition: sch_table.h:233
int GetPositionY() const
Definition: sch_table.h:102
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_table.cpp:422
void SetPositionX(int x)
Definition: sch_table.h:99
bool m_strokeHeader
Definition: sch_table.h:231
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:124
void SetColWidth(int aCol, int aWidth)
Definition: sch_table.h:112
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:142
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_table.cpp:213
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:397
int GetColWidth(int aCol) const
Definition: sch_table.h:114
void AddCell(SCH_TABLECELL *aCell)
Definition: sch_table.h:147
void SetSeparatorsWidth(int aWidth)
Definition: sch_table.h:74
const STROKE_PARAMS & GetBorderStroke() const
Definition: sch_table.h:60
VECTOR2I GetCenter() const
Definition: sch_table.cpp:121
void PrintBackground(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Print just the background fills.
Definition: sch_table.cpp:255
int m_colCount
Definition: sch_table.h:237
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:135
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:563
void SetPositionY(int y)
Definition: sch_table.h:100
STROKE_PARAMS m_separatorsStroke
Definition: sch_table.h:235
int GetColCount() const
Definition: sch_table.h:105
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_table.h:189
bool m_strokeExternal
Definition: sch_table.h:230
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:463
std::map< int, int > m_colWidths
Definition: sch_table.h:238
void SetStrokeColumns(bool aDoStroke)
Definition: sch_table.h:83
void DeleteMarkedCells()
Definition: sch_table.h:167
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition: sch_table.h:132
void ClearCells()
Definition: sch_table.h:159
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:214
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:101
bool StrokeRows() const
Definition: sch_table.h:87
STROKE_PARAMS m_borderStroke
Definition: sch_table.h:232
int GetRowCount() const
Definition: sch_table.h:107
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:428
bool StrokeHeader() const
Definition: sch_table.h:57
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_table.cpp:570
int GetBorderWidth() const
Definition: sch_table.h:63
void Normalize()
Definition: sch_table.cpp:149
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_table.cpp:200
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_table.cpp:219
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_table.cpp:248
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
int GetWidth() const
Definition: stroke_params.h:89
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:93
void SetWidth(int aWidth)
Definition: stroke_params.h:90
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:96
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:92
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:95
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:82
#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:46
@ SCH_TABLE_T
Definition: typeinfo.h:165
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691