93 auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
95 formatter->Print( 0,
"(kicad_symbol_lib (version %d) (generator kicad_symbol_editor)\n",
98 for(
const std::pair<const wxString, LIB_SYMBOL*>& parent :
m_symbols )
101 if( parent.second->IsRoot() )
103 SaveSymbol( parent.second, *formatter.get(), 1 );
106 for(
const std::pair<const wxString, LIB_SYMBOL*>& alias :
m_symbols )
108 if( !alias.second->IsAlias() )
111 std::shared_ptr<LIB_SYMBOL> aliasParent = alias.second->GetParent().lock();
113 if( aliasParent.get() != parent.second )
116 SaveSymbol( alias.second, *formatter.get(), 1 );
121 formatter->Print( 0,
")\n" );
131 int aNestLevel,
const wxString& aLibName )
133 wxCHECK_RET( aSymbol,
"Invalid LIB_SYMBOL pointer." );
136 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) ==
".",
140 std::vector<LIB_FIELD*> fields;
144 if( !aLibName.IsEmpty() )
150 wxCHECK2( unitId.
Parse( aLibName ) < 0, );
157 aFormatter.
Print( aNestLevel,
"(symbol %s",
name.c_str() );
160 aFormatter.
Print( 0,
" (power)" );
167 aFormatter.
Print( 0,
" (pin_numbers hide)" );
172 aFormatter.
Print( 0,
" (pin_names" );
175 aFormatter.
Print( 0,
" (offset %s)",
179 aFormatter.
Print( 0,
" hide" );
181 aFormatter.
Print( 0,
")" );
191 aFormatter.
Print( 0,
"\n" );
196 saveField( field, aFormatter, aNestLevel + 1 );
207 nextFreeFieldId += 1;
214 std::sort( units.begin(), units.end(),
217 if( a.m_unit == b.m_unit )
218 return a.m_convert < b.m_convert;
220 return a.m_unit < b.m_unit;
229 aFormatter.
Print( aNestLevel + 1,
"(symbol %s_%d_%d\"\n",
230 name.c_str(), unit.m_unit, unit.m_convert );
236 aFormatter.
Print( aNestLevel + 2,
"(unit_name %s)\n",
246 std::multiset<
LIB_ITEM*,
decltype( cmp )> save_map( cmp );
248 for(
LIB_ITEM* item : unit.m_items )
249 save_map.insert( item );
254 aFormatter.
Print( aNestLevel + 1,
")\n" );
259 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->
GetParent().lock();
263 aFormatter.
Print( aNestLevel,
"(symbol %s (extends %s)\n",
265 aFormatter.
Quotew( parent->GetName() ).c_str() );
270 saveField( field, aFormatter, aNestLevel + 1 );
277 aFormatter.
Print( aNestLevel,
")\n" );
282 int& aNextFreeFieldId,
int aNestLevel )
284 wxCHECK_RET( aSymbol,
"Invalid LIB_SYMBOL pointer." );
288 LIB_FIELD keywords( aNextFreeFieldId, wxString(
"ki_keywords" ) );
291 saveField( &keywords, aFormatter, aNestLevel + 1 );
292 aNextFreeFieldId += 1;
297 LIB_FIELD description( aNextFreeFieldId, wxString(
"ki_description" ) );
300 saveField( &description, aFormatter, aNestLevel + 1 );
301 aNextFreeFieldId += 1;
306 if( !fpFilters.IsEmpty() )
310 for(
const wxString&
filter : fpFilters )
318 tmp +=
" " + curr_filter;
321 LIB_FIELD description( aNextFreeFieldId, wxString(
"ki_fp_filters" ) );
324 saveField( &description, aFormatter, aNestLevel + 1 );
325 aNextFreeFieldId += 1;
333 wxCHECK_RET( aItem,
"Invalid LIB_ITEM pointer." );
335 switch( aItem->
Type() )
348 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
352 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
356 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
360 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
364 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
375 savePin(
static_cast<LIB_PIN*
>( aItem ), aFormatter, aNestLevel );
395 wxCHECK_RET( aField && aField->
Type() ==
LIB_FIELD_T,
"Invalid LIB_FIELD object." );
397 wxString fieldName = aField->
GetName();
402 aFormatter.
Print( aNestLevel,
"(property %s %s (at %s %s %g)",
403 aFormatter.
Quotew( fieldName ).c_str(),
410 aFormatter.
Print( 0,
" (show_name)" );
413 aFormatter.
Print( 0,
" (do_not_autoplace)" );
415 aFormatter.
Print( 0,
"\n" );
416 aField->
Format( &aFormatter, aNestLevel, 0 );
417 aFormatter.
Print( aNestLevel,
")\n" );
423 wxCHECK_RET( aPin && aPin->
Type() ==
LIB_PIN_T,
"Invalid LIB_PIN object." );
427 aFormatter.
Print( aNestLevel,
"(pin %s %s (at %s %s %s) (length %s)",
436 aFormatter.
Print( 0,
" hide\n" );
438 aFormatter.
Print( 0,
"\n" );
441 aFormatter.
Print( aNestLevel + 1,
"(name %s (effects (font (size %s %s))))\n",
446 aFormatter.
Print( aNestLevel + 1,
"(number %s (effects (font (size %s %s))))\n",
452 for(
const std::pair<const wxString, LIB_PIN::ALT>& alt : aPin->
GetAlternates() )
454 aFormatter.
Print( aNestLevel + 1,
"(alternate %s %s %s)\n",
455 aFormatter.
Quotew( alt.second.m_Name ).c_str(),
460 aFormatter.
Print( aNestLevel,
")\n" );
467 wxCHECK_RET( aText && aText->
Type() ==
LIB_TEXT_T,
"Invalid LIB_TEXT object." );
469 aFormatter.
Print( aNestLevel,
"(text%s %s (at %s %s %g)\n",
476 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
477 aFormatter.
Print( aNestLevel,
")\n" );
484 wxCHECK_RET( aTextBox && aTextBox->
Type() ==
LIB_TEXTBOX_T,
"Invalid LIB_TEXTBOX object." );
486 aFormatter.
Print( aNestLevel,
"(text_box%s %s\n",
493 aFormatter.
Print( aNestLevel + 1,
"(at %s %s %s) (size %s %s)\n",
501 aFormatter.
Print( 0,
"\n" );
504 aFormatter.
Print( 0,
"\n" );
506 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
507 aFormatter.
Print( aNestLevel,
")\n" );
513 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aSymbolName );
528 LIB_SYMBOL_MAP::iterator it1 =
m_symbols.begin();
532 if( it1->second->IsAlias()
533 && it1->second->GetParent().lock() == rootSymbol->
SharedPtr() )
constexpr EDA_IU_SCALE schIUScale
int AsTenthsOfADegree() const
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual wxString GetClass() const =0
Return the class name.
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)
virtual void SetText(const wxString &aText)
A LINE_READER that reads from an open file.
A color representation with 4 components: red, green, blue, alpha.
Field object used in symbol libraries.
bool CanAutoplace() const
VECTOR2I GetPosition() const override
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
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
The base class for drawable items used by schematic library symbols.
ELECTRICAL_PINTYPE GetType() const
int GetOrientation() const
int GetNumberTextSize() const
VECTOR2I GetPosition() const override
std::map< wxString, ALT > & GetAlternates()
const wxString & GetNumber() const
GRAPHIC_PINSHAPE GetShape() const
const wxString & GetName() const
int GetNameTextSize() const
STROKE_PARAMS GetStroke() const
Define a library symbol object.
int GetPinNameOffset() const
wxString GetKeyWords() const
bool UnitsLocked() const
Check whether symbol units are interchangeable.
int GetNextAvailableFieldId() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of LIB_ITEM objects separated by unit and convert number.
bool GetIncludeOnBoard() const
bool ShowPinNames() const
LIB_ID GetLibId() const override
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
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
bool GetIncludeInBom() const
wxString GetDescription() override
LIB_SYMBOL_REF & GetParent()
bool ShowPinNumbers() const
Define a symbol library graphical text item.
VECTOR2I GetPosition() const override
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
A base cache assistant implementation for the symbol library portion of the SCH_PLUGIN API.
wxFileName GetRealFile() const
wxDateTime GetLibModificationTime()
Object to parser s-expression symbol library and schematic file formats.
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
int GetParsedRequiredVersion() const
virtual ~SCH_SEXPR_PLUGIN_CACHE()
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
static void savePin(LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
int m_fileFormatVersionAtLoad
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveSymbolDrawItem(LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE(const wxString &aLibraryPath)
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel)
static void saveTextBox(LIB_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveDcmInfoAsFields(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int &aNextFreeFieldId, int aNestLevel)
void SetFileFormatVersionAtLoad(int aVersion)
void DeleteSymbol(const wxString &aName) override
Simple container to manage line stroke parameters.
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
#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)
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
Schematic and symbol library s-expression file format parser definitions.
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
EDA_ANGLE getPinAngle(int aOrientation)
void formatArc(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, 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 formatRect(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatBezier(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, 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
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
wxLogTrace helper definitions.