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@gmail.com>
6  * Copyright (C) 1992-2017 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 <wx/tokenzr.h>
31 
32 #include <fctsys.h>
33 #include <pgm_base.h>
34 #include <gr_basic.h>
35 #include <macros.h>
36 #include <trigo.h>
37 #include <sch_draw_panel.h>
38 #include <draw_graphic_text.h>
39 #include <plotter.h>
40 #include <sch_edit_frame.h>
41 #include <base_units.h>
42 #include <msgpanel.h>
43 
44 #include <general.h>
45 #include <lib_edit_frame.h>
46 #include <class_libentry.h>
47 #include <lib_pin.h>
48 #include <transform.h>
49 #include <sch_component.h>
50 #include <trace_helpers.h>
51 
52 
53 static const int pin_orientation_codes[] =
54 {
55  PIN_RIGHT,
56  PIN_LEFT,
57  PIN_UP,
58  PIN_DOWN
59 };
60 #define PIN_ORIENTATION_CNT arrayDim( pin_orientation_codes )
61 
62 // small margin in internal units between the pin text and the pin line
63 #define PIN_TEXT_MARGIN 4
64 
65 // bitmaps to show pins orientations in dialog editor
66 // must have same order than pin_orientation_names
67 static const BITMAP_DEF iconsPinsOrientations[] =
68 {
69  pinorient_right_xpm,
70  pinorient_left_xpm,
71  pinorient_up_xpm,
72  pinorient_down_xpm,
73 };
74 
75 
77 {
78  if( aType < 0 || aType >= (int) PINTYPE_COUNT )
79  return wxT( "???" );
80 
81  // These strings are the canonical name of the electrictal type
82  // Not translated, no space in name, only ASCII chars.
83  // to use when the string name must be known and well defined
84  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
85  static const wxChar* msgPinElectricType[] =
86  {
87  wxT( "input" ),
88  wxT( "output" ),
89  wxT( "BiDi" ),
90  wxT( "3state" ),
91  wxT( "passive" ),
92  wxT( "unspc" ),
93  wxT( "power_in" ),
94  wxT( "power_out" ),
95  wxT( "openCol" ),
96  wxT( "openEm" ),
97  wxT( "NotConnected" )
98  };
99 
100  return msgPinElectricType[ aType ];
101 }
102 
103 
104 // Helper functions to get the pin orientation name from pin_orientation_codes
105 // Note: the strings are *not* static because they are translated and must be built
106 // on the fly, to be properly translated
107 
108 static const wxString getPinOrientationName( unsigned aPinOrientationCode )
109 {
110  /* Note: The following name lists are sentence capitalized per the GNOME UI
111  * standards for list controls. Please do not change the capitalization
112  * of these strings unless the GNOME UI standards are changed.
113  */
114  const wxString pin_orientation_names[] =
115  {
116  _( "Right" ),
117  _( "Left" ),
118  _( "Up" ),
119  _( "Down" ),
120  wxT( "???" )
121  };
122 
123  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
124  aPinOrientationCode = PIN_ORIENTATION_CNT;
125 
126  return pin_orientation_names[ aPinOrientationCode ];
127 }
128 
130 // i.e. the clock symbols (falling clock is actually external but is of
131 // the same kind)
132 
133 static int InternalPinDecoSize( const LIB_PIN &aPin )
134 {
135 
136  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
137 }
138 
140 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
141 // marker
142 static int ExternalPinDecoSize( const LIB_PIN &aPin )
143 {
144  return aPin.GetNumberTextSize() / 2;
145 }
146 
148  LIB_ITEM( LIB_PIN_T, aParent ),
149  m_shape( PINSHAPE_LINE )
150 {
152  m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right
153  m_type = PIN_UNSPECIFIED; // electrical type of pin
154  m_attributes = 0; // bit 0 != 0: pin invisible
157  m_width = 0;
158 }
159 
160 
161 void LIB_PIN::SetName( const wxString& aName, bool aTestOtherPins )
162 {
163  wxString tmp = ( aName.IsEmpty() ) ? wxT( "~" ) : aName;
164 
165  // pin name string does not support spaces
166  tmp.Replace( wxT( " " ), wxT( "_" ) );
167 
168  if( m_name != tmp )
169  {
170  m_name = tmp;
171  SetModified();
172  }
173 
174  if( !aTestOtherPins )
175  return;
176 
177  if( GetParent() == NULL )
178  return;
179 
180  LIB_PINS pinList;
181  GetParent()->GetPins( pinList );
182 
183  for( size_t i = 0; i < pinList.size(); i++ )
184  {
185  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_name == m_name )
186  continue;
187 
188  pinList[i]->m_name = m_name;
189  SetModified();
190  }
191 }
192 
193 
194 void LIB_PIN::SetNameTextSize( int size, bool aTestOtherPins )
195 {
196  if( size != m_nameTextSize )
197  {
198  m_nameTextSize = size;
199  SetModified();
200  }
201 
202  if( !aTestOtherPins )
203  return;
204 
205  if( GetParent() == NULL )
206  return;
207 
208  LIB_PINS pinList;
209  GetParent()->GetPins( pinList );
210 
211  for( size_t i = 0; i < pinList.size(); i++ )
212  {
213  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_nameTextSize == size )
214  continue;
215 
216  pinList[i]->m_nameTextSize = size;
217  SetModified();
218  }
219 }
220 
221 
222 void LIB_PIN::SetNumber( const wxString& aNumber )
223 {
224  // Unlike SetName, others pin numbers marked by EnableEditMode() are
225  // not modified because each pin has its own number, so set number
226  // only for this.
227 
228  wxString tmp = ( aNumber.IsEmpty() ) ? wxT( "~" ) : aNumber;
229 
230  // pin number string does not support spaces
231  tmp.Replace( wxT( " " ), wxT( "_" ) );
232 
233  if( m_number != tmp )
234  {
235  m_number = tmp;
236  SetModified();
237  }
238 }
239 
240 
241 void LIB_PIN::SetNumberTextSize( int size, bool aTestOtherPins )
242 {
243  if( size != m_numTextSize )
244  {
245  m_numTextSize = size;
246  SetModified();
247  }
248 
249  if( !aTestOtherPins )
250  return;
251 
252  if( GetParent() == NULL )
253  return;
254 
255  LIB_PINS pinList;
256  GetParent()->GetPins( pinList );
257 
258  for( size_t i = 0; i < pinList.size(); i++ )
259  {
260  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_numTextSize == size )
261  continue;
262 
263  pinList[i]->m_numTextSize = size;
264  SetModified();
265  }
266 }
267 
268 
269 void LIB_PIN::SetOrientation( int orientation, bool aTestOtherPins )
270 {
271  if( m_orientation != orientation )
272  {
273  m_orientation = orientation;
274  SetModified();
275  }
276 
277  if( !aTestOtherPins )
278  return;
279 
280  if( GetParent() == NULL )
281  return;
282 
283  LIB_PINS pinList;
284  GetParent()->GetPins( pinList );
285 
286  for( size_t i = 0; i < pinList.size(); i++ )
287  {
288  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 ||
289  pinList[i]->m_orientation == orientation )
290  continue;
291 
292  pinList[i]->m_orientation = orientation;
293  SetModified();
294  }
295 }
296 
297 
299 {
300  assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) );
301 
302  if( m_shape != aShape )
303  {
304  m_shape = aShape;
305  SetModified();
306  }
307 
308  if( GetParent() == NULL )
309  return;
310 
311  LIB_PINS pinList;
312  GetParent()->GetPins( pinList );
313 
314  for( size_t i = 0; i < pinList.size(); i++ )
315  {
316  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
317  || pinList[i]->m_Convert != m_Convert
318  || pinList[i]->m_shape == aShape )
319  continue;
320 
321  pinList[i]->m_shape = aShape;
322  SetModified();
323  }
324 }
325 
326 
327 void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins )
328 {
329  assert( aType >= 0 && aType < (int)PINTYPE_COUNT );
330 
331  if( aType < PIN_INPUT )
332  aType = PIN_INPUT;
333 
334  if( aType >= (int)PINTYPE_COUNT )
335  aType = PIN_NC;
336 
337  if( m_type != aType )
338  {
339  m_type = aType;
340  SetModified();
341  }
342 
343  if( !aTestOtherPins )
344  return;
345 
346  if( GetParent() == NULL )
347  return;
348 
349  LIB_PINS pinList;
350  GetParent()->GetPins( pinList );
351 
352  for( size_t i = 0; i < pinList.size(); i++ )
353  {
354  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_type == aType )
355  continue;
356 
357  pinList[i]->m_type = aType;
358  SetModified();
359  }
360 }
361 
362 
363 void LIB_PIN::SetLength( int length, bool aTestOtherPins )
364 {
365  if( m_length != length )
366  {
367  m_length = length;
368  SetModified();
369  }
370 
371  if( !aTestOtherPins )
372  return;
373 
374  if( GetParent() == NULL )
375  return;
376 
377  LIB_PINS pinList;
378  GetParent()->GetPins( pinList );
379 
380  for( size_t i = 0; i < pinList.size(); i++ )
381  {
382  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
383  || pinList[i]->m_Convert != m_Convert
384  || pinList[i]->m_length == length )
385  continue;
386 
387  pinList[i]->m_length = length;
388  SetModified();
389  }
390 }
391 
392 
393 void LIB_PIN::SetPinPosition( wxPoint aPosition )
394 {
395  if( m_position != aPosition )
396  {
397  m_position = aPosition;
398  SetModified();
399  }
400 
401  if( GetParent() == NULL )
402  return;
403 
404  LIB_PINS pinList;
405  GetParent()->GetPins( pinList );
406 
407  for( size_t i = 0; i < pinList.size(); i++ )
408  {
409  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
410  || pinList[i]->m_Convert != m_Convert
411  || pinList[i]->m_position == aPosition )
412  continue;
413 
414  pinList[i]->m_position = aPosition;
415  SetModified();
416  }
417 }
418 
419 
420 void LIB_PIN::SetPartNumber( int part )
421 {
422  if( m_Unit == part )
423  return;
424 
425  m_Unit = part;
426  SetModified();
427 
428  if( m_Unit == 0 )
429  {
430  LIB_PIN* pin;
431  LIB_PIN* tmp = GetParent()->GetNextPin();
432 
433  while( tmp != NULL )
434  {
435  pin = tmp;
436  tmp = GetParent()->GetNextPin( pin );
437 
438  if( pin->m_Flags == 0 || pin == this
439  || ( m_Convert && ( m_Convert != pin->m_Convert ) )
440  || ( m_position != pin->m_position )
441  || ( pin->m_orientation != m_orientation ) )
442  continue;
443 
444  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
445  }
446  }
447 }
448 
449 
450 void LIB_PIN::SetConversion( int style )
451 {
452  if( m_Convert == style )
453  return;
454 
455  m_Convert = style;
456  SetFlags( IS_CHANGED );
457 
458  if( style == 0 )
459  {
460  LIB_PIN* pin;
461  LIB_PIN* tmp = GetParent()->GetNextPin();
462 
463  while( tmp != NULL )
464  {
465  pin = tmp;
466  tmp = GetParent()->GetNextPin( pin );
467 
468  if( ( pin->m_Flags & IS_LINKED ) == 0
469  || ( pin == this )
470  || ( m_Unit && ( m_Unit != pin->m_Unit ) )
471  || ( m_position != pin->m_position )
472  || ( pin->m_orientation != m_orientation ) )
473  continue;
474 
475  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
476  }
477  }
478 }
479 
480 
481 void LIB_PIN::SetVisible( bool visible )
482 {
483  if( visible == IsVisible() )
484  return;
485 
486  if( visible )
488  else
490 
491  SetModified();
492 
493  if( GetParent() == NULL )
494  return;
495 
496  LIB_PINS pinList;
497  GetParent()->GetPins( pinList );
498 
499  for( size_t i = 0; i < pinList.size(); i++ )
500  {
501  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->IsVisible() == visible )
502  continue;
503 
504  if( visible )
505  pinList[i]->m_attributes &= ~PIN_INVISIBLE;
506  else
507  pinList[i]->m_attributes |= PIN_INVISIBLE;
508 
509  SetModified();
510  }
511 }
512 
513 
514 void LIB_PIN::EnableEditMode( bool aEnable, bool aEditPinByPin )
515 {
516  LIB_PINS pinList;
517 
518  if( GetParent() == NULL )
519  return;
520 
521  GetParent()->GetPins( pinList );
522 
523  for( size_t i = 0; i < pinList.size(); i++ )
524  {
525  if( pinList[i] == this )
526  continue;
527 
528  if( ( pinList[i]->m_position == m_position )
529  && ( pinList[i]->m_orientation == m_orientation )
530  && !IsNew() && !aEditPinByPin && aEnable )
531  {
532  pinList[i]->SetFlags( IS_LINKED | IN_EDIT );
533  }
534  else
535  pinList[i]->ClearFlags( IS_LINKED | IN_EDIT );
536  }
537 }
538 
539 
540 bool LIB_PIN::HitTest( const wxPoint& aPosition ) const
541 {
542  return HitTest( aPosition, 0, DefaultTransform );
543 }
544 
545 
546 bool LIB_PIN::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
547 {
548  if( aThreshold < 0 )
549  aThreshold = 0;
550 
551  TRANSFORM transform = DefaultTransform;
552  DefaultTransform = aTransform;
553 
554  EDA_RECT rect = GetBoundingBox();
555  rect.Inflate( aThreshold );
556 
557  //Restore matrix
558  DefaultTransform = transform;
559 
560  return rect.Contains( aPosition );
561 }
562 
563 
565 {
566  if( m_width > 0 )
567  return m_width;
568 
569  if( m_width == 0 )
570  return GetDefaultLineThickness();
571 
572  return 0;
573 }
574 
575 
577  wxDC* aDC,
578  const wxPoint& aOffset,
579  COLOR4D aColor,
580  GR_DRAWMODE aDrawMode,
581  void* aData,
582  const TRANSFORM& aTransform )
583 {
584  // aData is used here as a bitfield of flags.
585  uintptr_t flags = (uintptr_t) aData;
586  bool drawPinText = flags & PIN_DRAW_TEXTS;
587  bool drawPinDangling = flags & PIN_DRAW_DANGLING;
588  bool drawDanglingHidden = flags & PIN_DANGLING_HIDDEN;
589  bool drawElectricalTypeName = flags & PIN_DRAW_ELECTRICAL_TYPE_NAME;
590 
591  LIB_PART* Entry = GetParent();
592 
593  /* Calculate pin orient taking in account the component orientation. */
594  int orient = PinDrawOrient( aTransform );
595 
596  /* Calculate the pin position */
597  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
598 
599  // Invisible pins are only drawn on request.
600  // They are drawn in GetInvisibleItemColor().
601  if( ! IsVisible() )
602  {
603  bool drawHidden = true;
604 
605  if( aPanel && aPanel->GetParent() )
606  {
607  EDA_DRAW_FRAME* frame = aPanel->GetParent();
608 
609  if( frame->IsType( FRAME_SCH ) )
610  drawHidden = static_cast<SCH_EDIT_FRAME*>( frame )->GetShowAllPins();
611  }
612 
613  if( !drawHidden )
614  {
615  if( drawPinDangling && drawDanglingHidden )
616  {
617  // Draw the target
618  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling,
619  /* aOnlyTarget */ true );
620  }
621  return;
622  }
623 
624  aColor = GetInvisibleItemColor();
625  }
626 
627  /* Drawing from the pin and the special symbol combination */
628  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling );
629 
630  if( drawPinText )
631  {
632  DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
633  Entry->ShowPinNumbers(), Entry->ShowPinNames(),
634  aColor, aDrawMode );
635  }
636 
637  if( drawElectricalTypeName )
638  DrawPinElectricalTypeName( aPanel, aDC, pos1, orient, aColor, aDrawMode );
639 
640 
641  /* Set to one (1) to draw bounding box around pin to validate bounding
642  * box calculation. */
643 #if 0
644  EDA_RECT bBox = GetBoundingBox();
645  bBox.RevertYAxis();
646  bBox = aTransform.TransformCoordinate( bBox );
647  bBox.Move( aOffset );
648  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
649 #endif
650 }
651 
652 
654  wxDC* aDC,
655  const wxPoint& aPinPos,
656  int aOrient,
657  GR_DRAWMODE aDrawMode,
658  COLOR4D aColor,
659  bool aDrawDangling,
660  bool aOnlyTarget )
661 {
662  int MapX1, MapY1, x1, y1;
663  int width = GetPenSize();
664  int posX = aPinPos.x, posY = aPinPos.y, len = m_length;
665  EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
666 
668 
669  if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color
670  {
671  if( IsSelected() )
673  }
674  else
675  color = aColor;
676 
677  GRSetDrawMode( aDC, aDrawMode );
678 
679  MapX1 = MapY1 = 0;
680  x1 = posX;
681  y1 = posY;
682 
683  switch( aOrient )
684  {
685  case PIN_UP:
686  y1 = posY - len;
687  MapY1 = 1;
688  break;
689 
690  case PIN_DOWN:
691  y1 = posY + len;
692  MapY1 = -1;
693  break;
694 
695  case PIN_LEFT:
696  x1 = posX - len;
697  MapX1 = 1;
698  break;
699 
700  case PIN_RIGHT:
701  x1 = posX + len;
702  MapX1 = -1;
703  break;
704  }
705 
706  // Draw the pin end target (active end of the pin)
707  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
708  #define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
709 
710  // Draw but do not print the pin end target 1 pixel width
711  if( m_type != PIN_NC && ( screen == NULL || !screen->m_IsPrinting ) )
712  {
713  if( aDrawDangling )
714  GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
715  }
716 
717  if( aOnlyTarget )
718  return;
719 
720 
722  {
723  const int radius = ExternalPinDecoSize( *this );
724  GRCircle( clipbox, aDC, MapX1 * radius + x1,
725  MapY1 * radius + y1,
726  radius, width, color );
727 
728  GRMoveTo( MapX1 * radius * 2 + x1,
729  MapY1 * radius * 2 + y1 );
730  GRLineTo( clipbox, aDC, posX, posY, width, color );
731  }
732  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
733  {
734  const int clock_size = InternalPinDecoSize( *this );
735  if( MapY1 == 0 ) /* MapX1 = +- 1 */
736  {
737  GRMoveTo( x1, y1 + clock_size );
738  GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
739  width, color );
740  GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
741  }
742  else /* MapX1 = 0 */
743  {
744  GRMoveTo( x1 + clock_size, y1 );
745  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
746  width, color );
747  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
748  width, color );
749  }
750  GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
751  GRLineTo( clipbox, aDC, posX, posY, width, color );
752  }
753  else
754  {
755  GRMoveTo( x1, y1 );
756  GRLineTo( clipbox, aDC, posX, posY, width, color );
757  }
758 
760  {
761  const int clock_size = InternalPinDecoSize( *this );
762  if( MapY1 == 0 ) /* MapX1 = +- 1 */
763  {
764  GRMoveTo( x1, y1 + clock_size );
765  GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
766  width, color );
767  GRLineTo( clipbox, aDC, x1, y1 - clock_size,
768  width, color );
769  }
770  else /* MapX1 = 0 */
771  {
772  GRMoveTo( x1 + clock_size, y1 );
773  GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
774  width, color );
775  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
776  width, color );
777  }
778  }
779 
781  {
782  const int symbol_size = ExternalPinDecoSize( *this );
783  if( MapY1 == 0 ) /* MapX1 = +- 1 */
784  {
785  GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
786  GRLineTo( clipbox, aDC,
787  x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
788  width, color );
789  GRLineTo( clipbox, aDC, x1, y1, width, color );
790  }
791  else /* MapX1 = 0 */
792  {
793  GRMoveTo( x1, y1 + MapY1 * symbol_size * 2 );
794  GRLineTo( clipbox, aDC, x1 - symbol_size * 2,
795  y1 + MapY1 * symbol_size * 2, width, color );
796  GRLineTo( clipbox, aDC, x1, y1, width, color );
797  }
798  }
799 
800 
801  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
802  {
803  const int symbol_size = ExternalPinDecoSize( *this );
804  if( MapY1 == 0 ) /* MapX1 = +- 1 */
805  {
806  GRMoveTo( x1, y1 - symbol_size * 2 );
807  GRLineTo( clipbox,
808  aDC,
809  x1 + MapX1 * symbol_size * 2,
810  y1,
811  width,
812  color );
813  }
814  else /* MapX1 = 0 */
815  {
816  GRMoveTo( x1 - symbol_size * 2, y1 );
817  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
818  width, color );
819  }
820  }
821  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
822  {
823  const int symbol_size = ExternalPinDecoSize( *this );
824  GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
825  y1 - (MapY1 - MapX1) * symbol_size );
826  GRLineTo( clipbox, aDC,
827  x1 + (MapX1 + MapY1) * symbol_size,
828  y1 + (MapY1 - MapX1) * symbol_size,
829  width, color );
830  GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
831  y1 - (MapY1 + MapX1) * symbol_size );
832  GRLineTo( clipbox, aDC,
833  x1 + (MapX1 - MapY1) * symbol_size,
834  y1 + (MapY1 + MapX1) * symbol_size,
835  width, color );
836  }
837 
838  if( m_type == PIN_NC ) // Draw a N.C. symbol
839  {
840  GRLine( clipbox, aDC,
841  posX - NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
842  posX + NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
843  width, color );
844  GRLine( clipbox, aDC,
845  posX + NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
846  posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
847  width, color );
848  }
849 }
850 
851 
853  wxDC* DC,
854  wxPoint& pin_pos,
855  int orient,
856  int TextInside,
857  bool DrawPinNum,
858  bool DrawPinName,
859  COLOR4D Color,
860  GR_DRAWMODE DrawMode )
861 {
862  if( !DrawPinName && !DrawPinNum )
863  return;
864 
865  int x, y;
866 
867  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
868  wxSize PinNumSize( m_numTextSize, m_numTextSize );
869 
870  int nameLineWidth = GetPenSize();
871 
872  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
873  int numLineWidth = GetPenSize();
874  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
875 
876  int name_offset = PIN_TEXT_MARGIN +
877  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
878  int num_offset = PIN_TEXT_MARGIN +
879  ( numLineWidth + GetDefaultLineThickness() ) / 2;
880 
881  GRSetDrawMode( DC, DrawMode );
882  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
883 
884  /* Get the num and name colors */
885  if( ( Color == COLOR4D::UNSPECIFIED ) && IsSelected() )
886  Color = GetItemSelectedColor();
887 
888  COLOR4D NameColor = Color == COLOR4D::UNSPECIFIED ?
889  GetLayerColor( LAYER_PINNAM ) : Color;
890  COLOR4D NumColor = Color == COLOR4D::UNSPECIFIED ?
891  GetLayerColor( LAYER_PINNUM ) : Color;
892 
893  int x1 = pin_pos.x;
894  int y1 = pin_pos.y;
895 
896  switch( orient )
897  {
898  case PIN_UP:
899  y1 -= m_length;
900  break;
901 
902  case PIN_DOWN:
903  y1 += m_length;
904  break;
905 
906  case PIN_LEFT:
907  x1 -= m_length;
908  break;
909 
910  case PIN_RIGHT:
911  x1 += m_length;
912  break;
913  }
914 
915  if( m_name.IsEmpty() )
916  DrawPinName = false;
917 
918  if( TextInside ) // Draw the text inside, but the pin numbers outside.
919  {
920  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
921  {
922  // It is an horizontal line
923  if( DrawPinName )
924  {
925  if( orient == PIN_RIGHT )
926  {
927  x = x1 + TextInside;
928  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
929  m_name,
931  PinNameSize,
933  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
934  false, false );
935  }
936  else // Orient == PIN_LEFT
937  {
938  x = x1 - TextInside;
939  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
940  m_name,
942  PinNameSize,
944  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
945  false, false );
946  }
947  }
948 
949  if( DrawPinNum )
950  {
951  DrawGraphicText( clipbox, DC,
952  wxPoint( (x1 + pin_pos.x) / 2,
953  y1 - num_offset ), NumColor,
954  m_number,
955  TEXT_ANGLE_HORIZ, PinNumSize,
957  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
958  false, false );
959  }
960  }
961  else /* Its a vertical line. */
962  {
963  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
964  if( orient == PIN_DOWN )
965  {
966  y = y1 + TextInside;
967 
968  if( DrawPinName )
969  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
970  m_name,
971  TEXT_ANGLE_VERT, PinNameSize,
973  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
974  false, false );
975 
976  if( DrawPinNum )
977  DrawGraphicText( clipbox, DC,
978  wxPoint( x1 - num_offset,
979  (y1 + pin_pos.y) / 2 ), NumColor,
980  m_number,
981  TEXT_ANGLE_VERT, PinNumSize,
983  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
984  false, false );
985  }
986  else /* PIN_UP */
987  {
988  y = y1 - TextInside;
989 
990  if( DrawPinName )
991  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
992  m_name,
993  TEXT_ANGLE_VERT, PinNameSize,
995  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
996  false, false );
997 
998  if( DrawPinNum )
999  DrawGraphicText( clipbox, DC,
1000  wxPoint( x1 - num_offset,
1001  (y1 + pin_pos.y) / 2 ), NumColor,
1002  m_number,
1003  TEXT_ANGLE_VERT, PinNumSize,
1005  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1006  false, false );
1007  }
1008  }
1009  }
1010  else /**** Draw num & text pin outside ****/
1011  {
1012  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1013  {
1014  /* Its an horizontal line. */
1015  if( DrawPinName )
1016  {
1017  x = (x1 + pin_pos.x) / 2;
1018  DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
1019  NameColor, m_name,
1020  TEXT_ANGLE_HORIZ, PinNameSize,
1022  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1023  false, false );
1024  }
1025  if( DrawPinNum )
1026  {
1027  x = (x1 + pin_pos.x) / 2;
1028  DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
1029  NumColor, m_number,
1030  TEXT_ANGLE_HORIZ, PinNumSize,
1032  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1033  false, false );
1034  }
1035  }
1036  else /* Its a vertical line. */
1037  {
1038  if( DrawPinName )
1039  {
1040  y = (y1 + pin_pos.y) / 2;
1041  DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
1042  NameColor, m_name,
1043  TEXT_ANGLE_VERT, PinNameSize,
1045  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1046  false, false );
1047  }
1048 
1049  if( DrawPinNum )
1050  {
1051  DrawGraphicText( clipbox, DC,
1052  wxPoint( x1 + num_offset, (y1 + pin_pos.y)
1053  / 2 ),
1054  NumColor, m_number,
1055  TEXT_ANGLE_VERT, PinNumSize,
1057  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1058  false, false );
1059  }
1060  }
1061  }
1062 }
1063 
1064 
1065 
1067  wxPoint& aPosition, int aOrientation,
1068  COLOR4D aColor, GR_DRAWMODE aDrawMode )
1069 {
1070  wxString etypeName = GetElectricalTypeName();
1071 
1072  // Use a reasonable (small) size to draw the text
1073  int etextSize = (m_nameTextSize*3)/4;
1074 
1075  #define ETXT_MAX_SIZE Millimeter2iu(0.7 )
1076  if( etextSize > ETXT_MAX_SIZE )
1077  etextSize = ETXT_MAX_SIZE;
1078 
1079  // Use a reasonable pen size to draw the text
1080  int pensize = etextSize/6;
1081 
1082  // Get a suitable color
1083  if( ( aColor == COLOR4D::UNSPECIFIED ) && IsSelected() )
1084  aColor = GetItemSelectedColor();
1085  else if( !IsVisible() )
1086  aColor = GetInvisibleItemColor();
1087  else
1088  aColor = GetLayerColor( LAYER_NOTES );
1089 
1090  wxPoint txtpos = aPosition;
1091  int offset = Millimeter2iu( 0.4 );
1093  int orient = TEXT_ANGLE_HORIZ;
1094 
1095  switch( aOrientation )
1096  {
1097  case PIN_UP:
1098  txtpos.y += offset;
1099  orient = TEXT_ANGLE_VERT;
1100  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1101  break;
1102 
1103  case PIN_DOWN:
1104  txtpos.y -= offset;
1105  orient = TEXT_ANGLE_VERT;
1106  break;
1107 
1108  case PIN_LEFT:
1109  txtpos.x += offset;
1110  break;
1111 
1112  case PIN_RIGHT:
1113  txtpos.x -= offset;
1114  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1115  break;
1116  }
1117 
1118  GRSetDrawMode( aDC, aDrawMode );
1119  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
1120 
1121  DrawGraphicText( clipbox, aDC, txtpos, aColor, etypeName,
1122  orient, wxSize( etextSize, etextSize ),
1123  hjustify, GR_TEXT_VJUSTIFY_CENTER, pensize,
1124  false, false );
1125 }
1126 
1127 
1128 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
1129 {
1130  int MapX1, MapY1, x1, y1;
1132 
1133  aPlotter->SetColor( color );
1134  aPlotter->SetCurrentLineWidth( GetPenSize() );
1135 
1136  MapX1 = MapY1 = 0;
1137  x1 = aPosition.x; y1 = aPosition.y;
1138 
1139  switch( aOrientation )
1140  {
1141  case PIN_UP:
1142  y1 = aPosition.y - m_length;
1143  MapY1 = 1;
1144  break;
1145 
1146  case PIN_DOWN:
1147  y1 = aPosition.y + m_length;
1148  MapY1 = -1;
1149  break;
1150 
1151  case PIN_LEFT:
1152  x1 = aPosition.x - m_length;
1153  MapX1 = 1;
1154  break;
1155 
1156  case PIN_RIGHT:
1157  x1 = aPosition.x + m_length;
1158  MapX1 = -1;
1159  break;
1160  }
1161 
1163  {
1164  const int radius = ExternalPinDecoSize( *this );
1165  aPlotter->Circle( wxPoint( MapX1 * radius + x1,
1166  MapY1 * radius + y1 ),
1167  radius * 2, // diameter
1168  NO_FILL, // fill option
1169  GetPenSize() ); // width
1170 
1171  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1,
1172  MapY1 * radius * 2 + y1 ) );
1173  aPlotter->FinishTo( aPosition );
1174  }
1175  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
1176  {
1177  const int clock_size = InternalPinDecoSize( *this );
1178  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1179  {
1180  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1181  aPlotter->LineTo( wxPoint( x1 + MapX1 * clock_size * 2, y1 ) );
1182  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1183  }
1184  else /* MapX1 = 0 */
1185  {
1186  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1187  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * clock_size * 2 ) );
1188  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1189  }
1190 
1191  aPlotter->MoveTo( wxPoint( MapX1 * clock_size * 2 + x1,
1192  MapY1 * clock_size * 2 + y1 ) );
1193  aPlotter->FinishTo( aPosition );
1194  }
1195  else
1196  {
1197  aPlotter->MoveTo( wxPoint( x1, y1 ) );
1198  aPlotter->FinishTo( aPosition );
1199  }
1200 
1203  {
1204  const int clock_size = InternalPinDecoSize( *this );
1205  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1206  {
1207  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1208  aPlotter->LineTo( wxPoint( x1 - MapX1 * clock_size * 2, y1 ) );
1209  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1210  }
1211  else /* MapX1 = 0 */
1212  {
1213  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1214  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * clock_size * 2 ) );
1215  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1216  }
1217  }
1218 
1219  if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1220  {
1221  const int symbol_size = ExternalPinDecoSize( *this );
1222 
1223  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1224  {
1225  aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1226  aPlotter->LineTo( wxPoint( x1 + MapX1 * symbol_size * 2,
1227  y1 - symbol_size * 2 ) );
1228  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1229  }
1230  else /* MapX1 = 0 */
1231  {
1232  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1233  aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
1234  y1 + MapY1 * symbol_size * 2 ) );
1235  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1236  }
1237  }
1238 
1239 
1240  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1241  {
1242  const int symbol_size = ExternalPinDecoSize( *this );
1243 
1244  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1245  {
1246  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
1247  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1248  }
1249  else /* MapX1 = 0 */
1250  {
1251  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
1252  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1253  }
1254  }
1255  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1256  {
1257  const int symbol_size = ExternalPinDecoSize( *this );
1258  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
1259  y1 - (MapY1 - MapX1) * symbol_size ) );
1260  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * symbol_size,
1261  y1 + (MapY1 - MapX1) * symbol_size ) );
1262  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * symbol_size,
1263  y1 - (MapY1 + MapX1) * symbol_size ) );
1264  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * symbol_size,
1265  y1 + (MapY1 + MapX1) * symbol_size ) );
1266  }
1267  if( m_type == PIN_NC ) // Draw a N.C. symbol
1268  {
1269  const int ex1 = aPosition.x;
1270  const int ey1 = aPosition.y;
1271  aPlotter->MoveTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1272  aPlotter->FinishTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1273  aPlotter->MoveTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1274  aPlotter->FinishTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1275  }
1276 }
1277 
1278 
1279 void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
1280  int TextInside, bool DrawPinNum,
1281  bool DrawPinName, int aWidth )
1282 {
1283  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
1284  DrawPinName = false;
1285 
1286  if( m_number.IsEmpty() )
1287  DrawPinNum = false;
1288 
1289  if( !DrawPinNum && !DrawPinName )
1290  return;
1291 
1292  int x, y;
1293  wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
1294  wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
1295 
1296  int nameLineWidth = GetPenSize();
1297  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1298  int numLineWidth = GetPenSize();
1299  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1300 
1301  int name_offset = PIN_TEXT_MARGIN +
1302  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1303  int num_offset = PIN_TEXT_MARGIN +
1304  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1305 
1306  /* Get the num and name colors */
1307  COLOR4D NameColor = GetLayerColor( LAYER_PINNAM );
1308  COLOR4D NumColor = GetLayerColor( LAYER_PINNUM );
1309 
1310  int x1 = pin_pos.x;
1311  int y1 = pin_pos.y;
1312 
1313  switch( orient )
1314  {
1315  case PIN_UP:
1316  y1 -= m_length;
1317  break;
1318 
1319  case PIN_DOWN:
1320  y1 += m_length;
1321  break;
1322 
1323  case PIN_LEFT:
1324  x1 -= m_length;
1325  break;
1326 
1327  case PIN_RIGHT:
1328  x1 += m_length;
1329  break;
1330  }
1331 
1332  /* Draw the text inside, but the pin numbers outside. */
1333  if( TextInside )
1334  {
1335  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) ) /* Its an horizontal line. */
1336  {
1337  if( DrawPinName )
1338  {
1339  if( orient == PIN_RIGHT )
1340  {
1341  x = x1 + TextInside;
1342  plotter->Text( wxPoint( x, y1 ), NameColor,
1343  m_name,
1345  PinNameSize,
1348  aWidth, false, false );
1349  }
1350  else // orient == PIN_LEFT
1351  {
1352  x = x1 - TextInside;
1353 
1354  if( DrawPinName )
1355  plotter->Text( wxPoint( x, y1 ),
1356  NameColor, m_name, TEXT_ANGLE_HORIZ,
1357  PinNameSize,
1360  aWidth, false, false );
1361  }
1362  }
1363  if( DrawPinNum )
1364  {
1365  plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
1366  y1 - num_offset ),
1367  NumColor, m_number,
1368  TEXT_ANGLE_HORIZ, PinNumSize,
1371  aWidth, false, false );
1372  }
1373  }
1374  else /* Its a vertical line. */
1375  {
1376  if( orient == PIN_DOWN )
1377  {
1378  y = y1 + TextInside;
1379 
1380  if( DrawPinName )
1381  plotter->Text( wxPoint( x1, y ), NameColor,
1382  m_name,
1383  TEXT_ANGLE_VERT, PinNameSize,
1386  aWidth, false, false );
1387 
1388  if( DrawPinNum )
1389  {
1390  plotter->Text( wxPoint( x1 - num_offset,
1391  (y1 + pin_pos.y) / 2 ),
1392  NumColor, m_number,
1393  TEXT_ANGLE_VERT, PinNumSize,
1396  aWidth, false, false );
1397  }
1398  }
1399  else /* PIN_UP */
1400  {
1401  y = y1 - TextInside;
1402 
1403  if( DrawPinName )
1404  plotter->Text( wxPoint( x1, y ), NameColor,
1405  m_name,
1406  TEXT_ANGLE_VERT, PinNameSize,
1409  aWidth, false, false );
1410 
1411  if( DrawPinNum )
1412  {
1413  plotter->Text( wxPoint( x1 - num_offset,
1414  (y1 + pin_pos.y) / 2 ),
1415  NumColor, m_number,
1416  TEXT_ANGLE_VERT, PinNumSize,
1419  aWidth, false, false );
1420  }
1421  }
1422  }
1423  }
1424  else /* Draw num & text pin outside */
1425  {
1426  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1427  {
1428  /* Its an horizontal line. */
1429  if( DrawPinName )
1430  {
1431  x = (x1 + pin_pos.x) / 2;
1432  plotter->Text( wxPoint( x, y1 - name_offset ),
1433  NameColor, m_name,
1434  TEXT_ANGLE_HORIZ, PinNameSize,
1437  aWidth, false, false );
1438  }
1439 
1440  if( DrawPinNum )
1441  {
1442  x = ( x1 + pin_pos.x ) / 2;
1443  plotter->Text( wxPoint( x, y1 + num_offset ),
1444  NumColor, m_number,
1445  TEXT_ANGLE_HORIZ, PinNumSize,
1448  aWidth, false, false );
1449  }
1450  }
1451  else /* Its a vertical line. */
1452  {
1453  if( DrawPinName )
1454  {
1455  y = ( y1 + pin_pos.y ) / 2;
1456  plotter->Text( wxPoint( x1 - name_offset, y ),
1457  NameColor, m_name,
1458  TEXT_ANGLE_VERT, PinNameSize,
1461  aWidth, false, false );
1462  }
1463 
1464  if( DrawPinNum )
1465  {
1466  plotter->Text( wxPoint( x1 + num_offset,
1467  ( y1 + pin_pos.y ) / 2 ),
1468  NumColor, m_number,
1469  TEXT_ANGLE_VERT, PinNumSize,
1472  aWidth, false, false );
1473  }
1474  }
1475  }
1476 }
1477 
1478 
1479 wxPoint LIB_PIN::PinEndPoint() const
1480 {
1481  wxPoint pos = m_position;
1482 
1483  switch( m_orientation )
1484  {
1485  case PIN_UP:
1486  pos.y += m_length;
1487  break;
1488 
1489  case PIN_DOWN:
1490  pos.y -= m_length;
1491  break;
1492 
1493  case PIN_LEFT:
1494  pos.x -= m_length;
1495  break;
1496 
1497  case PIN_RIGHT:
1498  pos.x += m_length;
1499  break;
1500  }
1501 
1502  return pos;
1503 }
1504 
1505 
1506 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
1507 {
1508  int orient;
1509  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
1510 
1511  switch( m_orientation )
1512  {
1513  case PIN_UP:
1514  end.y = 1;
1515  break;
1516 
1517  case PIN_DOWN:
1518  end.y = -1;
1519  break;
1520 
1521  case PIN_LEFT:
1522  end.x = -1;
1523  break;
1524 
1525  case PIN_RIGHT:
1526  end.x = 1;
1527  break;
1528  }
1529 
1530  // = pos of end point, according to the component orientation
1531  end = aTransform.TransformCoordinate( end );
1532  orient = PIN_UP;
1533 
1534  if( end.x == 0 )
1535  {
1536  if( end.y > 0 )
1537  orient = PIN_DOWN;
1538  }
1539  else
1540  {
1541  orient = PIN_RIGHT;
1542 
1543  if( end.x < 0 )
1544  orient = PIN_LEFT;
1545  }
1546 
1547  return orient;
1548 }
1549 
1550 
1552 {
1553  return new LIB_PIN( *this );
1554 }
1555 
1556 
1557 int LIB_PIN::compare( const LIB_ITEM& other ) const
1558 {
1559  wxASSERT( other.Type() == LIB_PIN_T );
1560 
1561  const LIB_PIN* tmp = (LIB_PIN*) &other;
1562 
1563  if( m_number != tmp->m_number )
1564  return m_number.Cmp( tmp->m_number );
1565 
1566  int result = m_name.CmpNoCase( tmp->m_name );
1567 
1568  if( result != 0 )
1569  return result;
1570 
1571  if( m_position.x != tmp->m_position.x )
1572  return m_position.x - tmp->m_position.x;
1573 
1574  if( m_position.y != tmp->m_position.y )
1575  return m_position.y - tmp->m_position.y;
1576 
1577  return 0;
1578 }
1579 
1580 
1581 void LIB_PIN::SetOffset( const wxPoint& aOffset )
1582 {
1583  m_position += aOffset;
1584 }
1585 
1586 
1587 bool LIB_PIN::Inside( EDA_RECT& rect ) const
1588 {
1589  wxPoint end = PinEndPoint();
1590 
1591  return rect.Contains( m_position.x, -m_position.y ) || rect.Contains( end.x, -end.y );
1592 }
1593 
1594 
1595 void LIB_PIN::Move( const wxPoint& newPosition )
1596 {
1597  if( m_position != newPosition )
1598  {
1599  m_position = newPosition;
1600  SetModified();
1601  }
1602 }
1603 
1604 
1605 void LIB_PIN::MirrorHorizontal( const wxPoint& center )
1606 {
1607  m_position.x -= center.x;
1608  m_position.x *= -1;
1609  m_position.x += center.x;
1610 
1611  if( m_orientation == PIN_RIGHT )
1613  else if( m_orientation == PIN_LEFT )
1615 }
1616 
1617 void LIB_PIN::MirrorVertical( const wxPoint& center )
1618 {
1619  m_position.y -= center.y;
1620  m_position.y *= -1;
1621  m_position.y += center.y;
1622 
1623  if( m_orientation == PIN_UP )
1625  else if( m_orientation == PIN_DOWN )
1627 }
1628 
1629 void LIB_PIN::Rotate( const wxPoint& center, bool aRotateCCW )
1630 {
1631  int rot_angle = aRotateCCW ? -900 : 900;
1632 
1633  RotatePoint( &m_position, center, rot_angle );
1634 
1635  if( aRotateCCW )
1636  {
1637  switch( m_orientation )
1638  {
1639  case PIN_RIGHT:
1641  break;
1642 
1643  case PIN_UP:
1645  break;
1646  case PIN_LEFT:
1648  break;
1649 
1650  case PIN_DOWN:
1652  break;
1653  }
1654  }
1655  else
1656  {
1657  switch( m_orientation )
1658  {
1659  case PIN_RIGHT:
1661  break;
1662 
1663  case PIN_UP:
1665  break;
1666  case PIN_LEFT:
1668  break;
1669 
1670  case PIN_DOWN:
1672  break;
1673  }
1674  }
1675 }
1676 
1677 
1678 void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
1679  const TRANSFORM& aTransform )
1680 {
1681  if( ! IsVisible() )
1682  return;
1683 
1684  int orient = PinDrawOrient( aTransform );
1685 
1686  wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
1687 
1688  PlotSymbol( plotter, pos, orient );
1689  PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
1690  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),
1691  GetPenSize() );
1692 }
1693 
1694 
1695 void LIB_PIN::SetWidth( int aWidth )
1696 {
1697  if( m_width != aWidth )
1698  {
1699  m_width = aWidth;
1700  SetModified();
1701  }
1702 }
1703 
1704 
1706 {
1707  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
1708 
1709  LIB_ITEM::GetMsgPanelInfo( aUnits, aList );
1710 
1711  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name, DARKCYAN ) );
1712 
1713  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
1714 
1715  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetText( m_type ), RED ) );
1716 
1717  text = GetText( m_shape );
1718 
1719  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
1720 
1721  if( IsVisible() )
1722  text = _( "Yes" );
1723  else
1724  text = _( "No" );
1725 
1726  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text, DARKGREEN ) );
1727 
1728  // Display pin length
1729  text = StringFromValue( aUnits, m_length, true );
1730  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) );
1731 
1733  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) );
1734 }
1735 
1737 {
1738  getMsgPanelInfoBase( aUnits, aList );
1739 
1740  wxString text;
1741  wxPoint pinpos = GetPosition();
1742  pinpos.y = -pinpos.y; // Display coord are top to bottom
1743  // lib items coord are bottom to top
1744 
1745  text = MessageTextFromValue( aUnits, pinpos.x, true );
1746  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1747 
1748  text = MessageTextFromValue( aUnits, pinpos.y, true );
1749  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1750 }
1751 
1752 void LIB_PIN::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList,
1753  SCH_COMPONENT* aComponent )
1754 {
1755  getMsgPanelInfoBase( aUnits, aList );
1756 
1757  if( !aComponent )
1758  return;
1759 
1760  wxString text;
1761  wxPoint pinpos = aComponent->GetTransform().TransformCoordinate( GetPosition() )
1762  + aComponent->GetPosition();
1763 
1764  text = MessageTextFromValue( aUnits, pinpos.x, true );
1765  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1766 
1767  text = MessageTextFromValue( aUnits, pinpos.y, true );
1768  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1769 
1770  aList.push_back( MSG_PANEL_ITEM( aComponent->GetField( REFERENCE )->GetShownText(),
1771  aComponent->GetField( VALUE )->GetShownText(),
1772  DARKCYAN ) );
1773 }
1774 
1775 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
1776 {
1777  LIB_PART* entry = (LIB_PART* ) m_Parent;
1778  EDA_RECT bbox;
1779  wxPoint begin;
1780  wxPoint end;
1781  int nameTextOffset = 0;
1782  bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" ));
1783  bool showNum = !m_number.IsEmpty();
1784  int minsizeV = TARGET_PIN_RADIUS;
1785 
1786  if( !aIncludeInvisibles && !IsVisible() )
1787  showName = false;
1788 
1789  if( entry )
1790  {
1791  if( entry->ShowPinNames() )
1792  nameTextOffset = entry->GetPinNameOffset();
1793  else
1794  showName = false;
1795 
1796  showNum = entry->ShowPinNumbers();
1797  }
1798 
1799  // First, calculate boundary box corners position
1800  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
1801 
1802  // Actual text height is bigger than text size
1803  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1804 
1806  minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
1807 
1808  // calculate top left corner position
1809  // for the default pin orientation (PIN_RIGHT)
1810  begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
1811  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1812 
1813  // calculate bottom right corner position and adjust top left corner position
1814  int nameTextLength = 0;
1815  int nameTextHeight = 0;
1816 
1817  if( showName )
1818  {
1819  int length = m_name.Len();
1820 
1821  // Don't count the line over text symbol.
1822  if( m_name.Left( 1 ) == wxT( "~" ) )
1823  length -= 1;
1824 
1825  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1826 
1827  // Actual text height are bigger than text size
1828  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
1829  }
1830 
1831  if( nameTextOffset ) // for values > 0, pin name is inside the body
1832  {
1833  end.x = m_length + nameTextLength;
1834  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1835  }
1836  else // if value == 0:
1837  // pin name is outside the body, and above the pin line
1838  // pin num is below the pin line
1839  {
1840  end.x = std::max(m_length, nameTextLength);
1841  end.y = -begin.y;
1842  begin.y = std::max( minsizeV, nameTextHeight );
1843  }
1844 
1845  // Now, calculate boundary box corners position for the actual pin orientation
1846  int orient = PinDrawOrient( DefaultTransform );
1847 
1848  /* Calculate the pin position */
1849  switch( orient )
1850  {
1851  case PIN_UP:
1852  // Pin is rotated and texts positions are mirrored
1853  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1854  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1855  break;
1856 
1857  case PIN_DOWN:
1858  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1859  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1860  begin.x = -begin.x;
1861  end.x = -end.x;
1862  break;
1863 
1864  case PIN_LEFT:
1865  begin.x = -begin.x;
1866  end.x = -end.x;
1867  break;
1868 
1869  case PIN_RIGHT:
1870  break;
1871  }
1872 
1873  begin += m_position;
1874  end += m_position;
1875 
1876  bbox.SetOrigin( begin );
1877  bbox.SetEnd( end );
1878  bbox.Normalize();
1879  bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
1880 
1881  // Draw Y axis is reversed in schematic:
1882  bbox.RevertYAxis();
1883 
1884  return bbox;
1885 }
1886 
1887 
1888 wxArrayString LIB_PIN::GetOrientationNames( void )
1889 {
1890  wxArrayString tmp;
1891 
1892  for( unsigned ii = 0; ii < PIN_ORIENTATION_CNT; ii++ )
1893  tmp.Add( getPinOrientationName( ii ) );
1894 
1895  return tmp;
1896 }
1897 
1898 
1900 {
1901  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
1902  return pin_orientation_codes[ index ];
1903 
1904  return PIN_RIGHT;
1905 }
1906 
1907 
1909 {
1910  size_t i;
1911 
1912  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
1913  {
1914  if( pin_orientation_codes[i] == code )
1915  return (int) i;
1916  }
1917 
1918  return wxNOT_FOUND;
1919 }
1920 
1921 
1923 {
1924  int orient = PIN_RIGHT;
1925 
1926  switch( GetOrientation() )
1927  {
1928  case PIN_UP:
1929  orient = PIN_LEFT;
1930  break;
1931 
1932  case PIN_DOWN:
1933  orient = PIN_RIGHT;
1934  break;
1935 
1936  case PIN_LEFT:
1937  orient = PIN_DOWN;
1938  break;
1939 
1940  case PIN_RIGHT:
1941  orient = PIN_UP;
1942  break;
1943  }
1944 
1945  // Set the new orientation
1946  SetOrientation( orient );
1947 }
1948 
1949 
1951 {
1952  return iconsPinsOrientations;
1953 }
1954 
1955 
1956 BITMAP_DEF LIB_PIN::GetMenuImage() const
1957 {
1958  return GetBitmap( m_type );
1959 }
1960 
1961 
1962 wxString LIB_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
1963 {
1964  return wxString::Format( _( "Pin %s, %s, %s" ),
1965  m_number,
1967  GetText( m_shape ));
1968 }
1969 
1970 
1971 bool LIB_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
1972 {
1973  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText( MILLIMETRES ) );
1974 
1975  // Note: this will have to be modified if we add find and replace capability to the
1976  // compoment library editor. Otherwise, you wont be able to replace pin text.
1977  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS )
1978  || ( aSearchData.GetFlags() & FR_SEARCH_REPLACE ) )
1979  return false;
1980 
1981  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText( MILLIMETRES ) );
1982 
1983  if( EDA_ITEM::Matches( GetName(), aSearchData ) || EDA_ITEM::Matches( m_number, aSearchData ) )
1984  {
1985  if( aFindLocation )
1986  *aFindLocation = GetBoundingBox().Centre();
1987 
1988  return true;
1989  }
1990 
1991  return false;
1992 }
1993 
1994 
1995 #if defined(DEBUG)
1996 
1997 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
1998 {
1999  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2000  << " num=\"" << m_number.mb_str()
2001  << '"' << "/>\n";
2002 
2003 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2004 }
2005 
2006 #endif
2007 
2008 void LIB_PIN::CalcEdit( const wxPoint& aPosition )
2009 {
2010  DBG(printf("m_Flags %x\n", m_Flags );)
2011  if( m_Flags == IS_NEW )
2012  {
2013  SetPosition( aPosition );
2014  }
2015  else if( m_Flags == IS_MOVED )
2016  {
2017  DBG(printf("MOVEPIN\n");)
2018  Move( aPosition );
2019  }
2020 }
virtual BASE_SCREEN * GetScreen()=0
Definition: colors.h:57
#define TEXT_ANGLE_HORIZ
void FinishTo(const wxPoint &pos)
Definition: plotter.h:251
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:111
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:113
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1971
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1557
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
void SetModified()
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:85
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:363
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1551
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...
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:171
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:112
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Draw the electrical type text of the pin (only for the footprint editor) aDrawMode = GR_OR,...
Definition: lib_pin.cpp:1066
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1479
static int ExternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
Definition: lib_pin.cpp:142
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:78
int GetPinNameOffset()
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
#define ETXT_MAX_SIZE
void SetPosition(const wxPoint &aPosition)
bool IsSelected() const
Definition: base_struct.h:224
#define TEXT_ANGLE_VERT
static const wxString getPinOrientationName(unsigned aPinOrientationCode)
Definition: lib_pin.cpp:108
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1908
Implementation of conversion functions that require both schematic and board internal units.
int m_numTextSize
Definition: lib_pin.h:84
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1888
int GetOrientation() const
Definition: lib_pin.h:221
virtual void SetColor(COLOR4D color)=0
LIB_PART * GetParent() const
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1956
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:298
Definition: colors.h:61
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:420
int color
Definition: DXF_plotter.cpp:62
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
static int GetDefaultPinLength()
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:161
static const BITMAP_DEF iconsPinsOrientations[]
Definition: lib_pin.cpp:67
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_pin.cpp:1695
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1581
Search texts (name and number (a 4 letters text) )in pins.
int m_Unit
Unit identification for multiple parts per package.
wxString m_name
Definition: lib_pin.h:82
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1950
virtual EDA_RECT * GetClipBox()
Definition: lib_pin.h:55
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:514
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1279
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:145
The base class for create windows for drawing purpose.
Definition: draw_frame.h:81
int PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: lib_pin.cpp:1506
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
int m_length
Length of the pin.
Definition: lib_pin.h:76
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)
Definition: eda_rect.h:144
COLOR4D GetInvisibleItemColor()
Field Reference of part, i.e. "IC21".
bool Contains(const wxPoint &aPoint) const
Function Contains.
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, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
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.
bool IsNew() const
Definition: base_struct.h:219
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
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.
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1617
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:576
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:450
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:337
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:222
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
virtual EDA_DRAW_FRAME * GetParent() const =0
bool ShowPinNames()
int GetPenSize() const override
Definition: lib_pin.cpp:564
static int GetPinNumDefaultSize()
void LineTo(const wxPoint &pos)
Definition: plotter.h:246
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:77
#define VALUE
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:110
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
bool ShowPinNumbers()
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:83
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1128
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:275
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
const wxString & GetName() const
Definition: lib_pin.h:166
TRANSFORM & GetTransform() const
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
Class LIB_ITEM definition.
void SetEnd(int x, int y)
Definition: eda_rect.h:134
bool Inside(EDA_RECT &aRect) const override
Test if any part of the draw object is inside rectangle bounds of aRect.
Definition: lib_pin.cpp:1587
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:540
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:481
wxLogTrace helper definitions.
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:1922
Definition: colors.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:362
static const int pin_orientation_codes[]
Definition: lib_pin.cpp:53
int GetNameTextSize() const
Definition: lib_pin.h:192
static int InternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius)
Definition: lib_pin.cpp:133
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:285
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:852
bool m_IsPrinting
Definition: base_screen.h:220
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:2008
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:147
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1962
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin editing.
Definition: lib_pin.cpp:393
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
void MoveTo(const wxPoint &pos)
Definition: plotter.h:241
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:81
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:327
void Normalize()
Function Normalize ensures that the height ant width are positive.
#define NCSYMB_PIN_DIM
Base plotter engine class.
Definition: plotter.h:97
Definition the SCH_COMPONENT class for Eeschema.
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:75
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:420
int GetNumberTextSize() const
Definition: lib_pin.h:219
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:59
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:1678
const wxChar *const traceFindItem
Flag to enable find debug tracing.
bool IsType(FRAME_T aType) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static int GetPinNameDefaultSize()
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:63
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:755
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:178
size_t i
Definition: json11.cpp:597
Perform a search for a item that has replaceable text.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetType(ELECTRICAL_PINTYPE aType, bool aTestOtherPins=true)
Set the electrical type of the pin.
Definition: lib_pin.cpp:327
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:70
wxPoint GetPosition() const override
Function GetPosition.
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1595
#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:154
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:80
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
wxPoint Centre() const
Definition: eda_rect.h:60
int m_Convert
Shape identification for alternate body styles.
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210
Definition of class LIB_EDIT_FRAME.
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:269
COLOR4D GetItemSelectedColor()
#define DBG(x)
Definition: fctsys.h:33
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:148
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
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:266
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:194
Message panel definition file.
int m_width
Line width of the pin.
Definition: lib_pin.h:79
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)
Draw the pin symbol without text.
Definition: lib_pin.cpp:653
#define PIN_ORIENTATION_CNT
Definition: lib_pin.cpp:60
EDA_UNITS_T
Definition: common.h:160
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
void getMsgPanelInfoBase(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1705
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:241
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
#define min(a, b)
Definition: auxiliary.h:85
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1605
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:1899
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113