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 void Serialize( google::protobuf::Any& aContainer ) const override;
39 bool Deserialize( const google::protobuf::Any& aContainer ) override;
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 SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
52 bool StrokeExternal() const { return m_strokeExternal; }
53
54 void SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
56
57 void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
58 const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
59
60 void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
61 int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
62
63 void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
65 {
66 if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
67 return LINE_STYLE::SOLID;
68 else
69 return m_borderStroke.GetLineStyle();
70 }
71
72 void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
73 COLOR4D GetBorderColor() const { return m_borderStroke.GetColor(); }
74
75 void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
77
78 void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
79 int GetSeparatorsWidth() const { return m_separatorsStroke.GetWidth(); }
80
81 void SetSeparatorsStyle( const LINE_STYLE aStyle )
82 {
83 m_separatorsStroke.SetLineStyle( aStyle );
84 }
85
87 {
88 if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
89 return LINE_STYLE::SOLID;
90 else
91 return m_separatorsStroke.GetLineStyle();
92 }
93
94 void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
95 COLOR4D GetSeparatorsColor() const { return m_separatorsStroke.GetColor(); }
96
97 void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
98 bool StrokeColumns() const { return m_strokeColumns; }
99
100 void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
101 bool StrokeRows() const { return m_strokeRows; }
102
103 void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode ) override;
104
105 bool operator<( const SCH_ITEM& aItem ) const override;
106
107 void SetPosition( const VECTOR2I& aPos ) override;
108 VECTOR2I GetPosition() const override;
109 VECTOR2I GetEnd() const;
110 VECTOR2I GetCenter() const;
111
112 // For property manager:
113 void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
114 void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
115 int GetPositionX() const { return GetPosition().x; }
116 int GetPositionY() const { return GetPosition().y; }
117
118 void SetColCount( int aCount ) { m_colCount = aCount; }
119 int GetColCount() const { return m_colCount; }
120
121 int GetRowCount() const
122 {
123 wxCHECK_MSG( m_colCount, 0, wxT( "Degenerate table with no columns!" ) );
124
125 return (int) m_cells.size() / m_colCount;
126 }
127
128 void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
129
130 int GetColWidth( int aCol ) const
131 {
132 if( m_colWidths.count( aCol ) )
133 return m_colWidths.at( aCol );
134
135 return 0;
136 }
137
138 void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
139
140 int GetRowHeight( int aRow ) const
141 {
142 if( m_rowHeights.count( aRow ) )
143 return m_rowHeights.at( aRow );
144
145 return 0;
146 }
147
148 SCH_TABLECELL* GetCell( int aRow, int aCol ) const
149 {
150 int idx = aRow * m_colCount + aCol;
151
152 if( idx < (int) m_cells.size() )
153 return m_cells[ idx ];
154 else
155 return nullptr;
156 }
157
158 std::vector<SCH_TABLECELL*> GetCells() const
159 {
160 return m_cells;
161 }
162
163 void AddCell( SCH_TABLECELL* aCell )
164 {
165 m_cells.push_back( aCell );
166 aCell->SetParent( this );
167 }
168
169 void InsertCell( int aIdx, SCH_TABLECELL* aCell )
170 {
171 m_cells.insert( m_cells.begin() + aIdx, aCell );
172 aCell->SetParent( this );
173 }
174
176 {
177 for( SCH_TABLECELL* cell : m_cells )
178 delete cell;
179
180 m_cells.clear();
181 }
182
184 {
185 std::erase_if( m_cells,
186 []( SCH_TABLECELL* cell )
187 {
188 if( cell->GetFlags() & STRUCT_DELETED )
189 {
190 delete cell;
191 return true;
192 }
193 return false;
194 } );
195 }
196
197 void Normalize();
198
199 void Move( const VECTOR2I& aMoveVector ) override;
200
201 void MirrorHorizontally( int aCenter ) override;
202 void MirrorVertically( int aCenter ) override;
203 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
204
205 const BOX2I GetBoundingBox() const override;
206
207 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
208 const std::vector<KICAD_T>& aScanTypes ) override;
209
210 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
211 {
212 // Symbols are searchable via the child field and pin item text.
213 return false;
214 }
215
216 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
217
218 BITMAPS GetMenuImage() const override;
219
220 std::vector<int> ViewGetLayers() const override;
221
222 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
223 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
224 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
225
226 void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
227 const STROKE_PARAMS& aStroke )>& aCallback ) const;
228
229 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
230 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
231
232 EDA_ITEM* Clone() const override
233 {
234 return new SCH_TABLE( *this );
235 }
236
237 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
238
239 double Similarity( const SCH_ITEM& aOther ) const override;
240
241 bool operator==( const SCH_ITEM& aOther ) const override;
242
243#if defined(DEBUG)
244 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
245#endif
246
247protected:
248 void swapData( SCH_ITEM* aItem ) override;
249
256
258 std::map<int, int> m_colWidths;
259 std::map<int, int> m_rowHeights;
260 std::vector<SCH_TABLECELL*> m_cells;
261};
262
263
264#endif /* SCH_TABLE_H */
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Base plotter engine class.
Definition plotter.h:136
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
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:60
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition sch_table.h:81
LINE_STYLE GetSeparatorsStyle() const
Definition sch_table.h:86
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:138
std::vector< SCH_TABLECELL * > m_cells
Definition sch_table.h:260
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition sch_table.h:76
std::map< int, int > m_rowHeights
Definition sch_table.h:259
bool m_strokeColumns
Definition sch_table.h:254
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:118
bool StrokeExternal() const
Definition sch_table.h:52
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:169
void SetBorderColor(const COLOR4D &aColor)
Definition sch_table.h:72
bool m_strokeRows
Definition sch_table.h:253
int GetPositionY() const
Definition sch_table.h:116
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:113
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
LINE_STYLE GetBorderStyle() const
Definition sch_table.h:64
void SetSeparatorsColor(const COLOR4D &aColor)
Definition sch_table.h:94
int GetRowHeight(int aRow) const
Definition sch_table.h:140
void SetColWidth(int aCol, int aWidth)
Definition sch_table.h:128
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
COLOR4D GetSeparatorsColor() const
Definition sch_table.h:95
SCH_TABLE(int aLineWidth=0)
Definition sch_table.cpp:40
std::vector< SCH_TABLECELL * > GetCells() const
Definition sch_table.h:158
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:130
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition sch_table.h:54
void AddCell(SCH_TABLECELL *aCell)
Definition sch_table.h:163
void SetSeparatorsWidth(int aWidth)
Definition sch_table.h:78
const STROKE_PARAMS & GetBorderStroke() const
Definition sch_table.h:58
bool m_StrokeHeaderSeparator
Definition sch_table.h:251
VECTOR2I GetCenter() const
int m_colCount
Definition sch_table.h:257
VECTOR2I GetPosition() const override
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
void SetStrokeExternal(bool aDoStroke)
Definition sch_table.h:51
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:114
STROKE_PARAMS m_separatorsStroke
Definition sch_table.h:255
int GetColCount() const
Definition sch_table.h:119
bool StrokeHeaderSeparator() const
Definition sch_table.h:55
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition sch_table.h:210
bool m_strokeExternal
Definition sch_table.h:250
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:258
void SetStrokeColumns(bool aDoStroke)
Definition sch_table.h:97
void DeleteMarkedCells()
Definition sch_table.h:183
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition sch_table.h:148
void ClearCells()
Definition sch_table.h:175
int GetSeparatorsWidth() const
Definition sch_table.h:79
bool StrokeColumns() const
Definition sch_table.h:98
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_table.h:232
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition sch_table.h:75
static bool ClassOf(const EDA_ITEM *aItem)
Definition sch_table.h:41
void SetPosition(const VECTOR2I &aPos) override
int GetPositionX() const
Definition sch_table.h:115
bool StrokeRows() const
Definition sch_table.h:101
STROKE_PARAMS m_borderStroke
Definition sch_table.h:252
int GetRowCount() const
Definition sch_table.h:121
void SetStrokeRows(bool aDoStroke)
Definition sch_table.h:100
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition sch_table.h:57
void SetBorderStyle(const LINE_STYLE aStyle)
Definition sch_table.h:63
COLOR4D GetBorderColor() const
Definition sch_table.h:73
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:61
void Normalize()
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_table.cpp:81
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: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.
@ SCH_TABLE_T
Definition typeinfo.h:161
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683