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 The 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 <fmt/format.h>
23
24#include <wx/log.h>
25#include <wx/dir.h>
26
27#include <base_units.h>
28#include <build_version.h>
29#include <common.h>
30#include <sch_shape.h>
31#include <lib_symbol.h>
32#include <sch_textbox.h>
33#include <macros.h>
34#include <richio.h>
38#include <string_utils.h>
39#include <trace_helpers.h>
41
42
43SCH_IO_KICAD_SEXPR_LIB_CACHE::SCH_IO_KICAD_SEXPR_LIB_CACHE( const wxString& aFullPathAndFileName ) :
44 SCH_IO_LIB_CACHE( aFullPathAndFileName )
45{
47}
48
49
53
54
56{
57 if( !isLibraryPathValid() )
58 {
59 THROW_IO_ERROR( wxString::Format( _( "Library '%s' not found." ), m_libFileName.GetFullPath() ) );
60 }
61
62 wxCHECK_RET( m_libFileName.IsAbsolute(),
63 wxString::Format( "Cannot use relative file paths in sexpr plugin to "
64 "open library '%s'.", m_libFileName.GetFullPath() ) );
65
66 if( !m_libFileName.IsDir() )
67 {
68 wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library file '%s'",
69 m_libFileName.GetFullPath() );
70
71 FILE_LINE_READER reader( m_libFileName.GetFullPath() );
72
73 SCH_IO_KICAD_SEXPR_PARSER parser( &reader );
74
75 parser.ParseLib( m_symbols );
79 }
80 else
81 {
82 wxString libFileName;
83
84 wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library folder '%s'", m_libFileName.GetPath() );
85
86 wxFileName tmp( m_libFileName.GetPath(), wxS( "dummy" ), wxString( FILEEXT::KiCadSymbolLibFileExtension ) );
87 wxDir dir( m_libFileName.GetPath() );
88 wxString fileSpec = wxS( "*." ) + wxString( FILEEXT::KiCadSymbolLibFileExtension );
89
90 if( dir.GetFirst( &libFileName, fileSpec ) )
91 {
92 wxString errorCache;
93
94 do
95 {
96 tmp.SetFullName( libFileName );
97
98 try
99 {
100 FILE_LINE_READER reader( tmp.GetFullPath() );
101 SCH_IO_KICAD_SEXPR_PARSER parser( &reader );
102
103 parser.ParseLib( m_symbols );
105 }
106 catch( const IO_ERROR& ioe )
107 {
108 if( !errorCache.IsEmpty() )
109 errorCache += wxT( "\n\n" );
110
111 errorCache += wxString::Format( _( "Unable to read file '%s'" ) + '\n', tmp.GetFullPath() );
112 errorCache += ioe.What();
113 }
114 } while( dir.GetNext( &libFileName ) );
115
116 if( !errorCache.IsEmpty() )
117 THROW_IO_ERROR( errorCache );
118 }
119
122 }
123
124 // Remember the file modification time of library file when the cache snapshot was made,
125 // so that in a networked environment we will reload the cache as needed.
127}
128
129
130void SCH_IO_KICAD_SEXPR_LIB_CACHE::Save( const std::optional<bool>& aOpt )
131{
132 if( !m_isModified )
133 return;
134
135 // Write through symlinks, don't replace them.
136 wxFileName fn = GetRealFile();
137
138 if( !fn.IsDir() )
139 {
140 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
141
142 formatLibraryHeader( *formatter.get() );
143
144 std::vector<LIB_SYMBOL*> orderedSymbols;
145
146 for( const auto& [ name, symbol ] : m_symbols )
147 {
148 if( symbol )
149 orderedSymbols.push_back( symbol );
150 }
151
152 // Library must be ordered by inheritance depth.
153 std::sort( orderedSymbols.begin(), orderedSymbols.end(),
154 []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
155 {
156 unsigned int lhDepth = aLhs->GetInheritanceDepth();
157 unsigned int rhDepth = aRhs->GetInheritanceDepth();
158
159 if( lhDepth == rhDepth )
160 return aLhs->GetName() < aRhs->GetName();
161
162 return lhDepth < rhDepth;
163 } );
164
165 for( LIB_SYMBOL* symbol : orderedSymbols )
166 SaveSymbol( symbol, *formatter.get() );
167
168 formatter->Print( ")" );
169 formatter.reset();
170 }
171 else
172 {
173 if( !fn.DirExists() )
174 {
175 if( !fn.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
176 THROW_IO_ERROR( wxString::Format( _( "Cannot create symbol library path '%s'." ), fn.GetPath() ) );
177 }
178
179 for( const auto& [ name, symbol ] : m_symbols )
180 {
181 wxFileName saveFn( fn );
182 saveFn.SetName( EscapeString( name, CTX_FILENAME ) );
184
185 auto formatter = std::make_unique<PRETTIFIED_FILE_OUTPUTFORMATTER>( saveFn.GetFullPath() );
186
187 formatLibraryHeader( *formatter.get() );
188
189 SaveSymbol( symbol, *formatter.get() );
190
191 formatter->Print( ")" );
192 formatter.reset();
193 }
194 }
195
197 m_isModified = false;
198}
199
200
202 const wxString& aLibName, bool aIncludeData )
203{
204 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
205
206 // If we've requested to embed the fonts in the symbol, do so.
207 // Otherwise, clear the embedded fonts from the symbol. Embedded
208 // fonts will be used if available
209 if( aSymbol->GetAreFontsEmbedded() )
210 aSymbol->EmbedFonts();
211 else
213
214 std::vector<SCH_FIELD*> orderedFields;
215 std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
216 std::string unitName = aSymbol->GetLibId().GetLibItemName();
217
218 if( !aLibName.IsEmpty() )
219 {
220 name = aFormatter.Quotew( aLibName );
221
222 LIB_ID unitId;
223
224 wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
225
226 unitName = unitId.GetLibItemName();
227 }
228
229 if( aSymbol->IsRoot() )
230 {
231 aFormatter.Print( "(symbol %s", name.c_str() );
232
233 if( aSymbol->IsGlobalPower() )
234 aFormatter.Print( "(power global)" );
235 else if( aSymbol->IsLocalPower() )
236 aFormatter.Print( "(power local)" );
237
238 // TODO: add uuid token here.
239
240 // TODO: add anchor position token here.
241
242 if( aSymbol->IsMultiBodyStyle() )
243 {
244 aFormatter.Print( "(body_styles " );
245
246 if( aSymbol->HasDeMorganBodyStyles() )
247 {
248 aFormatter.Print( "demorgan" );
249 }
250 else
251 {
252 for( const wxString& bodyStyle : aSymbol->GetBodyStyleNames() )
253 aFormatter.Print( "%s ", aFormatter.Quotew( bodyStyle ).c_str() );
254 }
255
256 aFormatter.Print( ")" );
257 }
258
259 if( !aSymbol->GetShowPinNumbers() )
260 aFormatter.Print( "(pin_numbers (hide yes))" );
261
262 if( aSymbol->GetPinNameOffset() != schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET )
263 || !aSymbol->GetShowPinNames() )
264 {
265 aFormatter.Print( "(pin_names" );
266
267 if( aSymbol->GetPinNameOffset() != schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) )
268 {
269 aFormatter.Print( "(offset %s)",
271 aSymbol->GetPinNameOffset() ).c_str() );
272 }
273
274 if( !aSymbol->GetShowPinNames() )
275 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
276
277 aFormatter.Print( ")" );
278 }
279
280 KICAD_FORMAT::FormatBool( &aFormatter, "exclude_from_sim", aSymbol->GetExcludedFromSim() );
281 KICAD_FORMAT::FormatBool( &aFormatter, "in_bom", !aSymbol->GetExcludedFromBOM() );
282 KICAD_FORMAT::FormatBool( &aFormatter, "on_board", !aSymbol->GetExcludedFromBoard() );
283
284 KICAD_FORMAT::FormatBool( &aFormatter, "duplicate_pin_numbers_are_jumpers",
286
287 const std::vector<std::set<wxString>>& jumperGroups = aSymbol->JumperPinGroups();
288
289 if( !jumperGroups.empty() )
290 {
291 aFormatter.Print( "(jumper_pin_groups" );
292
293 for( const std::set<wxString>& group : jumperGroups )
294 {
295 aFormatter.Print( "(" );
296
297 for( const wxString& padName : group )
298 aFormatter.Print( "%s ", aFormatter.Quotew( padName ).c_str() );
299
300 aFormatter.Print( ")" );
301 }
302
303 aFormatter.Print( ")" );
304 }
305
306 // TODO: add atomic token here.
307
308 // TODO: add required token here."
309
310 aSymbol->GetFields( orderedFields );
311
312 for( SCH_FIELD* field : orderedFields )
313 saveField( field, aFormatter );
314
315 // @todo At some point in the future the lock status (all units interchangeable) should
316 // be set deterministically. For now a custom lock property is used to preserve the
317 // locked flag state.
318 if( aSymbol->UnitsLocked() )
319 {
320 SCH_FIELD locked( nullptr, FIELD_T::USER, "ki_locked" );
321 saveField( &locked, aFormatter );
322 }
323
324 saveDcmInfoAsFields( aSymbol, aFormatter );
325
326 // Save the draw items grouped by units.
327 std::vector<LIB_SYMBOL_UNIT> units = aSymbol->GetUnitDrawItems();
328 std::sort( units.begin(), units.end(),
329 []( const LIB_SYMBOL_UNIT& a, const LIB_SYMBOL_UNIT& b )
330 {
331 if( a.m_unit == b.m_unit )
332 return a.m_bodyStyle < b.m_bodyStyle;
333
334 return a.m_unit < b.m_unit;
335 } );
336
337 for( const LIB_SYMBOL_UNIT& unit : units )
338 {
339 // Add quotes and escape chars like ") to the UTF8 unitName string
340 name = aFormatter.Quotes( unitName );
341 name.pop_back(); // Remove last char: the quote ending the string.
342
343 aFormatter.Print( "(symbol %s_%d_%d\"",
344 name.c_str(),
345 unit.m_unit,
346 unit.m_bodyStyle );
347
348 // if the unit has a display name, write that
349 if( aSymbol->GetUnitDisplayNames().contains( unit.m_unit ) )
350 {
351 name = aSymbol->GetUnitDisplayNames().at( unit.m_unit );
352 aFormatter.Print( "(unit_name %s)", aFormatter.Quotes( name ).c_str() );
353 }
354
355 // Enforce item ordering
356 auto cmp =
357 []( const SCH_ITEM* a, const SCH_ITEM* b )
358 {
359 return *a < *b;
360 };
361
362 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
363
364 for( SCH_ITEM* item : unit.m_items )
365 save_map.insert( item );
366
367 for( SCH_ITEM* item : save_map )
368 saveSymbolDrawItem( item, aFormatter );
369
370 aFormatter.Print( ")" );
371 }
372
373 KICAD_FORMAT::FormatBool( &aFormatter, "embedded_fonts", aSymbol->GetAreFontsEmbedded() );
374
375 if( !aSymbol->EmbeddedFileMap().empty() )
376 aSymbol->WriteEmbeddedFiles( aFormatter, aIncludeData );
377 }
378 else
379 {
380 std::shared_ptr<LIB_SYMBOL> parent = aSymbol->GetParent().lock();
381
382 wxASSERT( parent );
383
384 aFormatter.Print( "(symbol %s (extends %s)",
385 name.c_str(),
386 aFormatter.Quotew( parent->GetName() ).c_str() );
387
388 aSymbol->GetFields( orderedFields );
389
390 for( SCH_FIELD* field : orderedFields )
391 saveField( field, aFormatter );
392
393 saveDcmInfoAsFields( aSymbol, aFormatter );
394 }
395
396 aFormatter.Print( ")" );
397}
398
399
401 OUTPUTFORMATTER& aFormatter )
402{
403 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
404
405 if( !aSymbol->GetKeyWords().IsEmpty() )
406 {
407 SCH_FIELD keywords( nullptr, FIELD_T::USER, wxString( "ki_keywords" ) );
408 keywords.SetVisible( false );
409 keywords.SetText( aSymbol->GetKeyWords() );
410 saveField( &keywords, aFormatter );
411 }
412
413 wxArrayString fpFilters = aSymbol->GetFPFilters();
414
415 if( !fpFilters.IsEmpty() )
416 {
417 wxString tmp;
418
419 for( const wxString& filter : fpFilters )
420 {
421 // Spaces are not handled in fp filter names so escape spaces if any
422 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
423
424 if( tmp.IsEmpty() )
425 tmp = curr_filter;
426 else
427 tmp += " " + curr_filter;
428 }
429
430 SCH_FIELD description( nullptr, FIELD_T::USER, wxString( "ki_fp_filters" ) );
431 description.SetVisible( false );
432 description.SetText( tmp );
433 saveField( &description, aFormatter );
434 }
435}
436
437
439{
440 wxCHECK_RET( aItem, "Invalid SCH_ITEM pointer." );
441
442 switch( aItem->Type() )
443 {
444 case SCH_SHAPE_T:
445 {
446 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
447 STROKE_PARAMS stroke = shape->GetStroke();
448 FILL_T fillMode = shape->GetFillMode();
449 COLOR4D fillColor = shape->GetFillColor();
450 bool isPrivate = shape->IsPrivate();
451
452 switch( shape->GetShape() )
453 {
454 case SHAPE_T::ARC:
455 formatArc( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
456 break;
457
458 case SHAPE_T::CIRCLE:
459 formatCircle( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
460 break;
461
463 formatRect( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
464 break;
465
466 case SHAPE_T::BEZIER:
467 formatBezier(&aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
468 break;
469
470 case SHAPE_T::POLY:
471 formatPoly( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
472 break;
473
474 default:
476 }
477
478 break;
479 }
480
481 case SCH_PIN_T:
482 savePin( static_cast<SCH_PIN*>( aItem ), aFormatter );
483 break;
484
485 case SCH_TEXT_T:
486 saveText( static_cast<SCH_TEXT*>( aItem ), aFormatter );
487 break;
488
489 case SCH_TEXTBOX_T:
490 saveTextBox( static_cast<SCH_TEXTBOX*>( aItem ), aFormatter );
491 break;
492
493 default:
494 UNIMPLEMENTED_FOR( aItem->GetClass() );
495 }
496}
497
498
500{
501 wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
502
503 wxString fieldName = aField->GetName();
504
505 if( aField->IsMandatory() )
506 fieldName = GetCanonicalFieldName( aField->GetId() );
507
508 aFormatter.Print( "(property %s %s %s (at %s %s %s)",
509 aField->IsPrivate() ? "private" : "",
510 aFormatter.Quotew( fieldName ).c_str(),
511 aFormatter.Quotew( aField->GetText() ).c_str(),
513 aField->GetPosition().x ).c_str(),
515 -aField->GetPosition().y ).c_str(),
516 fmt::format( "{:g}", aField->GetTextAngle().AsDegrees() ).c_str() );
517
518 if( aField->IsNameShown() )
519 aFormatter.Print( "(show_name)" );
520
521 if( !aField->CanAutoplace() )
522 aFormatter.Print( "(do_not_autoplace)" );
523
524 if( !aField->IsVisible() )
525 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
526
527 aField->Format( &aFormatter, 0 );
528 aFormatter.Print( ")" );
529}
530
531
533{
534 wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." );
535
536 aPin->ClearFlags( IS_CHANGED );
537
538 aFormatter.Print( "(pin %s %s (at %s %s %s) (length %s)",
540 getPinShapeToken( aPin->GetShape() ),
542 aPin->GetPosition().x ).c_str(),
544 -aPin->GetPosition().y ).c_str(),
547 aPin->GetLength() ).c_str() );
548
549 if( !aPin->IsVisible() )
550 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
551
552 // This follows the EDA_TEXT effects formatting for future expansion.
553 aFormatter.Print( "(name %s (effects (font (size %s %s))))",
554 aFormatter.Quotew( aPin->GetName() ).c_str(),
556 aPin->GetNameTextSize() ).c_str(),
558 aPin->GetNameTextSize() ).c_str() );
559
560 aFormatter.Print( "(number %s (effects (font (size %s %s))))",
561 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
563 aPin->GetNumberTextSize() ).c_str(),
565 aPin->GetNumberTextSize() ).c_str() );
566
567
568 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->GetAlternates() )
569 {
570 // There was a bug somewhere in the alternate pin code that allowed pin alternates with no
571 // name to be saved in library symbols. This strips any invalid alternates just in case
572 // that code resurfaces.
573 if( alt.second.m_Name.IsEmpty() )
574 continue;
575
576 aFormatter.Print( "(alternate %s %s %s)",
577 aFormatter.Quotew( alt.second.m_Name ).c_str(),
578 getPinElectricalTypeToken( alt.second.m_Type ),
579 getPinShapeToken( alt.second.m_Shape ) );
580 }
581
582 aFormatter.Print( ")" );
583}
584
585
587{
588 wxCHECK_RET( aText && aText->Type() == SCH_TEXT_T, "Invalid SCH_TEXT object." );
589
590 aFormatter.Print( "(text %s %s (at %s %s %d)",
591 aText->IsPrivate() ? "private" : "",
592 aFormatter.Quotew( aText->GetText() ).c_str(),
594 aText->GetPosition().x ).c_str(),
596 -aText->GetPosition().y ).c_str(),
597 aText->GetTextAngle().AsTenthsOfADegree() );
598
599 aText->EDA_TEXT::Format( &aFormatter, 0 );
600 aFormatter.Print( ")" );
601}
602
603
605{
606 wxCHECK_RET( aTextBox && aTextBox->Type() == SCH_TEXTBOX_T, "Invalid SCH_TEXTBOX object." );
607
608 aFormatter.Print( "(text_box %s %s",
609 aTextBox->IsPrivate() ? "private" : "",
610 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
611
612 VECTOR2I pos = aTextBox->GetStart();
613 VECTOR2I size = aTextBox->GetEnd() - pos;
614
615 aFormatter.Print( "(at %s %s %s) (size %s %s) (margins %s %s %s %s)",
618 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
625
626 aTextBox->GetStroke().Format( &aFormatter, schIUScale );
627 formatFill( &aFormatter, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
628 aTextBox->EDA_TEXT::Format( &aFormatter, 0 );
629 aFormatter.Print( ")" );
630}
631
632
633void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
634{
635 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
636
637 if( it == m_symbols.end() )
638 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
639 m_libFileName.GetFullName(), aSymbolName ) );
640
641 LIB_SYMBOL* symbol = it->second;
642
643 if( symbol->IsRoot() )
644 {
645 LIB_SYMBOL* rootSymbol = symbol;
646
647 // Remove the root symbol and all its children.
648 m_symbols.erase( it );
649
650 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
651
652 while( it1 != m_symbols.end() )
653 {
654 if( it1->second->IsDerived()
655 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
656 {
657 delete it1->second;
658 it1 = m_symbols.erase( it1 );
659 }
660 else
661 {
662 it1++;
663 }
664 }
665
666 delete rootSymbol;
667 }
668 else
669 {
670 // Just remove the alias.
671 m_symbols.erase( it );
672 delete symbol;
673 }
674
676 m_isModified = true;
677}
678
679
681{
682 for( auto& [name, symbol] : m_symbols )
683 {
684 if( symbol->GetParentName().IsEmpty() )
685 continue;
686
687 auto it = m_symbols.find( symbol->GetParentName() );
688
689 if( it == m_symbols.end() )
690 {
691 wxString error;
692
693 error.Printf( _( "No parent for extended symbol %s found in library '%s'" ),
694 name.c_str(), m_libFileName.GetFullPath() );
695 THROW_IO_ERROR( error );
696 }
697
698 symbol->SetParent( it->second );
699 }
700}
701
702
704{
705 aFormatter.Print( "(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
706 "(generator_version \"%s\")",
708 GetMajorMinorVersion().c_str().AsChar() );
709}
710
711
713{
714 if( !m_libFileName.IsDir() )
715 return m_libFileName.FileExists();
716 else
717 return m_libFileName.DirExists();
718}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
int AsTenthsOfADegree() const
Definition eda_angle.h:118
double AsDegrees() const
Definition eda_angle.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:144
FILL_T GetFillMode() const
Definition eda_shape.h:142
SHAPE_T GetShape() const
Definition eda_shape.h:168
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:215
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:173
COLOR4D GetFillColor() const
Definition eda_shape.h:152
wxString SHAPE_T_asString() const
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
virtual bool IsVisible() const
Definition eda_text.h:187
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:397
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, bool aWriteData) const
Output formatter for the embedded files.
void ClearEmbeddedFonts()
Remove 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:186
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
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:52
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
Define a library symbol object.
Definition lib_symbol.h:85
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:155
wxString GetKeyWords() const override
Definition lib_symbol.h:185
std::weak_ptr< LIB_SYMBOL > & GetParent()
Definition lib_symbol.h:117
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition lib_symbol.h:291
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition lib_symbol.h:205
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of SCH_ITEM objects separated by unit and convert number.
std::map< int, wxString > & GetUnitDisplayNames()
Definition lib_symbol.h:726
bool IsMultiBodyStyle() const override
Definition lib_symbol.h:750
bool IsLocalPower() const override
wxArrayString GetFPFilters() const
Definition lib_symbol.h:217
std::shared_ptr< LIB_SYMBOL > SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
Definition lib_symbol.h:95
const std::vector< wxString > & GetBodyStyleNames() const
Definition lib_symbol.h:763
bool HasDeMorganBodyStyles() const override
Definition lib_symbol.h:760
EMBEDDED_FILES * GetEmbeddedFiles() override
bool IsGlobalPower() const override
bool GetDuplicatePinNumbersAreJumpers() const
Definition lib_symbol.h:729
std::vector< std::set< wxString > > & JumperPinGroups()
Each jumper pin group is a set of pin numbers that should be treated as internally connected.
Definition lib_symbol.h:736
void EmbedFonts() override
An interface used to output 8 bit text in a convenient way.
Definition richio.h:323
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:550
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:465
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition richio.cpp:511
bool IsMandatory() const
VECTOR2I GetPosition() const override
bool IsNameShown() const
Definition sch_field.h:201
FIELD_T GetId() const
Definition sch_field.h:116
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
bool CanAutoplace() const
Definition sch_field.h:212
void SetText(const wxString &aText) override
static void saveSymbolDrawItem(SCH_ITEM *aItem, OUTPUTFORMATTER &aFormatter)
SCH_IO_KICAD_SEXPR_LIB_CACHE(const wxString &aLibraryPath)
static void saveDcmInfoAsFields(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
static void saveTextBox(SCH_TEXTBOX *aTextBox, OUTPUTFORMATTER &aFormatter)
static void saveField(SCH_FIELD *aField, OUTPUTFORMATTER &aFormatter)
void formatLibraryHeader(OUTPUTFORMATTER &aFormatter)
void DeleteSymbol(const wxString &aName) override
static void savePin(SCH_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveText(SCH_TEXT *aText, OUTPUTFORMATTER &aFormatter)
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
void updateParentSymbolLinks()
Update the parent symbol links for derived symbols.
Object to parser s-expression symbol library and schematic file formats.
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
LIB_SYMBOL_MAP m_symbols
wxFileName GetRealFile() const
long long GetLibModificationTime()
wxFileName m_libFileName
SCH_IO_LIB_CACHE(const wxString &aLibraryPath)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
bool IsPrivate() const
Definition sch_item.h:253
wxString GetClass() const override
Return the class name.
Definition sch_item.h:177
int GetNumberTextSize() const
Definition sch_pin.cpp:679
int GetLength() const
Definition sch_pin.cpp:299
const std::map< wxString, ALT > & GetAlternates() const
Definition sch_pin.h:160
bool IsVisible() const
Definition sch_pin.cpp:387
const wxString & GetName() const
Definition sch_pin.cpp:401
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:264
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:256
int GetNameTextSize() const
Definition sch_pin.cpp:655
const wxString & GetNumber() const
Definition sch_pin.h:124
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:278
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:313
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:58
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:150
Simple container to manage line stroke parameters.
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
int GetPinNameOffset() const
Definition symbol.h:160
bool GetExcludedFromBoard() const override
Definition symbol.h:208
virtual bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition symbol.h:198
virtual bool GetShowPinNames() const
Definition symbol.h:166
virtual bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition symbol.h:183
virtual bool GetShowPinNumbers() const
Definition symbol.h:172
wxString wx_str() const
Definition utf8.cpp:45
The common library.
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
#define _(s)
#define IS_CHANGED
Item was edited, and modified.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:46
FILL_T
Definition eda_shape.h:56
static const std::string KiCadSymbolLibFileExtension
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:96
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Convert aAngle from board units to a string appropriate for writing to file.
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
#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, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatCircle(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
const char * getPinElectricalTypeToken(ELECTRICAL_PINTYPE aType)
void formatBezier(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatRect(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatFill(OUTPUTFORMATTER *aFormatter, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
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_FILENAME
@ CTX_NO_SPACE
@ USER
The field ID hasn't been set yet; field is invalid.
wxString GetCanonicalFieldName(FIELD_T aFieldType)
wxLogTrace helper definitions.
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_SHAPE_T
Definition typeinfo.h:153
@ SCH_TEXT_T
Definition typeinfo.h:155
@ SCH_TEXTBOX_T
Definition typeinfo.h:156
@ SCH_PIN_T
Definition typeinfo.h:157
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695