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