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.

152 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Oliver Walters
  5. * Copyright (C) 2017 KiCad Developers, see CHANGELOG.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 FIELDS_EDITOR_TABLE_COLUMN_H
  25. #define FIELDS_EDITOR_TABLE_COLUMN_H
  26. #include <wx/regex.h>
  27. #include <wx/string.h>
  28. #include <vector>
  29. // Default column names (translated)
  30. #define FIELDS_EDITOR_COL_TITLE_REFERENCE _( "Reference" )
  31. #define FIELDS_EDITOR_COL_TITLE_DESCRIPTION _( "Description" )
  32. #define FIELDS_EDITOR_COL_TITLE_FOOTPRINT _( "Footprint" )
  33. #define FIELDS_EDITOR_COL_TITLE_VALUE _( "Value" )
  34. #define FIELDS_EDITOR_COL_TITLE_DATASHEET _( "Datasheet" )
  35. #define FIELDS_EDITOR_COL_TITLE_QUANTITY _( "Quantity" )
  36. /**
  37. * Column type enumeration
  38. * Not currently implemented,
  39. * in the future the different column 'types' might
  40. * be used for something...
  41. */
  42. enum FIELDS_EDITOR_COLUMN_TYPE
  43. {
  44. FIELDS_EDITOR_COL_TYPE_KICAD = 0, ///< Default column (editable)
  45. FIELDS_EDITOR_COL_TYPE_LIBRARY, ///< Default column (non-editable)
  46. FIELDS_EDITOR_COL_TYPE_GENERATED, ///< Generated column (e.g. Quantity)
  47. FIELDS_EDITOR_COL_TYPE_USER, ///< User data
  48. };
  49. /**
  50. * Predefined column ID values for default columns.
  51. * User columns are assigned IDs of 1000 and above
  52. */
  53. enum FIELDS_EDITOR_COLUMN_ID
  54. {
  55. // Default component fields
  56. FIELDS_EDITOR_COL_ID_REFERENCE = 0,
  57. FIELDS_EDITOR_COL_ID_DESCRIPTION,
  58. FIELDS_EDITOR_COL_ID_FOOTPRINT,
  59. FIELDS_EDITOR_COL_ID_VALUE,
  60. FIELDS_EDITOR_COL_ID_DATASHEET,
  61. // Meta-data fields
  62. FIELDS_EDITOR_COL_ID_QUANTITY = 100,
  63. // Custom data fields
  64. FIELDS_EDITOR_COL_ID_USER = 1000,
  65. };
  66. /**
  67. * FIELDS_EDITOR_COLUMN class
  68. * Models a single column in the BOM view
  69. * Each column can be used to group components,
  70. * and can be hidden from the output BOM
  71. */
  72. class FIELDS_EDITOR_COLUMN
  73. {
  74. protected:
  75. unsigned int m_id; ///< Unique column ID
  76. FIELDS_EDITOR_COLUMN_TYPE m_Type; ///< Column type
  77. wxString m_Title; ///< The column (field) title
  78. bool m_Show; ///< Is this column visible?
  79. bool m_ReadOnly; ///< Is this column read only?
  80. bool m_sort; ///< Is this column used for sorting?
  81. public:
  82. FIELDS_EDITOR_COLUMN( unsigned int aId, FIELDS_EDITOR_COLUMN_TYPE aType, const wxString aTitle, bool aShow, bool aReadOnly = false, bool aSort = true ) :
  83. m_id( aId ),
  84. m_Type( aType ),
  85. m_Title( aTitle.Strip( wxString::both ) ),
  86. m_Show( aShow ),
  87. m_ReadOnly( aReadOnly ),
  88. m_sort( aSort )
  89. {
  90. }
  91. unsigned int Id() const { return m_id; }
  92. FIELDS_EDITOR_COLUMN_TYPE Type() const { return m_Type; }
  93. wxString Title() const { return m_Title; }
  94. bool IsVisible() const { return m_Show; }
  95. bool IsReadOnly() const { return m_ReadOnly; }
  96. bool IsUsedToSort() const { return m_sort; }
  97. //TODO - Should renaming of columns be allowed?
  98. //bool SetTitle( const wxString aTitle );
  99. void SetVisible( bool aShow = true ) { m_Show = aShow; }
  100. void SetReadOnly( bool aReadOnly = true ) { m_ReadOnly = aReadOnly; }
  101. void SetUsedToSort( bool aSort = true ) { m_sort = aSort; }
  102. };
  103. /*
  104. * The FIELDS_EDITOR_COLUMN_LIST class contains information
  105. * on all columns existing in the BOM
  106. */
  107. class FIELDS_EDITOR_COLUMN_LIST
  108. {
  109. protected:
  110. unsigned int m_nextFieldId;
  111. public:
  112. std::vector< FIELDS_EDITOR_COLUMN* > Columns;
  113. FIELDS_EDITOR_COLUMN_LIST();
  114. void Clear();
  115. unsigned int NextFieldId() const { return m_nextFieldId; }
  116. unsigned int ColumnCount( bool aIncludeHidden = true ) const;
  117. FIELDS_EDITOR_COLUMN* GetColumnByIndex( unsigned int aColIndex );
  118. FIELDS_EDITOR_COLUMN* GetColumnById( unsigned int aColId );
  119. FIELDS_EDITOR_COLUMN* GetColumnByTitle( const wxString& aColTitle ) ;
  120. bool ContainsColumn( unsigned int aColId );
  121. bool ContainsColumn( const wxString& aColTitle );
  122. bool AddColumn( FIELDS_EDITOR_COLUMN* aCol );
  123. };
  124. #endif /* FIELDS_EDITOR_TABLE_COLUMN_H */