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-2020 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 
26 #include <pgm_base.h>
27 #include <sch_draw_panel.h>
28 #include <sch_edit_frame.h>
29 #include <base_units.h>
30 #include <widgets/msgpanel.h>
31 #include <general.h>
32 #include <symbol_edit_frame.h>
33 #include <class_libentry.h>
34 #include <lib_pin.h>
37 #include <trigo.h>
38 #include "sch_painter.h"
39 
40 // small margin in internal units between the pin text and the pin line
41 #define PIN_TEXT_MARGIN 4
42 
44 {
45  // These strings are the canonical name of the electrictal type
46  // Not translated, no space in name, only ASCII chars.
47  // to use when the string name must be known and well defined
48  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
49  static const wxChar* msgPinElectricType[] =
50  {
51  wxT( "input" ),
52  wxT( "output" ),
53  wxT( "BiDi" ),
54  wxT( "3state" ),
55  wxT( "passive" ),
56  wxT( "unspc" ),
57  wxT( "power_in" ),
58  wxT( "power_out" ),
59  wxT( "openCol" ),
60  wxT( "openEm" ),
61  wxT( "NotConnected" )
62  };
63 
64  return msgPinElectricType[static_cast<int>( aType )];
65 }
66 
67 
69 // i.e. the clock symbols (falling clock is actually external but is of
70 // the same kind)
71 
72 static int internalPinDecoSize( RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
73 {
74  KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
75 
76  if( settings && settings->m_PinSymbolSize )
77  return settings->m_PinSymbolSize;
78 
79  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
80 }
81 
83 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
84 // marker
85 static int externalPinDecoSize( RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
86 {
87  KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
88 
89  if( settings && settings->m_PinSymbolSize )
90  return settings->m_PinSymbolSize;
91 
92  return aPin.GetNumberTextSize() / 2;
93 }
94 
95 
97  LIB_ITEM( LIB_PIN_T, aParent ),
98  m_orientation( PIN_RIGHT ),
99  m_shape( GRAPHIC_PINSHAPE::LINE ),
101  m_attributes( 0 )
102 {
103  // Use the application settings for pin sizes if exists.
104  // pgm can be nullptr when running a shared lib from a script, not from a kicad appl
105  PGM_BASE* pgm = PgmOrNull();
106 
107  if( pgm )
108  {
109  auto* settings = pgm->GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
110  m_length = Mils2iu( settings->m_Defaults.pin_length );
111  m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size );
112  m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size );
113  }
114  else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
115  {
116  m_length = Mils2iu( DEFAULT_PIN_LENGTH );
117  m_numTextSize = Mils2iu( DEFAULT_PINNUM_SIZE );
119  }
120 }
121 
122 
123 LIB_PIN::LIB_PIN( LIB_PART* aParent, const wxString& aName, const wxString& aNumber,
124  int aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize,
125  int aNumTextSize, int aConvert, const wxPoint& aPos, int aUnit ) :
126  LIB_ITEM( LIB_PIN_T, aParent ),
127  m_position( aPos ),
128  m_length( aLength ),
129  m_orientation( aOrientation ),
130  m_shape( GRAPHIC_PINSHAPE::LINE ),
131  m_type( aPinType ),
132  m_attributes( 0 ),
133  m_numTextSize( aNumTextSize ),
134  m_nameTextSize( aNameTextSize )
135 {
136  SetName( aName );
137  SetNumber( aNumber );
138  SetUnit( aUnit );
139  SetConvert( aConvert );
140 }
141 
142 
143 bool LIB_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
144 {
145  EDA_RECT rect = GetBoundingBox();
146 
147  return rect.Inflate( aAccuracy ).Contains( aPosition );
148 }
149 
150 
151 bool LIB_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
152 {
153  if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
154  return false;
155 
156  EDA_RECT sel = aRect;
157 
158  if ( aAccuracy )
159  sel.Inflate( aAccuracy );
160 
161  if( aContained )
162  return sel.Contains( GetBoundingBox( false, true ) );
163 
164  return sel.Intersects( GetBoundingBox( false, true ) );
165 }
166 
167 
169 {
170  return 1;
171 }
172 
173 
174 void LIB_PIN::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
175  const TRANSFORM& aTransform )
176 {
177  PART_DRAW_OPTIONS* opts = (PART_DRAW_OPTIONS*) aData;
178  bool drawHiddenFields = opts ? opts->draw_hidden_fields : false;
179  bool showPinType = opts ? opts->show_elec_type : false;
180 
181  LIB_PART* part = GetParent();
182 
183  /* Calculate pin orient taking in account the component orientation. */
184  int orient = PinDrawOrient( aTransform );
185 
186  /* Calculate the pin position */
187  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
188 
189  if( IsVisible() || drawHiddenFields )
190  {
191  printPinSymbol( aSettings, pos1, orient );
192 
193  printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), part->ShowPinNumbers(),
194  part->ShowPinNames() );
195 
196  if( showPinType )
197  printPinElectricalTypeName( aSettings, pos1, orient );
198  }
199 }
200 
201 
202 void LIB_PIN::printPinSymbol( RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrient )
203 {
204  wxDC* DC = aSettings->GetPrintDC();
205  int MapX1, MapY1, x1, y1;
206  int width = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
207  int posX = aPos.x, posY = aPos.y, len = m_length;
209 
210  MapX1 = MapY1 = 0;
211  x1 = posX;
212  y1 = posY;
213 
214  switch( aOrient )
215  {
216  case PIN_UP: y1 = posY - len; MapY1 = 1; break;
217  case PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
218  case PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
219  case PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
220  }
221 
223  {
224  const int radius = externalPinDecoSize( aSettings, *this );
225  GRCircle( nullptr, DC, MapX1 * radius + x1, MapY1 * radius + y1, radius, width, color );
226 
227  GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
228  GRLineTo( nullptr, DC, posX, posY, width, color );
229  }
230  else
231  {
232  GRMoveTo( x1, y1 );
233  GRLineTo( nullptr, DC, posX, posY, width, color );
234  }
235 
236  // Draw the clock shape (>)inside the symbol
241  {
242  const int clock_size = internalPinDecoSize( aSettings, *this );
243  if( MapY1 == 0 ) /* MapX1 = +- 1 */
244  {
245  GRMoveTo( x1, y1 + clock_size );
246  GRLineTo( nullptr, DC, x1 - MapX1 * clock_size * 2, y1, width, color );
247  GRLineTo( nullptr, DC, x1, y1 - clock_size, width, color );
248  }
249  else /* MapX1 = 0 */
250  {
251  GRMoveTo( x1 + clock_size, y1 );
252  GRLineTo( nullptr, DC, x1, y1 - MapY1 * clock_size * 2, width, color );
253  GRLineTo( nullptr, DC, x1 - clock_size, y1, width, color );
254  }
255  }
256 
257  // Draw the active low (or H to L active transition)
261  {
262  const int deco_size = externalPinDecoSize( aSettings, *this );
263  if( MapY1 == 0 ) /* MapX1 = +- 1 */
264  {
265  GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
266  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
267  GRLineTo( nullptr, DC, x1, y1, width, color );
268  }
269  else /* MapX1 = 0 */
270  {
271  GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
272  GRLineTo( nullptr, DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
273  GRLineTo( nullptr, DC, x1, y1, width, color );
274  }
275  }
276 
277  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
278  {
279  const int deco_size = externalPinDecoSize( aSettings, *this );
280  if( MapY1 == 0 ) /* MapX1 = +- 1 */
281  {
282  GRMoveTo( x1, y1 - deco_size * 2 );
283  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1, width, color );
284  }
285  else /* MapX1 = 0 */
286  {
287  GRMoveTo( x1 - deco_size * 2, y1 );
288  GRLineTo( nullptr, DC, x1, y1 + MapY1 * deco_size * 2, width, color );
289  }
290  }
291  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
292  {
293  const int deco_size = externalPinDecoSize( aSettings, *this );
294  GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
295  GRLineTo( nullptr, DC, x1 + (MapX1 + MapY1) * deco_size,
296  y1 + ( MapY1 - MapX1 ) * deco_size, width, color );
297  GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
298  GRLineTo( nullptr, DC, x1 + (MapX1 - MapY1) * deco_size,
299  y1 + ( MapY1 + MapX1 ) * deco_size, width, color );
300  }
301 
302  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
303  {
304  const int deco_size = TARGET_PIN_RADIUS;
305  GRLine( nullptr, DC, posX - deco_size, posY - deco_size, posX + deco_size,
306  posY + deco_size, width, color );
307  GRLine( nullptr, DC, posX + deco_size, posY - deco_size, posX - deco_size,
308  posY + deco_size, width, color );
309  }
310 }
311 
312 
313 void LIB_PIN::printPinTexts( RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
314  int aTextInside, bool aDrawPinNum, bool aDrawPinName )
315 {
316  if( !aDrawPinName && !aDrawPinNum )
317  return;
318 
319  int x, y;
320  wxDC* DC = aSettings->GetPrintDC();
321  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
322  wxSize PinNumSize( m_numTextSize, m_numTextSize );
323 
324  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
325  aSettings->GetDefaultPenWidth() );
326  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
327  aSettings->GetDefaultPenWidth() );
328 
329  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
330  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
331 
332  /* Get the num and name colors */
333  COLOR4D NameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
334  COLOR4D NumColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
335 
336  int x1 = aPinPos.x;
337  int y1 = aPinPos.y;
338 
339  switch( aPinOrient )
340  {
341  case PIN_UP: y1 -= m_length; break;
342  case PIN_DOWN: y1 += m_length; break;
343  case PIN_LEFT: x1 -= m_length; break;
344  case PIN_RIGHT: x1 += m_length; break;
345  }
346 
347  if( m_name.IsEmpty() )
348  aDrawPinName = false;
349 
350  if( aTextInside ) // Draw the text inside, but the pin numbers outside.
351  {
352  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
353  {
354  // It is an horizontal line
355  if( aDrawPinName )
356  {
357  if( aPinOrient == PIN_RIGHT )
358  {
359  x = x1 + aTextInside;
360  GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
362  namePenWidth, false, false );
363  }
364  else // Orient == PIN_LEFT
365  {
366  x = x1 - aTextInside;
367  GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
369  namePenWidth, false, false );
370  }
371  }
372 
373  if( aDrawPinNum )
374  {
375  GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, m_number,
377  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
378  }
379  }
380  else /* Its a vertical line. */
381  {
382  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
383  if( aPinOrient == PIN_DOWN )
384  {
385  y = y1 + aTextInside;
386 
387  if( aDrawPinName )
388  {
389  GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
390  GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
391  false );
392  }
393 
394  if( aDrawPinNum )
395  {
396  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
398  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
399  }
400  }
401  else /* PIN_UP */
402  {
403  y = y1 - aTextInside;
404 
405  if( aDrawPinName )
406  {
407  GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
408  GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
409  false );
410  }
411 
412  if( aDrawPinNum )
413  {
414  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
416  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
417  }
418  }
419  }
420  }
421  else /**** Draw num & text pin outside ****/
422  {
423  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
424  {
425  /* Its an horizontal line. */
426  if( aDrawPinName )
427  {
428  x = ( x1 + aPinPos.x) / 2;
429  GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, m_name, TEXT_ANGLE_HORIZ,
431  namePenWidth, false, false );
432  }
433  if( aDrawPinNum )
434  {
435  x = ( x1 + aPinPos.x) / 2;
436  GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, m_number, TEXT_ANGLE_HORIZ,
437  PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, numPenWidth,
438  false, false );
439  }
440  }
441  else /* Its a vertical line. */
442  {
443  if( aDrawPinName )
444  {
445  y = ( y1 + aPinPos.y) / 2;
446  GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, m_name, TEXT_ANGLE_VERT,
448  namePenWidth, false, false );
449  }
450 
451  if( aDrawPinNum )
452  {
453  GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, m_number,
455  numPenWidth, false, false );
456  }
457  }
458  }
459 }
460 
461 
462 
463 void LIB_PIN::printPinElectricalTypeName( RENDER_SETTINGS* aSettings, wxPoint& aPosition,
464  int aOrientation )
465 {
466  wxDC* DC = aSettings->GetPrintDC();
467  wxString typeName = GetElectricalTypeName();
468 
469  // Use a reasonable (small) size to draw the text
470  int textSize = ( m_nameTextSize * 3 ) / 4;
471 
472  #define ETXT_MAX_SIZE Millimeter2iu( 0.7 )
473 
474  if( textSize > ETXT_MAX_SIZE )
475  textSize = ETXT_MAX_SIZE;
476 
477  // Use a reasonable pen size to draw the text
478  int pensize = textSize/6;
479 
480  // Get a suitable color
482 
483  wxPoint txtpos = aPosition;
484  int offset = Millimeter2iu( 0.4 );
486  int orient = TEXT_ANGLE_HORIZ;
487 
488  switch( aOrientation )
489  {
490  case PIN_UP:
491  txtpos.y += offset;
492  orient = TEXT_ANGLE_VERT;
493  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
494  break;
495 
496  case PIN_DOWN:
497  txtpos.y -= offset;
498  orient = TEXT_ANGLE_VERT;
499  break;
500 
501  case PIN_LEFT:
502  txtpos.x += offset;
503  break;
504 
505  case PIN_RIGHT:
506  txtpos.x -= offset;
507  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
508  break;
509  }
510 
511  GRText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify,
512  GR_TEXT_VJUSTIFY_CENTER, pensize, false, false, 0 );
513 }
514 
515 
516 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
517 {
518  int MapX1, MapY1, x1, y1;
520  int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
521 
522  aPlotter->SetColor( color );
523  aPlotter->SetCurrentLineWidth( penWidth );
524 
525  MapX1 = MapY1 = 0;
526  x1 = aPosition.x; y1 = aPosition.y;
527 
528  switch( aOrientation )
529  {
530  case PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break;
531  case PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break;
532  case PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break;
533  case PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break;
534  }
535 
537  {
538  const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
539  aPlotter->Circle( wxPoint( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
540  FILL_TYPE::NO_FILL, penWidth );
541 
542  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
543  aPlotter->FinishTo( aPosition );
544  }
546  {
547  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
548  if( MapY1 == 0 ) /* MapX1 = +- 1 */
549  {
550  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
551  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
552  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
553  }
554  else /* MapX1 = 0 */
555  {
556  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
557  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
558  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
559  }
560 
561  aPlotter->MoveTo( wxPoint( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
562  aPlotter->FinishTo( aPosition );
563  }
564  else
565  {
566  aPlotter->MoveTo( wxPoint( x1, y1 ) );
567  aPlotter->FinishTo( aPosition );
568  }
569 
573  {
574  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
575  if( MapY1 == 0 ) /* MapX1 = +- 1 */
576  {
577  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
578  aPlotter->LineTo( wxPoint( x1 - MapX1 * deco_size * 2, y1 ) );
579  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
580  }
581  else /* MapX1 = 0 */
582  {
583  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
584  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * deco_size * 2 ) );
585  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
586  }
587  }
588 
590  || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
591  {
592  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
593 
594  if( MapY1 == 0 ) /* MapX1 = +- 1 */
595  {
596  aPlotter->MoveTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
597  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
598  aPlotter->FinishTo( wxPoint( x1, y1 ) );
599  }
600  else /* MapX1 = 0 */
601  {
602  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
603  aPlotter->LineTo( wxPoint( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
604  aPlotter->FinishTo( wxPoint( x1, y1 ) );
605  }
606  }
607 
608  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
609  {
610  const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
611 
612  if( MapY1 == 0 ) /* MapX1 = +- 1 */
613  {
614  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
615  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
616  }
617  else /* MapX1 = 0 */
618  {
619  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
620  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
621  }
622  }
623  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
624  {
625  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
626  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ) );
627  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * deco_size, y1 + (MapY1 - MapX1) * deco_size ) );
628  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ) );
629  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * deco_size, y1 + (MapY1 + MapX1) * deco_size ) );
630  }
631 
632  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
633  {
634  const int deco_size = TARGET_PIN_RADIUS;
635  const int ex1 = aPosition.x;
636  const int ey1 = aPosition.y;
637  aPlotter->MoveTo( wxPoint( ex1 - deco_size, ey1 - deco_size ) );
638  aPlotter->FinishTo( wxPoint( ex1 + deco_size, ey1 + deco_size ) );
639  aPlotter->MoveTo( wxPoint( ex1 + deco_size, ey1 - deco_size ) );
640  aPlotter->FinishTo( wxPoint( ex1 - deco_size, ey1 + deco_size ) );
641  }
642 }
643 
644 
645 void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, wxPoint& aPinPos, int aPinOrient, int aTextInside,
646  bool aDrawPinNum, bool aDrawPinName )
647 {
648  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
649  aDrawPinName = false;
650 
651  if( m_number.IsEmpty() )
652  aDrawPinNum = false;
653 
654  if( !aDrawPinNum && !aDrawPinName )
655  return;
656 
657  int x, y;
658  wxSize pinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
659  wxSize pinNumSize = wxSize( m_numTextSize, m_numTextSize );
660 
661  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
662  aPlotter->RenderSettings()->GetDefaultPenWidth() );
663  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
664  aPlotter->RenderSettings()->GetDefaultPenWidth() );
665 
666  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
667  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
668 
669  /* Get the num and name colors */
670  COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM );
671  COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM );
672 
673  int x1 = aPinPos.x;
674  int y1 = aPinPos.y;
675 
676  switch( aPinOrient )
677  {
678  case PIN_UP: y1 -= m_length; break;
679  case PIN_DOWN: y1 += m_length; break;
680  case PIN_LEFT: x1 -= m_length; break;
681  case PIN_RIGHT: x1 += m_length; break;
682  }
683 
684  /* Draw the text inside, but the pin numbers outside. */
685  if( aTextInside )
686  {
687  if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) ) /* Its an horizontal line. */
688  {
689  if( aDrawPinName )
690  {
691  if( aPinOrient == PIN_RIGHT )
692  {
693  x = x1 + aTextInside;
694  aPlotter->Text( wxPoint( x, y1 ), nameColor, m_name, TEXT_ANGLE_HORIZ,
696  namePenWidth, false, false );
697  }
698  else // orient == PIN_LEFT
699  {
700  x = x1 - aTextInside;
701 
702  if( aDrawPinName )
703  {
704  aPlotter->Text( wxPoint( x, y1 ), nameColor, m_name, TEXT_ANGLE_HORIZ,
705  pinNameSize, GR_TEXT_HJUSTIFY_RIGHT,
706  GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false, false );
707  }
708  }
709  }
710  if( aDrawPinNum )
711  {
712  aPlotter->Text( wxPoint( ( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
714  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
715  }
716  }
717  else /* Its a vertical line. */
718  {
719  if( aPinOrient == PIN_DOWN )
720  {
721  y = y1 + aTextInside;
722 
723  if( aDrawPinName )
724  aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
726  namePenWidth, false, false );
727 
728  if( aDrawPinNum )
729  {
730  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
732  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
733  }
734  }
735  else /* PIN_UP */
736  {
737  y = y1 - aTextInside;
738 
739  if( aDrawPinName )
740  {
741  aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
743  namePenWidth, false, false );
744  }
745 
746  if( aDrawPinNum )
747  {
748  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
750  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
751  }
752  }
753  }
754  }
755  else /* Draw num & text pin outside */
756  {
757  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
758  {
759  /* Its an horizontal line. */
760  if( aDrawPinName )
761  {
762  x = ( x1 + aPinPos.x) / 2;
763  aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, m_name,
765  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
766  }
767 
768  if( aDrawPinNum )
769  {
770  x = ( x1 + aPinPos.x ) / 2;
771  aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, m_number,
773  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
774  }
775  }
776  else /* Its a vertical line. */
777  {
778  if( aDrawPinName )
779  {
780  y = ( y1 + aPinPos.y ) / 2;
781  aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, m_name,
783  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
784  }
785 
786  if( aDrawPinNum )
787  {
788  aPlotter->Text( wxPoint( x1 + num_offset, ( y1 + aPinPos.y ) / 2 ), numColor,
790  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
791  }
792  }
793  }
794 }
795 
796 
797 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
798 {
799  int orient;
800  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
801 
802  switch( m_orientation )
803  {
804  case PIN_UP: end.y = 1; break;
805  case PIN_DOWN: end.y = -1; break;
806  case PIN_LEFT: end.x = -1; break;
807  case PIN_RIGHT: end.x = 1; break;
808  }
809 
810  // = pos of end point, according to the component orientation
811  end = aTransform.TransformCoordinate( end );
812  orient = PIN_UP;
813 
814  if( end.x == 0 )
815  {
816  if( end.y > 0 )
817  orient = PIN_DOWN;
818  }
819  else
820  {
821  orient = PIN_RIGHT;
822 
823  if( end.x < 0 )
824  orient = PIN_LEFT;
825  }
826 
827  return orient;
828 }
829 
830 
832 {
833  return new LIB_PIN( *this );
834 }
835 
836 
837 int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
838 {
839  wxASSERT( aOther.Type() == LIB_PIN_T );
840 
841  int retv = LIB_ITEM::compare( aOther, aCompareFlags );
842 
843  if( retv )
844  return retv;
845 
846  const LIB_PIN* tmp = (LIB_PIN*) &aOther;
847 
848  // When comparing units, we do not compare the part numbers. If everything else is
849  // identical, then we can just renumber the parts for the inherited symbol.
850  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
851  return m_number.Cmp( tmp->m_number );
852 
853  int result = m_name.CmpNoCase( tmp->m_name );
854 
855  if( result )
856  return result;
857 
858  if( m_position.x != tmp->m_position.x )
859  return m_position.x - tmp->m_position.x;
860 
861  if( m_position.y != tmp->m_position.y )
862  return m_position.y - tmp->m_position.y;
863 
864  if( m_length != tmp->m_length )
865  return m_length - tmp->m_length;
866 
867  if( m_orientation != tmp->m_orientation )
868  return m_orientation - tmp->m_orientation;
869 
870  if( m_shape != tmp->m_shape )
871  return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
872 
873  if( m_type != tmp->m_type )
874  return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
875 
876  if( m_attributes != tmp->m_attributes )
877  return m_attributes - tmp->m_attributes;
878 
879  if( m_numTextSize != tmp->m_numTextSize )
880  return m_numTextSize - tmp->m_numTextSize;
881 
882  if( m_nameTextSize != tmp->m_nameTextSize )
883  return m_nameTextSize - tmp->m_nameTextSize;
884 
885  return 0;
886 }
887 
888 
889 void LIB_PIN::Offset( const wxPoint& aOffset )
890 {
891  m_position += aOffset;
892 }
893 
894 
895 void LIB_PIN::MoveTo( const wxPoint& aNewPosition )
896 {
897  if( m_position != aNewPosition )
898  {
899  m_position = aNewPosition;
900  SetModified();
901  }
902 }
903 
904 
905 void LIB_PIN::MirrorHorizontal( const wxPoint& aCenter )
906 {
907  m_position.x -= aCenter.x;
908  m_position.x *= -1;
909  m_position.x += aCenter.x;
910 
911  if( m_orientation == PIN_RIGHT )
913  else if( m_orientation == PIN_LEFT )
915 }
916 
917 
918 void LIB_PIN::MirrorVertical( const wxPoint& aCenter )
919 {
920  m_position.y -= aCenter.y;
921  m_position.y *= -1;
922  m_position.y += aCenter.y;
923 
924  if( m_orientation == PIN_UP )
926  else if( m_orientation == PIN_DOWN )
928 }
929 
930 
931 void LIB_PIN::Rotate( const wxPoint& aCenter, bool aRotateCCW )
932 {
933  int rot_angle = aRotateCCW ? -900 : 900;
934 
935  RotatePoint( &m_position, aCenter, rot_angle );
936 
937  if( aRotateCCW )
938  {
939  switch( m_orientation )
940  {
941  case PIN_RIGHT: m_orientation = PIN_UP; break;
942  case PIN_UP: m_orientation = PIN_LEFT; break;
943  case PIN_LEFT: m_orientation = PIN_DOWN; break;
944  case PIN_DOWN: m_orientation = PIN_RIGHT; break;
945  }
946  }
947  else
948  {
949  switch( m_orientation )
950  {
951  case PIN_RIGHT: m_orientation = PIN_DOWN; break;
952  case PIN_UP: m_orientation = PIN_RIGHT; break;
953  case PIN_LEFT: m_orientation = PIN_UP; break;
954  case PIN_DOWN: m_orientation = PIN_LEFT; break;
955  }
956  }
957 }
958 
959 
960 void LIB_PIN::Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
961  const TRANSFORM& aTransform )
962 {
963  if( ! IsVisible() )
964  return;
965 
966  int orient = PinDrawOrient( aTransform );
967  wxPoint pos = aTransform.TransformCoordinate( m_position ) + aPffset;
968 
969  PlotSymbol( aPlotter, pos, orient );
970  PlotPinTexts( aPlotter, pos, orient, GetParent()->GetPinNameOffset(),
971  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames() );
972 }
973 
974 
976 {
977  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
978 
979  LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
980 
981  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name ) );
982  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text ) );
983  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( m_type ) ) );
984 
985  text = PinShapeGetText( m_shape );
986  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text ) );
987 
988  text = IsVisible() ? _( "Yes" ) : _( "No" );
989  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text ) );
990 
991  // Display pin length
992  text = StringFromValue( aFrame->GetUserUnits(), m_length );
993  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text ) );
994 
995  text = PinOrientationName( (unsigned) PinOrientationIndex( m_orientation ) );
996  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text ) );
997 
998  wxPoint pinpos = GetPosition();
999  pinpos.y = -pinpos.y; // Display coord are top to bottom
1000  // lib items coord are bottom to top
1001 
1002  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.x );
1003  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text ) );
1004 
1005  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.y );
1006  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text ) );
1007 }
1008 
1009 
1010 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly ) const
1011 {
1012  EDA_RECT bbox;
1013  wxPoint begin;
1014  wxPoint end;
1015  int nameTextOffset = 0;
1016  bool showName = !m_name.IsEmpty() && ( m_name != wxT( "~" ) );
1017  bool showNum = !m_number.IsEmpty();
1018  int minsizeV = TARGET_PIN_RADIUS;
1019 
1020  if( !aIncludeInvisibles && !IsVisible() )
1021  showName = false;
1022 
1023  if( GetParent() )
1024  {
1025  if( GetParent()->ShowPinNames() )
1026  nameTextOffset = GetParent()->GetPinNameOffset();
1027  else
1028  showName = false;
1029 
1030  if( !GetParent()->ShowPinNumbers() )
1031  showNum = false;
1032  }
1033 
1034  if( aPinOnly )
1035  {
1036  showName = false;
1037  showNum = false;
1038  }
1039 
1040  // First, calculate boundary box corners position
1041  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
1042 
1043  // Actual text height is bigger than text size
1044  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1045 
1047  minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) );
1048 
1049  // calculate top left corner position
1050  // for the default pin orientation (PIN_RIGHT)
1051  begin.y = std::max( minsizeV, numberTextHeight + Mils2iu( PIN_TEXT_MARGIN ) );
1052  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1053 
1054  // calculate bottom right corner position and adjust top left corner position
1055  int nameTextLength = 0;
1056  int nameTextHeight = 0;
1057 
1058  if( showName )
1059  {
1060  int length = m_name.Len();
1061 
1062  // Don't count the line over text symbol.
1063  if( m_name.Left( 1 ) == wxT( "~" ) )
1064  length -= 1;
1065 
1066  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1067 
1068  // Actual text height are bigger than text size
1069  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + Mils2iu( PIN_TEXT_MARGIN );
1070  }
1071 
1072  if( nameTextOffset ) // for values > 0, pin name is inside the body
1073  {
1074  end.x = m_length + nameTextLength + TARGET_PIN_RADIUS;
1075  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1076  }
1077  else // if value == 0:
1078  // pin name is outside the body, and above the pin line
1079  // pin num is below the pin line
1080  {
1081  end.x = std::max( m_length + TARGET_PIN_RADIUS, nameTextLength );
1082  end.y = -begin.y;
1083  begin.y = std::max( minsizeV, nameTextHeight );
1084  }
1085 
1086  // Now, calculate boundary box corners position for the actual pin orientation
1087  int orient = PinDrawOrient( DefaultTransform );
1088 
1089  /* Calculate the pin position */
1090  switch( orient )
1091  {
1092  case PIN_UP:
1093  // Pin is rotated and texts positions are mirrored
1094  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1095  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1096  break;
1097 
1098  case PIN_DOWN:
1099  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1100  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1101  begin.x = -begin.x;
1102  end.x = -end.x;
1103  break;
1104 
1105  case PIN_LEFT:
1106  begin.x = -begin.x;
1107  end.x = -end.x;
1108  break;
1109 
1110  case PIN_RIGHT:
1111  break;
1112  }
1113 
1114  begin += m_position;
1115  end += m_position;
1116 
1117  bbox.SetOrigin( begin );
1118  bbox.SetEnd( end );
1119  bbox.Normalize();
1120  bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
1121 
1122  // Draw Y axis is reversed in schematic:
1123  bbox.RevertYAxis();
1124 
1125  return bbox;
1126 }
1127 
1128 
1130 {
1132 }
1133 
1134 
1135 wxString LIB_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
1136 {
1137  if( !m_name.IsEmpty() )
1138  {
1139  return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1140  m_number,
1141  m_name,
1143  PinShapeGetText( m_shape ) );
1144  }
1145  else
1146  {
1147  return wxString::Format( _( "Pin %s [%s, %s]" ),
1148  m_number,
1150  PinShapeGetText( m_shape ) );
1151  }
1152 }
1153 
1154 
1155 #if defined(DEBUG)
1156 
1157 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
1158 {
1159  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1160  << " num=\"" << m_number.mb_str()
1161  << '"' << "/>\n";
1162 
1163 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
1164 }
1165 
1166 #endif
1167 
1168 void LIB_PIN::CalcEdit( const wxPoint& aPosition )
1169 {
1170  if( IsMoving() )
1171  {
1172  MoveTo( aPosition );
1173  }
1174 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:277
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:115
void printPinElectricalTypeName(RENDER_SETTINGS *aSettings, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:463
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1135
void SetModified()
Definition: eda_item.cpp:79
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Definition: base_units.cpp:123
int m_nameTextSize
Definition: lib_pin.h:75
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:831
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:931
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
PNG memory record (file in memory).
Definition: bitmap_def.h:29
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:69
int GetPinNameOffset()
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
#define ETXT_MAX_SIZE
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
void printPinTexts(RENDER_SETTINGS *aSettings, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:313
Implementation of conversion functions that require both schematic and board internal units.
void MoveTo(const wxPoint &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:895
int m_numTextSize
Definition: lib_pin.h:74
virtual void SetColor(COLOR4D color)=0
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
LIB_PART * GetParent() const
Definition: lib_item.h:183
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1129
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:240
bool IsMoving() const
Definition: eda_item.h:188
int color
Definition: DXF_plotter.cpp:60
void printPinSymbol(RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:202
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
TRANSFORM DefaultTransform
unknown electrical properties: creates always a warning when connected
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
int PinOrientationIndex(int code)
Definition: pin_type.cpp:150
wxString m_name
Definition: lib_pin.h:72
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: lib_pin.cpp:143
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:260
Definition: lib_pin.h:50
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:222
GRAPHIC_PINSHAPE
Definition: pin_type.h:53
The base class for create windows for drawing purpose.
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:797
int m_length
Definition: lib_pin.h:67
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)
Definition: eda_rect.h:209
bool Contains(const wxPoint &aPoint) const
Function Contains.
Definition: eda_rect.cpp:57
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
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: gr_text.cpp:219
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:918
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:264
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:166
bool ShowPinNames()
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:119
static int internalPinDecoSize(RENDER_SETTINGS *aSettings, const LIB_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius)
Definition: lib_pin.cpp:72
void LineTo(const wxPoint &pos)
Definition: plotter.h:272
int m_orientation
Definition: lib_pin.h:68
bool ShowPinNumbers()
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:69
wxString m_number
Definition: lib_pin.h:73
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:516
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:142
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:117
void SetEnd(int x, int y)
Definition: eda_rect.h:192
Define a library symbol object.
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
int GetPenWidth() const override
Definition: lib_pin.cpp:168
bool IsVisible() const
Definition: lib_pin.h:147
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:115
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:837
int GetNameTextSize() const
Definition: lib_pin.h:174
void print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print a pin, with or without the pin texts.
Definition: lib_pin.cpp:174
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:228
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:645
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_pin.cpp:975
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_item.cpp:50
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1168
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:96
void GRText(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 GRText Draw a graphic text (like footprint texts)
Definition: gr_text.cpp:131
void SetConvert(int aConvert)
Definition: lib_item.h:298
wxPoint GetPosition() const override
Definition: lib_pin.h:258
void MoveTo(const wxPoint &pos)
Definition: plotter.h:267
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int m_attributes
Definition: lib_pin.h:71
EDA_UNITS
Definition: eda_units.h:38
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:254
void Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
BITMAP_DEF ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:250
void SetUnit(int aUnit)
Definition: lib_item.h:295
Base plotter engine class.
Definition: plotter.h:131
wxPoint m_position
Definition: lib_pin.h:66
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:165
int GetNumberTextSize() const
Definition: lib_pin.h:177
see class PGM_BASE
void SetName(const wxString &aName)
Definition: lib_pin.h:157
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
#define _(s)
Definition: 3d_actions.cpp:33
#define PIN_TEXT_MARGIN
Definition: lib_pin.cpp:41
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:594
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:38
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:70
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
Definition: eda_rect.cpp:150
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:70
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:220
int GetDefaultPenWidth() const
static int externalPinDecoSize(RENDER_SETTINGS *aSettings, const LIB_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
Definition: lib_pin.cpp:85
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:137
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
void Plot(PLOTTER *aPlotter, const wxPoint &aPffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:960
not connected (must be left open)
STATUS_FLAGS m_flags
Definition: eda_item.h:164
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:889
Message panel definition file.
static constexpr int Millimeter2iu(double mm)
virtual int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:74
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:905
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100