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-2020 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 component, having 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 reserved (not currently used
30  * Fields 4 and more are user fields.
31  * They can be renamed and can appear in reports
32  */
33 
34 #include <wx/menu.h>
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_component.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, project );
158  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
159  text = ExpandTextVars( text, &sheetResolver, project );
160  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
161  text = ExpandTextVars( text, &globalLabelResolver, project );
162  else
163  text = ExpandTextVars( text, nullptr, project );
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( 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( wxFindReplaceData& aSearchData, void* aAuxData )
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  LIB_PART* part = parentSymbol->GetPartRef().get();
376 
377  if( part && part->IsPower() )
378  return false;
379  }
380  }
381  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
382  {
383  // See comments in SCH_FIELD::Replace(), below.
384  if( m_id == SHEETFILENAME )
385  return false;
386  }
387  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
388  {
389  return false;
390  }
391 
392  return true;
393 }
394 
395 
396 bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
397 {
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  if( m_id == REFERENCE_FIELD )
405  {
406  wxCHECK_MSG( aAuxData != NULL, false,
407  wxT( "Cannot replace reference designator without valid sheet path." ) );
408 
409  if( !( aSearchData.GetFlags() & FR_REPLACE_REFERENCES ) )
410  return false;
411 
412  wxString text = parentSymbol->GetRef((SCH_SHEET_PATH*) aAuxData );
413 
414  isReplaced = EDA_ITEM::Replace( aSearchData, text );
415 
416  if( isReplaced )
417  parentSymbol->SetRef((SCH_SHEET_PATH*) aAuxData, text );
418  }
419  else
420  {
421  isReplaced = EDA_TEXT::Replace( aSearchData );
422  }
423  }
424  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
425  {
426  isReplaced = EDA_TEXT::Replace( aSearchData );
427 
428  if( m_id == SHEETFILENAME && isReplaced )
429  {
430  // If we allowed this we'd have a bunch of work to do here, including warning
431  // about it not being undoable, checking for recursive hierarchies, reloading
432  // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
433  }
434  }
435 
436  return isReplaced;
437 }
438 
439 
440 void SCH_FIELD::Rotate( wxPoint aPosition )
441 {
442  wxPoint pt = GetTextPos();
443  RotatePoint( &pt, aPosition, 900 );
444  SetTextPos( pt );
445 }
446 
447 
448 wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
449 {
450  return wxString::Format( "%s '%s'",
451  GetName(),
452  ShortenedShownText() );
453 }
454 
455 
457 {
458  static wxString back = "HYPERTEXT_BACK";
459  wxMenu menu;
460  SCH_TEXT* label = dynamic_cast<SCH_TEXT*>( m_parent );
461 
462  if( label && Schematic() )
463  {
464  auto it = Schematic()->GetPageRefsMap().find( label->GetText() );
465 
466  if( it != Schematic()->GetPageRefsMap().end() )
467  {
468  std::map<wxString, wxString> sheetNames;
469  std::vector<wxString> pageListCopy;
470 
471  pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
472  std::sort( pageListCopy.begin(), pageListCopy.end() );
473 
474  for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
475  sheetNames[ sheet.GetPageNumber() ] = sheet.Last()->GetName();
476 
477  for( const wxString& pageNo : pageListCopy )
478  {
479  wxString pageName = pageNo == "/" ? _( "Root" ) : sheetNames[ pageNo ];
480 
481  menu.Append( -1, wxString::Format( _( "Go to Page %s (%s)" ),
482  pageNo,
483  pageName ) );
484  }
485 
486  menu.AppendSeparator();
487  menu.Append( -1, _( "Back" ) );
488 
489  int sel = aFrame->GetPopupMenuSelectionFromUser( menu );
490  void* param = nullptr;
491 
492  if( sel >= 1 && sel <= (int) pageListCopy.size() )
493  param = (void*) &pageListCopy[ sel - 1 ];
494  else if( sel == (int) pageListCopy.size() )
495  param = (void*) &back;
496 
497  if( param )
498  aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param );
499  }
500  }
501 }
502 
503 
504 wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
505 {
506  if( !m_name.IsEmpty() )
507  return m_name;
508  else if( aUseDefaultName )
509  {
510  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
512  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
514  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
515  return _( "Intersheet References" );
516  }
517 
518  return wxEmptyString;
519 }
520 
521 
523 {
524  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
525  {
526  switch( m_id )
527  {
528  case REFERENCE_FIELD: return wxT( "Reference" );
529  case VALUE_FIELD: return wxT( "Value" );
530  case FOOTPRINT_FIELD: return wxT( "Footprint" );
531  case DATASHEET_FIELD: return wxT( "Datasheet" );
532  }
533  }
534  else if( m_parent && m_parent->Type() == SCH_SHEET_T )
535  {
536  switch( m_id )
537  {
538  case SHEETNAME: return wxT( "Sheetname" );
539  case SHEETFILENAME: return wxT( "Sheetfile" );
540  }
541  }
542  else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
543  {
544  return wxT( "Intersheet References" );
545  }
546 
547  return m_name;
548 }
549 
550 
552 {
553  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
554  {
555  switch( m_id )
556  {
557  case REFERENCE_FIELD: return edit_comp_ref_xpm;
558  case VALUE_FIELD: return edit_comp_value_xpm;
560  default: return edit_text_xpm;
561  }
562  }
563 
564  return edit_text_xpm;
565 }
566 
567 
568 bool SCH_FIELD::HitTest( const wxPoint& aPosition, int aAccuracy ) const
569 {
570  // Do not hit test hidden or empty fields.
571  if( !IsVisible() || IsVoid() )
572  return false;
573 
574  EDA_RECT rect = GetBoundingBox();
575 
576  rect.Inflate( aAccuracy );
577 
578  return rect.Contains( aPosition );
579 }
580 
581 
582 bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
583 {
584  // Do not hit test hidden fields.
585  if( !IsVisible() || IsVoid() )
586  return false;
587 
588  EDA_RECT rect = aRect;
589 
590  rect.Inflate( aAccuracy );
591 
592  if( aContained )
593  return rect.Contains( GetBoundingBox() );
594 
595  return rect.Intersects( GetBoundingBox() );
596 }
597 
598 
599 void SCH_FIELD::Plot( PLOTTER* aPlotter )
600 {
601  RENDER_SETTINGS* settings = aPlotter->RenderSettings();
602  COLOR4D color = settings->GetLayerColor( GetLayer() );
603  int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
604 
605  penWidth = std::max( penWidth, settings->GetMinPenWidth() );
606 
607  if( !IsVisible() )
608  return;
609 
610  if( IsVoid() )
611  return;
612 
613  // Calculate the text orientation, according to the symbol orientation/mirror
614  int orient = GetTextAngle();
615 
616  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
617  {
618  SCH_COMPONENT* parentSymbol = static_cast<SCH_COMPONENT*>( m_parent );
619 
620  if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
621  {
622  if( orient == TEXT_ANGLE_HORIZ )
623  orient = TEXT_ANGLE_VERT;
624  else
625  orient = TEXT_ANGLE_HORIZ;
626  }
627  }
628 
629  /*
630  * Calculate the text justification, according to the symbol orientation/mirror.
631  * This is a bit complicated due to cumulative calculations:
632  * - numerous cases (mirrored or not, rotation)
633  * - the plotter's Text function will also recalculate H and V justifications according to
634  * the text orientation.
635  * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
636  * to calculate so the easier way is to use no justifications (centered text) and use
637  * GetBoundingBox to know the text coordinate considered as centered
638  */
639  EDA_RECT BoundaryBox = GetBoundingBox();
642  wxPoint textpos = BoundaryBox.Centre();
643 
644  aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify,
645  penWidth, IsItalic(), IsBold() );
646 }
647 
648 
649 void SCH_FIELD::SetPosition( const wxPoint& aPosition )
650 {
651  // Actual positions are calculated by the rotation/mirror transform of the
652  // parent component of the field. The inverse transform is used to calculate
653  // the position relative to the parent component.
654  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
655  {
656  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_parent );
657  wxPoint relativePos = aPosition - parentComponent->GetPosition();
658 
659  relativePos = parentComponent->GetTransform().
660  InverseTransform().TransformCoordinate( relativePos );
661 
662  SetTextPos( relativePos + parentComponent->GetPosition() );
663  return;
664  }
665 
666  SetTextPos( aPosition );
667 }
668 
669 
670 wxPoint SCH_FIELD::GetPosition() const
671 {
672  if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
673  {
674  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_parent );
675  wxPoint relativePos = GetTextPos() - parentComponent->GetPosition();
676 
677  relativePos = parentComponent->GetTransform().TransformCoordinate( relativePos );
678 
679  return relativePos + parentComponent->GetPosition();
680  }
681 
682  return GetTextPos();
683 }
684 
685 
687 {
688  return m_parent ? m_parent->GetPosition() : wxPoint( 0, 0 );
689 }
690 
691 
692 bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
693 {
694  if( Type() != aItem.Type() )
695  return Type() < aItem.Type();
696 
697  auto field = static_cast<const SCH_FIELD*>( &aItem );
698 
699  if( GetId() != field->GetId() )
700  return GetId() < field->GetId();
701 
702  if( GetText() != field->GetText() )
703  return GetText() < field->GetText();
704 
705  if( GetLibPosition().x != field->GetLibPosition().x )
706  return GetLibPosition().x < field->GetLibPosition().x;
707 
708  if( GetLibPosition().y != field->GetLibPosition().y )
709  return GetLibPosition().y < field->GetLibPosition().y;
710 
711  return GetName() < field->GetName();
712 }
#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:189
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:51
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:162
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)
Function Move moves the rectangle by the aMoveVector.
Definition: eda_rect.cpp:51
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
PROJECT holds project specific data.
Definition: project.h:63
PNG memory record (file in memory).
Definition: bitmap_def.h:29
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the component.
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:44
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
Definition: eda_item.cpp:159
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:73
bool IsVisible() const
Definition: eda_text.h:192
void ImportValues(const LIB_FIELD &aSource)
Function ImportValues copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:243
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:137
const BITMAP_OPAQUE edit_comp_value_xpm[1]
wxPoint GetPosition() const override
Definition: sch_field.cpp:670
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
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.
void SetVisible(bool aVisible)
Definition: eda_text.h:191
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:180
int GetId() const
Definition: sch_field.h:120
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
const BITMAP_OPAQUE edit_comp_ref_xpm[1]
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_field.cpp:448
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
The base class for create windows for drawing purpose.
void DoHypertextMenu(EDA_DRAW_FRAME *aFrame) override
Definition: sch_field.cpp:456
wxString m_name
Definition: sch_field.h:55
bool Contains(const wxPoint &aPoint) const
Function Contains.
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
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:321
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:157
Field Value of part, i.e. "3.3K".
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
bool IsItalic() const
Definition: eda_text.h:186
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:692
int y1
Definition: transform.h:49
const wxPoint GetEnd() const
Definition: eda_rect.h:116
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:522
int GetUnit() const
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: sch_text.cpp:1096
SCH_LAYER_ID m_layer
Definition: sch_item.h:199
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
#define NULL
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
TRANSFORM & GetTransform() const
void SetEnd(int x, int y)
Definition: eda_rect.h:192
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:292
Define a library symbol object.
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:210
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
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_field.cpp:568
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:44
wxPoint GetLibPosition() const
Definition: sch_field.h:194
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
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()
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_field.cpp:551
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
Field Name Module PCB, i.e. "16DIP300".
wxString ExpandTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject, const std::function< bool(wxString *)> *aFallbackResolver)
Expand '${var-name}' templates in text.
Definition: common.cpp:58
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:285
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
EDA_UNITS
Definition: eda_units.h:38
void Normalize()
Function 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.
Base plotter engine class.
Definition: plotter.h:131
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:143
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:599
bool IsForceVisible() const
Definition: eda_item.h:274
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:165
bool IsPower() const
const wxChar *const traceFindItem
Flag to enable find debug tracing.
bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_field.cpp:396
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_field.cpp:262
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_field.cpp:327
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:198
bool Replace(wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:178
#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
const BITMAP_OPAQUE edit_comp_footprint_xpm[1]
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:504
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Schematic symbol object.
Definition: sch_component.h:79
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:85
wxPoint GetPosition() const override
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
wxPoint Centre() const
Definition: eda_rect.h:62
bool IsHorizJustifyFlipped() const
Function IsHorizJustifyFlipped Returns whether the field will be rendered with the horizontal justifi...
Definition: sch_field.cpp:304
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
Definition: eda_rect.cpp:150
std::map< wxString, std::set< wxString > > & GetPageRefsMap()
Definition: schematic.h:168
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_field.cpp:367
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:204
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_field.cpp:440
Definition for part library class.
void SetId(int aId)
Definition: sch_field.cpp:79
wxPoint GetParentPosition() const
Definition: sch_field.cpp:686
int m_id
Field index,.
Definition: sch_field.h:53
Field Reference of part, i.e. "IC21".
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:649
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: eda_item.h:446
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
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:187
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:140
int GetPenWidth() const override
Definition: sch_field.cpp:192
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
const BITMAP_OPAQUE edit_text_xpm[1]
Definition: edit_text.cpp:59
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:127
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100