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.

209 lines
6.4 KiB

  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-2015 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 override
  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. const EDA_RECT GetBoundingBox() const override;
  83. /**
  84. * Function IsHorizJustifyFlipped
  85. * Returns whether the field will be rendered with the horizontal justification
  86. * inverted due to rotation or mirroring of the parent.
  87. */
  88. bool IsHorizJustifyFlipped() const;
  89. /**
  90. * Function IsVoid
  91. * returns true if the field is either empty or holds "~".
  92. */
  93. bool IsVoid() const
  94. {
  95. size_t len = m_Text.Len();
  96. return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) );
  97. }
  98. void SwapData( SCH_ITEM* aItem ) override;
  99. /**
  100. * Function ImportValues
  101. * copy parameters from a LIB_FIELD source.
  102. * Pointers and specific values (position) are not copied
  103. * @param aSource = the LIB_FIELD to read
  104. */
  105. void ImportValues( const LIB_FIELD& aSource );
  106. /**
  107. * Function ImportValues
  108. * copy parameters into a LIB_FIELD destination.
  109. * Pointers and specific values (position) are not copied
  110. * @param aDest = the LIB_FIELD to write
  111. */
  112. void ExportValues(LIB_FIELD& aDest ) const;
  113. int GetPenSize() const override;
  114. void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  115. GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
  116. bool Save( FILE* aFile ) const override;
  117. // Geometric transforms (used in block operations):
  118. void Move( const wxPoint& aMoveVector ) override
  119. {
  120. Offset( aMoveVector );
  121. }
  122. void Rotate( wxPoint aPosition ) override;
  123. /**
  124. * @copydoc SCH_ITEM::MirrorX()
  125. *
  126. * This overload does nothing. Fields are never mirrored alone. They are moved
  127. * when the parent component is mirrored. This function is only needed by the
  128. * pure function of the master class.
  129. */
  130. void MirrorX( int aXaxis_position ) override
  131. {
  132. }
  133. /**
  134. * @copydoc SCH_ITEM::MirrorY()
  135. *
  136. * This overload does nothing. Fields are never mirrored alone. They are moved
  137. * when the parent component is mirrored. This function is only needed by the
  138. * pure function of the master class.
  139. */
  140. void MirrorY( int aYaxis_position ) override
  141. {
  142. }
  143. bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
  144. bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override;
  145. wxString GetSelectMenuText() const override;
  146. BITMAP_DEF GetMenuImage() const override;
  147. bool IsReplaceable() const override { return true; }
  148. wxPoint GetLibPosition() const { return EDA_TEXT::GetTextPos(); }
  149. wxPoint GetPosition() const override;
  150. void SetPosition( const wxPoint& aPosition ) override;
  151. bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
  152. bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
  153. void Plot( PLOTTER* aPlotter ) override;
  154. EDA_ITEM* Clone() const override;
  155. #if defined(DEBUG)
  156. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  157. #endif
  158. };
  159. #endif /* CLASS_SCH_FIELD_H */