KiCad PCB EDA Suite
RESCUE_CASE_CANDIDATE Class Reference

#include <project_rescue.h>

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 GetActionDescription () const override
 Get a description of the action proposed, for displaying in the UI. More...
 
virtual bool PerformAction (RESCUER *aRescuer) override
 Perform the actual rescue action. More...
 
virtual wxString GetRequestedName () const
 Get the name that was originally requested in the schematic. More...
 
virtual wxString GetNewName () const
 Get the name we're proposing changing it to. More...
 
virtual LIB_PARTGetCacheCandidate () const
 Get the part that can be loaded from the project cache, if possible, or else NULL. More...
 
virtual LIB_PARTGetLibCandidate () const
 Get the part the would be loaded from the libraries, if possible, or else NULL. More...
 

Static Public Member Functions

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

Protected Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_PARTm_lib_candidate
 

Detailed Description

Definition at line 110 of file project_rescue.h.

Constructor & Destructor Documentation

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

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

References RESCUE_CANDIDATE::m_lib_candidate, RESCUE_CANDIDATE::m_new_name, and RESCUE_CANDIDATE::m_requested_name.

128 {
129  m_requested_name = aRequestedName;
130  m_new_name = aNewName;
131  m_lib_candidate = aLibCandidate;
132 }
LIB_PART * m_lib_candidate
wxString m_requested_name
RESCUE_CASE_CANDIDATE::RESCUE_CASE_CANDIDATE ( )
inline

Definition at line 130 of file project_rescue.h.

References RESCUE_CANDIDATE::m_lib_candidate.

Referenced by FindRescues().

130 { m_lib_candidate = NULL; }
LIB_PART * m_lib_candidate

Member Function Documentation

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

Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.

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

Definition at line 135 of file project_rescue.cpp.

References RESCUER::GetComponents(), RESCUER::GetPrj(), and RESCUE_CASE_CANDIDATE().

Referenced by LEGACY_RESCUER::FindCandidates().

137 {
138  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
139  candidate_map_t candidate_map;
140 
141  // Remember the list of components is sorted by part name.
142  // So a search in libraries is made only once by group
143  LIB_ALIAS* case_sensitive_match = nullptr;
144  std::vector<LIB_ALIAS*> case_insensitive_matches;
145 
146  wxString last_part_name;
147 
148  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
149  {
150  wxString part_name = each_component->GetLibId().GetLibItemName();
151 
152  if( last_part_name != part_name )
153  {
154  // A new part name is found (a new group starts here).
155  // Search the symbol names candidates only once for this group:
156  last_part_name = part_name;
157  case_insensitive_matches.clear();
158 
159  LIB_ID id( wxEmptyString, part_name );
160 
161  case_sensitive_match = aRescuer.GetPrj()->SchLibs()->FindLibraryAlias( id );
162 
163  if( !case_sensitive_match )
164  // the case sensitive match failed. Try a case insensitive match
165  aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches,
166  part_name );
167  }
168 
169  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
170  continue;
171 
172  RESCUE_CASE_CANDIDATE candidate( part_name, case_insensitive_matches[0]->GetName(),
173  case_insensitive_matches[0]->GetPart() );
174 
175  candidate_map[part_name] = candidate;
176  }
177 
178  // Now, dump the map into aCandidates
179  for( const candidate_map_t::value_type& each_pair : candidate_map )
180  {
181  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
182  }
183 }
Part library alias object definition.
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
wxString RESCUE_CASE_CANDIDATE::GetActionDescription ( ) const
overridevirtual

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

Implements RESCUE_CANDIDATE.

Definition at line 186 of file project_rescue.cpp.

References RESCUE_CANDIDATE::m_new_name.

187 {
188  wxString action;
189  action.Printf( _( "Rename to %s" ), m_new_name );
190  return action;
191 }
virtual LIB_PART* RESCUE_CANDIDATE::GetCacheCandidate ( ) const
inlinevirtualinherited

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

Reimplemented in RESCUE_SYMBOL_LIB_TABLE_CANDIDATE, and RESCUE_CACHE_CANDIDATE.

Definition at line 88 of file project_rescue.h.

Referenced by DIALOG_RESCUE_EACH::OnHandleCachePreviewRepaint().

88 { return NULL; }
virtual LIB_PART* RESCUE_CANDIDATE::GetLibCandidate ( ) const
inlinevirtualinherited

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

Definition at line 94 of file project_rescue.h.

References RESCUE_CANDIDATE::m_lib_candidate.

Referenced by DIALOG_RESCUE_EACH::OnHandleLibraryPreviewRepaint().

94 { return m_lib_candidate; }
LIB_PART * m_lib_candidate
virtual wxString RESCUE_CANDIDATE::GetNewName ( ) const
inlinevirtualinherited

Get the name we're proposing changing it to.

Definition at line 82 of file project_rescue.h.

References RESCUE_CANDIDATE::m_new_name.

82 { return m_new_name; }
virtual wxString RESCUE_CANDIDATE::GetRequestedName ( ) const
inlinevirtualinherited

Get the name that was originally requested in the schematic.

Definition at line 77 of file project_rescue.h.

References RESCUE_CANDIDATE::m_requested_name.

Referenced by DIALOG_RESCUE_EACH::PopulateConflictList(), and DIALOG_RESCUE_EACH::PopulateInstanceList().

77 { return m_requested_name; }
wxString m_requested_name
bool RESCUE_CASE_CANDIDATE::PerformAction ( RESCUER aRescuer)
overridevirtual

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

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

195 {
196  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
197  {
198  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
199  continue;
200 
201  LIB_ID libId;
202 
203  libId.SetLibItemName( m_new_name, false );
204  each_component->SetLibId( libId );
205  each_component->ClearFlags();
206  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
207  }
208 
209  return true;
210 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
wxString m_requested_name

Member Data Documentation


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