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#include <properties/property.h>
35
36
38 PCB_TEXTBOX( aParent, PCB_TABLECELL_T ),
39 m_colSpan( 1 ),
40 m_rowSpan( 1 )
41{
42 if( BOARD* board = GetBoard() )
43 SetMirrored( board->IsBackLayer( aParent->GetLayer() ) );
44 else
45 SetMirrored( IsBackLayer( aParent->GetLayer() ) );
46
47 SetRectangleHeight( std::numeric_limits<int>::max() / 2 );
48 SetRectangleWidth( std::numeric_limits<int>::max() / 2 );
49}
50
51
53{
54 wxASSERT( aImage->Type() == PCB_TABLECELL_T );
55
56 std::swap( *( (PCB_TABLECELL*) this ), *( (PCB_TABLECELL*) aImage ) );
57}
58
59
60wxString PCB_TABLECELL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
61{
62 return wxString::Format( _( "Table cell %s" ), GetAddr() );
63}
64
65
67{
68 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
69
70 for( int row = 0; row < table->GetRowCount(); ++row )
71 {
72 for( int col = 0; col < table->GetColCount(); ++col )
73 {
74 if( table->GetCell( row, col ) == this )
75 return row;
76 }
77 }
78
79 return -1;
80}
81
82
84{
85 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
86
87 for( int row = 0; row < table->GetRowCount(); ++row )
88 {
89 for( int col = 0; col < table->GetColCount(); ++col )
90 {
91 if( table->GetCell( row, col ) == this )
92 return col;
93 }
94 }
95
96 return -1;
97}
98
99
101{
102 return wxString::Format( wxT( "%c%d" ), 'A' + GetColumn() % 26, GetRow() + 1 );
103}
104
105
106wxString PCB_TABLECELL::GetShownText( bool aAllowExtraText, int aDepth ) const
107{
108 const FOOTPRINT* parentFootprint = GetParentFootprint();
109 const BOARD* board = GetBoard();
110
111 std::function<bool( wxString* )> tableCellResolver = [&]( wxString* token ) -> bool
112 {
113 if( token->IsSameAs( wxT( "ROW" ) ) )
114 {
115 *token = wxString::Format( wxT( "%d" ), GetRow() + 1 ); // 1-based
116 return true;
117 }
118 else if( token->IsSameAs( wxT( "COL" ) ) )
119 {
120 *token = wxString::Format( wxT( "%d" ), GetColumn() + 1 ); // 1-based
121 return true;
122 }
123 else if( token->IsSameAs( wxT( "ADDR" ) ) )
124 {
125 *token = GetAddr();
126 return true;
127 }
128 else if( token->IsSameAs( wxT( "LAYER" ) ) )
129 {
130 *token = GetLayerName();
131 return true;
132 }
133
134 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
135 return true;
136
137 if( board->ResolveTextVar( token, aDepth + 1 ) )
138 return true;
139
140 return false;
141 };
142
143 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
144
145 if( HasTextVars() )
146 text = ResolveTextVars( text, &tableCellResolver, aDepth );
147
148 KIFONT::FONT* font = GetDrawFont( nullptr );
149 EDA_ANGLE drawAngle = GetDrawRotation();
150 std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle );
151 int colWidth = ( corners[1] - corners[0] ).EuclideanNorm();
152
153 if( GetTextAngle().IsHorizontal() )
154 colWidth -= ( GetMarginLeft() + GetMarginRight() );
155 else
156 colWidth -= ( GetMarginTop() + GetMarginBottom() );
157
159
160 // Convert escape markers back to literal ${} and @{} for final display
161 text.Replace( wxT( "<<<ESC_DOLLAR:" ), wxT( "${" ) );
162 text.Replace( wxT( "<<<ESC_AT:" ), wxT( "@{" ) );
163
164 return text;
165}
166
167
169{
170 return static_cast<PCB_TABLE*>( GetParent() )->GetColWidth( GetColumn() );
171}
172
173
175{
176 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
177
178 table->SetColWidth( GetColumn(), aWidth );
179 table->Normalize();
180}
181
182
184{
185 return static_cast<PCB_TABLE*>( GetParent() )->GetRowHeight( GetRow() );
186}
187
188
190{
191 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
192
193 table->SetRowHeight( GetRow(), aHeight );
194 table->Normalize();
195}
196
197
198void PCB_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
199{
200 aList.emplace_back( _( "Table Cell" ), GetAddr() );
201
202 // Don't use GetShownText() here; we want to show the user the variable references
203 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
204
205 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
206 aList.emplace_back( _( "Status" ), _( "Locked" ) );
207
208 aList.emplace_back( _( "Layer" ), GetLayerName() );
209 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
210
211 aList.emplace_back( _( "Cell Width" ), aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
212 aList.emplace_back( _( "Cell Height" ), aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
213
214 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
215
216 if( GetTextThickness() )
217 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
218 else
219 aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
220
221 aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
222 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
223}
224
225
226double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const
227{
228 if( aBoardItem.Type() != Type() )
229 return 0.0;
230
231 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
232
233 double similarity = 1.0;
234
235 if( m_colSpan != other.m_colSpan )
236 similarity *= 0.9;
237
238 if( m_rowSpan != other.m_rowSpan )
239 similarity *= 0.9;
240
241 similarity *= PCB_TEXTBOX::Similarity( other );
242
243 return similarity;
244}
245
246bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
247{
248 if( aBoardItem.Type() != Type() )
249 return false;
250
251 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
252
253 return *this == other;
254}
255
256bool PCB_TABLECELL::operator==( const PCB_TABLECELL& aOther ) const
257{
258 return m_colSpan == aOther.m_colSpan && m_rowSpan == aOther.m_rowSpan && PCB_TEXTBOX::operator==( aOther );
259}
260
261
263{
265 {
268
281
282 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ) );
283 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ) );
284 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) );
285 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask" ) );
286 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask Margin Override" ) );
287 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Corner Radius" ) );
288
290
291 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border" ) );
292 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Style" ) );
293 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Width" ) );
294
295 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
296 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
297 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
298 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
299 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
300 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Width" ) );
301 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Height" ) );
302 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
303 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
304 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
305
306 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
307 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
308 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
309
310 const wxString tableProps = _( "Table" );
311
315 tableProps );
316
320 tableProps );
321 }
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:84
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:237
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:215
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:501
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
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:216
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:174
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:407
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:379
int GetTextWidth() const
Definition eda_text.h:264
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:661
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:479
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:98
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:609
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:99
PCB_TEXTBOX(BOARD_ITEM *aParent, KICAD_T aType=PCB_TEXTBOX_T)
int GetMarginLeft() const
Definition pcb_textbox.h:96
int GetMarginRight() const
Definition pcb_textbox.h:98
int GetMarginTop() const
Definition pcb_textbox.h:97
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:296
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