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.

216 lines
6.6 KiB

7 years ago
  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-2019 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. #ifndef CLASS_SCH_FIELD_H
  25. #define CLASS_SCH_FIELD_H
  26. #include <eda_text.h>
  27. #include <sch_item.h>
  28. #include <template_fieldnames.h>
  29. #include <general.h>
  30. class SCH_EDIT_FRAME;
  31. class SCH_COMPONENT;
  32. class LIB_FIELD;
  33. /**
  34. * SCH_FIELD
  35. * instances are attached to a component and provide a place for the component's value,
  36. * reference designator, footprint, and user definable name-value pairs of arbitrary purpose.
  37. *
  38. * <ul> <li>Field 0 is reserved for the component reference.</li>
  39. * <li>Field 1 is reserved for the component value.</li>
  40. * <li>Field 2 is reserved for the component footprint.</li>
  41. * <li>Field 3 is reserved for the component data sheet file.</li>
  42. * <li>Field 4 and higher are user defineable.</li></ul>
  43. */
  44. class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
  45. {
  46. int m_id; ///< Field index, @see enum NumFieldType
  47. wxString m_name;
  48. public:
  49. SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
  50. const wxString& aName = wxEmptyString );
  51. // Do not create a copy constructor. The one generated by the compiler is adequate.
  52. ~SCH_FIELD();
  53. static inline bool ClassOf( const EDA_ITEM* aItem )
  54. {
  55. return aItem && SCH_FIELD_T == aItem->Type();
  56. }
  57. wxString GetClass() const override
  58. {
  59. return wxT( "SCH_FIELD" );
  60. }
  61. bool IsType( const KICAD_T aScanTypes[] ) const override
  62. {
  63. if( SCH_ITEM::IsType( aScanTypes ) )
  64. return true;
  65. for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
  66. {
  67. if( *p == SCH_FIELD_LOCATE_REFERENCE_T && m_id == REFERENCE_FIELD )
  68. return true;
  69. else if ( *p == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
  70. return true;
  71. else if ( *p == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
  72. return true;
  73. else if ( *p == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
  74. return true;
  75. }
  76. return false;
  77. }
  78. bool IsHypertext() const override
  79. {
  80. return m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T;
  81. }
  82. void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) override;
  83. /**
  84. * Function GetName
  85. * returns the field name.
  86. *
  87. * @param aUseDefaultName When true return the default field name if the field name is
  88. * empty. Otherwise the default field name is returned.
  89. * @return A wxString object containing the name of the field.
  90. */
  91. wxString GetName( bool aUseDefaultName = true ) const;
  92. /**
  93. * Get a non-language-specific name for a field which can be used for storage, variable
  94. * look-up, etc.
  95. */
  96. wxString GetCanonicalName() const;
  97. void SetName( const wxString& aName ) { m_name = aName; }
  98. int GetId() const { return m_id; }
  99. void SetId( int aId );
  100. wxString GetShownText( int aDepth = 0 ) const override;
  101. const EDA_RECT GetBoundingBox() const override;
  102. /**
  103. * Function IsHorizJustifyFlipped
  104. * Returns whether the field will be rendered with the horizontal justification
  105. * inverted due to rotation or mirroring of the parent.
  106. */
  107. bool IsHorizJustifyFlipped() const;
  108. /**
  109. * Function IsVoid
  110. * returns true if the field is either empty or holds "~".
  111. */
  112. bool IsVoid() const;
  113. void SwapData( SCH_ITEM* aItem ) override;
  114. /**
  115. * Function ImportValues
  116. * copy parameters from a LIB_FIELD source.
  117. * Pointers and specific values (position) are not copied
  118. * @param aSource = the LIB_FIELD to read
  119. */
  120. void ImportValues( const LIB_FIELD& aSource );
  121. int GetPenWidth() const override;
  122. void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
  123. void Move( const wxPoint& aMoveVector ) override
  124. {
  125. Offset( aMoveVector );
  126. }
  127. void Rotate( wxPoint aPosition ) override;
  128. /**
  129. * @copydoc SCH_ITEM::MirrorX()
  130. *
  131. * This overload does nothing. Fields are never mirrored alone. They are moved
  132. * when the parent component is mirrored. This function is only needed by the
  133. * pure function of the master class.
  134. */
  135. void MirrorX( int aXaxis_position ) override
  136. {
  137. }
  138. /**
  139. * @copydoc SCH_ITEM::MirrorY()
  140. *
  141. * This overload does nothing. Fields are never mirrored alone. They are moved
  142. * when the parent component is mirrored. This function is only needed by the
  143. * pure function of the master class.
  144. */
  145. void MirrorY( int aYaxis_position ) override
  146. {
  147. }
  148. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override;
  149. bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override;
  150. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  151. BITMAP_DEF GetMenuImage() const override;
  152. bool IsReplaceable() const override;
  153. wxPoint GetLibPosition() const { return EDA_TEXT::GetTextPos(); }
  154. wxPoint GetPosition() const override;
  155. void SetPosition( const wxPoint& aPosition ) override;
  156. wxPoint GetParentPosition() const;
  157. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  158. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  159. void Plot( PLOTTER* aPlotter ) override;
  160. EDA_ITEM* Clone() const override;
  161. bool operator <( const SCH_ITEM& aItem ) const override;
  162. #if defined(DEBUG)
  163. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  164. #endif
  165. };
  166. #endif /* CLASS_SCH_FIELD_H */