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 <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 (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 ()
 

Typedef Documentation

◆ COMPONENT_NAME_PAIR

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

Definition at line 43 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 88 of file project_rescue.cpp.

89 {
90  LIB_PART *part = NULL;
91  wxString new_name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
92 
93  for( PART_LIB& each_lib : *aLibs )
94  {
95  if( aCached && !each_lib.IsCache() )
96  continue;
97 
98  if( !aCached && each_lib.IsCache() )
99  continue;
100 
101  part = each_lib.FindPart( new_name );
102 
103  if( part )
104  break;
105  }
106 
107  return part;
108 }
#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 ( 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 62 of file project_rescue.cpp.

63 {
64  SCH_SCREENS screens;
65 
66  // Get the full list
67  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
68  {
69  for( auto aItem : screen->Items().OfType( SCH_COMPONENT_T ) )
70  aComponents.push_back( static_cast<SCH_COMPONENT*>( aItem ) );
71  }
72 
73  if( aComponents.empty() )
74  return;
75 
76  // sort aComponents by lib part. Components will be grouped by same lib part.
77  std::sort( aComponents.begin(), aComponents.end(), sort_by_libid );
78 }
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:981
static bool sort_by_libid(const SCH_COMPONENT *ref, SCH_COMPONENT *cmp)
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:970
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:498

References SCH_SCREENS::GetFirst(), SCH_SCREENS::GetNext(), SCH_COMPONENT_T, and sort_by_libid().

Referenced by RESCUER::RESCUER().

◆ GetRescueLibraryFileName()

static wxFileName GetRescueLibraryFileName ( )
static

Definition at line 111 of file project_rescue.cpp.

112 {
113  wxFileName fn( g_RootSheet->GetScreen()->GetFileName() );
114  fn.SetName( fn.GetName() + wxT( "-rescue" ) );
115  fn.SetExt( SchematicLibraryFileExtension );
116  return fn;
117 }
const wxString & GetFileName() const
Definition: sch_screen.h:157
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:278
const std::string SchematicLibraryFileExtension
SCH_SHEET * g_RootSheet

References g_RootSheet, SCH_SCREEN::GetFileName(), SCH_SHEET::GetScreen(), and SchematicLibraryFileExtension.

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 47 of file project_rescue.cpp.

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

References SCH_COMPONENT::GetLibId().

Referenced by get_components().