KiCad PCB EDA Suite
sch_component.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <fctsys.h>
31 #include <pgm_base.h>
32 #include <class_drawpanel.h>
33 #include <gr_basic.h>
34 #include <kicad_string.h>
35 #include <richio.h>
36 #include <schframe.h>
37 #include <plot_common.h>
38 #include <msgpanel.h>
39 #include <bitmaps.h>
40 
41 #include <general.h>
42 #include <class_library.h>
43 #include <lib_rectangle.h>
44 #include <lib_pin.h>
45 #include <lib_text.h>
46 #include <sch_component.h>
47 #include <sch_sheet.h>
48 #include <sch_sheet_path.h>
49 //#include <sch_collectors.h>
50 #include <class_netlist_object.h>
51 #include <lib_draw_item.h>
52 
54 
55 #include <wx/tokenzr.h>
56 #include <iostream>
57 
58 #define NULL_STRING "_NONAME_"
59 
65 std::string toUTFTildaText( const wxString& txt )
66 {
67  std::string ret = TO_UTF8( txt );
68 
69  for( std::string::iterator it = ret.begin(); it!=ret.end(); ++it )
70  {
71  if( (unsigned char) *it <= ' ' )
72  *it = '~';
73  }
74  return ret;
75 }
76 
77 
91 static LIB_PART* dummy()
92 {
93  static LIB_PART* part;
94 
95  if( !part )
96  {
97  part = new LIB_PART( wxEmptyString );
98 
99  LIB_RECTANGLE* square = new LIB_RECTANGLE( part );
100 
101  square->Move( wxPoint( -200, 200 ) );
102  square->SetEndPosition( wxPoint( 200, -200 ) );
103 
104  LIB_TEXT* text = new LIB_TEXT( part );
105 
106  text->SetTextSize( wxSize( 150, 150 ) );
107  text->SetText( wxString( wxT( "??" ) ) );
108 
109  part->AddDrawItem( square );
110  part->AddDrawItem( text );
111  }
112 
113  return part;
114 }
115 
116 
118  SCH_ITEM( aParent, SCH_COMPONENT_T )
119 {
120  Init( aPos );
121  m_currentSheetPath = NULL;
123 }
124 
125 
127  int convert, const wxPoint& pos, bool setNewItemFlag ) :
128  SCH_ITEM( NULL, SCH_COMPONENT_T )
129 {
130  Init( pos );
131 
132  m_unit = unit;
133  m_convert = convert;
134  m_lib_id.SetLibItemName( aPart.GetName(), false );
135  m_part = aPart.SharedPtr();
136  m_currentSheetPath = NULL;
138 
140 
141  if( setNewItemFlag )
142  m_Flags = IS_NEW | IS_MOVED;
143 
144  // Import user defined fields from the library component:
145  LIB_FIELDS libFields;
146 
147  aPart.GetFields( libFields );
148 
149  for( LIB_FIELDS::iterator it = libFields.begin(); it!=libFields.end(); ++it )
150  {
151  // Can no longer insert an empty name, since names are now keys. The
152  // field index is not used beyond the first MANDATORY_FIELDS
153  if( it->GetName().IsEmpty() )
154  continue;
155 
156  // See if field already exists (mandatory fields always exist).
157  // for mandatory fields, the name and field id are fixed, so we use the
158  // known and fixed id to get them (more reliable than names, which can be translated)
159  // for other fields (custom fields), locate the field by same name
160  // (field id has no known meaning for custom fields)
161  int idx = it->GetId();
162  SCH_FIELD* schField;
163 
164  if( idx < MANDATORY_FIELDS )
165  schField = GetField( idx );
166  else
167  schField = FindField( it->GetName() );
168 
169  if( !schField )
170  {
171  SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, it->GetName() );
172  schField = AddField( fld );
173  }
174 
175  schField->ImportValues( *it );
176  schField->SetText( it->GetText() );
177 
178  // Now the field is initialized, place it to the right position:
179  schField->SetTextPos( m_Pos + it->GetTextPos() );
180  }
181 
182  wxString msg = aPart.GetReferenceField().GetText();
183 
184  if( msg.IsEmpty() )
185  msg = wxT( "U" );
186 
187  m_prefix = msg;
188 
189  // update the reference -- just the prefix for now.
190  msg += wxT( "?" );
191  SetRef( sheet, msg );
192 
193  // Use the schematic component name instead of the library value field name.
194  GetField( VALUE )->SetText( GetLibId().GetLibItemName() );
195 }
196 
197 
199  SCH_ITEM( aComponent )
200 {
201  m_currentSheetPath = NULL;
202  m_Parent = aComponent.m_Parent;
203  m_Pos = aComponent.m_Pos;
204  m_unit = aComponent.m_unit;
205  m_convert = aComponent.m_convert;
206  m_lib_id = aComponent.m_lib_id;
207  m_part = aComponent.m_part;
208 
209  SetTimeStamp( aComponent.m_TimeStamp );
210 
211  m_transform = aComponent.m_transform;
212  m_prefix = aComponent.m_prefix;
214  m_Fields = aComponent.m_Fields;
215 
216  // Re-parent the fields, which before this had aComponent as parent
217  for( int i = 0; i<GetFieldCount(); ++i )
218  {
219  GetField( i )->SetParent( this );
220  }
221 
222  m_isDangling = aComponent.m_isDangling;
224 }
225 
226 
227 void SCH_COMPONENT::Init( const wxPoint& pos )
228 {
229  m_Pos = pos;
230  m_unit = 0; // In multi unit chip - which unit to draw.
231  m_convert = 0; // De Morgan Handling
232 
233  // The rotation/mirror transformation matrix. pos normal
235 
236  // construct only the mandatory fields, which are the first 4 only.
237  for( int i = 0; i < MANDATORY_FIELDS; ++i )
238  {
239  SCH_FIELD field( pos, i, this, TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
240 
241  if( i == REFERENCE )
242  field.SetLayer( LAYER_REFERENCEPART );
243  else if( i == VALUE )
244  field.SetLayer( LAYER_VALUEPART );
245 
246  // else keep LAYER_FIELDS from SCH_FIELD constructor
247 
248  // SCH_FIELD's implicitly created copy constructor is called in here
249  AddField( field );
250  }
251 
252  m_prefix = wxString( wxT( "U" ) );
253 }
254 
255 
257 {
258  return new SCH_COMPONENT( *this );
259 }
260 
261 
262 void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, PART_LIBS* aLibs )
263 {
264  if( m_lib_id != aLibId )
265  {
266  m_lib_id = aLibId;
267  SetModified();
268 
269  if( aLibs )
270  Resolve( aLibs );
271  else
272  m_part.reset();
273  }
274 }
275 
276 
278 {
279  // I've never been happy that the actual individual PART_LIB is left up to
280  // flimsy search path ordering. None-the-less find a part based on that design:
281  if( LIB_PART* part = aLibs->FindLibPart( m_lib_id ) )
282  {
283  m_part = part->SharedPtr();
284  return true;
285  }
286 
287  return false;
288 }
289 
290 // Helper sort function, used in SCH_COMPONENT::ResolveAll, to sort
291 // sch component by lib_id
292 static bool sort_by_libid( const SCH_COMPONENT* ref, SCH_COMPONENT* cmp )
293 {
294  return ref->GetLibId() < cmp->GetLibId();
295 }
296 
298  const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs )
299 {
300  // Usually, many components use the same part lib.
301  // to avoid too long calculation time the list of components is grouped
302  // and once the lib part is found for one member of a group, it is also
303  // set for all other members of this group
304  std::vector<SCH_COMPONENT*> cmp_list;
305 
306  // build the cmp list.
307  for( int i = 0; i < aComponents.GetCount(); ++i )
308  {
309  SCH_COMPONENT* cmp = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
310  wxASSERT( cmp );
311 
312  if( cmp ) // cmp == NULL should not occur.
313  cmp_list.push_back( cmp );
314  }
315 
316  // sort it by lib part. Cmp will be grouped by same lib part.
317  std::sort( cmp_list.begin(), cmp_list.end(), sort_by_libid );
318 
319  LIB_ID curr_libid;
320 
321  for( unsigned ii = 0; ii < cmp_list.size (); ++ii )
322  {
323  SCH_COMPONENT* cmp = cmp_list[ii];
324  curr_libid = cmp->m_lib_id;
325  cmp->Resolve( aLibs );
326 
327  // Propagate the m_part pointer to other members using the same lib_id
328  for( unsigned jj = ii+1; jj < cmp_list.size (); ++jj )
329  {
330  SCH_COMPONENT* next_cmp = cmp_list[jj];
331 
332  if( curr_libid != next_cmp->m_lib_id )
333  break;
334 
335  next_cmp->m_part = cmp->m_part;
336  ii = jj;
337  }
338  }
339 }
340 
341 
342 void SCH_COMPONENT::SetUnit( int aUnit )
343 {
344  if( m_unit != aUnit )
345  {
346  m_unit = aUnit;
347  SetModified();
348  }
349 }
350 
351 void SCH_COMPONENT::UpdateUnit( int aUnit )
352 {
353  m_unit = aUnit;
354 }
355 
356 
357 void SCH_COMPONENT::SetConvert( int aConvert )
358 {
359  if( m_convert != aConvert )
360  {
361  m_convert = aConvert;
362  SetModified();
363  }
364 }
365 
366 
367 void SCH_COMPONENT::SetTransform( const TRANSFORM& aTransform )
368 {
369  if( m_transform != aTransform )
370  {
371  m_transform = aTransform;
372  SetModified();
373  }
374 }
375 
376 
378 {
379  if( PART_SPTR part = m_part.lock() )
380  {
381  return part->GetUnitCount();
382  }
383 
384  return 0;
385 }
386 
387 
388 void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
389  GR_DRAWMODE aDrawMode, COLOR4D aColor,
390  bool aDrawPinText )
391 {
392  auto opts = PART_DRAW_OPTIONS::Default();
393  opts.draw_mode = aDrawMode;
394  opts.color = aColor;
395  opts.transform = m_transform;
396  opts.show_pin_text = aDrawPinText;
397  opts.draw_visible_fields = false;
398  opts.draw_hidden_fields = false;
399 
400  if( PART_SPTR part = m_part.lock() )
401  {
402  // Draw pin targets if part is being dragged
403  bool dragging = aPanel->GetScreen()->GetCurItem() == this && aPanel->IsMouseCaptured();
404 
405  if( !dragging )
406  {
407  opts.dangling = m_isDangling;
408  }
409 
410  part->Draw( aPanel, aDC, m_Pos + aOffset, m_unit, m_convert, opts );
411  }
412  else // Use dummy() part if the actual cannot be found.
413  {
414  dummy()->Draw( aPanel, aDC, m_Pos + aOffset, 0, 0, opts );
415  }
416 
417  SCH_FIELD* field = GetField( REFERENCE );
418 
419  if( field->IsVisible() && !field->IsMoving() )
420  {
421  field->Draw( aPanel, aDC, aOffset, aDrawMode );
422  }
423 
424  for( int ii = VALUE; ii < GetFieldCount(); ii++ )
425  {
426  field = GetField( ii );
427 
428  if( field->IsMoving() )
429  continue;
430 
431  field->Draw( aPanel, aDC, aOffset, aDrawMode );
432  }
433 
434 #if 0
435  // Only for testing purposes, draw the component bounding box
436  {
438  GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
439 #if 1
440  if( GetField( REFERENCE )->IsVisible() )
441  {
442  boundingBox = GetField( REFERENCE )->GetBoundingBox();
443  GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
444  }
445 
446  if( GetField( VALUE )->IsVisible() )
447  {
448  boundingBox = GetField( VALUE )->GetBoundingBox();
449  GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
450  }
451 #endif
452  }
453 #endif
454 }
455 
456 
457 void SCH_COMPONENT::AddHierarchicalReference( const wxString& aPath,
458  const wxString& aRef,
459  int aMulti )
460 {
461  wxString h_path, h_ref;
462  wxStringTokenizer tokenizer;
463  wxString separators( wxT( " " ) );
464 
465  // Search for an existing path and remove it if found (should not occur)
466  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
467  {
468  tokenizer.SetString( m_PathsAndReferences[ii], separators );
469  h_path = tokenizer.GetNextToken();
470 
471  if( h_path.Cmp( aPath ) == 0 )
472  {
473  m_PathsAndReferences.RemoveAt( ii );
474  ii--;
475  }
476  }
477 
478  h_ref = aPath + wxT( " " ) + aRef;
479  h_ref << wxT( " " ) << aMulti;
480  m_PathsAndReferences.Add( h_ref );
481 }
482 
483 
484 wxString SCH_COMPONENT::GetPath( const SCH_SHEET_PATH* sheet ) const
485 {
486  wxCHECK_MSG( sheet != NULL, wxEmptyString,
487  wxT( "Cannot get component path with invalid sheet object." ) );
488 
489  wxString str;
490 
491  str.Printf( wxT( "%8.8lX" ), (long unsigned) m_TimeStamp );
492  return sheet->Path() + str;
493 }
494 
495 
496 const wxString SCH_COMPONENT::GetRef( const SCH_SHEET_PATH* sheet )
497 {
498  wxString path = GetPath( sheet );
499  wxString h_path, h_ref;
500  wxStringTokenizer tokenizer;
501  wxString separators( wxT( " " ) );
502 
503  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
504  {
505  tokenizer.SetString( m_PathsAndReferences[ii], separators );
506  h_path = tokenizer.GetNextToken();
507 
508  if( h_path.Cmp( path ) == 0 )
509  {
510  h_ref = tokenizer.GetNextToken();
511 
512  /* printf( "GetRef hpath: %s\n",
513  * TO_UTF8( m_PathsAndReferences[ii] ) ); */
514  return h_ref;
515  }
516  }
517 
518  // if it was not found in m_Paths array, then see if it is in
519  // m_Field[REFERENCE] -- if so, use this as a default for this path.
520  // this will happen if we load a version 1 schematic file.
521  // it will also mean that multiple instances of the same sheet by default
522  // all have the same component references, but perhaps this is best.
523  if( !GetField( REFERENCE )->GetText().IsEmpty() )
524  {
525  SetRef( sheet, GetField( REFERENCE )->GetText() );
526  return GetField( REFERENCE )->GetText();
527  }
528 
529  return m_prefix;
530 }
531 
532 
533 /* Function IsReferenceStringValid (static function)
534  * Tests for an acceptable reference string
535  * An acceptable reference string must support unannotation
536  * i.e starts by letter
537  * returns true if OK
538  */
539 bool SCH_COMPONENT::IsReferenceStringValid( const wxString& aReferenceString )
540 {
541  wxString text = aReferenceString;
542  bool ok = true;
543 
544  // Try to unannotate this reference
545  while( !text.IsEmpty() && ( text.Last() == '?' || isdigit( text.Last() ) ) )
546  text.RemoveLast();
547 
548  if( text.IsEmpty() )
549  ok = false;
550 
551  // Add here other constraints
552  // Currently:no other constraint
553 
554  return ok;
555 }
556 
557 
558 void SCH_COMPONENT::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
559 {
560  wxString path = GetPath( sheet );
561 
562  bool notInArray = true;
563 
564  wxString h_path, h_ref;
565  wxStringTokenizer tokenizer;
566  wxString separators( wxT( " " ) );
567 
568  // check to see if it is already there before inserting it
569  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
570  {
571  tokenizer.SetString( m_PathsAndReferences[ii], separators );
572  h_path = tokenizer.GetNextToken();
573 
574  if( h_path.Cmp( path ) == 0 )
575  {
576  // just update the reference text, not the timestamp.
577  h_ref = h_path + wxT( " " ) + ref;
578  h_ref += wxT( " " );
579  tokenizer.GetNextToken(); // Skip old reference
580  h_ref += tokenizer.GetNextToken(); // Add part selection
581 
582  // Add the part selection
583  m_PathsAndReferences[ii] = h_ref;
584  notInArray = false;
585  }
586  }
587 
588  if( notInArray )
589  AddHierarchicalReference( path, ref, m_unit );
590 
591  SCH_FIELD* rf = GetField( REFERENCE );
592 
593  if( rf->GetText().IsEmpty()
594  || ( abs( rf->GetTextPos().x - m_Pos.x ) +
595  abs( rf->GetTextPos().y - m_Pos.y ) > 10000 ) )
596  {
597  // move it to a reasonable position
598  rf->SetTextPos( m_Pos + wxPoint( 50, 50 ) );
599  }
600 
601  rf->SetText( ref ); // for drawing.
602 
603  // Reinit the m_prefix member if needed
604  wxString prefix = ref;
605 
606  if( IsReferenceStringValid( prefix ) )
607  {
608  while( prefix.Last() == '?' || isdigit( prefix.Last() ) )
609  prefix.RemoveLast();
610  }
611  else
612  {
613  prefix = wxT( "U" ); // Set to default ref prefix
614  }
615 
616  if( m_prefix != prefix )
617  m_prefix = prefix;
618 }
619 
620 
621 void SCH_COMPONENT::SetTimeStamp( time_t aNewTimeStamp )
622 {
623  wxString string_timestamp, string_oldtimestamp;
624 
625  string_timestamp.Printf( wxT( "%08lX" ), (long unsigned) aNewTimeStamp );
626  string_oldtimestamp.Printf( wxT( "%08lX" ), (long unsigned) m_TimeStamp );
627  EDA_ITEM::SetTimeStamp( aNewTimeStamp );
628 
629  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
630  {
631  m_PathsAndReferences[ii].Replace( string_oldtimestamp.GetData(),
632  string_timestamp.GetData() );
633  }
634 }
635 
636 
638 {
639  wxString path = GetPath( aSheet );
640  wxString h_path, h_multi;
641  wxStringTokenizer tokenizer;
642  wxString separators( wxT( " " ) );
643 
644  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
645  {
646  tokenizer.SetString( m_PathsAndReferences[ii], separators );
647  h_path = tokenizer.GetNextToken();
648 
649  if( h_path.Cmp( path ) == 0 )
650  {
651  tokenizer.GetNextToken(); // Skip reference
652  h_multi = tokenizer.GetNextToken();
653  long imulti = 1;
654  h_multi.ToLong( &imulti );
655  return imulti;
656  }
657  }
658 
659  // if it was not found in m_Paths array, then use m_unit.
660  // this will happen if we load a version 1 schematic file.
661  return m_unit;
662 }
663 
664 
665 void SCH_COMPONENT::SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection )
666 {
667  wxString path = GetPath( aSheet );
668 
669  bool notInArray = true;
670 
671  wxString h_path, h_ref;
672  wxStringTokenizer tokenizer;
673  wxString separators( wxT( " " ) );
674 
675  //check to see if it is already there before inserting it
676  for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
677  {
678  tokenizer.SetString( m_PathsAndReferences[ii], separators );
679  h_path = tokenizer.GetNextToken();
680 
681  if( h_path.Cmp( path ) == 0 )
682  {
683  //just update the unit selection.
684  h_ref = h_path + wxT( " " );
685  h_ref += tokenizer.GetNextToken(); // Add reference
686  h_ref += wxT( " " );
687  h_ref << aUnitSelection; // Add part selection
688 
689  // Ann the part selection
690  m_PathsAndReferences[ii] = h_ref;
691  notInArray = false;
692  }
693  }
694 
695  if( notInArray )
696  AddHierarchicalReference( path, m_prefix, aUnitSelection );
697 }
698 
699 
700 SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
701 {
702  const SCH_FIELD* field;
703 
704  if( (unsigned) aFieldNdx < m_Fields.size() )
705  field = &m_Fields[aFieldNdx];
706  else
707  field = NULL;
708 
709  wxASSERT( field );
710 
711  // use cast to remove const-ness
712  return (SCH_FIELD*) field;
713 }
714 
715 
716 void SCH_COMPONENT::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly )
717 {
718  for( SCH_FIELD& each_field : m_Fields )
719  {
720  if( !aVisibleOnly || ( each_field.IsVisible() && !each_field.IsVoid() ) )
721  aVector.push_back( &each_field );
722  }
723 }
724 
725 
727 {
728  int newNdx = m_Fields.size();
729 
730  m_Fields.push_back( aField );
731  return &m_Fields[newNdx];
732 }
733 
734 
735 SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName )
736 {
737  for( unsigned i = 0; i<m_Fields.size(); ++i )
738  {
739  if( aFieldName == m_Fields[i].GetName( false ) )
740  return &m_Fields[i];
741  }
742 
743  return NULL;
744 }
745 
746 
747 LIB_PIN* SCH_COMPONENT::GetPin( const wxString& number )
748 {
749  if( PART_SPTR part = m_part.lock() )
750  {
751  return part->GetPin( number, m_unit, m_convert );
752  }
753  return NULL;
754 }
755 
756 
757 void SCH_COMPONENT::GetPins( std::vector<LIB_PIN*>& aPinsList )
758 {
759  if( PART_SPTR part = m_part.lock() )
760  {
761  part->GetPins( aPinsList, m_unit, m_convert );
762  }
763  else
764  wxFAIL_MSG( "Could not obtain PART_SPTR lock" );
765 }
766 
767 
769 {
770  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_COMPONENT_T),
771  wxT( "Cannot swap data with invalid component." ) );
772 
773  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
774 
775  std::swap( m_lib_id, component->m_lib_id );
776  std::swap( m_part, component->m_part );
777  std::swap( m_Pos, component->m_Pos );
778  std::swap( m_unit, component->m_unit );
779  std::swap( m_convert, component->m_convert );
780 
781  TRANSFORM tmp = m_transform;
782 
783  m_transform = component->m_transform;
784  component->m_transform = tmp;
785 
786  m_Fields.swap( component->m_Fields ); // std::vector's swap()
787 
788  // Reparent items after copying data
789  // (after swap(), m_Parent member does not point to the right parent):
790  for( int ii = 0; ii < component->GetFieldCount(); ++ii )
791  {
792  component->GetField( ii )->SetParent( component );
793  }
794 
795  for( int ii = 0; ii < GetFieldCount(); ++ii )
796  {
797  GetField( ii )->SetParent( this );
798  }
799 
800  std::swap( m_PathsAndReferences, component->m_PathsAndReferences );
801 }
802 
803 
805 {
806  bool keepMulti = false;
807  wxArrayString reference_fields;
808 
809  static const wxChar separators[] = wxT( " " );
810 
811  PART_SPTR part = m_part.lock();
812 
813  if( part && part->UnitsLocked() )
814  keepMulti = true;
815 
816  // Build a reference with no annotation,
817  // i.e. a reference ended by only one '?'
818  wxString defRef = m_prefix;
819 
820  if( IsReferenceStringValid( defRef ) )
821  {
822  while( defRef.Last() == '?' )
823  defRef.RemoveLast();
824  }
825  else
826  { // This is a malformed reference: reinit this reference
827  m_prefix = defRef = wxT("U"); // Set to default ref prefix
828  }
829 
830  defRef.Append( wxT( "?" ) );
831 
832  wxString multi = wxT( "1" );
833 
834  // For components with units locked,
835  // we cannot remove all annotations: part selection must be kept
836  // For all components: if aSheetPath is not NULL,
837  // remove annotation only for the given path
838  if( keepMulti || aSheetPath )
839  {
840  wxString NewHref;
841  wxString path;
842 
843  if( aSheetPath )
844  path = GetPath( aSheetPath );
845 
846  for( unsigned int ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
847  {
848  // Break hierarchical reference in path, ref and multi selection:
849  reference_fields = wxStringTokenize( m_PathsAndReferences[ii], separators );
850 
851  if( aSheetPath == NULL || reference_fields[0].Cmp( path ) == 0 )
852  {
853  if( keepMulti ) // Get and keep part selection
854  multi = reference_fields[2];
855 
856  NewHref = reference_fields[0];
857  NewHref << wxT( " " ) << defRef << wxT( " " ) << multi;
858  m_PathsAndReferences[ii] = NewHref;
859  }
860  }
861  }
862  else
863  {
864  // Clear reference strings, but does not free memory because a new annotation
865  // will reuse it
866  m_PathsAndReferences.Empty();
867  m_unit = 1;
868  }
869 
870  // These 2 changes do not work in complex hierarchy.
871  // When a clear annotation is made, the calling function must call a
872  // UpdateAllScreenReferences for the active sheet.
873  // But this call cannot made here.
874  m_Fields[REFERENCE].SetText( defRef ); //for drawing.
875 
876  SetModified();
877 }
878 
879 
880 void SCH_COMPONENT::SetOrientation( int aOrientation )
881 {
882  TRANSFORM temp = TRANSFORM();
883  bool transform = false;
884 
885  switch( aOrientation )
886  {
887  case CMP_ORIENT_0:
888  case CMP_NORMAL: // default transform matrix
889  m_transform.x1 = 1;
890  m_transform.y2 = -1;
892  break;
893 
894  case CMP_ROTATE_COUNTERCLOCKWISE: // Rotate + (incremental rotation)
895  temp.x1 = temp.y2 = 0;
896  temp.y1 = 1;
897  temp.x2 = -1;
898  transform = true;
899  break;
900 
901  case CMP_ROTATE_CLOCKWISE: // Rotate - (incremental rotation)
902  temp.x1 = temp.y2 = 0;
903  temp.y1 = -1;
904  temp.x2 = 1;
905  transform = true;
906  break;
907 
908  case CMP_MIRROR_Y: // Mirror Y (incremental rotation)
909  temp.x1 = -1;
910  temp.y2 = 1;
911  temp.y1 = temp.x2 = 0;
912  transform = true;
913  break;
914 
915  case CMP_MIRROR_X: // Mirror X (incremental rotation)
916  temp.x1 = 1;
917  temp.y2 = -1;
918  temp.y1 = temp.x2 = 0;
919  transform = true;
920  break;
921 
922  case CMP_ORIENT_90:
925  break;
926 
927  case CMP_ORIENT_180:
931  break;
932 
933  case CMP_ORIENT_270:
936  break;
937 
938  case ( CMP_ORIENT_0 + CMP_MIRROR_X ):
941  break;
942 
943  case ( CMP_ORIENT_0 + CMP_MIRROR_Y ):
946  break;
947 
948  case ( CMP_ORIENT_90 + CMP_MIRROR_X ):
951  break;
952 
953  case ( CMP_ORIENT_90 + CMP_MIRROR_Y ):
956  break;
957 
958  case ( CMP_ORIENT_180 + CMP_MIRROR_X ):
961  break;
962 
963  case ( CMP_ORIENT_180 + CMP_MIRROR_Y ):
966  break;
967 
968  case ( CMP_ORIENT_270 + CMP_MIRROR_X ):
971  break;
972 
973  case ( CMP_ORIENT_270 + CMP_MIRROR_Y ):
976  break;
977 
978  default:
979  transform = false;
980  wxMessageBox( wxT( "SetRotateMiroir() error: ill value" ) );
981  break;
982  }
983 
984  if( transform )
985  {
986  /* The new matrix transform is the old matrix transform modified by the
987  * requested transformation, which is the temp transform (rot,
988  * mirror ..) in order to have (in term of matrix transform):
989  * transform coord = new_m_transform * coord
990  * where transform coord is the coord modified by new_m_transform from
991  * the initial value coord.
992  * new_m_transform is computed (from old_m_transform and temp) to
993  * have:
994  * transform coord = old_m_transform * temp
995  */
996  TRANSFORM newTransform;
997 
998  newTransform.x1 = m_transform.x1 * temp.x1 + m_transform.x2 * temp.y1;
999  newTransform.y1 = m_transform.y1 * temp.x1 + m_transform.y2 * temp.y1;
1000  newTransform.x2 = m_transform.x1 * temp.x2 + m_transform.x2 * temp.y2;
1001  newTransform.y2 = m_transform.y1 * temp.x2 + m_transform.y2 * temp.y2;
1002  m_transform = newTransform;
1003  }
1004 }
1005 
1006 
1008 {
1009  int type_rotate = CMP_ORIENT_0;
1010  TRANSFORM transform;
1011  int ii;
1012 
1013  #define ROTATE_VALUES_COUNT 12
1014 
1015  // list of all possibilities, but only the first 8 are actually used
1016  int rotate_value[ROTATE_VALUES_COUNT] =
1017  {
1023  CMP_MIRROR_Y + CMP_ORIENT_180, CMP_MIRROR_Y + CMP_ORIENT_270
1024  };
1025 
1026  // Try to find the current transform option:
1027  transform = m_transform;
1028 
1029  for( ii = 0; ii < ROTATE_VALUES_COUNT; ii++ )
1030  {
1031  type_rotate = rotate_value[ii];
1032  SetOrientation( type_rotate );
1033 
1034  if( transform == m_transform )
1035  return type_rotate;
1036  }
1037 
1038  // Error: orientation not found in list (should not happen)
1039  wxMessageBox( wxT( "Component orientation matrix internal error" ) );
1040  m_transform = transform;
1041 
1042  return CMP_NORMAL;
1043 }
1044 
1045 
1047 {
1048  return m_transform.TransformCoordinate( aPoint );
1049 }
1050 
1051 
1052 #if defined(DEBUG)
1053 
1054 void SCH_COMPONENT::Show( int nestLevel, std::ostream& os ) const
1055 {
1056  // for now, make it look like XML:
1057  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1058  << " ref=\"" << TO_UTF8( GetField( 0 )->GetName() )
1059  << '"' << " chipName=\""
1060  << GetLibId().Format() << '"' << m_Pos
1061  << " layer=\"" << m_Layer
1062  << '"' << ">\n";
1063 
1064  // skip the reference, it's been output already.
1065  for( int i = 1; i < GetFieldCount(); ++i )
1066  {
1067  wxString value = GetField( i )->GetText();
1068 
1069  if( !value.IsEmpty() )
1070  {
1071  NestedSpace( nestLevel + 1, os ) << "<field" << " name=\""
1072  << TO_UTF8( GetField( i )->GetName() )
1073  << '"' << " value=\""
1074  << TO_UTF8( value ) << "\"/>\n";
1075  }
1076  }
1077 
1078  NestedSpace( nestLevel, os ) << "</" << TO_UTF8( GetClass().Lower() ) << ">\n";
1079 }
1080 
1081 #endif
1082 
1083 
1084 bool SCH_COMPONENT::Save( FILE* f ) const
1085 {
1086  std::string name1;
1087  std::string name2;
1088  wxArrayString reference_fields;
1089 
1090  static wxString delimiters( wxT( " " ) );
1091 
1092  // this is redundant with the AR entries below, but it makes the
1093  // files backwards-compatible.
1094  if( m_PathsAndReferences.GetCount() > 0 )
1095  {
1096  reference_fields = wxStringTokenize( m_PathsAndReferences[0], delimiters );
1097 
1098  name1 = toUTFTildaText( reference_fields[1] );
1099  }
1100  else
1101  {
1102  if( GetField( REFERENCE )->GetText().IsEmpty() )
1103  name1 = toUTFTildaText( m_prefix );
1104  else
1105  name1 = toUTFTildaText( GetField( REFERENCE )->GetText() );
1106  }
1107 
1108  wxString part_name = GetLibId().GetLibItemName();
1109 
1110  if( part_name.size() )
1111  {
1112  name2 = toUTFTildaText( part_name );
1113  }
1114  else
1115  {
1116  name2 = NULL_STRING;
1117  }
1118 
1119  if( fprintf( f, "$Comp\n" ) == EOF )
1120  return false;
1121 
1122  if( fprintf( f, "L %s %s\n", name2.c_str(), name1.c_str() ) == EOF )
1123  return false;
1124 
1125  // Generate unit number, convert and time stamp
1126  if( fprintf( f, "U %d %d %8.8lX\n", m_unit, m_convert, (unsigned long)m_TimeStamp ) == EOF )
1127  return false;
1128 
1129  // Save the position
1130  if( fprintf( f, "P %d %d\n", m_Pos.x, m_Pos.y ) == EOF )
1131  return false;
1132 
1133  /* If this is a complex hierarchy; save hierarchical references.
1134  * but for simple hierarchies it is not necessary.
1135  * the reference inf is already saved
1136  * this is useful for old Eeschema version compatibility
1137  */
1138  if( m_PathsAndReferences.GetCount() > 1 )
1139  {
1140  for( unsigned int ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
1141  {
1142  /*format:
1143  * AR Path="/140/2" Ref="C99" Part="1"
1144  * where 140 is the uid of the containing sheet
1145  * and 2 is the timestamp of this component.
1146  * (timestamps are actually 8 hex chars)
1147  * Ref is the conventional component reference for this 'path'
1148  * Part is the conventional component part selection for this 'path'
1149  */
1150  reference_fields = wxStringTokenize( m_PathsAndReferences[ii], delimiters );
1151 
1152  if( fprintf( f, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
1153  TO_UTF8( reference_fields[0] ),
1154  TO_UTF8( reference_fields[1] ),
1155  TO_UTF8( reference_fields[2] ) ) == EOF )
1156  return false;
1157  }
1158  }
1159 
1160  // update the ugly field index, which I would like to see go away someday soon.
1161  for( unsigned i = 0; i<m_Fields.size(); ++i )
1162  {
1163  SCH_FIELD* fld = GetField( i );
1164  fld->SetId( i ); // we don't need field Ids, please be gone.
1165  }
1166 
1167  // Fixed fields:
1168  // Save mandatory fields even if they are blank,
1169  // because the visibility, size and orientation are set from libary editor.
1170  for( unsigned i = 0; i<MANDATORY_FIELDS; ++i )
1171  {
1172  SCH_FIELD* fld = GetField( i );
1173  if( !fld->Save( f ) )
1174  return false;
1175  }
1176 
1177  // User defined fields:
1178  // The *policy* about which user defined fields are part of a symbol is now
1179  // only in the dialog editors. No policy should be enforced here, simply
1180  // save all the user defined fields, they are present because a dialog editor
1181  // thought they should be. If you disagree, go fix the dialog editors.
1182  for( unsigned i = MANDATORY_FIELDS; i<m_Fields.size(); ++i )
1183  {
1184  SCH_FIELD* fld = GetField( i );
1185 
1186  if( !fld->Save( f ) )
1187  return false;
1188  }
1189 
1190  // Unit number, position, box ( old standard )
1191  if( fprintf( f, "\t%-4d %-4d %-4d\n", m_unit, m_Pos.x, m_Pos.y ) == EOF )
1192  return false;
1193 
1194  if( fprintf( f, "\t%-4d %-4d %-4d %-4d\n",
1196  return false;
1197 
1198  if( fprintf( f, "$EndComp\n" ) == EOF )
1199  return false;
1200 
1201  return true;
1202 }
1203 
1204 
1205 bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
1206 {
1207  // Remark: avoid using sscanf to read texts entered by user
1208  // which are UTF8 encoded, because sscanf does not work well on Windows
1209  // with some UTF8 values.
1210  char name1[256], char1[256], char2[256], char3[256];
1211  int newfmt = 0;
1212  char* ptcar;
1213  wxString fieldName;
1214  char* line = aLine.Line();
1215  unsigned long timeStamp;
1216 
1217  m_convert = 1;
1218 
1219  if( line[0] == '$' )
1220  {
1221  newfmt = 1;
1222 
1223  if( !(line = aLine.ReadLine()) )
1224  return true;
1225  }
1226 
1227  // Parse the first line of description:
1228  // like "L partname ref" (for instance "L 74LS00 U4"
1229  // They are UTF8 texts, so do not use sscanf
1230 
1231  line += 1;
1232 
1233  if( *line == ' ' )
1234  line++;
1235 
1236  // line points the first parameter
1237  wxString buffer( FROM_UTF8( line ) );
1238  wxStringTokenizer tokenizer( buffer, wxT( " \r\n" ) );
1239 
1240  if( tokenizer.CountTokens() < 2 )
1241  {
1242  aErrorMsg.Printf( wxT( "Eeschema component description error at line %d, aborted" ),
1243  aLine.LineNumber() );
1244  aErrorMsg << wxT( "\n" ) << FROM_UTF8( line );
1245  return false;
1246  }
1247 
1248  wxString partname = tokenizer.NextToken();
1249  partname.Replace( wxT("~"), wxT(" ") ); // all spaces were replaced by ~ in files.
1250 
1251  if( partname != NULL_STRING )
1252  {
1253  m_lib_id.SetLibItemName( partname, false );
1254 
1255  if( !newfmt )
1256  GetField( VALUE )->SetText( partname );
1257  }
1258  else
1259  {
1260  m_lib_id.clear();
1261  GetField( VALUE )->Empty();
1263  GetField( VALUE )->SetVisible( false );
1264  }
1265 
1266  wxString reference = tokenizer.NextToken();
1267  reference.Replace( wxT("~"), wxT(" ") ); // all spaces were replaced by ~ in files.
1268  reference.Trim( true );
1269  reference.Trim( false );
1270 
1271  if( reference != NULL_STRING )
1272  {
1273  wxString prefix = reference;
1274  // Build reference prefix from the actual reference by removing trailing digits
1275  // (Perhaps outdated code, only for very old schematic files)
1276  while( prefix.Length() )
1277  {
1278  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1279  break;
1280 
1281  prefix.RemoveLast();
1282  }
1283 
1284  // Avoid a prefix containing trailing/leading spaces
1285  prefix.Trim( true );
1286  prefix.Trim( false );
1287 
1288  if( prefix.IsEmpty() )
1289  m_prefix = wxT( "U" );
1290  else
1291  m_prefix = prefix;
1292 
1293  if( !newfmt )
1294  GetField( REFERENCE )->SetText( reference );
1295  }
1296  else
1297  {
1298  GetField( REFERENCE )->SetVisible( false );
1299  }
1300 
1301  /* Parse component description
1302  * These lines begin with:
1303  * "P" = Position
1304  * U = Num Unit and Conversion
1305  * "Fn" = Fields (0 .. n = = number of field)
1306  * "Ar" = Alternate reference in the case of multiple sheets referring to
1307  * one schematic file.
1308  */
1309  for( ; ; )
1310  {
1311  if( !(line = aLine.ReadLine()) )
1312  return false;
1313 
1314  if( line[0] == 'U' )
1315  {
1316  sscanf( line + 1, "%d %d %lX", &m_unit, &m_convert, &timeStamp );
1317  m_TimeStamp = (time_t)timeStamp;
1318  }
1319  else if( line[0] == 'P' )
1320  {
1321  sscanf( line + 1, "%d %d", &m_Pos.x, &m_Pos.y );
1322 
1323  // Set fields position to a default position (that is the
1324  // component position. For existing fields, the real position
1325  // will be set later
1326  for( int i = 0; i<GetFieldCount(); i++ )
1327  {
1328  if( GetField( i )->GetText().IsEmpty() )
1329  GetField( i )->SetTextPos( m_Pos );
1330  }
1331  }
1332  else if( line[0] == 'A' && line[1] == 'R' )
1333  {
1334  /* format:
1335  * AR Path="/9086AF6E/67452AA0" Ref="C99" Part="1"
1336  * where 9086AF6E is the unique timestamp of the containing sheet
1337  * and 67452AA0 is the timestamp of this component.
1338  * C99 is the reference given this path.
1339  */
1340  int ii;
1341  ptcar = line + 2;
1342 
1343  //copy the path.
1344  ii = ReadDelimitedText( name1, ptcar, 255 );
1345  ptcar += ii + 1;
1346  wxString path = FROM_UTF8( name1 );
1347 
1348  // copy the reference
1349  ii = ReadDelimitedText( name1, ptcar, 255 );
1350  ptcar += ii + 1;
1351  wxString ref = FROM_UTF8( name1 );
1352 
1353  // copy the multi, if exists
1354  ii = ReadDelimitedText( name1, ptcar, 255 );
1355 
1356  if( name1[0] == 0 ) // Nothing read, put a default value
1357  sprintf( name1, "%d", m_unit );
1358 
1359  int multi = atoi( name1 );
1360 
1361  if( multi < 0 || multi > 26 )
1362  multi = 1;
1363 
1364  AddHierarchicalReference( path, ref, multi );
1365  GetField( REFERENCE )->SetText( ref );
1366  }
1367  else if( line[0] == 'F' )
1368  {
1369  int fieldNdx;
1370 
1371  wxString fieldText;
1374 
1375  ptcar = (char*) aLine;
1376 
1377  while( *ptcar && (*ptcar != '"') )
1378  ptcar++;
1379 
1380  if( *ptcar != '"' )
1381  {
1382  aErrorMsg.Printf( wxT( "Eeschema file library field F at line %d, aborted" ),
1383  aLine.LineNumber() );
1384  return false;
1385  }
1386 
1387  ptcar += ReadDelimitedText( &fieldText, ptcar );
1388 
1389  if( *ptcar == 0 )
1390  {
1391  aErrorMsg.Printf( wxT( "Component field F at line %d, aborted" ),
1392  aLine.LineNumber() );
1393  return false;
1394  }
1395 
1396  fieldNdx = atoi( line + 2 );
1397 
1398  ReadDelimitedText( &fieldName, ptcar );
1399 
1400  if( fieldName.IsEmpty() )
1401  fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx );
1402 
1403  if( fieldNdx >= GetFieldCount() )
1404  {
1405  // The first MANDATOR_FIELDS _must_ be constructed within
1406  // the SCH_COMPONENT constructor. This assert is simply here
1407  // to guard against a change in that constructor.
1408  wxASSERT( GetFieldCount() >= MANDATORY_FIELDS );
1409 
1410  // Ignore the _supplied_ fieldNdx. It is not important anymore
1411  // if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
1412  // We freely renumber the index to fit the next available field slot.
1413 
1414  fieldNdx = GetFieldCount(); // new has this index after insertion
1415 
1416  SCH_FIELD field( wxPoint( 0, 0 ),
1417  -1, // field id is not relavant for user defined fields
1418  this, fieldName );
1419 
1420  AddField( field );
1421  }
1422  else
1423  {
1424  GetField( fieldNdx )->SetName( fieldName );
1425  }
1426 
1427  GetField( fieldNdx )->SetText( fieldText );
1428  memset( char3, 0, sizeof(char3) );
1429  int ii, x, y, w, attr;
1430 
1431  if( ( ii = sscanf( ptcar, "%255s %d %d %d %X %255s %255s", char1, &x, &y, &w, &attr,
1432  char2, char3 ) ) < 4 )
1433  {
1434  aErrorMsg.Printf( wxT( "Component Field error line %d, aborted" ),
1435  aLine.LineNumber() );
1436  continue;
1437  }
1438 
1439  GetField( fieldNdx )->SetTextPos( wxPoint( x, y ) );
1440  GetField( fieldNdx )->SetVisible( !attr );
1441 
1442  if( (w == 0 ) || (ii == 4) )
1443  w = GetDefaultTextSize();
1444 
1445  GetField( fieldNdx )->SetTextSize( wxSize( w, w ) );
1446  GetField( fieldNdx )->SetTextAngle( TEXT_ANGLE_HORIZ );
1447 
1448  if( char1[0] == 'V' )
1449  GetField( fieldNdx )->SetTextAngle( TEXT_ANGLE_VERT );
1450 
1451  if( ii >= 7 )
1452  {
1453  if( *char2 == 'L' )
1454  hjustify = GR_TEXT_HJUSTIFY_LEFT;
1455  else if( *char2 == 'R' )
1456  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1457 
1458  if( char3[0] == 'B' )
1459  vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
1460  else if( char3[0] == 'T' )
1461  vjustify = GR_TEXT_VJUSTIFY_TOP;
1462 
1463  GetField( fieldNdx )->SetItalic( char3[1] == 'I' );
1464  GetField( fieldNdx )->SetBold( char3[2] == 'B' );
1465  GetField( fieldNdx )->SetHorizJustify( hjustify );
1466  GetField( fieldNdx )->SetVertJustify( vjustify );
1467  }
1468 
1469  if( fieldNdx == REFERENCE )
1470  if( GetField( fieldNdx )->GetText()[0] == '#' )
1471  GetField( fieldNdx )->SetVisible( false );
1472  }
1473  else
1474  {
1475  break;
1476  }
1477  }
1478 
1479  if( sscanf( line, "%d %d %d", &m_unit, &m_Pos.x, &m_Pos.y ) != 3 )
1480  {
1481  aErrorMsg.Printf( wxT( "Component unit & pos error at line %d, aborted" ),
1482  aLine.LineNumber() );
1483  return false;
1484  }
1485 
1486  if( !(line = aLine.ReadLine()) ||
1487  sscanf( line, "%d %d %d %d",
1488  &m_transform.x1,
1489  &m_transform.y1,
1490  &m_transform.x2,
1491  &m_transform.y2 ) != 4 )
1492  {
1493  aErrorMsg.Printf( wxT( "Component orient error at line %d, aborted" ),
1494  aLine.LineNumber() );
1495  return false;
1496  }
1497 
1498  if( newfmt )
1499  {
1500  if( !(line = aLine.ReadLine()) )
1501  return false;
1502 
1503  if( strncasecmp( "$End", line, 4 ) != 0 )
1504  {
1505  aErrorMsg.Printf( wxT( "Component End expected at line %d, aborted" ),
1506  aLine.LineNumber() );
1507  return false;
1508  }
1509  }
1510 
1511  // ensure flags (mainly used in edit) are cleared.
1512  // some changes have set the modified flag
1513  m_Flags = 0;
1514 
1515  return true;
1516 }
1517 
1518 
1520 {
1521  EDA_RECT bBox;
1522 
1523  if( PART_SPTR part = m_part.lock() )
1524  {
1525  bBox = part->GetBodyBoundingBox( m_unit, m_convert );
1526  }
1527  else
1528  {
1529  bBox = dummy()->GetBodyBoundingBox( m_unit, m_convert );
1530  }
1531 
1532  int x0 = bBox.GetX();
1533  int xm = bBox.GetRight();
1534 
1535  // We must reverse Y values, because matrix orientation
1536  // suppose Y axis normal for the library items coordinates,
1537  // m_transform reverse Y values, but bBox is already reversed!
1538  int y0 = -bBox.GetY();
1539  int ym = -bBox.GetBottom();
1540 
1541  // Compute the real Boundary box (rotated, mirrored ...)
1542  int x1 = m_transform.x1 * x0 + m_transform.y1 * y0;
1543  int y1 = m_transform.x2 * x0 + m_transform.y2 * y0;
1544  int x2 = m_transform.x1 * xm + m_transform.y1 * ym;
1545  int y2 = m_transform.x2 * xm + m_transform.y2 * ym;
1546 
1547  // H and W must be > 0:
1548  if( x2 < x1 )
1549  std::swap( x2, x1 );
1550 
1551  if( y2 < y1 )
1552  std::swap( y2, y1 );
1553 
1554  bBox.SetX( x1 );
1555  bBox.SetY( y1 );
1556  bBox.SetWidth( x2 - x1 );
1557  bBox.SetHeight( y2 - y1 );
1558 
1559  bBox.Offset( m_Pos );
1560  return bBox;
1561 }
1562 
1563 
1565 {
1566  EDA_RECT bbox = GetBodyBoundingBox();
1567 
1568  for( size_t i = 0; i < m_Fields.size(); i++ )
1569  {
1570  bbox.Merge( m_Fields[i].GetBoundingBox() );
1571  }
1572 
1573  return bbox;
1574 }
1575 
1576 
1578 {
1579  // part and alias can differ if alias is not the root
1580  if( PART_SPTR part = m_part.lock() )
1581  {
1582  LIB_ALIAS* alias = part->GetAlias( GetLibId().GetLibItemName() );
1583 
1584  if( !alias )
1585  return;
1586 
1587  if( m_currentSheetPath )
1588  aList.push_back( MSG_PANEL_ITEM( _( "Reference" ),
1590  DARKCYAN ) );
1591 
1592  wxString msg = part->IsPower() ? _( "Power symbol" ) : _( "Value" );
1593 
1594  aList.push_back( MSG_PANEL_ITEM( msg, GetField( VALUE )->GetShownText(), DARKCYAN ) );
1595 
1596  // Display component reference in library and library
1597  aList.push_back( MSG_PANEL_ITEM( _( "Component" ), GetLibId().GetLibItemName(), BROWN ) );
1598 
1599  if( alias->GetName() != part->GetName() )
1600  aList.push_back( MSG_PANEL_ITEM( _( "Alias of" ), part->GetName(), BROWN ) );
1601 
1602  aList.push_back( MSG_PANEL_ITEM( _( "Library" ), alias->GetLibraryName(), BROWN ) );
1603 
1604  // Display the current associated footprint, if exists.
1605  if( !GetField( FOOTPRINT )->IsVoid() )
1606  msg = GetField( FOOTPRINT )->GetShownText();
1607  else
1608  msg = _( "<Unknown>" );
1609 
1610  aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), msg, DARKRED ) );
1611 
1612  // Display description of the component, and keywords found in lib
1613  aList.push_back( MSG_PANEL_ITEM( _( "Description" ), alias->GetDescription(), DARKCYAN ) );
1614  aList.push_back( MSG_PANEL_ITEM( _( "Key Words" ), alias->GetKeyWords(), DARKCYAN ) );
1615  }
1616 }
1617 
1618 
1620 {
1621  return add_component_xpm;
1622 }
1623 
1624 
1625 void SCH_COMPONENT::MirrorY( int aYaxis_position )
1626 {
1627  int dx = m_Pos.x;
1628 
1630  MIRROR( m_Pos.x, aYaxis_position );
1631  dx -= m_Pos.x; // dx,0 is the move vector for this transform
1632 
1633  for( int ii = 0; ii < GetFieldCount(); ii++ )
1634  {
1635  // Move the fields to the new position because the component itself has moved.
1636  wxPoint pos = GetField( ii )->GetTextPos();
1637  pos.x -= dx;
1638  GetField( ii )->SetTextPos( pos );
1639  }
1640 }
1641 
1642 
1643 void SCH_COMPONENT::MirrorX( int aXaxis_position )
1644 {
1645  int dy = m_Pos.y;
1646 
1648  MIRROR( m_Pos.y, aXaxis_position );
1649  dy -= m_Pos.y; // dy,0 is the move vector for this transform
1650 
1651  for( int ii = 0; ii < GetFieldCount(); ii++ )
1652  {
1653  // Move the fields to the new position because the component itself has moved.
1654  wxPoint pos = GetField( ii )->GetTextPos();
1655  pos.y -= dy;
1656  GetField( ii )->SetTextPos( pos );
1657  }
1658 }
1659 
1660 
1662 {
1663  wxPoint prev = m_Pos;
1664 
1665  RotatePoint( &m_Pos, aPosition, 900 );
1666 
1668 
1669  for( int ii = 0; ii < GetFieldCount(); ii++ )
1670  {
1671  // Move the fields to the new position because the component itself has moved.
1672  wxPoint pos = GetField( ii )->GetTextPos();
1673  pos.x -= prev.x - m_Pos.x;
1674  pos.y -= prev.y - m_Pos.y;
1675  GetField( ii )->SetTextPos( pos );
1676  }
1677 }
1678 
1679 
1680 bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void* aAuxData,
1681  wxPoint* aFindLocation )
1682 {
1683  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
1684 
1685  // Components are searchable via the child field and pin item text.
1686  return false;
1687 }
1688 
1689 
1690 void SCH_COMPONENT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
1691 {
1692  if( PART_SPTR part = m_part.lock() )
1693  {
1694  for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
1695  {
1696  wxASSERT( pin->Type() == LIB_PIN_T );
1697 
1698  if( pin->GetUnit() && m_unit && ( m_unit != pin->GetUnit() ) )
1699  continue;
1700 
1701  if( pin->GetConvert() && m_convert && ( m_convert != pin->GetConvert() ) )
1702  continue;
1703 
1704  DANGLING_END_ITEM item( PIN_END, pin, GetPinPhysicalPosition( pin ) );
1705  aItemList.push_back( item );
1706  }
1707  }
1708 }
1709 
1710 
1711 bool SCH_COMPONENT::IsPinDanglingStateChanged( std::vector<DANGLING_END_ITEM> &aItemList,
1712  LIB_PINS& aLibPins, unsigned aPin )
1713 {
1714  bool previousState;
1715 
1716  if( aPin < m_isDangling.size() )
1717  {
1718  previousState = m_isDangling[aPin];
1719  m_isDangling[aPin] = true;
1720  }
1721  else
1722  {
1723  previousState = true;
1724  m_isDangling.push_back( true );
1725  }
1726 
1727  wxPoint pin_position = GetPinPhysicalPosition( aLibPins[aPin] );
1728 
1729  for( DANGLING_END_ITEM& each_item : aItemList )
1730  {
1731  // Some people like to stack pins on top of each other in a symbol to indicate
1732  // internal connection. While technically connected, it is not particularly useful
1733  // to display them that way, so skip any pins that are in the same symbol as this
1734  // one.
1735  //
1736  // Do not make this exception for hidden pins, because those actually make internal
1737  // connections to a power net.
1738  const LIB_PIN* item_pin = dynamic_cast<const LIB_PIN*>( each_item.GetItem() );
1739 
1740  if( item_pin
1741  && ( !item_pin->IsPowerConnection() || !IsInNetlist() )
1742  && std::find( aLibPins.begin(), aLibPins.end(), item_pin) != aLibPins.end() )
1743  continue;
1744 
1745  switch( each_item.GetType() )
1746  {
1747  case PIN_END:
1748  case LABEL_END:
1749  case SHEET_LABEL_END:
1750  case WIRE_START_END:
1751  case WIRE_END_END:
1752  case NO_CONNECT_END:
1753  case JUNCTION_END:
1754  if( pin_position == each_item.GetPosition() )
1755  m_isDangling[aPin] = false;
1756  break;
1757  default:
1758  break;
1759  }
1760  if( !m_isDangling[aPin] )
1761  break;
1762  }
1763 
1764  return previousState != m_isDangling[aPin];
1765 }
1766 
1767 
1768 bool SCH_COMPONENT::IsDanglingStateChanged( std::vector<DANGLING_END_ITEM>& aItemList )
1769 {
1770  bool changed = false;
1771  LIB_PINS libPins;
1772  if( PART_SPTR part = m_part.lock() )
1773  part->GetPins( libPins, m_unit, m_convert );
1774  for( size_t i = 0; i < libPins.size(); ++i )
1775  {
1776  if( IsPinDanglingStateChanged( aItemList, libPins, i ) )
1777  changed = true;
1778  }
1779  return changed;
1780 }
1781 
1782 
1784 {
1785  for( bool each : m_isDangling )
1786  {
1787  if( each )
1788  return true;
1789  }
1790  return false;
1791 }
1792 
1793 
1795 {
1796  wxCHECK_MSG( Pin != NULL && Pin->Type() == LIB_PIN_T, wxPoint( 0, 0 ),
1797  wxT( "Cannot get physical position of pin." ) );
1798 
1799  return m_transform.TransformCoordinate( Pin->GetPosition() ) + m_Pos;
1800 }
1801 
1802 
1803 bool SCH_COMPONENT::IsSelectStateChanged( const wxRect& aRect )
1804 {
1805  bool previousState = IsSelected();
1806 
1808 
1809  if( aRect.Intersects( boundingBox ) )
1810  SetFlags( SELECTED );
1811  else
1812  ClearFlags( SELECTED );
1813 
1814  return previousState != IsSelected();
1815 }
1816 
1817 
1818 void SCH_COMPONENT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
1819 {
1820  if( PART_SPTR part = m_part.lock() )
1821  {
1822  for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
1823  {
1824  wxCHECK_RET( pin->Type() == LIB_PIN_T,
1825  wxT( "GetNextPin() did not return a pin object. Bad programmer!" ) );
1826 
1827  // Skip items not used for this part.
1828  if( m_unit && pin->GetUnit() && ( pin->GetUnit() != m_unit ) )
1829  continue;
1830 
1831  if( m_convert && pin->GetConvert() && ( pin->GetConvert() != m_convert ) )
1832  continue;
1833 
1834  // Calculate the pin position relative to the component position and orientation.
1835  aPoints.push_back( m_transform.TransformCoordinate( pin->GetPosition() ) + m_Pos );
1836  }
1837  }
1838  else
1839  {
1840  wxCHECK_RET( 0,
1841  wxT( "Cannot add connection points to list. Cannot find component <" ) +
1842  GetLibId().GetLibItemName() + wxT( "> in any of the loaded libraries." ) );
1843  }
1844 }
1845 
1846 
1848 {
1849  if( PART_SPTR part = m_part.lock() )
1850  {
1851  // Calculate the position relative to the component.
1852  wxPoint libPosition = aPosition - m_Pos;
1853 
1854  return part->LocateDrawItem( m_unit, m_convert, aType, libPosition, m_transform );
1855  }
1856 
1857  return NULL;
1858 }
1859 
1860 
1862 {
1863  wxString tmp;
1864  tmp.Printf( _( "Component %s, %s" ),
1865  GetChars( GetLibId().GetLibItemName() ),
1866  GetChars( GetField( REFERENCE )->GetShownText() ) );
1867  return tmp;
1868 }
1869 
1870 
1871 SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR aInspector, void* aTestData,
1872  const KICAD_T aFilterTypes[] )
1873 {
1874  KICAD_T stype;
1875 
1876  for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
1877  {
1878  // If caller wants to inspect component type or and component children types.
1879  if( stype == Type() )
1880  {
1881  if( SEARCH_QUIT == aInspector( this, aTestData ) )
1882  return SEARCH_QUIT;
1883  }
1884 
1885  switch( stype )
1886  {
1887  case SCH_FIELD_T:
1888  // Test the bounding boxes of fields if they are visible and not empty.
1889  for( int ii = 0; ii < GetFieldCount(); ii++ )
1890  {
1891  if( SEARCH_QUIT == aInspector( GetField( ii ), (void*) this ) )
1892  return SEARCH_QUIT;
1893  }
1894  break;
1895 
1897  if( SEARCH_QUIT == aInspector( GetField( REFERENCE ), (void*) this ) )
1898  return SEARCH_QUIT;
1899  break;
1900 
1902  if( SEARCH_QUIT == aInspector( GetField( VALUE ), (void*) this ) )
1903  return SEARCH_QUIT;
1904  break;
1905 
1907  if( SEARCH_QUIT == aInspector( GetField( FOOTPRINT ), (void*) this ) )
1908  return SEARCH_QUIT;
1909  break;
1910 
1911 
1912  case LIB_PIN_T:
1913  if( PART_SPTR part = m_part.lock() )
1914  {
1915  LIB_PINS pins;
1916 
1917  part->GetPins( pins, m_unit, m_convert );
1918 
1919  for( size_t i = 0; i < pins.size(); i++ )
1920  {
1921  if( SEARCH_QUIT == aInspector( pins[ i ], (void*) this ) )
1922  return SEARCH_QUIT;
1923  }
1924  }
1925  break;
1926 
1927  default:
1928  break;
1929  }
1930  }
1931 
1932  return SEARCH_CONTINUE;
1933 }
1934 
1935 
1937  SCH_SHEET_PATH* aSheetPath )
1938 {
1939  if( PART_SPTR part = m_part.lock() )
1940  {
1941  for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
1942  {
1943  wxASSERT( pin->Type() == LIB_PIN_T );
1944 
1945  if( pin->GetUnit() && ( pin->GetUnit() != GetUnitSelection( aSheetPath ) ) )
1946  continue;
1947 
1948  if( pin->GetConvert() && ( pin->GetConvert() != GetConvert() ) )
1949  continue;
1950 
1951  wxPoint pos = GetTransform().TransformCoordinate( pin->GetPosition() ) + m_Pos;
1952 
1953  NETLIST_OBJECT* item = new NETLIST_OBJECT();
1954  item->m_SheetPathInclude = *aSheetPath;
1955  item->m_Comp = (SCH_ITEM*) pin;
1956  item->m_SheetPath = *aSheetPath;
1957  item->m_Type = NET_PIN;
1958  item->m_Link = (SCH_ITEM*) this;
1959  item->m_ElectricalPinType = pin->GetType();
1960  item->m_PinNum = pin->GetNumber();
1961  item->m_Label = pin->GetName();
1962  item->m_Start = item->m_End = pos;
1963 
1964  aNetListItems.push_back( item );
1965 
1966  if( pin->IsPowerConnection() )
1967  {
1968  // There is an associated PIN_LABEL.
1969  item = new NETLIST_OBJECT();
1970  item->m_SheetPathInclude = *aSheetPath;
1971  item->m_Comp = NULL;
1972  item->m_SheetPath = *aSheetPath;
1973  item->m_Type = NET_PINLABEL;
1974  item->m_Label = pin->GetName();
1975  item->m_Start = pos;
1976  item->m_End = item->m_Start;
1977 
1978  aNetListItems.push_back( item );
1979  }
1980  }
1981  }
1982 }
1983 
1984 
1985 bool SCH_COMPONENT::operator <( const SCH_ITEM& aItem ) const
1986 {
1987  if( Type() != aItem.Type() )
1988  return Type() < aItem.Type();
1989 
1990  SCH_COMPONENT* component = (SCH_COMPONENT*) &aItem;
1991 
1992  EDA_RECT rect = GetBodyBoundingBox();
1993 
1994  if( rect.GetArea() != component->GetBodyBoundingBox().GetArea() )
1995  return rect.GetArea() < component->GetBodyBoundingBox().GetArea();
1996 
1997  if( m_Pos.x != component->m_Pos.x )
1998  return m_Pos.x < component->m_Pos.x;
1999 
2000  if( m_Pos.y != component->m_Pos.y )
2001  return m_Pos.y < component->m_Pos.y;
2002 
2003  return false;
2004 }
2005 
2006 
2007 bool SCH_COMPONENT::operator==( const SCH_COMPONENT& aComponent ) const
2008 {
2009  if( GetFieldCount() != aComponent.GetFieldCount() )
2010  return false;
2011 
2012  for( int i = VALUE; i < GetFieldCount(); i++ )
2013  {
2014  if( GetField( i )->GetText().Cmp( aComponent.GetField( i )->GetText() ) != 0 )
2015  return false;
2016  }
2017 
2018  return true;
2019 }
2020 
2021 
2022 bool SCH_COMPONENT::operator!=( const SCH_COMPONENT& aComponent ) const
2023 {
2024  return !( *this == aComponent );
2025 }
2026 
2027 
2029 {
2030  wxCHECK_MSG( Type() == aItem.Type(), *this,
2031  wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
2032  GetClass() );
2033 
2034  if( &aItem != this )
2035  {
2036  SCH_ITEM::operator=( aItem );
2037 
2038  SCH_COMPONENT* c = (SCH_COMPONENT*) &aItem;
2039 
2040  m_lib_id = c->m_lib_id;
2041  m_part = c->m_part;
2042  m_Pos = c->m_Pos;
2043  m_unit = c->m_unit;
2044  m_convert = c->m_convert;
2045  m_transform = c->m_transform;
2046 
2048 
2049  m_Fields = c->m_Fields; // std::vector's assignment operator.
2050 
2051  // Reparent fields after assignment to new component.
2052  for( int ii = 0; ii < GetFieldCount(); ++ii )
2053  {
2054  GetField( ii )->SetParent( this );
2055  }
2056  }
2057 
2058  return *this;
2059 }
2060 
2061 
2062 bool SCH_COMPONENT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
2063 {
2064  EDA_RECT bBox = GetBodyBoundingBox();
2065  bBox.Inflate( aAccuracy );
2066 
2067  if( bBox.Contains( aPosition ) )
2068  return true;
2069 
2070  return false;
2071 }
2072 
2073 
2074 bool SCH_COMPONENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
2075 {
2077  return false;
2078 
2079  EDA_RECT rect = aRect;
2080 
2081  rect.Inflate( aAccuracy );
2082 
2083  if( aContained )
2084  return rect.Contains( GetBodyBoundingBox() );
2085 
2086  return rect.Intersects( GetBodyBoundingBox() );
2087 }
2088 
2089 
2090 bool SCH_COMPONENT::doIsConnected( const wxPoint& aPosition ) const
2091 {
2092  std::vector< wxPoint > pts;
2093 
2094  GetConnectionPoints( pts );
2095 
2096  for( size_t i = 0; i < pts.size(); i++ )
2097  {
2098  if( pts[i] == aPosition )
2099  return true;
2100  }
2101 
2102  return false;
2103 }
2104 
2105 
2107 {
2108  SCH_FIELD* rf = GetField( REFERENCE );
2109  return ! rf->GetText().StartsWith( wxT( "#" ) );
2110 }
2111 
2112 
2113 void SCH_COMPONENT::Plot( PLOTTER* aPlotter )
2114 {
2115  TRANSFORM temp;
2116 
2117  if( PART_SPTR part = m_part.lock() )
2118  {
2119  temp = GetTransform();
2120 
2121  part->Plot( aPlotter, GetUnit(), GetConvert(), m_Pos, temp );
2122 
2123  for( size_t i = 0; i < m_Fields.size(); i++ )
2124  {
2125  m_Fields[i].Plot( aPlotter );
2126  }
2127  }
2128 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition of the SCH_SHEET class for Eeschema.
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
int GetCount() const
Function GetCount returns the number of objects in the list.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
void Offset(int dx, int dy)
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void SetModified()
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
const wxString traceFindItem
Flag to enable find item tracing using the WXTRACE environment variable.
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Draw part.
Part library alias object definition.
bool IsMoving() const
Definition: base_struct.h:218
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:168
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
TRANSFORM & GetTransform() const
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
void SetTransform(const TRANSFORM &aTransform)
PNG memory record (file in memory).
Definition: bitmap_types.h:38
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void UpdateUnit(int aUnit)
change the unit id to aUnit has maening only for multiple parts per package Do not change the modifie...
wxString GetPath(const SCH_SHEET_PATH *sheet) const
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
int GetOrientation()
Function GetOrientation Used to display component orientation (in dialog editor or info) ...
int y2
Definition: transform.h:51
EDA_ITEM * GetCurItem() const
SCH_SHEET_PATH m_SheetPathInclude
Class LIB_TEXT defines a component library graphical text item.
Definition: lib_text.h:45
time_t m_TimeStamp
Time stamp used for logical links.
Definition: base_struct.h:169
bool Contains(const wxPoint &aPoint) const
Function Contains.
SCH_FIELDS m_Fields
Variable length list of fields.
Definition: sch_component.h:90
const SCH_SHEET_PATH * m_currentSheetPath
A temporary sheet path is required to generate the correct reference designator string in complex hei...
wxPoint GetScreenCoord(const wxPoint &aPoint)
Function GetScreenCoord Returns the coordinated point relative to the orientation of the component of...
void ImportValues(const LIB_FIELD &aSource)
Function ImportValues copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:221
bool Resolve(PART_LIBS *aLibs)
Function Resolve [re-]assigns the current LIB_PART from aLibs which this component is based on...
static bool sort_by_libid(const SCH_COMPONENT *ref, SCH_COMPONENT *cmp)
const wxString GetLibraryName()
wxArrayString m_PathsAndReferences
Defines the hierarchical path and reference of the component.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:124
wxPoint m_Pos
Name and library where symbol was loaded from, i.e. "74xx:74LS00".
Definition: sch_component.h:76
void SetItalic(bool isItalic)
Definition: eda_text.h:169
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
const EDA_RECT GetBodyBoundingBox(int aUnit, int aConvert) const
Function GetBodyBoundingBox.
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_field.cpp:118
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetVisible(bool aVisible)
Definition: eda_text.h:175
time_t GetNewTimeStamp()
Definition: common.cpp:166
int x2
Definition: transform.h:50
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
bool IsSelected() const
Definition: base_struct.h:221
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
Definition: sch_field.cpp:314
SCH_FIELD * FindField(const wxString &aFieldName)
Function FindField searches for SCH_FIELD with aFieldName and returns it if found, else NULL.
LIB_PIN * GetPin(const wxString &number)
Function GetPin finds a component pin by number.
int x1
Definition: transform.h:48
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
void SetRef(const SCH_SHEET_PATH *sheet, const wxString &ref)
Set the reference, for the given sheet path.
SCH_SHEET_PATH m_SheetPath
LIB_ITEM * GetDrawItem(const wxPoint &aPosition, KICAD_T aType=TYPE_NOT_INIT)
Function GetDrawItem().
ELECTRICAL_PINTYPE m_ElectricalPinType
void SetUnitSelection(SCH_SHEET_PATH *aSheet, int aUnitSelection)
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
int GetUnitCount() const
Function GetUnitCount returns the number of parts per package of the component.
std::vector< bool > m_isDangling
One isDangling per pin.
Definition: sch_component.h:94
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
EDA_RECT GetBodyBoundingBox() const
Function GetBodyBoundingBox Return a bounding box for the component body but not the fields...
Class LIB_ID.
Definition: lib_id.h:56
NETLIST_ITEM_T m_Type
#define abs(a)
Definition: auxiliary.h:84
#define TEXT_ANGLE_VERT
Definition: common.h:92
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
search types array terminator (End Of Types)
Definition: typeinfo.h:94
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
Definition: colors.h:54
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Function GetFields populates a std::vector with SCH_FIELDs.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
void SetConvert(int aConvert)
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:135
bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
#define IS_NEW
New item, just created.
Definition: base_struct.h:113
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:104
Class SCH_COLLECTOR.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
int GetConvert() const
int y1
Definition: transform.h:49
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:111
#define SELECTED
Definition: base_struct.h:120
void SetLibId(const LIB_ID &aName, PART_LIBS *aLibs=NULL)
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
void SetTimeStamp(time_t aNewTimeStamp)
Function SetTimeStamp changes the time stamp to aNewTimeStamp updates the reference path...
double GetArea() const
Function GetArea returns the area of the rectangle.
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
PART_REF m_part
points into the PROJECT's libraries to the LIB_PART for this component
Definition: sch_component.h:92
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
void SetHeight(int val)
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
static void ResolveAll(const SCH_COLLECTOR &aComponents, PART_LIBS *aLibs)
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsMouseCaptured() const
const wxString & GetName() const
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
wxPoint GetPinPhysicalPosition(LIB_PIN *Pin)
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
bool operator<(const SCH_ITEM &aItem) const override
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
wxString GetDescription() const
SCH_COMPONENT(const wxPoint &pos=wxPoint(0, 0), SCH_ITEM *aParent=NULL)
PART_SPTR SharedPtr()
std::string toUTFTildaText(const wxString &txt)
Function toUTFTildaText convert a wxString to UTF8 and replace any control characters with a ~...
void Empty()
Definition: eda_text.h:231
Class LIB_PART defines a library part object.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Function AddField adds a field to the component.
bool IsDangling() const override
Return whether any pin has dangling status.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:122
EDA_RECT * GetClipBox()
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
void SetX(int val)
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void SetUnit(int aUnit)
change the unit id to aUnit has maening only for multiple parts per package Also set the modified fla...
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
int GetBottom() const
int GetUnit() const
Class SCH_SHEET_PATH.
bool IsInNetlist() const
static PART_DRAW_OPTIONS Default()
void clear()
Function clear.
Definition: lib_id.cpp:114
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Function ClearAnnotation clears exiting component annotation ( i.i IC23 changed to IC...
int GetRight() const
void SetWidth(int val)
void SetLayer(LAYERSCH_ID aLayer)
Function SetLayer sets the layer this item is on.
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
bool Load(LINE_READER &aLine, wxString &aErrorMsg) override
Function Load reads a schematic item from aLine in a .sch file.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
void SetEndPosition(const wxPoint &aPosition)
Definition: lib_rectangle.h:62
void SetY(int val)
bool operator==(const SCH_COMPONENT &aComponent) const
SCH_ITEM & operator=(const SCH_ITEM &aItem)
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:471
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Class PART_LIBS is a collection of PART_LIBs.
Definition of the NETLIST_OBJECT class.
int m_unit
The unit for multiple part per package components.
Definition: sch_component.h:81
Field Value of part, i.e. "3.3K".
void Init(const wxPoint &pos=wxPoint(0, 0))
bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList) override
Test if the component's dangling state has changed for all pins.
LAYERSCH_ID m_Layer
Base plotter engine class.
Definition: plot_common.h:86
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
Definition the SCH_COMPONENT class for Eeschema.
#define NULL_STRING
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:70
void GetPins(std::vector< LIB_PIN * > &aPinsList)
Function GetPins populate a vector with all the pins.
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
const wxString & GetName() const
int GetFieldCount() const
Function GetFieldCount returns the number of fields in this component.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_field.cpp:251
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...
static double square(int x)
Definition: trigo.cpp:138
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void AddHierarchicalReference(const wxString &aPath, const wxString &aRef, int aMulti)
Function AddHierarchicalReference adds a full hierarchical reference (path + local reference) ...
bool IsVisible() const
Definition: eda_text.h:176
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
bool IsPinDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList, LIB_PINS &aLibPins, unsigned aPin)
Test if the component's dangling state has changed for one given pin index.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Virtual function, from the base class SCH_ITEM::Draw.
#define ROTATE_VALUES_COUNT
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:488
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:175
Class EDA_RECT handles the component boundary box.
void SetName(const wxString &aName)
Definition: sch_field.h:85
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
int GetX() const
const LIB_ID & GetLibId() const
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
UTF8 Format() const
Function Format.
Definition: lib_id.cpp:263
int GetY() const
virtual wxString GetClass() const override
Function GetClass returns the class name.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
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:378
bool operator!=(const SCH_COMPONENT &aComponent) const
int m_convert
The alternate body style for components that have more than one body style defined.
Definition: sch_component.h:82
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
Definition for part library class.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void SetId(int aId)
Definition: sch_field.h:89
int ReadDelimitedText(wxString *aDest, const char *aSource)
Function ReadDelimitedText copies bytes from aSource delimited string segment to aDest wxString...
Definition: string.cpp:43
SEARCH_RESULT
Definition: base_struct.h:68
static bool IsReferenceStringValid(const wxString &aReferenceString)
Function IsReferenceStringValid (static) Tests for an acceptable reference string An acceptable refer...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxString GetClass() const override
Function GetClass returns the class name.
Message panel definition file.
AUTOPLACED m_fieldsAutoplaced
indicates status of field autoplacement
Definition: sch_component.h:96
wxString m_prefix
C, R, U, Q etc - the first character which typically indicates what the component is...
Definition: sch_component.h:85
void SetBold(bool aBold)
Definition: eda_text.h:172
wxString GetKeyWords() const
TRANSFORM m_transform
The rotation/mirror transformation matrix.
Definition: sch_component.h:89
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition...
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
void GetFields(LIB_FIELDS &aList)
Function GetFields returns a list of fields withing this part.
int GetDefaultTextSize()
Default size for text in general.
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
void SetOrientation(int aOrientation)
Function SetOrientation computes the new transform matrix based on aOrientation for the component whi...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
#define IS_MOVED
Item being moved.
Definition: base_struct.h:112
Definition: colors.h:62