KiCad PCB EDA Suite
PCB_IO Class Reference

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, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
const MODULEGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintExists check for the existence of a footprint. 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)
 
const MODULEgetFootprint (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 formatDefaults (const BOARD_DESIGN_SETTINGS &aSettings, int aNestLevel) const
 formats the defaults subsection of the board setup 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

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

Constructor & Destructor Documentation

◆ PCB_IO()

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 2012 of file kicad_plugin.cpp.

2012  :
2013  m_cache( 0 ),
2014  m_ctl( aControlFlags ),
2015  m_parser( new PCB_PARSER() ),
2016  m_mapping( new NETINFO_MAPPING() )
2017 {
2018  init( 0 );
2019  m_out = &m_sf;
2020 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
FP_CACHE * m_cache
Footprint library cache.
PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD...
Definition: pcb_parser.h:67
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

References init(), m_out, and m_sf.

◆ ~PCB_IO()

PCB_IO::~PCB_IO ( )

Definition at line 2023 of file kicad_plugin.cpp.

2024 {
2025  delete m_cache;
2026  delete m_parser;
2027  delete m_mapping;
2028 }
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

References m_cache, m_mapping, and m_parser.

Member Function Documentation

◆ FootprintDelete()

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

2292 {
2293  LOCALE_IO toggle; // toggles on, then off, the C locale.
2294 
2295  init( aProperties );
2296 
2297  validateCache( aLibraryPath );
2298 
2299  if( !m_cache->IsWritable() )
2300  {
2301  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only" ),
2302  aLibraryPath.GetData() ) );
2303  }
2304 
2305  m_cache->Remove( aFootprintName );
2306 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
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)
#define THROW_IO_ERROR(msg)
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 _(s)
Definition: 3d_actions.cpp:31

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

Referenced by GITHUB_PLUGIN::FootprintDelete().

◆ FootprintEnumerate()

void PCB_IO::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
bool  aBestEfforts,
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.
aBestEffortsif true, don't throw on errors, just return an empty list.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 2096 of file kicad_plugin.cpp.

2098 {
2099  LOCALE_IO toggle; // toggles on, then off, the C locale.
2100  wxDir dir( aLibPath );
2101  wxString errorMsg;
2102 
2103  init( aProperties );
2104 
2105  try
2106  {
2107  validateCache( aLibPath );
2108  }
2109  catch( const IO_ERROR& ioe )
2110  {
2111  errorMsg = ioe.What();
2112  }
2113 
2114  // Some of the files may have been parsed correctly so we want to add the valid files to
2115  // the library.
2116 
2117  for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
2118  aFootprintNames.Add( it->first );
2119 
2120  if( !errorMsg.IsEmpty() && !aBestEfforts )
2121  THROW_IO_ERROR( errorMsg );
2122 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
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()

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

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

◆ FootprintExists()

bool PCB_IO::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintExists check for the existence of a footprint.

Reimplemented from PLUGIN.

Definition at line 2162 of file kicad_plugin.cpp.

2164 {
2165  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2166  // only in case.
2167  //
2168  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2169  // case-insensitive filesystem) handled "for free".
2170  // Warning: footprint names frequently contain a point. So be careful when initializing
2171  // wxFileName, and use a CTOR with extension specified
2172  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2173 
2174  return footprintFile.Exists();
2175 }
const std::string KiCadFootprintFileExtension

References KiCadFootprintFileExtension.

◆ FootprintLibCreate()

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

2317 {
2318  if( wxDir::Exists( aLibraryPath ) )
2319  {
2320  THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path \"%s\"" ),
2321  aLibraryPath.GetData() ) );
2322  }
2323 
2324  LOCALE_IO toggle;
2325 
2326  init( aProperties );
2327 
2328  delete m_cache;
2329  m_cache = new FP_CACHE( this, aLibraryPath );
2330  m_cache->Save();
2331 }
friend class FP_CACHE
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
#define THROW_IO_ERROR(msg)
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 _(s)
Definition: 3d_actions.cpp:31

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

Referenced by GITHUB_PLUGIN::FootprintLibCreate().

◆ FootprintLibDelete()

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

2335 {
2336  wxFileName fn;
2337  fn.SetPath( aLibraryPath );
2338 
2339  // Return if there is no library path to delete.
2340  if( !fn.DirExists() )
2341  return false;
2342 
2343  if( !fn.IsDirWritable() )
2344  {
2345  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory \"%s\"" ),
2346  aLibraryPath.GetData() ) );
2347  }
2348 
2349  wxDir dir( aLibraryPath );
2350 
2351  if( dir.HasSubDirs() )
2352  {
2353  THROW_IO_ERROR( wxString::Format( _( "library directory \"%s\" has unexpected sub-directories" ),
2354  aLibraryPath.GetData() ) );
2355  }
2356 
2357  // All the footprint files must be deleted before the directory can be deleted.
2358  if( dir.HasFiles() )
2359  {
2360  unsigned i;
2361  wxFileName tmp;
2362  wxArrayString files;
2363 
2364  wxDir::GetAllFiles( aLibraryPath, &files );
2365 
2366  for( i = 0; i < files.GetCount(); i++ )
2367  {
2368  tmp = files[i];
2369 
2370  if( tmp.GetExt() != KiCadFootprintFileExtension )
2371  {
2372  THROW_IO_ERROR( wxString::Format( _( "unexpected file \"%s\" was found in library path \"%s\"" ),
2373  files[i].GetData(), aLibraryPath.GetData() ) );
2374  }
2375  }
2376 
2377  for( i = 0; i < files.GetCount(); i++ )
2378  {
2379  wxRemoveFile( files[i] );
2380  }
2381  }
2382 
2383  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"" ),
2384  aLibraryPath.GetData() );
2385 
2386  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2387  // we don't want that. we want bare metal portability with no UI here.
2388  if( !wxRmdir( aLibraryPath ) )
2389  {
2390  THROW_IO_ERROR( wxString::Format( _( "footprint library \"%s\" cannot be deleted" ),
2391  aLibraryPath.GetData() ) );
2392  }
2393 
2394  // For some reason removing a directory in Windows is not immediately updated. This delay
2395  // prevents an error when attempting to immediately recreate the same directory when over
2396  // writing an existing library.
2397 #ifdef __WINDOWS__
2398  wxMilliSleep( 250L );
2399 #endif
2400 
2401  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2402  {
2403  delete m_cache;
2404  m_cache = NULL;
2405  }
2406 
2407  return true;
2408 }
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
#define NULL
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.
#define THROW_IO_ERROR(msg)
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 _(s)
Definition: 3d_actions.cpp:31

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

Referenced by GITHUB_PLUGIN::FootprintLibDelete().

◆ FootprintLibOptions()

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 140 of file plugin.cpp.

141 {
142  // disable all these in another couple of months, after everyone has seen them:
143 #if 1
144  (*aListToAppendTo)["debug_level"] = UTF8( _(
145  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
146  ));
147 
148  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
149  "Regular expression <b>footprint name</b> filter."
150  ));
151 
152  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
153  "Enable transaction logging. The mere presence of this option turns on the "
154  "logging, no need to set a Value."
155  ));
156 
157  (*aListToAppendTo)["username"] = UTF8( _(
158  "User name for <b>login</b> to some special library server."
159  ));
160 
161  (*aListToAppendTo)["password"] = UTF8( _(
162  "Password for <b>login</b> to some special library server."
163  ));
164 #endif
165 
166 #if 1
167  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
168  // if and when implemented.
169  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
170  "Enter the python module which implements the PLUGIN::Footprint*() functions."
171  ));
172 #endif
173 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
#define _(s)
Definition: 3d_actions.cpp:31

References _.

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

◆ FootprintLoad()

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

2180 {
2181  const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2182  return footprint ? new MODULE( *footprint ) : nullptr;
2183 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References getFootprint().

Referenced by GITHUB_PLUGIN::FootprintLoad().

◆ FootprintSave()

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

2188 {
2189  LOCALE_IO toggle; // toggles on, then off, the C locale.
2190 
2191  init( aProperties );
2192 
2193  // In this public PLUGIN API function, we can safely assume it was
2194  // called for saving into a library path.
2196 
2197  validateCache( aLibraryPath );
2198 
2199  if( !m_cache->IsWritable() )
2200  {
2201  if( !m_cache->Exists() )
2202  {
2203  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2204  "Would you like to create it?"),
2205  GetChars( aLibraryPath ) );
2206 
2207  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2208  return;
2209 
2210  // Save throws its own IO_ERROR on failure, so no need to recreate here
2211  m_cache->Save( NULL );
2212  }
2213  else
2214  {
2215  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
2216  THROW_IO_ERROR( msg );
2217  }
2218  }
2219 
2220  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2221 
2222  MODULE_MAP& mods = m_cache->GetModules();
2223 
2224  // Quietly overwrite module and delete module file from path for any by same name.
2225  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2227 
2228 #ifndef __WINDOWS__
2229  // Write through symlinks, don't replace them
2230  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2231  {
2232  char buffer[ PATH_MAX + 1 ];
2233  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2234 
2235  if( pathLen > 0 )
2236  {
2237  buffer[ pathLen ] = '\0';
2238  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2239  fn.Normalize();
2240  }
2241  }
2242 #endif
2243 
2244  if( !fn.IsOk() )
2245  {
2246  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2247  fn.GetFullPath() ) );
2248  }
2249 
2250  if( fn.FileExists() && !fn.IsFileWritable() )
2251  {
2252  THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
2253  fn.GetFullPath() ) );
2254  }
2255 
2256  wxString fullPath = fn.GetFullPath();
2257  wxString fullName = fn.GetFullName();
2258  MODULE_CITER it = mods.find( footprintName );
2259 
2260  if( it != mods.end() )
2261  {
2262  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2263  mods.erase( footprintName );
2264  wxRemoveFile( fullPath );
2265  }
2266 
2267  // I need my own copy for the cache
2268  MODULE* module = new MODULE( *aFootprint );
2269 
2270  // and it's time stamp must be 0, it should have no parent, orientation should
2271  // be zero, and it should be on the front layer.
2272  module->SetTimeStamp( 0 );
2273  module->SetParent( nullptr );
2274  module->SetOrientation( 0 );
2275 
2276  if( module->GetLayer() != F_Cu )
2277  {
2278  if( m_board != nullptr )
2279  module->Flip( module->GetPosition(), m_board->GeneralSettings().m_FlipLeftRight );
2280  else
2281  module->Flip( module->GetPosition(), false );
2282  }
2283 
2284  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2285  mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
2286  m_cache->Save( module );
2287 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
const LIB_ID & GetFPID() const
Definition: class_module.h:219
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define NULL
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
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:101
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: common.h:316
const PCB_GENERAL_SETTINGS & GeneralSettings() const
Definition: class_board.h:562
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 _(s)
Definition: 3d_actions.cpp:31
void SetOrientation(double newangle)
BOARD * m_board
which BOARD, no ownership here
bool Exists() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint GetPosition() const override
Definition: class_module.h:210
MODULE_MAP & GetModules()
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

References _, CTL_FOR_LIBRARY, FP_CACHE::Exists(), F_Cu, MODULE::Flip(), Format(), BOARD::GeneralSettings(), GetChars(), MODULE::GetFPID(), BOARD_ITEM::GetLayer(), LIB_ID::GetLibItemName(), FP_CACHE::GetModules(), MODULE::GetPosition(), init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, m_board, m_cache, m_ctl, PCB_GENERAL_SETTINGS::m_FlipLeftRight, NULL, FP_CACHE::Save(), MODULE::SetOrientation(), EDA_ITEM::SetParent(), EDA_ITEM::SetTimeStamp(), THROW_IO_ERROR, TO_UTF8, traceKicadPcbPlugin, and validateCache().

Referenced by GITHUB_PLUGIN::FootprintSave().

◆ Format()

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

402 {
403  LOCALE_IO toggle; // public API function, perform anything convenient for caller
404 
405  switch( aItem->Type() )
406  {
407  case PCB_T:
408  format( static_cast<BOARD*>( aItem ), aNestLevel );
409  break;
410 
411  case PCB_DIMENSION_T:
412  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
413  break;
414 
415  case PCB_LINE_T:
416  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
417  break;
418 
419  case PCB_MODULE_EDGE_T:
420  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
421  break;
422 
423  case PCB_TARGET_T:
424  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
425  break;
426 
427  case PCB_MODULE_T:
428  format( static_cast<MODULE*>( aItem ), aNestLevel );
429  break;
430 
431  case PCB_PAD_T:
432  format( static_cast<D_PAD*>( aItem ), aNestLevel );
433  break;
434 
435  case PCB_TEXT_T:
436  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
437  break;
438 
439  case PCB_MODULE_TEXT_T:
440  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
441  break;
442 
443  case PCB_TRACE_T:
444  case PCB_VIA_T:
445  format( static_cast<TRACK*>( aItem ), aNestLevel );
446  break;
447 
449  case PCB_ZONE_AREA_T:
450  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
451  break;
452 
453  default:
454  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
455  }
456 }
Definition: typeinfo.h:85
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:101
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:96
class MODULE, a footprint
Definition: typeinfo.h:89
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:99
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:100
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:97
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References format(), EDA_ITEM::GetClass(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_MODULE_ZONE_AREA_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(), format(), CLIPBOARD_IO::Save(), Save(), FP_CACHE::Save(), and CLIPBOARD_IO::SaveSelection().

◆ format() [1/11]

void PCB_IO::format ( BOARD aBoard,
int  aNestLevel = 0 
) const
private

Definition at line 767 of file kicad_plugin.cpp.

768 {
769  formatHeader( aBoard, aNestLevel );
770 
771  // Save the modules.
772  for( auto module : aBoard->Modules() )
773  {
774  Format( module, aNestLevel );
775  m_out->Print( 0, "\n" );
776  }
777 
778  // Save the graphical items on the board (not owned by a module)
779  for( auto item : aBoard->Drawings() )
780  Format( item, aNestLevel );
781 
782  if( aBoard->Drawings().size() )
783  m_out->Print( 0, "\n" );
784 
785  // Do not save MARKER_PCBs, they can be regenerated easily.
786 
787  // Save the tracks and vias.
788  for( auto track : aBoard->Tracks() )
789  Format( track, aNestLevel );
790 
791  if( aBoard->Tracks().size() )
792  m_out->Print( 0, "\n" );
793 
794  // Save the polygon (which are the newer technology) zones.
795  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
796  Format( aBoard->GetArea( i ), aNestLevel );
797 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:948
MODULES & Modules()
Definition: class_board.h:226
void formatHeader(BOARD *aBoard, int aNestLevel=0) const
writes everything that comes before the board_items, like settings and layers etc
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:913
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
DRAWINGS & Drawings()
Definition: class_board.h:235
TRACKS & Tracks()
Definition: class_board.h:217

References BOARD::Drawings(), Format(), formatHeader(), BOARD::GetArea(), BOARD::GetAreaCount(), m_out, BOARD::Modules(), OUTPUTFORMATTER::Print(), and BOARD::Tracks().

Referenced by Format(), and format().

◆ format() [2/11]

void PCB_IO::format ( DIMENSION aDimension,
int  aNestLevel = 0 
) const
private

Definition at line 800 of file kicad_plugin.cpp.

801 {
802  m_out->Print( aNestLevel, "(dimension %s (width %s)",
803  FormatInternalUnits( aDimension->GetValue() ).c_str(),
804  FormatInternalUnits( aDimension->GetWidth() ).c_str() );
805 
806  formatLayer( aDimension );
807 
808  if( aDimension->GetTimeStamp() )
809  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aDimension->GetTimeStamp() );
810 
811  m_out->Print( 0, "\n" );
812 
813  Format( &aDimension->Text(), aNestLevel+1 );
814 
815  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
816  FormatInternalUnits( aDimension->m_featureLineDO.x ).c_str(),
817  FormatInternalUnits( aDimension->m_featureLineDO.y ).c_str(),
818  FormatInternalUnits( aDimension->m_featureLineDF.x ).c_str(),
819  FormatInternalUnits( aDimension->m_featureLineDF.y ).c_str() );
820 
821  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
822  FormatInternalUnits( aDimension->m_featureLineGO.x ).c_str(),
823  FormatInternalUnits( aDimension->m_featureLineGO.y ).c_str(),
824  FormatInternalUnits( aDimension->m_featureLineGF.x ).c_str(),
825  FormatInternalUnits( aDimension->m_featureLineGF.y ).c_str() );
826 
827  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
828  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
829  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
830  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
831  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str() );
832 
833  m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
834  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
835  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
836  FormatInternalUnits( aDimension->m_arrowD1F.x ).c_str(),
837  FormatInternalUnits( aDimension->m_arrowD1F.y ).c_str() );
838 
839  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
840  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
841  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
842  FormatInternalUnits( aDimension->m_arrowD2F.x ).c_str(),
843  FormatInternalUnits( aDimension->m_arrowD2F.y ).c_str() );
844 
845  m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
846  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
847  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
848  FormatInternalUnits( aDimension->m_arrowG1F.x ).c_str(),
849  FormatInternalUnits( aDimension->m_arrowG1F.y ).c_str() );
850 
851  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
852  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
853  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
854  FormatInternalUnits( aDimension->m_arrowG2F.x ).c_str(),
855  FormatInternalUnits( aDimension->m_arrowG2F.y ).c_str() );
856 
857  m_out->Print( aNestLevel, ")\n" );
858 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetWidth() const
void formatLayer(const BOARD_ITEM *aItem) const
wxPoint m_crossBarF
wxPoint m_arrowD1F
wxPoint m_featureLineDF
wxPoint m_featureLineGO
int GetValue() const
wxPoint m_arrowG1F
wxPoint m_arrowD2F
wxPoint m_arrowG2F
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
TEXTE_PCB & Text()
wxPoint m_crossBarO
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
wxPoint m_featureLineDO
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
wxPoint m_featureLineGF

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

◆ format() [3/11]

void PCB_IO::format ( EDGE_MODULE aModuleDrawing,
int  aNestLevel = 0 
) const
private

Definition at line 939 of file kicad_plugin.cpp.

940 {
941  switch( aModuleDrawing->GetShape() )
942  {
943  case S_SEGMENT: // Line
944  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
945  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
946  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
947  break;
948 
949  case S_CIRCLE: // Circle
950  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
951  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
952  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
953  break;
954 
955  case S_ARC: // Arc
956  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
957  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
958  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str(),
959  FormatAngle( aModuleDrawing->GetAngle() ).c_str() );
960  break;
961 
962  case S_POLYGON: // Polygonal segment
963  if( aModuleDrawing->IsPolyShapeValid() )
964  {
965  SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
966  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
967  int pointsCount = outline.PointCount();
968 
969  m_out->Print( aNestLevel, "(fp_poly (pts" );
970 
971  for( int ii = 0; ii < pointsCount; ++ii )
972  {
973  int nestLevel = 0;
974 
975  if( ii && !( ii%4 ) ) // newline every 4 pts
976  {
977  nestLevel = aNestLevel + 1;
978  m_out->Print( 0, "\n" );
979  }
980 
981  m_out->Print( nestLevel, "%s(xy %s)",
982  nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
983  }
984 
985  m_out->Print( 0, ")" );
986  }
987  else
988  {
989  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
990  return;
991  }
992  break;
993 
994  case S_CURVE: // Bezier curve
995  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
996  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
997  FormatInternalUnits( aModuleDrawing->GetBezier0_C1() ).c_str(),
998  FormatInternalUnits( aModuleDrawing->GetBezier0_C2() ).c_str(),
999  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
1000  break;
1001 
1002  default:
1003  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
1004  return;
1005  };
1006 
1007  formatLayer( aModuleDrawing );
1008 
1009  m_out->Print( 0, " (width %s)", FormatInternalUnits( aModuleDrawing->GetWidth() ).c_str() );
1010 
1011  m_out->Print( 0, ")\n" );
1012 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
STROKE_T GetShape() const
polygon (not yet used for tracks, but could be in microwave apps)
usual segment : line with rounded ends
int PointCount() const
Function PointCount()
const wxPoint & GetStart0() const
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
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 & GetBezier0_C2() const
SHAPE_POLY_SET & GetPolyShape()
Bezier Curve.
int GetWidth() const
double GetAngle() const
SHAPE_LINE_CHAIN.
bool IsPolyShapeValid() const
const wxPoint & GetBezier0_C1() const
const wxPoint & GetEnd0() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References SHAPE_LINE_CHAIN::CPoint(), FormatAngle(), FormatInternalUnits(), formatLayer(), DRAWSEGMENT::GetAngle(), EDGE_MODULE::GetBezier0_C1(), EDGE_MODULE::GetBezier0_C2(), EDGE_MODULE::GetEnd0(), DRAWSEGMENT::GetPolyShape(), DRAWSEGMENT::GetShape(), EDGE_MODULE::GetStart0(), DRAWSEGMENT::GetWidth(), DRAWSEGMENT::IsPolyShapeValid(), m_out, SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::PointCount(), OUTPUTFORMATTER::Print(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

◆ format() [4/11]

void PCB_IO::format ( DRAWSEGMENT aSegment,
int  aNestLevel = 0 
) const
private

Definition at line 861 of file kicad_plugin.cpp.

862 {
863  switch( aSegment->GetShape() )
864  {
865  case S_SEGMENT: // Line
866  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
867  FormatInternalUnits( aSegment->GetStart() ).c_str(),
868  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
869 
870  if( aSegment->GetAngle() != 0.0 )
871  m_out->Print( 0, " (angle %s)", FormatAngle( aSegment->GetAngle() ).c_str() );
872 
873  break;
874 
875  case S_CIRCLE: // Circle
876  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
877  FormatInternalUnits( aSegment->GetStart() ).c_str(),
878  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
879  break;
880 
881  case S_ARC: // Arc
882  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
883  FormatInternalUnits( aSegment->GetStart() ).c_str(),
884  FormatInternalUnits( aSegment->GetEnd() ).c_str(),
885  FormatAngle( aSegment->GetAngle() ).c_str() );
886  break;
887 
888  case S_POLYGON: // Polygon
889  if( aSegment->IsPolyShapeValid() )
890  {
891  SHAPE_POLY_SET& poly = aSegment->GetPolyShape();
892  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
893  int pointsCount = outline.PointCount();
894 
895  m_out->Print( aNestLevel, "(gr_poly (pts" );
896 
897  for( int ii = 0; ii < pointsCount; ++ii )
898  {
899  m_out->Print( 0, " (xy %s)", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
900  }
901 
902  m_out->Print( 0, ")" );
903  }
904  else
905  {
906  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
907  return;
908  }
909 
910  break;
911 
912  case S_CURVE: // Bezier curve
913  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
914  FormatInternalUnits( aSegment->GetStart() ).c_str(),
915  FormatInternalUnits( aSegment->GetBezControl1() ).c_str(),
916  FormatInternalUnits( aSegment->GetBezControl2() ).c_str(),
917  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
918  break;
919 
920  default:
921  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
922  return;
923  };
924 
925  formatLayer( aSegment );
926 
927  m_out->Print( 0, " (width %s)", FormatInternalUnits( aSegment->GetWidth() ).c_str() );
928 
929  if( aSegment->GetTimeStamp() )
930  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aSegment->GetTimeStamp() );
931 
932  if( aSegment->GetStatus() )
933  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
934 
935  m_out->Print( 0, ")\n" );
936 }
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:252
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
STROKE_T GetShape() const
polygon (not yet used for tracks, but could be in microwave apps)
usual segment : line with rounded ends
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Arcs (with rounded ends)
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
SHAPE_POLY_SET & GetPolyShape()
Bezier Curve.
int GetWidth() const
double GetAngle() const
SHAPE_LINE_CHAIN.
const wxPoint & GetBezControl2() const
bool IsPolyShapeValid() const
const wxPoint & GetBezControl1() const
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References SHAPE_LINE_CHAIN::CPoint(), FormatAngle(), FormatInternalUnits(), formatLayer(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetBezControl1(), DRAWSEGMENT::GetBezControl2(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetPolyShape(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), DRAWSEGMENT::GetWidth(), DRAWSEGMENT::IsPolyShapeValid(), m_out, SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::PointCount(), OUTPUTFORMATTER::Print(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, and S_SEGMENT.

◆ format() [5/11]

void PCB_IO::format ( PCB_TARGET aTarget,
int  aNestLevel = 0 
) const
private

Definition at line 1015 of file kicad_plugin.cpp.

1016 {
1017  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
1018  ( aTarget->GetShape() ) ? "x" : "plus",
1019  FormatInternalUnits( aTarget->GetPosition() ).c_str(),
1020  FormatInternalUnits( aTarget->GetSize() ).c_str() );
1021 
1022  if( aTarget->GetWidth() != 0 )
1023  m_out->Print( 0, " (width %s)", FormatInternalUnits( aTarget->GetWidth() ).c_str() );
1024 
1025  formatLayer( aTarget );
1026 
1027  if( aTarget->GetTimeStamp() )
1028  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTarget->GetTimeStamp() );
1029 
1030  m_out->Print( 0, ")\n" );
1031 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
int GetSize() const
int GetWidth() const
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
int GetShape() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
const wxPoint GetPosition() const override

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

◆ format() [6/11]

void PCB_IO::format ( MODULE aModule,
int  aNestLevel = 0 
) const
private

Definition at line 1034 of file kicad_plugin.cpp.

1035 {
1036  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1037  {
1038  const wxArrayString* initial_comments = aModule->GetInitialComments();
1039 
1040  if( initial_comments )
1041  {
1042  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
1043  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1044 
1045  m_out->Print( 0, "\n" ); // improve readability?
1046  }
1047  }
1048 
1049  m_out->Print( aNestLevel, "(module %s",
1050  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1051 
1052  if( aModule->IsLocked() )
1053  m_out->Print( 0, " locked" );
1054 
1055  if( aModule->IsPlaced() )
1056  m_out->Print( 0, " placed" );
1057 
1058  formatLayer( aModule );
1059 
1060  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1061 
1062  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1063  {
1064  m_out->Print( 0, " (tstamp %lX)\n", (unsigned long)aModule->GetTimeStamp() );
1065  }
1066  else
1067  m_out->Print( 0, "\n" );
1068 
1069  if( !( m_ctl & CTL_OMIT_AT ) )
1070  {
1071  m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aModule->GetPosition() ).c_str() );
1072 
1073  if( aModule->GetOrientation() != 0.0 )
1074  m_out->Print( 0, " %s", FormatAngle( aModule->GetOrientation() ).c_str() );
1075 
1076  m_out->Print( 0, ")\n" );
1077  }
1078 
1079  if( !aModule->GetDescription().IsEmpty() )
1080  m_out->Print( aNestLevel+1, "(descr %s)\n",
1081  m_out->Quotew( aModule->GetDescription() ).c_str() );
1082 
1083  if( !aModule->GetKeywords().IsEmpty() )
1084  m_out->Print( aNestLevel+1, "(tags %s)\n",
1085  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1086 
1087  if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
1088  m_out->Print( aNestLevel+1, "(path %s)\n",
1089  m_out->Quotew( aModule->GetPath() ).c_str() );
1090 
1091  if( aModule->GetPlacementCost90() != 0 )
1092  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1093 
1094  if( aModule->GetPlacementCost180() != 0 )
1095  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1096 
1097  if( aModule->GetLocalSolderMaskMargin() != 0 )
1098  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1099  FormatInternalUnits( aModule->GetLocalSolderMaskMargin() ).c_str() );
1100 
1101  if( aModule->GetLocalSolderPasteMargin() != 0 )
1102  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1103  FormatInternalUnits( aModule->GetLocalSolderPasteMargin() ).c_str() );
1104 
1105  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1106  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1107  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1108 
1109  if( aModule->GetLocalClearance() != 0 )
1110  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1111  FormatInternalUnits( aModule->GetLocalClearance() ).c_str() );
1112 
1113  if( aModule->GetZoneConnection() != ZONE_CONNECTION::INHERITED )
1114  m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
1115  static_cast<int>( aModule->GetZoneConnection() ) );
1116 
1117  if( aModule->GetThermalWidth() != 0 )
1118  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1119  FormatInternalUnits( aModule->GetThermalWidth() ).c_str() );
1120 
1121  if( aModule->GetThermalGap() != 0 )
1122  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1123  FormatInternalUnits( aModule->GetThermalGap() ).c_str() );
1124 
1125  // Attributes
1126  if( aModule->GetAttributes() != MOD_DEFAULT )
1127  {
1128  m_out->Print( aNestLevel+1, "(attr" );
1129 
1130  if( aModule->GetAttributes() & MOD_CMS )
1131  m_out->Print( 0, " smd" );
1132 
1133  if( aModule->GetAttributes() & MOD_VIRTUAL )
1134  m_out->Print( 0, " virtual" );
1135 
1136  m_out->Print( 0, ")\n" );
1137  }
1138 
1139  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1140  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1141 
1142  // Save drawing elements.
1143  for( auto gr : aModule->GraphicalItems() )
1144  Format( gr, aNestLevel+1 );
1145 
1146  // Save pads.
1147  for( auto pad : aModule->Pads() )
1148  format( pad, aNestLevel+1 );
1149 
1150  // Save zones.
1151  for( auto zone : aModule->Zones() )
1152  format( zone, aNestLevel + 1 );
1153 
1154  // Save 3D info.
1155  auto bs3D = aModule->Models().begin();
1156  auto es3D = aModule->Models().end();
1157 
1158  while( bs3D != es3D )
1159  {
1160  if( !bs3D->m_Filename.IsEmpty() )
1161  {
1162  m_out->Print( aNestLevel+1, "(model %s\n",
1163  m_out->Quotew( bs3D->m_Filename ).c_str() );
1164 
1165  /* Write 3D model offset in mm
1166  * 4.0.x wrote "at" which was actually in inches
1167  * 5.0.x onwards, 3D model offset is written using "offset"
1168  *
1169  * If the offset is all zero, write "at" (fewer file changes)
1170  * Otherwise, write "offset"
1171  */
1172 
1173  wxString offsetTag = "offset";
1174 
1175  if( bs3D->m_Offset.x == 0 &&
1176  bs3D->m_Offset.y == 0 &&
1177  bs3D->m_Offset.z == 0 )
1178  {
1179  offsetTag = "at";
1180  }
1181 
1182  m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
1183  offsetTag.ToStdString().c_str(),
1184  Double2Str( bs3D->m_Offset.x ).c_str(),
1185  Double2Str( bs3D->m_Offset.y ).c_str(),
1186  Double2Str( bs3D->m_Offset.z ).c_str() );
1187 
1188  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1189  Double2Str( bs3D->m_Scale.x ).c_str(),
1190  Double2Str( bs3D->m_Scale.y ).c_str(),
1191  Double2Str( bs3D->m_Scale.z ).c_str() );
1192 
1193  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1194  Double2Str( bs3D->m_Rotation.x ).c_str(),
1195  Double2Str( bs3D->m_Rotation.y ).c_str(),
1196  Double2Str( bs3D->m_Rotation.z ).c_str() );
1197 
1198  m_out->Print( aNestLevel+1, ")\n" );
1199  }
1200  ++bs3D;
1201  }
1202 
1203  m_out->Print( aNestLevel, ")\n" );
1204 }
timestamp_t GetLastEditTime() const
Definition: class_module.h:349
int GetAttributes() const
Definition: class_module.h:259
double GetOrientation() const
Definition: class_module.h:215
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetPlacementCost90() const
Definition: class_module.h:555
TEXTE_MODULE & Reference()
Definition: class_module.h:477
#define CTL_OMIT_AT
Omit position and rotation.
void formatLayer(const BOARD_ITEM *aItem) const
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
bool IsPlaced() const
Definition: class_module.h:319
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:248
const wxString & GetPath() const
Definition: class_module.h:228
PADS & Pads()
Definition: class_module.h:173
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
const LIB_ID & GetFPID() const
Definition: class_module.h:219
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
int GetLocalSolderMaskMargin() const
Definition: class_module.h:231
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
int GetLocalClearance() const
Definition: class_module.h:234
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership.
Definition: class_module.h:661
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:301
const wxString & GetKeywords() const
Definition: class_module.h:225
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:188
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:237
default
Definition: class_module.h:73
int GetPlacementCost180() const
Definition: class_module.h:552
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
const wxString & GetDescription() const
Definition: class_module.h:222
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:240
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
void format(BOARD *aBoard, 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
#define CTL_OMIT_INITIAL_COMMENTS
omit MODULE initial comments
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
int GetThermalWidth() const
Definition: class_module.h:254
const wxPoint GetPosition() const override
Definition: class_module.h:210
int GetThermalGap() const
Definition: class_module.h:257
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References CTL_OMIT_AT, CTL_OMIT_INITIAL_COMMENTS, CTL_OMIT_PATH, CTL_OMIT_TSTAMPS, Double2Str(), LIB_ID::Format(), Format(), format(), FormatAngle(), FormatInternalUnits(), formatLayer(), MODULE::GetAttributes(), MODULE::GetDescription(), MODULE::GetFPID(), MODULE::GetInitialComments(), MODULE::GetKeywords(), MODULE::GetLastEditTime(), MODULE::GetLocalClearance(), MODULE::GetLocalSolderMaskMargin(), MODULE::GetLocalSolderPasteMargin(), MODULE::GetLocalSolderPasteMarginRatio(), MODULE::GetOrientation(), MODULE::GetPath(), MODULE::GetPlacementCost180(), MODULE::GetPlacementCost90(), MODULE::GetPosition(), MODULE::GetThermalGap(), MODULE::GetThermalWidth(), EDA_ITEM::GetTimeStamp(), MODULE::GetZoneConnection(), MODULE::GraphicalItems(), INHERITED, MODULE::IsLocked(), MODULE::IsPlaced(), m_ctl, m_out, MOD_CMS, MOD_DEFAULT, MOD_VIRTUAL, MODULE::Models(), MODULE::Pads(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotes(), OUTPUTFORMATTER::Quotew(), MODULE::Reference(), TO_UTF8, MODULE::Value(), and MODULE::Zones().

◆ format() [7/11]

void PCB_IO::format ( D_PAD aPad,
int  aNestLevel = 0 
) const
private

Definition at line 1299 of file kicad_plugin.cpp.

1300 {
1301  const char* shape;
1302 
1303  switch( aPad->GetShape() )
1304  {
1305  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1306  case PAD_SHAPE_RECT: shape = "rect"; break;
1307  case PAD_SHAPE_OVAL: shape = "oval"; break;
1308  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1310  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1311  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1312 
1313  default:
1314  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1315  }
1316 
1317  const char* type;
1318 
1319  switch( aPad->GetAttribute() )
1320  {
1321  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1322  case PAD_ATTRIB_SMD: type = "smd"; break;
1323  case PAD_ATTRIB_CONN: type = "connect"; break;
1324  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1325 
1326  default:
1327  THROW_IO_ERROR( wxString::Format( "unknown pad attribute: %d", aPad->GetAttribute() ) );
1328  }
1329 
1330  const char* property = nullptr;
1331 
1332  switch( aPad->GetProperty() )
1333  {
1334  case PAD_PROP_NONE: break;
1335  case PAD_PROP_BGA: property = "pad_prop_bga"; break;
1336  case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1337  case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1338  case PAD_PROP_TESTPOINT: property = "pad_prop_testpoint"; break;
1339  case PAD_PROP_HEATSINK: property = "pad_prop_heatsink"; break;
1340  case PAD_PROP_CASTELLATED: property = "pad_prop_castellated"; break;
1341 
1342  default:
1343  THROW_IO_ERROR( wxString::Format( "unknown pad property: %d", aPad->GetProperty() ) );
1344  }
1345 
1346  m_out->Print( aNestLevel, "(pad %s %s %s",
1347  m_out->Quotew( aPad->GetName() ).c_str(),
1348  type, shape );
1349  m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
1350 
1351  if( aPad->GetOrientation() != 0.0 )
1352  m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() );
1353 
1354  m_out->Print( 0, ")" );
1355  m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
1356 
1357  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1358  m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() );
1359 
1360  wxSize sz = aPad->GetDrillSize();
1361  wxPoint shapeoffset = aPad->GetOffset();
1362 
1363  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1364  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1365  {
1366  m_out->Print( 0, " (drill" );
1367 
1368  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1369  m_out->Print( 0, " oval" );
1370 
1371  if( sz.GetWidth() > 0 )
1372  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetWidth() ).c_str() );
1373 
1374  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1375  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetHeight() ).c_str() );
1376 
1377  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1378  m_out->Print( 0, " (offset %s)", FormatInternalUnits( aPad->GetOffset() ).c_str() );
1379 
1380  m_out->Print( 0, ")" );
1381  }
1382 
1383  if( property && ADVANCED_CFG::GetCfg().m_EnableUsePadProperty )
1384  {
1385  // Add pad property, if exists.
1386  m_out->Print( 0, " (property %s)", property );
1387  }
1388 
1389  formatLayers( aPad->GetLayerSet() );
1390 
1391  // Output the radius ratio for rounded and chamfered rect pads
1392  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT || aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1393  {
1394  m_out->Print( 0, " (roundrect_rratio %s)",
1395  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1396  }
1397 
1398  // Output the chamfer corners for chamfered rect pads
1399  if( aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1400  {
1401  m_out->Print( 0, "\n" );
1402 
1403  m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
1404  Double2Str( aPad->GetChamferRectRatio() ).c_str() );
1405 
1406  m_out->Print( 0, " (chamfer" );
1407 
1408  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
1409  m_out->Print( 0, " top_left" );
1410 
1411  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT ) )
1412  m_out->Print( 0, " top_right" );
1413 
1414  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT ) )
1415  m_out->Print( 0, " bottom_left" );
1416 
1418  m_out->Print( 0, " bottom_right" );
1419 
1420  m_out->Print( 0, ")" );
1421  }
1422 
1423  std::string output;
1424 
1425  // Unconnected pad is default net so don't save it.
1426  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1427  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1428  m_out->Quotew( aPad->GetNetname() ).c_str() );
1429 
1431  {
1432  // Add pinfunction, if exists.
1433  // Pin function is closely related to nets, so if CTL_OMIT_NETS is set,
1434  // omit also pin function (for instance when saved from library editor)
1435  if( !(m_ctl & CTL_OMIT_NETS) && !aPad->GetPinFunction().IsEmpty() )
1436  StrPrintf( &output, " (pinfunction %s)",
1437  m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1438  }
1439 
1440  if( aPad->GetPadToDieLength() != 0 )
1441  StrPrintf( &output, " (die_length %s)",
1442  FormatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
1443 
1444  if( aPad->GetLocalSolderMaskMargin() != 0 )
1445  StrPrintf( &output, " (solder_mask_margin %s)",
1446  FormatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() );
1447 
1448  if( aPad->GetLocalSolderPasteMargin() != 0 )
1449  StrPrintf( &output, " (solder_paste_margin %s)",
1450  FormatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() );
1451 
1452  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1453  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1454  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1455 
1456  if( aPad->GetLocalClearance() != 0 )
1457  StrPrintf( &output, " (clearance %s)", FormatInternalUnits( aPad->GetLocalClearance() ).c_str() );
1458 
1460  StrPrintf( &output, " (zone_connect %d)", static_cast<int>( aPad->GetZoneConnection() ) );
1461 
1462  if( aPad->GetThermalWidth() != 0 )
1463  StrPrintf( &output, " (thermal_width %s)", FormatInternalUnits( aPad->GetThermalWidth() ).c_str() );
1464 
1465  if( aPad->GetThermalGap() != 0 )
1466  StrPrintf( &output, " (thermal_gap %s)", FormatInternalUnits( aPad->GetThermalGap() ).c_str() );
1467 
1468  if( output.size() )
1469  {
1470  m_out->Print( 0, "\n" );
1471  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1472  }
1473 
1474  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1475  {
1476  m_out->Print( 0, "\n");
1477  m_out->Print( aNestLevel+1, "(options" );
1478 
1480  m_out->Print( 0, " (clearance convexhull)" );
1481  #if 1 // Set to 1 to output the default option
1482  else
1483  m_out->Print( 0, " (clearance outline)" );
1484  #endif
1485 
1486  // Output the anchor pad shape (circle/rect)
1487  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1488  shape = "rect";
1489  else
1490  shape = "circle";
1491 
1492  m_out->Print( 0, " (anchor %s)", shape );
1493 
1494  m_out->Print( 0, ")"); // end of (options ...
1495 
1496  // Output graphic primitive of the pad shape
1497  m_out->Print( 0, "\n");
1498  m_out->Print( aNestLevel+1, "(primitives" );
1499 
1500  int nested_level = aNestLevel+2;
1501 
1502  // Output all basic shapes
1503  for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
1504  {
1505  m_out->Print( 0, "\n");
1506 
1507  const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
1508 
1509  switch( primitive.m_Shape )
1510  {
1511  case S_SEGMENT: // usual segment : line with rounded ends
1512  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1513  FormatInternalUnits( primitive.m_Start ).c_str(),
1514  FormatInternalUnits( primitive.m_End ).c_str(),
1515  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1516  break;
1517 
1518  case S_ARC: // Arc with rounded ends
1519  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1520  FormatInternalUnits( primitive.m_Start ).c_str(),
1521  FormatInternalUnits( primitive.m_End ).c_str(),
1522  FormatAngle( primitive.m_ArcAngle ).c_str(),
1523  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1524  break;
1525 
1526  case S_CIRCLE: // ring or circle (circle if width == 0
1527  m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
1528  FormatInternalUnits( primitive.m_Start ).c_str(),
1529  FormatInternalUnits( primitive.m_Start.x + primitive.m_Radius ).c_str(),
1530  FormatInternalUnits( primitive.m_Start.y ).c_str(),
1531  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1532  break;
1533 
1534  case S_CURVE: // Bezier Curve
1535  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s)) (width %s))",
1536  FormatInternalUnits( primitive.m_Start ).c_str(),
1537  FormatInternalUnits( primitive.m_Ctrl1 ).c_str(),
1538  FormatInternalUnits( primitive.m_Ctrl2 ).c_str(),
1539  FormatInternalUnits( primitive.m_End ).c_str(),
1540  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1541  break;
1542 
1543  case S_POLYGON: // polygon
1544  if( primitive.m_Poly.size() < 2 )
1545  break; // Malformed polygon.
1546 
1547  {
1548  m_out->Print( nested_level, "(gr_poly (pts\n");
1549 
1550  // Write the polygon corners coordinates:
1551  const std::vector< wxPoint>& poly = primitive.m_Poly;
1552  int newLine = 0;
1553 
1554  for( unsigned ii = 0; ii < poly.size(); ii++ )
1555  {
1556  if( newLine == 0 )
1557  m_out->Print( nested_level+1, " (xy %s)",
1558  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1559  else
1560  m_out->Print( 0, " (xy %s)",
1561  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1562 
1563  if( ++newLine > 4 )
1564  {
1565  newLine = 0;
1566  m_out->Print( 0, "\n" );
1567  }
1568  }
1569 
1570  m_out->Print( 0, ") (width %s))", FormatInternalUnits( primitive.m_Thickness ).c_str() );
1571  }
1572  break;
1573 
1574  default:
1575  break;
1576  }
1577  }
1578 
1579  m_out->Print( 0, "\n");
1580  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1581  }
1582 
1583  m_out->Print( 0, ")\n" );
1584 }
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:457
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:294
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
no special fabrication property
Definition: pad_shapes.h:78
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:247
a fiducial (usually a smd) for the full board
Definition: pad_shapes.h:80
wxPoint m_Start
angle of an arc, from its starting point, in 0.1 deg
Definition: class_pad.h:98
polygon (not yet used for tracks, but could be in microwave apps)
int GetPadToDieLength() const
Definition: class_pad.h:455
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
Smd pad, used in BGA footprints.
Definition: pad_shapes.h:79
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:65
a pad used as heat sink, usually in SMD footprints
Definition: pad_shapes.h:83
const wxString & GetPinFunction() const
Definition: class_pad.h:211
int GetThermalGap() const
Definition: class_pad.cpp:747
int GetLocalClearance() const
Definition: class_pad.h:460
wxPoint m_Ctrl1
is also the start point of the arc
Definition: class_pad.h:100
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:445
int GetChamferPositions() const
has meaning only for chamfered rect pads
Definition: class_pad.h:720
a pad with a castellated through hole
Definition: pad_shapes.h:84
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
int m_Radius
thickness of segment or outline For filled S_CIRCLE shape, thickness = 0.
Definition: class_pad.h:96
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:369
std::vector< wxPoint > m_Poly
Bezier Control point 2.
Definition: class_pad.h:102
Arcs (with rounded ends)
const wxPoint & GetOffset() const
Definition: class_pad.h:309
ZONE_CONNECTION GetZoneConnection() const
Definition: class_pad.cpp:725
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:428
double GetChamferRectRatio() const
has meaning only for chamfered rect pads
Definition: class_pad.h:697
int GetThermalWidth() const
Definition: class_pad.cpp:736
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:89
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:442
const wxString & GetName() const
Definition: class_pad.h:203
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
PAD_PROP_T GetProperty() const
Definition: class_pad.h:448
Bezier Curve.
const wxSize & GetDelta() const
Definition: class_pad.h:303
const wxString & GetNetname() const
Function GetNetname.
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:99
#define CTL_OMIT_NETS
Omit pads net names (useless in library)
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
STROKE_T m_Shape
Definition: class_pad.h:92
wxPoint m_Ctrl2
Bezier Control point 1.
Definition: class_pad.h:101
bool m_EnableUsePinFunction
Enable pad pin function handling in pcbnew.
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:253
int m_Thickness
S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
Definition: class_pad.h:93
a fiducial (usually a smd) local to the parent footprint
Definition: pad_shapes.h:81
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 _(s)
Definition: 3d_actions.cpp:31
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:422
const wxSize & GetDrillSize() const
Definition: class_pad.h:306
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:671
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:237
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
const wxSize & GetSize() const
Definition: class_pad.h:300
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:463
a test point pad
Definition: pad_shapes.h:82
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:463
double m_ArcAngle
radius of a circle
Definition: class_pad.h:97
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:466
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.

References _, CTL_OMIT_NETS, CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL, Double2Str(), Format(), FormatAngle(), FormatInternalUnits(), formatLayers(), D_PAD::GetAnchorPadShape(), D_PAD::GetAttribute(), ADVANCED_CFG::GetCfg(), D_PAD::GetChamferPositions(), D_PAD::GetChamferRectRatio(), 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::GetPinFunction(), D_PAD::GetPos0(), D_PAD::GetPrimitives(), D_PAD::GetProperty(), D_PAD::GetRoundRectRadiusRatio(), D_PAD::GetShape(), D_PAD::GetSize(), D_PAD::GetThermalGap(), D_PAD::GetThermalWidth(), D_PAD::GetZoneConnection(), INHERITED, PAD_CS_PRIMITIVE::m_ArcAngle, m_ctl, PAD_CS_PRIMITIVE::m_Ctrl1, PAD_CS_PRIMITIVE::m_Ctrl2, ADVANCED_CFG::m_EnableUsePinFunction, PAD_CS_PRIMITIVE::m_End, m_mapping, m_out, PAD_CS_PRIMITIVE::m_Poly, PAD_CS_PRIMITIVE::m_Radius, PAD_CS_PRIMITIVE::m_Shape, PAD_CS_PRIMITIVE::m_Start, PAD_CS_PRIMITIVE::m_Thickness, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_OBLONG, PAD_PROP_BGA, PAD_PROP_CASTELLATED, PAD_PROP_FIDUCIAL_GLBL, PAD_PROP_FIDUCIAL_LOCAL, PAD_PROP_HEATSINK, PAD_PROP_NONE, PAD_PROP_TESTPOINT, PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), RECT_CHAMFER_BOTTOM_LEFT, RECT_CHAMFER_BOTTOM_RIGHT, RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_TOP_RIGHT, S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, S_SEGMENT, numEval::StrPrintf(), THROW_IO_ERROR, NETINFO_MAPPING::Translate(), NETINFO_LIST::UNCONNECTED, wxPoint::x, and wxPoint::y.

◆ format() [8/11]

void PCB_IO::format ( TEXTE_PCB aText,
int  aNestLevel = 0 
) const
private

Definition at line 1587 of file kicad_plugin.cpp.

1588 {
1589  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1590  m_out->Quotew( aText->GetText() ).c_str(),
1591  FormatInternalUnits( aText->GetTextPos() ).c_str() );
1592 
1593  if( aText->GetTextAngle() != 0.0 )
1594  m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() );
1595 
1596  m_out->Print( 0, ")" );
1597 
1598  formatLayer( aText );
1599 
1600  if( aText->GetTimeStamp() )
1601  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aText->GetTimeStamp() );
1602 
1603  m_out->Print( 0, "\n" );
1604 
1605  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1606 
1607  m_out->Print( aNestLevel, ")\n" );
1608 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
double GetTextAngle() const
Definition: eda_text.h:158
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

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

◆ format() [9/11]

void PCB_IO::format ( TEXTE_MODULE aText,
int  aNestLevel = 0 
) const
private

Definition at line 1611 of file kicad_plugin.cpp.

1612 {
1613  std::string type;
1614 
1615  switch( aText->GetType() )
1616  {
1617  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1618  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1619  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1620  }
1621 
1622  m_out->Print( aNestLevel, "(fp_text %s %s (at %s", type.c_str(),
1623  m_out->Quotew( aText->GetText() ).c_str(),
1624  FormatInternalUnits( aText->GetPos0() ).c_str() );
1625 
1626  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1627  // but internally the angle is held relative to its parent footprint. parent
1628  // may be NULL when saving a footprint outside a BOARD.
1629  double orient = aText->GetTextAngle();
1630  MODULE* parent = (MODULE*) aText->GetParent();
1631 
1632  if( parent )
1633  {
1634  // GetTextAngle() is always in -360..+360 range because of
1635  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1636  // additional board angle could kick sum up >= 360 or <= -360, so to have
1637  // consistent results, normalize again for the BOARD save. A footprint
1638  // save does not use this code path since parent is NULL.
1639 #if 0
1640  // This one could be considered reasonable if you like positive angles
1641  // in your board text.
1642  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1643 #else
1644  // Choose compatibility for now, even though this is only a 720 degree clamp
1645  // with two possible values for every angle.
1646  orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
1647 #endif
1648  }
1649 
1650  if( orient != 0.0 )
1651  m_out->Print( 0, " %s", FormatAngle( orient ).c_str() );
1652 
1653  if( !aText->IsKeepUpright() )
1654  m_out->Print( 0, " unlocked" );
1655 
1656  m_out->Print( 0, ")" );
1657  formatLayer( aText );
1658 
1659  if( !aText->IsVisible() )
1660  m_out->Print( 0, " hide" );
1661 
1662  m_out->Print( 0, "\n" );
1663 
1664  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1665 
1666  m_out->Print( aNestLevel, ")\n" );
1667 }
double GetOrientation() const
Definition: class_module.h:215
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
bool IsKeepUpright()
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:513
TEXT_TYPE GetType() const
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
const wxPoint & GetPos0() const
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:244
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:233
BOARD_ITEM_CONTAINER * GetParent() const
#define CTL_OMIT_HIDE
Definition: eda_text.h:39
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

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

◆ format() [10/11]

void PCB_IO::format ( TRACK aTrack,
int  aNestLevel = 0 
) const
private

Definition at line 1670 of file kicad_plugin.cpp.

1671 {
1672  if( aTrack->Type() == PCB_VIA_T )
1673  {
1674  PCB_LAYER_ID layer1, layer2;
1675 
1676  const VIA* via = static_cast<const VIA*>( aTrack );
1677  BOARD* board = (BOARD*) via->GetParent();
1678 
1679  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( EDA_UNITS::MILLIMETRES )
1680  + wxT( " has no parent." ) );
1681 
1682  m_out->Print( aNestLevel, "(via" );
1683 
1684  via->LayerPair( &layer1, &layer2 );
1685 
1686  switch( via->GetViaType() )
1687  {
1688  case VIATYPE::THROUGH: // Default shape not saved.
1689  break;
1690 
1691  case VIATYPE::BLIND_BURIED:
1692  m_out->Print( 0, " blind" );
1693  break;
1694 
1695  case VIATYPE::MICROVIA:
1696  m_out->Print( 0, " micro" );
1697  break;
1698 
1699  default:
1700  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1701  }
1702 
1703  m_out->Print( 0, " (at %s) (size %s)",
1704  FormatInternalUnits( aTrack->GetStart() ).c_str(),
1705  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1706 
1707  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1708  m_out->Print( 0, " (drill %s)", FormatInternalUnits( via->GetDrill() ).c_str() );
1709 
1710  m_out->Print( 0, " (layers %s %s)",
1711  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1712  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1713  }
1714  else
1715  {
1716  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1717  FormatInternalUnits( aTrack->GetStart() ).c_str(), FormatInternalUnits( aTrack->GetEnd() ).c_str(),
1718  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1719 
1720  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1721  }
1722 
1723  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1724 
1725  if( aTrack->GetTimeStamp() != 0 )
1726  m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTrack->GetTimeStamp() );
1727 
1728  if( aTrack->GetStatus() != 0 )
1729  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1730 
1731  m_out->Print( 0, ")\n" );
1732 }
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...
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:252
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
const wxPoint & GetStart() const
Definition: class_track.h:109
PCB_LAYER_ID
A quick note on layer IDs:
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:358
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_track.cpp:89
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:69
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
int GetWidth() const
Definition: class_track.h:103
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
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
#define _(s)
Definition: 3d_actions.cpp:31
BOARD * m_board
which BOARD, no ownership here
VIATYPE GetViaType() const
Definition: class_track.h:336
const wxPoint & GetEnd() const
Definition: class_track.h:106
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
BOARD_ITEM_CONTAINER * GetParent() const
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, BLIND_BURIED, Format(), FormatInternalUnits(), VIA::GetDrill(), TRACK::GetEnd(), BOARD_ITEM::GetLayerName(), BOARD::GetLayerName(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_ITEM::GetParent(), VIA::GetSelectMenuText(), TRACK::GetStart(), EDA_ITEM::GetStatus(), EDA_ITEM::GetTimeStamp(), VIA::GetViaType(), TRACK::GetWidth(), VIA::LayerPair(), m_board, m_mapping, m_out, MICROVIA, MILLIMETRES, PCB_VIA_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), THROUGH, THROW_IO_ERROR, NETINFO_MAPPING::Translate(), EDA_ITEM::Type(), and UNDEFINED_DRILL_DIAMETER.

◆ format() [11/11]

void PCB_IO::format ( ZONE_CONTAINER aZone,
int  aNestLevel = 0 
) const
private

Definition at line 1735 of file kicad_plugin.cpp.

1736 {
1737  // Save the NET info; For keepout zones, net code and net name are irrelevant
1738  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1739  // (perhaps netcode and netname should be not stored)
1740  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1741  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1742  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1743 
1744  // If a zone exists on multiple layers, format accordingly
1745  if( aZone->GetLayerSet().count() > 1 )
1746  {
1747  formatLayers( aZone->GetLayerSet() );
1748  }
1749  else
1750  {
1751  formatLayer( aZone );
1752  }
1753 
1754  m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
1755 
1756  // Save the outline aux info
1757  std::string hatch;
1758 
1759  switch( aZone->GetHatchStyle() )
1760  {
1761  default:
1763  hatch = "none";
1764  break;
1766  hatch = "edge";
1767  break;
1769  hatch = "full";
1770  break;
1771  }
1772 
1773  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1774  FormatInternalUnits( aZone->GetHatchPitch() ).c_str() );
1775 
1776  if( aZone->GetPriority() > 0 )
1777  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1778 
1779  m_out->Print( aNestLevel+1, "(connect_pads" );
1780 
1781  switch( aZone->GetPadConnection() )
1782  {
1783  default:
1784  case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
1785  break;
1786 
1788  m_out->Print( 0, " thru_hole_only" );
1789  break;
1790 
1791  case ZONE_CONNECTION::FULL:
1792  m_out->Print( 0, " yes" );
1793  break;
1794 
1795  case ZONE_CONNECTION::NONE:
1796  m_out->Print( 0, " no" );
1797  break;
1798  }
1799 
1800  m_out->Print( 0, " (clearance %s))\n",
1801  FormatInternalUnits( aZone->GetZoneClearance() ).c_str() );
1802 
1803  m_out->Print( aNestLevel+1, "(min_thickness %s)",
1804  FormatInternalUnits( aZone->GetMinThickness() ).c_str() );
1805 
1806  // write it only if V 6.O version option is not used (i.e. do not write if the
1807  // "legacy" algorithm is used)
1808  if( !aZone->GetFilledPolysUseThickness() )
1809  m_out->Print( 0, " (filled_areas_thickness no)" );
1810 
1811  m_out->Print( 0, "\n" );
1812 
1813  if( aZone->GetIsKeepout() )
1814  {
1815  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
1816  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1817  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1818  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
1819  }
1820 
1821  m_out->Print( aNestLevel+1, "(fill" );
1822 
1823  // Default is not filled.
1824  if( aZone->IsFilled() )
1825  m_out->Print( 0, " yes" );
1826 
1827  // Default is polygon filled.
1828  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1829  m_out->Print( 0, " (mode hatch)" );
1830 
1831  m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
1832  FormatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
1833  FormatInternalUnits( aZone->GetThermalReliefCopperBridge() ).c_str() );
1834 
1836  {
1837  m_out->Print( 0, " (smoothing" );
1838 
1839  switch( aZone->GetCornerSmoothingType() )
1840  {
1842  m_out->Print( 0, " chamfer" );
1843  break;
1844 
1846  m_out->Print( 0, " fillet" );
1847  break;
1848 
1849  default:
1850  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1851  aZone->GetCornerSmoothingType() ) );
1852  }
1853  m_out->Print( 0, ")" );
1854 
1855  if( aZone->GetCornerRadius() != 0 )
1856  m_out->Print( 0, " (radius %s)",
1857  FormatInternalUnits( aZone->GetCornerRadius() ).c_str() );
1858  }
1859 
1860  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1861  {
1862  m_out->Print( 0, "\n" );
1863  m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
1864  FormatInternalUnits( aZone->GetHatchFillTypeThickness() ).c_str(),
1865  FormatInternalUnits( aZone->GetHatchFillTypeGap() ).c_str(),
1866  Double2Str( aZone->GetHatchFillTypeOrientation() ).c_str() );
1867 
1868  if( aZone->GetHatchFillTypeSmoothingLevel() > 0 )
1869  {
1870  m_out->Print( 0, "\n" );
1871  m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
1873  Double2Str( aZone->GetHatchFillTypeSmoothingValue() ).c_str() );
1874  }
1875  }
1876 
1877  m_out->Print( 0, ")\n" );
1878 
1879  int newLine = 0;
1880 
1881  if( aZone->GetNumCorners() )
1882  {
1883  bool new_polygon = true;
1884  bool is_closed = false;
1885 
1886  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1887  {
1888  if( new_polygon )
1889  {
1890  newLine = 0;
1891  m_out->Print( aNestLevel+1, "(polygon\n" );
1892  m_out->Print( aNestLevel+2, "(pts\n" );
1893  new_polygon = false;
1894  is_closed = false;
1895  }
1896 
1897  if( newLine == 0 )
1898  m_out->Print( aNestLevel+3, "(xy %s %s)",
1899  FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
1900  else
1901  m_out->Print( 0, " (xy %s %s)",
1902  FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
1903 
1904  if( newLine < 4 )
1905  {
1906  newLine += 1;
1907  }
1908  else
1909  {
1910  newLine = 0;
1911  m_out->Print( 0, "\n" );
1912  }
1913 
1914  if( iterator.IsEndContour() )
1915  {
1916  is_closed = true;
1917 
1918  if( newLine != 0 )
1919  m_out->Print( 0, "\n" );
1920 
1921  m_out->Print( aNestLevel+2, ")\n" );
1922  m_out->Print( aNestLevel+1, ")\n" );
1923  new_polygon = true;
1924  }
1925  }
1926 
1927  if( !is_closed ) // Should not happen, but...
1928  {
1929  if( newLine != 0 )
1930  m_out->Print( 0, "\n" );
1931 
1932  m_out->Print( aNestLevel+2, ")\n" );
1933  m_out->Print( aNestLevel+1, ")\n" );
1934  }
1935  }
1936 
1937  // Save the PolysList (filled areas)
1938  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1939  newLine = 0;
1940 
1941  if( !fv.IsEmpty() )
1942  {
1943  bool new_polygon = true;
1944  bool is_closed = false;
1945 
1946  for( auto it = fv.CIterate(); it; ++it )
1947  {
1948  if( new_polygon )
1949  {
1950  newLine = 0;
1951  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1952  m_out->Print( aNestLevel+2, "(pts\n" );
1953  new_polygon = false;
1954  is_closed = false;
1955  }
1956 
1957  if( newLine == 0 )
1958  m_out->Print( aNestLevel+3, "(xy %s %s)",
1959  FormatInternalUnits( it->x ).c_str(), FormatInternalUnits( it->y ).c_str() );
1960  else
1961  m_out->Print( 0, " (xy %s %s)",
1962  FormatInternalUnits( it->x ) .c_str(), FormatInternalUnits( it->y ).c_str() );
1963 
1964  if( newLine < 4 )
1965  {
1966  newLine += 1;
1967  }
1968  else
1969  {
1970  newLine = 0;
1971  m_out->Print( 0, "\n" );
1972  }
1973 
1974  if( it.IsEndContour() )
1975  {
1976  is_closed = true;
1977 
1978  if( newLine != 0 )
1979  m_out->Print( 0, "\n" );
1980 
1981  m_out->Print( aNestLevel+2, ")\n" );
1982  m_out->Print( aNestLevel+1, ")\n" );
1983  new_polygon = true;
1984  }
1985  }
1986 
1987  if( !is_closed ) // Should not happen, but...
1988  m_out->Print( aNestLevel+1, ")\n" );
1989  }
1990 
1991  // Save the filling segments list
1992  const auto& segs = aZone->FillSegments();
1993 
1994  if( segs.size() )
1995  {
1996  m_out->Print( aNestLevel+1, "(fill_segments\n" );
1997 
1998  for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
1999  {
2000  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
2001  FormatInternalUnits( wxPoint( it->A ) ).c_str(),
2002  FormatInternalUnits( wxPoint( it->B ) ).c_str() );
2003  }
2004 
2005  m_out->Print( aNestLevel+1, ")\n" );
2006  }
2007 
2008  m_out->Print( aNestLevel, ")\n" );
2009 }
bool IsFilled() const
Definition: class_zone.h:170
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
void formatLayer(const BOARD_ITEM *aItem) const
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:533
int GetHatchFillTypeThickness() const
Definition: class_zone.h:195
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
ZONE_SEGMENT_FILL & FillSegments()
Definition: class_zone.h:244
bool GetFilledPolysUseThickness() const
Definition: class_zone.h:599
double GetHatchFillTypeOrientation() const
Definition: class_zone.h:201
double GetHatchFillTypeSmoothingValue() const
Definition: class_zone.h:207
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:524
bool GetDoNotAllowVias() const
Definition: class_zone.h:633
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:268
pads are covered by copper
unsigned int GetCornerRadius() const
Definition: class_zone.h:597
SHAPE_POLY_SET.
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:156
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:632
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:432
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
ZONE_CONNECTION GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:867
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
ZONE_HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:520
int GetCornerSmoothingType() const
Definition: class_zone.h:593
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:631
Thermal relief only for THT pads.
Use thermal relief for pads.
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:100
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 _(s)
Definition: 3d_actions.cpp:31
SHAPE_POLY_SET::ITERATOR IterateWithHoles()
Function IterateWithHoles returns an iterator to visit all points of the zone's main outline with hol...
Definition: class_zone.h:452
int GetHatchPitch() const
Hatch related methods.
Definition: class_zone.cpp:952
int GetMinThickness() const
Definition: class_zone.h:186
Pads are not covered.
bool GetDoNotAllowTracks() const
Definition: class_zone.h:634
int GetHatchFillTypeSmoothingLevel() const
Definition: class_zone.h:204
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int GetZoneClearance() const
Definition: class_zone.h:176
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
int GetHatchFillTypeGap() const
Definition: class_zone.h:198
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:553

References _, SHAPE_POLY_SET::CIterate(), DIAGONAL_EDGE, DIAGONAL_FULL, Double2Str(), ZONE_CONTAINER::FillSegments(), Format(), FormatInternalUnits(), formatLayer(), formatLayers(), FULL, ZONE_CONTAINER::GetCornerRadius(), ZONE_CONTAINER::GetCornerSmoothingType(), ZONE_CONTAINER::GetDoNotAllowCopperPour(), ZONE_CONTAINER::GetDoNotAllowTracks(), ZONE_CONTAINER::GetDoNotAllowVias(), ZONE_CONTAINER::GetFilledPolysList(), ZONE_CONTAINER::GetFilledPolysUseThickness(), ZONE_CONTAINER::GetFillMode(), ZONE_CONTAINER::GetHatchFillTypeGap(), ZONE_CONTAINER::GetHatchFillTypeOrientation(), ZONE_CONTAINER::GetHatchFillTypeSmoothingLevel(), ZONE_CONTAINER::GetHatchFillTypeSmoothingValue(), ZONE_CONTAINER::GetHatchFillTypeThickness(), 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(), HATCH_PATTERN, SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::IsFilled(), ZONE_CONTAINER::IterateWithHoles(), m_mapping, m_out, NO_HATCH, NONE, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), ZONE_SETTINGS::SMOOTHING_CHAMFER, ZONE_SETTINGS::SMOOTHING_FILLET, ZONE_SETTINGS::SMOOTHING_NONE, THERMAL, THROW_IO_ERROR, THT_THERMAL, and NETINFO_MAPPING::Translate().

◆ formatBoardLayers()

void PCB_IO::formatBoardLayers ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the board layer information

Definition at line 665 of file kicad_plugin.cpp.

666 {
667  m_out->Print( aNestLevel, "(layers\n" );
668 
669  // Save only the used copper layers from front to back.
670  LSET visible_layers = aBoard->GetVisibleLayers();
671 
672  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
673  {
674  PCB_LAYER_ID layer = *cu;
675 
676  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
677  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
678  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
679 
680  if( !visible_layers[layer] )
681  m_out->Print( 0, " hide" );
682 
683  m_out->Print( 0, ")\n" );
684  }
685 
686  // Save used non-copper layers in the order they are defined.
687  // desired sequence for non Cu BOARD layers.
688  static const PCB_LAYER_ID non_cu[] =
689  {
690  B_Adhes, // 32
691  F_Adhes,
692  B_Paste,
693  F_Paste,
694  B_SilkS,
695  F_SilkS,
696  B_Mask,
697  F_Mask,
698  Dwgs_User,
699  Cmts_User,
700  Eco1_User,
701  Eco2_User,
702  Edge_Cuts,
703  Margin,
704  B_CrtYd,
705  F_CrtYd,
706  B_Fab,
707  F_Fab
708  };
709 
710  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
711  {
712  PCB_LAYER_ID layer = *seq;
713 
714  m_out->Print( aNestLevel+1, "(%d %s user", layer,
715  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
716 
717  if( !visible_layers[layer] )
718  m_out->Print( 0, " hide" );
719 
720  m_out->Print( 0, ")\n" );
721  }
722 
723  m_out->Print( aNestLevel, ")\n\n" );
724 }
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:155
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
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:377
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References arrayDim(), B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, LSET::CuStack(), 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(), m_out, Margin, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), and LAYER::ShowType().

Referenced by formatHeader(), and CLIPBOARD_IO::SaveSelection().

◆ formatDefaults()

void PCB_IO::formatDefaults ( const BOARD_DESIGN_SETTINGS aSettings,
int  aNestLevel 
) const
protected

formats the defaults subsection of the board setup

Definition at line 597 of file kicad_plugin.cpp.

598 {
599  m_out->Print( aNestLevel, "(defaults\n" );
600 
601  m_out->Print( aNestLevel+1, "(edge_clearance %s)\n",
602  FormatInternalUnits( aSettings.m_CopperEdgeClearance ).c_str() );
603 
604  m_out->Print( aNestLevel+1, "(edge_cuts_line_width %s)\n",
605  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_EDGES ] ).c_str() );
606 
607  m_out->Print( aNestLevel+1, "(courtyard_line_width %s)\n",
609 
610  m_out->Print( aNestLevel+1, "(copper_line_width %s)\n",
611  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_COPPER ] ).c_str() );
612  m_out->Print( aNestLevel+1, "(copper_text_dims (size %s %s) (thickness %s)%s%s)\n",
613  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].x ).c_str(),
614  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].y ).c_str(),
616  aSettings.m_TextItalic[ LAYER_CLASS_COPPER ] ? " italic" : "",
617  aSettings.m_TextUpright[ LAYER_CLASS_COPPER ] ? " keep_upright" : "" );
618 
619  m_out->Print( aNestLevel+1, "(silk_line_width %s)\n",
620  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_SILK ] ).c_str() );
621  m_out->Print( aNestLevel+1, "(silk_text_dims (size %s %s) (thickness %s)%s%s)\n",
622  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].x ).c_str(),
623  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].y ).c_str(),
624  FormatInternalUnits( aSettings.m_TextThickness[ LAYER_CLASS_SILK ] ).c_str(),
625  aSettings.m_TextItalic[ LAYER_CLASS_SILK ] ? " italic" : "",
626  aSettings.m_TextUpright[ LAYER_CLASS_SILK ] ? " keep_upright" : "" );
627 
628  m_out->Print( aNestLevel+1, "(other_layers_line_width %s)\n",
629  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_OTHERS ] ).c_str() );
630  m_out->Print( aNestLevel+1, "(other_layers_text_dims (size %s %s) (thickness %s)%s%s)\n",
631  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x ).c_str(),
632  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y ).c_str(),
634  aSettings.m_TextItalic[ LAYER_CLASS_OTHERS ] ? " italic" : "",
635  aSettings.m_TextUpright[ LAYER_CLASS_OTHERS ] ? " keep_upright" : "" );
636 
637  m_out->Print( aNestLevel+1, "(dimension_units %d)\n", aSettings.m_DimensionUnits );
638  m_out->Print( aNestLevel+1, "(dimension_precision %d)\n", aSettings.m_DimensionPrecision );
639 
640  m_out->Print( aNestLevel, ")\n" );
641 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
bool m_TextUpright[LAYER_CLASS_COUNT]
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References FormatInternalUnits(), LAYER_CLASS_COPPER, LAYER_CLASS_COURTYARD, LAYER_CLASS_EDGES, LAYER_CLASS_OTHERS, LAYER_CLASS_SILK, BOARD_DESIGN_SETTINGS::m_CopperEdgeClearance, BOARD_DESIGN_SETTINGS::m_DimensionPrecision, BOARD_DESIGN_SETTINGS::m_DimensionUnits, BOARD_DESIGN_SETTINGS::m_LineThickness, m_out, BOARD_DESIGN_SETTINGS::m_TextItalic, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, BOARD_DESIGN_SETTINGS::m_TextUpright, and OUTPUTFORMATTER::Print().

Referenced by formatSetup().

◆ formatGeneral()

void PCB_IO::formatGeneral ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the General section of the file

Definition at line 644 of file kicad_plugin.cpp.

645 {
646  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
647 
648  m_out->Print( 0, "\n" );
649  m_out->Print( aNestLevel, "(general\n" );
650  // Write Bounding box info
651  m_out->Print( aNestLevel+1, "(thickness %s)\n",
652  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
653 
654  m_out->Print( aNestLevel+1, "(drawings %u)\n", (unsigned)aBoard->Drawings().size() );
655  m_out->Print( aNestLevel + 1, "(tracks %u)\n", (unsigned)aBoard->Tracks().size() );
656  m_out->Print( aNestLevel + 1, "(modules %u)\n", (unsigned)aBoard->Modules().size() );
657  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
658  m_out->Print( aNestLevel, ")\n\n" );
659 
660  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
661  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
662 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:545
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
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
int GetSize() const
Function GetSize.
Definition: netinfo.h:377
MODULES & Modules()
Definition: class_board.h:226
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: ws_painter.cpp:198
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:551
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
DRAWINGS & Drawings()
Definition: class_board.h:235
TRACKS & Tracks()
Definition: class_board.h:217
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References BOARD::Drawings(), TITLE_BLOCK::Format(), PAGE_INFO::Format(), FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetDesignSettings(), BOARD::GetPageSettings(), NETINFO_MAPPING::GetSize(), BOARD::GetTitleBlock(), m_ctl, m_mapping, m_out, BOARD::Modules(), OUTPUTFORMATTER::Print(), and BOARD::Tracks().

Referenced by formatHeader().

◆ formatHeader()

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

755 {
756  formatGeneral( aBoard, aNestLevel );
757  // Layers list.
758  formatBoardLayers( aBoard, aNestLevel );
759 
760  // Setup
761  formatSetup( aBoard, aNestLevel );
762 
763  // Save net codes and names
764  formatNetInformation( aBoard, aNestLevel );
765 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
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 formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information

References formatBoardLayers(), formatGeneral(), formatNetInformation(), and formatSetup().

Referenced by format().

◆ formatLayer()

void PCB_IO::formatLayer ( const BOARD_ITEM aItem) const
private

Definition at line 459 of file kicad_plugin.cpp.

460 {
461  if( m_ctl & CTL_STD_LAYER_NAMES )
462  {
463  PCB_LAYER_ID layer = aItem->GetLayer();
464 
465  // English layer names should never need quoting.
466  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
467  }
468  else
469  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
470 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
PCB_LAYER_ID
A quick note on layer IDs:
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
#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
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:646

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

Referenced by format().

◆ formatLayers()

void PCB_IO::formatLayers ( LSET  aLayerMask,
int  aNestLevel = 0 
) const
private

Definition at line 1207 of file kicad_plugin.cpp.

1208 {
1209  std::string output;
1210 
1211  if( aNestLevel == 0 )
1212  output += ' ';
1213 
1214  output += "(layers";
1215 
1216  static const LSET cu_all( LSET::AllCuMask() );
1217  static const LSET fr_bk( 2, B_Cu, F_Cu );
1218  static const LSET adhes( 2, B_Adhes, F_Adhes );
1219  static const LSET paste( 2, B_Paste, F_Paste );
1220  static const LSET silks( 2, B_SilkS, F_SilkS );
1221  static const LSET mask( 2, B_Mask, F_Mask );
1222  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1223  static const LSET fab( 2, B_Fab, F_Fab );
1224 
1225  LSET cu_mask = cu_all;
1226 
1227  // output copper layers first, then non copper
1228 
1229  if( ( aLayerMask & cu_mask ) == cu_mask )
1230  {
1231  output += " *.Cu";
1232  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1233  }
1234  else if( ( aLayerMask & cu_mask ) == fr_bk )
1235  {
1236  output += " F&B.Cu";
1237  aLayerMask &= ~fr_bk;
1238  }
1239 
1240  if( ( aLayerMask & adhes ) == adhes )
1241  {
1242  output += " *.Adhes";
1243  aLayerMask &= ~adhes;
1244  }
1245 
1246  if( ( aLayerMask & paste ) == paste )
1247  {
1248  output += " *.Paste";
1249  aLayerMask &= ~paste;
1250  }
1251 
1252  if( ( aLayerMask & silks ) == silks )
1253  {
1254  output += " *.SilkS";
1255  aLayerMask &= ~silks;
1256  }
1257 
1258  if( ( aLayerMask & mask ) == mask )
1259  {
1260  output += " *.Mask";
1261  aLayerMask &= ~mask;
1262  }
1263 
1264  if( ( aLayerMask & crt_yd ) == crt_yd )
1265  {
1266  output += " *.CrtYd";
1267  aLayerMask &= ~crt_yd;
1268  }
1269 
1270  if( ( aLayerMask & fab ) == fab )
1271  {
1272  output += " *.Fab";
1273  aLayerMask &= ~fab;
1274  }
1275 
1276  // output any individual layers not handled in wildcard combos above
1277 
1278  wxString layerName;
1279 
1280  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1281  {
1282  if( aLayerMask[layer] )
1283  {
1284  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1285  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1286 
1287  else // I am being called from FootprintSave()
1288  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1289 
1290  output += ' ';
1291  output += m_out->Quotew( layerName );
1292  }
1293  }
1294 
1295  m_out->Print( aNestLevel, "%s)", output.c_str() );
1296 }
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:686
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
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:646

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::GetLayerName(), BOARD::GetStandardLayerName(), m_board, m_ctl, m_out, PCB_LAYER_ID_COUNT, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by format().

◆ formatNetInformation()

void PCB_IO::formatNetInformation ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the Nets and Netclasses

Definition at line 727 of file kicad_plugin.cpp.

728 {
729  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
730  for( NETINFO_ITEM* net : *m_mapping )
731  {
732  m_out->Print( aNestLevel, "(net %d %s)\n",
733  m_mapping->Translate( net->GetNet() ),
734  m_out->Quotew( net->GetNetname() ).c_str() );
735  }
736 
737  m_out->Print( 0, "\n" );
738 
739  // Save the default net class first.
740  NETCLASS defaultNC = *dsnSettings.GetDefault();
741  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
742  defaultNC.Format( m_out, aNestLevel, m_ctl );
743 
744  // Save the rest of the net classes alphabetically.
745  for( const auto& it : dsnSettings.m_NetClasses )
746  {
747  NETCLASS netclass = *it.second;
748  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
749  netclass.Format( m_out, aNestLevel, m_ctl );
750  }
751 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:55
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
NETCLASSPTR GetDefault() const
Function GetDefault.
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
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
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References filterNetClass(), NETCLASS::Format(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), m_ctl, m_mapping, BOARD_DESIGN_SETTINGS::m_NetClasses, m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and NETINFO_MAPPING::Translate().

Referenced by formatHeader(), and CLIPBOARD_IO::SaveSelection().

◆ formatSetup()

void PCB_IO::formatSetup ( BOARD aBoard,
int  aNestLevel = 0 
) const
protected

formats the board setup information

Definition at line 473 of file kicad_plugin.cpp.

474 {
475  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
476 
477  // Setup
478  m_out->Print( aNestLevel, "(setup\n" );
479 
480  // Save the board physical stackup structure
482 
483  if( aBoard->GetDesignSettings().m_HasStackup )
484  stackup.FormatBoardStackup( m_out,aBoard, aNestLevel+1 );
485 
486  // Save current default track width, for compatibility with older Pcbnew version;
487  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
488  FormatInternalUnits( dsnSettings.GetCurrentTrackWidth() ).c_str() );
489 
490  // Save custom track widths list (the first is not saved here: it's the netclass value)
491  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
492  {
493  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
494  FormatInternalUnits( dsnSettings.m_TrackWidthList[ii] ).c_str() );
495  }
496 
497  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
498  FormatInternalUnits( dsnSettings.GetDefault()->GetClearance() ).c_str() );
499 
500  // ZONE_SETTINGS
501  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
502  FormatInternalUnits( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
503  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
504  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
505 
506  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
507  FormatInternalUnits( dsnSettings.m_TrackMinWidth ).c_str() );
508 
509  // Save current default via size, for compatibility with older Pcbnew version;
510  m_out->Print( aNestLevel+1, "(via_size %s)\n",
511  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
512  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
513  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
514  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
515  FormatInternalUnits( dsnSettings.m_ViasMinSize ).c_str() );
516  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
517  FormatInternalUnits( dsnSettings.m_ViasMinDrill ).c_str() );
518 
519  // Save custom via dimensions list (the first is not saved here: it's the netclass value)
520  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
521  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
522  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
523  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
524 
525  // Save custom diff-pair dimensions (the first is not saved here: it's the netclass value)
526  for( unsigned ii = 1; ii < dsnSettings.m_DiffPairDimensionsList.size(); ii++ )
527  {
528  m_out->Print( aNestLevel+1, "(user_diff_pair %s %s %s)\n",
529  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Width ).c_str(),
530  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Gap ).c_str(),
531  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_ViaGap ).c_str() );
532  }
533 
534  // for old versions compatibility:
535  if( dsnSettings.m_BlindBuriedViaAllowed )
536  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
537 
538  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
539  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
540  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
541  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
542  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
543  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
544  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
545  FormatInternalUnits( dsnSettings.m_MicroViasMinSize ).c_str() );
546  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
547  FormatInternalUnits( dsnSettings.m_MicroViasMinDrill ).c_str() );
548 
549  m_out->Print( aNestLevel+1, "(max_error %s)\n",
550  FormatInternalUnits( dsnSettings.m_MaxError ).c_str() );
551 
552  // Store this option only if it is not the legacy option:
553  if( dsnSettings.m_ZoneUseNoOutlineInFill )
554  m_out->Print( aNestLevel+1, "(filled_areas_thickness no)\n" );
555 
556  formatDefaults( dsnSettings, aNestLevel+1 );
557 
558  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
559  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
560  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
561  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
562  FormatInternalUnits( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
563 
564  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
565  FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
566 
567  if( dsnSettings.m_SolderMaskMinWidth )
568  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
569  FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
570 
571  if( dsnSettings.m_SolderPasteMargin != 0 )
572  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
573  FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
574 
575  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
576  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
577  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
578 
579  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
580  FormatInternalUnits( aBoard->GetAuxOrigin().x ).c_str(),
581  FormatInternalUnits( aBoard->GetAuxOrigin().y ).c_str() );
582 
583  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
584  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
585  FormatInternalUnits( aBoard->GetGridOrigin().x ).c_str(),
586  FormatInternalUnits( aBoard->GetGridOrigin().y ).c_str() );
587 
588  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
589  dsnSettings.GetVisibleElements() );
590 
591  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
592 
593  m_out->Print( aNestLevel, ")\n\n" );
594 }
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, BOARD *aBoard, int aNestLevel) const
Writes the stackup info on board file.
int m_SolderMaskMargin
Solder mask margin.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:548
int m_SolderPasteMargin
Solder paste margin absolute value.
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
this class manage the layers needed to make a physical board they are solder mask,...
std::vector< int > m_TrackWidthList
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
BOARD_STACKUP & GetStackupDescriptor()
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_ViasMinDrill
vias (not micro vias) min drill diameter
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:73
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:353
int m_MicroViasMinSize
micro vias (not vias) min diameter
const wxPoint & GetGridOrigin() const
Definition: class_board.h:360
const ZONE_SETTINGS & GetZoneSettings() const
Fetch the zone settings for this container.
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible.
NETCLASSPTR GetDefault() const
Function GetDefault.
bool m_ZoneUseNoOutlineInFill
Option to handle filled polygons in zones: the "legacy" option is using thick outlines around filled ...
const wxSize & GetDrillSize() const
Definition: class_pad.h:306
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
void formatDefaults(const BOARD_DESIGN_SETTINGS &aSettings, int aNestLevel) const
formats the defaults subsection of the board setup
bool m_MicroViasAllowed
true to allow micro vias
bool m_HasStackup
Set to true if the board has a stackup management.
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values.
const wxSize & GetSize() const
Definition: class_pad.h:300
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
int m_SolderMaskMinWidth
Solder mask min width.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References Double2Str(), PCB_PLOT_PARAMS::Format(), BOARD_STACKUP::FormatBoardStackup(), formatDefaults(), FormatInternalUnits(), 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::GetStackupDescriptor(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), BOARD_ITEM_CONTAINER::GetZoneSettings(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, BOARD_DESIGN_SETTINGS::m_DiffPairDimensionsList, BOARD_DESIGN_SETTINGS::m_HasStackup, BOARD_DESIGN_SETTINGS::m_MaxError, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, m_out, BOARD_DESIGN_SETTINGS::m_Pad_Master, 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, BOARD_DESIGN_SETTINGS::m_ZoneUseNoOutlineInFill, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by formatHeader().

◆ GetEnumeratedFootprint()

const MODULE * PCB_IO::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

Reimplemented from PLUGIN.

Definition at line 2154 of file kicad_plugin.cpp.

2157 {
2158  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2159 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References getFootprint().

◆ GetFileExtension()

const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

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

113  {
114  // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
115  // but to be pure, a plugin should not assume that it will always be linked
116  // with the core of the pcbnew code. (Might someday be a DLL/DSO.) Besides,
117  // file extension policy should be controlled by the plugin.
118  return wxT( "kicad_pcb" );
119  }

◆ getFootprint()

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

Definition at line 2125 of file kicad_plugin.cpp.

2129 {
2130  LOCALE_IO toggle; // toggles on, then off, the C locale.
2131 
2132  init( aProperties );
2133 
2134  try
2135  {
2136  validateCache( aLibraryPath, checkModified );
2137  }
2138  catch( const IO_ERROR& )
2139  {
2140  // do nothing with the error
2141  }
2142 
2143  const MODULE_MAP& mods = m_cache->GetModules();
2144 
2145  MODULE_CITER it = mods.find( aFootprintName );
2146 
2147  if( it == mods.end() )
2148  return nullptr;
2149 
2150  return it->second->GetModule();
2151 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
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()

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

Referenced by FootprintLoad(), and GetEnumeratedFootprint().

◆ GetLibraryTimestamp()

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

2311 {
2312  return FP_CACHE::GetTimestamp( aLibraryPath );
2313 }
static long long GetTimestamp(const wxString &aLibPath)
Function GetTimestamp Generate a timestamp representing all source files in the cache (including the ...

References FP_CACHE::GetTimestamp().

Referenced by GITHUB_PLUGIN::GetLibraryTimestamp().

◆ GetStringOutput()

std::string PCB_IO::GetStringOutput ( bool  doClear)
inline

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

171  {
172  std::string ret = m_sf.GetString();
173  if( doClear )
174  m_sf.Clear();
175 
176  return ret;
177  }
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

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

◆ init()

void PCB_IO::init ( const PROPERTIES aProperties)
protected

Definition at line 2075 of file kicad_plugin.cpp.

2076 {
2077  m_board = NULL;
2078  m_reader = NULL;
2080  m_props = aProperties;
2081 }
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.
#define NULL
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
BOARD * m_board
which BOARD, no ownership here

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

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

◆ IsFootprintLibWritable()

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

2412 {
2413  LOCALE_IO toggle;
2414 
2415  init( NULL );
2416 
2417  validateCache( aLibraryPath );
2418 
2419  return m_cache->IsWritable();
2420 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
#define NULL
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const

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

Referenced by GITHUB_PLUGIN::IsFootprintLibWritable().

◆ Load()

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

2032 {
2033  FILE_LINE_READER reader( aFileName );
2034 
2035  init( aProperties );
2036 
2037  m_parser->SetLineReader( &reader );
2038  m_parser->SetBoard( aAppendToMe );
2039 
2040  BOARD* board;
2041 
2042  try
2043  {
2044  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2045  }
2046  catch( const FUTURE_FORMAT_ERROR& )
2047  {
2048  // Don't wrap a FUTURE_FORMAT_ERROR in another
2049  throw;
2050  }
2051  catch( const PARSE_ERROR& parse_error )
2052  {
2053  if( m_parser->IsTooRecent() )
2054  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2055  else
2056  throw;
2057  }
2058 
2059  if( !board )
2060  {
2061  // The parser loaded something that was valid, but wasn't a board.
2062  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
2063  m_parser->CurSource(), m_parser->CurLine(),
2064  m_parser->CurLineNumber(), m_parser->CurOffset() );
2065  }
2066 
2067  // Give the filename to the board if it's new
2068  if( !aAppendToMe )
2069  board->SetFileName( aFileName );
2070 
2071  return board;
2072 }
void init(const PROPERTIES *aProperties)
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:207
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:338
void SetFileName(const wxString &aFileName)
Definition: class_board.h:213
PCB_PARSER * m_parser
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:467
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:331
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:356
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
#define _(s)
Definition: 3d_actions.cpp:31
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172

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.

◆ Parse()

BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)

Definition at line 379 of file kicad_plugin.cpp.

380 {
381  std::string input = TO_UTF8( aClipboardSourceInput );
382 
383  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
384 
385  m_parser->SetLineReader( &reader );
386 
387  try
388  {
389  return m_parser->Parse();
390  }
391  catch( const PARSE_ERROR& parse_error )
392  {
393  if( m_parser->IsTooRecent() )
394  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
395  else
396  throw;
397  }
398 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:207
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:467
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:331
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:356
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
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
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254

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

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

◆ PluginName()

const wxString PCB_IO::PluginName ( ) const
inlineoverridevirtual

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

Implements PLUGIN.

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

108  {
109  return wxT( "KiCad" );
110  }

◆ PrefetchLib()

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 68 of file plugin.cpp.

69 {
70  (void) aLibraryPath;
71  (void) aProperties;
72 }

◆ Save()

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

356 {
357  LOCALE_IO toggle; // toggles on, then off, the C locale.
358 
359  init( aProperties );
360 
361  m_board = aBoard; // after init()
362 
363  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
364  m_mapping->SetBoard( aBoard );
365 
366  FILE_OUTPUTFORMATTER formatter( aFileName );
367 
368  m_out = &formatter; // no ownership
369 
370  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
371  formatter.Quotew( GetBuildVersion() ).c_str() );
372 
373  Format( aBoard, 1 );
374 
375  m_out->Print( 0, ")\n" );
376 }
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:90
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:283
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
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
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 Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.

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

Referenced by KI_TEST::DumpBoardToFile().

◆ SetOutputFormatter()

void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inline

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

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

References m_out.

Referenced by FP_CACHE::Save().

◆ validateCache()

void PCB_IO::validateCache ( const wxString &  aLibraryPath,
bool  checkModified = true 
)
protected

Definition at line 2084 of file kicad_plugin.cpp.

2085 {
2086  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2087  {
2088  // a spectacular episode in memory management:
2089  delete m_cache;
2090  m_cache = new FP_CACHE( this, aLibraryPath );
2091  m_cache->Load();
2092  }
2093 }
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()

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

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

Friends And Related Function Documentation

◆ FP_CACHE

friend class FP_CACHE
friend

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

Referenced by FootprintLibCreate(), and validateCache().

Member Data Documentation

◆ m_board

BOARD* PCB_IO::m_board
protected

◆ m_cache

◆ m_ctl

int PCB_IO::m_ctl
protected

◆ m_error

wxString PCB_IO::m_error
protected

for throwing exceptions

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

◆ m_filename

wxString PCB_IO::m_filename
protected

for saves only, name is in m_reader for loads

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

◆ m_loading_format_version

int PCB_IO::m_loading_format_version
protected

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

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

Referenced by init().

◆ m_mapping

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

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

◆ m_out

◆ m_parser

PCB_PARSER* PCB_IO::m_parser
protected

◆ m_props

const PROPERTIES* PCB_IO::m_props
protected

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

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

Referenced by init().

◆ m_reader

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

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

Referenced by init().

◆ m_sf

STRING_FORMATTER PCB_IO::m_sf
protected

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

Referenced by GetStringOutput(), and PCB_IO().


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