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.

319 lines
11 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. * 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. KICAD_T Type() override { return FP_LIB_TABLE_T; }
  89. virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
  90. virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
  91. /**
  92. * Constructor FP_LIB_TABLE
  93. *
  94. * builds a footprint library table by pre-pending this table fragment in front of
  95. * @a aFallBackTable. Loading of this table fragment is done by using Parse().
  96. *
  97. * @param aFallBackTable is another FP_LIB_TABLE which is searched only when
  98. * a row is not found in this table. No ownership is
  99. * taken of aFallBackTable.
  100. */
  101. FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL );
  102. bool operator==( const FP_LIB_TABLE& aFpTable ) const;
  103. bool operator!=( const FP_LIB_TABLE& r ) const { return !( *this == r ); }
  104. /**
  105. * Function FindRow
  106. *
  107. * returns an FP_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
  108. * fallBack table fragment. The #PLUGIN is loaded and attached to the "plugin" field
  109. * of the #FP_LIB_TABLE_ROW if not already loaded.
  110. *
  111. * @throw IO_ERROR if \a aNickName cannot be found.
  112. */
  113. const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
  114. //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
  115. /**
  116. * Return a list of footprint names contained within the library given by @a aNickname.
  117. *
  118. * @param aFootprintNames is the list to fill with the footprint names found in \a aNickname
  119. *
  120. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
  121. * @param aBestEfforts if true, don't throw on errors
  122. *
  123. * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
  124. */
  125. void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
  126. bool aBestEfforts );
  127. /**
  128. * Generate a hashed timestamp representing the last-mod-times of the library indicated
  129. * by \a aNickname, or all libraries if \a aNickname is NULL.
  130. */
  131. long long GenerateTimestamp( const wxString* aNickname );
  132. /**
  133. * Function PrefetchLib
  134. * If possible, prefetches the specified library (e.g. performing downloads). Does not parse.
  135. * Threadsafe.
  136. *
  137. * This is a no-op for libraries that cannot be prefetched.
  138. *
  139. * @param aNickname is a locator for the library; it is a name in LIB_TABLE_ROW.
  140. *
  141. * @throw IO_ERROR if there is an error prefetching the library.
  142. */
  143. void PrefetchLib( const wxString& aNickname );
  144. /**
  145. * Function FootprintLoad
  146. *
  147. * loads a footprint having @a aFootprintName from the library given by @a aNickname.
  148. *
  149. * @param aNickname is a locator for the "library", it is a "name" in #LIB_TABLE_ROW
  150. *
  151. * @param aFootprintName is the name of the footprint to load.
  152. *
  153. * @return MODULE* - if found caller owns it, else NULL if not found.
  154. *
  155. * @throw IO_ERROR if the library cannot be found or read. No exception
  156. * is thrown in the case where aFootprintName cannot be found.
  157. */
  158. MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName );
  159. /**
  160. * Function FootprintExists
  161. *
  162. * indicates whether or not the given footprint already exists in the given library.
  163. */
  164. bool FootprintExists( const wxString& aNickname, const wxString& aFootprintName );
  165. /**
  166. * Function GetEnumeratedFootprint
  167. *
  168. * a version of FootprintLoad() for use after FootprintEnumerate() for more efficient
  169. * cache management. Return value is const to allow it to return a reference to a cached
  170. * item.
  171. */
  172. const MODULE* GetEnumeratedFootprint( const wxString& aNickname,
  173. const wxString& aFootprintName );
  174. /**
  175. * Enum SAVE_T
  176. * is the set of return values from FootprintSave() below.
  177. */
  178. enum SAVE_T
  179. {
  180. SAVE_OK,
  181. SAVE_SKIPPED,
  182. };
  183. /**
  184. * Function FootprintSave
  185. *
  186. * will write @a aFootprint to an existing library given by @a aNickname.
  187. * If a footprint by the same name already exists, it is replaced.
  188. *
  189. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW
  190. *
  191. * @param aFootprint is what to store in the library. The caller continues to own the
  192. * footprint after this call.
  193. *
  194. * @param aOverwrite when true means overwrite any existing footprint by the same name,
  195. * else if false means skip the write and return SAVE_SKIPPED.
  196. *
  197. * @return SAVE_T - SAVE_OK or SAVE_SKIPPED. If error saving, then IO_ERROR is thrown.
  198. *
  199. * @throw IO_ERROR if there is a problem saving.
  200. */
  201. SAVE_T FootprintSave( const wxString& aNickname, const MODULE* aFootprint,
  202. bool aOverwrite = true );
  203. /**
  204. * Function FootprintDelete
  205. *
  206. * deletes the @a aFootprintName from the library given by @a aNickname.
  207. *
  208. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
  209. *
  210. * @param aFootprintName is the name of a footprint to delete from the specified library.
  211. *
  212. * @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
  213. */
  214. void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );
  215. /**
  216. * Function IsFootprintLibWritable
  217. *
  218. * returns true if the library given by @a aNickname is writable. (Often
  219. * system libraries are read only because of where they are installed.)
  220. *
  221. * @throw IO_ERROR if no library at aLibraryPath exists.
  222. */
  223. bool IsFootprintLibWritable( const wxString& aNickname );
  224. void FootprintLibDelete( const wxString& aNickname );
  225. void FootprintLibCreate( const wxString& aNickname );
  226. //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
  227. /**
  228. * Function FootprintLoadWithOptionalNickname
  229. * loads a footprint having @a aFootprintId with possibly an empty nickname.
  230. *
  231. * @param aFootprintId the [nickname] & footprint name of the footprint to load.
  232. *
  233. * @return MODULE* - if found caller owns it, else NULL if not found.
  234. *
  235. * @throw IO_ERROR if the library cannot be found or read. No exception
  236. * is thrown in the case where aFootprintName cannot be found.
  237. * @throw PARSE_ERROR if @a aFootprintId is not parsed OK.
  238. */
  239. MODULE* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId );
  240. /**
  241. * Function LoadGlobalTable
  242. * loads the global footprint library table into \a aTable.
  243. *
  244. * This probably should be move into the application object when KiCad is changed
  245. * to a single process application. This is the least painful solution for the
  246. * time being.
  247. *
  248. * @param aTable the #FP_LIB_TABLE object to load.
  249. * @return true if the global library table exists and is loaded properly.
  250. * @throw IO_ERROR if an error occurs attempting to load the footprint library
  251. * table.
  252. */
  253. static bool LoadGlobalTable( FP_LIB_TABLE& aTable );
  254. /**
  255. * Function GetGlobalTableFileName
  256. *
  257. * @return the platform specific global footprint library path and file name.
  258. */
  259. static wxString GetGlobalTableFileName();
  260. /**
  261. * Function GlobalPathEnvVarVariableName
  262. *
  263. * returns the name of the environment variable used to hold the directory of
  264. * locally installed "KiCad sponsored" system footprint libraries. These can
  265. * be either legacy or pretty format. The only thing special about this
  266. * particular environment variable is that it is set automatically by
  267. * KiCad on program start up, <b>if</b> it is not set already in the environment.
  268. */
  269. static const wxString GlobalPathEnvVariableName();
  270. };
  271. extern FP_LIB_TABLE GFootprintTable; // KIFACE scope.
  272. #endif // FP_LIB_TABLE_H_