KiCad PCB EDA Suite
lib_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 <stambaughw@verizon.net>
6  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <pgm_base.h>
32 #include <gr_basic.h>
33 #include <macros.h>
34 #include <trigo.h>
35 #include <class_drawpanel.h>
36 #include <drawtxt.h>
37 #include <plot_common.h>
38 #include <schframe.h>
39 #include <richio.h>
40 #include <base_units.h>
41 #include <msgpanel.h>
42 
43 #include <general.h>
44 #include <libeditframe.h>
45 #include <class_libentry.h>
46 #include <lib_pin.h>
47 #include <transform.h>
48 #include <sch_component.h>
49 
50 
51 static const int pin_orientation_codes[] =
52 {
53  PIN_RIGHT,
54  PIN_LEFT,
55  PIN_UP,
56  PIN_DOWN
57 };
58 #define PIN_ORIENTATION_CNT DIM( pin_orientation_codes )
59 
60 // small margin in internal units between the pin text and the pin line
61 #define PIN_TEXT_MARGIN 4
62 
63 // bitmaps to show pins orientations in dialog editor
64 // must have same order than pin_orientation_names
66 {
67  pinorient_right_xpm,
68  pinorient_left_xpm,
69  pinorient_up_xpm,
70  pinorient_down_xpm,
71 };
72 
73 
75 {
76  if( aType < 0 || aType >= (int) PINTYPE_COUNT )
77  return wxT( "???" );
78 
79  // These strings are the canonical name of the electrictal type
80  // Not translated, no space in name, only ASCII chars.
81  // to use when the string name must be known and well defined
82  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
83  static const wxChar* msgPinElectricType[] =
84  {
85  wxT( "input" ),
86  wxT( "output" ),
87  wxT( "BiDi" ),
88  wxT( "3state" ),
89  wxT( "passive" ),
90  wxT( "unspc" ),
91  wxT( "power_in" ),
92  wxT( "power_out" ),
93  wxT( "openCol" ),
94  wxT( "openEm" ),
95  wxT( "NotConnected" )
96  };
97 
98  return msgPinElectricType[ aType ];
99 }
100 
101 
102 // Helper functions to get the pin orientation name from pin_orientation_codes
103 // Note: the strings are *not* static because they are translated and must be built
104 // on the fly, to be properly translated
105 
106 static const wxString getPinOrientationName( unsigned aPinOrientationCode )
107 {
108  /* Note: The following name lists are sentence capitalized per the GNOME UI
109  * standards for list controls. Please do not change the capitalization
110  * of these strings unless the GNOME UI standards are changed.
111  */
112  const wxString pin_orientation_names[] =
113  {
114  _( "Right" ),
115  _( "Left" ),
116  _( "Up" ),
117  _( "Down" ),
118  wxT( "???" )
119  };
120 
121  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
122  aPinOrientationCode = PIN_ORIENTATION_CNT;
123 
124  return pin_orientation_names[ aPinOrientationCode ];
125 }
126 
128 // i.e. the clock symbols (falling clock is actually external but is of
129 // the same kind)
130 
131 static int InternalPinDecoSize( const LIB_PIN &aPin )
132 {
133 
134  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
135 }
136 
138 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
139 // marker
140 static int ExternalPinDecoSize( const LIB_PIN &aPin )
141 {
142  return aPin.GetNumberTextSize() / 2;
143 }
144 
146  LIB_ITEM( LIB_PIN_T, aParent ),
147  m_shape( PINSHAPE_LINE )
148 {
150  m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right
151  m_type = PIN_UNSPECIFIED; // electrical type of pin
152  m_attributes = 0; // bit 0 != 0: pin invisible
155  m_width = 0;
156  m_typeName = _( "Pin" );
157 }
158 
159 
160 void LIB_PIN::SetName( const wxString& aName, bool aTestOtherPins )
161 {
162  wxString tmp = ( aName.IsEmpty() ) ? wxT( "~" ) : aName;
163 
164  tmp.Replace( wxT( " " ), wxT( "_" ) );
165 
166  if( m_name != tmp )
167  {
168  m_name = tmp;
169  SetModified();
170  }
171 
172  if( !aTestOtherPins )
173  return;
174 
175  if( GetParent() == NULL )
176  return;
177 
178  LIB_PINS pinList;
179  GetParent()->GetPins( pinList );
180 
181  for( size_t i = 0; i < pinList.size(); i++ )
182  {
183  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_name == m_name )
184  continue;
185 
186  pinList[i]->m_name = m_name;
187  SetModified();
188  }
189 }
190 
191 
192 void LIB_PIN::SetNameTextSize( int size, bool aTestOtherPins )
193 {
194  if( size != m_nameTextSize )
195  {
196  m_nameTextSize = size;
197  SetModified();
198  }
199 
200  if( !aTestOtherPins )
201  return;
202 
203  if( GetParent() == NULL )
204  return;
205 
206  LIB_PINS pinList;
207  GetParent()->GetPins( pinList );
208 
209  for( size_t i = 0; i < pinList.size(); i++ )
210  {
211  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_nameTextSize == size )
212  continue;
213 
214  pinList[i]->m_nameTextSize = size;
215  SetModified();
216  }
217 }
218 
219 
220 void LIB_PIN::SetNumberTextSize( int size, bool aTestOtherPins )
221 {
222  if( size != m_numTextSize )
223  {
224  m_numTextSize = size;
225  SetModified();
226  }
227 
228  if( !aTestOtherPins )
229  return;
230 
231  if( GetParent() == NULL )
232  return;
233 
234  LIB_PINS pinList;
235  GetParent()->GetPins( pinList );
236 
237  for( size_t i = 0; i < pinList.size(); i++ )
238  {
239  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_numTextSize == size )
240  continue;
241 
242  pinList[i]->m_numTextSize = size;
243  SetModified();
244  }
245 }
246 
247 
248 void LIB_PIN::SetOrientation( int orientation, bool aTestOtherPins )
249 {
250  if( m_orientation != orientation )
251  {
252  m_orientation = orientation;
253  SetModified();
254  }
255 
256  if( !aTestOtherPins )
257  return;
258 
259  if( GetParent() == NULL )
260  return;
261 
262  LIB_PINS pinList;
263  GetParent()->GetPins( pinList );
264 
265  for( size_t i = 0; i < pinList.size(); i++ )
266  {
267  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 ||
268  pinList[i]->m_orientation == orientation )
269  continue;
270 
271  pinList[i]->m_orientation = orientation;
272  SetModified();
273  }
274 }
275 
276 
278 {
279  assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) );
280 
281  if( m_shape != aShape )
282  {
283  m_shape = aShape;
284  SetModified();
285  }
286 
287  if( GetParent() == NULL )
288  return;
289 
290  LIB_PINS pinList;
291  GetParent()->GetPins( pinList );
292 
293  for( size_t i = 0; i < pinList.size(); i++ )
294  {
295  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
296  || pinList[i]->m_Convert != m_Convert
297  || pinList[i]->m_shape == aShape )
298  continue;
299 
300  pinList[i]->m_shape = aShape;
301  SetModified();
302  }
303 }
304 
305 
306 void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins )
307 {
308  assert( aType >= 0 && aType < (int)PINTYPE_COUNT );
309 
310  if( aType < PIN_INPUT )
311  aType = PIN_INPUT;
312 
313  if( aType >= (int)PINTYPE_COUNT )
314  aType = PIN_NC;
315 
316  if( m_type != aType )
317  {
318  m_type = aType;
319  SetModified();
320  }
321 
322  if( !aTestOtherPins )
323  return;
324 
325  if( GetParent() == NULL )
326  return;
327 
328  LIB_PINS pinList;
329  GetParent()->GetPins( pinList );
330 
331  for( size_t i = 0; i < pinList.size(); i++ )
332  {
333  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_type == aType )
334  continue;
335 
336  pinList[i]->m_type = aType;
337  SetModified();
338  }
339 }
340 
341 
342 void LIB_PIN::SetLength( int length, bool aTestOtherPins )
343 {
344  if( m_length != length )
345  {
346  m_length = length;
347  SetModified();
348  }
349 
350  if( !aTestOtherPins )
351  return;
352 
353  if( GetParent() == NULL )
354  return;
355 
356  LIB_PINS pinList;
357  GetParent()->GetPins( pinList );
358 
359  for( size_t i = 0; i < pinList.size(); i++ )
360  {
361  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
362  || pinList[i]->m_Convert != m_Convert
363  || pinList[i]->m_length == length )
364  continue;
365 
366  pinList[i]->m_length = length;
367  SetModified();
368  }
369 }
370 
371 
373 {
374  if( m_position != aPosition )
375  {
376  m_position = aPosition;
377  SetModified();
378  }
379 
380  if( GetParent() == NULL )
381  return;
382 
383  LIB_PINS pinList;
384  GetParent()->GetPins( pinList );
385 
386  for( size_t i = 0; i < pinList.size(); i++ )
387  {
388  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
389  || pinList[i]->m_Convert != m_Convert
390  || pinList[i]->m_position == aPosition )
391  continue;
392 
393  pinList[i]->m_position = aPosition;
394  SetModified();
395  }
396 }
397 
398 
399 void LIB_PIN::SetPartNumber( int part )
400 {
401  if( m_Unit == part )
402  return;
403 
404  m_Unit = part;
405  SetModified();
406 
407  if( m_Unit == 0 )
408  {
409  LIB_PIN* pin;
410  LIB_PIN* tmp = GetParent()->GetNextPin();
411 
412  while( tmp != NULL )
413  {
414  pin = tmp;
415  tmp = GetParent()->GetNextPin( pin );
416 
417  if( pin->m_Flags == 0 || pin == this
418  || ( m_Convert && ( m_Convert != pin->m_Convert ) )
419  || ( m_position != pin->m_position )
420  || ( pin->m_orientation != m_orientation ) )
421  continue;
422 
423  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
424  }
425  }
426 }
427 
428 
429 void LIB_PIN::SetConversion( int style )
430 {
431  if( m_Convert == style )
432  return;
433 
434  m_Convert = style;
435  SetFlags( IS_CHANGED );
436 
437  if( style == 0 )
438  {
439  LIB_PIN* pin;
440  LIB_PIN* tmp = GetParent()->GetNextPin();
441 
442  while( tmp != NULL )
443  {
444  pin = tmp;
445  tmp = GetParent()->GetNextPin( pin );
446 
447  if( ( pin->m_Flags & IS_LINKED ) == 0
448  || ( pin == this )
449  || ( m_Unit && ( m_Unit != pin->m_Unit ) )
450  || ( m_position != pin->m_position )
451  || ( pin->m_orientation != m_orientation ) )
452  continue;
453 
454  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
455  }
456  }
457 }
458 
459 
460 void LIB_PIN::SetVisible( bool visible )
461 {
462  if( visible == IsVisible() )
463  return;
464 
465  if( visible )
467  else
469 
470  SetModified();
471 
472  if( GetParent() == NULL )
473  return;
474 
475  LIB_PINS pinList;
476  GetParent()->GetPins( pinList );
477 
478  for( size_t i = 0; i < pinList.size(); i++ )
479  {
480  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->IsVisible() == visible )
481  continue;
482 
483  if( visible )
484  pinList[i]->m_attributes &= ~PIN_INVISIBLE;
485  else
486  pinList[i]->m_attributes |= PIN_INVISIBLE;
487 
488  SetModified();
489  }
490 }
491 
492 
493 void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin )
494 {
495  LIB_PINS pinList;
496 
497  if( GetParent() == NULL )
498  return;
499 
500  GetParent()->GetPins( pinList );
501 
502  for( size_t i = 0; i < pinList.size(); i++ )
503  {
504  if( pinList[i] == this )
505  continue;
506 
507  if( ( pinList[i]->m_position == m_position )
508  && ( pinList[i]->m_orientation == m_orientation )
509  && !IsNew()
510  && editPinByPin == false
511  && enable )
512  pinList[i]->SetFlags( IS_LINKED | IN_EDIT );
513  else
514  pinList[i]->ClearFlags( IS_LINKED | IN_EDIT );
515  }
516 }
517 
518 
519 bool LIB_PIN::HitTest( const wxPoint& aPosition ) const
520 {
521  return HitTest( aPosition, 0, DefaultTransform );
522 }
523 
524 
525 bool LIB_PIN::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
526 {
527  if( aThreshold < 0 )
528  aThreshold = 0;
529 
530  TRANSFORM transform = DefaultTransform;
531  DefaultTransform = aTransform;
532 
533  EDA_RECT rect = GetBoundingBox();
534  rect.Inflate( aThreshold );
535 
536  //Restore matrix
537  DefaultTransform = transform;
538 
539  return rect.Contains( aPosition );
540 }
541 
542 
543 bool LIB_PIN::Save( OUTPUTFORMATTER& aFormatter )
544 {
545  int Etype;
546 
547  switch( m_type )
548  {
549  default:
550  case PIN_INPUT:
551  Etype = 'I';
552  break;
553 
554  case PIN_OUTPUT:
555  Etype = 'O';
556  break;
557 
558  case PIN_BIDI:
559  Etype = 'B';
560  break;
561 
562  case PIN_TRISTATE:
563  Etype = 'T';
564  break;
565 
566  case PIN_PASSIVE:
567  Etype = 'P';
568  break;
569 
570  case PIN_UNSPECIFIED:
571  Etype = 'U';
572  break;
573 
574  case PIN_POWER_IN:
575  Etype = 'W';
576  break;
577 
578  case PIN_POWER_OUT:
579  Etype = 'w';
580  break;
581 
582  case PIN_OPENCOLLECTOR:
583  Etype = 'C';
584  break;
585 
586  case PIN_OPENEMITTER:
587  Etype = 'E';
588  break;
589 
590  case PIN_NC:
591  Etype = 'N';
592  break;
593  }
594 
595  if( !m_name.IsEmpty() )
596  {
597  if( aFormatter.Print( 0, "X %s", TO_UTF8( m_name ) ) < 0 )
598  return false;
599  }
600  else
601  {
602  if( aFormatter.Print( 0, "X ~" ) < 0 )
603  return false;
604  }
605 
606  if( aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
607  m_number.IsEmpty() ? "~" : TO_UTF8( m_number ),
610  m_Unit, m_Convert, Etype ) < 0 )
611  return false;
612 
613  if( m_shape || !IsVisible() )
614  {
615  if( aFormatter.Print( 0, " " ) < 0 )
616  return false;
617  }
618 
619  if( !IsVisible() && aFormatter.Print( 0, "N" ) < 0 )
620  return false;
621 
622  switch( m_shape )
623  {
624  case PINSHAPE_LINE:
625  break;
626 
627  case PINSHAPE_INVERTED:
628  if( aFormatter.Print( 0, "I" ) < 0 )
629  return false;
630  break;
631 
632  case PINSHAPE_CLOCK:
633  if( aFormatter.Print( 0, "C" ) < 0 )
634  return false;
635  break;
636 
638  if( aFormatter.Print( 0, "IC" ) < 0 )
639  return false;
640  break;
641 
642  case PINSHAPE_INPUT_LOW:
643  if( aFormatter.Print( 0, "L" ) < 0 )
644  return false;
645  break;
646 
647  case PINSHAPE_CLOCK_LOW:
648  if( aFormatter.Print( 0, "CL" ) < 0 )
649  return false;
650  break;
651 
652  case PINSHAPE_OUTPUT_LOW:
653  if( aFormatter.Print( 0, "V" ) < 0 )
654  return false;
655  break;
656 
658  if( aFormatter.Print( 0, "F" ) < 0 )
659  return false;
660  break;
661 
662  case PINSHAPE_NONLOGIC:
663  if( aFormatter.Print( 0, "X" ) < 0 )
664  return false;
665  break;
666 
667  default:
668  assert( !"Invalid pin shape" );
669  return false;
670  }
671 
672  if( aFormatter.Print( 0, "\n" ) < 0 )
673  return false;
674 
676 
677  return true;
678 }
679 
680 #include <wx/tokenzr.h>
681 
682 bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
683 {
684  char pinAttrs[64];
685  char pinOrient[64];
686  char pinType[64];
687 
688  *pinAttrs = 0;
689 
690  // We cannot use sscanf, at least on Windows, to parse the pin description.
691  // The reason is the pin name is free, and use UTF8 encoding.
692  // We encourtered issues (Windows specific) to read this name for some UTF8
693  // cyrillic codes
694  // So, read the pin name (and num) after conversion from UTF8, and read the others
695  // parameters (in ASCII) using sscanf
696 
697  // the full line starts by "X ". The pin data starts at line + 2.
698  wxString utf8line = FROM_UTF8( aLineReader.Line() + 2 );
699  wxStringTokenizer tokenizer( utf8line, wxT(" \n\r" ) );
700  int prms_count = tokenizer.CountTokens();
701 
702  if( prms_count < 11 )
703  {
704  aErrorMsg.Printf( wxT( "pin had %d parameters of the required 11 or 12" ), prms_count );
705  return false;
706  }
707 
708  // Extract the pinName (UTF8 encoded)
709  m_name = tokenizer.GetNextToken();
710 
711  wxString tmp;
712 
713  // Extract the pinName (UTF8 encoded accepted, but should be only ASCII8.)
714  tmp = tokenizer.GetNextToken();
715  SetNumber( tmp );
716 
717  // Read other parameters, in pure ASCII
718  char line[1024];
719  tmp = tokenizer.GetString();
720 
721  unsigned len = tmp.Length();
722 
723  if( len >= sizeof( line ) ) // Should not occur.
724  len = sizeof( line) - 1;
725 
726  strncpy( line, TO_UTF8( tmp ), len );
727  line[len] = 0;
728 
729  int cnt = sscanf( line, "%d %d %d %63s %d %d %d %d %63s %63s",
730  &m_position.x, &m_position.y, &m_length, pinOrient, &m_numTextSize,
731  &m_nameTextSize, &m_Unit, &m_Convert, pinType, pinAttrs );
732 
733  if( cnt != (prms_count - 2) )
734  {
735  aErrorMsg.Printf( wxT( "pin parameters read issue" ) );
736  return false;
737  }
738 
739  m_orientation = pinOrient[0] & 255;
740 
741  switch( *pinType & 255 )
742  {
743  case 'I':
744  m_type = PIN_INPUT;
745  break;
746 
747  case 'O':
748  m_type = PIN_OUTPUT;
749  break;
750 
751  case 'B':
752  m_type = PIN_BIDI;
753  break;
754 
755  case 'T':
757  break;
758 
759  case 'P':
761  break;
762 
763  case 'U':
765  break;
766 
767  case 'W':
769  break;
770 
771  case 'w':
773  break;
774 
775  case 'C':
777  break;
778 
779  case 'E':
781  break;
782 
783  case 'N':
784  m_type = PIN_NC;
785  break;
786 
787  default:
788  aErrorMsg.Printf( wxT( "unknown pin type [%c]" ), *pinType & 255 );
789  return false;
790  }
791 
792  if( prms_count >= 12 ) /* Special Symbol defined */
793  {
794  enum
795  {
796  INVERTED = 1 << 0,
797  CLOCK = 1 << 1,
798  LOWLEVEL_IN = 1 << 2,
799  LOWLEVEL_OUT = 1 << 3,
800  FALLING_EDGE = 1 << 4,
801  NONLOGIC = 1 << 5
802  };
803 
804  int flags = 0;
805 
806  for( int j = strlen( pinAttrs ); j > 0; )
807  {
808  switch( pinAttrs[--j] )
809  {
810  case '~':
811  break;
812 
813  case 'N':
815  break;
816 
817  case 'I':
818  flags |= INVERTED;
819  break;
820 
821  case 'C':
822  flags |= CLOCK;
823  break;
824 
825  case 'L':
826  flags |= LOWLEVEL_IN;
827  break;
828 
829  case 'V':
830  flags |= LOWLEVEL_OUT;
831  break;
832 
833  case 'F':
834  flags |= FALLING_EDGE;
835  break;
836 
837  case 'X':
838  flags |= NONLOGIC;
839  break;
840 
841  default:
842  aErrorMsg.Printf( wxT( "unknown pin attribute [%c]" ), pinAttrs[j] );
843  return false;
844  }
845  }
846 
847  switch( flags )
848  {
849  case 0:
851  break;
852 
853  case INVERTED:
855  break;
856 
857  case CLOCK:
859  break;
860 
861  case INVERTED | CLOCK:
863  break;
864 
865  case LOWLEVEL_IN:
867  break;
868 
869  case LOWLEVEL_IN | CLOCK:
871  break;
872 
873  case LOWLEVEL_OUT:
875  break;
876 
877  case FALLING_EDGE:
879  break;
880 
881  case NONLOGIC:
883  break;
884 
885  default:
886  aErrorMsg.Printf( wxT( "pin attributes do not give a valid pin shape [%s]" ), pinAttrs );
887  return false;
888  }
889  }
890 
891  return true;
892 }
893 
894 
896 {
897  return ( m_width == 0 ) ? GetDefaultLineThickness() : m_width;
898 }
899 
900 
902  wxDC* aDC,
903  const wxPoint& aOffset,
904  COLOR4D aColor,
905  GR_DRAWMODE aDrawMode,
906  void* aData,
907  const TRANSFORM& aTransform )
908 {
909  // aData is used here as a bitfield of flags.
910  uintptr_t flags = (uintptr_t) aData;
911  bool drawPinText = flags & PIN_DRAW_TEXTS;
912  bool drawPinDangling = flags & PIN_DRAW_DANGLING;
913  bool drawDanglingHidden = flags & PIN_DANGLING_HIDDEN;
914  bool drawElectricalTypeName = flags & PIN_DRAW_ELECTRICAL_TYPE_NAME;
915 
916  LIB_PART* Entry = GetParent();
917 
918  /* Calculate pin orient taking in account the component orientation. */
919  int orient = PinDrawOrient( aTransform );
920 
921  /* Calculate the pin position */
922  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
923 
924  // Invisible pins are only drawn on request.
925  // They are drawn in GetInvisibleItemColor().
926  // in schematic, they are drawn only if m_showAllPins is true.
927  // In other windows, they are always drawn because we must see them.
928  if( ! IsVisible() )
929  {
930  EDA_DRAW_FRAME* frame = NULL;
931 
932  if( aPanel && aPanel->GetParent() )
933  frame = (EDA_DRAW_FRAME*)aPanel->GetParent();
934 
935  if( frame && frame->IsType( FRAME_SCH ) &&
936  ! ((SCH_EDIT_FRAME*)frame)->GetShowAllPins() )
937  {
938  if( drawPinDangling && drawDanglingHidden )
939  {
940  // Draw the target
941  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling,
942  /* aOnlyTarget */ true );
943  }
944  return;
945  }
946 
947  aColor = GetInvisibleItemColor();
948  }
949 
950  /* Drawing from the pin and the special symbol combination */
951  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling );
952 
953  if( drawPinText )
954  {
955  DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
956  Entry->ShowPinNumbers(), Entry->ShowPinNames(),
957  aColor, aDrawMode );
958  }
959 
960  if( drawElectricalTypeName )
961  DrawPinElectricalTypeName( aPanel, aDC, pos1, orient, aColor, aDrawMode );
962 
963 
964  /* Set to one (1) to draw bounding box around pin to validate bounding
965  * box calculation. */
966 #if 0
967  EDA_RECT bBox = GetBoundingBox();
968  bBox.RevertYAxis();
969  bBox = aTransform.TransformCoordinate( bBox );
970  bBox.Move( aOffset );
971  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
972 #endif
973 }
974 
975 
977  wxDC* aDC,
978  const wxPoint& aPinPos,
979  int aOrient,
980  GR_DRAWMODE aDrawMode,
981  COLOR4D aColor,
982  bool aDrawDangling,
983  bool aOnlyTarget )
984 {
985  int MapX1, MapY1, x1, y1;
986  int width = GetPenSize();
987  int posX = aPinPos.x, posY = aPinPos.y, len = m_length;
988  EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
989 
991 
992  if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color
993  {
994  if( IsSelected() )
995  color = GetItemSelectedColor();
996  }
997  else
998  color = aColor;
999 
1000  GRSetDrawMode( aDC, aDrawMode );
1001 
1002  MapX1 = MapY1 = 0;
1003  x1 = posX;
1004  y1 = posY;
1005 
1006  switch( aOrient )
1007  {
1008  case PIN_UP:
1009  y1 = posY - len;
1010  MapY1 = 1;
1011  break;
1012 
1013  case PIN_DOWN:
1014  y1 = posY + len;
1015  MapY1 = -1;
1016  break;
1017 
1018  case PIN_LEFT:
1019  x1 = posX - len;
1020  MapX1 = 1;
1021  break;
1022 
1023  case PIN_RIGHT:
1024  x1 = posX + len;
1025  MapX1 = -1;
1026  break;
1027  }
1028 
1029  // Draw the pin end target (active end of the pin)
1030  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
1031  #define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
1032 
1033  // Draw but do not print the pin end target 1 pixel width
1034  if( m_type != PIN_NC && ( screen == NULL || !screen->m_IsPrinting ) )
1035  {
1036  if( aDrawDangling )
1037  GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
1038  }
1039 
1040  if( aOnlyTarget )
1041  return;
1042 
1043 
1045  {
1046  const int radius = ExternalPinDecoSize( *this );
1047  GRCircle( clipbox, aDC, MapX1 * radius + x1,
1048  MapY1 * radius + y1,
1049  radius, width, color );
1050 
1051  GRMoveTo( MapX1 * radius * 2 + x1,
1052  MapY1 * radius * 2 + y1 );
1053  GRLineTo( clipbox, aDC, posX, posY, width, color );
1054  }
1055  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
1056  {
1057  const int clock_size = InternalPinDecoSize( *this );
1058  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1059  {
1060  GRMoveTo( x1, y1 + clock_size );
1061  GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
1062  width, color );
1063  GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
1064  }
1065  else /* MapX1 = 0 */
1066  {
1067  GRMoveTo( x1 + clock_size, y1 );
1068  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
1069  width, color );
1070  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
1071  width, color );
1072  }
1073  GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
1074  GRLineTo( clipbox, aDC, posX, posY, width, color );
1075  }
1076  else
1077  {
1078  GRMoveTo( x1, y1 );
1079  GRLineTo( clipbox, aDC, posX, posY, width, color );
1080  }
1081 
1083  {
1084  const int clock_size = InternalPinDecoSize( *this );
1085  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1086  {
1087  GRMoveTo( x1, y1 + clock_size );
1088  GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
1089  width, color );
1090  GRLineTo( clipbox, aDC, x1, y1 - clock_size,
1091  width, color );
1092  }
1093  else /* MapX1 = 0 */
1094  {
1095  GRMoveTo( x1 + clock_size, y1 );
1096  GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
1097  width, color );
1098  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
1099  width, color );
1100  }
1101  }
1102 
1104  {
1105  const int symbol_size = ExternalPinDecoSize( *this );
1106  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1107  {
1108  GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
1109  GRLineTo( clipbox, aDC,
1110  x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
1111  width, color );
1112  GRLineTo( clipbox, aDC, x1, y1, width, color );
1113  }
1114  else /* MapX1 = 0 */
1115  {
1116  GRMoveTo( x1, y1 + MapY1 * symbol_size * 2 );
1117  GRLineTo( clipbox, aDC, x1 - symbol_size * 2,
1118  y1 + MapY1 * symbol_size * 2, width, color );
1119  GRLineTo( clipbox, aDC, x1, y1, width, color );
1120  }
1121  }
1122 
1123 
1124  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1125  {
1126  const int symbol_size = ExternalPinDecoSize( *this );
1127  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1128  {
1129  GRMoveTo( x1, y1 - symbol_size * 2 );
1130  GRLineTo( clipbox,
1131  aDC,
1132  x1 + MapX1 * symbol_size * 2,
1133  y1,
1134  width,
1135  color );
1136  }
1137  else /* MapX1 = 0 */
1138  {
1139  GRMoveTo( x1 - symbol_size * 2, y1 );
1140  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
1141  width, color );
1142  }
1143  }
1144  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1145  {
1146  const int symbol_size = ExternalPinDecoSize( *this );
1147  GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
1148  y1 - (MapY1 - MapX1) * symbol_size );
1149  GRLineTo( clipbox, aDC,
1150  x1 + (MapX1 + MapY1) * symbol_size,
1151  y1 + (MapY1 - MapX1) * symbol_size,
1152  width, color );
1153  GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
1154  y1 - (MapY1 + MapX1) * symbol_size );
1155  GRLineTo( clipbox, aDC,
1156  x1 + (MapX1 - MapY1) * symbol_size,
1157  y1 + (MapY1 + MapX1) * symbol_size,
1158  width, color );
1159  }
1160 
1161  if( m_type == PIN_NC ) // Draw a N.C. symbol
1162  {
1163  GRLine( clipbox, aDC,
1164  posX - NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
1165  posX + NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
1166  width, color );
1167  GRLine( clipbox, aDC,
1168  posX + NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
1169  posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
1170  width, color );
1171  }
1172 }
1173 
1174 
1176  wxDC* DC,
1177  wxPoint& pin_pos,
1178  int orient,
1179  int TextInside,
1180  bool DrawPinNum,
1181  bool DrawPinName,
1182  COLOR4D Color,
1183  GR_DRAWMODE DrawMode )
1184 {
1185  if( !DrawPinName && !DrawPinNum )
1186  return;
1187 
1188  int x, y;
1189 
1190  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
1191  wxSize PinNumSize( m_numTextSize, m_numTextSize );
1192 
1193  int nameLineWidth = GetPenSize();
1194 
1195  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1196  int numLineWidth = GetPenSize();
1197  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1198 
1199  int name_offset = PIN_TEXT_MARGIN +
1200  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1201  int num_offset = PIN_TEXT_MARGIN +
1202  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1203 
1204  GRSetDrawMode( DC, DrawMode );
1205  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
1206 
1207  /* Get the num and name colors */
1208  if( ( Color == COLOR4D::UNSPECIFIED ) && IsSelected() )
1209  Color = GetItemSelectedColor();
1210 
1211  COLOR4D NameColor = Color == COLOR4D::UNSPECIFIED ?
1212  GetLayerColor( LAYER_PINNAM ) : Color;
1213  COLOR4D NumColor = Color == COLOR4D::UNSPECIFIED ?
1214  GetLayerColor( LAYER_PINNUM ) : Color;
1215 
1216  int x1 = pin_pos.x;
1217  int y1 = pin_pos.y;
1218 
1219  switch( orient )
1220  {
1221  case PIN_UP:
1222  y1 -= m_length;
1223  break;
1224 
1225  case PIN_DOWN:
1226  y1 += m_length;
1227  break;
1228 
1229  case PIN_LEFT:
1230  x1 -= m_length;
1231  break;
1232 
1233  case PIN_RIGHT:
1234  x1 += m_length;
1235  break;
1236  }
1237 
1238  if( m_name.IsEmpty() )
1239  DrawPinName = false;
1240 
1241  if( TextInside ) // Draw the text inside, but the pin numbers outside.
1242  {
1243  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1244  {
1245  // It is an horizontal line
1246  if( DrawPinName )
1247  {
1248  if( orient == PIN_RIGHT )
1249  {
1250  x = x1 + TextInside;
1251  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
1252  m_name,
1254  PinNameSize,
1256  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1257  false, false );
1258  }
1259  else // Orient == PIN_LEFT
1260  {
1261  x = x1 - TextInside;
1262  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
1263  m_name,
1265  PinNameSize,
1267  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1268  false, false );
1269  }
1270  }
1271 
1272  if( DrawPinNum )
1273  {
1274  DrawGraphicText( clipbox, DC,
1275  wxPoint( (x1 + pin_pos.x) / 2,
1276  y1 - num_offset ), NumColor,
1277  m_number,
1278  TEXT_ANGLE_HORIZ, PinNumSize,
1280  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1281  false, false );
1282  }
1283  }
1284  else /* Its a vertical line. */
1285  {
1286  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
1287  if( orient == PIN_DOWN )
1288  {
1289  y = y1 + TextInside;
1290 
1291  if( DrawPinName )
1292  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
1293  m_name,
1294  TEXT_ANGLE_VERT, PinNameSize,
1296  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1297  false, false );
1298 
1299  if( DrawPinNum )
1300  DrawGraphicText( clipbox, DC,
1301  wxPoint( x1 - num_offset,
1302  (y1 + pin_pos.y) / 2 ), NumColor,
1303  m_number,
1304  TEXT_ANGLE_VERT, PinNumSize,
1306  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1307  false, false );
1308  }
1309  else /* PIN_UP */
1310  {
1311  y = y1 - TextInside;
1312 
1313  if( DrawPinName )
1314  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
1315  m_name,
1316  TEXT_ANGLE_VERT, PinNameSize,
1318  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1319  false, false );
1320 
1321  if( DrawPinNum )
1322  DrawGraphicText( clipbox, DC,
1323  wxPoint( x1 - num_offset,
1324  (y1 + pin_pos.y) / 2 ), NumColor,
1325  m_number,
1326  TEXT_ANGLE_VERT, PinNumSize,
1328  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1329  false, false );
1330  }
1331  }
1332  }
1333  else /**** Draw num & text pin outside ****/
1334  {
1335  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1336  {
1337  /* Its an horizontal line. */
1338  if( DrawPinName )
1339  {
1340  x = (x1 + pin_pos.x) / 2;
1341  DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
1342  NameColor, m_name,
1343  TEXT_ANGLE_HORIZ, PinNameSize,
1345  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1346  false, false );
1347  }
1348  if( DrawPinNum )
1349  {
1350  x = (x1 + pin_pos.x) / 2;
1351  DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
1352  NumColor, m_number,
1353  TEXT_ANGLE_HORIZ, PinNumSize,
1355  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1356  false, false );
1357  }
1358  }
1359  else /* Its a vertical line. */
1360  {
1361  if( DrawPinName )
1362  {
1363  y = (y1 + pin_pos.y) / 2;
1364  DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
1365  NameColor, m_name,
1366  TEXT_ANGLE_VERT, PinNameSize,
1368  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1369  false, false );
1370  }
1371 
1372  if( DrawPinNum )
1373  {
1374  DrawGraphicText( clipbox, DC,
1375  wxPoint( x1 + num_offset, (y1 + pin_pos.y)
1376  / 2 ),
1377  NumColor, m_number,
1378  TEXT_ANGLE_VERT, PinNumSize,
1380  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1381  false, false );
1382  }
1383  }
1384  }
1385 }
1386 
1387 
1388 
1390  wxPoint& aPosition, int aOrientation,
1391  COLOR4D aColor, GR_DRAWMODE aDrawMode )
1392 {
1393  wxString etypeName = GetElectricalTypeName();
1394 
1395  // Use a reasonable (small) size to draw the text
1396  int etextSize = (m_nameTextSize*3)/4;
1397 
1398  #define ETXT_MAX_SIZE Millimeter2iu(0.7 )
1399  if( etextSize > ETXT_MAX_SIZE )
1400  etextSize = ETXT_MAX_SIZE;
1401 
1402  // Use a reasonable pen size to draw the text
1403  int pensize = etextSize/6;
1404 
1405  // Get a suitable color
1406  if( ( aColor == COLOR4D::UNSPECIFIED ) && IsSelected() )
1407  aColor = GetItemSelectedColor();
1408  else if( !IsVisible() )
1409  aColor = GetInvisibleItemColor();
1410  else
1411  aColor = GetLayerColor( LAYER_NOTES );
1412 
1413  wxPoint txtpos = aPosition;
1414  int offset = Millimeter2iu( 0.4 );
1416  int orient = TEXT_ANGLE_HORIZ;
1417 
1418  switch( aOrientation )
1419  {
1420  case PIN_UP:
1421  txtpos.y += offset;
1422  orient = TEXT_ANGLE_VERT;
1423  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1424  break;
1425 
1426  case PIN_DOWN:
1427  txtpos.y -= offset;
1428  orient = TEXT_ANGLE_VERT;
1429  break;
1430 
1431  case PIN_LEFT:
1432  txtpos.x += offset;
1433  break;
1434 
1435  case PIN_RIGHT:
1436  txtpos.x -= offset;
1437  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1438  break;
1439  }
1440 
1441  GRSetDrawMode( aDC, aDrawMode );
1442  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
1443 
1444  DrawGraphicText( clipbox, aDC, txtpos, aColor, etypeName,
1445  orient, wxSize( etextSize, etextSize ),
1446  hjustify, GR_TEXT_VJUSTIFY_CENTER, pensize,
1447  false, false );
1448 }
1449 
1450 
1451 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
1452 {
1453  int MapX1, MapY1, x1, y1;
1455 
1456  aPlotter->SetColor( color );
1457  aPlotter->SetCurrentLineWidth( GetPenSize() );
1458 
1459  MapX1 = MapY1 = 0;
1460  x1 = aPosition.x; y1 = aPosition.y;
1461 
1462  switch( aOrientation )
1463  {
1464  case PIN_UP:
1465  y1 = aPosition.y - m_length;
1466  MapY1 = 1;
1467  break;
1468 
1469  case PIN_DOWN:
1470  y1 = aPosition.y + m_length;
1471  MapY1 = -1;
1472  break;
1473 
1474  case PIN_LEFT:
1475  x1 = aPosition.x - m_length;
1476  MapX1 = 1;
1477  break;
1478 
1479  case PIN_RIGHT:
1480  x1 = aPosition.x + m_length;
1481  MapX1 = -1;
1482  break;
1483  }
1484 
1486  {
1487  const int radius = ExternalPinDecoSize( *this );
1488  aPlotter->Circle( wxPoint( MapX1 * radius + x1,
1489  MapY1 * radius + y1 ),
1490  radius * 2, // diameter
1491  NO_FILL, // fill option
1492  GetPenSize() ); // width
1493 
1494  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1,
1495  MapY1 * radius * 2 + y1 ) );
1496  aPlotter->FinishTo( aPosition );
1497  }
1498  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
1499  {
1500  const int clock_size = InternalPinDecoSize( *this );
1501  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1502  {
1503  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1504  aPlotter->LineTo( wxPoint( x1 + MapX1 * clock_size * 2, y1 ) );
1505  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1506  }
1507  else /* MapX1 = 0 */
1508  {
1509  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1510  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * clock_size * 2 ) );
1511  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1512  }
1513 
1514  aPlotter->MoveTo( wxPoint( MapX1 * clock_size * 2 + x1,
1515  MapY1 * clock_size * 2 + y1 ) );
1516  aPlotter->FinishTo( aPosition );
1517  }
1518  else
1519  {
1520  aPlotter->MoveTo( wxPoint( x1, y1 ) );
1521  aPlotter->FinishTo( aPosition );
1522  }
1523 
1526  {
1527  const int clock_size = InternalPinDecoSize( *this );
1528  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1529  {
1530  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1531  aPlotter->LineTo( wxPoint( x1 - MapX1 * clock_size * 2, y1 ) );
1532  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1533  }
1534  else /* MapX1 = 0 */
1535  {
1536  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1537  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * clock_size * 2 ) );
1538  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1539  }
1540  }
1541 
1542  if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1543  {
1544  const int symbol_size = ExternalPinDecoSize( *this );
1545 
1546  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1547  {
1548  aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1549  aPlotter->LineTo( wxPoint( x1 + MapX1 * symbol_size * 2,
1550  y1 - symbol_size * 2 ) );
1551  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1552  }
1553  else /* MapX1 = 0 */
1554  {
1555  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1556  aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
1557  y1 + MapY1 * symbol_size * 2 ) );
1558  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1559  }
1560  }
1561 
1562 
1563  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1564  {
1565  const int symbol_size = ExternalPinDecoSize( *this );
1566 
1567  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1568  {
1569  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
1570  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1571  }
1572  else /* MapX1 = 0 */
1573  {
1574  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
1575  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1576  }
1577  }
1578  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1579  {
1580  const int symbol_size = ExternalPinDecoSize( *this );
1581  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
1582  y1 - (MapY1 - MapX1) * symbol_size ) );
1583  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * symbol_size,
1584  y1 + (MapY1 - MapX1) * symbol_size ) );
1585  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * symbol_size,
1586  y1 - (MapY1 + MapX1) * symbol_size ) );
1587  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * symbol_size,
1588  y1 + (MapY1 + MapX1) * symbol_size ) );
1589  }
1590  if( m_type == PIN_NC ) // Draw a N.C. symbol
1591  {
1592  const int ex1 = aPosition.x;
1593  const int ey1 = aPosition.y;
1594  aPlotter->MoveTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1595  aPlotter->FinishTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1596  aPlotter->MoveTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1597  aPlotter->FinishTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1598  }
1599 }
1600 
1601 
1602 void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
1603  int TextInside, bool DrawPinNum,
1604  bool DrawPinName, int aWidth )
1605 {
1606  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
1607  DrawPinName = false;
1608 
1609  if( m_number.IsEmpty() )
1610  DrawPinNum = false;
1611 
1612  if( !DrawPinNum && !DrawPinName )
1613  return;
1614 
1615  int x, y;
1616  wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
1617  wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
1618 
1619  int nameLineWidth = GetPenSize();
1620  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1621  int numLineWidth = GetPenSize();
1622  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1623 
1624  int name_offset = PIN_TEXT_MARGIN +
1625  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1626  int num_offset = PIN_TEXT_MARGIN +
1627  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1628 
1629  /* Get the num and name colors */
1630  COLOR4D NameColor = GetLayerColor( LAYER_PINNAM );
1631  COLOR4D NumColor = GetLayerColor( LAYER_PINNUM );
1632 
1633  int x1 = pin_pos.x;
1634  int y1 = pin_pos.y;
1635 
1636  switch( orient )
1637  {
1638  case PIN_UP:
1639  y1 -= m_length;
1640  break;
1641 
1642  case PIN_DOWN:
1643  y1 += m_length;
1644  break;
1645 
1646  case PIN_LEFT:
1647  x1 -= m_length;
1648  break;
1649 
1650  case PIN_RIGHT:
1651  x1 += m_length;
1652  break;
1653  }
1654 
1655  /* Draw the text inside, but the pin numbers outside. */
1656  if( TextInside )
1657  {
1658  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) ) /* Its an horizontal line. */
1659  {
1660  if( DrawPinName )
1661  {
1662  if( orient == PIN_RIGHT )
1663  {
1664  x = x1 + TextInside;
1665  plotter->Text( wxPoint( x, y1 ), NameColor,
1666  m_name,
1668  PinNameSize,
1671  aWidth, false, false );
1672  }
1673  else // orient == PIN_LEFT
1674  {
1675  x = x1 - TextInside;
1676 
1677  if( DrawPinName )
1678  plotter->Text( wxPoint( x, y1 ),
1679  NameColor, m_name, TEXT_ANGLE_HORIZ,
1680  PinNameSize,
1683  aWidth, false, false );
1684  }
1685  }
1686  if( DrawPinNum )
1687  {
1688  plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
1689  y1 - num_offset ),
1690  NumColor, m_number,
1691  TEXT_ANGLE_HORIZ, PinNumSize,
1694  aWidth, false, false );
1695  }
1696  }
1697  else /* Its a vertical line. */
1698  {
1699  if( orient == PIN_DOWN )
1700  {
1701  y = y1 + TextInside;
1702 
1703  if( DrawPinName )
1704  plotter->Text( wxPoint( x1, y ), NameColor,
1705  m_name,
1706  TEXT_ANGLE_VERT, PinNameSize,
1709  aWidth, false, false );
1710 
1711  if( DrawPinNum )
1712  {
1713  plotter->Text( wxPoint( x1 - num_offset,
1714  (y1 + pin_pos.y) / 2 ),
1715  NumColor, m_number,
1716  TEXT_ANGLE_VERT, PinNumSize,
1719  aWidth, false, false );
1720  }
1721  }
1722  else /* PIN_UP */
1723  {
1724  y = y1 - TextInside;
1725 
1726  if( DrawPinName )
1727  plotter->Text( wxPoint( x1, y ), NameColor,
1728  m_name,
1729  TEXT_ANGLE_VERT, PinNameSize,
1732  aWidth, false, false );
1733 
1734  if( DrawPinNum )
1735  {
1736  plotter->Text( wxPoint( x1 - num_offset,
1737  (y1 + pin_pos.y) / 2 ),
1738  NumColor, m_number,
1739  TEXT_ANGLE_VERT, PinNumSize,
1742  aWidth, false, false );
1743  }
1744  }
1745  }
1746  }
1747  else /* Draw num & text pin outside */
1748  {
1749  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1750  {
1751  /* Its an horizontal line. */
1752  if( DrawPinName )
1753  {
1754  x = (x1 + pin_pos.x) / 2;
1755  plotter->Text( wxPoint( x, y1 - name_offset ),
1756  NameColor, m_name,
1757  TEXT_ANGLE_HORIZ, PinNameSize,
1760  aWidth, false, false );
1761  }
1762 
1763  if( DrawPinNum )
1764  {
1765  x = ( x1 + pin_pos.x ) / 2;
1766  plotter->Text( wxPoint( x, y1 + num_offset ),
1767  NumColor, m_number,
1768  TEXT_ANGLE_HORIZ, PinNumSize,
1771  aWidth, false, false );
1772  }
1773  }
1774  else /* Its a vertical line. */
1775  {
1776  if( DrawPinName )
1777  {
1778  y = ( y1 + pin_pos.y ) / 2;
1779  plotter->Text( wxPoint( x1 - name_offset, y ),
1780  NameColor, m_name,
1781  TEXT_ANGLE_VERT, PinNameSize,
1784  aWidth, false, false );
1785  }
1786 
1787  if( DrawPinNum )
1788  {
1789  plotter->Text( wxPoint( x1 + num_offset,
1790  ( y1 + pin_pos.y ) / 2 ),
1791  NumColor, m_number,
1792  TEXT_ANGLE_VERT, PinNumSize,
1795  aWidth, false, false );
1796  }
1797  }
1798  }
1799 }
1800 
1801 
1803 {
1804  wxPoint pos = m_position;
1805 
1806  switch( m_orientation )
1807  {
1808  case PIN_UP:
1809  pos.y += m_length;
1810  break;
1811 
1812  case PIN_DOWN:
1813  pos.y -= m_length;
1814  break;
1815 
1816  case PIN_LEFT:
1817  pos.x -= m_length;
1818  break;
1819 
1820  case PIN_RIGHT:
1821  pos.x += m_length;
1822  break;
1823  }
1824 
1825  return pos;
1826 }
1827 
1828 
1829 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
1830 {
1831  int orient;
1832  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
1833 
1834  switch( m_orientation )
1835  {
1836  case PIN_UP:
1837  end.y = 1;
1838  break;
1839 
1840  case PIN_DOWN:
1841  end.y = -1;
1842  break;
1843 
1844  case PIN_LEFT:
1845  end.x = -1;
1846  break;
1847 
1848  case PIN_RIGHT:
1849  end.x = 1;
1850  break;
1851  }
1852 
1853  // = pos of end point, according to the component orientation
1854  end = aTransform.TransformCoordinate( end );
1855  orient = PIN_UP;
1856 
1857  if( end.x == 0 )
1858  {
1859  if( end.y > 0 )
1860  orient = PIN_DOWN;
1861  }
1862  else
1863  {
1864  orient = PIN_RIGHT;
1865 
1866  if( end.x < 0 )
1867  orient = PIN_LEFT;
1868  }
1869 
1870  return orient;
1871 }
1872 
1873 
1875 {
1876  return new LIB_PIN( *this );
1877 }
1878 
1879 
1880 int LIB_PIN::compare( const LIB_ITEM& other ) const
1881 {
1882  wxASSERT( other.Type() == LIB_PIN_T );
1883 
1884  const LIB_PIN* tmp = (LIB_PIN*) &other;
1885 
1886  if( m_number != tmp->m_number )
1887  return m_number.Cmp( tmp->m_number );
1888 
1889  int result = m_name.CmpNoCase( tmp->m_name );
1890 
1891  if( result != 0 )
1892  return result;
1893 
1894  if( m_position.x != tmp->m_position.x )
1895  return m_position.x - tmp->m_position.x;
1896 
1897  if( m_position.y != tmp->m_position.y )
1898  return m_position.y - tmp->m_position.y;
1899 
1900  return 0;
1901 }
1902 
1903 
1904 void LIB_PIN::SetOffset( const wxPoint& aOffset )
1905 {
1906  m_position += aOffset;
1907 }
1908 
1909 
1910 bool LIB_PIN::Inside( EDA_RECT& rect ) const
1911 {
1912  wxPoint end = PinEndPoint();
1913 
1914  return rect.Contains( m_position.x, -m_position.y ) || rect.Contains( end.x, -end.y );
1915 }
1916 
1917 
1918 void LIB_PIN::Move( const wxPoint& newPosition )
1919 {
1920  if( m_position != newPosition )
1921  {
1922  m_position = newPosition;
1923  SetModified();
1924  }
1925 }
1926 
1927 
1928 void LIB_PIN::MirrorHorizontal( const wxPoint& center )
1929 {
1930  m_position.x -= center.x;
1931  m_position.x *= -1;
1932  m_position.x += center.x;
1933 
1934  if( m_orientation == PIN_RIGHT )
1936  else if( m_orientation == PIN_LEFT )
1938 }
1939 
1940 void LIB_PIN::MirrorVertical( const wxPoint& center )
1941 {
1942  m_position.y -= center.y;
1943  m_position.y *= -1;
1944  m_position.y += center.y;
1945 
1946  if( m_orientation == PIN_UP )
1948  else if( m_orientation == PIN_DOWN )
1950 }
1951 
1952 void LIB_PIN::Rotate( const wxPoint& center, bool aRotateCCW )
1953 {
1954  int rot_angle = aRotateCCW ? -900 : 900;
1955 
1956  RotatePoint( &m_position, center, rot_angle );
1957 
1958  if( aRotateCCW )
1959  {
1960  switch( m_orientation )
1961  {
1962  case PIN_RIGHT:
1964  break;
1965 
1966  case PIN_UP:
1968  break;
1969  case PIN_LEFT:
1971  break;
1972 
1973  case PIN_DOWN:
1975  break;
1976  }
1977  }
1978  else
1979  {
1980  switch( m_orientation )
1981  {
1982  case PIN_RIGHT:
1984  break;
1985 
1986  case PIN_UP:
1988  break;
1989  case PIN_LEFT:
1991  break;
1992 
1993  case PIN_DOWN:
1995  break;
1996  }
1997  }
1998 }
1999 
2000 
2001 void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
2002  const TRANSFORM& aTransform )
2003 {
2004  if( ! IsVisible() )
2005  return;
2006 
2007  int orient = PinDrawOrient( aTransform );
2008 
2009  wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
2010 
2011  PlotSymbol( plotter, pos, orient );
2012  PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
2013  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),
2014  GetPenSize() );
2015 }
2016 
2017 
2018 void LIB_PIN::SetWidth( int aWidth )
2019 {
2020  if( m_width != aWidth )
2021  {
2022  m_width = aWidth;
2023  SetModified();
2024  }
2025 }
2026 
2027 
2029 {
2030  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
2031 
2032  LIB_ITEM::GetMsgPanelInfo( aList );
2033 
2034  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name, DARKCYAN ) );
2035 
2036  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
2037 
2038  aList.push_back( MSG_PANEL_ITEM( _( "Type" ),
2039  GetText( m_type ),
2040  RED ) );
2041 
2042  text = GetText( m_shape );
2043 
2044  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
2045 
2046  if( IsVisible() )
2047  text = _( "Yes" );
2048  else
2049  text = _( "No" );
2050 
2051  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text, DARKGREEN ) );
2052 
2053  // Display pin length
2054  text = StringFromValue( g_UserUnit, m_length, true );
2055  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) );
2056 
2058  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) );
2059 }
2060 
2062 {
2063  getMsgPanelInfoBase( aList );
2064 
2065  wxString text;
2066  wxPoint pinpos = GetPosition();
2067  pinpos.y = -pinpos.y; // Display coord are top to bottom
2068  // lib items coord are bottom to top
2069 
2070  text = StringFromValue( g_UserUnit, pinpos.x, true );
2071  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
2072 
2073  text = StringFromValue( g_UserUnit, pinpos.y, true );
2074  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
2075 }
2076 
2077 void LIB_PIN::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList,
2078  SCH_COMPONENT* aComponent )
2079 {
2080  getMsgPanelInfoBase( aList );
2081 
2082  if( !aComponent )
2083  return;
2084 
2085  wxString text;
2086  wxPoint pinpos = aComponent->GetTransform().TransformCoordinate( GetPosition() )
2087  + aComponent->GetPosition();
2088 
2089  text = StringFromValue( g_UserUnit, pinpos.x, true );
2090  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
2091 
2092  text = StringFromValue( g_UserUnit, pinpos.y, true );
2093  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
2094 
2095  aList.push_back( MSG_PANEL_ITEM( aComponent->GetField( REFERENCE )->GetShownText(),
2096  aComponent->GetField( VALUE )->GetShownText(),
2097  DARKCYAN ) );
2098 }
2099 
2100 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
2101 {
2102  LIB_PART* entry = (LIB_PART* ) m_Parent;
2103  EDA_RECT bbox;
2104  wxPoint begin;
2105  wxPoint end;
2106  int nameTextOffset = 0;
2107  bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" ));
2108  bool showNum = !m_number.IsEmpty();
2109  int minsizeV = TARGET_PIN_RADIUS;
2110 
2111  if( !aIncludeInvisibles && !IsVisible() )
2112  showName = false;
2113 
2114  if( entry )
2115  {
2116  if( entry->ShowPinNames() )
2117  nameTextOffset = entry->GetPinNameOffset();
2118  else
2119  showName = false;
2120 
2121  showNum = entry->ShowPinNumbers();
2122  }
2123 
2124  // First, calculate boundary box corners position
2125  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
2126 
2127  // Actual text height is bigger than text size
2128  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
2129 
2131  minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
2132 
2133  // calculate top left corner position
2134  // for the default pin orientation (PIN_RIGHT)
2135  begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
2136  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
2137 
2138  // calculate bottom right corner position and adjust top left corner position
2139  int nameTextLength = 0;
2140  int nameTextHeight = 0;
2141 
2142  if( showName )
2143  {
2144  int length = m_name.Len();
2145 
2146  // Don't count the line over text symbol.
2147  if( m_name.Left( 1 ) == wxT( "~" ) )
2148  length -= 1;
2149 
2150  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
2151 
2152  // Actual text height are bigger than text size
2153  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
2154  }
2155 
2156  if( nameTextOffset ) // for values > 0, pin name is inside the body
2157  {
2158  end.x = m_length + nameTextLength;
2159  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
2160  }
2161  else // if value == 0:
2162  // pin name is outside the body, and above the pin line
2163  // pin num is below the pin line
2164  {
2165  end.x = std::max(m_length, nameTextLength);
2166  end.y = -begin.y;
2167  begin.y = std::max( minsizeV, nameTextHeight );
2168  }
2169 
2170  // Now, calculate boundary box corners position for the actual pin orientation
2171  int orient = PinDrawOrient( DefaultTransform );
2172 
2173  /* Calculate the pin position */
2174  switch( orient )
2175  {
2176  case PIN_UP:
2177  // Pin is rotated and texts positions are mirrored
2178  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
2179  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
2180  break;
2181 
2182  case PIN_DOWN:
2183  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
2184  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
2185  begin.x = -begin.x;
2186  end.x = -end.x;
2187  break;
2188 
2189  case PIN_LEFT:
2190  begin.x = -begin.x;
2191  end.x = -end.x;
2192  break;
2193 
2194  case PIN_RIGHT:
2195  break;
2196  }
2197 
2198  begin += m_position;
2199  end += m_position;
2200 
2201  bbox.SetOrigin( begin );
2202  bbox.SetEnd( end );
2203  bbox.Normalize();
2204  bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
2205 
2206  // Draw Y axis is reversed in schematic:
2207  bbox.RevertYAxis();
2208 
2209  return bbox;
2210 }
2211 
2212 
2213 wxArrayString LIB_PIN::GetOrientationNames( void )
2214 {
2215  wxArrayString tmp;
2216 
2217  for( unsigned ii = 0; ii < PIN_ORIENTATION_CNT; ii++ )
2218  tmp.Add( getPinOrientationName( ii ) );
2219 
2220  return tmp;
2221 }
2222 
2223 
2225 {
2226  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
2227  return pin_orientation_codes[ index ];
2228 
2229  return PIN_RIGHT;
2230 }
2231 
2232 
2234 {
2235  size_t i;
2236 
2237  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
2238  {
2239  if( pin_orientation_codes[i] == code )
2240  return (int) i;
2241  }
2242 
2243  return wxNOT_FOUND;
2244 }
2245 
2246 
2248 {
2249  int orient = PIN_RIGHT;
2250 
2251  switch( GetOrientation() )
2252  {
2253  case PIN_UP:
2254  orient = PIN_LEFT;
2255  break;
2256 
2257  case PIN_DOWN:
2258  orient = PIN_RIGHT;
2259  break;
2260 
2261  case PIN_LEFT:
2262  orient = PIN_DOWN;
2263  break;
2264 
2265  case PIN_RIGHT:
2266  orient = PIN_UP;
2267  break;
2268  }
2269 
2270  // Set the new orientation
2271  SetOrientation( orient );
2272 }
2273 
2274 
2276 {
2277  return iconsPinsOrientations;
2278 }
2279 
2280 
2282 {
2283  return GetBitmap( m_type );
2284 }
2285 
2286 
2288 {
2289  wxString tmp;
2290  wxString style;
2291 
2292  style = GetText( m_shape );
2293 
2294  tmp.Printf( _( "Pin %s, %s, %s" ),
2296 
2297  return tmp;
2298 }
2299 
2300 
2301 bool LIB_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
2302 {
2303  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
2304 
2305  // Note: this will have to be modified if we add find and replace capability to the
2306  // compoment library editor. Otherwise, you wont be able to replace pin text.
2307  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS )
2308  || ( aSearchData.GetFlags() & FR_SEARCH_REPLACE ) )
2309  return false;
2310 
2311  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
2312 
2313  if( EDA_ITEM::Matches( GetName(), aSearchData ) || EDA_ITEM::Matches( m_number, aSearchData ) )
2314  {
2315  if( aFindLocation )
2316  *aFindLocation = GetBoundingBox().Centre();
2317 
2318  return true;
2319  }
2320 
2321  return false;
2322 }
2323 
2324 
2325 #if defined(DEBUG)
2326 
2327 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
2328 {
2329  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2330  << " num=\"" << m_number.mb_str()
2331  << '"' << "/>\n";
2332 
2333 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2334 }
2335 
2336 #endif
Definition: colors.h:57
void FinishTo(const wxPoint &pos)
Definition: plot_common.h:241
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:124
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:108
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:2301
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
int compare(const LIB_ITEM &aOther) const override
Function compare provides the draw object specific comparison called by the == and < operators...
Definition: lib_pin.cpp:1880
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
void SetModified()
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:80
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:342
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1874
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf), PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
Definition: drawtxt.cpp:122
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:182
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:125
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Function DrawPinElectricalTypeName draws the electrical type text of the pin (only for the footprint ...
Definition: lib_pin.cpp:1389
TRANSFORM & GetTransform() const
static int ExternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
Definition: lib_pin.cpp:140
PNG memory record (file in memory).
Definition: bitmap_types.h:38
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:73
int GetPinNameOffset()
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
wxString m_typeName
Name of object displayed in the message panel.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
#define ETXT_MAX_SIZE
static const wxString getPinOrientationName(unsigned aPinOrientationCode)
Definition: lib_pin.cpp:106
Implementation of conversion functions that require both schematic and board internal units...
int m_numTextSize
Definition: lib_pin.h:79
bool IsNew() const
Definition: base_struct.h:230
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:2213
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:2028
virtual void SetColor(COLOR4D color)=0
bool Contains(const wxPoint &aPoint) const
Function Contains.
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:2281
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:277
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
Definition: colors.h:61
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:414
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
static int GetDefaultPinLength()
Definition: libeditframe.h:168
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:266
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:160
bool IsSelected() const
Definition: base_struct.h:235
static const BITMAP_DEF iconsPinsOrientations[]
Definition: lib_pin.cpp:65
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:275
void SetOrigin(const wxPoint &pos)
void SetWidth(int aWidth) override
Function SetWidth sets the width of the draw item to aWidth.
Definition: lib_pin.cpp:2018
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1904
Search texts (name and number (a 4 letters text) )in pins.
int m_Unit
Unit identification for multiple parts per package.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
wxString m_name
Definition: lib_pin.h:77
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:2275
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
Definition: lib_pin.cpp:2061
Definition: lib_pin.h:55
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:493
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth)
Function PlotPinTexts plots the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1602
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:138
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
int GetNameTextSize() const
Definition: lib_pin.h:189
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
int GetOrientation() const
Definition: lib_pin.h:221
int m_length
Length of the pin.
Definition: lib_pin.h:71
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:2233
#define TEXT_ANGLE_VERT
Definition: common.h:92
COLOR4D GetInvisibleItemColor()
Field Reference of part, i.e. "IC21".
int GetNumberTextSize() const
Definition: lib_pin.h:219
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
This file contains miscellaneous commonly used macros and functions.
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: drawtxt.cpp:229
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_pin.cpp:1940
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform) override
Draw a pin, with or without the pin texts.
Definition: lib_pin.cpp:901
const wxString & GetName() const
Definition: lib_pin.h:163
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:429
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:135
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:401
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.h:203
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
bool ShowPinNames()
int GetPenSize() const override
Function GetPenSize.
Definition: lib_pin.cpp:895
bool Load(LINE_READER &aLineReader, wxString &aErrorMsg) override
Definition: lib_pin.cpp:682
static int GetPinNumDefaultSize()
Definition: libeditframe.h:160
void LineTo(const wxPoint &pos)
Definition: plot_common.h:236
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:72
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:123
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
bool ShowPinNumbers()
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString traceFindItem
Flag to enable finding schematic item debug output.
wxString m_number
Definition: lib_pin.h:78
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1451
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:267
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Class LIB_ITEM definition.
void SetEnd(int x, int y)
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
bool Inside(EDA_RECT &aRect) const override
Function Inside tests if any part of the draw object is inside rectangle bounds of aRect...
Definition: lib_pin.cpp:1910
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: lib_pin.cpp:519
Class LIB_PART defines a library part object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:460
EDA_RECT * GetClipBox()
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:2247
Definition: colors.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
static const int pin_orientation_codes[]
Definition: lib_pin.cpp:51
wxPoint Centre() const
static int InternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius)
Definition: lib_pin.cpp:131
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:360
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Function DrawPinTexts puts the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1175
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:145
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin edition.
Definition: lib_pin.cpp:372
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:465
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void MoveTo(const wxPoint &pos)
Definition: plot_common.h:231
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:76
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:391
void Normalize()
Function Normalize ensures that the height ant width are positive.
Field Value of part, i.e. "3.3K".
#define NCSYMB_PIN_DIM
Base plotter engine class.
Definition: plot_common.h:86
Definition the SCH_COMPONENT class for Eeschema.
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:70
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:399
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:2001
wxPoint PinEndPoint() const
Function PinEndPoint.
Definition: lib_pin.cpp:1802
static int GetPinNameDefaultSize()
Definition: libeditframe.h:164
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define max(a, b)
Definition: auxiliary.h:86
#define PIN_TEXT_MARGIN
Definition: lib_pin.cpp:61
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:791
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:2287
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:189
Perform a search for a item that has replaceable text.
Class EDA_RECT handles the component boundary box.
void SetType(ELECTRICAL_PINTYPE aType, bool aTestOtherPins=true)
Set the electrical type of the pin.
Definition: lib_pin.cpp:306
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxPoint GetPosition() const override
Function GetPosition.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_pin.cpp:1918
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:43
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:75
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
int m_Convert
Shape identification for alternate body styles.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
This file is part of the common libary.
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:248
COLOR4D GetItemSelectedColor()
bool IsType(FRAME_T aType) const
Definition: wxstruct.h:229
BITMAP_DEF GetBitmap(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:70
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:192
Message panel definition file.
int m_width
Line width of the pin.
Definition: lib_pin.h:74
void DrawPinSymbol(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, int aOrientation, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED, bool aDrawDangling=true, bool aOnlyTarget=false)
Function DrawPinSymbol Draw the pin symbol without text.
Definition: lib_pin.cpp:976
#define PIN_ORIENTATION_CNT
Definition: lib_pin.cpp:58
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_pin.cpp:543
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
Definition of class LIB_EDIT_FRAME.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
int PinDrawOrient(const TRANSFORM &aTransform) const
Function PinDrawOrient returns the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation and the matrix transform (rot, mirror) aTransform.
Definition: lib_pin.cpp:1829
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:220
#define min(a, b)
Definition: auxiliary.h:85
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_pin.cpp:1928
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:2224
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39