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>
36
37
38SCH_IO_KICAD_SEXPR_LIB_CACHE::SCH_IO_KICAD_SEXPR_LIB_CACHE( const wxString& aFullPathAndFileName ) :
39 SCH_IO_LIB_CACHE( aFullPathAndFileName )
40{
42}
43
44
46{
47}
48
49
51{
52 if( !m_libFileName.FileExists() )
53 {
54 THROW_IO_ERROR( wxString::Format( _( "Library file '%s' not found." ),
55 m_libFileName.GetFullPath() ) );
56 }
57
58 wxCHECK_RET( m_libFileName.IsAbsolute(),
59 wxString::Format( "Cannot use relative file paths in sexpr plugin to "
60 "open library '%s'.", m_libFileName.GetFullPath() ) );
61
62 // The current locale must use period as the decimal point.
63 // Yes, we did this earlier, but it's sadly not thread-safe.
64 LOCALE_IO toggle;
65
66 wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library file '%s'",
67 m_libFileName.GetFullPath() );
68
69 FILE_LINE_READER reader( m_libFileName.GetFullPath() );
70
71 SCH_IO_KICAD_SEXPR_PARSER parser( &reader );
72
73 parser.ParseLib( m_symbols );
75
76 // Remember the file modification time of library file when the cache snapshot was made,
77 // so that in a networked environment we will reload the cache as needed.
80}
81
82
83void SCH_IO_KICAD_SEXPR_LIB_CACHE::Save( const std::optional<bool>& aOpt )
84{
85 if( !m_isModified )
86 return;
87
88 LOCALE_IO toggle; // toggles on, then off, the C locale.
89
90 // Write through symlinks, don't replace them.
91 wxFileName fn = GetRealFile();
92
93 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
94
95 formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
96 "(generator_version \"%s\")\n",
98
99 std::vector<LIB_SYMBOL*> orderedSymbols;
100
101 for( const auto& [ name, symbol ] : m_symbols )
102 {
103 if( symbol )
104 orderedSymbols.push_back( symbol );
105 }
106
107 // Library must be ordered by inheritance depth.
108 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
109 []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
110 {
111 unsigned int lhDepth = aLhs->GetInheritanceDepth();
112 unsigned int rhDepth = aRhs->GetInheritanceDepth();
113
114 if( lhDepth == rhDepth )
115 return aLhs->GetName() < aRhs->GetName();
116
117 return lhDepth < rhDepth;
118 } );
119
120 for( LIB_SYMBOL* symbol : orderedSymbols )
121 SaveSymbol( symbol, *formatter.get(), 1 );
122
123 formatter->Print( 0, ")\n" );
124
125 formatter.reset();
126
127 m_fileModTime = fn.GetModificationTime();
128 m_isModified = false;
129}
130
131
133 int aNestLevel, const wxString& aLibName )
134{
135 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
136
137 // The current locale must use period as the decimal point.
138 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) == ".",
139 LOCALE_IO toggle );
140
141 int nextFreeFieldId = MANDATORY_FIELDS;
142 std::vector<SCH_FIELD*> fields;
143 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
144 std::string unitName = aSymbol->GetLibId().GetLibItemName();
145
146 if( !aLibName.IsEmpty() )
147 {
148 name = aFormatter.Quotew( aLibName );
149
150 LIB_ID unitId;
151
152 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
153
154 unitName = unitId.GetLibItemName();
155 }
156
157 if( aSymbol->IsRoot() )
158 {
159 aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
160
161 if( aSymbol->IsPower() )
162 aFormatter.Print( 0, " (power)" );
163
164 // TODO: add uuid token here.
165
166 // TODO: add anchor position token here.
167
168 if( !aSymbol->GetShowPinNumbers() )
169 aFormatter.Print( 0, " (pin_numbers hide)" );
170
172 || !aSymbol->GetShowPinNames() )
173 {
174 aFormatter.Print( 0, " (pin_names" );
175
177 {
178 aFormatter.Print( 0, " (offset %s)",
180 aSymbol->GetPinNameOffset() ).c_str() );
181 }
182
183 if( !aSymbol->GetShowPinNames() )
184 aFormatter.Print( 0, " hide" );
185
186 aFormatter.Print( 0, ")" );
187 }
188
189 aFormatter.Print( 0, " (exclude_from_sim %s)",
190 ( aSymbol->GetExcludedFromSim() ) ? "yes" : "no" );
191 aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetExcludedFromBOM() ) ? "no" : "yes" );
192 aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetExcludedFromBoard() ) ? "no" : "yes" );
193
194 // TODO: add atomic token here.
195
196 // TODO: add required token here."
197
198 aFormatter.Print( 0, "\n" );
199
200 aSymbol->GetFields( fields );
201
202 for( SCH_FIELD* field : fields )
203 saveField( field, aFormatter, aNestLevel + 1 );
204
205 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
206
207 // @todo At some point in the future the lock status (all units interchangeable) should
208 // be set deterministically. For now a custom lock property is used to preserve the
209 // locked flag state.
210 if( aSymbol->UnitsLocked() )
211 {
212 SCH_FIELD locked( nullptr, nextFreeFieldId, "ki_locked" );
213 saveField( &locked, aFormatter, aNestLevel + 1 );
214 nextFreeFieldId += 1;
215 }
216
217 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
218
219 // Save the draw items grouped by units.
220 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
221 std::sort( units.begin(), units.end(),
222 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
223 {
224 if( a.m_unit == b.m_unit )
225 return a.m_bodyStyle < b.m_bodyStyle;
226
227 return a.m_unit < b.m_unit;
228 } );
229
230 for( const LIB_SYMBOL_UNIT& unit : units )
231 {
232 // Add quotes and escape chars like ") to the UTF8 unitName string
233 name = aFormatter.Quotes( unitName );
234 name.pop_back(); // Remove last char: the quote ending the string.
235
236 aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
237 name.c_str(),
238 unit.m_unit,
239 unit.m_bodyStyle );
240
241 // if the unit has a display name, write that
242 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
243 {
244 name = aSymbol->GetUnitDisplayName( unit.m_unit );
245 aFormatter.Print( aNestLevel + 2, "(unit_name %s)\n",
246 aFormatter.Quotes( name ).c_str() );
247 }
248 // Enforce item ordering
249 auto cmp =
250 []( const SCH_ITEM* a, const SCH_ITEM* b )
251 {
252 return *a < *b;
253 };
254
255 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
256
257 for( SCH_ITEM* item : unit.m_items )
258 save_map.insert( item );
259
260 for( SCH_ITEM* item : save_map )
261 saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
262
263 aFormatter.Print( aNestLevel + 1, ")\n" );
264 }
265 }
266 else
267 {
268 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
269
270 wxASSERT( parent );
271
272 aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
273 name.c_str(),
274 aFormatter.Quotew( parent->GetName() ).c_str() );
275
276 aSymbol->GetFields( fields );
277
278 for( SCH_FIELD* field : fields )
279 saveField( field, aFormatter, aNestLevel + 1 );
280
281 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
282
283 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
284 }
285
286 aFormatter.Print( aNestLevel, ")\n" );
287}
288
289
291 OUTPUTFORMATTER& aFormatter,
292 int& aNextFreeFieldId, int aNestLevel )
293{
294 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
295
296 if( !aSymbol->GetKeyWords().IsEmpty() )
297 {
298 SCH_FIELD keywords( nullptr, aNextFreeFieldId, wxString( "ki_keywords" ) );
299 keywords.SetVisible( false );
300 keywords.SetText( aSymbol->GetKeyWords() );
301 saveField( &keywords, aFormatter, aNestLevel + 1 );
302 aNextFreeFieldId += 1;
303 }
304
305 wxArrayString fpFilters = aSymbol->GetFPFilters();
306
307 if( !fpFilters.IsEmpty() )
308 {
309 wxString tmp;
310
311 for( const wxString& filter : fpFilters )
312 {
313 // Spaces are not handled in fp filter names so escape spaces if any
314 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
315
316 if( tmp.IsEmpty() )
317 tmp = curr_filter;
318 else
319 tmp += " " + curr_filter;
320 }
321
322 SCH_FIELD description( nullptr, aNextFreeFieldId, wxString( "ki_fp_filters" ) );
323 description.SetVisible( false );
324 description.SetText( tmp );
325 saveField( &description, aFormatter, aNestLevel + 1 );
326 aNextFreeFieldId += 1;
327 }
328}
329
330
332 int aNestLevel )
333{
334 wxCHECK_RET( aItem, "Invalid SCH_ITEM pointer." );
335
336 switch( aItem->Type() )
337 {
338 case SCH_SHAPE_T:
339 {
340 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
341 STROKE_PARAMS stroke = shape->GetStroke();
342 FILL_T fillMode = shape->GetFillMode();
343 COLOR4D fillColor = shape->GetFillColor();
344 bool isPrivate = shape->IsPrivate();
345
346 switch( shape->GetShape() )
347 {
348 case SHAPE_T::ARC:
349 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
350 break;
351
352 case SHAPE_T::CIRCLE:
353 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
354 break;
355
356 case SHAPE_T::RECTANGLE:
357 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
358 break;
359
360 case SHAPE_T::BEZIER:
361 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
362 break;
363
364 case SHAPE_T::POLY:
365 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
366 break;
367
368 default:
370 }
371
372 break;
373 }
374
375 case SCH_PIN_T:
376 savePin( static_cast<SCH_PIN*>( aItem ), aFormatter, aNestLevel );
377 break;
378
379 case SCH_TEXT_T:
380 saveText( static_cast<SCH_TEXT*>( aItem ), aFormatter, aNestLevel );
381 break;
382
383 case SCH_TEXTBOX_T:
384 saveTextBox( static_cast<SCH_TEXTBOX*>( aItem ), aFormatter, aNestLevel );
385 break;
386
387 default:
388 UNIMPLEMENTED_FOR( aItem->GetClass() );
389 }
390}
391
392
394 int aNestLevel )
395{
396 wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
397
398 wxString fieldName = aField->GetName();
399
400 if( aField->IsMandatory() )
401 fieldName = GetCanonicalFieldName( aField->GetId() );
402
403 aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
404 aFormatter.Quotew( fieldName ).c_str(),
405 aFormatter.Quotew( aField->GetText() ).c_str(),
407 aField->GetPosition().x ).c_str(),
409 -aField->GetPosition().y ).c_str(),
410 aField->GetTextAngle().AsDegrees() );
411
412 if( aField->IsNameShown() )
413 aFormatter.Print( 0, " (show_name)" );
414
415 if( !aField->CanAutoplace() )
416 aFormatter.Print( 0, " (do_not_autoplace)" );
417
418 aFormatter.Print( 0, "\n" );
419 aField->Format( &aFormatter, aNestLevel, 0 );
420 aFormatter.Print( aNestLevel, ")\n" );
421}
422
423
425 int aNestLevel )
426{
427 wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." );
428
429 aPin->ClearFlags( IS_CHANGED );
430
431 aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
433 getPinShapeToken( aPin->GetShape() ),
435 aPin->GetPosition().x ).c_str(),
437 -aPin->GetPosition().y ).c_str(),
440 aPin->GetLength() ).c_str() );
441
442 if( !aPin->IsVisible() )
443 aFormatter.Print( 0, " hide\n" );
444 else
445 aFormatter.Print( 0, "\n" );
446
447 // This follows the EDA_TEXT effects formatting for future expansion.
448 aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
449 aFormatter.Quotew( aPin->GetName() ).c_str(),
451 aPin->GetNameTextSize() ).c_str(),
453 aPin->GetNameTextSize() ).c_str() );
454
455 aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
456 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
458 aPin->GetNumberTextSize() ).c_str(),
460 aPin->GetNumberTextSize() ).c_str() );
461
462
463 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->GetAlternates() )
464 {
465 aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
466 aFormatter.Quotew( alt.second.m_Name ).c_str(),
467 getPinElectricalTypeToken( alt.second.m_Type ),
468 getPinShapeToken( alt.second.m_Shape ) );
469 }
470
471 aFormatter.Print( aNestLevel, ")\n" );
472}
473
474
476 int aNestLevel )
477{
478 wxCHECK_RET( aText && aText->Type() == SCH_TEXT_T, "Invalid SCH_TEXT object." );
479
480 aFormatter.Print( aNestLevel, "(text%s %s (at %s %s %g)\n",
481 aText->IsPrivate() ? " private" : "",
482 aFormatter.Quotew( aText->GetText() ).c_str(),
484 aText->GetPosition().x ).c_str(),
486 -aText->GetPosition().y ).c_str(),
487 (double) aText->GetTextAngle().AsTenthsOfADegree() );
488
489 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
490 aFormatter.Print( aNestLevel, ")\n" );
491}
492
493
495 int aNestLevel )
496{
497 wxCHECK_RET( aTextBox && aTextBox->Type() == SCH_TEXTBOX_T, "Invalid SCH_TEXTBOX object." );
498
499 aFormatter.Print( aNestLevel, "(text_box%s %s\n",
500 aTextBox->IsPrivate() ? " private" : "",
501 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
502
503 VECTOR2I pos = aTextBox->GetStart();
504 VECTOR2I size = aTextBox->GetEnd() - pos;
505
506 aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s) (margins %s %s %s %s)\n",
509 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
516
517 aTextBox->GetStroke().Format( &aFormatter, schIUScale, aNestLevel + 1 );
518 aFormatter.Print( 0, "\n" );
519
520 formatFill( &aFormatter, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
521 aFormatter.Print( 0, "\n" );
522
523 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
524 aFormatter.Print( aNestLevel, ")\n" );
525}
526
527
528void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
529{
530 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
531
532 if( it == m_symbols.end() )
533 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
534 m_libFileName.GetFullName(), aSymbolName ) );
535
536 LIB_SYMBOL* symbol = it->second;
537
538 if( symbol->IsRoot() )
539 {
540 LIB_SYMBOL* rootSymbol = symbol;
541
542 // Remove the root symbol and all its children.
543 m_symbols.erase( it );
544
545 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
546
547 while( it1 != m_symbols.end() )
548 {
549 if( it1->second->IsAlias()
550 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
551 {
552 delete it1->second;
553 it1 = m_symbols.erase( it1 );
554 }
555 else
556 {
557 it1++;
558 }
559 }
560
561 delete rootSymbol;
562 }
563 else
564 {
565 // Just remove the alias.
566 m_symbols.erase( it );
567 delete symbol;
568 }
569
571 m_isModified = true;
572}
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:100
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:128
FILL_T GetFillMode() const
Definition: eda_shape.h:107
SHAPE_T GetShape() const
Definition: eda_shape.h:125
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:167
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:130
COLOR4D GetFillColor() const
Definition: eda_shape.h:111
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:89
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 aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:910
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:243
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:77
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:142
wxString GetKeyWords() const override
Definition: lib_symbol.h:170
bool IsPower() const override
Definition: lib_symbol.cpp:388
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:263
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.
Definition: lib_symbol.h:193
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:259
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:205
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:253
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:88
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:105
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:526
int PRINTF_FUNC 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:487
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:1484
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1462
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:1204
bool CanAutoplace() const
Definition: sch_field.h:219
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1189
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)
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 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.
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:166
bool IsPrivate() const
Definition: sch_item.h:235
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:176
int GetNumberTextSize() const
Definition: sch_pin.cpp:499
int GetLength() const
Definition: sch_pin.cpp:278
bool IsVisible() const
Definition: sch_pin.cpp:340
const wxString & GetName() const
Definition: sch_pin.cpp:353
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:245
std::map< wxString, ALT > & GetAlternates()
Definition: sch_pin.h:121
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:237
int GetNameTextSize() const
Definition: sch_pin.cpp:477
const wxString & GetNumber() const
Definition: sch_pin.h:111
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:258
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:291
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:81
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
bool GetExcludedFromBoard() const
Definition: symbol.h:148
bool GetExcludedFromBOM() const
Definition: symbol.h:142
int GetPinNameOffset() const
Definition: symbol.h:118
virtual bool GetShowPinNames() const
Definition: symbol.h:124
virtual bool GetShowPinNumbers() const
Definition: symbol.h:130
bool GetExcludedFromSim() const override
Definition: symbol.h:136
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:55
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
#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
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