KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_tablecell.cpp
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#include <advanced_config.h>
25#include <common.h>
26#include <pcb_edit_frame.h>
27#include <font/font.h>
28#include <widgets/msgpanel.h>
29#include <string_utils.h>
30#include <board.h>
31#include <pcb_table.h>
32#include <footprint.h>
33
34
36 PCB_TEXTBOX( aParent, PCB_TABLECELL_T ),
37 m_colSpan( 1 ),
38 m_rowSpan( 1 )
39{
40 if( BOARD* board = GetBoard() )
41 SetMirrored( board->IsBackLayer( aParent->GetLayer() ) );
42 else
43 SetMirrored( IsBackLayer( aParent->GetLayer() ) );
44
45 SetRectangleHeight( std::numeric_limits<int>::max() / 2 );
46 SetRectangleWidth( std::numeric_limits<int>::max() / 2 );
47}
48
49
51{
52 wxASSERT( aImage->Type() == PCB_TABLECELL_T );
53
54 std::swap( *( (PCB_TABLECELL*) this ), *( (PCB_TABLECELL*) aImage ) );
55}
56
57
58wxString PCB_TABLECELL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
59{
60 return wxString::Format( _( "Table cell %s" ), GetAddr() );
61}
62
63
65{
66 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
67
68 for( int row = 0; row < table->GetRowCount(); ++row )
69 {
70 for( int col = 0; col < table->GetColCount(); ++col )
71 {
72 if( table->GetCell( row, col ) == this )
73 return row;
74 }
75 }
76
77 return -1;
78}
79
80
82{
83 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
84
85 for( int row = 0; row < table->GetRowCount(); ++row )
86 {
87 for( int col = 0; col < table->GetColCount(); ++col )
88 {
89 if( table->GetCell( row, col ) == this )
90 return col;
91 }
92 }
93
94 return -1;
95}
96
97
98wxString PCB_TABLECELL::GetAddr() const
99{
100 return wxString::Format( wxT( "%c%d" ), 'A' + GetColumn() % 26, GetRow() + 1 );
101}
102
103
104wxString PCB_TABLECELL::GetShownText( bool aAllowExtraText, int aDepth ) const
105{
106 const FOOTPRINT* parentFootprint = GetParentFootprint();
107 const BOARD* board = GetBoard();
108
109 std::function<bool( wxString* )> tableCellResolver = [&]( wxString* token ) -> bool
110 {
111 if( token->IsSameAs( wxT( "ROW" ) ) )
112 {
113 *token = wxString::Format( wxT( "%d" ), GetRow() + 1 ); // 1-based
114 return true;
115 }
116 else if( token->IsSameAs( wxT( "COL" ) ) )
117 {
118 *token = wxString::Format( wxT( "%d" ), GetColumn() + 1 ); // 1-based
119 return true;
120 }
121 else if( token->IsSameAs( wxT( "ADDR" ) ) )
122 {
123 *token = GetAddr();
124 return true;
125 }
126 else if( token->IsSameAs( wxT( "LAYER" ) ) )
127 {
128 *token = GetLayerName();
129 return true;
130 }
131
132 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
133 return true;
134
135 if( board->ResolveTextVar( token, aDepth + 1 ) )
136 return true;
137
138 return false;
139 };
140
141 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
142
143 if( HasTextVars() )
144 text = ResolveTextVars( text, &tableCellResolver, aDepth );
145
146 KIFONT::FONT* font = GetDrawFont( nullptr );
147 EDA_ANGLE drawAngle = GetDrawRotation();
148 std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle );
149 int colWidth = ( corners[1] - corners[0] ).EuclideanNorm();
150
151 if( GetTextAngle().IsHorizontal() )
152 colWidth -= ( GetMarginLeft() + GetMarginRight() );
153 else
154 colWidth -= ( GetMarginTop() + GetMarginBottom() );
155
157
158 // Convert escape markers back to literal ${} and @{} for final display
159 text.Replace( wxT( "<<<ESC_DOLLAR:" ), wxT( "${" ) );
160 text.Replace( wxT( "<<<ESC_AT:" ), wxT( "@{" ) );
161
162 return text;
163}
164
165
167{
168 return static_cast<PCB_TABLE*>( GetParent() )->GetColWidth( GetColumn() );
169}
170
171
173{
174 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
175
176 table->SetColWidth( GetColumn(), aWidth );
177 table->Normalize();
178}
179
180
182{
183 return static_cast<PCB_TABLE*>( GetParent() )->GetRowHeight( GetRow() );
184}
185
186
188{
189 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
190
191 table->SetRowHeight( GetRow(), aHeight );
192 table->Normalize();
193}
194
195
196void PCB_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
197{
198 aList.emplace_back( _( "Table Cell" ), GetAddr() );
199
200 // Don't use GetShownText() here; we want to show the user the variable references
201 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
202
203 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
204 aList.emplace_back( _( "Status" ), _( "Locked" ) );
205
206 aList.emplace_back( _( "Layer" ), GetLayerName() );
207 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
208
209 aList.emplace_back( _( "Cell Width" ), aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
210 aList.emplace_back( _( "Cell Height" ), aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
211
212 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
213
214 if( GetTextThickness() )
215 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
216 else
217 aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
218
219 aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
220 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
221}
222
223
224double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const
225{
226 if( aBoardItem.Type() != Type() )
227 return 0.0;
228
229 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
230
231 double similarity = 1.0;
232
233 if( m_colSpan != other.m_colSpan )
234 similarity *= 0.9;
235
236 if( m_rowSpan != other.m_rowSpan )
237 similarity *= 0.9;
238
239 similarity *= PCB_TEXTBOX::Similarity( other );
240
241 return similarity;
242}
243
244bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
245{
246 if( aBoardItem.Type() != Type() )
247 return false;
248
249 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
250
251 return *this == other;
252}
253
254bool PCB_TABLECELL::operator==( const PCB_TABLECELL& aOther ) const
255{
256 return m_colSpan == aOther.m_colSpan && m_rowSpan == aOther.m_rowSpan && PCB_TEXTBOX::operator==( aOther );
257}
258
259
261{
263 {
266
279
280 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ) );
281 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ) );
282 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) );
283 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask" ) );
284 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask Margin Override" ) );
285 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Corner Radius" ) );
286
288
289 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border" ) );
290 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Style" ) );
291 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Width" ) );
292
293 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
294 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
295 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
296 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
297 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
298 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Width" ) );
299 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Height" ) );
300 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
301 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
302 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
303
304 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
305 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
306 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
307
308 const wxString tableProps = _( "Table" );
309
313 tableProps );
314
318 tableProps );
319 }
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:236
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:214
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
bool ResolveTextVar(wxString *token, int aDepth) const
Definition board.cpp:498
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const
void SetRectangleHeight(const int &aHeight)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:215
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:173
void SetRectangleWidth(const int &aWidth)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:80
int GetTextHeight() const
Definition eda_text.h:267
bool IsItalic() const
Definition eda_text.h:169
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
KIFONT::FONT * GetFont() const
Definition eda_text.h:247
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:401
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:377
int GetTextWidth() const
Definition eda_text.h:264
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:655
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:117
bool IsMirrored() const
Definition eda_text.h:190
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:473
bool IsBold() const
Definition eda_text.h:184
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:109
int GetTextThickness() const
Definition eda_text.h:128
VECTOR2I GetTextSize() const
Definition eda_text.h:261
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the component.
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:131
void LinebreakText(wxString &aText, int aColumnWidth, const VECTOR2I &aGlyphSize, int aThickness, bool aBold, bool aItalic) const
Insert characters into text to ensure that no lines are wider than aColumnWidth.
Definition font.cpp:572
int GetColumnWidth() const
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
wxString GetAddr() const
void SetRowHeight(int aHeight)
virtual void swapData(BOARD_ITEM *aImage) override
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
bool operator==(const PCB_TABLECELL &aBoardItem) const
void SetColumnWidth(int aWidth)
int GetRow() const
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
int GetColumn() const
int GetRowHeight() 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.
PCB_TABLECELL(BOARD_ITEM *parent)
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
int GetMarginBottom() const
Definition pcb_textbox.h:92
PCB_TEXTBOX(BOARD_ITEM *aParent, KICAD_T aType=PCB_TEXTBOX_T)
int GetMarginLeft() const
Definition pcb_textbox.h:89
int GetMarginRight() const
Definition pcb_textbox.h:91
int GetMarginTop() const
Definition pcb_textbox.h:90
bool operator==(const PCB_TEXTBOX &aOther) const
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString ResolveTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
Multi-pass text variable expansion and math expression evaluation.
Definition common.cpp:247
The common library.
#define _(s)
#define PCB_EDIT_FRAME_NAME
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:803
Message panel definition file.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
#define _HKI(x)
Definition page_info.cpp:44
static struct PCB_TABLECELL_DESC _PCB_TABLECELL_DESC
#define TYPE_HASH(x)
Definition property.h:74
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:95