KiCad PCB EDA Suite
CLIPBOARD_IO Class Reference

#include <kicad_clipboard.h>

Inheritance diagram for CLIPBOARD_IO:
PCB_PLUGIN PLUGIN

Public Member Functions

 CLIPBOARD_IO ()
 
 ~CLIPBOARD_IO ()
 
void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=nullptr) override
 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 PCB_SELECTION &selected, bool isFootprintEditor)
 
BOARD_ITEMParse ()
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
 Load information from some input file format that this PLUGIN implementation knows about into either a new BOARD or an existing one. More...
 
void SetBoard (BOARD *aBoard)
 
const wxString PluginName () const override
 Return a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the PLUGIN. More...
 
BOARDDoLoad (LINE_READER &aReader, BOARD *aAppendToMe, const PROPERTIES *aProperties, PROGRESS_REPORTER *aProgressReporter, unsigned aLineCount)
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
const FOOTPRINTGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr) override
 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=nullptr) override
 Check for the existence of a footprint. More...
 
FOOTPRINTFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
 Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. More...
 
void FootprintSave (const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const PROPERTIES *aProperties=nullptr) override
 Write aFootprint to an existing library located at aLibraryPath. More...
 
void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr) override
 Delete 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=nullptr) override
 Create a new empty footprint library at aLibraryPath empty. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete 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
 Return true if the library at aLibraryPath is writable. More...
 
void Format (const BOARD_ITEM *aItem, int aNestLevel=0) const
 Output aItem to aFormatter in s-expression format. More...
 
std::string GetStringOutput (bool doClear)
 
void SetOutputFormatter (OUTPUTFORMATTER *aFormatter)
 
BOARD_ITEMParse (const wxString &aClipboardSourceInput)
 
virtual std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints ()
 Return a container with the cached library footprints generated in the last call to Load. More...
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Protected Member Functions

void validateCache (const wxString &aLibraryPath, bool checkModified=true)
 
const FOOTPRINTgetFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
 
void init (const PROPERTIES *aProperties)
 
void formatSetup (const BOARD *aBoard, int aNestLevel=0) const
 formats the board setup information More...
 
void formatGeneral (const BOARD *aBoard, int aNestLevel=0) const
 formats the General section of the file More...
 
void formatBoardLayers (const BOARD *aBoard, int aNestLevel=0) const
 formats the board layer information More...
 
void formatNetInformation (const BOARD *aBoard, int aNestLevel=0) const
 formats the Nets and Netclasses More...
 
void formatProperties (const BOARD *aBoard, int aNestLevel=0) const
 formats the Nets and Netclasses More...
 
void formatHeader (const 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...
 
STRING_FORMATTER m_sf
 
OUTPUTFORMATTERm_out
 output any Format()s to this, no ownership More...
 
int m_ctl
 
PCB_PARSERm_parser
 
NETINFO_MAPPINGm_mapping
 mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes More...
 

Private Attributes

STRING_FORMATTER m_formatter
 

Detailed Description

Definition at line 41 of file kicad_clipboard.h.

Constructor & Destructor Documentation

◆ CLIPBOARD_IO()

CLIPBOARD_IO::CLIPBOARD_IO ( )

Definition at line 44 of file kicad_clipboard.cpp.

44  :
46  m_formatter()
47 {
48  m_out = &m_formatter;
49 }
#define CTL_FOR_CLIPBOARD
Format output for the clipboard instead of footprint library or BOARD.
Definition: pcb_plugin.h:125
STRING_FORMATTER m_formatter
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
PCB_PLUGIN(int aControlFlags=CTL_FOR_BOARD)

References m_formatter, and PCB_PLUGIN::m_out.

◆ ~CLIPBOARD_IO()

CLIPBOARD_IO::~CLIPBOARD_IO ( )

Definition at line 52 of file kicad_clipboard.cpp.

53 {
54 }

Member Function Documentation

◆ DoLoad()

BOARD * PCB_PLUGIN::DoLoad ( LINE_READER aReader,
BOARD aAppendToMe,
const PROPERTIES aProperties,
PROGRESS_REPORTER aProgressReporter,
unsigned  aLineCount 
)
inherited

Definition at line 2318 of file pcb_plugin.cpp.

2320 {
2321  init( aProperties );
2322 
2323  m_parser->SetLineReader( &aReader );
2324  m_parser->SetBoard( aAppendToMe );
2325  m_parser->SetProgressReporter( aProgressReporter, &aReader, aLineCount );
2326 
2327  BOARD* board;
2328 
2329  try
2330  {
2331  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2332  }
2333  catch( const FUTURE_FORMAT_ERROR& )
2334  {
2335  // Don't wrap a FUTURE_FORMAT_ERROR in another
2336  throw;
2337  }
2338  catch( const PARSE_ERROR& parse_error )
2339  {
2340  if( m_parser->IsTooRecent() )
2341  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2342  else
2343  throw;
2344  }
2345 
2346  if( !board )
2347  {
2348  // The parser loaded something that was valid, but wasn't a board.
2349  THROW_PARSE_ERROR( _( "This file does not contain a PCB." ), m_parser->CurSource(),
2350  m_parser->CurLine(), m_parser->CurLineNumber(), m_parser->CurOffset() );
2351  }
2352 
2353  return board;
2354 }
void SetProgressReporter(PROGRESS_REPORTER *aProgressReporter, const LINE_READER *aLineReader, unsigned aLineCount)
Definition: pcb_parser.h:111
void init(const PROPERTIES *aProperties)
PCB_PARSER * m_parser
Definition: pcb_plugin.h:296
wxString GetRequiredVersion()
Return a string representing the version of KiCad required to open this file.
Definition: pcb_parser.cpp:246
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:102
#define _(s)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:626
LINE_READER * SetLineReader(LINE_READER *aReader)
Set aLineReader into the parser, and returns the previous one, if any.
Definition: pcb_parser.h:95
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:133
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:174

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

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

◆ FootprintDelete()

void PCB_PLUGIN::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Delete 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 2576 of file pcb_plugin.cpp.

2578 {
2579  LOCALE_IO toggle; // toggles on, then off, the C locale.
2580 
2581  init( aProperties );
2582 
2583  validateCache( aLibraryPath );
2584 
2585  if( !m_cache->IsWritable() )
2586  {
2587  THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
2588  aLibraryPath.GetData() ) );
2589  }
2590 
2591  m_cache->Remove( aFootprintName );
2592 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(const PROPERTIES *aProperties)
void Remove(const wxString &aFootprintName)
Definition: pcb_plugin.cpp:297
#define _(s)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool IsWritable() const
Definition: pcb_plugin.cpp:108
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ FootprintEnumerate()

void PCB_PLUGIN::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
bool  aBestEfforts,
const PROPERTIES aProperties = nullptr 
)
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 2377 of file pcb_plugin.cpp.

2379 {
2380  LOCALE_IO toggle; // toggles on, then off, the C locale.
2381  wxDir dir( aLibPath );
2382  wxString errorMsg;
2383 
2384  init( aProperties );
2385 
2386  try
2387  {
2388  validateCache( aLibPath );
2389  }
2390  catch( const IO_ERROR& ioe )
2391  {
2392  errorMsg = ioe.What();
2393  }
2394 
2395  // Some of the files may have been parsed correctly so we want to add the valid files to
2396  // the library.
2397 
2398  for( const auto& footprint : m_cache->GetFootprints() )
2399  aFootprintNames.Add( footprint.first );
2400 
2401  if( !errorMsg.IsEmpty() && !aBestEfforts )
2402  THROW_IO_ERROR( errorMsg );
2403 }
FOOTPRINT_MAP & GetFootprints()
Definition: pcb_plugin.cpp:112
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(const PROPERTIES *aProperties)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ FootprintExists()

bool PCB_PLUGIN::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Check for the existence of a footprint.

Reimplemented from PLUGIN.

Definition at line 2442 of file pcb_plugin.cpp.

2444 {
2445  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2446  // only in case.
2447  //
2448  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2449  // case-insensitive filesystem) handled "for free".
2450  // Warning: footprint names frequently contain a point. So be careful when initializing
2451  // wxFileName, and use a CTOR with extension specified
2452  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2453 
2454  return footprintFile.Exists();
2455 }
const std::string KiCadFootprintFileExtension

References KiCadFootprintFileExtension.

◆ FootprintLibCreate()

void PCB_PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Create 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 2602 of file pcb_plugin.cpp.

2603 {
2604  if( wxDir::Exists( aLibraryPath ) )
2605  {
2606  THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path '%s'." ),
2607  aLibraryPath.GetData() ) );
2608  }
2609 
2610  LOCALE_IO toggle;
2611 
2612  init( aProperties );
2613 
2614  delete m_cache;
2615  m_cache = new FP_CACHE( this, aLibraryPath );
2616  m_cache->Save();
2617 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save(FOOTPRINT *aFootprint=nullptr)
Save the footprint cache or a single footprint from it to disk.
Definition: pcb_plugin.cpp:166
void init(const PROPERTIES *aProperties)
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
friend class FP_CACHE
Definition: pcb_plugin.h:280
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ FootprintLibDelete()

bool PCB_PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Delete 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
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 2620 of file pcb_plugin.cpp.

2621 {
2622  wxFileName fn;
2623  fn.SetPath( aLibraryPath );
2624 
2625  // Return if there is no library path to delete.
2626  if( !fn.DirExists() )
2627  return false;
2628 
2629  if( !fn.IsDirWritable() )
2630  {
2631  THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete folder '%s'." ),
2632  aLibraryPath.GetData() ) );
2633  }
2634 
2635  wxDir dir( aLibraryPath );
2636 
2637  if( dir.HasSubDirs() )
2638  {
2639  THROW_IO_ERROR( wxString::Format( _( "Library folder '%s' has unexpected sub-folders." ),
2640  aLibraryPath.GetData() ) );
2641  }
2642 
2643  // All the footprint files must be deleted before the directory can be deleted.
2644  if( dir.HasFiles() )
2645  {
2646  unsigned i;
2647  wxFileName tmp;
2648  wxArrayString files;
2649 
2650  wxDir::GetAllFiles( aLibraryPath, &files );
2651 
2652  for( i = 0; i < files.GetCount(); i++ )
2653  {
2654  tmp = files[i];
2655 
2656  if( tmp.GetExt() != KiCadFootprintFileExtension )
2657  {
2658  THROW_IO_ERROR( wxString::Format( _( "Unexpected file '%s' found in library "
2659  "path '%s'." ),
2660  files[i].GetData(),
2661  aLibraryPath.GetData() ) );
2662  }
2663  }
2664 
2665  for( i = 0; i < files.GetCount(); i++ )
2666  wxRemoveFile( files[i] );
2667  }
2668 
2669  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library '%s'." ),
2670  aLibraryPath.GetData() );
2671 
2672  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2673  // we don't want that. we want bare metal portability with no UI here.
2674  if( !wxRmdir( aLibraryPath ) )
2675  {
2676  THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
2677  aLibraryPath.GetData() ) );
2678  }
2679 
2680  // For some reason removing a directory in Windows is not immediately updated. This delay
2681  // prevents an error when attempting to immediately recreate the same directory when over
2682  // writing an existing library.
2683 #ifdef __WINDOWS__
2684  wxMilliSleep( 250L );
2685 #endif
2686 
2687  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2688  {
2689  delete m_cache;
2690  m_cache = nullptr;
2691  }
2692 
2693  return true;
2694 }
const std::string KiCadFootprintFileExtension
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
Definition: pcb_plugin.cpp:316
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append 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
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 EAGLE_PLUGIN.

Definition at line 147 of file plugin.cpp.

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

References _.

Referenced by EAGLE_PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

FOOTPRINT * PCB_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
bool  aKeepUUID = false,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Load 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.
aKeepUUID= true to keep initial items UUID, false to set new UUID normally true if loaded in the footprint editor, false if loaded in the board editor. Make sense only in kicad_plugin
Returns
the FOOTPRINT object 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 2458 of file pcb_plugin.cpp.

2462 {
2463  const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2464 
2465  if( footprint )
2466  {
2467  FOOTPRINT* copy;
2468 
2469  if( aKeepUUID )
2470  copy = static_cast<FOOTPRINT*>( footprint->Clone() );
2471  else
2472  copy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
2473 
2474  copy->SetParent( nullptr );
2475  return copy;
2476  }
2477 
2478  return nullptr;
2479 }
BOARD_ITEM * Duplicate() const override
Create a copy of this BOARD_ITEM.
Definition: footprint.cpp:1724
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: footprint.cpp:1292
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References FOOTPRINT::Clone(), copy, FOOTPRINT::Duplicate(), and PCB_PLUGIN::getFootprint().

◆ FootprintSave()

void PCB_PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const FOOTPRINT aFootprint,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

Write aFootprint 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 2482 of file pcb_plugin.cpp.

2484 {
2485  LOCALE_IO toggle; // toggles on, then off, the C locale.
2486 
2487  init( aProperties );
2488 
2489  // In this public PLUGIN API function, we can safely assume it was
2490  // called for saving into a library path.
2492 
2493  validateCache( aLibraryPath );
2494 
2495  if( !m_cache->IsWritable() )
2496  {
2497  if( !m_cache->Exists() )
2498  {
2499  const wxString msg = wxString::Format( _( "Library '%s' does not exist.\n"
2500  "Would you like to create it?"),
2501  aLibraryPath );
2502 
2503  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2504  return;
2505 
2506  // Save throws its own IO_ERROR on failure, so no need to recreate here
2507  m_cache->Save( nullptr );
2508  }
2509  else
2510  {
2511  wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibraryPath );
2512  THROW_IO_ERROR( msg );
2513  }
2514  }
2515 
2516  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2517 
2518  FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
2519 
2520  // Quietly overwrite footprint and delete footprint file from path for any by same name.
2521  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2523 
2524  // Write through symlinks, don't replace them
2526 
2527  if( !fn.IsOk() )
2528  {
2529  THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
2530  fn.GetFullPath() ) );
2531  }
2532 
2533  if( fn.FileExists() && !fn.IsFileWritable() )
2534  {
2535  THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete '%s'." ),
2536  fn.GetFullPath() ) );
2537  }
2538 
2539  wxString fullPath = fn.GetFullPath();
2540  wxString fullName = fn.GetFullName();
2541  FOOTPRINT_MAP::const_iterator it = footprints.find( footprintName );
2542 
2543  if( it != footprints.end() )
2544  {
2545  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2546  footprints.erase( footprintName );
2547  wxRemoveFile( fullPath );
2548  }
2549 
2550  // I need my own copy for the cache
2551  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aFootprint->Clone() );
2552 
2553  // It's orientation should be zero and it should be on the front layer.
2554  footprint->SetOrientation( 0 );
2555 
2556  if( footprint->GetLayer() != F_Cu )
2557  {
2558  PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2559 
2560  if( cfg )
2561  footprint->Flip( footprint->GetPosition(), cfg->m_FlipLeftRight );
2562  else
2563  footprint->Flip( footprint->GetPosition(), false );
2564  }
2565 
2566  // Detach it from the board
2567  footprint->SetParent( nullptr );
2568 
2569  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2570  footprints.insert( footprintName,
2571  new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) );
2572  m_cache->Save( footprint );
2573 }
FOOTPRINT_MAP & GetFootprints()
Definition: pcb_plugin.cpp:112
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save(FOOTPRINT *aFootprint=nullptr)
Save the footprint cache or a single footprint from it to disk.
Definition: pcb_plugin.cpp:166
const std::string KiCadFootprintFileExtension
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void init(const PROPERTIES *aProperties)
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
void SetOrientation(double aNewAngle)
Definition: footprint.cpp:1680
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1490
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Definition: wx_filename.cpp:85
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define _(s)
const LIB_ID & GetFPID() const
Definition: footprint.h:194
Helper class for creating a footprint library cache.
Definition: pcb_plugin.cpp:69
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool IsWritable() const
Definition: pcb_plugin.cpp:108
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: wx_filename.h:36
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:50
Definition: layer_ids.h:71
wxPoint GetPosition() const override
Definition: footprint.h:186
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: footprint.cpp:1292
bool Exists() const
Definition: pcb_plugin.cpp:110
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:142
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
Definition: pcb_plugin.h:128

References _, FOOTPRINT::Clone(), CTL_FOR_LIBRARY, FP_CACHE::Exists(), F_Cu, FOOTPRINT::Flip(), Format(), FP_CACHE::GetFootprints(), FOOTPRINT::GetFPID(), BOARD_ITEM::GetLayer(), LIB_ID::GetLibItemName(), FOOTPRINT::GetPosition(), PCB_PLUGIN::init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, Kiface(), PCB_PLUGIN::m_cache, PCB_PLUGIN::m_ctl, PCBNEW_SETTINGS::m_FlipLeftRight, WX_FILENAME::ResolvePossibleSymlinks(), FP_CACHE::Save(), FOOTPRINT::SetOrientation(), EDA_ITEM::SetParent(), THROW_IO_ERROR, traceKicadPcbPlugin, and PCB_PLUGIN::validateCache().

◆ Format()

void PCB_PLUGIN::Format ( const BOARD_ITEM aItem,
int  aNestLevel = 0 
) const
inherited

Output aItem to aFormatter in s-expression format.

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

Definition at line 400 of file pcb_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<const BOARD*>( aItem ), aNestLevel );
408  break;
409 
410  case PCB_DIM_ALIGNED_T:
411  case PCB_DIM_CENTER_T:
413  case PCB_DIM_LEADER_T:
414  format( static_cast<const PCB_DIMENSION_BASE*>( aItem ), aNestLevel );
415  break;
416 
417  case PCB_SHAPE_T:
418  format( static_cast<const PCB_SHAPE*>( aItem ), aNestLevel );
419  break;
420 
421  case PCB_FP_SHAPE_T:
422  format( static_cast<const FP_SHAPE*>( aItem ), aNestLevel );
423  break;
424 
425  case PCB_TARGET_T:
426  format( static_cast<const PCB_TARGET*>( aItem ), aNestLevel );
427  break;
428 
429  case PCB_FOOTPRINT_T:
430  format( static_cast<const FOOTPRINT*>( aItem ), aNestLevel );
431  break;
432 
433  case PCB_PAD_T:
434  format( static_cast<const PAD*>( aItem ), aNestLevel );
435  break;
436 
437  case PCB_TEXT_T:
438  format( static_cast<const PCB_TEXT*>( aItem ), aNestLevel );
439  break;
440 
441  case PCB_FP_TEXT_T:
442  format( static_cast<const FP_TEXT*>( aItem ), aNestLevel );
443  break;
444 
445  case PCB_GROUP_T:
446  format( static_cast<const PCB_GROUP*>( aItem ), aNestLevel );
447  break;
448 
449  case PCB_TRACE_T:
450  case PCB_ARC_T:
451  case PCB_VIA_T:
452  format( static_cast<const PCB_TRACK*>( aItem ), aNestLevel );
453  break;
454 
455  case PCB_FP_ZONE_T:
456  case PCB_ZONE_T:
457  format( static_cast<const ZONE*>( aItem ), aNestLevel );
458  break;
459 
460  default:
461  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
462  }
463 }
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
Definition: typeinfo.h:84
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void format(const BOARD *aBoard, int aNestLevel=0) const
Definition: pcb_plugin.cpp:660
class ZONE, a copper pour area
Definition: typeinfo.h:105
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual wxString GetClass() const =0
Return the class name.
class ZONE, managed by a footprint
Definition: typeinfo.h:94
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References PCB_PLUGIN::format(), EDA_ITEM::GetClass(), PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, PCB_SHAPE_T, PCB_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, and EDA_ITEM::Type().

Referenced by FOOTPRINT_EDIT_FRAME::ExportFootprint(), PCB_PLUGIN::format(), Save(), FP_CACHE::Save(), PCB_PLUGIN::Save(), and SaveSelection().

◆ formatBoardLayers()

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

formats the board layer information

Definition at line 542 of file pcb_plugin.cpp.

543 {
544  m_out->Print( aNestLevel, "(layers\n" );
545 
546  // Save only the used copper layers from front to back.
547 
548  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
549  {
550  PCB_LAYER_ID layer = *cu;
551 
552  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
553  m_out->Quotew( LSET::Name( layer ) ).c_str(),
554  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
555 
556  if( LSET::Name( layer ) != m_board->GetLayerName( layer ) )
557  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
558 
559  m_out->Print( 0, ")\n" );
560  }
561 
562  // Save used non-copper layers in the order they are defined.
563  // desired sequence for non Cu BOARD layers.
564  static const PCB_LAYER_ID non_cu[] =
565  {
566  B_Adhes, // 32
567  F_Adhes,
568  B_Paste,
569  F_Paste,
570  B_SilkS,
571  F_SilkS,
572  B_Mask,
573  F_Mask,
574  Dwgs_User,
575  Cmts_User,
576  Eco1_User,
577  Eco2_User,
578  Edge_Cuts,
579  Margin,
580  B_CrtYd,
581  F_CrtYd,
582  B_Fab,
583  F_Fab,
584  User_1,
585  User_2,
586  User_3,
587  User_4,
588  User_5,
589  User_6,
590  User_7,
591  User_8,
592  User_9
593  };
594 
595  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
596  {
597  PCB_LAYER_ID layer = *seq;
598 
599  m_out->Print( aNestLevel+1, "(%d %s user", layer,
600  m_out->Quotew( LSET::Name( layer ) ).c_str() );
601 
602  if( m_board->GetLayerName( layer ) != LSET::Name( layer ) )
603  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
604 
605  m_out->Print( 0, ")\n" );
606  }
607 
608  m_out->Print( aNestLevel, ")\n\n" );
609 }
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:170
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:362
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:467
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
Definition: board.cpp:427
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:284
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:465
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition: board.cpp:396
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

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

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

◆ formatGeneral()

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

formats the General section of the file

Definition at line 526 of file pcb_plugin.cpp.

527 {
528  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
529 
530  m_out->Print( 0, "\n" );
531  m_out->Print( aNestLevel, "(general\n" );
532  m_out->Print( aNestLevel+1, "(thickness %s)\n",
533  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
534 
535  m_out->Print( aNestLevel, ")\n\n" );
536 
537  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
538  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
539 }
const PAGE_INFO & GetPageSettings() const
Definition: board.h:536
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:271
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:29
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:542
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:485
Container for design settings for a BOARD object.

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

Referenced by PCB_PLUGIN::formatHeader().

◆ formatHeader()

void PCB_PLUGIN::formatHeader ( const BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

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

Definition at line 642 of file pcb_plugin.cpp.

643 {
644  formatGeneral( aBoard, aNestLevel );
645 
646  // Layers list.
647  formatBoardLayers( aBoard, aNestLevel );
648 
649  // Setup
650  formatSetup( aBoard, aNestLevel );
651 
652  // Properties
653  formatProperties( aBoard, aNestLevel );
654 
655  // Save net codes and names
656  formatNetInformation( aBoard, aNestLevel );
657 }
void formatSetup(const BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
Definition: pcb_plugin.cpp:474
void formatGeneral(const BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
Definition: pcb_plugin.cpp:526
void formatBoardLayers(const BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
Definition: pcb_plugin.cpp:542
void formatProperties(const BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Definition: pcb_plugin.cpp:628
void formatNetInformation(const BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Definition: pcb_plugin.cpp:612

References PCB_PLUGIN::formatBoardLayers(), PCB_PLUGIN::formatGeneral(), PCB_PLUGIN::formatNetInformation(), PCB_PLUGIN::formatProperties(), and PCB_PLUGIN::formatSetup().

Referenced by PCB_PLUGIN::format().

◆ formatNetInformation()

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

formats the Nets and Netclasses

Definition at line 612 of file pcb_plugin.cpp.

613 {
614  for( NETINFO_ITEM* net : *m_mapping )
615  {
616  if( net == nullptr ) // Skip not actually existing nets (orphan nets)
617  continue;
618 
619  m_out->Print( aNestLevel, "(net %d %s)\n",
620  m_mapping->Translate( net->GetNetCode() ),
621  m_out->Quotew( net->GetNetname() ).c_str() );
622  }
623 
624  m_out->Print( 0, "\n" );
625 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
Definition: pcb_plugin.h:297
Handle the data for a net.
Definition: netinfo.h:66
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

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

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

◆ formatProperties()

void PCB_PLUGIN::formatProperties ( const BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the Nets and Netclasses

Definition at line 628 of file pcb_plugin.cpp.

629 {
630  for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
631  {
632  m_out->Print( aNestLevel, "(property %s %s)\n",
633  m_out->Quotew( prop.first ).c_str(),
634  m_out->Quotew( prop.second ).c_str() );
635  }
636 
637  if( !aBoard->GetProperties().empty() )
638  m_out->Print( 0, "\n" );
639 }
const std::map< wxString, wxString > & GetProperties() const
Definition: board.h:259
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

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

Referenced by PCB_PLUGIN::formatHeader().

◆ formatSetup()

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

formats the board setup information

Definition at line 474 of file pcb_plugin.cpp.

475 {
476  // Setup
477  m_out->Print( aNestLevel, "(setup\n" );
478 
479  // Save the board physical stackup structure
480  const BOARD_STACKUP& stackup = aBoard->GetDesignSettings().GetStackupDescriptor();
481 
482  if( aBoard->GetDesignSettings().m_HasStackup )
483  stackup.FormatBoardStackup( m_out, aBoard, aNestLevel+1 );
484 
485  BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
486 
487  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
488  FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
489 
490  if( dsnSettings.m_SolderMaskMinWidth )
491  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
492  FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
493 
494  if( dsnSettings.m_SolderPasteMargin != 0 )
495  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
496  FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
497 
498  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
499  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
500  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
501 
502  wxPoint origin = dsnSettings.GetAuxOrigin();
503 
504  if( origin != wxPoint( 0, 0 ) )
505  {
506  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
507  FormatInternalUnits( origin.x ).c_str(),
508  FormatInternalUnits( origin.y ).c_str() );
509  }
510 
511  origin = dsnSettings.GetGridOrigin();
512 
513  if( origin != wxPoint( 0, 0 ) )
514  {
515  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
516  FormatInternalUnits( origin.x ).c_str(),
517  FormatInternalUnits( origin.y ).c_str() );
518  }
519 
520  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
521 
522  m_out->Print( aNestLevel, ")\n\n" );
523 }
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: board.h:539
Manage layers needed to make a physical board.
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
const wxPoint & GetGridOrigin()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
BOARD_STACKUP & GetStackupDescriptor()
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard, int aNestLevel) const
Write the stackup info on board file.
const wxPoint & GetAuxOrigin()
std::string Double2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 We want to avoid scientific ...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:485
Container for design settings for a BOARD object.

References Double2Str(), PCB_PLOT_PARAMS::Format(), BOARD_STACKUP::FormatBoardStackup(), FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetAuxOrigin(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetGridOrigin(), BOARD::GetPlotOptions(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_DESIGN_SETTINGS::m_HasStackup, PCB_PLUGIN::m_out, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, and OUTPUTFORMATTER::Print().

Referenced by PCB_PLUGIN::formatHeader().

◆ GetEnumeratedFootprint()

const FOOTPRINT * PCB_PLUGIN::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = nullptr 
)
overridevirtualinherited

A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented from PLUGIN.

Definition at line 2434 of file pcb_plugin.cpp.

2437 {
2438  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2439 }
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References PCB_PLUGIN::getFootprint().

◆ GetFileExtension()

const wxString PCB_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtualinherited

Returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 149 of file pcb_plugin.h.

150  {
151  // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
152  // but to be pure, a plugin should not assume that it will always be linked
153  // with the core of the Pcbnew code. (Might someday be a DLL/DSO.) Besides,
154  // file extension policy should be controlled by the plugin.
155  return wxT( "kicad_pcb" );
156  }

◆ getFootprint()

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

Definition at line 2406 of file pcb_plugin.cpp.

2410 {
2411  LOCALE_IO toggle; // toggles on, then off, the C locale.
2412 
2413  init( aProperties );
2414 
2415  try
2416  {
2417  validateCache( aLibraryPath, checkModified );
2418  }
2419  catch( const IO_ERROR& )
2420  {
2421  // do nothing with the error
2422  }
2423 
2424  FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
2425  FOOTPRINT_MAP::const_iterator it = footprints.find( aFootprintName );
2426 
2427  if( it == footprints.end() )
2428  return nullptr;
2429 
2430  return it->second->GetFootprint();
2431 }
FOOTPRINT_MAP & GetFootprints()
Definition: pcb_plugin.cpp:112
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:50
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75

References FP_CACHE::GetFootprints(), PCB_PLUGIN::init(), PCB_PLUGIN::m_cache, and PCB_PLUGIN::validateCache().

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

◆ GetImportedCachedLibraryFootprints()

std::vector< FOOTPRINT * > PLUGIN::GetImportedCachedLibraryFootprints ( )
virtualinherited

Return a container with the cached library footprints generated in the last call to Load.

This function is intended to be used ONLY by the non-KiCad board importers for the purpose of obtaining the footprint library of the design and creating a project-specific library.

Returns
Footprints (caller owns the objects)

Reimplemented in EAGLE_PLUGIN, and CADSTAR_PCB_ARCHIVE_PLUGIN.

Definition at line 54 of file plugin.cpp.

55 {
56  not_implemented( this, __FUNCTION__ );
57  return std::vector<FOOTPRINT*>();
58 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

Referenced by PCB_EDIT_FRAME::OpenProjectFiles().

◆ GetLibraryTimestamp()

long long PCB_PLUGIN::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 2596 of file pcb_plugin.cpp.

2597 {
2598  return FP_CACHE::GetTimestamp( aLibraryPath );
2599 }
static long long GetTimestamp(const wxString &aLibPath)
Generate a timestamp representing all source files in the cache (including the parent directory).
Definition: pcb_plugin.cpp:330

References FP_CACHE::GetTimestamp().

◆ GetStringOutput()

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

Definition at line 211 of file pcb_plugin.h.

212  {
213  std::string ret = m_sf.GetString();
214 
215  if( doClear )
216  m_sf.Clear();
217 
218  return ret;
219  }
STRING_FORMATTER m_sf
Definition: pcb_plugin.h:293
const std::string & GetString()
Definition: richio.h:438
void Clear()
Clear the buffer and empties the internal string.
Definition: richio.h:428

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

Referenced by FOOTPRINT_EDIT_FRAME::ExportFootprint().

◆ init()

void PCB_PLUGIN::init ( const PROPERTIES aProperties)
protectedinherited

Definition at line 2357 of file pcb_plugin.cpp.

2358 {
2359  m_board = nullptr;
2360  m_reader = nullptr;
2361  m_props = aProperties;
2362 }
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: pcb_plugin.h:287
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:284
LINE_READER * m_reader
no ownership here.
Definition: pcb_plugin.h:290

References PCB_PLUGIN::m_board, PCB_PLUGIN::m_props, and PCB_PLUGIN::m_reader.

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

◆ IsFootprintLibWritable()

bool PCB_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtualinherited

Return true if the library at aLibraryPath is writable.

The system libraries are typically 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 2697 of file pcb_plugin.cpp.

2698 {
2699  LOCALE_IO toggle;
2700 
2701  init( nullptr );
2702 
2703  validateCache( aLibraryPath );
2704 
2705  return m_cache->IsWritable();
2706 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
bool IsWritable() const
Definition: pcb_plugin.cpp:108
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288

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

◆ Load()

BOARD * CLIPBOARD_IO::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = nullptr,
PROJECT aProject = nullptr,
PROGRESS_REPORTER aProgressReporter = nullptr 
)
overridevirtual

Load 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.
aProjectis the optional PROJECT object primarily used by third party importers.
aProgressReporteran optional progress reporter
aLineCounta line count (necessary if a progress reporter is supplied)
Returns
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 382 of file kicad_clipboard.cpp.

385 {
386  std::string result;
387 
388  wxLogNull doNotLog; // disable logging of failed clipboard actions
389 
390  auto clipboard = wxTheClipboard;
391  wxClipboardLocker clipboardLock( clipboard );
392 
393  if( !clipboardLock )
394  return nullptr;
395 
396  if( clipboard->IsSupported( wxDF_TEXT ) )
397  {
398  wxTextDataObject data;
399  clipboard->GetData( data );
400 
401  result = data.GetText().mb_str();
402  }
403 
404  STRING_LINE_READER reader(result, wxT( "clipboard" ) );
405 
406  init( aProperties );
407 
408  m_parser->SetLineReader( &reader );
409  m_parser->SetBoard( aAppendToMe );
410 
411  BOARD_ITEM* item;
412  BOARD* board;
413 
414  try
415  {
416  item = m_parser->Parse();
417  }
418  catch( const FUTURE_FORMAT_ERROR& )
419  {
420  // Don't wrap a FUTURE_FORMAT_ERROR in another
421  throw;
422  }
423  catch( const PARSE_ERROR& parse_error )
424  {
425  if( m_parser->IsTooRecent() )
426  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
427  else
428  throw;
429  }
430 
431  if( item->Type() != PCB_T )
432  {
433  // The parser loaded something that was valid, but wasn't a board.
434  THROW_PARSE_ERROR( _( "Clipboard content is not KiCad compatible" ),
435  m_parser->CurSource(), m_parser->CurLine(),
436  m_parser->CurLineNumber(), m_parser->CurOffset() );
437  }
438  else
439  {
440  board = dynamic_cast<BOARD*>( item );
441  }
442 
443  // Give the filename to the board if it's new
444  if( board && !aAppendToMe )
445  board->SetFileName( aFileName );
446 
447  return board;
448 }
Definition: typeinfo.h:84
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void init(const PROPERTIES *aProperties)
PCB_PARSER * m_parser
Definition: pcb_plugin.h:296
wxString GetRequiredVersion()
Return a string representing the version of KiCad required to open this file.
Definition: pcb_parser.cpp:246
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:102
#define _(s)
void SetFileName(const wxString &aFileName)
Definition: board.h:227
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:626
LINE_READER * SetLineReader(LINE_READER *aReader)
Set aLineReader into the parser, and returns the previous one, if any.
Definition: pcb_parser.h:95
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:133
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:174
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:240
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, PCB_PARSER::GetRequiredVersion(), PCB_PLUGIN::init(), PCB_PARSER::IsTooRecent(), PCB_PLUGIN::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 304 of file kicad_clipboard.cpp.

305 {
306  BOARD_ITEM* item;
307  wxString result;
308 
309  wxLogNull doNotLog; // disable logging of failed clipboard actions
310 
311  auto clipboard = wxTheClipboard;
312  wxClipboardLocker clipboardLock( clipboard );
313 
314  if( !clipboardLock )
315  return nullptr;
316 
317  if( clipboard->IsSupported( wxDF_TEXT ) )
318  {
319  wxTextDataObject data;
320  clipboard->GetData( data );
321  result = data.GetText();
322  }
323 
324  try
325  {
326  item = PCB_PLUGIN::Parse( result );
327  }
328  catch (...)
329  {
330  item = nullptr;
331  }
332 
333  return item;
334 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
Definition: pcb_plugin.cpp:378

References PCB_PLUGIN::Parse().

Referenced by PCB_CONTROL::Paste().

◆ Parse() [2/2]

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

Definition at line 378 of file pcb_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 }
PCB_PARSER * m_parser
Definition: pcb_plugin.h:296
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
wxString GetRequiredVersion()
Return a string representing the version of KiCad required to open this file.
Definition: pcb_parser.cpp:246
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:626
LINE_READER * SetLineReader(LINE_READER *aReader)
Set aLineReader into the parser, and returns the previous one, if any.
Definition: pcb_parser.h:95
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:133
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:174
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:240

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

Referenced by Parse(), and parse_footprint_kicad().

◆ PluginName()

const wxString PCB_PLUGIN::PluginName ( ) const
inlineoverridevirtualinherited

Return a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 144 of file pcb_plugin.h.

145  {
146  return wxT( "KiCad" );
147  }

◆ PrefetchLib()

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

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.

Definition at line 75 of file plugin.cpp.

76 {
77 }

◆ Save()

void CLIPBOARD_IO::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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_PLUGIN.

Definition at line 337 of file kicad_clipboard.cpp.

339 {
340  init( aProperties );
341 
342  m_board = aBoard; // after init()
343 
344  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
345  m_mapping->SetBoard( aBoard );
346 
347  STRING_FORMATTER formatter;
348 
349  m_out = &formatter;
350 
351  m_out->Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n", SEXPR_BOARD_FILE_VERSION );
352 
353  Format( aBoard, 1 );
354 
355  m_out->Print( 0, ")\n" );
356 
357  wxLogNull doNotLog; // disable logging of failed clipboard actions
358 
359  auto clipboard = wxTheClipboard;
360  wxClipboardLocker clipboardLock( clipboard );
361 
362  if( !clipboardLock )
363  return;
364 
365  clipboard->SetData( new wxTextDataObject(
366  wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
367  clipboard->Flush();
368 
369  // This section exists to return the clipboard data, ensuring it has fully
370  // been processed by the system clipboard. This appears to be needed for
371  // extremely large clipboard copies on asynchronous linux clipboard managers
372  // such as KDE's Klipper
373  if( clipboard->IsSupported( wxDF_TEXT ) )
374  {
375  wxTextDataObject data;
376  clipboard->GetData( data );
377  ignore_unused( data.GetText() );
378  }
379 }
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
Definition: pcb_plugin.h:105
void init(const PROPERTIES *aProperties)
STRING_FORMATTER m_formatter
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:200
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294
const std::string & GetString()
Definition: richio.h:438
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:284
void Format(const BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
Definition: pcb_plugin.cpp:400
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
Definition: pcb_plugin.h:297
void ignore_unused(const T &)
Definition: ignore.h:24
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414

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

◆ SaveSelection()

void CLIPBOARD_IO::SaveSelection ( const PCB_SELECTION selected,
bool  isFootprintEditor 
)

Definition at line 63 of file kicad_clipboard.cpp.

64 {
65  VECTOR2I refPoint( 0, 0 );
66 
67  // dont even start if the selection is empty
68  if( aSelected.Empty() )
69  return;
70 
71  if( aSelected.HasReferencePoint() )
72  refPoint = aSelected.GetReferencePoint();
73 
74  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
76 
77  if( aSelected.Size() == 1 && aSelected.Front()->Type() == PCB_FOOTPRINT_T )
78  {
79  // make the footprint safe to transfer to other pcbs
80  const FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aSelected.Front() );
81  // Do not modify existing board
82  FOOTPRINT newFootprint( *footprint );
83 
84  for( PAD* pad : newFootprint.Pads() )
85  pad->SetNetCode( 0 );
86 
87  // locked means "locked in place"; copied items therefore can't be locked
88  newFootprint.SetLocked( false );
89 
90  // locate the reference point at (0, 0) in the copied items
91  newFootprint.Move( wxPoint( -refPoint.x, -refPoint.y ) );
92 
93  Format( static_cast<BOARD_ITEM*>( &newFootprint ) );
94  }
95  else if( isFootprintEditor )
96  {
97  FOOTPRINT partialFootprint( m_board );
98 
99  // Useful to copy the selection to the board editor (if any), and provides
100  // a dummy lib id.
101  // Perhaps not a good Id, but better than a empty id
102  KIID dummy;
103  LIB_ID id( "clipboard", dummy.AsString() );
104  partialFootprint.SetFPID( id );
105 
106  for( const EDA_ITEM* item : aSelected )
107  {
108  const PCB_GROUP* group = dynamic_cast<const PCB_GROUP*>( item );
109  BOARD_ITEM* clone;
110 
111  if( const FP_TEXT* text = dyn_cast<const FP_TEXT*>( item ) )
112  {
113  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
114  continue;
115  }
116 
117  if( group )
118  clone = static_cast<BOARD_ITEM*>( group->DeepClone() );
119  else
120  clone = static_cast<BOARD_ITEM*>( item->Clone() );
121 
122  // If it is only a footprint, clear the nets from the pads
123  if( PAD* pad = dyn_cast<PAD*>( clone ) )
124  pad->SetNetCode( 0 );
125 
126  // Add the pad to the new footprint before moving to ensure the local coords are
127  // correct
128  partialFootprint.Add( clone );
129 
130  // A list of not added items, when adding items to the footprint
131  // some FP_TEXT (reference and value) cannot be added to the footprint
132  std::vector<BOARD_ITEM*> skipped_items;
133 
134  if( group )
135  {
136  static_cast<PCB_GROUP*>( clone )->RunOnDescendants(
137  [&]( BOARD_ITEM* descendant )
138  {
139  // One cannot add a text reference or value to a given footprint:
140  // only one is allowed. So add only FP_TEXT::TEXT_is_DIVERS
141  bool can_add = true;
142 
143  if( const FP_TEXT* text = dyn_cast<const FP_TEXT*>( descendant ) )
144  {
145  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
146  can_add = false;
147  }
148 
149  if( can_add )
150  partialFootprint.Add( descendant );
151  else
152  skipped_items.push_back( descendant );
153  } );
154  }
155 
156  // locate the reference point at (0, 0) in the copied items
157  clone->Move( (wxPoint) -refPoint );
158 
159  // Now delete items, duplicated but not added:
160  for( BOARD_ITEM* skp_item : skipped_items )
161  delete skp_item;
162  }
163 
164  // Set the new relative internal local coordinates of copied items
165  FOOTPRINT* editedFootprint = m_board->Footprints().front();
166  wxPoint moveVector = partialFootprint.GetPosition() + editedFootprint->GetPosition();
167 
168  partialFootprint.MoveAnchorPosition( moveVector );
169 
170  Format( &partialFootprint, 0 );
171  }
172  else
173  {
174  // we will fake being a .kicad_pcb to get the full parser kicking
175  // This means we also need layers and nets
176  LOCALE_IO io;
177 
178  m_formatter.Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n",
180 
181  m_formatter.Print( 0, "\n" );
182 
185 
186  m_formatter.Print( 0, "\n" );
187 
188  for( EDA_ITEM* i : aSelected )
189  {
190  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
191  BOARD_ITEM* copy = nullptr;
192 
193  if( item->Type() == PCB_FP_SHAPE_T )
194  {
195  // Convert to PCB_SHAPE_T
196  copy = (BOARD_ITEM*) reinterpret_cast<PCB_SHAPE*>( item )->Clone();
197  copy->SetLayer( item->GetLayer() );
198  }
199  else if( item->Type() == PCB_FP_TEXT_T )
200  {
201  // Convert to PCB_TEXT_T
202  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item->GetParent() );
203  FP_TEXT* fp_text = static_cast<FP_TEXT*>( item );
204  PCB_TEXT* pcb_text = new PCB_TEXT( m_board );
205 
206  if( fp_text->GetText() == "${VALUE}" )
207  pcb_text->SetText( footprint->GetValue() );
208  else if( fp_text->GetText() == "${REFERENCE}" )
209  pcb_text->SetText( footprint->GetReference() );
210  else
211  pcb_text->CopyText( *fp_text );
212 
213  pcb_text->SetEffects( *fp_text );
214  pcb_text->SetLayer( fp_text->GetLayer() );
215  copy = pcb_text;
216  }
217  else if( item->Type() == PCB_PAD_T )
218  {
219  // Create a parent to own the copied pad
220  FOOTPRINT* footprint = new FOOTPRINT( m_board );
221  PAD* pad = (PAD*) item->Clone();
222 
223  footprint->SetPosition( pad->GetPosition() );
224  pad->SetPos0( wxPoint() );
225  footprint->Add( pad );
226  copy = footprint;
227  }
228  else if( item->Type() == PCB_FP_ZONE_T )
229  {
230  // Convert to PCB_ZONE_T
231  ZONE* zone = new ZONE( m_board );
232  zone->InitDataFromSrcInCopyCtor( *static_cast<ZONE*>( item ) );
233  copy = zone;
234  }
235  else if( item->Type() == PCB_GROUP_T )
236  {
237  copy = static_cast<PCB_GROUP*>( item )->DeepClone();
238  }
239  else
240  {
241  copy = static_cast<BOARD_ITEM*>( item->Clone() );
242  }
243 
244  auto prepItem = [&]( BOARD_ITEM* aItem )
245  {
246  aItem->SetLocked( false );
247  };
248 
249  if( copy )
250  {
251  prepItem( copy );
252 
253  // locate the reference point at (0, 0) in the copied items
254  copy->Move( (wxPoint) -refPoint );
255 
256  Format( copy, 1 );
257 
258  if( copy->Type() == PCB_GROUP_T )
259  {
260  static_cast<PCB_GROUP*>( copy )->RunOnDescendants( prepItem );
261  static_cast<PCB_GROUP*>( copy )->RunOnDescendants( [&]( BOARD_ITEM* titem )
262  {
263  Format( titem, 1 );
264  } );
265  }
266 
267  delete copy;
268  }
269  }
270  m_formatter.Print( 0, "\n)" );
271  }
272 
273  // These are placed at the end to minimize the open time of the clipboard
274  wxLogNull doNotLog; // disable logging of failed clipboard actions
275  auto clipboard = wxTheClipboard;
276  wxClipboardLocker clipboardLock( clipboard );
277 
278  if( !clipboardLock || !clipboard->IsOpened() )
279  return;
280 
281  clipboard->SetData( new wxTextDataObject( wxString( m_formatter.GetString().c_str(),
282  wxConvUTF8 ) ) );
283 
284  clipboard->Flush();
285 
286  #ifndef __WXOSX__
287  // This section exists to return the clipboard data, ensuring it has fully
288  // been processed by the system clipboard. This appears to be needed for
289  // extremely large clipboard copies on asynchronous linux clipboard managers
290  // such as KDE's Klipper. However, a read back of the data on OSX before the
291  // clipboard is closed seems to cause an ASAN error (heap-buffer-overflow)
292  // since it uses the cached version of the clipboard data and not the system
293  // clipboard data.
294  if( clipboard->IsSupported( wxDF_TEXT ) )
295  {
296  wxTextDataObject data;
297  clipboard->GetData( data );
298  ignore_unused( data.GetText() );
299  }
300  #endif
301 }
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
Definition: pcb_plugin.h:105
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
const wxString & GetValue() const
Definition: footprint.h:485
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:131
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:163
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:139
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
STRING_FORMATTER m_formatter
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:200
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
Definition: kiid.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
FOOTPRINTS & Footprints()
Definition: board.h:234
void InitDataFromSrcInCopyCtor(const ZONE &aZone)
Copy aZone data to me.
Definition: zone.cpp:111
const wxString & GetReference() const
Definition: footprint.h:463
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
const std::string & GetString()
Definition: richio.h:438
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:284
void Format(const BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
Definition: pcb_plugin.cpp:400
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
Definition: pcb_plugin.h:297
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
void formatBoardLayers(const BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
Definition: pcb_plugin.cpp:542
class ZONE, managed by a footprint
Definition: typeinfo.h:94
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
void ignore_unused(const T &)
Definition: ignore.h:24
wxPoint GetPosition() const override
Definition: footprint.h:186
void formatNetInformation(const BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Definition: pcb_plugin.cpp:612
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:513
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
Definition: pad.h:57
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1561
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:142
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References FOOTPRINT::Add(), EDA_ITEM::Clone(), copy, EDA_TEXT::CopyText(), dummy(), SELECTION::Empty(), BOARD::Footprints(), PCB_PLUGIN::Format(), PCB_PLUGIN::formatBoardLayers(), PCB_PLUGIN::formatNetInformation(), SELECTION::Front(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetParent(), FOOTPRINT::GetPosition(), FOOTPRINT::GetReference(), SELECTION::GetReferencePoint(), STRING_FORMATTER::GetString(), FOOTPRINT::GetValue(), group, SELECTION::HasReferencePoint(), ignore_unused(), ZONE::InitDataFromSrcInCopyCtor(), PCB_PLUGIN::m_board, m_formatter, PCB_PLUGIN::m_mapping, FOOTPRINT::MoveAnchorPosition(), pad, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, OUTPUTFORMATTER::Print(), NETINFO_MAPPING::SetBoard(), EDA_TEXT::SetEffects(), FOOTPRINT::SetFPID(), BOARD_ITEM::SetLayer(), FOOTPRINT::SetPosition(), EDA_TEXT::SetText(), SEXPR_BOARD_FILE_VERSION, SELECTION::Size(), text, FP_TEXT::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 57 of file kicad_clipboard.cpp.

58 {
59  m_board = aBoard;
60 }
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:284

References PCB_PLUGIN::m_board.

Referenced by EDIT_TOOL::copyToClipboard().

◆ SetOutputFormatter()

void PCB_PLUGIN::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

Definition at line 221 of file pcb_plugin.h.

221 { m_out = aFormatter; }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:294

References PCB_PLUGIN::m_out.

Referenced by FP_CACHE::Save().

◆ validateCache()

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

Definition at line 2365 of file pcb_plugin.cpp.

2366 {
2367  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2368  {
2369  // a spectacular episode in memory management:
2370  delete m_cache;
2371  m_cache = new FP_CACHE( this, aLibraryPath );
2372  m_cache->Load();
2373  }
2374 }
bool IsModified()
Return true if the cache is not up-to-date.
Definition: pcb_plugin.cpp:322
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
Definition: pcb_plugin.cpp:316
void Load()
Definition: pcb_plugin.cpp:233
friend class FP_CACHE
Definition: pcb_plugin.h:280
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:288

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

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

Member Data Documentation

◆ m_board

BOARD* PCB_PLUGIN::m_board
protectedinherited

which BOARD, no ownership here

Definition at line 284 of file pcb_plugin.h.

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

◆ m_cache

◆ m_ctl

int PCB_PLUGIN::m_ctl
protectedinherited

◆ m_error

wxString PCB_PLUGIN::m_error
protectedinherited

for throwing exceptions

Definition at line 283 of file pcb_plugin.h.

◆ m_filename

wxString PCB_PLUGIN::m_filename
protectedinherited

for saves only, name is in m_reader for loads

Definition at line 291 of file pcb_plugin.h.

◆ m_formatter

STRING_FORMATTER CLIPBOARD_IO::m_formatter
private

Definition at line 68 of file kicad_clipboard.h.

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

◆ m_mapping

NETINFO_MAPPING* PCB_PLUGIN::m_mapping
protectedinherited

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

Definition at line 297 of file pcb_plugin.h.

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

◆ m_out

◆ m_parser

PCB_PARSER* PCB_PLUGIN::m_parser
protectedinherited

◆ m_props

const PROPERTIES* PCB_PLUGIN::m_props
protectedinherited

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

Definition at line 287 of file pcb_plugin.h.

Referenced by PCB_PLUGIN::init().

◆ m_reader

LINE_READER* PCB_PLUGIN::m_reader
protectedinherited

no ownership here.

Definition at line 290 of file pcb_plugin.h.

Referenced by PCB_PLUGIN::init().

◆ m_sf

STRING_FORMATTER PCB_PLUGIN::m_sf
protectedinherited

Definition at line 293 of file pcb_plugin.h.

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


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