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 PCBNEW_SELECTION &selected, bool isModEdit)
 
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...
 
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...
 
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 51 of file kicad_clipboard.h.

Constructor & Destructor Documentation

◆ CLIPBOARD_IO()

CLIPBOARD_IO::CLIPBOARD_IO ( )

Definition at line 40 of file kicad_clipboard.cpp.

40  :
42  m_formatter(),
43  m_parser( new CLIPBOARD_PARSER() )
44 {
45  m_out = &m_formatter;
46 }
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.

References m_formatter, and PCB_IO::m_out.

◆ ~CLIPBOARD_IO()

CLIPBOARD_IO::~CLIPBOARD_IO ( )

Definition at line 49 of file kicad_clipboard.cpp.

50 {
51  delete m_parser;
52 }
CLIPBOARD_PARSER * m_parser

References m_parser.

Member Function Documentation

◆ DoLoad()

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

Definition at line 1950 of file kicad_plugin.cpp.

1951 {
1952  init( aProperties );
1953 
1954  m_parser->SetLineReader( &aReader );
1955  m_parser->SetBoard( aAppendToMe );
1956 
1957  BOARD* board;
1958 
1959  try
1960  {
1961  board = dynamic_cast<BOARD*>( m_parser->Parse() );
1962  }
1963  catch( const FUTURE_FORMAT_ERROR& )
1964  {
1965  // Don't wrap a FUTURE_FORMAT_ERROR in another
1966  throw;
1967  }
1968  catch( const PARSE_ERROR& parse_error )
1969  {
1970  if( m_parser->IsTooRecent() )
1971  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
1972  else
1973  throw;
1974  }
1975 
1976  if( !board )
1977  {
1978  // The parser loaded something that was valid, but wasn't a board.
1979  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
1980  m_parser->CurSource(), m_parser->CurLine(),
1981  m_parser->CurLineNumber(), m_parser->CurOffset() );
1982  }
1983 
1984  return board;
1985 }
void init(const PROPERTIES *aProperties)
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:208
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:344
PCB_PARSER * m_parser
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:337
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:363
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172

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

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

◆ FootprintDelete()

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

2205 {
2206  LOCALE_IO toggle; // toggles on, then off, the C locale.
2207 
2208  init( aProperties );
2209 
2210  validateCache( aLibraryPath );
2211 
2212  if( !m_cache->IsWritable() )
2213  {
2214  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only." ),
2215  aLibraryPath.GetData() ) );
2216  }
2217 
2218  m_cache->Remove( aFootprintName );
2219 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
bool IsWritable() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), 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().

◆ FootprintEnumerate()

void PCB_IO::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
bool  aBestEfforts,
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.
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 2009 of file kicad_plugin.cpp.

2011 {
2012  LOCALE_IO toggle; // toggles on, then off, the C locale.
2013  wxDir dir( aLibPath );
2014  wxString errorMsg;
2015 
2016  init( aProperties );
2017 
2018  try
2019  {
2020  validateCache( aLibPath );
2021  }
2022  catch( const IO_ERROR& ioe )
2023  {
2024  errorMsg = ioe.What();
2025  }
2026 
2027  // Some of the files may have been parsed correctly so we want to add the valid files to
2028  // the library.
2029 
2030  for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
2031  aFootprintNames.Add( it->first );
2032 
2033  if( !errorMsg.IsEmpty() && !aBestEfforts )
2034  THROW_IO_ERROR( errorMsg );
2035 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()

References FP_CACHE::GetModules(), PCB_IO::init(), PCB_IO::m_cache, THROW_IO_ERROR, PCB_IO::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 
)
overridevirtualinherited

Function FootprintExists check for the existence of a footprint.

Reimplemented from PLUGIN.

Definition at line 2075 of file kicad_plugin.cpp.

2077 {
2078  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2079  // only in case.
2080  //
2081  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2082  // case-insensitive filesystem) handled "for free".
2083  // Warning: footprint names frequently contain a point. So be careful when initializing
2084  // wxFileName, and use a CTOR with extension specified
2085  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2086 
2087  return footprintFile.Exists();
2088 }
const std::string KiCadFootprintFileExtension

References KiCadFootprintFileExtension.

◆ FootprintLibCreate()

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

2230 {
2231  if( wxDir::Exists( aLibraryPath ) )
2232  {
2233  THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path \"%s\"." ),
2234  aLibraryPath.GetData() ) );
2235  }
2236 
2237  LOCALE_IO toggle;
2238 
2239  init( aProperties );
2240 
2241  delete m_cache;
2242  m_cache = new FP_CACHE( this, aLibraryPath );
2243  m_cache->Save();
2244 }
friend class FP_CACHE
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
#define THROW_IO_ERROR(msg)
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), PCB_IO::FP_CACHE, PCB_IO::init(), PCB_IO::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 
)
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 2247 of file kicad_plugin.cpp.

2248 {
2249  wxFileName fn;
2250  fn.SetPath( aLibraryPath );
2251 
2252  // Return if there is no library path to delete.
2253  if( !fn.DirExists() )
2254  return false;
2255 
2256  if( !fn.IsDirWritable() )
2257  {
2258  THROW_IO_ERROR( wxString::Format( _( "User does not have permission to delete directory \"%s\"." ),
2259  aLibraryPath.GetData() ) );
2260  }
2261 
2262  wxDir dir( aLibraryPath );
2263 
2264  if( dir.HasSubDirs() )
2265  {
2266  THROW_IO_ERROR( wxString::Format( _( "Library directory \"%s\" has unexpected sub-directories." ),
2267  aLibraryPath.GetData() ) );
2268  }
2269 
2270  // All the footprint files must be deleted before the directory can be deleted.
2271  if( dir.HasFiles() )
2272  {
2273  unsigned i;
2274  wxFileName tmp;
2275  wxArrayString files;
2276 
2277  wxDir::GetAllFiles( aLibraryPath, &files );
2278 
2279  for( i = 0; i < files.GetCount(); i++ )
2280  {
2281  tmp = files[i];
2282 
2283  if( tmp.GetExt() != KiCadFootprintFileExtension )
2284  {
2285  THROW_IO_ERROR( wxString::Format( _( "Unexpected file \"%s\" was found in library path \"%s\"." ),
2286  files[i].GetData(), aLibraryPath.GetData() ) );
2287  }
2288  }
2289 
2290  for( i = 0; i < files.GetCount(); i++ )
2291  wxRemoveFile( files[i] );
2292  }
2293 
2294  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"." ),
2295  aLibraryPath.GetData() );
2296 
2297  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2298  // we don't want that. we want bare metal portability with no UI here.
2299  if( !wxRmdir( aLibraryPath ) )
2300  {
2301  THROW_IO_ERROR( wxString::Format( _( "Footprint library \"%s\" cannot be deleted." ),
2302  aLibraryPath.GetData() ) );
2303  }
2304 
2305  // For some reason removing a directory in Windows is not immediately updated. This delay
2306  // prevents an error when attempting to immediately recreate the same directory when over
2307  // writing an existing library.
2308 #ifdef __WINDOWS__
2309  wxMilliSleep( 250L );
2310 #endif
2311 
2312  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2313  {
2314  delete m_cache;
2315  m_cache = NULL;
2316  }
2317 
2318  return true;
2319 }
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
#define NULL
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33

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

Referenced by GITHUB_PLUGIN::FootprintLibDelete().

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

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

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

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

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

Reimplemented in GITHUB_PLUGIN, and EAGLE_PLUGIN.

Definition at line 140 of file plugin.cpp.

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

References _.

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

◆ FootprintLoad()

MODULE * PCB_IO::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
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 2091 of file kicad_plugin.cpp.

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

References BOARD_ITEM::Duplicate(), and PCB_IO::getFootprint().

Referenced by GITHUB_PLUGIN::FootprintLoad().

◆ FootprintSave()

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

2101 {
2102  LOCALE_IO toggle; // toggles on, then off, the C locale.
2103 
2104  init( aProperties );
2105 
2106  // In this public PLUGIN API function, we can safely assume it was
2107  // called for saving into a library path.
2109 
2110  validateCache( aLibraryPath );
2111 
2112  if( !m_cache->IsWritable() )
2113  {
2114  if( !m_cache->Exists() )
2115  {
2116  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2117  "Would you like to create it?"),
2118  GetChars( aLibraryPath ) );
2119 
2120  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2121  return;
2122 
2123  // Save throws its own IO_ERROR on failure, so no need to recreate here
2124  m_cache->Save( NULL );
2125  }
2126  else
2127  {
2128  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
2129  THROW_IO_ERROR( msg );
2130  }
2131  }
2132 
2133  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2134 
2135  MODULE_MAP& mods = m_cache->GetModules();
2136 
2137  // Quietly overwrite module and delete module file from path for any by same name.
2138  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2140 
2141 #ifndef __WINDOWS__
2142  // Write through symlinks, don't replace them
2143  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2144  {
2145  char buffer[ PATH_MAX + 1 ];
2146  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2147 
2148  if( pathLen > 0 )
2149  {
2150  buffer[ pathLen ] = '\0';
2151  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2152  fn.Normalize();
2153  }
2154  }
2155 #endif
2156 
2157  if( !fn.IsOk() )
2158  {
2159  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2160  fn.GetFullPath() ) );
2161  }
2162 
2163  if( fn.FileExists() && !fn.IsFileWritable() )
2164  {
2165  THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
2166  fn.GetFullPath() ) );
2167  }
2168 
2169  wxString fullPath = fn.GetFullPath();
2170  wxString fullName = fn.GetFullName();
2171  MODULE_CITER it = mods.find( footprintName );
2172 
2173  if( it != mods.end() )
2174  {
2175  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2176  mods.erase( footprintName );
2177  wxRemoveFile( fullPath );
2178  }
2179 
2180  // I need my own copy for the cache
2181  MODULE* module = static_cast<MODULE*>( aFootprint->Duplicate() );
2182 
2183  // It should have no parent, orientation should be zero, and it should be on the front layer.
2184  module->SetParent( nullptr );
2185  module->SetOrientation( 0 );
2186 
2187  if( module->GetLayer() != F_Cu )
2188  {
2189  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2190 
2191  if( cfg )
2192  module->Flip( module->GetPosition(), cfg->m_FlipLeftRight );
2193  else
2194  module->Flip( module->GetPosition(), false );
2195  }
2196 
2197  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2198  mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
2199  m_cache->Save( module );
2200 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
const std::string KiCadFootprintFileExtension
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
const LIB_ID & GetFPID() const
Definition: class_module.h:225
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
#define NULL
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
FP_CACHE_ITEM is helper class for creating a footprint library cache.
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
bool IsWritable() const
MODULE_MAP::const_iterator MODULE_CITER
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: common.h:414
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
void SetOrientation(double newangle)
#define TO_UTF8(wxstring)
wxPoint GetPosition() const override
Definition: class_module.h:216
bool Exists() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
MODULE_MAP & GetModules()
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.

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

Referenced by GITHUB_PLUGIN::FootprintSave().

◆ Format()

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

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

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

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

◆ formatBoardLayers()

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

formats the board layer information

Definition at line 523 of file kicad_plugin.cpp.

524 {
525  m_out->Print( aNestLevel, "(layers\n" );
526 
527  // Save only the used copper layers from front to back.
528 
529  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
530  {
531  PCB_LAYER_ID layer = *cu;
532 
533  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
534  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
535  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
536 
537  m_out->Print( 0, ")\n" );
538  }
539 
540  // Save used non-copper layers in the order they are defined.
541  // desired sequence for non Cu BOARD layers.
542  static const PCB_LAYER_ID non_cu[] =
543  {
544  B_Adhes, // 32
545  F_Adhes,
546  B_Paste,
547  F_Paste,
548  B_SilkS,
549  F_SilkS,
550  B_Mask,
551  F_Mask,
552  Dwgs_User,
553  Cmts_User,
554  Eco1_User,
555  Eco2_User,
556  Edge_Cuts,
557  Margin,
558  B_CrtYd,
559  F_CrtYd,
560  B_Fab,
561  F_Fab
562  };
563 
564  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
565  {
566  PCB_LAYER_ID layer = *seq;
567 
568  m_out->Print( aNestLevel+1, "(%d %s user", layer,
569  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
570 
571  m_out->Print( 0, ")\n" );
572  }
573 
574  m_out->Print( aNestLevel, ")\n\n" );
575 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:155
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
PCB_LAYER_ID
A quick note on layer IDs:
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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

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

◆ formatGeneral()

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

formats the General section of the file

Definition at line 502 of file kicad_plugin.cpp.

503 {
504  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
505 
506  m_out->Print( 0, "\n" );
507  m_out->Print( aNestLevel, "(general\n" );
508  // Write Bounding box info
509  m_out->Print( aNestLevel+1, "(thickness %s)\n",
510  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
511 
512  m_out->Print( aNestLevel+1, "(drawings %u)\n", (unsigned)aBoard->Drawings().size() );
513  m_out->Print( aNestLevel + 1, "(tracks %u)\n", (unsigned)aBoard->Tracks().size() );
514  m_out->Print( aNestLevel + 1, "(modules %u)\n", (unsigned)aBoard->Modules().size() );
515  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
516  m_out->Print( aNestLevel, ")\n\n" );
517 
518  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
519  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
520 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:574
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
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
int GetSize() const
Function GetSize.
Definition: netinfo.h:390
MODULES & Modules()
Definition: class_board.h:266
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
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:580
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
DRAWINGS & Drawings()
Definition: class_board.h:275
TRACKS & Tracks()
Definition: class_board.h:257
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

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

Referenced by PCB_IO::formatHeader().

◆ formatHeader()

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

595 {
596  formatGeneral( aBoard, aNestLevel );
597  // Layers list.
598  formatBoardLayers( aBoard, aNestLevel );
599 
600  // Setup
601  formatSetup( aBoard, aNestLevel );
602 
603  // Save net codes and names
604  formatNetInformation( aBoard, aNestLevel );
605 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
void formatSetup(BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information

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

Referenced by PCB_IO::format().

◆ formatNetInformation()

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

formats the Nets and Netclasses

Definition at line 578 of file kicad_plugin.cpp.

579 {
580  for( NETINFO_ITEM* net : *m_mapping )
581  {
582  if( net == nullptr ) // Skip not actually existing nets (orphan nets)
583  continue;
584 
585  m_out->Print( aNestLevel, "(net %d %s)\n",
586  m_mapping->Translate( net->GetNet() ),
587  m_out->Quotew( net->GetNetname() ).c_str() );
588  }
589 
590  m_out->Print( 0, "\n" );
591 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.

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

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

◆ formatSetup()

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

formats the board setup information

Definition at line 473 of file kicad_plugin.cpp.

474 {
475  // Setup
476  m_out->Print( aNestLevel, "(setup\n" );
477 
478  // Save the board physical stackup structure
480 
481  if( aBoard->GetDesignSettings().m_HasStackup )
482  stackup.FormatBoardStackup( m_out,aBoard, aNestLevel+1 );
483 
484  BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
485 
486  if( dsnSettings.m_AuxOrigin != wxPoint( 0, 0 ) )
487  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
488  FormatInternalUnits( dsnSettings.m_AuxOrigin.x ).c_str(),
489  FormatInternalUnits( dsnSettings.m_AuxOrigin.y ).c_str() );
490 
491  if( dsnSettings.m_GridOrigin != wxPoint( 0, 0 ) )
492  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
493  FormatInternalUnits( dsnSettings.m_GridOrigin.x ).c_str(),
494  FormatInternalUnits( dsnSettings.m_GridOrigin.y ).c_str() );
495 
496  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
497 
498  m_out->Print( aNestLevel, ")\n\n" );
499 }
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:577
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
Function GetDesignSettings.
Definition: class_board.h:553
BOARD_STACKUP & GetStackupDescriptor()
bool m_HasStackup
Set to true if the board has a stackup management.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
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:560
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, PCB_IO::m_out, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by PCB_IO::formatHeader().

◆ GetEnumeratedFootprint()

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

2070 {
2071  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2072 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References PCB_IO::getFootprint().

◆ GetFileExtension()

const wxString PCB_IO::GetFileExtension ( ) const
inlineoverridevirtualinherited

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

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

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

◆ getFootprint()

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

Definition at line 2038 of file kicad_plugin.cpp.

2042 {
2043  LOCALE_IO toggle; // toggles on, then off, the C locale.
2044 
2045  init( aProperties );
2046 
2047  try
2048  {
2049  validateCache( aLibraryPath, checkModified );
2050  }
2051  catch( const IO_ERROR& )
2052  {
2053  // do nothing with the error
2054  }
2055 
2056  const MODULE_MAP& mods = m_cache->GetModules();
2057 
2058  MODULE_CITER it = mods.find( aFootprintName );
2059 
2060  if( it == mods.end() )
2061  return nullptr;
2062 
2063  return it->second->GetModule();
2064 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()

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

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

◆ GetFormatter()

STRING_FORMATTER * CLIPBOARD_IO::GetFormatter ( )

Definition at line 55 of file kicad_clipboard.cpp.

56 {
57  return &m_formatter;
58 }
STRING_FORMATTER m_formatter

References m_formatter.

◆ GetLibraryTimestamp()

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

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

References FP_CACHE::GetTimestamp().

Referenced by GITHUB_PLUGIN::GetLibraryTimestamp().

◆ GetStringOutput()

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

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

180  {
181  std::string ret = m_sf.GetString();
182  if( doClear )
183  m_sf.Clear();
184 
185  return ret;
186  }
const std::string & GetString()
Definition: richio.h:475
STRING_FORMATTER m_sf
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:464

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

◆ init()

void PCB_IO::init ( const PROPERTIES aProperties)
protectedinherited

Definition at line 1988 of file kicad_plugin.cpp.

1989 {
1990  m_board = NULL;
1991  m_reader = NULL;
1993  m_props = aProperties;
1994 }
LINE_READER * m_reader
no ownership here.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define NULL
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
BOARD * m_board
which BOARD, no ownership here

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

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

◆ IsFootprintLibWritable()

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

2323 {
2324  LOCALE_IO toggle;
2325 
2326  init( NULL );
2327 
2328  validateCache( aLibraryPath );
2329 
2330  return m_cache->IsWritable();
2331 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
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 PCB_IO::init(), FP_CACHE::IsWritable(), PCB_IO::m_cache, NULL, and PCB_IO::validateCache().

Referenced by GITHUB_PLUGIN::IsFootprintLibWritable().

◆ Load()

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 322 of file kicad_clipboard.cpp.

324 {
325  std::string result;
326 
327  auto clipboard = wxTheClipboard;
328  wxClipboardLocker clipboardLock( clipboard );
329 
330  if( !clipboardLock )
331  return nullptr;
332 
333  if( clipboard->IsSupported( wxDF_TEXT ) )
334  {
335  wxTextDataObject data;
336  clipboard->GetData( data );
337 
338  result = data.GetText().mb_str();
339  }
340 
341  STRING_LINE_READER reader(result, wxT( "clipboard" ) );
342 
343  init( aProperties );
344 
345  m_parser->SetLineReader( &reader );
346  m_parser->SetBoard( aAppendToMe );
347 
348  BOARD_ITEM* item;
349  BOARD* board;
350 
351  try
352  {
353  item = m_parser->Parse();
354  }
355  catch( const FUTURE_FORMAT_ERROR& )
356  {
357  // Don't wrap a FUTURE_FORMAT_ERROR in another
358  throw;
359  }
360  catch( const PARSE_ERROR& parse_error )
361  {
362  if( m_parser->IsTooRecent() )
363  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
364  else
365  throw;
366  }
367 
368  if( item->Type() != PCB_T )
369  {
370  // The parser loaded something that was valid, but wasn't a board.
371  THROW_PARSE_ERROR( _( "Clipboard content is not KiCad compatible" ),
372  m_parser->CurSource(), m_parser->CurLine(),
373  m_parser->CurLineNumber(), m_parser->CurOffset() );
374  }
375  else
376  {
377  board = dynamic_cast<BOARD*>( item );
378  }
379 
380  // Give the filename to the board if it's new
381  if( board && !aAppendToMe )
382  board->SetFileName( aFileName );
383 
384  return board;
385 }
Definition: typeinfo.h:85
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:208
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:344
void SetFileName(const wxString &aFileName)
Definition: class_board.h:253
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:337
CLIPBOARD_PARSER * m_parser
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:363
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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().

◆ Parse() [1/2]

BOARD_ITEM * CLIPBOARD_IO::Parse ( )

Definition at line 247 of file kicad_clipboard.cpp.

248 {
249  BOARD_ITEM* item;
250  wxString result;
251 
252  auto clipboard = wxTheClipboard;
253  wxClipboardLocker clipboardLock( clipboard );
254 
255  if( !clipboardLock )
256  return nullptr;
257 
258 
259  if( clipboard->IsSupported( wxDF_TEXT ) )
260  {
261  wxTextDataObject data;
262  clipboard->GetData( data );
263  result = data.GetText();
264  }
265 
266  try
267  {
268  item = PCB_IO::Parse( result );
269  }
270  catch (...)
271  {
272  item = nullptr;
273  }
274 
275  return item;
276 }
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...

References PCB_IO::Parse().

Referenced by PCBNEW_CONTROL::Paste().

◆ Parse() [2/2]

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

Definition at line 378 of file kicad_plugin.cpp.

379 {
380  std::string input = TO_UTF8( aClipboardSourceInput );
381 
382  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
383 
384  m_parser->SetLineReader( &reader );
385 
386  try
387  {
388  return m_parser->Parse();
389  }
390  catch( const PARSE_ERROR& parse_error )
391  {
392  if( m_parser->IsTooRecent() )
393  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
394  else
395  throw;
396  }
397 }
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:208
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:337
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:363
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
#define TO_UTF8(wxstring)
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254

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

Referenced by Parse(), and parse_module_kicad().

◆ PluginName()

const wxString PCB_IO::PluginName ( ) const
inlineoverridevirtualinherited

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

Implements PLUGIN.

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

115  {
116  return wxT( "KiCad" );
117  }

◆ PrefetchLib()

void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

performing downloads). Does not parse. Threadsafe.

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

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

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

Reimplemented in GITHUB_PLUGIN.

Definition at line 68 of file plugin.cpp.

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

◆ Save()

void 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 279 of file kicad_clipboard.cpp.

281 {
282  init( aProperties );
283 
284  m_board = aBoard; // after init()
285 
286  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
287  m_mapping->SetBoard( aBoard );
288 
289  STRING_FORMATTER formatter;
290 
291  m_out = &formatter;
292 
293  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
294  formatter.Quotew( GetBuildVersion() ).c_str() );
295 
296  Format( aBoard, 1 );
297 
298  m_out->Print( 0, ")\n" );
299 
300  auto clipboard = wxTheClipboard;
301  wxClipboardLocker clipboardLock( clipboard );
302 
303  if( !clipboardLock )
304  return;
305 
306  clipboard->SetData( new wxTextDataObject(
307  wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
308  clipboard->Flush();
309 
310  // This section exists to return the clipboard data, ensuring it has fully
311  // been processed by the system clipboard. This appears to be needed for
312  // extremely large clipboard copies on asynchronous linux clipboard managers
313  // such as KDE's Klipper
314  {
315  wxTextDataObject data;
316  clipboard->GetData( data );
317  ( void )data.GetText(); // Keep unused variable
318  }
319 }
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:296
wxString GetBuildVersion()
Get the full KiCad version string.
const std::string & GetString()
Definition: richio.h:475
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
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
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:445

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.

◆ SaveSelection()

void CLIPBOARD_IO::SaveSelection ( const PCBNEW_SELECTION selected,
bool  isModEdit 
)

Definition at line 67 of file kicad_clipboard.cpp.

68 {
69  VECTOR2I refPoint( 0, 0 );
70 
71  // dont even start if the selection is empty
72  if( aSelected.Empty() )
73  return;
74 
75  if( aSelected.HasReferencePoint() )
76  refPoint = aSelected.GetReferencePoint();
77 
78  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
80 
81  if( aSelected.Size() == 1 && aSelected.Front()->Type() == PCB_MODULE_T )
82  {
83  // make the module safe to transfer to other pcbs
84  const MODULE* mod = static_cast<MODULE*>( aSelected.Front() );
85  // Do not modify existing board
86  MODULE newModule( *mod );
87 
88  for( D_PAD* pad : newModule.Pads() )
89  pad->SetNetCode( 0 );
90 
91  // locked means "locked in place"; copied items therefore can't be locked
92  newModule.SetLocked( false );
93 
94  // locate the reference point at (0, 0) in the copied items
95  newModule.Move( wxPoint( -refPoint.x, -refPoint.y ) );
96 
97  Format( static_cast<BOARD_ITEM*>( &newModule ) );
98  }
99  else if( isModEdit )
100  {
101  MODULE partialModule( m_board );
102 
103  for( const EDA_ITEM* item : aSelected )
104  {
105  BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( item->Clone() );
106 
107  // Do not add reference/value - convert them to the common type
108  if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
109  text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
110 
111  // If it is only a module, clear the nets from the pads
112  if( D_PAD* pad = dyn_cast<D_PAD*>( clone ) )
113  pad->SetNetCode( 0 );
114 
115  // Add the pad to the new module before moving to ensure the local coords are correct
116  partialModule.Add( clone );
117 
118  // locate the reference point at (0, 0) in the copied items
119  clone->Move( (wxPoint) -refPoint );
120  }
121 
122  // Set the new relative internal local coordinates of copied items
123  MODULE* editedModule = m_board->Modules().front();
124  wxPoint moveVector = partialModule.GetPosition() + editedModule->GetPosition();
125 
126  partialModule.MoveAnchorPosition( moveVector );
127 
128  Format( &partialModule, 0 );
129  }
130  else
131  {
132  // we will fake being a .kicad_pcb to get the full parser kicking
133  // This means we also need layers and nets
134  LOCALE_IO io;
135 
136  m_formatter.Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n",
138  m_formatter.Quotew( GetBuildVersion() ).c_str() );
139 
140  m_formatter.Print( 0, "\n" );
141 
144 
145  m_formatter.Print( 0, "\n" );
146 
147  for( EDA_ITEM* i : aSelected )
148  {
149  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
150  BOARD_ITEM* copy = nullptr;
151 
152  if( item->Type() == PCB_MODULE_EDGE_T )
153  {
154  // Convert to PCB_LINE_T
155  copy = (BOARD_ITEM*) reinterpret_cast<DRAWSEGMENT*>( item )->Clone();
156  copy->SetLayer( item->GetLayer() );
157  }
158  else if( item->Type() == PCB_MODULE_TEXT_T )
159  {
160  // Convert to PCB_TEXT_T
161  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
162  TEXTE_MODULE* mod_text = static_cast<TEXTE_MODULE*>( item );
163  TEXTE_PCB* pcb_text = new TEXTE_PCB( m_board );
164 
165  if( mod_text->GetText() == "${VALUE}" )
166  pcb_text->SetText( mod->GetValue() );
167  else if( mod_text->GetText() == "${REFERENCE}" )
168  pcb_text->SetText( mod->GetReference() );
169  else
170  pcb_text->CopyText( *mod_text );
171 
172  pcb_text->SetEffects( *mod_text );
173  pcb_text->SetLayer( mod_text->GetLayer() );
174  copy = pcb_text;
175  }
176  else if( item->Type() == PCB_PAD_T )
177  {
178  // Create a parent to own the copied pad
179  MODULE* mod = new MODULE( m_board );
180  D_PAD* pad = (D_PAD*) item->Clone();
181 
182  mod->SetPosition( pad->GetPosition() );
183  pad->SetPos0( wxPoint() );
184  mod->Add( pad );
185  copy = mod;
186  }
187  else if( item->Type() == PCB_MODULE_ZONE_AREA_T )
188  {
189  // Convert to PCB_ZONE_AREA_T
190  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
191  zone->InitDataFromSrcInCopyCtor( *static_cast<ZONE_CONTAINER*>( item ) );
192  copy = zone;
193  }
194  else
195  {
196  copy = static_cast<BOARD_ITEM*>( item->Clone() );
197 
198  // locked means "locked in place"; copied items therefore can't be locked
199  if( MODULE* module = dyn_cast<MODULE*>( copy ) )
200  module->SetLocked( false );
201  else if( TRACK* track = dyn_cast<TRACK*>( copy ) )
202  track->SetLocked( false );
203  }
204 
205  if( copy )
206  {
207  // locate the reference point at (0, 0) in the copied items
208  copy->Move( (wxPoint) -refPoint );
209 
210  Format( copy, 1 );
211 
212  delete copy;
213  }
214  }
215  m_formatter.Print( 0, "\n)" );
216  }
217 
218  // These are placed at the end to minimize the open time of the clipboard
219  auto clipboard = wxTheClipboard;
220  wxClipboardLocker clipboardLock( clipboard );
221 
222  if( !clipboardLock || !clipboard->IsOpened() )
223  return;
224 
225  clipboard->SetData( new wxTextDataObject(
226  wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
227 
228  clipboard->Flush();
229 
230  #ifndef __WXOSX__
231  // This section exists to return the clipboard data, ensuring it has fully
232  // been processed by the system clipboard. This appears to be needed for
233  // extremely large clipboard copies on asynchronous linux clipboard managers
234  // such as KDE's Klipper. However, a read back of the data on OSX before the
235  // clipboard is closed seems to cause an ASAN error (heap-buffer-overflow)
236  // since it uses the cached version of the clipboard data and not the system
237  // clipboard data.
238  {
239  wxTextDataObject data;
240  clipboard->GetData( data );
241  ( void )data.GetText(); // Keep unused variable
242  }
243  #endif
244 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
void InitDataFromSrcInCopyCtor(const ZONE_CONTAINER &aZone)
Copy aZone data to me.
Definition: class_zone.cpp:100
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:129
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxPoint GetPosition() const override
Definition: class_pad.h:165
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:137
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:469
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
STRING_FORMATTER m_formatter
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:296
class MODULE, a footprint
Definition: typeinfo.h:89
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
MODULES & Modules()
Definition: class_board.h:266
wxString GetBuildVersion()
Get the full KiCad version string.
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:217
const std::string & GetString()
Definition: richio.h:475
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
void SetPosition(const wxPoint &aPos) override
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
BOARD * m_board
which BOARD, no ownership here
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
wxPoint GetPosition() const override
Definition: class_module.h:216
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References MODULE::Add(), EDA_ITEM::Clone(), EDA_TEXT::CopyText(), SELECTION::Empty(), PCB_IO::Format(), PCB_IO::formatBoardLayers(), PCB_IO::formatNetInformation(), SELECTION::Front(), GetBuildVersion(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetParent(), D_PAD::GetPosition(), MODULE::GetPosition(), MODULE::GetReference(), SELECTION::GetReferencePoint(), STRING_FORMATTER::GetString(), MODULE::GetValue(), SELECTION::HasReferencePoint(), ZONE_CONTAINER::InitDataFromSrcInCopyCtor(), PCB_IO::m_board, m_formatter, PCB_IO::m_mapping, BOARD::Modules(), BOARD_ITEM::Move(), MODULE::MoveAnchorPosition(), PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_MODULE_ZONE_AREA_T, PCB_PAD_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), NETINFO_MAPPING::SetBoard(), EDA_TEXT::SetEffects(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), D_PAD::SetPos0(), MODULE::SetPosition(), EDA_TEXT::SetText(), SEXPR_BOARD_FILE_VERSION, SELECTION::Size(), TEXTE_MODULE::TEXT_is_DIVERS, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDIT_TOOL::copyToClipboard().

◆ SetBoard()

void CLIPBOARD_IO::SetBoard ( BOARD aBoard)

Definition at line 61 of file kicad_clipboard.cpp.

62 {
63  m_board = aBoard;
64 }
BOARD * m_board
which BOARD, no ownership here

References PCB_IO::m_board.

Referenced by EDIT_TOOL::copyToClipboard().

◆ SetOutputFormatter()

void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

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

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

References PCB_IO::m_out.

Referenced by FP_CACHE::Save().

◆ validateCache()

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

Definition at line 1997 of file kicad_plugin.cpp.

1998 {
1999  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2000  {
2001  // a spectacular episode in memory management:
2002  delete m_cache;
2003  m_cache = new FP_CACHE( this, aLibraryPath );
2004  m_cache->Load();
2005  }
2006 }
friend class FP_CACHE
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
void Load()

References 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().

◆ writeHeader()

void CLIPBOARD_IO::writeHeader ( BOARD aBoard)
private

Member Data Documentation

◆ m_board

BOARD* PCB_IO::m_board
protectedinherited

which BOARD, no ownership here

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

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

◆ m_cache

◆ m_ctl

int PCB_IO::m_ctl
protectedinherited

◆ m_error

wxString PCB_IO::m_error
protectedinherited

for throwing exceptions

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

◆ m_filename

wxString PCB_IO::m_filename
protectedinherited

for saves only, name is in m_reader for loads

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

◆ m_formatter

STRING_FORMATTER CLIPBOARD_IO::m_formatter
private

Definition at line 75 of file kicad_clipboard.h.

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

◆ m_loading_format_version

int PCB_IO::m_loading_format_version
protectedinherited

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

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

Referenced by PCB_IO::init().

◆ m_mapping

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

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

◆ m_out

◆ m_parser

CLIPBOARD_PARSER* CLIPBOARD_IO::m_parser
private

Definition at line 76 of file kicad_clipboard.h.

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

◆ m_props

const PROPERTIES* PCB_IO::m_props
protectedinherited

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

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

Referenced by PCB_IO::init().

◆ m_reader

LINE_READER* PCB_IO::m_reader
protectedinherited

no ownership here.

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

Referenced by PCB_IO::init().

◆ m_sf

STRING_FORMATTER PCB_IO::m_sf
protectedinherited

Definition at line 206 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: