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  /*
451  * FIXME: This fails to take into account the size and/or orientation of
452  * the text.
453  */
454  return rect.Contains( GetTextPos().x, -GetTextPos().y );
455 }
456 
457 
458 void LIB_FIELD::Move( const wxPoint& newPosition )
459 {
460  EDA_TEXT::SetTextPos( newPosition );
461 }
462 
463 
465 {
466  int x = GetTextPos().x;
467 
468  x -= center.x;
469  x *= -1;
470  x += center.x;
471 
472  SetTextX( x );
473 }
474 
475 
476 void LIB_FIELD::MirrorVertical( const wxPoint& center )
477 {
478  int y = GetTextPos().y;
479 
480  y -= center.y;
481  y *= -1;
482  y += center.y;
483 
484  SetTextY( y );
485 }
486 
487 
488 void LIB_FIELD::Rotate( const wxPoint& center, bool aRotateCCW )
489 {
490  int rot_angle = aRotateCCW ? -900 : 900;
491 
492  wxPoint pt = GetTextPos();
493  RotatePoint( &pt, center, rot_angle );
494  SetTextPos( pt );
495 
496  SetTextAngle( GetTextAngle() != 0.0 ? 0 : 900 );
497 }
498 
499 
500 void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
501  const TRANSFORM& aTransform )
502 {
503  if( IsVoid() )
504  return;
505 
506  /* Calculate the text orientation, according to the component
507  * orientation/mirror */
508  int orient = GetTextAngle();
509 
510  if( aTransform.y1 ) // Rotate component 90 deg.
511  {
512  if( orient == TEXT_ANGLE_HORIZ )
513  orient = TEXT_ANGLE_VERT;
514  else
515  orient = TEXT_ANGLE_HORIZ;
516  }
517 
518  EDA_RECT BoundaryBox = GetBoundingBox();
519  BoundaryBox.RevertYAxis();
520 
523  wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() )
524  + aOffset;
525 
526  aPlotter->Text( textpos, GetDefaultColor(), GetShownText(),
527  orient, GetTextSize(),
528  hjustify, vjustify,
529  GetPenSize(), IsItalic(), IsBold() );
530 }
531 
532 
533 wxString LIB_FIELD::GetFullText( int unit ) const
534 {
535  if( m_id != REFERENCE )
536  return GetText();
537 
538  wxString text = GetText();
539  text << wxT( "?" );
540 
541  if( GetParent()->IsMulti() )
542  text << LIB_PART::SubReference( unit );
543 
544  return text;
545 }
546 
547 
549 {
550  /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
551  * calling GetTextBox() that works using top to bottom Y axis orientation.
552  */
553  EDA_RECT rect = GetTextBox( -1, -1, true );
554  rect.RevertYAxis();
555 
556  // We are using now a bottom to top Y axis.
557  wxPoint orig = rect.GetOrigin();
558  wxPoint end = rect.GetEnd();
559 
560  RotatePoint( &orig, GetTextPos(), -GetTextAngle() );
561  RotatePoint( &end, GetTextPos(), -GetTextAngle() );
562 
563  rect.SetOrigin( orig );
564  rect.SetEnd( end );
565 
566  // We are using now a top to bottom Y axis:
567  rect.RevertYAxis();
568 
569  return rect;
570 }
571 
572 
574 {
575  COLOR4D color;
576 
577  switch( m_id )
578  {
579  case REFERENCE:
581  break;
582 
583  case VALUE:
584  color = GetLayerColor( LAYER_VALUEPART );
585  break;
586 
587  default:
588  color = GetLayerColor( LAYER_FIELDS );
589  break;
590  }
591 
592  return color;
593 }
594 
595 
597 {
598  if( InEditMode() )
599  {
600  m_rotate = true;
601  }
602  else
603  {
605  }
606 }
607 
608 
609 wxString LIB_FIELD::GetName( bool aTranslate ) const
610 {
611  wxString name;
612 
613  switch( m_id )
614  {
615  case REFERENCE:
616  if( aTranslate )
617  name = _( "Reference" );
618  else
619  name = wxT( "Reference" );
620  break;
621 
622  case VALUE:
623  if( aTranslate )
624  name = _( "Value" );
625  else
626  name = wxT( "Value" );
627  break;
628 
629  case FOOTPRINT:
630  if( aTranslate )
631  name = _( "Footprint" );
632  else
633  name = wxT( "Footprint" );
634  break;
635 
636  case DATASHEET:
637  if( aTranslate )
638  name = _( "Datasheet" );
639  else
640  name = wxT( "Datasheet" );
641  break;
642 
643  default:
644  if( m_name.IsEmpty() )
645  {
646  if( aTranslate )
647  name.Printf( _( "Field%d" ), m_id );
648  else
649  name.Printf( wxT( "Field%d" ), m_id );
650  }
651  else
652  name = m_name;
653  }
654 
655  return name;
656 }
657 
658 
659 void LIB_FIELD::SetName( const wxString& aName )
660 {
661  // Mandatory field names are fixed.
662 
663  // So what? Why should the low level code be in charge of such a policy issue?
664  // Besides, m_id is a relic that is untrustworthy now.
665  if( m_id >=0 && m_id < MANDATORY_FIELDS )
666  {
667  DBG(printf( "trying to set a MANDATORY_FIELD's name\n" );)
668  return;
669  }
670 
671  if( m_name != aName )
672  {
673  m_name = aName;
674  SetModified();
675  }
676 }
677 
678 
679 void LIB_FIELD::SetText( const wxString& aText )
680 {
681  if( aText == GetText() )
682  return;
683 
684  wxString oldName = m_Text;
685 
686  if( m_id == VALUE && m_Parent != NULL )
687  {
688  LIB_PART* parent = GetParent();
689 
690  // Set the parent component and root alias to the new name.
691  if( parent->GetName().CmpNoCase( aText ) != 0 )
692  parent->SetName( aText );
693  }
694 
695  if( InEditMode() )
696  {
697  m_Text = oldName;
698  m_savedText = aText;
699  m_updateText = true;
700  }
701  else
702  {
703  m_Text = aText;
704  }
705 }
706 
707 
709 {
710  return wxString::Format( _( "Field %s %s" ),
711  GetChars( GetName() ),
713 }
714 
715 
716 void LIB_FIELD::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition )
717 {
718  wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0,
719  wxT( "Invalid edit mode for LIB_FIELD object." ) );
720 
721  if( aEditMode == IS_MOVED )
722  {
724  m_initialCursorPos = aPosition;
726  }
727  else
728  {
729  SetTextPos( aPosition );
730  }
731 
732  m_Flags = aEditMode;
733 }
734 
735 
736 bool LIB_FIELD::ContinueEdit( const wxPoint aPosition )
737 {
738  wxCHECK_MSG( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0, false,
739  wxT( "Bad call to ContinueEdit(). Text is not being edited." ) );
740 
741  return false;
742 }
743 
744 
745 void LIB_FIELD::EndEdit( const wxPoint& aPosition, bool aAbort )
746 {
747  wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0,
748  wxT( "Bad call to EndEdit(). Text is not being edited." ) );
749 
750  m_Flags = 0;
751  m_rotate = false;
752  m_updateText = false;
753  SetEraseLastDrawItem( false );
754 }
755 
756 
757 void LIB_FIELD::calcEdit( const wxPoint& aPosition )
758 {
759  if( m_rotate )
760  {
762  m_rotate = false;
763  }
764 
765  if( m_updateText )
766  {
767  std::swap( m_Text, m_savedText );
768  m_updateText = false;
769  }
770 
771  if( m_Flags == IS_NEW )
772  {
773  SetTextPos( aPosition );
774  }
775  else if( m_Flags == IS_MOVED )
776  {
777  Move( m_initialPos + aPosition - m_initialCursorPos );
778  }
779 }
780 
781 
783 {
784  wxString msg;
785 
786  LIB_ITEM::GetMsgPanelInfo( aList );
787 
788  // Display style:
789  msg = GetTextStyleName();
790  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg, MAGENTA ) );
791 
792  msg = StringFromValue( g_UserUnit, GetTextWidth(), true );
793  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, BLUE ) );
794 
795  msg = StringFromValue( g_UserUnit, GetTextHeight(), true );
796  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, BLUE ) );
797 
798  // Display field name (ref, value ...)
799  msg = GetName();
800  aList.push_back( MSG_PANEL_ITEM( _( "Field" ), msg, BROWN ) );
801 
802  // Display field text:
803  aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetShownText(), BROWN ) );
804 }
805 
806 
808 {
809  return move_xpm;
810 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition: colors.h:57
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
#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:476
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:168
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:92
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...
bool Contains(const wxPoint &aPoint) const
Function Contains.
void SetEffects(const EDA_TEXT &aSrc)
Function SetEffects sets the text effects from another instance.
Definition: eda_text.cpp:68
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:221
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:807
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_field.cpp:464
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:533
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:548
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:67
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:573
void SetName(const wxString &aName)
Function SetName.
Definition: lib_field.cpp:659
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:782
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:745
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:113
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:115
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:679
void calcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:757
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:716
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_field.cpp:458
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
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:267
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:500
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:144
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:609
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:596
Base plotter engine class.
Definition: plot_common.h:86
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:393
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:175
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:708
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:151
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:736
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:112
Definition: colors.h:62