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 <pcb_edit_frame.h>
25#include <font/font.h>
26#include <widgets/msgpanel.h>
27#include <string_utils.h>
28#include <board.h>
29#include <pcb_table.h>
30#include <pcb_tablecell.h>
31
32
34 PCB_TEXTBOX( aParent, PCB_TABLECELL_T ),
35 m_colSpan( 1 ),
36 m_rowSpan( 1 )
37{
38 if( BOARD* board = GetBoard() )
39 SetMirrored( board->IsBackLayer( aParent->GetLayer() ) );
40 else
41 SetMirrored( IsBackLayer( aParent->GetLayer() ) );
42
43 SetRectangleHeight( std::numeric_limits<int>::max() / 2 );
44 SetRectangleWidth( std::numeric_limits<int>::max() / 2 );
45}
46
47
49{
50 wxASSERT( aImage->Type() == PCB_TABLECELL_T );
51
52 std::swap( *((PCB_TABLECELL*) this), *((PCB_TABLECELL*) aImage) );
53}
54
55
56wxString PCB_TABLECELL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
57{
58 return wxString::Format( _( "Table Cell %s" ), GetAddr() );
59}
60
61
63{
64 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
65
66 for( int row = 0; row < table->GetRowCount(); ++row )
67 {
68 for( int col = 0; col < table->GetColCount(); ++col )
69 {
70 if( table->GetCell( row, col ) == this )
71 return row;
72 }
73 }
74
75 return -1;
76}
77
78
80{
81 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
82
83 for( int row = 0; row < table->GetRowCount(); ++row )
84 {
85 for( int col = 0; col < table->GetColCount(); ++col )
86 {
87 if( table->GetCell( row, col ) == this )
88 return col;
89 }
90 }
91
92 return -1;
93}
94
95
96wxString PCB_TABLECELL::GetAddr() const
97{
98 return wxString::Format( wxT( "%c%d" ),
99 'A' + GetColumn() % 26,
100 GetRow() + 1 );
101}
102
103
105{
106 return static_cast<PCB_TABLE*>( GetParent() )->GetColWidth( GetColumn() );
107}
108
109
111{
112 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
113
114 table->SetColWidth( GetColumn(), aWidth );
115 table->Normalize();
116}
117
118
120{
121 return static_cast<PCB_TABLE*>( GetParent() )->GetRowHeight( GetRow() );
122}
123
124
126{
127 PCB_TABLE* table = static_cast<PCB_TABLE*>( GetParent() );
128
129 table->SetRowHeight( GetRow(), aHeight );
130 table->Normalize();
131}
132
133
134void PCB_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
135{
136 aList.emplace_back( _( "Table Cell" ), GetAddr() );
137
138 // Don't use GetShownText() here; we want to show the user the variable references
139 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
140
141 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
142 aList.emplace_back( _( "Status" ), _( "Locked" ) );
143
144 aList.emplace_back( _( "Layer" ), GetLayerName() );
145 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
146
147 aList.emplace_back( _( "Cell Width" ),
148 aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
149 aList.emplace_back( _( "Cell Height" ),
150 aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
151
152 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
153
154 if( GetTextThickness() )
155 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
156 else
157 aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
158
159 aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
160 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
161}
162
163
164double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const
165{
166 if( aBoardItem.Type() != Type() )
167 return 0.0;
168
169 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
170
171 double similarity = 1.0;
172
173 if( m_colSpan != other.m_colSpan )
174 similarity *= 0.9;
175
176 if( m_rowSpan != other.m_rowSpan )
177 similarity *= 0.9;
178
179 similarity *= PCB_TEXTBOX::Similarity( other );
180
181 return similarity;
182}
183
184bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
185{
186 if( aBoardItem.Type() != Type() )
187 return false;
188
189 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
190
191 return *this == other;
192}
193
194bool PCB_TABLECELL::operator==( const PCB_TABLECELL& aOther ) const
195{
196 return m_colSpan == aOther.m_colSpan
197 && m_rowSpan == aOther.m_rowSpan
198 && PCB_TEXTBOX::operator==( aOther );
199}
200
201
202
204{
206 {
209
222
223 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ) );
224 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ) );
225 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) );
226 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask" ) );
227 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask Margin Override" ) );
228
230
231 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border" ) );
232 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Style" ) );
233 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Width" ) );
234
235 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
236 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
237 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
238 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
239 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
240 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Width" ) );
241 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Height" ) );
242 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
243 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
244 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
245
246 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
247 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
248 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
249 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
250 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
251 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
252
253 const wxString tableProps = _( "Table" );
254
255 propMgr.AddProperty( new PROPERTY<PCB_TABLECELL, int>( _HKI( "Column Width" ),
257 PROPERTY_DISPLAY::PT_SIZE ),
258 tableProps );
259
260 propMgr.AddProperty( new PROPERTY<PCB_TABLECELL, int>( _HKI( "Row Height" ),
262 PROPERTY_DISPLAY::PT_SIZE ),
263 tableProps );
264 }
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:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:232
bool IsLocked() const override
Definition: board_item.cpp:103
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:79
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:210
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:180
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
void SetRectangleHeight(const int &aHeight)
Definition: eda_shape.cpp:450
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)
Definition: eda_shape.cpp:465
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
int GetTextHeight() const
Definition: eda_text.h:264
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
KIFONT::FONT * GetFont() const
Definition: eda_text.h:244
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:393
int GetTextWidth() const
Definition: eda_text.h:261
bool IsMirrored() const
Definition: eda_text.h:187
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:465
int GetTextThickness() const
Definition: eda_text.h:125
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
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.
bool operator==(const PCB_TEXTBOX &aOther) const
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:74
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()
Definition: property_mgr.h:76
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().
#define _HKI(x)
#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:790
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.
Definition: ui_common.cpp:203
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:400
static struct PCB_TABLECELL_DESC _PCB_TABLECELL_DESC
#define TYPE_HASH(x)
Definition: property.h:72
#define REGISTER_TYPE(x)
Definition: property_mgr.h:351
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95