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 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 <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, bool aFull ) 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
99{
100 return static_cast<SCH_TABLE*>( GetParent() )->GetColWidth( GetColumn() );
101}
102
103
105{
106 SCH_TABLE* table = static_cast<SCH_TABLE*>( GetParent() );
107
108 table->SetColWidth( GetColumn(), aWidth );
109 table->Normalize();
110}
111
112
114{
115 return static_cast<SCH_TABLE*>( GetParent() )->GetRowHeight( GetRow() );
116}
117
118
120{
121 SCH_TABLE* table = static_cast<SCH_TABLE*>( GetParent() );
122
123 table->SetRowHeight( GetRow(), aHeight );
124 table->Normalize();
125}
126
127
128void SCH_TABLECELL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
129 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
130{
131 const int cell_body_style = -1; // flage to disable box ouline plotting
132 if( m_colSpan >= 1 && m_rowSpan >= 1 )
133 SCH_TEXTBOX::Plot( aPlotter, aBackground, aPlotOpts, aUnit, cell_body_style, aOffset, aDimmed );
134}
135
136
137void SCH_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
138{
139 aList.emplace_back( _( "Table Cell" ), GetAddr() );
140
141 // Don't use GetShownText() here; we want to show the user the variable references
142 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
143
144 aList.emplace_back( _( "Cell Width" ),
145 aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
146 aList.emplace_back( _( "Cell Height" ),
147 aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
148
149 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
150
151 wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
152 int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
153 aList.emplace_back( _( "Style" ), textStyle[style] );
154
155 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
156}
157
158
159double SCH_TABLECELL::Similarity( const SCH_ITEM& aOtherItem ) const
160{
161 if( aOtherItem.Type() != Type() )
162 return 0.0;
163
164 const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem );
165
166 double similarity = 1.0;
167
168 if( m_colSpan != other.m_colSpan )
169 similarity *= 0.9;
170
171 if( m_rowSpan != other.m_rowSpan )
172 similarity *= 0.9;
173
174 similarity *= SCH_TEXTBOX::Similarity( other );
175
176 return similarity;
177}
178
179
180bool SCH_TABLECELL::operator==( const SCH_ITEM& aOtherItem ) const
181{
182 if( aOtherItem.Type() != Type() )
183 return false;
184
185 const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem );
186
187 return *this == other;
188}
189
190
191bool SCH_TABLECELL::operator==( const SCH_TABLECELL& aOtherItem ) const
192{
193 return m_colSpan == aOtherItem.m_colSpan && m_rowSpan == aOtherItem.m_rowSpan
194 && SCH_TEXTBOX::operator==( aOtherItem );
195}
196
197
199{
201 {
204
213
214 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
215 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
216 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
217 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
218
219 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
220 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Width" ) );
221 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Height" ) );
222 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Fill" ) );
223 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Fill Color" ) );
224 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
225 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
226 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
227
228 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
229 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
230 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
231 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
232 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
233 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
234 propMgr.Mask( TYPE_HASH( SCH_TABLECELL ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
235
236 const wxString tableProps = _( "Table" );
237
238 propMgr.AddProperty( new PROPERTY<SCH_TABLECELL, int>( _HKI( "Column Width" ),
240 PROPERTY_DISPLAY::PT_SIZE ),
241 tableProps );
242
243 propMgr.AddProperty( new PROPERTY<SCH_TABLECELL, int>( _HKI( "Row Height" ),
245 PROPERTY_DISPLAY::PT_SIZE ),
246 tableProps );
247
248 const wxString cellProps = _( "Cell Properties" );
249
250 propMgr.AddProperty( new PROPERTY<EDA_SHAPE, bool>( _HKI( "Background Fill" ),
252 cellProps );
253
254 propMgr.AddProperty( new PROPERTY<EDA_SHAPE, COLOR4D>( _HKI( "Background Fill Color" ),
256 cellProps )
258
259 }
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
EDA_ITEM * GetParent() const
Definition: eda_item.h:112
virtual void SetFilled(bool aFlag)
Definition: eda_shape.h:136
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:153
bool IsSolidFill() const
Definition: eda_shape.h:117
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
COLOR4D GetFillColor() const
Definition: eda_shape.h:152
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
bool IsItalic() const
Definition: eda_text.h:166
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
int GetTextWidth() const
Definition: eda_text.h:261
bool IsBold() const
Definition: eda_text.h:181
Base plotter engine class.
Definition: plotter.h:121
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:322
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
int GetRowHeight() const
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
SCH_TABLECELL(int aLineWidth=0, FILL_T aFillType=FILL_T::NO_FILL)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
wxString GetAddr() const
bool operator==(const SCH_TABLECELL &aOther) const
void SetColumnWidth(int aWidth)
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 SetRowHeight(int aHeight)
int GetColumnWidth() const
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.
bool operator==(const SCH_ITEM &aOther) const override
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 swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
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:56
@ LAYER_NOTES
Definition: layer_ids.h:457
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
#define TYPE_HASH(x)
Definition: property.h:72
#define REGISTER_TYPE(x)
Definition: property_mgr.h:351
static struct SCH_TABLECELL_DESC _SCH_TABLECELL_DESC
@ SCH_TABLECELL_T
Definition: typeinfo.h:167