KiCad PCB EDA Suite
CLIPBOARD_IO Class Reference

#include <kicad_clipboard.h>

Inheritance diagram for CLIPBOARD_IO:
PCB_IO PLUGIN

Public Member Functions

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...
 
void SaveSelection (const SELECTION &selected)
 
BOARD_ITEMParse ()
 
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...
 
 CLIPBOARD_IO ()
 
 ~CLIPBOARD_IO ()
 
void SetBoard (BOARD *aBoard)
 
STRING_FORMATTERGetFormatter ()
 
const wxString PluginName () const override
 Function PluginName returns a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, 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...
 
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...
 
void Format (BOARD_ITEM *aItem, int aNestLevel=0) const
 Function Format outputs aItem to aFormatter in s-expression format. More...
 
std::string GetStringOutput (bool doClear)
 
void SetOutputFormatter (OUTPUTFORMATTER *aFormatter)
 
BOARD_ITEMParse (const wxString &aClipboardSourceInput)
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Protected Member Functions

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

Protected Attributes

wxString m_error
 for throwing exceptions More...
 
BOARDm_board
 which BOARD, no ownership here More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
FP_CACHEm_cache
 Footprint library cache. More...
 
LINE_READERm_reader
 no ownership here. More...
 
wxString m_filename
 for saves only, name is in m_reader for loads More...
 
int m_loading_format_version
 which SEXPR_BOARD_FILE_VERSION should be Load()ed? More...
 
STRING_FORMATTER m_sf
 
OUTPUTFORMATTERm_out
 output any Format()s to this, no ownership More...
 
int m_ctl
 
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 writeHeader (BOARD *aBoard)
 

Private Attributes

STRING_FORMATTER m_formatter
 
CLIPBOARD_PARSERm_parser
 

Detailed Description

Definition at line 56 of file kicad_clipboard.h.

Constructor & Destructor Documentation

CLIPBOARD_IO::CLIPBOARD_IO ( )

Definition at line 35 of file kicad_clipboard.cpp.

References m_formatter, and PCB_IO::m_out.

35  :
37  m_formatter(),
38  m_parser( new CLIPBOARD_PARSER() )
39 {
40  m_out = &m_formatter;
41 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
STRING_FORMATTER m_formatter
PCB_IO(int aControlFlags=CTL_FOR_BOARD)
CLIPBOARD_PARSER * m_parser
#define CTL_STD_LAYER_NAMES
Use English Standard layer names.
CLIPBOARD_IO::~CLIPBOARD_IO ( )

Definition at line 44 of file kicad_clipboard.cpp.

References m_parser.

45 {
46  delete m_parser;
47 }
CLIPBOARD_PARSER * m_parser

Member Function Documentation

void PCB_IO::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

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

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

2124 {
2125  LOCALE_IO toggle; // toggles on, then off, the C locale.
2126 
2127  init( aProperties );
2128 
2129  validateCache( aLibraryPath );
2130 
2131  if( !m_cache->IsWritable() )
2132  {
2133  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only" ),
2134  aLibraryPath.GetData() ) );
2135  }
2136 
2137  m_cache->Remove( aFootprintName );
2138 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
bool IsWritable() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void PCB_IO::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

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

Reimplemented from PLUGIN.

Definition at line 1941 of file kicad_plugin.cpp.

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

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

1944 {
1945  LOCALE_IO toggle; // toggles on, then off, the C locale.
1946  wxDir dir( aLibraryPath );
1947 
1948  init( aProperties );
1949 
1950  wxString errorMsg;
1951 
1952  try
1953  {
1954  validateCache( aLibraryPath );
1955  }
1956  catch( const IO_ERROR& ioe )
1957  {
1958  errorMsg = ioe.What();
1959  }
1960 
1961  // Some of the files may have been parsed correctly so we want to add the valid files to
1962  // the library.
1963 
1964  const MODULE_MAP& mods = m_cache->GetModules();
1965 
1966  for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
1967  {
1968  aFootprintNames.Add( it->first );
1969  }
1970 
1971  if( !errorMsg.IsEmpty() )
1972  THROW_IO_ERROR( errorMsg );
1973 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()
void PCB_IO::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

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

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

2149 {
2150  if( wxDir::Exists( aLibraryPath ) )
2151  {
2152  THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path \"%s\"" ),
2153  aLibraryPath.GetData() ) );
2154  }
2155 
2156  LOCALE_IO toggle;
2157 
2158  init( aProperties );
2159 
2160  delete m_cache;
2161  m_cache = new FP_CACHE( this, aLibraryPath );
2162  m_cache->Save();
2163 }
friend class FP_CACHE
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
#define THROW_IO_ERROR(msg)
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool PCB_IO::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

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

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

2167 {
2168  wxFileName fn;
2169  fn.SetPath( aLibraryPath );
2170 
2171  // Return if there is no library path to delete.
2172  if( !fn.DirExists() )
2173  return false;
2174 
2175  if( !fn.IsDirWritable() )
2176  {
2177  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory \"%s\"" ),
2178  aLibraryPath.GetData() ) );
2179  }
2180 
2181  wxDir dir( aLibraryPath );
2182 
2183  if( dir.HasSubDirs() )
2184  {
2185  THROW_IO_ERROR( wxString::Format( _( "library directory \"%s\" has unexpected sub-directories" ),
2186  aLibraryPath.GetData() ) );
2187  }
2188 
2189  // All the footprint files must be deleted before the directory can be deleted.
2190  if( dir.HasFiles() )
2191  {
2192  unsigned i;
2193  wxFileName tmp;
2194  wxArrayString files;
2195 
2196  wxDir::GetAllFiles( aLibraryPath, &files );
2197 
2198  for( i = 0; i < files.GetCount(); i++ )
2199  {
2200  tmp = files[i];
2201 
2202  if( tmp.GetExt() != KiCadFootprintFileExtension )
2203  {
2204  THROW_IO_ERROR( wxString::Format( _( "unexpected file \"%s\" was found in library path \"%s\"" ),
2205  files[i].GetData(), aLibraryPath.GetData() ) );
2206  }
2207  }
2208 
2209  for( i = 0; i < files.GetCount(); i++ )
2210  {
2211  wxRemoveFile( files[i] );
2212  }
2213  }
2214 
2215  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"" ),
2216  aLibraryPath.GetData() );
2217 
2218  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2219  // we don't want that. we want bare metal portability with no UI here.
2220  if( !wxRmdir( aLibraryPath ) )
2221  {
2222  THROW_IO_ERROR( wxString::Format( _( "footprint library \"%s\" cannot be deleted" ),
2223  aLibraryPath.GetData() ) );
2224  }
2225 
2226  // For some reason removing a directory in Windows is not immediately updated. This delay
2227  // prevents an error when attempting to immediately recreate the same directory when over
2228  // writing an existing library.
2229 #ifdef __WINDOWS__
2230  wxMilliSleep( 250L );
2231 #endif
2232 
2233  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2234  {
2235  delete m_cache;
2236  m_cache = NULL;
2237  }
2238 
2239  return true;
2240 }
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
size_t i
Definition: json11.cpp:597
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 132 of file plugin.cpp.

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

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

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

References PCB_IO::getFootprint().

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

2017 {
2018  const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2019  return footprint ? new MODULE( *footprint ) : nullptr;
2020 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
void PCB_IO::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

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

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

2025 {
2026  LOCALE_IO toggle; // toggles on, then off, the C locale.
2027 
2028  init( aProperties );
2029 
2030  // In this public PLUGIN API function, we can safely assume it was
2031  // called for saving into a library path.
2033 
2034  validateCache( aLibraryPath );
2035 
2036  if( !m_cache->IsWritable() )
2037  {
2038  if( !m_cache->Exists() )
2039  {
2040  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2041  "Would you like to create it?"),
2042  GetChars( aLibraryPath ) );
2043 
2044  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2045  return;
2046 
2047  // Save throws its own IO_ERROR on failure, so no need to recreate here
2048  m_cache->Save( NULL );
2049  }
2050  else
2051  {
2052  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
2053  THROW_IO_ERROR( msg );
2054  }
2055  }
2056 
2057  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2058 
2059  MODULE_MAP& mods = m_cache->GetModules();
2060 
2061  // Quietly overwrite module and delete module file from path for any by same name.
2062  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2064 
2065 #ifndef __WINDOWS__
2066  // Write through symlinks, don't replace them
2067  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2068  {
2069  char buffer[ PATH_MAX + 1 ];
2070  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2071 
2072  if( pathLen > 0 )
2073  {
2074  buffer[ pathLen ] = '\0';
2075  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2076  fn.Normalize();
2077  }
2078  }
2079 #endif
2080 
2081  if( !fn.IsOk() )
2082  {
2083  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2084  fn.GetFullPath() ) );
2085  }
2086 
2087  if( fn.FileExists() && !fn.IsFileWritable() )
2088  {
2089  THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
2090  fn.GetFullPath() ) );
2091  }
2092 
2093  wxString fullPath = fn.GetFullPath();
2094  wxString fullName = fn.GetFullName();
2095  MODULE_CITER it = mods.find( footprintName );
2096 
2097  if( it != mods.end() )
2098  {
2099  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2100  mods.erase( footprintName );
2101  wxRemoveFile( fullPath );
2102  }
2103 
2104  // I need my own copy for the cache
2105  MODULE* module = new MODULE( *aFootprint );
2106 
2107  // and it's time stamp must be 0, it should have no parent, orientation should
2108  // be zero, and it should be on the front layer.
2109  module->SetTimeStamp( 0 );
2110  module->SetParent( 0 );
2111  module->SetOrientation( 0 );
2112 
2113  if( module->GetLayer() != F_Cu )
2114  module->Flip( module->GetPosition() );
2115 
2116  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2117  mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
2118  m_cache->Save( module );
2119 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
void init(const PROPERTIES *aProperties)
const LIB_ID & GetFPID() const
Definition: class_module.h:192
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
bool Exists() const
#define THROW_IO_ERROR(msg)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
Class FP_CACHE_ITEM is helper class for creating a footprint library cache.
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
bool IsWritable() const
MODULE_MAP::const_iterator MODULE_CITER
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: common.h:392
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetOrientation(double newangle)
const wxPoint GetPosition() const override
Definition: class_module.h:183
MODULE_MAP & GetModules()
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
void PCB_IO::Format ( BOARD_ITEM aItem,
int  aNestLevel = 0 
) const
inherited

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

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

Definition at line 398 of file kicad_plugin.cpp.

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

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

399 {
400  LOCALE_IO toggle; // public API function, perform anything convenient for caller
401 
402  switch( aItem->Type() )
403  {
404  case PCB_T:
405  format( static_cast<BOARD*>( aItem ), aNestLevel );
406  break;
407 
408  case PCB_DIMENSION_T:
409  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
410  break;
411 
412  case PCB_LINE_T:
413  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
414  break;
415 
416  case PCB_MODULE_EDGE_T:
417  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
418  break;
419 
420  case PCB_TARGET_T:
421  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
422  break;
423 
424  case PCB_MODULE_T:
425  format( static_cast<MODULE*>( aItem ), aNestLevel );
426  break;
427 
428  case PCB_PAD_T:
429  format( static_cast<D_PAD*>( aItem ), aNestLevel );
430  break;
431 
432  case PCB_TEXT_T:
433  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
434  break;
435 
436  case PCB_MODULE_TEXT_T:
437  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
438  break;
439 
440  case PCB_TRACE_T:
441  case PCB_VIA_T:
442  format( static_cast<TRACK*>( aItem ), aNestLevel );
443  break;
444 
445  case PCB_ZONE_AREA_T:
446  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
447  break;
448 
449  default:
450  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
451  }
452 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
Definition: typeinfo.h:85
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
void PCB_IO::formatBoardLayers ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board layer information

Definition at line 612 of file kicad_plugin.cpp.

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

Referenced by SaveSelection().

613 {
614  m_out->Print( aNestLevel, "(layers\n" );
615 
616  // Save only the used copper layers from front to back.
617  LSET visible_layers = aBoard->GetVisibleLayers();
618 
619  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
620  {
621  PCB_LAYER_ID layer = *cu;
622 
623  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
624  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
625  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
626 
627  if( !visible_layers[layer] )
628  m_out->Print( 0, " hide" );
629 
630  m_out->Print( 0, ")\n" );
631  }
632 
633  // Save used non-copper layers in the order they are defined.
634  // desired sequence for non Cu BOARD layers.
635  static const PCB_LAYER_ID non_cu[] =
636  {
637  B_Adhes, // 32
638  F_Adhes,
639  B_Paste,
640  F_Paste,
641  B_SilkS,
642  F_SilkS,
643  B_Mask,
644  F_Mask,
645  Dwgs_User,
646  Cmts_User,
647  Eco1_User,
648  Eco2_User,
649  Edge_Cuts,
650  Margin,
651  B_CrtYd,
652  F_CrtYd,
653  B_Fab,
654  F_Fab
655  };
656 
657  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
658  {
659  PCB_LAYER_ID layer = *seq;
660 
661  m_out->Print( aNestLevel+1, "(%d %s user", layer,
662  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
663 
664  if( !visible_layers[layer] )
665  m_out->Print( 0, " hide" );
666 
667  m_out->Print( 0, ")\n" );
668  }
669 
670  m_out->Print( aNestLevel, ")\n\n" );
671 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:150
#define cu(a)
Definition: auxiliary.h:88
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:367
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void PCB_IO::formatGeneral ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the General section of the file

Definition at line 590 of file kicad_plugin.cpp.

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

591 {
592  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
593 
594  m_out->Print( 0, "\n" );
595  m_out->Print( aNestLevel, "(general\n" );
596  // Write Bounding box info
597  m_out->Print( aNestLevel+1, "(thickness %s)\n",
598  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
599 
600  m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->Drawings().Size() );
601  m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
602  m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
603  m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
604  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
605  m_out->Print( aNestLevel, ")\n\n" );
606 
607  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
608  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
609 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
int GetSize() const
Function GetSize.
Definition: netinfo.h:383
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:168
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
int GetNumSegmTrack() const
Functions to get some items count.
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:554
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:267
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:560
DLIST< MODULE > m_Modules
Definition: class_board.h:249
int GetNumSegmZone() const
Calculate the zone segment count.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:457
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:256
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatHeader ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

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

Definition at line 704 of file kicad_plugin.cpp.

705 {
706  formatGeneral( aBoard, aNestLevel );
707  // Layers.
708  formatBoardLayers( aBoard, aNestLevel );
709  // Setup
710  formatSetup( aBoard, aNestLevel );
711  // Save net codes and names
712  formatNetInformation( aBoard, aNestLevel );
713 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
void formatSetup(BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
void PCB_IO::formatNetInformation ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the Nets and Netclasses

Definition at line 674 of file kicad_plugin.cpp.

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

Referenced by SaveSelection().

675 {
676  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
677  for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
678  net != netEnd; ++net )
679  {
680  m_out->Print( aNestLevel, "(net %d %s)\n",
681  m_mapping->Translate( net->GetNet() ),
682  m_out->Quotew( net->GetNetname() ).c_str() );
683  }
684 
685  m_out->Print( 0, "\n" );
686 
687  // Save the default net class first.
688  NETCLASS defaultNC = *dsnSettings.GetDefault();
689  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
690  defaultNC.Format( m_out, aNestLevel, m_ctl );
691 
692  // Save the rest of the net classes alphabetically.
693  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
694  it != dsnSettings.m_NetClasses.end();
695  ++it )
696  {
697  NETCLASS netclass = *it->second;
698  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
699  netclass.Format( m_out, aNestLevel, m_ctl );
700  }
701 }
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:363
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
NETCLASSPTR GetDefault() const
Function GetDefault.
iterator end()
Definition: netclass.h:249
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:251
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:374
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the net class to aFormatter in s-expression form.
Definition: netclass.cpp:253
iterator begin()
Definition: netclass.h:248
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:313
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
void filterNetClass(const BOARD &aBoard, NETCLASS &aNetClass)
Removes empty nets (i.e. with node count equal zero) from net classes
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatSetup ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board setup information

Definition at line 468 of file kicad_plugin.cpp.

References Double2Str(), PCB_PLOT_PARAMS::Format(), FormatInternalUnits(), BOARD::GetAuxOrigin(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), D_PAD::GetDrillSize(), BOARD::GetGridOrigin(), BOARD::GetPlotOptions(), D_PAD::GetSize(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), BOARD::GetZoneSettings(), LAYER_CLASS_COPPER, LAYER_CLASS_EDGES, LAYER_CLASS_SILK, BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_Pad_Master, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, ZONE_SETTINGS::m_Zone_45_Only, and ZONE_SETTINGS::m_ZoneClearance.

469 {
470  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
471 
472  // Setup
473  m_out->Print( aNestLevel, "(setup\n" );
474 
475  // Save current default track width, for compatibility with older Pcbnew version;
476  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
477  FormatInternalUnits( dsnSettings.GetCurrentTrackWidth() ).c_str() );
478 
479  // Save custom tracks width list (the first is not saved here: this is the netclass value
480  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
481  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
482  FormatInternalUnits( dsnSettings.m_TrackWidthList[ii] ).c_str() );
483 
484  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
485  FormatInternalUnits( dsnSettings.GetDefault()->GetClearance() ).c_str() );
486 
487  // ZONE_SETTINGS
488  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
489  FormatInternalUnits( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
490  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
491  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
492 
493  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
494  FormatInternalUnits( dsnSettings.m_TrackMinWidth ).c_str() );
495 
496  // Save current default via size, for compatibility with older Pcbnew version;
497  m_out->Print( aNestLevel+1, "(via_size %s)\n",
498  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
499  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
500  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
501  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
502  FormatInternalUnits( dsnSettings.m_ViasMinSize ).c_str() );
503  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
504  FormatInternalUnits( dsnSettings.m_ViasMinDrill ).c_str() );
505 
506  // Save custom vias diameters list (the first is not saved here: this is
507  // the netclass value
508  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
509  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
510  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
511  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
512 
513  // for old versions compatibility:
514  if( dsnSettings.m_BlindBuriedViaAllowed )
515  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
516 
517  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
518  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
519  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
520  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
521  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
522  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
523  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
524  FormatInternalUnits( dsnSettings.m_MicroViasMinSize ).c_str() );
525  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
526  FormatInternalUnits( dsnSettings.m_MicroViasMinDrill ).c_str() );
527 
528  // 6.0 TODO: are we going to update the tokens we save these under?
529  // 6.0 TODO: need to save the LAYER_CLASS_OTHERS stuff
530  // 6.0 TODO: need to save the TextItalic and TextUpright settings
531 
532  m_out->Print( aNestLevel+1, "(edge_width %s)\n",
533  FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_EDGES ] ).c_str() );
534 
535  m_out->Print( aNestLevel+1, "(segment_width %s)\n",
536  FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_COPPER ] ).c_str() );
537  m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
538  FormatInternalUnits( dsnSettings.m_TextThickness[ LAYER_CLASS_COPPER ] ).c_str() );
539  m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
540  FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_COPPER ].x ).c_str(),
541  FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_COPPER ].y ).c_str() );
542 
543  m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
544  FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_SILK ] ).c_str() );
545  m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
546  FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_SILK ].x ).c_str(),
547  FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_SILK ].y ).c_str() );
548  m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
549  FormatInternalUnits( dsnSettings.m_TextThickness[ LAYER_CLASS_SILK ] ).c_str() );
550 
551  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
552  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
553  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
554  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
555  FormatInternalUnits( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
556 
557  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
558  FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
559 
560  if( dsnSettings.m_SolderMaskMinWidth )
561  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
562  FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
563 
564  if( dsnSettings.m_SolderPasteMargin != 0 )
565  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
566  FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
567 
568  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
569  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
570  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
571 
572  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
573  FormatInternalUnits( aBoard->GetAuxOrigin().x ).c_str(),
574  FormatInternalUnits( aBoard->GetAuxOrigin().y ).c_str() );
575 
576  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
577  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
578  FormatInternalUnits( aBoard->GetGridOrigin().x ).c_str(),
579  FormatInternalUnits( aBoard->GetGridOrigin().y ).c_str() );
580 
581  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
582  dsnSettings.GetVisibleElements() );
583 
584  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
585 
586  m_out->Print( aNestLevel, ")\n\n" );
587 }
int m_SolderMaskMargin
Solder mask margin.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:563
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
NETCLASSPTR GetDefault() const
Function GetDefault.
const wxPoint & GetGridOrigin() const
Definition: class_board.h:357
int m_SolderPasteMargin
Solder paste margin absolute value.
std::vector< int > m_TrackWidthList
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_ViasMinDrill
vias (not micro vias) min drill diameter
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:557
const wxSize & GetSize() const
Definition: class_pad.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:63
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
int m_MicroViasMinSize
micro vias (not vias) min diameter
int m_LineThickness[LAYER_CLASS_COUNT]
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:350
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
bool m_MicroViasAllowed
true to allow micro vias
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values...
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:457
int m_SolderMaskMinWidth
Solder mask min width.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
const MODULE * PCB_IO::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

Reimplemented from PLUGIN.

Definition at line 2007 of file kicad_plugin.cpp.

References PCB_IO::getFootprint().

Referenced by PCB_IO::GetFileExtension().

2010 {
2011  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2012 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtualinherited

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

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

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

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

Definition at line 1976 of file kicad_plugin.cpp.

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

Referenced by PCB_IO::FootprintLoad(), and PCB_IO::GetEnumeratedFootprint().

1980 {
1981  LOCALE_IO toggle; // toggles on, then off, the C locale.
1982 
1983  init( aProperties );
1984 
1985  try
1986  {
1987  validateCache( aLibraryPath, checkModified );
1988  }
1989  catch( const IO_ERROR& )
1990  {
1991  // do nothing with the error
1992  }
1993 
1994  const MODULE_MAP& mods = m_cache->GetModules();
1995 
1996  MODULE_CITER it = mods.find( aFootprintName );
1997 
1998  if( it == mods.end() )
1999  {
2000  return NULL;
2001  }
2002 
2003  return it->second->GetModule();
2004 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()
STRING_FORMATTER * CLIPBOARD_IO::GetFormatter ( )

Definition at line 50 of file kicad_clipboard.cpp.

References m_formatter.

51 {
52  return &m_formatter;
53 }
STRING_FORMATTER m_formatter
long long PCB_IO::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
overridevirtualinherited

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

References FP_CACHE::GetTimestamp().

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

2143 {
2144  return FP_CACHE::GetTimestamp( aLibraryPath );
2145 }
static long long GetTimestamp(const wxString &aLibPath)
Function GetTimestamp Generate a timestamp representing all source files in the cache (including the ...
std::string PCB_IO::GetStringOutput ( bool  doClear)
inlineinherited

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

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

162  {
163  std::string ret = m_sf.GetString();
164  if( doClear )
165  m_sf.Clear();
166 
167  return ret;
168  }
const std::string & GetString()
Definition: richio.h:475
STRING_FORMATTER m_sf
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:464
void PCB_IO::init ( const PROPERTIES aProperties)
protectedinherited

Definition at line 1920 of file kicad_plugin.cpp.

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

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

1921 {
1922  m_board = NULL;
1923  m_reader = NULL;
1925  m_props = aProperties;
1926 }
LINE_READER * m_reader
no ownership here.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
BOARD * m_board
which BOARD, no ownership here
bool PCB_IO::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtualinherited

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

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

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

2244 {
2245  LOCALE_IO toggle;
2246 
2247  init( NULL );
2248 
2249  validateCache( aLibraryPath );
2250 
2251  return m_cache->IsWritable();
2252 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const
BOARD * CLIPBOARD_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 282 of file kicad_clipboard.cpp.

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

284 {
285  std::string result;
286 
287  auto clipboard = wxTheClipboard;
288  wxClipboardLocker clipboardLock( clipboard );
289 
290  if( !clipboardLock )
291  return nullptr;
292 
293  if( clipboard->IsSupported( wxDF_TEXT ) )
294  {
295  wxTextDataObject data;
296  clipboard->GetData( data );
297 
298  result = data.GetText().mb_str();
299  }
300 
301  STRING_LINE_READER reader(result, wxT( "clipboard" ) );
302 
303  init( aProperties );
304 
305  m_parser->SetLineReader( &reader );
306  m_parser->SetBoard( aAppendToMe );
307 
308  BOARD_ITEM* item;
309  BOARD* board;
310 
311  try
312  {
313  item = m_parser->Parse();
314  }
315  catch( const FUTURE_FORMAT_ERROR& )
316  {
317  // Don't wrap a FUTURE_FORMAT_ERROR in another
318  throw;
319  }
320  catch( const PARSE_ERROR& parse_error )
321  {
322  if( m_parser->IsTooRecent() )
323  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
324  else
325  throw;
326  }
327 
328  if( item->Type() != PCB_T )
329  {
330  // The parser loaded something that was valid, but wasn't a board.
331  THROW_PARSE_ERROR( _( "Clipboard content is not KiCad compatible" ),
332  m_parser->CurSource(), m_parser->CurLine(),
333  m_parser->CurLineNumber(), m_parser->CurOffset() );
334  }
335  else
336  {
337  board = dynamic_cast<BOARD*>( item );
338  }
339 
340  // Give the filename to the board if it's new
341  if( board && !aAppendToMe )
342  board->SetFileName( aFileName );
343 
344  return board;
345 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
Definition: typeinfo.h:85
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void init(const PROPERTIES *aProperties)
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:301
void SetFileName(const wxString &aFileName)
Definition: class_board.h:236
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:294
CLIPBOARD_PARSER * m_parser
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:319
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:123
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
BOARD_ITEM * CLIPBOARD_IO::Parse ( )

Definition at line 207 of file kicad_clipboard.cpp.

References PCB_IO::Parse().

Referenced by PCBNEW_CONTROL::PasteItemsFromClipboard().

208 {
209  BOARD_ITEM* item;
210  wxString result;
211 
212  auto clipboard = wxTheClipboard;
213  wxClipboardLocker clipboardLock( clipboard );
214 
215  if( !clipboardLock )
216  return nullptr;
217 
218 
219  if( clipboard->IsSupported( wxDF_TEXT ) )
220  {
221  wxTextDataObject data;
222  clipboard->GetData( data );
223  result = data.GetText();
224  }
225 
226  try
227  {
228  item = PCB_IO::Parse( result );
229  }
230  catch (...)
231  {
232  item = nullptr;
233  }
234 
235  return item;
236 }
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)
inherited

Definition at line 376 of file kicad_plugin.cpp.

References TO_UTF8.

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

377 {
378  std::string input = TO_UTF8( aClipboardSourceInput );
379 
380  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
381 
382  m_parser->SetLineReader( &reader );
383 
384  try
385  {
386  return m_parser->Parse();
387  }
388  catch( const PARSE_ERROR& parse_error )
389  {
390  if( m_parser->IsTooRecent() )
391  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
392  else
393  throw;
394  }
395 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:294
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:319
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:123
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
const wxString PCB_IO::PluginName ( ) const
inlineoverridevirtualinherited

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

Implements PLUGIN.

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

102  {
103  return wxT( "KiCad" );
104  }
void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Plugins that cannot prefetch need not override this; a default no-op is provided.

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

Reimplemented in GITHUB_PLUGIN.

Definition at line 68 of file plugin.cpp.

Referenced by FP_LIB_TABLE::PrefetchLib().

69 {
70  (void) aLibraryPath;
71  (void) aProperties;
72 }
void CLIPBOARD_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 PCB_IO.

Definition at line 239 of file kicad_clipboard.cpp.

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

241 {
242  init( aProperties );
243 
244  m_board = aBoard; // after init()
245 
246  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
247  m_mapping->SetBoard( aBoard );
248 
249  STRING_FORMATTER formatter;
250 
251  m_out = &formatter;
252 
253  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
254  formatter.Quotew( GetBuildVersion() ).c_str() );
255 
256  Format( aBoard, 1 );
257 
258  m_out->Print( 0, ")\n" );
259 
260  auto clipboard = wxTheClipboard;
261  wxClipboardLocker clipboardLock( clipboard );
262 
263  if( !clipboardLock )
264  return;
265 
266  clipboard->SetData( new wxTextDataObject(
267  wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
268  clipboard->Flush();
269 
270  // This section exists to return the clipboard data, ensuring it has fully
271  // been processed by the system clipboard. This appears to be needed for
272  // extremely large clipboard copies on asynchronous linux clipboard managers
273  // such as KDE's Klipper
274  {
275  wxTextDataObject data;
276  clipboard->GetData( data );
277  ( void )data.GetText(); // Keep unused variable
278  }
279 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void init(const PROPERTIES *aProperties)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
STRING_FORMATTER m_formatter
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:289
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const std::string & GetString()
Definition: richio.h:475
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
BOARD * m_board
which BOARD, no ownership here
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
Class STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:445
void CLIPBOARD_IO::SaveSelection ( const SELECTION selected)

Definition at line 62 of file kicad_clipboard.cpp.

References MODULE::Add(), DLIST< T >::begin(), SELECTION::Empty(), PCB_IO::Format(), PCB_IO::formatBoardLayers(), PCB_IO::formatNetInformation(), GetBuildVersion(), MODULE::GetPosition(), SELECTION::GetReferencePoint(), STRING_FORMATTER::GetString(), SELECTION::HasReferencePoint(), i, PCB_IO::m_board, m_formatter, PCB_IO::m_mapping, BOARD::m_Modules, mod, MODULE::Move(), MODULE::MoveAnchorPosition(), D_PAD::Next(), MODULE::PadsList(), PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), NETINFO_MAPPING::SetBoard(), BOARD_CONNECTED_ITEM::SetNetCode(), SEXPR_BOARD_FILE_VERSION, TEXTE_MODULE::TEXT_is_DIVERS, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDIT_TOOL::doCopyToClipboard().

63 {
64  VECTOR2I refPoint( 0, 0 );
65 
66  // dont even start if the selection is empty
67  if( aSelected.Empty() )
68  return;
69 
70  if( aSelected.HasReferencePoint() )
71  refPoint = aSelected.GetReferencePoint();
72 
73  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
75 
76  // Differentiate how it is formatted depending on what selection contains
77  bool onlyModuleParts = true;
78  for( const auto i : aSelected )
79  {
80  // check if it not one of the module primitives
81  if( ( i->Type() != PCB_MODULE_EDGE_T ) &&
82  ( i->Type() != PCB_MODULE_TEXT_T ) &&
83  ( i->Type() != PCB_PAD_T ) )
84  {
85  onlyModuleParts = false;
86  continue;
87  }
88  }
89 
90  // if there is only parts of a module selected, format it as a new module else
91  // format it as an entire board
92  MODULE partialModule( m_board );
93 
94  // only a module selected.
95  if( aSelected.Size() == 1 && aSelected.Front()->Type() == PCB_MODULE_T )
96  {
97  // make the module safe to transfer to other pcbs
98  const MODULE* mod = static_cast<MODULE*>( aSelected.Front() );
99  // Do not modify existing board
100  MODULE newModule(*mod);
101 
102  for( D_PAD* pad = newModule.PadsList().begin(); pad; pad = pad->Next() )
103  {
104  pad->SetNetCode( 0, 0 );
105  }
106 
107  // locate the reference point at (0, 0) in the copied items
108  newModule.Move( wxPoint( -refPoint.x, -refPoint.y ) );
109 
110  Format( static_cast<BOARD_ITEM*>( &newModule ) );
111  }
112  // partial module selected.
113  else if( onlyModuleParts )
114  {
115  for( const auto item : aSelected )
116  {
117  auto clone = static_cast<BOARD_ITEM*>( item->Clone() );
118 
119  // Do not add reference/value - convert them to the common type
120  if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
121  text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
122 
123  // If it is only a module, clear the nets from the pads
124  if( clone->Type() == PCB_PAD_T )
125  {
126  D_PAD* pad = static_cast<D_PAD*>( clone );
127  pad->SetNetCode( 0, 0 );
128  }
129 
130  // locate the reference point at (0, 0) in the copied items
131  clone->Move( wxPoint(-refPoint.x, -refPoint.y ) );
132 
133  partialModule.Add( clone );
134  }
135 
136  // Set the new relative internal local coordinates of copied items
137  MODULE* editedModule = m_board->m_Modules;
138  wxPoint moveVector = partialModule.GetPosition() + editedModule->GetPosition();
139 
140  partialModule.MoveAnchorPosition( moveVector );
141 
142  Format( &partialModule, 0 );
143 
144  }
145  // lots of stuff selected
146  else
147  {
148  // we will fake being a .kicad_pcb to get the full parser kicking
149  // This means we also need layers and nets
150  LOCALE_IO io;
151 
152  m_formatter.Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n",
154 
155 
156  m_formatter.Print( 0, "\n" );
157 
160 
161  m_formatter.Print( 0, "\n" );
162 
163 
164  for( const auto i : aSelected )
165  {
166  // Dont format stuff that cannot exist standalone!
167  if( ( i->Type() != PCB_MODULE_EDGE_T ) &&
168  ( i->Type() != PCB_MODULE_TEXT_T ) &&
169  ( i->Type() != PCB_PAD_T ) )
170  {
171  auto item = static_cast<BOARD_ITEM*>( i );
172  std::unique_ptr<BOARD_ITEM> clone( static_cast<BOARD_ITEM*> ( item->Clone() ) );
173 
174  // locate the reference point at (0, 0) in the copied items
175  clone->Move( wxPoint(-refPoint.x, -refPoint.y ) );
176 
177  Format( clone.get(), 1 );
178  }
179  }
180  m_formatter.Print( 0, "\n)" );
181  }
182 
183  // These are placed at the end to minimize the open time of the clipboard
184  auto clipboard = wxTheClipboard;
185  wxClipboardLocker clipboardLock( clipboard );
186 
187  if( !clipboardLock || !clipboard->IsOpened() )
188  return;
189 
190  clipboard->SetData( new wxTextDataObject(
191  wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
192 
193  clipboard->Flush();
194 
195  // This section exists to return the clipboard data, ensuring it has fully
196  // been processed by the system clipboard. This appears to be needed for
197  // extremely large clipboard copies on asynchronous linux clipboard managers
198  // such as KDE's Klipper
199  {
200  wxTextDataObject data;
201  clipboard->GetData( data );
202  ( void )data.GetText(); // Keep unused variable
203  }
204 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
STRING_FORMATTER m_formatter
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:289
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
class MODULE, a footprint
Definition: typeinfo.h:89
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
D_PAD * Next() const
Definition: class_pad.h:160
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const std::string & GetString()
Definition: richio.h:475
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
DLIST< MODULE > m_Modules
Definition: class_board.h:249
size_t i
Definition: json11.cpp:597
BOARD * m_board
which BOARD, no ownership here
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
const wxPoint GetPosition() const override
Definition: class_module.h:183
#define mod(a, n)
Definition: greymap.cpp:24
void CLIPBOARD_IO::SetBoard ( BOARD aBoard)

Definition at line 56 of file kicad_clipboard.cpp.

References PCB_IO::m_board.

Referenced by EDIT_TOOL::doCopyToClipboard().

57 {
58  m_board = aBoard;
59 }
BOARD * m_board
which BOARD, no ownership here
void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

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

References PCB_IO::m_out, and PCB_IO::Parse().

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

Definition at line 1929 of file kicad_plugin.cpp.

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

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

1930 {
1931  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
1932  {
1933  // a spectacular episode in memory management:
1934  delete m_cache;
1935  m_cache = new FP_CACHE( this, aLibraryPath );
1936  m_cache->Load();
1937  }
1938 }
friend class FP_CACHE
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
void Load()
void CLIPBOARD_IO::writeHeader ( BOARD aBoard)
private

Member Data Documentation

BOARD* PCB_IO::m_board
protectedinherited

which BOARD, no ownership here

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

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

int PCB_IO::m_ctl
protectedinherited

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

Referenced by PCB_IO::FootprintSave().

wxString PCB_IO::m_error
protectedinherited

for throwing exceptions

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

wxString PCB_IO::m_filename
protectedinherited

for saves only, name is in m_reader for loads

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

STRING_FORMATTER CLIPBOARD_IO::m_formatter
private

Definition at line 80 of file kicad_clipboard.h.

Referenced by CLIPBOARD_IO(), GetFormatter(), Save(), and SaveSelection().

int PCB_IO::m_loading_format_version
protectedinherited

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

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

Referenced by PCB_IO::init().

NETINFO_MAPPING* PCB_IO::m_mapping
protectedinherited

mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes

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

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

OUTPUTFORMATTER* PCB_IO::m_out
protectedinherited

output any Format()s to this, no ownership

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

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

CLIPBOARD_PARSER* CLIPBOARD_IO::m_parser
private

Definition at line 81 of file kicad_clipboard.h.

Referenced by Load(), and ~CLIPBOARD_IO().

const PROPERTIES* PCB_IO::m_props
protectedinherited

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

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

Referenced by PCB_IO::init().

LINE_READER* PCB_IO::m_reader
protectedinherited

no ownership here.

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

Referenced by PCB_IO::init().

STRING_FORMATTER PCB_IO::m_sf
protectedinherited

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

Referenced by PCB_IO::GetStringOutput(), and PCB_IO::PCB_IO().


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