KiCad PCB EDA Suite
class_libentry.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) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <macros.h>
32 #include <kicad_string.h>
33 #include <class_drawpanel.h>
34 #include <plotter.h>
35 #include <gr_basic.h>
36 #include <sch_screen.h>
37 #include <richio.h>
38 #include <kicad_string.h>
39 #include <trace_helpers.h>
40 
41 #include <general.h>
42 #include <template_fieldnames.h>
43 #include <transform.h>
44 #include <class_library.h>
45 #include <class_libentry.h>
46 #include <lib_pin.h>
47 #include <lib_arc.h>
48 #include <lib_bezier.h>
49 #include <lib_circle.h>
50 #include <lib_polyline.h>
51 #include <lib_rectangle.h>
52 #include <lib_text.h>
53 
54 
55 // the separator char between the subpart id and the reference
56 // 0 (no separator) or '.' or some other character
58 
59 // the ascii char value to calculate the subpart symbol id from the part number:
60 // 'A' or '1' usually. (to print U1.A or U1.1)
61 // if this a a digit, a number is used as id symbol
63 
64 
65 LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_PART* aRootPart ):
67  shared( aRootPart )
68 {
69  SetName( aName );
70 }
71 
72 
73 LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootPart ) :
74  EDA_ITEM( aAlias ),
75  shared( aRootPart )
76 {
77  name = aAlias.name;
78 
79  description = aAlias.description;
80  keyWords = aAlias.keyWords;
81  docFileName = aAlias.docFileName;
82 }
83 
84 
86 {
87  wxLogTrace( traceSchLibMem, wxT( "%s: destroying alias:'%s'" ),
88  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ), GetChars( GetName() ) );
89 
90  wxCHECK_RET( shared, wxT( "~LIB_ALIAS() without a LIB_PART" ) );
91 
92  if( shared )
93  shared->RemoveAlias( this );
94 }
95 
96 
97 const wxString LIB_ALIAS::GetLibraryName()
98 {
99  wxASSERT_MSG( shared, wxT( "LIB_ALIAS without a LIB_PART" ) );
100 
101  if( shared )
102  return shared->GetLibraryName();
103 
104  return wxString( _( "none" ) );
105 }
106 
107 
108 bool LIB_ALIAS::IsRoot() const
109 {
110  return name == shared->GetName();
111 }
112 
113 
115 {
116  return shared->GetLib();
117 }
118 
119 
120 void LIB_ALIAS::SetName( const wxString& aName )
121 {
122  name = aName;
123  ValidateName( name );
124 }
125 
126 
127 void LIB_ALIAS::ValidateName( wxString& aName )
128 {
129  // they are same as illegal filename chars, but the ':' is allowed
130  // only because it is used to create symbol names in lib cache
131  static const wxString illegalSymbolNameChars( "\\/\"<>|" );
132 
133  for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
134  {
135  if( illegalSymbolNameChars.Find( *it ) != wxNOT_FOUND )
136  *it = '_';
137  }
138 }
139 
140 
141 bool LIB_ALIAS::operator==( const wxChar* aName ) const
142 {
143  return name == aName;
144 }
145 
146 
147 bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
148 {
149  return aItem1.GetName() < aItem2.GetName();
150 }
151 
152 
153 int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
154 {
155  return aItem1->GetName().Cmp( aItem2->GetName() );
156 }
157 
158 
161 {
162  void operator()(void const *) const
163  {
164  }
165 };
166 
167 
168 LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
169  EDA_ITEM( LIB_PART_T ),
170  m_me( this, null_deleter() )
171 {
172  m_dateLastEdition = 0;
173  m_unitCount = 1;
174  m_pinNameOffset = 40;
176  m_unitsLocked = false;
177  m_showPinNumbers = true;
178  m_showPinNames = true;
179 
180  // Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
181  // when the field editors are invoked.
186 
187  SetLib( aLibrary );
188  SetName( aName );
189 }
190 
191 
192 LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
193  EDA_ITEM( aPart ),
194  m_me( this, null_deleter() )
195 {
196  LIB_ITEM* newItem;
197 
198  m_library = aLibrary;
200  m_unitCount = aPart.m_unitCount;
206  m_options = aPart.m_options;
207  m_libId = aPart.m_libId;
208 
209  for( LIB_ITEM& oldItem : aPart.m_drawings )
210  {
211  if( oldItem.IsNew() )
212  continue;
213 
214  newItem = (LIB_ITEM*) oldItem.Clone();
215  newItem->SetParent( this );
216  m_drawings.push_back( newItem );
217  }
218 
219  for( size_t i = 0; i < aPart.m_aliases.size(); i++ )
220  {
221  LIB_ALIAS* alias = new LIB_ALIAS( *aPart.m_aliases[i], this );
222  m_aliases.push_back( alias );
223  }
224 }
225 
226 
228 {
229  wxLogTrace( traceSchLibMem,
230  wxT( "%s: destroying symbol with alias list count of %llu" ),
231  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ),
232  (long long unsigned) m_aliases.size() );
233 
234  // If the part is being deleted directly rather than through the library,
235  // delete all of the aliases.
236  while( m_aliases.size() )
237  {
238  LIB_ALIAS* alias = m_aliases.back();
239  m_aliases.pop_back();
240  delete alias;
241  }
242 }
243 
244 
245 const wxString LIB_PART::GetLibraryName()
246 {
247  if( m_library )
248  return m_library->GetName();
249 
250  return wxString( _( "none" ) );
251 }
252 
253 
254 wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
255 {
256  wxString subRef;
257 
258  if( m_subpartIdSeparator != 0 && aAddSeparator )
259  subRef << wxChar( m_subpartIdSeparator );
260 
261  if( m_subpartFirstId >= '0' && m_subpartFirstId <= '9' )
262  subRef << aUnit;
263  else
264  {
265  // use letters as notation. To allow more than 26 units, the sub ref
266  // use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
267  // first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
268  int u;
269  aUnit -= 1; // Unit number starts to 1. now to 0.
270 
271  while( aUnit >= 26 ) // more than one letter are needed
272  {
273  u = aUnit / 26;
274  subRef << wxChar( m_subpartFirstId + u -1 );
275  aUnit %= 26;
276  }
277 
278  u = m_subpartFirstId + aUnit;
279  subRef << wxChar( u );
280  }
281 
282  return subRef;
283 }
284 
285 
286 const wxString& LIB_PART::GetName() const
287 {
288  static wxString dummy;
289 
290  wxCHECK_MSG( m_aliases.size(), dummy, "no aliases defined for symbol" );
291 
292  return m_aliases[0]->GetName();
293 }
294 
295 
296 void LIB_PART::SetName( const wxString& aName )
297 {
298  // The LIB_ALIAS that is the LIB_PART name has to be created so create it.
299  if( m_aliases.empty() )
300  m_aliases.push_back( new LIB_ALIAS( aName, this ) );
301  else
302  m_aliases[0]->SetName( aName );
303 
304  // LIB_ALIAS validates the name, reuse it instead of validating the name again
305  wxString validatedName( m_aliases[0]->GetName() );
306  m_libId.SetLibItemName( validatedName, false );
307 
308  LIB_FIELD& valueField = GetValueField();
309 
310  // LIB_FIELD::SetText() calls LIB_PART::SetName(),
311  // the following if-clause is to break an infinite loop
312  if( valueField.GetText() != validatedName )
313  valueField.SetText( validatedName );
314 }
315 
316 
317 void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
318  int aMulti, int aConvert, const PART_DRAW_OPTIONS& aOpts )
319 {
320  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
321 
322  GRSetDrawMode( aDc, aOpts.draw_mode );
323 
324  /* draw background for filled items using background option
325  * Solid lines will be drawn after the background
326  * Note also, background is not drawn when:
327  * printing in black and white
328  * If the color is not the default color (aColor != -1 )
329  */
330  if( ! ( screen && screen->m_IsPrinting && GetGRForceBlackPenState() )
331  && ( aOpts.color == COLOR4D::UNSPECIFIED ) )
332  {
333  for( LIB_ITEM& drawItem : m_drawings )
334  {
335  if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
336  continue;
337 
338  if( aOpts.only_selected && !drawItem.IsSelected() )
339  continue;
340 
341  // Do not draw an item while moving (the cursor handler does that)
342  if( drawItem.m_Flags & IS_MOVED )
343  continue;
344 
345  // Do not draw items not attached to the current part
346  if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
347  continue;
348 
349  if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
350  continue;
351 
352  if( drawItem.Type() == LIB_FIELD_T )
353  continue;
354 
355  if( drawItem.Type() == LIB_FIELD_T ) // TODO dead code?
356  {
357  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
358  aOpts.draw_mode, (void*) NULL, aOpts.transform );
359  }
360 
361  // Now, draw only the background for items with
362  // m_Fill == FILLED_WITH_BG_BODYCOLOR:
363  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
364  aOpts.draw_mode, (void*) false, aOpts.transform );
365  }
366  }
367 
368  // Track the index into the dangling pins list
369  size_t pin_index = 0;
370 
371  for( LIB_ITEM& drawItem : m_drawings )
372  {
373  if( aOpts.only_selected && !drawItem.IsSelected() )
374  continue;
375 
376  // Do not draw an item while moving (the cursor handler does that)
377  if( drawItem.m_Flags & IS_MOVED )
378  continue;
379 
380  // Do not draw items not attached to the current part
381  if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
382  continue;
383 
384  if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
385  continue;
386 
387  if( drawItem.Type() == LIB_FIELD_T )
388  {
389  LIB_FIELD& field = dynamic_cast<LIB_FIELD&>( drawItem );
390 
391  if( field.IsVisible() && !aOpts.draw_visible_fields )
392  continue;
393 
394  if( !field.IsVisible() && !aOpts.draw_hidden_fields )
395  continue;
396  }
397 
398  if( drawItem.Type() == LIB_PIN_T )
399  {
400  LIB_PIN& pin = dynamic_cast<LIB_PIN&>( drawItem );
401 
402  uintptr_t flags = 0;
403  if( aOpts.show_pin_text )
404  flags |= PIN_DRAW_TEXTS;
405 
406  if( aOpts.show_elec_type )
408 
409  if( aOpts.PinIsDangling( pin_index ) )
410  flags |= PIN_DRAW_DANGLING;
411 
412  if( pin.IsPowerConnection() && IsPower() )
413  flags |= PIN_DANGLING_HIDDEN;
414 
415  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
416  aOpts.draw_mode, (void*) flags, aOpts.transform );
417 
418  ++pin_index;
419  }
420  else if( drawItem.Type() == LIB_FIELD_T )
421  {
422  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
423  aOpts.draw_mode, (void*) NULL, aOpts.transform );
424  }
425  else
426  {
427  bool forceNoFill = drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR;
428  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
429  aOpts.draw_mode, (void*) forceNoFill,
430  aOpts.transform );
431  }
432  }
433 
434  // Enable this to draw the anchor of the component.
435 #if 0
436  int len = aDc->DeviceToLogicalXRel( 3 );
437  EDA_RECT* const clipbox = aPanel ? aPanel->GetClipBox() : NULL;
438 
439  GRLine( clipbox, aDc, aOffset.x, aOffset.y - len, aOffset.x,
440  aOffset.y + len, 0, aOpts.color );
441  GRLine( clipbox, aDc, aOffset.x - len, aOffset.y, aOffset.x + len,
442  aOffset.y, 0, aOpts.color );
443 #endif
444 
445  /* Enable this to draw the bounding box around the component to validate
446  * the bounding box calculations. */
447 #if 0
448  EDA_RECT bBox = GetUnitBoundingBox( aMulti, aConvert );
449  bBox.RevertYAxis();
450  bBox = aOpts.transform.TransformCoordinate( bBox );
451  bBox.Move( aOffset );
452  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox, 0, LIGHTMAGENTA );
453 #endif
454 }
455 
456 
457 void LIB_PART::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
458  const wxPoint& aOffset, const TRANSFORM& aTransform )
459 {
460  wxASSERT( aPlotter != NULL );
461 
462  aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
463  bool fill = aPlotter->GetColorMode();
464 
465  // draw background for filled items using background option
466  // Solid lines will be drawn after the background
467  for( LIB_ITEM& item : m_drawings )
468  {
469  // Lib Fields are not plotted here, because this plot function
470  // is used to plot schematic items, which have they own fields
471  if( item.Type() == LIB_FIELD_T )
472  continue;
473 
474  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
475  continue;
476 
477  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
478  continue;
479 
480  if( item.m_Fill == FILLED_WITH_BG_BODYCOLOR )
481  item.Plot( aPlotter, aOffset, fill, aTransform );
482  }
483 
484  // Not filled items and filled shapes are now plotted
485  // (plot only items which are not already plotted)
486  for( LIB_ITEM& item : m_drawings )
487  {
488  if( item.Type() == LIB_FIELD_T )
489  continue;
490 
491  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
492  continue;
493 
494  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
495  continue;
496 
497  if( item.m_Fill != FILLED_WITH_BG_BODYCOLOR )
498  item.Plot( aPlotter, aOffset, fill, aTransform );
499  }
500 }
501 
502 
503 void LIB_PART::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
504  const wxPoint& aOffset, const TRANSFORM& aTransform )
505 {
506  wxASSERT( aPlotter != NULL );
507 
508  aPlotter->SetColor( GetLayerColor( LAYER_FIELDS ) );
509  bool fill = aPlotter->GetColorMode();
510 
511  for( LIB_ITEM& item : m_drawings )
512  {
513  if( item.Type() != LIB_FIELD_T )
514  continue;
515 
516  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
517  continue;
518 
519  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
520  continue;
521 
522  // The reference is a special case: we should change the basic text
523  // to add '?' and the part id
524  LIB_FIELD& field = (LIB_FIELD&) item;
525  wxString tmp = field.GetShownText();
526  if( field.GetId() == REFERENCE )
527  {
528  wxString text = field.GetFullText( aUnit );
529  field.SetText( text );
530  }
531  item.Plot( aPlotter, aOffset, fill, aTransform );
532  field.SetText( tmp );
533  }
534 }
535 
536 
537 void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc )
538 {
539  wxASSERT( aItem != NULL );
540 
541  // none of the MANDATORY_FIELDS may be removed in RAM, but they may be
542  // omitted when saving to disk.
543  if( aItem->Type() == LIB_FIELD_T )
544  {
545  LIB_FIELD* field = (LIB_FIELD*) aItem;
546 
547  if( field->GetId() < MANDATORY_FIELDS )
548  {
549  wxLogWarning( _(
550  "An attempt was made to remove the %s field from component %s in library %s." ),
551  GetChars( field->GetName() ), GetChars( GetName() ),
552  GetChars( GetLibraryName() ) );
553  return;
554  }
555  }
556 
557  LIB_ITEMS& items = m_drawings[ aItem->Type() ];
558 
559  for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
560  {
561  if( *i == aItem )
562  {
563  if( aDc != NULL )
564  aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED,
565  g_XorMode, NULL, DefaultTransform );
566 
567  items.erase( i );
568  SetModified();
569  break;
570  }
571  }
572 }
573 
574 
576 {
577  wxASSERT( aItem != NULL );
578 
579  m_drawings.push_back( aItem );
580 }
581 
582 
584 {
585  if( m_drawings.empty( aType ) )
586  return NULL;
587 
588  if( aItem == NULL )
589  return &( *( m_drawings.begin( aType ) ) );
590 
591  // Search for the last item, assume aItem is of type aType
592  wxASSERT( ( aType == TYPE_NOT_INIT ) || ( aType == aItem->Type() ) );
594 
595  while( ( it != m_drawings.end( aType ) ) && ( aItem != &( *it ) ) )
596  ++it;
597 
598  // Search the next item
599  if( it != m_drawings.end( aType ) )
600  {
601  ++it;
602 
603  if( it != m_drawings.end( aType ) )
604  return &( *it );
605  }
606 
607  return NULL;
608 }
609 
610 
611 void LIB_PART::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
612 {
613  if( m_drawings.empty( LIB_PIN_T ) )
614  return;
615 
616  /* Notes:
617  * when aUnit == 0: no unit filtering
618  * when aConvert == 0: no convert (shape selection) filtering
619  * when .m_Unit == 0, the body item is common to units
620  * when .m_Convert == 0, the body item is common to shapes
621  */
622  for( LIB_ITEM& item : m_drawings[ LIB_PIN_T ] )
623  {
624  // Unit filtering:
625  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
626  continue;
627 
628  // Shape filtering:
629  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
630  continue;
631 
632  aList.push_back( (LIB_PIN*) &item );
633  }
634 }
635 
636 
637 LIB_PIN* LIB_PART::GetPin( const wxString& aNumber, int aUnit, int aConvert )
638 {
639  LIB_PINS pinList;
640 
641  GetPins( pinList, aUnit, aConvert );
642 
643  for( size_t i = 0; i < pinList.size(); i++ )
644  {
645  wxASSERT( pinList[i]->Type() == LIB_PIN_T );
646 
647  if( aNumber == pinList[i]->GetNumber() )
648  return pinList[i];
649  }
650 
651  return NULL;
652 }
653 
654 
655 bool LIB_PART::PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
656  bool aTestType, bool aTestOrientation, bool aTestLength )
657 {
658  LIB_PINS thisPinList;
659  GetPins( thisPinList, /* aUnit */ 0, /* aConvert */ 0 );
660 
661  for( LIB_PIN* eachThisPin : thisPinList )
662  {
663  wxASSERT( eachThisPin );
664  LIB_PINS otherPinList;
665  aOtherPart.GetPins( otherPinList, /* aUnit */ 0, /* aConvert */ 0 );
666  bool foundMatch = false;
667 
668  for( LIB_PIN* eachOtherPin : otherPinList )
669  {
670  wxASSERT( eachOtherPin );
671  // Same position?
672  if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
673  continue;
674 
675  // Same number?
676  if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ))
677  continue;
678 
679  // Same name?
680  if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ))
681  continue;
682 
683  // Same electrical type?
684  if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ))
685  continue;
686 
687  // Same orientation?
688  if( aTestOrientation && ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ))
689  continue;
690 
691  // Same length?
692  if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ))
693  continue;
694 
695  foundMatch = true;
696  }
697 
698  if( !foundMatch )
699  {
700  // This means there was not an identical (according to the arguments)
701  // pin at the same position in the other component.
702  return true;
703  }
704  }
705 
706  // The loop never gave up, so no conflicts were found.
707  return false;
708 }
709 
710 
711 const EDA_RECT LIB_PART::GetUnitBoundingBox( int aUnit, int aConvert ) const
712 {
713  EDA_RECT bBox;
714  bool initialized = false;
715 
716  for( const LIB_ITEM& item : m_drawings )
717  {
718  if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
719  && ( aUnit != item.m_Unit ) ) )
720  continue;
721 
722  if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
723  continue;
724 
725  if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
726  continue;
727 
728  if( initialized )
729  bBox.Merge( item.GetBoundingBox() );
730  else
731  {
732  bBox = item.GetBoundingBox();
733  initialized = true;
734  }
735  }
736 
737  return bBox;
738 }
739 
740 
741 const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
742 {
743  EDA_RECT bBox;
744  bool initialized = false;
745 
746  for( const LIB_ITEM& item : m_drawings )
747  {
748  if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
749  && ( aUnit != item.m_Unit ) ) )
750  continue;
751 
752  if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
753  continue;
754 
755  if( item.Type() == LIB_FIELD_T )
756  continue;
757 
758  if( initialized )
759  bBox.Merge( item.GetBoundingBox() );
760  else
761  {
762  bBox = item.GetBoundingBox();
763  initialized = true;
764  }
765  }
766 
767  return bBox;
768 }
769 
770 
772 {
773  m_drawings[ LIB_FIELD_T ].clear();
774 }
775 
776 
777 void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
778 {
779  deleteAllFields();
780 
781  for( unsigned i=0; i<aFields.size(); ++i )
782  {
783  // drawings is a ptr_vector, new and copy an object on the heap.
784  LIB_FIELD* field = new LIB_FIELD( aFields[i] );
785 
786  field->SetParent( this );
787  m_drawings.push_back( field );
788  }
789 }
790 
791 
793 {
794  LIB_FIELD* field;
795 
796  // The only caller of this function is the library field editor, so it
797  // establishes policy here.
798 
799  // Grab the MANDATORY_FIELDS first, in expected order given by
800  // enum NumFieldType
801  for( int id=0; id<MANDATORY_FIELDS; ++id )
802  {
803  field = GetField( id );
804 
805  // the MANDATORY_FIELDS are exactly that in RAM.
806  wxASSERT( field );
807 
808  aList.push_back( *field );
809  }
810 
811  // Now grab all the rest of fields.
812  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
813  {
814  field = ( LIB_FIELD* ) &item;
815 
816  if( (unsigned) field->GetId() < MANDATORY_FIELDS )
817  continue; // was added above
818 
819  aList.push_back( *field );
820  }
821 }
822 
823 
825 {
826  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
827  {
828  LIB_FIELD* field = ( LIB_FIELD* ) &item;
829 
830  if( field->GetId() == aId )
831  return field;
832  }
833 
834  return NULL;
835 }
836 
837 
838 LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName )
839 {
840  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
841  {
842  LIB_FIELD* field = ( LIB_FIELD* ) &item;
843 
844  if( field->GetName() == aFieldName )
845  return field;
846  }
847 
848  return NULL;
849 }
850 
851 
853 {
854  LIB_FIELD* field = GetField( VALUE );
855  wxASSERT( field != NULL );
856  return *field;
857 }
858 
859 
861 {
862  LIB_FIELD* field = GetField( REFERENCE );
863  wxASSERT( field != NULL );
864  return *field;
865 }
866 
867 
869 {
870  LIB_FIELD* field = GetField( FOOTPRINT );
871  wxASSERT( field != NULL );
872  return *field;
873 }
874 
875 
877 {
878  int year, mon, day, hour, min, sec;
879 
880  if( m_dateLastEdition == 0 )
881  return true;
882 
883  sec = m_dateLastEdition & 63;
884  min = ( m_dateLastEdition >> 6 ) & 63;
885  hour = ( m_dateLastEdition >> 12 ) & 31;
886  day = ( m_dateLastEdition >> 17 ) & 31;
887  mon = ( m_dateLastEdition >> 22 ) & 15;
888  year = ( m_dateLastEdition >> 26 ) + 1990;
889 
890  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
891 
892  return true;
893 }
894 
895 
896 bool LIB_PART::LoadDateAndTime( char* aLine )
897 {
898  int year, mon, day, hour, min, sec;
899 
900  year = mon = day = hour = min = sec = 0;
901  strtok( aLine, " \r\t\n" );
902  strtok( NULL, " \r\t\n" );
903 
904  if( sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
905  return false;
906 
907  m_dateLastEdition = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
908  ( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
909  ( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
910 
911  return true;
912 }
913 
914 
915 void LIB_PART::SetOffset( const wxPoint& aOffset )
916 {
917  for( LIB_ITEM& item : m_drawings )
918  item.SetOffset( aOffset );
919 }
920 
921 
923 {
924  m_drawings.unique();
925 }
926 
927 
929 {
930  for( const LIB_ITEM& item : m_drawings )
931  {
932  if( item.m_Convert > 1 )
933  return true;
934  }
935 
936  return false;
937 }
938 
939 
941 {
942  for( LIB_ITEM& item : m_drawings )
943  {
944  item.m_Flags = 0;
945  }
946 }
947 
948 
949 int LIB_PART::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aSyncPinEdit )
950 {
951  int itemCount = 0;
952 
953  for( LIB_ITEM& item : m_drawings )
954  {
955  item.ClearFlags( SELECTED );
956 
957  if( ( item.m_Unit && item.m_Unit != aUnit )
958  || ( item.m_Convert && item.m_Convert != aConvert ) )
959  {
960  if( item.Type() != LIB_PIN_T )
961  continue;
962 
963  // Specific rules for pins:
964  // - do not select pins in other units when synchronized pin edit mode is disabled
965  // - do not select pins in other units when units are not interchangeable
966  // - in other cases verify if the pin belongs to the requested unit
967  if( !aSyncPinEdit || m_unitsLocked
968  || ( item.m_Convert && item.m_Convert != aConvert ) )
969  continue;
970  }
971 
972  if( item.Inside( aRect ) )
973  {
974  item.SetFlags( SELECTED );
975  itemCount++;
976  }
977  }
978 
979  return itemCount;
980 }
981 
982 
983 void LIB_PART::MoveSelectedItems( const wxPoint& aOffset )
984 {
985  for( LIB_ITEM& item : m_drawings )
986  {
987  if( !item.IsSelected() )
988  continue;
989 
990  item.SetOffset( aOffset );
991  item.m_Flags = 0;
992  }
993 }
994 
995 
997 {
998  for( LIB_ITEM& item : m_drawings )
999  {
1000  item.m_Flags = 0;
1001  }
1002 }
1003 
1004 
1006 {
1008 
1009  // We *do not* remove the 2 mandatory fields: reference and value
1010  // so skip them (do not remove) if they are flagged selected.
1011  // Skip also not visible items.
1012  // But I think fields must not be deleted by a block delete command or other global command
1013  // because they are not really graphic items
1014  while( item != m_drawings.end() )
1015  {
1016  if( item->Type() == LIB_FIELD_T )
1017  {
1018  item->ClearFlags( SELECTED );
1019  }
1020 
1021  if( !item->IsSelected() )
1022  ++item;
1023  else
1024  item = m_drawings.erase( item );
1025  }
1026 }
1027 
1028 
1029 void LIB_PART::CopySelectedItems( const wxPoint& aOffset )
1030 {
1031  std::vector< LIB_ITEM* > tmp;
1032 
1033  for( LIB_ITEM& item : m_drawings )
1034  {
1035  // We *do not* copy fields because they are unique for the whole component
1036  // so skip them (do not duplicate) if they are flagged selected.
1037  if( item.Type() == LIB_FIELD_T )
1038  item.ClearFlags( SELECTED );
1039 
1040  if( !item.IsSelected() )
1041  continue;
1042 
1043  item.ClearFlags( SELECTED );
1044  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1045  newItem->SetFlags( SELECTED );
1046 
1047  // When push_back elements in buffer, a memory reallocation can happen
1048  // and will break pointers.
1049  // So, push_back later.
1050  tmp.push_back( newItem );
1051  }
1052 
1053  for( auto item : tmp )
1054  m_drawings.push_back( item );
1055 
1056  MoveSelectedItems( aOffset );
1057 }
1058 
1059 
1061 {
1062  for( LIB_ITEM& item : m_drawings )
1063  {
1064  if( !item.IsSelected() )
1065  continue;
1066 
1067  item.MirrorHorizontal( aCenter );
1068  item.m_Flags = 0;
1069  }
1070 }
1071 
1072 
1074 {
1075  for( LIB_ITEM& item : m_drawings )
1076  {
1077  if( !item.IsSelected() )
1078  continue;
1079 
1080  item.MirrorVertical( aCenter );
1081  item.m_Flags = 0;
1082  }
1083 }
1084 
1085 
1087 {
1088  for( LIB_ITEM& item : m_drawings )
1089  {
1090  if( !item.IsSelected() )
1091  continue;
1092 
1093  item.Rotate( aCenter );
1094  item.m_Flags = 0;
1095  }
1096 }
1097 
1098 
1099 LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert,
1100  KICAD_T aType, const wxPoint& aPoint )
1101 {
1102  for( LIB_ITEM& item : m_drawings )
1103  {
1104  if( ( aUnit && item.m_Unit && ( aUnit != item.m_Unit) )
1105  || ( aConvert && item.m_Convert && ( aConvert != item.m_Convert ) )
1106  || ( ( item.Type() != aType ) && ( aType != TYPE_NOT_INIT ) ) )
1107  continue;
1108 
1109  if( item.HitTest( aPoint ) )
1110  return &item;
1111  }
1112 
1113  return NULL;
1114 }
1115 
1116 
1117 LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
1118  const wxPoint& aPoint, const TRANSFORM& aTransform )
1119 {
1120  /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1121  * wxPoint& pt ) to search items.
1122  * because this function uses DefaultTransform as orient/mirror matrix
1123  * we temporary copy aTransform in DefaultTransform
1124  */
1125  LIB_ITEM* item;
1126  TRANSFORM transform = DefaultTransform;
1127  DefaultTransform = aTransform;
1128 
1129  item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
1130 
1131  // Restore matrix
1132  DefaultTransform = transform;
1133 
1134  return item;
1135 }
1136 
1137 
1138 void LIB_PART::SetUnitCount( int aCount )
1139 {
1140  if( m_unitCount == aCount )
1141  return;
1142 
1143  if( aCount < m_unitCount )
1144  {
1146 
1147  while( i != m_drawings.end() )
1148  {
1149  if( i->m_Unit > aCount )
1150  i = m_drawings.erase( i );
1151  else
1152  ++i;
1153  }
1154  }
1155  else
1156  {
1157  int prevCount = m_unitCount;
1158 
1159  // Temporary storage for new items, as adding new items directly to
1160  // m_drawings may cause the buffer reallocation which invalidates the
1161  // iterators
1162  std::vector< LIB_ITEM* > tmp;
1163 
1164  for( LIB_ITEM& item : m_drawings )
1165  {
1166  if( item.m_Unit != 1 )
1167  continue;
1168 
1169  for( int j = prevCount + 1; j <= aCount; j++ )
1170  {
1171  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1172  newItem->m_Unit = j;
1173  tmp.push_back( newItem );
1174  }
1175  }
1176 
1177  for( auto item : tmp )
1178  m_drawings.push_back( item );
1179  }
1180 
1181  m_unitCount = aCount;
1182 }
1183 
1184 
1185 void LIB_PART::SetConversion( bool aSetConvert )
1186 {
1187  if( aSetConvert == HasConversion() )
1188  return;
1189 
1190  // Duplicate items to create the converted shape
1191  if( aSetConvert )
1192  {
1193  std::vector< LIB_ITEM* > tmp; // Temporarily store the duplicated pins here.
1194 
1195  for( LIB_ITEM& item : m_drawings )
1196  {
1197  // Only pins are duplicated.
1198  if( item.Type() != LIB_PIN_T )
1199  continue;
1200 
1201  if( item.m_Convert == 1 )
1202  {
1203  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1204  newItem->m_Convert = 2;
1205  tmp.push_back( newItem );
1206  }
1207  }
1208 
1209  // Transfer the new pins to the LIB_PART.
1210  for( unsigned i = 0; i < tmp.size(); i++ )
1211  m_drawings.push_back( tmp[i] );
1212  }
1213  else
1214  {
1215  // Delete converted shape items because the converted shape does
1216  // not exist
1218 
1219  while( i != m_drawings.end() )
1220  {
1221  if( i->m_Convert > 1 )
1222  i = m_drawings.erase( i );
1223  else
1224  ++i;
1225  }
1226  }
1227 }
1228 
1229 
1230 wxArrayString LIB_PART::GetAliasNames( bool aIncludeRoot ) const
1231 {
1232  wxArrayString names;
1233 
1234  LIB_ALIASES::const_iterator it;
1235 
1236  for( it=m_aliases.begin(); it != m_aliases.end(); ++it )
1237  {
1238  if( !aIncludeRoot && (*it)->IsRoot() )
1239  continue;
1240 
1241  names.Add( (*it)->GetName() );
1242  }
1243 
1244  return names;
1245 }
1246 
1247 
1248 bool LIB_PART::HasAlias( const wxString& aName ) const
1249 {
1250  wxCHECK2_MSG( !aName.IsEmpty(), return false,
1251  wxT( "Cannot get alias with an empty name, bad programmer." ) );
1252 
1253  for( size_t i = 0; i < m_aliases.size(); i++ )
1254  {
1255  if( aName == m_aliases[i]->GetName() )
1256  return true;
1257  }
1258 
1259  return false;
1260 }
1261 
1262 
1263 void LIB_PART::SetAliases( const wxArrayString& aAliasList )
1264 {
1265  wxCHECK_RET( !m_library,
1266  wxT( "Symbol aliases cannot be changed when they are owned by a library." ) );
1267  wxCHECK_RET( !aAliasList.IsEmpty(), wxT( "Alias list cannot be empty" ) );
1268 
1269  if( aAliasList == GetAliasNames() )
1270  return;
1271 
1272  // Add names not existing in the current component alias list.
1273  for( size_t i = 0; i < aAliasList.GetCount(); i++ )
1274  {
1275  if( HasAlias( aAliasList[ i ] ) )
1276  continue;
1277 
1278  m_aliases.push_back( new LIB_ALIAS( aAliasList[ i ], this ) );
1279  }
1280 
1281  // Remove names in the current component that are not in the new alias list.
1282  LIB_ALIASES::iterator it = m_aliases.begin();
1283 
1284  while( it != m_aliases.end() )
1285  {
1286  int index = aAliasList.Index( (*it)->GetName(), false );
1287 
1288  if( index != wxNOT_FOUND || (*it)->IsRoot() )
1289  ++it;
1290  else
1291  it = m_aliases.erase( it );
1292  }
1293 }
1294 
1295 
1296 void LIB_PART::RemoveAlias( const wxString& aName )
1297 {
1298  LIB_ALIAS* a = GetAlias( aName );
1299 
1300  if( a )
1301  RemoveAlias( a );
1302 }
1303 
1304 
1306 {
1307  wxCHECK_MSG( aAlias, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
1308 
1309  LIB_ALIAS* nextAlias = NULL;
1310 
1311  LIB_ALIASES::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
1312 
1313  if( it != m_aliases.end() )
1314  {
1315  bool rename = aAlias->IsRoot();
1316 
1317  wxLogTrace( traceSchLibMem,
1318  wxT( "%s: symbol:'%s', alias:'%s', alias count %llu, reference count %ld." ),
1319  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ),
1320  GetChars( GetName() ),
1321  GetChars( aAlias->GetName() ),
1322  (long long unsigned) m_aliases.size(),
1323  m_me.use_count() );
1324 
1325  it = m_aliases.erase( it );
1326 
1327  if( !m_aliases.empty() )
1328  {
1329  if( it == m_aliases.end() )
1330  it = m_aliases.begin();
1331 
1332  nextAlias = *it;
1333 
1334  if( rename )
1335  SetName( nextAlias->GetName() );
1336  }
1337  }
1338 
1339  return nextAlias;
1340 }
1341 
1342 
1344 {
1345  // Remove all of the aliases except the root alias.
1346  while( m_aliases.size() > 1 )
1347  m_aliases.pop_back();
1348 }
1349 
1350 
1351 LIB_ALIAS* LIB_PART::GetAlias( const wxString& aName )
1352 {
1353  wxCHECK2_MSG( !aName.IsEmpty(), return NULL,
1354  wxT( "Cannot get alias with an empty name. Bad programmer!" ) );
1355 
1356  for( size_t i = 0; i < m_aliases.size(); i++ )
1357  {
1358  if( aName == m_aliases[i]->GetName() )
1359  return m_aliases[i];
1360  }
1361 
1362  return NULL;
1363 }
1364 
1365 
1367 {
1368  wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL,
1369  wxT( "Illegal alias list index, bad programmer." ) );
1370 
1371  return m_aliases[aIndex];
1372 }
1373 
1374 
1375 void LIB_PART::AddAlias( const wxString& aName )
1376 {
1377  wxCHECK_RET( !HasAlias( aName ),
1378  wxT( "Symbol <" ) + GetName() + wxT( "> already has an alias <" ) +
1379  aName + wxT( ">. Bad programmer." ) );
1380 
1381  m_aliases.push_back( new LIB_ALIAS( aName, this ) );
1382 }
1383 
1384 
1385 void LIB_PART::SetSubpartIdNotation( int aSep, int aFirstId )
1386 {
1387  m_subpartFirstId = 'A';
1389 
1390  if( aSep == '.' || aSep == '-' || aSep == '_' )
1391  m_subpartIdSeparator = aSep;
1392 
1393  if( aFirstId == '1' && aSep != 0 )
1394  m_subpartFirstId = aFirstId;
1395 }
timestamp_t m_dateLastEdition
Date of the last modification.
LIB_ALIASES m_aliases
List of alias object pointers associated with the part.
PART_LIB * GetLib()
virtual ~LIB_ALIAS()
LIB_FIELD & GetFootprintField()
Return reference to the footprint field.
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
void SetLib(PART_LIB *aLibrary)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
LIB_FIELD * GetField(int aId)
Return pointer to the requested field.
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part&#39;s pins do not match another part&#39;s pins.
void SetModified()
static int m_subpartIdSeparator
the separator char between the subpart id and the reference like U1A ( m_subpartIdSeparator = 0 ) or ...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Draw part.
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
Part library alias object definition.
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:183
bool PinIsDangling(size_t aPin) const
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
static void ValidateName(wxString &aName)
Helper function to replace illegal chars in symbol names
void SetConversion(bool aSetConvert)
Set or clear the alternate body style (DeMorgan) for the part.
virtual ~LIB_PART()
name of datasheet
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
bool m_showPinNumbers
Determines if part pin numbers are visible.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:318
wxString description
documentation for info
int LibraryEntryCompare(const LIB_ALIAS *aItem1, const LIB_ALIAS *aItem2)
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
bool IsPower() const
LIB_ALIAS * GetAlias(size_t aIndex)
bool IsNew() const
Definition: base_struct.h:227
virtual void SetColor(COLOR4D color)=0
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
int m_unitCount
Number of units (parts) per package.
const wxString GetLibraryName()
LIB_ITEM * GetNextDrawItem(LIB_ITEM *aItem=NULL, KICAD_T aType=TYPE_NOT_INIT)
Return the next draw object pointer.
PART_LIB * m_library
Library the part belongs to if any.
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
static int m_subpartFirstId
the ascii char value to calculate the subpart symbol id from the part number: only &#39;A&#39;...
void unique()
Remove duplicate elements in list.
Definition: multivector.h:238
const EDA_RECT GetBodyBoundingBox(int aUnit, int aConvert) const
Get the symbol bounding box excluding fields.
bool HasAlias(const wxString &aName) const
Test if alias aName is in part alias list.
LIB_ITEMS_CONTAINER m_drawings
Drawing items of this part.
LIB_FIELD & GetValueField()
Return reference to the value field.
int m_Unit
Unit identification for multiple parts per package.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
LIB_ALIAS(const wxString &aName, LIB_PART *aRootComponent)
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:356
void ClearSelectedItems()
Clears all the draw items marked by a block select.
void AddAlias(const wxString &aName)
Add an alias aName to the part.
LIBRENTRYOPTIONS m_options
Special part features such as POWER or NORMAL.)
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
PART_LIB * GetLib()
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
Definition: eda_rect.h:144
void operator()(void const *) const
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool draw_hidden_fields
Whether to draw "hidden" fields.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool m_unitsLocked
True if part has multiple units and changing one unit does not automatically change another unit...
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
void MirrorSelectedItemsH(const wxPoint &aCenter)
Horizontally (X axis) mirror selected draw items about a point.
This file contains miscellaneous commonly used macros and functions.
wxString name
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot Lib Fields only of the part to plotter.
void SetOffset(const wxPoint &aOffset)
Move the part aOffset.
void MirrorSelectedItemsV(const wxPoint &aCenter)
Vertically (Y axis) mirror selected draw items about a point.
bool LoadDateAndTime(char *aLine)
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:133
int m_pinNameOffset
The offset in mils to draw the pin name.
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
void deleteAllFields()
#define SELECTED
Definition: base_struct.h:116
bool IsRoot() const
void SetName(const wxString &aName)
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1098
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot lib part to plotter.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:264
LIB_FIELD * FindField(const wxString &aFieldName)
Findd a field within this part matching aFieldName and returns it or NULL if not found.
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:502
void SetUnitCount(int count)
Set the units per part count.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:224
int GetId() const
Definition: lib_field.h:138
wxString docFileName
Associate doc file name.
void CopySelectedItems(const wxPoint &aOffset)
Make a copy of the selected draw items marked by a block select.
LIB_PART * shared
Actual LIB_PART referenced by [multiple] aliases.
void RotateSelectedItems(const wxPoint &aCenter)
Rotate CCW selected draw items about a point.
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
void push_back(T *aItem)
Definition: multivector.h:169
Class LIB_ITEM definition.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
const wxString GetName() const
Return the file name without path or extension.
int SelectItems(EDA_RECT &aRect, int aUnit, int aConvert, bool aSyncPinEdit)
Checks all draw objects of part to see if they are with block.
bool operator==(const wxChar *aName) const
KEEPCASE sensitive comparison of the part entry name.
Define a library symbol object.
EDA_RECT * GetClipBox()
wxLogTrace helper definitions.
void RemoveDuplicateDrawItems()
Remove duplicate draw items from list.
wxArrayString m_FootprintList
List of suitable footprint names for the part (wild card names accepted).
bool GetColorMode() const
Definition: plotter.h:130
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:380
LIB_PART(const wxString &aName, PART_LIB *aLibrary=NULL)
bool m_IsPrinting
Definition: base_screen.h:220
LIB_ID m_libId
const wxChar *const traceSchLibMem
Flag to enable schematic library memory deletion debug output.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:432
const wxString GetLibraryName()
ITERATOR erase(const ITERATOR &aIterator)
Definition: multivector.h:174
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared ...
ITERATOR_BASE< LIB_ITEM, MULTIVECTOR< LIB_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:160
Definitions for the Eeschema program SCH_SCREEN class.
Base plotter engine class.
Definition: plotter.h:96
void SetAliases(const wxArrayString &aAliasList)
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
void ClearStatus()
Clears the status flag all draw objects in this part.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
GR_DRAWMODE draw_mode
Device context drawing mode, see wxDC.
COLOR4D color
Color to draw part in.
void RemoveAlias(const wxString &aName)
void RemoveAllAliases()
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
const wxString & GetName() const
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
bool IsVisible() const
Definition: lib_field.h:164
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or &#39;...
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
bool show_pin_text
Whether to show pin texts.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
bool only_selected
Draws only the body items that are selected, for block moves.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
bool show_elec_type
Whether to show the pin electrical type.
int m_Convert
Shape identification for alternate body styles.
const wxString & GetName() const
void MoveSelectedItems(const wxPoint &aOffset)
Move the selected draw items marked by a block select.
bool IsPowerConnection() const
Return whether this pin forms an implicit power connection: i.e., is hidden and of type POWER_IN...
Definition: lib_pin.h:367
LIB_ITEM * LocateDrawItem(int aUnit, int aConvert, KICAD_T aType, const wxPoint &aPoint)
Locate a draw object.
virtual void SetName(const wxString &aName)
Definition for part library class.
bool draw_visible_fields
Whether to draw "visible" fields.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:309
void DeleteSelectedItems()
Deletes the select draw items marked by a block select.
bool m_showPinNames
Determines if part pin names are visible.
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
#define VALUE
Object used to load, save, search, and otherwise manipulate symbol library files. ...
TRANSFORM transform
Coordinate adjustment settings.
wxString keyWords
keyword list (used for search for parts by keyword)
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
LIB_PIN * GetPin(const wxString &aNumber, int aUnit=0, int aConvert=0)
Return pin object with the requested pin aNumber.
#define min(a, b)
Definition: auxiliary.h:85
bool SaveDateAndTime(OUTPUTFORMATTER &aFormatter)
Write the date and time of part to aFile in the format: "Ti yy/mm/jj hh:mm:ss".
#define IS_MOVED
Item being moved.
Definition: base_struct.h:108
PART_SPTR m_me
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared ...