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.

159 lines
4.8 KiB

15 years ago
  1. #ifndef _TEMPLATE_FIELDNAME_H_
  2. #define _TEMPLATE_FIELDNAME_H_
  3. #include <richio.h>
  4. #include <wxstruct.h>
  5. #include <macros.h>
  6. #include <template_fieldnames_lexer.h>
  7. class TEMPLATE_FIELDNAMES_LEXER;
  8. /**
  9. * Enum NumFieldType
  10. * is the set of all field indices assuming an array like sequence that a
  11. * SCH_COMPONENT or LIB_COMPONENT can hold.
  12. * The first fields are called fixed fields and the quantity of them is
  13. * given by MANDATORY_FIELDS. After that come an unlimited number of
  14. * user defined fields, only some of which have indices defined here.
  15. */
  16. enum NumFieldType {
  17. REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
  18. VALUE, ///< Field Value of part, i.e. "3.3K"
  19. FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300"
  20. DATASHEET, ///< name of datasheet
  21. /// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT
  22. /// and LIB_COMPONENT constructors
  23. MANDATORY_FIELDS,
  24. FIELD1 = MANDATORY_FIELDS,
  25. FIELD2,
  26. FIELD3,
  27. FIELD4,
  28. FIELD5,
  29. FIELD6,
  30. FIELD7,
  31. FIELD8
  32. };
  33. /**
  34. * Struct TEMPLATE_FIELDNAME
  35. * holds a name of a component's field, field value, and default visibility.
  36. * Template fieldnames are wanted fieldnames for use in the symbol/component
  37. * property editors.
  38. */
  39. struct TEMPLATE_FIELDNAME
  40. {
  41. wxString m_Name; ///< The field name
  42. wxString m_Value; ///< The default value or empty
  43. bool m_Visible; ///< If first appearance of the field's editor has as visible.
  44. TEMPLATE_FIELDNAME() :
  45. m_Visible( false )
  46. {
  47. }
  48. TEMPLATE_FIELDNAME( const wxString& aName ) :
  49. m_Name( aName ),
  50. m_Visible( false )
  51. {
  52. }
  53. /**
  54. * Function Format
  55. * serializes this object out as text into the given OUTPUTFORMATTER.
  56. */
  57. void Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR );
  58. /**
  59. * Function Parse
  60. * fills this object from information in the input stream \a aSpec, which
  61. * is a TEMPLATE_FIELDNAMES_LEXER. The entire textual element spec is <br>
  62. * (field (name _yourfieldname_)(value _yourvalue_) visible)) <br>
  63. * The presence of value is optional, the presence of visible is optional.
  64. * When this function is called, the input token stream given by \a aSpec
  65. * is assumed to be positioned at the '^' in the following example, i.e. just after the
  66. * identifying keyword and before the content specifying stuff.<br>
  67. * (field ^ (....) )
  68. *
  69. * @param aSpec is the input token stream of keywords and symbols.
  70. */
  71. void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec ) throw( IO_ERROR );
  72. /**
  73. * Function GetDefaultFieldName
  74. * returns a default symbol field name for field \a aFieldNdx for all components.
  75. * These fieldnames are not modifiable, but template fieldnames are.
  76. * @param aFieldNdx The field number index, > 0
  77. */
  78. static wxString GetDefaultFieldName( int aFieldNdx );
  79. };
  80. typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
  81. class TEMPLATES
  82. {
  83. private:
  84. TEMPLATE_FIELDNAMES m_Fields;
  85. public:
  86. /**
  87. * Function Format
  88. * serializes this object out as text into the given OUTPUTFORMATTER.
  89. */
  90. void Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR );
  91. /**
  92. * Function Parse
  93. * fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER
  94. */
  95. void Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR );
  96. /**
  97. * Function AddTemplateFieldName
  98. * inserts or appends a wanted symbol field name into the fieldnames
  99. * template. Should be used for any symbol property editor. If the name
  100. * already exists, it overwrites the same name.
  101. *
  102. * @param aFieldName is a full description of the wanted field, and it must not match
  103. * any of the default fieldnames.
  104. * @return int - the index within the config container at which aFieldName was
  105. * added, or -1 if the name is illegal because it matches a default fieldname.
  106. */
  107. int AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName );
  108. /**
  109. * Function DeleteAllTemplateFieldNames
  110. * deletes the entire contents.
  111. */
  112. void DeleteAllTemplateFieldNames()
  113. {
  114. m_Fields.clear();
  115. }
  116. /**
  117. * Function GetTemplateFieldName
  118. * returns a template fieldnames list for read only access.
  119. */
  120. const TEMPLATE_FIELDNAMES& GetTemplateFieldNames()
  121. {
  122. return m_Fields;
  123. }
  124. /**
  125. * Function HasFieldName
  126. * checks for \a aName in the the template field name list.
  127. *
  128. * @param aName A wxString object containing the field name to search for.
  129. * @return True if \a aName is found in the list.
  130. */
  131. bool HasFieldName( const wxString& aName ) const;
  132. };
  133. #endif // _TEMPLATE_FIELDNAME_H_