KiCad PCB EDA Suite
project_rescue.cpp File Reference
#include <sch_draw_panel.h>
#include <class_library.h>
#include <confirm.h>
#include <connection_graph.h>
#include <invoke_sch_dialog.h>
#include <kiway.h>
#include <lib_view_frame.h>
#include <project_rescue.h>
#include <sch_component.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_COMPONENT *, wxString > COMPONENT_NAME_PAIR
 

Functions

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

Typedef Documentation

◆ COMPONENT_NAME_PAIR

typedef std::pair<SCH_COMPONENT*, wxString> COMPONENT_NAME_PAIR

Definition at line 44 of file project_rescue.cpp.

Function Documentation

◆ find_component()

static LIB_PART* find_component ( const wxString &  aName,
PART_LIBS aLibs,
bool  aCached 
)
static

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

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

Definition at line 89 of file project_rescue.cpp.

90 {
91  LIB_PART *part = NULL;
92  wxString new_name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
93 
94  for( PART_LIB& each_lib : *aLibs )
95  {
96  if( aCached && !each_lib.IsCache() )
97  continue;
98 
99  if( !aCached && each_lib.IsCache() )
100  continue;
101 
102  part = each_lib.FindPart( new_name );
103 
104  if( part )
105  break;
106  }
107 
108  return part;
109 }
#define NULL
Define a library symbol object.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
Object used to load, save, search, and otherwise manipulate symbol library files.

References LIB_ID::FixIllegalChars(), LIB_ID::ID_SCH, and NULL.

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

◆ get_components()

static void get_components ( SCHEMATIC aSchematic,
std::vector< SCH_COMPONENT * > &  aComponents 
)
static

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

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

Parameters
aComponents- 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_COMPONENT_T ) )
71  aComponents.push_back( static_cast<SCH_COMPONENT*>( aItem ) );
72  }
73 
74  if( aComponents.empty() )
75  return;
76 
77  // sort aComponents by lib part. Components will be grouped by same lib part.
78  std::sort( aComponents.begin(), aComponents.end(), sort_by_libid );
79 }
static bool sort_by_libid(const SCH_COMPONENT *ref, SCH_COMPONENT *cmp)
SCH_SHEET & Root() const
Definition: schematic.h:97
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:528

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

Referenced by RESCUER::RESCUER().

◆ 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
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:132

References SCHEMATIC::GetFileName(), and LegacySymbolLibFileExtension.

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

◆ sort_by_libid()

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

Definition at line 48 of file project_rescue.cpp.

49 {
50  return ref->GetLibId() < cmp->GetLibId();
51 }
const LIB_ID & GetLibId() const

References SCH_COMPONENT::GetLibId().

Referenced by get_components().