KiCad PCB EDA Suite
sch_field.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) 2004-2021 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 
25 /*
26  * Fields are texts attached to a symbol, some of which have a special meaning.
27  * Fields 0 and 1 are very important: reference and value.
28  * Field 2 is used as default footprint name.
29  * Field 3 is used to point to a datasheet (usually a URL).
30  * Fields 4+ are user fields. They can be renamed and can appear in reports.
31  */
32 
33 #include <wx/menu.h>
34 #include <common.h> // for ExpandTextVars
35 #include <eda_item.h>
36 #include <gr_text.h>
37 #include <sch_edit_frame.h>
38 #include <plotter.h>
39 #include <bitmaps.h>
40 #include <core/mirror.h>
41 #include <kiway.h>
42 #include <general.h>
43 #include <class_library.h>
44 #include <sch_symbol.h>
45 #include <sch_field.h>
46 #include <schematic.h>
48 #include <kicad_string.h>
49 #include <trace_helpers.h>
50 #include <trigo.h>
51 #include <eeschema_id.h>
52 #include <tool/tool_manager.h>
53 #include <tools/ee_actions.h>
54 
55 SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
56  const wxString& aName ) :
57  SCH_ITEM( aParent, SCH_FIELD_T ),
58  EDA_TEXT( wxEmptyString ),
59  m_id( 0 ),
60  m_name( aName )
61 {
62  SetTextPos( aPos );
63  SetId( aFieldId ); // will also set the layer
64  SetVisible( false );
65 }
66 
67 
69 {
70 }
71 
72 
74 {
75  return new SCH_FIELD( *this );
76 }
77 
78 
79 void SCH_FIELD::SetId( int aId )
80 {
81  m_id = aId;
82 
83  if( m_parent && m_parent->Type() == SCH_SHEET_T )
84  {
85  switch( m_id )
86  {
87  case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
89  default: SetLayer( LAYER_SHEETFIELDS ); break;
90  }
91  }
92  else
93  {
94  switch( m_id )
95  {
97  case VALUE_FIELD: SetLayer( LAYER_VALUEPART ); break;
98  default: SetLayer( LAYER_FIELDS ); break;
99  }
100  }
101 }
102 
103 
104 wxString SCH_FIELD::GetShownText( int aDepth ) const
105 {
106  std::function<bool( wxString* )> symbolResolver =
107  [&]( wxString* token ) -> bool
108  {
109  if( token->Contains( ':' ) )
110  {
111  if( Schematic()->ResolveCrossReference( token, aDepth ) )
112  return true;
113  }
114  else
115  {
116  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
117 
118  if( parentSymbol->ResolveTextVar( token, aDepth + 1 ) )
119  return true;
120 
121  SCHEMATIC* schematic = parentSymbol->Schematic();
122  SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
123 
124  if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
125  return true;
126  }
127 
128  return false;
129  };
130 
131  std::function<bool( wxString* )> sheetResolver =
132  [&]( wxString* token ) -> bool
133  {
134  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
135  return sheet->ResolveTextVar( token, aDepth + 1 );
136  };
137 
138  std::function<bool( wxString* )> globalLabelResolver =
139  [&]( wxString* token ) -> bool
140  {
141  SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( m_parent );
142  return globalLabel->ResolveTextVar( token, aDepth + 1 );
143  };
144 
145  PROJECT* project = nullptr;
146  bool processTextVars = false;
147  wxString text = EDA_TEXT::GetShownText( &processTextVars );
148 
149  if( processTextVars )
150  {
151  if( Schematic() )
152  project = &Schematic()->Prj();
153 
154  if( aDepth < 10 )
155  {
156  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
157  text = ExpandTextVars( text, &symbolResolver, nullptr, project );
158  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
159  text = ExpandTextVars( text, &sheetResolver, nullptr, project );
160  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
161  text = ExpandTextVars( text, &globalLabelResolver, nullptr, project );
162  else
164  }
165  }
166 
167  // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
168  // id and the parent's type.
169 
170  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
171  {
172  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
173 
174  if( m_id == REFERENCE_FIELD )
175  {
176  // For more than one part per package, we must add the part selection
177  // A, B, ... or 1, 2, .. to the reference.
178  if( parentSymbol->GetUnitCount() > 1 )
179  text << LIB_PART::SubReference( parentSymbol->GetUnit() );
180  }
181  }
182  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
183  {
184  if( m_id == SHEETFILENAME )
185  text = _( "File:" ) + wxS( " " )+ text;
186  }
187 
188  return text;
189 }
190 
191 
193 {
194  return GetEffectiveTextPenWidth();
195 }
196 
197 
198 void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
199 {
200  wxDC* DC = aSettings->GetPrintDC();
202  int orient;
203  wxPoint textpos;
204  int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
205 
206  if( ( !IsVisible() && !IsForceVisible() ) || IsVoid() )
207  return;
208 
209  // Calculate the text orientation according to the symbol orientation.
210  orient = GetTextAngle();
211 
212  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
213  {
214  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
215 
216  if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
217  {
218  if( orient == TEXT_ANGLE_HORIZ )
219  orient = TEXT_ANGLE_VERT;
220  else
221  orient = TEXT_ANGLE_HORIZ;
222  }
223  }
224 
225  /*
226  * Calculate the text justification, according to the symbol orientation/mirror.
227  * This is a bit complicated due to cumulative calculations:
228  * - numerous cases (mirrored or not, rotation)
229  * - the GRText function will also recalculate H and V justifications according to the text
230  * orientation.
231  * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
232  * to calculate so the more easily way is to use no justifications (centered text) and use
233  * GetBoundingBox to know the text coordinate considered as centered
234  */
235  EDA_RECT boundaryBox = GetBoundingBox();
236  textpos = boundaryBox.Centre() + aOffset;
237 
238  GRText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_HJUSTIFY_CENTER,
239  GR_TEXT_VJUSTIFY_CENTER, penWidth, IsItalic(), IsBold() );
240 }
241 
242 
243 void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
244 {
245  SetEffects( aSource );
246 }
247 
248 
250 {
251  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_FIELD_T),
252  wxT( "Cannot swap field data with invalid item." ) );
253 
254  SCH_FIELD* item = (SCH_FIELD*) aItem;
255 
256  std::swap( m_layer, item->m_layer );
257  SwapText( *item );
258  SwapEffects( *item );
259 }
260 
261 
263 {
264  // Calculate the text bounding box:
265  EDA_RECT rect = GetTextBox();
266 
267  // Calculate the bounding box position relative to the parent:
268  wxPoint origin = GetParentPosition();
269  wxPoint pos = GetTextPos() - origin;
270  wxPoint begin = rect.GetOrigin() - origin;
271  wxPoint end = rect.GetEnd() - origin;
272  RotatePoint( &begin, pos, GetTextAngle() );
273  RotatePoint( &end, pos, GetTextAngle() );
274 
275  // Now, apply the symbol transform (mirror/rot)
276  TRANSFORM transform;
277 
278  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
279  {
280  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
281 
282  // Due to the Y axis direction, we must mirror the bounding box,
283  // relative to the text position:
284  MIRROR( begin.y, pos.y );
285  MIRROR( end.y, pos.y );
286 
287  transform = parentSymbol->GetTransform();
288  }
289  else
290  {
291  transform = TRANSFORM( 1, 0, 0, 1 ); // identity transform
292  }
293 
294  rect.SetOrigin( transform.TransformCoordinate( begin ) );
295  rect.SetEnd( transform.TransformCoordinate( end ) );
296 
297  rect.Move( origin );
298  rect.Normalize();
299 
300  return rect;
301 }
302 
303 
305 {
306  wxPoint render_center = GetBoundingBox().Centre();
307  wxPoint pos = GetPosition();
308 
309  switch( GetHorizJustify() )
310  {
312  return render_center.x < pos.x;
314  return render_center.x > pos.x;
315  default:
316  return false;
317  }
318 }
319 
320 
321 bool SCH_FIELD::IsVoid() const
322 {
323  return GetText().Len() == 0;
324 }
325 
326 
327 bool SCH_FIELD::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
328 {
329  wxString text = GetShownText();
330  int flags = aSearchData.GetFlags();
331  bool searchHiddenFields = flags & FR_SEARCH_ALL_FIELDS;
332  bool searchAndReplace = flags & FR_SEARCH_REPLACE;
333  bool replaceReferences = flags & FR_REPLACE_REFERENCES;
334 
335  wxLogTrace( traceFindItem, wxT( " child item " )
337 
338  if( !IsVisible() && !searchHiddenFields )
339  return false;
340 
342  {
343  if( searchAndReplace && !replaceReferences )
344  return false;
345 
346  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
347  wxASSERT( aAuxData );
348 
349  // Take sheet path into account which effects the reference field and the unit for
350  // symbols with multiple parts.
351  if( aAuxData )
352  {
353  text = parentSymbol->GetRef((SCH_SHEET_PATH*) aAuxData );
354 
355  if( SCH_ITEM::Matches( text, aSearchData ) )
356  return true;
357 
358  if( parentSymbol->GetUnitCount() > 1 )
359  text << LIB_PART::SubReference( parentSymbol->GetUnit() );
360  }
361  }
362 
363  return SCH_ITEM::Matches( text, aSearchData );
364 }
365 
366 
368 {
369  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
370  {
371  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
372 
373  if( m_id == VALUE_FIELD )
374  {
375  if( parentSymbol->GetPartRef() && parentSymbol->GetPartRef()->IsPower() )
376  return false;
377  }
378  }
379  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
380  {
381  // See comments in SCH_FIELD::Replace(), below.
382  if( m_id == SHEETFILENAME )
383  return false;
384  }
385  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
386  {
387  return false;
388  }
389 
390  return true;
391 }
392 
393 
394 bool SCH_FIELD::Replace( const wxFindReplaceData& aSearchData, void* aAuxData )
395 {
396  wxString text;
397  bool resolve = false; // Replace in source text, not shown text
398  bool isReplaced = false;
399 
400  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
401  {
402  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
403 
404  switch( m_id )
405  {
406  case REFERENCE_FIELD:
407  wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
408 
409  if( !( aSearchData.GetFlags() & FR_REPLACE_REFERENCES ) )
410  return false;
411 
412  text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
413  isReplaced = EDA_ITEM::Replace( aSearchData, text );
414 
415  if( isReplaced )
416  parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
417 
418  break;
419 
420  case VALUE_FIELD:
421  wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
422 
423  text = parentSymbol->GetValue((SCH_SHEET_PATH*) aAuxData, resolve );
424  isReplaced = EDA_ITEM::Replace( aSearchData, text );
425 
426  if( isReplaced )
427  parentSymbol->SetValue( (SCH_SHEET_PATH*) aAuxData, text );
428 
429  break;
430 
431  case FOOTPRINT_FIELD:
432  wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
433 
434  text = parentSymbol->GetFootprint((SCH_SHEET_PATH*) aAuxData, resolve );
435  isReplaced = EDA_ITEM::Replace( aSearchData, text );
436 
437  if( isReplaced )
438  parentSymbol->SetFootprint( (SCH_SHEET_PATH*) aAuxData, text );
439 
440  break;
441 
442  default:
443  isReplaced = EDA_TEXT::Replace( aSearchData );
444  }
445  }
446  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
447  {
448  isReplaced = EDA_TEXT::Replace( aSearchData );
449 
450  if( m_id == SHEETFILENAME && isReplaced )
451  {
452  // If we allowed this we'd have a bunch of work to do here, including warning
453  // about it not being undoable, checking for recursive hierarchies, reloading
454  // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
455  }
456  }
457 
458  return isReplaced;
459 }
460 
461 
462 void SCH_FIELD::Rotate( wxPoint aCenter )
463 {
464  wxPoint pt = GetPosition();
465  RotatePoint( &pt, aCenter, 900 );
466  SetPosition( pt );
467 }
468 
469 
470 wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
471 {
472  return wxString::Format( "%s '%s'",
473  GetName(),
474  ShortenedShownText() );
475 }
476 
477 
479 {
480  constexpr int START_ID = 1;
481 
482  static wxString back = "HYPERTEXT_BACK";
483  wxMenu menu;
484  SCH_TEXT* label = dynamic_cast<SCH_TEXT*>( m_parent );
485 
486  if( label && Schematic() )
487  {
488  auto it = Schematic()->GetPageRefsMap().find( label->GetText() );
489 
490  if( it != Schematic()->GetPageRefsMap().end() )
491  {
492  std::map<wxString, wxString> sheetNames;
493  std::vector<wxString> pageListCopy;
494 
495  pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
496  std::sort( pageListCopy.begin(), pageListCopy.end() );
497 
499  {
500  wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
501  pageListCopy.erase( std::remove( pageListCopy.begin(),
502  pageListCopy.end(),
503  currentPage ), pageListCopy.end() );
504 
505  if( pageListCopy.empty() )
506  return;
507  }
508 
509  for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
510  {
511  if( sheet.size() == 1 )
512  sheetNames[ sheet.GetPageNumber() ] = _( "<root sheet>" );
513  else
514  sheetNames[ sheet.GetPageNumber() ] = sheet.Last()->GetName();
515  }
516 
517  for( int i = 0; i < (int) pageListCopy.size(); ++i )
518  {
519  menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
520  pageListCopy[i],
521  sheetNames[ pageListCopy[i] ] ) );
522  }
523 
524  menu.AppendSeparator();
525  menu.Append( 999, _( "Back to Previous Selected Sheet" ) );
526 
527  int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
528  void* param = nullptr;
529 
530  if( sel >= 0 && sel < (int) pageListCopy.size() )
531  param = (void*) &pageListCopy[ sel ];
532  else if( sel == 999 )
533  param = (void*) &back;
534 
535  if( param )
536  aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param );
537  }
538  }
539 }
540 
541 
542 wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
543 {
544  if( !m_name.IsEmpty() )
545  return m_name;
546  else if( aUseDefaultName )
547  {
548  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
550  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
552  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
553  return _( "Intersheet References" );
554  }
555 
556  return wxEmptyString;
557 }
558 
559 
561 {
562  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
563  {
564  switch( m_id )
565  {
566  case REFERENCE_FIELD: return wxT( "Reference" );
567  case VALUE_FIELD: return wxT( "Value" );
568  case FOOTPRINT_FIELD: return wxT( "Footprint" );
569  case DATASHEET_FIELD: return wxT( "Datasheet" );
570  }
571  }
572  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
573  {
574  switch( m_id )
575  {
576  case SHEETNAME: return wxT( "Sheetname" );
577  case SHEETFILENAME: return wxT( "Sheetfile" );
578  }
579  }
580  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
581  {
582  return wxT( "Intersheet References" );
583  }
584 
585  return m_name;
586 }
587 
588 
590 {
591  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
592  {
593  switch( m_id )
594  {
598  default: return BITMAPS::text;
599  }
600  }
601 
602  return BITMAPS::text;
603 }
604 
605 
606 bool SCH_FIELD::HitTest( const wxPoint& aPosition, int aAccuracy ) const
607 {
608  // Do not hit test hidden or empty fields.
609  if( !IsVisible() || IsVoid() )
610  return false;
611 
612  EDA_RECT rect = GetBoundingBox();
613 
614  rect.Inflate( aAccuracy );
615 
616  return rect.Contains( aPosition );
617 }
618 
619 
620 bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
621 {
622  // Do not hit test hidden fields.
623  if( !IsVisible() || IsVoid() )
624  return false;
625 
626  EDA_RECT rect = aRect;
627 
628  rect.Inflate( aAccuracy );
629 
630  if( aContained )
631  return rect.Contains( GetBoundingBox() );
632 
633  return rect.Intersects( GetBoundingBox() );
634 }
635 
636 
637 void SCH_FIELD::Plot( PLOTTER* aPlotter ) const
638 {
639  RENDER_SETTINGS* settings = aPlotter->RenderSettings();
640  COLOR4D color = settings->GetLayerColor( GetLayer() );
641  int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
642 
643  penWidth = std::max( penWidth, settings->GetMinPenWidth() );
644 
645  if( !IsVisible() )
646  return;
647 
648  if( IsVoid() )
649  return;
650 
651  // Calculate the text orientation, according to the symbol orientation/mirror
652  int orient = GetTextAngle();
653 
654  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
655  {
656  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
657 
658  if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
659  {
660  if( orient == TEXT_ANGLE_HORIZ )
661  orient = TEXT_ANGLE_VERT;
662  else
663  orient = TEXT_ANGLE_HORIZ;
664  }
665  }
666 
667  /*
668  * Calculate the text justification, according to the symbol orientation/mirror.
669  * This is a bit complicated due to cumulative calculations:
670  * - numerous cases (mirrored or not, rotation)
671  * - the plotter's Text function will also recalculate H and V justifications according to
672  * the text orientation.
673  * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
674  * to calculate so the easier way is to use no justifications (centered text) and use
675  * GetBoundingBox to know the text coordinate considered as centered
676  */
677  EDA_RECT BoundaryBox = GetBoundingBox();
680  wxPoint textpos = BoundaryBox.Centre();
681 
682  aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify,
683  penWidth, IsItalic(), IsBold() );
684 }
685 
686 
687 void SCH_FIELD::SetPosition( const wxPoint& aPosition )
688 {
689  // Actual positions are calculated by the rotation/mirror transform of the parent symbol
690  // of the field. The inverse transform is used to calculate the position relative to the
691  // parent symbol.
692  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
693  {
694  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
695  wxPoint relPos = aPosition - parentSymbol->GetPosition();
696 
697  relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
698 
699  SetTextPos( relPos + parentSymbol->GetPosition() );
700  return;
701  }
702 
703  SetTextPos( aPosition );
704 }
705 
706 
707 wxPoint SCH_FIELD::GetPosition() const
708 {
709  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
710  {
711  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
712  wxPoint relativePos = GetTextPos() - parentSymbol->GetPosition();
713 
714  relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
715 
716  return relativePos + parentSymbol->GetPosition();
717  }
718 
719  return GetTextPos();
720 }
721 
722 
724 {
725  return m_parent ? m_parent->GetPosition() : wxPoint( 0, 0 );
726 }
727 
728 
729 bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
730 {
731  if( Type() != aItem.Type() )
732  return Type() < aItem.Type();
733 
734  auto field = static_cast<const SCH_FIELD*>( &aItem );
735 
736  if( GetId() != field->GetId() )
737  return GetId() < field->GetId();
738 
739  if( GetText() != field->GetText() )
740  return GetText() < field->GetText();
741 
742  if( GetLibPosition().x != field->GetLibPosition().x )
743  return GetLibPosition().x < field->GetLibPosition().x;
744 
745  if( GetLibPosition().y != field->GetLibPosition().y )
746  return GetLibPosition().y < field->GetLibPosition().y;
747 
748  return GetName() < field->GetName();
749 }
Field Reference of part, i.e. "IC21".
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
bool IsBold() const
Definition: eda_text.h:190
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:529
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:415
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:151
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
void Move(const wxPoint &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: eda_rect.cpp:51
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
Container for project specific data.
Definition: project.h:62
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
Definition: sch_symbol.cpp:932
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58
Holds all the data relating to one schematic.
Definition: schematic.h:59
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:73
bool IsVisible() const
Definition: eda_text.h:193
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:243
void Rotate(wxPoint aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:462
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:137
bool Replace(const wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:178
wxPoint GetPosition() const override
Definition: sch_field.cpp:707
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:129
int color
Definition: DXF_plotter.cpp:60
Field object used in symbol libraries.
Definition: lib_field.h:59
EDA_RECT GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:223
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:59
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
int GetUnitCount() const
Return the number of units per package of the symbol.
Definition: sch_symbol.cpp:360
void SetVisible(bool aVisible)
Definition: eda_text.h:192
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:181
int GetId() const
Definition: sch_field.h:114
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:126
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_field.cpp:470
virtual wxPoint GetPosition() const
Definition: eda_item.h:302
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
The base class for create windows for drawing purpose.
void DoHypertextMenu(EDA_DRAW_FRAME *aFrame) override
Definition: sch_field.cpp:478
wxString m_name
Definition: sch_field.h:210
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:104
bool IsVoid() const
Definition: sch_field.cpp:321
name of datasheet
bool Replace(const wxFindReplaceData &aSearchData, void *aAuxData=NULL) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:394
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:219
const wxString GetFootprint(const SCH_SHEET_PATH *sheet, bool aResolve) const
Return the instance-specific footprint assignment for the given sheet path.
Definition: sch_symbol.cpp:614
bool IsItalic() const
Definition: eda_text.h:187
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:729
int y1
Definition: transform.h:49
const wxPoint GetEnd() const
Definition: eda_rect.h:108
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:560
int GetUnit() const
Definition: sch_symbol.h:195
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: sch_text.cpp:1148
SCH_LAYER_ID m_layer
Definition: sch_item.h:496
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
Field Value of part, i.e. "3.3K".
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
Return the instance-specific value for the given sheet path.
Definition: sch_symbol.cpp:563
#define NULL
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:589
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
void SetEnd(int x, int y)
Definition: eda_rect.h:187
wxString GetPageNumber() const
const wxSize & GetTextSize() const
Definition: eda_text.h:245
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:279
SCH_FIELD(const wxPoint &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:55
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:214
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:202
wxLogTrace helper definitions.
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_field.cpp:606
wxDC * GetPrintDC() const
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:46
wxPoint GetLibPosition() const
Definition: sch_field.h:187
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
TRANSFORM & GetTransform()
Definition: sch_symbol.h:231
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::unique_ptr< LIB_PART > & GetPartRef()
Definition: sch_symbol.h:164
static bool Replace(const wxFindReplaceData &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:143
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
void GRText(wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Function GRText Draw a graphic text (like footprint texts)
Definition: gr_text.cpp:131
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:68
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
EDA_UNITS
Definition: eda_units.h:38
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:471
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
Base plotter engine class.
Definition: plotter.h:121
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:143
bool IsForceVisible() const
Definition: eda_item.h:256
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:155
const wxChar *const traceFindItem
Flag to enable find debug tracing.
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:262
#define _(s)
Definition: 3d_actions.cpp:33
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:249
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: sch_field.cpp:542
Handle the component boundary box.
Definition: eda_rect.h:42
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:447
Schematic symbol object.
Definition: sch_symbol.h:78
wxPoint GetPosition() const override
Definition: sch_symbol.h:641
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
The common library.
wxPoint Centre() const
Definition: eda_rect.h:60
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:304
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
std::map< wxString, std::set< wxString > > & GetPageRefsMap()
Definition: schematic.h:160
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:367
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:210
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
Definition for part library class.
void SetId(int aId)
Definition: sch_field.cpp:79
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:119
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:584
wxPoint GetParentPosition() const
Definition: sch_field.cpp:723
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:198
int m_id
Field index,.
Definition: sch_field.h:208
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:687
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
static TOOL_ACTION hypertextCommand
Definition: ee_actions.h:184
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
Definition: sch_symbol.cpp:635
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:141
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:327
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:637
int GetPenWidth() const override
Definition: sch_field.cpp:192
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:431
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
Field Name Module PCB, i.e. "16DIP300".