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.

206 lines
6.7 KiB

  1. /***********************************/
  2. /* Headers for library definition */
  3. /***********************************/
  4. #ifndef CLASS_LIBRARY_H
  5. #define CLASS_LIBRARY_H
  6. #include "class_libentry.h"
  7. /******************************/
  8. /* Class to handle a library */
  9. /******************************/
  10. class LibraryStruct
  11. {
  12. public:
  13. int m_Type; /* type indicator */
  14. wxString m_Name; /* Library file name (without path). */
  15. wxString m_FullFileName; /* Full File Name (with path) of library. */
  16. wxString m_Header; /* first line of loaded library. */
  17. int m_NumOfParts; /* Number of parts this library has. */
  18. LibraryStruct* m_Pnext; /* Point on next lib in chain. */
  19. int m_Modified; /* flag indicateur d'edition */
  20. int m_Size; // Size in bytes (for statistics)
  21. unsigned long m_TimeStamp; // Signature temporelle
  22. int m_Flags; // variable used in some functions
  23. bool m_IsLibCache; /* False for the "standard" libraries,
  24. * True for the library cache */
  25. public:
  26. LibraryStruct( int type, const wxString& name, const wxString& fullname );
  27. ~LibraryStruct();
  28. /**
  29. * Save library to file.
  30. *
  31. * Two files are created. The component objects are save as component
  32. * library (*.lib) files. The alias objects are save as document
  33. * definition (*.dcm) files. If the component library already exists,
  34. * it is backup up in file *.bak. If the document definition file
  35. * already exists, it is backed up in file *.bck.
  36. *
  37. * @param aFullFileName - The library filename with path.
  38. *
  39. * @return bool - true if success writing else false.
  40. */
  41. bool SaveLibrary( const wxString& aFullFileName );
  42. bool ReadHeader( FILE* file, int* LineNum );
  43. bool Load( wxString& errMsg );
  44. void InsertAliases( PriorQue** PQ, EDA_LibComponentStruct* component );
  45. private:
  46. bool WriteHeader( FILE* file );
  47. public:
  48. LibraryStruct( const wxChar* fileName = NULL );
  49. /**
  50. * Get library entry status.
  51. *
  52. * @return true if there are no entries in the library.
  53. */
  54. bool IsEmpty()
  55. {
  56. return m_Entries == NULL;
  57. }
  58. /**
  59. * Load a string array with the names of all the entries in this library.
  60. *
  61. * @param names - String array to place entry names into.
  62. * @param sort - Sort names if true.
  63. */
  64. void GetEntryNames( wxArrayString& names, bool sort = true );
  65. /**
  66. * Load string array with entry names matching name and/or key word.
  67. *
  68. * This currently mimics the old behavior of calling KeyWordOk() and
  69. * WildCompareString(). The names array will be populated with the
  70. * library entry names that meat the search criteria on exit.
  71. *
  72. * @todo Convert the search functions to use regular expressions which
  73. * should give better search capability.
  74. *
  75. * @param names - String array to place entry names into.
  76. * @param nameSearch - Name wild card search criteria.
  77. * @param keySearch - Key word search criteria.
  78. * @param sort - Sort names if true.
  79. */
  80. void SearchEntryNames( wxArrayString& names,
  81. const wxString& nameSearch = wxEmptyString,
  82. const wxString& keySearch = wxEmptyString,
  83. bool sort = true );
  84. /**
  85. * Find entry by name.
  86. *
  87. * @param name - Name of entry, case insensitive.
  88. *
  89. * @return Pointer to entry if found. NULL if not found.
  90. */
  91. LibCmpEntry* FindEntry( const wxChar* name );
  92. /**
  93. * Find entry by name and type.
  94. *
  95. * If the search type is an alias, the return entry can be either an
  96. * alias or a component object. If the search type is a component
  97. * (root) type, the object returned will be a component. This was
  98. * done to emulate the old search pattern.
  99. *
  100. * @param name - Name of entry, case insensitive.
  101. * @param type - Type of entry, root or alias.
  102. *
  103. * @return Pointer to entry if found. NULL if not found.
  104. */
  105. LibCmpEntry* FindEntry( const wxChar* name, LibrEntryType type );
  106. /**
  107. * Add component entry to library.
  108. *
  109. * @param cmp - Component to add.
  110. *
  111. * @return Pointer to added component if successful.
  112. */
  113. EDA_LibComponentStruct* AddComponent( EDA_LibComponentStruct* cmp );
  114. /**
  115. * Remove an entry from the library.
  116. *
  117. * If the entry is an alias, the alias is removed from the library and from
  118. * the alias list of the root component. If the entry is a root component
  119. * with no aliases, it is removed from the library. If the entry is a root
  120. * component with aliases, the root component is renamed to the name of
  121. * the first alias and the root name for all remaining aliases are updated
  122. * to reflect the new root name.
  123. *
  124. * @param entry - Entry to remove from library.
  125. */
  126. void RemoveEntry( LibCmpEntry* entry );
  127. /**
  128. * Return the first entry in the library.
  129. *
  130. * @return The first entry or NULL if the library has no entries.
  131. */
  132. LibCmpEntry* GetFirstEntry()
  133. {
  134. return (LibCmpEntry*) PQFirst( &m_Entries, false );
  135. }
  136. /**
  137. * Find next library entry by name.
  138. *
  139. * If the name of the entry is the last entry in the library, the first
  140. * entry in the list is returned.
  141. *
  142. * @param name - Name of current entry.
  143. *
  144. * @return LibCmpEntry - Pointer to next entry if entry name is found.
  145. * Otherwise NULL.
  146. */
  147. LibCmpEntry* GetNextEntry( const wxChar* name );
  148. /**
  149. * Find previous library entry by name.
  150. *
  151. * If the name of the entry is the first entry in the library, the last
  152. * entry in the list is returned.
  153. *
  154. * @param name - Name of current entry.
  155. *
  156. * @return LibCmpEntry - Pointer to previous entry if entry name is found.
  157. * Otherwise NULL.
  158. */
  159. LibCmpEntry* GetPreviousEntry( const wxChar* name );
  160. bool Save( const wxString& saveAsFile );
  161. wxString GetName();
  162. protected:
  163. wxFileName m_fileName; /* Library file name. */
  164. wxDateTime m_DateTime; /* Library save time and date. */
  165. wxString m_Version; /* Library save version. */
  166. PriorQue* m_Entries; /* Parts themselves are saved here. */
  167. friend class EDA_LibComponentStruct;
  168. };
  169. extern void FreeLibraryEntry( LibCmpEntry* Entry );
  170. /**
  171. * Case insensitive library name comparison.
  172. */
  173. extern bool operator==( const LibraryStruct& lib, const wxChar* name );
  174. extern bool operator!=( const LibraryStruct& lib, const wxChar* name );
  175. #endif // CLASS_LIBRARY_H