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.

307 lines
10 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 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-2017 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.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 FP_LIB_TABLE_H_
  26. #define FP_LIB_TABLE_H_
  27. #include <lib_table_base.h>
  28. #include <io_mgr.h>
  29. class MODULE;
  30. class FP_LIB_TABLE_GRID;
  31. /**
  32. * Class FP_LIB_TABLE_ROW
  33. *
  34. * holds a record identifying a library accessed by the appropriate footprint library #PLUGIN
  35. * object in the #FP_LIB_TABLE.
  36. */
  37. class FP_LIB_TABLE_ROW : public LIB_TABLE_ROW
  38. {
  39. friend class FP_LIB_TABLE;
  40. public:
  41. typedef IO_MGR::PCB_FILE_T LIB_T;
  42. FP_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
  43. const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
  44. LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
  45. {
  46. SetType( aType );
  47. }
  48. FP_LIB_TABLE_ROW() :
  49. type( IO_MGR::KICAD_SEXP )
  50. {
  51. }
  52. bool operator==( const FP_LIB_TABLE_ROW& aRow ) const;
  53. bool operator!=( const FP_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
  54. /**
  55. * Function GetType
  56. *
  57. * returns the type of footprint library table represented by this row.
  58. */
  59. const wxString GetType() const override { return IO_MGR::ShowType( type ); }
  60. /**
  61. * Function SetType
  62. *
  63. * changes the type represented by this row.
  64. */
  65. void SetType( const wxString& aType ) override;
  66. protected:
  67. FP_LIB_TABLE_ROW( const FP_LIB_TABLE_ROW& aRow ) :
  68. LIB_TABLE_ROW( aRow ),
  69. type( aRow.type )
  70. {
  71. }
  72. private:
  73. virtual LIB_TABLE_ROW* do_clone() const override
  74. {
  75. return new FP_LIB_TABLE_ROW( *this );
  76. }
  77. void setPlugin( PLUGIN* aPlugin )
  78. {
  79. plugin.set( aPlugin );
  80. }
  81. PLUGIN::RELEASER plugin;
  82. LIB_T type;
  83. };
  84. class FP_LIB_TABLE : public LIB_TABLE
  85. {
  86. friend class FP_LIB_TABLE_GRID;
  87. public:
  88. virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
  89. virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
  90. /**
  91. * Constructor FP_LIB_TABLE
  92. *
  93. * builds a footprint library table by pre-pending this table fragment in front of
  94. * @a aFallBackTable. Loading of this table fragment is done by using Parse().
  95. *
  96. * @param aFallBackTable is another FP_LIB_TABLE which is searched only when
  97. * a row is not found in this table. No ownership is
  98. * taken of aFallBackTable.
  99. */
  100. FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL );
  101. bool operator==( const FP_LIB_TABLE& aFpTable ) const;
  102. bool operator!=( const FP_LIB_TABLE& r ) const { return !( *this == r ); }
  103. /**
  104. * Function FindRow
  105. *
  106. * returns an FP_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
  107. * fallBack table fragment. The #PLUGIN is loaded and attached to the "plugin" field
  108. * of the #FP_LIB_TABLE_ROW if not already loaded.
  109. *
  110. * @throw IO_ERROR if \a aNickName cannot be found.
  111. */
  112. const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
  113. //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
  114. /**
  115. * Return a list of footprint names contained within the library given by @a aNickname.
  116. *
  117. * @param aFootprintNames is the list to fill with the footprint names found in \a aNickname
  118. *
  119. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
  120. *
  121. * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
  122. */
  123. void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname );
  124. /**
  125. * Generate a hashed timestamp representing the last-mod-times of the library indicated
  126. * by \a aNickname, or all libraries if \a aNickname is NULL.
  127. */
  128. long long GenerateTimestamp( const wxString* aNickname );
  129. /**
  130. * Function PrefetchLib
  131. * If possible, prefetches the specified library (e.g. performing downloads). Does not parse.
  132. * Threadsafe.
  133. *
  134. * This is a no-op for libraries that cannot be prefetched.
  135. *
  136. * @param aNickname is a locator for the library; it is a name in LIB_TABLE_ROW.
  137. *
  138. * @throw IO_ERROR if there is an error prefetching the library.
  139. */
  140. void PrefetchLib( const wxString& aNickname );
  141. /**
  142. * Function FootprintLoad
  143. *
  144. * loads a footprint having @a aFootprintName from the library given by @a aNickname.
  145. *
  146. * @param aNickname is a locator for the "library", it is a "name" in #LIB_TABLE_ROW
  147. *
  148. * @param aFootprintName is the name of the footprint to load.
  149. *
  150. * @return MODULE* - if found caller owns it, else NULL if not found.
  151. *
  152. * @throw IO_ERROR if the library cannot be found or read. No exception
  153. * is thrown in the case where aFootprintName cannot be found.
  154. */
  155. MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName );
  156. /**
  157. * Function LoadEnumeratedFootprint
  158. *
  159. * a version of FootprintLoad() for use after FootprintEnumerate() for more efficient
  160. * cache management.
  161. */
  162. MODULE* LoadEnumeratedFootprint( const wxString& aNickname, const wxString& aFootprintName );
  163. /**
  164. * Enum SAVE_T
  165. * is the set of return values from FootprintSave() below.
  166. */
  167. enum SAVE_T
  168. {
  169. SAVE_OK,
  170. SAVE_SKIPPED,
  171. };
  172. /**
  173. * Function FootprintSave
  174. *
  175. * will write @a aFootprint to an existing library given by @a aNickname.
  176. * If a footprint by the same name already exists, it is replaced.
  177. *
  178. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW
  179. *
  180. * @param aFootprint is what to store in the library. The caller continues to own the
  181. * footprint after this call.
  182. *
  183. * @param aOverwrite when true means overwrite any existing footprint by the same name,
  184. * else if false means skip the write and return SAVE_SKIPPED.
  185. *
  186. * @return SAVE_T - SAVE_OK or SAVE_SKIPPED. If error saving, then IO_ERROR is thrown.
  187. *
  188. * @throw IO_ERROR if there is a problem saving.
  189. */
  190. SAVE_T FootprintSave( const wxString& aNickname, const MODULE* aFootprint,
  191. bool aOverwrite = true );
  192. /**
  193. * Function FootprintDelete
  194. *
  195. * deletes the @a aFootprintName from the library given by @a aNickname.
  196. *
  197. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
  198. *
  199. * @param aFootprintName is the name of a footprint to delete from the specified library.
  200. *
  201. * @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
  202. */
  203. void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );
  204. /**
  205. * Function IsFootprintLibWritable
  206. *
  207. * returns true if the library given by @a aNickname is writable. (Often
  208. * system libraries are read only because of where they are installed.)
  209. *
  210. * @throw IO_ERROR if no library at aLibraryPath exists.
  211. */
  212. bool IsFootprintLibWritable( const wxString& aNickname );
  213. void FootprintLibDelete( const wxString& aNickname );
  214. void FootprintLibCreate( const wxString& aNickname );
  215. //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
  216. /**
  217. * Function FootprintLoadWithOptionalNickname
  218. * loads a footprint having @a aFootprintId with possibly an empty nickname.
  219. *
  220. * @param aFootprintId the [nickname] & footprint name of the footprint to load.
  221. *
  222. * @return MODULE* - if found caller owns it, else NULL if not found.
  223. *
  224. * @throw IO_ERROR if the library cannot be found or read. No exception
  225. * is thrown in the case where aFootprintName cannot be found.
  226. * @throw PARSE_ERROR if @a aFootprintId is not parsed OK.
  227. */
  228. MODULE* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId );
  229. /**
  230. * Function LoadGlobalTable
  231. * loads the global footprint library table into \a aTable.
  232. *
  233. * This probably should be move into the application object when KiCad is changed
  234. * to a single process application. This is the least painful solution for the
  235. * time being.
  236. *
  237. * @param aTable the #FP_LIB_TABLE object to load.
  238. * @return true if the global library table exists and is loaded properly.
  239. * @throw IO_ERROR if an error occurs attempting to load the footprint library
  240. * table.
  241. */
  242. static bool LoadGlobalTable( FP_LIB_TABLE& aTable );
  243. /**
  244. * Function GetGlobalTableFileName
  245. *
  246. * @return the platform specific global footprint library path and file name.
  247. */
  248. static wxString GetGlobalTableFileName();
  249. /**
  250. * Function GlobalPathEnvVarVariableName
  251. *
  252. * returns the name of the environment variable used to hold the directory of
  253. * locally installed "KiCad sponsored" system footprint libraries. These can
  254. * be either legacy or pretty format. The only thing special about this
  255. * particular environment variable is that it is set automatically by
  256. * KiCad on program start up, <b>if</b> it is not set already in the environment.
  257. */
  258. static const wxString GlobalPathEnvVariableName();
  259. };
  260. extern FP_LIB_TABLE GFootprintTable; // KIFACE scope.
  261. #endif // FP_LIB_TABLE_H_