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.

616 lines
23 KiB

++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
  1. #ifndef IO_MGR_H_
  2. #define IO_MGR_H_
  3. /*
  4. * This program source code file is part of KICAD, a free EDA CAD application.
  5. *
  6. * Copyright (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  7. * Copyright (C) 2016-2017 Kicad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <richio.h>
  27. #include <map>
  28. #include <functional>
  29. #include <wx/time.h>
  30. #include <config.h>
  31. class BOARD;
  32. class PLUGIN;
  33. class MODULE;
  34. class PROPERTIES;
  35. /**
  36. * Class IO_MGR
  37. * is a factory which returns an instance of a PLUGIN.
  38. */
  39. class IO_MGR
  40. {
  41. public:
  42. /**
  43. * Enum PCB_FILE_T
  44. * is a set of file types that the IO_MGR knows about, and for which there
  45. * has been a plugin written.
  46. */
  47. enum PCB_FILE_T
  48. {
  49. LEGACY, ///< Legacy Pcbnew file formats prior to s-expression.
  50. KICAD_SEXP, ///< S-expression Pcbnew file format.
  51. EAGLE,
  52. PCAD,
  53. GEDA_PCB, ///< Geda PCB file formats.
  54. //N.B. This needs to be commented out to ensure compile-type errors
  55. #if defined(BUILD_GITHUB_PLUGIN)
  56. GITHUB, ///< Read only http://github.com repo holding pretty footprints
  57. #endif
  58. // add your type here.
  59. // ALTIUM,
  60. // etc.
  61. FILE_TYPE_NONE
  62. };
  63. /**
  64. * Class PLUGIN_REGISTRY
  65. * Holds a list of available plugins, created using a singleton REGISTER_PLUGIN object.
  66. * This way, plugins can be added link-time.
  67. */
  68. class PLUGIN_REGISTRY
  69. {
  70. public:
  71. struct ENTRY
  72. {
  73. PCB_FILE_T m_type;
  74. std::function<PLUGIN*(void)> m_createFunc;
  75. wxString m_name;
  76. };
  77. static PLUGIN_REGISTRY *Instance()
  78. {
  79. static PLUGIN_REGISTRY *self = nullptr;
  80. if( !self )
  81. {
  82. self = new PLUGIN_REGISTRY;
  83. }
  84. return self;
  85. }
  86. void Register( PCB_FILE_T aType, const wxString& aName, std::function<PLUGIN*(void)> aCreateFunc )
  87. {
  88. ENTRY ent;
  89. ent.m_type = aType;
  90. ent.m_createFunc = aCreateFunc;
  91. ent.m_name = aName;
  92. m_plugins.push_back( ent );
  93. }
  94. PLUGIN* Create( PCB_FILE_T aFileType ) const
  95. {
  96. for( auto& ent : m_plugins )
  97. {
  98. if ( ent.m_type == aFileType )
  99. {
  100. return ent.m_createFunc();
  101. }
  102. }
  103. return nullptr;
  104. }
  105. const std::vector<ENTRY>& AllPlugins() const
  106. {
  107. return m_plugins;
  108. }
  109. private:
  110. std::vector<ENTRY> m_plugins;
  111. };
  112. /**
  113. * Class REGISTER_PLUGIN
  114. * Registers a plugin. Declare as a static variable in an anonymous namespace.
  115. * @param aType: type of the plugin
  116. * @param aName: name of the file format
  117. * @param aCreateFunc: function that creates a new object for the plugin.
  118. */
  119. struct REGISTER_PLUGIN
  120. {
  121. REGISTER_PLUGIN( PCB_FILE_T aType, const wxString& aName, std::function<PLUGIN*(void)> aCreateFunc )
  122. {
  123. PLUGIN_REGISTRY::Instance()->Register( aType, aName, aCreateFunc );
  124. }
  125. };
  126. /**
  127. * Function PluginFind
  128. * returns a PLUGIN which the caller can use to import, export, save, or load
  129. * design documents. The returned PLUGIN, may be reference counted, so please
  130. * call PluginRelease() when you are done using the returned PLUGIN. It may or
  131. * may not be code running from a DLL/DSO.
  132. *
  133. * @param aFileType is from PCB_FILE_T and tells which plugin to find.
  134. *
  135. * @return PLUGIN* - the plugin corresponding to aFileType or NULL if not found.
  136. * Caller owns the returned object, and must call PluginRelease when done using it.
  137. */
  138. static PLUGIN* PluginFind( PCB_FILE_T aFileType );
  139. /**
  140. * Function PluginRelease
  141. * releases a PLUGIN back to the system, and may cause it to be unloaded from memory.
  142. *
  143. * @param aPlugin is the one to be released, and which is no longer usable
  144. * after calling this.
  145. */
  146. static void PluginRelease( PLUGIN* aPlugin );
  147. /**
  148. * Function ShowType
  149. * returns a brief name for a plugin, given aFileType enum.
  150. */
  151. static const wxString ShowType( PCB_FILE_T aFileType );
  152. /**
  153. * Function EnumFromStr
  154. * returns the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
  155. */
  156. static PCB_FILE_T EnumFromStr( const wxString& aFileType );
  157. /**
  158. * Function GetFileExtension
  159. * returns the file extension for \a aFileType.
  160. *
  161. * @param aFileType The #PCB_FILE_T type.
  162. * @return A wxString object containing the file extension for \a aFileType or an empty
  163. * string if \a aFileType is invalid.
  164. */
  165. static const wxString GetFileExtension( PCB_FILE_T aFileType );
  166. /**
  167. * Function GuessPluginTypeFromLibPath
  168. * returns a plugin type given a footprint library's libPath.
  169. */
  170. static PCB_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
  171. /**
  172. * Function Load
  173. * finds the requested PLUGIN and if found, calls the PLUGIN->Load(..) funtion
  174. * on it using the arguments passed to this function. After the PLUGIN->Load()
  175. * function returns, the PLUGIN is Released() as part of this call.
  176. *
  177. * @param aFileType is the PCB_FILE_T of file to load.
  178. *
  179. * @param aFileName is the name of the file to load.
  180. *
  181. * @param aAppendToMe is an existing BOARD to append to, use NULL if fresh
  182. * board load is wanted.
  183. *
  184. * @param aProperties is an associative array that allows the caller to
  185. * pass additional tuning parameters to the PLUGIN.
  186. *
  187. * @return BOARD* - caller owns it, never NULL because exception thrown if error.
  188. *
  189. * @throw IO_ERROR if the PLUGIN cannot be found, file cannot be found,
  190. * or file cannot be loaded.
  191. */
  192. static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName,
  193. BOARD* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
  194. /**
  195. * Function Save
  196. * will write either a full aBoard to a storage file in a format that this
  197. * implementation knows about, or it can be used to write a portion of
  198. * aBoard to a special kind of export file.
  199. *
  200. * @param aFileType is the PCB_FILE_T of file to save.
  201. *
  202. * @param aFileName is the name of a file to save to on disk.
  203. * @param aBoard is the BOARD document (data tree) to save or export to disk.
  204. *
  205. * @param aBoard is the in memory document tree from which to extract information
  206. * when writing to \a aFileName. The caller continues to own the BOARD, and
  207. * the plugin should refrain from modifying the BOARD if possible.
  208. *
  209. * @param aProperties is an associative array that can be used to tell the
  210. * saver how to save the file, because it can take any number of
  211. * additional named tuning arguments that the plugin is known to support.
  212. * The caller continues to own this object (plugin may not delete it), and
  213. * plugins should expect it to be optionally NULL.
  214. *
  215. * @throw IO_ERROR if there is a problem saving or exporting.
  216. */
  217. static void Save( PCB_FILE_T aFileType, const wxString& aFileName,
  218. BOARD* aBoard, const PROPERTIES* aProperties = NULL );
  219. };
  220. /**
  221. * Class PLUGIN
  222. * is a base class that BOARD loading and saving plugins should derive from.
  223. * Implementations can provide either Load() or Save() functions, or both.
  224. * PLUGINs throw exceptions, so it is best that you wrap your calls to these
  225. * functions in a try catch block. Plugins throw exceptions because it is illegal
  226. * for them to have any user interface calls in them whatsoever, i.e. no windowing
  227. * or screen printing at all.
  228. *
  229. * <pre>
  230. * try
  231. * {
  232. * IO_MGR::Load(...);
  233. * or
  234. * IO_MGR::Save(...);
  235. * }
  236. * catch( const IO_ERROR& ioe )
  237. * {
  238. * // grab text from ioe, show in error window.
  239. * }
  240. * </pre>
  241. */
  242. class PLUGIN
  243. {
  244. public:
  245. //-----<PUBLIC PLUGIN API>-------------------------------------------------
  246. /**
  247. * Function PluginName
  248. * returns a brief hard coded name for this PLUGIN.
  249. */
  250. virtual const wxString PluginName() const = 0;
  251. /**
  252. * Function GetFileExtension
  253. * returns the file extension for the PLUGIN.
  254. */
  255. virtual const wxString GetFileExtension() const = 0;
  256. /**
  257. * Function Load
  258. * loads information from some input file format that this PLUGIN implementation
  259. * knows about, into either a new BOARD or an existing one. This may be used to load an
  260. * entire new BOARD, or to augment an existing one if @a aAppendToMe is not NULL.
  261. *
  262. * @param aFileName is the name of the file to use as input and may be foreign in
  263. * nature or native in nature.
  264. *
  265. * @param aAppendToMe is an existing BOARD to append to, but if NULL then
  266. * this means "do not append, rather load anew".
  267. *
  268. * @param aProperties is an associative array that can be used to tell the
  269. * loader how to load the file, because it can take any number of
  270. * additional named arguments that the plugin is known to support. These are
  271. * tuning parameters for the import or load. The caller continues to own
  272. * this object (plugin may not delete it), and plugins should expect it to
  273. * be optionally NULL.
  274. *
  275. * @return BOARD* - the successfully loaded board, or the same one as aAppendToMe
  276. * if aAppendToMe was not NULL, and caller owns it.
  277. *
  278. * @throw IO_ERROR if there is a problem loading, and its contents should
  279. * say what went wrong, using line number and character offsets of the
  280. * input file if possible.
  281. */
  282. virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
  283. const PROPERTIES* aProperties = NULL );
  284. /**
  285. * Function Save
  286. * will write @a aBoard to a storage file in a format that this
  287. * PLUGIN implementation knows about, or it can be used to write a portion of
  288. * aBoard to a special kind of export file.
  289. *
  290. * @param aFileName is the name of a file to save to on disk.
  291. *
  292. * @param aBoard is the class BOARD in memory document tree from which to
  293. * extract information when writing to \a aFileName. The caller continues to
  294. * own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
  295. *
  296. * @param aProperties is an associative array that can be used to tell the
  297. * saver how to save the file, because it can take any number of
  298. * additional named tuning arguments that the plugin is known to support.
  299. * The caller continues to own this object (plugin may not delete it),
  300. * and plugins should expect it to be optionally NULL.
  301. *
  302. * @throw IO_ERROR if there is a problem saving or exporting.
  303. */
  304. virtual void Save( const wxString& aFileName, BOARD* aBoard,
  305. const PROPERTIES* aProperties = NULL );
  306. //-----<Footprint Stuff>-----------------------------
  307. /**
  308. * Return a list of footprint names contained within the library at @a aLibraryPath.
  309. *
  310. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  311. * or URL containing several footprints.
  312. *
  313. * @param aProperties is an associative array that can be used to tell the
  314. * plugin anything needed about how to perform with respect to @a aLibraryPath.
  315. * The caller continues to own this object (plugin may not delete it), and
  316. * plugins should expect it to be optionally NULL.
  317. *
  318. * @param aFootprintNames is the array of available footprint names inside a library.
  319. *
  320. * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
  321. */
  322. virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
  323. const PROPERTIES* aProperties = NULL );
  324. /**
  325. * Generate a timestamp representing all the files in the library (including the library
  326. * directory).
  327. * Timestamps should not be considered ordered; they either match or they don't.
  328. */
  329. virtual long long GetLibraryTimestamp( const wxString& aLibraryPath ) const = 0;
  330. /**
  331. * Function PrefetchLib
  332. * If possible, prefetches the specified library (e.g. performing downloads). Does not parse.
  333. * Threadsafe.
  334. *
  335. * This is a no-op for libraries that cannot be prefetched.
  336. *
  337. * Plugins that cannot prefetch need not override this; a default no-op is provided.
  338. *
  339. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  340. * or URL containing several footprints.
  341. *
  342. * @param aProperties is an associative array that can be used to tell the
  343. * plugin anything needed about how to perform with respect to @a aLibraryPath.
  344. * The caller continues to own this object (plugin may not delete it), and
  345. * plugins should expect it to be optionally NULL.
  346. *
  347. * @throw IO_ERROR if there is an error prefetching the library.
  348. */
  349. virtual void PrefetchLib( const wxString& aLibraryPath,
  350. const PROPERTIES* aProperties = NULL );
  351. /**
  352. * Function FootprintLoad
  353. * loads a footprint having @a aFootprintName from the @a aLibraryPath containing
  354. * a library format that this PLUGIN knows about.
  355. *
  356. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  357. * or URL containing several footprints.
  358. *
  359. * @param aFootprintName is the name of the footprint to load.
  360. *
  361. * @param aProperties is an associative array that can be used to tell the
  362. * loader implementation to do something special, because it can take any number of
  363. * additional named tuning arguments that the plugin is known to support.
  364. * The caller continues to own this object (plugin may not delete it), and
  365. * plugins should expect it to be optionally NULL.
  366. *
  367. * @return MODULE* - if found caller owns it, else NULL if not found.
  368. *
  369. * @throw IO_ERROR if the library cannot be found or read. No exception
  370. * is thrown in the case where aFootprintName cannot be found.
  371. */
  372. virtual MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
  373. const PROPERTIES* aProperties = NULL );
  374. /**
  375. * Function GetEnumeratedFootprint
  376. * a version of FootprintLoad() for use after FootprintEnumerate() for more efficient
  377. * cache management.
  378. */
  379. virtual const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath,
  380. const wxString& aFootprintName,
  381. const PROPERTIES* aProperties = NULL );
  382. /**
  383. * Function FootprintSave
  384. * will write @a aModule to an existing library located at @a aLibraryPath.
  385. * If a footprint by the same name already exists, it is replaced.
  386. *
  387. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  388. * or URL containing several footprints.
  389. *
  390. * @param aFootprint is what to store in the library. The caller continues
  391. * to own the footprint after this call.
  392. *
  393. * @param aProperties is an associative array that can be used to tell the
  394. * saver how to save the footprint, because it can take any number of
  395. * additional named tuning arguments that the plugin is known to support.
  396. * The caller continues to own this object (plugin may not delete it), and
  397. * plugins should expect it to be optionally NULL.
  398. *
  399. * @throw IO_ERROR if there is a problem saving.
  400. */
  401. virtual void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
  402. const PROPERTIES* aProperties = NULL );
  403. /**
  404. * Function FootprintDelete
  405. * deletes @a aFootprintName from the library at @a aLibraryPath.
  406. *
  407. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  408. * or URL containing several footprints.
  409. *
  410. * @param aFootprintName is the name of a footprint to delete from the specified library.
  411. *
  412. * @param aProperties is an associative array that can be used to tell the
  413. * library delete function anything special, because it can take any number of
  414. * additional named tuning arguments that the plugin is known to support.
  415. * The caller continues to own this object (plugin may not delete it), and
  416. * plugins should expect it to be optionally NULL.
  417. *
  418. * @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
  419. */
  420. virtual void FootprintDelete( const wxString& aLibraryPath,
  421. const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
  422. /**
  423. * Function FootprintLibCreate
  424. * creates a new empty footprint library at @a aLibraryPath empty. It is an
  425. * error to attempt to create an existing library or to attempt to create
  426. * on a "read only" location.
  427. *
  428. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  429. * or URL containing several footprints.
  430. *
  431. * @param aProperties is an associative array that can be used to tell the
  432. * library create function anything special, because it can take any number of
  433. * additional named tuning arguments that the plugin is known to support.
  434. * The caller continues to own this object (plugin may not delete it), and
  435. * plugins should expect it to be optionally NULL.
  436. *
  437. * @throw IO_ERROR if there is a problem finding the library, or creating it.
  438. */
  439. virtual void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
  440. /**
  441. * Function FootprintLibDelete
  442. * deletes an existing footprint library and returns true, or if library does not
  443. * exist returns false, or throws an exception if library exists but is read only or
  444. * cannot be deleted for some other reason.
  445. *
  446. * @param aLibraryPath is a locator for the "library", usually a directory
  447. * or file which will contain footprints.
  448. *
  449. * @param aProperties is an associative array that can be used to tell the
  450. * library delete implementation function anything special, because it can
  451. * take any number of additional named tuning arguments that the plugin is
  452. * known to support. The caller continues to own this object (plugin may
  453. * not delete it), and plugins should expect it to be optionally NULL.
  454. *
  455. * @return bool - true if library deleted, false if library did not exist.
  456. *
  457. * @throw IO_ERROR if there is a problem deleting an existing library.
  458. */
  459. virtual bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
  460. /**
  461. * Function IsFootprintLibWritable
  462. * returns true iff the library at @a aLibraryPath is writable. (Often
  463. * system libraries are read only because of where they are installed.)
  464. *
  465. * @param aLibraryPath is a locator for the "library", usually a directory, file,
  466. * or URL containing several footprints.
  467. *
  468. * @throw IO_ERROR if no library at aLibraryPath exists.
  469. */
  470. virtual bool IsFootprintLibWritable( const wxString& aLibraryPath );
  471. /**
  472. * Function FootprintLibOptions
  473. * appends supported PLUGIN options to @a aListToAppenTo along with
  474. * internationalized descriptions. Options are typically appended so
  475. * that a derived PLUGIN can call its base class
  476. * function by the same name first, thus inheriting options declared there.
  477. * (Some base class options could pertain to all Footprint*() functions
  478. * in all derived PLUGINs.) Note that since aListToAppendTo is a PROPERTIES
  479. * object, all options will be unique and last guy wins.
  480. *
  481. * @param aListToAppendTo holds a tuple of
  482. * <dl>
  483. <dt>option</dt>
  484. <dd>This eventually is what shows up into the fp-lib-table "options"
  485. field, possibly combined with others.</dd>
  486. <dt>internationalized description</dt>
  487. <dd>The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS.
  488. * It may be multi-line and be quite explanatory of the option.</dd>
  489. </dl>
  490. * <br>
  491. * In the future perhaps @a aListToAppendTo evolves to something capable of also
  492. * holding a wxValidator for the cells in said dialog:
  493. * http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180.
  494. This would require a 3 column list, and introducing wx GUI knowledge to
  495. PLUGIN, which has been avoided to date.
  496. */
  497. virtual void FootprintLibOptions( PROPERTIES* aListToAppendTo ) const;
  498. //-----</PUBLIC PLUGIN API>------------------------------------------------
  499. /* The compiler writes the "zero argument" constructor for a PLUGIN
  500. automatically if you do not provide one. If you decide you need to
  501. provide a zero argument constructor of your own design, that is allowed.
  502. It must be public, and it is what the IO_MGR uses. Parameters may be
  503. passed into a PLUGIN via the PROPERTIES variable for any of the public
  504. API functions which take one.
  505. */
  506. virtual ~PLUGIN()
  507. {
  508. //printf( "~%s", __func__ );
  509. };
  510. #ifndef SWIG
  511. /**
  512. * Class RELEASER
  513. * releases a PLUGIN in the context of a potential thrown exception, through
  514. * its destructor.
  515. */
  516. class RELEASER
  517. {
  518. PLUGIN* plugin;
  519. // private assignment operator so it's illegal
  520. RELEASER& operator=( RELEASER& aOther ) { return *this; }
  521. // private copy constructor so it's illegal
  522. RELEASER( const RELEASER& aOther ) {}
  523. public:
  524. RELEASER( PLUGIN* aPlugin = NULL ) :
  525. plugin( aPlugin )
  526. {
  527. }
  528. ~RELEASER()
  529. {
  530. if( plugin )
  531. release();
  532. }
  533. void release()
  534. {
  535. IO_MGR::PluginRelease( plugin );
  536. plugin = NULL;
  537. }
  538. void set( PLUGIN* aPlugin )
  539. {
  540. if( plugin )
  541. release();
  542. plugin = aPlugin;
  543. }
  544. operator PLUGIN* () const
  545. {
  546. return plugin;
  547. }
  548. PLUGIN* operator -> () const
  549. {
  550. return plugin;
  551. }
  552. };
  553. #endif
  554. };
  555. #endif // IO_MGR_H_