2011-11-28 04:32:29 +00:00
|
|
|
#ifndef IO_MGR_H_
|
|
|
|
#define IO_MGR_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2011 Kicad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/hashmap.h>
|
|
|
|
#include <richio.h>
|
|
|
|
|
|
|
|
|
|
|
|
// http://docs.wxwidgets.org/trunk/classwx_hash_map.html
|
|
|
|
WX_DECLARE_STRING_HASH_MAP( wxString, PROPERTIES );
|
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class PLUGIN;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class IO_MGR
|
2011-11-30 07:43:46 +00:00
|
|
|
* is a factory which returns an instance of a PLUGIN.
|
2011-11-28 04:32:29 +00:00
|
|
|
*/
|
|
|
|
class IO_MGR
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enum PCB_FILE_T
|
|
|
|
* is a set of file types that the IO_MGR knows about, and for which there
|
|
|
|
* has been a plugin written.
|
|
|
|
*/
|
|
|
|
enum PCB_FILE_T
|
|
|
|
{
|
|
|
|
KICAD,
|
2011-12-02 16:28:00 +00:00
|
|
|
// add your type here.
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
// EAGLE,
|
|
|
|
// ALTIUM,
|
|
|
|
// etc.
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function PluginFind
|
|
|
|
* returns a PLUGIN which the caller can use to import, export, save, or load
|
|
|
|
* design documents. The returned PLUGIN, may be reference counted, so please
|
2011-11-30 07:43:46 +00:00
|
|
|
* call PluginRelease() when you are done using the returned PLUGIN. It may or
|
|
|
|
* may not be code running from a DLL/DSO.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @param aFileType is from PCB_FILE_T and tells which plugin to find.
|
|
|
|
*
|
|
|
|
* @return PLUGIN* - the plugin corresponding to aFileType or NULL if not found.
|
|
|
|
* Caller owns the returned object, and must call PluginRelease when done using it.
|
|
|
|
*/
|
|
|
|
static PLUGIN* PluginFind( PCB_FILE_T aFileType );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function PluginRelease
|
|
|
|
* releases a PLUGIN back to the system, and may cause it to be unloaded from memory.
|
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @param aPlugin is the one to be released, and which is no longer usable
|
|
|
|
* after calling this.
|
2011-11-28 04:32:29 +00:00
|
|
|
*/
|
|
|
|
static void PluginRelease( PLUGIN* aPlugin );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ShowType
|
|
|
|
* returns a brief name for a plugin, given aFileType enum.
|
|
|
|
*/
|
2011-12-02 21:56:47 +00:00
|
|
|
static const wxString ShowType( PCB_FILE_T aFileType );
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Load
|
2011-12-02 16:28:00 +00:00
|
|
|
* finds the requested PLUGIN and if found, calls the PLUGIN->Load(..) funtion
|
|
|
|
* on it using the arguments passed to this function. After the PLUGIN->Load()
|
|
|
|
* function returns, the PLUGIN is Released() as part of this call.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
2011-11-30 07:43:46 +00:00
|
|
|
* @param aFileType is the PCB_FILE_T of file to load.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @param aFileName is the name of the file to load.
|
|
|
|
*
|
|
|
|
* @param aAppendToMe is an existing BOARD to append to, use NULL if fresh
|
2011-11-30 07:43:46 +00:00
|
|
|
* board load is wanted.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @param aProperties is an associative array that allows the caller to
|
2011-11-30 07:43:46 +00:00
|
|
|
* pass additional tuning parameters to the PLUGIN.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @return BOARD* - caller owns it, never NULL because exception thrown if error.
|
|
|
|
*
|
2011-11-30 07:43:46 +00:00
|
|
|
* @throw IO_ERROR if the PLUGIN cannot be found, file cannot be found,
|
2011-11-28 04:32:29 +00:00
|
|
|
* or file cannot be loaded.
|
|
|
|
*/
|
|
|
|
static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName,
|
|
|
|
BOARD* aAppendToMe = NULL, PROPERTIES* aProperties = NULL );
|
|
|
|
|
2011-12-02 16:28:00 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
2011-12-02 16:57:44 +00:00
|
|
|
* will write either a full aBoard to a storage file in a format that this
|
2011-12-02 16:28:00 +00:00
|
|
|
* implementation knows about, or it can be used to write a portion of
|
|
|
|
* aBoard to a special kind of export file.
|
|
|
|
*
|
|
|
|
* @param aFileName is the name of a file to save to on disk.
|
|
|
|
* @param aBoard is the BOARD document (data tree) to save or export to disk.
|
|
|
|
*
|
2011-12-02 16:57:44 +00:00
|
|
|
* @param aBoard is the in memory document tree from which to extract information
|
|
|
|
* when writing to \a aFileName. The caller continues to own the BOARD, and
|
|
|
|
* the plugin should refrain from modifying the BOARD if possible.
|
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @param aProperties is an associative array that can be used to tell the
|
|
|
|
* saver how to save the file, because it can take any number of
|
|
|
|
* additional named tuning arguments that the plugin is known to support.
|
2011-12-02 16:57:44 +00:00
|
|
|
* The caller continues to own this object (plugin may not delete it), and
|
|
|
|
* plugins should expect it to be optionally NULL.
|
2011-12-02 16:28:00 +00:00
|
|
|
*
|
|
|
|
* @throw IO_ERROR if there is a problem saving or exporting.
|
|
|
|
*/
|
|
|
|
static void Save( PCB_FILE_T aFileType, const wxString& aFileName,
|
2011-12-02 16:57:44 +00:00
|
|
|
BOARD* aBoard, PROPERTIES* aProperties = NULL );
|
2011-11-28 04:32:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PLUGIN
|
|
|
|
* is a base class that BOARD loading and saving plugins should derive from.
|
|
|
|
* Implementations can provide either Load() or Save() functions, or both.
|
|
|
|
* PLUGINs throw exceptions, so it is best that you wrap your calls to these
|
2011-11-29 03:08:14 +00:00
|
|
|
* functions in a try catch block.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* try
|
|
|
|
* {
|
2011-12-02 16:28:00 +00:00
|
|
|
* IO_MGR::Load(...);
|
|
|
|
* or
|
|
|
|
* IO_MGR::Save(...);
|
2011-11-28 04:32:29 +00:00
|
|
|
* }
|
|
|
|
* catch( IO_ERROR ioe )
|
|
|
|
* {
|
|
|
|
* // grab text from ioe, show in error window.
|
|
|
|
* }
|
|
|
|
* </pre>
|
|
|
|
*/
|
|
|
|
class PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-12-02 16:28:00 +00:00
|
|
|
//-----<PUBLIC PLUGIN API>-------------------------------------------------
|
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
/**
|
|
|
|
* Function PluginName
|
|
|
|
* returns a brief hard coded name for this PLUGIN.
|
|
|
|
*/
|
|
|
|
virtual const wxString& PluginName() = 0;
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Load
|
2011-12-02 16:28:00 +00:00
|
|
|
* loads a board file, or a portion of one, from some input file format
|
|
|
|
* that this PLUGIN implementation knows about. This may be used to load an
|
|
|
|
* entire new BOARD, or to augment an existing one if \a aAppendToMe is not NULL.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @param aFileName is the name of the file to use as input and may be foreign in
|
2011-11-28 04:32:29 +00:00
|
|
|
* nature or native in nature.
|
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @param aAppendToMe is an existing BOARD to append to, but if NULL then
|
|
|
|
* this means "do not append, rather load anew".
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @param aProperties is an associative array that can be used to tell the
|
|
|
|
* loader how to load the file, because it can take any number of
|
2011-12-02 16:28:00 +00:00
|
|
|
* additional named arguments that the plugin is known to support. These are
|
|
|
|
* tuning parameters for the import or load. The caller continues to own
|
|
|
|
* this object (plugin may not delete it), and plugins should expect it to
|
|
|
|
* be optionally NULL.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @return BOARD* - the successfully loaded board, or the same one as aAppendToMe
|
|
|
|
* if aAppendToMe was not NULL, and caller owns it.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @throw IO_ERROR if there is a problem loading, and its contents should
|
2011-12-02 16:28:00 +00:00
|
|
|
* say what went wrong, using line number and character offsets of the
|
|
|
|
* input file if possible.
|
2011-11-28 04:32:29 +00:00
|
|
|
*/
|
2011-11-30 07:43:46 +00:00
|
|
|
virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
|
2011-11-28 04:32:29 +00:00
|
|
|
PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Save
|
2011-12-02 16:28:00 +00:00
|
|
|
* will write a full aBoard to a storage file in a format that this
|
|
|
|
* PLUGIN implementation knows about, or it can be used to write a portion of
|
2011-11-28 04:32:29 +00:00
|
|
|
* aBoard to a special kind of export file.
|
|
|
|
*
|
|
|
|
* @param aFileName is the name of a file to save to on disk.
|
2011-12-02 16:57:44 +00:00
|
|
|
*
|
|
|
|
* @param aBoard is the class BOARD in memory document tree from which to
|
|
|
|
* extract information when writing to \a aFileName. The caller continues to
|
|
|
|
* own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
|
|
|
* @param aProperties is an associative array that can be used to tell the
|
|
|
|
* saver how to save the file, because it can take any number of
|
2011-12-02 16:28:00 +00:00
|
|
|
* additional named tuning arguments that the plugin is known to support.
|
|
|
|
* The caller continues to own this object (plugin may not delete it),
|
|
|
|
* and plugins should expect it to be optionally NULL.
|
2011-11-28 04:32:29 +00:00
|
|
|
*
|
2011-12-02 16:28:00 +00:00
|
|
|
* @throw IO_ERROR if there is a problem saving or exporting.
|
2011-11-28 04:32:29 +00:00
|
|
|
*/
|
2011-12-02 16:57:44 +00:00
|
|
|
virtual void Save( const wxString& aFileName, BOARD* aBoard,
|
2011-11-28 04:32:29 +00:00
|
|
|
PROPERTIES* aProperties = NULL );
|
|
|
|
|
2011-12-02 16:28:00 +00:00
|
|
|
//-----</PUBLIC PLUGIN API>------------------------------------------------
|
++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()
2011-12-05 06:15:33 +00:00
|
|
|
|
2011-12-05 17:22:19 +00:00
|
|
|
/* The compiler writes the "zero argument" constructor for a PLUGIN
|
|
|
|
automatically if you do not provide one. If you decide you need to
|
|
|
|
provide a zero argument constructor of your own design, that is allowed,
|
|
|
|
but there can only be one constructor and it must be a "zero argument"
|
|
|
|
version. Normally you can do your initialization in a function like
|
|
|
|
KICAD_PLUGIN::init( PROPERTIES* aProperties ) instead.
|
|
|
|
*/
|
|
|
|
|
++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()
2011-12-05 06:15:33 +00:00
|
|
|
virtual ~PLUGIN() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RELEASER
|
|
|
|
* releases a PLUGIN in the context of a potential thrown exception, through
|
|
|
|
* its destructor.
|
|
|
|
*/
|
|
|
|
class RELEASER
|
|
|
|
{
|
|
|
|
PLUGIN* plugin;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RELEASER( PLUGIN* aPlugin = NULL ) :
|
|
|
|
plugin( aPlugin )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~RELEASER()
|
|
|
|
{
|
|
|
|
if( plugin )
|
|
|
|
IO_MGR::PluginRelease( plugin );
|
|
|
|
}
|
|
|
|
|
|
|
|
operator PLUGIN* ()
|
|
|
|
{
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN* operator -> ()
|
|
|
|
{
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
};
|
2011-12-02 16:28:00 +00:00
|
|
|
};
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
|
2011-12-02 16:28:00 +00:00
|
|
|
#if 0
|
2011-11-28 04:32:29 +00:00
|
|
|
//-----<SCHEMATIC STUFF>------------------------------------------------
|
2011-12-02 16:28:00 +00:00
|
|
|
// Should split into schematic specific PLUGIN base type
|
2011-11-28 04:32:29 +00:00
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
class SCHEMATIC;
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
/**
|
|
|
|
* Function Load
|
|
|
|
* loads a file from some special input file format that
|
|
|
|
* only this implementation knows about.
|
|
|
|
* @param aFileName is the name of the file to load and may be foreign in nature or native in nature.
|
|
|
|
* @param aAppendToMe is an existing SCHEMATIC to append to but may be NULL.
|
|
|
|
*/
|
|
|
|
virtual SCHEMATIC* Load( const wxString& aFileName, SCHEMATIC* aAppendToMe,
|
|
|
|
PROPERTIES* aProperties = NULL )
|
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement
|
|
|
|
// Load() or Save() but not both.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Save
|
2011-12-02 16:28:00 +00:00
|
|
|
* will write aSchematic to a storage file in a format that only this
|
2011-11-28 04:32:29 +00:00
|
|
|
* implementation knows about.
|
|
|
|
*
|
|
|
|
* @param aFileName is the name of a file to save to on disk.
|
|
|
|
*
|
|
|
|
* @param aBoard is the SCHEMATIC document (ram data tree) to save or export to disk.
|
|
|
|
*/
|
|
|
|
virtual void Save( const wxString* aFileName, SCHEMATIC* aSchematic,
|
|
|
|
PROPERTIES* aProperties = NULL )
|
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement
|
|
|
|
// Load() or Save() but not both.
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----</SCHEMATIC STUFF>----------------------------------------------
|
|
|
|
#endif
|
2011-12-02 16:28:00 +00:00
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
#endif // IO_MGR_H_
|