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, bool aIncludeData )
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
142 // If we've requested to embed the fonts in the symbol, do so.
143 // Otherwise, clear the embedded fonts from the symbol. Embedded
144 // fonts will be used if available
145 if( aSymbol->GetAreFontsEmbedded() )
146 aSymbol->EmbedFonts();
147 else
149
150 int nextFreeFieldId = MANDATORY_FIELDS;
151 std::vector<SCH_FIELD*> fields;
152 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
153 std::string unitName = aSymbol->GetLibId().GetLibItemName();
154
155 if( !aLibName.IsEmpty() )
156 {
157 name = aFormatter.Quotew( aLibName );
158
159 LIB_ID unitId;
160
161 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
162
163 unitName = unitId.GetLibItemName();
164 }
165
166 if( aSymbol->IsRoot() )
167 {
168 aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
169
170 if( aSymbol->IsPower() )
171 aFormatter.Print( 0, " (power)" );
172
173 // TODO: add uuid token here.
174
175 // TODO: add anchor position token here.
176
177 if( !aSymbol->GetShowPinNumbers() )
178 aFormatter.Print( 0, " (pin_numbers hide)" );
179
181 || !aSymbol->GetShowPinNames() )
182 {
183 aFormatter.Print( 0, " (pin_names" );
184
186 {
187 aFormatter.Print( 0, " (offset %s)",
189 aSymbol->GetPinNameOffset() ).c_str() );
190 }
191
192 if( !aSymbol->GetShowPinNames() )
193 aFormatter.Print( 0, " hide" );
194
195 aFormatter.Print( 0, ")" );
196 }
197
198 aFormatter.Print( 0, " (exclude_from_sim %s)",
199 ( aSymbol->GetExcludedFromSim() ) ? "yes" : "no" );
200 aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetExcludedFromBOM() ) ? "no" : "yes" );
201 aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetExcludedFromBoard() ) ? "no" : "yes" );
202
203 // TODO: add atomic token here.
204
205 // TODO: add required token here."
206
207 aFormatter.Print( 0, "\n" );
208
209 aSymbol->GetFields( fields );
210
211 for( SCH_FIELD* field : fields )
212 saveField( field, aFormatter, aNestLevel + 1 );
213
214 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
215
216 // @todo At some point in the future the lock status (all units interchangeable) should
217 // be set deterministically. For now a custom lock property is used to preserve the
218 // locked flag state.
219 if( aSymbol->UnitsLocked() )
220 {
221 SCH_FIELD locked( nullptr, nextFreeFieldId, "ki_locked" );
222 saveField( &locked, aFormatter, aNestLevel + 1 );
223 nextFreeFieldId += 1;
224 }
225
226 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
227
228 // Save the draw items grouped by units.
229 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
230 std::sort( units.begin(), units.end(),
231 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
232 {
233 if( a.m_unit == b.m_unit )
234 return a.m_bodyStyle < b.m_bodyStyle;
235
236 return a.m_unit < b.m_unit;
237 } );
238
239 for( const LIB_SYMBOL_UNIT& unit : units )
240 {
241 // Add quotes and escape chars like ") to the UTF8 unitName string
242 name = aFormatter.Quotes( unitName );
243 name.pop_back(); // Remove last char: the quote ending the string.
244
245 aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
246 name.c_str(),
247 unit.m_unit,
248 unit.m_bodyStyle );
249
250 // if the unit has a display name, write that
251 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
252 {
253 name = aSymbol->GetUnitDisplayName( unit.m_unit );
254 aFormatter.Print( aNestLevel + 2, "(unit_name %s)\n",
255 aFormatter.Quotes( name ).c_str() );
256 }
257 // Enforce item ordering
258 auto cmp =
259 []( const SCH_ITEM* a, const SCH_ITEM* b )
260 {
261 return *a < *b;
262 };
263
264 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
265
266 for( SCH_ITEM* item : unit.m_items )
267 save_map.insert( item );
268
269 for( SCH_ITEM* item : save_map )
270 saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
271
272 aFormatter.Print( aNestLevel + 1, ")\n" );
273 }
274
275 aFormatter.Print( aNestLevel + 1, "(embedded_fonts %s)\n",
276 aSymbol->GetAreFontsEmbedded() ? "yes" : "no" );
277
278 if( !aSymbol->EmbeddedFileMap().empty() )
279 aSymbol->WriteEmbeddedFiles( aFormatter, aNestLevel + 1, aIncludeData );
280 }
281 else
282 {
283 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
284
285 wxASSERT( parent );
286
287 aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
288 name.c_str(),
289 aFormatter.Quotew( parent->GetName() ).c_str() );
290
291 aSymbol->GetFields( fields );
292
293 for( SCH_FIELD* field : fields )
294 saveField( field, aFormatter, aNestLevel + 1 );
295
296 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
297
298 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
299 }
300
301 aFormatter.Print( aNestLevel, ")\n" );
302}
303
304
306 OUTPUTFORMATTER& aFormatter,
307 int& aNextFreeFieldId, int aNestLevel )
308{
309 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
310
311 if( !aSymbol->GetKeyWords().IsEmpty() )
312 {
313 SCH_FIELD keywords( nullptr, aNextFreeFieldId, wxString( "ki_keywords" ) );
314 keywords.SetVisible( false );
315 keywords.SetText( aSymbol->GetKeyWords() );
316 saveField( &keywords, aFormatter, aNestLevel + 1 );
317 aNextFreeFieldId += 1;
318 }
319
320 wxArrayString fpFilters = aSymbol->GetFPFilters();
321
322 if( !fpFilters.IsEmpty() )
323 {
324 wxString tmp;
325
326 for( const wxString& filter : fpFilters )
327 {
328 // Spaces are not handled in fp filter names so escape spaces if any
329 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
330
331 if( tmp.IsEmpty() )
332 tmp = curr_filter;
333 else
334 tmp += " " + curr_filter;
335 }
336
337 SCH_FIELD description( nullptr, aNextFreeFieldId, wxString( "ki_fp_filters" ) );
338 description.SetVisible( false );
339 description.SetText( tmp );
340 saveField( &description, aFormatter, aNestLevel + 1 );
341 aNextFreeFieldId += 1;
342 }
343}
344
345
347 int aNestLevel )
348{
349 wxCHECK_RET( aItem, "Invalid SCH_ITEM pointer." );
350
351 switch( aItem->Type() )
352 {
353 case SCH_SHAPE_T:
354 {
355 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
356 STROKE_PARAMS stroke = shape->GetStroke();
357 FILL_T fillMode = shape->GetFillMode();
358 COLOR4D fillColor = shape->GetFillColor();
359 bool isPrivate = shape->IsPrivate();
360
361 switch( shape->GetShape() )
362 {
363 case SHAPE_T::ARC:
364 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
365 break;
366
367 case SHAPE_T::CIRCLE:
368 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
369 break;
370
371 case SHAPE_T::RECTANGLE:
372 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
373 break;
374
375 case SHAPE_T::BEZIER:
376 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
377 break;
378
379 case SHAPE_T::POLY:
380 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor, true );
381 break;
382
383 default:
385 }
386
387 break;
388 }
389
390 case SCH_PIN_T:
391 savePin( static_cast<SCH_PIN*>( aItem ), aFormatter, aNestLevel );
392 break;
393
394 case SCH_TEXT_T:
395 saveText( static_cast<SCH_TEXT*>( aItem ), aFormatter, aNestLevel );
396 break;
397
398 case SCH_TEXTBOX_T:
399 saveTextBox( static_cast<SCH_TEXTBOX*>( aItem ), aFormatter, aNestLevel );
400 break;
401
402 default:
403 UNIMPLEMENTED_FOR( aItem->GetClass() );
404 }
405}
406
407
409 int aNestLevel )
410{
411 wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
412
413 wxString fieldName = aField->GetName();
414
415 if( aField->IsMandatory() )
416 fieldName = GetCanonicalFieldName( aField->GetId() );
417
418 aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
419 aFormatter.Quotew( fieldName ).c_str(),
420 aFormatter.Quotew( aField->GetText() ).c_str(),
422 aField->GetPosition().x ).c_str(),
424 -aField->GetPosition().y ).c_str(),
425 aField->GetTextAngle().AsDegrees() );
426
427 if( aField->IsNameShown() )
428 aFormatter.Print( 0, " (show_name)" );
429
430 if( !aField->CanAutoplace() )
431 aFormatter.Print( 0, " (do_not_autoplace)" );
432
433 aFormatter.Print( 0, "\n" );
434 aField->Format( &aFormatter, aNestLevel, 0 );
435 aFormatter.Print( aNestLevel, ")\n" );
436}
437
438
440 int aNestLevel )
441{
442 wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." );
443
444 aPin->ClearFlags( IS_CHANGED );
445
446 aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
448 getPinShapeToken( aPin->GetShape() ),
450 aPin->GetPosition().x ).c_str(),
452 -aPin->GetPosition().y ).c_str(),
455 aPin->GetLength() ).c_str() );
456
457 if( !aPin->IsVisible() )
458 aFormatter.Print( 0, " hide\n" );
459 else
460 aFormatter.Print( 0, "\n" );
461
462 // This follows the EDA_TEXT effects formatting for future expansion.
463 aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
464 aFormatter.Quotew( aPin->GetName() ).c_str(),
466 aPin->GetNameTextSize() ).c_str(),
468 aPin->GetNameTextSize() ).c_str() );
469
470 aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
471 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
473 aPin->GetNumberTextSize() ).c_str(),
475 aPin->GetNumberTextSize() ).c_str() );
476
477
478 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->GetAlternates() )
479 {
480 aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
481 aFormatter.Quotew( alt.second.m_Name ).c_str(),
482 getPinElectricalTypeToken( alt.second.m_Type ),
483 getPinShapeToken( alt.second.m_Shape ) );
484 }
485
486 aFormatter.Print( aNestLevel, ")\n" );
487}
488
489
491 int aNestLevel )
492{
493 wxCHECK_RET( aText && aText->Type() == SCH_TEXT_T, "Invalid SCH_TEXT object." );
494
495 aFormatter.Print( aNestLevel, "(text%s %s (at %s %s %g)\n",
496 aText->IsPrivate() ? " private" : "",
497 aFormatter.Quotew( aText->GetText() ).c_str(),
499 aText->GetPosition().x ).c_str(),
501 -aText->GetPosition().y ).c_str(),
502 (double) aText->GetTextAngle().AsTenthsOfADegree() );
503
504 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
505 aFormatter.Print( aNestLevel, ")\n" );
506}
507
508
510 int aNestLevel )
511{
512 wxCHECK_RET( aTextBox && aTextBox->Type() == SCH_TEXTBOX_T, "Invalid SCH_TEXTBOX object." );
513
514 aFormatter.Print( aNestLevel, "(text_box%s %s\n",
515 aTextBox->IsPrivate() ? " private" : "",
516 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
517
518 VECTOR2I pos = aTextBox->GetStart();
519 VECTOR2I size = aTextBox->GetEnd() - pos;
520
521 aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s) (margins %s %s %s %s)\n",
524 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
531
532 aTextBox->GetStroke().Format( &aFormatter, schIUScale, aNestLevel + 1 );
533 aFormatter.Print( 0, "\n" );
534
535 formatFill( &aFormatter, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
536 aFormatter.Print( 0, "\n" );
537
538 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
539 aFormatter.Print( aNestLevel, ")\n" );
540}
541
542
543void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
544{
545 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
546
547 if( it == m_symbols.end() )
548 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
549 m_libFileName.GetFullName(), aSymbolName ) );
550
551 LIB_SYMBOL* symbol = it->second;
552
553 if( symbol->IsRoot() )
554 {
555 LIB_SYMBOL* rootSymbol = symbol;
556
557 // Remove the root symbol and all its children.
558 m_symbols.erase( it );
559
560 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
561
562 while( it1 != m_symbols.end() )
563 {
564 if( it1->second->IsAlias()
565 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
566 {
567 delete it1->second;
568 it1 = m_symbols.erase( it1 );
569 }
570 else
571 {
572 it1++;
573 }
574 }
575
576 delete rootSymbol;
577 }
578 else
579 {
580 // Just remove the alias.
581 m_symbols.erase( it );
582 delete symbol;
583 }
584
586 m_isModified = true;
587}
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: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:130
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:911
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:244
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, int aNestLevel, 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:264
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: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
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: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 SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
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 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