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.

218 lines
6.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2004-2021 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. /**
  25. * @file lib_field.h
  26. */
  27. #ifndef CLASS_LIBENTRY_FIELDS_H
  28. #define CLASS_LIBENTRY_FIELDS_H
  29. #include <eda_text.h>
  30. #include <lib_item.h>
  31. class SCH_LEGACY_PLUGIN_CACHE;
  32. /**
  33. * Field object used in symbol libraries. At least MANDATORY_FIELDS are always present in a
  34. * RAM-resident library symbol. All constructors must ensure this because the symbol property
  35. * editor assumes it.
  36. * <p>
  37. * A field is a string linked to a symbol. Unlike purely graphical text, fields can be used in
  38. * netlist generation and other tools (BOM).
  39. *
  40. * The first 4 fields have a special meaning:
  41. *
  42. * 0 = REFERENCE_FIELD
  43. * 1 = VALUE_FIELD
  44. * 2 = FOOTPRINT_FIELD (default Footprint)
  45. * 3 = DATASHEET_FIELD (user doc link)
  46. *
  47. * others = free fields
  48. * </p>
  49. *
  50. * @see enum MANDATORY_FIELD_T
  51. */
  52. class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
  53. {
  54. int m_id; ///< @see enum MANDATORY_FIELD_T
  55. wxString m_name; ///< Name (not the field text value itself, that is .m_Text)
  56. /**
  57. * Print the field.
  58. * <p>
  59. * If \a aData not NULL, \a aData must point a wxString which is used instead of
  60. * the m_Text
  61. * </p>
  62. */
  63. void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
  64. const TRANSFORM& aTransform ) override;
  65. /**
  66. * Calculate the new circle at \a aPosition when editing.
  67. *
  68. * @param aPosition - The position to edit the circle in drawing coordinates.
  69. */
  70. void CalcEdit( const wxPoint& aPosition ) override;
  71. friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
  72. public:
  73. LIB_FIELD( int idfield = 2 );
  74. LIB_FIELD( int aID, const wxString& aName );
  75. LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
  76. // Do not create a copy constructor. The one generated by the compiler is adequate.
  77. ~LIB_FIELD();
  78. wxString GetClass() const override
  79. {
  80. return wxT( "LIB_FIELD" );
  81. }
  82. wxString GetTypeName() const override
  83. {
  84. return _( "Field" );
  85. }
  86. /**
  87. * Object constructor initialization helper.
  88. */
  89. void Init( int idfield );
  90. /**
  91. * Return the field name.
  92. *
  93. * The first four field IDs are reserved and therefore always return their respective
  94. * names.
  95. *
  96. * The user definable fields will return FieldN where N is the ID of the field when the
  97. * m_name member is empyt unless false is passed to \a aUseDefaultName.
  98. */
  99. wxString GetName( bool aUseDefaultName = true ) const;
  100. /**
  101. * Get a non-language-specific name for a field which can be used for storage, variable
  102. * look-up, etc.
  103. */
  104. wxString GetCanonicalName() const;
  105. /**
  106. * Set a user definable field name to \a aName.
  107. *
  108. * Reserved fields such as value and reference are not renamed. If the field name is
  109. * changed, the field modified flag is set. If the field is the child of a symbol, the
  110. * parent symbol's modified flag is also set.
  111. *
  112. * @param aName - User defined field name.
  113. */
  114. void SetName( const wxString& aName );
  115. int GetId() const { return m_id; }
  116. void SetId( int aId ) { m_id = aId; }
  117. int GetPenWidth() const override;
  118. /**
  119. * Copy parameters of this field to another field. Pointers are not copied.
  120. *
  121. * @param aTarget Target field to copy values to.
  122. */
  123. void Copy( LIB_FIELD* aTarget ) const;
  124. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  125. const EDA_RECT GetBoundingBox() const override;
  126. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  127. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  128. LIB_FIELD& operator=( const LIB_FIELD& field );
  129. /**
  130. * Return the text of a field.
  131. *
  132. * If the field is the reference field, the unit number is used to
  133. * create a pseudo reference text. If the base reference field is U,
  134. * the string U?A will be returned for unit = 1.
  135. *
  136. * @param unit - The package unit number. Only effects reference field.
  137. * @return Field text.
  138. */
  139. wxString GetFullText( int unit = 1 ) const;
  140. SCH_LAYER_ID GetDefaultLayer() const;
  141. void BeginEdit( const wxPoint& aStartPoint ) override;
  142. void Offset( const wxPoint& aOffset ) override;
  143. void MoveTo( const wxPoint& aPosition ) override;
  144. wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
  145. void MirrorHorizontal( const wxPoint& aCenter ) override;
  146. void MirrorVertical( const wxPoint& aCenter ) override;
  147. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
  148. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  149. const TRANSFORM& aTransform ) const override;
  150. int GetWidth() const override { return GetTextThickness(); }
  151. void SetWidth( int aWidth ) override { SetTextThickness( aWidth ); }
  152. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  153. BITMAPS GetMenuImage() const override;
  154. EDA_ITEM* Clone() const override;
  155. bool IsMandatory() const;
  156. private:
  157. /**
  158. * @copydoc LIB_ITEM::compare()
  159. *
  160. * The field specific sort order is as follows:
  161. *
  162. * - Field ID, REFERENCE, VALUE, etc.
  163. * - Field string, case insensitive compare.
  164. * - Field horizontal (X) position.
  165. * - Field vertical (Y) position.
  166. * - Field width.
  167. * - Field height.
  168. */
  169. int compare( const LIB_ITEM& aOther,
  170. LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
  171. };
  172. #endif // CLASS_LIBENTRY_FIELDS_H