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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *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...
 
void SetQueryUserCallback (std::function< bool(wxString aTitle, int aIcon, wxString aMessage, wxString aOKButtonTitle)> aCallback) override
 
virtual void SetQueryUserCallback (std::function< bool(wxString aTitle, int aIcon, wxString aMessage, wxString aAction)> aCallback)
 Registers a KIDIALOG callback for collecting info from the user. More...
 
BOARDDoLoad (LINE_READER &aReader, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties, PROGRESS_REPORTER *aProgressReporter, unsigned aLineCount)
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties=nullptr) override
 Check for the existence of a footprint. More...
 
FOOTPRINTFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties=nullptr) override
 Write aFootprint to an existing library located at aLibraryPath. More...
 
void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties=nullptr) override
 Create a new empty footprint library at aLibraryPath empty. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties=nullptr)
 If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintLibOptions (STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties, bool checkModified)
 
void init (const STRING_UTF8_MAP *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 STRING_UTF8_MAPm_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
 
NETINFO_MAPPINGm_mapping
 mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes More...
 
std::function< bool(wxString aTitle, int aIcon, wxString aMsg, wxString aAction)> * m_queryUserCallback
 

Private Member Functions

void format (const BOARD *aBoard, int aNestLevel=0) const
 
void format (const PCB_DIMENSION_BASE *aDimension, int aNestLevel=0) const
 
void format (const FP_SHAPE *aFPShape, int aNestLevel=0) const
 
void format (const PCB_BITMAP *aBitmap, int aNestLevel=0) const
 
void format (const PCB_GROUP *aGroup, int aNestLevel=0) const
 
void format (const PCB_SHAPE *aSegment, int aNestLevel=0) const
 
void format (const PCB_TARGET *aTarget, int aNestLevel=0) const
 
void format (const FOOTPRINT *aFootprint, int aNestLevel=0) const
 
void format (const PAD *aPad, int aNestLevel=0) const
 
void format (const PCB_TEXT *aText, int aNestLevel=0) const
 
void format (const PCB_TEXTBOX *aTextBox, int aNestLevel=0) const
 
void format (const FP_TEXT *aText, int aNestLevel=0) const
 
void format (const FP_TEXTBOX *aTextBox, int aNestLevel=0) const
 
void format (const PCB_TRACK *aTrack, int aNestLevel=0) const
 
void format (const ZONE *aZone, int aNestLevel=0) const
 
void formatPolyPts (const SHAPE_LINE_CHAIN &outline, int aNestLevel, bool aCompact) const
 
void formatRenderCache (const EDA_TEXT *aText, int aNestLevel) const
 
void formatLayer (PCB_LAYER_ID aLayer, bool aIsKnockout=false) const
 
void formatLayers (LSET aLayerMask, int aNestLevel=0) const
 

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

47 :
50{
52}
STRING_FORMATTER m_formatter
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Definition: pcb_plugin.h:423
PCB_PLUGIN(int aControlFlags=CTL_FOR_BOARD)
#define CTL_FOR_CLIPBOARD
Format output for the clipboard instead of footprint library or BOARD.
Definition: pcb_plugin.h:155

References m_formatter, and PCB_PLUGIN::m_out.

◆ ~CLIPBOARD_IO()

CLIPBOARD_IO::~CLIPBOARD_IO ( )

Definition at line 55 of file kicad_clipboard.cpp.

56{
57}

Member Function Documentation

◆ DoLoad()

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

Definition at line 2380 of file pcb_plugin.cpp.

2382{
2383 init( aProperties );
2384
2385 PCB_PARSER parser( &aReader, aAppendToMe, m_queryUserCallback, aProgressReporter, aLineCount );
2386 BOARD* board;
2387
2388 try
2389 {
2390 board = dynamic_cast<BOARD*>( parser.Parse() );
2391 }
2392 catch( const FUTURE_FORMAT_ERROR& )
2393 {
2394 // Don't wrap a FUTURE_FORMAT_ERROR in another
2395 throw;
2396 }
2397 catch( const PARSE_ERROR& parse_error )
2398 {
2399 if( parser.IsTooRecent() )
2400 throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
2401 else
2402 throw;
2403 }
2404
2405 if( !board )
2406 {
2407 // The parser loaded something that was valid, but wasn't a board.
2408 THROW_PARSE_ERROR( _( "This file does not contain a PCB." ), parser.CurSource(),
2409 parser.CurLine(), parser.CurLineNumber(), parser.CurOffset() );
2410 }
2411
2412 return board;
2413}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
Definition: pcb_parser.h:74
void init(const STRING_UTF8_MAP *aProperties)
std::function< bool(wxString aTitle, int aIcon, wxString aMsg, wxString aAction)> * m_queryUserCallback
Definition: pcb_plugin.h:428
#define _(s)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:175
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119

References _, PCB_PARSER::GetRequiredVersion(), PCB_PLUGIN::init(), PCB_PARSER::IsTooRecent(), PCB_PLUGIN::m_queryUserCallback, PCB_PARSER::Parse(), 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 STRING_UTF8_MAP 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 2635 of file pcb_plugin.cpp.

2637{
2638 LOCALE_IO toggle; // toggles on, then off, the C locale.
2639
2640 init( aProperties );
2641
2642 validateCache( aLibraryPath );
2643
2644 if( !m_cache->IsWritable() )
2645 {
2646 THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
2647 aLibraryPath.GetData() ) );
2648 }
2649
2650 m_cache->Remove( aFootprintName );
2651}
bool IsWritable() const
Definition: pcb_plugin.h:204
void Remove(const wxString &aFootprintName)
Definition: pcb_plugin.cpp:210
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
FP_CACHE * m_cache
Footprint library cache.
Definition: pcb_plugin.h:417
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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

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 STRING_UTF8_MAP 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 2436 of file pcb_plugin.cpp.

2438{
2439 LOCALE_IO toggle; // toggles on, then off, the C locale.
2440 wxDir dir( aLibPath );
2441 wxString errorMsg;
2442
2443 init( aProperties );
2444
2445 try
2446 {
2447 validateCache( aLibPath );
2448 }
2449 catch( const IO_ERROR& ioe )
2450 {
2451 errorMsg = ioe.What();
2452 }
2453
2454 // Some of the files may have been parsed correctly so we want to add the valid files to
2455 // the library.
2456
2457 for( const auto& footprint : m_cache->GetFootprints() )
2458 aFootprintNames.Add( footprint.first );
2459
2460 if( !errorMsg.IsEmpty() && !aBestEfforts )
2461 THROW_IO_ERROR( errorMsg );
2462}
FP_CACHE_FOOTPRINT_MAP & GetFootprints()
Definition: pcb_plugin.h:208
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30

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 STRING_UTF8_MAP aProperties = nullptr 
)
overridevirtualinherited

Check for the existence of a footprint.

Reimplemented from PLUGIN.

Definition at line 2501 of file pcb_plugin.cpp.

2503{
2504 // Note: checking the cache sounds like a good idea, but won't catch files which differ
2505 // only in case.
2506 //
2507 // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2508 // case-insensitive filesystem) handled "for free".
2509 // Warning: footprint names frequently contain a point. So be careful when initializing
2510 // wxFileName, and use a CTOR with extension specified
2511 wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2512
2513 return footprintFile.Exists();
2514}
const std::string KiCadFootprintFileExtension

References KiCadFootprintFileExtension.

◆ FootprintLibCreate()

void PCB_PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const STRING_UTF8_MAP 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 2661 of file pcb_plugin.cpp.

2662{
2663 if( wxDir::Exists( aLibraryPath ) )
2664 {
2665 THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path '%s'." ),
2666 aLibraryPath.GetData() ) );
2667 }
2668
2669 LOCALE_IO toggle;
2670
2671 init( aProperties );
2672
2673 delete m_cache;
2674 m_cache = new FP_CACHE( this, aLibraryPath );
2675 m_cache->Save();
2676}
void Save(FOOTPRINT *aFootprint=nullptr)
Save the footprint cache or a single footprint from it to disk.
Definition: pcb_plugin.cpp:85
friend class FP_CACHE
Definition: pcb_plugin.h:410

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 STRING_UTF8_MAP 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 2679 of file pcb_plugin.cpp.

2680{
2681 wxFileName fn;
2682 fn.SetPath( aLibraryPath );
2683
2684 // Return if there is no library path to delete.
2685 if( !fn.DirExists() )
2686 return false;
2687
2688 if( !fn.IsDirWritable() )
2689 {
2690 THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete folder '%s'." ),
2691 aLibraryPath.GetData() ) );
2692 }
2693
2694 wxDir dir( aLibraryPath );
2695
2696 if( dir.HasSubDirs() )
2697 {
2698 THROW_IO_ERROR( wxString::Format( _( "Library folder '%s' has unexpected sub-folders." ),
2699 aLibraryPath.GetData() ) );
2700 }
2701
2702 // All the footprint files must be deleted before the directory can be deleted.
2703 if( dir.HasFiles() )
2704 {
2705 unsigned i;
2706 wxFileName tmp;
2707 wxArrayString files;
2708
2709 wxDir::GetAllFiles( aLibraryPath, &files );
2710
2711 for( i = 0; i < files.GetCount(); i++ )
2712 {
2713 tmp = files[i];
2714
2715 if( tmp.GetExt() != KiCadFootprintFileExtension )
2716 {
2717 THROW_IO_ERROR( wxString::Format( _( "Unexpected file '%s' found in library "
2718 "path '%s'." ),
2719 files[i].GetData(),
2720 aLibraryPath.GetData() ) );
2721 }
2722 }
2723
2724 for( i = 0; i < files.GetCount(); i++ )
2725 wxRemoveFile( files[i] );
2726 }
2727
2728 wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library '%s'." ),
2729 aLibraryPath.GetData() );
2730
2731 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2732 // we don't want that. we want bare metal portability with no UI here.
2733 if( !wxRmdir( aLibraryPath ) )
2734 {
2735 THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
2736 aLibraryPath.GetData() ) );
2737 }
2738
2739 // For some reason removing a directory in Windows is not immediately updated. This delay
2740 // prevents an error when attempting to immediately recreate the same directory when over
2741 // writing an existing library.
2742#ifdef __WINDOWS__
2743 wxMilliSleep( 250L );
2744#endif
2745
2746 if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2747 {
2748 delete m_cache;
2749 m_cache = nullptr;
2750 }
2751
2752 return true;
2753}
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
Definition: pcb_plugin.cpp:229
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.

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

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( STRING_UTF8_MAP 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 145 of file plugin.cpp.

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

References _.

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

◆ FootprintLoad()

FOOTPRINT * PCB_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
bool  aKeepUUID = false,
const STRING_UTF8_MAP 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 2517 of file pcb_plugin.cpp.

2521{
2522 const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2523
2524 if( footprint )
2525 {
2526 FOOTPRINT* copy;
2527
2528 if( aKeepUUID )
2529 copy = static_cast<FOOTPRINT*>( footprint->Clone() );
2530 else
2531 copy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
2532
2533 copy->SetParent( nullptr );
2534 return copy;
2535 }
2536
2537 return nullptr;
2538}
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: footprint.cpp:1361
BOARD_ITEM * Duplicate() const override
Create a copy of this BOARD_ITEM.
Definition: footprint.cpp:1844
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *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 STRING_UTF8_MAP 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 2541 of file pcb_plugin.cpp.

2543{
2544 LOCALE_IO toggle; // toggles on, then off, the C locale.
2545
2546 init( aProperties );
2547
2548 // In this public PLUGIN API function, we can safely assume it was
2549 // called for saving into a library path.
2551
2552 validateCache( aLibraryPath );
2553
2554 if( !m_cache->IsWritable() )
2555 {
2556 if( !m_cache->Exists() )
2557 {
2558 const wxString msg = wxString::Format( _( "Library '%s' does not exist.\n"
2559 "Would you like to create it?"),
2560 aLibraryPath );
2561
2562 if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2563 return;
2564
2565 // Save throws its own IO_ERROR on failure, so no need to recreate here
2566 m_cache->Save( nullptr );
2567 }
2568 else
2569 {
2570 wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibraryPath );
2571 THROW_IO_ERROR( msg );
2572 }
2573 }
2574
2575 wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2576
2578
2579 // Quietly overwrite footprint and delete footprint file from path for any by same name.
2580 wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2582
2583 // Write through symlinks, don't replace them
2585
2586 if( !fn.IsOk() )
2587 {
2588 THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
2589 fn.GetFullPath() ) );
2590 }
2591
2592 if( fn.FileExists() && !fn.IsFileWritable() )
2593 {
2594 THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete '%s'." ),
2595 fn.GetFullPath() ) );
2596 }
2597
2598 wxString fullPath = fn.GetFullPath();
2599 wxString fullName = fn.GetFullName();
2600 FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( footprintName );
2601
2602 if( it != footprints.end() )
2603 {
2604 wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2605 footprints.erase( footprintName );
2606 wxRemoveFile( fullPath );
2607 }
2608
2609 // I need my own copy for the cache
2610 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aFootprint->Clone() );
2611
2612 // It's orientation should be zero and it should be on the front layer.
2613 footprint->SetOrientation( ANGLE_0 );
2614
2615 if( footprint->GetLayer() != F_Cu )
2616 {
2617 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2618
2619 if( cfg )
2620 footprint->Flip( footprint->GetPosition(), cfg->m_FlipLeftRight );
2621 else
2622 footprint->Flip( footprint->GetPosition(), false );
2623 }
2624
2625 // Detach it from the board
2626 footprint->SetParent( nullptr );
2627
2628 wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2629 footprints.insert( footprintName,
2630 new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) );
2631 m_cache->Save( footprint );
2632}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
void SetOrientation(const EDA_ANGLE &aNewAngle)
Definition: footprint.cpp:1790
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:200
const LIB_ID & GetFPID() const
Definition: footprint.h:212
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1574
VECTOR2I GetPosition() const override
Definition: footprint.h:188
Helper class for creating a footprint library cache.
Definition: pcb_plugin.h:174
bool Exists() const
Definition: pcb_plugin.h:206
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: wx_filename.h:49
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Definition: wx_filename.cpp:85
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
@ F_Cu
Definition: layer_ids.h:64
boost::ptr_map< wxString, FP_CACHE_ITEM > FP_CACHE_FOOTPRINT_MAP
Definition: pcb_plugin.h:185
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
Definition: pcb_plugin.h:158

References _, ANGLE_0, FOOTPRINT::Clone(), CTL_FOR_LIBRARY, FP_CACHE::Exists(), F_Cu, FOOTPRINT::Flip(), Format(), FP_CACHE::GetFootprints(), FOOTPRINT::GetFPID(), FOOTPRINT::GetLayer(), LIB_ID::GetLibItemName(), FOOTPRINT::GetPosition(), PCB_PLUGIN::init(), FP_CACHE::IsWritable(), KiCadFootprintFileExtension, Kiface(), KIFACE_BASE::KifaceSettings(), 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() [1/15]

void PCB_PLUGIN::format ( const BOARD aBoard,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 687 of file pcb_plugin.cpp.

688{
689 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_footprints( aBoard->Footprints().begin(),
690 aBoard->Footprints().end() );
691 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_drawings( aBoard->Drawings().begin(),
692 aBoard->Drawings().end() );
693 std::set<PCB_TRACK*, PCB_TRACK::cmp_tracks> sorted_tracks( aBoard->Tracks().begin(),
694 aBoard->Tracks().end() );
695 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aBoard->Zones().begin(),
696 aBoard->Zones().end() );
697 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(),
698 aBoard->Groups().end() );
699 formatHeader( aBoard, aNestLevel );
700
701 // Save the footprints.
702 for( BOARD_ITEM* footprint : sorted_footprints )
703 {
704 Format( footprint, aNestLevel );
705 m_out->Print( 0, "\n" );
706 }
707
708 // Save the graphical items on the board (not owned by a footprint)
709 for( BOARD_ITEM* item : sorted_drawings )
710 Format( item, aNestLevel );
711
712 if( sorted_drawings.size() )
713 m_out->Print( 0, "\n" );
714
715 // Do not save PCB_MARKERs, they can be regenerated easily.
716
717 // Save the tracks and vias.
718 for( PCB_TRACK* track : sorted_tracks )
719 Format( track, aNestLevel );
720
721 if( sorted_tracks.size() )
722 m_out->Print( 0, "\n" );
723
724 // Save the polygon (which are the newer technology) zones.
725 for( auto zone : sorted_zones )
726 Format( zone, aNestLevel );
727
728 // Save the groups
729 for( BOARD_ITEM* group : sorted_groups )
730 Format( group, aNestLevel );
731}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
ZONES & Zones()
Definition: board.h:313
FOOTPRINTS & Footprints()
Definition: board.h:307
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:327
TRACKS & Tracks()
Definition: board.h:304
DRAWINGS & Drawings()
Definition: board.h:310
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
void formatHeader(const BOARD *aBoard, int aNestLevel=0) const
writes everything that comes before the board_items, like settings and layers etc
Definition: pcb_plugin.cpp:669
void Format(const BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
Definition: pcb_plugin.cpp:311

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

Referenced by PCB_PLUGIN::Format().

◆ 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 311 of file pcb_plugin.cpp.

312{
313 LOCALE_IO toggle; // public API function, perform anything convenient for caller
314
315 switch( aItem->Type() )
316 {
317 case PCB_T:
318 format( static_cast<const BOARD*>( aItem ), aNestLevel );
319 break;
320
322 case PCB_DIM_CENTER_T:
323 case PCB_DIM_RADIAL_T:
325 case PCB_DIM_LEADER_T:
331 format( static_cast<const PCB_DIMENSION_BASE*>( aItem ), aNestLevel );
332 break;
333
334 case PCB_SHAPE_T:
335 format( static_cast<const PCB_SHAPE*>( aItem ), aNestLevel );
336 break;
337
338 case PCB_BITMAP_T:
339 format( static_cast<const PCB_BITMAP*>( aItem ), aNestLevel );
340 break;
341
342 case PCB_FP_SHAPE_T:
343 format( static_cast<const FP_SHAPE*>( aItem ), aNestLevel );
344 break;
345
346 case PCB_TARGET_T:
347 format( static_cast<const PCB_TARGET*>( aItem ), aNestLevel );
348 break;
349
350 case PCB_FOOTPRINT_T:
351 format( static_cast<const FOOTPRINT*>( aItem ), aNestLevel );
352 break;
353
354 case PCB_PAD_T:
355 format( static_cast<const PAD*>( aItem ), aNestLevel );
356 break;
357
358 case PCB_TEXT_T:
359 format( static_cast<const PCB_TEXT*>( aItem ), aNestLevel );
360 break;
361
362 case PCB_TEXTBOX_T:
363 format( static_cast<const PCB_TEXTBOX*>( aItem ), aNestLevel );
364 break;
365
366 case PCB_FP_TEXT_T:
367 format( static_cast<const FP_TEXT*>( aItem ), aNestLevel );
368 break;
369
370 case PCB_FP_TEXTBOX_T:
371 format( static_cast<const FP_TEXTBOX*>( aItem ), aNestLevel );
372 break;
373
374 case PCB_GROUP_T:
375 format( static_cast<const PCB_GROUP*>( aItem ), aNestLevel );
376 break;
377
378 case PCB_TRACE_T:
379 case PCB_ARC_T:
380 case PCB_VIA_T:
381 format( static_cast<const PCB_TRACK*>( aItem ), aNestLevel );
382 break;
383
384 case PCB_FP_ZONE_T:
385 case PCB_ZONE_T:
386 format( static_cast<const ZONE*>( aItem ), aNestLevel );
387 break;
388
389 default:
390 wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
391 }
392}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual wxString GetClass() const =0
Return the class name.
Definition: pad.h:59
Object to handle a bitmap image that can be inserted in a PCB.
Definition: pcb_bitmap.h:42
Abstract dimension API.
Definition: pcb_dimension.h:96
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
void format(const BOARD *aBoard, int aNestLevel=0) const
Definition: pcb_plugin.cpp:687
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
@ PCB_FP_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:95
@ PCB_T
Definition: typeinfo.h:82
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:110
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:111
@ PCB_FP_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:99
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:106
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_FP_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:98
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:109

References PCB_PLUGIN::format(), EDA_ITEM::GetClass(), PCB_ARC_T, PCB_BITMAP_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_DIM_RADIAL_T, PCB_FOOTPRINT_T, PCB_FP_DIM_ALIGNED_T, PCB_FP_DIM_CENTER_T, PCB_FP_DIM_LEADER_T, PCB_FP_DIM_ORTHOGONAL_T, PCB_FP_DIM_RADIAL_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, PCB_SHAPE_T, PCB_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, and EDA_ITEM::Type().

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

◆ format() [2/15]

void PCB_PLUGIN::format ( const FOOTPRINT aFootprint,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1086 of file pcb_plugin.cpp.

1087{
1088 if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1089 {
1090 const wxArrayString* initial_comments = aFootprint->GetInitialComments();
1091
1092 if( initial_comments )
1093 {
1094 for( unsigned i = 0; i < initial_comments->GetCount(); ++i )
1095 m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1096
1097 m_out->Print( 0, "\n" ); // improve readability?
1098 }
1099 }
1100
1101 if( m_ctl & CTL_OMIT_LIBNAME )
1102 {
1103 m_out->Print( aNestLevel, "(footprint %s",
1104 m_out->Quotes( aFootprint->GetFPID().GetLibItemName() ).c_str() );
1105 }
1106 else
1107 {
1108 m_out->Print( aNestLevel, "(footprint %s",
1109 m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );
1110 }
1111
1113 m_out->Print( 0, " (version %d) (generator pcbnew)\n ", SEXPR_BOARD_FILE_VERSION );
1114
1115 if( aFootprint->IsLocked() )
1116 m_out->Print( 0, " locked" );
1117
1118 if( aFootprint->IsPlaced() )
1119 m_out->Print( 0, " placed" );
1120
1121 formatLayer( aFootprint->GetLayer() );
1122
1123 m_out->Print( 0, "\n" );
1124
1125 if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1126 m_out->Print( aNestLevel+1, "(tstamp %s)\n", TO_UTF8( aFootprint->m_Uuid.AsString() ) );
1127
1128 if( !( m_ctl & CTL_OMIT_AT ) )
1129 {
1130 m_out->Print( aNestLevel+1, "(at %s",
1132
1133 if( !aFootprint->GetOrientation().IsZero() )
1134 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aFootprint->GetOrientation() ).c_str() );
1135
1136 m_out->Print( 0, ")\n" );
1137 }
1138
1139 if( !aFootprint->GetDescription().IsEmpty() )
1140 {
1141 m_out->Print( aNestLevel+1, "(descr %s)\n",
1142 m_out->Quotew( aFootprint->GetDescription() ).c_str() );
1143 }
1144
1145 if( !aFootprint->GetKeywords().IsEmpty() )
1146 {
1147 m_out->Print( aNestLevel+1, "(tags %s)\n",
1148 m_out->Quotew( aFootprint->GetKeywords() ).c_str() );
1149 }
1150
1151 const std::map<wxString, wxString>& props = aFootprint->GetProperties();
1152
1153 for( const std::pair<const wxString, wxString>& prop : props )
1154 {
1155 m_out->Print( aNestLevel+1, "(property %s %s)\n",
1156 m_out->Quotew( prop.first ).c_str(),
1157 m_out->Quotew( prop.second ).c_str() );
1158 }
1159
1160 if( !( m_ctl & CTL_OMIT_PATH ) && !aFootprint->GetPath().empty() )
1161 {
1162 m_out->Print( aNestLevel+1, "(path %s)\n",
1163 m_out->Quotew( aFootprint->GetPath().AsString() ).c_str() );
1164 }
1165
1166 if( aFootprint->GetLocalSolderMaskMargin() != 0 )
1167 {
1168 m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1170 }
1171
1172 if( aFootprint->GetLocalSolderPasteMargin() != 0 )
1173 {
1174 m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1176 }
1177
1178 if( aFootprint->GetLocalSolderPasteMarginRatio() != 0 )
1179 {
1180 m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1181 FormatDouble2Str( aFootprint->GetLocalSolderPasteMarginRatio() ).c_str() );
1182 }
1183
1184 if( aFootprint->GetLocalClearance() != 0 )
1185 {
1186 m_out->Print( aNestLevel+1, "(clearance %s)\n",
1188 }
1189
1190 if( aFootprint->GetZoneConnection() != ZONE_CONNECTION::INHERITED )
1191 {
1192 m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
1193 static_cast<int>( aFootprint->GetZoneConnection() ) );
1194 }
1195
1196 // Attributes
1197 if( aFootprint->GetAttributes() )
1198 {
1199 m_out->Print( aNestLevel+1, "(attr" );
1200
1201 if( aFootprint->GetAttributes() & FP_SMD )
1202 m_out->Print( 0, " smd" );
1203
1204 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1205 m_out->Print( 0, " through_hole" );
1206
1207 if( aFootprint->GetAttributes() & FP_BOARD_ONLY )
1208 m_out->Print( 0, " board_only" );
1209
1210 if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
1211 m_out->Print( 0, " exclude_from_pos_files" );
1212
1213 if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM )
1214 m_out->Print( 0, " exclude_from_bom" );
1215
1216 if( aFootprint->GetAttributes() & FP_ALLOW_MISSING_COURTYARD )
1217 m_out->Print( 0, " allow_missing_courtyard" );
1218
1219 if( aFootprint->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES )
1220 m_out->Print( 0, " allow_soldermask_bridges" );
1221
1222 m_out->Print( 0, ")\n" );
1223 }
1224
1225 if( aFootprint->GetPrivateLayers().any() )
1226 {
1227 m_out->Print( aNestLevel+1, "(private_layers" );
1228
1229 for( PCB_LAYER_ID layer : aFootprint->GetPrivateLayers().Seq() )
1230 {
1231 wxString canonicalName( LSET::Name( layer ) );
1232 m_out->Print( 0, " \"%s\"", canonicalName.ToStdString().c_str() );
1233 }
1234
1235 m_out->Print( 0, ")\n" );
1236 }
1237
1238 if( aFootprint->IsNetTie() )
1239 {
1240 m_out->Print( aNestLevel+1, "(net_tie_pad_groups" );
1241
1242 for( const wxString& group : aFootprint->GetNetTiePadGroups() )
1243 {
1244 m_out->Print( 0, " \"%s\"",
1245 EscapeString( group, CTX_QUOTED_STR ).ToStdString().c_str() );
1246 }
1247
1248 m_out->Print( 0, ")\n" );
1249 }
1250
1251 Format( (BOARD_ITEM*) &aFootprint->Reference(), aNestLevel + 1 );
1252 Format( (BOARD_ITEM*) &aFootprint->Value(), aNestLevel + 1 );
1253
1254 std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->Pads().begin(),
1255 aFootprint->Pads().end() );
1256 std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings(
1257 aFootprint->GraphicalItems().begin(),
1258 aFootprint->GraphicalItems().end() );
1259 std::set<FP_ZONE*, FOOTPRINT::cmp_zones> sorted_zones( aFootprint->Zones().begin(),
1260 aFootprint->Zones().end() );
1261 std::set<BOARD_ITEM*, PCB_GROUP::ptr_cmp> sorted_groups( aFootprint->Groups().begin(),
1262 aFootprint->Groups().end() );
1263
1264 // Save drawing elements.
1265
1266 for( BOARD_ITEM* gr : sorted_drawings )
1267 Format( gr, aNestLevel+1 );
1268
1269 // Save pads.
1270 for( PAD* pad : sorted_pads )
1271 Format( pad, aNestLevel+1 );
1272
1273 // Save zones.
1274 for( BOARD_ITEM* zone : sorted_zones )
1275 Format( zone, aNestLevel + 1 );
1276
1277 // Save groups.
1278 for( BOARD_ITEM* group : sorted_groups )
1279 Format( group, aNestLevel + 1 );
1280
1281 // Save 3D info.
1282 auto bs3D = aFootprint->Models().begin();
1283 auto es3D = aFootprint->Models().end();
1284
1285 while( bs3D != es3D )
1286 {
1287 if( !bs3D->m_Filename.IsEmpty() )
1288 {
1289 m_out->Print( aNestLevel+1, "(model %s%s\n",
1290 m_out->Quotew( bs3D->m_Filename ).c_str(),
1291 bs3D->m_Show ? "" : " hide" );
1292
1293 if( bs3D->m_Opacity != 1.0 )
1294 m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
1295
1296 m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
1297 FormatDouble2Str( bs3D->m_Offset.x ).c_str(),
1298 FormatDouble2Str( bs3D->m_Offset.y ).c_str(),
1299 FormatDouble2Str( bs3D->m_Offset.z ).c_str() );
1300
1301 m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1302 FormatDouble2Str( bs3D->m_Scale.x ).c_str(),
1303 FormatDouble2Str( bs3D->m_Scale.y ).c_str(),
1304 FormatDouble2Str( bs3D->m_Scale.z ).c_str() );
1305
1306 m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1307 FormatDouble2Str( bs3D->m_Rotation.x ).c_str(),
1308 FormatDouble2Str( bs3D->m_Rotation.y ).c_str(),
1309 FormatDouble2Str( bs3D->m_Rotation.z ).c_str() );
1310
1311 m_out->Print( aNestLevel+1, ")\n" );
1312 }
1313
1314 ++bs3D;
1315 }
1316
1317 m_out->Print( aNestLevel, ")\n" );
1318}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
bool IsZero() const
Definition: eda_angle.h:169
const KIID m_Uuid
Definition: eda_item.h:494
EDA_ANGLE GetOrientation() const
Definition: footprint.h:191
int GetLocalClearance() const
Definition: footprint.h:230
wxString GetDescription() const
Definition: footprint.h:218
double GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:244
FP_GROUPS & Groups()
Definition: footprint.h:179
int GetAttributes() const
Definition: footprint.h:250
LSET GetPrivateLayers() const
Definition: footprint.h:120
PADS & Pads()
Definition: footprint.h:170
int GetLocalSolderPasteMargin() const
Definition: footprint.h:241
const std::vector< wxString > & GetNetTiePadGroups() const
Definition: footprint.h:272
bool IsLocked() const override
Definition: footprint.h:340
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:567
bool IsNetTie() const
Definition: footprint.h:257
const wxArrayString * GetInitialComments() const
Definition: footprint.h:784
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:184
ZONE_CONNECTION GetZoneConnection() const
Definition: footprint.h:248
const KIID_PATH & GetPath() const
Definition: footprint.h:224
FP_ZONES & Zones()
Definition: footprint.h:176
wxString GetKeywords() const
Definition: footprint.h:221
bool IsPlaced() const
Definition: footprint.h:363
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
FP_TEXT & Reference()
Definition: footprint.h:568
int GetLocalSolderMaskMargin() const
Definition: footprint.h:227
const std::map< wxString, wxString > & GetProperties() const
Definition: footprint.h:574
wxString AsString() const
Definition: kiid.cpp:332
wxString AsString() const
Definition: kiid.cpp:251
UTF8 Format() const
Definition: lib_id.cpp:117
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 wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:499
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:460
void formatLayer(PCB_LAYER_ID aLayer, bool aIsKnockout=false) const
Definition: pcb_plugin.cpp:395
@ FP_SMD
Definition: footprint.h:69
@ FP_ALLOW_MISSING_COURTYARD
Definition: footprint.h:75
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:70
@ FP_BOARD_ONLY
Definition: footprint.h:72
@ FP_EXCLUDE_FROM_BOM
Definition: footprint.h:71
@ FP_THROUGH_HOLE
Definition: footprint.h:68
@ FP_ALLOW_SOLDERMASK_BRIDGES
Definition: footprint.h:74
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:139
std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:131
#define CTL_OMIT_FOOTPRINT_VERSION
Omit the version string from the (footprint) sexpr group.
Definition: pcb_plugin.h:149
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
Definition: pcb_plugin.h:133
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
Definition: pcb_plugin.h:141
#define CTL_OMIT_INITIAL_COMMENTS
omit FOOTPRINT initial comments
Definition: pcb_plugin.h:142
#define CTL_OMIT_LIBNAME
Omit lib alias when saving (used for board/not library).
Definition: pcb_plugin.h:147
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
Definition: pcb_plugin.h:143
#define CTL_OMIT_AT
Omit position and rotation.
Definition: pcb_plugin.h:144
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_QUOTED_STR
Definition: string_utils.h:57

References KIID::AsString(), KIID_PATH::AsString(), CTL_OMIT_AT, CTL_OMIT_FOOTPRINT_VERSION, CTL_OMIT_INITIAL_COMMENTS, CTL_OMIT_LIBNAME, CTL_OMIT_PATH, CTL_OMIT_TSTAMPS, CTX_QUOTED_STR, EscapeString(), LIB_ID::Format(), PCB_PLUGIN::Format(), EDA_UNIT_UTILS::FormatAngle(), FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), FP_ALLOW_MISSING_COURTYARD, FP_ALLOW_SOLDERMASK_BRIDGES, FP_BOARD_ONLY, FP_EXCLUDE_FROM_BOM, FP_EXCLUDE_FROM_POS_FILES, FP_SMD, FP_THROUGH_HOLE, FOOTPRINT::GetAttributes(), FOOTPRINT::GetDescription(), FOOTPRINT::GetFPID(), FOOTPRINT::GetInitialComments(), FOOTPRINT::GetKeywords(), FOOTPRINT::GetLayer(), LIB_ID::GetLibItemName(), FOOTPRINT::GetLocalClearance(), FOOTPRINT::GetLocalSolderMaskMargin(), FOOTPRINT::GetLocalSolderPasteMargin(), FOOTPRINT::GetLocalSolderPasteMarginRatio(), FOOTPRINT::GetNetTiePadGroups(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPath(), FOOTPRINT::GetPosition(), FOOTPRINT::GetPrivateLayers(), FOOTPRINT::GetProperties(), FOOTPRINT::GetZoneConnection(), FOOTPRINT::GraphicalItems(), group, FOOTPRINT::Groups(), INHERITED, FOOTPRINT::IsLocked(), FOOTPRINT::IsNetTie(), FOOTPRINT::IsPlaced(), EDA_ANGLE::IsZero(), PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, FOOTPRINT::Models(), LSET::Name(), pad, FOOTPRINT::Pads(), pcbIUScale, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotes(), OUTPUTFORMATTER::Quotew(), FOOTPRINT::Reference(), LSET::Seq(), SEXPR_BOARD_FILE_VERSION, TO_UTF8, FOOTPRINT::Value(), and FOOTPRINT::Zones().

◆ format() [3/15]

void PCB_PLUGIN::format ( const FP_SHAPE aFPShape,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 980 of file pcb_plugin.cpp.

981{
982 std::string locked = aFPShape->IsLocked() ? " locked" : "";
983
984 switch( aFPShape->GetShape() )
985 {
986 case SHAPE_T::SEGMENT:
987 m_out->Print( aNestLevel, "(fp_line%s (start %s) (end %s)",
988 locked.c_str(),
991 break;
992
993 case SHAPE_T::RECT:
994 m_out->Print( aNestLevel, "(fp_rect%s (start %s) (end %s)",
995 locked.c_str(),
998 break;
999
1000 case SHAPE_T::CIRCLE:
1001 m_out->Print( aNestLevel, "(fp_circle%s (center %s) (end %s)",
1002 locked.c_str(),
1004 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() );
1005 break;
1006
1007 case SHAPE_T::ARC:
1008 m_out->Print( aNestLevel, "(fp_arc%s (start %s) (mid %s) (end %s)",
1009 locked.c_str(),
1012 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() );
1013 break;
1014
1015 case SHAPE_T::POLY:
1016 if( aFPShape->IsPolyShapeValid() )
1017 {
1018 const SHAPE_POLY_SET& poly = aFPShape->GetPolyShape();
1019 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
1020
1021 m_out->Print( aNestLevel, "(fp_poly%s\n", locked.c_str() );
1022 formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave );
1023 }
1024 else
1025 {
1026 wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
1027 return;
1028 }
1029 break;
1030
1031 case SHAPE_T::BEZIER:
1032 m_out->Print( aNestLevel, "(fp_curve%s (pts (xy %s) (xy %s) (xy %s) (xy %s))",
1033 locked.c_str(),
1037 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() );
1038 break;
1039
1040 default:
1041 wxFAIL_MSG( wxT( "PCB_PLUGIN::format not implemented for " ) + aFPShape->SHAPE_T_asString() );
1042 return;
1043 };
1044
1045 m_out->Print( 0, "\n" );
1046
1047 aFPShape->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
1048
1049 // The filled flag represents if a solid fill is present on circles, rectangles and polygons
1050 if( ( aFPShape->GetShape() == SHAPE_T::POLY )
1051 || ( aFPShape->GetShape() == SHAPE_T::RECT )
1052 || ( aFPShape->GetShape() == SHAPE_T::CIRCLE ) )
1053 {
1054 if( aFPShape->IsFilled() )
1055 m_out->Print( 0, " (fill solid)" );
1056 else
1057 m_out->Print( 0, " (fill none)" );
1058 }
1059
1060 formatLayer( aFPShape->GetLayer() );
1061
1062 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aFPShape->m_Uuid.AsString() ) );
1063
1064 m_out->Print( 0, ")\n" );
1065}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
virtual bool IsLocked() const
Definition: board_item.cpp:71
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
bool IsFilled() const
Definition: eda_shape.h:90
SHAPE_T GetShape() const
Definition: eda_shape.h:113
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:75
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1230
VECTOR2I GetArcMid0() const
Definition: fp_shape.cpp:179
const VECTOR2I & GetBezierC1_0() const
Definition: fp_shape.h:98
const VECTOR2I & GetEnd0() const
Definition: fp_shape.h:95
const VECTOR2I & GetBezierC2_0() const
Definition: fp_shape.h:101
const VECTOR2I & GetStart0() const
Definition: fp_shape.h:92
void formatPolyPts(const SHAPE_LINE_CHAIN &outline, int aNestLevel, bool aCompact) const
Definition: pcb_plugin.cpp:403
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:71
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const

References ARC, KIID::AsString(), BEZIER, CIRCLE, STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatPolyPts(), FP_SHAPE::GetArcMid0(), FP_SHAPE::GetBezierC1_0(), FP_SHAPE::GetBezierC2_0(), ADVANCED_CFG::GetCfg(), FP_SHAPE::GetEnd0(), BOARD_ITEM::GetLayer(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), FP_SHAPE::GetStart0(), PCB_SHAPE::GetStroke(), EDA_SHAPE::IsFilled(), BOARD_ITEM::IsLocked(), EDA_SHAPE::IsPolyShapeValid(), locked, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), pcbIUScale, POLY, OUTPUTFORMATTER::Print(), RECT, SEGMENT, EDA_SHAPE::SHAPE_T_asString(), and TO_UTF8.

◆ format() [4/15]

void PCB_PLUGIN::format ( const FP_TEXT aText,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1879 of file pcb_plugin.cpp.

1880{
1881 std::string type;
1882
1883 switch( aText->GetType() )
1884 {
1885 case FP_TEXT::TEXT_is_REFERENCE: type = "reference"; break;
1886 case FP_TEXT::TEXT_is_VALUE: type = "value"; break;
1887 case FP_TEXT::TEXT_is_DIVERS: type = "user";
1888 }
1889
1890 std::string locked = aText->IsLocked() ? " locked" : "";
1891
1892 m_out->Print( aNestLevel, "(fp_text %s%s %s (at %s",
1893 type.c_str(),
1894 locked.c_str(),
1895 m_out->Quotew( aText->GetText() ).c_str(),
1897
1898 // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1899 // but internally the angle is held relative to its parent footprint. parent
1900 // may be NULL when saving a footprint outside a BOARD.
1901 EDA_ANGLE orient = aText->GetTextAngle();
1902 FOOTPRINT* parent = static_cast<FOOTPRINT*>( aText->GetParent() );
1903
1904 if( parent )
1905 {
1906 // GetTextAngle() is always in -360..+360 range because of
1907 // FP_TEXT::SetTextAngle(), but summing that angle with an
1908 // additional board angle could kick sum up >= 360 or <= -360, so to have
1909 // consistent results, normalize again for the BOARD save. A footprint
1910 // save does not use this code path since parent is NULL.
1911#if 0
1912 // This one could be considered reasonable if you like positive angles
1913 // in your board text.
1914 orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1915#else
1916 // Choose compatibility for now, even though this is only a 720 degree clamp
1917 // with two possible values for every angle.
1918 orient = ( orient + parent->GetOrientation() ).Normalize720();
1919#endif
1920 }
1921
1922 if( !orient.IsZero() )
1923 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( orient ).c_str() );
1924
1925 if( !aText->IsKeepUpright() )
1926 m_out->Print( 0, " unlocked" );
1927
1928 m_out->Print( 0, ")" );
1929 formatLayer( aText->GetLayer(), aText->IsKnockout() );
1930
1931 if( !aText->IsVisible() )
1932 m_out->Print( 0, " hide" );
1933
1934 m_out->Print( 0, "\n" );
1935
1936 aText->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE );
1937
1938 m_out->Print( aNestLevel + 1, "(tstamp %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
1939
1940 if( aText->GetFont() && aText->GetFont()->IsOutline() )
1941 formatRenderCache( aText, aNestLevel + 1 );
1942
1943 m_out->Print( aNestLevel, ")\n" );
1944}
virtual bool IsKnockout() const
Definition: board_item.h:250
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:163
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
bool IsKeepUpright() const
Definition: eda_text.h:148
virtual bool IsVisible() const
Definition: eda_text.h:129
KIFONT::FONT * GetFont() const
Definition: eda_text.h:181
const VECTOR2I & GetPos0() const
Definition: fp_text.h:124
@ TEXT_is_REFERENCE
Definition: fp_text.h:49
@ TEXT_is_DIVERS
Definition: fp_text.h:51
@ TEXT_is_VALUE
Definition: fp_text.h:50
TEXT_TYPE GetType() const
Definition: fp_text.h:120
virtual bool IsOutline() const
Definition: font.h:113
void formatRenderCache(const EDA_TEXT *aText, int aNestLevel) const
Definition: pcb_plugin.cpp:456
#define CTL_OMIT_HIDE
Definition: eda_text.h:53
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:205

References KIID::AsString(), CTL_OMIT_HIDE, EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatRenderCache(), EDA_TEXT::GetFont(), BOARD_ITEM::GetLayer(), FOOTPRINT::GetOrientation(), BOARD_ITEM::GetParent(), FP_TEXT::GetPos0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), FP_TEXT::GetType(), EDA_TEXT::IsKeepUpright(), BOARD_ITEM::IsKnockout(), BOARD_ITEM::IsLocked(), KIFONT::FONT::IsOutline(), EDA_TEXT::IsVisible(), EDA_ANGLE::IsZero(), locked, PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, NormalizeAnglePos(), pcbIUScale, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), FP_TEXT::TEXT_is_DIVERS, FP_TEXT::TEXT_is_REFERENCE, FP_TEXT::TEXT_is_VALUE, and TO_UTF8.

◆ format() [5/15]

void PCB_PLUGIN::format ( const FP_TEXTBOX aTextBox,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1947 of file pcb_plugin.cpp.

1948{
1949 std::string locked = aTextBox->IsLocked() ? " locked" : "";
1950
1951 m_out->Print( aNestLevel, "(fp_text_box%s %s\n",
1952 locked.c_str(),
1953 m_out->Quotew( aTextBox->GetText() ).c_str() );
1954
1955 if( aTextBox->GetShape() == SHAPE_T::RECT )
1956 {
1957 m_out->Print( aNestLevel, "(start %s) (end %s)",
1959 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetEnd0() ).c_str() );
1960 }
1961 else if( aTextBox->GetShape() == SHAPE_T::POLY )
1962 {
1963 const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape();
1964 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
1965
1966 formatPolyPts( outline, aNestLevel, true );
1967 }
1968 else
1969 {
1970 UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() );
1971 }
1972
1973 if( !aTextBox->GetTextAngle().IsZero() )
1974 m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() );
1975
1976 formatLayer( aTextBox->GetLayer() );
1977
1978 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTextBox->m_Uuid.AsString() ) );
1979
1980 m_out->Print( 0, "\n" );
1981
1982 // FP_TEXTBOXes are never hidden, so always omit "hide" attribute
1983 aTextBox->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE );
1984
1985 if( aTextBox->GetStroke().GetWidth() > 0 )
1986 aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
1987
1988 if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() )
1989 formatRenderCache( aTextBox, aNestLevel + 1 );
1990
1991 m_out->Print( aNestLevel, ")\n" );
1992}
int GetWidth() const
Definition: stroke_params.h:98
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120

References KIID::AsString(), CTL_OMIT_HIDE, STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatPolyPts(), PCB_PLUGIN::formatRenderCache(), FP_SHAPE::GetEnd0(), EDA_TEXT::GetFont(), BOARD_ITEM::GetLayer(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), FP_SHAPE::GetStart0(), PCB_SHAPE::GetStroke(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), STROKE_PARAMS::GetWidth(), BOARD_ITEM::IsLocked(), KIFONT::FONT::IsOutline(), EDA_ANGLE::IsZero(), locked, PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), pcbIUScale, POLY, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), RECT, EDA_SHAPE::SHAPE_T_asString(), TO_UTF8, and UNIMPLEMENTED_FOR.

◆ format() [6/15]

void PCB_PLUGIN::format ( const PAD aPad,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1407 of file pcb_plugin.cpp.

1408{
1409 const BOARD* board = aPad->GetBoard();
1410 const char* shape;
1411
1412 switch( aPad->GetShape() )
1413 {
1414 case PAD_SHAPE::CIRCLE: shape = "circle"; break;
1415 case PAD_SHAPE::RECT: shape = "rect"; break;
1416 case PAD_SHAPE::OVAL: shape = "oval"; break;
1417 case PAD_SHAPE::TRAPEZOID: shape = "trapezoid"; break;
1419 case PAD_SHAPE::ROUNDRECT: shape = "roundrect"; break;
1420 case PAD_SHAPE::CUSTOM: shape = "custom"; break;
1421
1422 default:
1423 THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1424 }
1425
1426 const char* type;
1427
1428 switch( aPad->GetAttribute() )
1429 {
1430 case PAD_ATTRIB::PTH: type = "thru_hole"; break;
1431 case PAD_ATTRIB::SMD: type = "smd"; break;
1432 case PAD_ATTRIB::CONN: type = "connect"; break;
1433 case PAD_ATTRIB::NPTH: type = "np_thru_hole"; break;
1434
1435 default:
1436 THROW_IO_ERROR( wxString::Format( wxT( "unknown pad attribute: %d" ),
1437 aPad->GetAttribute() ) );
1438 }
1439
1440 const char* property = nullptr;
1441
1442 switch( aPad->GetProperty() )
1443 {
1444 case PAD_PROP::NONE: break; // could be "none"
1445 case PAD_PROP::BGA: property = "pad_prop_bga"; break;
1446 case PAD_PROP::FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1447 case PAD_PROP::FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1448 case PAD_PROP::TESTPOINT: property = "pad_prop_testpoint"; break;
1449 case PAD_PROP::HEATSINK: property = "pad_prop_heatsink"; break;
1450 case PAD_PROP::CASTELLATED: property = "pad_prop_castellated"; break;
1451
1452 default:
1453 THROW_IO_ERROR( wxString::Format( wxT( "unknown pad property: %d" ),
1454 aPad->GetProperty() ) );
1455 }
1456
1457 m_out->Print( aNestLevel, "(pad %s %s %s",
1458 m_out->Quotew( aPad->GetNumber() ).c_str(),
1459 type,
1460 shape );
1461
1462 if( aPad->IsLocked() )
1463 m_out->Print( 0, " locked" );
1464
1465 m_out->Print( 0, " (at %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetPos0() ).c_str() );
1466
1467 if( !aPad->GetOrientation().IsZero() )
1468 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aPad->GetOrientation() ).c_str() );
1469
1470 m_out->Print( 0, ")" );
1471
1472 m_out->Print( 0, " (size %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetSize() ).c_str() );
1473
1474 if( (aPad->GetDelta().x) != 0 || (aPad->GetDelta().y != 0 ) )
1475 m_out->Print( 0, " (rect_delta %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetDelta() ).c_str() );
1476
1477 VECTOR2I sz = aPad->GetDrillSize();
1478 VECTOR2I shapeoffset = aPad->GetOffset();
1479
1480 if( (sz.x > 0) || (sz.y > 0) ||
1481 (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1482 {
1483 m_out->Print( 0, " (drill" );
1484
1485 if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1486 m_out->Print( 0, " oval" );
1487
1488 if( sz.x > 0 )
1489 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, sz.x ).c_str() );
1490
1491 if( sz.y > 0 && sz.x != sz.y )
1492 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, sz.y ).c_str() );
1493
1494 if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1495 m_out->Print( 0, " (offset %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetOffset() ).c_str() );
1496
1497 m_out->Print( 0, ")" );
1498 }
1499
1500 // Add pad property, if exists.
1501 if( property )
1502 m_out->Print( 0, " (property %s)", property );
1503
1504 formatLayers( aPad->GetLayerSet() );
1505
1506 if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
1507 {
1508 if( aPad->GetRemoveUnconnected() )
1509 {
1510 m_out->Print( 0, " (remove_unused_layers)" );
1511
1512 if( aPad->GetKeepTopBottom() )
1513 m_out->Print( 0, " (keep_end_layers)" );
1514
1515 if( board ) // Will be nullptr in footprint library
1516 {
1517 m_out->Print( 0, " (zone_layer_connections" );
1518
1519 for( LSEQ cu = board->GetEnabledLayers().CuStack(); cu; ++cu )
1520 {
1521 if( aPad->ZoneConnectionCache( *cu ) == ZLC_CONNECTED )
1522 m_out->Print( 0, " %s", m_out->Quotew( LSET::Name( *cu ) ).c_str() );
1523 }
1524
1525 m_out->Print( 0, ")" );
1526 }
1527 }
1528 }
1529
1530 // Output the radius ratio for rounded and chamfered rect pads
1532 {
1533 m_out->Print( 0, " (roundrect_rratio %s)",
1534 FormatDouble2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1535 }
1536
1537 // Output the chamfer corners for chamfered rect pads
1538 if( aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT)
1539 {
1540 m_out->Print( 0, "\n" );
1541
1542 m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
1543 FormatDouble2Str( aPad->GetChamferRectRatio() ).c_str() );
1544
1545 m_out->Print( 0, " (chamfer" );
1546
1547 if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
1548 m_out->Print( 0, " top_left" );
1549
1551 m_out->Print( 0, " top_right" );
1552
1554 m_out->Print( 0, " bottom_left" );
1555
1557 m_out->Print( 0, " bottom_right" );
1558
1559 m_out->Print( 0, ")" );
1560 }
1561
1562 std::string output;
1563
1564 // Unconnected pad is default net so don't save it.
1566 {
1567 StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1568 m_out->Quotew( aPad->GetNetname() ).c_str() );
1569 }
1570
1571 // Pin functions and types are closely related to nets, so if CTL_OMIT_NETS is set, omit
1572 // them as well (for instance when saved from library editor).
1573 if( !( m_ctl & CTL_OMIT_PAD_NETS ) )
1574 {
1575 if( !aPad->GetPinFunction().IsEmpty() )
1576 {
1577 StrPrintf( &output, " (pinfunction %s)",
1578 m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1579 }
1580
1581 if( !aPad->GetPinType().IsEmpty() )
1582 {
1583 StrPrintf( &output, " (pintype %s)",
1584 m_out->Quotew( aPad->GetPinType() ).c_str() );
1585 }
1586 }
1587
1588 if( aPad->GetPadToDieLength() != 0 )
1589 {
1590 StrPrintf( &output, " (die_length %s)",
1592 }
1593
1594 if( aPad->GetLocalSolderMaskMargin() != 0 )
1595 {
1596 StrPrintf( &output, " (solder_mask_margin %s)",
1598 }
1599
1600 if( aPad->GetLocalSolderPasteMargin() != 0 )
1601 {
1602 StrPrintf( &output, " (solder_paste_margin %s)",
1604 }
1605
1606 if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1607 {
1608 StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1610 }
1611
1612 if( aPad->GetLocalClearance() != 0 )
1613 {
1614 StrPrintf( &output, " (clearance %s)",
1616 }
1617
1619 {
1620 StrPrintf( &output, " (zone_connect %d)",
1621 static_cast<int>( aPad->GetZoneConnection() ) );
1622 }
1623
1624 if( aPad->GetThermalSpokeWidth() != 0 )
1625 {
1626 StrPrintf( &output, " (thermal_bridge_width %s)",
1628 }
1629
1630 if( ( aPad->GetShape() == PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_45 )
1631 || ( aPad->GetShape() != PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_90 ) )
1632 {
1633 StrPrintf( &output, " (thermal_bridge_angle %s)",
1635 }
1636
1637 if( aPad->GetThermalGap() != 0 )
1638 {
1639 StrPrintf( &output, " (thermal_gap %s)",
1641 }
1642
1643 if( output.size() )
1644 {
1645 m_out->Print( 0, "\n" );
1646 m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1647 }
1648
1649 if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
1650 {
1651 m_out->Print( 0, "\n");
1652 m_out->Print( aNestLevel+1, "(options" );
1653
1655 m_out->Print( 0, " (clearance convexhull)" );
1656 #if 1 // Set to 1 to output the default option
1657 else
1658 m_out->Print( 0, " (clearance outline)" );
1659 #endif
1660
1661 // Output the anchor pad shape (circle/rect)
1662 if( aPad->GetAnchorPadShape() == PAD_SHAPE::RECT )
1663 shape = "rect";
1664 else
1665 shape = "circle";
1666
1667 m_out->Print( 0, " (anchor %s)", shape );
1668
1669 m_out->Print( 0, ")"); // end of (options ...
1670
1671 // Output graphic primitive of the pad shape
1672 m_out->Print( 0, "\n");
1673 m_out->Print( aNestLevel+1, "(primitives" );
1674
1675 int nested_level = aNestLevel+2;
1676
1677 // Output all basic shapes
1678 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives() )
1679 {
1680 m_out->Print( 0, "\n");
1681
1682 switch( primitive->GetShape() )
1683 {
1684 case SHAPE_T::SEGMENT:
1685 m_out->Print( nested_level, "(gr_line (start %s) (end %s)",
1686 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1687 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1688 break;
1689
1690 case SHAPE_T::RECT:
1691 if( primitive->IsAnnotationProxy() )
1692 {
1693 m_out->Print( nested_level, "(gr_bbox (start %s) (end %s)",
1694 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1695 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1696 }
1697 else
1698 {
1699 m_out->Print( nested_level, "(gr_rect (start %s) (end %s)",
1700 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1701 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1702 }
1703 break;
1704
1705 case SHAPE_T::ARC:
1706 m_out->Print( nested_level, "(gr_arc (start %s) (mid %s) (end %s)",
1707 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1708 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetArcMid() ).c_str(),
1709 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1710 break;
1711
1712 case SHAPE_T::CIRCLE:
1713 m_out->Print( nested_level, "(gr_circle (center %s) (end %s)",
1714 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1715 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1716 break;
1717
1718 case SHAPE_T::BEZIER:
1719 m_out->Print( nested_level, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
1720 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(),
1721 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetBezierC1() ).c_str(),
1722 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetBezierC2() ).c_str(),
1723 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() );
1724 break;
1725
1726 case SHAPE_T::POLY:
1727 if( primitive->IsPolyShapeValid() )
1728 {
1729 const SHAPE_POLY_SET& poly = primitive->GetPolyShape();
1730 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
1731
1732 m_out->Print( nested_level, "(gr_poly\n" );
1733 formatPolyPts( outline, nested_level, ADVANCED_CFG::GetCfg().m_CompactSave );
1734 m_out->Print( nested_level, " " ); // just to align the next info at the right place
1735 }
1736 break;
1737
1738 default:
1739 break;
1740 }
1741
1742 m_out->Print( 0, " (width %s)",
1743 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetWidth() ).c_str() );
1744
1745 // The filled flag represents if a solid fill is present on circles,
1746 // rectangles and polygons
1747 if( ( primitive->GetShape() == SHAPE_T::POLY )
1748 || ( primitive->GetShape() == SHAPE_T::RECT )
1749 || ( primitive->GetShape() == SHAPE_T::CIRCLE ) )
1750 {
1751 if( primitive->IsFilled() )
1752 m_out->Print( 0, " (fill yes)" );
1753 else
1754 m_out->Print( 0, " (fill none)" );
1755 }
1756
1757 m_out->Print( 0, ")" );
1758 }
1759
1760 m_out->Print( 0, "\n");
1761 m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1762 }
1763
1764 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aPad->m_Uuid.AsString() ) );
1765
1766 m_out->Print( 0, ")\n" );
1767}
@ ZLC_CONNECTED
Definition: board_item.h:47
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:43
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:526
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:491
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
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:373
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: pad.cpp:786
PAD_PROP GetProperty() const
Definition: pad.h:398
bool GetRemoveUnconnected() const
Definition: pad.h:604
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: pad.h:378
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pad.h:392
const wxString & GetPinType() const
Definition: pad.h:152
const VECTOR2I & GetDrillSize() const
Definition: pad.h:262
PAD_ATTRIB GetAttribute() const
Definition: pad.h:395
ZONE_CONNECTION GetZoneConnection() const
Definition: pad.h:517
const wxString & GetPinFunction() const
Definition: pad.h:146
const wxString & GetNumber() const
Definition: pad.h:135
double GetLocalSolderPasteMarginRatio() const
Definition: pad.h:420
bool IsLocked() const override
Definition: pad.cpp:156
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives() const
Accessor to the basic shape list for custom-shaped pads.
Definition: pad.h:325
EDA_ANGLE GetThermalSpokeAngle() const
Definition: pad.h:536
const VECTOR2I & GetOffset() const
Definition: pad.h:269
int GetLocalSolderMaskMargin() const
Definition: pad.h:410
bool GetKeepTopBottom() const
Definition: pad.h:610
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: pad.h:207
const VECTOR2I & GetDelta() const
Definition: pad.h:259
PAD_SHAPE GetShape() const
Definition: pad.h:189
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:365
ZONE_LAYER_CONNECTION & ZoneConnectionCache(PCB_LAYER_ID aLayer) const
Definition: pad.h:736
int GetThermalSpokeWidth() const
Definition: pad.h:526
int GetLocalSolderPasteMargin() const
Definition: pad.h:417
int GetChamferPositions() const
Definition: pad.h:589
double GetRoundRectRadiusRatio() const
Definition: pad.h:570
int GetThermalGap() const
Definition: pad.h:549
const VECTOR2I & GetPos0() const
Definition: pad.h:246
const VECTOR2I & GetSize() const
Definition: pad.h:252
PAD_SHAPE GetAnchorPadShape() const
Definition: pad.h:202
double GetChamferRectRatio() const
Definition: pad.h:579
int GetPadToDieLength() const
Definition: pad.h:408
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
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:425
static constexpr EDA_ANGLE & ANGLE_45
Definition: eda_angle.h:413
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:414
@ CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL
Definition: pad.h:45
@ NPTH
like PAD_PTH, but not plated
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default)
@ PAD_DRILL_SHAPE_OBLONG
Definition: pad_shapes.h:71
@ FIDUCIAL_LOCAL
a fiducial (usually a smd) local to the parent footprint
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
@ HEATSINK
a pad used as heat sink, usually in SMD footprints
@ NONE
no special fabrication property
@ TESTPOINT
a test point pad
@ CASTELLATED
a pad with a castellated through hole
@ BGA
Smd pad, used in BGA footprints.
#define CTL_OMIT_PAD_NETS
Omit pads net names (useless in library)
Definition: pcb_plugin.h:140
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
Definition: richio.cpp:84

References _, ANGLE_45, ANGLE_90, ARC, KIID::AsString(), BEZIER, BGA, CASTELLATED, CHAMFERED_RECT, CIRCLE, CONN, CTL_OMIT_PAD_NETS, CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL, LSET::CuStack(), CUSTOM, FIDUCIAL_GLBL, FIDUCIAL_LOCAL, Format(), EDA_UNIT_UTILS::FormatAngle(), FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayers(), PCB_PLUGIN::formatPolyPts(), PAD::GetAnchorPadShape(), PAD::GetAttribute(), BOARD_ITEM::GetBoard(), ADVANCED_CFG::GetCfg(), PAD::GetChamferPositions(), PAD::GetChamferRectRatio(), PAD::GetCustomShapeInZoneOpt(), PAD::GetDelta(), PAD::GetDrillShape(), PAD::GetDrillSize(), BOARD::GetEnabledLayers(), PAD::GetKeepTopBottom(), PAD::GetLayerSet(), PAD::GetLocalClearance(), PAD::GetLocalSolderMaskMargin(), PAD::GetLocalSolderPasteMargin(), PAD::GetLocalSolderPasteMarginRatio(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), PAD::GetNumber(), PAD::GetOffset(), PAD::GetOrientation(), PAD::GetPadToDieLength(), PAD::GetPinFunction(), PAD::GetPinType(), PAD::GetPos0(), PAD::GetPrimitives(), PAD::GetProperty(), PAD::GetRemoveUnconnected(), PAD::GetRoundRectRadiusRatio(), PAD::GetShape(), PAD::GetSize(), PAD::GetThermalGap(), PAD::GetThermalSpokeAngle(), PAD::GetThermalSpokeWidth(), PAD::GetZoneConnection(), HEATSINK, INHERITED, PAD::IsLocked(), EDA_ANGLE::IsZero(), PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_mapping, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, LSET::Name(), NONE, NPTH, SHAPE_POLY_SET::Outline(), OVAL, PAD_DRILL_SHAPE_OBLONG, pcbIUScale, POLY, OUTPUTFORMATTER::Print(), PTH, OUTPUTFORMATTER::Quotew(), RECT, RECT_CHAMFER_BOTTOM_LEFT, RECT_CHAMFER_BOTTOM_RIGHT, RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_TOP_RIGHT, ROUNDRECT, SEGMENT, SMD, StrPrintf(), TESTPOINT, THROW_IO_ERROR, TO_UTF8, NETINFO_MAPPING::Translate(), TRAPEZOID, NETINFO_LIST::UNCONNECTED, VECTOR2< T >::x, VECTOR2< T >::y, ZLC_CONNECTED, and PAD::ZoneConnectionCache().

◆ format() [7/15]

void PCB_PLUGIN::format ( const PCB_BITMAP aBitmap,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 932 of file pcb_plugin.cpp.

933{
934 wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
935
936 const wxImage* image = aBitmap->GetImage()->GetImageData();
937
938 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
939
940 m_out->Print( aNestLevel, "(image (at %s %s)",
943
944 formatLayer( aBitmap->GetLayer() );
945
946 if( aBitmap->GetImage()->GetScale() != 1.0 )
947 m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
948
949 m_out->Print( 0, "\n" );
950
951 m_out->Print( aNestLevel + 1, "(data" );
952
953 wxMemoryOutputStream stream;
954
955 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
956
957 // Write binary data in hexadecimal form (ASCII)
958 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
959 wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
960
961 // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
962 // so use it in a vein attempt to be standard like.
963#define MIME_BASE64_LENGTH 76
964
965 size_t first = 0;
966
967 while( first < out.Length() )
968 {
969 m_out->Print( 0, "\n" );
970 m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
971 first += MIME_BASE64_LENGTH;
972 }
973
974 m_out->Print( 0, "\n" );
975 m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
976 m_out->Print( aNestLevel, ")\n" ); // Closes image token.
977}
double GetScale() const
Definition: bitmap_base.h:78
wxImage * GetImageData()
Definition: bitmap_base.h:69
VECTOR2I GetPosition() const override
Definition: pcb_bitmap.h:117
BITMAP_BASE * GetImage() const
Definition: pcb_bitmap.h:53
#define MIME_BASE64_LENGTH

References EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), BOARD_ITEM::GetLayer(), PCB_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), image, PCB_PLUGIN::m_out, MIME_BASE64_LENGTH, pcbIUScale, OUTPUTFORMATTER::Print(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ format() [8/15]

void PCB_PLUGIN::format ( const PCB_DIMENSION_BASE aDimension,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 734 of file pcb_plugin.cpp.

735{
736 const PCB_DIM_ALIGNED* aligned = dynamic_cast<const PCB_DIM_ALIGNED*>( aDimension );
737 const PCB_DIM_ORTHOGONAL* ortho = dynamic_cast<const PCB_DIM_ORTHOGONAL*>( aDimension );
738 const PCB_DIM_CENTER* center = dynamic_cast<const PCB_DIM_CENTER*>( aDimension );
739 const PCB_DIM_RADIAL* radial = dynamic_cast<const PCB_DIM_RADIAL*>( aDimension );
740 const PCB_DIM_LEADER* leader = dynamic_cast<const PCB_DIM_LEADER*>( aDimension );
741
742 m_out->Print( aNestLevel, "(dimension" );
743
744 if( aDimension->IsLocked() )
745 m_out->Print( 0, " locked" );
746
747 if( ortho ) // must be tested before aligned, because ortho is derived from aligned
748 // and aligned is not null
749 m_out->Print( 0, " (type orthogonal)" );
750 else if( aligned )
751 m_out->Print( 0, " (type aligned)" );
752 else if( leader )
753 m_out->Print( 0, " (type leader)" );
754 else if( center )
755 m_out->Print( 0, " (type center)" );
756 else if( radial )
757 m_out->Print( 0, " (type radial)" );
758 else
759 wxFAIL_MSG( wxT( "Cannot format unknown dimension type!" ) );
760
761 formatLayer( aDimension->GetLayer() );
762
763 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aDimension->m_Uuid.AsString() ) );
764
765 m_out->Print( 0, "\n" );
766
767 m_out->Print( aNestLevel+1, "(pts (xy %s %s) (xy %s %s))\n",
770 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetEnd().x ).c_str(),
771 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetEnd().y ).c_str() );
772
773 if( aligned )
774 {
775 m_out->Print( aNestLevel+1, "(height %s)\n",
777 }
778
779 if( radial )
780 {
781 m_out->Print( aNestLevel+1, "(leader_length %s)\n",
783 }
784
785 if( ortho )
786 {
787 m_out->Print( aNestLevel+1, "(orientation %d)\n",
788 static_cast<int>( ortho->GetOrientation() ) );
789 }
790
791 if( !center )
792 {
793 Format( &aDimension->Text(), aNestLevel + 1 );
794
795 m_out->Print( aNestLevel + 1, "(format" );
796
797 if( !aDimension->GetPrefix().IsEmpty() )
798 m_out->Print( 0, " (prefix %s)", m_out->Quotew( aDimension->GetPrefix() ).c_str() );
799
800 if( !aDimension->GetSuffix().IsEmpty() )
801 m_out->Print( 0, " (suffix %s)", m_out->Quotew( aDimension->GetSuffix() ).c_str() );
802
803 m_out->Print( 0, " (units %d) (units_format %d) (precision %d)",
804 static_cast<int>( aDimension->GetUnitsMode() ),
805 static_cast<int>( aDimension->GetUnitsFormat() ), aDimension->GetPrecision() );
806
807 if( aDimension->GetOverrideTextEnabled() )
808 m_out->Print( 0, " (override_value %s)",
809 m_out->Quotew( aDimension->GetOverrideText() ).c_str() );
810
811 if( aDimension->GetSuppressZeroes() )
812 m_out->Print( 0, " suppress_zeroes" );
813
814 m_out->Print( 0, ")\n" );
815 }
816
817 m_out->Print( aNestLevel+1, "(style (thickness %s) (arrow_length %s) (text_position_mode %d)",
820 static_cast<int>( aDimension->GetTextPositionMode() ) );
821
822 if( aligned )
823 {
824 m_out->Print( 0, " (extension_height %s)",
826 }
827
828 if( leader )
829 m_out->Print( 0, " (text_frame %d)", static_cast<int>( leader->GetTextBorder() ) );
830
831 m_out->Print( 0, " (extension_offset %s)",
833
834 if( aDimension->GetKeepTextAligned() )
835 m_out->Print( 0, " keep_text_aligned" );
836
837 m_out->Print( 0, ")\n" );
838
839 m_out->Print( aNestLevel, ")\n" );
840}
wxString GetOverrideText() const
wxString GetSuffix() const
int GetLineThickness() const
PCB_TEXT & Text()
DIM_TEXT_POSITION GetTextPositionMode() const
bool GetKeepTextAligned() const
wxString GetPrefix() const
DIM_UNITS_MODE GetUnitsMode() const
DIM_UNITS_FORMAT GetUnitsFormat() const
virtual const VECTOR2I & GetStart() const
The dimension's origin is the first feature point for the dimension.
bool GetSuppressZeroes() const
int GetExtensionOffset() const
int GetPrecision() const
int GetArrowLength() const
bool GetOverrideTextEnabled() const
virtual const VECTOR2I & GetEnd() const
For better understanding of the points that make a dimension:
int GetHeight() const
int GetExtensionHeight() const
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
DIM_TEXT_BORDER GetTextBorder() const
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
A radial dimension indicates either the radius or diameter of an arc or circle.
int GetLeaderLength() const

References KIID::AsString(), PCB_PLUGIN::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_DIMENSION_BASE::GetArrowLength(), PCB_DIMENSION_BASE::GetEnd(), PCB_DIM_ALIGNED::GetExtensionHeight(), PCB_DIMENSION_BASE::GetExtensionOffset(), PCB_DIM_ALIGNED::GetHeight(), PCB_DIMENSION_BASE::GetKeepTextAligned(), BOARD_ITEM::GetLayer(), PCB_DIM_RADIAL::GetLeaderLength(), PCB_DIMENSION_BASE::GetLineThickness(), PCB_DIMENSION_BASE::GetOverrideText(), PCB_DIMENSION_BASE::GetOverrideTextEnabled(), PCB_DIMENSION_BASE::GetPrecision(), PCB_DIMENSION_BASE::GetPrefix(), PCB_DIMENSION_BASE::GetStart(), PCB_DIMENSION_BASE::GetSuffix(), PCB_DIMENSION_BASE::GetSuppressZeroes(), PCB_DIM_LEADER::GetTextBorder(), PCB_DIMENSION_BASE::GetTextPositionMode(), PCB_DIMENSION_BASE::GetUnitsFormat(), PCB_DIMENSION_BASE::GetUnitsMode(), BOARD_ITEM::IsLocked(), PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, ortho, pcbIUScale, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), PCB_DIMENSION_BASE::Text(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ format() [9/15]

void PCB_PLUGIN::format ( const PCB_GROUP aGroup,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1851 of file pcb_plugin.cpp.

1852{
1853 // Don't write empty groups
1854 if( aGroup->GetItems().empty() )
1855 return;
1856
1857 m_out->Print( aNestLevel, "(group %s%s (id %s)\n",
1858 m_out->Quotew( aGroup->GetName() ).c_str(),
1859 aGroup->IsLocked() ? " locked" : "",
1860 TO_UTF8( aGroup->m_Uuid.AsString() ) );
1861
1862 m_out->Print( aNestLevel + 1, "(members\n" );
1863
1864 wxArrayString memberIds;
1865
1866 for( BOARD_ITEM* member : aGroup->GetItems() )
1867 memberIds.Add( member->m_Uuid.AsString() );
1868
1869 memberIds.Sort();
1870
1871 for( const wxString& memberId : memberIds )
1872 m_out->Print( aNestLevel + 2, "%s\n", TO_UTF8( memberId ) );
1873
1874 m_out->Print( aNestLevel + 1, ")\n" ); // Close `members` token.
1875 m_out->Print( aNestLevel, ")\n" ); // Close `group` token.
1876}
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:68
wxString GetName() const
Definition: pcb_group.h:65

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

◆ format() [10/15]

void PCB_PLUGIN::format ( const PCB_SHAPE aSegment,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 843 of file pcb_plugin.cpp.

844{
845 std::string locked = aShape->IsLocked() ? " locked" : "";
846
847 switch( aShape->GetShape() )
848 {
849 case SHAPE_T::SEGMENT:
850 m_out->Print( aNestLevel, "(gr_line%s (start %s) (end %s)",
851 locked.c_str(),
852 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(),
853 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() );
854 break;
855
856 case SHAPE_T::RECT:
857 m_out->Print( aNestLevel, "(gr_rect%s (start %s) (end %s)",
858 locked.c_str(),
859 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(),
860 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() );
861 break;
862
863 case SHAPE_T::CIRCLE:
864 m_out->Print( aNestLevel, "(gr_circle%s (center %s) (end %s)",
865 locked.c_str(),
866 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(),
867 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() );
868 break;
869
870 case SHAPE_T::ARC:
871 m_out->Print( aNestLevel, "(gr_arc%s (start %s) (mid %s) (end %s)",
872 locked.c_str(),
873 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(),
874 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetArcMid() ).c_str(),
875 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() );
876 break;
877
878 case SHAPE_T::POLY:
879 if( aShape->IsPolyShapeValid() )
880 {
881 const SHAPE_POLY_SET& poly = aShape->GetPolyShape();
882 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
883
884 m_out->Print( aNestLevel, "(gr_poly%s\n", locked.c_str() );
885 formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave );
886 }
887 else
888 {
889 wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
890 return;
891 }
892
893 break;
894
895 case SHAPE_T::BEZIER:
896 m_out->Print( aNestLevel, "(gr_curve%s (pts (xy %s) (xy %s) (xy %s) (xy %s))",
897 locked.c_str(),
898 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(),
899 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetBezierC1() ).c_str(),
900 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetBezierC2() ).c_str(),
901 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() );
902 break;
903
904 default:
905 UNIMPLEMENTED_FOR( aShape->SHAPE_T_asString() );
906 return;
907 };
908
909 m_out->Print( 0, "\n" );
910
911 aShape->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
912
913 // The filled flag represents if a solid fill is present on circles, rectangles and polygons
914 if( ( aShape->GetShape() == SHAPE_T::POLY )
915 || ( aShape->GetShape() == SHAPE_T::RECT )
916 || ( aShape->GetShape() == SHAPE_T::CIRCLE ) )
917 {
918 if( aShape->IsFilled() )
919 m_out->Print( 0, " (fill solid)" );
920 else
921 m_out->Print( 0, " (fill none)" );
922 }
923
924 formatLayer( aShape->GetLayer() );
925
926 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aShape->m_Uuid.AsString() ) );
927
928 m_out->Print( 0, ")\n" );
929}

References ARC, KIID::AsString(), BEZIER, CIRCLE, STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatPolyPts(), EDA_SHAPE::GetArcMid(), EDA_SHAPE::GetBezierC1(), EDA_SHAPE::GetBezierC2(), ADVANCED_CFG::GetCfg(), EDA_SHAPE::GetEnd(), BOARD_ITEM::GetLayer(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), PCB_SHAPE::GetStroke(), EDA_SHAPE::IsFilled(), BOARD_ITEM::IsLocked(), EDA_SHAPE::IsPolyShapeValid(), locked, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), pcbIUScale, POLY, OUTPUTFORMATTER::Print(), RECT, SEGMENT, EDA_SHAPE::SHAPE_T_asString(), TO_UTF8, and UNIMPLEMENTED_FOR.

◆ format() [11/15]

void PCB_PLUGIN::format ( const PCB_TARGET aTarget,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1068 of file pcb_plugin.cpp.

1069{
1070 m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
1071 ( aTarget->GetShape() ) ? "x" : "plus",
1074
1075 if( aTarget->GetWidth() != 0 )
1076 m_out->Print( 0, " (width %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTarget->GetWidth() ).c_str() );
1077
1078 formatLayer( aTarget->GetLayer() );
1079
1080 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTarget->m_Uuid.AsString() ) );
1081
1082 m_out->Print( 0, ")\n" );
1083}
int GetShape() const
Definition: pcb_target.h:58
int GetWidth() const
Definition: pcb_target.h:64
int GetSize() const
Definition: pcb_target.h:61
VECTOR2I GetPosition() const override
Definition: pcb_target.h:55

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

◆ format() [12/15]

void PCB_PLUGIN::format ( const PCB_TEXT aText,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1770 of file pcb_plugin.cpp.

1771{
1772 m_out->Print( aNestLevel, "(gr_text" );
1773
1774 if( aText->IsLocked() )
1775 m_out->Print( 0, " locked" );
1776
1777 m_out->Print( 0, " %s (at %s",
1778 m_out->Quotew( aText->GetText() ).c_str(),
1780
1781
1782 if( !aText->GetTextAngle().IsZero() )
1783 m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() );
1784
1785 m_out->Print( 0, ")" );
1786
1787 formatLayer( aText->GetLayer(), aText->IsKnockout() );
1788
1789 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aText->m_Uuid.AsString() ) );
1790
1791 m_out->Print( 0, "\n" );
1792
1793 // PCB_TEXTS are never hidden, so always omit "hide" attribute
1794 aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1795
1796 if( aText->GetFont() && aText->GetFont()->IsOutline() )
1797 formatRenderCache( aText, aNestLevel + 1 );
1798
1799 m_out->Print( aNestLevel, ")\n" );
1800}
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:201

References KIID::AsString(), CTL_OMIT_HIDE, EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatRenderCache(), EDA_TEXT::GetFont(), BOARD_ITEM::GetLayer(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), BOARD_ITEM::IsKnockout(), BOARD_ITEM::IsLocked(), KIFONT::FONT::IsOutline(), EDA_ANGLE::IsZero(), PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, pcbIUScale, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and TO_UTF8.

◆ format() [13/15]

void PCB_PLUGIN::format ( const PCB_TEXTBOX aTextBox,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1803 of file pcb_plugin.cpp.

1804{
1805 std::string locked = aTextBox->IsLocked() ? " locked" : "";
1806
1807 m_out->Print( aNestLevel, "(gr_text_box%s %s\n",
1808 locked.c_str(),
1809 m_out->Quotew( aTextBox->GetText() ).c_str() );
1810
1811 if( aTextBox->GetShape() == SHAPE_T::RECT )
1812 {
1813 m_out->Print( aNestLevel + 1, "(start %s) (end %s)",
1815 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetEnd() ).c_str() );
1816 }
1817 else if( aTextBox->GetShape() == SHAPE_T::POLY )
1818 {
1819 const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape();
1820 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
1821
1822 formatPolyPts( outline, aNestLevel + 1, true );
1823 }
1824 else
1825 {
1826 UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() );
1827 }
1828
1829 if( !aTextBox->GetTextAngle().IsZero() )
1830 m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() );
1831
1832 formatLayer( aTextBox->GetLayer() );
1833
1834 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTextBox->m_Uuid.AsString() ) );
1835
1836 m_out->Print( 0, "\n" );
1837
1838 // PCB_TEXTBOXes are never hidden, so always omit "hide" attribute
1839 aTextBox->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE );
1840
1841 if( aTextBox->GetStroke().GetWidth() > 0 )
1842 aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
1843
1844 if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() )
1845 formatRenderCache( aTextBox, aNestLevel + 1 );
1846
1847 m_out->Print( aNestLevel, ")\n" );
1848}
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120

References KIID::AsString(), CTL_OMIT_HIDE, STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatPolyPts(), PCB_PLUGIN::formatRenderCache(), EDA_SHAPE::GetEnd(), EDA_TEXT::GetFont(), BOARD_ITEM::GetLayer(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), PCB_SHAPE::GetStroke(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), STROKE_PARAMS::GetWidth(), BOARD_ITEM::IsLocked(), KIFONT::FONT::IsOutline(), EDA_ANGLE::IsZero(), locked, PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), pcbIUScale, POLY, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), RECT, EDA_SHAPE::SHAPE_T_asString(), TO_UTF8, and UNIMPLEMENTED_FOR.

◆ format() [14/15]

void PCB_PLUGIN::format ( const PCB_TRACK aTrack,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1995 of file pcb_plugin.cpp.

1996{
1997 if( aTrack->Type() == PCB_VIA_T )
1998 {
1999 PCB_LAYER_ID layer1, layer2;
2000
2001 const PCB_VIA* via = static_cast<const PCB_VIA*>( aTrack );
2002 const BOARD* board = via->GetBoard();
2003
2004 wxCHECK_RET( board != nullptr, wxT( "Via has no parent." ) );
2005
2006 m_out->Print( aNestLevel, "(via" );
2007
2008 via->LayerPair( &layer1, &layer2 );
2009
2010 switch( via->GetViaType() )
2011 {
2012 case VIATYPE::THROUGH: // Default shape not saved.
2013 break;
2014
2016 m_out->Print( 0, " blind" );
2017 break;
2018
2019 case VIATYPE::MICROVIA:
2020 m_out->Print( 0, " micro" );
2021 break;
2022
2023 default:
2024 THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
2025 }
2026
2027 if( via->IsLocked() )
2028 m_out->Print( 0, " locked" );
2029
2030 m_out->Print( 0, " (at %s) (size %s)",
2033
2034 // Old boards were using UNDEFINED_DRILL_DIAMETER value in file for via drill when
2035 // via drill was the netclass value.
2036 // recent boards always set the via drill to the actual value, but now we need to
2037 // always store the drill value, because netclass value is not stored in the board file.
2038 // Otherwise the drill value of some (old) vias can be unknown
2039 if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
2040 {
2041 m_out->Print( 0, " (drill %s)",
2042 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, via->GetDrill() ).c_str() );
2043 }
2044 else // Probably old board!
2045 {
2046 m_out->Print( 0, " (drill %s)",
2047 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, via->GetDrillValue() ).c_str() );
2048 }
2049
2050 m_out->Print( 0, " (layers %s %s)",
2051 m_out->Quotew( LSET::Name( layer1 ) ).c_str(),
2052 m_out->Quotew( LSET::Name( layer2 ) ).c_str() );
2053
2054 if( via->GetRemoveUnconnected() )
2055 {
2056 m_out->Print( 0, " (remove_unused_layers)" );
2057
2058 if( via->GetKeepStartEnd() )
2059 m_out->Print( 0, " (keep_end_layers)" );
2060 }
2061
2062 if( via->GetIsFree() )
2063 m_out->Print( 0, " (free)" );
2064
2065 if( via->GetRemoveUnconnected() )
2066 {
2067 m_out->Print( 0, " (zone_layer_connections" );
2068
2069 for( LSEQ cu = board->GetEnabledLayers().CuStack(); cu; ++cu )
2070 {
2071 if( via->ZoneConnectionCache( *cu ) == ZLC_CONNECTED )
2072 m_out->Print( 0, " %s", m_out->Quotew( LSET::Name( *cu ) ).c_str() );
2073 }
2074
2075 m_out->Print( 0, ")" );
2076 }
2077 }
2078 else if( aTrack->Type() == PCB_ARC_T )
2079 {
2080 const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
2081 std::string locked = arc->IsLocked() ? " locked" : "";
2082
2083 m_out->Print( aNestLevel, "(arc%s (start %s) (mid %s) (end %s) (width %s)",
2084 locked.c_str(),
2089
2090 m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( arc->GetLayer() ) ).c_str() );
2091 }
2092 else
2093 {
2094 std::string locked = aTrack->IsLocked() ? " locked" : "";
2095
2096 m_out->Print( aNestLevel, "(segment%s (start %s) (end %s) (width %s)",
2097 locked.c_str(),
2101
2102 m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( aTrack->GetLayer() ) ).c_str() );
2103 }
2104
2105 m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
2106
2107 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTrack->m_Uuid.AsString() ) );
2108
2109 m_out->Print( 0, ")\n" );
2110}
const VECTOR2I & GetMid() const
Definition: pcb_track.h:310
int GetWidth() const
Definition: pcb_track.h:106
const VECTOR2I & GetStart() const
Definition: pcb_track.h:112
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:109
@ BLIND_BURIED
#define UNDEFINED_DRILL_DIAMETER
Definition: pcb_track.h:71

References _, KIID::AsString(), BLIND_BURIED, LSET::CuStack(), Format(), EDA_UNIT_UTILS::FormatInternalUnits(), BOARD::GetEnabledLayers(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_ARC::GetMid(), BOARD_CONNECTED_ITEM::GetNetCode(), PCB_TRACK::GetStart(), PCB_TRACK::GetWidth(), BOARD_ITEM::IsLocked(), locked, PCB_PLUGIN::m_mapping, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, MICROVIA, LSET::Name(), PCB_ARC_T, PCB_VIA_T, pcbIUScale, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), THROUGH, THROW_IO_ERROR, TO_UTF8, NETINFO_MAPPING::Translate(), EDA_ITEM::Type(), UNDEFINED_DRILL_DIAMETER, via, and ZLC_CONNECTED.

◆ format() [15/15]

void PCB_PLUGIN::format ( const ZONE aZone,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 2113 of file pcb_plugin.cpp.

2114{
2115 std::string locked = aZone->IsLocked() ? " locked" : "";
2116
2117 // Save the NET info.
2118 // For keepout and non copper zones, net code and net name are irrelevant
2119 // so be sure a dummy value is stored, just for ZONE compatibility
2120 // (perhaps netcode and netname should be not stored)
2121 bool has_no_net = aZone->GetIsRuleArea() || !aZone->IsOnCopperLayer();
2122
2123 m_out->Print( aNestLevel, "(zone%s (net %d) (net_name %s)",
2124 locked.c_str(),
2125 has_no_net ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
2126 m_out->Quotew( has_no_net ? wxT("") : aZone->GetNetname() ).c_str() );
2127
2128 // If a zone exists on multiple layers, format accordingly
2129 if( aZone->GetLayerSet().count() > 1 )
2130 {
2131 formatLayers( aZone->GetLayerSet() );
2132 }
2133 else
2134 {
2135 formatLayer( aZone->GetFirstLayer() );
2136 }
2137
2138 m_out->Print( 0, " (tstamp %s)", TO_UTF8( aZone->m_Uuid.AsString() ) );
2139
2140 if( !aZone->GetZoneName().empty() )
2141 m_out->Print( 0, " (name %s)", m_out->Quotew( aZone->GetZoneName() ).c_str() );
2142
2143 // Save the outline aux info
2144 std::string hatch;
2145
2146 switch( aZone->GetHatchStyle() )
2147 {
2148 default:
2149 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: hatch = "none"; break;
2150 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: hatch = "edge"; break;
2151 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: hatch = "full"; break;
2152 }
2153
2154 m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
2156
2157 if( aZone->GetAssignedPriority() > 0 )
2158 m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetAssignedPriority() );
2159
2160 // Add teardrop keywords in file: (attr (teardrop (type xxx)))where xxx is the teardrop type
2161 if( aZone->IsTeardropArea() )
2162 {
2163 const char* td_type;
2164
2165 switch( aZone->GetTeardropAreaType() )
2166 {
2167 case TEARDROP_TYPE::TD_VIAPAD: // a teardrop on a via or pad
2168 td_type = "padvia";
2169 break;
2170
2171 default:
2172 case TEARDROP_TYPE::TD_TRACKEND: // a teardrop on a track end
2173 td_type = "track_end";
2174 break;
2175 }
2176
2177 m_out->Print( aNestLevel+1, "(attr (teardrop (type %s)))\n", td_type );
2178 }
2179
2180 m_out->Print( aNestLevel+1, "(connect_pads" );
2181
2182 switch( aZone->GetPadConnection() )
2183 {
2184 default:
2185 case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
2186 break;
2187
2189 m_out->Print( 0, " thru_hole_only" );
2190 break;
2191
2193 m_out->Print( 0, " yes" );
2194 break;
2195
2197 m_out->Print( 0, " no" );
2198 break;
2199 }
2200
2201 m_out->Print( 0, " (clearance %s))\n",
2203
2204 m_out->Print( aNestLevel+1, "(min_thickness %s)",
2206
2207 // We continue to write this for 3rd-party parsers, but we no longer read it (as of V7).
2208 m_out->Print( 0, " (filled_areas_thickness no)" );
2209
2210 m_out->Print( 0, "\n" );
2211
2212 if( aZone->GetIsRuleArea() )
2213 {
2214 m_out->Print( aNestLevel + 1,
2215 "(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) "
2216 "(footprints %s))\n",
2217 aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
2218 aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
2219 aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
2220 aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
2221 aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
2222 }
2223
2224 m_out->Print( aNestLevel + 1, "(fill" );
2225
2226 // Default is not filled.
2227 if( aZone->IsFilled() )
2228 m_out->Print( 0, " yes" );
2229
2230 // Default is polygon filled.
2232 m_out->Print( 0, " (mode hatch)" );
2233
2234 m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
2237
2239 {
2240 m_out->Print( 0, " (smoothing" );
2241
2242 switch( aZone->GetCornerSmoothingType() )
2243 {
2245 m_out->Print( 0, " chamfer" );
2246 break;
2247
2249 m_out->Print( 0, " fillet" );
2250 break;
2251
2252 default:
2253 THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
2254 aZone->GetCornerSmoothingType() ) );
2255 }
2256 m_out->Print( 0, ")" );
2257
2258 if( aZone->GetCornerRadius() != 0 )
2259 m_out->Print( 0, " (radius %s)",
2261 }
2262
2264 {
2265 m_out->Print( 0, " (island_removal_mode %d) (island_area_min %s)",
2266 static_cast<int>( aZone->GetIslandRemovalMode() ),
2268 }
2269
2271 {
2272 m_out->Print( 0, "\n" );
2273 m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
2276 FormatDouble2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() );
2277
2278 if( aZone->GetHatchSmoothingLevel() > 0 )
2279 {
2280 m_out->Print( 0, "\n" );
2281 m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
2282 aZone->GetHatchSmoothingLevel(),
2283 FormatDouble2Str( aZone->GetHatchSmoothingValue() ).c_str() );
2284 }
2285
2286 m_out->Print( 0, "\n" );
2287 m_out->Print( aNestLevel+2, "(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
2288 aZone->GetHatchBorderAlgorithm() ? "hatch_thickness" : "min_thickness",
2289 FormatDouble2Str( aZone->GetHatchHoleMinArea() ).c_str() );
2290 }
2291
2292 m_out->Print( 0, ")\n" );
2293
2294 if( aZone->GetNumCorners() )
2295 {
2296 SHAPE_POLY_SET::POLYGON poly = aZone->Outline()->Polygon(0);
2297
2298 for( auto& chain : poly )
2299 {
2300 m_out->Print( aNestLevel + 1, "(polygon\n" );
2301 formatPolyPts( chain, aNestLevel + 1, ADVANCED_CFG::GetCfg().m_CompactSave );
2302 m_out->Print( aNestLevel + 1, ")\n" );
2303 }
2304 }
2305
2306 // Save the PolysList (filled areas)
2307 for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() )
2308 {
2309 const std::shared_ptr<SHAPE_POLY_SET>& fv = aZone->GetFilledPolysList( layer );
2310
2311 for( int ii = 0; ii < fv->OutlineCount(); ++ii )
2312 {
2313 m_out->Print( aNestLevel + 1, "(filled_polygon\n" );
2314 m_out->Print( aNestLevel + 2, "(layer %s)\n",
2315 m_out->Quotew( LSET::Name( layer ) ).c_str() );
2316
2317 if( aZone->IsIsland( layer, ii ) )
2318 m_out->Print( aNestLevel + 2, "(island)\n" );
2319
2320 const SHAPE_LINE_CHAIN& chain = fv->COutline( ii );
2321
2322 formatPolyPts( chain, aNestLevel + 1, ADVANCED_CFG::GetCfg().m_CompactSave );
2323 m_out->Print( aNestLevel + 1, ")\n" );
2324 }
2325 }
2326
2327 m_out->Print( aNestLevel, ")\n" );
2328}
double AsDegrees() const
Definition: eda_angle.h:149
POLYGON & Polygon(int aIndex)
std::vector< SHAPE_LINE_CHAIN > POLYGON
< represents a single polygon outline with holes.
int GetHatchBorderAlgorithm() const
Definition: zone.h:278
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
bool GetDoNotAllowVias() const
Definition: zone.h:699
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:602
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:711
bool GetDoNotAllowPads() const
Definition: zone.h:701
bool GetDoNotAllowTracks() const
Definition: zone.h:700
bool IsFilled() const
Definition: zone.h:242
SHAPE_POLY_SET * Outline()
Definition: zone.h:312
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
Definition: zone.cpp:1019
long long int GetMinIslandArea() const
Definition: zone.h:714
wxString GetZoneName() const
Definition: zone.h:124
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: zone.cpp:467
int GetMinThickness() const
Definition: zone.h:251
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:248
int GetHatchThickness() const
Definition: zone.h:260
double GetHatchHoleMinArea() const
Definition: zone.h:275
bool IsTeardropArea() const
Definition: zone.h:681
int GetThermalReliefSpokeWidth() const
Definition: zone.h:195
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: zone.cpp:811
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:580
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:266
bool GetDoNotAllowFootprints() const
Definition: zone.h:702
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:174
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
bool GetDoNotAllowCopperPour() const
Definition: zone.h:698
int GetHatchGap() const
Definition: zone.h:263
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:692
double GetHatchSmoothingValue() const
Definition: zone.h:272
int GetHatchSmoothingLevel() const
Definition: zone.h:269
unsigned int GetCornerRadius() const
Definition: zone.h:652
int GetCornerSmoothingType() const
Definition: zone.h:648
bool IsOnCopperLayer() const override
Definition: zone.cpp:251
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:242
int GetThermalReliefGap() const
Definition: zone.h:184
unsigned GetAssignedPriority() const
Definition: zone.h:112
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: zone.h:490
const double IU_PER_MM
Definition: base_units.h:77
@ THERMAL
Use thermal relief for pads.
@ THT_THERMAL
Thermal relief only for THT pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper

References _, ALWAYS, EDA_ANGLE::AsDegrees(), KIID::AsString(), DIAGONAL_EDGE, DIAGONAL_FULL, Format(), FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), PCB_PLUGIN::formatLayer(), PCB_PLUGIN::formatLayers(), PCB_PLUGIN::formatPolyPts(), FULL, ZONE::GetAssignedPriority(), ZONE::GetBorderHatchPitch(), ADVANCED_CFG::GetCfg(), ZONE::GetCornerRadius(), ZONE::GetCornerSmoothingType(), ZONE::GetDoNotAllowCopperPour(), ZONE::GetDoNotAllowFootprints(), ZONE::GetDoNotAllowPads(), ZONE::GetDoNotAllowTracks(), ZONE::GetDoNotAllowVias(), ZONE::GetFilledPolysList(), ZONE::GetFillMode(), ZONE::GetFirstLayer(), ZONE::GetHatchBorderAlgorithm(), ZONE::GetHatchGap(), ZONE::GetHatchHoleMinArea(), ZONE::GetHatchOrientation(), ZONE::GetHatchSmoothingLevel(), ZONE::GetHatchSmoothingValue(), ZONE::GetHatchStyle(), ZONE::GetHatchThickness(), ZONE::GetIslandRemovalMode(), ZONE::GetIsRuleArea(), ZONE::GetLayerSet(), ZONE::GetLocalClearance(), ZONE::GetMinIslandArea(), ZONE::GetMinThickness(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetNetname(), ZONE::GetNumCorners(), ZONE::GetPadConnection(), ZONE::GetTeardropAreaType(), ZONE::GetThermalReliefGap(), ZONE::GetThermalReliefSpokeWidth(), ZONE::GetZoneName(), HATCH_PATTERN, ZONE::IsFilled(), ZONE::IsIsland(), BOARD_ITEM::IsLocked(), ZONE::IsOnCopperLayer(), ZONE::IsTeardropArea(), EDA_IU_SCALE::IU_PER_MM, locked, PCB_PLUGIN::m_mapping, PCB_PLUGIN::m_out, EDA_ITEM::m_Uuid, LSET::Name(), NO_HATCH, NONE, ZONE::Outline(), pcbIUScale, SHAPE_POLY_SET::Polygon(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), ZONE_SETTINGS::SMOOTHING_CHAMFER, ZONE_SETTINGS::SMOOTHING_FILLET, ZONE_SETTINGS::SMOOTHING_NONE, TD_TRACKEND, TD_VIAPAD, THERMAL, THROW_IO_ERROR, THT_THERMAL, TO_UTF8, and NETINFO_MAPPING::Translate().

◆ formatBoardLayers()

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

formats the board layer information

Definition at line 569 of file pcb_plugin.cpp.

570{
571 m_out->Print( aNestLevel, "(layers\n" );
572
573 // Save only the used copper layers from front to back.
574
575 for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
576 {
577 PCB_LAYER_ID layer = *cu;
578
579 m_out->Print( aNestLevel+1, "(%d %s %s", layer,
580 m_out->Quotew( LSET::Name( layer ) ).c_str(),
581 LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
582
583 if( LSET::Name( layer ) != m_board->GetLayerName( layer ) )
584 m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
585
586 m_out->Print( 0, ")\n" );
587 }
588
589 // Save used non-copper layers in the order they are defined.
590 // desired sequence for non Cu BOARD layers.
591 static const PCB_LAYER_ID non_cu[] =
592 {
593 B_Adhes, // 32
594 F_Adhes,
595 B_Paste,
596 F_Paste,
597 B_SilkS,
598 F_SilkS,
599 B_Mask,
600 F_Mask,
601 Dwgs_User,
602 Cmts_User,
603 Eco1_User,
604 Eco2_User,
605 Edge_Cuts,
606 Margin,
607 B_CrtYd,
608 F_CrtYd,
609 B_Fab,
610 F_Fab,
611 User_1,
612 User_2,
613 User_3,
614 User_4,
615 User_5,
616 User_6,
617 User_7,
618 User_8,
619 User_9
620 };
621
622 for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
623 {
624 PCB_LAYER_ID layer = *seq;
625
626 m_out->Print( aNestLevel+1, "(%d %s user", layer,
627 m_out->Quotew( LSET::Name( layer ) ).c_str() );
628
629 if( m_board->GetLayerName( layer ) != LSET::Name( layer ) )
630 m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
631
632 m_out->Print( 0, ")\n" );
633 }
634
635 m_out->Print( aNestLevel, ")\n\n" );
636}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition: board.cpp:447
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:413
BOARD * m_board
which BOARD, no ownership here
Definition: pcb_plugin.h:414
@ User_8
Definition: layer_ids.h:130
@ F_CrtYd
Definition: layer_ids.h:117
@ B_Adhes
Definition: layer_ids.h:97
@ Edge_Cuts
Definition: layer_ids.h:113
@ Dwgs_User
Definition: layer_ids.h:109
@ F_Paste
Definition: layer_ids.h:101
@ Cmts_User
Definition: layer_ids.h:110
@ User_6
Definition: layer_ids.h:128
@ User_7
Definition: layer_ids.h:129
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ User_5
Definition: layer_ids.h:127
@ Eco1_User
Definition: layer_ids.h:111
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ User_9
Definition: layer_ids.h:131
@ F_Fab
Definition: layer_ids.h:120
@ Margin
Definition: layer_ids.h:114
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ Eco2_User
Definition: layer_ids.h:112
@ User_3
Definition: layer_ids.h:125
@ User_1
Definition: layer_ids.h:123
@ B_SilkS
Definition: layer_ids.h:103
@ User_4
Definition: layer_ids.h:126
@ User_2
Definition: layer_ids.h:124
@ B_Fab
Definition: layer_ids.h:119
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
Definition: board.cpp:474

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

554{
555 const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
556
557 m_out->Print( 0, "\n" );
558 m_out->Print( aNestLevel, "(general\n" );
559 m_out->Print( aNestLevel+1, "(thickness %s)\n",
561
562 m_out->Print( aNestLevel, ")\n\n" );
563
564 aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
565 aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
566}
Container for design settings for a BOARD object.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
const PAGE_INFO & GetPageSettings() const
Definition: board.h:626
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:632
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:272
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:30

References PAGE_INFO::Format(), TITLE_BLOCK::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetDesignSettings(), BOARD::GetPageSettings(), BOARD::GetTitleBlock(), PCB_PLUGIN::m_ctl, PCB_PLUGIN::m_out, pcbIUScale, 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 669 of file pcb_plugin.cpp.

670{
671 formatGeneral( aBoard, aNestLevel );
672
673 // Layers list.
674 formatBoardLayers( aBoard, aNestLevel );
675
676 // Setup
677 formatSetup( aBoard, aNestLevel );
678
679 // Properties
680 formatProperties( aBoard, aNestLevel );
681
682 // Save net codes and names
683 formatNetInformation( aBoard, aNestLevel );
684}
void formatSetup(const BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
Definition: pcb_plugin.cpp:490
void formatNetInformation(const BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Definition: pcb_plugin.cpp:639
void formatProperties(const BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Definition: pcb_plugin.cpp:655
void formatBoardLayers(const BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
Definition: pcb_plugin.cpp:569
void formatGeneral(const BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
Definition: pcb_plugin.cpp:553

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

Referenced by PCB_PLUGIN::format().

◆ formatLayer()

void PCB_PLUGIN::formatLayer ( PCB_LAYER_ID  aLayer,
bool  aIsKnockout = false 
) const
privateinherited

Definition at line 395 of file pcb_plugin.cpp.

396{
397 m_out->Print( 0, " (layer %s%s)",
398 m_out->Quotew( LSET::Name( aLayer ) ).c_str(),
399 aIsKnockout ? " knockout" : "" );
400}

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

Referenced by PCB_PLUGIN::format().

◆ formatLayers()

void PCB_PLUGIN::formatLayers ( LSET  aLayerMask,
int  aNestLevel = 0 
) const
privateinherited

Definition at line 1321 of file pcb_plugin.cpp.

1322{
1323 std::string output;
1324
1325 if( aNestLevel == 0 )
1326 output += ' ';
1327
1328 output += "(layers";
1329
1330 static const LSET cu_all( LSET::AllCuMask() );
1331 static const LSET fr_bk( 2, B_Cu, F_Cu );
1332 static const LSET adhes( 2, B_Adhes, F_Adhes );
1333 static const LSET paste( 2, B_Paste, F_Paste );
1334 static const LSET silks( 2, B_SilkS, F_SilkS );
1335 static const LSET mask( 2, B_Mask, F_Mask );
1336 static const LSET crt_yd( 2, B_CrtYd, F_CrtYd );
1337 static const LSET fab( 2, B_Fab, F_Fab );
1338
1339 LSET cu_mask = cu_all;
1340
1341 // output copper layers first, then non copper
1342
1343 if( ( aLayerMask & cu_mask ) == cu_mask )
1344 {
1345 output += " *.Cu";
1346 aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1347 }
1348 else if( ( aLayerMask & cu_mask ) == fr_bk )
1349 {
1350 output += " F&B.Cu";
1351 aLayerMask &= ~fr_bk;
1352 }
1353
1354 if( ( aLayerMask & adhes ) == adhes )
1355 {
1356 output += " *.Adhes";
1357 aLayerMask &= ~adhes;
1358 }
1359
1360 if( ( aLayerMask & paste ) == paste )
1361 {
1362 output += " *.Paste";
1363 aLayerMask &= ~paste;
1364 }
1365
1366 if( ( aLayerMask & silks ) == silks )
1367 {
1368 output += " *.SilkS";
1369 aLayerMask &= ~silks;
1370 }
1371
1372 if( ( aLayerMask & mask ) == mask )
1373 {
1374 output += " *.Mask";
1375 aLayerMask &= ~mask;
1376 }
1377
1378 if( ( aLayerMask & crt_yd ) == crt_yd )
1379 {
1380 output += " *.CrtYd";
1381 aLayerMask &= ~crt_yd;
1382 }
1383
1384 if( ( aLayerMask & fab ) == fab )
1385 {
1386 output += " *.Fab";
1387 aLayerMask &= ~fab;
1388 }
1389
1390 // output any individual layers not handled in wildcard combos above
1391 wxString layerName;
1392
1393 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1394 {
1395 if( aLayerMask[layer] )
1396 {
1397 layerName = LSET::Name( PCB_LAYER_ID( layer ) );
1398 output += ' ';
1399 output += m_out->Quotew( layerName );
1400 }
1401 }
1402
1403 m_out->Print( aNestLevel, "%s)", output.c_str() );
1404}
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
@ B_Cu
Definition: layer_ids.h:95
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137

References LSET::AllCuMask(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, PCB_PLUGIN::m_out, LSET::Name(), paste, PCB_LAYER_ID_COUNT, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

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

640{
641 for( NETINFO_ITEM* net : *m_mapping )
642 {
643 if( net == nullptr ) // Skip not actually existing nets (orphan nets)
644 continue;
645
646 m_out->Print( aNestLevel, "(net %d %s)\n",
647 m_mapping->Translate( net->GetNetCode() ),
648 m_out->Quotew( net->GetNetname() ).c_str() );
649 }
650
651 m_out->Print( 0, "\n" );
652}
Handle the data for a net.
Definition: netinfo.h:66

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

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

◆ formatPolyPts()

void PCB_PLUGIN::formatPolyPts ( const SHAPE_LINE_CHAIN outline,
int  aNestLevel,
bool  aCompact 
) const
privateinherited

Definition at line 403 of file pcb_plugin.cpp.

405{
406 m_out->Print( aNestLevel + 1, "(pts\n" );
407
408 bool needNewline = false;
409 int nestLevel = aNestLevel + 2;
410 int shapesAdded = 0;
411
412 for( int ii = 0; ii < outline.PointCount(); ++ii )
413 {
414 int ind = outline.ArcIndex( ii );
415
416 if( ind < 0 )
417 {
418 m_out->Print( nestLevel, "(xy %s)",
419 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, outline.CPoint( ii ) ).c_str() );
420 needNewline = true;
421 }
422 else
423 {
424 const SHAPE_ARC& arc = outline.Arc( ind );
425 m_out->Print( nestLevel, "(arc (start %s) (mid %s) (end %s))",
429 needNewline = true;
430
431 do
432 {
433 ++ii;
434 } while( ii < outline.PointCount() && outline.ArcIndex( ii ) == ind );
435
436 --ii;
437 }
438
439 ++shapesAdded;
440
441 if( !( shapesAdded % 4 ) || !aCompact )
442 {
443 // newline every 4 shapes if compact save
444 m_out->Print( 0, "\n" );
445 needNewline = false;
446 }
447 }
448
449 if( needNewline )
450 m_out->Print( 0, "\n" );
451
452 m_out->Print( aNestLevel + 1, ")\n" );
453}
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:114
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
const VECTOR2I & GetP0() const
Definition: shape_arc.h:112
const SHAPE_ARC & Arc(size_t aArc) const
int PointCount() const
Return the number of points (vertices) in this line chain.
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.

References SHAPE_LINE_CHAIN::Arc(), SHAPE_LINE_CHAIN::ArcIndex(), SHAPE_LINE_CHAIN::CPoint(), EDA_UNIT_UTILS::FormatInternalUnits(), SHAPE_ARC::GetArcMid(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), PCB_PLUGIN::m_out, pcbIUScale, SHAPE_LINE_CHAIN::PointCount(), and OUTPUTFORMATTER::Print().

Referenced by PCB_PLUGIN::format(), and PCB_PLUGIN::formatRenderCache().

◆ formatProperties()

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

formats the Nets and Netclasses

Definition at line 655 of file pcb_plugin.cpp.

656{
657 for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
658 {
659 m_out->Print( aNestLevel, "(property %s %s)\n",
660 m_out->Quotew( prop.first ).c_str(),
661 m_out->Quotew( prop.second ).c_str() );
662 }
663
664 if( !aBoard->GetProperties().empty() )
665 m_out->Print( 0, "\n" );
666}
const std::map< wxString, wxString > & GetProperties() const
Definition: board.h:332

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

Referenced by PCB_PLUGIN::formatHeader().

◆ formatRenderCache()

void PCB_PLUGIN::formatRenderCache ( const EDA_TEXT aText,
int  aNestLevel 
) const
privateinherited

Definition at line 456 of file pcb_plugin.cpp.

457{
458 const wxString& shownText = aText->GetShownText();
459 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = aText->GetRenderCache( aText->GetFont(),
460 shownText );
461
462 m_out->Print( aNestLevel, "(render_cache %s %s\n",
463 m_out->Quotew( shownText ).c_str(),
464 EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
465
466 for( const std::unique_ptr<KIFONT::GLYPH>& baseGlyph : *cache )
467 {
468 KIFONT::OUTLINE_GLYPH* glyph = static_cast<KIFONT::OUTLINE_GLYPH*>( baseGlyph.get() );
469
470 if( glyph->OutlineCount() > 0 )
471 {
472 for( int ii = 0; ii < glyph->OutlineCount(); ++ii )
473 {
474 m_out->Print( aNestLevel + 1, "(polygon\n" );
475
476 formatPolyPts( glyph->Outline( ii ), aNestLevel + 1, true );
477
478 for( int jj = 0; jj < glyph->HoleCount( ii ); ++jj )
479 formatPolyPts( glyph->Hole( ii, jj ), aNestLevel + 2, true );
480
481 m_out->Print( aNestLevel + 1, ")\n" );
482 }
483 }
484 }
485
486 m_out->Print( aNestLevel, ")\n" );
487}
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition: eda_text.cpp:451
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:310
virtual wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:98
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the aIndex-th subpolygon in the set.
int OutlineCount() const
Return the number of vertices in a given outline/hole.

References EDA_UNIT_UTILS::FormatAngle(), PCB_PLUGIN::formatPolyPts(), EDA_TEXT::GetDrawRotation(), EDA_TEXT::GetFont(), EDA_TEXT::GetRenderCache(), EDA_TEXT::GetShownText(), SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::HoleCount(), PCB_PLUGIN::m_out, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by PCB_PLUGIN::format().

◆ formatSetup()

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

formats the board setup information

Definition at line 490 of file pcb_plugin.cpp.

491{
492 // Setup
493 m_out->Print( aNestLevel, "(setup\n" );
494
495 // Save the board physical stackup structure
496 const BOARD_STACKUP& stackup = aBoard->GetDesignSettings().GetStackupDescriptor();
497
498 if( aBoard->GetDesignSettings().m_HasStackup )
499 stackup.FormatBoardStackup( m_out, aBoard, aNestLevel+1 );
500
501 BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
502
503 m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
505
506 if( dsnSettings.m_SolderMaskMinWidth )
507 {
508 m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
510 }
511
512 if( dsnSettings.m_SolderPasteMargin != 0 )
513 {
514 m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
516 }
517
518 if( dsnSettings.m_SolderPasteMarginRatio != 0 )
519 {
520 m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
521 FormatDouble2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
522 }
523
524 if( dsnSettings.m_AllowSoldermaskBridgesInFPs )
525 {
526 m_out->Print( aNestLevel+1, "(allow_soldermask_bridges_in_footprints yes)\n" );
527 }
528
529 VECTOR2I origin = dsnSettings.GetAuxOrigin();
530
531 if( origin != VECTOR2I( 0, 0 ) )
532 {
533 m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
536 }
537
538 origin = dsnSettings.GetGridOrigin();
539
540 if( origin != VECTOR2I( 0, 0 ) )
541 {
542 m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
545 }
546
547 aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
548
549 m_out->Print( aNestLevel, ")\n\n" );
550}
const VECTOR2I & GetGridOrigin()
const VECTOR2I & GetAuxOrigin()
BOARD_STACKUP & GetStackupDescriptor()
Manage layers needed to make a physical board.
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard, int aNestLevel) const
Write the stackup info on board file.
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: board.h:629
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References PCB_PLOT_PARAMS::Format(), BOARD_STACKUP::FormatBoardStackup(), FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetAuxOrigin(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetGridOrigin(), BOARD::GetPlotOptions(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_DESIGN_SETTINGS::m_AllowSoldermaskBridgesInFPs, BOARD_DESIGN_SETTINGS::m_HasStackup, PCB_PLUGIN::m_out, BOARD_DESIGN_SETTINGS::m_SolderMaskExpansion, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, pcbIUScale, OUTPUTFORMATTER::Print(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_PLUGIN::formatHeader().

◆ GetEnumeratedFootprint()

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

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

Reimplemented from PLUGIN.

Definition at line 2493 of file pcb_plugin.cpp.

2496{
2497 return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2498}

References PCB_PLUGIN::getFootprint().

◆ GetFileExtension()

const wxString PCB_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtualinherited

Returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 265 of file pcb_plugin.h.

266 {
267 // Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
268 // but to be pure, a plugin should not assume that it will always be linked
269 // with the core of the Pcbnew code. (Might someday be a DLL/DSO.) Besides,
270 // file extension policy should be controlled by the plugin.
271 return wxT( "kicad_pcb" );
272 }

◆ getFootprint()

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

Definition at line 2465 of file pcb_plugin.cpp.

2469{
2470 LOCALE_IO toggle; // toggles on, then off, the C locale.
2471
2472 init( aProperties );
2473
2474 try
2475 {
2476 validateCache( aLibraryPath, checkModified );
2477 }
2478 catch( const IO_ERROR& )
2479 {
2480 // do nothing with the error
2481 }
2482
2484 FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( aFootprintName );
2485
2486 if( it == footprints.end() )
2487 return nullptr;
2488
2489 return it->second->GetFootprint();
2490}

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 CADSTAR_PCB_ARCHIVE_PLUGIN, and EAGLE_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 2655 of file pcb_plugin.cpp.

2656{
2657 return FP_CACHE::GetTimestamp( aLibraryPath );
2658}
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:243

References FP_CACHE::GetTimestamp().

◆ GetStringOutput()

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

Definition at line 333 of file pcb_plugin.h.

334 {
335 std::string ret = m_sf.GetString();
336
337 if( doClear )
338 m_sf.Clear();
339
340 return ret;
341 }
STRING_FORMATTER m_sf
Definition: pcb_plugin.h:422
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 STRING_UTF8_MAP aProperties)
protectedinherited

Definition at line 2416 of file pcb_plugin.cpp.

2417{
2418 m_board = nullptr;
2419 m_reader = nullptr;
2420 m_props = aProperties;
2421}
LINE_READER * m_reader
no ownership here.
Definition: pcb_plugin.h:419
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: pcb_plugin.h:416

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

2757{
2758 LOCALE_IO toggle;
2759
2760 init( nullptr );
2761
2762 validateCache( aLibraryPath );
2763
2764 return m_cache->IsWritable();
2765}

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

400{
401 std::string result;
402
403 wxLogNull doNotLog; // disable logging of failed clipboard actions
404
405 auto clipboard = wxTheClipboard;
406 wxClipboardLocker clipboardLock( clipboard );
407
408 if( !clipboardLock )
409 return nullptr;
410
411 if( clipboard->IsSupported( wxDF_TEXT ) || clipboard->IsSupported( wxDF_UNICODETEXT ) )
412 {
413 wxTextDataObject data;
414 clipboard->GetData( data );
415
416 result = data.GetText().mb_str();
417 }
418
419 std::function<bool( wxString, int, wxString, wxString )> queryUser =
420 [&]( wxString aTitle, int aIcon, wxString aMessage, wxString aAction ) -> bool
421 {
422 KIDIALOG dlg( nullptr, aMessage, aTitle, wxOK | wxCANCEL | aIcon );
423
424 if( !aAction.IsEmpty() )
425 dlg.SetOKLabel( aAction );
426
427 dlg.DoNotShowCheckbox( aMessage, 0 );
428
429 return dlg.ShowModal() == wxID_OK;
430 };
431
432 STRING_LINE_READER reader( result, wxT( "clipboard" ) );
433 PCB_PARSER parser( &reader, aAppendToMe, &queryUser );
434
435 init( aProperties );
436
437 BOARD_ITEM* item;
438 BOARD* board;
439
440 try
441 {
442 item = parser.Parse();
443 }
444 catch( const FUTURE_FORMAT_ERROR& )
445 {
446 // Don't wrap a FUTURE_FORMAT_ERROR in another
447 throw;
448 }
449 catch( const PARSE_ERROR& parse_error )
450 {
451 if( parser.IsTooRecent() )
452 throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
453 else
454 throw;
455 }
456
457 if( item->Type() != PCB_T )
458 {
459 // The parser loaded something that was valid, but wasn't a board.
460 THROW_PARSE_ERROR( _( "Clipboard content is not KiCad compatible" ), parser.CurSource(),
461 parser.CurLine(), parser.CurLineNumber(), parser.CurOffset() );
462 }
463 else
464 {
465 board = dynamic_cast<BOARD*>( item );
466 }
467
468 // Give the filename to the board if it's new
469 if( board && !aAppendToMe )
470 board->SetFileName( aFileName );
471
472 return board;
473}
void SetFileName(const wxString &aFileName)
Definition: board.h:300
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:46
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:241

References _, KIDIALOG::DoNotShowCheckbox(), PCB_PARSER::GetRequiredVersion(), PCB_PLUGIN::init(), PCB_PARSER::IsTooRecent(), PCB_PARSER::Parse(), PCB_T, BOARD::SetFileName(), KIDIALOG::ShowModal(), THROW_PARSE_ERROR, and EDA_ITEM::Type().

◆ Parse() [1/2]

BOARD_ITEM * CLIPBOARD_IO::Parse ( )

Definition at line 319 of file kicad_clipboard.cpp.

320{
321 BOARD_ITEM* item;
322 wxString result;
323
324 wxLogNull doNotLog; // disable logging of failed clipboard actions
325
326 auto clipboard = wxTheClipboard;
327 wxClipboardLocker clipboardLock( clipboard );
328
329 if( !clipboardLock )
330 return nullptr;
331
332 if( clipboard->IsSupported( wxDF_TEXT ) || clipboard->IsSupported( wxDF_UNICODETEXT ) )
333 {
334 wxTextDataObject data;
335 clipboard->GetData( data );
336 result = data.GetText();
337 }
338
339 try
340 {
341 item = PCB_PLUGIN::Parse( result );
342 }
343 catch (...)
344 {
345 item = nullptr;
346 }
347
348 return item;
349}
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
Definition: pcb_plugin.cpp:290

References PCB_PLUGIN::Parse().

Referenced by PCB_CONTROL::Paste().

◆ Parse() [2/2]

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

Definition at line 290 of file pcb_plugin.cpp.

291{
292 std::string input = TO_UTF8( aClipboardSourceInput );
293
294 STRING_LINE_READER reader( input, wxT( "clipboard" ) );
295 PCB_PARSER parser( &reader, nullptr, m_queryUserCallback );
296
297 try
298 {
299 return parser.Parse();
300 }
301 catch( const PARSE_ERROR& parse_error )
302 {
303 if( parser.IsTooRecent() )
304 throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
305 else
306 throw;
307 }
308}

References PCB_PARSER::GetRequiredVersion(), PCB_PARSER::IsTooRecent(), PCB_PLUGIN::m_queryUserCallback, PCB_PARSER::Parse(), 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 260 of file pcb_plugin.h.

261 {
262 return wxT( "KiCad" );
263 }

◆ PrefetchLib()

void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const STRING_UTF8_MAP 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}

Referenced by FP_LIB_TABLE::PrefetchLib().

◆ Save()

void CLIPBOARD_IO::Save ( const wxString &  aFileName,
BOARD aBoard,
const STRING_UTF8_MAP 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 PLUGIN.

Definition at line 352 of file kicad_clipboard.cpp.

354{
355 init( aProperties );
356
357 m_board = aBoard; // after init()
358
359 // Prepare net mapping that assures that net codes saved in a file are consecutive integers
360 m_mapping->SetBoard( aBoard );
361
362 STRING_FORMATTER formatter;
363
364 m_out = &formatter;
365
366 m_out->Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n", SEXPR_BOARD_FILE_VERSION );
367
368 Format( aBoard, 1 );
369
370 m_out->Print( 0, ")\n" );
371
372 wxLogNull doNotLog; // disable logging of failed clipboard actions
373
374 auto clipboard = wxTheClipboard;
375 wxClipboardLocker clipboardLock( clipboard );
376
377 if( !clipboardLock )
378 return;
379
380 clipboard->SetData( new wxTextDataObject(
381 wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
382 clipboard->Flush();
383
384 // This section exists to return the clipboard data, ensuring it has fully
385 // been processed by the system clipboard. This appears to be needed for
386 // extremely large clipboard copies on asynchronous linux clipboard managers
387 // such as KDE's Klipper
388 if( clipboard->IsSupported( wxDF_TEXT ) || clipboard->IsSupported( wxDF_UNICODETEXT ) )
389 {
390 wxTextDataObject data;
391 clipboard->GetData( data );
392 ignore_unused( data.GetText() );
393 }
394}
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:201
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:415
void ignore_unused(const T &)
Definition: ignore.h:24

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

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

References FOOTPRINT::Add(), EDA_ITEM::Clone(), PCB_SHAPE::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(), EDA_TEXT::GetText(), FOOTPRINT::GetValue(), group, SELECTION::HasReferencePoint(), ignore_unused(), ZONE::InitDataFromSrcInCopyCtor(), PCB_PLUGIN::m_board, m_formatter, PCB_PLUGIN::m_mapping, BOARD_ITEM::Move(), FOOTPRINT::Move(), FOOTPRINT::MoveAnchorPosition(), pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, OUTPUTFORMATTER::Print(), EDA_TEXT::SetAttributes(), NETINFO_MAPPING::SetBoard(), FOOTPRINT::SetFPID(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), FOOTPRINT::SetLocked(), 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 60 of file kicad_clipboard.cpp.

61{
62 m_board = aBoard;
63}

References PCB_PLUGIN::m_board.

Referenced by EDIT_TOOL::copyToClipboard().

◆ SetOutputFormatter()

void PCB_PLUGIN::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

Definition at line 343 of file pcb_plugin.h.

343{ m_out = aFormatter; }

References PCB_PLUGIN::m_out.

Referenced by FP_CACHE::Save().

◆ SetQueryUserCallback() [1/2]

virtual void PLUGIN::SetQueryUserCallback ( std::function< bool(wxString aTitle, int aIcon, wxString aMessage, wxString aAction)>  aCallback)
inlinevirtualinherited

Registers a KIDIALOG callback for collecting info from the user.

Definition at line 285 of file io_mgr.h.

288 { }

Referenced by PCB_CONTROL::AppendBoard(), and PCB_EDIT_FRAME::OpenProjectFiles().

◆ SetQueryUserCallback() [2/2]

void PCB_PLUGIN::SetQueryUserCallback ( std::function< bool(wxString aTitle, int aIcon, wxString aMessage, wxString aOKButtonTitle)>  aCallback)
inlineoverrideinherited

Definition at line 274 of file pcb_plugin.h.

276 {
277 m_queryUserCallback = &aCallback;
278 }

References PCB_PLUGIN::m_queryUserCallback.

◆ validateCache()

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

Definition at line 2424 of file pcb_plugin.cpp.

2425{
2426 if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2427 {
2428 // a spectacular episode in memory management:
2429 delete m_cache;
2430 m_cache = new FP_CACHE( this, aLibraryPath );
2431 m_cache->Load();
2432 }
2433}
bool IsModified()
Return true if the cache is not up-to-date.
Definition: pcb_plugin.cpp:235
void Load()
Definition: pcb_plugin.cpp:152

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 414 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 413 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 420 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 425 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_props

const STRING_UTF8_MAP* PCB_PLUGIN::m_props
protectedinherited

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

Definition at line 416 of file pcb_plugin.h.

Referenced by PCB_PLUGIN::init().

◆ m_queryUserCallback

std::function<bool( wxString aTitle, int aIcon, wxString aMsg, wxString aAction )>* PCB_PLUGIN::m_queryUserCallback
protectedinherited

◆ m_reader

LINE_READER* PCB_PLUGIN::m_reader
protectedinherited

no ownership here.

Definition at line 419 of file pcb_plugin.h.

Referenced by PCB_PLUGIN::init().

◆ m_sf

STRING_FORMATTER PCB_PLUGIN::m_sf
protectedinherited

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