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.

126 lines
4.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Mike Williams, mike@mikebwilliams.com
  5. * Copyright The 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. #ifndef PCB_FIELD_H
  25. #define PCB_FIELD_H
  26. #include <pcb_text.h>
  27. #include <template_fieldnames.h>
  28. class BOARD_DESIGN_SETTINGS;
  29. class PCB_FIELD : public PCB_TEXT
  30. {
  31. public:
  32. PCB_FIELD( FOOTPRINT* aParent, int aFieldId, const wxString& aName = wxEmptyString );
  33. PCB_FIELD( const PCB_TEXT& aText, int aFieldId, const wxString& aName = wxEmptyString );
  34. void Serialize( google::protobuf::Any &aContainer ) const override;
  35. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  36. static inline bool ClassOf( const EDA_ITEM* aItem )
  37. {
  38. return aItem && PCB_FIELD_T == aItem->Type();
  39. }
  40. wxString GetClass() const override { return wxT( "PCB_FIELD" ); }
  41. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
  42. {
  43. if( BOARD_ITEM::IsType( aScanTypes ) )
  44. return true;
  45. for( KICAD_T scanType : aScanTypes )
  46. {
  47. if( scanType == PCB_FIELD_LOCATE_REFERENCE_T && m_id == REFERENCE_FIELD )
  48. return true;
  49. else if( scanType == PCB_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
  50. return true;
  51. else if( scanType == PCB_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
  52. return true;
  53. }
  54. return false;
  55. }
  56. bool IsReference() const { return m_id == REFERENCE_FIELD; }
  57. bool IsValue() const { return m_id == VALUE_FIELD; }
  58. bool IsDatasheet() const { return m_id == DATASHEET_FIELD; }
  59. bool IsComponentClass() const { return GetName() == wxT( "Component Class" ); }
  60. bool IsMandatoryField() const { return m_id < MANDATORY_FIELDS; }
  61. wxString GetTextTypeDescription() const override;
  62. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  63. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  64. EDA_ITEM* Clone() const override;
  65. /**
  66. * Same as Clone, but returns a PCB_FIELD item.
  67. *
  68. * Useful mainly for python scripts, because Clone returns an EDA_ITEM.
  69. */
  70. PCB_FIELD* CloneField() const { return (PCB_FIELD*) Clone(); }
  71. /**
  72. * Return the field name (not translated)..
  73. *
  74. * @param aUseDefaultName When true return the default field name if the field name is
  75. * empty. Otherwise the default field name is returned.
  76. * @return the name of the field.
  77. */
  78. wxString GetName( bool aUseDefaultName = true ) const;
  79. /**
  80. * Get a non-language-specific name for a field which can be used for storage, variable
  81. * look-up, etc.
  82. */
  83. wxString GetCanonicalName() const;
  84. void SetName( const wxString& aName ) { m_name = aName; }
  85. int GetId() const { return m_id; }
  86. void SetId( int aId ) { m_id = aId; }
  87. double Similarity( const BOARD_ITEM& aOther ) const override;
  88. bool operator==( const PCB_FIELD& aOther ) const;
  89. bool operator==( const BOARD_ITEM& aOther ) const override;
  90. protected:
  91. void swapData( BOARD_ITEM* aImage ) override;
  92. private:
  93. void setId( int aId ) { m_id = aId; }
  94. int m_id; ///< Field index, @see enum MANDATORY_FIELD_T
  95. wxString m_name;
  96. };
  97. #endif