22#include <fmt/format.h> 
   63                 wxString::Format( 
"Cannot use relative file paths in sexpr plugin to " 
   90        if( dir.GetFirst( &libFileName, fileSpec ) )
 
   96                tmp.SetFullName( libFileName );
 
  108                    if( !errorCache.IsEmpty() )
 
  109                        errorCache += wxT( 
"\n\n" );
 
  111                    errorCache += wxString::Format( 
_( 
"Unable to read file '%s'" ) + 
'\n', tmp.GetFullPath() );
 
  112                    errorCache += ioe.
What();
 
  114            } 
while( dir.GetNext( &libFileName ) );
 
  116            if( !errorCache.IsEmpty() )
 
 
  140        auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
 
  144        std::vector<LIB_SYMBOL*> orderedSymbols;
 
  149                orderedSymbols.push_back( symbol );
 
  153        std::sort( orderedSymbols.begin(), orderedSymbols.end(),
 
  156                       unsigned int lhDepth = aLhs->GetInheritanceDepth();
 
  157                       unsigned int rhDepth = aRhs->GetInheritanceDepth();
 
  159                       if( lhDepth == rhDepth )
 
  160                           return aLhs->GetName() < aRhs->GetName();
 
  162                       return lhDepth < rhDepth;
 
  168        formatter->Print( 
")" );
 
  173        if( !fn.DirExists() )
 
  175            if( !fn.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
 
  176                THROW_IO_ERROR( wxString::Format( 
_( 
"Cannot create symbol library path '%s'." ), fn.GetPath() ) );
 
  181            wxFileName saveFn( fn );
 
  185            auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( saveFn.GetFullPath() );
 
  191            formatter->Print( 
")" );
 
 
  202                                               const wxString& aLibName, 
bool aIncludeData )
 
  204    wxCHECK_RET( aSymbol, 
"Invalid LIB_SYMBOL pointer." );
 
  214    std::vector<SCH_FIELD*> orderedFields;
 
  218    if( !aLibName.IsEmpty() )
 
  224        wxCHECK2( unitId.
Parse( aLibName ) < 0,  );
 
  231        aFormatter.
Print( 
"(symbol %s", 
name.c_str() );
 
  234            aFormatter.
Print( 
"(power global)" );
 
  236            aFormatter.
Print( 
"(power local)" );
 
  244            aFormatter.
Print( 
"(body_styles " );
 
  248                aFormatter.
Print( 
"demorgan" );
 
  253                    aFormatter.
Print( 
"%s ", aFormatter.
Quotew( bodyStyle ).c_str() );
 
  256            aFormatter.
Print( 
")" );
 
  260            aFormatter.
Print( 
"(pin_numbers (hide yes))" );
 
  265            aFormatter.
Print( 
"(pin_names" );
 
  269                aFormatter.
Print( 
"(offset %s)",
 
  277            aFormatter.
Print( 
")" );
 
  287        const std::vector<std::set<wxString>>& jumperGroups = aSymbol->
JumperPinGroups();
 
  289        if( !jumperGroups.empty() )
 
  291            aFormatter.
Print( 
"(jumper_pin_groups" );
 
  293            for( 
const std::set<wxString>& 
group : jumperGroups )
 
  295                aFormatter.
Print( 
"(" );
 
  297                for( 
const wxString& padName : 
group )
 
  298                    aFormatter.
Print( 
"%s ", aFormatter.
Quotew( padName ).c_str() );
 
  300                aFormatter.
Print( 
")" );
 
  303            aFormatter.
Print( 
")" );
 
  328        std::sort( units.begin(), units.end(),
 
  331                        if( a.m_unit == b.m_unit )
 
  332                            return a.m_bodyStyle < b.m_bodyStyle;
 
  334                        return a.m_unit < b.m_unit;
 
  343            aFormatter.
Print( 
"(symbol %s_%d_%d\"",
 
  352                aFormatter.
Print( 
"(unit_name %s)", aFormatter.
Quotes( 
name ).c_str() );
 
  362            std::multiset<
SCH_ITEM*, 
decltype( cmp )> save_map( cmp );
 
  364            for( 
SCH_ITEM* item : unit.m_items )
 
  365                save_map.insert( item );
 
  370            aFormatter.
Print( 
")" );
 
  380        std::shared_ptr<LIB_SYMBOL> parent = aSymbol->
GetParent().lock();
 
  384        aFormatter.
Print( 
"(symbol %s (extends %s)",
 
  386                          aFormatter.
Quotew( parent->GetName() ).c_str() );
 
  396    aFormatter.
Print( 
")" );
 
 
  403    wxCHECK_RET( aSymbol, 
"Invalid LIB_SYMBOL pointer." );
 
  415    if( !fpFilters.IsEmpty() )
 
  419        for( 
const wxString& 
filter : fpFilters )
 
  427                tmp += 
" " + curr_filter;
 
 
  440    wxCHECK_RET( aItem, 
"Invalid SCH_ITEM pointer." );
 
  442    switch( aItem->
Type() )
 
  455            formatArc( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, 
true );
 
  459            formatCircle( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, 
true );
 
  463            formatRect( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, 
true );
 
  467            formatBezier(&aFormatter, shape, isPrivate, stroke, fillMode, fillColor, 
true );
 
  471            formatPoly( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, 
true );
 
 
  501    wxCHECK_RET( aField && aField->
Type() == 
SCH_FIELD_T, 
"Invalid SCH_FIELD object." );
 
  503    wxString fieldName = aField->
GetName();
 
  508    aFormatter.
Print( 
"(property %s %s %s (at %s %s %s)",
 
  510                      aFormatter.
Quotew( fieldName ).c_str(),
 
  519        aFormatter.
Print( 
"(show_name)" );
 
  522        aFormatter.
Print( 
"(do_not_autoplace)" );
 
  527    aField->
Format( &aFormatter, 0 );
 
  528    aFormatter.
Print( 
")" );
 
 
  534    wxCHECK_RET( aPin && aPin->
Type() == 
SCH_PIN_T, 
"Invalid SCH_PIN object." );
 
  538    aFormatter.
Print( 
"(pin %s %s (at %s %s %s) (length %s)",
 
  553    aFormatter.
Print( 
"(name %s (effects (font (size %s %s))))",
 
  560    aFormatter.
Print( 
"(number %s (effects (font (size %s %s))))",
 
  568    for( 
const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->
GetAlternates() )
 
  573        if( alt.second.m_Name.IsEmpty() )
 
  576        aFormatter.
Print( 
"(alternate %s %s %s)",
 
  577                          aFormatter.
Quotew( alt.second.m_Name ).c_str(),
 
  582    aFormatter.
Print( 
")" );
 
 
  588    wxCHECK_RET( aText && aText->
Type() == 
SCH_TEXT_T, 
"Invalid SCH_TEXT object." );
 
  590    aFormatter.
Print( 
"(text %s %s (at %s %s %d)",
 
  599    aText->EDA_TEXT::Format( &aFormatter, 0 );
 
  600    aFormatter.
Print( 
")" );
 
 
  606    wxCHECK_RET( aTextBox && aTextBox->
Type() == 
SCH_TEXTBOX_T, 
"Invalid SCH_TEXTBOX object." );
 
  608    aFormatter.
Print( 
"(text_box %s %s",
 
  615    aFormatter.
Print( 
"(at %s %s %s) (size %s %s) (margins %s %s %s %s)",
 
  628    aTextBox->EDA_TEXT::Format( &aFormatter, 0 );
 
  629    aFormatter.
Print( 
")" );
 
 
  635    LIB_SYMBOL_MAP::iterator it = 
m_symbols.find( aSymbolName );
 
  638        THROW_IO_ERROR( wxString::Format( 
_( 
"library %s does not contain a symbol named %s" ),
 
  650        LIB_SYMBOL_MAP::iterator it1 = 
m_symbols.begin();
 
  654            if( it1->second->IsDerived()
 
  655              && it1->second->GetParent().lock() == rootSymbol->
SharedPtr() )
 
 
  684        if( symbol->GetParentName().IsEmpty() )
 
  687        auto it = 
m_symbols.find( symbol->GetParentName() );
 
  693            error.Printf( 
_( 
"No parent for extended symbol %s found in library '%s'" ),
 
  698        symbol->SetParent( it->second );
 
 
  705    aFormatter.
Print( 
"(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") " 
  706                      "(generator_version \"%s\")",
 
 
constexpr EDA_IU_SCALE schIUScale
 
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
 
int AsTenthsOfADegree() const
 
KICAD_T Type() const
Returns the type of object.
 
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
 
FILL_T GetFillMode() const
 
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
 
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
 
COLOR4D GetFillColor() const
 
wxString SHAPE_T_asString() const
 
const EDA_ANGLE & GetTextAngle() const
 
virtual const wxString & GetText() const
Return the string associated with the text object.
 
virtual bool IsVisible() const
 
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
 
virtual void SetVisible(bool aVisible)
 
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, bool aWriteData) const
Output formatter for the embedded files.
 
void ClearEmbeddedFonts()
Remove all embedded fonts from the collection.
 
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
 
bool GetAreFontsEmbedded() const
 
A LINE_READER that reads from an open file.
 
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
 
virtual const wxString What() const
A composite of Problem() and Where()
 
A color representation with 4 components: red, green, blue, alpha.
 
A logical library item identifier and consists of various portions much like a URI.
 
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
 
const UTF8 & GetLibItemName() const
 
Define a library symbol object.
 
const LIB_ID & GetLibId() const override
 
wxString GetKeyWords() const override
 
std::weak_ptr< LIB_SYMBOL > & GetParent()
 
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
 
bool UnitsLocked() const
Check whether symbol units are interchangeable.
 
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
 
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of SCH_ITEM objects separated by unit and convert number.
 
std::map< int, wxString > & GetUnitDisplayNames()
 
bool IsMultiBodyStyle() const override
 
bool IsLocalPower() const override
 
wxArrayString GetFPFilters() const
 
std::shared_ptr< LIB_SYMBOL > SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
 
const std::vector< wxString > & GetBodyStyleNames() const
 
bool HasDeMorganBodyStyles() const override
 
EMBEDDED_FILES * GetEmbeddedFiles() override
 
bool IsGlobalPower() const override
 
bool GetDuplicatePinNumbersAreJumpers() const
 
std::vector< std::set< wxString > > & JumperPinGroups()
Each jumper pin group is a set of pin numbers that should be treated as internally connected.
 
void EmbedFonts() override
 
VECTOR2I GetPosition() const override
 
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
 
bool CanAutoplace() const
 
void SetText(const wxString &aText) override
 
int m_fileFormatVersionAtLoad
 
static void saveSymbolDrawItem(SCH_ITEM *aItem, OUTPUTFORMATTER &aFormatter)
 
SCH_IO_KICAD_SEXPR_LIB_CACHE(const wxString &aLibraryPath)
 
static void saveDcmInfoAsFields(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
 
virtual ~SCH_IO_KICAD_SEXPR_LIB_CACHE()
 
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
 
static void saveTextBox(SCH_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter)
 
bool isLibraryPathValid() const
 
static void saveField(SCH_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
void formatLibraryHeader(OUTPUTFORMATTER &aFormatter)
 
void DeleteSymbol(const wxString &aName) override
 
static void savePin(SCH_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void saveText(SCH_TEXT *aText, OUTPUTFORMATTER &aFormatter)
 
void SetFileFormatVersionAtLoad(int aVersion)
 
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
 
void updateParentSymbolLinks()
Update the parent symbol links for derived symbols.
 
Object to parser s-expression symbol library and schematic file formats.
 
int GetParsedRequiredVersion() const
 
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
 
wxFileName GetRealFile() const
 
long long GetLibModificationTime()
 
SCH_IO_LIB_CACHE(const wxString &aLibraryPath)
 
void IncrementModifyHash()
 
Base class for any item which can be embedded within the SCHEMATIC container class,...
 
wxString GetClass() const override
Return the class name.
 
int GetNumberTextSize() const
 
const std::map< wxString, ALT > & GetAlternates() const
 
const wxString & GetName() const
 
PIN_ORIENTATION GetOrientation() const
 
VECTOR2I GetPosition() const override
 
int GetNameTextSize() const
 
const wxString & GetNumber() const
 
GRAPHIC_PINSHAPE GetShape() const
 
ELECTRICAL_PINTYPE GetType() const
 
STROKE_PARAMS GetStroke() const override
 
int GetMarginBottom() const
 
int GetMarginLeft() const
 
int GetMarginRight() const
 
VECTOR2I GetPosition() const override
 
Simple container to manage line stroke parameters.
 
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
 
int GetPinNameOffset() const
 
bool GetExcludedFromBoard() const override
 
virtual bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
 
virtual bool GetShowPinNames() const
 
virtual bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
 
virtual bool GetShowPinNumbers() const
 
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
 
#define IS_CHANGED
Item was edited, and modified.
 
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
 
static const std::string KiCadSymbolLibFileExtension
 
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
 
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
 
This file contains miscellaneous commonly used macros and functions.
 
#define UNIMPLEMENTED_FOR(type)
 
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Convert aAngle from board units to a string appropriate for writing to file.
 
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
 
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
 
EDA_ANGLE getPinAngle(PIN_ORIENTATION aOrientation)
 
void formatArc(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
 
void formatCircle(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
 
const char * getPinElectricalTypeToken(ELECTRICAL_PINTYPE aType)
 
void formatBezier(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
 
void formatRect(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
 
void formatPoly(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
 
void formatFill(OUTPUTFORMATTER *aFormatter, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
 
const char * getPinShapeToken(GRAPHIC_PINSHAPE aShape)
 
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
 
@ USER
The field ID hasn't been set yet; field is invalid.
 
wxString GetCanonicalFieldName(FIELD_T aFieldType)
 
wxLogTrace helper definitions.
 
VECTOR2< int32_t > VECTOR2I