KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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) 2023 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 <sch_edit_frame.h>
25#include <widgets/msgpanel.h>
26#include <string_utils.h>
27#include <sch_table.h>
28#include <sch_tablecell.h>
29
30
31SCH_TABLECELL::SCH_TABLECELL( int aLineWidth, FILL_T aFillType ) :
32 SCH_TEXTBOX( LAYER_NOTES, aLineWidth, aFillType, wxEmptyString, SCH_TABLECELL_T ),
33 m_colSpan( 1 ),
34 m_rowSpan( 1 )
35{
36}
37
38
40{
41 SCH_TEXTBOX::SwapData( aItem );
42
43 SCH_TABLECELL* cell = static_cast<SCH_TABLECELL*>( aItem );
44
45 std::swap( m_colSpan, cell->m_colSpan );
46 std::swap( m_rowSpan, cell->m_rowSpan );
47}
48
49
50wxString SCH_TABLECELL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
51{
52 return wxString::Format( _( "Table Cell %s" ), GetAddr() );
53}
54
55
57{
58 const SCH_TABLE* table = static_cast<const SCH_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 SCH_TABLE* table = static_cast<const SCH_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 SCH_TABLECELL::GetAddr() const
91{
92 return wxString::Format( wxT( "%c%d" ),
93 'A' + GetColumn() % 26,
94 GetRow() + 1 );
95}
96
97
98void SCH_TABLECELL::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
99 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
100{
101 if( m_colSpan >= 1 && m_rowSpan >= 1 )
102 SCH_TEXTBOX::Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
103}
104
105
106void SCH_TABLECELL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
107 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
108{
109 if( m_colSpan >= 1 && m_rowSpan >= 1 )
110 SCH_TEXTBOX::Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
111}
112
113
114void SCH_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
115{
116 aList.emplace_back( _( "Table Cell" ), GetAddr() );
117
118 // Don't use GetShownText() here; we want to show the user the variable references
119 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
120
121 aList.emplace_back( _( "Cell Width" ),
122 aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
123 aList.emplace_back( _( "Cell Height" ),
124 aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
125
126 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
127
128 wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
129 int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
130 aList.emplace_back( _( "Style" ), textStyle[style] );
131
132 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
133}
134
135
136double SCH_TABLECELL::Similarity( const SCH_ITEM& aOtherItem ) const
137{
138 if( aOtherItem.Type() != Type() )
139 return 0.0;
140
141 const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem );
142
143 double similarity = 1.0;
144
145 if( m_colSpan != other.m_colSpan )
146 similarity *= 0.9;
147
148 if( m_rowSpan != other.m_rowSpan )
149 similarity *= 0.9;
150
151 similarity *= SCH_TEXTBOX::Similarity( other );
152
153 return similarity;
154}
155
156
157bool SCH_TABLECELL::operator==( const SCH_ITEM& aOtherItem ) const
158{
159 if( aOtherItem.Type() != Type() )
160 return false;
161
162 const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem );
163
164 return *this == other;
165}
166
167
168bool SCH_TABLECELL::operator==( const SCH_TABLECELL& aOtherItem ) const
169{
170 return m_colSpan == aOtherItem.m_colSpan && m_rowSpan == aOtherItem.m_rowSpan
171 && SCH_TEXTBOX::operator==( aOtherItem );
172}
173
175{
177 {
180
189
190 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
191 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
192 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
193 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
194
195 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
196 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
197 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
198 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
199
200 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
201 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
202 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
203 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
204 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
205 }
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
EDA_ITEM * GetParent() const
Definition: eda_item.h:102
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
bool IsItalic() const
Definition: eda_text.h:144
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
int GetTextWidth() const
Definition: eda_text.h:225
bool IsBold() const
Definition: eda_text.h:148
Base plotter engine class.
Definition: plotter.h:104
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
SCH_TABLECELL(int aLineWidth=0, FILL_T aFillType=FILL_T::NO_FILL)
wxString GetAddr() const
bool operator==(const SCH_TABLECELL &aOther) const
int GetColumn() const
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.
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &offset, bool aForceNoFill, bool aDimmed) override
Print an item.
int GetRow() 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 SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
int GetColCount() const
Definition: sch_table.h:104
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition: sch_table.h:131
int GetRowCount() const
Definition: sch_table.h:106
bool operator==(const SCH_ITEM &aOther) const override
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &offset, bool aForceNoFill, bool aDimmed) override
Print an item.
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.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
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)
FILL_T
Definition: eda_shape.h:55
@ LAYER_NOTES
Definition: layer_ids.h:371
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:192
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
static struct SCH_TABLECELL_DESC _SCH_TABLECELL_DESC
@ SCH_TABLECELL_T
Definition: typeinfo.h:166