KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_field.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2022 CERN
6 * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <eda_item.h>
27#include <string_utils.h>
28#include <sch_draw_panel.h>
29#include <eda_draw_frame.h>
30#include <plotters/plotter.h>
31#include <font/font.h>
32#include <trigo.h>
33#include <base_units.h>
34#include <widgets/msgpanel.h>
35#include <bitmaps.h>
36#include <lib_symbol.h>
37#include <transform.h>
38#include <template_fieldnames.h>
40
41
42LIB_FIELD::LIB_FIELD( LIB_SYMBOL* aParent, int aId, const wxString& aName ) :
43 LIB_ITEM( LIB_FIELD_T, aParent ),
45{
46 Init( aId );
47 m_name = aName;
48}
49
50
52 LIB_ITEM( LIB_FIELD_T, nullptr ),
54{
55 Init( aId );
56}
57
58
59LIB_FIELD::LIB_FIELD( int aId, const wxString& aName ) :
60 LIB_ITEM( LIB_FIELD_T, nullptr ),
62{
63 Init( aId );
64 m_name = aName;
65}
66
67
69{
70 m_id = field.m_id;
71 m_name = field.m_name;
72 m_parent = field.m_parent;
74 m_showName = field.m_showName;
77
78 SetText( field.GetText() );
79 SetAttributes( field );
80
81 return *this;
82}
83
84
85void LIB_FIELD::Init( int aId )
86{
87 m_id = aId;
88
89 SetTextAngle( ANGLE_HORIZONTAL ); // constructor already did this.
90
91 // Fields in RAM must always have names, because we are trying to get less dependent on
92 // field ids and more dependent on names. Plus assumptions are made in the field editors.
94
95 // By contrast, VALUE and REFERENCE are are always constructed as initially visible, and
96 // template fieldsnames' initial visibility is controlled by the template fieldname config.
97 if( aId != VALUE_FIELD && aId != REFERENCE_FIELD && aId < MANDATORY_FIELDS )
98 SetVisible( false );
99
100 m_autoAdded = false;
101 m_showName = false;
102 m_allowAutoPlace = true;
103 m_showInChooser = true;
104}
105
106
107void LIB_FIELD::SetId( int aId )
108{
109 m_id = aId;
110}
111
112
114{
116}
117
118
120{
122
123 if( !font )
125
126 return font;
127}
128
129
130void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
131 const TRANSFORM& aTransform, bool aDimmed )
132{
133 wxDC* DC = aSettings->GetPrintDC();
135 COLOR4D bg = aSettings->GetBackgroundColor();
136 bool blackAndWhiteMode = GetGRForceBlackPenState();
137 int penWidth = GetEffectivePenWidth( aSettings );
138 VECTOR2I text_pos = aTransform.TransformCoordinate( GetTextPos() ) + aOffset;
139 wxString text = aData ? *static_cast<wxString*>( aData ) : GetText();
140
141 if( blackAndWhiteMode || bg == COLOR4D::UNSPECIFIED )
142 bg = COLOR4D::WHITE;
143
144 if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
146
147 if( aDimmed )
148 {
149 color.Desaturate( );
150 color = color.Mix( bg, 0.5f );
151 }
152
153 KIFONT::FONT* font = GetFont();
154
155 if( !font )
156 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
157
159 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, GetFontMetrics() );
160}
161
162
163bool LIB_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
164{
165 // Because HitTest is mainly used to select the field return false if it is empty
166 if( GetText().IsEmpty() )
167 return false;
168
169 // Build a temporary copy of the text for hit testing
170 EDA_TEXT tmp_text( *this );
171
172 // Reference designator text has one or 2 additional character (displays U? or U?A)
173 if( m_id == REFERENCE_FIELD )
174 {
175 const LIB_SYMBOL* parent = dynamic_cast<const LIB_SYMBOL*>( m_parent );
176
177 wxString extended_text = tmp_text.GetText();
178 extended_text.Append('?');
179
180 if ( parent && parent->GetUnitCount() > 1 )
181 extended_text.Append('A');
182
183 tmp_text.SetText( extended_text );
184 }
185
187
188 // The text orientation may need to be flipped if the transformation matrix causes xy axes
189 // to be flipped. This simple algo works only for schematic matrix (rot 90 or/and mirror)
190 bool t1 = ( DefaultTransform.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL );
192
193 return tmp_text.TextHitTest( aPosition, aAccuracy );
194}
195
196
198{
199 return new LIB_FIELD( *this );
200}
201
202
203void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
204{
205 aTarget->m_name = m_name;
206 aTarget->m_showName = m_showName;
209
210 aTarget->CopyText( *this );
211 aTarget->SetAttributes( *this );
212 aTarget->SetParent( m_parent );
213 aTarget->SetAutoAdded( IsAutoAdded() );
214}
215
216
217int LIB_FIELD::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
218{
219 wxASSERT( aOther.Type() == LIB_FIELD_T );
220
221 int retv = LIB_ITEM::compare( aOther, aCompareFlags );
222
223 if( retv )
224 return retv;
225
226 const LIB_FIELD* tmp = ( LIB_FIELD* ) &aOther;
227
228 // Equality test will vary depending whether or not the field is mandatory. Otherwise,
229 // sorting is done by ordinal.
230 if( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::EQUALITY )
231 {
232 // Mandatory fields have fixed ordinals and their names can vary due to translated field
233 // names. Optional fields have fixed names and their ordinals can vary.
234 if( IsMandatory() )
235 {
236 if( m_id != tmp->m_id )
237 return m_id - tmp->m_id;
238 }
239 else
240 {
241 retv = m_name.Cmp( tmp->m_name );
242
243 if( retv )
244 return retv;
245 }
246 }
247 else // assume we're sorting
248 {
249 if( m_id != tmp->m_id )
250 return m_id - tmp->m_id;
251 }
252
253 bool ignoreFieldText = false;
254
255 if( m_id == REFERENCE_FIELD && !( aCompareFlags & COMPARE_FLAGS::EQUALITY ) )
256 ignoreFieldText = true;
257
258 if( m_id == VALUE_FIELD && ( aCompareFlags & COMPARE_FLAGS::ERC ) )
259 ignoreFieldText = true;
260
261 if( !ignoreFieldText )
262 {
263 retv = GetText().CmpNoCase( tmp->GetText() );
264
265 if( retv != 0 )
266 return retv;
267 }
268
269 if( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::EQUALITY )
270 {
271 if( GetTextPos().x != tmp->GetTextPos().x )
272 return GetTextPos().x - tmp->GetTextPos().x;
273
274 if( GetTextPos().y != tmp->GetTextPos().y )
275 return GetTextPos().y - tmp->GetTextPos().y;
276 }
277
278 if( GetTextWidth() != tmp->GetTextWidth() )
279 return GetTextWidth() - tmp->GetTextWidth();
280
281 if( GetTextHeight() != tmp->GetTextHeight() )
282 return GetTextHeight() - tmp->GetTextHeight();
283
284 return 0;
285}
286
287
288void LIB_FIELD::Offset( const VECTOR2I& aOffset )
289{
290 EDA_TEXT::Offset( aOffset );
291}
292
293
294void LIB_FIELD::MoveTo( const VECTOR2I& newPosition )
295{
296 EDA_TEXT::SetTextPos( newPosition );
297}
298
299
301{
302 int x = GetTextPos().x;
303
304 x -= center.x;
305 x *= -1;
306 x += center.x;
307
308 SetTextX( x );
309}
310
311
313{
314 int y = GetTextPos().y;
315
316 y -= center.y;
317 y *= -1;
318 y += center.y;
319
320 SetTextY( y );
321}
322
323
324void LIB_FIELD::Rotate( const VECTOR2I& center, bool aRotateCCW )
325{
326 EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90;
327
328 VECTOR2I pt = GetTextPos();
329 RotatePoint( pt, center, rot_angle );
330 SetTextPos( pt );
331
333}
334
335
336void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
337 const TRANSFORM& aTransform, bool aDimmed ) const
338{
339 if( GetText().IsEmpty() || aBackground )
340 return;
341
342 RENDER_SETTINGS* renderSettings = aPlotter->RenderSettings();
343
344 // Calculate the text orientation, according to the symbol orientation/mirror.
345 EDA_ANGLE orient = GetTextAngle();
346
347 if( aTransform.y1 ) // Rotate symbol 90 deg.
348 {
349 if( orient.IsHorizontal() )
350 orient = ANGLE_VERTICAL;
351 else
352 orient = ANGLE_HORIZONTAL;
353 }
354
355 BOX2I bbox = GetBoundingBox();
356 bbox.RevertYAxis();
357
360 VECTOR2I textpos = aTransform.TransformCoordinate( bbox.Centre() ) + aOffset;
361
363 COLOR4D bg;
364
365 if( aPlotter->GetColorMode() )
366 {
367 if( GetTextColor() != COLOR4D::UNSPECIFIED )
369 else
370 color = renderSettings->GetLayerColor( GetDefaultLayer() );
371
372 bg = renderSettings->GetBackgroundColor();
373
374 if( bg == COLOR4D::UNSPECIFIED )
375 bg = COLOR4D::WHITE;
376 }
377 else
378 {
379 color = COLOR4D::BLACK;
380 bg = COLOR4D::WHITE;
381 }
382
383 if( aDimmed )
384 {
385 color.Desaturate( );
386 color = color.Mix( bg, 0.5f );
387 }
388
389 int penWidth = GetEffectivePenWidth( renderSettings );
390 KIFONT::FONT* font = GetFont();
391
392 if( !font )
393 font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
394
396 attrs.m_StrokeWidth = penWidth;
397 attrs.m_Halign = hjustify;
398 attrs.m_Valign = vjustify;
399 attrs.m_Angle = orient;
400 attrs.m_Multiline = false;
401
402 aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
403}
404
405
406wxString LIB_FIELD::GetFullText( int unit ) const
407{
408 if( m_id != REFERENCE_FIELD )
409 return GetText();
410
411 wxString text = GetText();
412 text << wxT( "?" );
413
414 wxCHECK( GetParent(), text );
415
416 if( GetParent()->IsMulti() )
417 text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
418
419 return text;
420}
421
422
423wxString LIB_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
424{
425 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
426
427 if( IsNameShown() && aAllowExtraText )
428 text = GetName() << wxT( ": " ) << text;
429
430 return text;
431}
432
433
435{
436 /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
437 * calling GetTextBox() that works using top to bottom Y axis orientation.
438 */
439 BOX2I bbox = GetTextBox( -1, true );
440 bbox.RevertYAxis();
441
442 // We are using now a bottom to top Y axis.
443 VECTOR2I orig = bbox.GetOrigin();
444 VECTOR2I end = bbox.GetEnd();
445
446 RotatePoint( orig, GetTextPos(), -GetTextAngle() );
447 RotatePoint( end, GetTextPos(), -GetTextAngle() );
448
449 bbox.SetOrigin( orig );
450 bbox.SetEnd( end );
451
452 // We are using now a top to bottom Y axis:
453 bbox.RevertYAxis();
454
455 return bbox;
456}
457
458
459void LIB_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
460{
461 aCount = 2;
462
463 switch( m_id )
464 {
465 case REFERENCE_FIELD: aLayers[0] = LAYER_REFERENCEPART; break;
466 case VALUE_FIELD: aLayers[0] = LAYER_VALUEPART; break;
467 default: aLayers[0] = LAYER_FIELDS; break;
468 }
469
470 aLayers[1] = LAYER_SELECTION_SHADOWS;
471}
472
473
475{
476 switch( m_id )
477 {
479 case VALUE_FIELD: return LAYER_VALUEPART;
480 default: return LAYER_FIELDS;
481 }
482}
483
484
485wxString LIB_FIELD::GetName( bool aUseDefaultName ) const
486{
487 if( m_name.IsEmpty() && aUseDefaultName )
489
490 return m_name;
491}
492
493
495{
496 if( m_id < MANDATORY_FIELDS )
497 return GetCanonicalFieldName( m_id );
498
499 return m_name;
500}
501
502
503void LIB_FIELD::SetName( const wxString& aName )
504{
505 // Mandatory field names are fixed.
506 if( IsMandatory() )
507 {
508 wxFAIL_MSG( wxS( "trying to set a MANDATORY_FIELD's name\n" ) );
509 return;
510 }
511
512 m_name = aName;
513}
514
515
516wxString LIB_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
517{
518 return wxString::Format( "%s '%s'",
521}
522
523
524void LIB_FIELD::BeginEdit( const VECTOR2I& aPosition )
525{
526 SetTextPos( aPosition );
527}
528
529
530void LIB_FIELD::CalcEdit( const VECTOR2I& aPosition )
531{
532 SetTextPos( aPosition );
533}
534
535
536void LIB_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
537{
538 wxString msg;
539
540 LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
541
542 // Don't use GetShownText(); we want to see the variable references here
543 aList.emplace_back( _( "Field" ), UnescapeString( GetName() ) );
544
545 // Don't use GetShownText() here; we want to show the user the variable references
546 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
547
548 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
549
550 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
551
552 aList.emplace_back( _( "Style" ), GetTextStyleName() );
553
554 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
555
556 switch ( GetHorizJustify() )
557 {
558 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
559 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
560 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
562 }
563
564 aList.emplace_back( _( "H Justification" ), msg );
565
566 switch ( GetVertJustify() )
567 {
568 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
569 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
570 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
572 }
573
574 aList.emplace_back( _( "V Justification" ), msg );
575}
576
577
579{
580 return BITMAPS::move;
581}
582
583
585{
586 return m_id >= 0 && m_id < MANDATORY_FIELDS;
587}
588
589
590bool LIB_FIELD::operator==( const LIB_ITEM& aItem ) const
591{
592 if( aItem.Type() != LIB_FIELD_T )
593 return false;
594
595 const LIB_FIELD& field = static_cast<const LIB_FIELD&>( aItem );
596
597 if( m_id != field.m_id )
598 return false;
599
600 if( m_name != field.m_name )
601 return false;
602
603 if( !m_parent || !aItem.GetParent() )
604 return false;
605
606 if( m_parent->m_Uuid != aItem.GetParent()->m_Uuid )
607 return false;
608
609 if( m_id < MANDATORY_FIELDS )
610 return true;
611
612 if( m_Uuid == field.m_Uuid )
613 return true;
614
615 return EDA_TEXT::operator==( field );
616}
617
618
619double LIB_FIELD::Similarity( const LIB_ITEM& aItem ) const
620{
621 if( aItem.Type() != LIB_FIELD_T )
622 return 0.0;
623
624 const LIB_FIELD& field = static_cast<const LIB_FIELD&>( aItem );
625
626 if( m_id != field.m_id && m_id < MANDATORY_FIELDS )
627 return 0.0;
628
629 if( m_parent->m_Uuid != aItem.GetParent()->m_Uuid )
630 return 0.0;
631
632 if( m_id < MANDATORY_FIELDS )
633 return 1.0;
634
635 if( m_Uuid == field.m_Uuid )
636 return 1.0;
637
638 double similarity = SimilarityBase( field );
639
640 similarity *= EDA_TEXT::Similarity( field );
641
642 return similarity;
643}
644
645static struct LIB_FIELD_DESC
646{
648 {
655
656 propMgr.AddProperty( new PROPERTY<LIB_FIELD, bool>( _HKI( "Show Field Name" ),
658
659 propMgr.AddProperty( new PROPERTY<LIB_FIELD, bool>( _HKI( "Allow Autoplacement" ),
661
662 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
663 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
664 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
665 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
666 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
667 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
668
669 propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
670 }
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
void SetOrigin(const Vec &pos)
Definition: box2.h:203
const Vec & GetOrigin() const
Definition: box2.h:184
void RevertYAxis()
Mirror the rectangle from the X axis (negate Y pos and size).
Definition: box2.h:690
const Vec GetEnd() const
Definition: box2.h:186
Vec Centre() const
Definition: box2.h:71
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:256
bool IsHorizontal() const
Definition: eda_angle.h:180
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
const KIID m_Uuid
Definition: eda_item.h:482
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:485
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:225
BOX2I GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:567
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:231
COLOR4D GetTextColor() const
Definition: eda_text.h:228
wxString GetTextStyleName() const
Definition: eda_text.cpp:824
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
virtual bool IsVisible() const
Definition: eda_text.h:148
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:419
void SetTextX(int aX)
Definition: eda_text.cpp:425
KIFONT::FONT * GetFont() const
Definition: eda_text.h:208
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:292
void SetTextY(int aY)
Definition: eda_text.cpp:431
int GetTextWidth() const
Definition: eda_text.h:222
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:437
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:161
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:245
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1151
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:706
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:192
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:324
bool IsBold() const
Definition: eda_text.h:145
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:190
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:164
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:106
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
bool operator==(const EDA_TEXT &aRhs) const
Definition: eda_text.h:354
VECTOR2I GetTextSize() const
Definition: eda_text.h:219
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
wxDC * GetPrintDC() const
Field object used in symbol libraries.
Definition: lib_field.h:62
bool IsAutoAdded() const
Definition: lib_field.h:189
bool m_allowAutoPlace
This field can be autoplaced when converted to a SCH_FIELD.
Definition: lib_field.h:243
void SetAutoAdded(bool aAutoAdded)
Definition: lib_field.h:190
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:197
void Offset(const VECTOR2I &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:288
void Init(int aId)
Object constructor initialization helper.
Definition: lib_field.cpp:85
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: lib_field.h:241
int m_id
Definition: lib_field.h:239
KIFONT::FONT * getDrawFont() const override
Definition: lib_field.cpp:119
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:324
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:240
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: lib_field.cpp:459
void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed) override
Print the field.
Definition: lib_field.cpp:130
bool CanAutoplace() const
Definition: lib_field.h:195
SCH_LAYER_ID GetDefaultLayer() const
Definition: lib_field.cpp:474
void Plot(PLOTTER *aPlotter, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const override
Plot the draw item using the plot object.
Definition: lib_field.cpp:336
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: lib_field.cpp:516
void SetId(int aId)
Definition: lib_field.cpp:107
bool operator==(const LIB_ITEM &aItem) const override
Test LIB_ITEM objects for equivalence.
Definition: lib_field.cpp:590
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:503
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:203
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: lib_field.h:244
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:406
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:485
bool IsNameShown() const
Definition: lib_field.h:192
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_field.cpp:524
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:494
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_field.cpp:578
double Similarity(const LIB_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: lib_field.cpp:619
int GetPenWidth() const override
Definition: lib_field.cpp:113
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:423
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:300
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:530
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:312
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:434
bool IsMandatory() const
Definition: lib_field.cpp:584
LIB_FIELD(int aId=2)
Definition: lib_field.cpp:51
void MoveTo(const VECTOR2I &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:294
void SetNameShown(bool aShown=true)
Definition: lib_field.h:193
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:68
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.
Definition: lib_field.cpp:536
void SetCanAutoplace(bool aCanPlace)
Definition: lib_field.h:196
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: lib_field.cpp:163
bool m_showName
Render the field's name in addition to its value.
Definition: lib_field.h:242
int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:217
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
const wxString & GetDefaultFont() const
Definition: lib_item.cpp:157
@ EQUALITY
Definition: lib_item.h:96
virtual int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:88
virtual int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:196
double SimilarityBase(const LIB_ITEM &aItem) const
Calculate the boilerplate similarity for all LIB_ITEMs without preventing the use above of a pure vir...
Definition: lib_item.h:227
const KIFONT::METRICS & GetFontMetrics() const
Definition: lib_item.cpp:165
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_item.cpp:68
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:209
Define a library symbol object.
Definition: lib_symbol.h:99
static wxString LetterSubReference(int aUnit, int aFirstId)
Definition: lib_symbol.cpp:760
int GetUnitCount() const override
For items with units, return the number of units.
Base plotter engine class.
Definition: plotter.h:104
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:135
bool GetColorMode() const
Definition: plotter.h:132
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Definition: plotter.cpp:753
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
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
int y1
Definition: transform.h:49
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:44
int x1
Definition: transform.h:48
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)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:432
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:431
TRANSFORM DefaultTransform
Definition: transform.cpp:32
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:142
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:352
@ LAYER_HIDDEN
Definition: layer_ids.h:392
@ LAYER_VALUEPART
Definition: layer_ids.h:364
@ LAYER_FIELDS
Definition: layer_ids.h:365
@ LAYER_REFERENCEPART
Definition: layer_ids.h:363
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:393
static struct LIB_FIELD_DESC _LIB_FIELD_DESC
Message panel definition file.
wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:210
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
#define TYPE_HASH(x)
Definition: property.h:67
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
wxString UnescapeString(const wxString &aSource)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
wxString GetCanonicalFieldName(int idx)
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
@ LIB_FIELD_T
Definition: typeinfo.h:212
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: ui_common.h:44