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