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 /* Fields are texts attached to a component, having a special meaning
26  * Fields 0 and 1 are very important: reference and value
27  * Field 2 is used as default footprint name.
28  * Field 3 is reserved (not currently used
29  * Fields 4 and more are user fields.
30  * They can be renamed and can appear in reports
31  */
32 
33 #include <fctsys.h>
34 #include <base_struct.h>
35 #include <gr_basic.h>
36 #include <gr_text.h>
37 #include <macros.h>
38 #include <sch_edit_frame.h>
39 #include <plotter.h>
40 #include <bitmaps.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 
51 
52 SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
53  const wxString& aName ) :
54  SCH_ITEM( aParent, SCH_FIELD_T ),
55  EDA_TEXT( wxEmptyString ),
56  m_id( 0 ),
57  m_name( aName )
58 {
59  SetTextPos( aPos );
60  SetId( aFieldId ); // will also set the layer
61  SetVisible( false );
62 }
63 
64 
66 {
67 }
68 
69 
71 {
72  return new SCH_FIELD( *this );
73 }
74 
75 
76 void SCH_FIELD::SetId( int aId )
77 {
78  m_id = aId;
79 
80  if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
81  {
82  switch( m_id )
83  {
84  case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
86  default: SetLayer( LAYER_SHEETFIELDS ); break;
87  }
88  }
89  else
90  {
91  switch( m_id )
92  {
93  case REFERENCE: SetLayer( LAYER_REFERENCEPART ); break;
94  case VALUE: SetLayer( LAYER_VALUEPART ); break;
95  default: SetLayer( LAYER_FIELDS ); break;
96  }
97  }
98 
99 }
100 
101 
102 wxString SCH_FIELD::GetShownText( int aDepth ) const
103 {
104  std::function<bool( wxString* )> symbolResolver =
105  [&]( wxString* token ) -> bool
106  {
107  if( token->Contains( ':' ) )
108  {
109  if( Schematic()->ResolveCrossReference( token, aDepth ) )
110  return true;
111  }
112  else
113  {
114  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( m_Parent );
115 
116  if( component->ResolveTextVar( token, aDepth + 1 ) )
117  return true;
118 
119  SCHEMATIC* schematic = component->Schematic();
120  SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
121 
122  if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
123  return true;
124  }
125 
126  return false;
127  };
128 
129  std::function<bool( wxString* )> sheetResolver =
130  [&]( wxString* token ) -> bool
131  {
132  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_Parent );
133  return sheet->ResolveTextVar( token, aDepth + 1 );
134  };
135 
136  PROJECT* project = nullptr;
137  bool processTextVars = false;
138  wxString text = EDA_TEXT::GetShownText( &processTextVars );
139 
140  if( processTextVars )
141  {
142  if( Schematic() )
143  project = &Schematic()->Prj();
144 
145  if( aDepth < 10 )
146  {
147  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
148  text = ExpandTextVars( text, &symbolResolver, project );
149  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
150  text = ExpandTextVars( text, &sheetResolver, project );
151  else
152  text = ExpandTextVars( text, nullptr, project );
153  }
154  }
155 
156  // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
157  // id and the parent's type.
158 
159  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
160  {
161  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( m_Parent );
162 
163  if( m_id == REFERENCE )
164  {
165  // For more than one part per package, we must add the part selection
166  // A, B, ... or 1, 2, .. to the reference.
167  if( component->GetUnitCount() > 1 )
168  text << LIB_PART::SubReference( component->GetUnit() );
169  }
170  }
171  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
172  {
173  if( m_id == SHEETFILENAME )
174  text = _( "File: " ) + text;
175  }
176 
177  return text;
178 }
179 
180 
182 {
183  return GetEffectiveTextPenWidth();
184 }
185 
186 
187 void SCH_FIELD::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
188 {
189  wxDC* DC = aSettings->GetPrintDC();
191  int orient;
192  wxPoint textpos;
193  int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
194 
195  if( ( !IsVisible() && !IsForceVisible() ) || IsVoid() )
196  return;
197 
198  // Calculate the text orientation according to the component orientation.
199  orient = GetTextAngle();
200 
201  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
202  {
203  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
204 
205  if( parentComponent && parentComponent->GetTransform().y1 ) // Rotate component 90 degrees.
206  {
207  if( orient == TEXT_ANGLE_HORIZ )
208  orient = TEXT_ANGLE_VERT;
209  else
210  orient = TEXT_ANGLE_HORIZ;
211  }
212  }
213 
214  /* Calculate the text justification, according to the component
215  * orientation/mirror this is a bit complicated due to cumulative
216  * calculations:
217  * - numerous cases (mirrored or not, rotation)
218  * - the DrawGraphicText function recalculate also H and H justifications
219  * according to the text orientation.
220  * - When a component is mirrored, the text is not mirrored and
221  * justifications are complicated to calculate
222  * so the more easily way is to use no justifications ( Centered text )
223  * and use GetBoundaryBox to know the text coordinate considered as centered
224  */
225  EDA_RECT boundaryBox = GetBoundingBox();
226  textpos = boundaryBox.Centre() + aOffset;
227 
228  GRText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_HJUSTIFY_CENTER,
229  GR_TEXT_VJUSTIFY_CENTER, penWidth, IsItalic(), IsBold() );
230 }
231 
232 
233 void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
234 {
235  SetEffects( aSource );
236 }
237 
238 
240 {
241  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_FIELD_T),
242  wxT( "Cannot swap field data with invalid item." ) );
243 
244  SCH_FIELD* item = (SCH_FIELD*) aItem;
245 
246  std::swap( m_Layer, item->m_Layer );
247  SwapText( *item );
248  SwapEffects( *item );
249 }
250 
251 
253 {
254  // Calculate the text bounding box:
255  EDA_RECT rect = GetTextBox();
256 
257  // Calculate the bounding box position relative to the parent:
258  wxPoint origin = GetParentPosition();
259  wxPoint pos = GetTextPos() - origin;
260  wxPoint begin = rect.GetOrigin() - origin;
261  wxPoint end = rect.GetEnd() - origin;
262  RotatePoint( &begin, pos, GetTextAngle() );
263  RotatePoint( &end, pos, GetTextAngle() );
264 
265  // Now, apply the component transform (mirror/rot)
266  TRANSFORM transform;
267 
268  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
269  {
270  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
271 
272  // Due to the Y axis direction, we must mirror the bounding box,
273  // relative to the text position:
274  MIRROR( begin.y, pos.y );
275  MIRROR( end.y, pos.y );
276 
277  transform = parentComponent->GetTransform();
278  }
279  else
280  {
281  transform = TRANSFORM( 1, 0, 0, 1 ); // identity transform
282  }
283 
284  rect.SetOrigin( transform.TransformCoordinate( begin ) );
285  rect.SetEnd( transform.TransformCoordinate( end ) );
286 
287  rect.Move( origin );
288  rect.Normalize();
289 
290  return rect;
291 }
292 
293 
295 {
296  wxPoint render_center = GetBoundingBox().Centre();
297  wxPoint pos = GetPosition();
298 
299  switch( GetHorizJustify() )
300  {
302  return render_center.x < pos.x;
304  return render_center.x > pos.x;
305  default:
306  return false;
307  }
308 }
309 
310 
311 bool SCH_FIELD::IsVoid() const
312 {
313  return GetText().Len() == 0;
314 }
315 
316 
317 bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData )
318 {
319  wxString text = GetShownText();
320  int flags = aSearchData.GetFlags();
321  bool searchHiddenFields = flags & FR_SEARCH_ALL_FIELDS;
322  bool searchAndReplace = flags & FR_SEARCH_REPLACE;
323  bool replaceReferences = flags & FR_REPLACE_REFERENCES;
324 
325  wxLogTrace( traceFindItem, wxT( " child item " )
327 
328  if( !IsVisible() && !searchHiddenFields )
329  return false;
330 
331  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
332  {
333  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
334 
335  if( searchAndReplace && m_id == REFERENCE && !replaceReferences )
336  return false;
337 
338  // Take sheet path into account which effects the reference field and the unit for
339  // components with multiple parts.
340  if( m_id == REFERENCE && aAuxData != NULL )
341  {
342  text = parentComponent->GetRef( (SCH_SHEET_PATH*) aAuxData );
343 
344  if( parentComponent->GetUnitCount() > 1 )
345  text << LIB_PART::SubReference( parentComponent->GetUnit() );
346  }
347  }
348 
349  return SCH_ITEM::Matches( text, aSearchData );
350 }
351 
352 
354 {
355  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
356  {
357  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
358 
359  if( m_id == VALUE )
360  {
361  LIB_PART* part = parentComponent->GetPartRef().get();
362 
363  if( part && part->IsPower() )
364  return false;
365  }
366  }
367  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
368  {
369  // See comments in SCH_FIELD::Replace(), below.
370  if( m_id == SHEETFILENAME )
371  return false;
372  }
373 
374  return true;
375 }
376 
377 
378 bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
379 {
380  bool isReplaced = false;
381 
382  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
383  {
384  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
385 
386  if( m_id == REFERENCE )
387  {
388  wxCHECK_MSG( aAuxData != NULL, false,
389  wxT( "Cannot replace reference designator without valid sheet path." ) );
390 
391  if( !( aSearchData.GetFlags() & FR_REPLACE_REFERENCES ) )
392  return false;
393 
394  wxString text = parentComponent->GetRef( (SCH_SHEET_PATH*) aAuxData );
395 
396  isReplaced = EDA_ITEM::Replace( aSearchData, text );
397 
398  if( isReplaced )
399  parentComponent->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
400  }
401  else
402  {
403  isReplaced = EDA_TEXT::Replace( aSearchData );
404  }
405  }
406  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
407  {
408  isReplaced = EDA_TEXT::Replace( aSearchData );
409 
410  if( m_id == SHEETFILENAME && isReplaced )
411  {
412  // If we allowed this we'd have a bunch of work to do here, including warning
413  // about it not being undoable, checking for recursive hierarchies, reloading
414  // sheets, etc. See DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow().
415  }
416  }
417 
418  return isReplaced;
419 }
420 
421 
422 void SCH_FIELD::Rotate( wxPoint aPosition )
423 {
424  wxPoint pt = GetTextPos();
425  RotatePoint( &pt, aPosition, 900 );
426  SetTextPos( pt );
427 }
428 
429 
430 wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
431 {
432  return wxString::Format( _( "Field %s (%s)" ),
433  GetName(),
434  ShortenedShownText() );
435 }
436 
437 
438 wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
439 {
440  if( !m_name.IsEmpty() )
441  return m_name;
442  else if( aUseDefaultName )
443  {
444  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
446  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
448  }
449 
450  return wxEmptyString;
451 }
452 
453 
455 {
456  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
457  {
458  switch( m_id )
459  {
460  case REFERENCE: return wxT( "Reference" );
461  case VALUE: return wxT( "Value" );
462  case FOOTPRINT: return wxT( "Footprint" );
463  case DATASHEET: return wxT( "Datasheet" );
464  }
465  }
466  else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
467  {
468  switch( m_id )
469  {
470  case SHEETNAME: return wxT( "Sheetname" );
471  case SHEETFILENAME: return wxT( "Sheetfile" );
472  }
473  }
474 
475  return m_name;
476 }
477 
478 
480 {
481  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
482  {
483  switch( m_id )
484  {
485  case REFERENCE: return edit_comp_ref_xpm;
486  case VALUE: return edit_comp_value_xpm;
487  case FOOTPRINT: return edit_comp_footprint_xpm;
488  default: return edit_text_xpm;
489  }
490  }
491 
492  return edit_text_xpm;
493 }
494 
495 
496 bool SCH_FIELD::HitTest( const wxPoint& aPosition, int aAccuracy ) const
497 {
498  // Do not hit test hidden or empty fields.
499  if( !IsVisible() || IsVoid() )
500  return false;
501 
502  EDA_RECT rect = GetBoundingBox();
503 
504  rect.Inflate( aAccuracy );
505 
506  return rect.Contains( aPosition );
507 }
508 
509 
510 bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
511 {
512  // Do not hit test hidden fields.
513  if( !IsVisible() || IsVoid() )
514  return false;
515 
516  EDA_RECT rect = aRect;
517 
518  rect.Inflate( aAccuracy );
519 
520  if( aContained )
521  return rect.Contains( GetBoundingBox() );
522 
523  return rect.Intersects( GetBoundingBox() );
524 }
525 
526 
527 void SCH_FIELD::Plot( PLOTTER* aPlotter )
528 {
529  RENDER_SETTINGS* settings = aPlotter->RenderSettings();
530  COLOR4D color = settings->GetLayerColor( GetLayer() );
531  int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
532 
533  penWidth = std::max( penWidth, settings->GetMinPenWidth() );
534 
535  if( !IsVisible() )
536  return;
537 
538  if( IsVoid() )
539  return;
540 
541  // Calculate the text orientation, according to the component orientation/mirror
542  int orient = GetTextAngle();
543 
544  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
545  {
546  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
547 
548  if( parentComponent->GetTransform().y1 ) // Rotate component 90 deg.
549  {
550  if( orient == TEXT_ANGLE_HORIZ )
551  orient = TEXT_ANGLE_VERT;
552  else
553  orient = TEXT_ANGLE_HORIZ;
554  }
555  }
556 
557  /*
558  * Calculate the text justification, according to the component orientation/mirror
559  * this is a bit complicated due to cumulative calculations:
560  * - numerous cases (mirrored or not, rotation)
561  * - the DrawGraphicText function also recalculates H and H justifications according to the
562  * text orientation.
563  * - When a component is mirrored, the text is not mirrored and justifications are
564  * complicated to calculate
565  * so the easier way is to use no justifications (centered text) and use GetBoundaryBox to
566  * know the text coordinate considered as centered
567  */
568  EDA_RECT BoundaryBox = GetBoundingBox();
571  wxPoint textpos = BoundaryBox.Centre();
572 
573  aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify,
574  penWidth, IsItalic(), IsBold() );
575 }
576 
577 
578 void SCH_FIELD::SetPosition( const wxPoint& aPosition )
579 {
580  // Actual positions are calculated by the rotation/mirror transform of the
581  // parent component of the field. The inverse transform is used to calculate
582  // the position relative to the parent component.
583  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
584  {
585  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
586  wxPoint relativePos = aPosition - parentComponent->GetPosition();
587 
588  relativePos = parentComponent->GetTransform().
589  InverseTransform().TransformCoordinate( relativePos );
590 
591  SetTextPos( relativePos + parentComponent->GetPosition() );
592  return;
593  }
594 
595  SetTextPos( aPosition );
596 }
597 
598 
600 {
601  if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
602  {
603  SCH_COMPONENT* parentComponent = static_cast<SCH_COMPONENT*>( m_Parent );
604  wxPoint relativePos = GetTextPos() - parentComponent->GetPosition();
605 
606  relativePos = parentComponent->GetTransform().TransformCoordinate( relativePos );
607 
608  return relativePos + parentComponent->GetPosition();
609  }
610 
611  return GetTextPos();
612 }
613 
614 
616 {
617  return m_Parent ? m_Parent->GetPosition() : wxPoint( 0, 0 );
618 }
619 
620 
621 bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
622 {
623  if( Type() != aItem.Type() )
624  return Type() < aItem.Type();
625 
626  auto field = static_cast<const SCH_FIELD*>( &aItem );
627 
628  if( GetId() != field->GetId() )
629  return GetId() < field->GetId();
630 
631  if( GetText() != field->GetText() )
632  return GetText() < field->GetText();
633 
634  if( GetLibPosition().x != field->GetLibPosition().x )
635  return GetLibPosition().x < field->GetLibPosition().x;
636 
637  if( GetLibPosition().y != field->GetLibPosition().y )
638  return GetLibPosition().y < field->GetLibPosition().y;
639 
640  return GetName() < field->GetName();
641 }
EDA_UNITS
Definition: common.h:198
bool IsBold() const
Definition: eda_text.h:183
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:185
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
SCH_LAYER_ID m_Layer
Definition: sch_item.h:199
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:151
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:48
name of datasheet
PROJECT holds project specific data.
Definition: project.h:61
PNG memory record (file in memory).
Definition: bitmap_def.h:29
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:42
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:70
bool IsVisible() const
Definition: eda_text.h:186
void ImportValues(const LIB_FIELD &aSource)
Function ImportValues copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:233
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:599
int color
Definition: DXF_plotter.cpp:61
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:222
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:247
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:116
int GetUnitCount() const
Return the number of units per package of the symbol.
void SetVisible(bool aVisible)
Definition: eda_text.h:185
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:174
int GetId() const
Definition: sch_field.h:114
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
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:430
virtual wxPoint GetPosition() const
Definition: base_struct.h:337
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
wxString m_name
Definition: sch_field.h:56
#define TEXT_ANGLE_VERT
Definition: common.h:186
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool Contains(const wxPoint &aPoint) const
Function Contains.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:102
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:311
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
This file contains miscellaneous commonly used macros and functions.
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:222
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:113
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:621
int y1
Definition: transform.h:49
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:175
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:454
int GetUnit() const
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
#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:239
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:286
Define a library symbol object.
SCH_FIELD(const wxPoint &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:52
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:165
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:201
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:496
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:44
wxPoint GetLibPosition() const
Definition: sch_field.h:188
SCH_SHEET_PATH.
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:479
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
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:384
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 module texts)
Definition: gr_text.cpp:134
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:55
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
void Normalize()
Function Normalize ensures that the height ant width are positive.
Field Value of part, i.e. "3.3K".
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:114
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:527
bool IsForceVisible() const
Definition: base_struct.h:286
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
bool IsPower() const
const wxChar *const traceFindItem
Flag to enable find debug tracing.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
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:378
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_field.cpp:252
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_field.cpp:317
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:187
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:239
const BITMAP_OPAQUE edit_comp_footprint_xpm[1]
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:438
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:80
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
wxPoint GetPosition() const override
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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:294
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_field.cpp:353
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:203
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_field.cpp:422
Definition for part library class.
void SetId(int aId)
Definition: sch_field.cpp:76
wxPoint GetParentPosition() const
Definition: sch_field.cpp:615
int m_id
Field index,.
Definition: sch_field.h:54
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:578
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:458
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:127
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:134
int GetPenWidth() const override
Definition: sch_field.cpp:181
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
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:119
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99