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...
 
BOARDDoLoad (LINE_READER &aReader, BOARD *aAppendToMe, const PROPERTIES *aProperties)
 
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
 Output 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 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 formatProperties (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 (FP_SHAPE *aModuleDrawing, int aNestLevel=0) const
 
void format (PCB_GROUP *aGroup, int aNestLevel=0) const
 
void format (PCB_SHAPE *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 (PCB_TEXT *aText, int aNestLevel=0) const
 
void format (FP_TEXT *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 125 of file pcbnew/plugins/kicad/kicad_plugin.h.

Constructor & Destructor Documentation

◆ PCB_IO()

PCB_IO::PCB_IO ( int  aControlFlags = CTL_FOR_BOARD)

Definition at line 2036 of file kicad_plugin.cpp.

2036  :
2037  m_cache( 0 ),
2038  m_ctl( aControlFlags ),
2039  m_parser( new PCB_PARSER() ),
2040  m_mapping( new NETINFO_MAPPING() )
2041 {
2042  init( 0 );
2043  m_out = &m_sf;
2044 }
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:70
void init(const PROPERTIES *aProperties)
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes

References init(), m_out, and m_sf.

◆ ~PCB_IO()

PCB_IO::~PCB_IO ( )

Definition at line 2047 of file kicad_plugin.cpp.

2048 {
2049  delete m_cache;
2050  delete m_parser;
2051  delete m_mapping;
2052 }
FP_CACHE * m_cache
Footprint library cache.
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

◆ DoLoad()

BOARD * PCB_IO::DoLoad ( LINE_READER aReader,
BOARD aAppendToMe,
const PROPERTIES aProperties 
)

Definition at line 2069 of file kicad_plugin.cpp.

2070 {
2071  init( aProperties );
2072 
2073  m_parser->SetLineReader( &aReader );
2074  m_parser->SetBoard( aAppendToMe );
2075 
2076  BOARD* board;
2077 
2078  try
2079  {
2080  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2081  }
2082  catch( const FUTURE_FORMAT_ERROR& )
2083  {
2084  // Don't wrap a FUTURE_FORMAT_ERROR in another
2085  throw;
2086  }
2087  catch( const PARSE_ERROR& parse_error )
2088  {
2089  if( m_parser->IsTooRecent() )
2090  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2091  else
2092  throw;
2093  }
2094 
2095  if( !board )
2096  {
2097  // The parser loaded something that was valid, but wasn't a board.
2098  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
2099  m_parser->CurSource(), m_parser->CurLine(),
2100  m_parser->CurLineNumber(), m_parser->CurOffset() );
2101  }
2102 
2103  return board;
2104 }
void init(const PROPERTIES *aProperties)
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:197
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:171
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:374
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:485
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:367
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:395
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#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:181

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

Referenced by PANEL_PCBNEW_COLOR_SETTINGS::createPreviewItems(), and Load().

◆ 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: locale_io.h:40
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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: locale_io.h:40
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
MODULE_MAP::const_iterator MODULE_CITER
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
MODULE_MAP & GetModules()

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 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Save(MODULE *aModule=NULL)
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:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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
Check if aPath is the same as the current cache path.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

142 {
143  // disable all these in another couple of months, after everyone has seen them:
144 #if 1
145  (*aListToAppendTo)["debug_level"] = UTF8( _(
146  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
147  ));
148 
149  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
150  "Regular expression <b>footprint name</b> filter."
151  ));
152 
153  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
154  "Enable transaction logging. The mere presence of this option turns on the "
155  "logging, no need to set a Value."
156  ));
157 
158  (*aListToAppendTo)["username"] = UTF8( _(
159  "User name for <b>login</b> to some special library server."
160  ));
161 
162  (*aListToAppendTo)["password"] = UTF8( _(
163  "Password for <b>login</b> to some special library server."
164  ));
165 #endif
166 
167 #if 1
168  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
169  // if and when implemented.
170  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
171  "Enter the python module which implements the PLUGIN::Footprint*() functions."
172  ));
173 #endif
174 }
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 }
BOARD_ITEM * Duplicate() const override
Function Duplicate creates a copy of a BOARD_ITEM.
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References MODULE::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  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->Clone() );
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: locale_io.h:40
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
MODULE_MAP::const_iterator MODULE_CITER
const LIB_ID & GetFPID() const
Definition: class_module.h:210
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:185
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
#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.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Helper class for creating a footprint library cache.
void Save(MODULE *aModule=NULL)
Save the footprint cache or a single module from it to disk.
void SetOrientation(double aNewAngle)
bool IsWritable() const
WX_FILENAME - A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: wx_filename.h:36
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:201
#define _(s)
Definition: 3d_actions.cpp:33
wxPoint GetPosition() const override
Definition: class_module.h:201
bool Exists() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
MODULE_MAP & GetModules()

References _, MODULE::Clone(), CTL_FOR_LIBRARY, FP_CACHE::Exists(), F_Cu, MODULE::Flip(), Format(), 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

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

386 {
387  LOCALE_IO toggle; // public API function, perform anything convenient for caller
388 
389  switch( aItem->Type() )
390  {
391  case PCB_T:
392  format( static_cast<BOARD*>( aItem ), aNestLevel );
393  break;
394 
395  case PCB_DIM_ALIGNED_T:
396  case PCB_DIM_CENTER_T:
398  case PCB_DIM_LEADER_T:
399  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
400  break;
401 
402  case PCB_SHAPE_T:
403  format( static_cast<PCB_SHAPE*>( aItem ), aNestLevel );
404  break;
405 
406  case PCB_FP_SHAPE_T:
407  format( static_cast<FP_SHAPE*>( aItem ), aNestLevel );
408  break;
409 
410  case PCB_TARGET_T:
411  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
412  break;
413 
414  case PCB_MODULE_T:
415  format( static_cast<MODULE*>( aItem ), aNestLevel );
416  break;
417 
418  case PCB_PAD_T:
419  format( static_cast<D_PAD*>( aItem ), aNestLevel );
420  break;
421 
422  case PCB_TEXT_T:
423  format( static_cast<PCB_TEXT*>( aItem ), aNestLevel );
424  break;
425 
426  case PCB_FP_TEXT_T:
427  format( static_cast<FP_TEXT*>( aItem ), aNestLevel );
428  break;
429 
430  case PCB_GROUP_T:
431  format( static_cast<PCB_GROUP*>( aItem ), aNestLevel );
432  break;
433 
434  case PCB_TRACE_T:
435  case PCB_ARC_T:
436  case PCB_VIA_T:
437  format( static_cast<TRACK*>( aItem ), aNestLevel );
438  break;
439 
440  case PCB_FP_ZONE_AREA_T:
441  case PCB_ZONE_AREA_T:
442  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
443  break;
444 
445  default:
446  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
447  }
448 }
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
Definition: typeinfo.h:85
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class MODULE, a footprint
Definition: typeinfo.h:89
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182

References format(), EDA_ITEM::GetClass(), PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_AREA_T, PCB_GROUP_T, PCB_MODULE_T, PCB_PAD_T, PCB_SHAPE_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(), FP_CACHE::Save(), Save(), and CLIPBOARD_IO::SaveSelection().

◆ format() [1/12]

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

Definition at line 620 of file kicad_plugin.cpp.

621 {
622  std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_modules( aBoard->Modules().begin(),
623  aBoard->Modules().end() );
624  std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_drawings( aBoard->Drawings().begin(),
625  aBoard->Drawings().end() );
626  std::set<TRACK*, TRACK::cmp_tracks> sorted_tracks( aBoard->Tracks().begin(),
627  aBoard->Tracks().end() );
628  std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aBoard->Zones().begin(),
629  aBoard->Zones().end() );
630  std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(),
631  aBoard->Groups().end() );
632 
633  formatHeader( aBoard, aNestLevel );
634 
635  // Save the footprints.
636  for( BOARD_ITEM* module : sorted_modules )
637  {
638  Format( module, aNestLevel );
639  m_out->Print( 0, "\n" );
640  }
641 
642  // Save the graphical items on the board (not owned by a module)
643  for( BOARD_ITEM* item : sorted_drawings )
644  Format( item, aNestLevel );
645 
646  if( sorted_drawings.size() )
647  m_out->Print( 0, "\n" );
648 
649  // Do not save MARKER_PCBs, they can be regenerated easily.
650 
651  // Save the tracks and vias.
652  for( TRACK* track : sorted_tracks )
653  Format( track, aNestLevel );
654 
655  if( sorted_tracks.size() )
656  m_out->Print( 0, "\n" );
657 
658  // Save the polygon (which are the newer technology) zones.
659  for( auto zone : sorted_zones )
660  Format( zone, aNestLevel );
661 
662  // Save the groups
663  for( BOARD_ITEM* group : sorted_groups )
664  Format( group, aNestLevel );
665 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: class_board.h:303
MODULES & Modules()
Definition: class_board.h:284
ZONE_CONTAINERS & Zones()
Definition: class_board.h:290
void formatHeader(BOARD *aBoard, int aNestLevel=0) const
writes everything that comes before the board_items, like settings and layers etc
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
DRAWINGS & Drawings()
Definition: class_board.h:287
TRACKS & Tracks()
Definition: class_board.h:281

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

Referenced by Format().

◆ format() [2/12]

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

Definition at line 668 of file kicad_plugin.cpp.

669 {
670  ALIGNED_DIMENSION* aligned = dynamic_cast<ALIGNED_DIMENSION*>( aDimension );
671  ORTHOGONAL_DIMENSION* ortho = dynamic_cast<ORTHOGONAL_DIMENSION*>( aDimension );
672  CENTER_DIMENSION* center = dynamic_cast<CENTER_DIMENSION*>( aDimension );
673  LEADER* leader = dynamic_cast<LEADER*>( aDimension );
674 
675  m_out->Print( aNestLevel, "(dimension" );
676 
677  if( aDimension->Type() == PCB_DIM_ALIGNED_T )
678  m_out->Print( 0, " (type aligned)" );
679  else if( aDimension->Type() == PCB_DIM_LEADER_T )
680  m_out->Print( 0, " (type leader)" );
681  else if( aDimension->Type() == PCB_DIM_CENTER_T )
682  m_out->Print( 0, " (type center)" );
683  else if( aDimension->Type() == PCB_DIM_ORTHOGONAL_T )
684  m_out->Print( 0, " (type orthogonal)" );
685  else
686  wxFAIL_MSG( wxT( "Cannot format unknown dimension type!" ) );
687 
688  formatLayer( aDimension );
689 
690  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aDimension->m_Uuid.AsString() ) );
691 
692  m_out->Print( 0, "\n" );
693 
694  m_out->Print( aNestLevel+1, "(pts (xy %s %s) (xy %s %s))\n",
695  FormatInternalUnits( aDimension->GetStart().x ).c_str(),
696  FormatInternalUnits( aDimension->GetStart().y ).c_str(),
697  FormatInternalUnits( aDimension->GetEnd().x ).c_str(),
698  FormatInternalUnits( aDimension->GetEnd().y ).c_str() );
699 
700  if( aligned )
701  m_out->Print( aNestLevel+1, "(height %s)\n",
702  FormatInternalUnits( aligned->GetHeight() ).c_str() );
703 
704  if( ortho )
705  m_out->Print( aNestLevel+1, "(orientation %d)\n",
706  static_cast<int>( ortho->GetOrientation() ) );
707 
708  if( !center )
709  {
710  Format( &aDimension->Text(), aNestLevel + 1 );
711 
712  m_out->Print( aNestLevel + 1, "(format" );
713 
714  if( !aDimension->GetPrefix().IsEmpty() )
715  m_out->Print( 0, " (prefix \"%s\")", TO_UTF8( aDimension->GetPrefix() ) );
716 
717  if( !aDimension->GetSuffix().IsEmpty() )
718  m_out->Print( 0, " (suffix \"%s\")", TO_UTF8( aDimension->GetSuffix() ) );
719 
720  m_out->Print( 0, " (units %d) (units_format %d) (precision %d)",
721  static_cast<int>( aDimension->GetUnitsMode() ),
722  static_cast<int>( aDimension->GetUnitsFormat() ), aDimension->GetPrecision() );
723 
724  if( aDimension->GetOverrideTextEnabled() )
725  m_out->Print( 0, " (override_value \"%s\")", TO_UTF8( aDimension->GetOverrideText() ) );
726 
727  if( aDimension->GetSuppressZeroes() )
728  m_out->Print( 0, " suppress_zeroes" );
729 
730  m_out->Print( 0, ")\n" );
731  }
732 
733  m_out->Print( aNestLevel+1, "(style (thickness %s) (arrow_length %s) (text_position_mode %d)",
734  FormatInternalUnits( aDimension->GetLineThickness() ).c_str(),
735  FormatInternalUnits( aDimension->GetArrowLength() ).c_str(),
736  static_cast<int>( aDimension->GetTextPositionMode() ) );
737 
738  if( aligned )
739  {
740  m_out->Print( 0, " (extension_height %s)",
741  FormatInternalUnits( aligned->GetExtensionHeight() ).c_str() );
742  }
743 
744  if( leader )
745  m_out->Print( 0, " (text_frame %d)", static_cast<int>( leader->GetTextFrame() ) );
746 
747  m_out->Print( 0, " (extension_offset %s)",
748  FormatInternalUnits( aDimension->GetExtensionOffset() ).c_str() );
749 
750  if( aDimension->GetKeepTextAligned() )
751  m_out->Print( 0, " keep_text_aligned" );
752 
753  m_out->Print( 0, ")\n" );
754 
755  m_out->Print( aNestLevel, ")\n" );
756 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
void formatLayer(const BOARD_ITEM *aItem) const
DIM_TEXT_FRAME GetTextFrame() const
DIM_TEXT_POSITION GetTextPositionMode() const
int GetPrecision() const
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
wxString AsString() const
Definition: kiid.cpp:174
virtual const wxPoint & GetEnd() const
DIM_UNITS_MODE GetUnitsMode() const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
int GetExtensionOffset() const
A leader is a dimension-like object pointing to a specific point.
int GetExtensionHeight() const
bool GetKeepTextAligned() const
int GetArrowLength() const
DIR GetOrientation() const
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
PCB_TEXT & Text()
DIM_UNITS_FORMAT GetUnitsFormat() const
bool GetSuppressZeroes() const
wxString GetOverrideText() const
wxString GetPrefix() const
const KIID m_Uuid
Definition: eda_item.h:151
int GetHeight() const
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
wxString GetSuffix() const
int GetLineThickness() const
bool GetOverrideTextEnabled() const
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
For better understanding of the points that make a dimension:
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
Marks the center of a circle or arc with a cross shape The size and orientation of the cross is adjus...

References KIID::AsString(), Format(), FormatInternalUnits(), formatLayer(), DIMENSION::GetArrowLength(), DIMENSION::GetEnd(), ALIGNED_DIMENSION::GetExtensionHeight(), DIMENSION::GetExtensionOffset(), ALIGNED_DIMENSION::GetHeight(), DIMENSION::GetKeepTextAligned(), DIMENSION::GetLineThickness(), ORTHOGONAL_DIMENSION::GetOrientation(), DIMENSION::GetOverrideText(), DIMENSION::GetOverrideTextEnabled(), DIMENSION::GetPrecision(), DIMENSION::GetPrefix(), DIMENSION::GetStart(), DIMENSION::GetSuffix(), DIMENSION::GetSuppressZeroes(), LEADER::GetTextFrame(), DIMENSION::GetTextPositionMode(), DIMENSION::GetUnitsFormat(), DIMENSION::GetUnitsMode(), m_out, EDA_ITEM::m_Uuid, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, OUTPUTFORMATTER::Print(), DIMENSION::Text(), TO_UTF8, and EDA_ITEM::Type().

◆ format() [3/12]

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

Definition at line 849 of file kicad_plugin.cpp.

850 {
851  switch( aModuleDrawing->GetShape() )
852  {
853  case S_SEGMENT: // Line
854  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
855  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
856  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
857  break;
858 
859  case S_RECT: // Rectangle
860  m_out->Print( aNestLevel, "(fp_rect (start %s) (end %s)",
861  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
862  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
863  break;
864 
865  case S_CIRCLE: // Circle
866  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
867  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
868  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
869  break;
870 
871  case S_ARC: // Arc
872  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
873  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
874  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str(),
875  FormatAngle( aModuleDrawing->GetAngle() ).c_str() );
876  break;
877 
878  case S_POLYGON: // Polygonal segment
879  if( aModuleDrawing->IsPolyShapeValid() )
880  {
881  SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
882  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
883  int pointsCount = outline.PointCount();
884 
885  m_out->Print( aNestLevel, "(fp_poly (pts" );
886 
887  for( int ii = 0; ii < pointsCount; ++ii )
888  {
889  int nestLevel = 0;
890 
891  if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts
892  {
893  nestLevel = aNestLevel + 1;
894  m_out->Print( 0, "\n" );
895  }
896 
897  m_out->Print( nestLevel, "%s(xy %s)",
898  nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
899  }
900 
901  m_out->Print( 0, ")" );
902  }
903  else
904  {
905  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
906  return;
907  }
908  break;
909 
910  case S_CURVE: // Bezier curve
911  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
912  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
913  FormatInternalUnits( aModuleDrawing->GetBezier0_C1() ).c_str(),
914  FormatInternalUnits( aModuleDrawing->GetBezier0_C2() ).c_str(),
915  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
916  break;
917 
918  default:
919  wxFAIL_MSG( "PCB_IO::format cannot format unknown FP_SHAPE shape:"
920  + PCB_SHAPE_TYPE_T_asString( aModuleDrawing->GetShape()) );
921  return;
922  };
923 
924  formatLayer( aModuleDrawing );
925 
926  m_out->Print( 0, " (width %s)", FormatInternalUnits( aModuleDrawing->GetWidth() ).c_str() );
927 
928  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aModuleDrawing->m_Uuid.AsString() ) );
929 
930  m_out->Print( 0, ")\n" );
931 }
bool IsPolyShapeValid() const
Definition: pcb_shape.cpp:1196
usual segment : line with rounded ends
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
SHAPE_POLY_SET & GetPolyShape()
Definition: pcb_shape.h:243
int GetWidth() const
Definition: pcb_shape.h:100
const wxPoint & GetStart0() const
Definition: fp_shape.h:106
Bezier Curve.
wxString AsString() const
Definition: kiid.cpp:174
Arcs (with rounded ends)
int PointCount() const
Function PointCount()
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
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:557
segment with non rounded ends
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
const KIID m_Uuid
Definition: eda_item.h:151
const wxPoint & GetBezier0_C2() const
Definition: fp_shape.h:118
const wxPoint & GetBezier0_C1() const
Definition: fp_shape.h:115
polygon (not yet used for tracks, but could be in microwave apps)
SHAPE_LINE_CHAIN.
double GetAngle() const
Definition: pcb_shape.h:108
const wxPoint & GetEnd0() const
Definition: fp_shape.h:109
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
PCB_SHAPE_TYPE_T GetShape() const
Definition: pcb_shape.h:114
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
static wxString PCB_SHAPE_TYPE_T_asString(PCB_SHAPE_TYPE_T a)

References KIID::AsString(), SHAPE_LINE_CHAIN::CPoint(), FormatAngle(), FormatInternalUnits(), formatLayer(), PCB_SHAPE::GetAngle(), FP_SHAPE::GetBezier0_C1(), FP_SHAPE::GetBezier0_C2(), ADVANCED_CFG::GetCfg(), FP_SHAPE::GetEnd0(), PCB_SHAPE::GetPolyShape(), PCB_SHAPE::GetShape(), FP_SHAPE::GetStart0(), PCB_SHAPE::GetWidth(), PCB_SHAPE::IsPolyShapeValid(), m_out, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), PCB_SHAPE_TYPE_T_asString(), SHAPE_LINE_CHAIN::PointCount(), OUTPUTFORMATTER::Print(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, S_RECT, S_SEGMENT, and TO_UTF8.

◆ format() [4/12]

void PCB_IO::format ( PCB_GROUP aGroup,
int  aNestLevel = 0 
) const
private

Definition at line 1558 of file kicad_plugin.cpp.

1559 {
1560  // Don't write empty groups
1561  if( aGroup->GetItems().empty() )
1562  return;
1563 
1564  m_out->Print( aNestLevel, "(group %s (id %s)\n",
1565  m_out->Quotew( aGroup->GetName() ).c_str(),
1566  TO_UTF8( aGroup->m_Uuid.AsString() ) );
1567 
1568  m_out->Print( aNestLevel + 1, "(members\n" );
1569 
1570  wxArrayString memberIds;
1571 
1572  for( BOARD_ITEM* member : aGroup->GetItems() )
1573  memberIds.Add( member->m_Uuid.AsString() );
1574 
1575  memberIds.Sort();
1576 
1577  for( const wxString& memberId : memberIds )
1578  m_out->Print( aNestLevel + 2, "%s\n", TO_UTF8( memberId ) );
1579 
1580  m_out->Print( 0, " )\n" );
1581  m_out->Print( aNestLevel, ")\n" );
1582 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxString AsString() const
Definition: kiid.cpp:174
const std::unordered_set< BOARD_ITEM * > & GetItems() const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
wxString GetName() const
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
const KIID m_Uuid
Definition: eda_item.h:151
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References KIID::AsString(), PCB_GROUP::GetItems(), PCB_GROUP::GetName(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and TO_UTF8.

◆ format() [5/12]

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

Definition at line 759 of file kicad_plugin.cpp.

760 {
761  switch( aShape->GetShape() )
762  {
763  case S_SEGMENT: // Line
764  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
765  FormatInternalUnits( aShape->GetStart() ).c_str(),
766  FormatInternalUnits( aShape->GetEnd() ).c_str() );
767 
768  if( aShape->GetAngle() != 0.0 )
769  m_out->Print( 0, " (angle %s)", FormatAngle( aShape->GetAngle() ).c_str() );
770 
771  break;
772 
773  case S_RECT: // Rectangle
774  m_out->Print( aNestLevel, "(gr_rect (start %s) (end %s)",
775  FormatInternalUnits( aShape->GetStart() ).c_str(),
776  FormatInternalUnits( aShape->GetEnd() ).c_str() );
777  break;
778 
779  case S_CIRCLE: // Circle
780  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
781  FormatInternalUnits( aShape->GetStart() ).c_str(),
782  FormatInternalUnits( aShape->GetEnd() ).c_str() );
783  break;
784 
785  case S_ARC: // Arc
786  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
787  FormatInternalUnits( aShape->GetStart() ).c_str(),
788  FormatInternalUnits( aShape->GetEnd() ).c_str(),
789  FormatAngle( aShape->GetAngle() ).c_str() );
790  break;
791 
792  case S_POLYGON: // Polygon
793  if( aShape->IsPolyShapeValid() )
794  {
795  SHAPE_POLY_SET& poly = aShape->GetPolyShape();
796  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
797  int pointsCount = outline.PointCount();
798 
799  m_out->Print( aNestLevel, "(gr_poly (pts\n" );
800 
801  for( int ii = 0; ii < pointsCount; ++ii )
802  {
803  int nestLevel = 0;
804 
805  if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts
806  {
807  nestLevel = aNestLevel + 1;
808  m_out->Print( 0, "\n" );
809  }
810 
811  m_out->Print( nestLevel, "%s(xy %s)",
812  nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
813  }
814 
815  m_out->Print( 0, ")" );
816  }
817  else
818  {
819  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
820  return;
821  }
822 
823  break;
824 
825  case S_CURVE: // Bezier curve
826  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
827  FormatInternalUnits( aShape->GetStart() ).c_str(),
828  FormatInternalUnits( aShape->GetBezControl1() ).c_str(),
829  FormatInternalUnits( aShape->GetBezControl2() ).c_str(),
830  FormatInternalUnits( aShape->GetEnd() ).c_str() );
831  break;
832 
833  default:
834  wxFAIL_MSG( "PCB_IO::format cannot format unknown PCB_SHAPE shape:"
835  + PCB_SHAPE_TYPE_T_asString( aShape->GetShape()) );
836  return;
837  };
838 
839  formatLayer( aShape );
840 
841  m_out->Print( 0, " (width %s)", FormatInternalUnits( aShape->GetWidth() ).c_str() );
842 
843  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aShape->m_Uuid.AsString() ) );
844 
845  m_out->Print( 0, ")\n" );
846 }
usual segment : line with rounded ends
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void formatLayer(const BOARD_ITEM *aItem) const
Bezier Curve.
Arcs (with rounded ends)
int PointCount() const
Function PointCount()
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
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:557
segment with non rounded ends
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
polygon (not yet used for tracks, but could be in microwave apps)
SHAPE_LINE_CHAIN.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
static wxString PCB_SHAPE_TYPE_T_asString(PCB_SHAPE_TYPE_T a)

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

◆ format() [6/12]

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

Definition at line 934 of file kicad_plugin.cpp.

935 {
936  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
937  ( aTarget->GetShape() ) ? "x" : "plus",
938  FormatInternalUnits( aTarget->GetPosition() ).c_str(),
939  FormatInternalUnits( aTarget->GetSize() ).c_str() );
940 
941  if( aTarget->GetWidth() != 0 )
942  m_out->Print( 0, " (width %s)", FormatInternalUnits( aTarget->GetWidth() ).c_str() );
943 
944  formatLayer( aTarget );
945 
946  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTarget->m_Uuid.AsString() ) );
947 
948  m_out->Print( 0, ")\n" );
949 }
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: kiid.cpp:174
wxPoint GetPosition() const override
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
int GetWidth() const
const KIID m_Uuid
Definition: eda_item.h:151
int GetShape() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

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() [7/12]

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

Definition at line 952 of file kicad_plugin.cpp.

953 {
954  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
955  {
956  const wxArrayString* initial_comments = aModule->GetInitialComments();
957 
958  if( initial_comments )
959  {
960  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
961  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
962 
963  m_out->Print( 0, "\n" ); // improve readability?
964  }
965  }
966 
967  if( m_ctl & CTL_OMIT_LIBNAME )
968  m_out->Print( aNestLevel, "(module %s",
969  m_out->Quotes( aModule->GetFPID().GetLibItemNameAndRev() ).c_str() );
970  else
971  m_out->Print( aNestLevel, "(module %s",
972  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
973 
974  if( aModule->IsLocked() )
975  m_out->Print( 0, " locked" );
976 
977  if( aModule->IsPlaced() )
978  m_out->Print( 0, " placed" );
979 
980  formatLayer( aModule );
981 
982  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
983 
984  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
985  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aModule->m_Uuid.AsString() ) );
986 
987  m_out->Print( 0, "\n" );
988 
989  if( !( m_ctl & CTL_OMIT_AT ) )
990  {
991  m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aModule->GetPosition() ).c_str() );
992 
993  if( aModule->GetOrientation() != 0.0 )
994  m_out->Print( 0, " %s", FormatAngle( aModule->GetOrientation() ).c_str() );
995 
996  m_out->Print( 0, ")\n" );
997  }
998 
999  if( !aModule->GetDescription().IsEmpty() )
1000  m_out->Print( aNestLevel+1, "(descr %s)\n",
1001  m_out->Quotew( aModule->GetDescription() ).c_str() );
1002 
1003  if( !aModule->GetKeywords().IsEmpty() )
1004  m_out->Print( aNestLevel+1, "(tags %s)\n",
1005  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1006 
1007  const std::map<wxString, wxString>& props = aModule->GetProperties();
1008 
1009  for( const std::pair<const wxString, wxString>& prop : props )
1010  {
1011  m_out->Print( aNestLevel+1, "(property %s %s)\n",
1012  m_out->Quotew( prop.first ).c_str(),
1013  m_out->Quotew( prop.second ).c_str() );
1014  }
1015 
1016  if( !( m_ctl & CTL_OMIT_PATH ) && !aModule->GetPath().empty() )
1017  m_out->Print( aNestLevel+1, "(path %s)\n",
1018  m_out->Quotew( aModule->GetPath().AsString() ).c_str() );
1019 
1020  if( aModule->GetPlacementCost90() != 0 )
1021  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1022 
1023  if( aModule->GetPlacementCost180() != 0 )
1024  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1025 
1026  if( aModule->GetLocalSolderMaskMargin() != 0 )
1027  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1028  FormatInternalUnits( aModule->GetLocalSolderMaskMargin() ).c_str() );
1029 
1030  if( aModule->GetLocalSolderPasteMargin() != 0 )
1031  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1032  FormatInternalUnits( aModule->GetLocalSolderPasteMargin() ).c_str() );
1033 
1034  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1035  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1036  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1037 
1038  if( aModule->GetLocalClearance() != 0 )
1039  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1040  FormatInternalUnits( aModule->GetLocalClearance() ).c_str() );
1041 
1042  if( aModule->GetZoneConnection() != ZONE_CONNECTION::INHERITED )
1043  m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
1044  static_cast<int>( aModule->GetZoneConnection() ) );
1045 
1046  if( aModule->GetThermalWidth() != 0 )
1047  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1048  FormatInternalUnits( aModule->GetThermalWidth() ).c_str() );
1049 
1050  if( aModule->GetThermalGap() != 0 )
1051  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1052  FormatInternalUnits( aModule->GetThermalGap() ).c_str() );
1053 
1054  // Attributes
1055  if( aModule->GetAttributes() )
1056  {
1057  m_out->Print( aNestLevel+1, "(attr" );
1058 
1059  if( aModule->GetAttributes() & MOD_SMD )
1060  m_out->Print( 0, " smd" );
1061 
1062  if( aModule->GetAttributes() & MOD_THROUGH_HOLE )
1063  m_out->Print( 0, " through_hole" );
1064 
1065  if( aModule->GetAttributes() & MOD_BOARD_ONLY )
1066  m_out->Print( 0, " board_only" );
1067 
1068  if( aModule->GetAttributes() & MOD_EXCLUDE_FROM_POS_FILES )
1069  m_out->Print( 0, " exclude_from_pos_files" );
1070 
1071  if( aModule->GetAttributes() & MOD_EXCLUDE_FROM_BOM )
1072  m_out->Print( 0, " exclude_from_bom" );
1073 
1074  m_out->Print( 0, ")\n" );
1075  }
1076 
1077  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1078  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1079 
1080  std::set<D_PAD*, MODULE::cmp_pads> sorted_pads( aModule->Pads().begin(),
1081  aModule->Pads().end() );
1082  std::set<BOARD_ITEM*, MODULE::cmp_drawings> sorted_drawings( aModule->GraphicalItems().begin(),
1083  aModule->GraphicalItems().end() );
1084  std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aModule->Zones().begin(),
1085  aModule->Zones().end() );
1086  std::set<BOARD_ITEM*, PCB_GROUP::ptr_cmp> sorted_groups( aModule->Groups().begin(),
1087  aModule->Groups().end() );
1088 
1089  // Save drawing elements.
1090 
1091  for( BOARD_ITEM* gr : sorted_drawings )
1092  Format( gr, aNestLevel+1 );
1093 
1094  // Save pads.
1095  for( D_PAD* pad : sorted_pads )
1096  Format( pad, aNestLevel+1 );
1097 
1098  // Save zones.
1099  for( BOARD_ITEM* zone : sorted_zones )
1100  Format( zone, aNestLevel + 1 );
1101 
1102  // Save groups.
1103  for( BOARD_ITEM* group : sorted_groups )
1104  Format( group, aNestLevel + 1 );
1105 
1106  // Save 3D info.
1107  auto bs3D = aModule->Models().begin();
1108  auto es3D = aModule->Models().end();
1109 
1110  while( bs3D != es3D )
1111  {
1112  if( !bs3D->m_Filename.IsEmpty() )
1113  {
1114  m_out->Print( aNestLevel+1, "(model %s%s\n",
1115  m_out->Quotew( bs3D->m_Filename ).c_str(),
1116  bs3D->m_Show ? "" : " hide" );
1117 
1118  if( bs3D->m_Opacity != 1.0 )
1119  m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
1120 
1121  m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
1122  Double2Str( bs3D->m_Offset.x ).c_str(),
1123  Double2Str( bs3D->m_Offset.y ).c_str(),
1124  Double2Str( bs3D->m_Offset.z ).c_str() );
1125 
1126  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1127  Double2Str( bs3D->m_Scale.x ).c_str(),
1128  Double2Str( bs3D->m_Scale.y ).c_str(),
1129  Double2Str( bs3D->m_Scale.z ).c_str() );
1130 
1131  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1132  Double2Str( bs3D->m_Rotation.x ).c_str(),
1133  Double2Str( bs3D->m_Rotation.y ).c_str(),
1134  Double2Str( bs3D->m_Rotation.z ).c_str() );
1135 
1136  m_out->Print( aNestLevel+1, ")\n" );
1137  }
1138  ++bs3D;
1139  }
1140 
1141  m_out->Print( aNestLevel, ")\n" );
1142 }
timestamp_t GetLastEditTime() const
Definition: class_module.h:341
int GetAttributes() const
Definition: class_module.h:251
double GetOrientation() const
Definition: class_module.h:206
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetPlacementCost90() const
Definition: class_module.h:557
void formatLayer(const BOARD_ITEM *aItem) const
#define CTL_OMIT_AT
Omit position and rotation.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
FP_TEXT & Value()
read/write accessors:
Definition: class_module.h:475
bool IsPlaced() const
Definition: class_module.h:311
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:243
PADS & Pads()
Definition: class_module.h:182
#define CTL_OMIT_INITIAL_COMMENTS
omit MODULE initial comments
wxString AsString() const
Definition: kiid.cpp:174
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
const LIB_ID & GetFPID() const
Definition: class_module.h:210
const KIID_PATH & GetPath() const
Definition: class_module.h:219
DRAWINGS & GraphicalItems()
Definition: class_module.h:185
int GetLocalSolderMaskMargin() const
Definition: class_module.h:222
FP_TEXT & Reference()
Definition: class_module.h:476
UTF8 GetLibItemNameAndRev() const
Definition: lib_id.cpp:259
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
int GetLocalClearance() const
Definition: class_module.h:225
#define CTL_OMIT_LIBNAME
Omit lib alias when saving (used for board/not library)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
MODULE_GROUPS & Groups()
Definition: class_module.h:191
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership.
Definition: class_module.h:662
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:293
const wxString & GetKeywords() const
Definition: class_module.h:216
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:236
const KIID m_Uuid
Definition: eda_item.h:151
int GetPlacementCost180() const
Definition: class_module.h:554
virtual std::string Quotes(const std::string &aWrapee)
Function Quotes checks aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:437
const wxString & GetDescription() const
Definition: class_module.h:213
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:239
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:196
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
wxString AsString() const
Definition: kiid.cpp:206
const std::map< wxString, wxString > & GetProperties() const
Definition: class_module.h:482
MODULE_ZONE_CONTAINERS & Zones()
Definition: class_module.h:188
wxPoint GetPosition() const override
Definition: class_module.h:201
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
int GetThermalWidth() const
Definition: class_module.h:246
int GetThermalGap() const
Definition: class_module.h:249
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

References KIID::AsString(), KIID_PATH::AsString(), CTL_OMIT_AT, CTL_OMIT_INITIAL_COMMENTS, CTL_OMIT_LIBNAME, CTL_OMIT_PATH, CTL_OMIT_TSTAMPS, Double2Str(), LIB_ID::Format(), Format(), FormatAngle(), FormatInternalUnits(), formatLayer(), MODULE::GetAttributes(), MODULE::GetDescription(), MODULE::GetFPID(), MODULE::GetInitialComments(), MODULE::GetKeywords(), MODULE::GetLastEditTime(), LIB_ID::GetLibItemNameAndRev(), MODULE::GetLocalClearance(), MODULE::GetLocalSolderMaskMargin(), MODULE::GetLocalSolderPasteMargin(), MODULE::GetLocalSolderPasteMarginRatio(), MODULE::GetOrientation(), MODULE::GetPath(), MODULE::GetPlacementCost180(), MODULE::GetPlacementCost90(), MODULE::GetPosition(), MODULE::GetProperties(), MODULE::GetThermalGap(), MODULE::GetThermalWidth(), MODULE::GetZoneConnection(), MODULE::GraphicalItems(), MODULE::Groups(), INHERITED, MODULE::IsLocked(), MODULE::IsPlaced(), m_ctl, m_out, EDA_ITEM::m_Uuid, MOD_BOARD_ONLY, MOD_EXCLUDE_FROM_BOM, MOD_EXCLUDE_FROM_POS_FILES, MOD_SMD, MOD_THROUGH_HOLE, MODULE::Models(), MODULE::Pads(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotes(), OUTPUTFORMATTER::Quotew(), MODULE::Reference(), TO_UTF8, MODULE::Value(), and MODULE::Zones().

◆ format() [8/12]

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

Definition at line 1232 of file kicad_plugin.cpp.

1233 {
1234  const char* shape;
1235 
1236  switch( aPad->GetShape() )
1237  {
1238  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1239  case PAD_SHAPE_RECT: shape = "rect"; break;
1240  case PAD_SHAPE_OVAL: shape = "oval"; break;
1241  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1243  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1244  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1245 
1246  default:
1247  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1248  }
1249 
1250  const char* type;
1251 
1252  switch( aPad->GetAttribute() )
1253  {
1254  case PAD_ATTRIB_PTH: type = "thru_hole"; break;
1255  case PAD_ATTRIB_SMD: type = "smd"; break;
1256  case PAD_ATTRIB_CONN: type = "connect"; break;
1257  case PAD_ATTRIB_NPTH: type = "np_thru_hole"; break;
1258 
1259  default:
1260  THROW_IO_ERROR( wxString::Format( "unknown pad attribute: %d", aPad->GetAttribute() ) );
1261  }
1262 
1263  const char* property = nullptr;
1264 
1265  switch( aPad->GetProperty() )
1266  {
1267  case PAD_PROP_NONE: break; // could be also "none"
1268  case PAD_PROP_BGA: property = "pad_prop_bga"; break;
1269  case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1270  case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1271  case PAD_PROP_TESTPOINT: property = "pad_prop_testpoint"; break;
1272  case PAD_PROP_HEATSINK: property = "pad_prop_heatsink"; break;
1273  case PAD_PROP_CASTELLATED: property = "pad_prop_castellated"; break;
1274 
1275  default:
1276  THROW_IO_ERROR( wxString::Format( "unknown pad property: %d", aPad->GetProperty() ) );
1277  }
1278 
1279  m_out->Print( aNestLevel, "(pad %s %s %s",
1280  m_out->Quotew( aPad->GetName() ).c_str(),
1281  type, shape );
1282  m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
1283 
1284  if( aPad->GetOrientation() != 0.0 )
1285  m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() );
1286 
1287  m_out->Print( 0, ")" );
1288  m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
1289 
1290  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1291  m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() );
1292 
1293  wxSize sz = aPad->GetDrillSize();
1294  wxPoint shapeoffset = aPad->GetOffset();
1295 
1296  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1297  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1298  {
1299  m_out->Print( 0, " (drill" );
1300 
1301  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1302  m_out->Print( 0, " oval" );
1303 
1304  if( sz.GetWidth() > 0 )
1305  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetWidth() ).c_str() );
1306 
1307  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1308  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetHeight() ).c_str() );
1309 
1310  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1311  m_out->Print( 0, " (offset %s)", FormatInternalUnits( aPad->GetOffset() ).c_str() );
1312 
1313  m_out->Print( 0, ")" );
1314  }
1315 
1316  // Add pad property, if exists.
1317  if( property )
1318  m_out->Print( 0, " (property %s)", property );
1319 
1320  formatLayers( aPad->GetLayerSet() );
1321 
1322  if( aPad->GetAttribute() == PAD_ATTRIB_PTH )
1323  {
1324  if( aPad->GetRemoveUnconnected() )
1325  {
1326  m_out->Print( 0, " (remove_unused_layers)" );
1327 
1328  if( aPad->GetKeepTopBottom() )
1329  m_out->Print( 0, " (keep_end_layers)" );
1330  }
1331  }
1332 
1333  // Output the radius ratio for rounded and chamfered rect pads
1334  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT || aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1335  {
1336  m_out->Print( 0, " (roundrect_rratio %s)",
1337  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1338  }
1339 
1340  // Output the chamfer corners for chamfered rect pads
1341  if( aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1342  {
1343  m_out->Print( 0, "\n" );
1344 
1345  m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
1346  Double2Str( aPad->GetChamferRectRatio() ).c_str() );
1347 
1348  m_out->Print( 0, " (chamfer" );
1349 
1350  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
1351  m_out->Print( 0, " top_left" );
1352 
1353  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT ) )
1354  m_out->Print( 0, " top_right" );
1355 
1356  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT ) )
1357  m_out->Print( 0, " bottom_left" );
1358 
1360  m_out->Print( 0, " bottom_right" );
1361 
1362  m_out->Print( 0, ")" );
1363  }
1364 
1365  std::string output;
1366 
1367  // Unconnected pad is default net so don't save it.
1368  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1369  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1370  m_out->Quotew( aPad->GetNetname() ).c_str() );
1371 
1372  // Add pinfunction, if exists.
1373  // Pin function is closely related to nets, so if CTL_OMIT_NETS is set,
1374  // omit also pin function (for instance when saved from library editor)
1375  if( !(m_ctl & CTL_OMIT_NETS) && !aPad->GetPinFunction().IsEmpty() )
1376  StrPrintf( &output, " (pinfunction %s)",
1377  m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1378 
1379  if( aPad->GetPadToDieLength() != 0 )
1380  StrPrintf( &output, " (die_length %s)",
1381  FormatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
1382 
1383  if( aPad->GetLocalSolderMaskMargin() != 0 )
1384  StrPrintf( &output, " (solder_mask_margin %s)",
1385  FormatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() );
1386 
1387  if( aPad->GetLocalSolderPasteMargin() != 0 )
1388  StrPrintf( &output, " (solder_paste_margin %s)",
1389  FormatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() );
1390 
1391  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1392  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1393  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1394 
1395  if( aPad->GetLocalClearance() != 0 )
1396  StrPrintf( &output, " (clearance %s)",
1397  FormatInternalUnits( aPad->GetLocalClearance() ).c_str() );
1398 
1400  StrPrintf( &output, " (zone_connect %d)",
1401  static_cast<int>( aPad->GetEffectiveZoneConnection() ) );
1402 
1403  if( aPad->GetThermalSpokeWidth() != 0 )
1404  StrPrintf( &output, " (thermal_width %s)",
1405  FormatInternalUnits( aPad->GetThermalSpokeWidth() ).c_str() );
1406 
1407  if( aPad->GetThermalGap() != 0 )
1408  StrPrintf( &output, " (thermal_gap %s)",
1409  FormatInternalUnits( aPad->GetThermalGap() ).c_str() );
1410 
1411  if( output.size() )
1412  {
1413  m_out->Print( 0, "\n" );
1414  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1415  }
1416 
1417  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1418  {
1419  m_out->Print( 0, "\n");
1420  m_out->Print( aNestLevel+1, "(options" );
1421 
1423  m_out->Print( 0, " (clearance convexhull)" );
1424  #if 1 // Set to 1 to output the default option
1425  else
1426  m_out->Print( 0, " (clearance outline)" );
1427  #endif
1428 
1429  // Output the anchor pad shape (circle/rect)
1430  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1431  shape = "rect";
1432  else
1433  shape = "circle";
1434 
1435  m_out->Print( 0, " (anchor %s)", shape );
1436 
1437  m_out->Print( 0, ")"); // end of (options ...
1438 
1439  // Output graphic primitive of the pad shape
1440  m_out->Print( 0, "\n");
1441  m_out->Print( aNestLevel+1, "(primitives" );
1442 
1443  int nested_level = aNestLevel+2;
1444 
1445  // Output all basic shapes
1446  for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives() )
1447  {
1448  m_out->Print( 0, "\n");
1449 
1450  switch( primitive->GetShape() )
1451  {
1452  case S_SEGMENT: // usual segment : line with rounded ends
1453  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1454  FormatInternalUnits( primitive->GetStart() ).c_str(),
1455  FormatInternalUnits( primitive->GetEnd() ).c_str(),
1456  FormatInternalUnits( primitive->GetWidth() ).c_str() );
1457  break;
1458 
1459  case S_RECT:
1460  m_out->Print( nested_level, "(gr_rect (start %s) (end %s) (width %s))",
1461  FormatInternalUnits( primitive->GetStart() ).c_str(),
1462  FormatInternalUnits( primitive->GetEnd() ).c_str(),
1463  FormatInternalUnits( primitive->GetWidth() ).c_str() );
1464  break;
1465 
1466  case S_ARC: // Arc with rounded ends
1467  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1468  FormatInternalUnits( primitive->GetStart() ).c_str(),
1469  FormatInternalUnits( primitive->GetEnd() ).c_str(),
1470  FormatAngle( primitive->GetAngle() ).c_str(),
1471  FormatInternalUnits( primitive->GetWidth() ).c_str() );
1472  break;
1473 
1474  case S_CIRCLE: // ring or circle (circle if width == 0
1475  m_out->Print( nested_level, "(gr_circle (center %s) (end %s) (width %s))",
1476  FormatInternalUnits( primitive->GetStart() ).c_str(),
1477  FormatInternalUnits( primitive->GetEnd() ).c_str(),
1478  FormatInternalUnits( primitive->GetWidth() ).c_str() );
1479  break;
1480 
1481  case S_CURVE: // Bezier Curve
1482  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s)) (width %s))",
1483  FormatInternalUnits( primitive->GetStart() ).c_str(),
1484  FormatInternalUnits( primitive->GetBezControl1() ).c_str(),
1485  FormatInternalUnits( primitive->GetBezControl2() ).c_str(),
1486  FormatInternalUnits( primitive->GetEnd() ).c_str(),
1487  FormatInternalUnits( primitive->GetWidth() ).c_str() );
1488  break;
1489 
1490  case S_POLYGON: // polygon
1491  if( primitive->GetPolyShape().COutline( 0 ).CPoints().size() < 2 )
1492  break; // Malformed polygon.
1493 
1494  {
1495  m_out->Print( nested_level, "(gr_poly (pts\n");
1496 
1497  // Write the polygon corners coordinates:
1498  int newLine = 0;
1499 
1500  for( const VECTOR2I &pt : primitive->GetPolyShape().COutline( 0 ).CPoints() )
1501  {
1502  if( newLine == 0 )
1503  m_out->Print( nested_level+1, "(xy %s)",
1504  FormatInternalUnits( (wxPoint) pt ).c_str() );
1505  else
1506  m_out->Print( 0, " (xy %s)",
1507  FormatInternalUnits( (wxPoint) pt ).c_str() );
1508 
1509  if( ++newLine > 4 || !ADVANCED_CFG::GetCfg().m_CompactSave )
1510  {
1511  newLine = 0;
1512  m_out->Print( 0, "\n" );
1513  }
1514  }
1515 
1516  m_out->Print( 0, ") (width %s))", FormatInternalUnits( primitive->GetWidth() ).c_str() );
1517  }
1518  break;
1519 
1520  default:
1521  break;
1522  }
1523  }
1524 
1525  m_out->Print( 0, "\n");
1526  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1527  }
1528 
1529  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aPad->m_Uuid.AsString() ) );
1530 
1531  m_out->Print( 0, ")\n" );
1532 }
usual segment : line with rounded ends
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:364
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:225
no special fabrication property
Definition: pad_shapes.h:97
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:178
#define CTL_OMIT_NETS
Definition: pcb_netlist.h:282
a fiducial (usually a smd) for the full board
Definition: pad_shapes.h:99
int GetPadToDieLength() const
Definition: class_pad.h:362
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
Bezier Curve.
Smd pad, used in BGA footprints.
Definition: pad_shapes.h:98
wxString GetNetname() const
Function GetNetname.
wxString AsString() const
Definition: kiid.cpp:174
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
a pad used as heat sink, usually in SMD footprints
Definition: pad_shapes.h:102
const wxString & GetPinFunction() const
Definition: class_pad.h:138
Arcs (with rounded ends)
int GetThermalGap() const
Definition: class_pad.h:484
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:352
int GetChamferPositions() const
Definition: class_pad.h:523
a pad with a castellated through hole
Definition: pad_shapes.h:103
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:78
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
segment with non rounded ends
bool GetRemoveUnconnected() const
Definition: class_pad.h:538
const wxPoint & GetOffset() const
Definition: class_pad.h:248
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:343
double GetChamferRectRatio() const
Definition: class_pad.h:515
LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_pad.h:349
int GetLocalClearance(wxString *aSource) const override
Function GetLocalClearance returns any local clearances set in the "classic" (ie: pre-rule) system.
Definition: class_pad.cpp:638
const wxString & GetName() const
Definition: class_pad.h:132
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
PAD_PROP_T GetProperty() const
Definition: class_pad.h:355
const wxSize & GetDelta() const
Definition: class_pad.h:238
ZONE_CONNECTION GetEffectiveZoneConnection(wxString *aSource=nullptr) const
Return the zone connection in effect (either locally overridden or overridden in the parent module).
Definition: class_pad.cpp:746
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:82
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: eda_item.h:151
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:184
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives() const
Accessor to the basic shape list for custom-shaped pads.
Definition: class_pad.h:290
bool GetKeepTopBottom() const
Definition: class_pad.h:544
a fiducial (usually a smd) local to the parent footprint
Definition: pad_shapes.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:201
polygon (not yet used for tracks, but could be in microwave apps)
#define _(s)
Definition: 3d_actions.cpp:33
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in a variety of units (the basic call r...
Definition: class_pad.h:338
const wxSize & GetDrillSize() const
Definition: class_pad.h:241
Plated through hole pad.
Definition: pad_shapes.h:80
double GetRoundRectRadiusRatio() const
Definition: class_pad.h:507
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
Definition: class_pad.h:164
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
const wxSize & GetSize() const
Definition: class_pad.h:231
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:371
int GetThermalSpokeWidth() const
Definition: class_pad.h:476
a test point pad
Definition: pad_shapes.h:101
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:374
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::GetEffectiveZoneConnection(), D_PAD::GetKeepTopBottom(), 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::GetRemoveUnconnected(), D_PAD::GetRoundRectRadiusRatio(), D_PAD::GetShape(), D_PAD::GetSize(), D_PAD::GetThermalGap(), D_PAD::GetThermalSpokeWidth(), INHERITED, m_ctl, m_mapping, m_out, EDA_ITEM::m_Uuid, PAD_ATTRIB_CONN, PAD_ATTRIB_NPTH, PAD_ATTRIB_PTH, PAD_ATTRIB_SMD, 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_RECT, S_SEGMENT, StrPrintf(), THROW_IO_ERROR, TO_UTF8, NETINFO_MAPPING::Translate(), and NETINFO_LIST::UNCONNECTED.

◆ format() [9/12]

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

Definition at line 1535 of file kicad_plugin.cpp.

1536 {
1537  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1538  m_out->Quotew( aText->GetText() ).c_str(),
1539  FormatInternalUnits( aText->GetTextPos() ).c_str() );
1540 
1541  if( aText->GetTextAngle() != 0.0 )
1542  m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() );
1543 
1544  m_out->Print( 0, ")" );
1545 
1546  formatLayer( aText );
1547 
1548  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aText->m_Uuid.AsString() ) );
1549 
1550  m_out->Print( 0, "\n" );
1551 
1552  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1553 
1554  m_out->Print( aNestLevel, ")\n" );
1555 }
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:180
wxString AsString() const
Definition: kiid.cpp:174
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
const KIID m_Uuid
Definition: eda_item.h:151
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

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() [10/12]

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

Definition at line 1585 of file kicad_plugin.cpp.

1586 {
1587  std::string type;
1588 
1589  switch( aText->GetType() )
1590  {
1591  case FP_TEXT::TEXT_is_REFERENCE: type = "reference"; break;
1592  case FP_TEXT::TEXT_is_VALUE: type = "value"; break;
1593  case FP_TEXT::TEXT_is_DIVERS: type = "user";
1594  }
1595 
1596  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1597  type.c_str(),
1598  m_out->Quotew( aText->GetText() ).c_str(),
1599  FormatInternalUnits( aText->GetPos0() ).c_str() );
1600 
1601  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1602  // but internally the angle is held relative to its parent footprint. parent
1603  // may be NULL when saving a footprint outside a BOARD.
1604  double orient = aText->GetTextAngle();
1605  MODULE* parent = (MODULE*) aText->GetParent();
1606 
1607  if( parent )
1608  {
1609  // GetTextAngle() is always in -360..+360 range because of
1610  // FP_TEXT::SetTextAngle(), but summing that angle with an
1611  // additional board angle could kick sum up >= 360 or <= -360, so to have
1612  // consistent results, normalize again for the BOARD save. A footprint
1613  // save does not use this code path since parent is NULL.
1614 #if 0
1615  // This one could be considered reasonable if you like positive angles
1616  // in your board text.
1617  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1618 #else
1619  // Choose compatibility for now, even though this is only a 720 degree clamp
1620  // with two possible values for every angle.
1621  orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
1622 #endif
1623  }
1624 
1625  if( orient != 0.0 )
1626  m_out->Print( 0, " %s", FormatAngle( orient ).c_str() );
1627 
1628  if( !aText->IsKeepUpright() )
1629  m_out->Print( 0, " unlocked" );
1630 
1631  m_out->Print( 0, ")" );
1632  formatLayer( aText );
1633 
1634  if( !aText->IsVisible() )
1635  m_out->Print( 0, " hide" );
1636 
1637  m_out->Print( 0, "\n" );
1638 
1639  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1640 
1641  m_out->Print( aNestLevel + 1, "(tstamp %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
1642 
1643  m_out->Print( aNestLevel, ")\n" );
1644 }
double GetOrientation() const
Definition: class_module.h:206
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:192
double GetTextAngle() const
Definition: eda_text.h:180
wxString AsString() const
Definition: kiid.cpp:174
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
TEXT_TYPE GetType() const
Definition: fp_text.h:143
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
const KIID m_Uuid
Definition: eda_item.h:151
const wxPoint & GetPos0() const
Definition: fp_text.h:170
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:268
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
bool IsKeepUpright()
Definition: fp_text.h:112
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:243
BOARD_ITEM_CONTAINER * GetParent() const
#define CTL_OMIT_HIDE
Definition: eda_text.h:56
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

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

◆ format() [11/12]

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

Definition at line 1647 of file kicad_plugin.cpp.

1648 {
1649  if( aTrack->Type() == PCB_VIA_T )
1650  {
1651  PCB_LAYER_ID layer1, layer2;
1652 
1653  const VIA* via = static_cast<const VIA*>( aTrack );
1654  BOARD* board = (BOARD*) via->GetParent();
1655 
1656  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( EDA_UNITS::MILLIMETRES )
1657  + wxT( " has no parent." ) );
1658 
1659  m_out->Print( aNestLevel, "(via" );
1660 
1661  via->LayerPair( &layer1, &layer2 );
1662 
1663  switch( via->GetViaType() )
1664  {
1665  case VIATYPE::THROUGH: // Default shape not saved.
1666  break;
1667 
1668  case VIATYPE::BLIND_BURIED:
1669  m_out->Print( 0, " blind" );
1670  break;
1671 
1672  case VIATYPE::MICROVIA:
1673  m_out->Print( 0, " micro" );
1674  break;
1675 
1676  default:
1677  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1678  }
1679 
1680  m_out->Print( 0, " (at %s) (size %s)",
1681  FormatInternalUnits( aTrack->GetStart() ).c_str(),
1682  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1683 
1684  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1685  m_out->Print( 0, " (drill %s)", FormatInternalUnits( via->GetDrill() ).c_str() );
1686 
1687  m_out->Print( 0, " (layers %s %s)",
1688  m_out->Quotew( LSET::Name( layer1 ) ).c_str(),
1689  m_out->Quotew( LSET::Name( layer2 ) ).c_str() );
1690 
1691  if( via->GetRemoveUnconnected() )
1692  {
1693  m_out->Print( 0, " (remove_unused_layers)" );
1694 
1695  if( via->GetKeepTopBottom() )
1696  m_out->Print( 0, " (keep_end_layers)" );
1697  }
1698  }
1699  else if( aTrack->Type() == PCB_ARC_T )
1700  {
1701  const ARC* arc = static_cast<const ARC*>( aTrack );
1702 
1703  m_out->Print( aNestLevel, "(arc (start %s) (mid %s) (end %s) (width %s)",
1704  FormatInternalUnits( arc->GetStart() ).c_str(),
1705  FormatInternalUnits( arc->GetMid() ).c_str(),
1706  FormatInternalUnits( arc->GetEnd() ).c_str(),
1707  FormatInternalUnits( arc->GetWidth() ).c_str() );
1708 
1709  m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( arc->GetLayer() ) ).c_str() );
1710  }
1711  else
1712  {
1713  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1714  FormatInternalUnits( aTrack->GetStart() ).c_str(),
1715  FormatInternalUnits( aTrack->GetEnd() ).c_str(),
1716  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1717 
1718  m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( aTrack->GetLayer() ) ).c_str() );
1719  }
1720 
1721  if( aTrack->IsLocked() )
1722  m_out->Print( 0, " (locked)" );
1723 
1724  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1725 
1726  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTrack->m_Uuid.AsString() ) );
1727 
1728  m_out->Print( 0, ")\n" );
1729 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:136
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...
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetStart() const
Definition: class_track.h:116
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
wxString AsString() const
Definition: kiid.cpp:174
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
PCB_LAYER_ID
A quick note on layer IDs:
const wxPoint & GetMid() const
Definition: class_track.h:302
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:493
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:79
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
#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: eda_item.h:151
int GetWidth() const
Definition: class_track.h:110
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:201
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
bool GetRemoveUnconnected() const
Definition: class_track.h:459
VIATYPE GetViaType() const
Definition: class_track.h:384
const wxPoint & GetEnd() const
Definition: class_track.h:113
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:408
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
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: eda_item.h:182
bool GetKeepTopBottom() const
Definition: class_track.h:465

References _, KIID::AsString(), BLIND_BURIED, Format(), FormatInternalUnits(), VIA::GetDrill(), TRACK::GetEnd(), VIA::GetKeepTopBottom(), BOARD_ITEM::GetLayer(), ARC::GetMid(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_ITEM::GetParent(), VIA::GetRemoveUnconnected(), VIA::GetSelectMenuText(), TRACK::GetStart(), VIA::GetViaType(), TRACK::GetWidth(), TRACK::IsLocked(), VIA::LayerPair(), m_mapping, m_out, EDA_ITEM::m_Uuid, MICROVIA, MILLIMETRES, LSET::Name(), 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() [12/12]

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

Definition at line 1732 of file kicad_plugin.cpp.

1733 {
1734  // Save the NET info; For keepout zones, net code and net name are irrelevant
1735  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1736  // (perhaps netcode and netname should be not stored)
1737  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1738  aZone->GetIsRuleArea() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1739  m_out->Quotew( aZone->GetIsRuleArea() ? wxT("") : aZone->GetNetname() ).c_str() );
1740 
1741  // If a zone exists on multiple layers, format accordingly
1742  if( aZone->GetLayerSet().count() > 1 )
1743  {
1744  formatLayers( aZone->GetLayerSet() );
1745  }
1746  else
1747  {
1748  formatLayer( aZone );
1749  }
1750 
1751  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aZone->m_Uuid.AsString() ) );
1752 
1753  if( !aZone->GetZoneName().empty() )
1754  m_out->Print( 0, " (name %s)", m_out->Quotew( aZone->GetZoneName() ).c_str() );
1755 
1756  // Save the outline aux info
1757  std::string hatch;
1758 
1759  switch( aZone->GetHatchStyle() )
1760  {
1761  default:
1762  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: hatch = "none"; break;
1763  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: hatch = "edge"; break;
1764  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: hatch = "full"; break;
1765  }
1766 
1767  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1768  FormatInternalUnits( aZone->GetBorderHatchPitch() ).c_str() );
1769 
1770  if( aZone->GetPriority() > 0 )
1771  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1772 
1773  m_out->Print( aNestLevel+1, "(connect_pads" );
1774 
1775  switch( aZone->GetPadConnection() )
1776  {
1777  default:
1778  case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
1779  break;
1780 
1782  m_out->Print( 0, " thru_hole_only" );
1783  break;
1784 
1785  case ZONE_CONNECTION::FULL:
1786  m_out->Print( 0, " yes" );
1787  break;
1788 
1789  case ZONE_CONNECTION::NONE:
1790  m_out->Print( 0, " no" );
1791  break;
1792  }
1793 
1794  m_out->Print( 0, " (clearance %s))\n",
1795  FormatInternalUnits( aZone->GetLocalClearance() ).c_str() );
1796 
1797  m_out->Print( aNestLevel+1, "(min_thickness %s)",
1798  FormatInternalUnits( aZone->GetMinThickness() ).c_str() );
1799 
1800  // write it only if V 6.O version option is used (i.e. do not write if the "legacy"
1801  // algorithm is used)
1802  if( !aZone->GetFilledPolysUseThickness() )
1803  m_out->Print( 0, " (filled_areas_thickness no)" );
1804 
1805  m_out->Print( 0, "\n" );
1806 
1807  if( aZone->GetIsRuleArea() )
1808  {
1809  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (pads %s ) (copperpour %s) (footprints %s))\n",
1810  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1811  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1812  aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
1813  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
1814  aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
1815  }
1816 
1817  m_out->Print( aNestLevel+1, "(fill" );
1818 
1819  // Default is not filled.
1820  if( aZone->IsFilled() )
1821  m_out->Print( 0, " yes" );
1822 
1823  // Default is polygon filled.
1824  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1825  m_out->Print( 0, " (mode hatch)" );
1826 
1827  m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
1828  FormatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
1829  FormatInternalUnits( aZone->GetThermalReliefSpokeWidth() ).c_str() );
1830 
1832  {
1833  m_out->Print( 0, " (smoothing" );
1834 
1835  switch( aZone->GetCornerSmoothingType() )
1836  {
1838  m_out->Print( 0, " chamfer" );
1839  break;
1840 
1842  m_out->Print( 0, " fillet" );
1843  break;
1844 
1845  default:
1846  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1847  aZone->GetCornerSmoothingType() ) );
1848  }
1849  m_out->Print( 0, ")" );
1850 
1851  if( aZone->GetCornerRadius() != 0 )
1852  m_out->Print( 0, " (radius %s)",
1853  FormatInternalUnits( aZone->GetCornerRadius() ).c_str() );
1854  }
1855 
1857  {
1858  m_out->Print( 0, " (island_removal_mode %d) (island_area_min %s)",
1859  static_cast<int>( aZone->GetIslandRemovalMode() ),
1860  FormatInternalUnits( aZone->GetMinIslandArea() / IU_PER_MM ).c_str() );
1861  }
1862 
1863  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1864  {
1865  m_out->Print( 0, "\n" );
1866  m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
1867  FormatInternalUnits( aZone->GetHatchThickness() ).c_str(),
1868  FormatInternalUnits( aZone->GetHatchGap() ).c_str(),
1869  Double2Str( aZone->GetHatchOrientation() ).c_str() );
1870 
1871  if( aZone->GetHatchSmoothingLevel() > 0 )
1872  {
1873  m_out->Print( 0, "\n" );
1874  m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
1875  aZone->GetHatchSmoothingLevel(),
1876  Double2Str( aZone->GetHatchSmoothingValue() ).c_str() );
1877  }
1878 
1879  m_out->Print( 0, "\n" );
1880  m_out->Print( aNestLevel+2, "(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
1881  aZone->GetHatchBorderAlgorithm() ? "hatch_thickness" : "min_thickness",
1882  Double2Str( aZone->GetHatchHoleMinArea() ).c_str() );
1883  }
1884 
1885  m_out->Print( 0, ")\n" );
1886 
1887  int newLine = 0;
1888 
1889  if( aZone->GetNumCorners() )
1890  {
1891  bool new_polygon = true;
1892  bool is_closed = false;
1893 
1894  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1895  {
1896  if( new_polygon )
1897  {
1898  newLine = 0;
1899  m_out->Print( aNestLevel+1, "(polygon\n" );
1900  m_out->Print( aNestLevel+2, "(pts\n" );
1901  new_polygon = false;
1902  is_closed = false;
1903  }
1904 
1905  if( newLine == 0 )
1906  m_out->Print( aNestLevel+3, "(xy %s %s)",
1907  FormatInternalUnits( iterator->x ).c_str(),
1908  FormatInternalUnits( iterator->y ).c_str() );
1909  else
1910  m_out->Print( 0, " (xy %s %s)",
1911  FormatInternalUnits( iterator->x ).c_str(),
1912  FormatInternalUnits( iterator->y ).c_str() );
1913 
1914  if( newLine < 4 && ADVANCED_CFG::GetCfg().m_CompactSave )
1915  {
1916  newLine += 1;
1917  }
1918  else
1919  {
1920  newLine = 0;
1921  m_out->Print( 0, "\n" );
1922  }
1923 
1924  if( iterator.IsEndContour() )
1925  {
1926  is_closed = true;
1927 
1928  if( newLine != 0 )
1929  m_out->Print( 0, "\n" );
1930 
1931  m_out->Print( aNestLevel+2, ")\n" );
1932  m_out->Print( aNestLevel+1, ")\n" );
1933  new_polygon = true;
1934  }
1935  }
1936 
1937  if( !is_closed ) // Should not happen, but...
1938  {
1939  if( newLine != 0 )
1940  m_out->Print( 0, "\n" );
1941 
1942  m_out->Print( aNestLevel+2, ")\n" );
1943  m_out->Print( aNestLevel+1, ")\n" );
1944  }
1945  }
1946 
1947  // Save the PolysList (filled areas)
1948  for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() )
1949  {
1950  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList( layer );
1951  newLine = 0;
1952 
1953  if( !fv.IsEmpty() )
1954  {
1955  int poly_index = 0;
1956  bool new_polygon = true;
1957  bool is_closed = false;
1958 
1959  for( auto it = fv.CIterate(); it; ++it )
1960  {
1961  if( new_polygon )
1962  {
1963  newLine = 0;
1964  m_out->Print( aNestLevel + 1, "(filled_polygon\n" );
1965  m_out->Print( aNestLevel + 2, "(layer %s)\n",
1966  m_out->Quotew( LSET::Name( layer ) ).c_str() );
1967 
1968  if( aZone->IsIsland( layer, poly_index ) )
1969  m_out->Print( aNestLevel + 2, "(island)\n" );
1970 
1971  m_out->Print( aNestLevel + 2, "(pts\n" );
1972  new_polygon = false;
1973  is_closed = false;
1974  poly_index++;
1975  }
1976 
1977  if( newLine == 0 )
1978  m_out->Print( aNestLevel + 3, "(xy %s %s)",
1979  FormatInternalUnits( it->x ).c_str(),
1980  FormatInternalUnits( it->y ).c_str() );
1981  else
1982  m_out->Print( 0, " (xy %s %s)", FormatInternalUnits( it->x ).c_str(),
1983  FormatInternalUnits( it->y ).c_str() );
1984 
1985  if( newLine < 4 && ADVANCED_CFG::GetCfg().m_CompactSave )
1986  {
1987  newLine += 1;
1988  }
1989  else
1990  {
1991  newLine = 0;
1992  m_out->Print( 0, "\n" );
1993  }
1994 
1995  if( it.IsEndContour() )
1996  {
1997  is_closed = true;
1998 
1999  if( newLine != 0 )
2000  m_out->Print( 0, "\n" );
2001 
2002  m_out->Print( aNestLevel + 2, ")\n" );
2003  m_out->Print( aNestLevel + 1, ")\n" );
2004  new_polygon = true;
2005  }
2006  }
2007 
2008  if( !is_closed ) // Should not happen, but...
2009  m_out->Print( aNestLevel + 1, ")\n" );
2010  }
2011 
2012  // Save the filling segments list
2013  const auto& segs = aZone->FillSegments( layer );
2014 
2015  if( segs.size() )
2016  {
2017  m_out->Print( aNestLevel + 1, "(fill_segments\n" );
2018  m_out->Print( aNestLevel + 2, "(layer %s)\n",
2019  TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
2020 
2021  for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
2022  {
2023  m_out->Print( aNestLevel + 2, "(pts (xy %s) (xy %s))\n",
2024  FormatInternalUnits( wxPoint( it->A ) ).c_str(),
2025  FormatInternalUnits( wxPoint( it->B ) ).c_str() );
2026  }
2027 
2028  m_out->Print( aNestLevel + 1, ")\n" );
2029  }
2030  }
2031 
2032  m_out->Print( aNestLevel, ")\n" );
2033 }
bool GetDoNotAllowPads() const
Definition: class_zone.h:732
bool IsFilled() const
Definition: class_zone.h:214
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
bool m_CompactSave
Save files in compact display mode When is is not specified, points are written one per line.
int GetNetCode() const
Function GetNetCode.
void formatLayer(const BOARD_ITEM *aItem) const
int GetHatchBorderAlgorithm() const
Definition: class_zone.h:251
static constexpr double IU_PER_MM
Mock up a conversion function.
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
bool GetFilledPolysUseThickness() const
Definition: class_zone.h:685
const SHAPE_POLY_SET & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:629
int GetLocalClearance(wxString *aSource) const override
Function GetLocalClearance returns any local clearances set in the "classic" (ie: pre-rule) system.
Definition: class_zone.cpp:469
wxString AsString() const
Definition: kiid.cpp:174
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: class_zone.h:594
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:410
bool GetDoNotAllowVias() const
Definition: class_zone.h:730
long long int GetMinIslandArea() const
Definition: class_zone.h:746
int GetHatchGap() const
Definition: class_zone.h:236
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_zone.cpp:287
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
wxString GetZoneName() const
Definition: class_zone.h:113
PCB_LAYER_ID
A quick note on layer IDs:
pads are covered by copper
unsigned int GetCornerRadius() const
Definition: class_zone.h:683
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
SHAPE_POLY_SET.
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:163
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:729
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: class_zone.h:742
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: class_zone.cpp:882
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:506
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
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
int GetCornerSmoothingType() const
Definition: class_zone.h:679
double GetHatchOrientation() const
Definition: class_zone.h:239
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: class_zone.h:728
Thermal relief only for THT pads.
const KIID m_Uuid
Definition: eda_item.h:151
int GetThermalReliefGap() const
Definition: class_zone.h:172
Use thermal relief for pads.
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:106
double GetHatchSmoothingValue() const
Definition: class_zone.h:245
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:201
#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:526
int GetMinThickness() const
Definition: class_zone.h:224
Pads are not covered.
ZONE_CONNECTION GetPadConnection(D_PAD *aPad, wxString *aSource=nullptr) const
Definition: class_zone.cpp:769
int GetHatchSmoothingLevel() const
Definition: class_zone.h:242
bool GetDoNotAllowTracks() const
Definition: class_zone.h:731
bool GetDoNotAllowFootprints() const
Definition: class_zone.h:733
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
ZONE_SEGMENT_FILL & FillSegments(PCB_LAYER_ID aLayer)
Definition: class_zone.h:288
int GetHatchThickness() const
Definition: class_zone.h:233
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
int GetThermalReliefSpokeWidth() const
Definition: class_zone.h:182
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx)
Checks if a given filled polygon is an insulated island.
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
double GetHatchHoleMinArea() const
Definition: class_zone.h:248
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: class_board.h:646

References _, ALWAYS, KIID::AsString(), SHAPE_POLY_SET::CIterate(), DIAGONAL_EDGE, DIAGONAL_FULL, Double2Str(), ZONE_CONTAINER::FillSegments(), Format(), FormatInternalUnits(), formatLayer(), formatLayers(), FULL, ZONE_CONTAINER::GetBorderHatchPitch(), ADVANCED_CFG::GetCfg(), 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::GetHatchBorderAlgorithm(), ZONE_CONTAINER::GetHatchGap(), ZONE_CONTAINER::GetHatchHoleMinArea(), ZONE_CONTAINER::GetHatchOrientation(), ZONE_CONTAINER::GetHatchSmoothingLevel(), ZONE_CONTAINER::GetHatchSmoothingValue(), ZONE_CONTAINER::GetHatchStyle(), ZONE_CONTAINER::GetHatchThickness(), ZONE_CONTAINER::GetIslandRemovalMode(), ZONE_CONTAINER::GetIsRuleArea(), ZONE_CONTAINER::GetLayerSet(), ZONE_CONTAINER::GetLocalClearance(), ZONE_CONTAINER::GetMinIslandArea(), ZONE_CONTAINER::GetMinThickness(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), ZONE_CONTAINER::GetNumCorners(), ZONE_CONTAINER::GetPadConnection(), ZONE_CONTAINER::GetPriority(), BOARD::GetStandardLayerName(), ZONE_CONTAINER::GetThermalReliefGap(), ZONE_CONTAINER::GetThermalReliefSpokeWidth(), ZONE_CONTAINER::GetZoneName(), HATCH_PATTERN, SHAPE_POLY_SET::IsEmpty(), ZONE_CONTAINER::IsFilled(), ZONE_CONTAINER::IsIsland(), ZONE_CONTAINER::IterateWithHoles(), IU_PER_MM, ADVANCED_CFG::m_CompactSave, m_mapping, m_out, EDA_ITEM::m_Uuid, LSET::Name(), NO_HATCH, NONE, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), 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 504 of file kicad_plugin.cpp.

505 {
506  m_out->Print( aNestLevel, "(layers\n" );
507 
508  // Save only the used copper layers from front to back.
509 
510  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
511  {
512  PCB_LAYER_ID layer = *cu;
513 
514  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
515  m_out->Quotew( LSET::Name( layer ) ).c_str(),
516  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
517 
518  if( LSET::Name( layer ) != m_board->GetLayerName( layer ) )
519  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
520 
521  m_out->Print( 0, ")\n" );
522  }
523 
524  // Save used non-copper layers in the order they are defined.
525  // desired sequence for non Cu BOARD layers.
526  static const PCB_LAYER_ID non_cu[] =
527  {
528  B_Adhes, // 32
529  F_Adhes,
530  B_Paste,
531  F_Paste,
532  B_SilkS,
533  F_SilkS,
534  B_Mask,
535  F_Mask,
536  Dwgs_User,
537  Cmts_User,
538  Eco1_User,
539  Eco2_User,
540  Edge_Cuts,
541  Margin,
542  B_CrtYd,
543  F_CrtYd,
544  B_Fab,
545  F_Fab,
546  User_1,
547  User_2,
548  User_3,
549  User_4,
550  User_5,
551  User_6,
552  User_7,
553  User_8,
554  User_9
555  };
556 
557  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
558  {
559  PCB_LAYER_ID layer = *seq;
560 
561  m_out->Print( aNestLevel+1, "(%d %s user", layer,
562  m_out->Quotew( LSET::Name( layer ) ).c_str() );
563 
564  if( m_board->GetLayerName( layer ) != LSET::Name( layer ) )
565  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
566 
567  m_out->Print( 0, ")\n" );
568  }
569 
570  m_out->Print( aNestLevel, ")\n\n" );
571 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:169
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:410
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
PCB_LAYER_ID
A quick note on layer IDs:
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
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:121
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
BOARD * m_board
which BOARD, no ownership here
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

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(), m_board, m_out, Margin, LSET::Name(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), LAYER::ShowType(), User_1, User_2, User_3, User_4, User_5, User_6, User_7, User_8, and User_9.

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

◆ formatGeneral()

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

formats the General section of the file

Definition at line 488 of file kicad_plugin.cpp.

489 {
490  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
491 
492  m_out->Print( 0, "\n" );
493  m_out->Print( aNestLevel, "(general\n" );
494  m_out->Print( aNestLevel+1, "(thickness %s)\n",
495  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
496 
497  m_out->Print( aNestLevel, ")\n\n" );
498 
499  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
500  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
501 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:573
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
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:271
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: title_block.cpp:28
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:579
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References TITLE_BLOCK::Format(), PAGE_INFO::Format(), FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetDesignSettings(), BOARD::GetPageSettings(), BOARD::GetTitleBlock(), m_ctl, m_out, and OUTPUTFORMATTER::Print().

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

604 {
605  formatGeneral( aBoard, aNestLevel );
606  // Layers list.
607  formatBoardLayers( aBoard, aNestLevel );
608 
609  // Setup
610  formatSetup( aBoard, aNestLevel );
611 
612  // Properties
613  formatProperties( aBoard, aNestLevel );
614 
615  // Save net codes and names
616  formatNetInformation( aBoard, aNestLevel );
617 }
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 formatProperties(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(), formatProperties(), and formatSetup().

Referenced by format().

◆ formatLayer()

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

Definition at line 451 of file kicad_plugin.cpp.

452 {
453  PCB_LAYER_ID layer = aItem->GetLayer();
454 
455  m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( layer ) ).c_str() );
456 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
PCB_LAYER_ID
A quick note on layer IDs:
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.

References BOARD_ITEM::GetLayer(), m_out, LSET::Name(), OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by format().

◆ formatLayers()

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

Definition at line 1145 of file kicad_plugin.cpp.

1146 {
1147  std::string output;
1148 
1149  if( aNestLevel == 0 )
1150  output += ' ';
1151 
1152  output += "(layers";
1153 
1154  static const LSET cu_all( LSET::AllCuMask() );
1155  static const LSET fr_bk( 2, B_Cu, F_Cu );
1156  static const LSET adhes( 2, B_Adhes, F_Adhes );
1157  static const LSET paste( 2, B_Paste, F_Paste );
1158  static const LSET silks( 2, B_SilkS, F_SilkS );
1159  static const LSET mask( 2, B_Mask, F_Mask );
1160  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1161  static const LSET fab( 2, B_Fab, F_Fab );
1162 
1163  LSET cu_mask = cu_all;
1164 
1165  // output copper layers first, then non copper
1166 
1167  if( ( aLayerMask & cu_mask ) == cu_mask )
1168  {
1169  output += " *.Cu";
1170  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1171  }
1172  else if( ( aLayerMask & cu_mask ) == fr_bk )
1173  {
1174  output += " F&B.Cu";
1175  aLayerMask &= ~fr_bk;
1176  }
1177 
1178  if( ( aLayerMask & adhes ) == adhes )
1179  {
1180  output += " *.Adhes";
1181  aLayerMask &= ~adhes;
1182  }
1183 
1184  if( ( aLayerMask & paste ) == paste )
1185  {
1186  output += " *.Paste";
1187  aLayerMask &= ~paste;
1188  }
1189 
1190  if( ( aLayerMask & silks ) == silks )
1191  {
1192  output += " *.SilkS";
1193  aLayerMask &= ~silks;
1194  }
1195 
1196  if( ( aLayerMask & mask ) == mask )
1197  {
1198  output += " *.Mask";
1199  aLayerMask &= ~mask;
1200  }
1201 
1202  if( ( aLayerMask & crt_yd ) == crt_yd )
1203  {
1204  output += " *.CrtYd";
1205  aLayerMask &= ~crt_yd;
1206  }
1207 
1208  if( ( aLayerMask & fab ) == fab )
1209  {
1210  output += " *.Fab";
1211  aLayerMask &= ~fab;
1212  }
1213 
1214  // output any individual layers not handled in wildcard combos above
1215 
1216  wxString layerName;
1217 
1218  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1219  {
1220  if( aLayerMask[layer] )
1221  {
1222  layerName = LSET::Name( PCB_LAYER_ID( layer ) );
1223  output += ' ';
1224  output += m_out->Quotew( layerName );
1225  }
1226  }
1227 
1228  m_out->Print( aNestLevel, "%s)", output.c_str() );
1229 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:749
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
int LAYER_NUM
This can be replaced with int and removed.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References LSET::AllCuMask(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, m_out, LSET::Name(), 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 574 of file kicad_plugin.cpp.

575 {
576  for( NETINFO_ITEM* net : *m_mapping )
577  {
578  if( net == nullptr ) // Skip not actually existing nets (orphan nets)
579  continue;
580 
581  m_out->Print( aNestLevel, "(net %d %s)\n",
582  m_mapping->Translate( net->GetNet() ),
583  m_out->Quotew( net->GetNetname() ).c_str() );
584  }
585 
586  m_out->Print( 0, "\n" );
587 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
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
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.

References m_mapping, m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and NETINFO_MAPPING::Translate().

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

◆ formatProperties()

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

formats the Nets and Netclasses

Definition at line 590 of file kicad_plugin.cpp.

591 {
592  for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
593  {
594  m_out->Print( aNestLevel, "(property %s %s)\n",
595  m_out->Quotew( prop.first ).c_str(),
596  m_out->Quotew( prop.second ).c_str() );
597  }
598 
599  m_out->Print( 0, "\n" );
600 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const std::map< wxString, wxString > & GetProperties() const
Definition: class_board.h:307
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References BOARD::GetProperties(), m_out, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by formatHeader().

◆ formatSetup()

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

formats the board setup information

Definition at line 459 of file kicad_plugin.cpp.

460 {
461  // Setup
462  m_out->Print( aNestLevel, "(setup\n" );
463 
464  // Save the board physical stackup structure
466 
467  if( aBoard->GetDesignSettings().m_HasStackup )
468  stackup.FormatBoardStackup( m_out, aBoard, aNestLevel+1 );
469 
470  BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
471 
472  if( dsnSettings.m_AuxOrigin != wxPoint( 0, 0 ) )
473  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
474  FormatInternalUnits( dsnSettings.m_AuxOrigin.x ).c_str(),
475  FormatInternalUnits( dsnSettings.m_AuxOrigin.y ).c_str() );
476 
477  if( dsnSettings.m_GridOrigin != wxPoint( 0, 0 ) )
478  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
479  FormatInternalUnits( dsnSettings.m_GridOrigin.x ).c_str(),
480  FormatInternalUnits( dsnSettings.m_GridOrigin.y ).c_str() );
481 
482  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
483 
484  m_out->Print( aNestLevel, ")\n\n" );
485 }
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, BOARD *aBoard, int aNestLevel) const
Writes the stackup info on board file.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:576
wxPoint m_GridOrigin
origin for grid offsets
this class manage the layers needed to make a physical board they are solder mask,...
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
BOARD_STACKUP & GetStackupDescriptor()
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxPoint m_AuxOrigin
origin for plot exports
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References PCB_PLOT_PARAMS::Format(), BOARD_STACKUP::FormatBoardStackup(), FormatInternalUnits(), BOARD::GetDesignSettings(), BOARD::GetPlotOptions(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, BOARD_DESIGN_SETTINGS::m_GridOrigin, BOARD_DESIGN_SETTINGS::m_HasStackup, m_out, and OUTPUTFORMATTER::Print().

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 138 of file pcbnew/plugins/kicad/kicad_plugin.h.

139  {
140  // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
141  // but to be pure, a plugin should not assume that it will always be linked
142  // with the core of the Pcbnew code. (Might someday be a DLL/DSO.) Besides,
143  // file extension policy should be controlled by the plugin.
144  return wxT( "kicad_pcb" );
145  }

◆ 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: locale_io.h:40
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
MODULE_MAP::const_iterator MODULE_CITER
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
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)
Generate a timestamp representing all source files in the cache (including the parent directory).

References FP_CACHE::GetTimestamp().

Referenced by GITHUB_PLUGIN::GetLibraryTimestamp().

◆ GetStringOutput()

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

Definition at line 199 of file pcbnew/plugins/kicad/kicad_plugin.h.

200  {
201  std::string ret = m_sf.GetString();
202  if( doClear )
203  m_sf.Clear();
204 
205  return ret;
206  }
const std::string & GetString()
Definition: richio.h:476
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:465

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 NULL
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
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 DoLoad(), FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintSave(), getFootprint(), IsFootprintLibWritable(), CLIPBOARD_IO::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: locale_io.h:40
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 2055 of file kicad_plugin.cpp.

2056 {
2057  FILE_LINE_READER reader( aFileName );
2058 
2059  BOARD* board = DoLoad( reader, aAppendToMe, aProperties );
2060 
2061  // Give the filename to the board if it's new
2062  if( !aAppendToMe )
2063  board->SetFileName( aFileName );
2064 
2065  return board;
2066 }
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:181
void SetFileName(const wxString &aFileName)
Definition: class_board.h:277
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
BOARD * DoLoad(LINE_READER &aReader, BOARD *aAppendToMe, const PROPERTIES *aProperties)

References DoLoad(), and BOARD::SetFileName().

◆ Parse()

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

Definition at line 363 of file kicad_plugin.cpp.

364 {
365  std::string input = TO_UTF8( aClipboardSourceInput );
366 
367  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
368 
369  m_parser->SetLineReader( &reader );
370 
371  try
372  {
373  return m_parser->Parse();
374  }
375  catch( const PARSE_ERROR& parse_error )
376  {
377  if( m_parser->IsTooRecent() )
378  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
379  else
380  throw;
381  }
382 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:197
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:485
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:367
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:395
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:181
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:255

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 133 of file pcbnew/plugins/kicad/kicad_plugin.h.

134  {
135  return wxT( "KiCad" );
136  }

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

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

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

326 {
327  LOCALE_IO toggle; // toggles on, then off, the C locale.
328 
329  wxString sanityResult = aBoard->GroupsSanityCheck();
330 
331  if( sanityResult != wxEmptyString )
332  {
333  KIDIALOG dlg( nullptr, wxString::Format(
334  _( "Please report this bug. Error validating group structure: %s"
335  "\n\nSave anyway?" ), sanityResult ),
336  _( "Internal group data structure corrupt" ),
337  wxOK | wxCANCEL | wxICON_ERROR );
338  dlg.SetOKLabel( _( "Save Anyway" ) );
339 
340  if( dlg.ShowModal() == wxID_CANCEL )
341  return;
342  }
343 
344  init( aProperties );
345 
346  m_board = aBoard; // after init()
347 
348  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
349  m_mapping->SetBoard( aBoard );
350 
351  FILE_OUTPUTFORMATTER formatter( aFileName );
352 
353  m_out = &formatter; // no ownership
354 
355  m_out->Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n", SEXPR_BOARD_FILE_VERSION );
356 
357  Format( aBoard, 1 );
358 
359  m_out->Print( 0, ")\n" );
360 }
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: locale_io.h:40
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
void init(const PROPERTIES *aProperties)
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:296
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
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:201
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * m_board
which BOARD, no ownership here
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:493
wxString GroupsSanityCheck(bool repair=false)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.

References _, Format(), Format(), BOARD::GroupsSanityCheck(), init(), m_board, m_mapping, m_out, OUTPUTFORMATTER::Print(), NETINFO_MAPPING::SetBoard(), SEXPR_BOARD_FILE_VERSION, and KIDIALOG::ShowModal().

Referenced by KI_TEST::DumpBoardToFile(), and ROUTER_TOOL::handleCommonEvents().

◆ SetOutputFormatter()

void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inline

Definition at line 208 of file pcbnew/plugins/kicad/kicad_plugin.h.

208 { 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 }
bool IsModified()
Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Check 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 127 of file pcbnew/plugins/kicad/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

Definition at line 228 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by FootprintSave(), format(), and formatGeneral().

◆ m_error

wxString PCB_IO::m_error
protected

for throwing exceptions

Definition at line 214 of file pcbnew/plugins/kicad/kicad_plugin.h.

◆ m_filename

wxString PCB_IO::m_filename
protected

for saves only, name is in m_reader for loads

Definition at line 222 of file pcbnew/plugins/kicad/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 224 of file pcbnew/plugins/kicad/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 230 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by format(), 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 218 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by init().

◆ m_reader

LINE_READER* PCB_IO::m_reader
protected

no ownership here.

Definition at line 221 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by init().

◆ m_sf

STRING_FORMATTER PCB_IO::m_sf
protected

Definition at line 226 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by GetStringOutput(), and PCB_IO().


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