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 CLIPBOARD_IO 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...
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL) override
 Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
 Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
MODULELoadEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. 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...
 
long long GetLibraryTimestamp (const wxString &aLibraryPath) const override
 Generate a timestamp representing all the files in the library (including the library directory). More...
 
void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
 PCB_IO (int aControlFlags=CTL_FOR_BOARD)
 
 ~PCB_IO ()
 
void Format (BOARD_ITEM *aItem, int aNestLevel=0) const
 Function Format outputs aItem to aFormatter in s-expression format. More...
 
std::string GetStringOutput (bool doClear)
 
void SetOutputFormatter (OUTPUTFORMATTER *aFormatter)
 
BOARD_ITEMParse (const wxString &aClipboardSourceInput)
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Protected Member Functions

void validateCache (const wxString &aLibraryPath, bool checkModified=true)
 
MODULEdoLoadFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
 
void init (const PROPERTIES *aProperties)
 
void formatSetup (BOARD *aBoard, int aNestLevel=0) const
 formats the board setup information More...
 
void formatGeneral (BOARD *aBoard, int aNestLevel=0) const
 formats the General section of the file More...
 
void formatBoardLayers (BOARD *aBoard, int aNestLevel=0) const
 formats the board layer information More...
 
void formatNetInformation (BOARD *aBoard, int aNestLevel=0) const
 formats the Nets and Netclasses More...
 
void formatHeader (BOARD *aBoard, int aNestLevel=0) const
 writes everything that comes before the board_items, like settings and layers etc More...
 

Protected Attributes

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

Private Member Functions

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

Friends

class FP_CACHE
 

Detailed Description

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

Note
This class is not thread safe, but it is re-entrant multiple times in sequence.

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

Constructor & Destructor Documentation

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 1893 of file kicad_plugin.cpp.

References init(), m_out, and m_sf.

Referenced by GetFileExtension().

1893  :
1894  m_cache( 0 ),
1895  m_ctl( aControlFlags ),
1896  m_parser( new PCB_PARSER() ),
1897  m_mapping( new NETINFO_MAPPING() )
1898 {
1899  init( 0 );
1900  m_out = &m_sf;
1901 }
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:65
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 1904 of file kicad_plugin.cpp.

References m_cache, m_mapping, and m_parser.

Referenced by GetFileExtension().

1905 {
1906  delete m_cache;
1907  delete m_parser;
1908  delete m_mapping;
1909 }
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

MODULE * PCB_IO::doLoadFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties,
bool  checkModified 
)
protected

Definition at line 2012 of file kicad_plugin.cpp.

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

Referenced by FootprintLoad(), and LoadEnumeratedFootprint().

2016 {
2017  LOCALE_IO toggle; // toggles on, then off, the C locale.
2018 
2019  init( aProperties );
2020 
2021  try
2022  {
2023  validateCache( aLibraryPath, checkModified );
2024  }
2025  catch( const IO_ERROR& )
2026  {
2027  // do nothing with the error
2028  }
2029 
2030  const MODULE_MAP& mods = m_cache->GetModules();
2031 
2032  MODULE_CITER it = mods.find( aFootprintName );
2033 
2034  if( it == mods.end() )
2035  {
2036  return NULL;
2037  }
2038 
2039  // copy constructor to clone the already loaded MODULE
2040  return new MODULE( *it->second->GetModule() );
2041 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()
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 2147 of file kicad_plugin.cpp.

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

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

2149 {
2150  LOCALE_IO toggle; // toggles on, then off, the C locale.
2151 
2152  init( aProperties );
2153 
2154  validateCache( aLibraryPath );
2155 
2156  if( !m_cache->IsWritable() )
2157  {
2158  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only" ),
2159  aLibraryPath.GetData() ) );
2160  }
2161 
2162  m_cache->Remove( aFootprintName );
2163 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void PCB_IO::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

Reimplemented from PLUGIN.

Definition at line 1977 of file kicad_plugin.cpp.

References FP_CACHE::GetModules(), init(), m_cache, THROW_IO_ERROR, validateCache(), and IO_ERROR::What().

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

1980 {
1981  LOCALE_IO toggle; // toggles on, then off, the C locale.
1982  wxDir dir( aLibraryPath );
1983 
1984  init( aProperties );
1985 
1986  wxString errorMsg;
1987 
1988  try
1989  {
1990  validateCache( aLibraryPath );
1991  }
1992  catch( const IO_ERROR& ioe )
1993  {
1994  errorMsg = ioe.What();
1995  }
1996 
1997  // Some of the files may have been parsed correctly so we want to add the valid files to
1998  // the library.
1999 
2000  const MODULE_MAP& mods = m_cache->GetModules();
2001 
2002  for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
2003  {
2004  aFootprintNames.Add( it->first );
2005  }
2006 
2007  if( !errorMsg.IsEmpty() )
2008  THROW_IO_ERROR( errorMsg );
2009 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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 2177 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::FootprintLibCreate(), and GetFileExtension().

2178 {
2179  if( wxDir::Exists( aLibraryPath ) )
2180  {
2181  THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path \"%s\"" ),
2182  aLibraryPath.GetData() ) );
2183  }
2184 
2185  LOCALE_IO toggle;
2186 
2187  init( aProperties );
2188 
2189  delete m_cache;
2190  m_cache = new FP_CACHE( this, aLibraryPath );
2191  m_cache->Save();
2192 }
friend class FP_CACHE
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
bool PCB_IO::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain footprints.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
bool - true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented from PLUGIN.

Definition at line 2195 of file kicad_plugin.cpp.

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

Referenced by GITHUB_PLUGIN::FootprintLibDelete(), and GetFileExtension().

2196 {
2197  wxFileName fn;
2198  fn.SetPath( aLibraryPath );
2199 
2200  // Return if there is no library path to delete.
2201  if( !fn.DirExists() )
2202  return false;
2203 
2204  if( !fn.IsDirWritable() )
2205  {
2206  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory \"%s\"" ),
2207  aLibraryPath.GetData() ) );
2208  }
2209 
2210  wxDir dir( aLibraryPath );
2211 
2212  if( dir.HasSubDirs() )
2213  {
2214  THROW_IO_ERROR( wxString::Format( _( "library directory \"%s\" has unexpected sub-directories" ),
2215  aLibraryPath.GetData() ) );
2216  }
2217 
2218  // All the footprint files must be deleted before the directory can be deleted.
2219  if( dir.HasFiles() )
2220  {
2221  unsigned i;
2222  wxFileName tmp;
2223  wxArrayString files;
2224 
2225  wxDir::GetAllFiles( aLibraryPath, &files );
2226 
2227  for( i = 0; i < files.GetCount(); i++ )
2228  {
2229  tmp = files[i];
2230 
2231  if( tmp.GetExt() != KiCadFootprintFileExtension )
2232  {
2233  THROW_IO_ERROR( wxString::Format( _( "unexpected file \"%s\" was found in library path \"%s\"" ),
2234  files[i].GetData(), aLibraryPath.GetData() ) );
2235  }
2236  }
2237 
2238  for( i = 0; i < files.GetCount(); i++ )
2239  {
2240  wxRemoveFile( files[i] );
2241  }
2242  }
2243 
2244  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"" ),
2245  aLibraryPath.GetData() );
2246 
2247  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2248  // we don't want that. we want bare metal portability with no UI here.
2249  if( !wxRmdir( aLibraryPath ) )
2250  {
2251  THROW_IO_ERROR( wxString::Format( _( "footprint library \"%s\" cannot be deleted" ),
2252  aLibraryPath.GetData() ) );
2253  }
2254 
2255  // For some reason removing a directory in Windows is not immediately updated. This delay
2256  // prevents an error when attempting to immediately recreate the same directory when over
2257  // writing an existing library.
2258 #ifdef __WINDOWS__
2259  wxMilliSleep( 250L );
2260 #endif
2261 
2262  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2263  {
2264  delete m_cache;
2265  m_cache = NULL;
2266  }
2267 
2268  return true;
2269 }
FP_CACHE * m_cache
Footprint library cache.
const wxString KiCadFootprintFileExtension
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
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
size_t i
Definition: json11.cpp:597
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

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

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

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

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

Reimplemented in GITHUB_PLUGIN, and EAGLE_PLUGIN.

Definition at line 131 of file plugin.cpp.

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

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

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

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of the footprint to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Reimplemented from PLUGIN.

Definition at line 2052 of file kicad_plugin.cpp.

References doLoadFootprint().

Referenced by GITHUB_PLUGIN::FootprintLoad(), and GetFileExtension().

2054 {
2055  return doLoadFootprint( aLibraryPath, aFootprintName, aProperties, true );
2056 }
MODULE * doLoadFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
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 2059 of file kicad_plugin.cpp.

References CTL_FOR_LIBRARY, FP_CACHE::Exists(), F_Cu, Format(), GetChars(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), FP_CACHE::GetModules(), init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, m_cache, m_ctl, FP_CACHE::Save(), THROW_IO_ERROR, traceKicadPcbPlugin, and validateCache().

Referenced by GITHUB_PLUGIN::FootprintSave(), and GetFileExtension().

2061 {
2062  LOCALE_IO toggle; // toggles on, then off, the C locale.
2063 
2064  init( aProperties );
2065 
2066  // In this public PLUGIN API function, we can safely assume it was
2067  // called for saving into a library path.
2069 
2070  validateCache( aLibraryPath );
2071 
2072  if( !m_cache->IsWritable() )
2073  {
2074  if( !m_cache->Exists() )
2075  {
2076  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2077  "Would you like to create it?"),
2078  GetChars( aLibraryPath ) );
2079  const wxString title = wxString::Format( _( "Create new library \"%s\"?"),
2080  GetChars( aLibraryPath ) );
2081 
2082  if( wxMessageBox( msg, title, wxYES_NO | wxICON_QUESTION ) != wxYES )
2083  return;
2084 
2085  // Save throws its own IO_ERROR on failure, so no need to recreate here
2086  m_cache->Save( NULL );
2087  }
2088  else
2089  {
2090  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ),
2091  GetChars( aLibraryPath ) );
2092  THROW_IO_ERROR( msg );
2093  }
2094 
2095 
2096  }
2097 
2098  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2099 
2100  MODULE_MAP& mods = m_cache->GetModules();
2101 
2102  // Quietly overwrite module and delete module file from path for any by same name.
2103  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2105 
2106  if( !fn.IsOk() )
2107  {
2108  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2109  GetChars( fn.GetFullPath() ) ) );
2110  }
2111 
2112  if( fn.FileExists() && !fn.IsFileWritable() )
2113  {
2114  THROW_IO_ERROR( wxString::Format( _( "user does not have write permission to delete file \"%s\" " ),
2115  GetChars( fn.GetFullPath() ) ) );
2116  }
2117 
2118  MODULE_CITER it = mods.find( footprintName );
2119 
2120  if( it != mods.end() )
2121  {
2122  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library file '%s'." ),
2123  fn.GetFullPath().GetData() );
2124  mods.erase( footprintName );
2125  wxRemoveFile( fn.GetFullPath() );
2126  }
2127 
2128  // I need my own copy for the cache
2129  MODULE* module = new MODULE( *aFootprint );
2130 
2131  // and it's time stamp must be 0, it should have no parent, orientation should
2132  // be zero, and it should be on the front layer.
2133  module->SetTimeStamp( 0 );
2134  module->SetParent( 0 );
2135  module->SetOrientation( 0 );
2136 
2137  if( module->GetLayer() != F_Cu )
2138  module->Flip( module->GetPosition() );
2139 
2140  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expression footprint file: %s." ),
2141  fn.GetFullPath().GetData() );
2142  mods.insert( footprintName, new FP_CACHE_ITEM( module, fn ) );
2143  m_cache->Save( module );
2144 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
const wxString KiCadFootprintFileExtension
const LIB_ID & GetFPID() const
Definition: class_module.h:191
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
bool Exists() const
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
Class FP_CACHE_ITEM is helper class for creating a footprint library cache.
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
bool IsWritable() const
MODULE_MAP::const_iterator MODULE_CITER
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
MODULE_MAP & GetModules()
void PCB_IO::Format ( BOARD_ITEM aItem,
int  aNestLevel = 0 
) const

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

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

Definition at line 437 of file kicad_plugin.cpp.

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module(), GetFileExtension(), CLIPBOARD_IO::Save(), and CLIPBOARD_IO::SaveSelection().

438 {
439  LOCALE_IO toggle; // public API function, perform anything convenient for caller
440 
441  switch( aItem->Type() )
442  {
443  case PCB_T:
444  format( static_cast<BOARD*>( aItem ), aNestLevel );
445  break;
446 
447  case PCB_DIMENSION_T:
448  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
449  break;
450 
451  case PCB_LINE_T:
452  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
453  break;
454 
455  case PCB_MODULE_EDGE_T:
456  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
457  break;
458 
459  case PCB_TARGET_T:
460  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
461  break;
462 
463  case PCB_MODULE_T:
464  format( static_cast<MODULE*>( aItem ), aNestLevel );
465  break;
466 
467  case PCB_PAD_T:
468  format( static_cast<D_PAD*>( aItem ), aNestLevel );
469  break;
470 
471  case PCB_TEXT_T:
472  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
473  break;
474 
475  case PCB_MODULE_TEXT_T:
476  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
477  break;
478 
479  case PCB_TRACE_T:
480  case PCB_VIA_T:
481  format( static_cast<TRACK*>( aItem ), aNestLevel );
482  break;
483 
484  case PCB_ZONE_AREA_T:
485  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
486  break;
487 
488  default:
489  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
490  }
491 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
Definition: typeinfo.h:85
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
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:96
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
void PCB_IO::format ( BOARD aBoard,
int  aNestLevel = 0 
) const
private
Todo:
Add warning here that the old segment filed zones are no longer supported and will not be saved.

Definition at line 750 of file kicad_plugin.cpp.

References BOARD::Drawings(), Format(), BOARD::GetArea(), BOARD::GetAreaCount(), DHEAD::GetCount(), i, BOARD::m_Modules, BOARD::m_Track, TRACK::Next(), and MODULE::Next().

751 {
752  formatHeader( aBoard, aNestLevel );
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( auto item : aBoard->Drawings() )
763  Format( item, aNestLevel );
764 
765  if( aBoard->Drawings().Size() )
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 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
MODULE * Next() const
Definition: class_module.h:121
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
void formatHeader(BOARD *aBoard, int aNestLevel=0) const
writes everything that comes before the board_items, like settings and layers etc ...
TRACK * Next() const
Definition: class_track.h:99
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
DLIST< MODULE > m_Modules
Definition: class_board.h:247
size_t i
Definition: json11.cpp:597
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:248
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:254
void PCB_IO::format ( DIMENSION aDimension,
int  aNestLevel = 0 
) const
private

Definition at line 786 of file kicad_plugin.cpp.

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

787 {
788  m_out->Print( aNestLevel, "(dimension %s (width %s)",
789  FMT_IU( aDimension->GetValue() ).c_str(),
790  FMT_IU( aDimension->GetWidth() ).c_str() );
791 
792  formatLayer( aDimension );
793 
794  if( aDimension->GetTimeStamp() )
795  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aDimension->GetTimeStamp() );
796 
797  m_out->Print( 0, "\n" );
798 
799  Format( &aDimension->Text(), aNestLevel+1 );
800 
801  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
802  FMT_IU( aDimension->m_featureLineDO.x ).c_str(),
803  FMT_IU( aDimension->m_featureLineDO.y ).c_str(),
804  FMT_IU( aDimension->m_featureLineDF.x ).c_str(),
805  FMT_IU( aDimension->m_featureLineDF.y ).c_str() );
806 
807  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
808  FMT_IU( aDimension->m_featureLineGO.x ).c_str(),
809  FMT_IU( aDimension->m_featureLineGO.y ).c_str(),
810  FMT_IU( aDimension->m_featureLineGF.x ).c_str(),
811  FMT_IU( aDimension->m_featureLineGF.y ).c_str() );
812 
813  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
814  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
815  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
816  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
817  FMT_IU( aDimension->m_crossBarF.y ).c_str() );
818 
819  m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
820  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
821  FMT_IU( aDimension->m_crossBarF.y ).c_str(),
822  FMT_IU( aDimension->m_arrowD1F.x ).c_str(),
823  FMT_IU( aDimension->m_arrowD1F.y ).c_str() );
824 
825  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
826  FMT_IU( aDimension->m_crossBarF.x ).c_str(),
827  FMT_IU( aDimension->m_crossBarF.y ).c_str(),
828  FMT_IU( aDimension->m_arrowD2F.x ).c_str(),
829  FMT_IU( aDimension->m_arrowD2F.y ).c_str() );
830 
831  m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
832  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
833  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
834  FMT_IU( aDimension->m_arrowG1F.x ).c_str(),
835  FMT_IU( aDimension->m_arrowG1F.y ).c_str() );
836 
837  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
838  FMT_IU( aDimension->m_crossBarO.x ).c_str(),
839  FMT_IU( aDimension->m_crossBarO.y ).c_str(),
840  FMT_IU( aDimension->m_arrowG2F.x ).c_str(),
841  FMT_IU( aDimension->m_arrowG2F.y ).c_str() );
842 
843  m_out->Print( aNestLevel, ")\n" );
844 }
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
#define FMT_IU
wxPoint m_arrowG1F
wxPoint m_arrowD2F
wxPoint m_arrowG2F
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
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:404
wxPoint m_featureLineDO
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
wxPoint m_featureLineGF
void PCB_IO::format ( EDGE_MODULE aModuleDrawing,
int  aNestLevel = 0 
) const
private

Definition at line 925 of file kicad_plugin.cpp.

References SHAPE_LINE_CHAIN::CPoint(), FMT_ANGLE, FMT_IU, DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetBezControl1(), DRAWSEGMENT::GetBezControl2(), EDGE_MODULE::GetEnd0(), DRAWSEGMENT::GetPolyShape(), DRAWSEGMENT::GetShape(), EDGE_MODULE::GetStart0(), DRAWSEGMENT::GetWidth(), DRAWSEGMENT::IsPolyShapeValid(), SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::PointCount(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

926 {
927  switch( aModuleDrawing->GetShape() )
928  {
929  case S_SEGMENT: // Line
930  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
931  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
932  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
933  break;
934 
935  case S_CIRCLE: // Circle
936  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
937  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
938  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
939  break;
940 
941  case S_ARC: // Arc
942  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
943  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
944  FMT_IU( aModuleDrawing->GetEnd0() ).c_str(),
945  FMT_ANGLE( aModuleDrawing->GetAngle() ).c_str() );
946  break;
947 
948  case S_POLYGON: // Polygonal segment
949  if( aModuleDrawing->IsPolyShapeValid() )
950  {
951  SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
952  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
953  int pointsCount = outline.PointCount();
954 
955  m_out->Print( aNestLevel, "(fp_poly (pts" );
956 
957  for( int ii = 0; ii < pointsCount; ++ii )
958  {
959  int nestLevel = 0;
960 
961  if( ii && !( ii%4 ) ) // newline every 4 pts
962  {
963  nestLevel = aNestLevel + 1;
964  m_out->Print( 0, "\n" );
965  }
966 
967  m_out->Print( nestLevel, "%s(xy %s)",
968  nestLevel ? "" : " ", FMT_IU( outline.CPoint( ii ) ).c_str() );
969  }
970 
971  m_out->Print( 0, ")" );
972  }
973  else
974  {
975  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
976  return;
977  }
978  break;
979 
980  case S_CURVE: // Bezier curve
981  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
982  FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
983  FMT_IU( aModuleDrawing->GetBezControl1() ).c_str(),
984  FMT_IU( aModuleDrawing->GetBezControl2() ).c_str(),
985  FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
986  break;
987 
988  default:
989  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
990  return;
991  };
992 
993  formatLayer( aModuleDrawing );
994 
995  m_out->Print( 0, " (width %s)", FMT_IU( aModuleDrawing->GetWidth() ).c_str() );
996 
997  m_out->Print( 0, ")\n" );
998 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetBezControl2() const
int PointCount() const
Function PointCount()
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
bool IsPolyShapeValid() const
#define FMT_IU
STROKE_T GetShape() const
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Arcs (with rounded ends)
const wxPoint & GetBezControl1() const
SHAPE_POLY_SET & GetPolyShape()
Bezier Curve.
double GetAngle() const
const wxPoint & GetStart0() const
Class SHAPE_LINE_CHAIN.
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:404
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
#define FMT_ANGLE
void PCB_IO::format ( DRAWSEGMENT aSegment,
int  aNestLevel = 0 
) const
private

Definition at line 847 of file kicad_plugin.cpp.

References SHAPE_LINE_CHAIN::CPoint(), FMT_ANGLE, FMT_IU, DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetBezControl1(), DRAWSEGMENT::GetBezControl2(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetPolyShape(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), DRAWSEGMENT::GetWidth(), DRAWSEGMENT::IsPolyShapeValid(), SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::PointCount(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

848 {
849  switch( aSegment->GetShape() )
850  {
851  case S_SEGMENT: // Line
852  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
853  FMT_IU( aSegment->GetStart() ).c_str(),
854  FMT_IU( aSegment->GetEnd() ).c_str() );
855 
856  if( aSegment->GetAngle() != 0.0 )
857  m_out->Print( 0, " (angle %s)", FMT_ANGLE( aSegment->GetAngle() ).c_str() );
858 
859  break;
860 
861  case S_CIRCLE: // Circle
862  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
863  FMT_IU( aSegment->GetStart() ).c_str(),
864  FMT_IU( aSegment->GetEnd() ).c_str() );
865  break;
866 
867  case S_ARC: // Arc
868  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
869  FMT_IU( aSegment->GetStart() ).c_str(),
870  FMT_IU( aSegment->GetEnd() ).c_str(),
871  FMT_ANGLE( aSegment->GetAngle() ).c_str() );
872  break;
873 
874  case S_POLYGON: // Polygon
875  if( aSegment->IsPolyShapeValid() )
876  {
877  SHAPE_POLY_SET& poly = aSegment->GetPolyShape();
878  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
879  int pointsCount = outline.PointCount();
880 
881  m_out->Print( aNestLevel, "(gr_poly (pts" );
882 
883  for( int ii = 0; ii < pointsCount; ++ii )
884  {
885  m_out->Print( 0, " (xy %s)", FMT_IU( outline.CPoint( ii ) ).c_str() );
886  }
887 
888  m_out->Print( 0, ")" );
889  }
890  else
891  {
892  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
893  return;
894  }
895 
896  break;
897 
898  case S_CURVE: // Bezier curve
899  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
900  FMT_IU( aSegment->GetStart() ).c_str(),
901  FMT_IU( aSegment->GetBezControl1() ).c_str(),
902  FMT_IU( aSegment->GetBezControl2() ).c_str(),
903  FMT_IU( aSegment->GetEnd() ).c_str() );
904  break;
905 
906  default:
907  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
908  return;
909  };
910 
911  formatLayer( aSegment );
912 
913  m_out->Print( 0, " (width %s)", FMT_IU( aSegment->GetWidth() ).c_str() );
914 
915  if( aSegment->GetTimeStamp() )
916  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aSegment->GetTimeStamp() );
917 
918  if( aSegment->GetStatus() )
919  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
920 
921  m_out->Print( 0, ")\n" );
922 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetBezControl2() const
int PointCount() const
Function PointCount()
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
bool IsPolyShapeValid() const
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:261
#define FMT_IU
STROKE_T GetShape() const
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Arcs (with rounded ends)
const wxPoint & GetBezControl1() const
SHAPE_POLY_SET & GetPolyShape()
Bezier Curve.
double GetAngle() const
Class SHAPE_LINE_CHAIN.
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:404
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
#define FMT_ANGLE
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void PCB_IO::format ( PCB_TARGET aTarget,
int  aNestLevel = 0 
) const
private

Definition at line 1001 of file kicad_plugin.cpp.

References FMT_IU, PCB_TARGET::GetPosition(), PCB_TARGET::GetShape(), PCB_TARGET::GetSize(), EDA_ITEM::GetTimeStamp(), and PCB_TARGET::GetWidth().

1002 {
1003  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
1004  ( aTarget->GetShape() ) ? "x" : "plus",
1005  FMT_IU( aTarget->GetPosition() ).c_str(),
1006  FMT_IU( aTarget->GetSize() ).c_str() );
1007 
1008  if( aTarget->GetWidth() != 0 )
1009  m_out->Print( 0, " (width %s)", FMT_IU( aTarget->GetWidth() ).c_str() );
1010 
1011  formatLayer( aTarget );
1012 
1013  if( aTarget->GetTimeStamp() )
1014  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTarget->GetTimeStamp() );
1015 
1016  m_out->Print( 0, ")\n" );
1017 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetWidth() const
void formatLayer(const BOARD_ITEM *aItem) const
#define FMT_IU
int GetShape() const
int GetSize() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
const wxPoint GetPosition() const override
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void PCB_IO::format ( MODULE aModule,
int  aNestLevel = 0 
) const
private

Definition at line 1020 of file kicad_plugin.cpp.

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

1021 {
1022  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1023  {
1024  const wxArrayString* initial_comments = aModule->GetInitialComments();
1025 
1026  if( initial_comments )
1027  {
1028  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
1029  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1030 
1031  m_out->Print( 0, "\n" ); // improve readability?
1032  }
1033  }
1034 
1035  m_out->Print( aNestLevel, "(module %s",
1036  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1037 
1038  if( aModule->IsLocked() )
1039  m_out->Print( 0, " locked" );
1040 
1041  if( aModule->IsPlaced() )
1042  m_out->Print( 0, " placed" );
1043 
1044  formatLayer( aModule );
1045 
1046  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1047 
1048  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1049  {
1050  m_out->Print( 0, " (tstamp %lX)\n", (unsigned long)aModule->GetTimeStamp() );
1051  }
1052  else
1053  m_out->Print( 0, "\n" );
1054 
1055  if( !( m_ctl & CTL_OMIT_AT ) )
1056  {
1057  m_out->Print( aNestLevel+1, "(at %s", FMT_IU( aModule->GetPosition() ).c_str() );
1058 
1059  if( aModule->GetOrientation() != 0.0 )
1060  m_out->Print( 0, " %s", FMT_ANGLE( aModule->GetOrientation() ).c_str() );
1061 
1062  m_out->Print( 0, ")\n" );
1063  }
1064 
1065  if( !aModule->GetDescription().IsEmpty() )
1066  m_out->Print( aNestLevel+1, "(descr %s)\n",
1067  m_out->Quotew( aModule->GetDescription() ).c_str() );
1068 
1069  if( !aModule->GetKeywords().IsEmpty() )
1070  m_out->Print( aNestLevel+1, "(tags %s)\n",
1071  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1072 
1073  if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
1074  m_out->Print( aNestLevel+1, "(path %s)\n",
1075  m_out->Quotew( aModule->GetPath() ).c_str() );
1076 
1077  if( aModule->GetPlacementCost90() != 0 )
1078  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1079 
1080  if( aModule->GetPlacementCost180() != 0 )
1081  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1082 
1083  if( aModule->GetLocalSolderMaskMargin() != 0 )
1084  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1085  FMT_IU( aModule->GetLocalSolderMaskMargin() ).c_str() );
1086 
1087  if( aModule->GetLocalSolderPasteMargin() != 0 )
1088  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1089  FMT_IU( aModule->GetLocalSolderPasteMargin() ).c_str() );
1090 
1091  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1092  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1093  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1094 
1095  if( aModule->GetLocalClearance() != 0 )
1096  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1097  FMT_IU( aModule->GetLocalClearance() ).c_str() );
1098 
1099  if( aModule->GetZoneConnection() != PAD_ZONE_CONN_INHERITED )
1100  m_out->Print( aNestLevel+1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
1101 
1102  if( aModule->GetThermalWidth() != 0 )
1103  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1104  FMT_IU( aModule->GetThermalWidth() ).c_str() );
1105 
1106  if( aModule->GetThermalGap() != 0 )
1107  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1108  FMT_IU( aModule->GetThermalGap() ).c_str() );
1109 
1110  // Attributes
1111  if( aModule->GetAttributes() != MOD_DEFAULT )
1112  {
1113  m_out->Print( aNestLevel+1, "(attr" );
1114 
1115  if( aModule->GetAttributes() & MOD_CMS )
1116  m_out->Print( 0, " smd" );
1117 
1118  if( aModule->GetAttributes() & MOD_VIRTUAL )
1119  m_out->Print( 0, " virtual" );
1120 
1121  m_out->Print( 0, ")\n" );
1122  }
1123 
1124  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1125  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1126 
1127  // Save drawing elements.
1128  for( BOARD_ITEM* gr = aModule->GraphicalItemsList(); gr; gr = gr->Next() )
1129  Format( gr, aNestLevel+1 );
1130 
1131  // Save pads.
1132  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
1133  format( pad, aNestLevel+1 );
1134 
1135  // Save 3D info.
1136  auto bs3D = aModule->Models().begin();
1137  auto es3D = aModule->Models().end();
1138 
1139  while( bs3D != es3D )
1140  {
1141  if( !bs3D->m_Filename.IsEmpty() )
1142  {
1143  m_out->Print( aNestLevel+1, "(model %s\n",
1144  m_out->Quotew( bs3D->m_Filename ).c_str() );
1145 
1146  /* Write 3D model offset in mm
1147  * 4.0.x wrote "at" which was actually in inches
1148  * 5.0.x onwards, 3D model offset is written using "offset"
1149  *
1150  * If the offset is all zero, write "at" (fewer file changes)
1151  * Otherwise, write "offset"
1152  */
1153 
1154  wxString offsetTag = "offset";
1155 
1156  if( bs3D->m_Offset.x == 0 &&
1157  bs3D->m_Offset.y == 0 &&
1158  bs3D->m_Offset.z == 0 )
1159  {
1160  offsetTag = "at";
1161  }
1162 
1163  m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
1164  offsetTag.ToStdString().c_str(),
1165  Double2Str( bs3D->m_Offset.x ).c_str(),
1166  Double2Str( bs3D->m_Offset.y ).c_str(),
1167  Double2Str( bs3D->m_Offset.z ).c_str() );
1168 
1169  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1170  Double2Str( bs3D->m_Scale.x ).c_str(),
1171  Double2Str( bs3D->m_Scale.y ).c_str(),
1172  Double2Str( bs3D->m_Scale.z ).c_str() );
1173 
1174  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1175  Double2Str( bs3D->m_Rotation.x ).c_str(),
1176  Double2Str( bs3D->m_Rotation.y ).c_str(),
1177  Double2Str( bs3D->m_Rotation.z ).c_str() );
1178 
1179  m_out->Print( aNestLevel+1, ")\n" );
1180  }
1181  ++bs3D;
1182  }
1183 
1184  m_out->Print( aNestLevel, ")\n" );
1185 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
TEXTE_MODULE & Reference()
Definition: class_module.h:502
#define CTL_OMIT_AT
Omit position and rotation.
int GetThermalGap() const
Definition: class_module.h:222
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:206
void formatLayer(const BOARD_ITEM *aItem) const
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:77
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
timestamp_t GetLastEditTime() const
Definition: class_module.h:311
ZoneConnection GetZoneConnection() const
Definition: class_module.h:216
int GetPlacementCost90() const
Definition: class_module.h:572
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:212
BOARD_ITEM * Next() const
const LIB_ID & GetFPID() const
Definition: class_module.h:191
#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
#define FMT_IU
double GetOrientation() const
Definition: class_module.h:187
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
D_PAD * Next() const
Definition: class_pad.h:160
int GetAttributes() const
Definition: class_module.h:224
const wxString & GetKeywords() const
Definition: class_module.h:197
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
int GetLocalSolderMaskMargin() const
Definition: class_module.h:203
#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:263
int GetLocalSolderPasteMargin() const
Definition: class_module.h:209
default
Definition: class_module.h:76
virtual std::string Quotes(const std::string &aWrapee)
Function Quotes checks aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:433
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:177
const wxString & GetDescription() const
Definition: class_module.h:194
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:79
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
size_t i
Definition: json11.cpp:597
void format(BOARD *aBoard, int aNestLevel=0) const
UTF8 Format() const
Definition: lib_id.cpp:263
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define CTL_OMIT_INITIAL_COMMENTS
omit MODULE initial comments
const wxString & GetPath() const
Definition: class_module.h:200
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership. ...
Definition: class_module.h:696
bool IsPlaced() const
Definition: class_module.h:281
int GetPlacementCost180() const
Definition: class_module.h:569
const wxPoint GetPosition() const override
Definition: class_module.h:182
#define FMT_ANGLE
int GetThermalWidth() const
Definition: class_module.h:219
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void PCB_IO::format ( D_PAD aPad,
int  aNestLevel = 0 
) const
private

Definition at line 1280 of file kicad_plugin.cpp.

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

1281 {
1282  const char* shape;
1283 
1284  switch( aPad->GetShape() )
1285  {
1286  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1287  case PAD_SHAPE_RECT: shape = "rect"; break;
1288  case PAD_SHAPE_OVAL: shape = "oval"; break;
1289  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1290  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1291  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1292 
1293  default:
1294  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1295  }
1296 
1297  const char* type;
1298 
1299  switch( aPad->GetAttribute() )
1300  {
1301  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1302  case PAD_ATTRIB_SMD: type = "smd"; break;
1303  case PAD_ATTRIB_CONN: type = "connect"; break;
1304  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1305 
1306  default:
1307  THROW_IO_ERROR( wxString::Format( _( "unknown pad attribute: %d" ),
1308  aPad->GetAttribute() ) );
1309  }
1310 
1311  m_out->Print( aNestLevel, "(pad %s %s %s",
1312  m_out->Quotew( aPad->GetName() ).c_str(),
1313  type, shape );
1314  m_out->Print( 0, " (at %s", FMT_IU( aPad->GetPos0() ).c_str() );
1315 
1316  if( aPad->GetOrientation() != 0.0 )
1317  m_out->Print( 0, " %s", FMT_ANGLE( aPad->GetOrientation() ).c_str() );
1318 
1319  m_out->Print( 0, ")" );
1320  m_out->Print( 0, " (size %s)", FMT_IU( aPad->GetSize() ).c_str() );
1321 
1322  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1323  m_out->Print( 0, " (rect_delta %s )", FMT_IU( aPad->GetDelta() ).c_str() );
1324 
1325  wxSize sz = aPad->GetDrillSize();
1326  wxPoint shapeoffset = aPad->GetOffset();
1327 
1328  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1329  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1330  {
1331  m_out->Print( 0, " (drill" );
1332 
1333  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1334  m_out->Print( 0, " oval" );
1335 
1336  if( sz.GetWidth() > 0 )
1337  m_out->Print( 0, " %s", FMT_IU( sz.GetWidth() ).c_str() );
1338 
1339  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1340  m_out->Print( 0, " %s", FMT_IU( sz.GetHeight() ).c_str() );
1341 
1342  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1343  m_out->Print( 0, " (offset %s)", FMT_IU( aPad->GetOffset() ).c_str() );
1344 
1345  m_out->Print( 0, ")" );
1346  }
1347 
1348  formatLayers( aPad->GetLayerSet() );
1349 
1350  // Output the radius ratio for rounded rect pads
1351  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
1352  {
1353  m_out->Print( 0, " (roundrect_rratio %s)",
1354  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1355  }
1356 
1357  std::string output;
1358 
1359  // Unconnected pad is default net so don't save it.
1360  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1361  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1362  m_out->Quotew( aPad->GetNetname() ).c_str() );
1363 
1364  if( aPad->GetPadToDieLength() != 0 )
1365  StrPrintf( &output, " (die_length %s)", FMT_IU( aPad->GetPadToDieLength() ).c_str() );
1366 
1367  if( aPad->GetLocalSolderMaskMargin() != 0 )
1368  StrPrintf( &output, " (solder_mask_margin %s)",
1369  FMT_IU( aPad->GetLocalSolderMaskMargin() ).c_str() );
1370 
1371  if( aPad->GetLocalSolderPasteMargin() != 0 )
1372  StrPrintf( &output, " (solder_paste_margin %s)",
1373  FMT_IU( aPad->GetLocalSolderPasteMargin() ).c_str() );
1374 
1375  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1376  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1377  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1378 
1379  if( aPad->GetLocalClearance() != 0 )
1380  StrPrintf( &output, " (clearance %s)", FMT_IU( aPad->GetLocalClearance() ).c_str() );
1381 
1383  StrPrintf( &output, " (zone_connect %d)", aPad->GetZoneConnection() );
1384 
1385  if( aPad->GetThermalWidth() != 0 )
1386  StrPrintf( &output, " (thermal_width %s)", FMT_IU( aPad->GetThermalWidth() ).c_str() );
1387 
1388  if( aPad->GetThermalGap() != 0 )
1389  StrPrintf( &output, " (thermal_gap %s)", FMT_IU( aPad->GetThermalGap() ).c_str() );
1390 
1391  if( output.size() )
1392  {
1393  m_out->Print( 0, "\n" );
1394  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1395  }
1396 
1397  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1398  {
1399  m_out->Print( 0, "\n");
1400  m_out->Print( aNestLevel+1, "(options" );
1401 
1403  m_out->Print( 0, " (clearance convexhull)" );
1404  #if 1 // Set to 1 to output the default option
1405  else
1406  m_out->Print( 0, " (clearance outline)" );
1407  #endif
1408 
1409  // Output the anchor pad shape (circle/rect)
1410  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1411  shape = "rect";
1412  else
1413  shape = "circle";
1414 
1415  m_out->Print( 0, " (anchor %s)", shape );
1416 
1417  m_out->Print( 0, ")"); // end of (options ...
1418 
1419  // Output graphic primitive of the pad shape
1420  m_out->Print( 0, "\n");
1421  m_out->Print( aNestLevel+1, "(primitives" );
1422 
1423  int nested_level = aNestLevel+2;
1424 
1425  // Output all basic shapes
1426  for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
1427  {
1428  m_out->Print( 0, "\n");
1429 
1430  const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
1431 
1432  switch( primitive.m_Shape )
1433  {
1434  case S_SEGMENT: // usual segment : line with rounded ends
1435  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1436  FMT_IU( primitive.m_Start ).c_str(),
1437  FMT_IU( primitive.m_End ).c_str(),
1438  FMT_IU( primitive.m_Thickness ).c_str() );
1439  break;
1440 
1441  case S_ARC: // Arc with rounded ends
1442  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1443  FMT_IU( primitive.m_Start ).c_str(),
1444  FMT_IU( primitive.m_End ).c_str(),
1445  FMT_ANGLE( primitive.m_ArcAngle ).c_str(),
1446  FMT_IU( primitive.m_Thickness ).c_str() );
1447  break;
1448 
1449  case S_CIRCLE: // ring or circle (circle if width == 0
1450  m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
1451  FMT_IU( primitive.m_Start ).c_str(),
1452  FMT_IU( primitive.m_Start.x + primitive.m_Radius ).c_str(),
1453  FMT_IU( primitive.m_Start.y ).c_str(),
1454  FMT_IU( primitive.m_Thickness ).c_str() );
1455  break;
1456 
1457  case S_POLYGON: // polygon
1458  if( primitive.m_Poly.size() < 2 )
1459  break; // Malformed polygon.
1460 
1461  {
1462  m_out->Print( nested_level, "(gr_poly (pts\n");
1463 
1464  // Write the polygon corners coordinates:
1465  const std::vector< wxPoint>& poly = primitive.m_Poly;
1466  int newLine = 0;
1467 
1468  for( unsigned ii = 0; ii < poly.size(); ii++ )
1469  {
1470  if( newLine == 0 )
1471  m_out->Print( nested_level+1, " (xy %s)",
1472  FMT_IU( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1473  else
1474  m_out->Print( 0, " (xy %s)",
1475  FMT_IU( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1476 
1477  if( ++newLine > 4 )
1478  {
1479  newLine = 0;
1480  m_out->Print( 0, "\n" );
1481  }
1482  }
1483 
1484  m_out->Print( 0, ") (width %s))", FMT_IU( primitive.m_Thickness ).c_str() );
1485  }
1486  break;
1487 
1488  default:
1489  break;
1490  }
1491  }
1492 
1493  m_out->Print( 0, "\n");
1494  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1495  }
1496 
1497  m_out->Print( 0, ")\n" );
1498 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:226
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:336
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:405
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
int GetPadToDieLength() const
Definition: class_pad.h:408
wxPoint m_Start
angle of an arc, from its starting point, in 0.1 deg
Definition: class_pad.h:100
polygon (not yet used for tracks, but could be in microwave apps)
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:410
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
const wxPoint & GetPos0() const
Definition: class_pad.h:263
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
usual segment : line with rounded ends
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
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:74
#define FMT_IU
int m_Radius
thickness of segment or outline For filled S_CIRCLE shape, thickness = 0.
Definition: class_pad.h:98
std::vector< wxPoint > m_Poly
is also the start point of the arc
Definition: class_pad.h:102
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Arcs (with rounded ends)
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:91
ZoneConnection GetZoneConnection() const
Definition: class_pad.cpp:670
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:402
int GetThermalWidth() const
Definition: class_pad.cpp:681
int GetThermalGap() const
Definition: class_pad.cpp:692
const wxSize & GetSize() const
Definition: class_pad.h:269
const wxString & GetName() const
Definition: class_pad.h:190
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:416
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:101
#define CTL_OMIT_NETS
Omit pads net names (useless in library)
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:62
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
STROKE_T m_Shape
Definition: class_pad.h:94
int GetLocalClearance() const
Definition: class_pad.h:413
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:419
int GetNetCode() const
Function GetNetCode.
int m_Thickness
S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
Definition: class_pad.h:95
const wxString & GetNetname() const
Function GetNetname.
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:621
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:232
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
const wxSize & GetDelta() const
Definition: class_pad.h:272
Usual pad.
Definition: pad_shapes.h:60
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
#define FMT_ANGLE
const wxPoint & GetOffset() const
Definition: class_pad.h:278
double m_ArcAngle
radius of a circle
Definition: class_pad.h:99
void PCB_IO::format ( TEXTE_PCB aText,
int  aNestLevel = 0 
) const
private

Definition at line 1501 of file kicad_plugin.cpp.

References FMT_ANGLE, FMT_IU, EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), and EDA_ITEM::GetTimeStamp().

1502 {
1503  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1504  m_out->Quotew( aText->GetText() ).c_str(),
1505  FMT_IU( aText->GetTextPos() ).c_str() );
1506 
1507  if( aText->GetTextAngle() != 0.0 )
1508  m_out->Print( 0, " %s", FMT_ANGLE( aText->GetTextAngle() ).c_str() );
1509 
1510  m_out->Print( 0, ")" );
1511 
1512  formatLayer( aText );
1513 
1514  if( aText->GetTimeStamp() )
1515  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aText->GetTimeStamp() );
1516 
1517  m_out->Print( 0, "\n" );
1518 
1519  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1520 
1521  m_out->Print( aNestLevel, ")\n" );
1522 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
void formatLayer(const BOARD_ITEM *aItem) const
double GetTextAngle() const
Definition: eda_text.h:162
#define FMT_IU
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define FMT_ANGLE
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void PCB_IO::format ( TEXTE_MODULE aText,
int  aNestLevel = 0 
) const
private

Definition at line 1525 of file kicad_plugin.cpp.

References CTL_OMIT_HIDE, FMT_ANGLE, FMT_IU, MODULE::GetOrientation(), BOARD_ITEM::GetParent(), TEXTE_MODULE::GetPos0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), TEXTE_MODULE::GetType(), TEXTE_MODULE::IsUnlocked(), EDA_TEXT::IsVisible(), NormalizeAngle360Min(), NormalizeAnglePos(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, and TEXTE_MODULE::TEXT_is_VALUE.

1526 {
1527  wxString type;
1528 
1529  switch( aText->GetType() )
1530  {
1531  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1532  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1533  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1534  }
1535 
1536  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1537  m_out->Quotew( type ).c_str(),
1538  m_out->Quotew( aText->GetText() ).c_str(),
1539  FMT_IU( aText->GetPos0() ).c_str() );
1540 
1541  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1542  // but internally the angle is held relative to its parent footprint. parent
1543  // may be NULL when saving a footprint outside a BOARD.
1544  double orient = aText->GetTextAngle();
1545  MODULE* parent = (MODULE*) aText->GetParent();
1546 
1547  if( parent )
1548  {
1549  // GetTextAngle() is always in -360..+360 range because of
1550  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1551  // additional board angle could kick sum up >= 360 or <= -360, so to have
1552  // consistent results, normalize again for the BOARD save. A footprint
1553  // save does not use this code path since parent is NULL.
1554 #if 0
1555  // This one could be considered reasonable if you like positive angles
1556  // in your board text.
1557  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1558 #else
1559  // Choose compatibility for now, even though this is only a 720 degree clamp
1560  // with two possible values for every angle.
1561  orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
1562 #endif
1563  }
1564 
1565  if( orient != 0.0 )
1566  m_out->Print( 0, " %s", FMT_ANGLE( orient ).c_str() );
1567 
1568  if( aText->IsUnlocked() )
1569  m_out->Print( 0, " unlocked" );
1570 
1571  m_out->Print( 0, ")" );
1572  formatLayer( aText );
1573 
1574  if( !aText->IsVisible() )
1575  m_out->Print( 0, " hide" );
1576 
1577  m_out->Print( 0, "\n" );
1578 
1579  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1580 
1581  m_out->Print( aNestLevel, ")\n" );
1582 }
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:162
#define FMT_IU
bool IsUnlocked()
double GetOrientation() const
Definition: class_module.h:187
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
bool IsVisible() const
Definition: eda_text.h:174
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:233
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
T NormalizeAngle360Min(T Angle)
Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0...
Definition: trigo.h:222
#define CTL_OMIT_HIDE
Definition: eda_text.h:42
#define FMT_ANGLE
void PCB_IO::format ( TRACK aTrack,
int  aNestLevel = 0 
) const
private

Definition at line 1585 of file kicad_plugin.cpp.

References FMT_IU, Format(), VIA::GetDrill(), TRACK::GetEnd(), BOARD_ITEM::GetLayerName(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_ITEM::GetParent(), VIA::GetSelectMenuText(), TRACK::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), VIA::GetViaType(), TRACK::GetWidth(), VIA::LayerPair(), PCB_VIA_T, THROW_IO_ERROR, EDA_ITEM::Type(), UNDEFINED_DRILL_DIAMETER, VIA_BLIND_BURIED, VIA_MICROVIA, and VIA_THROUGH.

1586 {
1587  if( aTrack->Type() == PCB_VIA_T )
1588  {
1589  PCB_LAYER_ID layer1, layer2;
1590 
1591  const VIA* via = static_cast<const VIA*>( aTrack );
1592  BOARD* board = (BOARD*) via->GetParent();
1593 
1594  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText() +
1595  wxT( " has no parent." ) );
1596 
1597  m_out->Print( aNestLevel, "(via" );
1598 
1599  via->LayerPair( &layer1, &layer2 );
1600 
1601  switch( via->GetViaType() )
1602  {
1603  case VIA_THROUGH: // Default shape not saved.
1604  break;
1605 
1606  case VIA_BLIND_BURIED:
1607  m_out->Print( 0, " blind" );
1608  break;
1609 
1610  case VIA_MICROVIA:
1611  m_out->Print( 0, " micro" );
1612  break;
1613 
1614  default:
1615  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1616  }
1617 
1618  m_out->Print( 0, " (at %s) (size %s)",
1619  FMT_IU( aTrack->GetStart() ).c_str(),
1620  FMT_IU( aTrack->GetWidth() ).c_str() );
1621 
1622  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1623  m_out->Print( 0, " (drill %s)", FMT_IU( via->GetDrill() ).c_str() );
1624 
1625  m_out->Print( 0, " (layers %s %s)",
1626  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1627  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1628  }
1629  else
1630  {
1631  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1632  FMT_IU( aTrack->GetStart() ).c_str(), FMT_IU( aTrack->GetEnd() ).c_str(),
1633  FMT_IU( aTrack->GetWidth() ).c_str() );
1634 
1635  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1636  }
1637 
1638  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1639 
1640  if( aTrack->GetTimeStamp() != 0 )
1641  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTrack->GetTimeStamp() );
1642 
1643  if( aTrack->GetStatus() != 0 )
1644  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1645 
1646  m_out->Print( 0, ")\n" );
1647 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
BOARD_ITEM_CONTAINER * GetParent() const
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:261
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:475
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:119
#define FMT_IU
PCB_LAYER_ID
A quick note on layer IDs:
VIATYPE_T GetViaType() const
Definition: class_track.h:460
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:122
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:482
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:59
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...
int GetNetCode() const
Function GetNetCode.
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int GetWidth() const
Definition: class_track.h:116
BOARD * m_board
which BOARD, no ownership here
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void PCB_IO::format ( ZONE_CONTAINER aZone,
int  aNestLevel = 0 
) const
private

Definition at line 1650 of file kicad_plugin.cpp.

References SHAPE_POLY_SET::CIterate(), ZONE_CONTAINER::DIAGONAL_EDGE, ZONE_CONTAINER::DIAGONAL_FULL, ZONE_CONTAINER::FillSegments(), FMT_IU, Format(), ZONE_CONTAINER::GetArcSegmentCount(), ZONE_CONTAINER::GetCornerRadius(), ZONE_CONTAINER::GetCornerSmoothingType(), ZONE_CONTAINER::GetDoNotAllowCopperPour(), ZONE_CONTAINER::GetDoNotAllowTracks(), ZONE_CONTAINER::GetDoNotAllowVias(), ZONE_CONTAINER::GetFilledPolysList(), ZONE_CONTAINER::GetFillMode(), ZONE_CONTAINER::GetHatchPitch(), ZONE_CONTAINER::GetHatchStyle(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::GetLayerSet(), ZONE_CONTAINER::GetMinThickness(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), ZONE_CONTAINER::GetNumCorners(), ZONE_CONTAINER::GetPadConnection(), ZONE_CONTAINER::GetPriority(), ZONE_CONTAINER::GetThermalReliefCopperBridge(), ZONE_CONTAINER::GetThermalReliefGap(), EDA_ITEM::GetTimeStamp(), ZONE_CONTAINER::GetZoneClearance(), SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::IsFilled(), ZONE_CONTAINER::IterateWithHoles(), 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.

1651 {
1652  // Save the NET info; For keepout zones, net code and net name are irrelevant
1653  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1654  // (perhaps netcode and netname should be not stored)
1655  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1656  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1657  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1658 
1659  // If a zone exists on multiple layers, format accordingly
1660  if( aZone->GetLayerSet().count() > 1 )
1661  {
1662  formatLayers( aZone->GetLayerSet() );
1663  }
1664  else
1665  {
1666  formatLayer( aZone );
1667  }
1668 
1669  m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
1670 
1671  // Save the outline aux info
1672  std::string hatch;
1673 
1674  switch( aZone->GetHatchStyle() )
1675  {
1676  default:
1677  case ZONE_CONTAINER::NO_HATCH: hatch = "none"; break;
1678  case ZONE_CONTAINER::DIAGONAL_EDGE: hatch = "edge"; break;
1679  case ZONE_CONTAINER::DIAGONAL_FULL: hatch = "full"; break;
1680  }
1681 
1682  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1683  FMT_IU( aZone->GetHatchPitch() ).c_str() );
1684 
1685  if( aZone->GetPriority() > 0 )
1686  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1687 
1688  m_out->Print( aNestLevel+1, "(connect_pads" );
1689 
1690  switch( aZone->GetPadConnection() )
1691  {
1692  default:
1693  case PAD_ZONE_CONN_THERMAL: // Default option not saved or loaded.
1694  break;
1695 
1697  m_out->Print( 0, " thru_hole_only" );
1698  break;
1699 
1700  case PAD_ZONE_CONN_FULL:
1701  m_out->Print( 0, " yes" );
1702  break;
1703 
1704  case PAD_ZONE_CONN_NONE:
1705  m_out->Print( 0, " no" );
1706  break;
1707  }
1708 
1709  m_out->Print( 0, " (clearance %s))\n",
1710  FMT_IU( aZone->GetZoneClearance() ).c_str() );
1711 
1712  m_out->Print( aNestLevel+1, "(min_thickness %s)\n",
1713  FMT_IU( aZone->GetMinThickness() ).c_str() );
1714 
1715  if( aZone->GetIsKeepout() )
1716  {
1717  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
1718  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1719  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1720  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
1721  }
1722 
1723  m_out->Print( aNestLevel+1, "(fill" );
1724 
1725  // Default is not filled.
1726  if( aZone->IsFilled() )
1727  m_out->Print( 0, " yes" );
1728 
1729  // Default is polygon filled.
1730  if( aZone->GetFillMode() )
1731  m_out->Print( 0, " (mode segment)" );
1732 
1733  m_out->Print( 0, " (arc_segments %d) (thermal_gap %s) (thermal_bridge_width %s)",
1734  aZone->GetArcSegmentCount(),
1735  FMT_IU( aZone->GetThermalReliefGap() ).c_str(),
1736  FMT_IU( aZone->GetThermalReliefCopperBridge() ).c_str() );
1737 
1739  {
1740  m_out->Print( 0, " (smoothing" );
1741 
1742  switch( aZone->GetCornerSmoothingType() )
1743  {
1745  m_out->Print( 0, " chamfer" );
1746  break;
1747 
1749  m_out->Print( 0, " fillet" );
1750  break;
1751 
1752  default:
1753  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1754  aZone->GetCornerSmoothingType() ) );
1755  }
1756  m_out->Print( 0, ")" );
1757 
1758  if( aZone->GetCornerRadius() != 0 )
1759  m_out->Print( 0, " (radius %s)",
1760  FMT_IU( aZone->GetCornerRadius() ).c_str() );
1761  }
1762 
1763  m_out->Print( 0, ")\n" );
1764 
1765  int newLine = 0;
1766 
1767  if( aZone->GetNumCorners() )
1768  {
1769  bool new_polygon = true;
1770  bool is_closed = false;
1771 
1772  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1773  {
1774  if( new_polygon )
1775  {
1776  newLine = 0;
1777  m_out->Print( aNestLevel+1, "(polygon\n" );
1778  m_out->Print( aNestLevel+2, "(pts\n" );
1779  new_polygon = false;
1780  is_closed = false;
1781  }
1782 
1783  if( newLine == 0 )
1784  m_out->Print( aNestLevel+3, "(xy %s %s)",
1785  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1786  else
1787  m_out->Print( 0, " (xy %s %s)",
1788  FMT_IU( iterator->x ).c_str(), FMT_IU( iterator->y ).c_str() );
1789 
1790  if( newLine < 4 )
1791  {
1792  newLine += 1;
1793  }
1794  else
1795  {
1796  newLine = 0;
1797  m_out->Print( 0, "\n" );
1798  }
1799 
1800  if( iterator.IsEndContour() )
1801  {
1802  is_closed = true;
1803 
1804  if( newLine != 0 )
1805  m_out->Print( 0, "\n" );
1806 
1807  m_out->Print( aNestLevel+2, ")\n" );
1808  m_out->Print( aNestLevel+1, ")\n" );
1809  new_polygon = true;
1810  }
1811  }
1812 
1813  if( !is_closed ) // Should not happen, but...
1814  m_out->Print( aNestLevel+1, ")\n" );
1815 
1816  }
1817 
1818  // Save the PolysList (filled areas)
1819  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1820  newLine = 0;
1821 
1822  if( !fv.IsEmpty() )
1823  {
1824  bool new_polygon = true;
1825  bool is_closed = false;
1826 
1827  for( auto it = fv.CIterate(); it; ++it )
1828  {
1829  if( new_polygon )
1830  {
1831  newLine = 0;
1832  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1833  m_out->Print( aNestLevel+2, "(pts\n" );
1834  new_polygon = false;
1835  is_closed = false;
1836  }
1837 
1838  if( newLine == 0 )
1839  m_out->Print( aNestLevel+3, "(xy %s %s)",
1840  FMT_IU( it->x ).c_str(), FMT_IU( it->y ).c_str() );
1841  else
1842  m_out->Print( 0, " (xy %s %s)",
1843  FMT_IU( it->x ) .c_str(), FMT_IU( it->y ).c_str() );
1844 
1845  if( newLine < 4 )
1846  {
1847  newLine += 1;
1848  }
1849  else
1850  {
1851  newLine = 0;
1852  m_out->Print( 0, "\n" );
1853  }
1854 
1855  if( it.IsEndContour() )
1856  {
1857  is_closed = true;
1858 
1859  if( newLine != 0 )
1860  m_out->Print( 0, "\n" );
1861 
1862  m_out->Print( aNestLevel+2, ")\n" );
1863  m_out->Print( aNestLevel+1, ")\n" );
1864  new_polygon = true;
1865  }
1866  }
1867 
1868  if( !is_closed ) // Should not happen, but...
1869  m_out->Print( aNestLevel+1, ")\n" );
1870  }
1871 
1872  // Save the filling segments list
1873  const auto& segs = aZone->FillSegments();
1874 
1875  if( segs.size() )
1876  {
1877  m_out->Print( aNestLevel+1, "(fill_segments\n" );
1878 
1879  for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
1880  {
1881  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
1882  FMT_IU( wxPoint( it->A ) ).c_str(),
1883  FMT_IU( wxPoint( it->B ) ).c_str() );
1884  }
1885 
1886  m_out->Print( aNestLevel+1, ")\n" );
1887  }
1888 
1889  m_out->Print( aNestLevel, ")\n" );
1890 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:414
int GetMinThickness() const
Definition: class_zone.h:198
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:603
int GetArcSegmentCount() const
Definition: class_zone.h:187
bool IsFilled() const
Definition: class_zone.h:189
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
ZONE_SEGMENT_FILL & FillSegments()
Definition: class_zone.h:233
void formatLayer(const BOARD_ITEM *aItem) const
int GetCornerSmoothingType() const
Definition: class_zone.h:570
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:637
unsigned int GetCornerRadius() const
Definition: class_zone.h:574
Pads are not covered.
Definition: zones.h:57
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:230
#define FMT_IU
ZoneConnection GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:997
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:628
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:175
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
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:534
Thermal relief only for THT pads.
Definition: zones.h:60
int GetNetCode() const
Function GetNetCode.
bool GetDoNotAllowTracks() const
Definition: class_zone.h:605
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:604
SHAPE_POLY_SET::ITERATOR IterateWithHoles()
Function IterateWithHoles returns an iterator to visit all points of the zone&#39;s main outline with hol...
Definition: class_zone.h:434
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:498
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int GetHatchPitch() const
Hatch related methods.
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:404
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:101
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Use thermal relief for pads.
Definition: zones.h:58
int GetZoneClearance() const
Definition: class_zone.h:192
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
pads are covered by copper
Definition: zones.h:59
void PCB_IO::formatBoardLayers ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the board layer information

Definition at line 647 of file kicad_plugin.cpp.

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, cu, LSET::CuStack(), DIM, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, BOARD::GetEnabledLayers(), BOARD::GetLayerName(), BOARD::GetLayerType(), BOARD::GetVisibleLayers(), Margin, LSET::Seq(), and LAYER::ShowType().

Referenced by CLIPBOARD_IO::SaveSelection().

648 {
649  m_out->Print( aNestLevel, "(layers\n" );
650 
651  // Save only the used copper layers from front to back.
652  LSET visible_layers = aBoard->GetVisibleLayers();
653 
654  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
655  {
656  PCB_LAYER_ID layer = *cu;
657 
658  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
659  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
660  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
661 
662  if( !visible_layers[layer] )
663  m_out->Print( 0, " hide" );
664 
665  m_out->Print( 0, ")\n" );
666  }
667 
668  // Save used non-copper layers in the order they are defined.
669  // desired sequence for non Cu BOARD layers.
670  static const PCB_LAYER_ID non_cu[] =
671  {
672  B_Adhes, // 32
673  F_Adhes,
674  B_Paste,
675  F_Paste,
676  B_SilkS,
677  F_SilkS,
678  B_Mask,
679  F_Mask,
680  Dwgs_User,
681  Cmts_User,
682  Eco1_User,
683  Eco2_User,
684  Edge_Cuts,
685  Margin,
686  B_CrtYd,
687  F_CrtYd,
688  B_Fab,
689  F_Fab
690  };
691 
692  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) ); seq; ++seq )
693  {
694  PCB_LAYER_ID layer = *seq;
695 
696  m_out->Print( aNestLevel+1, "(%d %s user", layer,
697  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
698 
699  if( !visible_layers[layer] )
700  m_out->Print( 0, " hide" );
701 
702  m_out->Print( 0, ")\n" );
703  }
704 
705  m_out->Print( aNestLevel, ")\n\n" );
706 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:147
#define cu(a)
Definition: auxiliary.h:88
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
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:364
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:482
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void PCB_IO::formatGeneral ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the General section of the file

Definition at line 625 of file kicad_plugin.cpp.

References BOARD::Drawings(), FMT_IU, TITLE_BLOCK::Format(), PAGE_INFO::Format(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), DHEAD::GetCount(), BOARD::GetDesignSettings(), BOARD::GetNumSegmTrack(), BOARD::GetNumSegmZone(), BOARD::GetPageSettings(), BOARD::GetTitleBlock(), and BOARD::m_Modules.

626 {
627  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
628 
629  m_out->Print( 0, "\n" );
630  m_out->Print( aNestLevel, "(general\n" );
631  // Write Bounding box info
632  m_out->Print( aNestLevel+1, "(thickness %s)\n",
633  FMT_IU( dsnSettings.GetBoardThickness() ).c_str() );
634 
635  m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->Drawings().Size() );
636  m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
637  m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
638  m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
639  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
640  m_out->Print( aNestLevel, ")\n\n" );
641 
642  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
643  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
644 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
#define FMT_IU
int GetSize() const
Function GetSize.
Definition: netinfo.h:375
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:246
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.
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:550
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:267
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:556
DLIST< MODULE > m_Modules
Definition: class_board.h:247
int GetNumSegmZone() const
Calculate the zone segment count.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:254
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatHeader ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

writes everything that comes before the board_items, like settings and layers etc

Definition at line 739 of file kicad_plugin.cpp.

740 {
741  formatGeneral( aBoard, aNestLevel );
742  // Layers.
743  formatBoardLayers( aBoard, aNestLevel );
744  // Setup
745  formatSetup( aBoard, aNestLevel );
746  // Save net codes and names
747  formatNetInformation( aBoard, aNestLevel );
748 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
void formatSetup(BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
void PCB_IO::formatLayer ( const BOARD_ITEM aItem) const
private

Definition at line 494 of file kicad_plugin.cpp.

References CTL_STD_LAYER_NAMES, BOARD_ITEM::GetLayer(), BOARD_ITEM::GetLayerName(), BOARD::GetStandardLayerName(), and TO_UTF8.

495 {
496  if( m_ctl & CTL_STD_LAYER_NAMES )
497  {
498  PCB_LAYER_ID layer = aItem->GetLayer();
499 
500  // English layer names should never need quoting.
501  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
502  }
503  else
504  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
505 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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:482
#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:404
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:650
void PCB_IO::formatLayers ( LSET  aLayerMask,
int  aNestLevel = 0 
) const
private

Definition at line 1188 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.

1189 {
1190  std::string output;
1191 
1192  if( aNestLevel == 0 )
1193  output += ' ';
1194 
1195  output += "(layers";
1196 
1197  static const LSET cu_all( LSET::AllCuMask() );
1198  static const LSET fr_bk( 2, B_Cu, F_Cu );
1199  static const LSET adhes( 2, B_Adhes, F_Adhes );
1200  static const LSET paste( 2, B_Paste, F_Paste );
1201  static const LSET silks( 2, B_SilkS, F_SilkS );
1202  static const LSET mask( 2, B_Mask, F_Mask );
1203  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1204  static const LSET fab( 2, B_Fab, F_Fab );
1205 
1206  LSET cu_mask = cu_all;
1207 
1208  // output copper layers first, then non copper
1209 
1210  if( ( aLayerMask & cu_mask ) == cu_mask )
1211  {
1212  output += " *.Cu";
1213  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1214  }
1215  else if( ( aLayerMask & cu_mask ) == fr_bk )
1216  {
1217  output += " F&B.Cu";
1218  aLayerMask &= ~fr_bk;
1219  }
1220 
1221  if( ( aLayerMask & adhes ) == adhes )
1222  {
1223  output += " *.Adhes";
1224  aLayerMask &= ~adhes;
1225  }
1226 
1227  if( ( aLayerMask & paste ) == paste )
1228  {
1229  output += " *.Paste";
1230  aLayerMask &= ~paste;
1231  }
1232 
1233  if( ( aLayerMask & silks ) == silks )
1234  {
1235  output += " *.SilkS";
1236  aLayerMask &= ~silks;
1237  }
1238 
1239  if( ( aLayerMask & mask ) == mask )
1240  {
1241  output += " *.Mask";
1242  aLayerMask &= ~mask;
1243  }
1244 
1245  if( ( aLayerMask & crt_yd ) == crt_yd )
1246  {
1247  output += " *.CrtYd";
1248  aLayerMask &= ~crt_yd;
1249  }
1250 
1251  if( ( aLayerMask & fab ) == fab )
1252  {
1253  output += " *.Fab";
1254  aLayerMask &= ~fab;
1255  }
1256 
1257  // output any individual layers not handled in wildcard combos above
1258 
1259  wxString layerName;
1260 
1261  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1262  {
1263  if( aLayerMask[layer] )
1264  {
1265  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1266  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1267 
1268  else // I am being called from FootprintSave()
1269  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1270 
1271  output += ' ';
1272  output += m_out->Quotew( layerName );
1273  }
1274  }
1275 
1276  m_out->Print( aNestLevel, "%s)", output.c_str() );
1277 }
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:673
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
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:482
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:404
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:650
void PCB_IO::formatNetInformation ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the Nets and Netclasses

Definition at line 709 of file kicad_plugin.cpp.

References NETCLASSES::begin(), NETCLASSES::end(), filterNetClass(), NETCLASS::Format(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), and BOARD_DESIGN_SETTINGS::m_NetClasses.

Referenced by CLIPBOARD_IO::SaveSelection().

710 {
711  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
712  for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
713  net != netEnd; ++net )
714  {
715  m_out->Print( aNestLevel, "(net %d %s)\n",
716  m_mapping->Translate( net->GetNet() ),
717  m_out->Quotew( net->GetNetname() ).c_str() );
718  }
719 
720  m_out->Print( 0, "\n" );
721 
722  // Save the default net class first.
723  NETCLASS defaultNC = *dsnSettings.GetDefault();
724  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
725  defaultNC.Format( m_out, aNestLevel, m_ctl );
726 
727  // Save the rest of the net classes alphabetically.
728  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
729  it != dsnSettings.m_NetClasses.end();
730  ++it )
731  {
732  NETCLASS netclass = *it->second;
733  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
734  netclass.Format( m_out, aNestLevel, m_ctl );
735  }
736 }
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:355
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
NETCLASSPTR GetDefault() const
Function GetDefault.
iterator end()
Definition: netclass.h:256
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:258
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:366
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the net class to aFormatter in s-expression form.
Definition: netclass.cpp:253
iterator begin()
Definition: netclass.h:255
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:305
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
void filterNetClass(const BOARD &aBoard, NETCLASS &aNetClass)
Removes empty nets (i.e. with node count equal zero) from net classes
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatSetup ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the board setup information

Definition at line 507 of file kicad_plugin.cpp.

References Double2Str(), FMT_IU, PCB_PLOT_PARAMS::Format(), BOARD::GetAuxOrigin(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), D_PAD::GetDrillSize(), BOARD::GetGridOrigin(), BOARD::GetPlotOptions(), D_PAD::GetSize(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), BOARD::GetZoneSettings(), 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_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, ZONE_SETTINGS::m_Zone_45_Only, ZONE_SETTINGS::m_ZoneClearance, wxPoint::x, and wxPoint::y.

508 {
509  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
510 
511  // Setup
512  m_out->Print( aNestLevel, "(setup\n" );
513 
514  // Save current default track width, for compatibility with older Pcbnew version;
515  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
516  FMT_IU( dsnSettings.GetCurrentTrackWidth() ).c_str() );
517 
518  // Save custom tracks width list (the first is not saved here: this is the netclass value
519  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
520  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
521  FMT_IU( dsnSettings.m_TrackWidthList[ii] ).c_str() );
522 
523  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
524  FMT_IU( dsnSettings.GetDefault()->GetClearance() ).c_str() );
525 
526  // ZONE_SETTINGS
527  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
528  FMT_IU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
529  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
530  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
531 
532  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
533  FMT_IU( dsnSettings.m_TrackMinWidth ).c_str() );
534 
535  m_out->Print( aNestLevel+1, "(segment_width %s)\n",
536  FMT_IU( dsnSettings.m_DrawSegmentWidth ).c_str() );
537  m_out->Print( aNestLevel+1, "(edge_width %s)\n",
538  FMT_IU( dsnSettings.m_EdgeSegmentWidth ).c_str() );
539 
540  // Save current default via size, for compatibility with older Pcbnew version;
541  m_out->Print( aNestLevel+1, "(via_size %s)\n",
542  FMT_IU( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
543  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
544  FMT_IU( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
545  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
546  FMT_IU( dsnSettings.m_ViasMinSize ).c_str() );
547  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
548  FMT_IU( dsnSettings.m_ViasMinDrill ).c_str() );
549 
550  // Save custom vias diameters list (the first is not saved here: this is
551  // the netclass value
552  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
553  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
554  FMT_IU( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
555  FMT_IU( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
556 
557  // for old versions compatibility:
558  if( dsnSettings.m_BlindBuriedViaAllowed )
559  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
560 
561  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
562  FMT_IU( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
563  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
564  FMT_IU( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
565  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
566  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
567  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
568  FMT_IU( dsnSettings.m_MicroViasMinSize ).c_str() );
569  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
570  FMT_IU( dsnSettings.m_MicroViasMinDrill ).c_str() );
571 
572  m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
573  FMT_IU( dsnSettings.m_PcbTextWidth ).c_str() );
574  m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
575  FMT_IU( dsnSettings.m_PcbTextSize.x ).c_str(),
576  FMT_IU( dsnSettings.m_PcbTextSize.y ).c_str() );
577 
578  m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
579  FMT_IU( dsnSettings.m_ModuleSegmentWidth ).c_str() );
580  m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
581  FMT_IU( dsnSettings.m_ModuleTextSize.x ).c_str(),
582  FMT_IU( dsnSettings.m_ModuleTextSize.y ).c_str() );
583  m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
584  FMT_IU( dsnSettings.m_ModuleTextWidth ).c_str() );
585 
586  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
587  FMT_IU( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
588  FMT_IU( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
589  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
590  FMT_IU( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
591 
592  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
593  FMT_IU( dsnSettings.m_SolderMaskMargin ).c_str() );
594 
595  if( dsnSettings.m_SolderMaskMinWidth )
596  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
597  FMT_IU( dsnSettings.m_SolderMaskMinWidth ).c_str() );
598 
599  if( dsnSettings.m_SolderPasteMargin != 0 )
600  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
601  FMT_IU( dsnSettings.m_SolderPasteMargin ).c_str() );
602 
603  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
604  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
605  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
606 
607  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
608  FMT_IU( aBoard->GetAuxOrigin().x ).c_str(),
609  FMT_IU( aBoard->GetAuxOrigin().y ).c_str() );
610 
611  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
612  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
613  FMT_IU( aBoard->GetGridOrigin().x ).c_str(),
614  FMT_IU( aBoard->GetGridOrigin().y ).c_str() );
615 
616  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
617  dsnSettings.GetVisibleElements() );
618 
619  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
620 
621  m_out->Print( aNestLevel, ")\n\n" );
622 }
int m_SolderMaskMargin
Solder mask margin.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:559
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
NETCLASSPTR GetDefault() const
Function GetDefault.
const wxPoint & GetGridOrigin() const
Definition: class_board.h:353
int m_SolderPasteMargin
Solder paste margin absolute value.
int m_ModuleTextWidth
Default footprint texts thickness.
std::vector< int > m_TrackWidthList
Track width list.
int m_ModuleSegmentWidth
Default width for all graphic lines.
int m_PcbTextWidth
current Pcb (not module) Text width
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
wxSize m_ModuleTextSize
Default footprint texts size.
#define FMT_IU
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
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:553
const wxSize & GetSize() const
Definition: class_pad.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:63
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
int m_MicroViasMinSize
micro vias (not vias) min diameter
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:346
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
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:404
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.
int m_SolderMaskMinWidth
Solder mask min width.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

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

References CTL_FOR_BOARD, FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintLibDelete(), FootprintLoad(), FootprintSave(), Format(), GetLibraryTimestamp(), IsFootprintLibWritable(), Load(), LoadEnumeratedFootprint(), PCB_IO(), Save(), and ~PCB_IO().

107  {
108  // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
109  // but to be pure, a plugin should not assume that it will always be linked
110  // with the core of the pcbnew code. (Might someday be a DLL/DSO.) Besides,
111  // file extension policy should be controlled by the plugin.
112  return wxT( "kicad_pcb" );
113  }
long long PCB_IO::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
overridevirtual

Generate a timestamp representing all the files in the library (including the library directory).

Timestamps should not be considered ordered; they either match or they don't.

Implements PLUGIN.

Definition at line 2167 of file kicad_plugin.cpp.

References FP_CACHE::GetTimestamp(), FP_CACHE::IsPath(), and m_cache.

Referenced by GetFileExtension(), and GITHUB_PLUGIN::GetLibraryTimestamp().

2168 {
2169  // If we have no cache, return a number which won't match any stored timestamps
2170  if( !m_cache || !m_cache->IsPath( aLibraryPath ) )
2171  return wxDateTime::Now().GetValue().GetValue();
2172 
2173  return m_cache->GetTimestamp();
2174 }
FP_CACHE * m_cache
Footprint library cache.
long long GetTimestamp()
Function GetTimestamp Generate a timestamp representing all source files in the cache (including the ...
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
std::string PCB_IO::GetStringOutput ( bool  doClear)
inline

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

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

161  {
162  std::string ret = m_sf.GetString();
163  if( doClear )
164  m_sf.Clear();
165 
166  return ret;
167  }
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 1956 of file kicad_plugin.cpp.

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

Referenced by doLoadFootprint(), FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintSave(), IsFootprintLibWritable(), CLIPBOARD_IO::Load(), Load(), PCB_IO(), and CLIPBOARD_IO::Save().

1957 {
1958  m_board = NULL;
1959  m_reader = NULL;
1961  m_props = aProperties;
1962 }
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 2272 of file kicad_plugin.cpp.

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

Referenced by GetFileExtension(), and GITHUB_PLUGIN::IsFootprintLibWritable().

2273 {
2274  LOCALE_IO toggle;
2275 
2276  init( NULL );
2277 
2278  validateCache( aLibraryPath );
2279 
2280  return m_cache->IsWritable();
2281 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const
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 1912 of file kicad_plugin.cpp.

References PCB_PARSER::GetRequiredVersion(), init(), PCB_PARSER::IsTooRecent(), m_parser, PCB_PARSER::Parse(), PCB_PARSER::SetBoard(), BOARD::SetFileName(), PCB_PARSER::SetLineReader(), and THROW_PARSE_ERROR.

Referenced by GetFileExtension().

1913 {
1914  FILE_LINE_READER reader( aFileName );
1915 
1916  init( aProperties );
1917 
1918  m_parser->SetLineReader( &reader );
1919  m_parser->SetBoard( aAppendToMe );
1920 
1921  BOARD* board;
1922 
1923  try
1924  {
1925  board = dynamic_cast<BOARD*>( m_parser->Parse() );
1926  }
1927  catch( const FUTURE_FORMAT_ERROR& )
1928  {
1929  // Don't wrap a FUTURE_FORMAT_ERROR in another
1930  throw;
1931  }
1932  catch( const PARSE_ERROR& parse_error )
1933  {
1934  if( m_parser->IsTooRecent() )
1935  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
1936  else
1937  throw;
1938  }
1939 
1940  if( !board )
1941  {
1942  // The parser loaded something that was valid, but wasn't a board.
1943  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
1944  m_parser->CurSource(), m_parser->CurLine(),
1945  m_parser->CurLineNumber(), m_parser->CurOffset() );
1946  }
1947 
1948  // Give the filename to the board if it's new
1949  if( !aAppendToMe )
1950  board->SetFileName( aFileName );
1951 
1952  return board;
1953 }
void init(const PROPERTIES *aProperties)
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:162
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:296
void SetFileName(const wxString &aFileName)
Definition: class_board.h:234
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:289
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:314
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&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:123
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
MODULE * PCB_IO::LoadEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented from PLUGIN.

Definition at line 2044 of file kicad_plugin.cpp.

References doLoadFootprint().

Referenced by GetFileExtension().

2047 {
2048  return doLoadFootprint( aLibraryPath, aFootprintName, aProperties, false );
2049 }
MODULE * doLoadFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)

Definition at line 415 of file kicad_plugin.cpp.

References TO_UTF8.

Referenced by CLIPBOARD_IO::Parse(), parse_module_kicad(), and SetOutputFormatter().

416 {
417  std::string input = TO_UTF8( aClipboardSourceInput );
418 
419  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
420 
421  m_parser->SetLineReader( &reader );
422 
423  try
424  {
425  return m_parser->Parse();
426  }
427  catch( const PARSE_ERROR& parse_error )
428  {
429  if( m_parser->IsTooRecent() )
430  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
431  else
432  throw;
433  }
434 }
#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:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:289
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:314
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&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:123
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
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 101 of file pcbnew/kicad_plugin.h.

102  {
103  return wxT( "KiCad" );
104  }
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.

Reimplemented in CLIPBOARD_IO.

Definition at line 391 of file kicad_plugin.cpp.

References Format(), GetBuildVersion(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and SEXPR_BOARD_FILE_VERSION.

Referenced by GetFileExtension().

392 {
393  LOCALE_IO toggle; // toggles on, then off, the C locale.
394 
395  init( aProperties );
396 
397  m_board = aBoard; // after init()
398 
399  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
400  m_mapping->SetBoard( aBoard );
401 
402  FILE_OUTPUTFORMATTER formatter( aFileName );
403 
404  m_out = &formatter; // no ownership
405 
406  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
407  formatter.Quotew( GetBuildVersion() ).c_str() );
408 
409  Format( aBoard, 1 );
410 
411  m_out->Print( 0, ")\n" );
412 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
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.
Definition: netinfo.h:281
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:404
void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inline

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

References m_out, and Parse().

169 { m_out = aFormatter; }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void PCB_IO::validateCache ( const wxString &  aLibraryPath,
bool  checkModified = true 
)
protected

Definition at line 1965 of file kicad_plugin.cpp.

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

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

1966 {
1967  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
1968  {
1969  // a spectacular episode in memory management:
1970  delete m_cache;
1971  m_cache = new FP_CACHE( this, aLibraryPath );
1972  m_cache->Load();
1973  }
1974 }
friend class FP_CACHE
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
void Load()

Friends And Related Function Documentation

friend class FP_CACHE
friend

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

Referenced by FootprintLibCreate(), and validateCache().

Member Data Documentation

BOARD* PCB_IO::m_board
protected

which BOARD, no ownership here

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

Referenced by init(), CLIPBOARD_IO::Save(), CLIPBOARD_IO::SaveSelection(), and CLIPBOARD_IO::SetBoard().

int PCB_IO::m_ctl
protected

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

Referenced by FootprintSave().

wxString PCB_IO::m_error
protected

for throwing exceptions

Definition at line 175 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 183 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 185 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 191 of file pcbnew/kicad_plugin.h.

Referenced by CLIPBOARD_IO::Save(), CLIPBOARD_IO::SaveSelection(), and ~PCB_IO().

OUTPUTFORMATTER* PCB_IO::m_out
protected

output any Format()s to this, no ownership

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

Referenced by CLIPBOARD_IO::CLIPBOARD_IO(), PCB_IO(), CLIPBOARD_IO::Save(), and SetOutputFormatter().

PCB_PARSER* PCB_IO::m_parser
protected

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

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

const PROPERTIES* PCB_IO::m_props
protected

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

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

Referenced by init().

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

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

Referenced by init().

STRING_FORMATTER PCB_IO::m_sf
protected

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

Referenced by GetStringOutput(), and PCB_IO().


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