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 (C) 2024 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 <pcb_table.h>
29#include <pcb_tablecell.h>
30
31
33 PCB_TEXTBOX( aParent, PCB_TABLECELL_T ),
34 m_colSpan( 1 ),
35 m_rowSpan( 1 )
36{
37 if( IsBackLayer( aParent->GetLayer() ) )
38 SetMirrored( true );
39}
40
41
43{
44 wxASSERT( aImage->Type() == PCB_TABLECELL_T );
45
46 std::swap( *((PCB_TABLECELL*) this), *((PCB_TABLECELL*) aImage) );
47}
48
49
50wxString PCB_TABLECELL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
51{
52 return wxString::Format( _( "Table Cell %s" ), GetAddr() );
53}
54
55
57{
58 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
59
60 for( int row = 0; row < table->GetRowCount(); ++row )
61 {
62 for( int col = 0; col < table->GetColCount(); ++col )
63 {
64 if( table->GetCell( row, col ) == this )
65 return row;
66 }
67 }
68
69 return -1;
70}
71
72
74{
75 const PCB_TABLE* table = static_cast<const PCB_TABLE*>( GetParent() );
76
77 for( int row = 0; row < table->GetRowCount(); ++row )
78 {
79 for( int col = 0; col < table->GetColCount(); ++col )
80 {
81 if( table->GetCell( row, col ) == this )
82 return col;
83 }
84 }
85
86 return -1;
87}
88
89
90wxString PCB_TABLECELL::GetAddr() const
91{
92 return wxString::Format( wxT( "%c%d" ),
93 'A' + GetColumn() % 26,
94 GetRow() + 1 );
95}
96
97
98void PCB_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
99{
100 aList.emplace_back( _( "Table Cell" ), GetAddr() );
101
102 // Don't use GetShownText() here; we want to show the user the variable references
103 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
104
105 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
106 aList.emplace_back( _( "Status" ), _( "Locked" ) );
107
108 aList.emplace_back( _( "Layer" ), GetLayerName() );
109 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
110
111 aList.emplace_back( _( "Cell Width" ),
112 aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
113 aList.emplace_back( _( "Cell Height" ),
114 aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
115
116 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
117 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) );
118 aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
119 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
120}
121
122
123double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const
124{
125 if( aBoardItem.Type() != Type() )
126 return 0.0;
127
128 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
129
130 double similarity = 1.0;
131
132 if( m_colSpan != other.m_colSpan )
133 similarity *= 0.9;
134
135 if( m_rowSpan != other.m_rowSpan )
136 similarity *= 0.9;
137
138 similarity *= PCB_TEXTBOX::Similarity( other );
139
140 return similarity;
141}
142
143bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
144{
145 if( aBoardItem.Type() != Type() )
146 return false;
147
148 const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
149
150 return *this == other;
151}
152
153bool PCB_TABLECELL::operator==( const PCB_TABLECELL& aOther ) const
154{
155 return m_colSpan == aOther.m_colSpan
156 && m_rowSpan == aOther.m_rowSpan
157 && PCB_TEXTBOX::operator==( aOther );
158}
159
160
161
163{
165 {
168
181
182 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ) );
183 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ) );
184 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) );
185
187
188 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border" ) );
189 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Style" ) );
190 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( PCB_TEXTBOX ), _HKI( "Border Width" ) );
191
192 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
193 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
194 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
195 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
196 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
197 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
198 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
199 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
200
201 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
202 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
203 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
204 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
205 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
206 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
207 propMgr.Mask( TYPE_HASH( PCB_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
208 }
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:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual bool IsLocked() const
Definition: board_item.cpp:74
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:204
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:103
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:150
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:125
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
int GetTextHeight() const
Definition: eda_text.h:228
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:211
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:250
int GetTextWidth() const
Definition: eda_text.h:225
bool IsMirrored() const
Definition: eda_text.h:154
int GetTextThickness() const
Definition: eda_text.h:126
wxString GetAddr() const
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
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
int GetRow() const
int GetColumn() 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)
int GetRowCount() const
Definition: pcb_table.h:103
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition: pcb_table.h:128
int GetColCount() const
Definition: pcb_table.h:101
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 BOARD_ITEM &aBoardItem) const override
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
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:87
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:978
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:195
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
static struct PCB_TABLECELL_DESC _PCB_TABLECELL_DESC
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95