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 } ),
104 m_orientation( PIN_ORIENTATION::PIN_RIGHT ),
105 m_shape( GRAPHIC_PINSHAPE::LINE ),
107 m_hidden( false ),
108 m_isDangling( true ),
109 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
110{
111 // Use the application settings for pin sizes if exists.
112 // pgm can be nullptr when running a shared lib from a script, not from a kicad appl
113 PGM_BASE* pgm = PgmOrNull();
114
115 if( pgm )
116 {
118 SYMBOL_EDITOR_SETTINGS* cfg = mgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" );
119
120 m_length = schIUScale.MilsToIU( cfg->m_Defaults.pin_length );
121 m_numTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_num_size );
122 m_nameTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_name_size );
123 }
124 else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
125 {
127 m_numTextSize = schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE );
128 m_nameTextSize = schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE );
129 }
130
131 m_layer = LAYER_DEVICE;
132}
133
134
135SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber,
136 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
137 int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos,
138 int aUnit ) :
139 SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ),
140 m_libPin( nullptr ),
141 m_position( aPos ),
142 m_length( aLength ),
143 m_orientation( aOrientation ),
144 m_shape( GRAPHIC_PINSHAPE::LINE ),
145 m_type( aPinType ),
146 m_hidden( false ),
147 m_numTextSize( aNumTextSize ),
148 m_nameTextSize( aNameTextSize ),
149 m_isDangling( true ),
150 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
151{
152 SetName( aName );
153 SetNumber( aNumber );
154
156}
157
158
159SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, SCH_PIN* aLibPin ) :
160 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
161 m_libPin( aLibPin ),
162 m_orientation( PIN_ORIENTATION::INHERIT ),
163 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
165 m_isDangling( true ),
166 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
167{
168 wxASSERT( aParentSymbol );
169
173
175}
176
177
178SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
179 const KIID& aUuid ) :
180 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
181 m_libPin( nullptr ),
182 m_orientation( PIN_ORIENTATION::INHERIT ),
183 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
185 m_number( aNumber ),
186 m_alt( aAlt ),
187 m_isDangling( true ),
188 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
189{
190 wxASSERT( aParentSymbol );
191
192 const_cast<KIID&>( m_Uuid ) = aUuid;
194}
195
196
197SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
198 SCH_ITEM( aPin ),
199 m_libPin( aPin.m_libPin ),
200 m_alternates( aPin.m_alternates ),
201 m_position( aPin.m_position ),
202 m_length( aPin.m_length ),
203 m_orientation( aPin.m_orientation ),
204 m_shape( aPin.m_shape ),
205 m_type( aPin.m_type ),
206 m_hidden( aPin.m_hidden ),
207 m_numTextSize( aPin.m_numTextSize ),
208 m_nameTextSize( aPin.m_nameTextSize ),
209 m_alt( aPin.m_alt ),
210 m_isDangling( aPin.m_isDangling ),
211 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
212{
213 SetName( aPin.m_name );
214 SetNumber( aPin.m_number );
215
216 m_layer = aPin.m_layer;
217}
218
219
221{
222}
223
224
226{
227 SCH_ITEM::operator=( aPin );
228
229 m_libPin = aPin.m_libPin;
231 m_alt = aPin.m_alt;
232 m_name = aPin.m_name;
233 m_number = aPin.m_number;
234 m_position = aPin.m_position;
235 m_length = aPin.m_length;
237 m_shape = aPin.m_shape;
238 m_type = aPin.m_type;
239 m_hidden = aPin.m_hidden;
243
244 return *this;
245}
246
247
249{
250 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
251 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
252 else
253 return m_position;
254}
255
257{
258 if( m_orientation == PIN_ORIENTATION::INHERIT )
259 {
260 if( !m_libPin )
261 return PIN_ORIENTATION::PIN_RIGHT;
262
263 return m_libPin->GetOrientation();
264 }
265
266 return m_orientation;
267}
268
269
271{
272 if( !m_alt.IsEmpty() )
273 {
274 if( !m_libPin )
275 return GRAPHIC_PINSHAPE::LINE;
276
277 return m_libPin->GetAlt( m_alt ).m_Shape;
278 }
279 else if( m_shape == GRAPHIC_PINSHAPE::INHERIT )
280 {
281 if( !m_libPin )
282 return GRAPHIC_PINSHAPE::LINE;
283
284 return m_libPin->GetShape();
285 }
286
287 return m_shape;
288}
289
290
292{
293 if( !m_length.has_value() )
294 {
295 if( !m_libPin )
296 return 0;
297
298 return m_libPin->GetLength();
299 }
300
301 return m_length.value();
302}
303
304
306{
307 if( !m_alt.IsEmpty() )
308 {
309 if( !m_libPin )
310 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
311
312 return m_libPin->GetAlt( m_alt ).m_Type;
313 }
314 else if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
315 {
316 if( !m_libPin )
317 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
318
319 return m_libPin->GetType();
320 }
321
322 return m_type;
323}
324
326{
327 if( aType == m_type )
328 return;
329
330 m_type = aType;
332}
333
334
336{
337 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
338 {
339 if( !m_libPin )
340 return GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
341
343 }
344
346}
347
348
350{
351 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
352 {
353 if( !m_libPin )
354 return ElectricalPinTypeGetText( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
355
357 }
358
360}
361
362
364{
365 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
366 && ( !IsVisible() || GetParentSymbol()->IsPower() );
367}
368
369
371{
372 if( !m_hidden.has_value() )
373 {
374 if( !m_libPin )
375 return true;
376
377 return m_libPin->IsVisible();
378 }
379
380 return !m_hidden.value();
381}
382
383
384const wxString& SCH_PIN::GetName() const
385{
386 if( !m_alt.IsEmpty() )
387 return m_alt;
388
389 return GetBaseName();
390}
391
392
393const wxString& SCH_PIN::GetBaseName() const
394{
395 if( m_libPin )
396 return m_libPin->GetBaseName();
397
398 return m_name;
399}
400
401
402void SCH_PIN::SetName( const wxString& aName )
403{
404 if( m_name == aName )
405 return;
406
407 m_name = aName;
408
409 // pin name string does not support spaces
410 m_name.Replace( wxT( " " ), wxT( "_" ) );
411
413}
414
415
417{
418 if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
419 return false;
420
421 return m_isDangling;
422}
423
424
425void SCH_PIN::SetIsDangling( bool aIsDangling )
426{
427 m_isDangling = aIsDangling;
428}
429
430
431bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
432{
433 bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
434 || GetType() == ELECTRICAL_PINTYPE::PT_NIC;
435 bool isConnectableType_b = aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
436 || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC;
437
438 return m_parent == aPin->GetParent()
439 && GetPosition() == aPin->GetPosition()
440 && GetName() == aPin->GetName()
441 && ( GetType() == aPin->GetType() || isConnectableType_a || isConnectableType_b );
442}
443
444
445bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
446{
447 const SCH_SEARCH_DATA& schSearchData =
448 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
449
450 if( !schSearchData.searchAllPins )
451 return false;
452
453 return EDA_ITEM::Matches( GetName(), aSearchData )
454 || EDA_ITEM::Matches( GetNumber(), aSearchData );
455}
456
457
458bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
459{
460 bool isReplaced = false;
461
462 /* TODO: waiting on a way to override pins in the schematic...
463 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
464 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
465 */
466
467 return isReplaced;
468}
469
470
471bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
472{
473 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
474 // no pin number or name. Give it a floor.
475 if( Schematic() )
476 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
477
478 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
479
480 return rect.Inflate( aAccuracy ).Contains( aPosition );
481}
482
483
484bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
485{
487 return false;
488
489 BOX2I sel = aRect;
490
491 if ( aAccuracy )
492 sel.Inflate( aAccuracy );
493
494 if( aContained )
495 return sel.Contains( GetBoundingBox( false, false, false ) );
496
497 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
498}
499
500
501wxString SCH_PIN::GetShownName() const
502{
503 if( !m_alt.IsEmpty() )
504 return m_alt;
505 else if( m_libPin )
506 return m_libPin->GetShownName();
507
508 if( m_name == wxS( "~" ) )
509 return wxEmptyString;
510 else
511 return m_name;
512}
513
514
516{
517 if( m_number == wxS( "~" ) )
518 return wxEmptyString;
519 else
520 return m_number;
521}
522
523
524void SCH_PIN::SetNumber( const wxString& aNumber )
525{
526 if( m_number == aNumber )
527 return;
528
529 m_number = aNumber;
530 // pin number string does not support spaces
531 m_number.Replace( wxT( " " ), wxT( "_" ) );
532
534}
535
536
538{
539 if( !m_nameTextSize.has_value() )
540 {
541 if( !m_libPin )
543
544 return m_libPin->GetNameTextSize();
545 }
546
547 return m_nameTextSize.value();
548}
549
550
552{
553 if( aSize == m_nameTextSize )
554 return;
555
556 m_nameTextSize = aSize;
558}
559
560
562{
563 if( !m_numTextSize.has_value() )
564 {
565 if( !m_libPin )
567
568 return m_libPin->GetNumberTextSize();
569 }
570
571 return m_numTextSize.value();
572}
573
574
576{
577 if( aSize == m_numTextSize )
578 return;
579
580 m_numTextSize = aSize;
582}
583
584
586{
587 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
588 {
589 const TRANSFORM& t = symbol->GetTransform();
590
591 if( !m_libPin )
592 return GetPosition();
593
594 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
595 }
596
597 switch( GetOrientation() )
598 {
599 default:
600 case PIN_ORIENTATION::PIN_RIGHT: return m_position + VECTOR2I( GetLength(), 0 );
601 case PIN_ORIENTATION::PIN_LEFT: return m_position + VECTOR2I( -GetLength(), 0 );
602 case PIN_ORIENTATION::PIN_UP: return m_position + VECTOR2I( 0, -GetLength() );
603 case PIN_ORIENTATION::PIN_DOWN: return m_position + VECTOR2I( 0, GetLength() );
604 }
605}
606
607
608void SCH_PIN::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
609 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
610{
611 LIB_SYMBOL* part = dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() );
612
613 wxCHECK( part && aSettings, /* void */ );
614
615 /* Calculate pin orient taking in account the symbol orientation. */
616 PIN_ORIENTATION orient = PinDrawOrient( aSettings->m_Transform );
617
618 /* Calculate the pin position */
619 VECTOR2I pos1 = aSettings->TransformCoordinate( m_position ) + aOffset;
620
621 if( IsVisible() || aSettings->m_ShowHiddenFields )
622 {
623 printPinSymbol( aSettings, pos1, orient, aDimmed );
624
625 printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(),
626 aSettings->m_ShowPinNumbers || part->GetShowPinNumbers(),
627 aSettings->m_ShowPinNames || part->GetShowPinNames(),
628 aDimmed );
629
630 if( aSettings->m_ShowPinsElectricalType )
631 printPinElectricalTypeName( aSettings, pos1, orient, aDimmed );
632
633 if( aSettings->m_ShowConnectionPoints
634 && m_type != ELECTRICAL_PINTYPE::PT_NC
635 && m_type != ELECTRICAL_PINTYPE::PT_NIC )
636 {
637 wxDC* DC = aSettings->GetPrintDC();
639
640 COLOR4D bg = aSettings->GetBackgroundColor();
641
642 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
643 bg = COLOR4D::WHITE;
644
645 if( aDimmed )
646 {
647 color.Desaturate( );
648 color = color.Mix( bg, 0.5f );
649 }
650
651 GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color );
652 }
653 }
654}
655
656
657void SCH_PIN::printPinSymbol( const SCH_RENDER_SETTINGS* aSettings, const VECTOR2I& aPos,
658 PIN_ORIENTATION aOrientation, bool aDimmed )
659{
660 wxDC* DC = aSettings->GetPrintDC();
661 int MapX1, MapY1, x1, y1;
662 int width = GetEffectivePenWidth( aSettings );
663 int posX = aPos.x;
664 int posY = aPos.y;
665 int len = GetLength();
667 COLOR4D bg = aSettings->GetBackgroundColor();
668
669 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
670 bg = COLOR4D::WHITE;
671
672 if( !IsVisible() )
673 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
674
675 if( aDimmed )
676 {
677 color.Desaturate( );
678 color = color.Mix( bg, 0.5f );
679 }
680
681 MapX1 = MapY1 = 0;
682 x1 = posX;
683 y1 = posY;
684
685 switch( aOrientation )
686 {
687 case PIN_ORIENTATION::PIN_UP: y1 = posY - len; MapY1 = 1; break;
688 case PIN_ORIENTATION::PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
689 case PIN_ORIENTATION::PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
690 case PIN_ORIENTATION::PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
691 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
692 }
693
694 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
695 {
696 const int radius = externalPinDecoSize( aSettings, *this );
697 GRCircle( DC, VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius, width, color );
698
699 GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
700 GRLineTo( DC, posX, posY, width, color );
701 }
702 else
703 {
704 GRMoveTo( x1, y1 );
705 GRLineTo( DC, posX, posY, width, color );
706 }
707
708 // Draw the clock shape (>)inside the symbol
709 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
710 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
711 || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
712 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
713 {
714 const int clock_size = internalPinDecoSize( aSettings, *this );
715 if( MapY1 == 0 ) /* MapX1 = +- 1 */
716 {
717 GRMoveTo( x1, y1 + clock_size );
718 GRLineTo( DC, x1 - MapX1 * clock_size * 2, y1, width, color );
719 GRLineTo( DC, x1, y1 - clock_size, width, color );
720 }
721 else /* MapX1 = 0 */
722 {
723 GRMoveTo( x1 + clock_size, y1 );
724 GRLineTo( DC, x1, y1 - MapY1 * clock_size * 2, width, color );
725 GRLineTo( DC, x1 - clock_size, y1, width, color );
726 }
727 }
728
729 // Draw the active low (or H to L active transition)
730 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
731 || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
732 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
733 {
734 const int deco_size = externalPinDecoSize( aSettings, *this );
735 if( MapY1 == 0 ) /* MapX1 = +- 1 */
736 {
737 GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
738 GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
739 GRLineTo( DC, x1, y1, width, color );
740 }
741 else /* MapX1 = 0 */
742 {
743 GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
744 GRLineTo( DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
745 GRLineTo( DC, x1, y1, width, color );
746 }
747 }
748
749 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
750 {
751 const int deco_size = externalPinDecoSize( aSettings, *this );
752 if( MapY1 == 0 ) /* MapX1 = +- 1 */
753 {
754 GRMoveTo( x1, y1 - deco_size * 2 );
755 GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1, width, color );
756 }
757 else /* MapX1 = 0 */
758 {
759 GRMoveTo( x1 - deco_size * 2, y1 );
760 GRLineTo( DC, x1, y1 + MapY1 * deco_size * 2, width, color );
761 }
762 }
763 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
764 {
765 const int deco_size = externalPinDecoSize( aSettings, *this );
766 GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
767 GRLineTo( DC, x1 + (MapX1 + MapY1) * deco_size, y1 + ( MapY1 - MapX1 ) * deco_size, width,
768 color );
769 GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
770 GRLineTo( DC, x1 + (MapX1 - MapY1) * deco_size, y1 + ( MapY1 + MapX1 ) * deco_size, width,
771 color );
772 }
773
774 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
775 {
776 const int deco_size = TARGET_PIN_RADIUS;
777 GRLine( DC, posX - deco_size, posY - deco_size, posX + deco_size, posY + deco_size, width,
778 color );
779 GRLine( DC, posX + deco_size, posY - deco_size, posX - deco_size, posY + deco_size, width,
780 color );
781 }
782}
783
784
785void SCH_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPinPos,
786 PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum,
787 bool aDrawPinName, bool aDimmed )
788{
789 if( !aDrawPinName && !aDrawPinNum )
790 return;
791
792 KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false );
793 wxString name = GetShownName();
794 wxString number = GetShownNumber();
797 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN );
798 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN );
799
800 /* Get the num and name colors */
801 COLOR4D nameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
802 COLOR4D numColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
803 COLOR4D bg = aSettings->GetBackgroundColor();
804
805 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
806 bg = COLOR4D::WHITE;
807
808 if( !IsVisible() )
809 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
810
811 if( aDimmed )
812 {
813 nameColor.Desaturate();
814 numColor.Desaturate();
815 nameColor = nameColor.Mix( bg, 0.5f );
816 numColor = numColor.Mix( bg, 0.5f );
817 }
818
819 int x1 = aPinPos.x;
820 int y1 = aPinPos.y;
821
822 switch( aPinOrient )
823 {
824 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
825 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
826 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
827 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
828 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxT( "aPinOrient must be resolved!" ) ); break;
829 }
830
831 if( name.IsEmpty() || m_nameTextSize == 0 )
832 aDrawPinName = false;
833
834 if( number.IsEmpty() || m_numTextSize == 0 )
835 aDrawPinNum = false;
836
837 auto printName =
838 [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign,
839 enum GR_TEXT_V_ALIGN_T vAlign )
840 {
841 GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), nameColor, name, angle,
842 nameSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() );
843 };
844
845 auto printNum =
846 [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign,
847 enum GR_TEXT_V_ALIGN_T vAlign )
848 {
849 GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), numColor, number, angle,
850 numSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() );
851 };
852
853 if( aTextInside ) // Draw the text inside, but the pin numbers outside.
854 {
855 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
856 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
857 {
858 // It is an horizontal line
859 if( aDrawPinName )
860 {
861 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
862 {
863 printName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
865 }
866 else // Orient == PIN_LEFT
867 {
868 printName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
870 }
871 }
872
873 if( aDrawPinNum )
874 {
875 printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
877 }
878 }
879 else /* Its a vertical line. */
880 {
881 // Text is drawn from bottom to top (i.e. to negative value for Y axis)
882 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
883 {
884 if( aDrawPinName )
885 {
886 printName( x1, y1 + aTextInside, ANGLE_VERTICAL,
888 }
889
890 if( aDrawPinNum )
891 {
892 printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
894 }
895 }
896 else /* PIN_UP */
897 {
898 if( aDrawPinName )
899 {
900 printName( x1, y1 - aTextInside, ANGLE_VERTICAL,
902 }
903
904 if( aDrawPinNum )
905 {
906 printNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
908 }
909 }
910 }
911 }
912 else /**** Draw num & text pin outside ****/
913 {
914 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
915 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
916 {
917 /* Its an horizontal line. */
918 if( aDrawPinName && aDrawPinNum )
919 {
920 printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
922
923 printNum( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
925 }
926 else if( aDrawPinName )
927 {
928 printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
930 }
931 else if( aDrawPinNum )
932 {
933 printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
935 }
936 }
937 else /* Its a vertical line. */
938 {
939 if( aDrawPinName && aDrawPinNum )
940 {
941 printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
943
944 printNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
946 }
947 else if( aDrawPinName )
948 {
949 printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
951 }
952 else if( aDrawPinNum )
953 {
954 printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
956 }
957 }
958 }
959}
960
961
963 const VECTOR2I& aPosition, PIN_ORIENTATION aOrientation,
964 bool aDimmed )
965{
966 wxDC* DC = aSettings->GetPrintDC();
967 wxString typeName = GetElectricalTypeName();
968
969 // Use a reasonable (small) size to draw the text
970 int textSize = ( GetNameTextSize() * 3 ) / 4;
971
972 #define ETXT_MAX_SIZE schIUScale.mmToIU( 0.7 )
973
974 if( textSize > ETXT_MAX_SIZE )
975 textSize = ETXT_MAX_SIZE;
976
977 // Use a reasonable pen size to draw the text
978 int pensize = textSize/6;
979
980 // Get a suitable color
982 COLOR4D bg = aSettings->GetBackgroundColor();
983
984 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
985 bg = COLOR4D::WHITE;
986
987 if( !IsVisible() )
988 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
989
990 if( aDimmed )
991 {
992 color.Desaturate( );
993 color = color.Mix( bg, 0.5f );
994 }
995
996 VECTOR2I txtpos = aPosition;
997 int offset = schIUScale.mmToIU( 0.4 );
1000 KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false );
1001
1002 switch( aOrientation )
1003 {
1004 case PIN_ORIENTATION::PIN_UP:
1005 txtpos.y += offset;
1006 orient = ANGLE_VERTICAL;
1007 hjustify = GR_TEXT_H_ALIGN_RIGHT;
1008 break;
1009
1010 case PIN_ORIENTATION::PIN_DOWN:
1011 txtpos.y -= offset;
1012 orient = ANGLE_VERTICAL;
1013 break;
1014
1015 case PIN_ORIENTATION::PIN_LEFT:
1016 txtpos.x += offset;
1017 break;
1018
1019 case PIN_ORIENTATION::PIN_RIGHT:
1020 txtpos.x -= offset;
1021 hjustify = GR_TEXT_H_ALIGN_RIGHT;
1022 break;
1023
1024 case PIN_ORIENTATION::INHERIT:
1025 wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) );
1026 break;
1027 }
1028
1029 GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify,
1030 GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() );
1031}
1032
1033
1034void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
1035 PIN_ORIENTATION aOrientation, bool aDimmed ) const
1036{
1037 int MapX1, MapY1, x1, y1;
1038 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1039 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
1040 COLOR4D bg = renderSettings->GetBackgroundColor();
1041 int penWidth = GetEffectivePenWidth( renderSettings );
1042 int pinLength = GetLength();
1043
1044 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1045 bg = COLOR4D::WHITE;
1046
1047 if( aDimmed )
1048 {
1049 color.Desaturate( );
1050 color = color.Mix( bg, 0.5f );
1051 }
1052
1053 aPlotter->SetColor( color );
1054 aPlotter->SetCurrentLineWidth( penWidth );
1055
1056 MapX1 = MapY1 = 0;
1057 x1 = aPosition.x; y1 = aPosition.y;
1058
1059 switch( aOrientation )
1060 {
1061 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
1062 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
1063 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
1064 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
1065 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
1066 }
1067
1068 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
1069 {
1070 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1071 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
1072 FILL_T::NO_FILL, penWidth );
1073
1074 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
1075 aPlotter->FinishTo( aPosition );
1076 }
1077 else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
1078 {
1079 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
1080 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1081 {
1082 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
1083 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
1084 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
1085 }
1086 else /* MapX1 = 0 */
1087 {
1088 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
1089 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1090 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
1091 }
1092
1093 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
1094 aPlotter->FinishTo( aPosition );
1095 }
1096 else
1097 {
1098 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
1099 aPlotter->FinishTo( aPosition );
1100 }
1101
1102 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
1103 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
1104 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
1105 {
1106 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
1107 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1108 {
1109 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
1110 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
1111 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
1112 }
1113 else /* MapX1 = 0 */
1114 {
1115 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
1116 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
1117 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
1118 }
1119 }
1120
1121 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
1122 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1123 {
1124 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1125
1126 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1127 {
1128 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
1129 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
1130 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1131 }
1132 else /* MapX1 = 0 */
1133 {
1134 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1135 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
1136 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1137 }
1138 }
1139
1140 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1141 {
1142 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1143
1144 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1145 {
1146 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
1147 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
1148 }
1149 else /* MapX1 = 0 */
1150 {
1151 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
1152 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
1153 }
1154 }
1155 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
1156 {
1157 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1158 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
1159 y1 - ( MapY1 - MapX1 ) * deco_size ) );
1160 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
1161 y1 + ( MapY1 - MapX1 ) * deco_size ) );
1162 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
1163 y1 - ( MapY1 + MapX1 ) * deco_size ) );
1164 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
1165 y1 + ( MapY1 + MapX1 ) * deco_size ) );
1166 }
1167
1168 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
1169 {
1170 const int deco_size = TARGET_PIN_RADIUS;
1171 const int ex1 = aPosition.x;
1172 const int ey1 = aPosition.y;
1173 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
1174 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
1175 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
1176 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
1177 }
1178}
1179
1180
1181void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
1182 int aTextInside, bool aDrawPinNum, bool aDrawPinName,
1183 bool aDimmed ) const
1184{
1185 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
1186 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
1187 wxString name = GetShownName();
1188 wxString number = GetShownNumber();
1189
1190 if( name.IsEmpty() || m_nameTextSize == 0 )
1191 aDrawPinName = false;
1192
1193 if( number.IsEmpty() || m_numTextSize == 0 )
1194 aDrawPinNum = false;
1195
1196 if( !aDrawPinNum && !aDrawPinName )
1197 return;
1198
1199 int namePenWidth = settings->GetDefaultPenWidth();
1200 int numPenWidth = settings->GetDefaultPenWidth();
1201 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
1202 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
1203
1204 /* Get the num and name colors */
1205 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
1206 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
1207 COLOR4D bg = settings->GetBackgroundColor();
1208
1209 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1210 bg = COLOR4D::WHITE;
1211
1212 if( aDimmed )
1213 {
1214 nameColor.Desaturate( );
1215 numColor.Desaturate( );
1216 nameColor = nameColor.Mix( bg, 0.5f );
1217 numColor = numColor.Mix( bg, 0.5f );
1218 }
1219
1220 int x1 = aPinPos.x;
1221 int y1 = aPinPos.y;
1222
1223 switch( aPinOrient )
1224 {
1225 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
1226 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
1227 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
1228 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
1229 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aPinOrient must be resolved!" ) ); break;
1230 }
1231
1232 auto plotName =
1233 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
1234 GR_TEXT_V_ALIGN_T vJustify )
1235 {
1236 TEXT_ATTRIBUTES attrs;
1237 attrs.m_StrokeWidth = namePenWidth;
1238 attrs.m_Angle = angle;
1240 attrs.m_Halign = hJustify;
1241 attrs.m_Valign = vJustify;
1242 attrs.m_Multiline = false;
1243
1244 aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font,
1245 GetFontMetrics() );
1246 };
1247
1248 auto plotNum =
1249 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
1250 GR_TEXT_V_ALIGN_T vJustify )
1251 {
1252 TEXT_ATTRIBUTES attrs;
1253 attrs.m_StrokeWidth = numPenWidth;
1254 attrs.m_Angle = angle;
1256 attrs.m_Halign = hJustify;
1257 attrs.m_Valign = vJustify;
1258 attrs.m_Multiline = false;
1259
1260 aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font,
1261 GetFontMetrics() );
1262 };
1263
1264 // Draw the text inside, but the pin numbers outside.
1265 if( aTextInside )
1266 {
1267 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
1268 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) // It's a horizontal line.
1269 {
1270 if( aDrawPinName )
1271 {
1272 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
1273 {
1274 plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
1276 }
1277 else // orient == PIN_LEFT
1278 {
1279 plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
1281 }
1282 }
1283
1284 if( aDrawPinNum )
1285 {
1286 plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
1288 }
1289 }
1290 else // It's a vertical line.
1291 {
1292 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
1293 {
1294 if( aDrawPinName )
1295 {
1296 plotName( x1, y1 + aTextInside, ANGLE_VERTICAL,
1298 }
1299
1300 if( aDrawPinNum )
1301 {
1302 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
1304 }
1305 }
1306 else /* PIN_UP */
1307 {
1308 if( aDrawPinName )
1309 {
1310 plotName( x1, y1 - aTextInside, ANGLE_VERTICAL,
1312 }
1313
1314 if( aDrawPinNum )
1315 {
1316 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
1318 }
1319 }
1320 }
1321 }
1322 else // Draw num & text pin outside.
1323 {
1324 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
1325 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1326 {
1327 // It's an horizontal line.
1328 if( aDrawPinName && aDrawPinNum )
1329 {
1330 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1332
1333 plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
1335 }
1336 else if( aDrawPinName )
1337 {
1338 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1340 }
1341 else if( aDrawPinNum )
1342 {
1343 plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1345 }
1346 }
1347 else
1348 {
1349 // Its a vertical line.
1350 if( aDrawPinName && aDrawPinNum )
1351 {
1352 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1354
1355 plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1357 }
1358 else if( aDrawPinName )
1359 {
1360 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1362 }
1363 else if( aDrawPinNum )
1364 {
1365 plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1367 }
1368 }
1369 }
1370}
1371
1372
1374{
1375 PIN_ORIENTATION orient;
1376 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
1377
1378 switch( GetOrientation() )
1379 {
1380 default:
1381 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
1382 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
1383 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
1384 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
1385 }
1386
1387 // = pos of end point, according to the symbol orientation.
1388 end = aTransform.TransformCoordinate( end );
1389 orient = PIN_ORIENTATION::PIN_UP;
1390
1391 if( end.x == 0 )
1392 {
1393 if( end.y > 0 )
1394 orient = PIN_ORIENTATION::PIN_DOWN;
1395 }
1396 else
1397 {
1398 orient = PIN_ORIENTATION::PIN_RIGHT;
1399
1400 if( end.x < 0 )
1401 orient = PIN_ORIENTATION::PIN_LEFT;
1402 }
1403
1404 return orient;
1405}
1406
1407
1409{
1410 //return new SCH_PIN( *this );
1411 SCH_ITEM* newPin = new SCH_PIN( *this );
1412 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1413 return newPin;
1414}
1415
1416
1417void SCH_PIN::ChangeLength( int aLength )
1418{
1419 int lengthChange = GetLength() - aLength;
1420 int offsetX = 0;
1421 int offsetY = 0;
1422
1423 switch( m_orientation )
1424 {
1425 default:
1426 case PIN_ORIENTATION::PIN_RIGHT:
1427 offsetX = lengthChange;
1428 break;
1429 case PIN_ORIENTATION::PIN_LEFT:
1430 offsetX = -1 * lengthChange;
1431 break;
1432 case PIN_ORIENTATION::PIN_UP:
1433 offsetY = lengthChange;
1434 break;
1435 case PIN_ORIENTATION::PIN_DOWN:
1436 offsetY = -1 * lengthChange;
1437 break;
1438 }
1439
1440 m_position += VECTOR2I( offsetX, offsetY );
1441 m_length = aLength;
1442}
1443
1444
1445void SCH_PIN::Move( const VECTOR2I& aOffset )
1446{
1447 m_position += aOffset;
1448}
1449
1450
1452{
1453 m_position.x -= aCenter;
1454 m_position.x *= -1;
1455 m_position.x += aCenter;
1456
1457 if( m_orientation == PIN_ORIENTATION::PIN_RIGHT )
1458 m_orientation = PIN_ORIENTATION::PIN_LEFT;
1459 else if( m_orientation == PIN_ORIENTATION::PIN_LEFT )
1460 m_orientation = PIN_ORIENTATION::PIN_RIGHT;
1461}
1462
1463
1465{
1466 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1467 MirrorHorizontallyPin( aCenter );
1468}
1469
1470
1472{
1473 m_position.y -= aCenter;
1474 m_position.y *= -1;
1475 m_position.y += aCenter;
1476
1477 if( m_orientation == PIN_ORIENTATION::PIN_UP )
1478 m_orientation = PIN_ORIENTATION::PIN_DOWN;
1479 else if( m_orientation == PIN_ORIENTATION::PIN_DOWN )
1480 m_orientation = PIN_ORIENTATION::PIN_UP;
1481}
1482
1483
1484void SCH_PIN::MirrorVertically( int aCenter )
1485{
1486 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1487 MirrorVerticallyPin( aCenter );
1488}
1489
1490
1491void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1492{
1493 if( aRotateCCW )
1494 {
1495 RotatePoint( m_position, aCenter, ANGLE_90 );
1496
1497 switch( GetOrientation() )
1498 {
1499 default:
1500 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1501 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1502 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1503 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1504 }
1505 }
1506 else
1507 {
1508 RotatePoint( m_position, aCenter, -ANGLE_90 );
1509
1510 switch( GetOrientation() )
1511 {
1512 default:
1513 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1514 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1515 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1516 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1517 }
1518 }
1519}
1520
1521
1522void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1523{
1524 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1525 RotatePin( aCenter, aRotateCCW );
1526}
1527
1528
1529void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1530 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1531{
1532 if( aBackground )
1533 return;
1534
1535 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1536
1537 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1538 return;
1539
1540 const SYMBOL* part = GetParentSymbol();
1541 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1542 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1543
1544 PlotPinType( aPlotter, pos, orient, aDimmed );
1545 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1546 part->GetShowPinNames(), aDimmed );
1547}
1548
1549
1550void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1551{
1552 wxString msg;
1553 SYMBOL* symbol = GetParentSymbol();
1554
1555 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1556 {
1557 getSymbolEditorMsgPanelInfo( aFrame, aList );
1558 }
1559 else
1560 {
1561 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1562
1563 if( symbol->GetUnitCount() )
1564 {
1566 wxString( "Undefined library pin." );
1567 aList.emplace_back( _( "Unit" ), msg );
1568 }
1569
1570 if( symbol->HasAlternateBodyStyle() )
1571 {
1573 wxString( "Undefined library pin." );
1574 aList.emplace_back( _( "Body Style" ), msg );
1575 }
1576 }
1577
1578 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1579 aList.emplace_back( _( "Number" ), GetShownNumber() );
1580 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1581 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1582
1583 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1584
1585 // Display pin length
1586 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1587
1588 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1589
1590 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1591 {
1592 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1593 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1594 }
1595 else
1596 {
1597 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1598 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1599 SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol );
1600
1601 // Don't use GetShownText(); we want to see the variable references here
1602 aList.emplace_back( symbol->GetRef( currentSheet ),
1603 UnescapeString( schsymbol->GetField( VALUE_FIELD )->GetText() ) );
1604 }
1605
1606#if defined(DEBUG)
1607 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1608 {
1609 SCH_CONNECTION* conn = Connection();
1610
1611 if( conn )
1612 conn->AppendInfoToMsgPanel( aList );
1613 }
1614#endif
1615}
1616
1617
1619{
1620 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1621
1622 if( aPath )
1623 m_net_name_map.erase( *aPath );
1624 else
1625 m_net_name_map.clear();
1626}
1627
1628
1629wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1630{
1631 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1632
1633 // Need to check for parent as power symbol to make sure we aren't dealing
1634 // with legacy global power pins on non-power symbols
1635 if( IsGlobalPower() )
1636 {
1637 if( GetLibPin()->GetParentSymbol()->IsPower() )
1638 {
1639 return EscapeString( symbol->GetValue( true, &aPath, false ), CTX_NETNAME );
1640 }
1641 else
1642 {
1643 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1644
1645 return EscapeString( tmp, CTX_NETNAME );
1646 }
1647 }
1648
1649 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1650
1651 auto it = m_net_name_map.find( aPath );
1652
1653 if( it != m_net_name_map.end() )
1654 {
1655 if( it->second.second == aForceNoConnect )
1656 return it->second.first;
1657 }
1658
1659 wxString name = "Net-(";
1660 bool unconnected = false;
1661
1662 if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
1663 {
1664 unconnected = true;
1665 name = ( "unconnected-(" );
1666 }
1667
1668 bool annotated = true;
1669
1670 std::vector<SCH_PIN*> pins = symbol->GetPins( &aPath );
1671 bool has_multiple = false;
1672
1673 for( SCH_PIN* pin : pins )
1674 {
1675 if( pin->GetShownName() == GetShownName()
1676 && pin->GetShownNumber() != GetShownNumber()
1677 && unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
1678 {
1679 has_multiple = true;
1680 break;
1681 }
1682 }
1683
1684 wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1685 wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1686
1687 // Use timestamp for unannotated symbols
1688 if( symbol->GetRef( &aPath, false ).Last() == '?' )
1689 {
1691
1692 wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1693 name << "-Pad" << libPinNumber << ")";
1694 annotated = false;
1695 }
1696 else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
1697 {
1698 // Pin names might not be unique between different units so we must have the
1699 // unit token in the reference designator
1700 name << symbol->GetRef( &aPath, true );
1701 name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
1702
1703 if( unconnected || has_multiple )
1704 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME );
1705
1706 name << ")";
1707 }
1708 else
1709 {
1710 // Pin numbers are unique, so we skip the unit token
1711 name << symbol->GetRef( &aPath, false );
1712 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME ) << ")";
1713 }
1714
1715 if( annotated )
1716 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1717
1718 return name;
1719}
1720
1721
1723{
1724 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1725}
1726
1727
1728std::vector<int> SCH_PIN::ViewGetLayers() const
1729{
1732}
1733
1734
1735void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1736 EXTENTS_CACHE* aCache ) const
1737{
1738 if( aCache->m_Font == aFont
1739 && aCache->m_FontSize == aSize
1740 && aCache->m_Extents != VECTOR2I() )
1741 {
1742 return;
1743 }
1744
1745 aCache->m_Font = aFont;
1746 aCache->m_FontSize = aSize;
1747
1748 VECTOR2D fontSize( aSize, aSize );
1749 int penWidth = GetPenSizeForNormal( aSize );
1750
1751 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1752 GetFontMetrics() );
1753}
1754
1755
1756BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1757 bool aIncludeElectricalType ) const
1758{
1759 // Just defer to the cache
1760 return m_layoutCache->GetPinBoundingBox( aIncludeLabelsOnInvisiblePins, aIncludeNameAndNumber,
1761 aIncludeElectricalType );
1762}
1763
1764
1766 const SCH_SHEET_PATH* aInstance ) const
1767{
1768 // Do not compare to ourself.
1769 if( aItem == this )
1770 return false;
1771
1772 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1773
1774 // Don't compare against a different SCH_ITEM.
1775 wxCHECK( pin, false );
1776
1777 if( GetPosition() != pin->GetPosition() )
1778 return true;
1779
1780 if( GetNumber() != pin->GetNumber() )
1781 return true;
1782
1783 return GetName() != pin->GetName();
1784}
1785
1786
1788{
1789 if( !m_libPin )
1790 return false;
1791
1792 // Reciprocal checking is done in CONNECTION_GRAPH anyway
1793 return m_libPin->GetType() != ELECTRICAL_PINTYPE::PT_NC;
1794}
1795
1796
1798{
1799 if( m_libPin )
1800 return m_libPin->GetMenuImage();
1801
1803}
1804
1805
1806wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1807{
1808 return getItemDescription( aAlt );
1809}
1810
1811
1812wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1813{
1814 if( m_libPin )
1815 {
1816 SCH_PIN::ALT localStorage;
1817 SCH_PIN::ALT* alt = nullptr;
1818
1819 if( !m_alt.IsEmpty() )
1820 {
1821 localStorage = m_libPin->GetAlt( m_alt );
1822 alt = &localStorage;
1823 }
1824
1825 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1826 : wxString( wxS( "Undefined library pin." ) );
1827
1828 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1829
1830 return wxString::Format( "Symbol %s %s",
1832 itemDesc );
1833 }
1834
1835 return getItemDescription( nullptr );
1836}
1837
1838
1839wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1840{
1841 // This code previously checked "m_name.IsEmpty()" to choose the correct
1842 // formatting path, but that check fails if the pin is called "~" which is
1843 // the default for an empty pin name. Instead we get the final display string
1844 // that will be shown and check if it's empty.
1845
1846 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1847 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1848 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1849
1850 if( IsVisible() )
1851 {
1852 if ( !name.IsEmpty() )
1853 {
1854 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1856 name,
1857 electricalTypeName,
1858 pinShapeName );
1859 }
1860 else
1861 {
1862 return wxString::Format( _( "Pin %s [%s, %s]" ),
1864 electricalTypeName,
1865 pinShapeName );
1866 }
1867 }
1868 else
1869 {
1870 if( !name.IsEmpty() )
1871 {
1872 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1874 name,
1875 electricalTypeName,
1876 pinShapeName );
1877 }
1878 else
1879 {
1880 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1882 electricalTypeName,
1883 pinShapeName );
1884 }
1885 }
1886}
1887
1888
1889int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1890{
1891 // Ignore the UUID here.
1892 int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY );
1893
1894 if( retv )
1895 return retv;
1896
1897 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
1898
1899 wxCHECK( tmp, -1 );
1900
1901 if( m_number != tmp->m_number )
1902 return m_number.Cmp( tmp->m_number );
1903
1904 if( m_position.x != tmp->m_position.x )
1905 return m_position.x - tmp->m_position.x;
1906
1907 if( m_position.y != tmp->m_position.y )
1908 return m_position.y - tmp->m_position.y;
1909
1910 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
1911 {
1912 if( ( m_libPin == nullptr ) || ( tmp->m_libPin == nullptr ) )
1913 return -1;
1914
1915 retv = m_libPin->compare( *tmp->m_libPin );
1916
1917 if( retv )
1918 return retv;
1919
1920 retv = m_alt.Cmp( tmp->m_alt );
1921
1922 if( retv )
1923 return retv;
1924 }
1925
1926 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
1927 {
1928 if( m_length != tmp->m_length )
1929 return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1930
1931 if( m_orientation != tmp->m_orientation )
1932 return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1933
1934 if( m_shape != tmp->m_shape )
1935 return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1936
1937 if( m_type != tmp->m_type )
1938 return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
1939
1940 if( m_hidden != tmp->m_hidden )
1941 return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
1942
1943 if( m_numTextSize != tmp->m_numTextSize )
1944 return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
1945
1946 if( m_nameTextSize != tmp->m_nameTextSize )
1947 return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
1948
1949 if( m_alternates.size() != tmp->m_alternates.size() )
1950 return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
1951
1952 auto lhsItem = m_alternates.begin();
1953 auto rhsItem = tmp->m_alternates.begin();
1954
1955 while( lhsItem != m_alternates.end() )
1956 {
1957 const ALT& lhsAlt = lhsItem->second;
1958 const ALT& rhsAlt = rhsItem->second;
1959
1960 retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
1961
1962 if( retv )
1963 return retv;
1964
1965 if( lhsAlt.m_Type != rhsAlt.m_Type )
1966 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
1967
1968 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
1969 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
1970
1971 ++lhsItem;
1972 ++rhsItem;
1973 }
1974 }
1975
1976 return 0;
1977}
1978
1979
1980double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
1981{
1982 if( aOther.m_Uuid == m_Uuid )
1983 return 1.0;
1984
1985 if( aOther.Type() != SCH_PIN_T )
1986 return 0.0;
1987
1988 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
1989
1990 if( m_libPin )
1991 {
1992 if( m_number != other->m_number )
1993 return 0.0;
1994
1995 if( m_position != other->m_position )
1996 return 0.0;
1997
1998 return m_libPin->Similarity( *other->m_libPin );
1999 }
2000
2001 double similarity = SimilarityBase( aOther );
2002
2003 if( m_name != other->m_name )
2004 similarity *= 0.9;
2005
2006 if( m_number != other->m_number )
2007 similarity *= 0.9;
2008
2009 if( m_position != other->m_position )
2010 similarity *= 0.9;
2011
2012 if( m_length != other->m_length )
2013 similarity *= 0.9;
2014
2015 if( m_orientation != other->m_orientation )
2016 similarity *= 0.9;
2017
2018 if( m_shape != other->m_shape )
2019 similarity *= 0.9;
2020
2021 if( m_type != other->m_type )
2022 similarity *= 0.9;
2023
2024 if( m_hidden != other->m_hidden )
2025 similarity *= 0.9;
2026
2027 if( m_numTextSize != other->m_numTextSize )
2028 similarity *= 0.9;
2029
2030 if( m_nameTextSize != other->m_nameTextSize )
2031 similarity *= 0.9;
2032
2033 if( m_alternates.size() != other->m_alternates.size() )
2034 similarity *= 0.9;
2035
2036 return similarity;
2037}
2038
2039
2040std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
2041{
2042 aStream << "SCH_PIN:" << std::endl
2043 << " Name: \"" << m_name << "\"" << std::endl
2044 << " Number: \"" << m_number << "\"" << std::endl
2045 << " Position: " << m_position << std::endl
2046 << " Length: " << GetLength() << std::endl
2047 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
2048 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
2049 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
2050 << " Name Text Size: " << GetNameTextSize() << std::endl
2051 << " Number Text Size: " << GetNumberTextSize() << std::endl;
2052
2053 return aStream;
2054}
2055
2056
2057#if defined(DEBUG)
2058
2059void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
2060{
2061 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2062 << " num=\"" << m_number.mb_str()
2063 << '"' << "/>\n";
2064}
2065
2066#endif
2067
2068
2069void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
2070{
2071 if( IsMoving() )
2072 SetPosition( aPosition );
2073}
2074
2075
2076static struct SCH_PIN_DESC
2077{
2079 {
2080 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
2081
2082 if( pinTypeEnum.Choices().GetCount() == 0 )
2083 {
2084 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
2085 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
2086 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
2087 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
2088 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
2089 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
2090 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
2091 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
2092 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
2093 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
2094 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
2095 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
2096 }
2097
2098 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
2099
2100 if( pinShapeEnum.Choices().GetCount() == 0 )
2101 {
2102 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
2103 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
2104 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
2105 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
2106 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
2107 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
2108 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
2109 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
2110 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
2111 }
2112
2113 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
2114
2115 if( orientationEnum.Choices().GetCount() == 0 )
2116 {
2117 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) )
2118 .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) )
2119 .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) )
2120 .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) );
2121 }
2122
2123 auto isSymbolEditor =
2124 []( INSPECTABLE* aItem ) -> bool
2125 {
2126 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
2127 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
2128
2129 return false;
2130 };
2131
2136
2137 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
2139 .SetWriteableFunc( isSymbolEditor );
2140
2141 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
2143 .SetWriteableFunc( isSymbolEditor );
2144
2146 _HKI( "Electrical Type" ),
2148 .SetWriteableFunc( isSymbolEditor );
2149
2151 _HKI( "Graphic Style" ),
2153 .SetWriteableFunc( isSymbolEditor );
2154
2155 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
2156 &SCH_PIN::SetX, &SCH_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) )
2157 .SetAvailableFunc( isSymbolEditor );
2158
2159 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
2160 &SCH_PIN::SetY, &SCH_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) )
2161 .SetAvailableFunc( isSymbolEditor );
2162
2163 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
2165 .SetWriteableFunc( isSymbolEditor );
2166
2167 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
2169 PROPERTY_DISPLAY::PT_SIZE ) )
2170 .SetWriteableFunc( isSymbolEditor );
2171
2172 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
2174 PROPERTY_DISPLAY::PT_SIZE ) )
2175 .SetAvailableFunc( isSymbolEditor );
2176
2177 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
2179 PROPERTY_DISPLAY::PT_SIZE ) )
2180 .SetAvailableFunc( isSymbolEditor );
2181
2182 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
2184 .SetAvailableFunc( isSymbolEditor );
2185
2186 }
2188
2189
int color
Definition: DXF_plotter.cpp:60
const char * name
Definition: DXF_plotter.cpp:59
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
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:89
const KIID m_Uuid
Definition: eda_item.h:488
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:499
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:376
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:500
bool IsMoving() const
Definition: eda_item.h:108
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
static ENUM_MAP< T > & Instance()
Definition: property.h:680
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.
wxDC * GetPrintDC() const
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
Define a library symbol object.
Definition: lib_symbol.h:84
Definition: line.h:36
Container for data for KiCad programs.
Definition: pgm_base.h:103
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
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:105
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:244
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:254
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
bool GetColorMode() const
Definition: plotter.h:133
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:249
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:754
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:257
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:268
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).
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:167
int m_unit
Definition: sch_item.h:719
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:101
int m_bodyStyle
Definition: sch_item.h:720
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:665
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:166
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
int GetBodyStyle() const
Definition: sch_item.h:236
static wxString GetUnitDescription(int aUnit)
Definition: sch_item.cpp:52
@ EQUALITY
Definition: sch_item.h:655
int GetUnit() const
Definition: sch_item.h:233
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:417
bool IsConnectivityDirty() const
Definition: sch_item.h:520
static wxString GetBodyStyleDescription(int aBodyStyle)
Definition: sch_item.cpp:61
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:218
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:465
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:474
SCH_LAYER_ID m_layer
Definition: sch_item.h:718
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:325
void getSymbolEditorMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: sch_item.cpp:500
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.cpp:1522
std::ostream & operator<<(std::ostream &aStream)
Definition: sch_pin.cpp:2040
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:1181
int GetNumberTextSize() const
Definition: sch_pin.cpp:561
int GetLength() const
Definition: sch_pin.cpp:291
std::optional< bool > m_hidden
Definition: sch_pin.h:379
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:445
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:1550
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition: sch_pin.h:395
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1471
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition: sch_pin.cpp:1735
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: sch_pin.cpp:1722
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:1728
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_pin.cpp:2069
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:524
std::optional< int > m_nameTextSize
Definition: sch_pin.h:383
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:1373
void SetVisible(bool aVisible)
Definition: sch_pin.h:113
int GetX() const
Definition: sch_pin.h:208
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: sch_pin.cpp:1417
ALT GetAlt(const wxString &aAlt)
Definition: sch_pin.h:147
void SetX(int aX)
Definition: sch_pin.h:209
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:1765
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:225
wxString GetShownNumber() const
Definition: sch_pin.cpp:515
SCH_PIN * m_libPin
Definition: sch_pin.h:368
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.cpp:1445
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:399
PIN_ORIENTATION m_orientation
Definition: sch_pin.h:376
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: sch_pin.h:92
void SetName(const wxString &aName)
Definition: sch_pin.cpp:402
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:363
wxString getItemDescription(ALT *aAlt) const
Definition: sch_pin.cpp:1839
bool IsVisible() const
Definition: sch_pin.cpp:370
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:1787
std::optional< int > m_numTextSize
Definition: sch_pin.h:382
VECTOR2I GetPinRoot() const
Definition: sch_pin.cpp:585
ELECTRICAL_PINTYPE m_type
Definition: sch_pin.h:378
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.cpp:1484
SCH_PIN * GetLibPin() const
Definition: sch_pin.h:88
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:205
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:1980
bool m_isDangling
Definition: sch_pin.h:388
void SetIsDangling(bool aIsDangling)
Definition: sch_pin.cpp:425
wxString GetElectricalTypeName() const
Definition: sch_pin.cpp:349
std::map< wxString, ALT > m_alternates
Definition: sch_pin.h:371
const wxString & GetName() const
Definition: sch_pin.cpp:384
void SetLength(int aLength)
Definition: sch_pin.h:98
bool IsDangling() const override
Definition: sch_pin.cpp:416
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:1529
void MirrorHorizontally(int aCenter) override
These transforms have effect only if the pin has a LIB_SYMBOL as parent.
Definition: sch_pin.cpp:1464
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:398
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:256
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:73
void SetNumberTextSize(int aSize)
Definition: sch_pin.cpp:575
void printPinTexts(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed)
Put the pin number and pin text info, given the pin line coordinates.
Definition: sch_pin.cpp:785
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: sch_pin.h:95
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1491
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:248
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.cpp:335
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:458
int GetNameTextSize() const
Definition: sch_pin.cpp:537
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_pin.cpp:1812
VECTOR2I m_position
Definition: sch_pin.h:374
void printPinSymbol(const SCH_RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, PIN_ORIENTATION aOrientation, bool aDimmed)
Print the pin symbol without text.
Definition: sch_pin.cpp:657
GRAPHIC_PINSHAPE m_shape
Definition: sch_pin.h:377
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition: sch_pin.cpp:1889
wxString GetShownName() const
Definition: sch_pin.cpp:501
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition: sch_pin.cpp:1451
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:471
wxString m_name
Definition: sch_pin.h:380
wxString m_alt
Definition: sch_pin.h:384
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:325
const wxString & GetBaseName() const
Get the name without any alternates.
Definition: sch_pin.cpp:393
~SCH_PIN()
Definition: sch_pin.cpp:220
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:1618
void SetY(int aY)
Definition: sch_pin.h:211
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed)
Draw the electrical type text of the pin (only for the footprint editor).
Definition: sch_pin.cpp:962
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:100
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:431
const wxString & GetNumber() const
Definition: sch_pin.h:123
wxString m_number
Definition: sch_pin.h:381
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:1408
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:181
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_pin.cpp:608
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:1629
std::optional< int > m_length
Definition: sch_pin.h:375
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:270
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition: sch_pin.cpp:1034
int GetY() const
Definition: sch_pin.h:210
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:305
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_pin.cpp:1797
void SetNameTextSize(int aSize)
Definition: sch_pin.cpp:551
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:77
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:907
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:875
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:705
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
virtual int GetUnitCount() const =0
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
virtual bool IsPower() const =0
int GetPinNameOffset() const
Definition: symbol.h:151
virtual bool GetShowPinNames() const
Definition: symbol.h:157
virtual bool GetShowPinNumbers() const
Definition: symbol.h:163
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:403
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
#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.
void GRLineTo(wxDC *DC, int x, int y, int width, const COLOR4D &Color)
Definition: gr_basic.cpp:195
void GRCircle(wxDC *aDC, const VECTOR2I &aPos, int aRadius, int aWidth, const COLOR4D &aColor)
Definition: gr_basic.cpp:358
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:188
void GRLine(wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:171
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:109
@ LAYER_DANGLING
Definition: layer_ids.h:466
@ LAYER_PINNUM
Definition: layer_ids.h:447
@ LAYER_DEVICE
Definition: layer_ids.h:455
@ LAYER_HIDDEN
Definition: layer_ids.h:481
@ LAYER_PINNAM
Definition: layer_ids.h:448
@ LAYER_PRIVATE_NOTES
Definition: layer_ids.h:457
@ LAYER_PIN
Definition: layer_ids.h:459
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:490
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:483
STL namespace.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
Definition: pgm_base.cpp:1081
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:71
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:782
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
#define ETXT_MAX_SIZE
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:93
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
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:312
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
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:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695