You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.9 KiB

  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-2012 KiCad Developers, see change_log.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. * @file sch_field.h
  26. * @brief Definition of the SCH_FIELD class for Eeschema.
  27. */
  28. #ifndef CLASS_SCH_FIELD_H
  29. #define CLASS_SCH_FIELD_H
  30. #include <eda_text.h>
  31. #include <sch_item_struct.h>
  32. #include <general.h>
  33. class SCH_EDIT_FRAME;
  34. class SCH_COMPONENT;
  35. class LIB_FIELD;
  36. /**
  37. * Class SCH_FIELD
  38. * instances are attached to a component and provide a place for the component's value,
  39. * reference designator, footprint, and user definable name-value pairs of arbitrary purpose.
  40. *
  41. * <ul> <li>Field 0 is reserved for the component reference.</li>
  42. * <li>Field 1 is reserved for the component value.</li>
  43. * <li>Field 2 is reserved for the component footprint.</li>
  44. * <li>Field 3 is reserved for the component data sheet file.</li>
  45. * <li>Field 4 and higher are user defineable.</li></ul>
  46. */
  47. class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
  48. {
  49. int m_id; ///< Field index, @see enum NumFieldType
  50. wxString m_name;
  51. public:
  52. SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
  53. wxString aName = wxEmptyString );
  54. // Do not create a copy constructor. The one generated by the compiler is adequate.
  55. ~SCH_FIELD();
  56. wxString GetClass() const
  57. {
  58. return wxT( "SCH_FIELD" );
  59. }
  60. /**
  61. * Function GetName
  62. * returns the field name.
  63. *
  64. * @param aUseDefaultName When true return the default field name if the field name is
  65. * empty. Otherwise the default field name is returned.
  66. * @return A wxString object containing the name of the field.
  67. */
  68. wxString GetName( bool aUseDefaultName = true ) const;
  69. void SetName( const wxString& aName ) { m_name = aName; }
  70. int GetId() const { return m_id; }
  71. void SetId( int aId ) { m_id = aId; }
  72. /**
  73. * Function GetFullyQualifiedText
  74. * returns the fully qualified field text by allowing for the part suffix to be added
  75. * to the reference designator field if the component has multiple parts. For all other
  76. * fields this is the equivalent of EDA_TEXT::GetText().
  77. *
  78. * @return a const wxString object containing the field's string.
  79. */
  80. const wxString GetFullyQualifiedText() const;
  81. void Place( SCH_EDIT_FRAME* frame, wxDC* DC );
  82. EDA_RECT GetBoundingBox() const;
  83. /**
  84. * Function IsVoid
  85. * returns true if the field is either empty or holds "~".
  86. */
  87. bool IsVoid() const
  88. {
  89. size_t len = m_Text.Len();
  90. return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) );
  91. }
  92. void SwapData( SCH_ITEM* aItem );
  93. /**
  94. * Function ImportValues
  95. * copy parameters from a source.
  96. * Pointers and specific values (position) are not copied
  97. * @param aSource = the LIB_FIELD to read
  98. */
  99. void ImportValues( const LIB_FIELD& aSource );
  100. int GetPenSize() const;
  101. /**
  102. * Function IsVisible
  103. * @return true is this field is visible, false if flagged invisible
  104. */
  105. bool IsVisible() const
  106. {
  107. return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false;
  108. }
  109. void Draw( EDA_DRAW_PANEL* aPanel,
  110. wxDC* aDC,
  111. const wxPoint& aOffset,
  112. GR_DRAWMODE aDrawMode,
  113. EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
  114. bool Save( FILE* aFile ) const;
  115. // Geometric transforms (used in block operations):
  116. void Move( const wxPoint& aMoveVector )
  117. {
  118. m_Pos += aMoveVector;
  119. }
  120. void Rotate( wxPoint aPosition );
  121. /**
  122. * @copydoc SCH_ITEM::MirrorX()
  123. *
  124. * This overload does nothing. Fields are never mirrored alone. They are moved
  125. * when the parent component is mirrored. This function is only needed by the
  126. * pure function of the master class.
  127. */
  128. void MirrorX( int aXaxis_position )
  129. {
  130. }
  131. /**
  132. * @copydoc SCH_ITEM::MirrorY()
  133. *
  134. * This overload does nothing. Fields are never mirrored alone. They are moved
  135. * when the parent component is mirrored. This function is only needed by the
  136. * pure function of the master class.
  137. */
  138. void MirrorY( int aYaxis_position )
  139. {
  140. }
  141. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
  142. bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
  143. wxString GetSelectMenuText() const;
  144. BITMAP_DEF GetMenuImage() const;
  145. bool IsReplaceable() const { return true; }
  146. wxPoint GetPosition() const;
  147. void SetPosition( const wxPoint& aPosition );
  148. bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
  149. bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const;
  150. void Plot( PLOTTER* aPlotter );
  151. EDA_ITEM* Clone() const;
  152. #if defined(DEBUG)
  153. void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
  154. #endif
  155. };
  156. #endif /* CLASS_SCH_FIELD_H */