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