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.

202 lines
6.5 KiB

15 years ago
11 years ago
11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2014-2020 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 _TEMPLATE_FIELDNAME_H_
  25. #define _TEMPLATE_FIELDNAME_H_
  26. #include <richio.h>
  27. #include <macros.h>
  28. #include <template_fieldnames_lexer.h>
  29. class TEMPLATE_FIELDNAMES_LEXER;
  30. /**
  31. * Enum NumFieldType
  32. * is the set of all field indices assuming an array like sequence that a
  33. * SCH_COMPONENT or LIB_PART can hold.
  34. * The first fields are called fixed fields and the quantity of them is
  35. * given by MANDATORY_FIELDS. After that come an unlimited number of
  36. * user defined fields, only some of which have indices defined here.
  37. */
  38. enum NumFieldType {
  39. REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
  40. VALUE, ///< Field Value of part, i.e. "3.3K"
  41. FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300"
  42. DATASHEET, ///< name of datasheet
  43. /// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT
  44. /// and LIB_PART constructors
  45. MANDATORY_FIELDS,
  46. FIELD1 = MANDATORY_FIELDS,
  47. FIELD2,
  48. FIELD3,
  49. FIELD4,
  50. FIELD5,
  51. FIELD6,
  52. FIELD7,
  53. FIELD8
  54. };
  55. /**
  56. * Struct TEMPLATE_FIELDNAME
  57. * holds a name of a component's field, field value, and default visibility.
  58. * Template fieldnames are wanted fieldnames for use in the symbol/component
  59. * property editors.
  60. */
  61. struct TEMPLATE_FIELDNAME
  62. {
  63. wxString m_Name; // The field name
  64. bool m_Visible; // Field defaults to being visible in schematic.
  65. bool m_URL; // If field should have a browse button
  66. TEMPLATE_FIELDNAME() :
  67. m_Visible( false ),
  68. m_URL( false )
  69. {
  70. }
  71. TEMPLATE_FIELDNAME( const wxString& aName ) :
  72. m_Name( aName ),
  73. m_Visible( false ),
  74. m_URL( false )
  75. {
  76. }
  77. TEMPLATE_FIELDNAME( const TEMPLATE_FIELDNAME& ref )
  78. {
  79. m_Name = ref.m_Name;
  80. m_Visible = ref.m_Visible;
  81. m_URL = ref.m_URL;
  82. }
  83. /**
  84. * Function Format
  85. * serializes this object out as text into the given OUTPUTFORMATTER.
  86. */
  87. void Format( OUTPUTFORMATTER* out, int nestLevel ) const ;
  88. /**
  89. * Function Parse
  90. * fills this object from information in the input stream \a aSpec, which
  91. * is a TEMPLATE_FIELDNAMES_LEXER. The entire textual element spec is <br>
  92. * (field (name _yourfieldname_)(value _yourvalue_) visible)) <br>
  93. * The presence of value is optional, the presence of visible is optional.
  94. * When this function is called, the input token stream given by \a aSpec
  95. * is assumed to be positioned at the '^' in the following example, i.e. just after the
  96. * identifying keyword and before the content specifying stuff.<br>
  97. * (field ^ (....) )
  98. *
  99. * @param aSpec is the input token stream of keywords and symbols.
  100. */
  101. void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
  102. /**
  103. * Function GetDefaultFieldName
  104. * returns a default symbol field name for field \a aFieldNdx for all components.
  105. * These fieldnames are not modifiable, but template fieldnames are.
  106. * @param aFieldNdx The field number index, > 0
  107. */
  108. static const wxString GetDefaultFieldName( int aFieldNdx );
  109. };
  110. typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
  111. class TEMPLATES
  112. {
  113. private:
  114. TEMPLATE_FIELDNAMES m_globals;
  115. TEMPLATE_FIELDNAMES m_project;
  116. // Combined list. Project templates override global ones.
  117. TEMPLATE_FIELDNAMES m_resolved;
  118. bool m_resolvedDirty;
  119. public:
  120. TEMPLATES() :
  121. m_resolvedDirty( true )
  122. { }
  123. /**
  124. * Function Format
  125. * serializes this object out as text into the given OUTPUTFORMATTER.
  126. */
  127. void Format( OUTPUTFORMATTER* out, int nestLevel, bool aGlobal ) const ;
  128. /**
  129. * Function Parse
  130. * fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER
  131. */
  132. void Parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal );
  133. /**
  134. * Function AddTemplateFieldName
  135. * inserts or appends a wanted symbol field name into the fieldnames
  136. * template. Should be used for any symbol property editor. If the name
  137. * already exists, it overwrites the same name.
  138. *
  139. * @param aFieldName is a full description of the wanted field, and it must not match
  140. * any of the default fieldnames.
  141. * @param aGlobal indicates whether to add to the global or project table.
  142. */
  143. void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal );
  144. /**
  145. * Function DeleteAllFieldNameTemplates
  146. * deletes the entire contents.
  147. */
  148. void DeleteAllFieldNameTemplates( bool aGlobal );
  149. /**
  150. * Function GetTemplateFieldName
  151. * returns a template fieldnames list for read only access.
  152. */
  153. const TEMPLATE_FIELDNAMES& GetTemplateFieldNames();
  154. /**
  155. * Function GetTemplateFieldName
  156. * returns a specific list (global or project) for read only access.
  157. */
  158. const TEMPLATE_FIELDNAMES& GetTemplateFieldNames( bool aGlobal );
  159. /**
  160. * Function GetFieldName
  161. * searches for \a aName in the the template field name list.
  162. *
  163. * @param aName A wxString object containing the field name to search for.
  164. * @return the template fieldname if found; NULL otherwise.
  165. */
  166. const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
  167. protected:
  168. void resolveTemplates();
  169. };
  170. #endif // _TEMPLATE_FIELDNAME_H_