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  return aPin.GetNameTextSize() / 2;
134 }
135 
137 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
138 // marker
139 static int ExternalPinDecoSize( const LIB_PIN &aPin )
140 {
141  return aPin.GetNumberTextSize() / 2;
142 }
143 
145  LIB_ITEM( LIB_PIN_T, aParent ),
146  m_shape( PINSHAPE_LINE )
147 {
149  m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right
150  m_type = PIN_UNSPECIFIED; // electrical type of pin
151  m_attributes = 0; // bit 0 != 0: pin invisible
152  m_number = 0; // pin number (i.e. 4 ASCII chars)
155  m_width = 0;
156  m_typeName = _( "Pin" );
157 }
158 
159 
160 void LIB_PIN::SetName( const wxString& aName )
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( GetParent() == NULL )
173  return;
174 
175  LIB_PINS pinList;
176  GetParent()->GetPins( pinList );
177 
178  for( size_t i = 0; i < pinList.size(); i++ )
179  {
180  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_name == m_name )
181  continue;
182 
183  pinList[i]->m_name = m_name;
184  SetModified();
185  }
186 }
187 
188 
189 void LIB_PIN::SetNameTextSize( int size )
190 {
191  if( size != m_nameTextSize )
192  {
193  m_nameTextSize = size;
194  SetModified();
195  }
196 
197  if( GetParent() == NULL )
198  return;
199 
200  LIB_PINS pinList;
201  GetParent()->GetPins( pinList );
202 
203  for( size_t i = 0; i < pinList.size(); i++ )
204  {
205  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_nameTextSize == size )
206  continue;
207 
208  pinList[i]->m_nameTextSize = size;
209  SetModified();
210  }
211 }
212 
213 
214 void LIB_PIN::SetNumber( const wxString& number )
215 {
216  wxString tmp = ( number.IsEmpty() ) ? wxT( "~" ) : number;
217 
218  tmp.Replace( wxT( " " ), wxT( "_" ) );
219  long oldNumber = m_number;
220  SetPinNumFromString( tmp );
221 
222  if( m_number != oldNumber )
223  SetFlags( IS_CHANGED );
224 
225  /* Others pin numbers marked by EnableEditMode() are not modified
226  * because each pin has its own number
227  */
228 }
229 
230 
232 {
233  if( size != m_numTextSize )
234  {
235  m_numTextSize = size;
236  SetModified();
237  }
238 
239  if( GetParent() == NULL )
240  return;
241 
242  LIB_PINS pinList;
243  GetParent()->GetPins( pinList );
244 
245  for( size_t i = 0; i < pinList.size(); i++ )
246  {
247  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_numTextSize == size )
248  continue;
249 
250  pinList[i]->m_numTextSize = size;
251  SetModified();
252  }
253 }
254 
255 
256 void LIB_PIN::SetOrientation( int orientation )
257 {
258  if( m_orientation != orientation )
259  {
260  m_orientation = orientation;
261  SetModified();
262  }
263 
264  if( GetParent() == NULL )
265  return;
266 
267  LIB_PINS pinList;
268  GetParent()->GetPins( pinList );
269 
270  for( size_t i = 0; i < pinList.size(); i++ )
271  {
272  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 ||
273  pinList[i]->m_orientation == orientation )
274  continue;
275 
276  pinList[i]->m_orientation = orientation;
277  SetModified();
278  }
279 }
280 
281 
283 {
284  assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) );
285 
286  if( m_shape != aShape )
287  {
288  m_shape = aShape;
289  SetModified();
290  }
291 
292  if( GetParent() == NULL )
293  return;
294 
295  LIB_PINS pinList;
296  GetParent()->GetPins( pinList );
297 
298  for( size_t i = 0; i < pinList.size(); i++ )
299  {
300  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
301  || pinList[i]->m_Convert != m_Convert
302  || pinList[i]->m_shape == aShape )
303  continue;
304 
305  pinList[i]->m_shape = aShape;
306  SetModified();
307  }
308 }
309 
310 
312 {
313  assert( aType >= 0 && aType < (int)PINTYPE_COUNT );
314 
315  if( aType < PIN_INPUT )
316  aType = PIN_INPUT;
317 
318  if( aType >= (int)PINTYPE_COUNT )
319  aType = PIN_NC;
320 
321  if( m_type != aType )
322  {
323  m_type = aType;
324  SetModified();
325  }
326 
327  if( GetParent() == NULL )
328  return;
329 
330  LIB_PINS pinList;
331  GetParent()->GetPins( pinList );
332 
333  for( size_t i = 0; i < pinList.size(); i++ )
334  {
335  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_type == aType )
336  continue;
337 
338  pinList[i]->m_type = aType;
339  SetModified();
340  }
341 }
342 
343 
344 void LIB_PIN::SetLength( int length )
345 {
346  if( m_length != length )
347  {
348  m_length = length;
349  SetModified();
350  }
351 
352  if( GetParent() == NULL )
353  return;
354 
355  LIB_PINS pinList;
356  GetParent()->GetPins( pinList );
357 
358  for( size_t i = 0; i < pinList.size(); i++ )
359  {
360  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
361  || pinList[i]->m_Convert != m_Convert
362  || pinList[i]->m_length == length )
363  continue;
364 
365  pinList[i]->m_length = length;
366  SetModified();
367  }
368 }
369 
370 
372 {
373  if( m_position != aPosition )
374  {
375  m_position = aPosition;
376  SetModified();
377  }
378 
379  if( GetParent() == NULL )
380  return;
381 
382  LIB_PINS pinList;
383  GetParent()->GetPins( pinList );
384 
385  for( size_t i = 0; i < pinList.size(); i++ )
386  {
387  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
388  || pinList[i]->m_Convert != m_Convert
389  || pinList[i]->m_position == aPosition )
390  continue;
391 
392  pinList[i]->m_position = aPosition;
393  SetModified();
394  }
395 }
396 
397 
398 void LIB_PIN::SetPartNumber( int part )
399 {
400  if( m_Unit == part )
401  return;
402 
403  m_Unit = part;
404  SetModified();
405 
406  if( m_Unit == 0 )
407  {
408  LIB_PIN* pin;
409  LIB_PIN* tmp = GetParent()->GetNextPin();
410 
411  while( tmp != NULL )
412  {
413  pin = tmp;
414  tmp = GetParent()->GetNextPin( pin );
415 
416  if( pin->m_Flags == 0 || pin == this
417  || ( m_Convert && ( m_Convert != pin->m_Convert ) )
418  || ( m_position != pin->m_position )
419  || ( pin->m_orientation != m_orientation ) )
420  continue;
421 
422  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
423  }
424  }
425 }
426 
427 
428 void LIB_PIN::SetConversion( int style )
429 {
430  if( m_Convert == style )
431  return;
432 
433  m_Convert = style;
434  SetFlags( IS_CHANGED );
435 
436  if( style == 0 )
437  {
438  LIB_PIN* pin;
439  LIB_PIN* tmp = GetParent()->GetNextPin();
440 
441  while( tmp != NULL )
442  {
443  pin = tmp;
444  tmp = GetParent()->GetNextPin( pin );
445 
446  if( ( pin->m_Flags & IS_LINKED ) == 0
447  || ( pin == this )
448  || ( m_Unit && ( m_Unit != pin->m_Unit ) )
449  || ( m_position != pin->m_position )
450  || ( pin->m_orientation != m_orientation ) )
451  continue;
452 
453  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
454  }
455  }
456 }
457 
458 
459 void LIB_PIN::SetVisible( bool visible )
460 {
461  if( visible == IsVisible() )
462  return;
463 
464  if( visible )
466  else
468 
469  SetModified();
470 
471  if( GetParent() == NULL )
472  return;
473 
474  LIB_PINS pinList;
475  GetParent()->GetPins( pinList );
476 
477  for( size_t i = 0; i < pinList.size(); i++ )
478  {
479  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->IsVisible() == visible )
480  continue;
481 
482  if( visible )
483  pinList[i]->m_attributes &= ~PIN_INVISIBLE;
484  else
485  pinList[i]->m_attributes |= PIN_INVISIBLE;
486 
487  SetModified();
488  }
489 }
490 
491 
492 void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin )
493 {
494  LIB_PINS pinList;
495 
496  if( GetParent() == NULL )
497  return;
498 
499  GetParent()->GetPins( pinList );
500 
501  for( size_t i = 0; i < pinList.size(); i++ )
502  {
503  if( pinList[i] == this )
504  continue;
505 
506  if( ( pinList[i]->m_position == m_position )
507  && ( pinList[i]->m_orientation == m_orientation )
508  && !IsNew()
509  && editPinByPin == false
510  && enable )
511  pinList[i]->SetFlags( IS_LINKED | IN_EDIT );
512  else
513  pinList[i]->ClearFlags( IS_LINKED | IN_EDIT );
514  }
515 }
516 
517 
518 bool LIB_PIN::HitTest( const wxPoint& aPosition ) const
519 {
520  return HitTest( aPosition, 0, DefaultTransform );
521 }
522 
523 
524 bool LIB_PIN::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
525 {
526  if( aThreshold < 0 )
527  aThreshold = 0;
528 
529  TRANSFORM transform = DefaultTransform;
530  DefaultTransform = aTransform;
531 
532  EDA_RECT rect = GetBoundingBox();
533  rect.Inflate( aThreshold );
534 
535  //Restore matrix
536  DefaultTransform = transform;
537 
538  return rect.Contains( aPosition );
539 }
540 
541 
542 bool LIB_PIN::Save( OUTPUTFORMATTER& aFormatter )
543 {
544  wxString StringPinNum;
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  PinStringNum( StringPinNum );
596 
597  if( StringPinNum.IsEmpty() )
598  StringPinNum = wxT( "~" );
599 
600  if( !m_name.IsEmpty() )
601  {
602  if( aFormatter.Print( 0, "X %s", TO_UTF8( m_name ) ) < 0 )
603  return false;
604  }
605  else
606  {
607  if( aFormatter.Print( 0, "X ~" ) < 0 )
608  return false;
609  }
610 
611  if( aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
612  TO_UTF8( StringPinNum ), m_position.x, m_position.y,
614  m_Unit, m_Convert, Etype ) < 0 )
615  return false;
616 
617  if( m_shape || !IsVisible() )
618  {
619  if( aFormatter.Print( 0, " " ) < 0 )
620  return false;
621  }
622 
623  if( !IsVisible() && aFormatter.Print( 0, "N" ) < 0 )
624  return false;
625 
626  switch( m_shape )
627  {
628  case PINSHAPE_LINE:
629  break;
630 
631  case PINSHAPE_INVERTED:
632  if( aFormatter.Print( 0, "I" ) < 0 )
633  return false;
634  break;
635 
636  case PINSHAPE_CLOCK:
637  if( aFormatter.Print( 0, "C" ) < 0 )
638  return false;
639  break;
640 
642  if( aFormatter.Print( 0, "IC" ) < 0 )
643  return false;
644  break;
645 
646  case PINSHAPE_INPUT_LOW:
647  if( aFormatter.Print( 0, "L" ) < 0 )
648  return false;
649  break;
650 
651  case PINSHAPE_CLOCK_LOW:
652  if( aFormatter.Print( 0, "CL" ) < 0 )
653  return false;
654  break;
655 
656  case PINSHAPE_OUTPUT_LOW:
657  if( aFormatter.Print( 0, "V" ) < 0 )
658  return false;
659  break;
660 
662  if( aFormatter.Print( 0, "F" ) < 0 )
663  return false;
664  break;
665 
666  case PINSHAPE_NONLOGIC:
667  if( aFormatter.Print( 0, "X" ) < 0 )
668  return false;
669  break;
670 
671  default:
672  assert( !"Invalid pin shape" );
673  return false;
674  }
675 
676  if( aFormatter.Print( 0, "\n" ) < 0 )
677  return false;
678 
680 
681  return true;
682 }
683 
684 #include <wx/tokenzr.h>
685 
686 bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
687 {
688  char pinAttrs[64];
689  char pinOrient[64];
690  char pinType[64];
691 
692  *pinAttrs = 0;
693 
694  // We cannot use sscanf, at least on Windows, to parse the pin description.
695  // The reason is the pin name is free, and use UTF8 encoding.
696  // We encourtered issues (Windows specific) to read this name for some UTF8
697  // cyrillic codes
698  // So, read the pin name (and num) after conversion from UTF8, and read the others
699  // parameters (in ASCII) using sscanf
700 
701  // the full line starts by "X ". The pin data starts at line + 2.
702  wxString utf8line = FROM_UTF8( aLineReader.Line() + 2 );
703  wxStringTokenizer tokenizer( utf8line, wxT(" \n\r" ) );
704  int prms_count = tokenizer.CountTokens();
705 
706  if( prms_count < 11 )
707  {
708  aErrorMsg.Printf( wxT( "pin had %d parameters of the required 11 or 12" ), prms_count );
709  return false;
710  }
711 
712  // Extract the pinName (UTF8 encoded)
713  m_name = tokenizer.GetNextToken();
714 
715  wxString tmp;
716 
717  // Extract the pinName (UTF8 encoded accepted, but should be only ASCII8.)
718  tmp = tokenizer.GetNextToken();
719  SetPinNumFromString( tmp );
720 
721  // Read other parameters, in pure ASCII
722  char line[1024];
723  tmp = tokenizer.GetString();
724 
725  unsigned len = tmp.Length();
726 
727  if( len >= sizeof( line ) ) // Should not occur.
728  len = sizeof( line) - 1;
729 
730  strncpy( line, TO_UTF8( tmp ), len );
731  line[len] = 0;
732 
733  int cnt = sscanf( line, "%d %d %d %63s %d %d %d %d %63s %63s",
734  &m_position.x, &m_position.y, &m_length, pinOrient, &m_numTextSize,
735  &m_nameTextSize, &m_Unit, &m_Convert, pinType, pinAttrs );
736 
737  if( cnt != (prms_count - 2) )
738  {
739  aErrorMsg.Printf( wxT( "pin parameters read issue" ) );
740  return false;
741  }
742 
743  m_orientation = pinOrient[0] & 255;
744 
745  switch( *pinType & 255 )
746  {
747  case 'I':
748  m_type = PIN_INPUT;
749  break;
750 
751  case 'O':
752  m_type = PIN_OUTPUT;
753  break;
754 
755  case 'B':
756  m_type = PIN_BIDI;
757  break;
758 
759  case 'T':
761  break;
762 
763  case 'P':
765  break;
766 
767  case 'U':
769  break;
770 
771  case 'W':
773  break;
774 
775  case 'w':
777  break;
778 
779  case 'C':
781  break;
782 
783  case 'E':
785  break;
786 
787  case 'N':
788  m_type = PIN_NC;
789  break;
790 
791  default:
792  aErrorMsg.Printf( wxT( "unknown pin type [%c]" ), *pinType & 255 );
793  return false;
794  }
795 
796  if( prms_count >= 12 ) /* Special Symbol defined */
797  {
798  enum
799  {
800  INVERTED = 1 << 0,
801  CLOCK = 1 << 1,
802  LOWLEVEL_IN = 1 << 2,
803  LOWLEVEL_OUT = 1 << 3,
804  FALLING_EDGE = 1 << 4,
805  NONLOGIC = 1 << 5
806  };
807 
808  int flags = 0;
809 
810  for( int j = strlen( pinAttrs ); j > 0; )
811  {
812  switch( pinAttrs[--j] )
813  {
814  case '~':
815  break;
816 
817  case 'N':
819  break;
820 
821  case 'I':
822  flags |= INVERTED;
823  break;
824 
825  case 'C':
826  flags |= CLOCK;
827  break;
828 
829  case 'L':
830  flags |= LOWLEVEL_IN;
831  break;
832 
833  case 'V':
834  flags |= LOWLEVEL_OUT;
835  break;
836 
837  case 'F':
838  flags |= FALLING_EDGE;
839  break;
840 
841  case 'X':
842  flags |= NONLOGIC;
843  break;
844 
845  default:
846  aErrorMsg.Printf( wxT( "unknown pin attribute [%c]" ), pinAttrs[j] );
847  return false;
848  }
849  }
850 
851  switch( flags )
852  {
853  case 0:
855  break;
856 
857  case INVERTED:
859  break;
860 
861  case CLOCK:
863  break;
864 
865  case INVERTED | CLOCK:
867  break;
868 
869  case LOWLEVEL_IN:
871  break;
872 
873  case LOWLEVEL_IN | CLOCK:
875  break;
876 
877  case LOWLEVEL_OUT:
879  break;
880 
881  case FALLING_EDGE:
883  break;
884 
885  case NONLOGIC:
887  break;
888 
889  default:
890  aErrorMsg.Printf( wxT( "pin attributes do not give a valid pin shape [%s]" ), pinAttrs );
891  return false;
892  }
893  }
894 
895  return true;
896 }
897 
898 
900 {
901  return ( m_width == 0 ) ? GetDefaultLineThickness() : m_width;
902 }
903 
904 
906  wxDC* aDC,
907  const wxPoint& aOffset,
908  COLOR4D aColor,
909  GR_DRAWMODE aDrawMode,
910  void* aData,
911  const TRANSFORM& aTransform )
912 {
913  // aData is used here as a bitfield of flags.
914  uintptr_t flags = (uintptr_t) aData;
915  bool drawPinText = flags & PIN_DRAW_TEXTS;
916  bool drawPinDangling = flags & PIN_DRAW_DANGLING;
917  bool drawDanglingHidden = flags & PIN_DANGLING_HIDDEN;
918  bool drawElectricalTypeName = flags & PIN_DRAW_ELECTRICAL_TYPE_NAME;
919 
920  LIB_PART* Entry = GetParent();
921 
922  /* Calculate pin orient taking in account the component orientation. */
923  int orient = PinDrawOrient( aTransform );
924 
925  /* Calculate the pin position */
926  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
927 
928  // Invisible pins are only drawn on request.
929  // They are drawn in GetInvisibleItemColor().
930  // in schematic, they are drawn only if m_showAllPins is true.
931  // In other windows, they are always drawn because we must see them.
932  if( ! IsVisible() )
933  {
934  EDA_DRAW_FRAME* frame = NULL;
935 
936  if( aPanel && aPanel->GetParent() )
937  frame = (EDA_DRAW_FRAME*)aPanel->GetParent();
938 
939  if( frame && frame->IsType( FRAME_SCH ) &&
940  ! ((SCH_EDIT_FRAME*)frame)->GetShowAllPins() )
941  {
942  if( drawPinDangling && drawDanglingHidden )
943  {
944  // Draw the target
945  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling,
946  /* aOnlyTarget */ true );
947  }
948  return;
949  }
950 
951  aColor = GetInvisibleItemColor();
952  }
953 
954  /* Drawing from the pin and the special symbol combination */
955  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling );
956 
957  if( drawPinText )
958  {
959  DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
960  Entry->ShowPinNumbers(), Entry->ShowPinNames(),
961  aColor, aDrawMode );
962  }
963 
964  if( drawElectricalTypeName )
965  DrawPinElectricalTypeName( aPanel, aDC, pos1, orient, aColor, aDrawMode );
966 
967 
968  /* Set to one (1) to draw bounding box around pin to validate bounding
969  * box calculation. */
970 #if 0
971  EDA_RECT bBox = GetBoundingBox();
972  bBox.RevertYAxis();
973  bBox = aTransform.TransformCoordinate( bBox );
974  bBox.Move( aOffset );
975  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
976 #endif
977 }
978 
979 
981  wxDC* aDC,
982  const wxPoint& aPinPos,
983  int aOrient,
984  GR_DRAWMODE aDrawMode,
985  COLOR4D aColor,
986  bool aDrawDangling,
987  bool aOnlyTarget )
988 {
989  int MapX1, MapY1, x1, y1;
990  int width = GetPenSize();
991  int posX = aPinPos.x, posY = aPinPos.y, len = m_length;
992  EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
993 
995 
996  if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color
997  {
998  if( IsSelected() )
999  color = GetItemSelectedColor();
1000  }
1001  else
1002  color = aColor;
1003 
1004  GRSetDrawMode( aDC, aDrawMode );
1005 
1006  MapX1 = MapY1 = 0;
1007  x1 = posX;
1008  y1 = posY;
1009 
1010  switch( aOrient )
1011  {
1012  case PIN_UP:
1013  y1 = posY - len;
1014  MapY1 = 1;
1015  break;
1016 
1017  case PIN_DOWN:
1018  y1 = posY + len;
1019  MapY1 = -1;
1020  break;
1021 
1022  case PIN_LEFT:
1023  x1 = posX - len;
1024  MapX1 = 1;
1025  break;
1026 
1027  case PIN_RIGHT:
1028  x1 = posX + len;
1029  MapX1 = -1;
1030  break;
1031  }
1032 
1033  // Draw the pin end target (active end of the pin)
1034  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
1035  #define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
1036 
1037  // Draw but do not print the pin end target 1 pixel width
1038  if( m_type != PIN_NC && ( screen == NULL || !screen->m_IsPrinting ) )
1039  {
1040  if( aDrawDangling )
1041  GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
1042  }
1043 
1044  if( aOnlyTarget )
1045  return;
1046 
1047 
1049  {
1050  const int radius = ExternalPinDecoSize( *this );
1051  GRCircle( clipbox, aDC, MapX1 * radius + x1,
1052  MapY1 * radius + y1,
1053  radius, width, color );
1054 
1055  GRMoveTo( MapX1 * radius * 2 + x1,
1056  MapY1 * radius * 2 + y1 );
1057  GRLineTo( clipbox, aDC, posX, posY, width, color );
1058  }
1059  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
1060  {
1061  const int clock_size = InternalPinDecoSize( *this );
1062  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1063  {
1064  GRMoveTo( x1, y1 + clock_size );
1065  GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
1066  width, color );
1067  GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
1068  }
1069  else /* MapX1 = 0 */
1070  {
1071  GRMoveTo( x1 + clock_size, y1 );
1072  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
1073  width, color );
1074  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
1075  width, color );
1076  }
1077  GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
1078  GRLineTo( clipbox, aDC, posX, posY, width, color );
1079  }
1080  else
1081  {
1082  GRMoveTo( x1, y1 );
1083  GRLineTo( clipbox, aDC, posX, posY, width, color );
1084  }
1085 
1087  {
1088  const int clock_size = InternalPinDecoSize( *this );
1089  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1090  {
1091  GRMoveTo( x1, y1 + clock_size );
1092  GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
1093  width, color );
1094  GRLineTo( clipbox, aDC, x1, y1 - clock_size,
1095  width, color );
1096  }
1097  else /* MapX1 = 0 */
1098  {
1099  GRMoveTo( x1 + clock_size, y1 );
1100  GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
1101  width, color );
1102  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
1103  width, color );
1104  }
1105  }
1106 
1108  {
1109  const int symbol_size = ExternalPinDecoSize( *this );
1110  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1111  {
1112  GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
1113  GRLineTo( clipbox, aDC,
1114  x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
1115  width, color );
1116  GRLineTo( clipbox, aDC, x1, y1, width, color );
1117  }
1118  else /* MapX1 = 0 */
1119  {
1120  GRMoveTo( x1, y1 + MapY1 * symbol_size * 2 );
1121  GRLineTo( clipbox, aDC, x1 - symbol_size * 2,
1122  y1 + MapY1 * symbol_size * 2, width, color );
1123  GRLineTo( clipbox, aDC, x1, y1, width, color );
1124  }
1125  }
1126 
1127 
1128  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1129  {
1130  const int symbol_size = ExternalPinDecoSize( *this );
1131  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1132  {
1133  GRMoveTo( x1, y1 - symbol_size * 2 );
1134  GRLineTo( clipbox,
1135  aDC,
1136  x1 + MapX1 * symbol_size * 2,
1137  y1,
1138  width,
1139  color );
1140  }
1141  else /* MapX1 = 0 */
1142  {
1143  GRMoveTo( x1 - symbol_size * 2, y1 );
1144  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
1145  width, color );
1146  }
1147  }
1148  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1149  {
1150  const int symbol_size = ExternalPinDecoSize( *this );
1151  GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
1152  y1 - (MapY1 - MapX1) * symbol_size );
1153  GRLineTo( clipbox, aDC,
1154  x1 + (MapX1 + MapY1) * symbol_size,
1155  y1 + (MapY1 - MapX1) * symbol_size,
1156  width, color );
1157  GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
1158  y1 - (MapY1 + MapX1) * symbol_size );
1159  GRLineTo( clipbox, aDC,
1160  x1 + (MapX1 - MapY1) * symbol_size,
1161  y1 + (MapY1 + MapX1) * symbol_size,
1162  width, color );
1163  }
1164 
1165  if( m_type == PIN_NC ) // Draw a N.C. symbol
1166  {
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  GRLine( clipbox, aDC,
1172  posX + NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
1173  posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
1174  width, color );
1175  }
1176 }
1177 
1178 
1180  wxDC* DC,
1181  wxPoint& pin_pos,
1182  int orient,
1183  int TextInside,
1184  bool DrawPinNum,
1185  bool DrawPinName,
1186  COLOR4D Color,
1187  GR_DRAWMODE DrawMode )
1188 {
1189  if( !DrawPinName && !DrawPinNum )
1190  return;
1191 
1192  int x, y;
1193  wxString StringPinNum;
1194 
1195  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
1196  wxSize PinNumSize( m_numTextSize, m_numTextSize );
1197 
1198  int nameLineWidth = GetPenSize();
1199 
1200  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1201  int numLineWidth = GetPenSize();
1202  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1203 
1204  int name_offset = PIN_TEXT_MARGIN +
1205  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1206  int num_offset = PIN_TEXT_MARGIN +
1207  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1208 
1209  GRSetDrawMode( DC, DrawMode );
1210  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
1211 
1212  /* Get the num and name colors */
1213  if( ( Color == COLOR4D::UNSPECIFIED ) && IsSelected() )
1214  Color = GetItemSelectedColor();
1215 
1216  COLOR4D NameColor = Color == COLOR4D::UNSPECIFIED ?
1217  GetLayerColor( LAYER_PINNAM ) : Color;
1218  COLOR4D NumColor = Color == COLOR4D::UNSPECIFIED ?
1219  GetLayerColor( LAYER_PINNUM ) : Color;
1220 
1221  /* Create the pin num string */
1222  PinStringNum( StringPinNum );
1223 
1224  int x1 = pin_pos.x;
1225  int y1 = pin_pos.y;
1226 
1227  switch( orient )
1228  {
1229  case PIN_UP:
1230  y1 -= m_length;
1231  break;
1232 
1233  case PIN_DOWN:
1234  y1 += m_length;
1235  break;
1236 
1237  case PIN_LEFT:
1238  x1 -= m_length;
1239  break;
1240 
1241  case PIN_RIGHT:
1242  x1 += m_length;
1243  break;
1244  }
1245 
1246  if( m_name.IsEmpty() )
1247  DrawPinName = false;
1248 
1249  if( TextInside ) // Draw the text inside, but the pin numbers outside.
1250  {
1251  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1252  {
1253  // It is an horizontal line
1254  if( DrawPinName )
1255  {
1256  if( orient == PIN_RIGHT )
1257  {
1258  x = x1 + TextInside;
1259  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
1260  m_name,
1262  PinNameSize,
1264  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1265  false, false );
1266  }
1267  else // Orient == PIN_LEFT
1268  {
1269  x = x1 - TextInside;
1270  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
1271  m_name,
1273  PinNameSize,
1275  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1276  false, false );
1277  }
1278  }
1279 
1280  if( DrawPinNum )
1281  {
1282  DrawGraphicText( clipbox, DC,
1283  wxPoint( (x1 + pin_pos.x) / 2,
1284  y1 - num_offset ), NumColor,
1285  StringPinNum,
1286  TEXT_ANGLE_HORIZ, PinNumSize,
1288  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1289  false, false );
1290  }
1291  }
1292  else /* Its a vertical line. */
1293  {
1294  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
1295  if( orient == PIN_DOWN )
1296  {
1297  y = y1 + TextInside;
1298 
1299  if( DrawPinName )
1300  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
1301  m_name,
1302  TEXT_ANGLE_VERT, PinNameSize,
1304  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1305  false, false );
1306 
1307  if( DrawPinNum )
1308  DrawGraphicText( clipbox, DC,
1309  wxPoint( x1 - num_offset,
1310  (y1 + pin_pos.y) / 2 ), NumColor,
1311  StringPinNum,
1312  TEXT_ANGLE_VERT, PinNumSize,
1314  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1315  false, false );
1316  }
1317  else /* PIN_UP */
1318  {
1319  y = y1 - TextInside;
1320 
1321  if( DrawPinName )
1322  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
1323  m_name,
1324  TEXT_ANGLE_VERT, PinNameSize,
1326  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
1327  false, false );
1328 
1329  if( DrawPinNum )
1330  DrawGraphicText( clipbox, DC,
1331  wxPoint( x1 - num_offset,
1332  (y1 + pin_pos.y) / 2 ), NumColor,
1333  StringPinNum,
1334  TEXT_ANGLE_VERT, PinNumSize,
1336  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1337  false, false );
1338  }
1339  }
1340  }
1341  else /**** Draw num & text pin outside ****/
1342  {
1343  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1344  {
1345  /* Its an horizontal line. */
1346  if( DrawPinName )
1347  {
1348  x = (x1 + pin_pos.x) / 2;
1349  DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
1350  NameColor, m_name,
1351  TEXT_ANGLE_HORIZ, PinNameSize,
1353  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1354  false, false );
1355  }
1356  if( DrawPinNum )
1357  {
1358  x = (x1 + pin_pos.x) / 2;
1359  DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
1360  NumColor, StringPinNum,
1361  TEXT_ANGLE_HORIZ, PinNumSize,
1363  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1364  false, false );
1365  }
1366  }
1367  else /* Its a vertical line. */
1368  {
1369  if( DrawPinName )
1370  {
1371  y = (y1 + pin_pos.y) / 2;
1372  DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
1373  NameColor, m_name,
1374  TEXT_ANGLE_VERT, PinNameSize,
1376  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1377  false, false );
1378  }
1379 
1380  if( DrawPinNum )
1381  {
1382  DrawGraphicText( clipbox, DC,
1383  wxPoint( x1 + num_offset, (y1 + pin_pos.y)
1384  / 2 ),
1385  NumColor, StringPinNum,
1386  TEXT_ANGLE_VERT, PinNumSize,
1388  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1389  false, false );
1390  }
1391  }
1392  }
1393 }
1394 
1395 
1396 
1398  wxPoint& aPosition, int aOrientation,
1399  COLOR4D aColor, GR_DRAWMODE aDrawMode )
1400 {
1401  wxString etypeName = GetElectricalTypeName();
1402 
1403  // Use a reasonable (small) size to draw the text
1404  int etextSize = (m_nameTextSize*3)/4;
1405 
1406  #define ETXT_MAX_SIZE Millimeter2iu(0.7 )
1407  if( etextSize > ETXT_MAX_SIZE )
1408  etextSize = ETXT_MAX_SIZE;
1409 
1410  // Use a reasonable pen size to draw the text
1411  int pensize = etextSize/6;
1412 
1413  // Get a suitable color
1414  if( ( aColor == COLOR4D::UNSPECIFIED ) && IsSelected() )
1415  aColor = GetItemSelectedColor();
1416  else if( !IsVisible() )
1417  aColor = GetInvisibleItemColor();
1418  else
1419  aColor = GetLayerColor( LAYER_NOTES );
1420 
1421  wxPoint txtpos = aPosition;
1422  int offset = Millimeter2iu( 0.4 );
1424  int orient = TEXT_ANGLE_HORIZ;
1425 
1426  switch( aOrientation )
1427  {
1428  case PIN_UP:
1429  txtpos.y += offset;
1430  orient = TEXT_ANGLE_VERT;
1431  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1432  break;
1433 
1434  case PIN_DOWN:
1435  txtpos.y -= offset;
1436  orient = TEXT_ANGLE_VERT;
1437  break;
1438 
1439  case PIN_LEFT:
1440  txtpos.x += offset;
1441  break;
1442 
1443  case PIN_RIGHT:
1444  txtpos.x -= offset;
1445  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1446  break;
1447  }
1448 
1449  GRSetDrawMode( aDC, aDrawMode );
1450  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
1451 
1452  DrawGraphicText( clipbox, aDC, txtpos, aColor, etypeName,
1453  orient, wxSize( etextSize, etextSize ),
1454  hjustify, GR_TEXT_VJUSTIFY_CENTER, pensize,
1455  false, false );
1456 }
1457 
1458 
1459 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
1460 {
1461  int MapX1, MapY1, x1, y1;
1463 
1464  aPlotter->SetColor( color );
1465  aPlotter->SetCurrentLineWidth( GetPenSize() );
1466 
1467  MapX1 = MapY1 = 0;
1468  x1 = aPosition.x; y1 = aPosition.y;
1469 
1470  switch( aOrientation )
1471  {
1472  case PIN_UP:
1473  y1 = aPosition.y - m_length;
1474  MapY1 = 1;
1475  break;
1476 
1477  case PIN_DOWN:
1478  y1 = aPosition.y + m_length;
1479  MapY1 = -1;
1480  break;
1481 
1482  case PIN_LEFT:
1483  x1 = aPosition.x - m_length;
1484  MapX1 = 1;
1485  break;
1486 
1487  case PIN_RIGHT:
1488  x1 = aPosition.x + m_length;
1489  MapX1 = -1;
1490  break;
1491  }
1492 
1494  {
1495  const int radius = ExternalPinDecoSize( *this );
1496  aPlotter->Circle( wxPoint( MapX1 * radius + x1,
1497  MapY1 * radius + y1 ),
1498  radius * 2, // diameter
1499  NO_FILL, // fill option
1500  GetPenSize() ); // width
1501 
1502  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1,
1503  MapY1 * radius * 2 + y1 ) );
1504  aPlotter->FinishTo( aPosition );
1505  }
1506  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
1507  {
1508  const int clock_size = InternalPinDecoSize( *this );
1509  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1510  {
1511  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1512  aPlotter->LineTo( wxPoint( x1 + MapX1 * clock_size * 2, y1 ) );
1513  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1514  }
1515  else /* MapX1 = 0 */
1516  {
1517  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1518  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * clock_size * 2 ) );
1519  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1520  }
1521 
1522  aPlotter->MoveTo( wxPoint( MapX1 * clock_size * 2 + x1,
1523  MapY1 * clock_size * 2 + y1 ) );
1524  aPlotter->FinishTo( aPosition );
1525  }
1526  else
1527  {
1528  aPlotter->MoveTo( wxPoint( x1, y1 ) );
1529  aPlotter->FinishTo( aPosition );
1530  }
1531 
1534  {
1535  const int clock_size = InternalPinDecoSize( *this );
1536  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1537  {
1538  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1539  aPlotter->LineTo( wxPoint( x1 - MapX1 * clock_size * 2, y1 ) );
1540  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1541  }
1542  else /* MapX1 = 0 */
1543  {
1544  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1545  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * clock_size * 2 ) );
1546  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1547  }
1548  }
1549 
1550  if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1551  {
1552  const int symbol_size = ExternalPinDecoSize( *this );
1553 
1554  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1555  {
1556  aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1557  aPlotter->LineTo( wxPoint( x1 + MapX1 * symbol_size * 2,
1558  y1 - symbol_size * 2 ) );
1559  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1560  }
1561  else /* MapX1 = 0 */
1562  {
1563  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1564  aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
1565  y1 + MapY1 * symbol_size * 2 ) );
1566  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1567  }
1568  }
1569 
1570 
1571  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1572  {
1573  const int symbol_size = ExternalPinDecoSize( *this );
1574 
1575  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1576  {
1577  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
1578  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1579  }
1580  else /* MapX1 = 0 */
1581  {
1582  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
1583  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1584  }
1585  }
1586  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1587  {
1588  const int symbol_size = ExternalPinDecoSize( *this );
1589  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
1590  y1 - (MapY1 - MapX1) * symbol_size ) );
1591  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * symbol_size,
1592  y1 + (MapY1 - MapX1) * symbol_size ) );
1593  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * symbol_size,
1594  y1 - (MapY1 + MapX1) * symbol_size ) );
1595  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * symbol_size,
1596  y1 + (MapY1 + MapX1) * symbol_size ) );
1597  }
1598  if( m_type == PIN_NC ) // Draw a N.C. symbol
1599  {
1600  const int ex1 = aPosition.x;
1601  const int ey1 = aPosition.y;
1602  aPlotter->MoveTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1603  aPlotter->FinishTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1604  aPlotter->MoveTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1605  aPlotter->FinishTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1606  }
1607 }
1608 
1609 
1610 void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
1611  int TextInside, bool DrawPinNum,
1612  bool DrawPinName, int aWidth )
1613 {
1614  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
1615  DrawPinName = false;
1616 
1617  /* Create the pin num string */
1618  wxString StringPinNum;
1619  PinStringNum( StringPinNum );
1620 
1621  if( StringPinNum.IsEmpty() )
1622  DrawPinNum = false;
1623 
1624  if( !DrawPinNum && !DrawPinName )
1625  return;
1626 
1627  int x, y;
1628  wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
1629  wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
1630 
1631  int nameLineWidth = GetPenSize();
1632  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1633  int numLineWidth = GetPenSize();
1634  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1635 
1636  int name_offset = PIN_TEXT_MARGIN +
1637  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1638  int num_offset = PIN_TEXT_MARGIN +
1639  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1640 
1641  /* Get the num and name colors */
1642  COLOR4D NameColor = GetLayerColor( LAYER_PINNAM );
1643  COLOR4D NumColor = GetLayerColor( LAYER_PINNUM );
1644 
1645  int x1 = pin_pos.x;
1646  int y1 = pin_pos.y;
1647 
1648  switch( orient )
1649  {
1650  case PIN_UP:
1651  y1 -= m_length;
1652  break;
1653 
1654  case PIN_DOWN:
1655  y1 += m_length;
1656  break;
1657 
1658  case PIN_LEFT:
1659  x1 -= m_length;
1660  break;
1661 
1662  case PIN_RIGHT:
1663  x1 += m_length;
1664  break;
1665  }
1666 
1667  /* Draw the text inside, but the pin numbers outside. */
1668  if( TextInside )
1669  {
1670  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) ) /* Its an horizontal line. */
1671  {
1672  if( DrawPinName )
1673  {
1674  if( orient == PIN_RIGHT )
1675  {
1676  x = x1 + TextInside;
1677  plotter->Text( wxPoint( x, y1 ), NameColor,
1678  m_name,
1680  PinNameSize,
1683  aWidth, false, false );
1684  }
1685  else // orient == PIN_LEFT
1686  {
1687  x = x1 - TextInside;
1688 
1689  if( DrawPinName )
1690  plotter->Text( wxPoint( x, y1 ),
1691  NameColor, m_name, TEXT_ANGLE_HORIZ,
1692  PinNameSize,
1695  aWidth, false, false );
1696  }
1697  }
1698  if( DrawPinNum )
1699  {
1700  plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
1701  y1 - num_offset ),
1702  NumColor, StringPinNum,
1703  TEXT_ANGLE_HORIZ, PinNumSize,
1706  aWidth, false, false );
1707  }
1708  }
1709  else /* Its a vertical line. */
1710  {
1711  if( orient == PIN_DOWN )
1712  {
1713  y = y1 + TextInside;
1714 
1715  if( DrawPinName )
1716  plotter->Text( wxPoint( x1, y ), NameColor,
1717  m_name,
1718  TEXT_ANGLE_VERT, PinNameSize,
1721  aWidth, false, false );
1722 
1723  if( DrawPinNum )
1724  {
1725  plotter->Text( wxPoint( x1 - num_offset,
1726  (y1 + pin_pos.y) / 2 ),
1727  NumColor, StringPinNum,
1728  TEXT_ANGLE_VERT, PinNumSize,
1731  aWidth, false, false );
1732  }
1733  }
1734  else /* PIN_UP */
1735  {
1736  y = y1 - TextInside;
1737 
1738  if( DrawPinName )
1739  plotter->Text( wxPoint( x1, y ), NameColor,
1740  m_name,
1741  TEXT_ANGLE_VERT, PinNameSize,
1744  aWidth, false, false );
1745 
1746  if( DrawPinNum )
1747  {
1748  plotter->Text( wxPoint( x1 - num_offset,
1749  (y1 + pin_pos.y) / 2 ),
1750  NumColor, StringPinNum,
1751  TEXT_ANGLE_VERT, PinNumSize,
1754  aWidth, false, false );
1755  }
1756  }
1757  }
1758  }
1759  else /* Draw num & text pin outside */
1760  {
1761  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1762  {
1763  /* Its an horizontal line. */
1764  if( DrawPinName )
1765  {
1766  x = (x1 + pin_pos.x) / 2;
1767  plotter->Text( wxPoint( x, y1 - name_offset ),
1768  NameColor, m_name,
1769  TEXT_ANGLE_HORIZ, PinNameSize,
1772  aWidth, false, false );
1773  }
1774 
1775  if( DrawPinNum )
1776  {
1777  x = ( x1 + pin_pos.x ) / 2;
1778  plotter->Text( wxPoint( x, y1 + num_offset ),
1779  NumColor, StringPinNum,
1780  TEXT_ANGLE_HORIZ, PinNumSize,
1783  aWidth, false, false );
1784  }
1785  }
1786  else /* Its a vertical line. */
1787  {
1788  if( DrawPinName )
1789  {
1790  y = ( y1 + pin_pos.y ) / 2;
1791  plotter->Text( wxPoint( x1 - name_offset, y ),
1792  NameColor, m_name,
1793  TEXT_ANGLE_VERT, PinNameSize,
1796  aWidth, false, false );
1797  }
1798 
1799  if( DrawPinNum )
1800  {
1801  plotter->Text( wxPoint( x1 + num_offset,
1802  ( y1 + pin_pos.y ) / 2 ),
1803  NumColor, StringPinNum,
1804  TEXT_ANGLE_VERT, PinNumSize,
1807  aWidth, false, false );
1808  }
1809  }
1810  }
1811 }
1812 
1813 
1815 {
1816  wxPoint pos = m_position;
1817 
1818  switch( m_orientation )
1819  {
1820  case PIN_UP:
1821  pos.y += m_length;
1822  break;
1823 
1824  case PIN_DOWN:
1825  pos.y -= m_length;
1826  break;
1827 
1828  case PIN_LEFT:
1829  pos.x -= m_length;
1830  break;
1831 
1832  case PIN_RIGHT:
1833  pos.x += m_length;
1834  break;
1835  }
1836 
1837  return pos;
1838 }
1839 
1840 
1841 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
1842 {
1843  int orient;
1844  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
1845 
1846  switch( m_orientation )
1847  {
1848  case PIN_UP:
1849  end.y = 1;
1850  break;
1851 
1852  case PIN_DOWN:
1853  end.y = -1;
1854  break;
1855 
1856  case PIN_LEFT:
1857  end.x = -1;
1858  break;
1859 
1860  case PIN_RIGHT:
1861  end.x = 1;
1862  break;
1863  }
1864 
1865  // = pos of end point, according to the component orientation
1866  end = aTransform.TransformCoordinate( end );
1867  orient = PIN_UP;
1868 
1869  if( end.x == 0 )
1870  {
1871  if( end.y > 0 )
1872  orient = PIN_DOWN;
1873  }
1874  else
1875  {
1876  orient = PIN_RIGHT;
1877 
1878  if( end.x < 0 )
1879  orient = PIN_LEFT;
1880  }
1881 
1882  return orient;
1883 }
1884 
1885 
1886 void LIB_PIN::PinStringNum( wxString& aStringBuffer ) const
1887 {
1888  aStringBuffer = PinStringNum( m_number );
1889 }
1890 
1891 
1892 wxString LIB_PIN::PinStringNum( long aPinNum )
1893 {
1894  char ascii_buf[5];
1895 
1896  memcpy( ascii_buf, &aPinNum, 4 );
1897  ascii_buf[4] = 0;
1898 
1899  wxString buffer = FROM_UTF8( ascii_buf );
1900 
1901  return buffer;
1902 }
1903 
1904 
1905 void LIB_PIN::SetPinNumFromString( wxString& buffer )
1906 {
1907  char ascii_buf[4];
1908  unsigned ii, len = buffer.Len();
1909 
1910  ascii_buf[0] = ascii_buf[1] = ascii_buf[2] = ascii_buf[3] = 0;
1911 
1912  if( len > 4 )
1913  len = 4;
1914 
1915  for( ii = 0; ii < len; ii++ )
1916  {
1917  ascii_buf[ii] = buffer.GetChar( ii );
1918  ascii_buf[ii] &= 0xFF;
1919  }
1920 
1921  strncpy( (char*) &m_number, ascii_buf, 4 );
1922 }
1923 
1924 
1926 {
1927  return new LIB_PIN( *this );
1928 }
1929 
1930 
1931 int LIB_PIN::compare( const LIB_ITEM& other ) const
1932 {
1933  wxASSERT( other.Type() == LIB_PIN_T );
1934 
1935  const LIB_PIN* tmp = (LIB_PIN*) &other;
1936 
1937  if( m_number != tmp->m_number )
1938  return m_number - tmp->m_number;
1939 
1940  int result = m_name.CmpNoCase( tmp->m_name );
1941 
1942  if( result != 0 )
1943  return result;
1944 
1945  if( m_position.x != tmp->m_position.x )
1946  return m_position.x - tmp->m_position.x;
1947 
1948  if( m_position.y != tmp->m_position.y )
1949  return m_position.y - tmp->m_position.y;
1950 
1951  return 0;
1952 }
1953 
1954 
1955 void LIB_PIN::SetOffset( const wxPoint& aOffset )
1956 {
1957  m_position += aOffset;
1958 }
1959 
1960 
1961 bool LIB_PIN::Inside( EDA_RECT& rect ) const
1962 {
1963  wxPoint end = PinEndPoint();
1964 
1965  return rect.Contains( m_position.x, -m_position.y ) || rect.Contains( end.x, -end.y );
1966 }
1967 
1968 
1969 void LIB_PIN::Move( const wxPoint& newPosition )
1970 {
1971  if( m_position != newPosition )
1972  {
1973  m_position = newPosition;
1974  SetModified();
1975  }
1976 }
1977 
1978 
1979 void LIB_PIN::MirrorHorizontal( const wxPoint& center )
1980 {
1981  m_position.x -= center.x;
1982  m_position.x *= -1;
1983  m_position.x += center.x;
1984 
1985  if( m_orientation == PIN_RIGHT )
1987  else if( m_orientation == PIN_LEFT )
1989 }
1990 
1991 void LIB_PIN::MirrorVertical( const wxPoint& center )
1992 {
1993  m_position.y -= center.y;
1994  m_position.y *= -1;
1995  m_position.y += center.y;
1996 
1997  if( m_orientation == PIN_UP )
1999  else if( m_orientation == PIN_DOWN )
2001 }
2002 
2003 void LIB_PIN::Rotate( const wxPoint& center, bool aRotateCCW )
2004 {
2005  int rot_angle = aRotateCCW ? -900 : 900;
2006 
2007  RotatePoint( &m_position, center, rot_angle );
2008 
2009  if( aRotateCCW )
2010  {
2011  switch( m_orientation )
2012  {
2013  case PIN_RIGHT:
2015  break;
2016 
2017  case PIN_UP:
2019  break;
2020  case PIN_LEFT:
2022  break;
2023 
2024  case PIN_DOWN:
2026  break;
2027  }
2028  }
2029  else
2030  {
2031  switch( m_orientation )
2032  {
2033  case PIN_RIGHT:
2035  break;
2036 
2037  case PIN_UP:
2039  break;
2040  case PIN_LEFT:
2042  break;
2043 
2044  case PIN_DOWN:
2046  break;
2047  }
2048  }
2049 }
2050 
2051 
2052 void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
2053  const TRANSFORM& aTransform )
2054 {
2055  if( ! IsVisible() )
2056  return;
2057 
2058  int orient = PinDrawOrient( aTransform );
2059 
2060  wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
2061 
2062  PlotSymbol( plotter, pos, orient );
2063  PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
2064  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),
2065  GetPenSize() );
2066 }
2067 
2068 
2069 void LIB_PIN::SetWidth( int aWidth )
2070 {
2071  if( m_width != aWidth )
2072  {
2073  m_width = aWidth;
2074  SetModified();
2075  }
2076 }
2077 
2078 
2080 {
2081  wxString text;
2082 
2083  LIB_ITEM::GetMsgPanelInfo( aList );
2084 
2085  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name, DARKCYAN ) );
2086 
2087  if( m_number == 0 )
2088  text = wxT( "?" );
2089  else
2090  PinStringNum( text );
2091 
2092  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
2093 
2094  aList.push_back( MSG_PANEL_ITEM( _( "Type" ),
2095  GetText( m_type ),
2096  RED ) );
2097 
2098  text = GetText( m_shape );
2099 
2100  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
2101 
2102  if( IsVisible() )
2103  text = _( "Yes" );
2104  else
2105  text = _( "No" );
2106 
2107  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text, DARKGREEN ) );
2108 
2109  // Display pin length
2110  text = StringFromValue( g_UserUnit, m_length, true );
2111  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) );
2112 
2114  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) );
2115 }
2116 
2118 {
2119  getMsgPanelInfoBase( aList );
2120 
2121  wxString text;
2122  wxPoint pinpos = GetPosition();
2123  pinpos.y = -pinpos.y; // Display coord are top to bottom
2124  // lib items coord are bottom to top
2125 
2126  text = StringFromValue( g_UserUnit, pinpos.x, true );
2127  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
2128 
2129  text = StringFromValue( g_UserUnit, pinpos.y, true );
2130  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
2131 }
2132 
2133 void LIB_PIN::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList,
2134  SCH_COMPONENT* aComponent )
2135 {
2136  getMsgPanelInfoBase( aList );
2137 
2138  if( !aComponent )
2139  return;
2140 
2141  wxString text;
2142  wxPoint pinpos = aComponent->GetTransform().TransformCoordinate( GetPosition() )
2143  + aComponent->GetPosition();
2144 
2145  text = StringFromValue( g_UserUnit, pinpos.x, true );
2146  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
2147 
2148  text = StringFromValue( g_UserUnit, pinpos.y, true );
2149  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
2150 
2151  aList.push_back( MSG_PANEL_ITEM( aComponent->GetField( REFERENCE )->GetShownText(),
2152  aComponent->GetField( VALUE )->GetShownText(),
2153  DARKCYAN ) );
2154 }
2155 
2156 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
2157 {
2158  LIB_PART* entry = (LIB_PART* ) m_Parent;
2159  EDA_RECT bbox;
2160  wxPoint begin;
2161  wxPoint end;
2162  int nameTextOffset = 0;
2163  bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" ));
2164  bool showNum = m_number != 0;
2165  int minsizeV = TARGET_PIN_RADIUS;
2166 
2167  if( !aIncludeInvisibles && !IsVisible() )
2168  showName = false;
2169 
2170  if( entry )
2171  {
2172  if( entry->ShowPinNames() )
2173  nameTextOffset = entry->GetPinNameOffset();
2174  else
2175  showName = false;
2176 
2177  showNum = entry->ShowPinNumbers();
2178  }
2179 
2180  // First, calculate boundary box corners position
2181  int numberTextLength = showNum ? m_numTextSize * GetNumberString().Len() : 0;
2182 
2183  // Actual text height is bigger than text size
2184  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
2185 
2187  minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
2188 
2189  // calculate top left corner position
2190  // for the default pin orientation (PIN_RIGHT)
2191  begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
2192  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
2193 
2194  // calculate bottom right corner position and adjust top left corner position
2195  int nameTextLength = 0;
2196  int nameTextHeight = 0;
2197 
2198  if( showName )
2199  {
2200  int length = m_name.Len();
2201 
2202  // Don't count the line over text symbol.
2203  if( m_name.Left( 1 ) == wxT( "~" ) )
2204  length -= 1;
2205 
2206  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
2207 
2208  // Actual text height are bigger than text size
2209  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
2210  }
2211 
2212  if( nameTextOffset ) // for values > 0, pin name is inside the body
2213  {
2214  end.x = m_length + nameTextLength;
2215  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
2216  }
2217  else // if value == 0:
2218  // pin name is outside the body, and above the pin line
2219  // pin num is below the pin line
2220  {
2221  end.x = std::max(m_length, nameTextLength);
2222  end.y = -begin.y;
2223  begin.y = std::max( minsizeV, nameTextHeight );
2224  }
2225 
2226  // Now, calculate boundary box corners position for the actual pin orientation
2227  int orient = PinDrawOrient( DefaultTransform );
2228 
2229  /* Calculate the pin position */
2230  switch( orient )
2231  {
2232  case PIN_UP:
2233  // Pin is rotated and texts positions are mirrored
2234  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
2235  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
2236  break;
2237 
2238  case PIN_DOWN:
2239  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
2240  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
2241  begin.x = -begin.x;
2242  end.x = -end.x;
2243  break;
2244 
2245  case PIN_LEFT:
2246  begin.x = -begin.x;
2247  end.x = -end.x;
2248  break;
2249 
2250  case PIN_RIGHT:
2251  break;
2252  }
2253 
2254  begin += m_position;
2255  end += m_position;
2256 
2257  bbox.SetOrigin( begin );
2258  bbox.SetEnd( end );
2259  bbox.Normalize();
2260  bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
2261 
2262  // Draw Y axis is reversed in schematic:
2263  bbox.RevertYAxis();
2264 
2265  return bbox;
2266 }
2267 
2268 
2269 wxArrayString LIB_PIN::GetOrientationNames( void )
2270 {
2271  wxArrayString tmp;
2272 
2273  for( unsigned ii = 0; ii < PIN_ORIENTATION_CNT; ii++ )
2274  tmp.Add( getPinOrientationName( ii ) );
2275 
2276  return tmp;
2277 }
2278 
2279 
2281 {
2282  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
2283  return pin_orientation_codes[ index ];
2284 
2285  return PIN_RIGHT;
2286 }
2287 
2288 
2290 {
2291  size_t i;
2292 
2293  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
2294  {
2295  if( pin_orientation_codes[i] == code )
2296  return (int) i;
2297  }
2298 
2299  return wxNOT_FOUND;
2300 }
2301 
2302 
2304 {
2305  int orient = PIN_RIGHT;
2306 
2307  switch( GetOrientation() )
2308  {
2309  case PIN_UP:
2310  orient = PIN_LEFT;
2311  break;
2312 
2313  case PIN_DOWN:
2314  orient = PIN_RIGHT;
2315  break;
2316 
2317  case PIN_LEFT:
2318  orient = PIN_DOWN;
2319  break;
2320 
2321  case PIN_RIGHT:
2322  orient = PIN_UP;
2323  break;
2324  }
2325 
2326  // Set the new orientation
2327  SetOrientation( orient );
2328 }
2329 
2330 
2332 {
2333  return iconsPinsOrientations;
2334 }
2335 
2336 
2338 {
2339  return GetBitmap( m_type );
2340 }
2341 
2342 
2344 {
2345  wxString tmp;
2346  wxString style;
2347 
2348  style = GetText( m_shape );
2349 
2350  tmp.Printf( _( "Pin %s, %s, %s" ),
2353  GetChars( style )
2354  );
2355  return tmp;
2356 }
2357 
2358 
2359 bool LIB_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
2360 {
2361  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
2362 
2363  // Note: this will have to be modified if we add find and replace capability to the
2364  // compoment library editor. Otherwise, you wont be able to replace pin text.
2365  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS )
2366  || ( aSearchData.GetFlags() & FR_SEARCH_REPLACE ) )
2367  return false;
2368 
2369  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
2370 
2371  if( EDA_ITEM::Matches( GetName(), aSearchData )
2372  || EDA_ITEM::Matches( GetNumberString(), aSearchData ) )
2373  {
2374  if( aFindLocation )
2375  *aFindLocation = GetBoundingBox().Centre();
2376 
2377  return true;
2378  }
2379 
2380  return false;
2381 }
2382 
2383 
2384 #if defined(DEBUG)
2385 
2386 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
2387 {
2388  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2389  << " num=\"" << GetNumberString().mb_str()
2390  << '"' << "/>\n";
2391 
2392 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2393 }
2394 
2395 #endif
Definition: colors.h:57
void FinishTo(const wxPoint &pos)
Definition: plot_common.h:241
void SetNumberTextSize(int aSize)
Set the size of the pin number text.
Definition: lib_pin.cpp:231
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:110
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:109
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:2359
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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:1931
#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()
const wxString traceFindItem
Flag to enable find item tracing using the WXTRACE environment variable.
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:81
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:1925
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:168
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:111
wxString GetName() const
Definition: lib_pin.h:192
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:1397
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:139
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:72
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.
void SetOrientation(int aOrientation)
Set orientation on the pin.
Definition: lib_pin.cpp:256
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:80
bool IsNew() const
Definition: base_struct.h:216
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:2269
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:2079
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:2337
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:282
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:400
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:280
bool IsSelected() const
Definition: base_struct.h:221
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:289
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:2069
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1955
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
void SetLength(int aLength)
Set the pin length.
Definition: lib_pin.cpp:344
wxString m_name
Definition: lib_pin.h:76
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:2331
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:2117
Definition: lib_pin.h:54
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:492
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:1610
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:53
int GetNameTextSize() const
Definition: lib_pin.h:213
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:166
int GetOrientation() const
Definition: lib_pin.h:236
int m_length
Length of the pin.
Definition: lib_pin.h:70
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:2289
#define TEXT_ANGLE_VERT
Definition: common.h:92
COLOR4D GetInvisibleItemColor()
Field Reference of part, i.e. "IC21".
int GetNumberTextSize() const
Definition: lib_pin.h:234
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
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:227
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_pin.cpp:1991
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:905
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:428
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.cpp:214
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:899
bool Load(LINE_READER &aLineReader, wxString &aErrorMsg) override
Definition: lib_pin.cpp:686
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:71
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:109
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
void SetType(ELECTRICAL_PINTYPE aType)
Set the electrical type of the pin.
Definition: lib_pin.cpp:311
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1459
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
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:45
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:1961
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:518
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:459
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:2303
Definition: colors.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
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:372
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:1179
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:144
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin edition.
Definition: lib_pin.cpp:371
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:471
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:75
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:69
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:70
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:398
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:57
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:2052
wxPoint PinEndPoint() const
Function PinEndPoint.
Definition: lib_pin.cpp:1814
void SetName(const wxString &aName)
Set the pin name.
Definition: lib_pin.cpp:160
static int GetPinNameDefaultSize()
Definition: libeditframe.h:164
void SetNameTextSize(int aSize)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:189
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
void PinStringNum(wxString &aStringBuffer) const
Fill a string buffer with pin number.
Definition: lib_pin.cpp:1886
#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:2343
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:175
Perform a search for a item that has replaceable text.
Class EDA_RECT handles the component boundary box.
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:188
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:1969
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:42
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:74
void SetPinNumFromString(wxString &aBuffer)
Function SetPinNumFromString fill the pin number buffer with aBuffer.
Definition: lib_pin.cpp:1905
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:254
This file is part of the common libary.
COLOR4D GetItemSelectedColor()
bool IsType(FRAME_T aType) const
Definition: wxstruct.h:216
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
Message panel definition file.
int m_width
Line width of the pin.
Definition: lib_pin.h:73
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:980
#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:542
long m_number
Pin number defined as 4 ASCII characters like "12", "anod", "G6", or "12".
Definition: lib_pin.h:77
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:1841
#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:1979
wxString GetNumberString() const
Definition: lib_pin.h:175
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:2280
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39