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

Constructor & Destructor Documentation

◆ PCB_IO()

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 2044 of file kicad_plugin.cpp.

2044  :
2045  m_cache( 0 ),
2046  m_ctl( aControlFlags ),
2047  m_parser( new PCB_PARSER() ),
2048  m_mapping( new NETINFO_MAPPING() )
2049 {
2050  init( 0 );
2051  m_out = &m_sf;
2052 }
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:69
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 2055 of file kicad_plugin.cpp.

2056 {
2057  delete m_cache;
2058  delete m_parser;
2059  delete m_mapping;
2060 }
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 2322 of file kicad_plugin.cpp.

2324 {
2325  LOCALE_IO toggle; // toggles on, then off, the C locale.
2326 
2327  init( aProperties );
2328 
2329  validateCache( aLibraryPath );
2330 
2331  if( !m_cache->IsWritable() )
2332  {
2333  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only." ),
2334  aLibraryPath.GetData() ) );
2335  }
2336 
2337  m_cache->Remove( aFootprintName );
2338 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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:33

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

2130 {
2131  LOCALE_IO toggle; // toggles on, then off, the C locale.
2132  wxDir dir( aLibPath );
2133  wxString errorMsg;
2134 
2135  init( aProperties );
2136 
2137  try
2138  {
2139  validateCache( aLibPath );
2140  }
2141  catch( const IO_ERROR& ioe )
2142  {
2143  errorMsg = ioe.What();
2144  }
2145 
2146  // Some of the files may have been parsed correctly so we want to add the valid files to
2147  // the library.
2148 
2149  for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
2150  aFootprintNames.Add( it->first );
2151 
2152  if( !errorMsg.IsEmpty() && !aBestEfforts )
2153  THROW_IO_ERROR( errorMsg );
2154 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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 2194 of file kicad_plugin.cpp.

2196 {
2197  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2198  // only in case.
2199  //
2200  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2201  // case-insensitive filesystem) handled "for free".
2202  // Warning: footprint names frequently contain a point. So be careful when initializing
2203  // wxFileName, and use a CTOR with extension specified
2204  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2205 
2206  return footprintFile.Exists();
2207 }
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 2348 of file kicad_plugin.cpp.

2349 {
2350  if( wxDir::Exists( aLibraryPath ) )
2351  {
2352  THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path \"%s\"." ),
2353  aLibraryPath.GetData() ) );
2354  }
2355 
2356  LOCALE_IO toggle;
2357 
2358  init( aProperties );
2359 
2360  delete m_cache;
2361  m_cache = new FP_CACHE( this, aLibraryPath );
2362  m_cache->Save();
2363 }
friend class FP_CACHE
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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:33

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

2367 {
2368  wxFileName fn;
2369  fn.SetPath( aLibraryPath );
2370 
2371  // Return if there is no library path to delete.
2372  if( !fn.DirExists() )
2373  return false;
2374 
2375  if( !fn.IsDirWritable() )
2376  {
2377  THROW_IO_ERROR( wxString::Format( _( "User does not have permission to delete directory \"%s\"." ),
2378  aLibraryPath.GetData() ) );
2379  }
2380 
2381  wxDir dir( aLibraryPath );
2382 
2383  if( dir.HasSubDirs() )
2384  {
2385  THROW_IO_ERROR( wxString::Format( _( "Library directory \"%s\" has unexpected sub-directories." ),
2386  aLibraryPath.GetData() ) );
2387  }
2388 
2389  // All the footprint files must be deleted before the directory can be deleted.
2390  if( dir.HasFiles() )
2391  {
2392  unsigned i;
2393  wxFileName tmp;
2394  wxArrayString files;
2395 
2396  wxDir::GetAllFiles( aLibraryPath, &files );
2397 
2398  for( i = 0; i < files.GetCount(); i++ )
2399  {
2400  tmp = files[i];
2401 
2402  if( tmp.GetExt() != KiCadFootprintFileExtension )
2403  {
2404  THROW_IO_ERROR( wxString::Format( _( "Unexpected file \"%s\" was found in library path \"%s\"." ),
2405  files[i].GetData(), aLibraryPath.GetData() ) );
2406  }
2407  }
2408 
2409  for( i = 0; i < files.GetCount(); i++ )
2410  wxRemoveFile( files[i] );
2411  }
2412 
2413  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"." ),
2414  aLibraryPath.GetData() );
2415 
2416  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2417  // we don't want that. we want bare metal portability with no UI here.
2418  if( !wxRmdir( aLibraryPath ) )
2419  {
2420  THROW_IO_ERROR( wxString::Format( _( "Footprint library \"%s\" cannot be deleted." ),
2421  aLibraryPath.GetData() ) );
2422  }
2423 
2424  // For some reason removing a directory in Windows is not immediately updated. This delay
2425  // prevents an error when attempting to immediately recreate the same directory when over
2426  // writing an existing library.
2427 #ifdef __WINDOWS__
2428  wxMilliSleep( 250L );
2429 #endif
2430 
2431  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2432  {
2433  delete m_cache;
2434  m_cache = NULL;
2435  }
2436 
2437  return true;
2438 }
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:33

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:33

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

2212 {
2213  const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2214  return footprint ? (MODULE*) footprint->Duplicate() : nullptr;
2215 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.

References BOARD_ITEM::Duplicate(), and 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 2218 of file kicad_plugin.cpp.

2220 {
2221  LOCALE_IO toggle; // toggles on, then off, the C locale.
2222 
2223  init( aProperties );
2224 
2225  // In this public PLUGIN API function, we can safely assume it was
2226  // called for saving into a library path.
2228 
2229  validateCache( aLibraryPath );
2230 
2231  if( !m_cache->IsWritable() )
2232  {
2233  if( !m_cache->Exists() )
2234  {
2235  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2236  "Would you like to create it?"),
2237  GetChars( aLibraryPath ) );
2238 
2239  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2240  return;
2241 
2242  // Save throws its own IO_ERROR on failure, so no need to recreate here
2243  m_cache->Save( NULL );
2244  }
2245  else
2246  {
2247  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
2248  THROW_IO_ERROR( msg );
2249  }
2250  }
2251 
2252  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2253 
2254  MODULE_MAP& mods = m_cache->GetModules();
2255 
2256  // Quietly overwrite module and delete module file from path for any by same name.
2257  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2259 
2260 #ifndef __WINDOWS__
2261  // Write through symlinks, don't replace them
2262  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2263  {
2264  char buffer[ PATH_MAX + 1 ];
2265  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2266 
2267  if( pathLen > 0 )
2268  {
2269  buffer[ pathLen ] = '\0';
2270  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2271  fn.Normalize();
2272  }
2273  }
2274 #endif
2275 
2276  if( !fn.IsOk() )
2277  {
2278  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2279  fn.GetFullPath() ) );
2280  }
2281 
2282  if( fn.FileExists() && !fn.IsFileWritable() )
2283  {
2284  THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
2285  fn.GetFullPath() ) );
2286  }
2287 
2288  wxString fullPath = fn.GetFullPath();
2289  wxString fullName = fn.GetFullName();
2290  MODULE_CITER it = mods.find( footprintName );
2291 
2292  if( it != mods.end() )
2293  {
2294  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2295  mods.erase( footprintName );
2296  wxRemoveFile( fullPath );
2297  }
2298 
2299  // I need my own copy for the cache
2300  MODULE* module = static_cast<MODULE*>( aFootprint->Duplicate() );
2301 
2302  // It should have no parent, orientation should be zero, and it should be on the front layer.
2303  module->SetParent( nullptr );
2304  module->SetOrientation( 0 );
2305 
2306  if( module->GetLayer() != F_Cu )
2307  {
2308  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2309 
2310  if( cfg )
2311  module->Flip( module->GetPosition(), cfg->m_FlipLeftRight );
2312  else
2313  module->Flip( module->GetPosition(), false );
2314  }
2315 
2316  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2317  mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
2318  m_cache->Save( module );
2319 }
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:214
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:215
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:200
#define NULL
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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:153
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: common.h:412
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:33
void SetOrientation(double newangle)
#define TO_UTF8(wxstring)
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:206
MODULE_MAP & GetModules()
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.

References _, CTL_FOR_LIBRARY, BOARD_ITEM::Duplicate(), FP_CACHE::Exists(), F_Cu, MODULE::Flip(), Format(), GetChars(), MODULE::GetFPID(), BOARD_ITEM::GetLayer(), LIB_ID::GetLibItemName(), FP_CACHE::GetModules(), MODULE::GetPosition(), init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, Kiface(), m_cache, m_ctl, NULL, FP_CACHE::Save(), MODULE::SetOrientation(), EDA_ITEM::SetParent(), 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 402 of file kicad_plugin.cpp.

403 {
404  LOCALE_IO toggle; // public API function, perform anything convenient for caller
405 
406  switch( aItem->Type() )
407  {
408  case PCB_T:
409  format( static_cast<BOARD*>( aItem ), aNestLevel );
410  break;
411 
412  case PCB_DIMENSION_T:
413  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
414  break;
415 
416  case PCB_LINE_T:
417  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
418  break;
419 
420  case PCB_MODULE_EDGE_T:
421  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
422  break;
423 
424  case PCB_TARGET_T:
425  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
426  break;
427 
428  case PCB_MODULE_T:
429  format( static_cast<MODULE*>( aItem ), aNestLevel );
430  break;
431 
432  case PCB_PAD_T:
433  format( static_cast<D_PAD*>( aItem ), aNestLevel );
434  break;
435 
436  case PCB_TEXT_T:
437  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
438  break;
439 
440  case PCB_MODULE_TEXT_T:
441  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
442  break;
443 
444  case PCB_TRACE_T:
445  case PCB_ARC_T:
446  case PCB_VIA_T:
447  format( static_cast<TRACK*>( aItem ), aNestLevel );
448  break;
449 
451  case PCB_ZONE_AREA_T:
452  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
453  break;
454 
455  default:
456  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
457  }
458 }
Definition: typeinfo.h:85
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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:100
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h: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:197

References format(), EDA_ITEM::GetClass(), PCB_ARC_T, 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 784 of file kicad_plugin.cpp.

785 {
786  formatHeader( aBoard, aNestLevel );
787 
788  // Save the modules.
789  for( auto module : aBoard->Modules() )
790  {
791  Format( module, aNestLevel );
792  m_out->Print( 0, "\n" );
793  }
794 
795  // Save the graphical items on the board (not owned by a module)
796  for( auto item : aBoard->Drawings() )
797  Format( item, aNestLevel );
798 
799  if( aBoard->Drawings().size() )
800  m_out->Print( 0, "\n" );
801 
802  // Do not save MARKER_PCBs, they can be regenerated easily.
803 
804  // Save the tracks and vias.
805  for( auto track : aBoard->Tracks() )
806  Format( track, aNestLevel );
807 
808  if( aBoard->Tracks().size() )
809  m_out->Print( 0, "\n" );
810 
811  // Save the polygon (which are the newer technology) zones.
812  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
813  Format( aBoard->GetArea( i ), aNestLevel );
814 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:927
MODULES & Modules()
Definition: class_board.h:256
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:892
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:265
TRACKS & Tracks()
Definition: class_board.h:247

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

818 {
819  m_out->Print( aNestLevel, "(dimension %s (width %s)",
820  FormatInternalUnits( aDimension->GetValue() ).c_str(),
821  FormatInternalUnits( aDimension->GetWidth() ).c_str() );
822 
823  formatLayer( aDimension );
824 
825  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aDimension->m_Uuid.AsString() ) );
826 
827  m_out->Print( 0, "\n" );
828 
829  Format( &aDimension->Text(), aNestLevel+1 );
830 
831  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
832  FormatInternalUnits( aDimension->m_featureLineDO.x ).c_str(),
833  FormatInternalUnits( aDimension->m_featureLineDO.y ).c_str(),
834  FormatInternalUnits( aDimension->m_featureLineDF.x ).c_str(),
835  FormatInternalUnits( aDimension->m_featureLineDF.y ).c_str() );
836 
837  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
838  FormatInternalUnits( aDimension->m_featureLineGO.x ).c_str(),
839  FormatInternalUnits( aDimension->m_featureLineGO.y ).c_str(),
840  FormatInternalUnits( aDimension->m_featureLineGF.x ).c_str(),
841  FormatInternalUnits( aDimension->m_featureLineGF.y ).c_str() );
842 
843  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
844  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
845  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
846  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
847  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str() );
848 
849  m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
850  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
851  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
852  FormatInternalUnits( aDimension->m_arrowD1F.x ).c_str(),
853  FormatInternalUnits( aDimension->m_arrowD1F.y ).c_str() );
854 
855  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
856  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
857  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
858  FormatInternalUnits( aDimension->m_arrowD2F.x ).c_str(),
859  FormatInternalUnits( aDimension->m_arrowD2F.y ).c_str() );
860 
861  m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
862  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
863  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
864  FormatInternalUnits( aDimension->m_arrowG1F.x ).c_str(),
865  FormatInternalUnits( aDimension->m_arrowG1F.y ).c_str() );
866 
867  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
868  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
869  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
870  FormatInternalUnits( aDimension->m_arrowG2F.x ).c_str(),
871  FormatInternalUnits( aDimension->m_arrowG2F.y ).c_str() );
872 
873  m_out->Print( aNestLevel, ")\n" );
874 }
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
wxString AsString() const
Definition: common.cpp:157
wxPoint m_featureLineDF
wxPoint m_featureLineGO
int GetValue() const
wxPoint m_arrowG1F
wxPoint m_arrowD2F
wxPoint m_arrowG2F
const KIID m_Uuid
Definition: base_struct.h:166
TEXTE_PCB & Text()
#define TO_UTF8(wxstring)
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:531
wxPoint m_featureLineGF

References KIID::AsString(), Format(), FormatInternalUnits(), formatLayer(), 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, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), DIMENSION::Text(), TO_UTF8, wxPoint::x, and wxPoint::y.

◆ format() [3/11]

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

Definition at line 954 of file kicad_plugin.cpp.

955 {
956  switch( aModuleDrawing->GetShape() )
957  {
958  case S_SEGMENT: // Line
959  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
960  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
961  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
962  break;
963 
964  case S_CIRCLE: // Circle
965  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
966  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
967  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
968  break;
969 
970  case S_ARC: // Arc
971  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
972  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
973  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str(),
974  FormatAngle( aModuleDrawing->GetAngle() ).c_str() );
975  break;
976 
977  case S_POLYGON: // Polygonal segment
978  if( aModuleDrawing->IsPolyShapeValid() )
979  {
980  SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
981  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
982  int pointsCount = outline.PointCount();
983 
984  m_out->Print( aNestLevel, "(fp_poly (pts" );
985 
986  for( int ii = 0; ii < pointsCount; ++ii )
987  {
988  int nestLevel = 0;
989 
990  if( ii && !( ii%4 ) ) // newline every 4 pts
991  {
992  nestLevel = aNestLevel + 1;
993  m_out->Print( 0, "\n" );
994  }
995 
996  m_out->Print( nestLevel, "%s(xy %s)",
997  nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
998  }
999 
1000  m_out->Print( 0, ")" );
1001  }
1002  else
1003  {
1004  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
1005  return;
1006  }
1007  break;
1008 
1009  case S_CURVE: // Bezier curve
1010  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
1011  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
1012  FormatInternalUnits( aModuleDrawing->GetBezier0_C1() ).c_str(),
1013  FormatInternalUnits( aModuleDrawing->GetBezier0_C2() ).c_str(),
1014  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
1015  break;
1016 
1017  default:
1018  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
1019  return;
1020  };
1021 
1022  formatLayer( aModuleDrawing );
1023 
1024  m_out->Print( 0, " (width %s)", FormatInternalUnits( aModuleDrawing->GetWidth() ).c_str() );
1025 
1026  m_out->Print( 0, ")\n" );
1027 }
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:560
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:531

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

878 {
879  switch( aSegment->GetShape() )
880  {
881  case S_SEGMENT: // Line
882  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
883  FormatInternalUnits( aSegment->GetStart() ).c_str(),
884  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
885 
886  if( aSegment->GetAngle() != 0.0 )
887  m_out->Print( 0, " (angle %s)", FormatAngle( aSegment->GetAngle() ).c_str() );
888 
889  break;
890 
891  case S_CIRCLE: // Circle
892  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
893  FormatInternalUnits( aSegment->GetStart() ).c_str(),
894  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
895  break;
896 
897  case S_ARC: // Arc
898  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
899  FormatInternalUnits( aSegment->GetStart() ).c_str(),
900  FormatInternalUnits( aSegment->GetEnd() ).c_str(),
901  FormatAngle( aSegment->GetAngle() ).c_str() );
902  break;
903 
904  case S_POLYGON: // Polygon
905  if( aSegment->IsPolyShapeValid() )
906  {
907  SHAPE_POLY_SET& poly = aSegment->GetPolyShape();
908  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
909  int pointsCount = outline.PointCount();
910 
911  m_out->Print( aNestLevel, "(gr_poly (pts" );
912 
913  for( int ii = 0; ii < pointsCount; ++ii )
914  {
915  m_out->Print( 0, " (xy %s)", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
916  }
917 
918  m_out->Print( 0, ")" );
919  }
920  else
921  {
922  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
923  return;
924  }
925 
926  break;
927 
928  case S_CURVE: // Bezier curve
929  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
930  FormatInternalUnits( aSegment->GetStart() ).c_str(),
931  FormatInternalUnits( aSegment->GetBezControl1() ).c_str(),
932  FormatInternalUnits( aSegment->GetBezControl2() ).c_str(),
933  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
934  break;
935 
936  default:
937  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
938  return;
939  };
940 
941  formatLayer( aSegment );
942 
943  m_out->Print( 0, " (width %s)", FormatInternalUnits( aSegment->GetWidth() ).c_str() );
944 
945  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aSegment->m_Uuid.AsString() ) );
946 
947  if( aSegment->GetStatus() )
948  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
949 
950  m_out->Print( 0, ")\n" );
951 }
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:236
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)
wxString AsString() const
Definition: common.cpp:157
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:560
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Arcs (with rounded ends)
SHAPE_POLY_SET & GetPolyShape()
Bezier Curve.
int GetWidth() const
const KIID m_Uuid
Definition: base_struct.h:166
double GetAngle() const
SHAPE_LINE_CHAIN.
const wxPoint & GetBezControl2() const
#define TO_UTF8(wxstring)
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:531

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

◆ format() [5/11]

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

Definition at line 1030 of file kicad_plugin.cpp.

1031 {
1032  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
1033  ( aTarget->GetShape() ) ? "x" : "plus",
1034  FormatInternalUnits( aTarget->GetPosition() ).c_str(),
1035  FormatInternalUnits( aTarget->GetSize() ).c_str() );
1036 
1037  if( aTarget->GetWidth() != 0 )
1038  m_out->Print( 0, " (width %s)", FormatInternalUnits( aTarget->GetWidth() ).c_str() );
1039 
1040  formatLayer( aTarget );
1041 
1042  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTarget->m_Uuid.AsString() ) );
1043 
1044  m_out->Print( 0, ")\n" );
1045 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
int GetSize() const
wxString AsString() const
Definition: common.cpp:157
int GetWidth() const
const KIID m_Uuid
Definition: base_struct.h:166
int GetShape() const
#define TO_UTF8(wxstring)
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:531
const wxPoint GetPosition() const override

References KIID::AsString(), FormatInternalUnits(), formatLayer(), PCB_TARGET::GetPosition(), PCB_TARGET::GetShape(), PCB_TARGET::GetSize(), PCB_TARGET::GetWidth(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), and TO_UTF8.

◆ format() [6/11]

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

Definition at line 1048 of file kicad_plugin.cpp.

1049 {
1050  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1051  {
1052  const wxArrayString* initial_comments = aModule->GetInitialComments();
1053 
1054  if( initial_comments )
1055  {
1056  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
1057  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1058 
1059  m_out->Print( 0, "\n" ); // improve readability?
1060  }
1061  }
1062 
1063  m_out->Print( aNestLevel, "(module %s",
1064  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1065 
1066  if( aModule->IsLocked() )
1067  m_out->Print( 0, " locked" );
1068 
1069  if( aModule->IsPlaced() )
1070  m_out->Print( 0, " placed" );
1071 
1072  formatLayer( aModule );
1073 
1074  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1075 
1076  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1077  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aModule->m_Uuid.AsString() ) );
1078 
1079  m_out->Print( 0, "\n" );
1080 
1081  if( !( m_ctl & CTL_OMIT_AT ) )
1082  {
1083  m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aModule->GetPosition() ).c_str() );
1084 
1085  if( aModule->GetOrientation() != 0.0 )
1086  m_out->Print( 0, " %s", FormatAngle( aModule->GetOrientation() ).c_str() );
1087 
1088  m_out->Print( 0, ")\n" );
1089  }
1090 
1091  if( !aModule->GetDescription().IsEmpty() )
1092  m_out->Print( aNestLevel+1, "(descr %s)\n",
1093  m_out->Quotew( aModule->GetDescription() ).c_str() );
1094 
1095  if( !aModule->GetKeywords().IsEmpty() )
1096  m_out->Print( aNestLevel+1, "(tags %s)\n",
1097  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1098 
1099  if( !( m_ctl & CTL_OMIT_PATH ) && !aModule->GetPath().empty() )
1100  m_out->Print( aNestLevel+1, "(path %s)\n",
1101  m_out->Quotew( aModule->GetPath().AsString() ).c_str() );
1102 
1103  if( aModule->GetPlacementCost90() != 0 )
1104  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1105 
1106  if( aModule->GetPlacementCost180() != 0 )
1107  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1108 
1109  if( aModule->GetLocalSolderMaskMargin() != 0 )
1110  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1111  FormatInternalUnits( aModule->GetLocalSolderMaskMargin() ).c_str() );
1112 
1113  if( aModule->GetLocalSolderPasteMargin() != 0 )
1114  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1115  FormatInternalUnits( aModule->GetLocalSolderPasteMargin() ).c_str() );
1116 
1117  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1118  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1119  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1120 
1121  if( aModule->GetLocalClearance() != 0 )
1122  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1123  FormatInternalUnits( aModule->GetLocalClearance() ).c_str() );
1124 
1125  if( aModule->GetZoneConnection() != ZONE_CONNECTION::INHERITED )
1126  m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
1127  static_cast<int>( aModule->GetZoneConnection() ) );
1128 
1129  if( aModule->GetThermalWidth() != 0 )
1130  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1131  FormatInternalUnits( aModule->GetThermalWidth() ).c_str() );
1132 
1133  if( aModule->GetThermalGap() != 0 )
1134  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1135  FormatInternalUnits( aModule->GetThermalGap() ).c_str() );
1136 
1137  // Attributes
1138  if( aModule->GetAttributes() != MOD_DEFAULT )
1139  {
1140  m_out->Print( aNestLevel+1, "(attr" );
1141 
1142  if( aModule->GetAttributes() & MOD_CMS )
1143  m_out->Print( 0, " smd" );
1144 
1145  if( aModule->GetAttributes() & MOD_VIRTUAL )
1146  m_out->Print( 0, " virtual" );
1147 
1148  m_out->Print( 0, ")\n" );
1149  }
1150 
1151  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1152  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1153 
1154  // Save drawing elements.
1155  for( auto gr : aModule->GraphicalItems() )
1156  Format( gr, aNestLevel+1 );
1157 
1158  // Save pads.
1159  for( auto pad : aModule->Pads() )
1160  format( pad, aNestLevel+1 );
1161 
1162  // Save zones.
1163  for( auto zone : aModule->Zones() )
1164  format( zone, aNestLevel + 1 );
1165 
1166  // Save 3D info.
1167  auto bs3D = aModule->Models().begin();
1168  auto es3D = aModule->Models().end();
1169 
1170  while( bs3D != es3D )
1171  {
1172  if( !bs3D->m_Filename.IsEmpty() )
1173  {
1174  m_out->Print( aNestLevel+1, "(model %s%s\n",
1175  m_out->Quotew( bs3D->m_Filename ).c_str(),
1176  bs3D->m_Show ? "" : " hide" );
1177 
1178  if( bs3D->m_Opacity != 1.0 )
1179  m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
1180 
1181  /* Write 3D model offset in mm
1182  * 4.0.x wrote "at" which was actually in inches
1183  * 5.0.x onwards, 3D model offset is written using "offset"
1184  *
1185  * If the offset is all zero, write "at" (fewer file changes)
1186  * Otherwise, write "offset"
1187  */
1188 
1189  wxString offsetTag = "offset";
1190 
1191  if( bs3D->m_Offset.x == 0 &&
1192  bs3D->m_Offset.y == 0 &&
1193  bs3D->m_Offset.z == 0 )
1194  {
1195  offsetTag = "at";
1196  }
1197 
1198  m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
1199  offsetTag.ToStdString().c_str(),
1200  Double2Str( bs3D->m_Offset.x ).c_str(),
1201  Double2Str( bs3D->m_Offset.y ).c_str(),
1202  Double2Str( bs3D->m_Offset.z ).c_str() );
1203 
1204  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1205  Double2Str( bs3D->m_Scale.x ).c_str(),
1206  Double2Str( bs3D->m_Scale.y ).c_str(),
1207  Double2Str( bs3D->m_Scale.z ).c_str() );
1208 
1209  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1210  Double2Str( bs3D->m_Rotation.x ).c_str(),
1211  Double2Str( bs3D->m_Rotation.y ).c_str(),
1212  Double2Str( bs3D->m_Rotation.z ).c_str() );
1213 
1214  m_out->Print( aNestLevel+1, ")\n" );
1215  }
1216  ++bs3D;
1217  }
1218 
1219  m_out->Print( aNestLevel, ")\n" );
1220 }
timestamp_t GetLastEditTime() const
Definition: class_module.h:345
int GetAttributes() const
Definition: class_module.h:255
double GetOrientation() const
Definition: class_module.h:211
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetPlacementCost90() const
Definition: class_module.h:547
TEXTE_MODULE & Reference()
Definition: class_module.h:469
#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:315
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:244
PADS & Pads()
Definition: class_module.h:169
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:68
wxString AsString() const
Definition: common.cpp:157
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
const LIB_ID & GetFPID() const
Definition: class_module.h:215
const KIID_PATH & GetPath() const
Definition: class_module.h:224
DRAWINGS & GraphicalItems()
Definition: class_module.h:179
int GetLocalSolderMaskMargin() const
Definition: class_module.h:227
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:560
int GetLocalClearance() const
Definition: class_module.h:230
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:468
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:650
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:297
const wxString & GetKeywords() const
Definition: class_module.h:221
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:184
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:233
default
Definition: class_module.h:67
const KIID m_Uuid
Definition: base_struct.h:166
int GetPlacementCost180() const
Definition: class_module.h:544
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:218
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:236
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:201
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:70
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
wxString AsString() const
Definition: common.h:135
void format(BOARD *aBoard, int aNestLevel=0) const
#define TO_UTF8(wxstring)
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:250
const wxPoint GetPosition() const override
Definition: class_module.h:206
int GetThermalGap() const
Definition: class_module.h:253
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531

References KIID::AsString(), KIID_PATH::AsString(), 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(), MODULE::GetZoneConnection(), MODULE::GraphicalItems(), INHERITED, MODULE::IsLocked(), MODULE::IsPlaced(), m_ctl, m_out, EDA_ITEM::m_Uuid, 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 1315 of file kicad_plugin.cpp.

1316 {
1317  const char* shape;
1318 
1319  switch( aPad->GetShape() )
1320  {
1321  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1322  case PAD_SHAPE_RECT: shape = "rect"; break;
1323  case PAD_SHAPE_OVAL: shape = "oval"; break;
1324  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1326  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1327  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1328 
1329  default:
1330  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1331  }
1332 
1333  const char* type;
1334 
1335  switch( aPad->GetAttribute() )
1336  {
1337  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1338  case PAD_ATTRIB_SMD: type = "smd"; break;
1339  case PAD_ATTRIB_CONN: type = "connect"; break;
1340  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1341 
1342  default:
1343  THROW_IO_ERROR( wxString::Format( "unknown pad attribute: %d", aPad->GetAttribute() ) );
1344  }
1345 
1346  const char* property = nullptr;
1347 
1348  switch( aPad->GetProperty() )
1349  {
1350  case PAD_PROP_NONE: break;
1351  case PAD_PROP_BGA: property = "pad_prop_bga"; break;
1352  case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1353  case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1354  case PAD_PROP_TESTPOINT: property = "pad_prop_testpoint"; break;
1355  case PAD_PROP_HEATSINK: property = "pad_prop_heatsink"; break;
1356  case PAD_PROP_CASTELLATED: property = "pad_prop_castellated"; break;
1357 
1358  default:
1359  THROW_IO_ERROR( wxString::Format( "unknown pad property: %d", aPad->GetProperty() ) );
1360  }
1361 
1362  m_out->Print( aNestLevel, "(pad %s %s %s",
1363  m_out->Quotew( aPad->GetName() ).c_str(),
1364  type, shape );
1365  m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
1366 
1367  if( aPad->GetOrientation() != 0.0 )
1368  m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() );
1369 
1370  m_out->Print( 0, ")" );
1371  m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
1372 
1373  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1374  m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() );
1375 
1376  wxSize sz = aPad->GetDrillSize();
1377  wxPoint shapeoffset = aPad->GetOffset();
1378 
1379  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1380  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1381  {
1382  m_out->Print( 0, " (drill" );
1383 
1384  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1385  m_out->Print( 0, " oval" );
1386 
1387  if( sz.GetWidth() > 0 )
1388  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetWidth() ).c_str() );
1389 
1390  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1391  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetHeight() ).c_str() );
1392 
1393  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1394  m_out->Print( 0, " (offset %s)", FormatInternalUnits( aPad->GetOffset() ).c_str() );
1395 
1396  m_out->Print( 0, ")" );
1397  }
1398 
1399  if( property && ADVANCED_CFG::GetCfg().m_EnableUsePadProperty )
1400  {
1401  // Add pad property, if exists.
1402  m_out->Print( 0, " (property %s)", property );
1403  }
1404 
1405  formatLayers( aPad->GetLayerSet() );
1406 
1407  // Output the radius ratio for rounded and chamfered rect pads
1408  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT || aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1409  {
1410  m_out->Print( 0, " (roundrect_rratio %s)",
1411  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1412  }
1413 
1414  // Output the chamfer corners for chamfered rect pads
1415  if( aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1416  {
1417  m_out->Print( 0, "\n" );
1418 
1419  m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
1420  Double2Str( aPad->GetChamferRectRatio() ).c_str() );
1421 
1422  m_out->Print( 0, " (chamfer" );
1423 
1424  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
1425  m_out->Print( 0, " top_left" );
1426 
1427  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT ) )
1428  m_out->Print( 0, " top_right" );
1429 
1430  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT ) )
1431  m_out->Print( 0, " bottom_left" );
1432 
1434  m_out->Print( 0, " bottom_right" );
1435 
1436  m_out->Print( 0, ")" );
1437  }
1438 
1439  std::string output;
1440 
1441  // Unconnected pad is default net so don't save it.
1442  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1443  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1444  m_out->Quotew( aPad->GetNetname() ).c_str() );
1445 
1446  // Add pinfunction, if exists.
1447  // Pin function is closely related to nets, so if CTL_OMIT_NETS is set,
1448  // omit also pin function (for instance when saved from library editor)
1449  if( !(m_ctl & CTL_OMIT_NETS) && !aPad->GetPinFunction().IsEmpty() )
1450  StrPrintf( &output, " (pinfunction %s)",
1451  m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1452 
1453  if( aPad->GetPadToDieLength() != 0 )
1454  StrPrintf( &output, " (die_length %s)",
1455  FormatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
1456 
1457  if( aPad->GetLocalSolderMaskMargin() != 0 )
1458  StrPrintf( &output, " (solder_mask_margin %s)",
1459  FormatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() );
1460 
1461  if( aPad->GetLocalSolderPasteMargin() != 0 )
1462  StrPrintf( &output, " (solder_paste_margin %s)",
1463  FormatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() );
1464 
1465  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1466  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1467  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1468 
1469  if( aPad->GetLocalClearance() != 0 )
1470  StrPrintf( &output, " (clearance %s)", FormatInternalUnits( aPad->GetLocalClearance() ).c_str() );
1471 
1473  StrPrintf( &output, " (zone_connect %d)", static_cast<int>( aPad->GetZoneConnection() ) );
1474 
1475  if( aPad->GetThermalWidth() != 0 )
1476  StrPrintf( &output, " (thermal_width %s)", FormatInternalUnits( aPad->GetThermalWidth() ).c_str() );
1477 
1478  if( aPad->GetThermalGap() != 0 )
1479  StrPrintf( &output, " (thermal_gap %s)", FormatInternalUnits( aPad->GetThermalGap() ).c_str() );
1480 
1481  if( output.size() )
1482  {
1483  m_out->Print( 0, "\n" );
1484  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1485  }
1486 
1487  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1488  {
1489  m_out->Print( 0, "\n");
1490  m_out->Print( aNestLevel+1, "(options" );
1491 
1493  m_out->Print( 0, " (clearance convexhull)" );
1494  #if 1 // Set to 1 to output the default option
1495  else
1496  m_out->Print( 0, " (clearance outline)" );
1497  #endif
1498 
1499  // Output the anchor pad shape (circle/rect)
1500  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1501  shape = "rect";
1502  else
1503  shape = "circle";
1504 
1505  m_out->Print( 0, " (anchor %s)", shape );
1506 
1507  m_out->Print( 0, ")"); // end of (options ...
1508 
1509  // Output graphic primitive of the pad shape
1510  m_out->Print( 0, "\n");
1511  m_out->Print( aNestLevel+1, "(primitives" );
1512 
1513  int nested_level = aNestLevel+2;
1514 
1515  // Output all basic shapes
1516  for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
1517  {
1518  m_out->Print( 0, "\n");
1519 
1520  const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
1521 
1522  switch( primitive.m_Shape )
1523  {
1524  case S_SEGMENT: // usual segment : line with rounded ends
1525  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1526  FormatInternalUnits( primitive.m_Start ).c_str(),
1527  FormatInternalUnits( primitive.m_End ).c_str(),
1528  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1529  break;
1530 
1531  case S_ARC: // Arc with rounded ends
1532  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1533  FormatInternalUnits( primitive.m_Start ).c_str(),
1534  FormatInternalUnits( primitive.m_End ).c_str(),
1535  FormatAngle( primitive.m_ArcAngle ).c_str(),
1536  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1537  break;
1538 
1539  case S_CIRCLE: // ring or circle (circle if width == 0
1540  m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
1541  FormatInternalUnits( primitive.m_Start ).c_str(),
1542  FormatInternalUnits( primitive.m_Start.x + primitive.m_Radius ).c_str(),
1543  FormatInternalUnits( primitive.m_Start.y ).c_str(),
1544  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1545  break;
1546 
1547  case S_CURVE: // Bezier Curve
1548  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s)) (width %s))",
1549  FormatInternalUnits( primitive.m_Start ).c_str(),
1550  FormatInternalUnits( primitive.m_Ctrl1 ).c_str(),
1551  FormatInternalUnits( primitive.m_Ctrl2 ).c_str(),
1552  FormatInternalUnits( primitive.m_End ).c_str(),
1553  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1554  break;
1555 
1556  case S_POLYGON: // polygon
1557  if( primitive.m_Poly.size() < 2 )
1558  break; // Malformed polygon.
1559 
1560  {
1561  m_out->Print( nested_level, "(gr_poly (pts\n");
1562 
1563  // Write the polygon corners coordinates:
1564  const std::vector< wxPoint>& poly = primitive.m_Poly;
1565  int newLine = 0;
1566 
1567  for( unsigned ii = 0; ii < poly.size(); ii++ )
1568  {
1569  if( newLine == 0 )
1570  m_out->Print( nested_level+1, " (xy %s)",
1571  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1572  else
1573  m_out->Print( 0, " (xy %s)",
1574  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1575 
1576  if( ++newLine > 4 )
1577  {
1578  newLine = 0;
1579  m_out->Print( 0, "\n" );
1580  }
1581  }
1582 
1583  m_out->Print( 0, ") (width %s))", FormatInternalUnits( primitive.m_Thickness ).c_str() );
1584  }
1585  break;
1586 
1587  default:
1588  break;
1589  }
1590  }
1591 
1592  m_out->Print( 0, "\n");
1593  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1594  }
1595 
1596  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aPad->m_Uuid.AsString() ) );
1597 
1598  m_out->Print( 0, ")\n" );
1599 }
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:450
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:279
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:232
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:74
polygon (not yet used for tracks, but could be in microwave apps)
int GetPadToDieLength() const
Definition: class_pad.h:448
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
wxString AsString() const
Definition: common.cpp:157
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:62
a pad used as heat sink, usually in SMD footprints
Definition: pad_shapes.h:83
const wxString & GetPinFunction() const
Definition: class_pad.h:208
int GetThermalGap() const
Definition: class_pad.cpp:761
int GetLocalClearance() const
Definition: class_pad.h:453
wxPoint m_Ctrl1
is also the start point of the arc
Definition: class_pad.h:76
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:438
int GetChamferPositions() const
has meaning only for chamfered rect pads
Definition: class_pad.h:702
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:560
int m_Radius
thickness of segment or outline For filled S_CIRCLE shape, thickness = 0.
Definition: class_pad.h:72
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:358
std::vector< wxPoint > m_Poly
Bezier Control point 2.
Definition: class_pad.h:78
Arcs (with rounded ends)
const wxPoint & GetOffset() const
Definition: class_pad.h:294
ZONE_CONNECTION GetZoneConnection() const
Definition: class_pad.cpp:739
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:417
double GetChamferRectRatio() const
has meaning only for chamfered rect pads
Definition: class_pad.h:679
int GetThermalWidth() const
Definition: class_pad.cpp:750
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:65
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:435
const wxString & GetName() const
Definition: class_pad.h:200
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
PAD_PROP_T GetProperty() const
Definition: class_pad.h:441
Bezier Curve.
const wxSize & GetDelta() const
Definition: class_pad.h:288
const wxString & GetNetname() const
Function GetNetname.
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:75
#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:68
wxPoint m_Ctrl2
Bezier Control point 1.
Definition: class_pad.h:77
const KIID m_Uuid
Definition: base_struct.h:166
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:238
int m_Thickness
S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
Definition: class_pad.h:69
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:33
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:411
const wxSize & GetDrillSize() const
Definition: class_pad.h:291
#define TO_UTF8(wxstring)
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:653
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:222
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:285
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:456
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:461
double m_ArcAngle
radius of a circle
Definition: class_pad.h:73
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:459
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.

References _, KIID::AsString(), 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, 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, EDA_ITEM::m_Uuid, 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, TO_UTF8, 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 1602 of file kicad_plugin.cpp.

1603 {
1604  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1605  m_out->Quotew( aText->GetText() ).c_str(),
1606  FormatInternalUnits( aText->GetTextPos() ).c_str() );
1607 
1608  if( aText->GetTextAngle() != 0.0 )
1609  m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() );
1610 
1611  m_out->Print( 0, ")" );
1612 
1613  formatLayer( aText );
1614 
1615  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aText->m_Uuid.AsString() ) );
1616 
1617  m_out->Print( 0, "\n" );
1618 
1619  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1620 
1621  m_out->Print( aNestLevel, ")\n" );
1622 }
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:173
wxString AsString() const
Definition: common.cpp:157
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:560
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
const KIID m_Uuid
Definition: base_struct.h:166
#define TO_UTF8(wxstring)
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
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:126
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531

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

◆ format() [9/11]

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

Definition at line 1625 of file kicad_plugin.cpp.

1626 {
1627  std::string type;
1628 
1629  switch( aText->GetType() )
1630  {
1631  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1632  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1633  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1634  }
1635 
1636  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1637  type.c_str(),
1638  m_out->Quotew( aText->GetText() ).c_str(),
1639  FormatInternalUnits( aText->GetPos0() ).c_str() );
1640 
1641  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1642  // but internally the angle is held relative to its parent footprint. parent
1643  // may be NULL when saving a footprint outside a BOARD.
1644  double orient = aText->GetTextAngle();
1645  MODULE* parent = (MODULE*) aText->GetParent();
1646 
1647  if( parent )
1648  {
1649  // GetTextAngle() is always in -360..+360 range because of
1650  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1651  // additional board angle could kick sum up >= 360 or <= -360, so to have
1652  // consistent results, normalize again for the BOARD save. A footprint
1653  // save does not use this code path since parent is NULL.
1654 #if 0
1655  // This one could be considered reasonable if you like positive angles
1656  // in your board text.
1657  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1658 #else
1659  // Choose compatibility for now, even though this is only a 720 degree clamp
1660  // with two possible values for every angle.
1661  orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
1662 #endif
1663  }
1664 
1665  if( orient != 0.0 )
1666  m_out->Print( 0, " %s", FormatAngle( orient ).c_str() );
1667 
1668  if( !aText->IsKeepUpright() )
1669  m_out->Print( 0, " unlocked" );
1670 
1671  m_out->Print( 0, ")" );
1672  formatLayer( aText );
1673 
1674  if( !aText->IsVisible() )
1675  m_out->Print( 0, " hide" );
1676 
1677  m_out->Print( 0, "\n" );
1678 
1679  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1680 
1681  m_out->Print( aNestLevel, ")\n" );
1682 }
double GetOrientation() const
Definition: class_module.h:211
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:185
double GetTextAngle() const
Definition: eda_text.h:173
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:560
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:248
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:237
BOARD_ITEM_CONTAINER * GetParent() const
#define CTL_OMIT_HIDE
Definition: eda_text.h:42
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531

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

1686 {
1687  if( aTrack->Type() == PCB_VIA_T )
1688  {
1689  PCB_LAYER_ID layer1, layer2;
1690 
1691  const VIA* via = static_cast<const VIA*>( aTrack );
1692  BOARD* board = (BOARD*) via->GetParent();
1693 
1694  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( EDA_UNITS::MILLIMETRES )
1695  + wxT( " has no parent." ) );
1696 
1697  m_out->Print( aNestLevel, "(via" );
1698 
1699  via->LayerPair( &layer1, &layer2 );
1700 
1701  switch( via->GetViaType() )
1702  {
1703  case VIATYPE::THROUGH: // Default shape not saved.
1704  break;
1705 
1706  case VIATYPE::BLIND_BURIED:
1707  m_out->Print( 0, " blind" );
1708  break;
1709 
1710  case VIATYPE::MICROVIA:
1711  m_out->Print( 0, " micro" );
1712  break;
1713 
1714  default:
1715  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1716  }
1717 
1718  m_out->Print( 0, " (at %s) (size %s)",
1719  FormatInternalUnits( aTrack->GetStart() ).c_str(),
1720  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1721 
1722  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1723  m_out->Print( 0, " (drill %s)", FormatInternalUnits( via->GetDrill() ).c_str() );
1724 
1725  m_out->Print( 0, " (layers %s %s)",
1726  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1727  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1728  }
1729  else if( aTrack->Type() == PCB_ARC_T )
1730  {
1731  const ARC* arc = static_cast<const ARC*>( aTrack );
1732 
1733  m_out->Print( aNestLevel, "(arc (start %s) (mid %s) (end %s) (width %s)",
1734  FormatInternalUnits( arc->GetStart() ).c_str(),
1735  FormatInternalUnits( arc->GetMid() ).c_str(),
1736  FormatInternalUnits( arc->GetEnd() ).c_str(),
1737  FormatInternalUnits( arc->GetWidth() ).c_str() );
1738 
1739  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1740  }
1741  else
1742  {
1743  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1744  FormatInternalUnits( aTrack->GetStart() ).c_str(), FormatInternalUnits( aTrack->GetEnd() ).c_str(),
1745  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1746 
1747  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1748  }
1749 
1750  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1751 
1752  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTrack->m_Uuid.AsString() ) );
1753 
1754  if( aTrack->GetStatus() != 0 )
1755  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1756 
1757  m_out->Print( 0, ")\n" );
1758 }
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:236
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.
const wxPoint & GetStart() const
Definition: class_track.h:118
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
wxString AsString() const
Definition: common.cpp:157
PCB_LAYER_ID
A quick note on layer IDs:
const wxPoint & GetMid() const
Definition: class_track.h:292
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:451
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:78
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:77
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
const KIID m_Uuid
Definition: base_struct.h:166
int GetWidth() const
Definition: class_track.h:112
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:181
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * m_board
which BOARD, no ownership here
VIATYPE GetViaType() const
Definition: class_track.h:370
#define TO_UTF8(wxstring)
const wxPoint & GetEnd() const
Definition: class_track.h:115
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:531
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:197

References _, KIID::AsString(), BLIND_BURIED, Format(), FormatInternalUnits(), VIA::GetDrill(), TRACK::GetEnd(), BOARD_ITEM::GetLayerName(), BOARD::GetLayerName(), ARC::GetMid(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_ITEM::GetParent(), VIA::GetSelectMenuText(), TRACK::GetStart(), EDA_ITEM::GetStatus(), VIA::GetViaType(), TRACK::GetWidth(), VIA::LayerPair(), m_board, m_mapping, m_out, EDA_ITEM::m_Uuid, MICROVIA, MILLIMETRES, PCB_ARC_T, PCB_VIA_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), THROUGH, THROW_IO_ERROR, TO_UTF8, 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 1761 of file kicad_plugin.cpp.

1762 {
1763  // Save the NET info; For keepout zones, net code and net name are irrelevant
1764  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1765  // (perhaps netcode and netname should be not stored)
1766  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1767  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1768  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1769 
1770  // If a zone exists on multiple layers, format accordingly
1771  if( aZone->GetLayerSet().count() > 1 )
1772  {
1773  formatLayers( aZone->GetLayerSet() );
1774  }
1775  else
1776  {
1777  formatLayer( aZone );
1778  }
1779 
1780  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aZone->m_Uuid.AsString() ) );
1781 
1782  // Save the outline aux info
1783  std::string hatch;
1784 
1785  switch( aZone->GetHatchStyle() )
1786  {
1787  default:
1789  hatch = "none";
1790  break;
1792  hatch = "edge";
1793  break;
1795  hatch = "full";
1796  break;
1797  }
1798 
1799  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1800  FormatInternalUnits( aZone->GetHatchPitch() ).c_str() );
1801 
1802  if( aZone->GetPriority() > 0 )
1803  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1804 
1805  m_out->Print( aNestLevel+1, "(connect_pads" );
1806 
1807  switch( aZone->GetPadConnection() )
1808  {
1809  default:
1810  case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
1811  break;
1812 
1814  m_out->Print( 0, " thru_hole_only" );
1815  break;
1816 
1817  case ZONE_CONNECTION::FULL:
1818  m_out->Print( 0, " yes" );
1819  break;
1820 
1821  case ZONE_CONNECTION::NONE:
1822  m_out->Print( 0, " no" );
1823  break;
1824  }
1825 
1826  m_out->Print( 0, " (clearance %s))\n",
1827  FormatInternalUnits( aZone->GetZoneClearance() ).c_str() );
1828 
1829  m_out->Print( aNestLevel+1, "(min_thickness %s)",
1830  FormatInternalUnits( aZone->GetMinThickness() ).c_str() );
1831 
1832  // write it only if V 6.O version option is not used (i.e. do not write if the
1833  // "legacy" algorithm is used)
1834  if( !aZone->GetFilledPolysUseThickness() )
1835  m_out->Print( 0, " (filled_areas_thickness no)" );
1836 
1837  m_out->Print( 0, "\n" );
1838 
1839  if( aZone->GetIsKeepout() )
1840  {
1841  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (pads %s ) (copperpour %s) (footprints %s))\n",
1842  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1843  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1844  aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
1845  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
1846  aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
1847  }
1848 
1849  m_out->Print( aNestLevel+1, "(fill" );
1850 
1851  // Default is not filled.
1852  if( aZone->IsFilled() )
1853  m_out->Print( 0, " yes" );
1854 
1855  // Default is polygon filled.
1856  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1857  m_out->Print( 0, " (mode hatch)" );
1858 
1859  m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
1860  FormatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
1861  FormatInternalUnits( aZone->GetThermalReliefCopperBridge() ).c_str() );
1862 
1864  {
1865  m_out->Print( 0, " (smoothing" );
1866 
1867  switch( aZone->GetCornerSmoothingType() )
1868  {
1870  m_out->Print( 0, " chamfer" );
1871  break;
1872 
1874  m_out->Print( 0, " fillet" );
1875  break;
1876 
1877  default:
1878  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1879  aZone->GetCornerSmoothingType() ) );
1880  }
1881  m_out->Print( 0, ")" );
1882 
1883  if( aZone->GetCornerRadius() != 0 )
1884  m_out->Print( 0, " (radius %s)",
1885  FormatInternalUnits( aZone->GetCornerRadius() ).c_str() );
1886  }
1887 
1888  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1889  {
1890  m_out->Print( 0, "\n" );
1891  m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
1892  FormatInternalUnits( aZone->GetHatchFillTypeThickness() ).c_str(),
1893  FormatInternalUnits( aZone->GetHatchFillTypeGap() ).c_str(),
1894  Double2Str( aZone->GetHatchFillTypeOrientation() ).c_str() );
1895 
1896  if( aZone->GetHatchFillTypeSmoothingLevel() > 0 )
1897  {
1898  m_out->Print( 0, "\n" );
1899  m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
1901  Double2Str( aZone->GetHatchFillTypeSmoothingValue() ).c_str() );
1902  }
1903  }
1904 
1905  m_out->Print( 0, ")\n" );
1906 
1907  int newLine = 0;
1908 
1909  if( aZone->GetNumCorners() )
1910  {
1911  bool new_polygon = true;
1912  bool is_closed = false;
1913 
1914  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1915  {
1916  if( new_polygon )
1917  {
1918  newLine = 0;
1919  m_out->Print( aNestLevel+1, "(polygon\n" );
1920  m_out->Print( aNestLevel+2, "(pts\n" );
1921  new_polygon = false;
1922  is_closed = false;
1923  }
1924 
1925  if( newLine == 0 )
1926  m_out->Print( aNestLevel+3, "(xy %s %s)",
1927  FormatInternalUnits( iterator->x ).c_str(),
1928  FormatInternalUnits( iterator->y ).c_str() );
1929  else
1930  m_out->Print( 0, " (xy %s %s)",
1931  FormatInternalUnits( iterator->x ).c_str(),
1932  FormatInternalUnits( iterator->y ).c_str() );
1933 
1934  if( newLine < 4 )
1935  {
1936  newLine += 1;
1937  }
1938  else
1939  {
1940  newLine = 0;
1941  m_out->Print( 0, "\n" );
1942  }
1943 
1944  if( iterator.IsEndContour() )
1945  {
1946  is_closed = true;
1947 
1948  if( newLine != 0 )
1949  m_out->Print( 0, "\n" );
1950 
1951  m_out->Print( aNestLevel+2, ")\n" );
1952  m_out->Print( aNestLevel+1, ")\n" );
1953  new_polygon = true;
1954  }
1955  }
1956 
1957  if( !is_closed ) // Should not happen, but...
1958  {
1959  if( newLine != 0 )
1960  m_out->Print( 0, "\n" );
1961 
1962  m_out->Print( aNestLevel+2, ")\n" );
1963  m_out->Print( aNestLevel+1, ")\n" );
1964  }
1965  }
1966 
1967  // Save the PolysList (filled areas)
1968  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1969  newLine = 0;
1970 
1971  if( !fv.IsEmpty() )
1972  {
1973  bool new_polygon = true;
1974  bool is_closed = false;
1975 
1976  for( auto it = fv.CIterate(); it; ++it )
1977  {
1978  if( new_polygon )
1979  {
1980  newLine = 0;
1981  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1982  m_out->Print( aNestLevel+2, "(pts\n" );
1983  new_polygon = false;
1984  is_closed = false;
1985  }
1986 
1987  if( newLine == 0 )
1988  m_out->Print( aNestLevel+3, "(xy %s %s)",
1989  FormatInternalUnits( it->x ).c_str(),
1990  FormatInternalUnits( it->y ).c_str() );
1991  else
1992  m_out->Print( 0, " (xy %s %s)",
1993  FormatInternalUnits( it->x ) .c_str(),
1994  FormatInternalUnits( it->y ).c_str() );
1995 
1996  if( newLine < 4 )
1997  {
1998  newLine += 1;
1999  }
2000  else
2001  {
2002  newLine = 0;
2003  m_out->Print( 0, "\n" );
2004  }
2005 
2006  if( it.IsEndContour() )
2007  {
2008  is_closed = true;
2009 
2010  if( newLine != 0 )
2011  m_out->Print( 0, "\n" );
2012 
2013  m_out->Print( aNestLevel+2, ")\n" );
2014  m_out->Print( aNestLevel+1, ")\n" );
2015  new_polygon = true;
2016  }
2017  }
2018 
2019  if( !is_closed ) // Should not happen, but...
2020  m_out->Print( aNestLevel+1, ")\n" );
2021  }
2022 
2023  // Save the filling segments list
2024  const auto& segs = aZone->FillSegments();
2025 
2026  if( segs.size() )
2027  {
2028  m_out->Print( aNestLevel+1, "(fill_segments\n" );
2029 
2030  for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
2031  {
2032  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
2033  FormatInternalUnits( wxPoint( it->A ) ).c_str(),
2034  FormatInternalUnits( wxPoint( it->B ) ).c_str() );
2035  }
2036 
2037  m_out->Print( aNestLevel+1, ")\n" );
2038  }
2039 
2040  m_out->Print( aNestLevel, ")\n" );
2041 }
bool GetDoNotAllowPads() const
Definition: class_zone.h:658
bool IsFilled() const
Definition: class_zone.h:168
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:344
int GetHatchFillTypeThickness() const
Definition: class_zone.h:193
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
ZONE_SEGMENT_FILL & FillSegments()
Definition: class_zone.h:242
bool GetFilledPolysUseThickness() const
Definition: class_zone.h:614
double GetHatchFillTypeOrientation() const
Definition: class_zone.h:199
wxString AsString() const
Definition: common.cpp:157
double GetHatchFillTypeSmoothingValue() const
Definition: class_zone.h:205
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:335
bool GetDoNotAllowVias() const
Definition: class_zone.h:656
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:283
pads are covered by copper
unsigned int GetCornerRadius() const
Definition: class_zone.h:612
SHAPE_POLY_SET.
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:136
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:655
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:447
#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:829
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:535
int GetCornerSmoothingType() const
Definition: class_zone.h:608
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:654
Thermal relief only for THT pads.
const KIID m_Uuid
Definition: base_struct.h:166
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:33
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:467
int GetHatchPitch() const
Hatch related methods.
Definition: class_zone.cpp:921
#define TO_UTF8(wxstring)
int GetMinThickness() const
Definition: class_zone.h:184
Pads are not covered.
bool GetDoNotAllowTracks() const
Definition: class_zone.h:657
bool GetDoNotAllowFootprints() const
Definition: class_zone.h:659
int GetHatchFillTypeSmoothingLevel() const
Definition: class_zone.h:202
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int GetZoneClearance() const
Definition: class_zone.h:174
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:196
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531
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:568

References _, KIID::AsString(), 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::GetDoNotAllowFootprints(), ZONE_CONTAINER::GetDoNotAllowPads(), 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(), ZONE_CONTAINER::GetZoneClearance(), HATCH_PATTERN, SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::IsFilled(), ZONE_CONTAINER::IterateWithHoles(), m_mapping, m_out, EDA_ITEM::m_Uuid, 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, TO_UTF8, and NETINFO_MAPPING::Translate().

◆ formatBoardLayers()

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

formats the board layer information

Definition at line 682 of file kicad_plugin.cpp.

683 {
684  m_out->Print( aNestLevel, "(layers\n" );
685 
686  // Save only the used copper layers from front to back.
687  LSET visible_layers = aBoard->GetVisibleLayers();
688 
689  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
690  {
691  PCB_LAYER_ID layer = *cu;
692 
693  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
694  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
695  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
696 
697  if( !visible_layers[layer] )
698  m_out->Print( 0, " hide" );
699 
700  m_out->Print( 0, ")\n" );
701  }
702 
703  // Save used non-copper layers in the order they are defined.
704  // desired sequence for non Cu BOARD layers.
705  static const PCB_LAYER_ID non_cu[] =
706  {
707  B_Adhes, // 32
708  F_Adhes,
709  B_Paste,
710  F_Paste,
711  B_SilkS,
712  F_SilkS,
713  B_Mask,
714  F_Mask,
715  Dwgs_User,
716  Cmts_User,
717  Eco1_User,
718  Eco2_User,
719  Edge_Cuts,
720  Margin,
721  B_CrtYd,
722  F_CrtYd,
723  B_Fab,
724  F_Fab
725  };
726 
727  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
728  {
729  PCB_LAYER_ID layer = *seq;
730 
731  m_out->Print( aNestLevel+1, "(%d %s user", layer,
732  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
733 
734  if( !visible_layers[layer] )
735  m_out->Print( 0, " hide" );
736 
737  m_out->Print( 0, ")\n" );
738  }
739 
740  m_out->Print( aNestLevel, ")\n\n" );
741 }
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.
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:160
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 605 of file kicad_plugin.cpp.

606 {
607  m_out->Print( aNestLevel, "(defaults\n" );
608 
609  m_out->Print( aNestLevel+1, "(edge_clearance %s)\n",
610  FormatInternalUnits( aSettings.m_CopperEdgeClearance ).c_str() );
611 
612  m_out->Print( aNestLevel+1, "(edge_cuts_line_width %s)\n",
613  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_EDGES ] ).c_str() );
614 
615  m_out->Print( aNestLevel+1, "(courtyard_line_width %s)\n",
617 
618  m_out->Print( aNestLevel+1, "(copper_line_width %s)\n",
619  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_COPPER ] ).c_str() );
620  m_out->Print( aNestLevel+1, "(copper_text_dims (size %s %s) (thickness %s)%s%s)\n",
621  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].x ).c_str(),
622  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].y ).c_str(),
624  aSettings.m_TextItalic[ LAYER_CLASS_COPPER ] ? " italic" : "",
625  aSettings.m_TextUpright[ LAYER_CLASS_COPPER ] ? " keep_upright" : "" );
626 
627  m_out->Print( aNestLevel+1, "(silk_line_width %s)\n",
628  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_SILK ] ).c_str() );
629  m_out->Print( aNestLevel+1, "(silk_text_dims (size %s %s) (thickness %s)%s%s)\n",
630  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].x ).c_str(),
631  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].y ).c_str(),
632  FormatInternalUnits( aSettings.m_TextThickness[ LAYER_CLASS_SILK ] ).c_str(),
633  aSettings.m_TextItalic[ LAYER_CLASS_SILK ] ? " italic" : "",
634  aSettings.m_TextUpright[ LAYER_CLASS_SILK ] ? " keep_upright" : "" );
635 
636  m_out->Print( aNestLevel+1, "(fab_layers_line_width %s)\n",
637  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_FAB ] ).c_str() );
638  m_out->Print( aNestLevel+1, "(fab_layers_text_dims (size %s %s) (thickness %s)%s%s)\n",
639  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_FAB ].x ).c_str(),
640  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_FAB ].y ).c_str(),
641  FormatInternalUnits( aSettings.m_TextThickness[ LAYER_CLASS_FAB ] ).c_str(),
642  aSettings.m_TextItalic[ LAYER_CLASS_OTHERS ] ? " italic" : "",
643  aSettings.m_TextUpright[ LAYER_CLASS_OTHERS ] ? " keep_upright" : "" );
644 
645  m_out->Print( aNestLevel+1, "(other_layers_line_width %s)\n",
646  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_OTHERS ] ).c_str() );
647  m_out->Print( aNestLevel+1, "(other_layers_text_dims (size %s %s) (thickness %s)%s%s)\n",
648  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x ).c_str(),
649  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y ).c_str(),
651  aSettings.m_TextItalic[ LAYER_CLASS_OTHERS ] ? " italic" : "",
652  aSettings.m_TextUpright[ LAYER_CLASS_OTHERS ] ? " keep_upright" : "" );
653 
654  m_out->Print( aNestLevel+1, "(dimension_units %d)\n", aSettings.m_DimensionUnits );
655  m_out->Print( aNestLevel+1, "(dimension_precision %d)\n", aSettings.m_DimensionPrecision );
656 
657  m_out->Print( aNestLevel, ")\n" );
658 }
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:531

References FormatInternalUnits(), LAYER_CLASS_COPPER, LAYER_CLASS_COURTYARD, LAYER_CLASS_EDGES, LAYER_CLASS_FAB, 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 661 of file kicad_plugin.cpp.

662 {
663  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
664 
665  m_out->Print( 0, "\n" );
666  m_out->Print( aNestLevel, "(general\n" );
667  // Write Bounding box info
668  m_out->Print( aNestLevel+1, "(thickness %s)\n",
669  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
670 
671  m_out->Print( aNestLevel+1, "(drawings %u)\n", (unsigned)aBoard->Drawings().size() );
672  m_out->Print( aNestLevel + 1, "(tracks %u)\n", (unsigned)aBoard->Tracks().size() );
673  m_out->Print( aNestLevel + 1, "(modules %u)\n", (unsigned)aBoard->Modules().size() );
674  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
675  m_out->Print( aNestLevel, ")\n\n" );
676 
677  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
678  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
679 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:557
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
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:375
MODULES & Modules()
Definition: class_board.h:256
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:183
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:563
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:265
TRACKS & Tracks()
Definition: class_board.h:247
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531
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 771 of file kicad_plugin.cpp.

772 {
773  formatGeneral( aBoard, aNestLevel );
774  // Layers list.
775  formatBoardLayers( aBoard, aNestLevel );
776 
777  // Setup
778  formatSetup( aBoard, aNestLevel );
779 
780  // Save net codes and names
781  formatNetInformation( aBoard, aNestLevel );
782 }
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 461 of file kicad_plugin.cpp.

462 {
463  if( m_ctl & CTL_STD_LAYER_NAMES )
464  {
465  PCB_LAYER_ID layer = aItem->GetLayer();
466 
467  // English layer names should never need quoting.
468  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
469  }
470  else
471  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
472 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
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.
#define TO_UTF8(wxstring)
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:640

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

1224 {
1225  std::string output;
1226 
1227  if( aNestLevel == 0 )
1228  output += ' ';
1229 
1230  output += "(layers";
1231 
1232  static const LSET cu_all( LSET::AllCuMask() );
1233  static const LSET fr_bk( 2, B_Cu, F_Cu );
1234  static const LSET adhes( 2, B_Adhes, F_Adhes );
1235  static const LSET paste( 2, B_Paste, F_Paste );
1236  static const LSET silks( 2, B_SilkS, F_SilkS );
1237  static const LSET mask( 2, B_Mask, F_Mask );
1238  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1239  static const LSET fab( 2, B_Fab, F_Fab );
1240 
1241  LSET cu_mask = cu_all;
1242 
1243  // output copper layers first, then non copper
1244 
1245  if( ( aLayerMask & cu_mask ) == cu_mask )
1246  {
1247  output += " *.Cu";
1248  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1249  }
1250  else if( ( aLayerMask & cu_mask ) == fr_bk )
1251  {
1252  output += " F&B.Cu";
1253  aLayerMask &= ~fr_bk;
1254  }
1255 
1256  if( ( aLayerMask & adhes ) == adhes )
1257  {
1258  output += " *.Adhes";
1259  aLayerMask &= ~adhes;
1260  }
1261 
1262  if( ( aLayerMask & paste ) == paste )
1263  {
1264  output += " *.Paste";
1265  aLayerMask &= ~paste;
1266  }
1267 
1268  if( ( aLayerMask & silks ) == silks )
1269  {
1270  output += " *.SilkS";
1271  aLayerMask &= ~silks;
1272  }
1273 
1274  if( ( aLayerMask & mask ) == mask )
1275  {
1276  output += " *.Mask";
1277  aLayerMask &= ~mask;
1278  }
1279 
1280  if( ( aLayerMask & crt_yd ) == crt_yd )
1281  {
1282  output += " *.CrtYd";
1283  aLayerMask &= ~crt_yd;
1284  }
1285 
1286  if( ( aLayerMask & fab ) == fab )
1287  {
1288  output += " *.Fab";
1289  aLayerMask &= ~fab;
1290  }
1291 
1292  // output any individual layers not handled in wildcard combos above
1293 
1294  wxString layerName;
1295 
1296  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1297  {
1298  if( aLayerMask[layer] )
1299  {
1300  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1301  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1302 
1303  else // I am being called from FootprintSave()
1304  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1305 
1306  output += ' ';
1307  output += m_out->Quotew( layerName );
1308  }
1309  }
1310 
1311  m_out->Print( aNestLevel, "%s)", output.c_str() );
1312 }
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:712
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.
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:640

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

745 {
746  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
747  for( NETINFO_ITEM* net : *m_mapping )
748  {
749  m_out->Print( aNestLevel, "(net %d %s)\n",
750  m_mapping->Translate( net->GetNet() ),
751  m_out->Quotew( net->GetNetname() ).c_str() );
752  }
753 
754  m_out->Print( 0, "\n" );
755 
756  // Save the default net class first.
757  NETCLASS defaultNC = *dsnSettings.GetDefault();
758  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
759  defaultNC.Format( m_out, aNestLevel, m_ctl );
760 
761  // Save the rest of the net classes alphabetically.
762  for( const auto& it : dsnSettings.m_NetClasses )
763  {
764  NETCLASS netclass = *it.second;
765  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
766  netclass.Format( m_out, aNestLevel, m_ctl );
767  }
768 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
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
NETCLASS * 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:255
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 475 of file kicad_plugin.cpp.

476 {
477  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
478 
479  // Setup
480  m_out->Print( aNestLevel, "(setup\n" );
481 
482  // Save the board physical stackup structure
484 
485  if( aBoard->GetDesignSettings().m_HasStackup )
486  stackup.FormatBoardStackup( m_out,aBoard, aNestLevel+1 );
487 
488  // Save current default track width, for compatibility with older Pcbnew version;
489  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
490  FormatInternalUnits( dsnSettings.GetCurrentTrackWidth() ).c_str() );
491 
492  // Save custom track widths list (the first is not saved here: it's the netclass value)
493  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
494  {
495  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
496  FormatInternalUnits( dsnSettings.m_TrackWidthList[ii] ).c_str() );
497  }
498 
499  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
500  FormatInternalUnits( dsnSettings.GetDefault()->GetClearance() ).c_str() );
501 
502  // ZONE_SETTINGS
503  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
504  FormatInternalUnits( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
505  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
506  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
507 
508  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
509  FormatInternalUnits( dsnSettings.m_TrackMinWidth ).c_str() );
510  m_out->Print( aNestLevel+1, "(clearance_min %s)\n",
511  FormatInternalUnits( dsnSettings.m_MinClearance ).c_str() );
512  m_out->Print( aNestLevel+1, "(via_min_annulus %s)\n",
513  FormatInternalUnits( dsnSettings.m_ViasMinAnnulus ).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, "(through_hole_min %s)\n",
517  FormatInternalUnits( dsnSettings.m_MinThroughDrill ).c_str() );
518  m_out->Print( aNestLevel+1, "(hole_to_hole_min %s)\n",
519  FormatInternalUnits( dsnSettings.m_HoleToHoleMin ).c_str() );
520 
521  // Save current default via size, for compatibility with older Pcbnew version;
522  m_out->Print( aNestLevel+1, "(via_size %s)\n",
523  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
524  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
525  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
526 
527  // Save custom via dimensions list (the first is not saved here: it's the netclass value)
528  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
529  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
530  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
531  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
532 
533  // Save custom diff-pair dimensions (the first is not saved here: it's the netclass value)
534  for( unsigned ii = 1; ii < dsnSettings.m_DiffPairDimensionsList.size(); ii++ )
535  {
536  m_out->Print( aNestLevel+1, "(user_diff_pair %s %s %s)\n",
537  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Width ).c_str(),
538  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Gap ).c_str(),
539  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_ViaGap ).c_str() );
540  }
541 
542  // for old versions compatibility:
543  if( dsnSettings.m_BlindBuriedViaAllowed )
544  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
545 
546  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
547  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
548  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
549  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
550  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
551  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
552  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
553  FormatInternalUnits( dsnSettings.m_MicroViasMinSize ).c_str() );
554  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
555  FormatInternalUnits( dsnSettings.m_MicroViasMinDrill ).c_str() );
556 
557  m_out->Print( aNestLevel+1, "(max_error %s)\n",
558  FormatInternalUnits( dsnSettings.m_MaxError ).c_str() );
559 
560  // Store this option only if it is not the legacy option:
561  if( dsnSettings.m_ZoneUseNoOutlineInFill )
562  m_out->Print( aNestLevel+1, "(filled_areas_thickness no)\n" );
563 
564  formatDefaults( dsnSettings, aNestLevel+1 );
565 
566  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
567  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
568  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
569  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
570  FormatInternalUnits( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
571 
572  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
573  FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
574 
575  if( dsnSettings.m_SolderMaskMinWidth )
576  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
577  FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
578 
579  if( dsnSettings.m_SolderPasteMargin != 0 )
580  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
581  FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
582 
583  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
584  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
585  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
586 
587  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
588  FormatInternalUnits( aBoard->GetAuxOrigin().x ).c_str(),
589  FormatInternalUnits( aBoard->GetAuxOrigin().y ).c_str() );
590 
591  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
592  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
593  FormatInternalUnits( aBoard->GetGridOrigin().x ).c_str(),
594  FormatInternalUnits( aBoard->GetGridOrigin().y ).c_str() );
595 
596  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
597  dsnSettings.GetVisibleElements() );
598 
599  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
600 
601  m_out->Print( aNestLevel, ")\n\n" );
602 }
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:560
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:542
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
BOARD_STACKUP & GetStackupDescriptor()
int GetViaDrill() const
Definition: netclass.h:171
int m_ZoneClearance
Minimal clearance value.
Definition: zone_settings.h:74
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
int GetuViaDiameter() const
Definition: netclass.h:174
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:364
const wxPoint & GetGridOrigin() const
Definition: class_board.h:371
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.
bool m_ZoneUseNoOutlineInFill
Option to handle filled polygons in zones: the "legacy" option is using thick outlines around filled ...
int GetClearance() const
Definition: netclass.h:162
const wxSize & GetDrillSize() const
Definition: class_pad.h:291
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
NETCLASS * GetDefault() const
Function GetDefault.
int GetViaDiameter() const
Definition: netclass.h:168
std::vector< VIA_DIMENSION > m_ViasDimensionsList
int GetuViaDrill() const
Definition: netclass.h:177
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 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:285
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:531
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(), NETCLASS::GetClearance(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), D_PAD::GetDrillSize(), BOARD::GetGridOrigin(), BOARD::GetPlotOptions(), D_PAD::GetSize(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), NETCLASS::GetuViaDiameter(), NETCLASS::GetuViaDrill(), NETCLASS::GetViaDiameter(), NETCLASS::GetViaDrill(), 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_HoleToHoleMin, BOARD_DESIGN_SETTINGS::m_MaxError, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_MinClearance, BOARD_DESIGN_SETTINGS::m_MinThroughDrill, 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_ViasMinAnnulus, 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 2186 of file kicad_plugin.cpp.

2189 {
2190  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2191 }
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 115 of file pcbnew/kicad_plugin.h.

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

◆ getFootprint()

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

Definition at line 2157 of file kicad_plugin.cpp.

2161 {
2162  LOCALE_IO toggle; // toggles on, then off, the C locale.
2163 
2164  init( aProperties );
2165 
2166  try
2167  {
2168  validateCache( aLibraryPath, checkModified );
2169  }
2170  catch( const IO_ERROR& )
2171  {
2172  // do nothing with the error
2173  }
2174 
2175  const MODULE_MAP& mods = m_cache->GetModules();
2176 
2177  MODULE_CITER it = mods.find( aFootprintName );
2178 
2179  if( it == mods.end() )
2180  return nullptr;
2181 
2182  return it->second->GetModule();
2183 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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 2342 of file kicad_plugin.cpp.

2343 {
2344  return FP_CACHE::GetTimestamp( aLibraryPath );
2345 }
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 173 of file pcbnew/kicad_plugin.h.

174  {
175  std::string ret = m_sf.GetString();
176  if( doClear )
177  m_sf.Clear();
178 
179  return ret;
180  }
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 2107 of file kicad_plugin.cpp.

2108 {
2109  m_board = NULL;
2110  m_reader = NULL;
2112  m_props = aProperties;
2113 }
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 2441 of file kicad_plugin.cpp.

2442 {
2443  LOCALE_IO toggle;
2444 
2445  init( NULL );
2446 
2447  validateCache( aLibraryPath );
2448 
2449  return m_cache->IsWritable();
2450 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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 2063 of file kicad_plugin.cpp.

2064 {
2065  FILE_LINE_READER reader( aFileName );
2066 
2067  init( aProperties );
2068 
2069  m_parser->SetLineReader( &reader );
2070  m_parser->SetBoard( aAppendToMe );
2071 
2072  BOARD* board;
2073 
2074  try
2075  {
2076  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2077  }
2078  catch( const FUTURE_FORMAT_ERROR& )
2079  {
2080  // Don't wrap a FUTURE_FORMAT_ERROR in another
2081  throw;
2082  }
2083  catch( const PARSE_ERROR& parse_error )
2084  {
2085  if( m_parser->IsTooRecent() )
2086  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2087  else
2088  throw;
2089  }
2090 
2091  if( !board )
2092  {
2093  // The parser loaded something that was valid, but wasn't a board.
2094  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
2095  m_parser->CurSource(), m_parser->CurLine(),
2096  m_parser->CurLineNumber(), m_parser->CurOffset() );
2097  }
2098 
2099  // Give the filename to the board if it's new
2100  if( !aAppendToMe )
2101  board->SetFileName( aFileName );
2102 
2103  return board;
2104 }
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:208
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:342
void SetFileName(const wxString &aFileName)
Definition: class_board.h:243
PCB_PARSER * m_parser
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:335
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:360
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:181
#define _(s)
Definition: 3d_actions.cpp:33
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 380 of file kicad_plugin.cpp.

381 {
382  std::string input = TO_UTF8( aClipboardSourceInput );
383 
384  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
385 
386  m_parser->SetLineReader( &reader );
387 
388  try
389  {
390  return m_parser->Parse();
391  }
392  catch( const PARSE_ERROR& parse_error )
393  {
394  if( m_parser->IsTooRecent() )
395  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
396  else
397  throw;
398  }
399 }
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:208
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:335
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:360
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
#define TO_UTF8(wxstring)
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 110 of file pcbnew/kicad_plugin.h.

111  {
112  return wxT( "KiCad" );
113  }

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

357 {
358  LOCALE_IO toggle; // toggles on, then off, the C locale.
359 
360  init( aProperties );
361 
362  m_board = aBoard; // after init()
363 
364  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
365  m_mapping->SetBoard( aBoard );
366 
367  FILE_OUTPUTFORMATTER formatter( aFileName );
368 
369  m_out = &formatter; // no ownership
370 
371  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
372  formatter.Quotew( GetBuildVersion() ).c_str() );
373 
374  Format( aBoard, 1 );
375 
376  m_out->Print( 0, ")\n" );
377 }
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:214
void init(const PROPERTIES *aProperties)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:281
wxString GetBuildVersion()
Get the full KiCad 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 182 of file pcbnew/kicad_plugin.h.

182 { 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 2116 of file kicad_plugin.cpp.

2117 {
2118  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2119  {
2120  // a spectacular episode in memory management:
2121  delete m_cache;
2122  m_cache = new FP_CACHE( this, aLibraryPath );
2123  m_cache->Load();
2124  }
2125 }
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 104 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 188 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 196 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 198 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 204 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 192 of file pcbnew/kicad_plugin.h.

Referenced by init().

◆ m_reader

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

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

Referenced by init().

◆ m_sf

STRING_FORMATTER PCB_IO::m_sf
protected

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

Referenced by GetStringOutput(), and PCB_IO().


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