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 KICAD_FORMAT::FormatBool( &aFormatter, "embedded_fonts", aSymbol->GetAreFontsEmbedded() );
396
397 if( !aSymbol->EmbeddedFileMap().empty() )
398 aSymbol->WriteEmbeddedFiles( aFormatter, aIncludeData );
399 }
400
401 aFormatter.Print( ")" );
402}
403
404
406 OUTPUTFORMATTER& aFormatter )
407{
408 wxCHECK_RET( aSymbol, "Invalid LIB_SYMBOL pointer." );
409
410 if( !aSymbol->GetKeyWords().IsEmpty() )
411 {
412 SCH_FIELD keywords( nullptr, FIELD_T::USER, wxString( "ki_keywords" ) );
413 keywords.SetVisible( false );
414 keywords.SetText( aSymbol->GetKeyWords() );
415 saveField( &keywords, aFormatter );
416 }
417
418 wxArrayString fpFilters = aSymbol->GetFPFilters();
419
420 if( !fpFilters.IsEmpty() )
421 {
422 wxString tmp;
423
424 for( const wxString& filter : fpFilters )
425 {
426 // Spaces are not handled in fp filter names so escape spaces if any
427 wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE );
428
429 if( tmp.IsEmpty() )
430 tmp = curr_filter;
431 else
432 tmp += " " + curr_filter;
433 }
434
435 SCH_FIELD description( nullptr, FIELD_T::USER, wxString( "ki_fp_filters" ) );
436 description.SetVisible( false );
437 description.SetText( tmp );
438 saveField( &description, aFormatter );
439 }
440}
441
442
444{
445 wxCHECK_RET( aItem, "Invalid SCH_ITEM pointer." );
446
447 switch( aItem->Type() )
448 {
449 case SCH_SHAPE_T:
450 {
451 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
452 STROKE_PARAMS stroke = shape->GetStroke();
453 FILL_T fillMode = shape->GetFillMode();
454 COLOR4D fillColor = shape->GetFillColor();
455 bool isPrivate = shape->IsPrivate();
456
457 switch( shape->GetShape() )
458 {
459 case SHAPE_T::ARC:
460 formatArc( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
461 break;
462
463 case SHAPE_T::CIRCLE:
464 formatCircle( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
465 break;
466
468 formatRect( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
469 break;
470
471 case SHAPE_T::BEZIER:
472 formatBezier(&aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
473 break;
474
475 case SHAPE_T::POLY:
476 formatPoly( &aFormatter, shape, isPrivate, stroke, fillMode, fillColor, true );
477 break;
478
479 default:
481 }
482
483 break;
484 }
485
486 case SCH_PIN_T:
487 savePin( static_cast<SCH_PIN*>( aItem ), aFormatter );
488 break;
489
490 case SCH_TEXT_T:
491 saveText( static_cast<SCH_TEXT*>( aItem ), aFormatter );
492 break;
493
494 case SCH_TEXTBOX_T:
495 saveTextBox( static_cast<SCH_TEXTBOX*>( aItem ), aFormatter );
496 break;
497
498 default:
499 UNIMPLEMENTED_FOR( aItem->GetClass() );
500 }
501}
502
503
505{
506 wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
507
508 wxString fieldName = aField->GetName();
509
510 if( aField->IsMandatory() )
511 fieldName = GetCanonicalFieldName( aField->GetId() );
512
513 aFormatter.Print( "(property %s %s %s (at %s %s %s)",
514 aField->IsPrivate() ? "private" : "",
515 aFormatter.Quotew( fieldName ).c_str(),
516 aFormatter.Quotew( aField->GetText() ).c_str(),
518 aField->GetPosition().x ).c_str(),
520 -aField->GetPosition().y ).c_str(),
521 fmt::format( "{:g}", aField->GetTextAngle().AsDegrees() ).c_str() );
522
523 KICAD_FORMAT::FormatBool( &aFormatter, "show_name", aField->IsNameShown() );
524
525 KICAD_FORMAT::FormatBool( &aFormatter, "do_not_autoplace", !aField->CanAutoplace() );
526
527 if( !aField->IsVisible() )
528 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
529
530 aField->Format( &aFormatter, 0 );
531 aFormatter.Print( ")" );
532}
533
534
536{
537 wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." );
538
539 aPin->ClearFlags( IS_CHANGED );
540
541 aFormatter.Print( "(pin %s %s (at %s %s %s) (length %s)",
543 getPinShapeToken( aPin->GetShape() ),
545 aPin->GetPosition().x ).c_str(),
547 -aPin->GetPosition().y ).c_str(),
550 aPin->GetLength() ).c_str() );
551
552 if( !aPin->IsVisible() )
553 KICAD_FORMAT::FormatBool( &aFormatter, "hide", true );
554
555 // This follows the EDA_TEXT effects formatting for future expansion.
556 aFormatter.Print( "(name %s (effects (font (size %s %s))))",
557 aFormatter.Quotew( aPin->GetName() ).c_str(),
559 aPin->GetNameTextSize() ).c_str(),
561 aPin->GetNameTextSize() ).c_str() );
562
563 aFormatter.Print( "(number %s (effects (font (size %s %s))))",
564 aFormatter.Quotew( aPin->GetNumber() ).c_str(),
566 aPin->GetNumberTextSize() ).c_str(),
568 aPin->GetNumberTextSize() ).c_str() );
569
570
571 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : aPin->GetAlternates() )
572 {
573 // There was a bug somewhere in the alternate pin code that allowed pin alternates with no
574 // name to be saved in library symbols. This strips any invalid alternates just in case
575 // that code resurfaces.
576 if( alt.second.m_Name.IsEmpty() )
577 continue;
578
579 aFormatter.Print( "(alternate %s %s %s)",
580 aFormatter.Quotew( alt.second.m_Name ).c_str(),
581 getPinElectricalTypeToken( alt.second.m_Type ),
582 getPinShapeToken( alt.second.m_Shape ) );
583 }
584
585 aFormatter.Print( ")" );
586}
587
588
590{
591 wxCHECK_RET( aText && aText->Type() == SCH_TEXT_T, "Invalid SCH_TEXT object." );
592
593 aFormatter.Print( "(text %s %s (at %s %s %d)",
594 aText->IsPrivate() ? "private" : "",
595 aFormatter.Quotew( aText->GetText() ).c_str(),
597 aText->GetPosition().x ).c_str(),
599 -aText->GetPosition().y ).c_str(),
600 aText->GetTextAngle().AsTenthsOfADegree() );
601
602 aText->EDA_TEXT::Format( &aFormatter, 0 );
603 aFormatter.Print( ")" );
604}
605
606
608{
609 wxCHECK_RET( aTextBox && aTextBox->Type() == SCH_TEXTBOX_T, "Invalid SCH_TEXTBOX object." );
610
611 aFormatter.Print( "(text_box %s %s",
612 aTextBox->IsPrivate() ? "private" : "",
613 aFormatter.Quotew( aTextBox->GetText() ).c_str() );
614
615 VECTOR2I pos = aTextBox->GetStart();
616 VECTOR2I size = aTextBox->GetEnd() - pos;
617
618 aFormatter.Print( "(at %s %s %s) (size %s %s) (margins %s %s %s %s)",
621 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
628
629 aTextBox->GetStroke().Format( &aFormatter, schIUScale );
630 formatFill( &aFormatter, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
631 aTextBox->EDA_TEXT::Format( &aFormatter, 0 );
632 aFormatter.Print( ")" );
633}
634
635
636void SCH_IO_KICAD_SEXPR_LIB_CACHE::DeleteSymbol( const wxString& aSymbolName )
637{
638 LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
639
640 if( it == m_symbols.end() )
641 THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
642 m_libFileName.GetFullName(), aSymbolName ) );
643
644 LIB_SYMBOL* symbol = it->second;
645
646 if( symbol->IsRoot() )
647 {
648 LIB_SYMBOL* rootSymbol = symbol;
649
650 // Remove the root symbol and all its children.
651 m_symbols.erase( it );
652
653 LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
654
655 while( it1 != m_symbols.end() )
656 {
657 if( it1->second->IsDerived()
658 && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
659 {
660 delete it1->second;
661 it1 = m_symbols.erase( it1 );
662 }
663 else
664 {
665 it1++;
666 }
667 }
668
669 delete rootSymbol;
670 }
671 else
672 {
673 // Just remove the alias.
674 m_symbols.erase( it );
675 delete symbol;
676 }
677
679 m_isModified = true;
680}
681
682
684{
685 for( auto& [name, symbol] : m_symbols )
686 {
687 if( symbol->GetParentName().IsEmpty() )
688 continue;
689
690 auto it = m_symbols.find( symbol->GetParentName() );
691
692 if( it == m_symbols.end() )
693 {
694 wxString error;
695
696 error.Printf( _( "No parent for extended symbol %s found in library '%s'" ),
697 name.c_str(), m_libFileName.GetFullPath() );
698 THROW_IO_ERROR( error );
699 }
700
701 symbol->SetParent( it->second );
702 }
703}
704
705
707{
708 aFormatter.Print( "(kicad_symbol_lib (version %d) (generator \"kicad_symbol_editor\") "
709 "(generator_version \"%s\")",
711 GetMajorMinorVersion().c_str().AsChar() );
712}
713
714
716{
717 if( !m_libFileName.IsDir() )
718 return m_libFileName.FileExists();
719 else
720 return m_libFileName.DirExists();
721}
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:394
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:158
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:105
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:83
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:153
wxString GetKeyWords() const override
Definition lib_symbol.h:183
std::weak_ptr< LIB_SYMBOL > & GetParent()
Definition lib_symbol.h:115
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:288
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition lib_symbol.h:203
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:723
bool IsMultiBodyStyle() const override
Definition lib_symbol.h:747
bool IsLocalPower() const override
wxArrayString GetFPFilters() const
Definition lib_symbol.h:215
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:93
const std::vector< wxString > & GetBodyStyleNames() const
Definition lib_symbol.h:760
bool HasDeMorganBodyStyles() const override
Definition lib_symbol.h:757
EMBEDDED_FILES * GetEmbeddedFiles() override
bool IsGlobalPower() const override
bool GetDuplicatePinNumbersAreJumpers() const
Definition lib_symbol.h:726
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:733
void EmbedFonts() override
An interface used to output 8 bit text in a convenient way.
Definition richio.h:295
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:507
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:422
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition richio.cpp:468
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