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
28#include <symbol_library.h>
30#include <symbol_edit_frame.h>
31#include <symbol_lib_table.h>
32#include <env_paths.h>
33#include <pgm_base.h>
34#include <project_sch.h>
35#include <kiway.h>
36#include <core/profile.h>
37#include <wx_filename.h>
39#include <symbol_async_loader.h>
40#include <progress_reporter.h>
41#include <list>
42#include <locale_io.h>
43#include <confirm.h>
44#include <string_utils.h>
45#include "lib_logger.h"
46
47
49 m_frame( aFrame )
50{
51 m_logger = new LIB_LOGGER();
52}
53
54
56{
57 delete m_logger;
58}
59
60
62{
63 SYMBOL_ASYNC_LOADER loader( symTable()->GetLogicalLibs(), symTable(), false, nullptr,
64 &aReporter );
65
66 LOCALE_IO toggle;
67
68 loader.Start();
69
70 while( !loader.Done() )
71 {
72 if( !aReporter.KeepRefreshing() )
73 break;
74
75 wxMilliSleep( 33 /* 30 FPS refresh rate */ );
76 }
77
78 loader.Join();
79
80 if( !loader.GetErrors().IsEmpty() )
81 {
82 HTML_MESSAGE_BOX dlg( &m_frame, _( "Load Error" ) );
83
84 dlg.MessageSet( _( "Errors loading symbols:" ) );
85
86 wxString msg = loader.GetErrors();
87 msg.Replace( "\n", "<BR>" );
88
89 dlg.AddHTML_Text( msg );
90 dlg.ShowModal();
91 }
92}
93
94
96{
97 for( const auto& [name, buffer] : m_libs )
98 {
99 if( buffer.IsModified() )
100 return true;
101 }
102
103 return false;
104}
105
106
108{
109 int hash = symTable()->GetModifyHash();
110
111 for( const auto& [name, buffer] : m_libs )
112 hash += buffer.GetHash();
113
114 return hash;
115}
116
117
118int SYMBOL_LIBRARY_MANAGER::GetLibraryHash( const wxString& aLibrary ) const
119{
120 const auto libBufIt = m_libs.find( aLibrary );
121
122 if( libBufIt != m_libs.end() )
123 return libBufIt->second.GetHash();
124
125 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
126
127 // return -1 if library does not exist or 0 if not modified
128 return row ? std::hash<std::string>{}( aLibrary.ToStdString() +
129 row->GetFullURI( true ).ToStdString() ) : -1;
130}
131
132
134{
135 wxArrayString res;
136
137 for( const wxString& libName : symTable()->GetLogicalLibs() )
138 {
139 // Database libraries are hidden from the symbol editor at the moment
140 if( GetLibrary( libName )->SchLibType() == SCH_IO_MGR::SCH_DATABASE )
141 continue;
142
143 res.Add( libName );
144 }
145
146 return res;
147}
148
149
151{
152 SYMBOL_LIB_TABLE_ROW* row = nullptr;
153
154 try
155 {
156 row = symTable()->FindRow( aLibrary, true );
157 }
158 catch( const IO_ERROR& e )
159 {
160 wxString msg;
161
162 msg.Printf( _( "Library '%s' not found in the Symbol Library Table." ), aLibrary );
163 DisplayErrorMessage( &m_frame, msg, e.What() );
164 }
165
166 return row;
167}
168
169
170bool SYMBOL_LIBRARY_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName,
171 SCH_IO_MGR::SCH_FILE_T aFileType )
172{
173 wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false );
174 wxFileName fn( aFileName );
175 wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
176
177 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( aFileType ) );
178 bool res = true; // assume all libraries are successfully saved
179 std::map<std::string, UTF8> properties;
180
181 properties.emplace( SCH_IO_KICAD_LEGACY::PropBuffering, "" );
182
183 auto it = m_libs.find( aLibrary );
184
185 if( it != m_libs.end() )
186 {
187 // Handle buffered library
188 LIB_BUFFER& libBuf = it->second;
189
190 const auto& symbolBuffers = libBuf.GetBuffers();
191
192 for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : symbolBuffers )
193 {
194 wxCHECK2( symbolBuf, continue );
195 if( !libBuf.SaveBuffer( *symbolBuf, aFileName, &*pi, true ) )
196 {
197 // Something went wrong, but try to save other libraries
198 res = false;
199 }
200 }
201
202 // clear the deleted symbols buffer only if data is saved to the original file
203 wxFileName original, destination( aFileName );
204 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
205
206 if( row )
207 {
208 original = row->GetFullURI();
209 original.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
210 }
211
212 destination.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
213
214 if( res && original == destination )
215 libBuf.ClearDeletedBuffer();
216 }
217 else
218 {
219 // Handle original library
220 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
221 {
222 LIB_SYMBOL* newSymbol;
223
224 try
225 {
226 if( symbol->IsAlias() )
227 {
228 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
229
230 wxCHECK_MSG( oldParent, false,
231 wxString::Format( wxT( "Derived symbol '%s' found with "
232 "undefined parent." ),
233 symbol->GetName() ) );
234
235 LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(),
236 &properties );
237
238 if( !libParent )
239 {
240 libParent = new LIB_SYMBOL( *oldParent.get() );
241 pi->SaveSymbol( aLibrary, libParent, &properties );
242 }
243
244 newSymbol = new LIB_SYMBOL( *symbol );
245 newSymbol->SetParent( libParent );
246 pi->SaveSymbol( aLibrary, newSymbol, &properties );
247 }
248 else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) )
249 {
250 pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties );
251 }
252 }
253 catch( ... )
254 {
255 res = false;
256 break;
257 }
258 }
259 }
260
261 try
262 {
263 pi->SaveLibrary( aFileName );
264 }
265 catch( ... )
266 {
267 // return false because something happens.
268 // The library is not successfully saved
269 res = false;
270 }
271
272 return res;
273}
274
275
276bool SYMBOL_LIBRARY_MANAGER::IsLibraryModified( const wxString& aLibrary ) const
277{
278 auto it = m_libs.find( aLibrary );
279 return it != m_libs.end() ? it->second.IsModified() : false;
280}
281
282
283bool SYMBOL_LIBRARY_MANAGER::IsSymbolModified( const wxString& aAlias,
284 const wxString& aLibrary ) const
285{
286 auto libIt = m_libs.find( aLibrary );
287
288 if( libIt == m_libs.end() )
289 return false;
290
291 const LIB_BUFFER& buf = libIt->second;
292 const std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
293
294 return symbolBuf ? symbolBuf->IsModified() : false;
295}
296
297
298void SYMBOL_LIBRARY_MANAGER::SetSymbolModified( const wxString& aAlias, const wxString& aLibrary )
299{
300 auto libIt = m_libs.find( aLibrary );
301
302 if( libIt == m_libs.end() )
303 return;
304
305 const LIB_BUFFER& buf = libIt->second;
306 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
307
308 wxCHECK( symbolBuf, /* void */ );
309
310 symbolBuf->GetScreen()->SetContentModified();
311}
312
313
314bool SYMBOL_LIBRARY_MANAGER::ClearLibraryModified( const wxString& aLibrary ) const
315{
316 auto libIt = m_libs.find( aLibrary );
317
318 if( libIt == m_libs.end() )
319 return false;
320
321 for( auto& symbolBuf : libIt->second.GetBuffers() )
322 {
323 SCH_SCREEN* screen = symbolBuf->GetScreen();
324
325 if( screen )
326 screen->SetContentModified( false );
327 }
328
329 return true;
330}
331
332
334 const wxString& aLibrary ) const
335{
336 auto libIt = m_libs.find( aLibrary );
337
338 if( libIt == m_libs.end() )
339 return false;
340
341 auto symbolBuf = libIt->second.GetBuffer( aAlias );
342 wxCHECK( symbolBuf, false );
343
344 symbolBuf->GetScreen()->SetContentModified( false );
345 return true;
346}
347
348
349bool SYMBOL_LIBRARY_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const
350{
351 wxCHECK( LibraryExists( aLibrary ), true );
352
353 return !symTable()->IsSymbolLibWritable( aLibrary );
354}
355
356
357bool SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded( const wxString& aLibrary ) const
358{
359 wxCHECK( LibraryExists( aLibrary ), false );
360
361 return symTable()->IsSymbolLibLoaded( aLibrary );
362}
363
364
365std::list<LIB_SYMBOL*> SYMBOL_LIBRARY_MANAGER::GetAliases( const wxString& aLibrary ) const
366{
367 std::list<LIB_SYMBOL*> ret;
368 wxCHECK( LibraryExists( aLibrary ), ret );
369
370 auto libIt = m_libs.find( aLibrary );
371
372 if( libIt != m_libs.end() )
373 {
374 for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : libIt->second.GetBuffers() )
375 ret.push_back( &symbolBuf->GetSymbol() );
376 }
377 else
378 {
379 std::vector<LIB_SYMBOL*> aliases;
380
381 try
382 {
383 symTable()->LoadSymbolLib( aliases, aLibrary );
384 }
385 catch( const IO_ERROR& e )
386 {
387 wxLogWarning( e.Problem() );
388 }
389
390 std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) );
391 }
392
393 return ret;
394}
395
396
398 const wxString& aLibrary )
399{
400 wxCHECK( LibraryExists( aLibrary ), nullptr );
401
402 // try the library buffers first
403 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
404 LIB_SYMBOL* bufferedSymbol = libBuf.GetSymbol( aAlias );
405
406 if( !bufferedSymbol ) // no buffer symbol found
407 {
408 // create a copy of the symbol
409 try
410 {
411 LIB_SYMBOL* symbol = symTable()->LoadSymbol( aLibrary, aAlias );
412
413 if( symbol == nullptr )
414 THROW_IO_ERROR( _( "Symbol not found." ) );
415
416 LIB_SYMBOL* bufferedParent = nullptr;
417
418 // Create parent symbols on demand so parent symbol can be set.
419 if( symbol->IsAlias() )
420 {
421 std::shared_ptr<LIB_SYMBOL> parent = symbol->GetParent().lock();
422 wxCHECK_MSG( parent, nullptr,
423 wxString::Format( "Derived symbol '%s' found with undefined parent.",
424 symbol->GetName() ) );
425
426 // Check if the parent symbol buffer has already be created.
427 bufferedParent = libBuf.GetSymbol( parent->GetName() );
428
429 if( !bufferedParent )
430 {
431 auto newParent = std::make_unique<LIB_SYMBOL>( *parent.get() );
432 bufferedParent = newParent.get();
433 libBuf.CreateBuffer( std::move( newParent ), std::make_unique<SCH_SCREEN>() );
434 }
435 }
436
437 auto newSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
438 bufferedSymbol = newSymbol.get();
439
440 if( bufferedParent )
441 newSymbol->SetParent( bufferedParent );
442
443 libBuf.CreateBuffer( std::move( newSymbol ), std::make_unique<SCH_SCREEN>() );
444 }
445 catch( const IO_ERROR& e )
446 {
447 wxString msg;
448
449 msg.Printf( _( "Error loading symbol %s from library '%s'." ), aAlias, aLibrary );
450 DisplayErrorMessage( &m_frame, msg, e.What() );
451 bufferedSymbol = nullptr;
452 }
453 }
454
455 return bufferedSymbol;
456}
457
458
459SCH_SCREEN* SYMBOL_LIBRARY_MANAGER::GetScreen( const wxString& aAlias, const wxString& aLibrary )
460{
461 wxCHECK( LibraryExists( aLibrary ), nullptr );
462 wxCHECK( !aAlias.IsEmpty(), nullptr );
463 auto it = m_libs.find( aLibrary );
464 wxCHECK( it != m_libs.end(), nullptr );
465
466 LIB_BUFFER& buf = it->second;
467 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
468
469 return symbolBuf ? symbolBuf->GetScreen() : nullptr;
470}
471
472
473bool SYMBOL_LIBRARY_MANAGER::UpdateSymbol( LIB_SYMBOL* aSymbol, const wxString& aLibrary )
474{
475 wxCHECK( LibraryExists( aLibrary ), false );
476 wxCHECK( aSymbol, false );
477
478 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
479 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aSymbol->GetName() );
480
481 if( symbolBuf ) // Existing symbol.
482 {
483 LIB_SYMBOL& bufferedSymbol = symbolBuf->GetSymbol();
484
485 // If we are coming from a different library, the library ID needs to be preserved
486 const LIB_ID libId = bufferedSymbol.GetLibId();
487 bufferedSymbol = *aSymbol;
488 bufferedSymbol.SetLibId( libId );
489
490 symbolBuf->GetScreen()->SetContentModified();
491 }
492 else // New symbol
493 {
494 auto symbolCopy = std::make_unique<LIB_SYMBOL>( *aSymbol, nullptr );
495
496 symbolCopy->SetLibId( LIB_ID( aLibrary, aSymbol->GetLibId().GetLibItemName() ) );
497
498 auto newScreen = std::make_unique<SCH_SCREEN>();
499 SCH_SCREEN& screen = *newScreen;
500 libBuf.CreateBuffer( std::move( symbolCopy ), std::move( newScreen ) );
501 screen.SetContentModified();
502 }
503
504 return true;
505}
506
507
508bool SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename( LIB_SYMBOL* aSymbol, const wxString& aOldName,
509 const wxString& aLibrary )
510{
511 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
512 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aOldName );
513
514 wxCHECK( symbolBuf && aSymbol, false );
515
516 libBuf.UpdateBuffer( *symbolBuf, *aSymbol );
518
519 return true;
520}
521
522
523LIB_ID SYMBOL_LIBRARY_MANAGER::RevertSymbol( const wxString& aAlias, const wxString& aLibrary )
524{
525 auto it = m_libs.find( aLibrary );
526
527 if( it == m_libs.end() ) // no items to flush
528 return LIB_ID( aLibrary, aAlias );
529
530 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = it->second.GetBuffer( aAlias );
531 wxCHECK( symbolBuf, LIB_ID( aLibrary, aAlias ) );
532 LIB_SYMBOL original( symbolBuf->GetOriginal() );
533
534 if( original.GetName() != aAlias )
535 {
536 UpdateSymbolAfterRename( &original, aAlias, aLibrary );
537 }
538 else
539 {
540 // copy the initial data to the current symbol to restore
541 symbolBuf->GetSymbol() = original;
543 }
544
545 return LIB_ID( aLibrary, original.GetName() );
546}
547
548
549bool SYMBOL_LIBRARY_MANAGER::RevertLibrary( const wxString& aLibrary )
550{
551 auto it = m_libs.find( aLibrary );
552
553 if( it == m_libs.end() ) // nothing to reverse
554 return false;
555
556 m_libs.erase( it );
558
559 return true;
560}
561
562
564{
565 bool retv = true;
566
567 // Nothing to revert.
568 if( GetHash() == 0 )
569 return true;
570
571 for( const auto& lib : m_libs )
572 {
573 if( !lib.second.IsModified() )
574 continue;
575
576 for( const std::shared_ptr<SYMBOL_BUFFER>& buffer : lib.second.GetBuffers() )
577 {
578 if( !buffer->IsModified() )
579 continue;
580
581 RevertSymbol( lib.first, buffer->GetOriginal().GetName() );
582 }
583 }
584
585 return retv;
586}
587
588
589bool SYMBOL_LIBRARY_MANAGER::RemoveSymbol( const wxString& aAlias, const wxString& aLibrary )
590{
591 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
592 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.GetBuffer( aAlias );
593 wxCHECK( symbolBuf, false );
594
595 bool retv = true;
596
597 retv &= libBuf.DeleteBuffer( *symbolBuf );
599
600 return retv;
601}
602
603
605 const wxString& aLibrary ) const
606{
607 // Try the library buffers first
608 auto libIt = m_libs.find( aLibrary );
609
610 if( libIt != m_libs.end() )
611 {
612 LIB_SYMBOL* symbol = libIt->second.GetSymbol( aAlias );
613
614 if( symbol )
615 return symbol;
616 }
617
618 // Get the original symbol
619 LIB_SYMBOL* alias = nullptr;
620
621 try
622 {
623 alias = symTable()->LoadSymbol( aLibrary, aAlias );
624 }
625 catch( const IO_ERROR& e )
626 {
627 wxString msg;
628
629 msg.Printf( _( "Cannot load symbol '%s' from library '%s'." ), aAlias, aLibrary );
630 DisplayErrorMessage( &m_frame, msg, e.What() );
631 }
632
633 return alias;
634}
635
636
637bool SYMBOL_LIBRARY_MANAGER::SymbolExists( const wxString& aAlias, const wxString& aLibrary ) const
638{
639 auto libBufIt = m_libs.find( aLibrary );
640 LIB_SYMBOL* alias = nullptr;
641
642 if( libBufIt != m_libs.end() )
643 return !!libBufIt->second.GetBuffer( aAlias );
644
645 try
646 {
647 alias = symTable()->LoadSymbol( aLibrary, aAlias );
648 }
649 catch( IO_ERROR& )
650 {
651 // checking if certain symbol exists, so its absence is perfectly fine
652 }
653
654 return alias != nullptr;
655}
656
657
658bool SYMBOL_LIBRARY_MANAGER::LibraryExists( const wxString& aLibrary, bool aCheckEnabled ) const
659{
660 if( aLibrary.IsEmpty() )
661 return false;
662
663 if( m_libs.count( aLibrary ) > 0 )
664 return true;
665
666 return symTable()->HasLibrary( aLibrary, aCheckEnabled );
667}
668
669
671{
672 wxString name = "New_Library";
673
674 if( !LibraryExists( name ) )
675 return name;
676
677 name += "_";
678
679 for( unsigned int i = 0; i < std::numeric_limits<unsigned int>::max(); ++i )
680 {
681 if( !LibraryExists( name + wxString::Format( "%u", i ) ) )
682 return name + wxString::Format( "%u", i );
683 }
684
685 wxFAIL;
686 return wxEmptyString;
687}
688
689
690void SYMBOL_LIBRARY_MANAGER::GetSymbolNames( const wxString& aLibraryName,
691 wxArrayString& aSymbolNames,
692 SYMBOL_NAME_FILTER aFilter )
693{
694 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
695
696 libBuf.GetSymbolNames( aSymbolNames, aFilter );
697}
698
699
700bool SYMBOL_LIBRARY_MANAGER:: HasDerivedSymbols( const wxString& aSymbolName,
701 const wxString& aLibraryName )
702{
703 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
704
705 return libBuf.HasDerivedSymbols( aSymbolName );
706}
707
708
710{
711 return symTable()->GetLogicalLibs().size();
712}
713
714
715wxString SYMBOL_LIBRARY_MANAGER::getLibraryName( const wxString& aFilePath )
716{
717 wxFileName fn( aFilePath );
718 return fn.GetName();
719}
720
721
722bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate,
723 SYMBOL_LIB_TABLE& aTable )
724{
725 wxString libName = getLibraryName( aFilePath );
726 wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
727
728 // try to use path normalized to an environmental variable or project path
729 wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
730
731 SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath );
732
733 if( schFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
734 schFileType = SCH_IO_MGR::SCH_LEGACY;
735
736 wxString typeName = SCH_IO_MGR::ShowType( schFileType );
737 SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
738 aTable.InsertRow( libRow );
739
740 if( aCreate )
741 {
742 wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY, false );
743
744 try
745 {
746 aTable.CreateSymbolLib( libName );
747 }
748 catch( const IO_ERROR& )
749 {
750 aTable.RemoveRow( libRow );
751 return false;
752 }
753 }
754
756
757 return true;
758}
759
760
762{
764}
765
766
767std::set<LIB_SYMBOL*> SYMBOL_LIBRARY_MANAGER::getOriginalSymbols( const wxString& aLibrary )
768{
769 std::set<LIB_SYMBOL*> symbols;
770 wxCHECK( LibraryExists( aLibrary ), symbols );
771
772 try
773 {
774 wxArrayString aliases;
775 symTable()->EnumerateSymbolLib( aLibrary, aliases );
776
777 for( const auto& aliasName : aliases )
778 {
779 LIB_SYMBOL* alias = symTable()->LoadSymbol( aLibrary, aliasName );
780 symbols.insert( alias );
781 }
782 }
783 catch( const IO_ERROR& e )
784 {
785 wxString msg;
786
787 msg.Printf( _( "Cannot enumerate library '%s'." ), aLibrary );
788 DisplayErrorMessage( &m_frame, msg, e.What() );
789 }
790
791 return symbols;
792}
793
794
796{
797 auto it = m_libs.find( aLibrary );
798
799 if( it != m_libs.end() )
800 return it->second;
801
802 // The requested buffer does not exist yet, so create one
803 auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) );
804 LIB_BUFFER& buf = ret.first->second;
805
806 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
807 {
808 if( symbol->IsAlias() )
809 {
810 std::shared_ptr<LIB_SYMBOL> oldParent = symbol->GetParent().lock();
811
812 wxCHECK_MSG( oldParent, buf,
813 wxString::Format( "Derived symbol '%s' found with undefined parent.",
814 symbol->GetName() ) );
815
816 LIB_SYMBOL* libParent = buf.GetSymbol( oldParent->GetName() );
817
818 if( !libParent )
819 {
820 auto newParent = std::make_unique<LIB_SYMBOL>( *oldParent.get() );
821 libParent = newParent.get();
822 buf.CreateBuffer( std::move( newParent ), std::make_unique<SCH_SCREEN>() );
823 }
824
825 auto newSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
826 newSymbol->SetParent( libParent );
827 buf.CreateBuffer( std::move( newSymbol ), std::make_unique<SCH_SCREEN>() );
828 }
829 else if( !buf.GetSymbol( symbol->GetName() ) )
830 {
831 buf.CreateBuffer( std::make_unique<LIB_SYMBOL>( *symbol ),
832 std::make_unique<SCH_SCREEN>() );
833 }
834 }
835
836 return buf;
837}
838
839
840bool SYMBOL_LIBRARY_MANAGER::UpdateLibraryBuffer( const wxString& aLibrary )
841{
842 try
843 {
844 m_libs.erase( aLibrary );
845 getLibraryBuffer( aLibrary );
846 }
847 catch(const std::exception& e)
848 {
849 wxLogError( _( "Error updating library buffer: %s" ), e.what() );
850 return false;
851 }
852 catch( const IO_ERROR& e )
853 {
854 wxLogError( _( "Error updating library buffer: %s" ), e.What() );
855 return false;
856 }
857 catch(...)
858 {
859 wxLogError( _( "Error updating library buffer." ) );
860 return false;
861 }
862
863 getLibraryBuffer( aLibrary );
864
865 return true;
866}
867
868
869SYMBOL_BUFFER::SYMBOL_BUFFER( std::unique_ptr<LIB_SYMBOL> aSymbol,
870 std::unique_ptr<SCH_SCREEN> aScreen ) :
871 m_screen( std::move( aScreen ) ), m_symbol( std::move( aSymbol ) )
872{
873 wxASSERT( m_symbol );
874 m_original = std::make_unique<LIB_SYMBOL>( *m_symbol );
875 wxASSERT( m_original );
876}
877
878
880{
881}
882
883
884void SYMBOL_BUFFER::SetSymbol( std::unique_ptr<LIB_SYMBOL> aSymbol )
885{
886 wxCHECK( m_symbol != aSymbol, /* void */ );
887 wxASSERT( aSymbol );
888 m_symbol = std::move( aSymbol );
889
890 // If the symbol moves libraries then the original moves with it
891 if( m_original->GetLibId().GetLibNickname() != m_symbol->GetLibId().GetLibNickname() )
892 {
893 m_original->SetLibId( LIB_ID( m_symbol->GetLibId().GetLibNickname(),
894 m_original->GetLibId().GetLibItemName() ) );
895 }
896}
897
898
899void SYMBOL_BUFFER::SetOriginal( std::unique_ptr<LIB_SYMBOL> aSymbol )
900{
901 wxCHECK( m_original != aSymbol, /* void */ );
902 wxASSERT( aSymbol );
903 m_original = std::move( aSymbol );
904
905 // The original is not allowed to have a different library than its symbol
906 if( m_original->GetLibId().GetLibNickname() != m_symbol->GetLibId().GetLibNickname() )
907 {
908 m_original->SetLibId( LIB_ID( m_symbol->GetLibId().GetLibNickname(),
909 m_original->GetLibId().GetLibItemName() ) );
910 }
911}
912
913
915{
916 return m_screen && m_screen->IsContentModified();
917}
918
919
920LIB_SYMBOL* LIB_BUFFER::GetSymbol( const wxString& aAlias ) const
921{
922 auto buf = GetBuffer( aAlias );
923
924 if( !buf )
925 return nullptr;
926
927 LIB_SYMBOL& symbol = buf->GetSymbol();
928 return &symbol;
929}
930
931
932bool LIB_BUFFER::CreateBuffer( std::unique_ptr<LIB_SYMBOL> aCopy,
933 std::unique_ptr<SCH_SCREEN> aScreen )
934{
935 wxASSERT( aCopy );
936 wxASSERT( aCopy->GetLib() == nullptr );
937
938 // Set the parent library name,
939 // otherwise it is empty as no library has been given as the owner during object construction
940 LIB_ID libId = aCopy->GetLibId();
941 libId.SetLibNickname( m_libName );
942 aCopy->SetLibId( libId );
943
944 auto symbolBuf = std::make_shared<SYMBOL_BUFFER>( std::move( aCopy ), std::move( aScreen ) );
945 m_symbols.push_back( symbolBuf );
946
947 ++m_hash;
948
949 return true;
950}
951
952
953bool LIB_BUFFER::UpdateBuffer( SYMBOL_BUFFER& aSymbolBuf, const LIB_SYMBOL& aCopy )
954{
955 LIB_SYMBOL& bufferedSymbol = aSymbolBuf.GetSymbol();
956
957 bufferedSymbol = aCopy;
958 ++m_hash;
959
960 return true;
961}
962
963
965{
966 const auto sameBufferPredicate = [&]( const std::shared_ptr<SYMBOL_BUFFER>& aBuf )
967 {
968 return aBuf.get() == &aSymbolBuf;
969 };
970
971 auto symbolBufIt = std::find_if( m_symbols.begin(), m_symbols.end(), sameBufferPredicate );
972 wxCHECK( symbolBufIt != m_symbols.end(), false );
973
974 bool retv = true;
975
976 // Remove all derived symbols to prevent broken inheritance.
977 if( HasDerivedSymbols( aSymbolBuf.GetSymbol().GetName() )
978 && ( removeChildSymbols( aSymbolBuf ) == 0 ) )
979 {
980 retv = false;
981 }
982
983 m_deleted.emplace_back( *symbolBufIt );
984 m_symbols.erase( symbolBufIt );
985 ++m_hash;
986
987 return retv;
988}
989
990
991bool LIB_BUFFER::SaveBuffer( SYMBOL_BUFFER& aSymbolBuf, const wxString& aFileName, SCH_IO* aPlugin,
992 bool aBuffer )
993{
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 std::map<std::string, UTF8> properties;
1000 properties.emplace( SCH_IO_KICAD_LEGACY::PropBuffering, "" );
1001
1002 LIB_SYMBOL& libSymbol = aSymbolBuf.GetSymbol();
1003
1004 {
1005 LIB_SYMBOL& originalSymbol = aSymbolBuf.GetOriginal();
1006 const wxString originalName = originalSymbol.GetName();
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, originalName ) )
1014 aPlugin->DeleteSymbol( aFileName, originalName, &properties );
1015 }
1016 catch( const IO_ERROR& ioe )
1017 {
1018 wxLogError( errorMsg, UnescapeString( originalName ), aFileName, ioe.What() );
1019 return false;
1020 }
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 auto originalParent = std::make_unique<LIB_SYMBOL>( *bufferedParent.get() );
1073 LIB_SYMBOL& parentRef = *originalParent;
1074 aSymbolBuf.SetOriginal( std::move( originalParent ) );
1075
1076 auto newSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1077 newSymbol->SetParent( &parentRef );
1078 aSymbolBuf.SetOriginal( std::move( newSymbol ) );
1079 }
1080 else
1081 {
1082 newCachedSymbol->SetParent( cachedParent );
1083
1084 try
1085 {
1086 aPlugin->SaveSymbol( aFileName, newCachedSymbol, aBuffer ? &properties : nullptr );
1087 }
1088 catch( const IO_ERROR& ioe )
1089 {
1090 wxLogError( errorMsg, UnescapeString( newCachedSymbol->GetName() ), aFileName,
1091 ioe.What() );
1092 return false;
1093 }
1094
1095 auto originalBufferedParent = GetBuffer( bufferedParent->GetName() );
1096 wxCHECK( originalBufferedParent, false );
1097
1098 auto newSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1099 newSymbol->SetParent( &originalBufferedParent->GetSymbol() );
1100 aSymbolBuf.SetOriginal( std::move( newSymbol ) );
1101 }
1102 }
1103 else
1104 {
1105 parentSymbol = new LIB_SYMBOL( libSymbol );
1106
1107 try
1108 {
1109 aPlugin->SaveSymbol( aFileName, parentSymbol, aBuffer ? &properties : nullptr );
1110 }
1111 catch( const IO_ERROR& ioe )
1112 {
1113 wxLogError( errorMsg, UnescapeString( libSymbol.GetName() ), aFileName, ioe.What() );
1114 return false;
1115 }
1116
1117 aSymbolBuf.SetOriginal( std::make_unique<LIB_SYMBOL>( libSymbol ) );
1118 }
1119
1120 wxArrayString derivedSymbols;
1121
1122 // Reparent all symbols derived from the saved symbol.
1123 if( GetDerivedSymbolNames( libSymbol.GetName(), derivedSymbols ) != 0 )
1124 {
1125 // Save the derived symbols.
1126 for( const wxString& entry : derivedSymbols )
1127 {
1128 std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
1129
1130 wxCHECK2( symbol, continue );
1131
1132 LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( symbol->GetSymbol() );
1133 derivedSymbol->SetParent( parentSymbol );
1134
1135 try
1136 {
1137 aPlugin->SaveSymbol( aFileName, new LIB_SYMBOL( *derivedSymbol ),
1138 aBuffer ? &properties : nullptr );
1139 }
1140 catch( const IO_ERROR& ioe )
1141 {
1142 wxLogError( errorMsg, UnescapeString( derivedSymbol->GetName() ), aFileName,
1143 ioe.What() );
1144 return false;
1145 }
1146 }
1147 }
1148
1149 ++m_hash;
1150 return true;
1151}
1152
1153
1154std::shared_ptr<SYMBOL_BUFFER> LIB_BUFFER::GetBuffer( const wxString& aAlias ) const
1155{
1156 for( std::shared_ptr<SYMBOL_BUFFER> entry : m_symbols )
1157 {
1158 if( entry->GetSymbol().GetName() == aAlias )
1159 return entry;
1160 }
1161
1162 return std::shared_ptr<SYMBOL_BUFFER>( nullptr );
1163}
1164
1165
1166bool LIB_BUFFER::HasDerivedSymbols( const wxString& aParentName ) const
1167{
1168 for( const std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1169 {
1170 if( entry->GetSymbol().IsAlias() )
1171 {
1172 LIB_SYMBOL_SPTR parent = entry->GetSymbol().GetParent().lock();
1173
1174 // Check for inherited symbol without a valid parent.
1175 wxCHECK( parent, false );
1176
1177 if( parent->GetName() == aParentName )
1178 return true;
1179 }
1180 }
1181
1182 return false;
1183}
1184
1185
1186void LIB_BUFFER::GetSymbolNames( wxArrayString& aSymbolNames, SYMBOL_NAME_FILTER aFilter )
1187{
1188 for( std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1189 {
1190 const LIB_SYMBOL& symbol = entry->GetSymbol();
1191 if( ( symbol.IsAlias() && ( aFilter == SYMBOL_NAME_FILTER::ROOT_ONLY ) )
1192 || ( symbol.IsRoot() && ( aFilter == SYMBOL_NAME_FILTER::DERIVED_ONLY ) ) )
1193 {
1194 continue;
1195 }
1196 aSymbolNames.Add( UnescapeString( symbol.GetName() ) );
1197 }
1198}
1199
1200
1201size_t LIB_BUFFER::GetDerivedSymbolNames( const wxString& aSymbolName, wxArrayString& aList )
1202{
1203 wxCHECK( !aSymbolName.IsEmpty(), 0 );
1204
1205 for( std::shared_ptr<SYMBOL_BUFFER>& entry : m_symbols )
1206 {
1207 const LIB_SYMBOL& symbol = entry->GetSymbol();
1208 if( symbol.IsAlias() )
1209 {
1210 LIB_SYMBOL_SPTR parent = symbol.GetParent().lock();
1211
1212 // Check for inherited symbol without a valid parent.
1213 wxCHECK2( parent, continue );
1214
1215 if( parent->GetName() == aSymbolName )
1216 {
1217 aList.Add( symbol.GetName() );
1218
1219 GetDerivedSymbolNames( symbol.GetName(), aList );
1220 }
1221 }
1222 }
1223
1224 return aList.GetCount();
1225}
1226
1227
1229{
1230 int cnt = 0;
1231 wxArrayString derivedSymbolNames;
1232 std::deque<std::shared_ptr<SYMBOL_BUFFER>>::iterator it;
1233
1234 if( GetDerivedSymbolNames( aSymbolBuf.GetSymbol().GetName(), derivedSymbolNames ) )
1235 {
1236 for( const wxString& symbolName : derivedSymbolNames )
1237 {
1238 it = std::find_if( m_symbols.begin(), m_symbols.end(),
1239 [symbolName]( std::shared_ptr<SYMBOL_BUFFER>& buf )
1240 {
1241 return buf->GetSymbol().GetName() == symbolName;
1242 } );
1243
1244 wxCHECK2( it != m_symbols.end(), continue );
1245
1246 m_deleted.emplace_back( *it );
1247 m_symbols.erase( it );
1248 cnt += 1;
1249 }
1250 }
1251
1252 return cnt;
1253}
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.
bool CreateBuffer(std::unique_ptr< LIB_SYMBOL > aCopy, std::unique_ptr< SCH_SCREEN > aScreen)
Update the buffered symbol with the contents of aCopy.
bool DeleteBuffer(const SYMBOL_BUFFER &aSymbolBuf)
Delete the given symbol buffer from the library buffer.
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.
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.
bool SaveBuffer(SYMBOL_BUFFER &aSymbolBuf, const wxString &aFileName, SCH_IO *aPlugin, bool aBuffer)
Return a symbol buffer with LIB_SYMBOL holding a symbolicular alias.
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.
int removeChildSymbols(const SYMBOL_BUFFER &aSymbolBuf)
Remove all symbols derived from aParent from the library buffer.
bool HasDerivedSymbols(const wxString &aParentName) const
Check to see any symbols in the buffer are derived from a parent named aParentName.
bool UpdateBuffer(SYMBOL_BUFFER &aSymbolBuf, const LIB_SYMBOL &aCopy)
const wxString m_libName
Buffered library name.
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
Define a library symbol object.
Definition: lib_symbol.h:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:194
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
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 void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_io.cpp:108
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_io.cpp:116
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_io.cpp:100
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.
Store a working copy of a library.
std::unique_ptr< LIB_SYMBOL > m_symbol
std::unique_ptr< SCH_SCREEN > m_screen
void SetSymbol(std::unique_ptr< LIB_SYMBOL > aSymbol)
LIB_SYMBOL & GetSymbol() const
SYMBOL_BUFFER(std::unique_ptr< LIB_SYMBOL > aSymbol=nullptr, std::unique_ptr< SCH_SCREEN > aScreen=nullptr)
std::unique_ptr< LIB_SYMBOL > m_original
LIB_SYMBOL & GetOriginal() const
void SetOriginal(std::unique_ptr< LIB_SYMBOL > aSymbol)
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 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 addLibrary(const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE &aTable)
Return the current Symbol Library Table.
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:1060
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