2012-06-09 17:00:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_PLUGIN_H_
|
|
|
|
#define KICAD_PLUGIN_H_
|
|
|
|
|
|
|
|
#include <io_mgr.h>
|
|
|
|
#include <string>
|
2013-03-30 17:24:04 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class BOARD_ITEM;
|
2012-10-07 15:37:25 +00:00
|
|
|
class FP_CACHE;
|
2012-10-24 18:20:33 +00:00
|
|
|
class PCB_PARSER;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
|
2012-11-10 06:39:18 +00:00
|
|
|
/// Current s-expression file format version. 2 was the last legacy format version.
|
|
|
|
#define SEXPR_BOARD_FILE_VERSION 3
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-11-10 06:39:18 +00:00
|
|
|
|
2013-06-24 05:30:22 +00:00
|
|
|
#define CTL_STD_LAYER_NAMES (1 << 0) ///< Use English Standard layer names
|
2012-11-10 06:39:18 +00:00
|
|
|
#define CTL_OMIT_NETS (1 << 1)
|
2012-11-14 07:15:59 +00:00
|
|
|
#define CTL_OMIT_TSTAMPS (1 << 2)
|
2013-06-24 05:30:22 +00:00
|
|
|
#define CTL_OMIT_INITIAL_COMMENTS (1 << 3) ///< omit MODULE initial comments
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
// common combinations of the above:
|
|
|
|
|
|
|
|
/// Format output for the clipboard instead of footprint library or BOARD
|
2013-03-20 04:46:32 +00:00
|
|
|
#define CTL_FOR_CLIPBOARD (CTL_STD_LAYER_NAMES|CTL_OMIT_NETS)
|
2012-11-14 07:15:59 +00:00
|
|
|
|
|
|
|
/// Format output for a footprint library instead of clipboard or BOARD
|
2013-03-20 04:46:32 +00:00
|
|
|
#define CTL_FOR_LIBRARY (CTL_STD_LAYER_NAMES|CTL_OMIT_NETS|CTL_OMIT_TSTAMPS)
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-06-24 05:30:22 +00:00
|
|
|
/// The zero arg constructor when PCB_IO is used for PLUGIN::Load() and PLUGIN::Save()ing
|
|
|
|
/// a BOARD file underneath IO_MGR.
|
|
|
|
#define CTL_FOR_BOARD (CTL_OMIT_INITIAL_COMMENTS)
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
/**
|
|
|
|
* Class PCB_IO
|
|
|
|
* is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
|
|
|
|
*
|
|
|
|
* @note This class is not thread safe, but it is re-entrant multiple times in sequence.
|
|
|
|
*/
|
|
|
|
class PCB_IO : public PLUGIN
|
|
|
|
{
|
2012-10-24 18:20:33 +00:00
|
|
|
friend class FP_CACHE;
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
//-----<PLUGIN API>---------------------------------------------------------
|
|
|
|
|
|
|
|
const wxString& PluginName() const
|
|
|
|
{
|
|
|
|
static const wxString name = wxT( "KiCad" );
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetFileExtension() const
|
|
|
|
{
|
2012-12-14 16:54:54 +00:00
|
|
|
// Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
|
|
|
|
// but to be pure, a plugin should not assume that it will always be linked
|
|
|
|
// with the core of the pcbnew code. (Might someday be a DLL/DSO.) Besides,
|
|
|
|
// file extension policy should be controlled by the plugin.
|
2012-06-09 17:00:13 +00:00
|
|
|
static const wxString extension = wxT( "kicad_pcb" );
|
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Save( const wxString& aFileName, BOARD* aBoard,
|
|
|
|
PROPERTIES* aProperties = NULL ); // overload
|
|
|
|
|
|
|
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL );
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
wxArrayString FootprintEnumerate( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL);
|
|
|
|
|
|
|
|
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
|
|
|
PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
|
|
|
|
PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName );
|
|
|
|
|
|
|
|
void FootprintLibCreate( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL);
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
bool FootprintLibDelete( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
bool IsFootprintLibWritable( const wxString& aLibraryPath );
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
//-----</PLUGIN API>--------------------------------------------------------
|
|
|
|
|
|
|
|
PCB_IO();
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
PCB_IO( int aControlFlags );
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
~PCB_IO();
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
/**
|
|
|
|
* Function Format
|
|
|
|
* outputs \a aItem to \a aFormatter in s-expression format.
|
|
|
|
*
|
|
|
|
* @param aItem A pointer the an #BOARD_ITEM object to format.
|
|
|
|
* @param aNestLevel The indentation nest level.
|
|
|
|
* @throw IO_ERROR on write error.
|
|
|
|
*/
|
|
|
|
void Format( BOARD_ITEM* aItem, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
std::string GetStringOutput( bool doClear )
|
|
|
|
{
|
|
|
|
std::string ret = m_sf.GetString();
|
|
|
|
if( doClear )
|
|
|
|
m_sf.Clear();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
void SetOutputFormatter( OUTPUTFORMATTER* aFormatter ) { m_out = aFormatter; }
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
BOARD_ITEM* Parse( const wxString& aClipboardSourceInput )
|
2012-11-27 19:57:38 +00:00
|
|
|
throw( PARSE_ERROR, IO_ERROR );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
wxString m_error; ///< for throwing exceptions
|
|
|
|
BOARD* m_board; ///< which BOARD, no ownership here
|
|
|
|
PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
|
2012-10-07 15:37:25 +00:00
|
|
|
FP_CACHE* m_cache; ///< Footprint library cache.
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
LINE_READER* m_reader; ///< no ownership here.
|
|
|
|
wxString m_filename; ///< for saves only, name is in m_reader for loads
|
|
|
|
|
2012-12-18 13:54:44 +00:00
|
|
|
int m_loading_format_version; ///< which #SEXPR_BOARD_FILE_VERSION should be Load()ed?
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
STRING_FORMATTER m_sf;
|
|
|
|
OUTPUTFORMATTER* m_out; ///< output any Format()s to this, no ownership
|
|
|
|
int m_ctl;
|
2012-10-24 18:20:33 +00:00
|
|
|
PCB_PARSER* m_parser;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
void format( BOARD* aBoard, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( DIMENSION* aDimension, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( EDGE_MODULE* aModuleDrawing, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( DRAWSEGMENT* aSegment, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( PCB_TARGET* aTarget, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( MODULE* aModule, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( D_PAD* aPad, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( TEXTE_PCB* aText, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( TEXTE_MODULE* aText, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( TRACK* aTrack, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void format( ZONE_CONTAINER* aZone, int aNestLevel = 0 ) const
|
|
|
|
throw( IO_ERROR );
|
|
|
|
|
|
|
|
void formatLayer( const BOARD_ITEM* aItem ) const;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2013-03-30 17:24:04 +00:00
|
|
|
void formatLayers( LAYER_MSK aLayerMask, int aNestLevel = 0 ) const
|
2012-11-14 07:15:59 +00:00
|
|
|
throw( IO_ERROR );
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
/// we only cache one footprint library for now, this determines which one.
|
|
|
|
void cacheLib( const wxString& aLibraryPath );
|
|
|
|
|
|
|
|
void init( PROPERTIES* aProperties );
|
2012-06-09 17:00:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KICAD_PLUGIN_H_
|