59 wxString::Format(
"Cannot use relative file paths in sexpr plugin to "
93 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
95 formatter->Print( 0,
"(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
96 "(generator_version \"%s\")\n",
99 std::vector<LIB_SYMBOL*> orderedSymbols;
104 orderedSymbols.push_back( symbol );
108 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
111 unsigned int lhDepth = aLhs->GetInheritanceDepth();
112 unsigned int rhDepth = aRhs->GetInheritanceDepth();
114 if( lhDepth == rhDepth )
115 return aLhs->GetName() < aRhs->GetName();
117 return lhDepth < rhDepth;
123 formatter->Print( 0,
")\n" );
133 int aNestLevel,
const wxString& aLibName )
135 wxCHECK_RET( aSymbol,
"Invalid LIB_SYMBOL pointer." );
138 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) ==
".",
142 std::vector<SCH_FIELD*> fields;
146 if( !aLibName.IsEmpty() )
152 wxCHECK2( unitId.
Parse( aLibName ) < 0, );
159 aFormatter.
Print( aNestLevel,
"(symbol %s",
name.c_str() );
162 aFormatter.
Print( 0,
" (power)" );
169 aFormatter.
Print( 0,
" (pin_numbers hide)" );
174 aFormatter.
Print( 0,
" (pin_names" );
178 aFormatter.
Print( 0,
" (offset %s)",
184 aFormatter.
Print( 0,
" hide" );
186 aFormatter.
Print( 0,
")" );
189 aFormatter.
Print( 0,
" (exclude_from_sim %s)",
198 aFormatter.
Print( 0,
"\n" );
203 saveField( field, aFormatter, aNestLevel + 1 );
214 nextFreeFieldId += 1;
221 std::sort( units.begin(), units.end(),
224 if( a.m_unit == b.m_unit )
225 return a.m_bodyStyle < b.m_bodyStyle;
227 return a.m_unit < b.m_unit;
236 aFormatter.
Print( aNestLevel + 1,
"(symbol %s_%d_%d\"\n",
245 aFormatter.
Print( aNestLevel + 2,
"(unit_name %s)\n",
255 std::multiset<
SCH_ITEM*,
decltype( cmp )> save_map( cmp );
257 for(
SCH_ITEM* item : unit.m_items )
258 save_map.insert( item );
263 aFormatter.
Print( aNestLevel + 1,
")\n" );
268 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->
GetParent().lock();
272 aFormatter.
Print( aNestLevel,
"(symbol %s (extends %s)\n",
274 aFormatter.
Quotew( parent->GetName() ).c_str() );
279 saveField( field, aFormatter, aNestLevel + 1 );
286 aFormatter.
Print( aNestLevel,
")\n" );
292 int& aNextFreeFieldId,
int aNestLevel )
294 wxCHECK_RET( aSymbol,
"Invalid LIB_SYMBOL pointer." );
298 SCH_FIELD keywords(
nullptr, aNextFreeFieldId, wxString(
"ki_keywords" ) );
301 saveField( &keywords, aFormatter, aNestLevel + 1 );
302 aNextFreeFieldId += 1;
307 if( !fpFilters.IsEmpty() )
311 for(
const wxString&
filter : fpFilters )
319 tmp +=
" " + curr_filter;
322 SCH_FIELD description(
nullptr, aNextFreeFieldId, wxString(
"ki_fp_filters" ) );
325 saveField( &description, aFormatter, aNestLevel + 1 );
326 aNextFreeFieldId += 1;
334 wxCHECK_RET( aItem,
"Invalid SCH_ITEM pointer." );
336 switch( aItem->
Type() )
349 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor,
true );
352 case SHAPE_T::CIRCLE:
353 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor,
true );
356 case SHAPE_T::RECTANGLE:
357 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor,
true );
360 case SHAPE_T::BEZIER:
361 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor,
true );
365 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor,
true );
376 savePin(
static_cast<SCH_PIN*
>( aItem ), aFormatter, aNestLevel );
396 wxCHECK_RET( aField && aField->
Type() ==
SCH_FIELD_T,
"Invalid SCH_FIELD object." );
398 wxString fieldName = aField->
GetName();
403 aFormatter.
Print( aNestLevel,
"(property %s %s (at %s %s %g)",
404 aFormatter.
Quotew( fieldName ).c_str(),
413 aFormatter.
Print( 0,
" (show_name)" );
416 aFormatter.
Print( 0,
" (do_not_autoplace)" );
418 aFormatter.
Print( 0,
"\n" );
419 aField->
Format( &aFormatter, aNestLevel, 0 );
420 aFormatter.
Print( aNestLevel,
")\n" );
427 wxCHECK_RET( aPin && aPin->
Type() ==
SCH_PIN_T,
"Invalid SCH_PIN object." );
431 aFormatter.
Print( aNestLevel,
"(pin %s %s (at %s %s %s) (length %s)",
443 aFormatter.
Print( 0,
" hide\n" );
445 aFormatter.
Print( 0,
"\n" );
448 aFormatter.
Print( aNestLevel + 1,
"(name %s (effects (font (size %s %s))))\n",
455 aFormatter.
Print( aNestLevel + 1,
"(number %s (effects (font (size %s %s))))\n",
463 for(
const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->
GetAlternates() )
465 aFormatter.
Print( aNestLevel + 1,
"(alternate %s %s %s)\n",
466 aFormatter.
Quotew( alt.second.m_Name ).c_str(),
471 aFormatter.
Print( aNestLevel,
")\n" );
478 wxCHECK_RET( aText && aText->
Type() ==
SCH_TEXT_T,
"Invalid SCH_TEXT object." );
480 aFormatter.
Print( aNestLevel,
"(text%s %s (at %s %s %g)\n",
489 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
490 aFormatter.
Print( aNestLevel,
")\n" );
497 wxCHECK_RET( aTextBox && aTextBox->
Type() ==
SCH_TEXTBOX_T,
"Invalid SCH_TEXTBOX object." );
499 aFormatter.
Print( aNestLevel,
"(text_box%s %s\n",
506 aFormatter.
Print( aNestLevel + 1,
"(at %s %s %s) (size %s %s) (margins %s %s %s %s)\n",
518 aFormatter.
Print( 0,
"\n" );
521 aFormatter.
Print( 0,
"\n" );
523 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
524 aFormatter.
Print( aNestLevel,
")\n" );
530 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aSymbolName );
533 THROW_IO_ERROR( wxString::Format(
_(
"library %s does not contain a symbol named %s" ),
545 LIB_SYMBOL_MAP::iterator it1 =
m_symbols.begin();
549 if( it1->second->IsAlias()
550 && it1->second->GetParent().lock() == rootSymbol->
SharedPtr() )
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 void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
virtual void SetVisible(bool aVisible)
A LINE_READER that reads from an open file.
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
bool IsPower() const override
bool UnitsLocked() const
Check whether symbol units are interchangeable.
int GetNextAvailableFieldId() const
void GetFields(std::vector< SCH_FIELD * > &aList)
Return a list of fields within this symbol.
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.
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
wxArrayString GetFPFilters() const
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
LIB_SYMBOL_SPTR SharedPtr() const
LIB_SYMBOL_REF & GetParent()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
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
SCH_IO_KICAD_SEXPR_LIB_CACHE(const wxString &aLibraryPath)
static void saveField(SCH_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel)
static void saveTextBox(SCH_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
virtual ~SCH_IO_KICAD_SEXPR_LIB_CACHE()
static void saveDcmInfoAsFields(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int &aNextFreeFieldId, int aNestLevel)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
static void saveText(SCH_TEXT *aText, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveSymbolDrawItem(SCH_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
void DeleteSymbol(const wxString &aName) override
void SetFileFormatVersionAtLoad(int aVersion)
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
static void savePin(SCH_PIN *aPin, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
Object to parser s-expression symbol library and schematic file formats.
int GetParsedRequiredVersion() const
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
A base cache assistant implementation for the symbol library portion of the SCH_IO API.
wxDateTime GetLibModificationTime()
wxFileName GetRealFile() const
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 wxString & GetName() const
PIN_ORIENTATION GetOrientation() const
std::map< wxString, ALT > & GetAlternates()
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, int nestLevel) const
bool GetExcludedFromBoard() const
bool GetExcludedFromBOM() const
int GetPinNameOffset() const
virtual bool GetShowPinNames() const
virtual bool GetShowPinNumbers() const
bool GetExcludedFromSim() const override
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
#define IS_CHANGED
Item was edited, and modified.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board 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, int aNestLevel, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
const char * getPinElectricalTypeToken(ELECTRICAL_PINTYPE aType)
void formatFill(OUTPUTFORMATTER *aFormatter, int aNestLevel, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatBezier(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatRect(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
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:...
constexpr int MilsToIU(int mils) const
wxString GetCanonicalFieldName(int idx)
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
wxLogTrace helper definitions.