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.

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