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.

200 lines
6.7 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef _FPID_H_
  26. #define _FPID_H_
  27. #include <richio.h>
  28. #include <utf8.h>
  29. /**
  30. * Class FPID
  31. * is a Logical Footprint ID and consists of various portions much like a URI.
  32. * It is a container for the separated portions of a logical footprint id so they
  33. * can be accessed individually. The various portions of an FPID are:
  34. * logicalLibraryName (nick name), footprint name, and revision. The logical library
  35. * name and the footprint name are mandatory. The revision is optional and currently is
  36. * not used.
  37. *
  38. * Example FPID string:
  39. * "smt:R_0805/rev0".
  40. *
  41. * <p>
  42. * <ul>
  43. * <li> "smt" is the logical library name used to look up library information saved in the
  44. * #FP_LIB_TABLE.
  45. * <li> "R" is the name of the footprint within the library.
  46. * <li> "rev0" is the revision, which is optional. If missing then its
  47. * / delimiter should also not be present. A revision must begin with
  48. * "rev" and be followed by at least one or more decimal digits.
  49. * </ul>
  50. *
  51. * @author Dick Hollenbeck
  52. */
  53. class FPID
  54. {
  55. public:
  56. FPID() {}
  57. /**
  58. * Constructor FPID
  59. * takes \a aId string and parses it. A typical FPID string consists of a
  60. * library nickname followed by a footprint name.
  61. * e.g.: "smt:R_0805", or
  62. * e.g.: "mylib:R_0805"
  63. *
  64. * @param aId is a string to be parsed into the FPID object.
  65. */
  66. FPID( const std::string& aId ) throw( PARSE_ERROR );
  67. FPID( const wxString& aId ) throw( PARSE_ERROR );
  68. /**
  69. * Function Parse
  70. * [re-]stuffs this FPID with the information from @a aId.
  71. *
  72. * @param aId is the string to populate the #FPID object.
  73. * @return int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into
  74. * aId at which an error was detected.
  75. */
  76. int Parse( const std::string& aId );
  77. int Parse( const wxString& aId );
  78. /**
  79. * Function GetLibNickname
  80. * returns the logical library name portion of a FPID.
  81. */
  82. const UTF8& GetLibNickname() const
  83. {
  84. return nickname;
  85. }
  86. /**
  87. * Function SetLibNickname
  88. * overrides the logical footprint library name portion of the FPID to @a aNickname.
  89. * @return int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset
  90. * into the parameter at which an error was detected, usually because it
  91. * contained '/' or ':'.
  92. */
  93. int SetLibNickname( const std::string& aNickname );
  94. int SetLibNickname( const wxString& aNickname );
  95. /**
  96. * Function GetFootprintName
  97. * returns the footprint name, i.e. footprintName.
  98. */
  99. const UTF8& GetFootprintName() const { return footprint; }
  100. /**
  101. * Function SetFootprintName
  102. * overrides the footprint name portion of the FPID to @a aFootprintName
  103. */
  104. int SetFootprintName( const std::string& aFootprintName );
  105. int SetFootprintName( const wxString& aFootprintName );
  106. int SetRevision( const std::string& aRevision );
  107. const UTF8& GetRevision() const { return revision; }
  108. UTF8 GetFootprintNameAndRev() const;
  109. /**
  110. * Function Format
  111. * returns the fully formatted text of the FPID.
  112. */
  113. UTF8 Format() const;
  114. /**
  115. * Function Format
  116. * returns a wxString in the proper format as an FPID for a combination of
  117. * aLibNickname, aFootprintName, and aRevision.
  118. *
  119. * @throw PARSE_ERROR if any of the pieces are illegal.
  120. */
  121. static UTF8 Format( const std::string& aLibNickname, const std::string& aFootprintName,
  122. const std::string& aRevision )
  123. throw( PARSE_ERROR );
  124. /**
  125. * Function IsValid
  126. * @return true is the #FPID is valid.
  127. *
  128. * A valid #FPID must have both the footprint library nickname and the footprint name
  129. * defined. The revision field is optional.
  130. *
  131. * @note A return value of true does not indicated that the #FPID is a valid #FP_LIB_TABLE
  132. * entry.
  133. */
  134. bool IsValid() const { return !nickname.empty() && !footprint.empty(); }
  135. /**
  136. * Function IsLegacy
  137. * @return true if the #FPID only has the #footprint name defined.
  138. */
  139. bool IsLegacy() const { return nickname.empty() && !footprint.empty() && revision.empty(); }
  140. /**
  141. * Function clear
  142. * clears the contents of the library nickname, footprint name, and revision strings.
  143. */
  144. void clear();
  145. /**
  146. * Function empty
  147. * @return a boolean true value if the FPID is empty. Otherwise return false.
  148. */
  149. bool empty() const { return nickname.empty() && footprint.empty() && revision.empty(); }
  150. /**
  151. * Function Compare
  152. * compares the contents of FPID objects by performing a std::string comparison of the
  153. * library nickname, footprint name, and revision strings respectively.
  154. *
  155. * @param aFPID is the FPID to compare against.
  156. * @return -1 if less than \a aFPID, 1 if greater than \a aFPID, and 0 if equal to \a aFPID.
  157. */
  158. int compare( const FPID& aFPID ) const;
  159. bool operator < ( const FPID& aFPID ) const { return this->compare( aFPID ) < 0; }
  160. bool operator > ( const FPID& aFPID ) const { return this->compare( aFPID ) > 0; }
  161. bool operator ==( const FPID& aFPID ) const { return this->compare( aFPID ) == 0; }
  162. bool operator !=( const FPID& aFPID ) const { return !(*this == aFPID); }
  163. #if defined(DEBUG)
  164. static void Test();
  165. #endif
  166. protected:
  167. UTF8 nickname; ///< The nickname of the footprint library or empty.
  168. UTF8 footprint; ///< The name of the footprint in the logical library.
  169. UTF8 revision; ///< The footprint revision.
  170. };
  171. #endif // _FPID_H_