KiCad PCB EDA Suite
RESCUE_CACHE_CANDIDATE Class Reference

#include <project_rescue.h>

Inheritance diagram for RESCUE_CACHE_CANDIDATE:
RESCUE_CANDIDATE

Public Member Functions

 RESCUE_CACHE_CANDIDATE (const wxString &aRequestedName, const wxString &aNewName, LIB_PART *aCacheCandidate, LIB_PART *aLibCandidate)
 Constructor RESCUE_CACHE_CANDIDATE. More...
 
 RESCUE_CACHE_CANDIDATE ()
 
virtual LIB_PARTGetCacheCandidate () const override
 Get the part that can be loaded from the project cache, if possible, or else NULL. More...
 
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_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_CACHE_CANDIDATE objectss into a vector. More...
 

Protected Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_PARTm_lib_candidate
 

Private Attributes

LIB_PARTm_cache_candidate
 

Detailed Description

Definition at line 138 of file project_rescue.h.

Constructor & Destructor Documentation

RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( const wxString &  aRequestedName,
const wxString &  aNewName,
LIB_PART aCacheCandidate,
LIB_PART aLibCandidate 
)

Constructor RESCUE_CACHE_CANDIDATE.

Parameters
aRequestedName- the name the schematic asks for
aNewName- the name we want to change it to
aCacheCandidate- the part from the cache
aLibCandidate- the part that would be loaded from the library

Definition at line 213 of file project_rescue.cpp.

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

217 {
218  m_requested_name = aRequestedName;
219  m_new_name = aNewName;
220  m_cache_candidate = aCacheCandidate;
221  m_lib_candidate = aLibCandidate;
222 }
LIB_PART * m_lib_candidate
wxString m_requested_name
RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( )

Definition at line 225 of file project_rescue.cpp.

References m_cache_candidate, and RESCUE_CANDIDATE::m_lib_candidate.

Referenced by FindRescues().

226 {
227  m_cache_candidate = NULL;
228  m_lib_candidate = NULL;
229 }
LIB_PART * m_lib_candidate

Member Function Documentation

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

Grab all possible RESCUE_CACHE_CANDIDATE objectss into a vector.

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

Definition at line 232 of file project_rescue.cpp.

References find_component(), LIB_ID::FixIllegalChars(), RESCUER::GetComponents(), RESCUER::GetPartNameSuffix(), RESCUER::GetPrj(), LIB_ID::HasIllegalChars(), LIB_PART::PinsConflictWith(), and RESCUE_CACHE_CANDIDATE().

Referenced by LEGACY_RESCUER::FindCandidates().

234 {
235  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
236  candidate_map_t candidate_map;
237 
238  // Remember the list of components is sorted by part name.
239  // So a search in libraries is made only once by group
240  LIB_PART* cache_match = nullptr;
241  LIB_PART* lib_match = nullptr;
242  wxString old_part_name;
243 
244  wxString part_name_suffix = aRescuer.GetPartNameSuffix();
245 
246  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
247  {
248  wxString part_name = each_component->GetLibId().GetLibItemName();
249 
250  if( old_part_name != part_name )
251  {
252  // A new part name is found (a new group starts here).
253  // Search the symbol names candidates only once for this group:
254  old_part_name = part_name;
255  cache_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), true );
256  lib_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), false );
257 
258  if( !cache_match && !lib_match )
259  continue;
260 
261  // Test whether there is a conflict or if the symbol can only be found in the cache
262  // and the symbol name does not have any illegal characters.
263  if( ( ( cache_match && lib_match
264  && !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
265  || (!cache_match && lib_match ) ) && !LIB_ID::HasIllegalChars( part_name ) )
266  continue;
267 
268  // Check if the symbol has already been rescued.
269  wxString new_name = LIB_ID::FixIllegalChars( part_name );
270 
271  if( new_name.Find( part_name_suffix ) == wxNOT_FOUND )
272  new_name += part_name_suffix;
273 
274  RESCUE_CACHE_CANDIDATE candidate( part_name, new_name, cache_match, lib_match );
275 
276  candidate_map[part_name] = candidate;
277  }
278  }
279 
280  // Now, dump the map into aCandidates
281  for( const candidate_map_t::value_type& each_pair : candidate_map )
282  {
283  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
284  }
285 }
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Function PinsConflictWith returns true if this part's pins do not match another part's pins...
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:384
static LIB_PART * find_component(wxString aName, PART_LIBS *aLibs, bool aCached)
Search the libraries for the first component with a given name.
Class LIB_PART defines a library part object.
wxString GetPartNameSuffix()
Return the suffix to add to rescued parts.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
static bool HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:362
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
wxString RESCUE_CACHE_CANDIDATE::GetActionDescription ( ) const
overridevirtual

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

Implements RESCUE_CANDIDATE.

Definition at line 288 of file project_rescue.cpp.

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

289 {
290  wxString action;
291  action.Printf( _( "Rescue %s as %s" ), m_requested_name, m_new_name );
292  return action;
293 }
wxString m_requested_name
virtual LIB_PART* RESCUE_CACHE_CANDIDATE::GetCacheCandidate ( ) const
inlineoverridevirtual

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

Reimplemented from RESCUE_CANDIDATE.

Definition at line 163 of file project_rescue.h.

References m_cache_candidate.

163 { return m_cache_candidate; }
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_CACHE_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 296 of file project_rescue.cpp.

References RESCUER::AddPart(), RESCUER::GetComponents(), RESCUER::LogRescue(), m_cache_candidate, RESCUE_CANDIDATE::m_new_name, RESCUE_CANDIDATE::m_requested_name, LIB_PART::RemoveAllAliases(), LIB_ID::SetLibItemName(), and LIB_PART::SetName().

297 {
298  LIB_PART new_part( *m_cache_candidate );
299  new_part.SetName( m_new_name );
300  new_part.RemoveAllAliases();
301  aRescuer->AddPart( &new_part );
302 
303  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
304  {
305  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
306  continue;
307 
308  LIB_ID libId;
309 
310  libId.SetLibItemName( m_new_name, false );
311  each_component->SetLibId( libId );
312  each_component->ClearFlags();
313  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
314  }
315 
316  return true;
317 }
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
Class LIB_PART defines a library part object.
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
virtual void AddPart(LIB_PART *aNewPart)=0
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

LIB_PART* RESCUE_CACHE_CANDIDATE::m_cache_candidate
private

Definition at line 140 of file project_rescue.h.

Referenced by GetCacheCandidate(), PerformAction(), and RESCUE_CACHE_CANDIDATE().


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