KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_kicad_sexpr_lib_cache.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * @author Wayne Stambaugh <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <wx/log.h>
23#include <base_units.h>
24#include <build_version.h>
25#include <sch_shape.h>
26#include <lib_symbol.h>
27#include <sch_textbox.h>
28#include <locale_io.h>
29#include <macros.h>
30#include <richio.h>
34#include <string_utils.h>
35#include <trace_helpers.h>
37
38
39SCH_IO_KICAD_SEXPR_LIB_CACHE::SCH_IO_KICAD_SEXPR_LIB_CACHE( const wxString& aFullPathAndFileName ) :
40 SCH_IO_LIB_CACHE( aFullPathAndFileName )
41{
43}
44
45
47{
48}
49
50
52{
53 if( !m_libFileName.FileExists() )
54 {
55 THROW_IO_ERROR( wxString::Format( _( "Library file '%s' not found." ),
56 m_libFileName.GetFullPath() ) );
57 }
58
59 wxCHECK_RET( m_libFileName.IsAbsolute(),
60 wxString::Format( "Cannot use relative file paths in sexpr plugin to "
61 "open library '%s'.", m_libFileName.GetFullPath() ) );
62
63 // The current locale must use period as the decimal point.
64 // Yes, we did this earlier, but it's sadly not thread-safe.
65 LOCALE_IO toggle;
66
67 wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library file '%s'",
68 m_libFileName.GetFullPath() );
69
70 FILE_LINE_READER reader( m_libFileName.GetFullPath() );
71
72 SCH_IO_KICAD_SEXPR_PARSER parser( &reader );
73
74 parser.ParseLib( m_symbols );
76
77 // Remember the file modification time of library file when the cache snapshot was made,
78 // so that in a networked environment we will reload the cache as needed.
81}
82
83
84void SCH_IO_KICAD_SEXPR_LIB_CACHE::Save( const std::optional<bool>& aOpt )
85{
86 if( !m_isModified )
87 return;
88
89 LOCALE_IO toggle; // toggles on, then off, the C locale.
90
91 // Write through symlinks, don't replace them.
92 wxFileName fn = GetRealFile();
93
94 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
95
96 formatter->Print( "(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
97 "(generator_version \"%s\")",
99 GetMajorMinorVersion().c_str().AsChar() );
100
101 std::vector<LIB_SYMBOL*> orderedSymbols;
102
103 for( const auto& [ name, symbol ] : m_symbols )
104 {
105 if( symbol )
106 orderedSymbols.push_back( symbol );
107 }
108
109 // Library must be ordered by inheritance depth.
110 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
111 []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
112 {
113 unsigned int lhDepth = aLhs->GetInheritanceDepth();
114 unsigned int rhDepth = aRhs->GetInheritanceDepth();
115
116 if( lhDepth == rhDepth )
117 return aLhs->GetName() < aRhs->GetName();
118
119 return lhDepth < rhDepth;
120 } );
121
122 for( LIB_SYMBOL* symbol : orderedSymbols )
123 SaveSymbol( symbol, *formatter.get() );
124
125 formatter->Print( ")" );
126
127 formatter.reset();
128
129 m_fileModTime = fn.GetModificationTime();
130 m_isModified = false;
131}
132
133
135 const wxString& aLibName, bool aIncludeData )
136{
137 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
138
139 // The current locale must use period as the decimal point.
140 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) == ".",
141 LOCALE_IO toggle );
142
143
144 // If we've requested to embed the fonts in the symbol, do so.
145 // Otherwise, clear the embedded fonts from the symbol. Embedded
146 // fonts will be used if available
147 if( aSymbol->GetAreFontsEmbedded() )
148 aSymbol->EmbedFonts();
149 else
151
152 int nextFreeFieldId = MANDATORY_FIELDS;
153 std::vector<SCH_FIELD*> fields;
154 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
155 std::string unitName = aSymbol->GetLibId().GetLibItemName();
156
157 if( !aLibName.IsEmpty() )
158 {
159 name = aFormatter.Quotew( aLibName );
160
161 LIB_ID unitId;
162
163 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
164
165 unitName = unitId.GetLibItemName();
166 }
167
168 if( aSymbol->IsRoot() )
169 {
170 aFormatter.Print( "(symbol %s", name.c_str() );
171
172 if( aSymbol->IsPower() )
173 aFormatter.Print( "(power)" );
174
175 // TODO: add uuid token here.
176
177 // TODO: add anchor position token here.
178
179 if( !aSymbol->GetShowPinNumbers() )
180 aFormatter.Print( "(pin_numbers (hide yes))" );
181
183 || !aSymbol->GetShowPinNames() )
184 {
185 aFormatter.Print( "(pin_names" );
186
188 {
189 aFormatter.Print( "(offset %s)",
191 aSymbol->GetPinNameOffset() ).c_str() );
192 }
193
194 if( !aSymbol->GetShowPinNames() )
195 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
196
197 aFormatter.Print( ")" );
198 }
199
200 KICAD_FORMAT::FormatBool( &aFormatter, "exclude_from_sim", aSymbol->GetExcludedFromSim() );
201 KICAD_FORMAT::FormatBool( &aFormatter, "in_bom", !aSymbol->GetExcludedFromBOM() );
202 KICAD_FORMAT::FormatBool( &aFormatter, "on_board", !aSymbol->GetExcludedFromBoard() );
203
204 // TODO: add atomic token here.
205
206 // TODO: add required token here."
207
208 aSymbol->GetFields( fields );
209
210 for( SCH_FIELD* field : fields )
211 saveField( field, aFormatter );
212
213 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
214
215 // @todo At some point in the future the lock status (all units interchangeable) should
216 // be set deterministically. For now a custom lock property is used to preserve the
217 // locked flag state.
218 if( aSymbol->UnitsLocked() )
219 {
220 SCH_FIELD locked( nullptr, nextFreeFieldId, "ki_locked" );
221 saveField( &locked, aFormatter );
222 nextFreeFieldId += 1;
223 }
224
225 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId );
226
227 // Save the draw items grouped by units.
228 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
229 std::sort( units.begin(), units.end(),
230 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
231 {
232 if( a.m_unit == b.m_unit )
233 return a.m_bodyStyle < b.m_bodyStyle;
234
235 return a.m_unit < b.m_unit;
236 } );
237
238 for( const LIB_SYMBOL_UNIT& unit : units )
239 {
240 // Add quotes and escape chars like ") to the UTF8 unitName string
241 name = aFormatter.Quotes( unitName );
242 name.pop_back(); // Remove last char: the quote ending the string.
243
244 aFormatter.Print( "(symbol %s_%d_%d\"",
245 name.c_str(),
246 unit.m_unit,
247 unit.m_bodyStyle );
248
249 // if the unit has a display name, write that
250 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
251 {
252 name = aSymbol->GetUnitDisplayName( unit.m_unit );
253 aFormatter.Print( "(unit_name %s)", aFormatter.Quotes( name ).c_str() );
254 }
255
256 // Enforce item ordering
257 auto cmp =
258 []( const SCH_ITEM* a, const SCH_ITEM* b )
259 {
260 return *a < *b;
261 };
262
263 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
264
265 for( SCH_ITEM* item : unit.m_items )
266 save_map.insert( item );
267
268 for( SCH_ITEM* item : save_map )
269 saveSymbolDrawItem( item, aFormatter );
270
271 aFormatter.Print( ")" );
272 }
273
274 KICAD_FORMAT::FormatBool( &aFormatter, "embedded_fonts", aSymbol->GetAreFontsEmbedded() );
275
276 if( !aSymbol->EmbeddedFileMap().empty() )
277 aSymbol->WriteEmbeddedFiles( aFormatter, aIncludeData );
278 }
279 else
280 {
281 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
282
283 wxASSERT( parent );
284
285 aFormatter.Print( "(symbol %s (extends %s)",
286 name.c_str(),
287 aFormatter.Quotew( parent->GetName() ).c_str() );
288
289 aSymbol->GetFields( fields );
290
291 for( SCH_FIELD* field : fields )
292 saveField( field, aFormatter );
293
294 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
295
296 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId );
297 }
298
299 aFormatter.Print( ")" );
300}
301
302
304 OUTPUTFORMATTER& aFormatter,
305 int& aNextFreeFieldId )
306{
307 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
308
309 if( !aSymbol->GetKeyWords().IsEmpty() )
310 {
311 SCH_FIELD keywords( nullptr, aNextFreeFieldId, wxString( "ki_keywords" ) );
312 keywords.SetVisible( false );
313 keywords.SetText( aSymbol->GetKeyWords() );
314 saveField( &keywords, aFormatter );
315 aNextFreeFieldId += 1;
316 }
317
318 wxArrayString fpFilters = aSymbol->GetFPFilters();
319
320 if( !fpFilters.IsEmpty() )
321 {
322 wxString tmp;
323
324 for( const wxString& filter : fpFilters )
325 {
326 // Spaces are not handled in fp filter names so escape spaces if any
327 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
328
329 if( tmp.IsEmpty() )
330 tmp = curr_filter;
331 else
332 tmp += " " + curr_filter;
333 }
334
335 SCH_FIELD description( nullptr, aNextFreeFieldId, wxString( "ki_fp_filters" ) );
336 description.SetVisible( false );
337 description.SetText( tmp );
338 saveField( &description, aFormatter );
339 aNextFreeFieldId += 1;
340 }
341}
342
343
345{
346 wxCHECK_RET( aItem, "Invalid SCH_ITEM pointer." );
347
348 switch( aItem->Type() )
349 {
350 case SCH_SHAPE_T:
351 {
352 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
353 STROKE_PARAMS stroke = shape->GetStroke();
354 FILL_T fillMode = shape->GetFillMode();
355 COLOR4D fillColor = shape->GetFillColor();
356 bool isPrivate = shape->IsPrivate();
357
358 switch( shape->GetShape() )
359 {
360 case SHAPE_T::ARC:
361 formatArc( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
362 break;
363
364 case SHAPE_T::CIRCLE:
365 formatCircle( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
366 break;
367
368 case SHAPE_T::RECTANGLE:
369 formatRect( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
370 break;
371
372 case SHAPE_T::BEZIER:
373 formatBezier(&aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
374 break;
375
376 case SHAPE_T::POLY:
377 formatPoly( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
378 break;
379
380 default:
382 }
383
384 break;
385 }
386
387 case SCH_PIN_T:
388 savePin( static_cast<SCH_PIN*>( aItem ), aFormatter );
389 break;
390
391 case SCH_TEXT_T:
392 saveText( static_cast<SCH_TEXT*>( aItem ), aFormatter );
393 break;
394
395 case SCH_TEXTBOX_T:
396 saveTextBox( static_cast<SCH_TEXTBOX*>( aItem ), aFormatter );
397 break;
398
399 default:
400 UNIMPLEMENTED_FOR( aItem->GetClass() );
401 }
402}
403
404
406{
407 wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
408
409 wxString fieldName = aField->GetName();
410
411 if( aField->IsMandatory() )
412 fieldName = GetCanonicalFieldName( aField->GetId() );
413
414 aFormatter.Print( "(property %s %s %s (at %s %s %g)",
415 aField->IsPrivate() ? "private" : "",
416 aFormatter.Quotew( fieldName ).c_str(),
417 aFormatter.Quotew( aField->GetText() ).c_str(),
419 aField->GetPosition().x ).c_str(),
421 -aField->GetPosition().y ).c_str(),
422 aField->GetTextAngle().AsDegrees() );
423
424 if( aField->IsNameShown() )
425 aFormatter.Print( "(show_name)" );
426
427 if( !aField->CanAutoplace() )
428 aFormatter.Print( "(do_not_autoplace)" );
429
430 aField->Format( &aFormatter, 0 );
431 aFormatter.Print( ")" );
432}
433
434
436{
437 wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." );
438
439 aPin->ClearFlags( IS_CHANGED );
440
441 aFormatter.Print( "(pin %s %s (at %s %s %s) (length %s)",
443 getPinShapeToken( aPin->GetShape() ),
445 aPin->GetPosition().x ).c_str(),
447 -aPin->GetPosition().y ).c_str(),
450 aPin->GetLength() ).c_str() );
451
452 if( !aPin->IsVisible() )
453 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
454
455 // This follows the EDA_TEXT effects formatting for future expansion.
456 aFormatter.Print( "(name %s (effects (font (size %s %s))))",
457 aFormatter.Quotew( aPin->GetName() ).c_str(),
459 aPin->GetNameTextSize() ).c_str(),
461 aPin->GetNameTextSize() ).c_str() );
462
463 aFormatter.Print( "(number %s (effects (font (size %s %s))))",
464 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
466 aPin->GetNumberTextSize() ).c_str(),
468 aPin->GetNumberTextSize() ).c_str() );
469
470
471 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->GetAlternates() )
472 {
473 aFormatter.Print( "(alternate %s %s %s)",
474 aFormatter.Quotew( alt.second.m_Name ).c_str(),
475 getPinElectricalTypeToken( alt.second.m_Type ),
476 getPinShapeToken( alt.second.m_Shape ) );
477 }
478
479 aFormatter.Print( ")" );
480}
481
482
484{
485 wxCHECK_RET( aText && aText->Type() == SCH_TEXT_T, "Invalid SCH_TEXT object." );
486
487 aFormatter.Print( "(text %s %s (at %s %s %g)",
488 aText->IsPrivate() ? "private" : "",
489 aFormatter.Quotew( aText->GetText() ).c_str(),
491 aText->GetPosition().x ).c_str(),
493 -aText->GetPosition().y ).c_str(),
494 (double) aText->GetTextAngle().AsTenthsOfADegree() );
495
496 aText->EDA_TEXT::Format( &aFormatter, 0 );
497 aFormatter.Print( ")" );
498}
499
500
502{
503 wxCHECK_RET( aTextBox && aTextBox->Type() == SCH_TEXTBOX_T, "Invalid SCH_TEXTBOX object." );
504
505 aFormatter.Print( "(text_box %s %s",
506 aTextBox->IsPrivate() ? "private" : "",
507 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
508
509 VECTOR2I pos = aTextBox->GetStart();
510 VECTOR2I size = aTextBox->GetEnd() - pos;
511
512 aFormatter.Print( "(at %s %s %s) (size %s %s) (margins %s %s %s %s)",
515 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
522
523 aTextBox->GetStroke().Format( &aFormatter, schIUScale );
524 formatFill( &aFormatter, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
525 aTextBox->EDA_TEXT::Format( &aFormatter, 0 );
526 aFormatter.Print( ")" );
527}
528
529
530void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
531{
532 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
533
534 if( it == m_symbols.end() )
535 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
536 m_libFileName.GetFullName(), aSymbolName ) );
537
538 LIB_SYMBOL* symbol = it->second;
539
540 if( symbol->IsRoot() )
541 {
542 LIB_SYMBOL* rootSymbol = symbol;
543
544 // Remove the root symbol and all its children.
545 m_symbols.erase( it );
546
547 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
548
549 while( it1 != m_symbols.end() )
550 {
551 if( it1->second->IsAlias()
552 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
553 {
554 delete it1->second;
555 it1 = m_symbols.erase( it1 );
556 }
557 else
558 {
559 it1++;
560 }
561 }
562
563 delete rootSymbol;
564 }
565 else
566 {
567 // Just remove the alias.
568 m_symbols.erase( it );
569 delete symbol;
570 }
571
573 m_isModified = true;
574}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
int AsTenthsOfADegree() const
Definition: eda_angle.h:115
double AsDegrees() const
Definition: eda_angle.h:113
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
FILL_T GetFillMode() const
Definition: eda_shape.h:114
SHAPE_T GetShape() const
Definition: eda_shape.h:132
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
COLOR4D GetFillColor() const
Definition: eda_shape.h:118
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:340
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:1047
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:377
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, bool aWriteData) const
Output formatter for the embedded files.
void ClearEmbeddedFonts()
Removes 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.
Definition: richio.h:185
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
Define a library symbol object.
Definition: lib_symbol.h:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
wxString GetKeyWords() const override
Definition: lib_symbol.h:171
bool IsPower() const override
Definition: lib_symbol.cpp:389
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:274
int GetNextAvailableFieldId() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:194
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.
Definition: lib_symbol.cpp:260
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) override
Return a list of fields within this symbol.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:206
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:254
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:89
EMBEDDED_FILES * GetEmbeddedFiles() override
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:106
void EmbedFonts() override
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:543
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:504
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
bool IsMandatory() const
Definition: sch_field.cpp:1508
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1486
bool IsNameShown() const
Definition: sch_field.h:208
int GetId() const
Definition: sch_field.h:133
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1228
bool CanAutoplace() const
Definition: sch_field.h:219
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1213
static void saveSymbolDrawItem(SCH_ITEM *aItem, OUTPUTFORMATTER &aFormatter)
SCH_IO_KICAD_SEXPR_LIB_CACHE(const wxString &aLibraryPath)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
static void saveDcmInfoAsFields(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int &aNextFreeFieldId)
static void saveTextBox(SCH_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter)
static void saveField(SCH_FIELD *aField, 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 Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
Object to parser s-expression symbol library and schematic file formats.
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
A base cache assistant implementation for the symbol library portion of the SCH_IO API.
wxDateTime GetLibModificationTime()
LIB_SYMBOL_MAP m_symbols
wxFileName GetRealFile() const
wxDateTime m_fileModTime
wxFileName m_libFileName
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
bool IsPrivate() const
Definition: sch_item.h:237
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:178
int GetNumberTextSize() const
Definition: sch_pin.cpp:564
int GetLength() const
Definition: sch_pin.cpp:295
const std::map< wxString, ALT > & GetAlternates() const
Definition: sch_pin.h:126
bool IsVisible() const
Definition: sch_pin.cpp:374
const wxString & GetName() const
Definition: sch_pin.cpp:388
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:260
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:252
int GetNameTextSize() const
Definition: sch_pin.cpp:540
const wxString & GetNumber() const
Definition: sch_pin.h:116
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:274
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:309
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:55
int GetMarginBottom() const
Definition: sch_textbox.h:66
int GetMarginLeft() const
Definition: sch_textbox.h:63
int GetMarginRight() const
Definition: sch_textbox.h:65
int GetMarginTop() const
Definition: sch_textbox.h:64
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
bool GetExcludedFromBoard() const
Definition: symbol.h:181
bool GetExcludedFromBOM() const
Definition: symbol.h:175
int GetPinNameOffset() const
Definition: symbol.h:151
virtual bool GetShowPinNames() const
Definition: symbol.h:157
virtual bool GetShowPinNumbers() const
Definition: symbol.h:163
bool GetExcludedFromSim() const override
Definition: symbol.h:169
wxString wx_str() const
Definition: utf8.cpp:45
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
#define _(s)
#define IS_CHANGED
Item was edited, and modified.
FILL_T
Definition: eda_shape.h:56
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
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.
Definition: eda_units.cpp:169
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:161
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
#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:...
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
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.
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_PIN_T
Definition: typeinfo.h:153