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

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

Definition at line 314 of file project_rescue.cpp.

Referenced by FindRescues().

314 { 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 253 of file project_rescue.cpp.

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

Referenced by RESCUER::FindCandidates().

254  {
255  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
256  candidate_map_t candidate_map;
257 
258  // Remember the list of components is sorted by part name.
259  // So a search in libraries is made only once by group
260  LIB_ALIAS* case_sensitive_match = nullptr;
261  std::vector<LIB_ALIAS*> case_insensitive_matches;
262 
263  wxString last_part_name;
264 
265  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
266  {
267  wxString part_name = each_component->GetLibId().GetLibItemName();
268 
269  if( last_part_name != part_name )
270  {
271  // A new part name is found (a new group starts here).
272  // Search the symbol names candidates only once for this group:
273  last_part_name = part_name;
274  case_insensitive_matches.clear();
275 
276  LIB_ID id( wxEmptyString, part_name );
277 
278  case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( id );
279 
280  if( !case_sensitive_match )
281  // the case sensitive match failed. Try a case insensitive match
282  aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name );
283  }
284 
285  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
286  continue;
287 
288  RESCUE_CASE_CANDIDATE candidate(
289  part_name, case_insensitive_matches[0]->GetName(),
290  case_insensitive_matches[0]->GetPart() );
291 
292  candidate_map[part_name] = candidate;
293  }
294 
295  // Now, dump the map into aCandidates
296  for( const candidate_map_t::value_type& each_pair : candidate_map )
297  {
298  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
299  }
300  }
Part library alias object definition.
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 319 of file project_rescue.cpp.

320  {
321  wxString action;
322  action.Printf( _( "Rename to %s" ), m_new_name );
323  return action;
324  }
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 78 of file project_rescue.h.

Referenced by DIALOG_RESCUE_EACH::OnHandleCachePreviewRepaint().

78 { 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 318 of file project_rescue.cpp.

References m_lib_candidate.

318 { 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 317 of file project_rescue.cpp.

References m_new_name.

317 { 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 316 of file project_rescue.cpp.

References m_requested_name.

316 { 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 326 of file project_rescue.cpp.

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

327  {
328  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
329  {
330  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
331  continue;
332 
333  LIB_ID libId;
334 
335  libId.SetLibItemName( m_new_name, false );
336  each_component->SetLibId( libId );
337  each_component->ClearFlags();
338  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
339  }
340  return true;
341  }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
Class LIB_ID.
Definition: lib_id.h:56
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 244 of file project_rescue.cpp.

Referenced by GetLibCandidate().

wxString RESCUE_CASE_CANDIDATE::m_new_name
private

Definition at line 243 of file project_rescue.cpp.

Referenced by GetNewName().

wxString RESCUE_CASE_CANDIDATE::m_requested_name
private

Definition at line 242 of file project_rescue.cpp.

Referenced by GetRequestedName().


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