KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_sexpr_lib_plugin_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 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 <lib_shape.h>
25#include <lib_symbol.h>
26#include <lib_text.h>
27#include <lib_textbox.h>
28#include <locale_io.h>
29#include <macros.h>
30#include <richio.h>
33#include "sch_sexpr_parser.h"
34#include <string_utils.h>
35#include <trace_helpers.h>
36
37
38SCH_SEXPR_PLUGIN_CACHE::SCH_SEXPR_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
39 SCH_LIB_PLUGIN_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_SEXPR_PARSER parser( &reader );
72
73 parser.ParseLib( m_symbols );
74 ++m_modHash;
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_SEXPR_PLUGIN_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<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
94
95 formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator kicad_symbol_editor)\n",
97
98 std::vector<LIB_SYMBOL*> orderedSymbols;
99
100 for( const auto& [ name, symbol ] : m_symbols )
101 {
102 if( symbol )
103 orderedSymbols.push_back( symbol );
104 }
105
106 // Library must be ordered by inheritance depth.
107 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
108 []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
109 {
110 unsigned int lhDepth = aLhs->GetInheritanceDepth();
111 unsigned int rhDepth = aRhs->GetInheritanceDepth();
112
113 if( lhDepth == rhDepth )
114 return aLhs->GetName() < aRhs->GetName();
115
116 return lhDepth < rhDepth;
117 } );
118
119 for( LIB_SYMBOL* symbol : orderedSymbols )
120 SaveSymbol( symbol, *formatter.get(), 1 );
121
122 formatter->Print( 0, ")\n" );
123
124 formatter.reset();
125
126 m_fileModTime = fn.GetModificationTime();
127 m_isModified = false;
128}
129
130
132 int aNestLevel, const wxString& aLibName )
133{
134 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
135
136 // The current locale must use period as the decimal point.
137 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) == ".",
138 LOCALE_IO toggle );
139
140 int nextFreeFieldId = MANDATORY_FIELDS;
141 std::vector<LIB_FIELD*> fields;
142 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
143 std::string unitName = aSymbol->GetLibId().GetLibItemName();
144
145 if( !aLibName.IsEmpty() )
146 {
147 name = aFormatter.Quotew( aLibName );
148
149 LIB_ID unitId;
150
151 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
152
153 unitName = unitId.GetLibItemName();
154 }
155
156 if( aSymbol->IsRoot() )
157 {
158 aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
159
160 if( aSymbol->IsPower() )
161 aFormatter.Print( 0, " (power)" );
162
163 // TODO: add uuid token here.
164
165 // TODO: add anchor position token here.
166
167 if( !aSymbol->ShowPinNumbers() )
168 aFormatter.Print( 0, " (pin_numbers hide)" );
169
171 || !aSymbol->ShowPinNames() )
172 {
173 aFormatter.Print( 0, " (pin_names" );
174
176 aFormatter.Print( 0, " (offset %s)",
178
179 if( !aSymbol->ShowPinNames() )
180 aFormatter.Print( 0, " hide" );
181
182 aFormatter.Print( 0, ")" );
183 }
184
185 aFormatter.Print( 0, " (exclude_from_sim %s)",
186 ( aSymbol->GetExcludedFromSim() ) ? "yes" : "no" );
187 aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetExcludedFromBOM() ) ? "no" : "yes" );
188 aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetExcludedFromBoard() ) ? "no" : "yes" );
189
190 // TODO: add atomic token here.
191
192 // TODO: add required token here."
193
194 aFormatter.Print( 0, "\n" );
195
196 aSymbol->GetFields( fields );
197
198 for( LIB_FIELD* field : fields )
199 saveField( field, aFormatter, aNestLevel + 1 );
200
201 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
202
203 // @todo At some point in the future the lock status (all units interchangeable) should
204 // be set deterministically. For now a custom lock property is used to preserve the
205 // locked flag state.
206 if( aSymbol->UnitsLocked() )
207 {
208 LIB_FIELD locked( nextFreeFieldId, "ki_locked" );
209 saveField( &locked, aFormatter, aNestLevel + 1 );
210 nextFreeFieldId += 1;
211 }
212
213 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
214
215 // Save the draw items grouped by units.
216 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
217 std::sort( units.begin(), units.end(),
218 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
219 {
220 if( a.m_unit == b.m_unit )
221 return a.m_convert < b.m_convert;
222
223 return a.m_unit < b.m_unit;
224 } );
225
226 for( const LIB_SYMBOL_UNIT& unit : units )
227 {
228 // Add quotes and escape chars like ") to the UTF8 unitName string
229 name = aFormatter.Quotes( unitName );
230 name.pop_back(); // Remove last char: the quote ending the string.
231
232 aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
233 name.c_str(), unit.m_unit, unit.m_convert );
234
235 // if the unit has a display name, write that
236 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
237 {
238 name = aSymbol->GetUnitDisplayName( unit.m_unit );
239 aFormatter.Print( aNestLevel + 2, "(unit_name %s)\n",
240 aFormatter.Quotes( name ).c_str() );
241 }
242 // Enforce item ordering
243 auto cmp =
244 []( const LIB_ITEM* a, const LIB_ITEM* b )
245 {
246 return *a < *b;
247 };
248
249 std::multiset<LIB_ITEM*, decltype( cmp )> save_map( cmp );
250
251 for( LIB_ITEM* item : unit.m_items )
252 save_map.insert( item );
253
254 for( LIB_ITEM* item : save_map )
255 saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
256
257 aFormatter.Print( aNestLevel + 1, ")\n" );
258 }
259 }
260 else
261 {
262 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
263
264 wxASSERT( parent );
265
266 aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
267 name.c_str(),
268 aFormatter.Quotew( parent->GetName() ).c_str() );
269
270 aSymbol->GetFields( fields );
271
272 for( LIB_FIELD* field : fields )
273 saveField( field, aFormatter, aNestLevel + 1 );
274
275 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
276
277 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
278 }
279
280 aFormatter.Print( aNestLevel, ")\n" );
281}
282
283
285 int& aNextFreeFieldId, int aNestLevel )
286{
287 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
288
289 if( !aSymbol->GetKeyWords().IsEmpty() )
290 {
291 LIB_FIELD keywords( aNextFreeFieldId, wxString( "ki_keywords" ) );
292 keywords.SetVisible( false );
293 keywords.SetText( aSymbol->GetKeyWords() );
294 saveField( &keywords, aFormatter, aNestLevel + 1 );
295 aNextFreeFieldId += 1;
296 }
297
298 wxArrayString fpFilters = aSymbol->GetFPFilters();
299
300 if( !fpFilters.IsEmpty() )
301 {
302 wxString tmp;
303
304 for( const wxString& filter : fpFilters )
305 {
306 // Spaces are not handled in fp filter names so escape spaces if any
307 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
308
309 if( tmp.IsEmpty() )
310 tmp = curr_filter;
311 else
312 tmp += " " + curr_filter;
313 }
314
315 LIB_FIELD description( aNextFreeFieldId, wxString( "ki_fp_filters" ) );
316 description.SetVisible( false );
317 description.SetText( tmp );
318 saveField( &description, aFormatter, aNestLevel + 1 );
319 aNextFreeFieldId += 1;
320 }
321}
322
323
325 int aNestLevel )
326{
327 wxCHECK_RET( aItem, "Invalid LIB_ITEM pointer." );
328
329 switch( aItem->Type() )
330 {
331 case LIB_SHAPE_T:
332 {
333 LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( aItem );
334 STROKE_PARAMS stroke = shape->GetStroke();
335 FILL_T fillMode = shape->GetFillMode();
336 COLOR4D fillColor = shape->GetFillColor();
337 bool isPrivate = shape->IsPrivate();
338
339 switch( shape->GetShape() )
340 {
341 case SHAPE_T::ARC:
342 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
343 break;
344
345 case SHAPE_T::CIRCLE:
346 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
347 break;
348
349 case SHAPE_T::RECTANGLE:
350 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
351 break;
352
353 case SHAPE_T::BEZIER:
354 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
355 break;
356
357 case SHAPE_T::POLY:
358 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
359 break;
360
361 default:
363 }
364
365 break;
366 }
367
368 case LIB_PIN_T:
369 savePin( static_cast<LIB_PIN*>( aItem ), aFormatter, aNestLevel );
370 break;
371
372 case LIB_TEXT_T:
373 saveText( static_cast<LIB_TEXT*>( aItem ), aFormatter, aNestLevel );
374 break;
375
376 case LIB_TEXTBOX_T:
377 saveTextBox( static_cast<LIB_TEXTBOX*>( aItem ), aFormatter, aNestLevel );
378 break;
379
380 default:
381 UNIMPLEMENTED_FOR( aItem->GetClass() );
382 }
383}
384
385
387 int aNestLevel )
388{
389 wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
390
391 wxString fieldName = aField->GetName();
392
393 if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
394 fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
395
396 aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
397 aFormatter.Quotew( fieldName ).c_str(),
398 aFormatter.Quotew( aField->GetText() ).c_str(),
401 aField->GetTextAngle().AsDegrees() );
402
403 if( aField->IsNameShown() )
404 aFormatter.Print( 0, " (show_name)" );
405
406 if( !aField->CanAutoplace() )
407 aFormatter.Print( 0, " (do_not_autoplace)" );
408
409 aFormatter.Print( 0, "\n" );
410 aField->Format( &aFormatter, aNestLevel, 0 );
411 aFormatter.Print( aNestLevel, ")\n" );
412}
413
414
415void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel )
416{
417 wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
418
419 aPin->ClearFlags( IS_CHANGED );
420
421 aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
423 getPinShapeToken( aPin->GetShape() ),
428
429 if( !aPin->IsVisible() )
430 aFormatter.Print( 0, " hide\n" );
431 else
432 aFormatter.Print( 0, "\n" );
433
434 // This follows the EDA_TEXT effects formatting for future expansion.
435 aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
436 aFormatter.Quotew( aPin->GetName() ).c_str(),
439
440 aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
441 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
444
445
446 for( const std::pair<const wxString, LIB_PIN::ALT>& alt : aPin->GetAlternates() )
447 {
448 aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
449 aFormatter.Quotew( alt.second.m_Name ).c_str(),
450 getPinElectricalTypeToken( alt.second.m_Type ),
451 getPinShapeToken( alt.second.m_Shape ) );
452 }
453
454 aFormatter.Print( aNestLevel, ")\n" );
455}
456
457
459 int aNestLevel )
460{
461 wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
462
463 aFormatter.Print( aNestLevel, "(text%s %s (at %s %s %g)\n",
464 aText->IsPrivate() ? " private" : "",
465 aFormatter.Quotew( aText->GetText() ).c_str(),
468 (double) aText->GetTextAngle().AsTenthsOfADegree() );
469
470 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
471 aFormatter.Print( aNestLevel, ")\n" );
472}
473
474
476 int aNestLevel )
477{
478 wxCHECK_RET( aTextBox && aTextBox->Type() == LIB_TEXTBOX_T, "Invalid LIB_TEXTBOX object." );
479
480 aFormatter.Print( aNestLevel, "(text_box%s %s\n",
481 aTextBox->IsPrivate() ? " private" : "",
482 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
483
484 VECTOR2I pos = aTextBox->GetStart();
485 VECTOR2I size = aTextBox->GetEnd() - pos;
486
487 aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
490 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
493
494 aTextBox->GetStroke().Format( &aFormatter, schIUScale, aNestLevel + 1 );
495 aFormatter.Print( 0, "\n" );
496
497 formatFill( &aFormatter, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
498 aFormatter.Print( 0, "\n" );
499
500 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
501 aFormatter.Print( aNestLevel, ")\n" );
502}
503
504
505void SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
506{
507 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
508
509 if( it == m_symbols.end() )
510 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
511 m_libFileName.GetFullName(), aSymbolName ) );
512
513 LIB_SYMBOL* symbol = it->second;
514
515 if( symbol->IsRoot() )
516 {
517 LIB_SYMBOL* rootSymbol = symbol;
518
519 // Remove the root symbol and all its children.
520 m_symbols.erase( it );
521
522 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
523
524 while( it1 != m_symbols.end() )
525 {
526 if( it1->second->IsAlias()
527 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
528 {
529 delete it1->second;
530 it1 = m_symbols.erase( it1 );
531 }
532 else
533 {
534 it1++;
535 }
536 }
537
538 delete rootSymbol;
539 }
540 else
541 {
542 // Just remove the alias.
543 m_symbols.erase( it );
544 delete symbol;
545 }
546
547 ++m_modHash;
548 m_isModified = true;
549}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
int AsTenthsOfADegree() const
Definition: eda_angle.h:151
double AsDegrees() const
Definition: eda_angle.h:149
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:125
virtual wxString GetClass() const =0
Return the class name.
FILL_T GetFillMode() const
Definition: eda_shape.h:102
SHAPE_T GetShape() const
Definition: eda_shape.h:117
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:149
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:124
COLOR4D GetFillColor() const
Definition: eda_shape.h:106
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:87
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:836
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:226
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:180
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
Field object used in symbol libraries.
Definition: lib_field.h:62
bool CanAutoplace() const
Definition: lib_field.h:195
VECTOR2I GetPosition() const override
Definition: lib_field.h:172
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:489
bool IsNameShown() const
Definition: lib_field.h:192
int GetId() const
Definition: lib_field.h:120
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
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
bool IsPrivate() const
Definition: lib_item.h:313
int GetLength() const
Definition: lib_pin.h:74
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:84
PIN_ORIENTATION GetOrientation() const
Definition: lib_pin.h:68
int GetNumberTextSize() const
Definition: lib_pin.h:135
VECTOR2I GetPosition() const override
Definition: lib_pin.h:232
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:142
const wxString & GetNumber() const
Definition: lib_pin.h:117
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:71
bool IsVisible() const
Definition: lib_pin.h:97
const wxString & GetName() const
Definition: lib_pin.h:106
int GetNameTextSize() const
Definition: lib_pin.h:128
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
Define a library symbol object.
Definition: lib_symbol.h:99
int GetPinNameOffset() const
Definition: lib_symbol.h:661
wxString GetKeyWords() const
Definition: lib_symbol.h:191
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:285
int GetNextAvailableFieldId() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:214
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:561
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of LIB_ITEM objects separated by unit and convert number.
bool IsPower() const
Definition: lib_symbol.cpp:714
bool ShowPinNames() const
Definition: lib_symbol.h:669
LIB_ID GetLibId() const override
Definition: lib_symbol.h:163
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:226
bool GetExcludedFromBOM() const
Definition: lib_symbol.h:693
bool GetExcludedFromSim() const
Definition: lib_symbol.h:685
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:555
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:110
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:127
bool ShowPinNumbers() const
Definition: lib_symbol.h:677
bool GetExcludedFromBoard() const
Definition: lib_symbol.h:701
Define a symbol library graphical text item.
Definition: lib_text.h:40
VECTOR2I GetPosition() const override
Definition: lib_text.h:98
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 Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:475
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
A base cache assistant implementation for the symbol library portion of the SCH_PLUGIN API.
wxFileName GetRealFile() const
Object to parser s-expression symbol library and schematic file formats.
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
int GetParsedRequiredVersion() const
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)
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.
Definition: stroke_params.h:81
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
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:38
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:142
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:134
#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.
EDA_ANGLE getPinAngle(PIN_ORIENTATION aOrientation)
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
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
Definition: base_units.h:94
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 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
wxLogTrace helper definitions.
@ LIB_TEXT_T
Definition: typeinfo.h:199
@ LIB_TEXTBOX_T
Definition: typeinfo.h:200
@ LIB_SHAPE_T
Definition: typeinfo.h:198
@ LIB_PIN_T
Definition: typeinfo.h:201
@ LIB_FIELD_T
Definition: typeinfo.h:207