KiCad PCB EDA Suite
lib_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) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2004-2017 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 
29 #include <fctsys.h>
30 #include <pgm_base.h>
31 #include <gr_basic.h>
32 #include <macros.h>
33 #include <base_struct.h>
34 #include <drawtxt.h>
35 #include <kicad_string.h>
36 #include <class_drawpanel.h>
37 #include <plot_common.h>
38 #include <trigo.h>
39 #include <base_units.h>
40 #include <msgpanel.h>
41 #include <bitmaps.h>
42 
43 #include <general.h>
44 #include <class_libentry.h>
45 #include <transform.h>
46 #include <lib_field.h>
47 #include <template_fieldnames.h>
48 
49 
50 LIB_FIELD::LIB_FIELD(LIB_PART * aParent, int idfield ) :
51  LIB_ITEM( LIB_FIELD_T, aParent )
52 {
53  Init( idfield );
54 }
55 
56 
57 LIB_FIELD::LIB_FIELD( int idfield ) :
58  LIB_ITEM( LIB_FIELD_T, NULL )
59 {
60  Init( idfield );
61 }
62 
63 
65 {
66 }
67 
68 
69 void LIB_FIELD::operator=( const LIB_FIELD& field )
70 {
71  m_id = field.m_id;
72  m_Text = field.m_Text;
73  m_name = field.m_name;
74  m_Parent = field.m_Parent;
75 
76  SetEffects( field );
77 }
78 
79 
80 void LIB_FIELD::Init( int id )
81 {
82  m_id = id;
83 
86 
87  m_typeName = _( "Field" );
88 
89  SetTextAngle( TEXT_ANGLE_HORIZ ); // constructor already did this.
90 
91  m_rotate = false;
92  m_updateText = false;
93 
94  // fields in RAM must always have names, because we are trying to get
95  // less dependent on field ids and more dependent on names.
96  // Plus assumptions are made in the field editors.
98 
99  switch( id )
100  {
101  case DATASHEET:
102  case FOOTPRINT:
103  // by contrast, VALUE and REFERENCE are are always constructed as
104  // initially visible, and template fieldsnames' initial visibility
105  // is controlled by the template fieldname configuration record.
106  SetVisible( false );
107  break;
108  }
109 }
110 
111 
112 bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter )
113 {
114  int hjustify, vjustify;
115  wxString text = m_Text;
116 
117  hjustify = 'C';
118 
120  hjustify = 'L';
122  hjustify = 'R';
123 
124  vjustify = 'C';
125 
127  vjustify = 'B';
128  else if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
129  vjustify = 'T';
130 
131  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
132  m_id,
133  EscapedUTF8( text ).c_str(), // wraps in quotes
134  GetTextPos().x, GetTextPos().y, GetTextWidth(),
135  GetTextAngle() == 0 ? 'H' : 'V',
136  IsVisible() ? 'V' : 'I',
137  hjustify, vjustify,
138  IsItalic() ? 'I' : 'N',
139  IsBold() ? 'B' : 'N' );
140 
141  /* Save field name, if necessary
142  * Field name is saved only if it is not the default name.
143  * Just because default name depends on the language and can change from
144  * a country to an other
145  */
146  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
147 
148  if( m_id >= FIELD1 && !m_name.IsEmpty() && m_name != defName )
149  aFormatter.Print( 0, " %s", EscapedUTF8( m_name ).c_str() );
150 
151  aFormatter.Print( 0, "\n" );
152 
153  return true;
154 }
155 
156 
157 bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
158 {
159  int cnt;
160  int x, y, size;
161  char textOrient;
162  char textVisible;
163  char textHJustify;
164  char textVJustify[256];
165 
166  char* line = (char*) aLineReader;
167  char* limit = line + aLineReader.Length();
168 
169  if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
170  {
171  errorMsg = wxT( "invalid field header" );
172  return false;
173  }
174 
175  // Caller did a strtok(), which inserts a nul, so next few bytes are ugly:
176  // digit(s), a nul, some whitespace, then a double quote.
177  while( line < limit && *line != '"' )
178  line++;
179 
180  if( line == limit )
181  return false;
182 
183  line += ReadDelimitedText( &m_Text, line );
184 
185  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
186  // not save like this, and eventually these two lines can be removed.
187  if( m_Text.size() == 1 && m_Text[0] == wxChar( '~' ) )
188  m_Text.clear();
189 
190  memset( textVJustify, 0, sizeof( textVJustify ) );
191 
192  cnt = sscanf( line, " %d %d %d %c %c %c %255s", &x, &y, &size,
193  &textOrient, &textVisible, &textHJustify, textVJustify );
194 
195  if( cnt < 5 )
196  {
197  errorMsg.Printf( wxT( "field %d does not have the correct number of parameters" ),
198  m_id );
199  return false;
200  }
201 
202  SetTextPos( wxPoint( x, y ) );
203  SetTextSize( wxSize( size, size ) );
204 
205  if( textOrient == 'H' )
207  else if( textOrient == 'V' )
209  else
210  {
211  errorMsg.Printf( wxT( "field %d text orientation parameter <%c> is not valid" ),
212  textOrient );
213  return false;
214  }
215 
216  if( textVisible == 'V' )
217  SetVisible( true );
218  else if( textVisible == 'I' )
219  SetVisible( false );
220  else
221  {
222  errorMsg.Printf( wxT( "field %d text visible parameter <%c> is not valid" ),
223  textVisible );
224  return false;
225  }
226 
229 
230  if( cnt >= 6 )
231  {
232  if( textHJustify == 'C' )
234  else if( textHJustify == 'L' )
236  else if( textHJustify == 'R' )
238  else
239  {
240  errorMsg.Printf(
241  wxT( "field %d text horizontal justification parameter <%c> is not valid" ),
242  textHJustify );
243  return false;
244  }
245 
246  if( textVJustify[0] == 'C' )
248  else if( textVJustify[0] == 'B' )
250  else if( textVJustify[0] == 'T' )
252  else
253  {
254  errorMsg.Printf(
255  wxT( "field %d text vertical justification parameter <%c> is not valid" ),
256  textVJustify[0] );
257  return false;
258  }
259 
260  if( textVJustify[1] == 'I' ) // Italic
261  SetItalic( true );
262  if( textVJustify[2] == 'B' ) // Bold
263  SetBold( true );
264  }
265 
266  // fields in RAM must always have names.
267  if( m_id < MANDATORY_FIELDS )
268  {
269  // Fields in RAM must always have names, because we are trying to get
270  // less dependent on field ids and more dependent on names.
271  // Plus assumptions are made in the field editors.
273  }
274  else
275  {
276  ReadDelimitedText( &m_name, line );
277  }
278 
279  return true;
280 }
281 
282 
284 {
285  return GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
286 }
287 
288 
289 void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
290  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
291  const TRANSFORM& aTransform )
292 {
293  wxPoint text_pos;
294  COLOR4D color = COLOR4D::UNSPECIFIED;
295  int linewidth = GetPenSize();
296 
297  if( IsBold() )
298  linewidth = GetPenSizeForBold( GetTextWidth() );
299  else
300  linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
301 
302  if( !IsVisible() && ( aColor == COLOR4D::UNSPECIFIED ) )
303  {
304  color = GetInvisibleItemColor();
305  }
306  else if( IsSelected() && ( aColor == COLOR4D::UNSPECIFIED ) )
307  {
308  color = GetItemSelectedColor();
309  }
310  else
311  {
312  color = aColor;
313  }
314 
315  if( color == COLOR4D::UNSPECIFIED )
316  color = GetDefaultColor();
317 
318  text_pos = aTransform.TransformCoordinate( GetTextPos() ) + aOffset;
319 
320  wxString text;
321 
322  if( aData )
323  text = *(wxString*)aData;
324  else
325  text = m_Text;
326 
327  GRSetDrawMode( aDC, aDrawMode );
328  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
329 
330  DrawGraphicText( clipbox, aDC, text_pos, color, text,
333  linewidth, IsItalic(), IsBold() );
334 
335  /* Set to one (1) to draw bounding box around field text to validate
336  * bounding box calculation. */
337 #if 0
338  EDA_RECT bBox = GetBoundingBox();
339  bBox.RevertYAxis();
340  bBox = aTransform.TransformCoordinate( bBox );
341  bBox.Move( aOffset );
342  GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
343 #endif
344 }
345 
346 
347 bool LIB_FIELD::HitTest( const wxPoint& aPosition ) const
348 {
349  // Because HitTest is mainly used to select the field
350  // return always false if this field is void
351  if( IsVoid() )
352  return false;
353 
354  return HitTest( aPosition, 0, DefaultTransform );
355 }
356 
357 
358 bool LIB_FIELD::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
359 {
360  if( aThreshold < 0 )
361  aThreshold = 0;
362 
363  // Build a temporary copy of the text for hit testing
364  EDA_TEXT tmp_text( *this );
365 
366  // Reference designator text has one or 2 additional character (displays
367  // U? or U?A)
368  if( m_id == REFERENCE )
369  {
370  wxString extended_text = tmp_text.GetText();
371  extended_text.Append('?');
372  const LIB_PART* parent = static_cast<const LIB_PART*>( m_Parent );
373 
374  if ( parent && ( parent->GetUnitCount() > 1 ) )
375  extended_text.Append('A');
376  tmp_text.SetText( extended_text );
377  }
378 
379  tmp_text.SetTextPos( aTransform.TransformCoordinate( GetTextPos() ) );
380 
381  /* The text orientation may need to be flipped if the
382  * transformation matrix causes xy axes to be flipped.
383  * this simple algo works only for schematic matrix (rot 90 or/and mirror)
384  */
385  bool t1 = ( aTransform.x1 != 0 ) ^ ( GetTextAngle() != 0 );
386  tmp_text.SetTextAngle( t1 ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT );
387 
388  return tmp_text.TextHitTest( aPosition );
389 }
390 
391 
393 {
394  LIB_FIELD* newfield = new LIB_FIELD( m_id );
395 
396  Copy( newfield );
397 
398  return (EDA_ITEM*) newfield;
399 }
400 
401 
402 void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
403 {
404  aTarget->m_Text = m_Text;
405  aTarget->m_name = m_name;
406 
407  aTarget->SetEffects( *this );
408  aTarget->SetParent( m_Parent );
409 }
410 
411 
412 int LIB_FIELD::compare( const LIB_ITEM& other ) const
413 {
414  wxASSERT( other.Type() == LIB_FIELD_T );
415 
416  const LIB_FIELD* tmp = ( LIB_FIELD* ) &other;
417 
418  if( m_id != tmp->m_id )
419  return m_id - tmp->m_id;
420 
421  int result = m_Text.CmpNoCase( tmp->m_Text );
422 
423  if( result != 0 )
424  return result;
425 
426  if( GetTextPos().x != tmp->GetTextPos().x )
427  return GetTextPos().x - tmp->GetTextPos().x;
428 
429  if( GetTextPos().y != tmp->GetTextPos().y )
430  return GetTextPos().y - tmp->GetTextPos().y;
431 
432  if( GetTextWidth() != tmp->GetTextWidth() )
433  return GetTextWidth() - tmp->GetTextWidth();
434 
435  if( GetTextHeight() != tmp->GetTextHeight() )
436  return GetTextHeight() - tmp->GetTextHeight();
437 
438  return 0;
439 }
440 
441 
442 void LIB_FIELD::SetOffset( const wxPoint& aOffset )
443 {
444  EDA_TEXT::Offset( aOffset );
445 }
446 
447 
448 bool LIB_FIELD::Inside( EDA_RECT& rect ) const
449 {
450  return rect.Intersects( GetBoundingBox() );
451 }
452 
453 
454 void LIB_FIELD::Move( const wxPoint& newPosition )
455 {
456  EDA_TEXT::SetTextPos( newPosition );
457 }
458 
459 
461 {
462  int x = GetTextPos().x;
463 
464  x -= center.x;
465  x *= -1;
466  x += center.x;
467 
468  SetTextX( x );
469 }
470 
471 
472 void LIB_FIELD::MirrorVertical( const wxPoint& center )
473 {
474  int y = GetTextPos().y;
475 
476  y -= center.y;
477  y *= -1;
478  y += center.y;
479 
480  SetTextY( y );
481 }
482 
483 
484 void LIB_FIELD::Rotate( const wxPoint& center, bool aRotateCCW )
485 {
486  int rot_angle = aRotateCCW ? -900 : 900;
487 
488  wxPoint pt = GetTextPos();
489  RotatePoint( &pt, center, rot_angle );
490  SetTextPos( pt );
491 
492  SetTextAngle( GetTextAngle() != 0.0 ? 0 : 900 );
493 }
494 
495 
496 void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
497  const TRANSFORM& aTransform )
498 {
499  if( IsVoid() )
500  return;
501 
502  /* Calculate the text orientation, according to the component
503  * orientation/mirror */
504  int orient = GetTextAngle();
505 
506  if( aTransform.y1 ) // Rotate component 90 deg.
507  {
508  if( orient == TEXT_ANGLE_HORIZ )
509  orient = TEXT_ANGLE_VERT;
510  else
511  orient = TEXT_ANGLE_HORIZ;
512  }
513 
514  EDA_RECT BoundaryBox = GetBoundingBox();
515  BoundaryBox.RevertYAxis();
516 
519  wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() )
520  + aOffset;
521 
522  aPlotter->Text( textpos, GetDefaultColor(), GetShownText(),
523  orient, GetTextSize(),
524  hjustify, vjustify,
525  GetPenSize(), IsItalic(), IsBold() );
526 }
527 
528 
529 wxString LIB_FIELD::GetFullText( int unit ) const
530 {
531  if( m_id != REFERENCE )
532  return GetText();
533 
534  wxString text = GetText();
535  text << wxT( "?" );
536 
537  if( GetParent()->IsMulti() )
538  text << LIB_PART::SubReference( unit );
539 
540  return text;
541 }
542 
543 
545 {
546  /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
547  * calling GetTextBox() that works using top to bottom Y axis orientation.
548  */
549  EDA_RECT rect = GetTextBox( -1, -1, true );
550  rect.RevertYAxis();
551 
552  // We are using now a bottom to top Y axis.
553  wxPoint orig = rect.GetOrigin();
554  wxPoint end = rect.GetEnd();
555 
556  RotatePoint( &orig, GetTextPos(), -GetTextAngle() );
557  RotatePoint( &end, GetTextPos(), -GetTextAngle() );
558 
559  rect.SetOrigin( orig );
560  rect.SetEnd( end );
561 
562  // We are using now a top to bottom Y axis:
563  rect.RevertYAxis();
564 
565  return rect;
566 }
567 
568 
570 {
571  COLOR4D color;
572 
573  switch( m_id )
574  {
575  case REFERENCE:
577  break;
578 
579  case VALUE:
580  color = GetLayerColor( LAYER_VALUEPART );
581  break;
582 
583  default:
584  color = GetLayerColor( LAYER_FIELDS );
585  break;
586  }
587 
588  return color;
589 }
590 
591 
593 {
594  if( InEditMode() )
595  {
596  m_rotate = true;
597  }
598  else
599  {
601  }
602 }
603 
604 
605 wxString LIB_FIELD::GetName( bool aTranslate ) const
606 {
607  wxString name;
608 
609  switch( m_id )
610  {
611  case REFERENCE:
612  if( aTranslate )
613  name = _( "Reference" );
614  else
615  name = wxT( "Reference" );
616  break;
617 
618  case VALUE:
619  if( aTranslate )
620  name = _( "Value" );
621  else
622  name = wxT( "Value" );
623  break;
624 
625  case FOOTPRINT:
626  if( aTranslate )
627  name = _( "Footprint" );
628  else
629  name = wxT( "Footprint" );
630  break;
631 
632  case DATASHEET:
633  if( aTranslate )
634  name = _( "Datasheet" );
635  else
636  name = wxT( "Datasheet" );
637  break;
638 
639  default:
640  if( m_name.IsEmpty() )
641  {
642  if( aTranslate )
643  name.Printf( _( "Field%d" ), m_id );
644  else
645  name.Printf( wxT( "Field%d" ), m_id );
646  }
647  else
648  name = m_name;
649  }
650 
651  return name;
652 }
653 
654 
655 void LIB_FIELD::SetName( const wxString& aName )
656 {
657  // Mandatory field names are fixed.
658 
659  // So what? Why should the low level code be in charge of such a policy issue?
660  // Besides, m_id is a relic that is untrustworthy now.
661  if( m_id >=0 && m_id < MANDATORY_FIELDS )
662  {
663  DBG(printf( "trying to set a MANDATORY_FIELD's name\n" );)
664  return;
665  }
666 
667  if( m_name != aName )
668  {
669  m_name = aName;
670  SetModified();
671  }
672 }
673 
674 
675 void LIB_FIELD::SetText( const wxString& aText )
676 {
677  if( aText == GetText() )
678  return;
679 
680  wxString oldName = m_Text;
681 
682  if( m_id == VALUE && m_Parent != NULL )
683  {
684  LIB_PART* parent = GetParent();
685 
686  // Set the parent component and root alias to the new name.
687  if( parent->GetName().CmpNoCase( aText ) != 0 )
688  parent->SetName( aText );
689  }
690 
691  if( InEditMode() )
692  {
693  m_Text = oldName;
694  m_savedText = aText;
695  m_updateText = true;
696  }
697  else
698  {
699  m_Text = aText;
700  }
701 }
702 
703 
705 {
706  return wxString::Format( _( "Field %s %s" ),
707  GetChars( GetName() ),
709 }
710 
711 
712 void LIB_FIELD::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition )
713 {
714  wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0,
715  wxT( "Invalid edit mode for LIB_FIELD object." ) );
716 
717  if( aEditMode == IS_MOVED )
718  {
720  m_initialCursorPos = aPosition;
722  }
723  else
724  {
725  SetTextPos( aPosition );
726  }
727 
728  m_Flags = aEditMode;
729 }
730 
731 
732 bool LIB_FIELD::ContinueEdit( const wxPoint aPosition )
733 {
734  wxCHECK_MSG( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0, false,
735  wxT( "Bad call to ContinueEdit(). Text is not being edited." ) );
736 
737  return false;
738 }
739 
740 
741 void LIB_FIELD::EndEdit( const wxPoint& aPosition, bool aAbort )
742 {
743  wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0,
744  wxT( "Bad call to EndEdit(). Text is not being edited." ) );
745 
746  m_Flags = 0;
747  m_rotate = false;
748  m_updateText = false;
749  SetEraseLastDrawItem( false );
750 }
751 
752 
753 void LIB_FIELD::calcEdit( const wxPoint& aPosition )
754 {
755  if( m_rotate )
756  {
758  m_rotate = false;
759  }
760 
761  if( m_updateText )
762  {
763  std::swap( m_Text, m_savedText );
764  m_updateText = false;
765  }
766 
767  if( m_Flags == IS_NEW )
768  {
769  SetTextPos( aPosition );
770  }
771  else if( m_Flags == IS_MOVED )
772  {
773  Move( m_initialPos + aPosition - m_initialCursorPos );
774  }
775 }
776 
777 
779 {
780  wxString msg;
781 
782  LIB_ITEM::GetMsgPanelInfo( aList );
783 
784  // Display style:
785  msg = GetTextStyleName();
786  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg, MAGENTA ) );
787 
788  msg = StringFromValue( g_UserUnit, GetTextWidth(), true );
789  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, BLUE ) );
790 
791  msg = StringFromValue( g_UserUnit, GetTextHeight(), true );
792  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, BLUE ) );
793 
794  // Display field name (ref, value ...)
795  msg = GetName();
796  aList.push_back( MSG_PANEL_ITEM( _( "Field" ), msg, BROWN ) );
797 
798  // Display field text:
799  aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetShownText(), BROWN ) );
800 }
801 
802 
804 {
805  return move_xpm;
806 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition: colors.h:57
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
#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:91
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_field.cpp:472
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:229
void SetModified()
int compare(const LIB_ITEM &aOther) const override
Function compare provides the draw object specific comparison called by the == and < operators...
Definition: lib_field.cpp:412
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void DrawGraphicText(EDA_RECT *aClipBox, 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), PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
Definition: drawtxt.cpp:122
bool IsMulti() const
Function IsMulti.
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:182
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
wxString m_Text
Definition: eda_text.h:346
name of datasheet
bool Load(LINE_READER &aLineReader, wxString &errorMsg) override
Definition: lib_field.cpp:157
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:79
PNG memory record (file in memory).
Definition: bitmap_types.h:38
wxString m_savedText
Temporary storage for the string when edition.
Definition: lib_field.h:65
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:57
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
wxString m_typeName
Name of object displayed in the message panel.
bool IsItalic() const
Definition: eda_text.h:170
void SetEraseLastDrawItem(bool aErase=true)
Implementation of conversion functions that require both schematic and board internal units...
void SetEffects(const EDA_TEXT &aSrc)
Function SetEffects sets the text effects from another instance.
Definition: eda_text.cpp:55
Definition: colors.h:61
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
void SetItalic(bool isItalic)
Definition: eda_text.h:169
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
int GetTextWidth() const
Definition: eda_text.h:218
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetVisible(bool aVisible)
Definition: eda_text.h:175
bool IsSelected() const
Definition: base_struct.h:235
bool InEditMode() const
Return the draw item editing mode status.
void SetOrigin(const wxPoint &pos)
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
int x1
Definition: transform.h:48
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:803
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_field.cpp:460
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:529
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:544
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:67
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:569
void SetName(const wxString &aName)
Function SetName.
Definition: lib_field.cpp:655
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
Definition: lib_field.cpp:778
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
#define TEXT_ANGLE_VERT
Definition: common.h:92
COLOR4D GetInvisibleItemColor()
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_field.cpp:112
void EndEdit(const wxPoint &aPosition, bool aAbort=false) override
End an object editing action.
Definition: lib_field.cpp:741
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: lib_field.cpp:347
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: drawtxt.cpp:229
void SetTextX(int aX)
Definition: eda_text.h:226
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:135
#define IS_NEW
New item, just created.
Definition: base_struct.h:127
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
const wxPoint & GetOrigin() const
int y1
Definition: transform.h:49
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
EDA_RECT GetTextBox(int aLine=-1, int aThickness=-1, bool aInvertY=false) const
Function GetTextBox useful in multiline texts to calculate the full text or a line area (for zones fi...
Definition: eda_text.cpp:102
void operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:69
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:675
void calcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:753
void BeginEdit(STATUS_FLAGS aEditMode, const wxPoint aStartPoint=wxPoint(0, 0)) override
Begin an editing a component library draw item in aEditMode at aPosition.
Definition: lib_field.cpp:712
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_field.cpp:454
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227
virtual bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const
Function TextHitTest Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:254
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsVoid() const
Function IsVoid.
Definition: lib_field.h:159
const wxString & GetName() const
Class LIB_ITEM definition.
void SetEnd(int x, int y)
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
bool Inside(EDA_RECT &aRect) const override
Function Inside tests if any part of the draw object is inside rectangle bounds of aRect...
Definition: lib_field.cpp:448
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_field.cpp:496
Class LIB_PART defines a library part object.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:392
unsigned STATUS_FLAGS
Definition: base_struct.h:158
EDA_RECT * GetClipBox()
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:80
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
wxPoint Centre() const
unsigned Length() const
Function Length returns the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:168
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:605
const wxPoint GetEnd() const
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
int GetUnitCount() const
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void SetTextWidth(int aWidth)
Definition: eda_text.h:217
int m_id
Definition: lib_field.h:62
Field Value of part, i.e. "3.3K".
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:592
Base plotter engine class.
Definition: plot_common.h:86
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: drawtxt.cpp:49
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
wxString GetTextStyleName()
Function GetTextStyleName.
Definition: eda_text.cpp:380
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:205
bool IsVisible() const
Function IsVisible.
Definition: lib_field.h:168
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
wxPoint m_initialPos
Temporary position when moving an existing item.
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:189
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:704
Class EDA_RECT handles the component boundary box.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Function SubReference.
void SetTextHeight(int aHeight)
Definition: eda_text.h:220
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
const char * name
int GetTextHeight() const
Definition: eda_text.h:221
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:402
This file is part of the common libary.
virtual void SetName(const wxString &aName)
COLOR4D GetItemSelectedColor()
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_field.cpp:442
int GetPenSize() const override
Function GetPenSize.
Definition: lib_field.cpp:283
#define DBG(x)
Definition: fctsys.h:33
const wxSize & GetTextSize() const
Definition: eda_text.h:215
Basic classes for most KiCad items.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:63
int ReadDelimitedText(wxString *aDest, const char *aSource)
Function ReadDelimitedText copies bytes from aSource delimited string segment to aDest wxString...
Definition: string.cpp:43
Message panel definition file.
void SetBold(bool aBold)
Definition: eda_text.h:172
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform) override
Draw the field.
Definition: lib_field.cpp:289
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:66
bool ContinueEdit(const wxPoint aNextPoint) override
Continue an edit in progress at aPosition.
Definition: lib_field.cpp:732
void SetTextY(int aY)
Definition: eda_text.h:227
int GetDefaultTextSize()
Default size for text in general.
wxPoint m_initialCursorPos
Initial cursor position at the beginning of a move.
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
#define IS_MOVED
Item being moved.
Definition: base_struct.h:126
Definition: colors.h:62