KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_pin.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2018 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 * @author Jon Evans <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include "sch_pin.h"
29
30#include <base_units.h>
31#include <pgm_base.h>
32#include <pin_layout_cache.h>
33#include <plotters/plotter.h>
34#include <sch_draw_panel.h>
35#include <sch_edit_frame.h>
36#include <symbol_edit_frame.h>
39#include <trigo.h>
40#include <string_utils.h>
41
42
43// small margin in internal units between the pin text and the pin line
44#define PIN_TEXT_MARGIN 4
45
47{
48 // These strings are the canonical name of the electrictal type
49 // Not translated, no space in name, only ASCII chars.
50 // to use when the string name must be known and well defined
51 // must have same order than enum ELECTRICAL_PINTYPE (see sch_pin.h)
52 static const wxChar* msgPinElectricType[] =
53 {
54 wxT( "input" ),
55 wxT( "output" ),
56 wxT( "bidirectional" ),
57 wxT( "tri_state" ),
58 wxT( "passive" ),
59 wxT( "free" ),
60 wxT( "unspecified" ),
61 wxT( "power_in" ),
62 wxT( "power_out" ),
63 wxT( "open_collector" ),
64 wxT( "open_emitter" ),
65 wxT( "no_connect" )
66 };
67
68 return msgPinElectricType[static_cast<int>( aType )];
69}
70
71
75static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
76{
77 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
78
79 if( settings && settings->m_PinSymbolSize )
80 return settings->m_PinSymbolSize;
81
82 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
83}
84
85
89static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
90{
91 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
92
93 if( settings && settings->m_PinSymbolSize )
94 return settings->m_PinSymbolSize;
95
96 return aPin.GetNumberTextSize() / 2;
97}
98
99
100SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol ) :
101 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
102 m_libPin( nullptr ),
103 m_position( { 0, 0 } ),
105 m_orientation( PIN_ORIENTATION::PIN_RIGHT ),
106 m_shape( GRAPHIC_PINSHAPE::LINE ),
108 m_hidden( false ),
109 m_numTextSize( schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ) ),
110 m_nameTextSize( schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ) ),
111 m_isDangling( true ),
112 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
113{
114 if( SYMBOL_EDITOR_SETTINGS* cfg = GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" ) )
115 {
116 m_length = schIUScale.MilsToIU( cfg->m_Defaults.pin_length );
117 m_numTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_num_size );
118 m_nameTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_name_size );
119 }
120
121 m_layer = LAYER_DEVICE;
122}
123
124
125SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber,
126 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
127 int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos,
128 int aUnit ) :
129 SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ),
130 m_libPin( nullptr ),
131 m_position( aPos ),
132 m_length( aLength ),
133 m_orientation( aOrientation ),
134 m_shape( GRAPHIC_PINSHAPE::LINE ),
135 m_type( aPinType ),
136 m_hidden( false ),
137 m_numTextSize( aNumTextSize ),
138 m_nameTextSize( aNameTextSize ),
139 m_isDangling( true ),
140 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
141{
142 SetName( aName );
143 SetNumber( aNumber );
144
146}
147
148
149SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, SCH_PIN* aLibPin ) :
150 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
151 m_libPin( aLibPin ),
152 m_orientation( PIN_ORIENTATION::INHERIT ),
153 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
155 m_isDangling( true ),
156 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
157{
158 wxASSERT( aParentSymbol );
159
163
165}
166
167
168SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
169 const KIID& aUuid ) :
170 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
171 m_libPin( nullptr ),
172 m_orientation( PIN_ORIENTATION::INHERIT ),
173 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
175 m_number( aNumber ),
176 m_alt( aAlt ),
177 m_isDangling( true ),
178 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
179{
180 wxASSERT( aParentSymbol );
181
182 const_cast<KIID&>( m_Uuid ) = aUuid;
184}
185
186
187SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
188 SCH_ITEM( aPin ),
189 m_libPin( aPin.m_libPin ),
190 m_alternates( aPin.m_alternates ),
191 m_position( aPin.m_position ),
192 m_length( aPin.m_length ),
193 m_orientation( aPin.m_orientation ),
194 m_shape( aPin.m_shape ),
195 m_type( aPin.m_type ),
196 m_hidden( aPin.m_hidden ),
197 m_numTextSize( aPin.m_numTextSize ),
198 m_nameTextSize( aPin.m_nameTextSize ),
199 m_alt( aPin.m_alt ),
200 m_isDangling( aPin.m_isDangling ),
201 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
202{
203 SetName( aPin.m_name );
204 SetNumber( aPin.m_number );
205
206 m_layer = aPin.m_layer;
207}
208
209
211{
212}
213
214
216{
217 SCH_ITEM::operator=( aPin );
218
219 m_libPin = aPin.m_libPin;
221 m_alt = aPin.m_alt;
222 m_name = aPin.m_name;
223 m_number = aPin.m_number;
224 m_position = aPin.m_position;
225 m_length = aPin.m_length;
227 m_shape = aPin.m_shape;
228 m_type = aPin.m_type;
229 m_hidden = aPin.m_hidden;
233
234 return *this;
235}
236
237
239{
240 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
241 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
242 else
243 return m_position;
244}
245
247{
248 if( m_orientation == PIN_ORIENTATION::INHERIT )
249 {
250 if( !m_libPin )
251 return PIN_ORIENTATION::PIN_RIGHT;
252
253 return m_libPin->GetOrientation();
254 }
255
256 return m_orientation;
257}
258
259
261{
262 if( !m_alt.IsEmpty() )
263 {
264 if( !m_libPin )
265 return GRAPHIC_PINSHAPE::LINE;
266
267 return m_libPin->GetAlt( m_alt ).m_Shape;
268 }
269 else if( m_shape == GRAPHIC_PINSHAPE::INHERIT )
270 {
271 if( !m_libPin )
272 return GRAPHIC_PINSHAPE::LINE;
273
274 return m_libPin->GetShape();
275 }
276
277 return m_shape;
278}
279
280
282{
283 if( !m_length.has_value() )
284 {
285 if( !m_libPin )
286 return 0;
287
288 return m_libPin->GetLength();
289 }
290
291 return m_length.value();
292}
293
294
296{
297 if( !m_alt.IsEmpty() )
298 {
299 if( !m_libPin )
300 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
301
302 return m_libPin->GetAlt( m_alt ).m_Type;
303 }
304 else if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
305 {
306 if( !m_libPin )
307 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
308
309 return m_libPin->GetType();
310 }
311
312 return m_type;
313}
314
316{
317 if( aType == m_type )
318 return;
319
320 m_type = aType;
322}
323
324
326{
327 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
328 {
329 if( !m_libPin )
330 return GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
331
333 }
334
336}
337
338
340{
341 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
342 {
343 if( !m_libPin )
344 return ElectricalPinTypeGetText( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
345
347 }
348
350}
351
352
354{
355 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
356 && ( !IsVisible() || GetParentSymbol()->IsGlobalPower() );
357}
358
359
361{
362 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
364}
365
366
368{
369 return IsLocalPower() || IsGlobalPower();
370}
371
372
374{
375 if( !m_hidden.has_value() )
376 {
377 if( !m_libPin )
378 return true;
379
380 return m_libPin->IsVisible();
381 }
382
383 return !m_hidden.value();
384}
385
386
387const wxString& SCH_PIN::GetName() const
388{
389 if( !m_alt.IsEmpty() )
390 return m_alt;
391
392 return GetBaseName();
393}
394
395
396const wxString& SCH_PIN::GetBaseName() const
397{
398 if( m_libPin )
399 return m_libPin->GetBaseName();
400
401 return m_name;
402}
403
404
405void SCH_PIN::SetName( const wxString& aName )
406{
407 if( m_name == aName )
408 return;
409
410 m_name = aName;
411
412 // pin name string does not support spaces
413 m_name.Replace( wxT( " " ), wxT( "_" ) );
414
416}
417
418
419void SCH_PIN::SetAlt( const wxString& aAlt )
420{
421 wxString alt = aAlt;
422
423 // Do not set the alternate pin definition to the default pin name. This breaks the library
424 // symbol comparison for the ERC and the library diff tool. It also incorrectly causes the
425 // schematic symbol pin alternate to be set.
426 if( aAlt.IsEmpty() || ( alt == GetBaseName() ) )
427 {
428 m_alt = wxEmptyString;
429 return;
430 }
431
432 wxCHECK2_MSG( m_libPin && m_libPin->GetAlternates().count( aAlt ), alt = wxEmptyString,
433 wxString::Format( wxS( "Pin '%s' does not have an alterate '%s'" ), m_number, aAlt ) );
434
435 m_alt = aAlt;
436}
437
439{
440 if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
441 return false;
442
443 return m_isDangling;
444}
445
446
447void SCH_PIN::SetIsDangling( bool aIsDangling )
448{
449 m_isDangling = aIsDangling;
450}
451
452
453bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
454{
455 bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
456 || GetType() == ELECTRICAL_PINTYPE::PT_NIC;
457 bool isConnectableType_b = aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
458 || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC;
459
460 return m_parent == aPin->GetParent()
461 && GetPosition() == aPin->GetPosition()
462 && GetName() == aPin->GetName()
463 && ( GetType() == aPin->GetType() || isConnectableType_a || isConnectableType_b );
464}
465
466
467bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
468{
469 const SCH_SEARCH_DATA& schSearchData =
470 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
471
472 if( schSearchData.searchAllPins
473 && ( EDA_ITEM::Matches( GetName(), aSearchData )
474 || EDA_ITEM::Matches( GetNumber(), aSearchData ) ) )
475 {
476 return true;
477 }
478
479 SCH_CONNECTION* connection = nullptr;
480 SCH_SHEET_PATH* sheetPath = reinterpret_cast<SCH_SHEET_PATH*>( aAuxData );
481
482 if( schSearchData.searchNetNames && sheetPath && ( connection = Connection( sheetPath ) ) )
483 {
484 wxString netName = connection->GetNetName();
485
486 if( EDA_ITEM::Matches( netName, aSearchData ) )
487 return true;
488 }
489
490 return false;
491}
492
493
494bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
495{
496 bool isReplaced = false;
497
498 /* TODO: waiting on a way to override pins in the schematic...
499 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
500 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
501 */
502
503 return isReplaced;
504}
505
506
507bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
508{
509 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
510 // no pin number or name. Give it a floor.
511 if( Schematic() )
512 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
513
514 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
515
516 return rect.Inflate( aAccuracy ).Contains( aPosition );
517}
518
519
520bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
521{
523 return false;
524
525 BOX2I sel = aRect;
526
527 if ( aAccuracy )
528 sel.Inflate( aAccuracy );
529
530 if( aContained )
531 return sel.Contains( GetBoundingBox( false, false, false ) );
532
533 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
534}
535
536
537wxString SCH_PIN::GetShownName() const
538{
539 if( !m_alt.IsEmpty() )
540 return m_alt;
541 else if( m_libPin )
542 return m_libPin->GetShownName();
543
544 return m_name;
545}
546
547
549{
550 return m_number;
551}
552
553
554void SCH_PIN::SetNumber( const wxString& aNumber )
555{
556 if( m_number == aNumber )
557 return;
558
559 m_number = aNumber;
560 // pin number string does not support spaces
561 m_number.Replace( wxT( " " ), wxT( "_" ) );
562
564}
565
566
568{
569 if( !m_nameTextSize.has_value() )
570 {
571 if( !m_libPin )
573
574 return m_libPin->GetNameTextSize();
575 }
576
577 return m_nameTextSize.value();
578}
579
580
582{
583 if( aSize == m_nameTextSize )
584 return;
585
586 m_nameTextSize = aSize;
588}
589
590
592{
593 if( !m_numTextSize.has_value() )
594 {
595 if( !m_libPin )
597
598 return m_libPin->GetNumberTextSize();
599 }
600
601 return m_numTextSize.value();
602}
603
604
606{
607 if( aSize == m_numTextSize )
608 return;
609
610 m_numTextSize = aSize;
612}
613
614
616{
617 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
618 {
619 const TRANSFORM& t = symbol->GetTransform();
620
621 if( !m_libPin )
622 return GetPosition();
623
624 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
625 }
626
627 switch( GetOrientation() )
628 {
629 default:
630 case PIN_ORIENTATION::PIN_RIGHT: return m_position + VECTOR2I( GetLength(), 0 );
631 case PIN_ORIENTATION::PIN_LEFT: return m_position + VECTOR2I( -GetLength(), 0 );
632 case PIN_ORIENTATION::PIN_UP: return m_position + VECTOR2I( 0, -GetLength() );
633 case PIN_ORIENTATION::PIN_DOWN: return m_position + VECTOR2I( 0, GetLength() );
634 }
635}
636
637
638void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
639 PIN_ORIENTATION aOrientation, bool aDimmed ) const
640{
641 int MapX1, MapY1, x1, y1;
642 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
643 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
644 COLOR4D bg = renderSettings->GetBackgroundColor();
645 int penWidth = GetEffectivePenWidth( renderSettings );
646 int pinLength = GetLength();
647
648 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
649 bg = COLOR4D::WHITE;
650
651 if( aDimmed )
652 {
653 color.Desaturate( );
654 color = color.Mix( bg, 0.5f );
655 }
656
657 aPlotter->SetColor( color );
658 aPlotter->SetCurrentLineWidth( penWidth );
659
660 MapX1 = MapY1 = 0;
661 x1 = aPosition.x; y1 = aPosition.y;
662
663 switch( aOrientation )
664 {
665 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
666 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
667 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
668 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
669 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
670 }
671
672 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
673 {
674 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
675 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
676 FILL_T::NO_FILL, penWidth );
677
678 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
679 aPlotter->FinishTo( aPosition );
680 }
681 else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
682 {
683 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
684 if( MapY1 == 0 ) /* MapX1 = +- 1 */
685 {
686 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
687 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
688 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
689 }
690 else /* MapX1 = 0 */
691 {
692 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
693 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
694 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
695 }
696
697 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
698 aPlotter->FinishTo( aPosition );
699 }
700 else
701 {
702 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
703 aPlotter->FinishTo( aPosition );
704 }
705
706 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
707 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
708 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
709 {
710 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
711 if( MapY1 == 0 ) /* MapX1 = +- 1 */
712 {
713 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
714 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
715 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
716 }
717 else /* MapX1 = 0 */
718 {
719 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
720 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
721 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
722 }
723 }
724
725 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
726 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
727 {
728 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
729
730 if( MapY1 == 0 ) /* MapX1 = +- 1 */
731 {
732 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
733 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
734 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
735 }
736 else /* MapX1 = 0 */
737 {
738 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
739 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
740 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
741 }
742 }
743
744 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
745 {
746 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
747
748 if( MapY1 == 0 ) /* MapX1 = +- 1 */
749 {
750 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
751 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
752 }
753 else /* MapX1 = 0 */
754 {
755 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
756 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
757 }
758 }
759 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
760 {
761 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
762 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
763 y1 - ( MapY1 - MapX1 ) * deco_size ) );
764 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
765 y1 + ( MapY1 - MapX1 ) * deco_size ) );
766 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
767 y1 - ( MapY1 + MapX1 ) * deco_size ) );
768 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
769 y1 + ( MapY1 + MapX1 ) * deco_size ) );
770 }
771
772 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
773 {
774 const int deco_size = TARGET_PIN_RADIUS;
775 const int ex1 = aPosition.x;
776 const int ey1 = aPosition.y;
777 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
778 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
779 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
780 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
781 }
782}
783
784
785void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
786 int aTextInside, bool aDrawPinNum, bool aDrawPinName,
787 bool aDimmed ) const
788{
789 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
790 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
791 wxString name = GetShownName();
792 wxString number = GetShownNumber();
793
794 if( name.IsEmpty() || m_nameTextSize == 0 )
795 aDrawPinName = false;
796
797 if( number.IsEmpty() || m_numTextSize == 0 )
798 aDrawPinNum = false;
799
800 if( !aDrawPinNum && !aDrawPinName )
801 return;
802
803 int namePenWidth = settings->GetDefaultPenWidth();
804 int numPenWidth = settings->GetDefaultPenWidth();
805 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
806 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
807
808 /* Get the num and name colors */
809 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
810 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
811 COLOR4D bg = settings->GetBackgroundColor();
812
813 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
814 bg = COLOR4D::WHITE;
815
816 if( aDimmed )
817 {
818 nameColor.Desaturate( );
819 numColor.Desaturate( );
820 nameColor = nameColor.Mix( bg, 0.5f );
821 numColor = numColor.Mix( bg, 0.5f );
822 }
823
824 int x1 = aPinPos.x;
825 int y1 = aPinPos.y;
826
827 switch( aPinOrient )
828 {
829 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
830 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
831 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
832 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
833 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aPinOrient must be resolved!" ) ); break;
834 }
835
836 auto plotName =
837 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
838 GR_TEXT_V_ALIGN_T vJustify )
839 {
840 TEXT_ATTRIBUTES attrs;
841 attrs.m_StrokeWidth = namePenWidth;
842 attrs.m_Angle = angle;
844 attrs.m_Halign = hJustify;
845 attrs.m_Valign = vJustify;
846 attrs.m_Multiline = false;
847
848 aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font,
849 GetFontMetrics() );
850 };
851
852 auto plotNum =
853 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
854 GR_TEXT_V_ALIGN_T vJustify )
855 {
856 TEXT_ATTRIBUTES attrs;
857 attrs.m_StrokeWidth = numPenWidth;
858 attrs.m_Angle = angle;
860 attrs.m_Halign = hJustify;
861 attrs.m_Valign = vJustify;
862 attrs.m_Multiline = false;
863
864 aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font,
865 GetFontMetrics() );
866 };
867
868 // Draw the text inside, but the pin numbers outside.
869 if( aTextInside )
870 {
871 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
872 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) // It's a horizontal line.
873 {
874 if( aDrawPinName )
875 {
876 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
877 {
878 plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
880 }
881 else // orient == PIN_LEFT
882 {
883 plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
885 }
886 }
887
888 if( aDrawPinNum )
889 {
890 plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
892 }
893 }
894 else // It's a vertical line.
895 {
896 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
897 {
898 if( aDrawPinName )
899 {
900 plotName( x1, y1 + aTextInside, ANGLE_VERTICAL,
902 }
903
904 if( aDrawPinNum )
905 {
906 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
908 }
909 }
910 else /* PIN_UP */
911 {
912 if( aDrawPinName )
913 {
914 plotName( x1, y1 - aTextInside, ANGLE_VERTICAL,
916 }
917
918 if( aDrawPinNum )
919 {
920 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
922 }
923 }
924 }
925 }
926 else // Draw num & text pin outside.
927 {
928 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
929 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
930 {
931 // It's an horizontal line.
932 if( aDrawPinName && aDrawPinNum )
933 {
934 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
936
937 plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
939 }
940 else if( aDrawPinName )
941 {
942 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
944 }
945 else if( aDrawPinNum )
946 {
947 plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
949 }
950 }
951 else
952 {
953 // Its a vertical line.
954 if( aDrawPinName && aDrawPinNum )
955 {
956 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
958
959 plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
961 }
962 else if( aDrawPinName )
963 {
964 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
966 }
967 else if( aDrawPinNum )
968 {
969 plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
971 }
972 }
973 }
974}
975
976
978{
979 PIN_ORIENTATION orient;
980 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
981
982 switch( GetOrientation() )
983 {
984 default:
985 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
986 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
987 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
988 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
989 }
990
991 // = pos of end point, according to the symbol orientation.
992 end = aTransform.TransformCoordinate( end );
993 orient = PIN_ORIENTATION::PIN_UP;
994
995 if( end.x == 0 )
996 {
997 if( end.y > 0 )
998 orient = PIN_ORIENTATION::PIN_DOWN;
999 }
1000 else
1001 {
1002 orient = PIN_ORIENTATION::PIN_RIGHT;
1003
1004 if( end.x < 0 )
1005 orient = PIN_ORIENTATION::PIN_LEFT;
1006 }
1007
1008 return orient;
1009}
1010
1011
1013{
1014 //return new SCH_PIN( *this );
1015 SCH_ITEM* newPin = new SCH_PIN( *this );
1016 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1017 return newPin;
1018}
1019
1020
1021void SCH_PIN::ChangeLength( int aLength )
1022{
1023 int lengthChange = GetLength() - aLength;
1024 int offsetX = 0;
1025 int offsetY = 0;
1026
1027 switch( m_orientation )
1028 {
1029 default:
1030 case PIN_ORIENTATION::PIN_RIGHT:
1031 offsetX = lengthChange;
1032 break;
1033 case PIN_ORIENTATION::PIN_LEFT:
1034 offsetX = -1 * lengthChange;
1035 break;
1036 case PIN_ORIENTATION::PIN_UP:
1037 offsetY = -1 * lengthChange;
1038 break;
1039 case PIN_ORIENTATION::PIN_DOWN:
1040 offsetY = lengthChange;
1041 break;
1042 }
1043
1044 m_position += VECTOR2I( offsetX, offsetY );
1045 m_length = aLength;
1046}
1047
1048
1049void SCH_PIN::Move( const VECTOR2I& aOffset )
1050{
1051 m_position += aOffset;
1052}
1053
1054
1056{
1057 m_position.x -= aCenter;
1058 m_position.x *= -1;
1059 m_position.x += aCenter;
1060
1061 if( m_orientation == PIN_ORIENTATION::PIN_RIGHT )
1062 m_orientation = PIN_ORIENTATION::PIN_LEFT;
1063 else if( m_orientation == PIN_ORIENTATION::PIN_LEFT )
1064 m_orientation = PIN_ORIENTATION::PIN_RIGHT;
1065}
1066
1067
1069{
1070 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1071 MirrorHorizontallyPin( aCenter );
1072}
1073
1074
1076{
1077 m_position.y -= aCenter;
1078 m_position.y *= -1;
1079 m_position.y += aCenter;
1080
1081 if( m_orientation == PIN_ORIENTATION::PIN_UP )
1082 m_orientation = PIN_ORIENTATION::PIN_DOWN;
1083 else if( m_orientation == PIN_ORIENTATION::PIN_DOWN )
1084 m_orientation = PIN_ORIENTATION::PIN_UP;
1085}
1086
1087
1088void SCH_PIN::MirrorVertically( int aCenter )
1089{
1090 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1091 MirrorVerticallyPin( aCenter );
1092}
1093
1094
1095void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1096{
1097 if( aRotateCCW )
1098 {
1099 RotatePoint( m_position, aCenter, ANGLE_90 );
1100
1101 switch( GetOrientation() )
1102 {
1103 default:
1104 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1105 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1106 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1107 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1108 }
1109 }
1110 else
1111 {
1112 RotatePoint( m_position, aCenter, -ANGLE_90 );
1113
1114 switch( GetOrientation() )
1115 {
1116 default:
1117 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1118 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1119 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1120 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1121 }
1122 }
1123}
1124
1125
1126void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1127{
1128 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1129 RotatePin( aCenter, aRotateCCW );
1130}
1131
1132
1133void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1134 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1135{
1136 if( aBackground )
1137 return;
1138
1139 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1140
1141 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1142 return;
1143
1144 const SYMBOL* part = GetParentSymbol();
1145 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1146 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1147
1148 PlotPinType( aPlotter, pos, orient, aDimmed );
1149 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1150 part->GetShowPinNames(), aDimmed );
1151}
1152
1153
1154void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1155{
1156 wxString msg;
1157 SYMBOL* symbol = GetParentSymbol();
1158
1159 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1160 {
1161 getSymbolEditorMsgPanelInfo( aFrame, aList );
1162 }
1163 else
1164 {
1165 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1166
1167 if( symbol->GetUnitCount() )
1168 {
1170 wxString( "Undefined library pin." );
1171 aList.emplace_back( _( "Unit" ), msg );
1172 }
1173
1174 if( symbol->HasAlternateBodyStyle() )
1175 {
1177 wxString( "Undefined library pin." );
1178 aList.emplace_back( _( "Body Style" ), msg );
1179 }
1180 }
1181
1182 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1183 aList.emplace_back( _( "Number" ), GetShownNumber() );
1184 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1185 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1186
1187 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1188
1189 // Display pin length
1190 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1191
1192 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1193
1194 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1195 {
1196 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1197 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1198 }
1199 else if( SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol ) )
1200 {
1201 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1202 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1203
1204 // Don't use GetShownText(); we want to see the variable references here
1205 aList.emplace_back( symbol->GetRef( currentSheet ),
1206 UnescapeString( schsymbol->GetField( FIELD_T::VALUE )->GetText() ) );
1207 }
1208
1209#if defined(DEBUG)
1210 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1211 {
1212 SCH_CONNECTION* conn = Connection();
1213
1214 if( conn )
1215 conn->AppendInfoToMsgPanel( aList );
1216 }
1217#endif
1218}
1219
1220
1222{
1223 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1224
1225 if( aPath )
1226 m_net_name_map.erase( *aPath );
1227 else
1228 m_net_name_map.clear();
1229}
1230
1231
1232wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1233{
1234 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1235
1236 // Need to check for parent as power symbol to make sure we aren't dealing
1237 // with legacy global power pins on non-power symbols
1238 if( IsGlobalPower() || IsLocalPower() )
1239 {
1240 SYMBOL* parent = GetLibPin()->GetParentSymbol();
1241
1242 if( parent->IsGlobalPower() || parent->IsLocalPower() )
1243 {
1244 return EscapeString( symbol->GetValue( true, &aPath, false ), CTX_NETNAME );
1245 }
1246 else
1247 {
1248 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1249
1250 return EscapeString( tmp, CTX_NETNAME );
1251 }
1252 }
1253
1254 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1255
1256 auto it = m_net_name_map.find( aPath );
1257
1258 if( it != m_net_name_map.end() )
1259 {
1260 if( it->second.second == aForceNoConnect )
1261 return it->second.first;
1262 }
1263
1264 wxString name = "Net-(";
1265 bool unconnected = false;
1266
1267 if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
1268 {
1269 unconnected = true;
1270 name = ( "unconnected-(" );
1271 }
1272
1273 bool annotated = true;
1274
1275 std::vector<SCH_PIN*> pins = symbol->GetPins( &aPath );
1276 bool has_multiple = false;
1277
1278 for( SCH_PIN* pin : pins )
1279 {
1280 if( pin->GetShownName() == GetShownName()
1281 && pin->GetShownNumber() != GetShownNumber()
1282 && unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
1283 {
1284 has_multiple = true;
1285 break;
1286 }
1287 }
1288
1289 wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1290 wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1291
1292 // Use timestamp for unannotated symbols
1293 if( symbol->GetRef( &aPath, false ).Last() == '?' )
1294 {
1296
1297 wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1298 name << "-Pad" << libPinNumber << ")";
1299 annotated = false;
1300 }
1301 else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
1302 {
1303 // Pin names might not be unique between different units so we must have the
1304 // unit token in the reference designator
1305 name << symbol->GetRef( &aPath, true );
1306 name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
1307
1308 if( unconnected || has_multiple )
1309 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME );
1310
1311 name << ")";
1312 }
1313 else
1314 {
1315 // Pin numbers are unique, so we skip the unit token
1316 name << symbol->GetRef( &aPath, false );
1317 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME ) << ")";
1318 }
1319
1320 if( annotated )
1321 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1322
1323 return name;
1324}
1325
1326
1328{
1329 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1330}
1331
1332
1333std::vector<int> SCH_PIN::ViewGetLayers() const
1334{
1337}
1338
1339
1340void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1341 EXTENTS_CACHE* aCache ) const
1342{
1343 if( aCache->m_Font == aFont
1344 && aCache->m_FontSize == aSize
1345 && aCache->m_Extents != VECTOR2I() )
1346 {
1347 return;
1348 }
1349
1350 aCache->m_Font = aFont;
1351 aCache->m_FontSize = aSize;
1352
1353 VECTOR2D fontSize( aSize, aSize );
1354 int penWidth = GetPenSizeForNormal( aSize );
1355
1356 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1357 GetFontMetrics() );
1358}
1359
1360
1361BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1362 bool aIncludeElectricalType ) const
1363{
1364 // Just defer to the cache
1365 return m_layoutCache->GetPinBoundingBox( aIncludeLabelsOnInvisiblePins, aIncludeNameAndNumber,
1366 aIncludeElectricalType );
1367}
1368
1369
1371 const SCH_SHEET_PATH* aInstance ) const
1372{
1373 // Do not compare to ourself.
1374 if( aItem == this )
1375 return false;
1376
1377 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1378
1379 // Don't compare against a different SCH_ITEM.
1380 wxCHECK( pin, false );
1381
1382 if( GetPosition() != pin->GetPosition() )
1383 return true;
1384
1385 if( GetNumber() != pin->GetNumber() )
1386 return true;
1387
1388 return GetName() != pin->GetName();
1389}
1390
1391
1393{
1394 if( !m_libPin )
1395 return false;
1396
1397 // Reciprocal checking is done in CONNECTION_GRAPH anyway
1398 return m_libPin->GetType() != ELECTRICAL_PINTYPE::PT_NC;
1399}
1400
1401
1403{
1404 if( m_libPin )
1405 return m_libPin->GetMenuImage();
1406
1408}
1409
1410
1411wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1412{
1413 return getItemDescription( aAlt );
1414}
1415
1416
1417wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1418{
1419 if( m_libPin )
1420 {
1421 SCH_PIN::ALT localStorage;
1422 SCH_PIN::ALT* alt = nullptr;
1423
1424 if( !m_alt.IsEmpty() )
1425 {
1426 localStorage = m_libPin->GetAlt( m_alt );
1427 alt = &localStorage;
1428 }
1429
1430 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1431 : wxString( wxS( "Undefined library pin." ) );
1432
1433 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1434
1435 return wxString::Format( "Symbol %s %s",
1436 UnescapeString( symbol->GetField( FIELD_T::REFERENCE )->GetText() ),
1437 itemDesc );
1438 }
1439
1440 return getItemDescription( nullptr );
1441}
1442
1443
1444wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1445{
1446 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1447 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1448 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1449
1450 if( IsVisible() )
1451 {
1452 if ( !name.IsEmpty() )
1453 {
1454 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1456 name,
1457 electricalTypeName,
1458 pinShapeName );
1459 }
1460 else
1461 {
1462 return wxString::Format( _( "Pin %s [%s, %s]" ),
1464 electricalTypeName,
1465 pinShapeName );
1466 }
1467 }
1468 else
1469 {
1470 if( !name.IsEmpty() )
1471 {
1472 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1474 name,
1475 electricalTypeName,
1476 pinShapeName );
1477 }
1478 else
1479 {
1480 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1482 electricalTypeName,
1483 pinShapeName );
1484 }
1485 }
1486}
1487
1488
1489int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1490{
1491 // Ignore the UUID here.
1492 int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY );
1493
1494 if( retv )
1495 return retv;
1496
1497 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
1498
1499 wxCHECK( tmp, -1 );
1500
1501 if( m_number != tmp->m_number )
1502 return m_number.Cmp( tmp->m_number );
1503
1504 if( m_position.x != tmp->m_position.x )
1505 return m_position.x - tmp->m_position.x;
1506
1507 if( m_position.y != tmp->m_position.y )
1508 return m_position.y - tmp->m_position.y;
1509
1510 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
1511 {
1512 if( ( m_libPin == nullptr ) || ( tmp->m_libPin == nullptr ) )
1513 return -1;
1514
1515 retv = m_libPin->compare( *tmp->m_libPin );
1516
1517 if( retv )
1518 return retv;
1519
1520 retv = m_alt.Cmp( tmp->m_alt );
1521
1522 if( retv )
1523 return retv;
1524 }
1525
1526 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
1527 {
1528 if( m_length != tmp->m_length )
1529 return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1530
1531 if( m_orientation != tmp->m_orientation )
1532 return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1533
1534 if( m_shape != tmp->m_shape )
1535 return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1536
1537 if( m_type != tmp->m_type )
1538 return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
1539
1540 if( m_hidden != tmp->m_hidden )
1541 return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
1542
1543 if( m_numTextSize != tmp->m_numTextSize )
1544 return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
1545
1546 if( m_nameTextSize != tmp->m_nameTextSize )
1547 return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
1548
1549 if( m_alternates.size() != tmp->m_alternates.size() )
1550 return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
1551
1552 auto lhsItem = m_alternates.begin();
1553 auto rhsItem = tmp->m_alternates.begin();
1554
1555 while( lhsItem != m_alternates.end() )
1556 {
1557 const ALT& lhsAlt = lhsItem->second;
1558 const ALT& rhsAlt = rhsItem->second;
1559
1560 retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
1561
1562 if( retv )
1563 return retv;
1564
1565 if( lhsAlt.m_Type != rhsAlt.m_Type )
1566 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
1567
1568 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
1569 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
1570
1571 ++lhsItem;
1572 ++rhsItem;
1573 }
1574 }
1575
1576 return 0;
1577}
1578
1579
1580double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
1581{
1582 if( aOther.m_Uuid == m_Uuid )
1583 return 1.0;
1584
1585 if( aOther.Type() != SCH_PIN_T )
1586 return 0.0;
1587
1588 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
1589
1590 if( m_libPin )
1591 {
1592 if( m_number != other->m_number )
1593 return 0.0;
1594
1595 if( m_position != other->m_position )
1596 return 0.0;
1597
1598 return m_libPin->Similarity( *other->m_libPin );
1599 }
1600
1601 double similarity = SimilarityBase( aOther );
1602
1603 if( m_name != other->m_name )
1604 similarity *= 0.9;
1605
1606 if( m_number != other->m_number )
1607 similarity *= 0.9;
1608
1609 if( m_position != other->m_position )
1610 similarity *= 0.9;
1611
1612 if( m_length != other->m_length )
1613 similarity *= 0.9;
1614
1615 if( m_orientation != other->m_orientation )
1616 similarity *= 0.9;
1617
1618 if( m_shape != other->m_shape )
1619 similarity *= 0.9;
1620
1621 if( m_type != other->m_type )
1622 similarity *= 0.9;
1623
1624 if( m_hidden != other->m_hidden )
1625 similarity *= 0.9;
1626
1627 if( m_numTextSize != other->m_numTextSize )
1628 similarity *= 0.9;
1629
1630 if( m_nameTextSize != other->m_nameTextSize )
1631 similarity *= 0.9;
1632
1633 if( m_alternates.size() != other->m_alternates.size() )
1634 similarity *= 0.9;
1635
1636 return similarity;
1637}
1638
1639
1640std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
1641{
1642 aStream << "SCH_PIN:" << std::endl
1643 << " Name: \"" << m_name << "\"" << std::endl
1644 << " Number: \"" << m_number << "\"" << std::endl
1645 << " Position: " << m_position << std::endl
1646 << " Length: " << GetLength() << std::endl
1647 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
1648 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
1649 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
1650 << " Name Text Size: " << GetNameTextSize() << std::endl
1651 << " Number Text Size: " << GetNumberTextSize() << std::endl;
1652
1653 return aStream;
1654}
1655
1656
1657#if defined(DEBUG)
1658
1659void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
1660{
1661 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1662 << " num=\"" << m_number.mb_str()
1663 << '"' << "/>\n";
1664}
1665
1666#endif
1667
1668
1669void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
1670{
1671 if( IsMoving() )
1672 SetPosition( aPosition );
1673}
1674
1675
1676static struct SCH_PIN_DESC
1677{
1679 {
1680 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
1681
1682 if( pinTypeEnum.Choices().GetCount() == 0 )
1683 {
1684 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
1685 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
1686 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
1687 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
1688 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
1689 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
1690 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
1691 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
1692 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
1693 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
1694 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
1695 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
1696 }
1697
1698 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
1699
1700 if( pinShapeEnum.Choices().GetCount() == 0 )
1701 {
1702 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
1703 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
1704 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
1705 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
1706 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
1707 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
1708 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
1709 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
1710 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
1711 }
1712
1713 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
1714
1715 if( orientationEnum.Choices().GetCount() == 0 )
1716 {
1717 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) )
1718 .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) )
1719 .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) )
1720 .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) );
1721 }
1722
1723 auto isSymbolEditor =
1724 []( INSPECTABLE* aItem ) -> bool
1725 {
1726 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
1727 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
1728
1729 return false;
1730 };
1731
1736
1737 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
1739 .SetWriteableFunc( isSymbolEditor );
1740
1741 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
1743 .SetWriteableFunc( isSymbolEditor );
1744
1746 _HKI( "Electrical Type" ),
1748 .SetWriteableFunc( isSymbolEditor );
1749
1751 _HKI( "Graphic Style" ),
1753 .SetWriteableFunc( isSymbolEditor );
1754
1755 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
1756 &SCH_PIN::SetX, &SCH_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) )
1757 .SetAvailableFunc( isSymbolEditor );
1758
1759 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
1760 &SCH_PIN::SetY, &SCH_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) )
1761 .SetAvailableFunc( isSymbolEditor );
1762
1763 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
1765 .SetWriteableFunc( isSymbolEditor );
1766
1767 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
1769 PROPERTY_DISPLAY::PT_SIZE ) )
1770 .SetWriteableFunc( isSymbolEditor );
1771
1772 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
1774 PROPERTY_DISPLAY::PT_SIZE ) )
1775 .SetAvailableFunc( isSymbolEditor );
1776
1777 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
1779 PROPERTY_DISPLAY::PT_SIZE ) )
1780 .SetAvailableFunc( isSymbolEditor );
1781
1782 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
1784 .SetAvailableFunc( isSymbolEditor );
1785
1786 }
1788
1789
int color
Definition: DXF_plotter.cpp:63
const char * name
Definition: DXF_plotter.cpp:62
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
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:97
const KIID m_Uuid
Definition: eda_item.h:502
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:513
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:388
EDA_ITEM * GetParent() const
Definition: eda_item.h:111
EDA_ITEM * m_parent
Owner.
Definition: eda_item.h:514
bool IsMoving() const
Definition: eda_item.h:124
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
static ENUM_MAP< T > & Instance()
Definition: property.h:681
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
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, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:147
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition: font.cpp:427
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition: color4d.cpp:511
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:295
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.
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
Define a library symbol object.
Definition: lib_symbol.h:85
Definition: line.h:36
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
Base plotter engine class.
Definition: plotter.h:121
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width)=0
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:261
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:271
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:152
bool GetColorMode() const
Definition: plotter.h:149
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void LineTo(const VECTOR2I &pos)
Definition: plotter.h:266
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
Definition: plotter.cpp:687
virtual void SetColor(const COLOR4D &color)=0
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:258
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:269
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.
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.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString GetNetName() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
int m_unit
Definition: sch_item.h:739
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:97
int m_bodyStyle
Definition: sch_item.h:740
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:685
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:218
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:212
int GetBodyStyle() const
Definition: sch_item.h:246
static wxString GetUnitDescription(int aUnit)
Definition: sch_item.cpp:48
@ EQUALITY
Definition: sch_item.h:666
int GetUnit() const
Definition: sch_item.h:242
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition: sch_item.cpp:532
bool IsConnectivityDirty() const
Definition: sch_item.h:555
static wxString GetBodyStyleDescription(int aBodyStyle)
Definition: sch_item.cpp:57
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:318
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:584
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:593
SCH_LAYER_ID m_layer
Definition: sch_item.h:738
double SimilarityBase(const SCH_ITEM &aItem) const
Calculate the boilerplate similarity for all LIB_ITEMs without preventing the use above of a pure vir...
Definition: sch_item.h:346
void getSymbolEditorMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: sch_item.cpp:628
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.cpp:1126
std::ostream & operator<<(std::ostream &aStream)
Definition: sch_pin.cpp:1640
void SetAlt(const wxString &aAlt)
Set the name of the alternate pin.
Definition: sch_pin.cpp:419
void PlotPinTexts(PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed) const
Plot the pin name and number.
Definition: sch_pin.cpp:785
int GetNumberTextSize() const
Definition: sch_pin.cpp:591
int GetLength() const
Definition: sch_pin.cpp:281
std::optional< bool > m_hidden
Definition: sch_pin.h:372
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:467
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_pin.cpp:1154
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition: sch_pin.h:388
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1075
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition: sch_pin.cpp:1340
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: sch_pin.cpp:1327
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_pin.cpp:1333
const std::map< wxString, ALT > & GetAlternates() const
Definition: sch_pin.h:133
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_pin.cpp:1669
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:554
std::optional< int > m_nameTextSize
Definition: sch_pin.h:376
PIN_ORIENTATION PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: sch_pin.cpp:977
void SetVisible(bool aVisible)
Definition: sch_pin.h:113
int GetX() const
Definition: sch_pin.h:227
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: sch_pin.cpp:1021
ALT GetAlt(const wxString &aAlt)
Definition: sch_pin.h:147
void SetX(int aX)
Definition: sch_pin.h:228
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition: sch_pin.cpp:1370
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:215
wxString GetShownNumber() const
Definition: sch_pin.cpp:548
SCH_PIN * m_libPin
Definition: sch_pin.h:361
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.cpp:1049
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:392
PIN_ORIENTATION m_orientation
Definition: sch_pin.h:369
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: sch_pin.h:92
void SetName(const wxString &aName)
Definition: sch_pin.cpp:405
bool IsGlobalPower() const
Return whether this pin forms a global power connection: i.e., is part of a power symbol and of type ...
Definition: sch_pin.cpp:353
wxString getItemDescription(ALT *aAlt) const
Definition: sch_pin.cpp:1444
bool IsVisible() const
Definition: sch_pin.cpp:373
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:1392
std::optional< int > m_numTextSize
Definition: sch_pin.h:375
VECTOR2I GetPinRoot() const
Definition: sch_pin.cpp:615
bool IsLocalPower() const
Local power pin is the same except that it is sheet-local and it does not support the legacy hidden p...
Definition: sch_pin.cpp:360
ELECTRICAL_PINTYPE m_type
Definition: sch_pin.h:371
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.cpp:1088
SCH_PIN * GetLibPin() const
Definition: sch_pin.h:88
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:224
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_pin.cpp:1580
bool m_isDangling
Definition: sch_pin.h:381
void SetIsDangling(bool aIsDangling)
Definition: sch_pin.cpp:447
wxString GetElectricalTypeName() const
Definition: sch_pin.cpp:339
std::map< wxString, ALT > m_alternates
Definition: sch_pin.h:364
const wxString & GetName() const
Definition: sch_pin.cpp:387
bool IsDangling() const override
Definition: sch_pin.cpp:438
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.
Definition: sch_pin.cpp:1133
void MirrorHorizontally(int aCenter) override
These transforms have effect only if the pin has a LIB_SYMBOL as parent.
Definition: sch_pin.cpp:1068
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:391
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:246
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:73
void SetNumberTextSize(int aSize)
Definition: sch_pin.cpp:605
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: sch_pin.h:95
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1095
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:238
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.cpp:325
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_pin.cpp:494
int GetNameTextSize() const
Definition: sch_pin.cpp:567
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_pin.cpp:1417
VECTOR2I m_position
Definition: sch_pin.h:367
GRAPHIC_PINSHAPE m_shape
Definition: sch_pin.h:370
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition: sch_pin.cpp:1489
wxString GetShownName() const
Definition: sch_pin.cpp:537
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition: sch_pin.cpp:1055
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_pin.cpp:507
wxString m_name
Definition: sch_pin.h:373
wxString m_alt
Definition: sch_pin.h:377
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:315
const wxString & GetBaseName() const
Get the name without any alternates.
Definition: sch_pin.cpp:396
~SCH_PIN()
Definition: sch_pin.cpp:210
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:1221
void SetY(int aY)
Definition: sch_pin.h:230
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:100
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:453
const wxString & GetNumber() const
Definition: sch_pin.h:123
wxString m_number
Definition: sch_pin.h:374
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:1012
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:188
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:1232
std::optional< int > m_length
Definition: sch_pin.h:368
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:260
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition: sch_pin.cpp:638
int GetY() const
Definition: sch_pin.h:229
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition: sch_pin.cpp:367
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:295
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_pin.cpp:1402
void SetNameTextSize(int aSize)
Definition: sch_pin.cpp:581
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:75
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:720
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:550
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:752
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
virtual bool IsGlobalPower() const =0
virtual int GetUnitCount() const =0
virtual bool IsLocalPower() const =0
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
int GetPinNameOffset() const
Definition: symbol.h:153
virtual bool GetShowPinNames() const
Definition: symbol.h:159
virtual bool GetShowPinNumbers() const
Definition: symbol.h:165
virtual bool HasAlternateBodyStyle() const =0
Test if symbol has more than one body conversion type (DeMorgan).
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
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:44
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:407
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define SHOW_ELEC_TYPE
Show pin electrical type.
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
@ LAYER_DANGLING
Definition: layer_ids.h:467
@ LAYER_PINNUM
Definition: layer_ids.h:448
@ LAYER_DEVICE
Definition: layer_ids.h:456
@ LAYER_PINNAM
Definition: layer_ids.h:449
@ LAYER_PIN
Definition: layer_ids.h:460
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:491
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:484
STL namespace.
see class PGM_BASE
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:212
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:226
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:240
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:268
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:80
@ PIN_RIGHT
The pin extends rightwards from the connection point.
GRAPHIC_PINSHAPE
Definition: pin_type.h:59
#define TYPE_HASH(x)
Definition: property.h:72
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:783
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static int externalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius) i.e.
Definition: sch_pin.cpp:89
#define PIN_TEXT_MARGIN
Definition: sch_pin.cpp:44
static int internalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius) i.e.
Definition: sch_pin.cpp:75
static struct SCH_PIN_DESC _SCH_PIN_DESC
#define TARGET_PIN_RADIUS
Definition: sch_pin.h:36
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
Definition: string_utils.h:53
constexpr int MilsToIU(int mils) const
Definition: base_units.h:97
wxString m_Name
Definition: sch_pin.h:44
GRAPHIC_PINSHAPE m_Shape
Definition: sch_pin.h:45
ELECTRICAL_PINTYPE m_Type
Definition: sch_pin.h:46
KIFONT::FONT * m_Font
Definition: sch_pin.h:331
int radius
VECTOR2I end
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ 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:229
@ SCH_PIN_T
Definition: typeinfo.h:154
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695