KiCad PCB EDA Suite
project_rescue.cpp File Reference
#include <sch_draw_panel.h>
#include <symbol_library.h>
#include <confirm.h>
#include <connection_graph.h>
#include <invoke_sch_dialog.h>
#include <kiway.h>
#include <symbol_viewer_frame.h>
#include <project_rescue.h>
#include <sch_symbol.h>
#include <sch_sheet.h>
#include <sch_edit_frame.h>
#include <schematic.h>
#include <symbol_lib_table.h>
#include <wildcards_and_files_ext.h>
#include <cctype>
#include <map>

Go to the source code of this file.

Typedefs

typedef std::pair< SCH_SYMBOL *, wxString > SYMBOL_NAME_PAIR
 

Functions

static bool sort_by_libid (const SCH_SYMBOL *ref, SCH_SYMBOL *cmp)
 
static void getSymbols (SCHEMATIC *aSchematic, std::vector< SCH_SYMBOL * > &aSymbols)
 Fill a vector with all of the project's symbols, to ease iterating over them. More...
 
static LIB_SYMBOLfindSymbol (const wxString &aName, SYMBOL_LIBS *aLibs, bool aCached)
 Search the libraries for the first symbol with a given name. More...
 
static wxFileName GetRescueLibraryFileName (SCHEMATIC *aSchematic)
 

Typedef Documentation

◆ SYMBOL_NAME_PAIR

typedef std::pair<SCH_SYMBOL*, wxString> SYMBOL_NAME_PAIR

Definition at line 44 of file project_rescue.cpp.

Function Documentation

◆ findSymbol()

static LIB_SYMBOL* findSymbol ( const wxString &  aName,
SYMBOL_LIBS aLibs,
bool  aCached 
)
static

Search the libraries for the first symbol with a given name.

Parameters
aName- name to search for
aLibs- the loaded SYMBOL_LIBS
aCached- whether we are looking for the cached symbol

Definition at line 89 of file project_rescue.cpp.

90 {
91  LIB_SYMBOL *symbol = nullptr;
92  // wxString new_name = LIB_ID::FixIllegalChars( aName, false );
93 
94  for( SYMBOL_LIB& each_lib : *aLibs )
95  {
96  if( aCached && !each_lib.IsCache() )
97  continue;
98 
99  if( !aCached && each_lib.IsCache() )
100  continue;
101 
102  symbol = each_lib.FindSymbol( aName );
103 
104  if( symbol )
105  break;
106  }
107 
108  return symbol;
109 }
Object used to load, save, search, and otherwise manipulate symbol library files.
Define a library symbol object.
Definition: lib_symbol.h:96

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues(), and RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

◆ GetRescueLibraryFileName()

static wxFileName GetRescueLibraryFileName ( SCHEMATIC aSchematic)
static

Definition at line 112 of file project_rescue.cpp.

113 {
114  wxFileName fn = aSchematic->GetFileName();
115  fn.SetName( fn.GetName() + wxT( "-rescue" ) );
116  fn.SetExt( LegacySymbolLibFileExtension );
117  return fn;
118 }
const std::string LegacySymbolLibFileExtension
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:161

References SCHEMATIC::GetFileName(), and LegacySymbolLibFileExtension.

Referenced by SYMBOL_LIB_TABLE_RESCUER::AddSymbol(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), LEGACY_RESCUER::OpenRescueLibrary(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

◆ getSymbols()

static void getSymbols ( SCHEMATIC aSchematic,
std::vector< SCH_SYMBOL * > &  aSymbols 
)
static

Fill a vector with all of the project's symbols, to ease iterating over them.

The list is sorted by LIB_ID, therefore symbols using the same library symbol are grouped, allowing later faster calculations (one library search by group of symbols)

Parameters
aSymbolsis a vector that will take the symbols.

Definition at line 63 of file project_rescue.cpp.

64 {
65  SCH_SCREENS screens( aSchematic->Root() );
66 
67  // Get the full list
68  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
69  {
70  for( auto aItem : screen->Items().OfType( SCH_SYMBOL_T ) )
71  aSymbols.push_back( static_cast<SCH_SYMBOL*>( aItem ) );
72  }
73 
74  if( aSymbols.empty() )
75  return;
76 
77  // sort aSymbols by lib symbol. symbols will be grouped by same lib symbol.
78  std::sort( aSymbols.begin(), aSymbols.end(), sort_by_libid );
79 }
static bool sort_by_libid(const SCH_SYMBOL *ref, SCH_SYMBOL *cmp)
SCH_SHEET & Root() const
Definition: schematic.h:92
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:557

References SCHEMATIC::Root(), SCH_SYMBOL_T, and sort_by_libid().

Referenced by RESCUER::RESCUER().

◆ sort_by_libid()

static bool sort_by_libid ( const SCH_SYMBOL ref,
SCH_SYMBOL cmp 
)
static

Definition at line 48 of file project_rescue.cpp.

49 {
50  return ref->GetLibId() < cmp->GetLibId();
51 }
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:147

References SCH_SYMBOL::GetLibId().

Referenced by getSymbols().