KiCad PCB EDA Suite
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 <base_units.h>
23#include <lib_field.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 for( const std::pair<const wxString, LIB_SYMBOL*>& parent : m_symbols )
99 {
100 // Save the root symbol first so alias can inherit from them.
101 if( parent.second->IsRoot() )
102 {
103 SaveSymbol( parent.second, *formatter.get(), 1 );
104
105 // Save all of the aliases associated with the current root symbol.
106 for( const std::pair<const wxString, LIB_SYMBOL*>& alias : m_symbols )
107 {
108 if( !alias.second->IsAlias() )
109 continue;
110
111 std::shared_ptr<LIB_SYMBOL> aliasParent = alias.second->GetParent().lock();
112
113 if( aliasParent.get() != parent.second )
114 continue;
115
116 SaveSymbol( alias.second, *formatter.get(), 1 );
117 }
118 }
119 }
120
121 formatter->Print( 0, ")\n" );
122
123 formatter.reset();
124
125 m_fileModTime = fn.GetModificationTime();
126 m_isModified = false;
127}
128
129
131 int aNestLevel, const wxString& aLibName )
132{
133 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
134
135 // The current locale must use period as the decimal point.
136 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) == ".",
137 LOCALE_IO toggle );
138
139 int nextFreeFieldId = MANDATORY_FIELDS;
140 std::vector<LIB_FIELD*> fields;
141 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
142 std::string unitName = aSymbol->GetLibId().GetLibItemName();
143
144 if( !aLibName.IsEmpty() )
145 {
146 name = aFormatter.Quotew( aLibName );
147
148 LIB_ID unitId;
149
150 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
151
152 unitName = unitId.GetLibItemName();
153 }
154
155 if( aSymbol->IsRoot() )
156 {
157 aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
158
159 if( aSymbol->IsPower() )
160 aFormatter.Print( 0, " (power)" );
161
162 // TODO: add uuid token here.
163
164 // TODO: add anchor position token here.
165
166 if( !aSymbol->ShowPinNumbers() )
167 aFormatter.Print( 0, " (pin_numbers hide)" );
168
170 || !aSymbol->ShowPinNames() )
171 {
172 aFormatter.Print( 0, " (pin_names" );
173
175 aFormatter.Print( 0, " (offset %s)",
177
178 if( !aSymbol->ShowPinNames() )
179 aFormatter.Print( 0, " hide" );
180
181 aFormatter.Print( 0, ")" );
182 }
183
184 aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
185 aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
186
187 // TODO: add atomic token here.
188
189 // TODO: add required token here."
190
191 aFormatter.Print( 0, "\n" );
192
193 aSymbol->GetFields( fields );
194
195 for( LIB_FIELD* field : fields )
196 saveField( field, aFormatter, aNestLevel + 1 );
197
198 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
199
200 // @todo At some point in the future the lock status (all units interchangeable) should
201 // be set deterministically. For now a custom lock property is used to preserve the
202 // locked flag state.
203 if( aSymbol->UnitsLocked() )
204 {
205 LIB_FIELD locked( nextFreeFieldId, "ki_locked" );
206 saveField( &locked, aFormatter, aNestLevel + 1 );
207 nextFreeFieldId += 1;
208 }
209
210 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
211
212 // Save the draw items grouped by units.
213 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
214 std::sort( units.begin(), units.end(),
215 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
216 {
217 if( a.m_unit == b.m_unit )
218 return a.m_convert < b.m_convert;
219
220 return a.m_unit < b.m_unit;
221 } );
222
223 for( const LIB_SYMBOL_UNIT& unit : units )
224 {
225 // Add quotes and escape chars like ") to the UTF8 unitName string
226 name = aFormatter.Quotes( unitName );
227 name.pop_back(); // Remove last char: the quote ending the string.
228
229 aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
230 name.c_str(), unit.m_unit, unit.m_convert );
231
232 // if the unit has a display name, write that
233 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
234 {
235 name = aSymbol->GetUnitDisplayName( unit.m_unit );
236 aFormatter.Print( aNestLevel + 2, "(unit_name %s)\n",
237 aFormatter.Quotes( name ).c_str() );
238 }
239 // Enforce item ordering
240 auto cmp =
241 []( const LIB_ITEM* a, const LIB_ITEM* b )
242 {
243 return *a < *b;
244 };
245
246 std::multiset<LIB_ITEM*, decltype( cmp )> save_map( cmp );
247
248 for( LIB_ITEM* item : unit.m_items )
249 save_map.insert( item );
250
251 for( LIB_ITEM* item : save_map )
252 saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
253
254 aFormatter.Print( aNestLevel + 1, ")\n" );
255 }
256 }
257 else
258 {
259 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
260
261 wxASSERT( parent );
262
263 aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
264 name.c_str(),
265 aFormatter.Quotew( parent->GetName() ).c_str() );
266
267 aSymbol->GetFields( fields );
268
269 for( LIB_FIELD* field : fields )
270 saveField( field, aFormatter, aNestLevel + 1 );
271
272 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
273
274 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
275 }
276
277 aFormatter.Print( aNestLevel, ")\n" );
278}
279
280
282 int& aNextFreeFieldId, int aNestLevel )
283{
284 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
285
286 if( !aSymbol->GetKeyWords().IsEmpty() )
287 {
288 LIB_FIELD keywords( aNextFreeFieldId, wxString( "ki_keywords" ) );
289 keywords.SetVisible( false );
290 keywords.SetText( aSymbol->GetKeyWords() );
291 saveField( &keywords, aFormatter, aNestLevel + 1 );
292 aNextFreeFieldId += 1;
293 }
294
295 if( !aSymbol->GetDescription().IsEmpty() )
296 {
297 LIB_FIELD description( aNextFreeFieldId, wxString( "ki_description" ) );
298 description.SetVisible( false );
299 description.SetText( aSymbol->GetDescription() );
300 saveField( &description, aFormatter, aNestLevel + 1 );
301 aNextFreeFieldId += 1;
302 }
303
304 wxArrayString fpFilters = aSymbol->GetFPFilters();
305
306 if( !fpFilters.IsEmpty() )
307 {
308 wxString tmp;
309
310 for( const wxString& filter : fpFilters )
311 {
312 // Spaces are not handled in fp filter names so escape spaces if any
313 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
314
315 if( tmp.IsEmpty() )
316 tmp = curr_filter;
317 else
318 tmp += " " + curr_filter;
319 }
320
321 LIB_FIELD description( aNextFreeFieldId, wxString( "ki_fp_filters" ) );
322 description.SetVisible( false );
323 description.SetText( tmp );
324 saveField( &description, aFormatter, aNestLevel + 1 );
325 aNextFreeFieldId += 1;
326 }
327}
328
329
331 int aNestLevel )
332{
333 wxCHECK_RET( aItem, "Invalid LIB_ITEM pointer." );
334
335 switch( aItem->Type() )
336 {
337 case LIB_SHAPE_T:
338 {
339 LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( aItem );
340 STROKE_PARAMS stroke = shape->GetStroke();
341 FILL_T fillMode = shape->GetFillMode();
342 COLOR4D fillColor = shape->GetFillColor();
343 bool isPrivate = shape->IsPrivate();
344
345 switch( shape->GetShape() )
346 {
347 case SHAPE_T::ARC:
348 formatArc( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
349 break;
350
351 case SHAPE_T::CIRCLE:
352 formatCircle( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
353 break;
354
355 case SHAPE_T::RECT:
356 formatRect( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
357 break;
358
359 case SHAPE_T::BEZIER:
360 formatBezier(&aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
361 break;
362
363 case SHAPE_T::POLY:
364 formatPoly( &aFormatter, aNestLevel, shape, isPrivate, stroke, fillMode, fillColor );
365 break;
366
367 default:
369 }
370
371 break;
372 }
373
374 case LIB_PIN_T:
375 savePin( static_cast<LIB_PIN*>( aItem ), aFormatter, aNestLevel );
376 break;
377
378 case LIB_TEXT_T:
379 saveText( static_cast<LIB_TEXT*>( aItem ), aFormatter, aNestLevel );
380 break;
381
382 case LIB_TEXTBOX_T:
383 saveTextBox( static_cast<LIB_TEXTBOX*>( aItem ), aFormatter, aNestLevel );
384 break;
385
386 default:
387 UNIMPLEMENTED_FOR( aItem->GetClass() );
388 }
389}
390
391
393 int aNestLevel )
394{
395 wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
396
397 wxString fieldName = aField->GetName();
398
399 if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
400 fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
401
402 aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
403 aFormatter.Quotew( fieldName ).c_str(),
404 aFormatter.Quotew( aField->GetText() ).c_str(),
407 aField->GetTextAngle().AsDegrees() );
408
409 if( aField->IsNameShown() )
410 aFormatter.Print( 0, " (show_name)" );
411
412 if( !aField->CanAutoplace() )
413 aFormatter.Print( 0, " (do_not_autoplace)" );
414
415 aFormatter.Print( 0, "\n" );
416 aField->Format( &aFormatter, aNestLevel, 0 );
417 aFormatter.Print( aNestLevel, ")\n" );
418}
419
420
421void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel )
422{
423 wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
424
425 aPin->ClearFlags( IS_CHANGED );
426
427 aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
429 getPinShapeToken( aPin->GetShape() ),
434
435 if( !aPin->IsVisible() )
436 aFormatter.Print( 0, " hide\n" );
437 else
438 aFormatter.Print( 0, "\n" );
439
440 // This follows the EDA_TEXT effects formatting for future expansion.
441 aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
442 aFormatter.Quotew( aPin->GetName() ).c_str(),
445
446 aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
447 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
450
451
452 for( const std::pair<const wxString, LIB_PIN::ALT>& alt : aPin->GetAlternates() )
453 {
454 aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
455 aFormatter.Quotew( alt.second.m_Name ).c_str(),
456 getPinElectricalTypeToken( alt.second.m_Type ),
457 getPinShapeToken( alt.second.m_Shape ) );
458 }
459
460 aFormatter.Print( aNestLevel, ")\n" );
461}
462
463
465 int aNestLevel )
466{
467 wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
468
469 aFormatter.Print( aNestLevel, "(text%s %s (at %s %s %g)\n",
470 aText->IsPrivate() ? " private" : "",
471 aFormatter.Quotew( aText->GetText() ).c_str(),
474 (double) aText->GetTextAngle().AsTenthsOfADegree() );
475
476 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
477 aFormatter.Print( aNestLevel, ")\n" );
478}
479
480
482 int aNestLevel )
483{
484 wxCHECK_RET( aTextBox && aTextBox->Type() == LIB_TEXTBOX_T, "Invalid LIB_TEXTBOX object." );
485
486 aFormatter.Print( aNestLevel, "(text_box%s %s\n",
487 aTextBox->IsPrivate() ? " private" : "",
488 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
489
490 VECTOR2I pos = aTextBox->GetStart();
491 VECTOR2I size = aTextBox->GetEnd() - pos;
492
493 aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
496 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
499
500 aTextBox->GetStroke().Format( &aFormatter, schIUScale, aNestLevel + 1 );
501 aFormatter.Print( 0, "\n" );
502
503 formatFill( &aFormatter, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
504 aFormatter.Print( 0, "\n" );
505
506 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
507 aFormatter.Print( aNestLevel, ")\n" );
508}
509
510
511void SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
512{
513 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
514
515 if( it == m_symbols.end() )
516 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
517 m_libFileName.GetFullName(), aSymbolName ) );
518
519 LIB_SYMBOL* symbol = it->second;
520
521 if( symbol->IsRoot() )
522 {
523 LIB_SYMBOL* rootSymbol = symbol;
524
525 // Remove the root symbol and all its children.
526 m_symbols.erase( it );
527
528 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
529
530 while( it1 != m_symbols.end() )
531 {
532 if( it1->second->IsAlias()
533 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
534 {
535 delete it1->second;
536 it1 = m_symbols.erase( it1 );
537 }
538 else
539 {
540 it1++;
541 }
542 }
543
544 delete rootSymbol;
545 }
546 else
547 {
548 // Just remove the alias.
549 m_symbols.erase( it );
550 delete symbol;
551 }
552
553 ++m_modHash;
554 m_isModified = true;
555}
const char * name
Definition: DXF_plotter.cpp:56
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:143
virtual wxString GetClass() const =0
Return the class name.
FILL_T GetFillMode() const
Definition: eda_shape.h:101
SHAPE_T GetShape() const
Definition: eda_shape.h:113
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:75
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:781
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:217
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
A LINE_READER that reads from an open file.
Definition: richio.h:173
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Field object used in symbol libraries.
Definition: lib_field.h:60
bool CanAutoplace() const
Definition: lib_field.h:184
VECTOR2I GetPosition() const override
Definition: lib_field.h:161
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:470
bool IsNameShown() const
Definition: lib_field.h:181
int GetId() const
Definition: lib_field.h:115
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:50
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
bool IsPrivate() const
Definition: lib_item.h:279
int GetLength() const
Definition: lib_pin.h:80
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:90
int GetOrientation() const
Definition: lib_pin.h:74
int GetNumberTextSize() const
Definition: lib_pin.h:135
VECTOR2I GetPosition() const override
Definition: lib_pin.h:222
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:138
const wxString & GetNumber() const
Definition: lib_pin.h:122
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:77
bool IsVisible() const
Definition: lib_pin.h:103
const wxString & GetName() const
Definition: lib_pin.h:112
int GetNameTextSize() const
Definition: lib_pin.h:132
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:52
Define a library symbol object.
Definition: lib_symbol.h:98
int GetPinNameOffset() const
Definition: lib_symbol.h:628
wxString GetKeyWords() const
Definition: lib_symbol.h:159
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:253
int GetNextAvailableFieldId() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:182
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:403
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:552
bool GetIncludeOnBoard() const
Definition: lib_symbol.h:660
bool ShowPinNames() const
Definition: lib_symbol.h:636
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:194
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:397
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:108
bool GetIncludeInBom() const
Definition: lib_symbol.h:652
wxString GetDescription() override
Definition: lib_symbol.h:146
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:125
bool ShowPinNumbers() const
Definition: lib_symbol.h:644
Define a symbol library graphical text item.
Definition: lib_text.h:40
VECTOR2I GetPosition() const override
Definition: lib_text.h:93
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:499
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:460
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:88
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
wxString wx_str() const
Definition: utf8.cpp:46
#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:54
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:120
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:139
std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:131
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
Schematic and symbol library s-expression file format parser definitions.
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
EDA_ANGLE getPinAngle(int aOrientation)
void formatArc(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
const char * getPinElectricalTypeToken(ELECTRICAL_PINTYPE aType)
void formatFill(OUTPUTFORMATTER *aFormatter, int aNestLevel, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
void formatRect(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatBezier(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
const char * getPinShapeToken(GRAPHIC_PINSHAPE aShape)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NO_SPACE
Definition: string_utils.h:62
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 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
wxLogTrace helper definitions.
@ LIB_TEXT_T
Definition: typeinfo.h:200
@ LIB_TEXTBOX_T
Definition: typeinfo.h:201
@ LIB_SHAPE_T
Definition: typeinfo.h:199
@ LIB_PIN_T
Definition: typeinfo.h:202
@ LIB_FIELD_T
Definition: typeinfo.h:208