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...
 
wxArrayString FootprintEnumerate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintEnumerate returns 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 throw ( IO_ERROR )
 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) throw ( FUTURE_FORMAT_ERROR, PARSE_ERROR, IO_ERROR )
 
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 throw ( IO_ERROR )
 
void format (DIMENSION *aDimension, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (EDGE_MODULE *aModuleDrawing, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (DRAWSEGMENT *aSegment, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (PCB_TARGET *aTarget, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (MODULE *aModule, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (D_PAD *aPad, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (TEXTE_PCB *aText, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (TEXTE_MODULE *aText, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (TRACK *aTrack, int aNestLevel=0) const throw ( IO_ERROR )
 
void format (ZONE_CONTAINER *aZone, int aNestLevel=0) const throw ( IO_ERROR )
 
void formatLayer (const BOARD_ITEM *aItem) const
 
void formatLayers (LSET aLayerMask, int aNestLevel=0) const throw ( IO_ERROR )
 

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 88 of file pcbnew/kicad_plugin.h.

Constructor & Destructor Documentation

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 1752 of file kicad_plugin.cpp.

References init(), m_out, and m_sf.

1752  :
1753  m_cache( 0 ),
1754  m_ctl( aControlFlags ),
1755  m_parser( new PCB_PARSER() ),
1756  m_mapping( new NETINFO_MAPPING() )
1757 {
1758  init( 0 );
1759  m_out = &m_sf;
1760 }
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 1763 of file kicad_plugin.cpp.

References m_cache, m_mapping, and m_parser.

1764 {
1765  delete m_cache;
1766  delete m_parser;
1767  delete m_mapping;
1768 }
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 1824 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().

1825 {
1826  if( !m_cache || m_cache->IsModified( aLibraryPath, aFootprintName ) )
1827  {
1828  // a spectacular episode in memory management:
1829  delete m_cache;
1830  m_cache = new FP_CACHE( this, aLibraryPath );
1831  m_cache->Load();
1832  }
1833 }
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 1974 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().

1975 {
1976  LOCALE_IO toggle; // toggles on, then off, the C locale.
1977 
1978  init( aProperties );
1979 
1980  cacheLib( aLibraryPath );
1981 
1982  if( !m_cache->IsWritable() )
1983  {
1984  THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ),
1985  aLibraryPath.GetData() ) );
1986  }
1987 
1988  m_cache->Remove( aFootprintName );
1989 }
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)
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
void cacheLib(const wxString &aLibraryPath, const wxString &aFootprintName=wxEmptyString)
we only cache one footprint library, this determines which one.
wxArrayString PCB_IO::FootprintEnumerate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintEnumerate returns 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.
Returns
wxArrayString - is 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 1836 of file kicad_plugin.cpp.

References cacheLib(), Format(), FROM_UTF8(), GetChars(), FP_CACHE::GetModules(), init(), KiCadFootprintFileExtension, m_cache, and THROW_IO_ERROR.

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

1838 {
1839  LOCALE_IO toggle; // toggles on, then off, the C locale.
1840  wxArrayString ret;
1841  wxDir dir( aLibraryPath );
1842 
1843  if( !dir.IsOpened() )
1844  {
1845  THROW_IO_ERROR( wxString::Format( _( "footprint library path '%s' does not exist" ),
1846  GetChars( aLibraryPath ) ) );
1847  }
1848 
1849  init( aProperties );
1850 
1851 #if 1 // Set to 0 to only read directory contents, not load cache.
1852  cacheLib( aLibraryPath );
1853 
1854  const MODULE_MAP& mods = m_cache->GetModules();
1855 
1856 
1857  for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
1858  {
1859  ret.Add( FROM_UTF8( it->first.c_str() ) );
1860  }
1861 #else
1862  wxString fpFileName;
1863  wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
1864 
1865  if( dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) )
1866  {
1867  do
1868  {
1869  wxFileName fn( aLibraryPath, fpFileName );
1870  ret.Add( fn.GetName() );
1871  } while( dir.GetNext( &fpFileName ) );
1872  }
1873 #endif
1874 
1875  return ret;
1876 }
const wxString KiCadFootprintFileExtension
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
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 1992 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::FootprintLibCreate().

1993 {
1994  if( wxDir::Exists( aLibraryPath ) )
1995  {
1996  THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path '%s'" ),
1997  aLibraryPath.GetData() ) );
1998  }
1999 
2000  LOCALE_IO toggle;
2001 
2002  init( aProperties );
2003 
2004  delete m_cache;
2005  m_cache = new FP_CACHE( this, aLibraryPath );
2006  m_cache->Save();
2007 }
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)
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
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 2010 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::FootprintLibDelete().

2011 {
2012  wxFileName fn;
2013  fn.SetPath( aLibraryPath );
2014 
2015  // Return if there is no library path to delete.
2016  if( !fn.DirExists() )
2017  return false;
2018 
2019  if( !fn.IsDirWritable() )
2020  {
2021  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory '%s'" ),
2022  aLibraryPath.GetData() ) );
2023  }
2024 
2025  wxDir dir( aLibraryPath );
2026 
2027  if( dir.HasSubDirs() )
2028  {
2029  THROW_IO_ERROR( wxString::Format( _( "library directory '%s' has unexpected sub-directories" ),
2030  aLibraryPath.GetData() ) );
2031  }
2032 
2033  // All the footprint files must be deleted before the directory can be deleted.
2034  if( dir.HasFiles() )
2035  {
2036  unsigned i;
2037  wxFileName tmp;
2038  wxArrayString files;
2039 
2040  wxDir::GetAllFiles( aLibraryPath, &files );
2041 
2042  for( i = 0; i < files.GetCount(); i++ )
2043  {
2044  tmp = files[i];
2045 
2046  if( tmp.GetExt() != KiCadFootprintFileExtension )
2047  {
2048  THROW_IO_ERROR( wxString::Format( _( "unexpected file '%s' was found in library path '%s'" ),
2049  files[i].GetData(), aLibraryPath.GetData() ) );
2050  }
2051  }
2052 
2053  for( i = 0; i < files.GetCount(); i++ )
2054  {
2055  wxRemoveFile( files[i] );
2056  }
2057  }
2058 
2059  wxLogTrace( traceFootprintLibrary, wxT( "Removing footprint library '%s'" ),
2060  aLibraryPath.GetData() );
2061 
2062  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2063  // we don't want that. we want bare metal portability with no UI here.
2064  if( !wxRmdir( aLibraryPath ) )
2065  {
2066  THROW_IO_ERROR( wxString::Format( _( "footprint library '%s' cannot be deleted" ),
2067  aLibraryPath.GetData() ) );
2068  }
2069 
2070  // For some reason removing a directory in Windows is not immediately updated. This delay
2071  // prevents an error when attempting to immediately recreate the same directory when over
2072  // writing an existing library.
2073 #ifdef __WINDOWS__
2074  wxMilliSleep( 250L );
2075 #endif
2076 
2077  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2078  {
2079  delete m_cache;
2080  m_cache = NULL;
2081  }
2082 
2083  return true;
2084 }
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.
static const wxString traceFootprintLibrary(wxT("KicadFootprintLib"))
Definition for enabling and disabling footprint library trace output.
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
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 std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
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 1879 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::FootprintLoad().

1881 {
1882  LOCALE_IO toggle; // toggles on, then off, the C locale.
1883 
1884  init( aProperties );
1885 
1886  cacheLib( aLibraryPath, aFootprintName );
1887 
1888  const MODULE_MAP& mods = m_cache->GetModules();
1889 
1890  MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
1891 
1892  if( it == mods.end() )
1893  {
1894  return NULL;
1895  }
1896 
1897  // copy constructor to clone the already loaded MODULE
1898  return new MODULE( *it->second->GetModule() );
1899 }
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)
#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
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 1902 of file kicad_plugin.cpp.

References cacheLib(), CTL_FOR_LIBRARY, F_Cu, MODULE::Flip(), Format(), FROM_UTF8(), 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().

1904 {
1905  LOCALE_IO toggle; // toggles on, then off, the C locale.
1906 
1907  init( aProperties );
1908 
1909  // In this public PLUGIN API function, we can safely assume it was
1910  // called for saving into a library path.
1912 
1913  cacheLib( aLibraryPath );
1914 
1915  if( !m_cache->IsWritable() )
1916  {
1917  wxString msg = wxString::Format(
1918  _( "Library '%s' is read only" ),
1919  GetChars( aLibraryPath )
1920  );
1921 
1922  THROW_IO_ERROR( msg );
1923  }
1924 
1925  std::string footprintName = aFootprint->GetFPID().GetLibItemName();
1926 
1927  MODULE_MAP& mods = m_cache->GetModules();
1928 
1929  // Quietly overwrite module and delete module file from path for any by same name.
1930  wxFileName fn( aLibraryPath, FROM_UTF8( aFootprint->GetFPID().GetLibItemName() ),
1932 
1933  if( !fn.IsOk() )
1934  {
1935  THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
1936  GetChars( fn.GetFullPath() ) ) );
1937  }
1938 
1939  if( fn.FileExists() && !fn.IsFileWritable() )
1940  {
1941  THROW_IO_ERROR( wxString::Format( _( "user does not have write permission to delete file '%s' " ),
1942  GetChars( fn.GetFullPath() ) ) );
1943  }
1944 
1945  MODULE_CITER it = mods.find( footprintName );
1946 
1947  if( it != mods.end() )
1948  {
1949  wxLogTrace( traceFootprintLibrary, wxT( "Removing footprint library file '%s'." ),
1950  fn.GetFullPath().GetData() );
1951  mods.erase( footprintName );
1952  wxRemoveFile( fn.GetFullPath() );
1953  }
1954 
1955  // I need my own copy for the cache
1956  MODULE* module = new MODULE( *aFootprint );
1957 
1958  // and it's time stamp must be 0, it should have no parent, orientation should
1959  // be zero, and it should be on the front layer.
1960  module->SetTimeStamp( 0 );
1961  module->SetParent( 0 );
1962  module->SetOrientation( 0 );
1963 
1964  if( module->GetLayer() != F_Cu )
1965  module->Flip( module->GetPosition() );
1966 
1967  wxLogTrace( traceFootprintLibrary, wxT( "Creating s-expression footprint file: %s." ),
1968  fn.GetFullPath().GetData() );
1969  mods.insert( footprintName, new FP_CACHE_ITEM( module, fn ) );
1970  m_cache->Save();
1971 }
const wxString KiCadFootprintFileExtension
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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:143
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
const LIB_ID & GetFPID() const
Definition: class_module.h:151
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
static const wxString traceFootprintLibrary(wxT("KicadFootprintLib"))
Definition for enabling and disabling footprint library trace output.
std::map< std::string, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
void SetOrientation(double newangle)
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
throw (IO_ERROR
)

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 457 of file kicad_plugin.cpp.

References 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, and PCB_ZONE_AREA_T.

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

459 {
460  LOCALE_IO toggle; // public API function, perform anything convenient for caller
461 
462  switch( aItem->Type() )
463  {
464  case PCB_T:
465  format( static_cast<BOARD*>( aItem ), aNestLevel );
466  break;
467 
468  case PCB_DIMENSION_T:
469  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
470  break;
471 
472  case PCB_LINE_T:
473  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
474  break;
475 
476  case PCB_MODULE_EDGE_T:
477  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
478  break;
479 
480  case PCB_TARGET_T:
481  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
482  break;
483 
484  case PCB_MODULE_T:
485  format( static_cast<MODULE*>( aItem ), aNestLevel );
486  break;
487 
488  case PCB_PAD_T:
489  format( static_cast<D_PAD*>( aItem ), aNestLevel );
490  break;
491 
492  case PCB_TEXT_T:
493  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
494  break;
495 
496  case PCB_MODULE_TEXT_T:
497  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
498  break;
499 
500  case PCB_TRACE_T:
501  case PCB_VIA_T:
502  format( static_cast<TRACK*>( aItem ), aNestLevel );
503  break;
504 
505  case PCB_ZONE_AREA_T:
506  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
507  break;
508 
509  default:
510  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
511  }
512 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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
throw (IO_ERROR
)
private
Todo:
Add warning here that the old segment filed zones are no longer supported and will not be saved.

Definition at line 529 of file kicad_plugin.cpp.

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, NETCLASSES::begin(), Cmts_User, cu, DIM, Double2Str(), Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, NETCLASSES::end(), F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, filterNetClass(), FMTIU, Format(), NETCLASS::Format(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), EDA_RECT::GetBottom(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), D_PAD::GetDrillSize(), EDA_RECT::GetRight(), D_PAD::GetSize(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), EDA_RECT::GetX(), EDA_RECT::GetY(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, BOARD_DESIGN_SETTINGS::m_DrawSegmentWidth, BOARD_DESIGN_SETTINGS::m_EdgeSegmentWidth, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_ModuleSegmentWidth, BOARD_DESIGN_SETTINGS::m_ModuleTextSize, BOARD_DESIGN_SETTINGS::m_ModuleTextWidth, BOARD_DESIGN_SETTINGS::m_NetClasses, 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_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, Margin, TRACK::Next(), MODULE::Next(), BOARD_ITEM::Next(), and LAYER::ShowType().

531 {
532  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
533 
534  m_out->Print( 0, "\n" );
535 
536  m_out->Print( aNestLevel, "(general\n" );
537  m_out->Print( aNestLevel+1, "(links %d)\n", aBoard->GetRatsnestsCount() );
538  m_out->Print( aNestLevel+1, "(no_connects %d)\n", aBoard->GetUnconnectedNetCount() );
539 
540  // Write Bounding box info
541  EDA_RECT bbox = aBoard->GetBoundingBox();
542  m_out->Print( aNestLevel+1, "(area %s %s %s %s)\n",
543  FMTIU( bbox.GetX() ).c_str(), FMTIU( bbox.GetY() ).c_str(),
544  FMTIU( bbox.GetRight() ).c_str(), FMTIU( bbox.GetBottom() ).c_str() );
545  m_out->Print( aNestLevel+1, "(thickness %s)\n",
546  FMTIU( dsnSettings.GetBoardThickness() ).c_str() );
547 
548  m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->m_Drawings.GetCount() );
549  m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
550  m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
551  m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
552  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
553  m_out->Print( aNestLevel, ")\n\n" );
554 
555  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
556  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
557 
558  // Layers.
559  m_out->Print( aNestLevel, "(layers\n" );
560 
561  // Save only the used copper layers from front to back.
562  LSET visible_layers = aBoard->GetVisibleLayers();
563 
564  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
565  {
566  PCB_LAYER_ID layer = *cu;
567 
568  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
569  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
570  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
571 
572  if( !visible_layers[layer] )
573  m_out->Print( 0, " hide" );
574 
575  m_out->Print( 0, ")\n" );
576  }
577 
578  // Save used non-copper layers in the order they are defined.
579  // desired sequence for non Cu BOARD layers.
580  static const PCB_LAYER_ID non_cu[] = {
581  B_Adhes, // 32
582  F_Adhes,
583  B_Paste,
584  F_Paste,
585  B_SilkS,
586  F_SilkS,
587  B_Mask,
588  F_Mask,
589  Dwgs_User,
590  Cmts_User,
591  Eco1_User,
592  Eco2_User,
593  Edge_Cuts,
594  Margin,
595  B_CrtYd,
596  F_CrtYd,
597  B_Fab,
598  F_Fab
599  };
600 
601  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) ); seq; ++seq )
602  {
603  PCB_LAYER_ID layer = *seq;
604 
605  m_out->Print( aNestLevel+1, "(%d %s user", layer,
606  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
607 
608  if( !visible_layers[layer] )
609  m_out->Print( 0, " hide" );
610 
611  m_out->Print( 0, ")\n" );
612  }
613 
614  m_out->Print( aNestLevel, ")\n\n" );
615 
616  // Setup
617  m_out->Print( aNestLevel, "(setup\n" );
618 
619  // Save current default track width, for compatibility with older Pcbnew version;
620  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
621  FMTIU( dsnSettings.GetCurrentTrackWidth() ).c_str() );
622 
623  // Save custom tracks width list (the first is not saved here: this is the netclass value
624  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
625  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
626  FMTIU( dsnSettings.m_TrackWidthList[ii] ).c_str() );
627 
628  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
629  FMTIU( dsnSettings.GetDefault()->GetClearance() ).c_str() );
630 
631  // ZONE_SETTINGS
632  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
633  FMTIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
634  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
635  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
636 
637  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
638  FMTIU( dsnSettings.m_TrackMinWidth ).c_str() );
639 
640  m_out->Print( aNestLevel+1, "(segment_width %s)\n",
641  FMTIU( dsnSettings.m_DrawSegmentWidth ).c_str() );
642  m_out->Print( aNestLevel+1, "(edge_width %s)\n",
643  FMTIU( dsnSettings.m_EdgeSegmentWidth ).c_str() );
644 
645  // Save current default via size, for compatibility with older Pcbnew version;
646  m_out->Print( aNestLevel+1, "(via_size %s)\n",
647  FMTIU( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
648  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
649  FMTIU( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
650  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
651  FMTIU( dsnSettings.m_ViasMinSize ).c_str() );
652  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
653  FMTIU( dsnSettings.m_ViasMinDrill ).c_str() );
654 
655  // Save custom vias diameters list (the first is not saved here: this is
656  // the netclass value
657  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
658  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
659  FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
660  FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
661 
662  // for old versions compatibility:
663  if( dsnSettings.m_BlindBuriedViaAllowed )
664  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
665 
666  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
667  FMTIU( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
668  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
669  FMTIU( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
670  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
671  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
672  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
673  FMTIU( dsnSettings.m_MicroViasMinSize ).c_str() );
674  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
675  FMTIU( dsnSettings.m_MicroViasMinDrill ).c_str() );
676 
677  m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
678  FMTIU( dsnSettings.m_PcbTextWidth ).c_str() );
679  m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
680  FMTIU( dsnSettings.m_PcbTextSize.x ).c_str(),
681  FMTIU( dsnSettings.m_PcbTextSize.y ).c_str() );
682 
683  m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
684  FMTIU( dsnSettings.m_ModuleSegmentWidth ).c_str() );
685  m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
686  FMTIU( dsnSettings.m_ModuleTextSize.x ).c_str(),
687  FMTIU( dsnSettings.m_ModuleTextSize.y ).c_str() );
688  m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
689  FMTIU( dsnSettings.m_ModuleTextWidth ).c_str() );
690 
691  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
692  FMTIU( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
693  FMTIU( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
694  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
695  FMTIU( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
696 
697  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
698  FMTIU( dsnSettings.m_SolderMaskMargin ).c_str() );
699 
700  if( dsnSettings.m_SolderMaskMinWidth )
701  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
702  FMTIU( dsnSettings.m_SolderMaskMinWidth ).c_str() );
703 
704  if( dsnSettings.m_SolderPasteMargin != 0 )
705  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
706  FMTIU( dsnSettings.m_SolderPasteMargin ).c_str() );
707 
708  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
709  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
710  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
711 
712  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
713  FMTIU( aBoard->GetAuxOrigin().x ).c_str(),
714  FMTIU( aBoard->GetAuxOrigin().y ).c_str() );
715 
716  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
717  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
718  FMTIU( aBoard->GetGridOrigin().x ).c_str(),
719  FMTIU( aBoard->GetGridOrigin().y ).c_str() );
720 
721  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
722  dsnSettings.GetVisibleElements() );
723 
724  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
725 
726  m_out->Print( aNestLevel, ")\n\n" );
727 
728  // Save net codes and names
729  for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
730  net != netEnd; ++net )
731  {
732  m_out->Print( aNestLevel, "(net %d %s)\n",
733  m_mapping->Translate( net->GetNet() ),
734  m_out->Quotew( net->GetNetname() ).c_str() );
735  }
736 
737  m_out->Print( 0, "\n" );
738 
739  // Save the default net class first.
740  NETCLASS defaultNC = *dsnSettings.GetDefault();
741  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
742  defaultNC.Format( m_out, aNestLevel, m_ctl );
743 
744  // Save the rest of the net classes alphabetically.
745  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
746  it != dsnSettings.m_NetClasses.end();
747  ++it )
748  {
749  NETCLASS netclass = *it->second;
750  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
751  netclass.Format( m_out, aNestLevel, m_ctl );
752  }
753 
754  // Save the modules.
755  for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
756  {
757  Format( module, aNestLevel );
758  m_out->Print( 0, "\n" );
759  }
760 
761  // Save the graphical items on the board (not owned by a module)
762  for( BOARD_ITEM* item = aBoard->m_Drawings; item; item = item->Next() )
763  Format( item, aNestLevel );
764 
765  if( aBoard->m_Drawings.GetCount() )
766  m_out->Print( 0, "\n" );
767 
768  // Do not save MARKER_PCBs, they can be regenerated easily.
769 
770  // Save the tracks and vias.
771  for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
772  Format( track, aNestLevel );
773 
774  if( aBoard->m_Track.GetCount() )
775  m_out->Print( 0, "\n" );
776 
779 
780  // Save the polygon (which are the newer technology) zones.
781  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
782  Format( aBoard->GetArea( i ), aNestLevel );
783 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_SolderMaskMargin
Solder mask margin.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_board.h:827
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:554
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
NETCLASSPTR GetDefault() const
Function GetDefault.
unsigned GetUnconnectedNetCount() const
Function GetUnconnectedNetCount.
Definition: class_board.h:727
const wxPoint & GetGridOrigin() const
Definition: class_board.h:339
int m_SolderPasteMargin
Solder paste margin absolute value.
int m_ModuleTextWidth
Default footprint texts thickness.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
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:99
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:188
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
BOARD_ITEM * Next() const
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
iterator begin()
unsigned GetRatsnestsCount() const
Function GetNumRatsnests.
Definition: class_board.h:704
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:548
const wxSize & GetSize() const
Definition: class_pad.h:182
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:242
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:1051
int GetBottom() const
int GetRight() const
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:545
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:332
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:551
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
DLIST< MODULE > m_Modules
Definition: class_board.h:243
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.
Class EDA_RECT handles the component boundary box.
int GetX() const
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
int GetY() const
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:244
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.
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
throw (IO_ERROR
)
private

Definition at line 786 of file kicad_plugin.cpp.

References FMT_IU, and Format().

788 {
789  m_out->Print( aNestLevel, "(dimension %s (width %s)",
790  FMT_IU( aDimension->GetValue() ).c_str(),
791  FMT_IU( aDimension->GetWidth() ).c_str() );
792 
793  formatLayer( aDimension );
794 
795  if( aDimension->GetTimeStamp() )
796  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aDimension->GetTimeStamp() );
797 
798  m_out->Print( 0, "\n" );
799 
800  Format( &aDimension->Text(), aNestLevel+1 );
801 
802  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
803  FMT_IU( aDimension->m_featureLineDO.x ).c_str(),
804  FMT_IU( aDimension->m_featureLineDO.y ).c_str(),
805  FMT_IU( aDimension->m_featureLineDF.x ).c_str(),
806  FMT_IU( aDimension->m_featureLineDF.y ).c_str() );
807 
808  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
809  FMT_IU( aDimension->m_featureLineGO.x ).c_str(),
810  FMT_IU( aDimension->m_featureLineGO.y ).c_str(),
811  FMT_IU( aDimension->m_featureLineGF.x ).c_str(),
812  FMT_IU( aDimension->m_featureLineGF.y ).c_str() );
813 
814  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
815  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
816  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
817  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
818  FMT_IU( aDimension->m_crossBarF.y ).c_str() );
819 
820  m_out->Print( aNestLevel+1, "(arrow1a (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_arrowD1F.x ).c_str(),
824  FMT_IU( aDimension->m_arrowD1F.y ).c_str() );
825 
826  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
827  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
828  FMT_IU( aDimension->m_crossBarF.y ).c_str(),
829  FMT_IU( aDimension->m_arrowD2F.x ).c_str(),
830  FMT_IU( aDimension->m_arrowD2F.y ).c_str() );
831 
832  m_out->Print( aNestLevel+1, "(arrow2a (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_arrowG1F.x ).c_str(),
836  FMT_IU( aDimension->m_arrowG1F.y ).c_str() );
837 
838  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
839  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
840  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
841  FMT_IU( aDimension->m_arrowG2F.x ).c_str(),
842  FMT_IU( aDimension->m_arrowG2F.y ).c_str() );
843 
844  m_out->Print( aNestLevel, ")\n" );
845 }
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:204
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
throw (IO_ERROR
)
private

Definition at line 914 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

916 {
917  switch( aModuleDrawing->GetShape() )
918  {
919  case S_SEGMENT: // Line
920  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
921  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
922  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
923  break;
924 
925  case S_CIRCLE: // Circle
926  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
927  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
928  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
929  break;
930 
931  case S_ARC: // Arc
932  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
933  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
934  FMT_IU( aModuleDrawing->GetEnd0() ).c_str(),
935  FMT_ANGLE( aModuleDrawing->GetAngle() ).c_str() );
936  break;
937 
938  case S_POLYGON: // Polygon
939  m_out->Print( aNestLevel, "(fp_poly (pts" );
940 
941  for( unsigned i = 0; i < aModuleDrawing->GetPolyPoints().size(); ++i )
942  {
943  int nestLevel = 0;
944 
945  if( i && !(i%4) ) // newline every 4(pts)
946  {
947  nestLevel = aNestLevel + 1;
948  m_out->Print( 0, "\n" );
949  }
950 
951  m_out->Print( nestLevel, "%s(xy %s)",
952  nestLevel ? "" : " ",
953  FMT_IU( aModuleDrawing->GetPolyPoints()[i] ).c_str() );
954  }
955  m_out->Print( 0, ")" );
956  break;
957 
958  case S_CURVE: // Bezier curve
959  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
960  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
961  FMT_IU( aModuleDrawing->GetBezControl1() ).c_str(),
962  FMT_IU( aModuleDrawing->GetBezControl2() ).c_str(),
963  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
964  break;
965 
966  default:
967  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
968  };
969 
970  formatLayer( aModuleDrawing );
971 
972  m_out->Print( 0, " (width %s)", FMT_IU( aModuleDrawing->GetWidth() ).c_str() );
973 
974  m_out->Print( 0, ")\n" );
975 }
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
throw (IO_ERROR
)
private

Definition at line 848 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

850 {
851  unsigned i;
852 
853  switch( aSegment->GetShape() )
854  {
855  case S_SEGMENT: // Line
856  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
857  FMT_IU( aSegment->GetStart() ).c_str(),
858  FMT_IU( aSegment->GetEnd() ).c_str() );
859 
860  if( aSegment->GetAngle() != 0.0 )
861  m_out->Print( 0, " (angle %s)", FMT_ANGLE( aSegment->GetAngle() ).c_str() );
862 
863  break;
864 
865  case S_CIRCLE: // Circle
866  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
867  FMT_IU( aSegment->GetStart() ).c_str(),
868  FMT_IU( aSegment->GetEnd() ).c_str() );
869  break;
870 
871  case S_ARC: // Arc
872  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
873  FMT_IU( aSegment->GetStart() ).c_str(),
874  FMT_IU( aSegment->GetEnd() ).c_str(),
875  FMT_ANGLE( aSegment->GetAngle() ).c_str() );
876  break;
877 
878  case S_POLYGON: // Polygon
879  m_out->Print( aNestLevel, "(gr_poly (pts" );
880 
881  for( i = 0; i < aSegment->GetPolyPoints().size(); ++i )
882  m_out->Print( 0, " (xy %s)", FMT_IU( aSegment->GetPolyPoints()[i] ).c_str() );
883 
884  m_out->Print( 0, ")" );
885  break;
886 
887  case S_CURVE: // Bezier curve
888  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
889  FMT_IU( aSegment->GetStart() ).c_str(),
890  FMT_IU( aSegment->GetBezControl1() ).c_str(),
891  FMT_IU( aSegment->GetBezControl2() ).c_str(),
892  FMT_IU( aSegment->GetEnd() ).c_str() );
893  break;
894 
895  default:
896  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
897  };
898 
899  formatLayer( aSegment );
900 
901  if( aSegment->GetWidth() != 0 )
902  m_out->Print( 0, " (width %s)", FMT_IU( aSegment->GetWidth() ).c_str() );
903 
904  if( aSegment->GetTimeStamp() )
905  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aSegment->GetTimeStamp() );
906 
907  if( aSegment->GetStatus() )
908  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
909 
910  m_out->Print( 0, ")\n" );
911 }
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:250
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:204
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
throw (IO_ERROR
)
private

Definition at line 978 of file kicad_plugin.cpp.

References FMT_IU.

980 {
981  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
982  ( aTarget->GetShape() ) ? "x" : "plus",
983  FMT_IU( aTarget->GetPosition() ).c_str(),
984  FMT_IU( aTarget->GetSize() ).c_str() );
985 
986  if( aTarget->GetWidth() != 0 )
987  m_out->Print( 0, " (width %s)", FMT_IU( aTarget->GetWidth() ).c_str() );
988 
989  formatLayer( aTarget );
990 
991  if( aTarget->GetTimeStamp() )
992  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTarget->GetTimeStamp() );
993 
994  m_out->Print( 0, ")\n" );
995 }
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:204
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
throw (IO_ERROR
)
private

Definition at line 998 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(), MOD_CMS, MOD_DEFAULT, MOD_VIRTUAL, D_PAD::Next(), BOARD_ITEM::Next(), PAD_ZONE_CONN_INHERITED, and TO_UTF8.

1000 {
1001  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1002  {
1003  const wxArrayString* initial_comments = aModule->GetInitialComments();
1004 
1005  if( initial_comments )
1006  {
1007  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
1008  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1009 
1010  m_out->Print( 0, "\n" ); // improve readability?
1011  }
1012  }
1013 
1014  m_out->Print( aNestLevel, "(module %s",
1015  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1016 
1017  if( aModule->IsLocked() )
1018  m_out->Print( 0, " locked" );
1019 
1020  if( aModule->IsPlaced() )
1021  m_out->Print( 0, " placed" );
1022 
1023  formatLayer( aModule );
1024 
1025  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1026 
1027  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1028  {
1029  m_out->Print( 0, " (tstamp %lX)\n", (unsigned long)aModule->GetTimeStamp() );
1030  }
1031  else
1032  m_out->Print( 0, "\n" );
1033 
1034  if( !( m_ctl & CTL_OMIT_AT ) )
1035  {
1036  m_out->Print( aNestLevel+1, "(at %s", FMT_IU( aModule->GetPosition() ).c_str() );
1037 
1038  if( aModule->GetOrientation() != 0.0 )
1039  m_out->Print( 0, " %s", FMT_ANGLE( aModule->GetOrientation() ).c_str() );
1040 
1041  m_out->Print( 0, ")\n" );
1042  }
1043 
1044  if( !aModule->GetDescription().IsEmpty() )
1045  m_out->Print( aNestLevel+1, "(descr %s)\n",
1046  m_out->Quotew( aModule->GetDescription() ).c_str() );
1047 
1048  if( !aModule->GetKeywords().IsEmpty() )
1049  m_out->Print( aNestLevel+1, "(tags %s)\n",
1050  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1051 
1052  if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
1053  m_out->Print( aNestLevel+1, "(path %s)\n",
1054  m_out->Quotew( aModule->GetPath() ).c_str() );
1055 
1056  if( aModule->GetPlacementCost90() != 0 )
1057  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1058 
1059  if( aModule->GetPlacementCost180() != 0 )
1060  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1061 
1062  if( aModule->GetLocalSolderMaskMargin() != 0 )
1063  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1064  FMT_IU( aModule->GetLocalSolderMaskMargin() ).c_str() );
1065 
1066  if( aModule->GetLocalSolderPasteMargin() != 0 )
1067  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1068  FMT_IU( aModule->GetLocalSolderPasteMargin() ).c_str() );
1069 
1070  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1071  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1072  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1073 
1074  if( aModule->GetLocalClearance() != 0 )
1075  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1076  FMT_IU( aModule->GetLocalClearance() ).c_str() );
1077 
1078  if( aModule->GetZoneConnection() != PAD_ZONE_CONN_INHERITED )
1079  m_out->Print( aNestLevel+1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
1080 
1081  if( aModule->GetThermalWidth() != 0 )
1082  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1083  FMT_IU( aModule->GetThermalWidth() ).c_str() );
1084 
1085  if( aModule->GetThermalGap() != 0 )
1086  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1087  FMT_IU( aModule->GetThermalGap() ).c_str() );
1088 
1089  // Attributes
1090  if( aModule->GetAttributes() != MOD_DEFAULT )
1091  {
1092  m_out->Print( aNestLevel+1, "(attr" );
1093 
1094  if( aModule->GetAttributes() & MOD_CMS )
1095  m_out->Print( 0, " smd" );
1096 
1097  if( aModule->GetAttributes() & MOD_VIRTUAL )
1098  m_out->Print( 0, " virtual" );
1099 
1100  m_out->Print( 0, ")\n" );
1101  }
1102 
1103  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1104  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1105 
1106  // Save drawing elements.
1107  for( BOARD_ITEM* gr = aModule->GraphicalItems(); gr; gr = gr->Next() )
1108  Format( gr, aNestLevel+1 );
1109 
1110  // Save pads.
1111  for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
1112  format( pad, aNestLevel+1 );
1113 
1114  // Save 3D info.
1115  std::list<S3D_INFO>::const_iterator bs3D = aModule->Models().begin();
1116  std::list<S3D_INFO>::const_iterator es3D = aModule->Models().end();
1117 
1118  while( bs3D != es3D )
1119  {
1120  if( !bs3D->m_Filename.IsEmpty() )
1121  {
1122  m_out->Print( aNestLevel+1, "(model %s\n",
1123  m_out->Quotew( bs3D->m_Filename ).c_str() );
1124 
1125  m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n",
1126  Double2Str( bs3D->m_Offset.x ).c_str(),
1127  Double2Str( bs3D->m_Offset.y ).c_str(),
1128  Double2Str( bs3D->m_Offset.z ).c_str() );
1129 
1130  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1131  Double2Str( bs3D->m_Scale.x ).c_str(),
1132  Double2Str( bs3D->m_Scale.y ).c_str(),
1133  Double2Str( bs3D->m_Scale.z ).c_str() );
1134 
1135  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1136  Double2Str( bs3D->m_Rotation.x ).c_str(),
1137  Double2Str( bs3D->m_Rotation.y ).c_str(),
1138  Double2Str( bs3D->m_Rotation.z ).c_str() );
1139 
1140  m_out->Print( aNestLevel+1, ")\n" );
1141  }
1142  ++bs3D;
1143  }
1144 
1145  m_out->Print( aNestLevel, ")\n" );
1146 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
TEXTE_MODULE & Reference()
Definition: class_module.h:455
#define CTL_OMIT_AT
Omit position and rotation.
int GetThermalGap() const
Definition: class_module.h:182
time_t GetLastEditTime() const
Definition: class_module.h:271
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:166
const wxPoint & GetPosition() const override
Definition: class_module.h:143
void formatLayer(const BOARD_ITEM *aItem) const
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:76
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:176
std::list< S3D_INFO > & Models()
Definition: class_module.h:139
int GetPlacementCost90() const
Definition: class_module.h:525
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:172
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
BOARD_ITEM * Next() const
const LIB_ID & GetFPID() const
Definition: class_module.h:151
#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:147
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
D_PAD * Next() const
Definition: class_pad.h:106
#define FMT_IU
int GetAttributes() const
Definition: class_module.h:184
const wxString & GetKeywords() const
Definition: class_module.h:157
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
int GetLocalSolderMaskMargin() const
Definition: class_module.h:163
#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:223
int GetLocalSolderPasteMargin() const
Definition: class_module.h:169
time_t GetTimeStamp() const
Definition: base_struct.h:204
default
Definition: class_module.h:75
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:154
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:78
#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< D_PAD > & Pads()
Definition: class_module.h:133
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:160
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership. ...
Definition: class_module.h:643
#define FMT_ANGLE
bool IsPlaced() const
Definition: class_module.h:241
int GetPlacementCost180() const
Definition: class_module.h:522
int GetThermalWidth() const
Definition: class_module.h:179
void PCB_IO::format ( D_PAD aPad,
int  aNestLevel = 0 
) const
throw (IO_ERROR
)
private

Definition at line 1248 of file kicad_plugin.cpp.

References CTL_OMIT_NETS, Double2Str(), FMT_ANGLE, FMT_IU, Format(), PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, PAD_ZONE_CONN_INHERITED, StrPrintf(), THROW_IO_ERROR, NETINFO_LIST::UNCONNECTED, wxPoint::x, and wxPoint::y.

1250 {
1251  const char* shape;
1252 
1253  switch( aPad->GetShape() )
1254  {
1255  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1256  case PAD_SHAPE_RECT: shape = "rect"; break;
1257  case PAD_SHAPE_OVAL: shape = "oval"; break;
1258  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1259  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1260 
1261  default:
1262  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1263  }
1264 
1265  const char* type;
1266 
1267  switch( aPad->GetAttribute() )
1268  {
1269  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1270  case PAD_ATTRIB_SMD: type = "smd"; break;
1271  case PAD_ATTRIB_CONN: type = "connect"; break;
1272  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1273 
1274  default:
1275  THROW_IO_ERROR( wxString::Format( _( "unknown pad attribute: %d" ),
1276  aPad->GetAttribute() ) );
1277  }
1278 
1279  m_out->Print( aNestLevel, "(pad %s %s %s",
1280  m_out->Quotew( aPad->GetPadName() ).c_str(),
1281  type, shape );
1282  m_out->Print( 0, " (at %s", FMT_IU( aPad->GetPos0() ).c_str() );
1283 
1284  if( aPad->GetOrientation() != 0.0 )
1285  m_out->Print( 0, " %s", FMT_ANGLE( aPad->GetOrientation() ).c_str() );
1286 
1287  m_out->Print( 0, ")" );
1288  m_out->Print( 0, " (size %s)", FMT_IU( aPad->GetSize() ).c_str() );
1289 
1290  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1291  m_out->Print( 0, " (rect_delta %s )", FMT_IU( aPad->GetDelta() ).c_str() );
1292 
1293  wxSize sz = aPad->GetDrillSize();
1294  wxPoint shapeoffset = aPad->GetOffset();
1295 
1296  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1297  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1298  {
1299  m_out->Print( 0, " (drill" );
1300 
1301  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1302  m_out->Print( 0, " oval" );
1303 
1304  if( sz.GetWidth() > 0 )
1305  m_out->Print( 0, " %s", FMT_IU( sz.GetWidth() ).c_str() );
1306 
1307  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1308  m_out->Print( 0, " %s", FMT_IU( sz.GetHeight() ).c_str() );
1309 
1310  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1311  m_out->Print( 0, " (offset %s)", FMT_IU( aPad->GetOffset() ).c_str() );
1312 
1313  m_out->Print( 0, ")" );
1314  }
1315 
1316  formatLayers( aPad->GetLayerSet(), 0 );
1317 
1318  // Output the radius ratio for rounded rect pads
1319  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
1320  {
1321  m_out->Print( 0, "(roundrect_rratio %s)",
1322  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1323  }
1324 
1325  std::string output;
1326 
1327  // Unconnected pad is default net so don't save it.
1328  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1329  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1330  m_out->Quotew( aPad->GetNetname() ).c_str() );
1331 
1332  if( aPad->GetPadToDieLength() != 0 )
1333  StrPrintf( &output, " (die_length %s)", FMT_IU( aPad->GetPadToDieLength() ).c_str() );
1334 
1335  if( aPad->GetLocalSolderMaskMargin() != 0 )
1336  StrPrintf( &output, " (solder_mask_margin %s)", FMT_IU( aPad->GetLocalSolderMaskMargin() ).c_str() );
1337 
1338  if( aPad->GetLocalSolderPasteMargin() != 0 )
1339  StrPrintf( &output, " (solder_paste_margin %s)", FMT_IU( aPad->GetLocalSolderPasteMargin() ).c_str() );
1340 
1341  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1342  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1343  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1344 
1345  if( aPad->GetLocalClearance() != 0 )
1346  StrPrintf( &output, " (clearance %s)", FMT_IU( aPad->GetLocalClearance() ).c_str() );
1347 
1349  StrPrintf( &output, " (zone_connect %d)", aPad->GetZoneConnection() );
1350 
1351  if( aPad->GetThermalWidth() != 0 )
1352  StrPrintf( &output, " (thermal_width %s)", FMT_IU( aPad->GetThermalWidth() ).c_str() );
1353 
1354  if( aPad->GetThermalGap() != 0 )
1355  StrPrintf( &output, " (thermal_gap %s)", FMT_IU( aPad->GetThermalGap() ).c_str() );
1356 
1357  if( output.size() )
1358  {
1359  m_out->Print( 0, "\n" );
1360  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1361  }
1362 
1363  m_out->Print( 0, ")\n" );
1364 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:238
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
int GetPadToDieLength() const
Definition: class_pad.h:241
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:243
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
const wxPoint & GetPos0() const
Definition: class_pad.h:176
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:221
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:188
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
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 Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
ZoneConnection GetZoneConnection() const
Definition: class_pad.cpp:610
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:235
int GetThermalWidth() const
Definition: class_pad.cpp:621
int GetThermalGap() const
Definition: class_pad.cpp:632
const wxSize & GetSize() const
Definition: class_pad.h:182
#define FMT_IU
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:249
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
#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:60
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
int GetLocalClearance() const
Definition: class_pad.h:246
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:252
int GetNetCode() const
Function GetNetCode.
const wxString & GetNetname() const
Function GetNetname.
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:450
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
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
const wxSize & GetDelta() const
Definition: class_pad.h:185
Usual pad.
Definition: pad_shapes.h:58
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
wxString GetPadName() const
Definition: class_pad.cpp:433
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 ...
const wxPoint & GetOffset() const
Definition: class_pad.h:191
void PCB_IO::format ( TEXTE_PCB aText,
int  aNestLevel = 0 
) const
throw (IO_ERROR
)
private

Definition at line 1367 of file kicad_plugin.cpp.

References FMT_ANGLE, and FMT_IU.

1369 {
1370  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1371  m_out->Quotew( aText->GetText() ).c_str(),
1372  FMT_IU( aText->GetTextPos() ).c_str() );
1373 
1374  if( aText->GetTextAngle() != 0.0 )
1375  m_out->Print( 0, " %s", FMT_ANGLE( aText->GetTextAngle() ).c_str() );
1376 
1377  m_out->Print( 0, ")" );
1378 
1379  formatLayer( aText );
1380 
1381  if( aText->GetTimeStamp() )
1382  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aText->GetTimeStamp() );
1383 
1384  m_out->Print( 0, "\n" );
1385 
1386  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1387 
1388  m_out->Print( aNestLevel, ")\n" );
1389 }
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:204
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
throw (IO_ERROR
)
private

Definition at line 1392 of file kicad_plugin.cpp.

References CTL_OMIT_HIDE, FMT_ANGLE, FMT_IU, MODULE::GetOrientation(), BOARD_ITEM::GetParent(), NormalizeAngle360(), NormalizeAnglePos(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, and TEXTE_MODULE::TEXT_is_VALUE.

1394 {
1395  wxString type;
1396 
1397  switch( aText->GetType() )
1398  {
1399  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1400  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1401  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1402  }
1403 
1404  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1405  m_out->Quotew( type ).c_str(),
1406  m_out->Quotew( aText->GetText() ).c_str(),
1407  FMT_IU( aText->GetPos0() ).c_str() );
1408 
1409  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1410  // but internally the angle is held relative to its parent footprint. parent
1411  // may be NULL when saving a footprint outside a BOARD.
1412  double orient = aText->GetTextAngle();
1413  MODULE* parent = (MODULE*) aText->GetParent();
1414 
1415  if( parent )
1416  {
1417  // GetTextAngle() is always in -360..+360 range because of
1418  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1419  // additional board angle could kick sum up >= 360 or <= -360, so to have
1420  // consistent results, normalize again for the BOARD save. A footprint
1421  // save does not use this code path since parent is NULL.
1422 #if 0
1423  // This one could be considered reasonable if you like positive angles
1424  // in your board text.
1425  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1426 #else
1427  // Choose compatibility for now, even though this is only a 720 degree clamp
1428  // with two possible values for every angle.
1429  orient = NormalizeAngle360( orient + parent->GetOrientation() );
1430 #endif
1431  }
1432 
1433  if( orient != 0.0 )
1434  m_out->Print( 0, " %s", FMT_ANGLE( orient ).c_str() );
1435 
1436  m_out->Print( 0, ")" );
1437  formatLayer( aText );
1438 
1439  if( !aText->IsVisible() )
1440  m_out->Print( 0, " hide" );
1441 
1442  m_out->Print( 0, "\n" );
1443 
1444  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1445 
1446  m_out->Print( aNestLevel, ")\n" );
1447 }
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:147
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
throw (IO_ERROR
)
private

Definition at line 1450 of file kicad_plugin.cpp.

References FMT_IU, Format(), VIA::GetDrill(), BOARD_ITEM::GetParent(), VIA::GetSelectMenuText(), VIA::GetViaType(), VIA::LayerPair(), PCB_VIA_T, THROW_IO_ERROR, UNDEFINED_DRILL_DIAMETER, VIA_BLIND_BURIED, VIA_MICROVIA, and VIA_THROUGH.

1452 {
1453  if( aTrack->Type() == PCB_VIA_T )
1454  {
1455  PCB_LAYER_ID layer1, layer2;
1456 
1457  const VIA* via = static_cast<const VIA*>(aTrack);
1458  BOARD* board = (BOARD*) via->GetParent();
1459 
1460  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText() +
1461  wxT( " has no parent." ) );
1462 
1463  m_out->Print( aNestLevel, "(via" );
1464 
1465  via->LayerPair( &layer1, &layer2 );
1466 
1467  switch( via->GetViaType() )
1468  {
1469  case VIA_THROUGH: // Default shape not saved.
1470  break;
1471 
1472  case VIA_BLIND_BURIED:
1473  m_out->Print( 0, " blind" );
1474  break;
1475 
1476  case VIA_MICROVIA:
1477  m_out->Print( 0, " micro" );
1478  break;
1479 
1480  default:
1481  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1482  }
1483 
1484  m_out->Print( 0, " (at %s) (size %s)",
1485  FMT_IU( aTrack->GetStart() ).c_str(),
1486  FMT_IU( aTrack->GetWidth() ).c_str() );
1487 
1488  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1489  m_out->Print( 0, " (drill %s)", FMT_IU( via->GetDrill() ).c_str() );
1490 
1491  m_out->Print( 0, " (layers %s %s)",
1492  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1493  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1494  }
1495  else
1496  {
1497  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1498  FMT_IU( aTrack->GetStart() ).c_str(), FMT_IU( aTrack->GetEnd() ).c_str(),
1499  FMT_IU( aTrack->GetWidth() ).c_str() );
1500 
1501  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1502  }
1503 
1504  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1505 
1506  if( aTrack->GetTimeStamp() != 0 )
1507  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTrack->GetTimeStamp() );
1508 
1509  if( aTrack->GetStatus() != 0 )
1510  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1511 
1512  m_out->Print( 0, ")\n" );
1513 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
BOARD_ITEM_CONTAINER * GetParent() const
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:250
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:461
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:446
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 THROW_IO_ERROR(x)
Definition: utf8.cpp:60
#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:204
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:166
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
void PCB_IO::format ( ZONE_CONTAINER aZone,
int  aNestLevel = 0 
) const
throw (IO_ERROR
)
private

Definition at line 1516 of file kicad_plugin.cpp.

References SHAPE_POLY_SET::CIterate(), ZONE_CONTAINER::DIAGONAL_EDGE, ZONE_CONTAINER::DIAGONAL_FULL, FMT_IU, Format(), SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_NONE, PAD_ZONE_CONN_THERMAL, PAD_ZONE_CONN_THT_THERMAL, ZONE_SETTINGS::SMOOTHING_CHAMFER, ZONE_SETTINGS::SMOOTHING_FILLET, ZONE_SETTINGS::SMOOTHING_NONE, and THROW_IO_ERROR.

1518 {
1519  // Save the NET info; For keepout zones, net code and net name are irrelevant
1520  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1521  // (perhaps netcode and netname should be not stored)
1522  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1523  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1524  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1525 
1526  formatLayer( aZone );
1527 
1528  m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
1529 
1530  // Save the outline aux info
1531  std::string hatch;
1532 
1533  switch( aZone->GetHatchStyle() )
1534  {
1535  default:
1536  case ZONE_CONTAINER::NO_HATCH: hatch = "none"; break;
1537  case ZONE_CONTAINER::DIAGONAL_EDGE: hatch = "edge"; break;
1538  case ZONE_CONTAINER::DIAGONAL_FULL: hatch = "full"; break;
1539  }
1540 
1541  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1542  FMT_IU( aZone->GetHatchPitch() ).c_str() );
1543 
1544  if( aZone->GetPriority() > 0 )
1545  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1546 
1547  m_out->Print( aNestLevel+1, "(connect_pads" );
1548 
1549  switch( aZone->GetPadConnection() )
1550  {
1551  default:
1552  case PAD_ZONE_CONN_THERMAL: // Default option not saved or loaded.
1553  break;
1554 
1556  m_out->Print( 0, " thru_hole_only" );
1557  break;
1558 
1559  case PAD_ZONE_CONN_FULL:
1560  m_out->Print( 0, " yes" );
1561  break;
1562 
1563  case PAD_ZONE_CONN_NONE:
1564  m_out->Print( 0, " no" );
1565  break;
1566  }
1567 
1568  m_out->Print( 0, " (clearance %s))\n",
1569  FMT_IU( aZone->GetZoneClearance() ).c_str() );
1570 
1571  m_out->Print( aNestLevel+1, "(min_thickness %s)\n",
1572  FMT_IU( aZone->GetMinThickness() ).c_str() );
1573 
1574  if( aZone->GetIsKeepout() )
1575  {
1576  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
1577  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1578  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1579  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
1580  }
1581 
1582  m_out->Print( aNestLevel+1, "(fill" );
1583 
1584  // Default is not filled.
1585  if( aZone->IsFilled() )
1586  m_out->Print( 0, " yes" );
1587 
1588  // Default is polygon filled.
1589  if( aZone->GetFillMode() )
1590  m_out->Print( 0, " (mode segment)" );
1591 
1592  m_out->Print( 0, " (arc_segments %d) (thermal_gap %s) (thermal_bridge_width %s)",
1593  aZone->GetArcSegmentCount(),
1594  FMT_IU( aZone->GetThermalReliefGap() ).c_str(),
1595  FMT_IU( aZone->GetThermalReliefCopperBridge() ).c_str() );
1596 
1598  {
1599  m_out->Print( 0, " (smoothing" );
1600 
1601  switch( aZone->GetCornerSmoothingType() )
1602  {
1604  m_out->Print( 0, " chamfer" );
1605  break;
1606 
1608  m_out->Print( 0, " fillet" );
1609  break;
1610 
1611  default:
1612  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1613  aZone->GetCornerSmoothingType() ) );
1614  }
1615  m_out->Print( 0, ")" );
1616 
1617  if( aZone->GetCornerRadius() != 0 )
1618  m_out->Print( 0, " (radius %s)",
1619  FMT_IU( aZone->GetCornerRadius() ).c_str() );
1620  }
1621 
1622  m_out->Print( 0, ")\n" );
1623 
1624  int newLine = 0;
1625 
1626  if( aZone->GetNumCorners() )
1627  {
1628  bool new_polygon = true;
1629  bool is_closed = false;
1630 
1631  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1632  {
1633  if( new_polygon )
1634  {
1635  newLine = 0;
1636  m_out->Print( aNestLevel+1, "(polygon\n" );
1637  m_out->Print( aNestLevel+2, "(pts\n" );
1638  new_polygon = false;
1639  is_closed = false;
1640  }
1641 
1642  if( newLine == 0 )
1643  m_out->Print( aNestLevel+3, "(xy %s %s)",
1644  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1645  else
1646  m_out->Print( 0, " (xy %s %s)",
1647  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1648 
1649  if( newLine < 4 )
1650  {
1651  newLine += 1;
1652  }
1653  else
1654  {
1655  newLine = 0;
1656  m_out->Print( 0, "\n" );
1657  }
1658 
1659  if( iterator.IsEndContour() )
1660  {
1661  is_closed = true;
1662 
1663  if( newLine != 0 )
1664  m_out->Print( 0, "\n" );
1665 
1666  m_out->Print( aNestLevel+2, ")\n" );
1667  m_out->Print( aNestLevel+1, ")\n" );
1668  new_polygon = true;
1669  }
1670  }
1671 
1672  if( !is_closed ) // Should not happen, but...
1673  m_out->Print( aNestLevel+1, ")\n" );
1674 
1675  }
1676 
1677  // Save the PolysList (filled areas)
1678  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1679  newLine = 0;
1680 
1681  if( !fv.IsEmpty() )
1682  {
1683  bool new_polygon = true;
1684  bool is_closed = false;
1685 
1686  for( auto it = fv.CIterate(); it; ++it )
1687  {
1688  if( new_polygon )
1689  {
1690  newLine = 0;
1691  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1692  m_out->Print( aNestLevel+2, "(pts\n" );
1693  new_polygon = false;
1694  is_closed = false;
1695  }
1696 
1697  if( newLine == 0 )
1698  m_out->Print( aNestLevel+3, "(xy %s %s)",
1699  FMT_IU( it->x ).c_str(), FMT_IU( it->y ).c_str() );
1700  else
1701  m_out->Print( 0, " (xy %s %s)",
1702  FMT_IU( it->x ) .c_str(), FMT_IU( it->y ).c_str() );
1703 
1704  if( newLine < 4 )
1705  {
1706  newLine += 1;
1707  }
1708  else
1709  {
1710  newLine = 0;
1711  m_out->Print( 0, "\n" );
1712  }
1713 
1714  if( it.IsEndContour() )
1715  {
1716  is_closed = true;
1717 
1718  if( newLine != 0 )
1719  m_out->Print( 0, "\n" );
1720 
1721  m_out->Print( aNestLevel+2, ")\n" );
1722  m_out->Print( aNestLevel+1, ")\n" );
1723  new_polygon = true;
1724  }
1725  }
1726 
1727  if( !is_closed ) // Should not happen, but...
1728  m_out->Print( aNestLevel+1, ")\n" );
1729  }
1730 
1731  // Save the filling segments list
1732  const std::vector< SEGMENT >& segs = aZone->FillSegments();
1733 
1734  if( segs.size() )
1735  {
1736  m_out->Print( aNestLevel+1, "(fill_segments\n" );
1737 
1738  for( std::vector< SEGMENT >::const_iterator it = segs.begin(); it != segs.end(); ++it )
1739  {
1740  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
1741  FMT_IU( it->m_Start ).c_str(),
1742  FMT_IU( it->m_End ).c_str() );
1743  }
1744 
1745  m_out->Print( aNestLevel+1, ")\n" );
1746  }
1747 
1748  m_out->Print( aNestLevel, ")\n" );
1749 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:466
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:617
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:466
unsigned int GetCornerRadius() const
Definition: class_zone.h:621
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:814
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:457
#define FMT_IU
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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:587
Thermal relief only for THT pads.
Definition: zones.h:60
time_t GetTimeStamp() const
Definition: base_struct.h:204
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:486
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:554
int GetHatchPitch() const
Hatch related methods.
Definition: class_zone.cpp:896
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
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 515 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.

516 {
517  if( m_ctl & CTL_STD_LAYER_NAMES )
518  {
519  PCB_LAYER_ID layer = aItem->GetLayer();
520 
521  // English layer names should never need quoting.
522  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
523  }
524  else
525  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
526 }
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:646
void PCB_IO::formatLayers ( LSET  aLayerMask,
int  aNestLevel = 0 
) const
throw (IO_ERROR
)
private

Definition at line 1149 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::GetStandardLayerName(), and PCB_LAYER_ID_COUNT.

1151 {
1152  std::string output;
1153 
1154  if( aNestLevel == 0 )
1155  output += ' ';
1156 
1157  output += "(layers";
1158 
1159  static const LSET cu_all( LSET::AllCuMask() );
1160  static const LSET fr_bk( 2, B_Cu, F_Cu );
1161  static const LSET adhes( 2, B_Adhes, F_Adhes );
1162  static const LSET paste( 2, B_Paste, F_Paste );
1163  static const LSET silks( 2, B_SilkS, F_SilkS );
1164  static const LSET mask( 2, B_Mask, F_Mask );
1165  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1166  static const LSET fab( 2, B_Fab, F_Fab );
1167 
1168  LSET cu_mask = cu_all;
1169 
1170  if( m_board )
1171  cu_mask &= m_board->GetEnabledLayers();
1172 
1173  // output copper layers first, then non copper
1174 
1175  if( ( aLayerMask & cu_mask ) == cu_mask )
1176  {
1177  output += " *.Cu";
1178  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1179  }
1180  else if( ( aLayerMask & cu_mask ) == fr_bk )
1181  {
1182  output += " F&B.Cu";
1183  aLayerMask &= ~fr_bk;
1184  }
1185 
1186  if( ( aLayerMask & adhes ) == adhes )
1187  {
1188  output += " *.Adhes";
1189  aLayerMask &= ~adhes;
1190  }
1191 
1192  if( ( aLayerMask & paste ) == paste )
1193  {
1194  output += " *.Paste";
1195  aLayerMask &= ~paste;
1196  }
1197 
1198  if( ( aLayerMask & silks ) == silks )
1199  {
1200  output += " *.SilkS";
1201  aLayerMask &= ~silks;
1202  }
1203 
1204  if( ( aLayerMask & mask ) == mask )
1205  {
1206  output += " *.Mask";
1207  aLayerMask &= ~mask;
1208  }
1209 
1210  if( ( aLayerMask & crt_yd ) == crt_yd )
1211  {
1212  output += " *.CrtYd";
1213  aLayerMask &= ~crt_yd;
1214  }
1215 
1216  if( ( aLayerMask & fab ) == fab )
1217  {
1218  output += " *.Fab";
1219  aLayerMask &= ~fab;
1220  }
1221 
1222  // output any individual layers not handled in wildcard combos above
1223 
1224  if( m_board )
1225  aLayerMask &= m_board->GetEnabledLayers();
1226 
1227  wxString layerName;
1228 
1229  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1230  {
1231  if( aLayerMask[layer] )
1232  {
1233  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1234  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1235 
1236  else // I am being called from FootprintSave()
1237  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1238 
1239  output += ' ';
1240  output += m_out->Quotew( layerName );
1241  }
1242  }
1243 
1244  m_out->Print( aNestLevel, "%s)", output.c_str() );
1245 }
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:646
const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

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

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

Definition at line 149 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().

150  {
151  std::string ret = m_sf.GetString();
152  if( doClear )
153  m_sf.Clear();
154 
155  return ret;
156  }
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 1815 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().

1816 {
1817  m_board = NULL;
1818  m_reader = NULL;
1820  m_props = aProperties;
1821 }
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 2087 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::IsFootprintLibWritable().

2088 {
2089  LOCALE_IO toggle;
2090 
2091  init( NULL );
2092 
2093  cacheLib( aLibraryPath );
2094 
2095  return m_cache->IsWritable();
2096 }
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 1771 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.

1772 {
1773  FILE_LINE_READER reader( aFileName );
1774 
1775  init( aProperties );
1776 
1777  m_parser->SetLineReader( &reader );
1778  m_parser->SetBoard( aAppendToMe );
1779 
1780  BOARD* board;
1781 
1782  try
1783  {
1784  board = dynamic_cast<BOARD*>( m_parser->Parse() );
1785  }
1786  catch( const FUTURE_FORMAT_ERROR& )
1787  {
1788  // Don't wrap a FUTURE_FORMAT_ERROR in another
1789  throw;
1790  }
1791  catch( const PARSE_ERROR& parse_error )
1792  {
1793  if( m_parser->IsTooRecent() )
1794  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
1795  else
1796  throw;
1797  }
1798 
1799  if( !board )
1800  {
1801  // The parser loaded something that was valid, but wasn't a board.
1802  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
1805  }
1806 
1807  // Give the filename to the board if it's new
1808  if( !aAppendToMe )
1809  board->SetFileName( aFileName );
1810 
1811  return board;
1812 }
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:235
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:166
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)
throw ( FUTURE_FORMAT_ERROR,
PARSE_ERROR,
IO_ERROR
)

Definition at line 434 of file kicad_plugin.cpp.

References TO_UTF8.

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

436 {
437  std::string input = TO_UTF8( aClipboardSourceInput );
438 
439  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
440 
441  m_parser->SetLineReader( &reader );
442 
443  try
444  {
445  return m_parser->Parse();
446  }
447  catch( const PARSE_ERROR& parse_error )
448  {
449  if( m_parser->IsTooRecent() )
450  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
451  else
452  throw;
453  }
454 }
#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 96 of file pcbnew/kicad_plugin.h.

97  {
98  return wxT( "KiCad" );
99  }
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 410 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.

411 {
412  LOCALE_IO toggle; // toggles on, then off, the C locale.
413 
414  init( aProperties );
415 
416  m_board = aBoard; // after init()
417 
418  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
419  m_mapping->SetBoard( aBoard );
420 
421  FILE_OUTPUTFORMATTER formatter( aFileName );
422 
423  m_out = &formatter; // no ownership
424 
425  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
426  formatter.Quotew( GetBuildVersion() ).c_str() );
427 
428  Format( aBoard, 1 );
429 
430  m_out->Print( 0, ")\n" );
431 }
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 158 of file pcbnew/kicad_plugin.h.

References m_out.

Referenced by FP_CACHE::Save().

158 { 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 90 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 166 of file pcbnew/kicad_plugin.h.

Referenced by init(), and Save().

int PCB_IO::m_ctl
protected

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

Referenced by FootprintSave(), and formatLayer().

wxString PCB_IO::m_error
protected

for throwing exceptions

Definition at line 165 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 173 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 175 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 181 of file pcbnew/kicad_plugin.h.

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

OUTPUTFORMATTER* PCB_IO::m_out
protected

output any Format()s to this, no ownership

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

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

PCB_PARSER* PCB_IO::m_parser
protected

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

Referenced by GITHUB_PLUGIN::FootprintLoad(), Load(), FP_CACHE::Load(), and ~PCB_IO().

const PROPERTIES* PCB_IO::m_props
protected

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

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

Referenced by init().

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

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

Referenced by init().

STRING_FORMATTER PCB_IO::m_sf
protected

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

Referenced by GetStringOutput(), and PCB_IO().


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