KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Fields are texts attached to a symbol, some of which have a special meaning.
27 * Fields 0 and 1 are very important: reference and value.
28 * Field 2 is used as default footprint name.
29 * Field 3 is used to point to a datasheet (usually a URL).
30 * Fields 4+ are user fields. They can be renamed and can appear in reports.
31 */
32
33#include <wx/log.h>
34#include <wx/menu.h>
35#include <base_units.h>
36#include <common.h> // for ExpandTextVars
37#include <eda_item.h>
38#include <sch_edit_frame.h>
39#include <plotters/plotter.h>
40#include <bitmaps.h>
41#include <core/kicad_algo.h>
42#include <core/mirror.h>
43#include <kiway.h>
44#include <general.h>
45#include <symbol_library.h>
46#include <sch_symbol.h>
47#include <sch_field.h>
48#include <sch_label.h>
49#include <schematic.h>
51#include <string_utils.h>
52#include <trace_helpers.h>
53#include <trigo.h>
54#include <eeschema_id.h>
55#include <tool/tool_manager.h>
57#include <font/outline_font.h>
58
59SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
60 const wxString& aName ) :
61 SCH_ITEM( aParent, SCH_FIELD_T ),
62 EDA_TEXT( schIUScale, wxEmptyString ),
63 m_id( 0 ),
64 m_name( aName ),
65 m_showName( false ),
66 m_allowAutoPlace( true ),
67 m_renderCacheValid( false ),
68 m_lastResolvedColor( COLOR4D::UNSPECIFIED )
69{
70 SetTextPos( aPos );
71 SetId( aFieldId ); // will also set the layer
72 SetVisible( false );
73}
74
75
76SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName ) :
77 SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
78{
79}
80
81
83 SCH_ITEM( aField ),
84 EDA_TEXT( aField )
85{
86 m_id = aField.m_id;
87 m_name = aField.m_name;
88 m_showName = aField.m_showName;
90
91 m_renderCache.clear();
92
93 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
94 {
95 KIFONT::OUTLINE_GLYPH* outline_glyph = static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() );
96 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline_glyph ) );
97 }
98
101
103}
104
105
107{
108 EDA_TEXT::operator=( aField );
109
110 m_id = aField.m_id;
111 m_name = aField.m_name;
112 m_showName = aField.m_showName;
114
115 m_renderCache.clear();
116
117 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
118 {
119 KIFONT::OUTLINE_GLYPH* outline_glyph = static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() );
120 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline_glyph ) );
121 }
122
125
127
128 return *this;
129}
130
131
133{
134 return new SCH_FIELD( *this );
135}
136
137
138void SCH_FIELD::SetId( int aId )
139{
140 m_id = aId;
141
142 if( m_parent && m_parent->Type() == SCH_SHEET_T )
143 {
144 switch( m_id )
145 {
146 case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
148 default: SetLayer( LAYER_SHEETFIELDS ); break;
149 }
150 }
151 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
152 {
153 switch( m_id )
154 {
156 case VALUE_FIELD: SetLayer( LAYER_VALUEPART ); break;
157 default: SetLayer( LAYER_FIELDS ); break;
158 }
159 }
160 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
161 {
162 // We can't use defined IDs for labels because there can be multiple net class
163 // assignments.
164
165 if( GetCanonicalName() == wxT( "Netclass" ) )
167 else if( GetCanonicalName() == wxT( "Intersheetrefs" ) )
169 else
171 }
172}
173
174
175wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
176 int aDepth ) const
177{
178 std::function<bool( wxString* )> symbolResolver =
179 [&]( wxString* token ) -> bool
180 {
181 return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( aPath, token, aDepth + 1 );
182 };
183
184 std::function<bool( wxString* )> sheetResolver =
185 [&]( wxString* token ) -> bool
186 {
187 return static_cast<SCH_SHEET*>( m_parent )->ResolveTextVar( token, aDepth + 1 );
188 };
189
190 std::function<bool( wxString* )> labelResolver =
191 [&]( wxString* token ) -> bool
192 {
193 return static_cast<SCH_LABEL_BASE*>( m_parent )->ResolveTextVar( aPath, token,
194 aDepth + 1 );
195 };
196
197 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
198
199 if( IsNameShown() && aAllowExtraText )
200 text = GetName() << wxS( ": " ) << text;
201
202 if( text == wxS( "~" ) ) // Legacy placeholder for empty string
203 {
204 text = wxS( "" );
205 }
206 else if( HasTextVars() )
207 {
208 if( aDepth < 10 )
209 {
210 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
211 text = ExpandTextVars( text, &symbolResolver );
212 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
213 text = ExpandTextVars( text, &sheetResolver );
214 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
215 text = ExpandTextVars( text, &labelResolver );
216 else if( Schematic() )
218 }
219 }
220
221 // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
222 // id and the parent's type.
223
224 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
225 {
226 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
227
228 if( m_id == REFERENCE_FIELD )
229 {
230 // For more than one part per package, we must add the part selection
231 // A, B, ... or 1, 2, .. to the reference.
232 if( parentSymbol->GetUnitCount() > 1 )
233 text << LIB_SYMBOL::SubReference( parentSymbol->GetUnit() );
234 }
235 }
236 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
237 {
238 if( m_id == SHEETFILENAME && aAllowExtraText )
239 text = _( "File:" ) + wxS( " " )+ text;
240 }
241
242 return text;
243}
244
245
246wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
247{
248 if( SCHEMATIC* schematic = Schematic() )
249 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
250 else
251 return EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
252}
253
254
255
257{
259}
260
261
263{
265
266 if( !font )
268
269 return font;
270}
271
272
274{
277}
278
279
281{
283 m_renderCacheValid = false;
284}
285
286
287std::vector<std::unique_ptr<KIFONT::GLYPH>>*
288SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
289 TEXT_ATTRIBUTES& aAttrs ) const
290{
291 KIFONT::FONT* font = GetFont();
292
293 if( !font )
295
296 if( font->IsOutline() )
297 {
298 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
299
300 if( m_renderCache.empty() || !m_renderCacheValid )
301 {
302 m_renderCache.clear();
303
304 outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs );
305
306 m_renderCachePos = forPosition;
307 m_renderCacheValid = true;
308 }
309
310 if( m_renderCachePos != forPosition )
311 {
312 VECTOR2I delta = forPosition - m_renderCachePos;
313
314 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
315 static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
316
317 m_renderCachePos = forPosition;
318 }
319
320 return &m_renderCache;
321 }
322
323 return nullptr;
324}
325
326
327void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
328{
329 wxDC* DC = aSettings->GetPrintDC();
331 bool blackAndWhiteMode = GetGRForceBlackPenState();
332 VECTOR2I textpos;
333 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
334
335 if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( true ).IsEmpty() )
336 return;
337
338 COLOR4D bg = aSettings->GetBackgroundColor();
339
340 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
341 bg = COLOR4D::WHITE;
342
343 if( IsForceVisible() )
344 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
345
346 if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
348
349 // Calculate the text orientation according to the symbol orientation.
350 EDA_ANGLE orient = GetTextAngle();
351
352 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
353 {
354 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
355
356 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
357 {
358 if( orient == ANGLE_HORIZONTAL )
359 orient = ANGLE_VERTICAL;
360 else
361 orient = ANGLE_HORIZONTAL;
362 }
363
364 if( parentSymbol && parentSymbol->GetDNP() )
365 {
366 color.Desaturate();
367 color = color.Mix( bg, 0.5f );
368 }
369 }
370
371 KIFONT::FONT* font = GetFont();
372
373 if( !font )
374 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
375
376 /*
377 * Calculate the text justification, according to the symbol orientation/mirror.
378 * This is a bit complicated due to cumulative calculations:
379 * - numerous cases (mirrored or not, rotation)
380 * - the GRText function will also recalculate H and V justifications according to the text
381 * orientation.
382 * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
383 * to calculate so the more easily way is to use no justifications (centered text) and use
384 * GetBoundingBox to know the text coordinate considered as centered
385 */
386 textpos = GetBoundingBox().Centre() + aOffset;
387
388 GRPrintText( DC, textpos, color, GetShownText( true ), orient, GetTextSize(),
390 font );
391}
392
393
394void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
395{
396 SetAttributes( aSource );
397 SetNameShown( aSource.IsNameShown() );
398 SetCanAutoplace( aSource.CanAutoplace() );
399}
400
401
403{
404 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ),
405 wxT( "Cannot swap field data with invalid item." ) );
406
407 SCH_FIELD* item = (SCH_FIELD*) aItem;
408
409 std::swap( m_layer, item->m_layer );
410 std::swap( m_showName, item->m_showName );
411 std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
412 SwapText( *item );
413 SwapAttributes( *item );
414
415 std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
416}
417
418
420{
421 if( GetTextColor() != COLOR4D::UNSPECIFIED )
422 {
424 }
425 else
426 {
427 SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
428
429 if( parentLabel && !parentLabel->IsConnectivityDirty() )
430 m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor();
431 else
433 }
434
435 return m_lastResolvedColor;
436}
437
438
439void SCH_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
440{
441 aCount = 2;
442
443 switch( m_id )
444 {
445 case REFERENCE_FIELD: aLayers[0] = LAYER_REFERENCEPART; break;
446 case VALUE_FIELD: aLayers[0] = LAYER_VALUEPART; break;
447 default: aLayers[0] = LAYER_FIELDS; break;
448 }
449
450 aLayers[1] = LAYER_SELECTION_SHADOWS;
451}
452
453
455{
456 // Calculate the text orientation according to the symbol orientation.
457 EDA_ANGLE orient = GetTextAngle();
458
459 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
460 {
461 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
462
463 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
464 {
465 if( orient.IsHorizontal() )
466 orient = ANGLE_VERTICAL;
467 else
468 orient = ANGLE_HORIZONTAL;
469 }
470 }
471
472 return orient;
473}
474
475
477{
478 // Calculate the text bounding box:
479 BOX2I bbox = GetTextBox();
480
481 // Calculate the bounding box position relative to the parent:
482 VECTOR2I origin = GetParentPosition();
483 VECTOR2I pos = GetTextPos() - origin;
484 VECTOR2I begin = bbox.GetOrigin() - origin;
485 VECTOR2I end = bbox.GetEnd() - origin;
486 RotatePoint( begin, pos, GetTextAngle() );
487 RotatePoint( end, pos, GetTextAngle() );
488
489 // Now, apply the symbol transform (mirror/rot)
490 TRANSFORM transform;
491
492 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
493 {
494 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
495
496 // Due to the Y axis direction, we must mirror the bounding box,
497 // relative to the text position:
498 MIRROR( begin.y, pos.y );
499 MIRROR( end.y, pos.y );
500
501 transform = parentSymbol->GetTransform();
502 }
503 else
504 {
505 transform = TRANSFORM( 1, 0, 0, 1 ); // identity transform
506 }
507
508 bbox.SetOrigin( transform.TransformCoordinate( begin ) );
509 bbox.SetEnd( transform.TransformCoordinate( end ) );
510
511 bbox.Move( origin );
512 bbox.Normalize();
513
514 return bbox;
515}
516
517
519{
520 VECTOR2I render_center = GetBoundingBox().Centre();
521 VECTOR2I pos = GetPosition();
522
523 switch( GetHorizJustify() )
524 {
526 if( GetDrawRotation().IsVertical() )
527 return render_center.y > pos.y;
528 else
529 return render_center.x < pos.x;
531 if( GetDrawRotation().IsVertical() )
532 return render_center.y < pos.y;
533 else
534 return render_center.x > pos.x;
535 default:
536 return false;
537 }
538}
539
540
542{
543 switch( GetHorizJustify() )
544 {
549 default:
551 }
552}
553
554
556{
557 VECTOR2I render_center = GetBoundingBox().Centre();
558 VECTOR2I pos = GetPosition();
559
560 switch( GetVertJustify() )
561 {
563 if( GetDrawRotation().IsVertical() )
564 return render_center.x < pos.x;
565 else
566 return render_center.y < pos.y;
568 if( GetDrawRotation().IsVertical() )
569 return render_center.x > pos.x;
570 else
571 return render_center.y > pos.y;
572 default:
573 return false;
574 }
575}
576
577
579{
580 switch( GetVertJustify() )
581 {
586 default:
588 }
589}
590
591
592bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
593{
594 bool searchHiddenFields = false;
595 bool searchAndReplace = false;
596 bool replaceReferences = false;
597
598 try
599 {
600 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData ); // downcast
601 searchHiddenFields = schSearchData.searchAllFields;
602 searchAndReplace = schSearchData.searchAndReplace;
603 replaceReferences = schSearchData.replaceReferences;
604 }
605 catch( const std::bad_cast& )
606 {
607 }
608
609 wxString text = UnescapeString( GetText() );
610
611 if( !IsVisible() && !searchHiddenFields )
612 return false;
613
615 {
616 if( searchAndReplace && !replaceReferences )
617 return false;
618
619 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
620 wxASSERT( aAuxData );
621
622 // Take sheet path into account which effects the reference field and the unit for
623 // symbols with multiple parts.
624 if( aAuxData )
625 {
626 text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
627
628 if( SCH_ITEM::Matches( text, aSearchData ) )
629 return true;
630
631 if( parentSymbol->GetUnitCount() > 1 )
632 text << LIB_SYMBOL::SubReference( parentSymbol->GetUnit() );
633 }
634 }
635
636 return SCH_ITEM::Matches( text, aSearchData );
637}
638
639
641{
642 if( m_parent && m_parent->Type() == SCH_SHEET_T )
643 {
644 // See comments in SCH_FIELD::Replace(), below.
645 if( m_id == SHEETFILENAME )
646 return false;
647 }
648 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
649 {
650 if( m_id == 0 /* IntersheetRefs */ )
651 return false;
652 }
653
654 return true;
655}
656
657
658bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
659{
660 bool replaceReferences = false;
661
662 try
663 {
664 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
665 replaceReferences = schSearchData.replaceReferences;
666 }
667 catch( const std::bad_cast& )
668 {
669 }
670
671 wxString text;
672 bool isReplaced = false;
673
674 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
675 {
676 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
677
678 switch( m_id )
679 {
680 case REFERENCE_FIELD:
681 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
682
683 if( !replaceReferences )
684 return false;
685
686 text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
687 isReplaced = EDA_ITEM::Replace( aSearchData, text );
688
689 if( isReplaced )
690 parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
691
692 break;
693
694 case VALUE_FIELD:
695 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
696
697 text = parentSymbol->GetField( VALUE_FIELD )->GetText();
698 isReplaced = EDA_ITEM::Replace( aSearchData, text );
699
700 if( isReplaced )
701 parentSymbol->SetValueFieldText( text );
702
703 break;
704
705 case FOOTPRINT_FIELD:
706 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
707
708 text = parentSymbol->GetField( FOOTPRINT_FIELD )->GetText();
709 isReplaced = EDA_ITEM::Replace( aSearchData, text );
710
711 if( isReplaced )
712 parentSymbol->SetFootprintFieldText( text );
713
714 break;
715
716 default:
717 isReplaced = EDA_TEXT::Replace( aSearchData );
718 }
719 }
720 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
721 {
722 isReplaced = EDA_TEXT::Replace( aSearchData );
723
724 if( m_id == SHEETFILENAME && isReplaced )
725 {
726 // If we allowed this we'd have a bunch of work to do here, including warning
727 // about it not being undoable, checking for recursive hierarchies, reloading
728 // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
729 }
730 }
731 else
732 {
733 isReplaced = EDA_TEXT::Replace( aSearchData );
734 }
735
736 return isReplaced;
737}
738
739
740void SCH_FIELD::Rotate( const VECTOR2I& aCenter )
741{
742 VECTOR2I pt = GetPosition();
743 RotatePoint( pt, aCenter, ANGLE_90 );
744 SetPosition( pt );
745}
746
747
748wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
749{
750 return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetText() ) );
751}
752
753
754void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
755{
756 wxString msg;
757
758 aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
759
760 // Don't use GetShownText() here; we want to show the user the variable references
761 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
762
763 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
764
765 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
766
767 aList.emplace_back( _( "Style" ), GetTextStyleName() );
768
769 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
770
771 switch ( GetHorizJustify() )
772 {
773 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
774 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
775 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
776 }
777
778 aList.emplace_back( _( "H Justification" ), msg );
779
780 switch ( GetVertJustify() )
781 {
782 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
783 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
784 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
785 }
786
787 aList.emplace_back( _( "V Justification" ), msg );
788}
789
790
792{
793 constexpr int START_ID = 1;
794
795 if( IsHypertext() )
796 {
797 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
798 std::vector<std::pair<wxString, wxString>> pages;
799 wxMenu menu;
800 wxString href;
801
802 label->GetIntersheetRefs( &pages );
803
804 for( int i = 0; i < (int) pages.size(); ++i )
805 {
806 menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
807 pages[i].first,
808 pages[i].second ) );
809 }
810
811 menu.AppendSeparator();
812 menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
813
814 int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
815
816 if( sel >= 0 && sel < (int) pages.size() )
817 href = wxT( "#" ) + pages[ sel ].first;
818 else if( sel == 999 )
820
821 if( !href.IsEmpty() )
822 {
824 navTool->HypertextCommand( href );
825 }
826 }
827}
828
829
830wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
831{
832 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
833 {
834 if( m_id >= 0 && m_id < MANDATORY_FIELDS )
836 else if( m_name.IsEmpty() && aUseDefaultName )
838 else
839 return m_name;
840 }
841 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
842 {
843 if( m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS )
845 else if( m_name.IsEmpty() && aUseDefaultName )
847 else
848 return m_name;
849 }
850 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
851 {
852 return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
853 }
854 else
855 {
856 wxFAIL_MSG( "Unhandled field owner type." );
857 return m_name;
858 }
859}
860
861
863{
864 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
865 {
866 switch( m_id )
867 {
868 case REFERENCE_FIELD: return wxT( "Reference" );
869 case VALUE_FIELD: return wxT( "Value" );
870 case FOOTPRINT_FIELD: return wxT( "Footprint" );
871 case DATASHEET_FIELD: return wxT( "Datasheet" );
872 default: return m_name;
873 }
874 }
875 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
876 {
877 switch( m_id )
878 {
879 case SHEETNAME: return wxT( "Sheetname" );
880 case SHEETFILENAME: return wxT( "Sheetfile" );
881 default: return m_name;
882 }
883 }
884 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
885 {
886 // These should be stored in canonical format, but just in case:
887 if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) )
888 return wxT( "Netclass" );
889 else if( m_name == _( "Sheet References" )
890 || m_name == wxT( "Sheet References" )
891 || m_name == wxT( "Intersheet References" ) )
892 return wxT( "Intersheetrefs" );
893 else
894 return m_name;
895 }
896 else
897 {
898 if( m_parent )
899 {
900 wxFAIL_MSG( wxString::Format( "Unhandled field owner type (id %d, parent type %d).",
901 m_id, m_parent->Type() ) );
902 }
903
904 return m_name;
905 }
906}
907
908
910{
911 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
912 {
913 switch( m_id )
914 {
915 case REFERENCE_FIELD: return BITMAPS::edit_comp_ref;
916 case VALUE_FIELD: return BITMAPS::edit_comp_value;
917 case FOOTPRINT_FIELD: return BITMAPS::edit_comp_footprint;
918 default: return BITMAPS::text;
919 }
920 }
921
922 return BITMAPS::text;
923}
924
925
926bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
927{
928 // Do not hit test hidden or empty fields.
929 if( !IsVisible() || GetShownText( true ).IsEmpty() )
930 return false;
931
932 BOX2I rect = GetBoundingBox();
933
934 rect.Inflate( aAccuracy );
935
936 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
937 {
938 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
939 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
940 }
941
942 return rect.Contains( aPosition );
943}
944
945
946bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
947{
948 // Do not hit test hidden fields.
949 if( !IsVisible() || GetShownText( true ).IsEmpty() )
950 return false;
951
952 BOX2I rect = aRect;
953
954 rect.Inflate( aAccuracy );
955
956 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
957 {
958 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
959 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
960 }
961
962 if( aContained )
963 return rect.Contains( GetBoundingBox() );
964
965 return rect.Intersects( GetBoundingBox() );
966}
967
968
969void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
970{
971 if( GetShownText( true ).IsEmpty() || aBackground )
972 return;
973
974 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
975 COLOR4D color = settings->GetLayerColor( GetLayer() );
976 int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
977
978 COLOR4D bg = settings->GetBackgroundColor();;
979
980 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
981 bg = COLOR4D::WHITE;
982
983 if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
985
986 penWidth = std::max( penWidth, settings->GetMinPenWidth() );
987
988 // clamp the pen width to be sure the text is readable
989 penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
990
991 if( !IsVisible() )
992 return;
993
994 // Calculate the text orientation, according to the symbol orientation/mirror
995 EDA_ANGLE orient = GetTextAngle();
996 VECTOR2I textpos = GetTextPos();
999
1000 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1001 {
1002 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1003
1004 if( parentSymbol->GetDNP() )
1005 {
1006 color.Desaturate();
1007 color = color.Mix( bg, 0.5f );
1008 }
1009
1010 if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
1011 {
1012 if( orient.IsHorizontal() )
1013 orient = ANGLE_VERTICAL;
1014 else
1015 orient = ANGLE_HORIZONTAL;
1016 }
1017
1018 /*
1019 * Calculate the text justification, according to the symbol orientation/mirror. This is
1020 * a bit complicated due to cumulative calculations:
1021 * - numerous cases (mirrored or not, rotation)
1022 * - the plotter's Text() function will also recalculate H and V justifications according
1023 * to the text orientation
1024 * - when a symbol is mirrored the text is not, and justifications become a nightmare
1025 *
1026 * So the easier way is to use no justifications (centered text) and use GetBoundingBox to
1027 * know the text coordinate considered as centered.
1028 */
1029 hjustify = GR_TEXT_H_ALIGN_CENTER;
1030 vjustify = GR_TEXT_V_ALIGN_CENTER;
1031 textpos = GetBoundingBox().Centre();
1032 }
1033 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1034 {
1035 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
1036 textpos += label->GetSchematicTextOffset( settings );
1037 }
1038
1039 KIFONT::FONT* font = GetFont();
1040
1041 if( !font )
1042 font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() );
1043
1045 attrs.m_StrokeWidth = penWidth;
1046 attrs.m_Halign = hjustify;
1047 attrs.m_Valign = vjustify;
1048 attrs.m_Angle = orient;
1049 attrs.m_Multiline = false;
1050
1051 aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
1052
1053 if( IsHypertext() )
1054 {
1055 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1056 std::vector<std::pair<wxString, wxString>> pages;
1057 std::vector<wxString> pageHrefs;
1058 BOX2I bbox = GetBoundingBox();
1059
1060 wxCHECK( label, /* void */ );
1061
1062 label->GetIntersheetRefs( &pages );
1063
1064 for( const std::pair<wxString, wxString>& page : pages )
1065 pageHrefs.push_back( wxT( "#" ) + page.first );
1066
1067 bbox.Offset( label->GetSchematicTextOffset( settings ) );
1068
1069 aPlotter->HyperlinkMenu( bbox, pageHrefs );
1070 }
1071}
1072
1073
1074void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
1075{
1076 // Actual positions are calculated by the rotation/mirror transform of the parent symbol
1077 // of the field. The inverse transform is used to calculate the position relative to the
1078 // parent symbol.
1079 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1080 {
1081 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1082 VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
1083
1084 relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
1085
1086 SetTextPos( relPos + parentSymbol->GetPosition() );
1087 return;
1088 }
1089
1090 SetTextPos( aPosition );
1091}
1092
1093
1095{
1096 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1097 {
1098 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1099 VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
1100
1101 relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
1102
1103 return relativePos + parentSymbol->GetPosition();
1104 }
1105
1106 return GetTextPos();
1107}
1108
1109
1111{
1112 return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
1113}
1114
1115
1116bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
1117{
1118 if( Type() != aItem.Type() )
1119 return Type() < aItem.Type();
1120
1121 auto field = static_cast<const SCH_FIELD*>( &aItem );
1122
1123 if( GetId() != field->GetId() )
1124 return GetId() < field->GetId();
1125
1126 if( GetText() != field->GetText() )
1127 return GetText() < field->GetText();
1128
1129 if( GetLibPosition().x != field->GetLibPosition().x )
1130 return GetLibPosition().x < field->GetLibPosition().x;
1131
1132 if( GetLibPosition().y != field->GetLibPosition().y )
1133 return GetLibPosition().y < field->GetLibPosition().y;
1134
1135 return GetName() < field->GetName();
1136}
int color
Definition: DXF_plotter.cpp:57
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
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:120
const Vec & GetOrigin() const
Definition: box2.h:184
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:225
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:270
const Vec GetEnd() const
Definition: box2.h:186
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:112
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
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:174
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
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:232
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:365
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:165
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
bool IsForceVisible() const
Definition: eda_item.h:184
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:167
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:77
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:536
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:216
COLOR4D GetTextColor() const
Definition: eda_text.h:213
wxString GetTextStyleName() const
Definition: eda_text.cpp:778
bool IsItalic() const
Definition: eda_text.h:138
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:128
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:92
void SetAttributes(const EDA_TEXT &aSrc)
Set the text attributes from another instance.
Definition: eda_text.cpp:276
virtual bool IsVisible() const
Definition: eda_text.h:144
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:393
KIFONT::FONT * GetFont() const
Definition: eda_text.h:196
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:144
int GetTextWidth() const
Definition: eda_text.h:207
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:157
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:330
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:111
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:229
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:474
virtual void ClearRenderCache()
Definition: eda_text.cpp:468
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:180
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:309
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:296
bool IsBold() const
Definition: eda_text.h:141
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:160
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:103
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:285
VECTOR2I GetTextSize() const
Definition: eda_text.h:204
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:137
virtual bool IsOutline() const
Definition: font.h:113
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:52
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
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:61
bool CanAutoplace() const
Definition: lib_field.h:188
bool IsNameShown() const
Definition: lib_field.h:185
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:720
Base plotter engine class.
Definition: plotter.h:110
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:141
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, void *aData=nullptr)
Definition: plotter.cpp:758
bool GetColorMode() const
Definition: plotter.h:138
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition: plotter.h:466
Holds all the data relating to one schematic.
Definition: schematic.h:72
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
void ClearRenderCache() override
Definition: sch_field.cpp:280
COLOR4D m_lastResolvedColor
Definition: sch_field.h:266
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:578
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:476
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:264
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:969
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: sch_field.cpp:439
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1094
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:658
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:259
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:740
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:327
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:132
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:909
bool IsNameShown() const
Definition: sch_field.h:163
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:95
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_field.cpp:926
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:518
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:555
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:748
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:454
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:592
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:167
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:791
int GetPenWidth() const override
Definition: sch_field.cpp:256
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:862
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:419
int GetId() const
Definition: sch_field.h:125
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:106
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1116
VECTOR2I GetLibPosition() const
Definition: sch_field.h:231
SCH_FIELD(const VECTOR2I &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:59
bool m_renderCacheValid
Definition: sch_field.h:262
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:640
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:541
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:830
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1074
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:394
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:402
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:175
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:191
VECTOR2I m_renderCachePos
Definition: sch_field.h:263
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:288
void SetId(int aId)
Definition: sch_field.cpp:138
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: sch_field.cpp:754
void ClearCaches() override
Definition: sch_field.cpp:273
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1110
int m_id
Field index,.
Definition: sch_field.h:255
wxString m_name
Definition: sch_field.h:257
void SetNameShown(bool aShown=true)
Definition: sch_field.h:164
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:262
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:260
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:1487
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:294
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:174
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:256
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:249
bool IsConnectivityDirty() const
Definition: sch_item.h:416
SCH_LAYER_ID m_layer
Definition: sch_item.h:497
void GetIntersheetRefs(std::vector< std::pair< wxString, wxString > > *pages)
Builds an array of { pageNumber, pageName } pairs.
Definition: sch_label.cpp:537
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Definition: sch_label.cpp:184
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:275
Handle actions specific to the schematic editor.
static wxString g_BackLink
void HypertextCommand(const wxString &href)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:54
Schematic symbol object.
Definition: sch_symbol.h:81
int GetUnitCount() const
Return the number of units per package of the symbol.
Definition: sch_symbol.cpp:427
int GetUnit() const
Definition: sch_symbol.h:231
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:869
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:698
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:891
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:740
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:885
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:726
TRANSFORM & GetTransform()
Definition: sch_symbol.h:286
bool GetDNP() const
Definition: sch_symbol.h:767
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
int y1
Definition: transform.h:49
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:61
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:46
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58
The common library.
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:425
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:426
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:431
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)
Print a graphic text through wxDC.
Definition: gr_text.cpp:141
PROJECT & Prj()
Definition: kicad.cpp:565
@ LAYER_SHEETNAME
Definition: layer_ids.h:367
@ LAYER_HIDDEN
Definition: layer_ids.h:384
@ LAYER_VALUEPART
Definition: layer_ids.h:357
@ LAYER_FIELDS
Definition: layer_ids.h:358
@ LAYER_SHEETFIELDS
Definition: layer_ids.h:369
@ LAYER_REFERENCEPART
Definition: layer_ids.h:356
@ LAYER_NETCLASS_REFS
Definition: layer_ids.h:360
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:385
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:359
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:368
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:215
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:197
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:49
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
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.
Definition for symbol library class.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
constexpr int delta
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
@ SCH_SYMBOL_T
Definition: typeinfo.h:146
@ SCH_FIELD_T
Definition: typeinfo.h:145
@ SCH_SHEET_T
Definition: typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:142
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588