KiCad PCB EDA Suite
RESCUE_CASE_CANDIDATE Class Reference
Inheritance diagram for RESCUE_CASE_CANDIDATE:
RESCUE_CANDIDATE

Public Member Functions

 RESCUE_CASE_CANDIDATE (const wxString &aRequestedName, const wxString &aNewName, LIB_PART *aLibCandidate)
 Constructor RESCUE_CANDIDATE. More...
 
 RESCUE_CASE_CANDIDATE ()
 
virtual wxString GetRequestedName () const override
 Function GetRequestedName Get the name that was originally requested in the schematic. More...
 
virtual wxString GetNewName () const override
 Function GetNewName Get the name we're proposing changing it to. More...
 
virtual LIB_PARTGetLibCandidate () const override
 Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL. More...
 
virtual wxString GetActionDescription () const override
 Function GetActionDescription Get a description of the action proposed, for displaying in the UI. More...
 
virtual bool PerformAction (RESCUER *aRescuer) override
 Function PerformAction Perform the actual rescue action. More...
 
virtual LIB_PARTGetCacheCandidate () const
 Function GetCacheCandidate Get the part that can be loaded from the project cache, if possible, or else NULL. More...
 

Static Public Member Functions

static void FindRescues (RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
 Function FindRescues Grab all possible RESCUE_CASE_CANDIDATES into a vector. More...
 

Private Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_PARTm_lib_candidate
 

Detailed Description

Definition at line 239 of file project_rescue.cpp.

Constructor & Destructor Documentation

RESCUE_CASE_CANDIDATE::RESCUE_CASE_CANDIDATE ( const wxString &  aRequestedName,
const wxString &  aNewName,
LIB_PART aLibCandidate 
)
inline

Constructor RESCUE_CANDIDATE.

Parameters
aRequestedName- the name the schematic asks for
aNewName- the name we want to change it to
aLibCandidate- the part that will give us

Definition at line 307 of file project_rescue.cpp.

309  : m_requested_name( aRequestedName ),
310  m_new_name( aNewName ),
311  m_lib_candidate( aLibCandidate ) { }
RESCUE_CASE_CANDIDATE::RESCUE_CASE_CANDIDATE ( )
inline

Definition at line 313 of file project_rescue.cpp.

Referenced by FindRescues().

313 { m_lib_candidate = NULL; }

Member Function Documentation

static void RESCUE_CASE_CANDIDATE::FindRescues ( RESCUER aRescuer,
boost::ptr_vector< RESCUE_CANDIDATE > &  aCandidates 
)
inlinestatic

Function FindRescues Grab all possible RESCUE_CASE_CANDIDATES into a vector.

Parameters
aRescuer- the working RESCUER instance.
aCandidates- the vector the will hold the candidates.

Definition at line 252 of file project_rescue.cpp.

References PART_LIBS::FindLibraryAlias(), PART_LIBS::FindLibraryNearEntries(), FROM_UTF8(), RESCUER::GetComponents(), RESCUER::GetLibs(), and RESCUE_CASE_CANDIDATE().

Referenced by RESCUER::FindCandidates().

253  {
254  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
255  candidate_map_t candidate_map;
256 
257  // Remember the list of components is sorted by part name.
258  // So a search in libraries is made only once by group
259  LIB_ALIAS* case_sensitive_match = nullptr;
260  std::vector<LIB_ALIAS*> case_insensitive_matches;
261 
262  wxString last_part_name;
263 
264  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
265  {
266  wxString part_name( FROM_UTF8( each_component->GetLibId().GetLibItemName() ) );
267 
268  if( last_part_name != part_name )
269  {
270  // A new part name is found (a new group starts here).
271  // Search the symbol names candidates only once for this group:
272  last_part_name = part_name;
273  case_insensitive_matches.clear();
274 
275  LIB_ID id( wxEmptyString, part_name );
276 
277  case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( id );
278 
279  if( !case_sensitive_match )
280  // the case sensitive match failed. Try a case insensitive match
281  aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name );
282  }
283 
284  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
285  continue;
286 
287  RESCUE_CASE_CANDIDATE candidate(
288  part_name, case_insensitive_matches[0]->GetName(),
289  case_insensitive_matches[0]->GetPart() );
290 
291  candidate_map[part_name] = candidate;
292  }
293 
294  // Now, dump the map into aCandidates
295  for( const candidate_map_t::value_type& each_pair : candidate_map )
296  {
297  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
298  }
299  }
Part library alias object definition.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
Class LIB_ID.
Definition: lib_id.h:56
LIB_ALIAS * FindLibraryAlias(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibraryEntry searches all libraries in the list for an entry.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Function GetComponents.
PART_LIBS * GetLibs()
Function GetLibs.
void FindLibraryNearEntries(std::vector< LIB_ALIAS * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Function FindLibraryNearEntries Searches all libraries in the list for an entry, using a case insensi...
virtual wxString RESCUE_CASE_CANDIDATE::GetActionDescription ( ) const
inlineoverridevirtual

Function GetActionDescription Get a description of the action proposed, for displaying in the UI.

Implements RESCUE_CANDIDATE.

Definition at line 318 of file project_rescue.cpp.

319  {
320  wxString action;
321  action.Printf( _( "Rename to %s" ), m_new_name );
322  return action;
323  }
virtual LIB_PART* RESCUE_CANDIDATE::GetCacheCandidate ( ) const
inlinevirtualinherited

Function GetCacheCandidate Get the part that can be loaded from the project cache, if possible, or else NULL.

Reimplemented in RESCUE_CACHE_CANDIDATE.

Definition at line 77 of file project_rescue.h.

Referenced by DIALOG_RESCUE_EACH::OnHandleCachePreviewRepaint().

77 { return NULL; }
virtual LIB_PART* RESCUE_CASE_CANDIDATE::GetLibCandidate ( ) const
inlineoverridevirtual

Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL.

Reimplemented from RESCUE_CANDIDATE.

Definition at line 317 of file project_rescue.cpp.

References m_lib_candidate.

317 { return m_lib_candidate; }
virtual wxString RESCUE_CASE_CANDIDATE::GetNewName ( ) const
inlineoverridevirtual

Function GetNewName Get the name we're proposing changing it to.

Implements RESCUE_CANDIDATE.

Definition at line 316 of file project_rescue.cpp.

References m_new_name.

316 { return m_new_name; }
virtual wxString RESCUE_CASE_CANDIDATE::GetRequestedName ( ) const
inlineoverridevirtual

Function GetRequestedName Get the name that was originally requested in the schematic.

Implements RESCUE_CANDIDATE.

Definition at line 315 of file project_rescue.cpp.

References m_requested_name.

315 { return m_requested_name; }
virtual bool RESCUE_CASE_CANDIDATE::PerformAction ( RESCUER aRescuer)
inlineoverridevirtual

Function PerformAction Perform the actual rescue action.

If successful, this must log the rescue using RESCUER::LogRescue to allow it to be reversed.

Returns
True on success.

Implements RESCUE_CANDIDATE.

Definition at line 325 of file project_rescue.cpp.

References RESCUER::GetComponents(), RESCUER::LogRescue(), LIB_ID::SetLibItemName(), and TO_UTF8.

326  {
327  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
328  {
329  if( each_component->GetLibId().GetLibItemName() != TO_UTF8( m_requested_name ) )
330  continue;
331 
332  LIB_ID libId;
333 
334  libId.SetLibItemName( TO_UTF8( m_new_name ), false );
335  each_component->SetLibId( libId );
336  each_component->ClearFlags();
337  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
338  }
339  return true;
340  }
Class LIB_ID.
Definition: lib_id.h:56
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Function GetComponents.
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Function LogRescue Used by individual RESCUE_CANDIDATEs to log a rescue for undoing.

Member Data Documentation

LIB_PART* RESCUE_CASE_CANDIDATE::m_lib_candidate
private

Definition at line 243 of file project_rescue.cpp.

Referenced by GetLibCandidate().

wxString RESCUE_CASE_CANDIDATE::m_new_name
private

Definition at line 242 of file project_rescue.cpp.

Referenced by GetNewName().

wxString RESCUE_CASE_CANDIDATE::m_requested_name
private

Definition at line 241 of file project_rescue.cpp.

Referenced by GetRequestedName().


The documentation for this class was generated from the following file: