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 <lib_shape.h>
26#include <lib_symbol.h>
27#include <lib_text.h>
28#include <lib_textbox.h>
29#include <locale_io.h>
30#include <macros.h>
31#include <richio.h>
35#include <string_utils.h>
36#include <trace_helpers.h>
37
38
39SCH_IO_KICAD_SEXPR_LIB_CACHE::SCH_IO_KICAD_SEXPR_LIB_CACHE( const wxString& aFullPathAndFileName ) :
40 SCH_IO_LIB_CACHE( aFullPathAndFileName )
41{
43}
44
45
47{
48}
49
50
52{
53 if( !m_libFileName.FileExists() )
54 {
55 THROW_IO_ERROR( wxString::Format( _( "Library file '%s' not found." ),
56 m_libFileName.GetFullPath() ) );
57 }
58
59 wxCHECK_RET( m_libFileName.IsAbsolute(),
60 wxString::Format( "Cannot use relative file paths in sexpr plugin to "
61 "open library '%s'.", m_libFileName.GetFullPath() ) );
62
63 // The current locale must use period as the decimal point.
64 // Yes, we did this earlier, but it's sadly not thread-safe.
65 LOCALE_IO toggle;
66
67 wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library file '%s'",
68 m_libFileName.GetFullPath() );
69
70 FILE_LINE_READER reader( m_libFileName.GetFullPath() );
71
72 SCH_IO_KICAD_SEXPR_PARSER parser( &reader );
73
74 parser.ParseLib( m_symbols );
76
77 // Remember the file modification time of library file when the cache snapshot was made,
78 // so that in a networked environment we will reload the cache as needed.
81}
82
83
84void SCH_IO_KICAD_SEXPR_LIB_CACHE::Save( const std::optional<bool>& aOpt )
85{
86 if( !m_isModified )
87 return;
88
89 LOCALE_IO toggle; // toggles on, then off, the C locale.
90
91 // Write through symlinks, don't replace them.
92 wxFileName fn = GetRealFile();
93
94 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
95
96 formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
97 "(generator_version \"%s\")\n",
99
100 std::vector<LIB_SYMBOL*> orderedSymbols;
101
102 for( const auto& [ name, symbol ] : m_symbols )
103 {
104 if( symbol )
105 orderedSymbols.push_back( symbol );
106 }
107
108 // Library must be ordered by inheritance depth.
109 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
110 []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
111 {
112 unsigned int lhDepth = aLhs->GetInheritanceDepth();
113 unsigned int rhDepth = aRhs->GetInheritanceDepth();
114
115 if( lhDepth == rhDepth )
116 return aLhs->GetName() < aRhs->GetName();
117
118 return lhDepth < rhDepth;
119 } );
120
121 for( LIB_SYMBOL* symbol : orderedSymbols )
122 SaveSymbol( symbol, *formatter.get(), 1 );
123
124 formatter->Print( 0, ")\n" );
125
126 formatter.reset();
127
128 m_fileModTime = fn.GetModificationTime();
129 m_isModified = false;
130}
131
132
134 int aNestLevel, const wxString& aLibName )
135{
136 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
137
138 // The current locale must use period as the decimal point.
139 wxCHECK2( wxLocale::GetInfo( wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER ) == ".",
140 LOCALE_IO toggle );
141
142 int nextFreeFieldId = MANDATORY_FIELDS;
143 std::vector<LIB_FIELD*> fields;
144 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
145 std::string unitName = aSymbol->GetLibId().GetLibItemName();
146
147 if( !aLibName.IsEmpty() )
148 {
149 name = aFormatter.Quotew( aLibName );
150
151 LIB_ID unitId;
152
153 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
154
155 unitName = unitId.GetLibItemName();
156 }
157
158 if( aSymbol->IsRoot() )
159 {
160 aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
161
162 if( aSymbol->IsPower() )
163 aFormatter.Print( 0, " (power)" );
164
165 // TODO: add uuid token here.
166
167 // TODO: add anchor position token here.
168
169 if( !aSymbol->GetShowPinNumbers() )
170 aFormatter.Print( 0, " (pin_numbers hide)" );
171
173 || !aSymbol->GetShowPinNames() )
174 {
175 aFormatter.Print( 0, " (pin_names" );
176
178 aFormatter.Print( 0, " (offset %s)",
180 aSymbol->GetPinNameOffset() ).c_str() );
181
182 if( !aSymbol->GetShowPinNames() )
183 aFormatter.Print( 0, " hide" );
184
185 aFormatter.Print( 0, ")" );
186 }
187
188 aFormatter.Print( 0, " (exclude_from_sim %s)",
189 ( aSymbol->GetExcludedFromSim() ) ? "yes" : "no" );
190 aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetExcludedFromBOM() ) ? "no" : "yes" );
191 aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetExcludedFromBoard() ) ? "no" : "yes" );
192
193 // TODO: add atomic token here.
194
195 // TODO: add required token here."
196
197 aFormatter.Print( 0, "\n" );
198
199 aSymbol->GetFields( fields );
200
201 for( LIB_FIELD* field : fields )
202 saveField( field, aFormatter, aNestLevel + 1 );
203
204 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
205
206 // @todo At some point in the future the lock status (all units interchangeable) should
207 // be set deterministically. For now a custom lock property is used to preserve the
208 // locked flag state.
209 if( aSymbol->UnitsLocked() )
210 {
211 LIB_FIELD locked( nextFreeFieldId, "ki_locked" );
212 saveField( &locked, aFormatter, aNestLevel + 1 );
213 nextFreeFieldId += 1;
214 }
215
216 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
217
218 // Save the draw items grouped by units.
219 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
220 std::sort( units.begin(), units.end(),
221 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
222 {
223 if( a.m_unit == b.m_unit )
224 return a.m_bodyStyle < b.m_bodyStyle;
225
226 return a.m_unit < b.m_unit;
227 } );
228
229 for( const LIB_SYMBOL_UNIT& unit : units )
230 {
231 // Add quotes and escape chars like ") to the UTF8 unitName string
232 name = aFormatter.Quotes( unitName );
233 name.pop_back(); // Remove last char: the quote ending the string.
234
235 aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
236 name.c_str(),
237 unit.m_unit,
238 unit.m_bodyStyle );
239
240 // if the unit has a display name, write that
241 if( aSymbol->HasUnitDisplayName( unit.m_unit ) )
242 {
243 name = aSymbol->GetUnitDisplayName( unit.m_unit );
244 aFormatter.Print( aNestLevel + 2, "(unit_name %s)\n",
245 aFormatter.Quotes( name ).c_str() );
246 }
247 // Enforce item ordering
248 auto cmp =
249 []( const SCH_ITEM* a, const SCH_ITEM* b )
250 {
251 return *a < *b;
252 };
253
254 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
255
256 for( SCH_ITEM* item : unit.m_items )
257 save_map.insert( item );
258
259 for( SCH_ITEM* item : save_map )
260 saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
261
262 aFormatter.Print( aNestLevel + 1, ")\n" );
263 }
264 }
265 else
266 {
267 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
268
269 wxASSERT( parent );
270
271 aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
272 name.c_str(),
273 aFormatter.Quotew( parent->GetName() ).c_str() );
274
275 aSymbol->GetFields( fields );
276
277 for( LIB_FIELD* field : fields )
278 saveField( field, aFormatter, aNestLevel + 1 );
279
280 nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
281
282 saveDcmInfoAsFields( aSymbol, aFormatter, nextFreeFieldId, aNestLevel );
283 }
284
285 aFormatter.Print( aNestLevel, ")\n" );
286}
287
288
290 OUTPUTFORMATTER& aFormatter,
291 int& aNextFreeFieldId, int aNestLevel )
292{
293 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
294
295 if( !aSymbol->GetKeyWords().IsEmpty() )
296 {
297 LIB_FIELD keywords( aNextFreeFieldId, wxString( "ki_keywords" ) );
298 keywords.SetVisible( false );
299 keywords.SetText( aSymbol->GetKeyWords() );
300 saveField( &keywords, 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 SCH_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::RECTANGLE:
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 = GetCanonicalFieldName( aField->GetId() );
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(),
406 aField->GetPosition().x ).c_str(),
408 aField->GetPosition().y ).c_str(),
409 aField->GetTextAngle().AsDegrees() );
410
411 if( aField->IsNameShown() )
412 aFormatter.Print( 0, " (show_name)" );
413
414 if( !aField->CanAutoplace() )
415 aFormatter.Print( 0, " (do_not_autoplace)" );
416
417 aFormatter.Print( 0, "\n" );
418 aField->Format( &aFormatter, aNestLevel, 0 );
419 aFormatter.Print( aNestLevel, ")\n" );
420}
421
422
424 int aNestLevel )
425{
426 wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
427
428 aPin->ClearFlags( IS_CHANGED );
429
430 aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
432 getPinShapeToken( aPin->GetShape() ),
434 aPin->GetPosition().x ).c_str(),
436 aPin->GetPosition().y ).c_str(),
439 aPin->GetLength() ).c_str() );
440
441 if( !aPin->IsVisible() )
442 aFormatter.Print( 0, " hide\n" );
443 else
444 aFormatter.Print( 0, "\n" );
445
446 // This follows the EDA_TEXT effects formatting for future expansion.
447 aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
448 aFormatter.Quotew( aPin->GetName() ).c_str(),
450 aPin->GetNameTextSize() ).c_str(),
452 aPin->GetNameTextSize() ).c_str() );
453
454 aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
455 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
457 aPin->GetNumberTextSize() ).c_str(),
459 aPin->GetNumberTextSize() ).c_str() );
460
461
462 for( const std::pair<const wxString, LIB_PIN::ALT>& alt : aPin->GetAlternates() )
463 {
464 aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
465 aFormatter.Quotew( alt.second.m_Name ).c_str(),
466 getPinElectricalTypeToken( alt.second.m_Type ),
467 getPinShapeToken( alt.second.m_Shape ) );
468 }
469
470 aFormatter.Print( aNestLevel, ")\n" );
471}
472
473
475 int aNestLevel )
476{
477 wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
478
479 aFormatter.Print( aNestLevel, "(text%s %s (at %s %s %g)\n",
480 aText->IsPrivate() ? " private" : "",
481 aFormatter.Quotew( aText->GetText() ).c_str(),
483 aText->GetPosition().x ).c_str(),
485 aText->GetPosition().y ).c_str(),
486 (double) aText->GetTextAngle().AsTenthsOfADegree() );
487
488 aText->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
489 aFormatter.Print( aNestLevel, ")\n" );
490}
491
492
494 int aNestLevel )
495{
496 wxCHECK_RET( aTextBox && aTextBox->Type() == LIB_TEXTBOX_T, "Invalid LIB_TEXTBOX object." );
497
498 aFormatter.Print( aNestLevel, "(text_box%s %s\n",
499 aTextBox->IsPrivate() ? " private" : "",
500 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
501
502 VECTOR2I pos = aTextBox->GetStart();
503 VECTOR2I size = aTextBox->GetEnd() - pos;
504
505 aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s) (margins %s %s %s %s)\n",
508 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
515
516 aTextBox->GetStroke().Format( &aFormatter, schIUScale, aNestLevel + 1 );
517 aFormatter.Print( 0, "\n" );
518
519 formatFill( &aFormatter, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
520 aFormatter.Print( 0, "\n" );
521
522 aTextBox->EDA_TEXT::Format( &aFormatter, aNestLevel, 0 );
523 aFormatter.Print( aNestLevel, ")\n" );
524}
525
526
527void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
528{
529 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
530
531 if( it == m_symbols.end() )
532 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
533 m_libFileName.GetFullName(), aSymbolName ) );
534
535 LIB_SYMBOL* symbol = it->second;
536
537 if( symbol->IsRoot() )
538 {
539 LIB_SYMBOL* rootSymbol = symbol;
540
541 // Remove the root symbol and all its children.
542 m_symbols.erase( it );
543
544 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
545
546 while( it1 != m_symbols.end() )
547 {
548 if( it1->second->IsAlias()
549 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
550 {
551 delete it1->second;
552 it1 = m_symbols.erase( it1 );
553 }
554 else
555 {
556 it1++;
557 }
558 }
559
560 delete rootSymbol;
561 }
562 else
563 {
564 // Just remove the alias.
565 m_symbols.erase( it );
566 delete symbol;
567 }
568
570 m_isModified = true;
571}
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:157
double AsDegrees() const
Definition: eda_angle.h:155
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:102
SHAPE_T GetShape() const
Definition: eda_shape.h:120
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:152
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:127
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: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:913
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:245
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
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:199
VECTOR2I GetPosition() const override
Definition: lib_field.h:173
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:502
bool IsNameShown() const
Definition: lib_field.h:196
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
int GetLength() const
Definition: lib_pin.h:82
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:92
PIN_ORIENTATION GetOrientation() const
Definition: lib_pin.h:76
int GetNumberTextSize() const
Definition: lib_pin.h:143
VECTOR2I GetPosition() const override
Definition: lib_pin.h:209
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:150
const wxString & GetNumber() const
Definition: lib_pin.h:125
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:79
bool IsVisible() const
Definition: lib_pin.h:105
const wxString & GetName() const
Definition: lib_pin.h:114
int GetNameTextSize() const
Definition: lib_pin.h:136
STROKE_PARAMS GetStroke() const override
Definition: lib_shape.h:57
Define a library symbol object.
Definition: lib_symbol.h:79
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:144
wxString GetKeyWords() const override
Definition: lib_symbol.h:172
bool IsPower() const override
Definition: lib_symbol.cpp:654
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:265
int GetNextAvailableFieldId() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:195
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:524
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of SCH_ITEM objects separated by unit and convert number.
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:207
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:518
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:90
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:107
int GetMarginTop() const
Definition: lib_textbox.h:62
int GetMarginBottom() const
Definition: lib_textbox.h:64
int GetMarginRight() const
Definition: lib_textbox.h:63
int GetMarginLeft() const
Definition: lib_textbox.h:61
Define a symbol library graphical text item.
Definition: lib_text.h:40
VECTOR2I GetPosition() const override
Definition: lib_text.h:96
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
SCH_IO_KICAD_SEXPR_LIB_CACHE(const wxString &aLibraryPath)
static void saveTextBox(LIB_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel)
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 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(LIB_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:172
bool IsPrivate() const
Definition: sch_item.h:241
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:182
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:153
bool GetShowPinNames() const
Definition: symbol.h:129
bool GetExcludedFromBOM() const
Definition: symbol.h:147
int GetPinNameOffset() const
Definition: symbol.h:123
bool GetShowPinNumbers() const
Definition: symbol.h:135
bool GetExcludedFromSim() const override
Definition: symbol.h:141
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 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: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.
@ LIB_TEXT_T
Definition: typeinfo.h:204
@ LIB_TEXTBOX_T
Definition: typeinfo.h:205
@ LIB_SHAPE_T
Definition: typeinfo.h:203
@ LIB_PIN_T
Definition: typeinfo.h:206
@ LIB_FIELD_T
Definition: typeinfo.h:212