KiCad PCB EDA Suite
PCB_IO Class Reference

Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files. More...

#include <kicad_plugin.h>

Inheritance diagram for PCB_IO:
PLUGIN GITHUB_PLUGIN

Public Member Functions

const wxString PluginName () const override
 Function PluginName returns a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL) override
 Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
 Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
MODULEFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. More...
 
void FootprintSave (const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL) override
 Function FootprintSave will write aModule to an existing library located at aLibraryPath. More...
 
void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. More...
 
void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
 PCB_IO (int aControlFlags=CTL_FOR_BOARD)
 
 ~PCB_IO ()
 
void Format (BOARD_ITEM *aItem, int aNestLevel=0) const
 Function Format outputs aItem to aFormatter in s-expression format. More...
 
std::string GetStringOutput (bool doClear)
 
void SetOutputFormatter (OUTPUTFORMATTER *aFormatter)
 
BOARD_ITEMParse (const wxString &aClipboardSourceInput)
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Protected Member Functions

void cacheLib (const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
 we only cache one footprint library, this determines which one. More...
 
void init (const PROPERTIES *aProperties)
 

Protected Attributes

wxString m_error
 for throwing exceptions More...
 
BOARDm_board
 which BOARD, no ownership here More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
FP_CACHEm_cache
 Footprint library cache. More...
 
LINE_READERm_reader
 no ownership here. More...
 
wxString m_filename
 for saves only, name is in m_reader for loads More...
 
int m_loading_format_version
 which SEXPR_BOARD_FILE_VERSION should be Load()ed? More...
 
STRING_FORMATTER m_sf
 
OUTPUTFORMATTERm_out
 output any Format()s to this, no ownership More...
 
int m_ctl
 
PCB_PARSERm_parser
 
NETINFO_MAPPINGm_mapping
 mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes More...
 

Private Member Functions

void format (BOARD *aBoard, int aNestLevel=0) const
 
void format (DIMENSION *aDimension, int aNestLevel=0) const
 
void format (EDGE_MODULE *aModuleDrawing, int aNestLevel=0) const
 
void format (DRAWSEGMENT *aSegment, int aNestLevel=0) const
 
void format (PCB_TARGET *aTarget, int aNestLevel=0) const
 
void format (MODULE *aModule, int aNestLevel=0) const
 
void format (D_PAD *aPad, int aNestLevel=0) const
 
void format (TEXTE_PCB *aText, int aNestLevel=0) const
 
void format (TEXTE_MODULE *aText, int aNestLevel=0) const
 
void format (TRACK *aTrack, int aNestLevel=0) const
 
void format (ZONE_CONTAINER *aZone, int aNestLevel=0) const
 
void formatLayer (const BOARD_ITEM *aItem) const
 
void formatLayers (LSET aLayerMask, int aNestLevel=0) const
 

Friends

class FP_CACHE
 

Detailed Description

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.

Definition at line 89 of file pcbnew/kicad_plugin.h.

Constructor & Destructor Documentation

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 1838 of file kicad_plugin.cpp.

References init(), m_out, and m_sf.

1838  :
1839  m_cache( 0 ),
1840  m_ctl( aControlFlags ),
1841  m_parser( new PCB_PARSER() ),
1842  m_mapping( new NETINFO_MAPPING() )
1843 {
1844  init( 0 );
1845  m_out = &m_sf;
1846 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
FP_CACHE * m_cache
Footprint library cache.
Class PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate...
Definition: pcb_parser.h:66
void init(const PROPERTIES *aProperties)
PCB_PARSER * m_parser
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
STRING_FORMATTER m_sf
PCB_IO::~PCB_IO ( )

Definition at line 1849 of file kicad_plugin.cpp.

References m_cache, m_mapping, and m_parser.

1850 {
1851  delete m_cache;
1852  delete m_parser;
1853  delete m_mapping;
1854 }
FP_CACHE * m_cache
Footprint library cache.
PCB_PARSER * m_parser
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...

Member Function Documentation

void PCB_IO::cacheLib ( const wxString &  aLibraryPath,
const wxString &  aFootprintName = wxEmptyString 
)
protected

we only cache one footprint library, this determines which one.

Definition at line 1910 of file kicad_plugin.cpp.

References FP_CACHE, FP_CACHE::IsModified(), FP_CACHE::Load(), and m_cache.

Referenced by FootprintDelete(), FootprintEnumerate(), FootprintLoad(), FootprintSave(), and IsFootprintLibWritable().

1911 {
1912  if( !m_cache || m_cache->IsModified( aLibraryPath, aFootprintName ) )
1913  {
1914  // a spectacular episode in memory management:
1915  delete m_cache;
1916  m_cache = new FP_CACHE( this, aLibraryPath );
1917  m_cache->Load();
1918  }
1919 }
friend class FP_CACHE
FP_CACHE * m_cache
Footprint library cache.
bool IsModified(const wxString &aLibPath, const wxString &aFootprintName=wxEmptyString) const
Function IsModified check if the footprint cache has been modified relative to aLibPath and aFootprin...
void Load()
void PCB_IO::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of a footprint to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of 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.
Exceptions
IO_ERRORif there is a problem finding the footprint or the library, or deleting it.

Reimplemented from PLUGIN.

Definition at line 2057 of file kicad_plugin.cpp.

References cacheLib(), Format(), init(), FP_CACHE::IsWritable(), m_cache, FP_CACHE::Remove(), and THROW_IO_ERROR.

Referenced by GITHUB_PLUGIN::FootprintDelete().

2058 {
2059  LOCALE_IO toggle; // toggles on, then off, the C locale.
2060 
2061  init( aProperties );
2062 
2063  cacheLib( aLibraryPath );
2064 
2065  if( !m_cache->IsWritable() )
2066  {
2067  THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ),
2068  aLibraryPath.GetData() ) );
2069  }
2070 
2071  m_cache->Remove( aFootprintName );
2072 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
bool IsWritable() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
void PCB_IO::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Return a list of footprint names contained within the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
aFootprintNamesis the array of available footprint names inside a library.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 1922 of file kicad_plugin.cpp.

References cacheLib(), Format(), GetChars(), FP_CACHE::GetModules(), init(), m_cache, THROW_IO_ERROR, and IO_ERROR::What().

Referenced by GITHUB_PLUGIN::FootprintDelete(), and GITHUB_PLUGIN::FootprintEnumerate().

1925 {
1926  LOCALE_IO toggle; // toggles on, then off, the C locale.
1927  wxDir dir( aLibraryPath );
1928 
1929  if( !dir.IsOpened() )
1930  {
1931  THROW_IO_ERROR( wxString::Format( _( "footprint library path '%s' does not exist" ),
1932  GetChars( aLibraryPath ) ) );
1933  }
1934 
1935  init( aProperties );
1936 
1937  wxString errorMsg;
1938 
1939  // Some of the files may have been parsed correctly so we want to add the valid files to
1940  // the library.
1941  try
1942  {
1943  cacheLib( aLibraryPath );
1944  }
1945  catch( const IO_ERROR& ioe )
1946  {
1947  errorMsg = ioe.What();
1948  }
1949 
1950  const MODULE_MAP& mods = m_cache->GetModules();
1951 
1952  for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
1953  {
1954  aFootprintNames.Add( it->first );
1955  }
1956 
1957  if( !errorMsg.IsEmpty() )
1958  THROW_IO_ERROR( errorMsg );
1959 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
std::map< std::string, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULE_MAP::const_iterator MODULE_CITER
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
MODULE_MAP & GetModules()
void PCB_IO::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of 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.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented from PLUGIN.

Definition at line 2075 of file kicad_plugin.cpp.

References Format(), FP_CACHE, init(), m_cache, FP_CACHE::Save(), and THROW_IO_ERROR.

Referenced by GITHUB_PLUGIN::FootprintLibCreate().

2076 {
2077  if( wxDir::Exists( aLibraryPath ) )
2078  {
2079  THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path '%s'" ),
2080  aLibraryPath.GetData() ) );
2081  }
2082 
2083  LOCALE_IO toggle;
2084 
2085  init( aProperties );
2086 
2087  delete m_cache;
2088  m_cache = new FP_CACHE( this, aLibraryPath );
2089  m_cache->Save();
2090 }
friend class FP_CACHE
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Save()
save the entire legacy library to m_lib_name;
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
bool PCB_IO::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain footprints.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of 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.
Returns
bool - true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented from PLUGIN.

Definition at line 2093 of file kicad_plugin.cpp.

References Format(), FP_CACHE::IsPath(), KiCadFootprintFileExtension, m_cache, THROW_IO_ERROR, and traceFootprintLibrary.

Referenced by GITHUB_PLUGIN::FootprintLibDelete().

2094 {
2095  wxFileName fn;
2096  fn.SetPath( aLibraryPath );
2097 
2098  // Return if there is no library path to delete.
2099  if( !fn.DirExists() )
2100  return false;
2101 
2102  if( !fn.IsDirWritable() )
2103  {
2104  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory '%s'" ),
2105  aLibraryPath.GetData() ) );
2106  }
2107 
2108  wxDir dir( aLibraryPath );
2109 
2110  if( dir.HasSubDirs() )
2111  {
2112  THROW_IO_ERROR( wxString::Format( _( "library directory '%s' has unexpected sub-directories" ),
2113  aLibraryPath.GetData() ) );
2114  }
2115 
2116  // All the footprint files must be deleted before the directory can be deleted.
2117  if( dir.HasFiles() )
2118  {
2119  unsigned i;
2120  wxFileName tmp;
2121  wxArrayString files;
2122 
2123  wxDir::GetAllFiles( aLibraryPath, &files );
2124 
2125  for( i = 0; i < files.GetCount(); i++ )
2126  {
2127  tmp = files[i];
2128 
2129  if( tmp.GetExt() != KiCadFootprintFileExtension )
2130  {
2131  THROW_IO_ERROR( wxString::Format( _( "unexpected file '%s' was found in library path '%s'" ),
2132  files[i].GetData(), aLibraryPath.GetData() ) );
2133  }
2134  }
2135 
2136  for( i = 0; i < files.GetCount(); i++ )
2137  {
2138  wxRemoveFile( files[i] );
2139  }
2140  }
2141 
2142  wxLogTrace( traceFootprintLibrary, wxT( "Removing footprint library '%s'" ),
2143  aLibraryPath.GetData() );
2144 
2145  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2146  // we don't want that. we want bare metal portability with no UI here.
2147  if( !wxRmdir( aLibraryPath ) )
2148  {
2149  THROW_IO_ERROR( wxString::Format( _( "footprint library '%s' cannot be deleted" ),
2150  aLibraryPath.GetData() ) );
2151  }
2152 
2153  // For some reason removing a directory in Windows is not immediately updated. This delay
2154  // prevents an error when attempting to immediately recreate the same directory when over
2155  // writing an existing library.
2156 #ifdef __WINDOWS__
2157  wxMilliSleep( 250L );
2158 #endif
2159 
2160  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2161  {
2162  delete m_cache;
2163  m_cache = NULL;
2164  }
2165 
2166  return true;
2167 }
const wxString KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static const wxString traceFootprintLibrary
Flag to enable KiCad PCB plugin debug output.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Footprint*() functions in all derived PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to PLUGIN, which has been avoided to date.

Reimplemented in GITHUB_PLUGIN, and EAGLE_PLUGIN.

Definition at line 122 of file plugin.cpp.

Referenced by DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), EAGLE_PLUGIN::FootprintLibOptions(), and GITHUB_PLUGIN::FootprintLibOptions().

123 {
124  // disable all these in another couple of months, after everyone has seen them:
125 #if 1
126  (*aListToAppendTo)["debug_level"] = UTF8( _(
127  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
128  ));
129 
130  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
131  "Regular expression <b>footprint name</b> filter."
132  ));
133 
134  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
135  "Enable transaction logging. The mere presence of this option turns on the "
136  "logging, no need to set a Value."
137  ));
138 
139  (*aListToAppendTo)["username"] = UTF8( _(
140  "User name for <b>login</b> to some special library server."
141  ));
142 
143  (*aListToAppendTo)["password"] = UTF8( _(
144  "Password for <b>login</b> to some special library server."
145  ));
146 #endif
147 
148 #if 1
149  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
150  // if and when implemented.
151  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
152  "Enter the python module which implements the PLUGIN::Footprint*() functions."
153  ));
154 #endif
155 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
MODULE * PCB_IO::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of the footprint to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of 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.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Reimplemented from PLUGIN.

Definition at line 1962 of file kicad_plugin.cpp.

References cacheLib(), FP_CACHE::GetModules(), init(), and m_cache.

Referenced by GITHUB_PLUGIN::FootprintLoad().

1964 {
1965  LOCALE_IO toggle; // toggles on, then off, the C locale.
1966 
1967  init( aProperties );
1968 
1969  cacheLib( aLibraryPath, aFootprintName );
1970 
1971  const MODULE_MAP& mods = m_cache->GetModules();
1972 
1973  MODULE_CITER it = mods.find( aFootprintName );
1974 
1975  if( it == mods.end() )
1976  {
1977  return NULL;
1978  }
1979 
1980  // copy constructor to clone the already loaded MODULE
1981  return new MODULE( *it->second->GetModule() );
1982 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
std::map< std::string, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
MODULE_MAP::const_iterator MODULE_CITER
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
MODULE_MAP & GetModules()
void PCB_IO::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintSave will write aModule to an existing library located at aLibraryPath.

If a footprint by the same name already exists, it is replaced.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aPropertiesis an associative array that can be used to tell the saver how to save the footprint, because it can take any number of 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.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented from PLUGIN.

Definition at line 1985 of file kicad_plugin.cpp.

References cacheLib(), CTL_FOR_LIBRARY, F_Cu, MODULE::Flip(), Format(), GetChars(), MODULE::GetFPID(), BOARD_ITEM::GetLayer(), LIB_ID::GetLibItemName(), FP_CACHE::GetModules(), MODULE::GetPosition(), init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, m_cache, m_ctl, FP_CACHE::Save(), MODULE::SetOrientation(), EDA_ITEM::SetParent(), EDA_ITEM::SetTimeStamp(), THROW_IO_ERROR, and traceFootprintLibrary.

Referenced by GITHUB_PLUGIN::FootprintSave().

1987 {
1988  LOCALE_IO toggle; // toggles on, then off, the C locale.
1989 
1990  init( aProperties );
1991 
1992  // In this public PLUGIN API function, we can safely assume it was
1993  // called for saving into a library path.
1995 
1996  cacheLib( aLibraryPath );
1997 
1998  if( !m_cache->IsWritable() )
1999  {
2000  wxString msg = wxString::Format(
2001  _( "Library '%s' is read only" ),
2002  GetChars( aLibraryPath )
2003  );
2004 
2005  THROW_IO_ERROR( msg );
2006  }
2007 
2008  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2009 
2010  MODULE_MAP& mods = m_cache->GetModules();
2011 
2012  // Quietly overwrite module and delete module file from path for any by same name.
2013  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2015 
2016  if( !fn.IsOk() )
2017  {
2018  THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
2019  GetChars( fn.GetFullPath() ) ) );
2020  }
2021 
2022  if( fn.FileExists() && !fn.IsFileWritable() )
2023  {
2024  THROW_IO_ERROR( wxString::Format( _( "user does not have write permission to delete file '%s' " ),
2025  GetChars( fn.GetFullPath() ) ) );
2026  }
2027 
2028  MODULE_CITER it = mods.find( footprintName );
2029 
2030  if( it != mods.end() )
2031  {
2032  wxLogTrace( traceFootprintLibrary, wxT( "Removing footprint library file '%s'." ),
2033  fn.GetFullPath().GetData() );
2034  mods.erase( footprintName );
2035  wxRemoveFile( fn.GetFullPath() );
2036  }
2037 
2038  // I need my own copy for the cache
2039  MODULE* module = new MODULE( *aFootprint );
2040 
2041  // and it's time stamp must be 0, it should have no parent, orientation should
2042  // be zero, and it should be on the front layer.
2043  module->SetTimeStamp( 0 );
2044  module->SetParent( 0 );
2045  module->SetOrientation( 0 );
2046 
2047  if( module->GetLayer() != F_Cu )
2048  module->Flip( module->GetPosition() );
2049 
2050  wxLogTrace( traceFootprintLibrary, wxT( "Creating s-expression footprint file: %s." ),
2051  fn.GetFullPath().GetData() );
2052  mods.insert( footprintName, new FP_CACHE_ITEM( module, fn ) );
2053  m_cache->Save();
2054 }
const wxString KiCadFootprintFileExtension
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
void init(const PROPERTIES *aProperties)
const wxPoint & GetPosition() const override
Definition: class_module.h:155
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
const LIB_ID & GetFPID() const
Definition: class_module.h:164
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
std::map< std::string, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
Class FP_CACHE_ITEM is helper class for creating a footprint library cache.
bool IsWritable() const
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
MODULE_MAP::const_iterator MODULE_CITER
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
void Save()
save the entire legacy library to m_lib_name;
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static const wxString traceFootprintLibrary
Flag to enable KiCad PCB plugin debug output.
void SetOrientation(double newangle)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
MODULE_MAP & GetModules()
void PCB_IO::Format ( BOARD_ITEM aItem,
int  aNestLevel = 0 
) const

Function Format outputs aItem to aFormatter in s-expression format.

Parameters
aItemA pointer the an BOARD_ITEM object to format.
aNestLevelThe indentation nest level.
Exceptions
IO_ERRORon write error.

Definition at line 460 of file kicad_plugin.cpp.

References format(), EDA_ITEM::GetClass(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by MODULE_EDITOR_TOOLS::CopyItems(), FOOTPRINT_EDIT_FRAME::Export_Module(), format(), FOOTPRINT_EDIT_FRAME::retainLastFootprint(), Save(), and FP_CACHE::Save().

461 {
462  LOCALE_IO toggle; // public API function, perform anything convenient for caller
463 
464  switch( aItem->Type() )
465  {
466  case PCB_T:
467  format( static_cast<BOARD*>( aItem ), aNestLevel );
468  break;
469 
470  case PCB_DIMENSION_T:
471  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
472  break;
473 
474  case PCB_LINE_T:
475  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
476  break;
477 
478  case PCB_MODULE_EDGE_T:
479  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
480  break;
481 
482  case PCB_TARGET_T:
483  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
484  break;
485 
486  case PCB_MODULE_T:
487  format( static_cast<MODULE*>( aItem ), aNestLevel );
488  break;
489 
490  case PCB_PAD_T:
491  format( static_cast<D_PAD*>( aItem ), aNestLevel );
492  break;
493 
494  case PCB_TEXT_T:
495  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
496  break;
497 
498  case PCB_MODULE_TEXT_T:
499  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
500  break;
501 
502  case PCB_TRACE_T:
503  case PCB_VIA_T:
504  format( static_cast<TRACK*>( aItem ), aNestLevel );
505  break;
506 
507  case PCB_ZONE_AREA_T:
508  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
509  break;
510 
511  default:
512  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
513  }
514 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
Definition: typeinfo.h:97
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
class MODULE, a footprint
Definition: typeinfo.h:101
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
void PCB_IO::format ( BOARD aBoard,
int  aNestLevel = 0 
) const
private
Todo:
Add warning here that the old segment filed zones are no longer supported and will not be saved.

Definition at line 531 of file kicad_plugin.cpp.

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, NETCLASSES::begin(), NETINFO_MAPPING::begin(), Cmts_User, cu, LSET::CuStack(), DIM, Double2Str(), BOARD::Drawings(), Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, NETCLASSES::end(), NETINFO_MAPPING::end(), F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, filterNetClass(), FMTIU, TITLE_BLOCK::Format(), Format(), PCB_PLOT_PARAMS::Format(), PAGE_INFO::Format(), NETCLASS::Format(), BOARD::GetArea(), BOARD::GetAreaCount(), BOARD::GetAuxOrigin(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), DHEAD::GetCount(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), D_PAD::GetDrillSize(), BOARD::GetEnabledLayers(), BOARD::GetGridOrigin(), BOARD::GetLayerName(), BOARD::GetLayerType(), BOARD::GetNumSegmTrack(), BOARD::GetNumSegmZone(), BOARD::GetPageSettings(), BOARD::GetPlotOptions(), D_PAD::GetSize(), NETINFO_MAPPING::GetSize(), BOARD::GetTitleBlock(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), BOARD::GetVisibleLayers(), BOARD::GetZoneSettings(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, m_ctl, BOARD_DESIGN_SETTINGS::m_DrawSegmentWidth, BOARD_DESIGN_SETTINGS::m_EdgeSegmentWidth, m_mapping, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD::m_Modules, BOARD_DESIGN_SETTINGS::m_ModuleSegmentWidth, BOARD_DESIGN_SETTINGS::m_ModuleTextSize, BOARD_DESIGN_SETTINGS::m_ModuleTextWidth, BOARD_DESIGN_SETTINGS::m_NetClasses, m_out, BOARD_DESIGN_SETTINGS::m_Pad_Master, BOARD_DESIGN_SETTINGS::m_PcbTextSize, BOARD_DESIGN_SETTINGS::m_PcbTextWidth, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, BOARD::m_Track, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, ZONE_SETTINGS::m_Zone_45_Only, ZONE_SETTINGS::m_ZoneClearance, Margin, TRACK::Next(), MODULE::Next(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), LAYER::ShowType(), NETINFO_MAPPING::Translate(), wxPoint::x, and wxPoint::y.

Referenced by Format(), and format().

532 {
533  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
534 
535  m_out->Print( 0, "\n" );
536 
537  m_out->Print( aNestLevel, "(general\n" );
538 
539  // Write Bounding box info
540  m_out->Print( aNestLevel+1, "(thickness %s)\n",
541  FMTIU( dsnSettings.GetBoardThickness() ).c_str() );
542 
543  m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->Drawings().Size() );
544  m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
545  m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
546  m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
547  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
548  m_out->Print( aNestLevel, ")\n\n" );
549 
550  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
551  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
552 
553  // Layers.
554  m_out->Print( aNestLevel, "(layers\n" );
555 
556  // Save only the used copper layers from front to back.
557  LSET visible_layers = aBoard->GetVisibleLayers();
558 
559  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
560  {
561  PCB_LAYER_ID layer = *cu;
562 
563  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
564  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
565  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
566 
567  if( !visible_layers[layer] )
568  m_out->Print( 0, " hide" );
569 
570  m_out->Print( 0, ")\n" );
571  }
572 
573  // Save used non-copper layers in the order they are defined.
574  // desired sequence for non Cu BOARD layers.
575  static const PCB_LAYER_ID non_cu[] = {
576  B_Adhes, // 32
577  F_Adhes,
578  B_Paste,
579  F_Paste,
580  B_SilkS,
581  F_SilkS,
582  B_Mask,
583  F_Mask,
584  Dwgs_User,
585  Cmts_User,
586  Eco1_User,
587  Eco2_User,
588  Edge_Cuts,
589  Margin,
590  B_CrtYd,
591  F_CrtYd,
592  B_Fab,
593  F_Fab
594  };
595 
596  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) ); seq; ++seq )
597  {
598  PCB_LAYER_ID layer = *seq;
599 
600  m_out->Print( aNestLevel+1, "(%d %s user", layer,
601  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
602 
603  if( !visible_layers[layer] )
604  m_out->Print( 0, " hide" );
605 
606  m_out->Print( 0, ")\n" );
607  }
608 
609  m_out->Print( aNestLevel, ")\n\n" );
610 
611  // Setup
612  m_out->Print( aNestLevel, "(setup\n" );
613 
614  // Save current default track width, for compatibility with older Pcbnew version;
615  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
616  FMTIU( dsnSettings.GetCurrentTrackWidth() ).c_str() );
617 
618  // Save custom tracks width list (the first is not saved here: this is the netclass value
619  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
620  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
621  FMTIU( dsnSettings.m_TrackWidthList[ii] ).c_str() );
622 
623  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
624  FMTIU( dsnSettings.GetDefault()->GetClearance() ).c_str() );
625 
626  // ZONE_SETTINGS
627  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
628  FMTIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
629  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
630  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
631 
632  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
633  FMTIU( dsnSettings.m_TrackMinWidth ).c_str() );
634 
635  m_out->Print( aNestLevel+1, "(segment_width %s)\n",
636  FMTIU( dsnSettings.m_DrawSegmentWidth ).c_str() );
637  m_out->Print( aNestLevel+1, "(edge_width %s)\n",
638  FMTIU( dsnSettings.m_EdgeSegmentWidth ).c_str() );
639 
640  // Save current default via size, for compatibility with older Pcbnew version;
641  m_out->Print( aNestLevel+1, "(via_size %s)\n",
642  FMTIU( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
643  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
644  FMTIU( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
645  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
646  FMTIU( dsnSettings.m_ViasMinSize ).c_str() );
647  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
648  FMTIU( dsnSettings.m_ViasMinDrill ).c_str() );
649 
650  // Save custom vias diameters list (the first is not saved here: this is
651  // the netclass value
652  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
653  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
654  FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
655  FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
656 
657  // for old versions compatibility:
658  if( dsnSettings.m_BlindBuriedViaAllowed )
659  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
660 
661  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
662  FMTIU( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
663  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
664  FMTIU( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
665  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
666  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
667  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
668  FMTIU( dsnSettings.m_MicroViasMinSize ).c_str() );
669  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
670  FMTIU( dsnSettings.m_MicroViasMinDrill ).c_str() );
671 
672  m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
673  FMTIU( dsnSettings.m_PcbTextWidth ).c_str() );
674  m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
675  FMTIU( dsnSettings.m_PcbTextSize.x ).c_str(),
676  FMTIU( dsnSettings.m_PcbTextSize.y ).c_str() );
677 
678  m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
679  FMTIU( dsnSettings.m_ModuleSegmentWidth ).c_str() );
680  m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
681  FMTIU( dsnSettings.m_ModuleTextSize.x ).c_str(),
682  FMTIU( dsnSettings.m_ModuleTextSize.y ).c_str() );
683  m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
684  FMTIU( dsnSettings.m_ModuleTextWidth ).c_str() );
685 
686  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
687  FMTIU( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
688  FMTIU( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
689  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
690  FMTIU( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
691 
692  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
693  FMTIU( dsnSettings.m_SolderMaskMargin ).c_str() );
694 
695  if( dsnSettings.m_SolderMaskMinWidth )
696  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
697  FMTIU( dsnSettings.m_SolderMaskMinWidth ).c_str() );
698 
699  if( dsnSettings.m_SolderPasteMargin != 0 )
700  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
701  FMTIU( dsnSettings.m_SolderPasteMargin ).c_str() );
702 
703  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
704  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
705  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
706 
707  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
708  FMTIU( aBoard->GetAuxOrigin().x ).c_str(),
709  FMTIU( aBoard->GetAuxOrigin().y ).c_str() );
710 
711  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
712  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
713  FMTIU( aBoard->GetGridOrigin().x ).c_str(),
714  FMTIU( aBoard->GetGridOrigin().y ).c_str() );
715 
716  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
717  dsnSettings.GetVisibleElements() );
718 
719  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
720 
721  m_out->Print( aNestLevel, ")\n\n" );
722 
723  // Save net codes and names
724  for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
725  net != netEnd; ++net )
726  {
727  m_out->Print( aNestLevel, "(net %d %s)\n",
728  m_mapping->Translate( net->GetNet() ),
729  m_out->Quotew( net->GetNetname() ).c_str() );
730  }
731 
732  m_out->Print( 0, "\n" );
733 
734  // Save the default net class first.
735  NETCLASS defaultNC = *dsnSettings.GetDefault();
736  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
737  defaultNC.Format( m_out, aNestLevel, m_ctl );
738 
739  // Save the rest of the net classes alphabetically.
740  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
741  it != dsnSettings.m_NetClasses.end();
742  ++it )
743  {
744  NETCLASS netclass = *it->second;
745  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
746  netclass.Format( m_out, aNestLevel, m_ctl );
747  }
748 
749  // Save the modules.
750  for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
751  {
752  Format( module, aNestLevel );
753  m_out->Print( 0, "\n" );
754  }
755 
756  // Save the graphical items on the board (not owned by a module)
757  for( auto item : aBoard->Drawings() )
758  Format( item, aNestLevel );
759 
760  if( aBoard->Drawings().Size() )
761  m_out->Print( 0, "\n" );
762 
763  // Do not save MARKER_PCBs, they can be regenerated easily.
764 
765  // Save the tracks and vias.
766  for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
767  Format( track, aNestLevel );
768 
769  if( aBoard->m_Track.GetCount() )
770  m_out->Print( 0, "\n" );
771 
774 
775  // Save the polygon (which are the newer technology) zones.
776  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
777  Format( aBoard->GetArea( i ), aNestLevel );
778 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_SolderMaskMargin
Solder mask margin.
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:556
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
NETCLASSPTR GetDefault() const
Function GetDefault.
const wxPoint & GetGridOrigin() const
Definition: class_board.h:350
int m_SolderPasteMargin
Solder paste margin absolute value.
int m_ModuleTextWidth
Default footprint texts thickness.
std::vector< int > m_TrackWidthList
Track width list.
int m_ModuleSegmentWidth
Default width for all graphic lines.
int m_PcbTextWidth
current Pcb (not module) Text width
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:147
MODULE * Next() const
Definition: class_module.h:100
iterator end()
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:60
const wxSize & GetDrillSize() const
Definition: class_pad.h:260
wxSize m_ModuleTextSize
Default footprint texts size.
#define cu(a)
Definition: auxiliary.h:88
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
NETCLASS_MAP::const_iterator const_iterator
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the net class to aFormatter in s-expression form.
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:337
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
iterator begin()
int GetSize() const
Function GetSize.
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
wxSize m_PcbTextSize
current Pcb (not module) Text size
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int m_DrawSegmentWidth
current graphic line width (not EDGE layer)
int m_ViasMinDrill
vias (not micro vias) min drill diameter
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:550
const wxSize & GetSize() const
Definition: class_pad.h:254
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
int m_ZoneClearance
Clearance value.
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:245
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
int m_MicroViasMinSize
micro vias (not vias) min diameter
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
int GetNumSegmTrack() const
Functions to get some items count.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:547
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:343
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
TRACK * Next() const
Definition: class_track.h:98
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:553
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
DLIST< MODULE > m_Modules
Definition: class_board.h:245
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
int GetNumSegmZone() const
Calculate the zone segment count.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
DLIST< TRACK > m_Track
Definition: class_board.h:246
void filterNetClass(const BOARD &aBoard, NETCLASS &aNetClass)
Removes empty nets (i.e. with node count equal zero) from net classes
bool m_MicroViasAllowed
true to allow micro vias
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
int m_EdgeSegmentWidth
current graphic line width (EDGE layer only)
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values...
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
#define FMTIU
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
int m_SolderMaskMinWidth
Solder mask min width.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::format ( DIMENSION aDimension,
int  aNestLevel = 0 
) const
private

Definition at line 781 of file kicad_plugin.cpp.

References FMT_IU, Format(), formatLayer(), EDA_ITEM::GetTimeStamp(), DIMENSION::GetValue(), DIMENSION::GetWidth(), DIMENSION::m_arrowD1F, DIMENSION::m_arrowD2F, DIMENSION::m_arrowG1F, DIMENSION::m_arrowG2F, DIMENSION::m_crossBarF, DIMENSION::m_crossBarO, DIMENSION::m_featureLineDF, DIMENSION::m_featureLineDO, DIMENSION::m_featureLineGF, DIMENSION::m_featureLineGO, m_out, OUTPUTFORMATTER::Print(), DIMENSION::Text(), wxPoint::x, and wxPoint::y.

782 {
783  m_out->Print( aNestLevel, "(dimension %s (width %s)",
784  FMT_IU( aDimension->GetValue() ).c_str(),
785  FMT_IU( aDimension->GetWidth() ).c_str() );
786 
787  formatLayer( aDimension );
788 
789  if( aDimension->GetTimeStamp() )
790  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aDimension->GetTimeStamp() );
791 
792  m_out->Print( 0, "\n" );
793 
794  Format( &aDimension->Text(), aNestLevel+1 );
795 
796  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
797  FMT_IU( aDimension->m_featureLineDO.x ).c_str(),
798  FMT_IU( aDimension->m_featureLineDO.y ).c_str(),
799  FMT_IU( aDimension->m_featureLineDF.x ).c_str(),
800  FMT_IU( aDimension->m_featureLineDF.y ).c_str() );
801 
802  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
803  FMT_IU( aDimension->m_featureLineGO.x ).c_str(),
804  FMT_IU( aDimension->m_featureLineGO.y ).c_str(),
805  FMT_IU( aDimension->m_featureLineGF.x ).c_str(),
806  FMT_IU( aDimension->m_featureLineGF.y ).c_str() );
807 
808  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
809  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
810  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
811  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
812  FMT_IU( aDimension->m_crossBarF.y ).c_str() );
813 
814  m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
815  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
816  FMT_IU( aDimension->m_crossBarF.y ).c_str(),
817  FMT_IU( aDimension->m_arrowD1F.x ).c_str(),
818  FMT_IU( aDimension->m_arrowD1F.y ).c_str() );
819 
820  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
821  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
822  FMT_IU( aDimension->m_crossBarF.y ).c_str(),
823  FMT_IU( aDimension->m_arrowD2F.x ).c_str(),
824  FMT_IU( aDimension->m_arrowD2F.y ).c_str() );
825 
826  m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
827  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
828  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
829  FMT_IU( aDimension->m_arrowG1F.x ).c_str(),
830  FMT_IU( aDimension->m_arrowG1F.y ).c_str() );
831 
832  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
833  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
834  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
835  FMT_IU( aDimension->m_arrowG2F.x ).c_str(),
836  FMT_IU( aDimension->m_arrowG2F.y ).c_str() );
837 
838  m_out->Print( aNestLevel, ")\n" );
839 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
wxPoint m_crossBarF
wxPoint m_arrowD1F
int GetWidth() const
void formatLayer(const BOARD_ITEM *aItem) const
wxPoint m_featureLineDF
wxPoint m_featureLineGO
wxPoint m_arrowG1F
wxPoint m_arrowD2F
wxPoint m_arrowG2F
#define FMT_IU
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
time_t GetTimeStamp() const
Definition: base_struct.h:218
TEXTE_PCB & Text()
wxPoint m_crossBarO
int GetValue() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxPoint m_featureLineDO
wxPoint m_featureLineGF
void PCB_IO::format ( EDGE_MODULE aModuleDrawing,
int  aNestLevel = 0 
) const
private

Definition at line 907 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, formatLayer(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetBezControl1(), DRAWSEGMENT::GetBezControl2(), EDGE_MODULE::GetEnd0(), DRAWSEGMENT::GetPolyPoints(), DRAWSEGMENT::GetShape(), EDGE_MODULE::GetStart0(), DRAWSEGMENT::GetWidth(), m_out, OUTPUTFORMATTER::Print(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

908 {
909  switch( aModuleDrawing->GetShape() )
910  {
911  case S_SEGMENT: // Line
912  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
913  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
914  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
915  break;
916 
917  case S_CIRCLE: // Circle
918  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
919  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
920  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
921  break;
922 
923  case S_ARC: // Arc
924  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
925  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
926  FMT_IU( aModuleDrawing->GetEnd0() ).c_str(),
927  FMT_ANGLE( aModuleDrawing->GetAngle() ).c_str() );
928  break;
929 
930  case S_POLYGON: // Polygon
931  m_out->Print( aNestLevel, "(fp_poly (pts" );
932 
933  for( unsigned i = 0; i < aModuleDrawing->GetPolyPoints().size(); ++i )
934  {
935  int nestLevel = 0;
936 
937  if( i && !(i%4) ) // newline every 4(pts)
938  {
939  nestLevel = aNestLevel + 1;
940  m_out->Print( 0, "\n" );
941  }
942 
943  m_out->Print( nestLevel, "%s(xy %s)",
944  nestLevel ? "" : " ",
945  FMT_IU( aModuleDrawing->GetPolyPoints()[i] ).c_str() );
946  }
947  m_out->Print( 0, ")" );
948  break;
949 
950  case S_CURVE: // Bezier curve
951  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
952  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
953  FMT_IU( aModuleDrawing->GetBezControl1() ).c_str(),
954  FMT_IU( aModuleDrawing->GetBezControl2() ).c_str(),
955  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
956  break;
957 
958  default:
959  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
960  };
961 
962  formatLayer( aModuleDrawing );
963 
964  m_out->Print( 0, " (width %s)", FMT_IU( aModuleDrawing->GetWidth() ).c_str() );
965 
966  m_out->Print( 0, ")\n" );
967 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetBezControl2() const
polygon (not yet used for tracks, but could be in microwave apps)
const wxPoint & GetEnd0() const
void formatLayer(const BOARD_ITEM *aItem) const
usual segment : line with rounded ends
const std::vector< wxPoint > & GetPolyPoints() const
STROKE_T GetShape() const
Arcs (with rounded ends)
#define FMT_IU
const wxPoint & GetBezControl1() const
Bezier Curve.
double GetAngle() const
const wxPoint & GetStart0() const
int GetWidth() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define FMT_ANGLE
void PCB_IO::format ( DRAWSEGMENT aSegment,
int  aNestLevel = 0 
) const
private

Definition at line 842 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, formatLayer(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetBezControl1(), DRAWSEGMENT::GetBezControl2(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetPolyPoints(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), DRAWSEGMENT::GetWidth(), m_out, OUTPUTFORMATTER::Print(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

843 {
844  unsigned i;
845 
846  switch( aSegment->GetShape() )
847  {
848  case S_SEGMENT: // Line
849  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
850  FMT_IU( aSegment->GetStart() ).c_str(),
851  FMT_IU( aSegment->GetEnd() ).c_str() );
852 
853  if( aSegment->GetAngle() != 0.0 )
854  m_out->Print( 0, " (angle %s)", FMT_ANGLE( aSegment->GetAngle() ).c_str() );
855 
856  break;
857 
858  case S_CIRCLE: // Circle
859  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
860  FMT_IU( aSegment->GetStart() ).c_str(),
861  FMT_IU( aSegment->GetEnd() ).c_str() );
862  break;
863 
864  case S_ARC: // Arc
865  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
866  FMT_IU( aSegment->GetStart() ).c_str(),
867  FMT_IU( aSegment->GetEnd() ).c_str(),
868  FMT_ANGLE( aSegment->GetAngle() ).c_str() );
869  break;
870 
871  case S_POLYGON: // Polygon
872  m_out->Print( aNestLevel, "(gr_poly (pts" );
873 
874  for( i = 0; i < aSegment->GetPolyPoints().size(); ++i )
875  m_out->Print( 0, " (xy %s)", FMT_IU( aSegment->GetPolyPoints()[i] ).c_str() );
876 
877  m_out->Print( 0, ")" );
878  break;
879 
880  case S_CURVE: // Bezier curve
881  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
882  FMT_IU( aSegment->GetStart() ).c_str(),
883  FMT_IU( aSegment->GetBezControl1() ).c_str(),
884  FMT_IU( aSegment->GetBezControl2() ).c_str(),
885  FMT_IU( aSegment->GetEnd() ).c_str() );
886  break;
887 
888  default:
889  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
890  };
891 
892  formatLayer( aSegment );
893 
894  if( aSegment->GetWidth() != 0 )
895  m_out->Print( 0, " (width %s)", FMT_IU( aSegment->GetWidth() ).c_str() );
896 
897  if( aSegment->GetTimeStamp() )
898  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aSegment->GetTimeStamp() );
899 
900  if( aSegment->GetStatus() )
901  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
902 
903  m_out->Print( 0, ")\n" );
904 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetBezControl2() const
polygon (not yet used for tracks, but could be in microwave apps)
void formatLayer(const BOARD_ITEM *aItem) const
usual segment : line with rounded ends
const std::vector< wxPoint > & GetPolyPoints() const
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:264
STROKE_T GetShape() const
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Arcs (with rounded ends)
#define FMT_IU
const wxPoint & GetBezControl1() const
Bezier Curve.
time_t GetTimeStamp() const
Definition: base_struct.h:218
double GetAngle() const
int GetWidth() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
#define FMT_ANGLE
void PCB_IO::format ( PCB_TARGET aTarget,
int  aNestLevel = 0 
) const
private

Definition at line 970 of file kicad_plugin.cpp.

References FMT_IU, formatLayer(), PCB_TARGET::GetPosition(), PCB_TARGET::GetShape(), PCB_TARGET::GetSize(), EDA_ITEM::GetTimeStamp(), PCB_TARGET::GetWidth(), m_out, and OUTPUTFORMATTER::Print().

971 {
972  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
973  ( aTarget->GetShape() ) ? "x" : "plus",
974  FMT_IU( aTarget->GetPosition() ).c_str(),
975  FMT_IU( aTarget->GetSize() ).c_str() );
976 
977  if( aTarget->GetWidth() != 0 )
978  m_out->Print( 0, " (width %s)", FMT_IU( aTarget->GetWidth() ).c_str() );
979 
980  formatLayer( aTarget );
981 
982  if( aTarget->GetTimeStamp() )
983  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTarget->GetTimeStamp() );
984 
985  m_out->Print( 0, ")\n" );
986 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetWidth() const
Definition: class_mire.h:72
void formatLayer(const BOARD_ITEM *aItem) const
int GetShape() const
Definition: class_mire.h:66
#define FMT_IU
time_t GetTimeStamp() const
Definition: base_struct.h:218
const wxPoint & GetPosition() const override
Definition: class_mire.h:63
int GetSize() const
Definition: class_mire.h:69
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void PCB_IO::format ( MODULE aModule,
int  aNestLevel = 0 
) const
private

Definition at line 989 of file kicad_plugin.cpp.

References CTL_OMIT_AT, CTL_OMIT_INITIAL_COMMENTS, CTL_OMIT_PATH, CTL_OMIT_TSTAMPS, Double2Str(), FMT_ANGLE, FMT_IU, Format(), LIB_ID::Format(), format(), formatLayer(), MODULE::GetAttributes(), MODULE::GetDescription(), MODULE::GetFPID(), MODULE::GetInitialComments(), MODULE::GetKeywords(), MODULE::GetLastEditTime(), MODULE::GetLocalClearance(), MODULE::GetLocalSolderMaskMargin(), MODULE::GetLocalSolderPasteMargin(), MODULE::GetLocalSolderPasteMarginRatio(), MODULE::GetOrientation(), MODULE::GetPath(), MODULE::GetPlacementCost180(), MODULE::GetPlacementCost90(), MODULE::GetPosition(), MODULE::GetThermalGap(), MODULE::GetThermalWidth(), EDA_ITEM::GetTimeStamp(), MODULE::GetZoneConnection(), MODULE::GraphicalItemsList(), MODULE::IsLocked(), MODULE::IsPlaced(), m_ctl, m_out, MOD_CMS, MOD_DEFAULT, MOD_VIRTUAL, MODULE::Models(), BOARD_ITEM::Next(), D_PAD::Next(), PAD_ZONE_CONN_INHERITED, MODULE::PadsList(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotes(), OUTPUTFORMATTER::Quotew(), MODULE::Reference(), TO_UTF8, and MODULE::Value().

990 {
991  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
992  {
993  const wxArrayString* initial_comments = aModule->GetInitialComments();
994 
995  if( initial_comments )
996  {
997  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
998  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
999 
1000  m_out->Print( 0, "\n" ); // improve readability?
1001  }
1002  }
1003 
1004  m_out->Print( aNestLevel, "(module %s",
1005  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1006 
1007  if( aModule->IsLocked() )
1008  m_out->Print( 0, " locked" );
1009 
1010  if( aModule->IsPlaced() )
1011  m_out->Print( 0, " placed" );
1012 
1013  formatLayer( aModule );
1014 
1015  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1016 
1017  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1018  {
1019  m_out->Print( 0, " (tstamp %lX)\n", (unsigned long)aModule->GetTimeStamp() );
1020  }
1021  else
1022  m_out->Print( 0, "\n" );
1023 
1024  if( !( m_ctl & CTL_OMIT_AT ) )
1025  {
1026  m_out->Print( aNestLevel+1, "(at %s", FMT_IU( aModule->GetPosition() ).c_str() );
1027 
1028  if( aModule->GetOrientation() != 0.0 )
1029  m_out->Print( 0, " %s", FMT_ANGLE( aModule->GetOrientation() ).c_str() );
1030 
1031  m_out->Print( 0, ")\n" );
1032  }
1033 
1034  if( !aModule->GetDescription().IsEmpty() )
1035  m_out->Print( aNestLevel+1, "(descr %s)\n",
1036  m_out->Quotew( aModule->GetDescription() ).c_str() );
1037 
1038  if( !aModule->GetKeywords().IsEmpty() )
1039  m_out->Print( aNestLevel+1, "(tags %s)\n",
1040  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1041 
1042  if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
1043  m_out->Print( aNestLevel+1, "(path %s)\n",
1044  m_out->Quotew( aModule->GetPath() ).c_str() );
1045 
1046  if( aModule->GetPlacementCost90() != 0 )
1047  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1048 
1049  if( aModule->GetPlacementCost180() != 0 )
1050  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1051 
1052  if( aModule->GetLocalSolderMaskMargin() != 0 )
1053  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1054  FMT_IU( aModule->GetLocalSolderMaskMargin() ).c_str() );
1055 
1056  if( aModule->GetLocalSolderPasteMargin() != 0 )
1057  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1058  FMT_IU( aModule->GetLocalSolderPasteMargin() ).c_str() );
1059 
1060  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1061  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1062  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1063 
1064  if( aModule->GetLocalClearance() != 0 )
1065  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1066  FMT_IU( aModule->GetLocalClearance() ).c_str() );
1067 
1068  if( aModule->GetZoneConnection() != PAD_ZONE_CONN_INHERITED )
1069  m_out->Print( aNestLevel+1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
1070 
1071  if( aModule->GetThermalWidth() != 0 )
1072  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1073  FMT_IU( aModule->GetThermalWidth() ).c_str() );
1074 
1075  if( aModule->GetThermalGap() != 0 )
1076  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1077  FMT_IU( aModule->GetThermalGap() ).c_str() );
1078 
1079  // Attributes
1080  if( aModule->GetAttributes() != MOD_DEFAULT )
1081  {
1082  m_out->Print( aNestLevel+1, "(attr" );
1083 
1084  if( aModule->GetAttributes() & MOD_CMS )
1085  m_out->Print( 0, " smd" );
1086 
1087  if( aModule->GetAttributes() & MOD_VIRTUAL )
1088  m_out->Print( 0, " virtual" );
1089 
1090  m_out->Print( 0, ")\n" );
1091  }
1092 
1093  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1094  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1095 
1096  // Save drawing elements.
1097  for( BOARD_ITEM* gr = aModule->GraphicalItemsList(); gr; gr = gr->Next() )
1098  Format( gr, aNestLevel+1 );
1099 
1100  // Save pads.
1101  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
1102  format( pad, aNestLevel+1 );
1103 
1104  // Save 3D info.
1105  std::list<S3D_INFO>::const_iterator bs3D = aModule->Models().begin();
1106  std::list<S3D_INFO>::const_iterator es3D = aModule->Models().end();
1107 
1108  while( bs3D != es3D )
1109  {
1110  if( !bs3D->m_Filename.IsEmpty() )
1111  {
1112  m_out->Print( aNestLevel+1, "(model %s\n",
1113  m_out->Quotew( bs3D->m_Filename ).c_str() );
1114 
1115  m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n",
1116  Double2Str( bs3D->m_Offset.x ).c_str(),
1117  Double2Str( bs3D->m_Offset.y ).c_str(),
1118  Double2Str( bs3D->m_Offset.z ).c_str() );
1119 
1120  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1121  Double2Str( bs3D->m_Scale.x ).c_str(),
1122  Double2Str( bs3D->m_Scale.y ).c_str(),
1123  Double2Str( bs3D->m_Scale.z ).c_str() );
1124 
1125  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1126  Double2Str( bs3D->m_Rotation.x ).c_str(),
1127  Double2Str( bs3D->m_Rotation.y ).c_str(),
1128  Double2Str( bs3D->m_Rotation.z ).c_str() );
1129 
1130  m_out->Print( aNestLevel+1, ")\n" );
1131  }
1132  ++bs3D;
1133  }
1134 
1135  m_out->Print( aNestLevel, ")\n" );
1136 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
TEXTE_MODULE & Reference()
Definition: class_module.h:463
#define CTL_OMIT_AT
Omit position and rotation.
int GetThermalGap() const
Definition: class_module.h:195
time_t GetLastEditTime() const
Definition: class_module.h:284
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
int GetLocalClearance() const
Definition: class_module.h:179
const wxPoint & GetPosition() const override
Definition: class_module.h:155
void formatLayer(const BOARD_ITEM *aItem) const
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:77
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:60
ZoneConnection GetZoneConnection() const
Definition: class_module.h:189
std::list< S3D_INFO > & Models()
Definition: class_module.h:150
int GetPlacementCost90() const
Definition: class_module.h:533
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:185
BOARD_ITEM * Next() const
const LIB_ID & GetFPID() const
Definition: class_module.h:164
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
double GetOrientation() const
Definition: class_module.h:160
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:462
D_PAD * Next() const
Definition: class_pad.h:145
#define FMT_IU
int GetAttributes() const
Definition: class_module.h:197
const wxString & GetKeywords() const
Definition: class_module.h:170
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
int GetLocalSolderMaskMargin() const
Definition: class_module.h:176
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:236
int GetLocalSolderPasteMargin() const
Definition: class_module.h:182
time_t GetTimeStamp() const
Definition: base_struct.h:218
default
Definition: class_module.h:76
virtual std::string Quotes(const std::string &aWrapee)
Function Quotes checks aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:437
const wxString & GetDescription() const
Definition: class_module.h:167
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:79
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
void format(BOARD *aBoard, int aNestLevel=0) const
UTF8 Format() const
Function Format.
Definition: lib_id.cpp:263
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define CTL_OMIT_INITIAL_COMMENTS
omit MODULE initial comments
const wxString & GetPath() const
Definition: class_module.h:173
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership. ...
Definition: class_module.h:648
#define FMT_ANGLE
bool IsPlaced() const
Definition: class_module.h:254
int GetPlacementCost180() const
Definition: class_module.h:530
int GetThermalWidth() const
Definition: class_module.h:192
void PCB_IO::format ( D_PAD aPad,
int  aNestLevel = 0 
) const
private

Definition at line 1237 of file kicad_plugin.cpp.

References CTL_OMIT_NETS, CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL, Double2Str(), FMT_ANGLE, FMT_IU, Format(), formatLayers(), D_PAD::GetAnchorPadShape(), D_PAD::GetAttribute(), D_PAD::GetCustomShapeInZoneOpt(), D_PAD::GetDelta(), D_PAD::GetDrillShape(), D_PAD::GetDrillSize(), D_PAD::GetLayerSet(), D_PAD::GetLocalClearance(), D_PAD::GetLocalSolderMaskMargin(), D_PAD::GetLocalSolderPasteMargin(), D_PAD::GetLocalSolderPasteMarginRatio(), D_PAD::GetName(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), D_PAD::GetOffset(), D_PAD::GetOrientation(), D_PAD::GetPadToDieLength(), D_PAD::GetPos0(), D_PAD::GetPrimitives(), D_PAD::GetRoundRectRadiusRatio(), D_PAD::GetShape(), D_PAD::GetSize(), D_PAD::GetThermalGap(), D_PAD::GetThermalWidth(), D_PAD::GetZoneConnection(), PAD_CS_PRIMITIVE::m_ArcAngle, m_ctl, PAD_CS_PRIMITIVE::m_End, m_mapping, m_out, PAD_CS_PRIMITIVE::m_Poly, PAD_CS_PRIMITIVE::m_Radius, PAD_CS_PRIMITIVE::m_Shape, PAD_CS_PRIMITIVE::m_Start, PAD_CS_PRIMITIVE::m_Thickness, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, PAD_ZONE_CONN_INHERITED, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), S_ARC, S_CIRCLE, S_POLYGON, S_SEGMENT, StrPrintf(), THROW_IO_ERROR, NETINFO_MAPPING::Translate(), NETINFO_LIST::UNCONNECTED, wxPoint::x, and wxPoint::y.

1238 {
1239  const char* shape;
1240 
1241  switch( aPad->GetShape() )
1242  {
1243  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1244  case PAD_SHAPE_RECT: shape = "rect"; break;
1245  case PAD_SHAPE_OVAL: shape = "oval"; break;
1246  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1247  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1248  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1249 
1250  default:
1251  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1252  }
1253 
1254  const char* type;
1255 
1256  switch( aPad->GetAttribute() )
1257  {
1258  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1259  case PAD_ATTRIB_SMD: type = "smd"; break;
1260  case PAD_ATTRIB_CONN: type = "connect"; break;
1261  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1262 
1263  default:
1264  THROW_IO_ERROR( wxString::Format( _( "unknown pad attribute: %d" ),
1265  aPad->GetAttribute() ) );
1266  }
1267 
1268  m_out->Print( aNestLevel, "(pad %s %s %s",
1269  m_out->Quotew( aPad->GetName() ).c_str(),
1270  type, shape );
1271  m_out->Print( 0, " (at %s", FMT_IU( aPad->GetPos0() ).c_str() );
1272 
1273  if( aPad->GetOrientation() != 0.0 )
1274  m_out->Print( 0, " %s", FMT_ANGLE( aPad->GetOrientation() ).c_str() );
1275 
1276  m_out->Print( 0, ")" );
1277  m_out->Print( 0, " (size %s)", FMT_IU( aPad->GetSize() ).c_str() );
1278 
1279  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1280  m_out->Print( 0, " (rect_delta %s )", FMT_IU( aPad->GetDelta() ).c_str() );
1281 
1282  wxSize sz = aPad->GetDrillSize();
1283  wxPoint shapeoffset = aPad->GetOffset();
1284 
1285  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1286  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1287  {
1288  m_out->Print( 0, " (drill" );
1289 
1290  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1291  m_out->Print( 0, " oval" );
1292 
1293  if( sz.GetWidth() > 0 )
1294  m_out->Print( 0, " %s", FMT_IU( sz.GetWidth() ).c_str() );
1295 
1296  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1297  m_out->Print( 0, " %s", FMT_IU( sz.GetHeight() ).c_str() );
1298 
1299  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1300  m_out->Print( 0, " (offset %s)", FMT_IU( aPad->GetOffset() ).c_str() );
1301 
1302  m_out->Print( 0, ")" );
1303  }
1304 
1305  formatLayers( aPad->GetLayerSet(), 0 );
1306 
1307  // Output the radius ratio for rounded rect pads
1308  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
1309  {
1310  m_out->Print( 0, "(roundrect_rratio %s)",
1311  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1312  }
1313 
1314  std::string output;
1315 
1316  // Unconnected pad is default net so don't save it.
1317  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1318  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1319  m_out->Quotew( aPad->GetNetname() ).c_str() );
1320 
1321  if( aPad->GetPadToDieLength() != 0 )
1322  StrPrintf( &output, " (die_length %s)", FMT_IU( aPad->GetPadToDieLength() ).c_str() );
1323 
1324  if( aPad->GetLocalSolderMaskMargin() != 0 )
1325  StrPrintf( &output, " (solder_mask_margin %s)", FMT_IU( aPad->GetLocalSolderMaskMargin() ).c_str() );
1326 
1327  if( aPad->GetLocalSolderPasteMargin() != 0 )
1328  StrPrintf( &output, " (solder_paste_margin %s)", FMT_IU( aPad->GetLocalSolderPasteMargin() ).c_str() );
1329 
1330  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1331  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1332  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1333 
1334  if( aPad->GetLocalClearance() != 0 )
1335  StrPrintf( &output, " (clearance %s)", FMT_IU( aPad->GetLocalClearance() ).c_str() );
1336 
1338  StrPrintf( &output, " (zone_connect %d)", aPad->GetZoneConnection() );
1339 
1340  if( aPad->GetThermalWidth() != 0 )
1341  StrPrintf( &output, " (thermal_width %s)", FMT_IU( aPad->GetThermalWidth() ).c_str() );
1342 
1343  if( aPad->GetThermalGap() != 0 )
1344  StrPrintf( &output, " (thermal_gap %s)", FMT_IU( aPad->GetThermalGap() ).c_str() );
1345 
1346  if( output.size() )
1347  {
1348  m_out->Print( 0, "\n" );
1349  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1350  }
1351 
1352  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1353  {
1354  m_out->Print( 0, "\n");
1355  m_out->Print( aNestLevel+1, "(options" );
1356 
1358  m_out->Print( 0, " (clearance convexhull)" );
1359  #if 1 // Set to 1 to output the default option
1360  else
1361  m_out->Print( 0, " (clearance outline)" );
1362  #endif
1363 
1364  // Output the anchor pad shape (circle/rect)
1365  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1366  shape = "rect";
1367  else
1368  shape = "circle";
1369 
1370  m_out->Print( 0, " (anchor %s)", shape );
1371 
1372  m_out->Print( 0, ")"); // end of (options ...
1373 
1374  // Output graphic primitive of the pad shape
1375  m_out->Print( 0, "\n");
1376  m_out->Print( aNestLevel+1, "(primitives" );
1377 
1378  int nested_level = aNestLevel+2;
1379 
1380  // Output all basic shapes
1381  for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
1382  {
1383  m_out->Print( 0, "\n");
1384 
1385  const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
1386 
1387  switch( primitive.m_Shape )
1388  {
1389  case S_SEGMENT: // usual segment : line with rounded ends
1390  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1391  FMT_IU( primitive.m_Start ).c_str(),
1392  FMT_IU( primitive.m_End ).c_str(),
1393  FMT_IU( primitive.m_Thickness ).c_str() );
1394  break;
1395 
1396  case S_ARC: // Arc with rounded ends
1397  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1398  FMT_IU( primitive.m_Start ).c_str(),
1399  FMT_IU( primitive.m_End ).c_str(),
1400  FMT_ANGLE( primitive.m_ArcAngle ).c_str(),
1401  FMT_IU( primitive.m_Thickness ).c_str() );
1402  break;
1403 
1404  case S_CIRCLE: // ring or circle (circle if width == 0
1405  m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
1406  FMT_IU( primitive.m_Start ).c_str(),
1407  FMT_IU( primitive.m_Start.x + primitive.m_Radius ).c_str(),
1408  FMT_IU( primitive.m_Start.y ).c_str(),
1409  FMT_IU( primitive.m_Thickness ).c_str() );
1410  break;
1411 
1412  case S_POLYGON: // polygon
1413  if( primitive.m_Poly.size() < 2 )
1414  break; // Malformed polygon.
1415 
1416  {
1417  m_out->Print( nested_level, "(gr_poly (pts\n");
1418 
1419  // Write the polygon corners coordinates:
1420  const std::vector< wxPoint>& poly = primitive.m_Poly;
1421  int newLine = 0;
1422 
1423  for( unsigned ii = 0; ii < poly.size(); ii++ )
1424  {
1425  if( newLine == 0 )
1426  m_out->Print( nested_level+1, " (xy %s)", FMT_IU( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1427  else
1428  m_out->Print( 0, " (xy %s)", FMT_IU( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1429 
1430  if( ++newLine > 4 )
1431  {
1432  newLine = 0;
1433  m_out->Print( 0, "\n" );
1434  }
1435  }
1436 
1437  if( primitive.m_Thickness != 0 )
1438  m_out->Print( 0, ") (width %s))", FMT_IU( primitive.m_Thickness ).c_str() );
1439  else
1440  m_out->Print( 0, "))");
1441  }
1442  break;
1443 
1444  default:
1445  break;
1446  }
1447  }
1448 
1449  m_out->Print( 0, "\n");
1450  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1451  }
1452 
1453  m_out->Print( 0, ")\n" );
1454 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:211
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:318
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:380
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
int GetPadToDieLength() const
Definition: class_pad.h:383
wxPoint m_Start
angle of an arc, from its starting point, in 0.1 deg
Definition: class_pad.h:98
polygon (not yet used for tracks, but could be in microwave apps)
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:385
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
const wxPoint & GetPos0() const
Definition: class_pad.h:248
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:363
usual segment : line with rounded ends
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:60
const wxSize & GetDrillSize() const
Definition: class_pad.h:260
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:201
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:75
int m_Radius
thickness of segment or outline For filled S_CIRCLE shape, thickness = 0.
Definition: class_pad.h:96
std::vector< wxPoint > m_Poly
is also the start point of the arc
Definition: class_pad.h:100
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Arcs (with rounded ends)
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:89
ZoneConnection GetZoneConnection() const
Definition: class_pad.cpp:650
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:377
int GetThermalWidth() const
Definition: class_pad.cpp:661
int GetThermalGap() const
Definition: class_pad.cpp:672
const wxSize & GetSize() const
Definition: class_pad.h:254
#define FMT_IU
const wxString & GetName() const
Definition: class_pad.h:175
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:391
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:99
#define CTL_OMIT_NETS
Omit pads net names (useless in library)
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:62
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
STROKE_T m_Shape
Definition: class_pad.h:92
int GetLocalClearance() const
Definition: class_pad.h:388
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:394
int GetNetCode() const
Function GetNetCode.
int m_Thickness
S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
Definition: class_pad.h:93
const wxString & GetNetname() const
Function GetNetname.
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:590
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:217
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:357
const wxSize & GetDelta() const
Definition: class_pad.h:257
Usual pad.
Definition: pad_shapes.h:60
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define FMT_ANGLE
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
const wxPoint & GetOffset() const
Definition: class_pad.h:263
double m_ArcAngle
radius of a circle
Definition: class_pad.h:97
void PCB_IO::format ( TEXTE_PCB aText,
int  aNestLevel = 0 
) const
private

Definition at line 1457 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, formatLayer(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_ITEM::GetTimeStamp(), m_ctl, m_out, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

1458 {
1459  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1460  m_out->Quotew( aText->GetText() ).c_str(),
1461  FMT_IU( aText->GetTextPos() ).c_str() );
1462 
1463  if( aText->GetTextAngle() != 0.0 )
1464  m_out->Print( 0, " %s", FMT_ANGLE( aText->GetTextAngle() ).c_str() );
1465 
1466  m_out->Print( 0, ")" );
1467 
1468  formatLayer( aText );
1469 
1470  if( aText->GetTimeStamp() )
1471  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aText->GetTimeStamp() );
1472 
1473  m_out->Print( 0, "\n" );
1474 
1475  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1476 
1477  m_out->Print( aNestLevel, ")\n" );
1478 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
void formatLayer(const BOARD_ITEM *aItem) const
double GetTextAngle() const
Definition: eda_text.h:164
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
#define FMT_IU
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
time_t GetTimeStamp() const
Definition: base_struct.h:218
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define FMT_ANGLE
void PCB_IO::format ( TEXTE_MODULE aText,
int  aNestLevel = 0 
) const
private

Definition at line 1481 of file kicad_plugin.cpp.

References CTL_OMIT_HIDE, FMT_ANGLE, FMT_IU, formatLayer(), MODULE::GetOrientation(), BOARD_ITEM::GetParent(), TEXTE_MODULE::GetPos0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), TEXTE_MODULE::GetType(), EDA_TEXT::IsVisible(), m_ctl, m_out, NormalizeAngle360(), NormalizeAnglePos(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, and TEXTE_MODULE::TEXT_is_VALUE.

1482 {
1483  wxString type;
1484 
1485  switch( aText->GetType() )
1486  {
1487  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1488  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1489  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1490  }
1491 
1492  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1493  m_out->Quotew( type ).c_str(),
1494  m_out->Quotew( aText->GetText() ).c_str(),
1495  FMT_IU( aText->GetPos0() ).c_str() );
1496 
1497  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1498  // but internally the angle is held relative to its parent footprint. parent
1499  // may be NULL when saving a footprint outside a BOARD.
1500  double orient = aText->GetTextAngle();
1501  MODULE* parent = (MODULE*) aText->GetParent();
1502 
1503  if( parent )
1504  {
1505  // GetTextAngle() is always in -360..+360 range because of
1506  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1507  // additional board angle could kick sum up >= 360 or <= -360, so to have
1508  // consistent results, normalize again for the BOARD save. A footprint
1509  // save does not use this code path since parent is NULL.
1510 #if 0
1511  // This one could be considered reasonable if you like positive angles
1512  // in your board text.
1513  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1514 #else
1515  // Choose compatibility for now, even though this is only a 720 degree clamp
1516  // with two possible values for every angle.
1517  orient = NormalizeAngle360( orient + parent->GetOrientation() );
1518 #endif
1519  }
1520 
1521  if( orient != 0.0 )
1522  m_out->Print( 0, " %s", FMT_ANGLE( orient ).c_str() );
1523 
1524  m_out->Print( 0, ")" );
1525  formatLayer( aText );
1526 
1527  if( !aText->IsVisible() )
1528  m_out->Print( 0, " hide" );
1529 
1530  m_out->Print( 0, "\n" );
1531 
1532  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1533 
1534  m_out->Print( aNestLevel, ")\n" );
1535 }
BOARD_ITEM_CONTAINER * GetParent() const
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
TEXT_TYPE GetType() const
const wxPoint & GetPos0() const
void formatLayer(const BOARD_ITEM *aItem) const
double GetTextAngle() const
Definition: eda_text.h:164
double GetOrientation() const
Definition: class_module.h:160
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
#define FMT_IU
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
bool IsVisible() const
Definition: eda_text.h:176
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:214
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define FMT_ANGLE
#define CTL_OMIT_HIDE
Definition: eda_text.h:42
T NormalizeAngle360(T Angle)
Normalize angle to be in the -360.0 .. 360.0:
Definition: trigo.h:202
void PCB_IO::format ( TRACK aTrack,
int  aNestLevel = 0 
) const
private

Definition at line 1538 of file kicad_plugin.cpp.

References FMT_IU, Format(), VIA::GetDrill(), TRACK::GetEnd(), BOARD_ITEM::GetLayerName(), BOARD::GetLayerName(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_ITEM::GetParent(), VIA::GetSelectMenuText(), TRACK::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), VIA::GetViaType(), TRACK::GetWidth(), VIA::LayerPair(), m_board, m_mapping, m_out, PCB_VIA_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), THROW_IO_ERROR, NETINFO_MAPPING::Translate(), EDA_ITEM::Type(), UNDEFINED_DRILL_DIAMETER, VIA_BLIND_BURIED, VIA_MICROVIA, and VIA_THROUGH.

1539 {
1540  if( aTrack->Type() == PCB_VIA_T )
1541  {
1542  PCB_LAYER_ID layer1, layer2;
1543 
1544  const VIA* via = static_cast<const VIA*>(aTrack);
1545  BOARD* board = (BOARD*) via->GetParent();
1546 
1547  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText() +
1548  wxT( " has no parent." ) );
1549 
1550  m_out->Print( aNestLevel, "(via" );
1551 
1552  via->LayerPair( &layer1, &layer2 );
1553 
1554  switch( via->GetViaType() )
1555  {
1556  case VIA_THROUGH: // Default shape not saved.
1557  break;
1558 
1559  case VIA_BLIND_BURIED:
1560  m_out->Print( 0, " blind" );
1561  break;
1562 
1563  case VIA_MICROVIA:
1564  m_out->Print( 0, " micro" );
1565  break;
1566 
1567  default:
1568  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1569  }
1570 
1571  m_out->Print( 0, " (at %s) (size %s)",
1572  FMT_IU( aTrack->GetStart() ).c_str(),
1573  FMT_IU( aTrack->GetWidth() ).c_str() );
1574 
1575  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1576  m_out->Print( 0, " (drill %s)", FMT_IU( via->GetDrill() ).c_str() );
1577 
1578  m_out->Print( 0, " (layers %s %s)",
1579  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1580  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1581  }
1582  else
1583  {
1584  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1585  FMT_IU( aTrack->GetStart() ).c_str(), FMT_IU( aTrack->GetEnd() ).c_str(),
1586  FMT_IU( aTrack->GetWidth() ).c_str() );
1587 
1588  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1589  }
1590 
1591  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1592 
1593  if( aTrack->GetTimeStamp() != 0 )
1594  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTrack->GetTimeStamp() );
1595 
1596  if( aTrack->GetStatus() != 0 )
1597  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1598 
1599  m_out->Print( 0, ")\n" );
1600 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
BOARD_ITEM_CONTAINER * GetParent() const
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:264
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:454
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
const wxPoint & GetEnd() const
Definition: class_track.h:118
PCB_LAYER_ID
A quick note on layer IDs:
VIATYPE_T GetViaType() const
Definition: class_track.h:439
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
const wxPoint & GetStart() const
Definition: class_track.h:121
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
#define FMT_IU
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:58
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
time_t GetTimeStamp() const
Definition: base_struct.h:218
int GetNetCode() const
Function GetNetCode.
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int GetWidth() const
Definition: class_track.h:115
BOARD * m_board
which BOARD, no ownership here
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void PCB_IO::format ( ZONE_CONTAINER aZone,
int  aNestLevel = 0 
) const
private

Definition at line 1603 of file kicad_plugin.cpp.

References SHAPE_POLY_SET::CIterate(), ZONE_CONTAINER::DIAGONAL_EDGE, ZONE_CONTAINER::DIAGONAL_FULL, ZONE_CONTAINER::FillSegments(), FMT_IU, Format(), formatLayer(), ZONE_CONTAINER::GetArcSegmentCount(), ZONE_CONTAINER::GetCornerRadius(), ZONE_CONTAINER::GetCornerSmoothingType(), ZONE_CONTAINER::GetDoNotAllowCopperPour(), ZONE_CONTAINER::GetDoNotAllowTracks(), ZONE_CONTAINER::GetDoNotAllowVias(), ZONE_CONTAINER::GetFilledPolysList(), ZONE_CONTAINER::GetFillMode(), ZONE_CONTAINER::GetHatchPitch(), ZONE_CONTAINER::GetHatchStyle(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::GetMinThickness(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), ZONE_CONTAINER::GetNumCorners(), ZONE_CONTAINER::GetPadConnection(), ZONE_CONTAINER::GetPriority(), ZONE_CONTAINER::GetThermalReliefCopperBridge(), ZONE_CONTAINER::GetThermalReliefGap(), EDA_ITEM::GetTimeStamp(), ZONE_CONTAINER::GetZoneClearance(), SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::IsFilled(), ZONE_CONTAINER::IterateWithHoles(), m_mapping, m_out, ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_NONE, PAD_ZONE_CONN_THERMAL, PAD_ZONE_CONN_THT_THERMAL, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), ZONE_SETTINGS::SMOOTHING_CHAMFER, ZONE_SETTINGS::SMOOTHING_FILLET, ZONE_SETTINGS::SMOOTHING_NONE, THROW_IO_ERROR, and NETINFO_MAPPING::Translate().

1604 {
1605  // Save the NET info; For keepout zones, net code and net name are irrelevant
1606  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1607  // (perhaps netcode and netname should be not stored)
1608  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1609  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1610  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1611 
1612  formatLayer( aZone );
1613 
1614  m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
1615 
1616  // Save the outline aux info
1617  std::string hatch;
1618 
1619  switch( aZone->GetHatchStyle() )
1620  {
1621  default:
1622  case ZONE_CONTAINER::NO_HATCH: hatch = "none"; break;
1623  case ZONE_CONTAINER::DIAGONAL_EDGE: hatch = "edge"; break;
1624  case ZONE_CONTAINER::DIAGONAL_FULL: hatch = "full"; break;
1625  }
1626 
1627  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1628  FMT_IU( aZone->GetHatchPitch() ).c_str() );
1629 
1630  if( aZone->GetPriority() > 0 )
1631  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1632 
1633  m_out->Print( aNestLevel+1, "(connect_pads" );
1634 
1635  switch( aZone->GetPadConnection() )
1636  {
1637  default:
1638  case PAD_ZONE_CONN_THERMAL: // Default option not saved or loaded.
1639  break;
1640 
1642  m_out->Print( 0, " thru_hole_only" );
1643  break;
1644 
1645  case PAD_ZONE_CONN_FULL:
1646  m_out->Print( 0, " yes" );
1647  break;
1648 
1649  case PAD_ZONE_CONN_NONE:
1650  m_out->Print( 0, " no" );
1651  break;
1652  }
1653 
1654  m_out->Print( 0, " (clearance %s))\n",
1655  FMT_IU( aZone->GetZoneClearance() ).c_str() );
1656 
1657  m_out->Print( aNestLevel+1, "(min_thickness %s)\n",
1658  FMT_IU( aZone->GetMinThickness() ).c_str() );
1659 
1660  if( aZone->GetIsKeepout() )
1661  {
1662  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
1663  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1664  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1665  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
1666  }
1667 
1668  m_out->Print( aNestLevel+1, "(fill" );
1669 
1670  // Default is not filled.
1671  if( aZone->IsFilled() )
1672  m_out->Print( 0, " yes" );
1673 
1674  // Default is polygon filled.
1675  if( aZone->GetFillMode() )
1676  m_out->Print( 0, " (mode segment)" );
1677 
1678  m_out->Print( 0, " (arc_segments %d) (thermal_gap %s) (thermal_bridge_width %s)",
1679  aZone->GetArcSegmentCount(),
1680  FMT_IU( aZone->GetThermalReliefGap() ).c_str(),
1681  FMT_IU( aZone->GetThermalReliefCopperBridge() ).c_str() );
1682 
1684  {
1685  m_out->Print( 0, " (smoothing" );
1686 
1687  switch( aZone->GetCornerSmoothingType() )
1688  {
1690  m_out->Print( 0, " chamfer" );
1691  break;
1692 
1694  m_out->Print( 0, " fillet" );
1695  break;
1696 
1697  default:
1698  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1699  aZone->GetCornerSmoothingType() ) );
1700  }
1701  m_out->Print( 0, ")" );
1702 
1703  if( aZone->GetCornerRadius() != 0 )
1704  m_out->Print( 0, " (radius %s)",
1705  FMT_IU( aZone->GetCornerRadius() ).c_str() );
1706  }
1707 
1708  m_out->Print( 0, ")\n" );
1709 
1710  int newLine = 0;
1711 
1712  if( aZone->GetNumCorners() )
1713  {
1714  bool new_polygon = true;
1715  bool is_closed = false;
1716 
1717  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1718  {
1719  if( new_polygon )
1720  {
1721  newLine = 0;
1722  m_out->Print( aNestLevel+1, "(polygon\n" );
1723  m_out->Print( aNestLevel+2, "(pts\n" );
1724  new_polygon = false;
1725  is_closed = false;
1726  }
1727 
1728  if( newLine == 0 )
1729  m_out->Print( aNestLevel+3, "(xy %s %s)",
1730  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1731  else
1732  m_out->Print( 0, " (xy %s %s)",
1733  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1734 
1735  if( newLine < 4 )
1736  {
1737  newLine += 1;
1738  }
1739  else
1740  {
1741  newLine = 0;
1742  m_out->Print( 0, "\n" );
1743  }
1744 
1745  if( iterator.IsEndContour() )
1746  {
1747  is_closed = true;
1748 
1749  if( newLine != 0 )
1750  m_out->Print( 0, "\n" );
1751 
1752  m_out->Print( aNestLevel+2, ")\n" );
1753  m_out->Print( aNestLevel+1, ")\n" );
1754  new_polygon = true;
1755  }
1756  }
1757 
1758  if( !is_closed ) // Should not happen, but...
1759  m_out->Print( aNestLevel+1, ")\n" );
1760 
1761  }
1762 
1763  // Save the PolysList (filled areas)
1764  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1765  newLine = 0;
1766 
1767  if( !fv.IsEmpty() )
1768  {
1769  bool new_polygon = true;
1770  bool is_closed = false;
1771 
1772  for( auto it = fv.CIterate(); it; ++it )
1773  {
1774  if( new_polygon )
1775  {
1776  newLine = 0;
1777  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1778  m_out->Print( aNestLevel+2, "(pts\n" );
1779  new_polygon = false;
1780  is_closed = false;
1781  }
1782 
1783  if( newLine == 0 )
1784  m_out->Print( aNestLevel+3, "(xy %s %s)",
1785  FMT_IU( it->x ).c_str(), FMT_IU( it->y ).c_str() );
1786  else
1787  m_out->Print( 0, " (xy %s %s)",
1788  FMT_IU( it->x ) .c_str(), FMT_IU( it->y ).c_str() );
1789 
1790  if( newLine < 4 )
1791  {
1792  newLine += 1;
1793  }
1794  else
1795  {
1796  newLine = 0;
1797  m_out->Print( 0, "\n" );
1798  }
1799 
1800  if( it.IsEndContour() )
1801  {
1802  is_closed = true;
1803 
1804  if( newLine != 0 )
1805  m_out->Print( 0, "\n" );
1806 
1807  m_out->Print( aNestLevel+2, ")\n" );
1808  m_out->Print( aNestLevel+1, ")\n" );
1809  new_polygon = true;
1810  }
1811  }
1812 
1813  if( !is_closed ) // Should not happen, but...
1814  m_out->Print( aNestLevel+1, ")\n" );
1815  }
1816 
1817  // Save the filling segments list
1818  const std::vector< SEGMENT >& segs = aZone->FillSegments();
1819 
1820  if( segs.size() )
1821  {
1822  m_out->Print( aNestLevel+1, "(fill_segments\n" );
1823 
1824  for( std::vector< SEGMENT >::const_iterator it = segs.begin(); it != segs.end(); ++it )
1825  {
1826  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
1827  FMT_IU( it->m_Start ).c_str(),
1828  FMT_IU( it->m_End ).c_str() );
1829  }
1830 
1831  m_out->Print( aNestLevel+1, ")\n" );
1832  }
1833 
1834  m_out->Print( aNestLevel, ")\n" );
1835 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:465
int GetMinThickness() const
Definition: class_zone.h:209
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:655
int GetArcSegmentCount() const
Definition: class_zone.h:198
bool IsFilled() const
Definition: class_zone.h:200
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
void formatLayer(const BOARD_ITEM *aItem) const
int GetCornerSmoothingType() const
Definition: class_zone.h:612
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:472
unsigned int GetCornerRadius() const
Definition: class_zone.h:616
Pads are not covered.
Definition: zones.h:57
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:654
std::vector< SEGMENT > & FillSegments()
Definition: class_zone.h:244
ZoneConnection GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:820
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Class SHAPE_POLY_SET.
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:463
#define FMT_IU
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:582
Thermal relief only for THT pads.
Definition: zones.h:60
time_t GetTimeStamp() const
Definition: base_struct.h:218
int GetNetCode() const
Function GetNetCode.
bool GetDoNotAllowTracks() const
Definition: class_zone.h:657
int GetFillMode() const
Definition: class_zone.h:186
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool GetDoNotAllowVias() const
Definition: class_zone.h:656
SHAPE_POLY_SET::ITERATOR IterateWithHoles()
Function IterateWithHoles returns an iterator to visit all points of the zone's main outline with hol...
Definition: class_zone.h:485
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:549
int GetHatchPitch() const
Hatch related methods.
Definition: class_zone.cpp:920
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:119
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Use thermal relief for pads.
Definition: zones.h:58
int GetZoneClearance() const
Definition: class_zone.h:203
pads are covered by copper
Definition: zones.h:59
void PCB_IO::formatLayer ( const BOARD_ITEM aItem) const
private

Definition at line 517 of file kicad_plugin.cpp.

References CTL_STD_LAYER_NAMES, BOARD_ITEM::GetLayer(), BOARD_ITEM::GetLayerName(), BOARD::GetStandardLayerName(), m_ctl, m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and TO_UTF8.

Referenced by format().

518 {
519  if( m_ctl & CTL_STD_LAYER_NAMES )
520  {
521  PCB_LAYER_ID layer = aItem->GetLayer();
522 
523  // English layer names should never need quoting.
524  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
525  }
526  else
527  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
528 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PCB_LAYER_ID
A quick note on layer IDs:
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
#define CTL_STD_LAYER_NAMES
Use English Standard layer names.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:647
void PCB_IO::formatLayers ( LSET  aLayerMask,
int  aNestLevel = 0 
) const
private

Definition at line 1139 of file kicad_plugin.cpp.

References LSET::AllCuMask(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, CTL_STD_LAYER_NAMES, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, BOARD::GetEnabledLayers(), BOARD::GetLayerName(), BOARD::GetStandardLayerName(), m_board, m_ctl, m_out, PCB_LAYER_ID_COUNT, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by format().

1140 {
1141  std::string output;
1142 
1143  if( aNestLevel == 0 )
1144  output += ' ';
1145 
1146  output += "(layers";
1147 
1148  static const LSET cu_all( LSET::AllCuMask() );
1149  static const LSET fr_bk( 2, B_Cu, F_Cu );
1150  static const LSET adhes( 2, B_Adhes, F_Adhes );
1151  static const LSET paste( 2, B_Paste, F_Paste );
1152  static const LSET silks( 2, B_SilkS, F_SilkS );
1153  static const LSET mask( 2, B_Mask, F_Mask );
1154  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1155  static const LSET fab( 2, B_Fab, F_Fab );
1156 
1157  LSET cu_mask = cu_all;
1158 
1159  if( m_board )
1160  cu_mask &= m_board->GetEnabledLayers();
1161 
1162  // output copper layers first, then non copper
1163 
1164  if( ( aLayerMask & cu_mask ) == cu_mask )
1165  {
1166  output += " *.Cu";
1167  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1168  }
1169  else if( ( aLayerMask & cu_mask ) == fr_bk )
1170  {
1171  output += " F&B.Cu";
1172  aLayerMask &= ~fr_bk;
1173  }
1174 
1175  if( ( aLayerMask & adhes ) == adhes )
1176  {
1177  output += " *.Adhes";
1178  aLayerMask &= ~adhes;
1179  }
1180 
1181  if( ( aLayerMask & paste ) == paste )
1182  {
1183  output += " *.Paste";
1184  aLayerMask &= ~paste;
1185  }
1186 
1187  if( ( aLayerMask & silks ) == silks )
1188  {
1189  output += " *.SilkS";
1190  aLayerMask &= ~silks;
1191  }
1192 
1193  if( ( aLayerMask & mask ) == mask )
1194  {
1195  output += " *.Mask";
1196  aLayerMask &= ~mask;
1197  }
1198 
1199  if( ( aLayerMask & crt_yd ) == crt_yd )
1200  {
1201  output += " *.CrtYd";
1202  aLayerMask &= ~crt_yd;
1203  }
1204 
1205  if( ( aLayerMask & fab ) == fab )
1206  {
1207  output += " *.Fab";
1208  aLayerMask &= ~fab;
1209  }
1210 
1211  // output any individual layers not handled in wildcard combos above
1212 
1213  if( m_board )
1214  aLayerMask &= m_board->GetEnabledLayers();
1215 
1216  wxString layerName;
1217 
1218  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1219  {
1220  if( aLayerMask[layer] )
1221  {
1222  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1223  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1224 
1225  else // I am being called from FootprintSave()
1226  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1227 
1228  output += ' ';
1229  output += m_out->Quotew( layerName );
1230  }
1231  }
1232 
1233  m_out->Print( aNestLevel, "%s)", output.c_str() );
1234 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
#define CTL_STD_LAYER_NAMES
Use English Standard layer names.
BOARD * m_board
which BOARD, no ownership here
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:647
const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 102 of file pcbnew/kicad_plugin.h.

103  {
104  // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
105  // but to be pure, a plugin should not assume that it will always be linked
106  // with the core of the pcbnew code. (Might someday be a DLL/DSO.) Besides,
107  // file extension policy should be controlled by the plugin.
108  return wxT( "kicad_pcb" );
109  }
std::string PCB_IO::GetStringOutput ( bool  doClear)
inline

Definition at line 151 of file pcbnew/kicad_plugin.h.

References STRING_FORMATTER::Clear(), STRING_FORMATTER::GetString(), and m_sf.

Referenced by MODULE_EDITOR_TOOLS::CopyItems(), FOOTPRINT_EDIT_FRAME::Export_Module(), and FOOTPRINT_EDIT_FRAME::retainLastFootprint().

152  {
153  std::string ret = m_sf.GetString();
154  if( doClear )
155  m_sf.Clear();
156 
157  return ret;
158  }
const std::string & GetString()
Definition: richio.h:475
STRING_FORMATTER m_sf
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:464
void PCB_IO::init ( const PROPERTIES aProperties)
protected

Definition at line 1901 of file kicad_plugin.cpp.

References m_board, m_loading_format_version, m_props, m_reader, and SEXPR_BOARD_FILE_VERSION.

Referenced by FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintLoad(), FootprintSave(), IsFootprintLibWritable(), Load(), PCB_IO(), and Save().

1902 {
1903  m_board = NULL;
1904  m_reader = NULL;
1906  m_props = aProperties;
1907 }
LINE_READER * m_reader
no ownership here.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
BOARD * m_board
which BOARD, no ownership here
bool PCB_IO::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from PLUGIN.

Definition at line 2170 of file kicad_plugin.cpp.

References cacheLib(), init(), FP_CACHE::IsWritable(), and m_cache.

Referenced by GITHUB_PLUGIN::IsFootprintLibWritable().

2171 {
2172  LOCALE_IO toggle;
2173 
2174  init( NULL );
2175 
2176  cacheLib( aLibraryPath );
2177 
2178  return m_cache->IsWritable();
2179 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
bool IsWritable() const
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
BOARD * PCB_IO::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one.

This may be used to load an entire new BOARD, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aAppendToMeis an existing BOARD to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of 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.
Returns
BOARD* - the successfully loaded board, or the same one as aAppendToMe if aAppendToMe was not NULL, and caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.

Reimplemented from PLUGIN.

Definition at line 1857 of file kicad_plugin.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), PCB_PARSER::GetRequiredVersion(), init(), PCB_PARSER::IsTooRecent(), m_parser, PCB_PARSER::Parse(), PCB_PARSER::SetBoard(), BOARD::SetFileName(), PCB_PARSER::SetLineReader(), and THROW_PARSE_ERROR.

1858 {
1859  FILE_LINE_READER reader( aFileName );
1860 
1861  init( aProperties );
1862 
1863  m_parser->SetLineReader( &reader );
1864  m_parser->SetBoard( aAppendToMe );
1865 
1866  BOARD* board;
1867 
1868  try
1869  {
1870  board = dynamic_cast<BOARD*>( m_parser->Parse() );
1871  }
1872  catch( const FUTURE_FORMAT_ERROR& )
1873  {
1874  // Don't wrap a FUTURE_FORMAT_ERROR in another
1875  throw;
1876  }
1877  catch( const PARSE_ERROR& parse_error )
1878  {
1879  if( m_parser->IsTooRecent() )
1880  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
1881  else
1882  throw;
1883  }
1884 
1885  if( !board )
1886  {
1887  // The parser loaded something that was valid, but wasn't a board.
1888  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
1891  }
1892 
1893  // Give the filename to the board if it's new
1894  if( !aAppendToMe )
1895  board->SetFileName( aFileName );
1896 
1897  return board;
1898 }
void init(const PROPERTIES *aProperties)
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:305
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
void SetFileName(const wxString &aFileName)
Definition: class_board.h:232
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:405
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:298
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:316
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)

Definition at line 438 of file kicad_plugin.cpp.

References PCB_PARSER::GetRequiredVersion(), PCB_PARSER::IsTooRecent(), m_parser, PCB_PARSER::Parse(), PCB_PARSER::SetLineReader(), and TO_UTF8.

Referenced by parse_module_kicad(), MODULE_EDITOR_TOOLS::PasteItems(), and FOOTPRINT_EDIT_FRAME::restoreLastFootprint().

439 {
440  std::string input = TO_UTF8( aClipboardSourceInput );
441 
442  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
443 
444  m_parser->SetLineReader( &reader );
445 
446  try
447  {
448  return m_parser->Parse();
449  }
450  catch( const PARSE_ERROR& parse_error )
451  {
452  if( m_parser->IsTooRecent() )
453  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
454  else
455  throw;
456  }
457 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:405
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:298
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:316
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
const wxString PCB_IO::PluginName ( ) const
inlineoverridevirtual

Function PluginName returns a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 97 of file pcbnew/kicad_plugin.h.

98  {
99  return wxT( "KiCad" );
100  }
void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Plugins that cannot prefetch need not override this; a default no-op is provided.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is an error prefetching the library.

Reimplemented in GITHUB_PLUGIN.

Definition at line 69 of file plugin.cpp.

Referenced by FP_LIB_TABLE::PrefetchLib().

70 {
71  (void) aLibraryPath;
72  (void) aProperties;
73 }
void PCB_IO::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aBoardis the class BOARD in memory document tree from which to extract information when writing to aFileName. The caller continues to own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
aPropertiesis 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. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from PLUGIN.

Definition at line 414 of file kicad_plugin.cpp.

References Format(), GetBuildVersion(), init(), m_board, m_mapping, m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), NETINFO_MAPPING::SetBoard(), and SEXPR_BOARD_FILE_VERSION.

415 {
416  LOCALE_IO toggle; // toggles on, then off, the C locale.
417 
418  init( aProperties );
419 
420  m_board = aBoard; // after init()
421 
422  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
423  m_mapping->SetBoard( aBoard );
424 
425  FILE_OUTPUTFORMATTER formatter( aFileName );
426 
427  m_out = &formatter; // no ownership
428 
429  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
430  formatter.Quotew( GetBuildVersion() ).c_str() );
431 
432  Format( aBoard, 1 );
433 
434  m_out->Print( 0, ")\n" );
435 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void init(const PROPERTIES *aProperties)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
BOARD * m_board
which BOARD, no ownership here
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inline

Definition at line 160 of file pcbnew/kicad_plugin.h.

References m_out.

Referenced by FP_CACHE::Save().

160 { m_out = aFormatter; }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership

Friends And Related Function Documentation

friend class FP_CACHE
friend

Definition at line 91 of file pcbnew/kicad_plugin.h.

Referenced by cacheLib(), and FootprintLibCreate().

Member Data Documentation

BOARD* PCB_IO::m_board
protected

which BOARD, no ownership here

Definition at line 167 of file pcbnew/kicad_plugin.h.

Referenced by format(), formatLayers(), init(), and Save().

int PCB_IO::m_ctl
protected

Definition at line 180 of file pcbnew/kicad_plugin.h.

Referenced by FootprintSave(), format(), formatLayer(), and formatLayers().

wxString PCB_IO::m_error
protected

for throwing exceptions

Definition at line 166 of file pcbnew/kicad_plugin.h.

wxString PCB_IO::m_filename
protected

for saves only, name is in m_reader for loads

Definition at line 174 of file pcbnew/kicad_plugin.h.

int PCB_IO::m_loading_format_version
protected

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

Definition at line 176 of file pcbnew/kicad_plugin.h.

Referenced by init().

NETINFO_MAPPING* PCB_IO::m_mapping
protected

mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes

Definition at line 182 of file pcbnew/kicad_plugin.h.

Referenced by format(), Save(), and ~PCB_IO().

OUTPUTFORMATTER* PCB_IO::m_out
protected

output any Format()s to this, no ownership

Definition at line 179 of file pcbnew/kicad_plugin.h.

Referenced by format(), formatLayer(), formatLayers(), PCB_IO(), Save(), and SetOutputFormatter().

PCB_PARSER* PCB_IO::m_parser
protected
const PROPERTIES* PCB_IO::m_props
protected

passed via Save() or Load(), no ownership, may be NULL.

Definition at line 170 of file pcbnew/kicad_plugin.h.

Referenced by init().

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

Definition at line 173 of file pcbnew/kicad_plugin.h.

Referenced by init().

STRING_FORMATTER PCB_IO::m_sf
protected

Definition at line 178 of file pcbnew/kicad_plugin.h.

Referenced by GetStringOutput(), and PCB_IO().


The documentation for this class was generated from the following files: