KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_library_manager.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) 2017 CERN
5 * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[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 3
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
19 * along with this program; if not, you may find one here:
20 * https://www.gnu.org/licenses/gpl-3.0.html
21 * or you may search the http://www.gnu.org website for the version 3 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include <symbol_library.h>
29#include <symbol_edit_frame.h>
30#include <env_paths.h>
31#include <pgm_base.h>
32#include <project_sch.h>
33#include <kiway.h>
34#include <core/profile.h>
35#include <wx_filename.h>
37#include <symbol_async_loader.h>
38#include <progress_reporter.h>
39#include <list>
40#include <locale_io.h>
41#include <confirm.h>
42#include <string_utils.h>
43#include "lib_logger.h"
44
45
47 m_frame( aFrame )
48{
49 m_logger = new LIB_LOGGER();
50}
51
52
54{
55 delete m_logger;
56}
57
58
60{
61 SYMBOL_ASYNC_LOADER loader( symTable()->GetLogicalLibs(), symTable(), false, nullptr,
62 &aReporter );
63
64 LOCALE_IO toggle;
65
66 loader.Start();
67
68 while( !loader.Done() )
69 {
70 if( !aReporter.KeepRefreshing() )
71 break;
72
73 wxMilliSleep( 33 /* 30 FPS refresh rate */ );
74 }
75
76 loader.Join();
77
78 if( !loader.GetErrors().IsEmpty() )
79 {
80 HTML_MESSAGE_BOX dlg( &m_frame, _( "Load Error" ) );
81
82 dlg.MessageSet( _( "Errors loading symbols:" ) );
83
84 wxString msg = loader.GetErrors();
85 msg.Replace( "\n", "<BR>" );
86
87 dlg.AddHTML_Text( msg );
88 dlg.ShowModal();
89 }
90}
91
92
94{
95 for( const auto& [name, buffer] : m_libs )
96 {
97 if( buffer.IsModified() )
98 return true;
99 }
100
101 return false;
102}
103
104
106{
107 int hash = symTable()->GetModifyHash();
108
109 for( const auto& [name, buffer] : m_libs )
110 hash += buffer.GetHash();
111
112 return hash;
113}
114
115
116int SYMBOL_LIBRARY_MANAGER::GetLibraryHash( const wxString& aLibrary ) const
117{
118 const auto libBufIt = m_libs.find( aLibrary );
119
120 if( libBufIt != m_libs.end() )
121 return libBufIt->second.GetHash();
122
123 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
124
125 // return -1 if library does not exist or 0 if not modified
126 return row ? std::hash<std::string>{}( aLibrary.ToStdString() +
127 row->GetFullURI( true ).ToStdString() ) : -1;
128}
129
130
132{
133 wxArrayString res;
134
135 for( const wxString& libName : symTable()->GetLogicalLibs() )
136 {
137 // Database libraries are hidden from the symbol editor at the moment
138 if( GetLibrary( libName )->SchLibType() == SCH_IO_MGR::SCH_DATABASE )
139 continue;
140
141 res.Add( libName );
142 }
143
144 return res;
145}
146
147
149{
150 SYMBOL_LIB_TABLE_ROW* row = nullptr;
151
152 try
153 {
154 row = symTable()->FindRow( aLibrary, true );
155 }
156 catch( const IO_ERROR& e )
157 {
158 wxString msg;
159
160 msg.Printf( _( "Library '%s' not found in the Symbol Library Table." ), aLibrary );
161 DisplayErrorMessage( &m_frame, msg, e.What() );
162 }
163
164 return row;
165}
166
167
168bool SYMBOL_LIBRARY_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName,
169 SCH_IO_MGR::SCH_FILE_T aFileType )
170{
171 wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false );
172 wxFileName fn( aFileName );
173 wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
174
175 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( aFileType ) );
176 bool res = true; // assume all libraries are successfully saved
177 STRING_UTF8_MAP properties;
178
179 properties.emplace( SCH_IO_KICAD_LEGACY::PropBuffering, "" );
180
181 auto it = m_libs.find( aLibrary );
182
183 if( it != m_libs.end() )
184 {
185 // Handle buffered library
186 LIB_BUFFER& libBuf = it->second;
187
188 const auto& symbolBuffers = libBuf.GetBuffers();
189
190 for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : symbolBuffers )
191 {
192 if( !libBuf.SaveBuffer( symbolBuf, aFileName, &*pi, true ) )
193 {
194 // Something went wrong, but try to save other libraries
195 res = false;
196 }
197 }
198
199 // clear the deleted symbols buffer only if data is saved to the original file
200 wxFileName original, destination( aFileName );
201 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
202
203 if( row )
204 {
205 original = row->GetFullURI();
206 original.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
207 }
208
209 destination.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
210
211 if( res && original == destination )
212 libBuf.ClearDeletedBuffer();
213 }
214 else
215 {
216 // Handle original library
217 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
218 {
219 LIB_SYMBOL* newSymbol;
220
221 try
222 {
223 if( symbol->IsAlias() )
224 {
225 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
226
227 wxCHECK_MSG( oldParent, false,
228 wxString::Format( wxT( "Derived symbol '%s' found with "
229 "undefined parent." ),
230 symbol->GetName() ) );
231
232 LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(),
233 &properties );
234
235 if( !libParent )
236 {
237 libParent = new LIB_SYMBOL( *oldParent.get() );
238 pi->SaveSymbol( aLibrary, libParent, &properties );
239 }
240
241 newSymbol = new LIB_SYMBOL( *symbol );
242 newSymbol->SetParent( libParent );
243 pi->SaveSymbol( aLibrary, newSymbol, &properties );
244 }
245 else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) )
246 {
247 pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties );
248 }
249 }
250 catch( ... )
251 {
252 res = false;
253 break;
254 }
255 }
256 }
257
258 try
259 {
260 pi->SaveLibrary( aFileName );
261 }
262 catch( ... )
263 {
264 // return false because something happens.
265 // The library is not successfully saved
266 res = false;
267 }
268
269 return res;
270}
271
272
273bool SYMBOL_LIBRARY_MANAGER::IsLibraryModified( const wxString& aLibrary ) const
274{
275 auto it = m_libs.find( aLibrary );
276 return it != m_libs.end() ? it->second.IsModified() : false;
277}
278
279
280bool SYMBOL_LIBRARY_MANAGER::IsSymbolModified( const wxString& aAlias,
281 const wxString& aLibrary ) const
282{
283 auto libIt = m_libs.find( aLibrary );
284
285 if( libIt == m_libs.end() )
286 return false;
287
288 const LIB_BUFFER& buf = libIt->second;
289 const std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
290
291 return symbolBuf ? symbolBuf->IsModified() : false;
292}
293
294
295void SYMBOL_LIBRARY_MANAGER::SetSymbolModified( const wxString& aAlias, const wxString& aLibrary )
296{
297 auto libIt = m_libs.find( aLibrary );
298
299 if( libIt == m_libs.end() )
300 return;
301
302 const LIB_BUFFER& buf = libIt->second;
303 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
304
305 wxCHECK( symbolBuf, /* void */ );
306
307 symbolBuf->GetScreen()->SetContentModified();
308}
309
310
311bool SYMBOL_LIBRARY_MANAGER::ClearLibraryModified( const wxString& aLibrary ) const
312{
313 auto libIt = m_libs.find( aLibrary );
314
315 if( libIt == m_libs.end() )
316 return false;
317
318 for( auto& symbolBuf : libIt->second.GetBuffers() )
319 {
320 SCH_SCREEN* screen = symbolBuf->GetScreen();
321
322 if( screen )
323 screen->SetContentModified( false );
324 }
325
326 return true;
327}
328
329
331 const wxString& aLibrary ) const
332{
333 auto libIt = m_libs.find( aLibrary );
334
335 if( libIt == m_libs.end() )
336 return false;
337
338 auto symbolBuf = libIt->second.GetBuffer( aAlias );
339 wxCHECK( symbolBuf, false );
340
341 symbolBuf->GetScreen()->SetContentModified( false );
342 return true;
343}
344
345
346bool SYMBOL_LIBRARY_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const
347{
348 wxCHECK( LibraryExists( aLibrary ), true );
349
350 return !symTable()->IsSymbolLibWritable( aLibrary );
351}
352
353
354bool SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded( const wxString& aLibrary ) const
355{
356 wxCHECK( LibraryExists( aLibrary ), false );
357
358 return symTable()->IsSymbolLibLoaded( aLibrary );
359}
360
361
362std::list<LIB_SYMBOL*> SYMBOL_LIBRARY_MANAGER::GetAliases( const wxString& aLibrary ) const
363{
364 std::list<LIB_SYMBOL*> ret;
365 wxCHECK( LibraryExists( aLibrary ), ret );
366
367 auto libIt = m_libs.find( aLibrary );
368
369 if( libIt != m_libs.end() )
370 {
371 for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : libIt->second.GetBuffers() )
372 ret.push_back( symbolBuf->GetSymbol() );
373 }
374 else
375 {
376 std::vector<LIB_SYMBOL*> aliases;
377
378 try
379 {
380 symTable()->LoadSymbolLib( aliases, aLibrary );
381 }
382 catch( const IO_ERROR& e )
383 {
384 wxLogWarning( e.Problem() );
385 }
386
387 std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) );
388 }
389
390 return ret;
391}
392
393
395 const wxString& aLibrary )
396{
397 wxCHECK( LibraryExists( aLibrary ), nullptr );
398
399 // try the library buffers first
400 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
401 LIB_SYMBOL* bufferedSymbol = libBuf.GetSymbol( aAlias );
402
403 if( !bufferedSymbol ) // no buffer symbol found
404 {
405 // create a copy of the symbol
406 try
407 {
408 LIB_SYMBOL* symbol = symTable()->LoadSymbol( aLibrary, aAlias );
409
410 if( symbol == nullptr )
411 THROW_IO_ERROR( _( "Symbol not found." ) );
412
413 LIB_SYMBOL* bufferedParent = nullptr;
414
415 // Create parent symbols on demand so parent symbol can be set.
416 if( symbol->IsAlias() )
417 {
418 std::shared_ptr<LIB_SYMBOL> parent = symbol->GetParent().lock();
419 wxCHECK_MSG( parent, nullptr,
420 wxString::Format( "Derived symbol '%s' found with undefined parent.",
421 symbol->GetName() ) );
422
423 // Check if the parent symbol buffer has already be created.
424 bufferedParent = libBuf.GetSymbol( parent->GetName() );
425
426 if( !bufferedParent )
427 {
428 bufferedParent = new LIB_SYMBOL( *parent.get() );
429 libBuf.CreateBuffer( bufferedParent, new SCH_SCREEN );
430 }
431 }
432
433 bufferedSymbol = new LIB_SYMBOL( *symbol );
434
435 if( bufferedParent )
436 bufferedSymbol->SetParent( bufferedParent );
437
438 libBuf.CreateBuffer( bufferedSymbol, new SCH_SCREEN );
439 }
440 catch( const IO_ERROR& e )
441 {
442 wxString msg;
443
444 msg.Printf( _( "Error loading symbol %s from library '%s'." ), aAlias, aLibrary );
445 DisplayErrorMessage( &m_frame, msg, e.What() );
446 bufferedSymbol = nullptr;
447 }
448 }
449
450 return bufferedSymbol;
451}
452
453
454SCH_SCREEN* SYMBOL_LIBRARY_MANAGER::GetScreen( const wxString& aAlias, const wxString& aLibrary )
455{
456 wxCHECK( LibraryExists( aLibrary ), nullptr );
457 wxCHECK( !aAlias.IsEmpty(), nullptr );
458 auto it = m_libs.find( aLibrary );
459 wxCHECK( it != m_libs.end(), nullptr );
460
461 LIB_BUFFER& buf = it->second;
462 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
463
464 return symbolBuf ? symbolBuf->GetScreen() : nullptr;
465}
466
467
468bool SYMBOL_LIBRARY_MANAGER::UpdateSymbol( LIB_SYMBOL* aSymbol, const wxString& aLibrary )
469{
470 wxCHECK( LibraryExists( aLibrary ), false );
471 wxCHECK( aSymbol, false );
472
473 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
474 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aSymbol->GetName() );
475
476 if( symbolBuf ) // Existing symbol.
477 {
478 LIB_SYMBOL* bufferedSymbol = const_cast< LIB_SYMBOL* >( symbolBuf->GetSymbol() );
479
480 wxCHECK( bufferedSymbol, false );
481
482 // If we are coming from a different library, the library ID needs to be preserved
483 auto libId = bufferedSymbol->GetLibId();
484 *bufferedSymbol = *aSymbol;
485 bufferedSymbol->SetLibId( libId );
486
487 symbolBuf->GetScreen()->SetContentModified();
488 }
489 else // New symbol
490 {
491 LIB_SYMBOL* symbolCopy = new LIB_SYMBOL( *aSymbol, nullptr );
492
493 symbolCopy->SetLibId( LIB_ID( aLibrary, aSymbol->GetLibId().GetLibItemName() ) );
494
495 SCH_SCREEN* screen = new SCH_SCREEN;
496 libBuf.CreateBuffer( symbolCopy, screen );
497 screen->SetContentModified();
498 }
499
500 return true;
501}
502
503
504bool SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename( LIB_SYMBOL* aSymbol, const wxString& aOldName,
505 const wxString& aLibrary )
506{
507 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
508 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aOldName );
509
510 wxCHECK( symbolBuf, false );
511
512 libBuf.UpdateBuffer( symbolBuf, aSymbol );
514
515 return true;
516}
517
518
519LIB_ID SYMBOL_LIBRARY_MANAGER::RevertSymbol( const wxString& aAlias, const wxString& aLibrary )
520{
521 auto it = m_libs.find( aLibrary );
522
523 if( it == m_libs.end() ) // no items to flush
524 return LIB_ID( aLibrary, aAlias );
525
526 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = it->second.GetBuffer( aAlias );
527 wxCHECK( symbolBuf, LIB_ID( aLibrary, aAlias ) );
528 LIB_SYMBOL original( *symbolBuf->GetOriginal() );
529
530 if( original.GetName() != aAlias )
531 {
532 UpdateSymbolAfterRename( &original, aAlias, aLibrary );
533 }
534 else
535 {
536 // copy the initial data to the current symbol to restore
537 *symbolBuf->GetSymbol() = original;
539 }
540
541 return LIB_ID( aLibrary, original.GetName() );
542}
543
544
545bool SYMBOL_LIBRARY_MANAGER::RevertLibrary( const wxString& aLibrary )
546{
547 auto it = m_libs.find( aLibrary );
548
549 if( it == m_libs.end() ) // nothing to reverse
550 return false;
551
552 m_libs.erase( it );
554
555 return true;
556}
557
558
560{
561 bool retv = true;
562
563 // Nothing to revert.
564 if( GetHash() == 0 )
565 return true;
566
567 for( const auto& lib : m_libs )
568 {
569 if( !lib.second.IsModified() )
570 continue;
571
572 for( const std::shared_ptr<SYMBOL_BUFFER>& buffer : lib.second.GetBuffers() )
573 {
574 if( !buffer->IsModified() )
575 continue;
576
577 RevertSymbol( lib.first, buffer->GetOriginal()->GetName() );
578 }
579 }
580
581 return retv;
582}
583
584
585bool SYMBOL_LIBRARY_MANAGER::RemoveSymbol( const wxString& aAlias, const wxString& aLibrary )
586{
587 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
588 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aAlias );
589 wxCHECK( symbolBuf, false );
590
591 bool retv = true;
592
593 retv &= libBuf.DeleteBuffer( symbolBuf );
595
596 return retv;
597}
598
599
601 const wxString& aLibrary ) const
602{
603 // Try the library buffers first
604 auto libIt = m_libs.find( aLibrary );
605
606 if( libIt != m_libs.end() )
607 {
608 LIB_SYMBOL* symbol = libIt->second.GetSymbol( aAlias );
609
610 if( symbol )
611 return symbol;
612 }
613
614 // Get the original symbol
615 LIB_SYMBOL* alias = nullptr;
616
617 try
618 {
619 alias = symTable()->LoadSymbol( aLibrary, aAlias );
620 }
621 catch( const IO_ERROR& e )
622 {
623 wxString msg;
624
625 msg.Printf( _( "Cannot load symbol '%s' from library '%s'." ), aAlias, aLibrary );
626 DisplayErrorMessage( &m_frame, msg, e.What() );
627 }
628
629 return alias;
630}
631
632
633bool SYMBOL_LIBRARY_MANAGER::SymbolExists( const wxString& aAlias, const wxString& aLibrary ) const
634{
635 auto libBufIt = m_libs.find( aLibrary );
636 LIB_SYMBOL* alias = nullptr;
637
638 if( libBufIt != m_libs.end() )
639 return !!libBufIt->second.GetBuffer( aAlias );
640
641 try
642 {
643 alias = symTable()->LoadSymbol( aLibrary, aAlias );
644 }
645 catch( IO_ERROR& )
646 {
647 // checking if certain symbol exists, so its absence is perfectly fine
648 }
649
650 return alias != nullptr;
651}
652
653
654bool SYMBOL_LIBRARY_MANAGER::LibraryExists( const wxString& aLibrary, bool aCheckEnabled ) const
655{
656 if( aLibrary.IsEmpty() )
657 return false;
658
659 if( m_libs.count( aLibrary ) > 0 )
660 return true;
661
662 return symTable()->HasLibrary( aLibrary, aCheckEnabled );
663}
664
665
667{
668 wxString name = "New_Library";
669
670 if( !LibraryExists( name ) )
671 return name;
672
673 name += "_";
674
675 for( unsigned int i = 0; i < std::numeric_limits<unsigned int>::max(); ++i )
676 {
677 if( !LibraryExists( name + wxString::Format( "%u", i ) ) )
678 return name + wxString::Format( "%u", i );
679 }
680
681 wxFAIL;
682 return wxEmptyString;
683}
684
685
686void SYMBOL_LIBRARY_MANAGER::GetSymbolNames( const wxString& aLibraryName,
687 wxArrayString& aSymbolNames,
688 SYMBOL_NAME_FILTER aFilter )
689{
690 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
691
692 libBuf.GetSymbolNames( aSymbolNames, aFilter );
693}
694
695
696bool SYMBOL_LIBRARY_MANAGER:: HasDerivedSymbols( const wxString& aSymbolName,
697 const wxString& aLibraryName )
698{
699 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
700
701 return libBuf.HasDerivedSymbols( aSymbolName );
702}
703
704
706{
707 return symTable()->GetLogicalLibs().size();
708}
709
710
711wxString SYMBOL_LIBRARY_MANAGER::getLibraryName( const wxString& aFilePath )
712{
713 wxFileName fn( aFilePath );
714 return fn.GetName();
715}
716
717
718bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate,
719 SYMBOL_LIB_TABLE* aTable )
720{
721 wxCHECK( aTable, false );
722 wxString libName = getLibraryName( aFilePath );
723 wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
724
725 // try to use path normalized to an environmental variable or project path
726 wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
727
728 SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath );
729
730 if( schFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
731 schFileType = SCH_IO_MGR::SCH_LEGACY;
732
733 wxString typeName = SCH_IO_MGR::ShowType( schFileType );
734 SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
735 aTable->InsertRow( libRow );
736
737 if( aCreate )
738 {
739 wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY, false );
740
741 try
742 {
743 aTable->CreateSymbolLib( libName );
744 }
745 catch( const IO_ERROR& )
746 {
747 aTable->RemoveRow( libRow );
748 return false;
749 }
750 }
751
753
754 return true;
755}
756
757
759{
761}
762
763
764std::set<LIB_SYMBOL*> SYMBOL_LIBRARY_MANAGER::getOriginalSymbols( const wxString& aLibrary )
765{
766 std::set<LIB_SYMBOL*> symbols;
767 wxCHECK( LibraryExists( aLibrary ), symbols );
768
769 try
770 {
771 wxArrayString aliases;
772 symTable()->EnumerateSymbolLib( aLibrary, aliases );
773
774 for( const auto& aliasName : aliases )
775 {
776 LIB_SYMBOL* alias = symTable()->LoadSymbol( aLibrary, aliasName );
777 symbols.insert( alias );
778 }
779 }
780 catch( const IO_ERROR& e )
781 {
782 wxString msg;
783
784 msg.Printf( _( "Cannot enumerate library '%s'." ), aLibrary );
785 DisplayErrorMessage( &m_frame, msg, e.What() );
786 }
787
788 return symbols;
789}
790
791
793{
794 auto it = m_libs.find( aLibrary );
795
796 if( it != m_libs.end() )
797 return it->second;
798
799 // The requested buffer does not exist yet, so create one
800 auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) );
801 LIB_BUFFER& buf = ret.first->second;
802
803 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
804 {
805 LIB_SYMBOL* newSymbol;
806
807 if( symbol->IsAlias() )
808 {
809 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
810
811 wxCHECK_MSG( oldParent, buf,
812 wxString::Format( "Derived symbol '%s' found with undefined parent.",
813 symbol->GetName() ) );
814
815 LIB_SYMBOL* libParent = buf.GetSymbol( oldParent->GetName() );
816
817 if( !libParent )
818 {
819 libParent = new LIB_SYMBOL( *oldParent.get() );
820 buf.CreateBuffer( libParent, new SCH_SCREEN );
821 }
822
823 newSymbol = new LIB_SYMBOL( *symbol );
824 newSymbol->SetParent( libParent );
825 buf.CreateBuffer( newSymbol, new SCH_SCREEN );
826 }
827 else if( !buf.GetSymbol( symbol->GetName() ) )
828 {
829 buf.CreateBuffer( new LIB_SYMBOL( *symbol ), new SCH_SCREEN );
830 }
831 }
832
833 return buf;
834}
835
836
837bool SYMBOL_LIBRARY_MANAGER::UpdateLibraryBuffer( const wxString& aLibrary )
838{
839 try
840 {
841 m_libs.erase( aLibrary );
842 getLibraryBuffer( aLibrary );
843 }
844 catch(const std::exception& e)
845 {
846 wxLogError( _( "Error updating library buffer: %s" ), e.what() );
847 return false;
848 }
849 catch( const IO_ERROR& e )
850 {
851 wxLogError( _( "Error updating library buffer: %s" ), e.What() );
852 return false;
853 }
854 catch(...)
855 {
856 wxLogError( _( "Error updating library buffer." ) );
857 return false;
858 }
859
860 getLibraryBuffer( aLibrary );
861
862 return true;
863}
864
865
866SYMBOL_BUFFER::SYMBOL_BUFFER( LIB_SYMBOL* aSymbol, std::unique_ptr<SCH_SCREEN> aScreen ) :
867 m_screen( std::move( aScreen ) ),
868 m_symbol( aSymbol )
869{
870 m_original = new LIB_SYMBOL( *aSymbol );
871}
872
873
875{
876 delete m_symbol;
877 delete m_original;
878}
879
880
882{
883 wxCHECK( m_symbol != aSymbol, /* void */ );
884 wxASSERT( aSymbol );
885 delete m_symbol;
886 m_symbol = aSymbol;
887
888 // If the symbol moves libraries then the original moves with it
890 {
893 }
894}
895
896
898{
899 wxCHECK( m_original != aSymbol, /* void */ );
900 wxASSERT( aSymbol );
901 delete m_original;
902 m_original = aSymbol;
903
904 // The original is not allowed to have a different library than its symbol
906 {
909 }
910}
911
912
914{
915 return m_screen && m_screen->IsContentModified();
916}
917
918
919LIB_SYMBOL* LIB_BUFFER::GetSymbol( const wxString& aAlias ) const
920{
921 auto buf = GetBuffer( aAlias );
922
923 if( !buf )
924 return nullptr;
925
926 LIB_SYMBOL* symbol = buf->GetSymbol();
927
928 wxCHECK( symbol, nullptr );
929
930 return symbol;
931}
932
933
935{
936 wxASSERT( aCopy );
937 wxASSERT( aCopy->GetLib() == nullptr );
938 std::unique_ptr<SCH_SCREEN> screen( aScreen );
939 auto symbolBuf = std::make_shared<SYMBOL_BUFFER>( aCopy, std::move( screen ) );
940 m_symbols.push_back( symbolBuf );
941
942 // Set the parent library name,
943 // otherwise it is empty as no library has been given as the owner during object construction
944 LIB_ID libId = aCopy->GetLibId();
945 libId.SetLibNickname( m_libName );
946 aCopy->SetLibId( libId );
947 ++m_hash;
948
949 return true;
950}
951
952
953bool LIB_BUFFER::UpdateBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf, LIB_SYMBOL* aCopy )
954{
955 wxCHECK( aCopy && aSymbolBuf, false );
956
957 LIB_SYMBOL* bufferedSymbol = aSymbolBuf->GetSymbol();
958
959 wxCHECK( bufferedSymbol, false );
960
961 *bufferedSymbol = *aCopy;
962 ++m_hash;
963
964 return true;
965}
966
967
968bool LIB_BUFFER::DeleteBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf )
969{
970 auto symbolBufIt = std::find( m_symbols.begin(), m_symbols.end(), aSymbolBuf );
971 wxCHECK( symbolBufIt != m_symbols.end(), false );
972
973 bool retv = true;
974
975 // Remove all derived symbols to prevent broken inheritance.
976 if( HasDerivedSymbols( aSymbolBuf->GetSymbol()->GetName() )
977 && ( removeChildSymbols( aSymbolBuf ) == 0 ) )
978 {
979 retv = false;
980 }
981
982 m_deleted.emplace_back( *symbolBufIt );
983 m_symbols.erase( symbolBufIt );
984 ++m_hash;
985
986 return retv;
987}
988
989
990bool LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf,
991 const wxString& aFileName, SCH_IO* aPlugin, bool aBuffer )
992{
993 wxCHECK( aSymbolBuf, false );
994 wxCHECK( !aFileName.IsEmpty(), false );
995
996 wxString errorMsg = _( "Error saving symbol %s to library '%s'." ) + wxS( "\n%s" );
997
998 // Set properties to prevent saving the file on every symbol save.
999 STRING_UTF8_MAP properties;
1000 properties.emplace( SCH_IO_KICAD_LEGACY::PropBuffering, "" );
1001
1002 std::shared_ptr<SYMBOL_BUFFER>& symbolBuf = aSymbolBuf;
1003 LIB_SYMBOL* libSymbol = symbolBuf->GetSymbol();
1004 LIB_SYMBOL* originalSymbol = symbolBuf->GetOriginal();
1005
1006 wxCHECK( libSymbol && originalSymbol, false );
1007
1008 // Delete the original symbol if the symbol name has been changed.
1009 if( libSymbol->GetName() != originalSymbol->GetName() )
1010 {
1011 try
1012 {
1013 if( aPlugin->LoadSymbol( aFileName, originalSymbol->GetName() ) )
1014 aPlugin->DeleteSymbol( aFileName, originalSymbol->GetName(), &properties );
1015 }
1016 catch( const IO_ERROR& ioe )
1017 {
1018 wxLogError( errorMsg, UnescapeString( originalSymbol->GetName() ), aFileName,
1019 ioe.What() );
1020 return false;
1021 }
1022 }
1023
1024 LIB_SYMBOL* parentSymbol = nullptr;
1025
1026 if( libSymbol->IsAlias() )
1027 {
1028 LIB_SYMBOL* newCachedSymbol = new LIB_SYMBOL( *libSymbol );
1029 std::shared_ptr<LIB_SYMBOL> bufferedParent = libSymbol->GetParent().lock();
1030 parentSymbol = newCachedSymbol;
1031
1032 wxCHECK( bufferedParent, false );
1033
1034 LIB_SYMBOL* cachedParent = nullptr;
1035
1036 try
1037 {
1038 cachedParent = aPlugin->LoadSymbol( aFileName, bufferedParent->GetName() );
1039 }
1040 catch( const IO_ERROR& )
1041 {
1042 return false;
1043 }
1044
1045 if( !cachedParent )
1046 {
1047 cachedParent = new LIB_SYMBOL( *bufferedParent.get() );
1048 newCachedSymbol->SetParent( cachedParent );
1049
1050 try
1051 {
1052 aPlugin->SaveSymbol( aFileName, cachedParent, aBuffer ? &properties : nullptr );
1053 }
1054 catch( const IO_ERROR& ioe )
1055 {
1056 wxLogError( errorMsg, UnescapeString( cachedParent->GetName() ), aFileName,
1057 ioe.What() );
1058 return false;
1059 }
1060
1061 try
1062 {
1063 aPlugin->SaveSymbol( aFileName, newCachedSymbol, aBuffer ? &properties : nullptr );
1064 }
1065 catch( const IO_ERROR& ioe )
1066 {
1067 wxLogError( errorMsg, UnescapeString( newCachedSymbol->GetName() ), aFileName,
1068 ioe.What() );
1069 return false;
1070 }
1071
1072 LIB_SYMBOL* originalParent = new LIB_SYMBOL( *bufferedParent.get() );
1073 aSymbolBuf->SetOriginal( originalParent );
1074 originalSymbol = new LIB_SYMBOL( *libSymbol );
1075 originalSymbol->SetParent( originalParent );
1076 aSymbolBuf->SetOriginal( originalSymbol );
1077 }
1078 else
1079 {
1080 newCachedSymbol->SetParent( cachedParent );
1081
1082 try
1083 {
1084 aPlugin->SaveSymbol( aFileName, newCachedSymbol, aBuffer ? &properties : nullptr );
1085 }
1086 catch( const IO_ERROR& ioe )
1087 {
1088 wxLogError( errorMsg, UnescapeString( newCachedSymbol->GetName() ), aFileName,
1089 ioe.What() );
1090 return false;
1091 }
1092
1093 auto originalBufferedParent = GetBuffer( bufferedParent->GetName() );
1094 wxCHECK( originalBufferedParent, false );
1095 originalSymbol = new LIB_SYMBOL( *libSymbol );
1096 originalSymbol->SetParent( originalBufferedParent->GetSymbol() );
1097 aSymbolBuf->SetOriginal( originalSymbol );
1098 }
1099 }
1100 else
1101 {
1102 parentSymbol = new LIB_SYMBOL( *libSymbol );
1103
1104 try
1105 {
1106 aPlugin->SaveSymbol( aFileName, parentSymbol, aBuffer ? &properties : nullptr );
1107 }
1108 catch( const IO_ERROR& ioe )
1109 {
1110 wxLogError( errorMsg, UnescapeString( libSymbol->GetName() ), aFileName,
1111 ioe.What() );
1112 return false;
1113 }
1114
1115 aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
1116 }
1117
1118 wxArrayString derivedSymbols;
1119
1120 // Reparent all symbols derived from the saved symbol.
1121 if( GetDerivedSymbolNames( libSymbol->GetName(), derivedSymbols ) != 0 )
1122 {
1123 // Save the derived symbols.
1124 for( const wxString& entry : derivedSymbols )
1125 {
1126 std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
1127
1128 wxCHECK2( symbol, continue );
1129
1130 LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
1131 derivedSymbol->SetParent( parentSymbol );
1132
1133 try
1134 {
1135 aPlugin->SaveSymbol( aFileName, new LIB_SYMBOL( *derivedSymbol ),
1136 aBuffer ? &properties : nullptr );
1137 }
1138 catch( const IO_ERROR& ioe )
1139 {
1140 wxLogError( errorMsg, UnescapeString( derivedSymbol->GetName() ), aFileName,
1141 ioe.What() );
1142 return false;
1143 }
1144 }
1145 }
1146
1147 ++m_hash;
1148 return true;
1149}
1150
1151
1152std::shared_ptr<SYMBOL_BUFFER> LIB_BUFFER::GetBuffer( const wxString& aAlias ) const
1153{
1154 for( std::shared_ptr<SYMBOL_BUFFER> entry : m_symbols )
1155 {
1156 if( entry->GetSymbol()->GetName() == aAlias )
1157 return entry;
1158 }
1159
1160 return std::shared_ptr<SYMBOL_BUFFER>( nullptr );
1161}
1162
1163
1164bool LIB_BUFFER::HasDerivedSymbols( const wxString& aParentName ) const
1165{
1166 for( const std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1167 {
1168 if( entry->GetSymbol()->IsAlias() )
1169 {
1170 LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1171
1172 // Check for inherited symbol without a valid parent.
1173 wxCHECK( parent, false );
1174
1175 if( parent->GetName() == aParentName )
1176 return true;
1177 }
1178 }
1179
1180 return false;
1181}
1182
1183
1184void LIB_BUFFER::GetSymbolNames( wxArrayString& aSymbolNames, SYMBOL_NAME_FILTER aFilter )
1185{
1186 for( std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1187 {
1188 if( ( entry->GetSymbol()->IsAlias() && ( aFilter == SYMBOL_NAME_FILTER::ROOT_ONLY ) )
1189 || ( entry->GetSymbol()->IsRoot() && ( aFilter == SYMBOL_NAME_FILTER::DERIVED_ONLY ) ) )
1190 continue;
1191
1192 aSymbolNames.Add( UnescapeString( entry->GetSymbol()->GetName() ) );
1193 }
1194}
1195
1196
1197size_t LIB_BUFFER::GetDerivedSymbolNames( const wxString& aSymbolName, wxArrayString& aList )
1198{
1199 wxCHECK( !aSymbolName.IsEmpty(), 0 );
1200
1201 for( std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1202 {
1203 if( entry->GetSymbol()->IsAlias() )
1204 {
1205 LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1206
1207 // Check for inherited symbol without a valid parent.
1208 wxCHECK2( parent, continue );
1209
1210 if( parent->GetName() == aSymbolName )
1211 {
1212 aList.Add( entry->GetSymbol()->GetName() );
1213
1214 GetDerivedSymbolNames( entry->GetSymbol()->GetName(), aList );
1215 }
1216 }
1217 }
1218
1219 return aList.GetCount();
1220}
1221
1222
1223int LIB_BUFFER::removeChildSymbols( std::shared_ptr<SYMBOL_BUFFER>& aSymbolBuf )
1224{
1225 wxCHECK( aSymbolBuf, 0 );
1226
1227 int cnt = 0;
1228 wxArrayString derivedSymbolNames;
1229 std::deque<std::shared_ptr<SYMBOL_BUFFER>>::iterator it;
1230
1231 if( GetDerivedSymbolNames( aSymbolBuf->GetSymbol()->GetName(), derivedSymbolNames ) )
1232 {
1233 for( const wxString& symbolName : derivedSymbolNames )
1234 {
1235 it = std::find_if( m_symbols.begin(), m_symbols.end(),
1236 [symbolName]( std::shared_ptr<SYMBOL_BUFFER>& buf )
1237 {
1238 return buf->GetSymbol()->GetName() == symbolName;
1239 } );
1240
1241 wxCHECK2( it != m_symbols.end(), continue );
1242
1243 m_deleted.emplace_back( *it );
1244 m_symbols.erase( it );
1245 cnt += 1;
1246 }
1247 }
1248
1249 return cnt;
1250}
const char * name
Definition: DXF_plotter.cpp:57
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
size_t GetDerivedSymbolNames(const wxString &aSymbolName, wxArrayString &aList)
Fetch all of the symbols derived from a aSymbolName into aList.
int removeChildSymbols(std::shared_ptr< SYMBOL_BUFFER > &aSymbolBuf)
Remove all symbols derived from aParent from the library buffer.
bool DeleteBuffer(std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf)
bool CreateBuffer(LIB_SYMBOL *aCopy, SCH_SCREEN *aScreen)
Update the buffered symbol with the contents of aCopy.
void ClearDeletedBuffer()
Save stored modifications using a plugin.
void GetSymbolNames(wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
Fetch a list of root symbols names from the library buffer.
bool UpdateBuffer(std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf, LIB_SYMBOL *aCopy)
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
Buffer for deleted symbols until library is saved.
const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & GetBuffers() const
std::shared_ptr< SYMBOL_BUFFER > GetBuffer(const wxString &aAlias) const
Return all buffered symbols.
LIB_SYMBOL * GetSymbol(const wxString &aAlias) const
Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy.
bool HasDerivedSymbols(const wxString &aParentName) const
Check to see any symbols in the buffer are derived from a parent named aParentName.
const wxString m_libName
Buffered library name.
bool SaveBuffer(std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf, const wxString &aFileName, SCH_IO *aPlugin, bool aBuffer)
Return a symbol buffer with LIB_SYMBOL holding a symbolicular alias.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition: lib_id.cpp:99
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Define a library symbol object.
Definition: lib_symbol.h:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
bool IsAlias() const
Definition: lib_symbol.h:195
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:295
wxString GetName() const override
Definition: lib_symbol.h:137
SYMBOL_LIB * GetLib() const
Definition: lib_symbol.h:199
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:144
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:106
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table and frees the pointer.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:83
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:140
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_io.cpp:101
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_io.cpp:117
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_io.cpp:109
A name/value tuple with unique names and optional values.
bool Done()
Returns a string containing any errors generated during the load.
const wxString & GetErrors() const
Represents a pair of <nickname, loaded parts list>
void Start()
Spins up threads to load all the libraries in m_nicknames.
bool Join()
Finalizes the threads and combines the output into the target output map.
std::unique_ptr< SCH_SCREEN > m_screen
void SetOriginal(LIB_SYMBOL *aSymbol)
void SetSymbol(LIB_SYMBOL *aSymbol)
SYMBOL_BUFFER(LIB_SYMBOL *aSymbol=nullptr, std::unique_ptr< SCH_SCREEN > aScreen=nullptr)
LIB_SYMBOL * m_original
LIB_SYMBOL * GetBufferedSymbol(const wxString &aAlias, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &oldAlias, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
bool addLibrary(const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
Return the current Symbol Library Table.
bool ClearSymbolModified(const wxString &aAlias, const wxString &aLibrary) const
Clear the modified flag for a symbol.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
bool ClearLibraryModified(const wxString &aLibrary) const
Clear the modified flag for all symbols in a library.
LIB_SYMBOL * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
SCH_SCREEN * GetScreen(const wxString &aAlias, const wxString &aLibrary)
Return the screen used to edit a specific symbol.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
wxArrayString GetLibraryNames() const
Return the array of library names.
void SetSymbolModified(const wxString &aAlias, const wxString &aLibrary)
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Return an existing library buffer or creates one to using Symbol Library Table to get the original da...
wxString GetUniqueLibraryName() const
Return a library name that is not currently in use.
bool RemoveSymbol(const wxString &aName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
static wxString getLibraryName(const wxString &aFilePath)
Helper function to add either existing or create new library.
virtual void OnDataChanged() const
Extract library name basing on the file name.
bool IsSymbolModified(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol has unsaved modifications.
bool IsLibraryLoaded(const wxString &aLibrary) const
Return true if the library was successfully loaded.
SYMBOL_LIB_TABLE * symTable() const
Class to store a working copy of a LIB_SYMBOL object and editor context.
bool RevertLibrary(const wxString &aLibrary)
Revert unsaved changes for a symbolicular library.
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
std::set< LIB_SYMBOL * > getOriginalSymbols(const wxString &aLibrary)
Return a set of LIB_SYMBOL objects belonging to the original library.
int GetLibraryHash(const wxString &aLibrary) const
Return a library hash value to determine if it has changed.
void Preload(PROGRESS_REPORTER &aReporter)
Preloads all symbol libraries in the symbol library table using SYMBOL_ASYNC_LOADER.
bool RevertAll()
Revert all pending changes.
SYMBOL_LIBRARY_MANAGER(SCH_BASE_FRAME &aFrame)
LIB_ID RevertSymbol(const wxString &aAlias, const wxString &aLibrary)
Revert unsaved changes for a symbolicular symbol.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
SCH_BASE_FRAME & m_frame
Parent frame.
std::list< LIB_SYMBOL * > GetAliases(const wxString &aLibrary) const
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
bool SaveLibrary(const wxString &aLibrary, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aFileType=SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY)
Save library to a file, including unsaved changes.
bool HasDerivedSymbols(const wxString &aSymbolName, const wxString &aLibraryName)
Check if symbol aSymbolName in library aLibraryName is a root symbol that has derived symbols.
std::map< wxString, LIB_BUFFER > m_libs
The library buffers.
bool UpdateLibraryBuffer(const wxString &aLibrary)
Update the library buffer with a new version of the library.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.
void CreateSymbolLib(const wxString &aNickname)
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:46
STL namespace.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
wxString UnescapeString(const wxString &aSource)
Definition for symbol library class.
SYMBOL_NAME_FILTER
VECTOR3I res
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39