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, int aUnit=0, int aConvert=0)
 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...
 
int GetUnit () const
 
int GetConvert () const
 

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
 
int m_unit
 
int m_convert
 

Private Attributes

LIB_PARTm_cache_candidate
 

Detailed Description

Definition at line 148 of file project_rescue.h.

Constructor & Destructor Documentation

◆ RESCUE_CACHE_CANDIDATE() [1/2]

RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( const wxString &  aRequestedName,
const wxString &  aNewName,
LIB_PART aCacheCandidate,
LIB_PART aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

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
aUnitThe unit of the rescued symbol.
aConvertThe body style of the rescued symbol.

Definition at line 214 of file project_rescue.cpp.

220 {
221  m_requested_name = aRequestedName;
222  m_new_name = aNewName;
223  m_cache_candidate = aCacheCandidate;
224  m_lib_candidate = aLibCandidate;
225  m_unit = aUnit;
226  m_convert = aConvert;
227 }
LIB_PART * m_lib_candidate
wxString m_requested_name

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

◆ RESCUE_CACHE_CANDIDATE() [2/2]

RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( )

Definition at line 230 of file project_rescue.cpp.

231 {
234 }
LIB_PART * m_lib_candidate
#define NULL

References m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, and NULL.

Referenced by FindRescues().

Member Function Documentation

◆ FindRescues()

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

239 {
240  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
241  candidate_map_t candidate_map;
242 
243  // Remember the list of components is sorted by part name.
244  // So a search in libraries is made only once by group
245  LIB_PART* cache_match = nullptr;
246  LIB_PART* lib_match = nullptr;
247  wxString old_part_name;
248 
249  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
250  {
251  wxString part_name = each_component->GetLibId().GetLibItemName();
252 
253  if( old_part_name != part_name )
254  {
255  // A new part name is found (a new group starts here).
256  // Search the symbol names candidates only once for this group:
257  old_part_name = part_name;
258  cache_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), true );
259  lib_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), false );
260 
261  if( !cache_match && !lib_match )
262  continue;
263 
264  // Test whether there is a conflict or if the symbol can only be found in the cache
265  // and the symbol name does not have any illegal characters.
266  if( LIB_ID::HasIllegalChars( part_name, LIB_ID::ID_SCH ) == -1 )
267  {
268  if( cache_match && lib_match &&
269  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
270  continue;
271 
272  if( !cache_match && lib_match )
273  continue;
274  }
275 
276  // Check if the symbol has already been rescued.
277  wxString new_name = LIB_ID::FixIllegalChars( part_name, LIB_ID::ID_SCH );
278 
279  RESCUE_CACHE_CANDIDATE candidate( part_name, new_name, cache_match, lib_match,
280  each_component->GetUnit(),
281  each_component->GetConvert() );
282 
283  candidate_map[part_name] = candidate;
284  }
285  }
286 
287  // Now, dump the map into aCandidates
288  for( const candidate_map_t::value_type& each_pair : candidate_map )
289  {
290  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
291  }
292 }
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part's pins do not match another part's pins.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_ID GetLibId() const override
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
static int HasIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:336
Define a library symbol object.
static LIB_PART * find_component(const wxString &aName, PART_LIBS *aLibs, bool aCached)
Search the libraries for the first component with a given name.
Schematic symbol object.
Definition: sch_component.h:88
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
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

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

Referenced by LEGACY_RESCUER::FindCandidates().

◆ GetActionDescription()

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

296 {
297  wxString action;
298 
300  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
301  "the cache." ), m_requested_name );
302  else if( m_cache_candidate && !m_lib_candidate )
303  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
305  else
306  action.Printf( _( "Rescue modified symbol %s to %s" ),
308 
309  return action;
310 }
LIB_PART * m_lib_candidate
#define _(s)
Definition: 3d_actions.cpp:33
wxString m_requested_name

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

◆ GetCacheCandidate()

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 176 of file project_rescue.h.

176 { return m_cache_candidate; }

References m_cache_candidate.

◆ GetConvert()

int RESCUE_CANDIDATE::GetConvert ( ) const
inlineinherited

Definition at line 102 of file project_rescue.h.

102 { return m_convert; }

References RESCUE_CANDIDATE::m_convert.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetLibCandidate()

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 98 of file project_rescue.h.

98 { return m_lib_candidate; }
LIB_PART * m_lib_candidate

References RESCUE_CANDIDATE::m_lib_candidate.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetNewName()

virtual wxString RESCUE_CANDIDATE::GetNewName ( ) const
inlinevirtualinherited

Get the name we're proposing changing it to.

Definition at line 86 of file project_rescue.h.

86 { return m_new_name; }

References RESCUE_CANDIDATE::m_new_name.

◆ GetRequestedName()

virtual wxString RESCUE_CANDIDATE::GetRequestedName ( ) const
inlinevirtualinherited

Get the name that was originally requested in the schematic.

Definition at line 81 of file project_rescue.h.

81 { return m_requested_name; }
wxString m_requested_name

References RESCUE_CANDIDATE::m_requested_name.

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

◆ GetUnit()

int RESCUE_CANDIDATE::GetUnit ( ) const
inlineinherited

Definition at line 100 of file project_rescue.h.

100 { return m_unit; }

References RESCUE_CANDIDATE::m_unit.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ PerformAction()

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

314 {
316 
317  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
318 
319  std::unique_ptr<LIB_PART> new_part = tmp->Flatten();
320  new_part->SetName( m_new_name );
321  aRescuer->AddPart( new_part.get() );
322 
323  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
324  {
325  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
326  continue;
327 
328  LIB_ID libId;
329 
330  libId.SetLibItemName( m_new_name, false );
331  each_component->SetLibId( libId );
332  each_component->ClearFlags();
333  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
334  }
335 
336  return true;
337 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_PART * m_lib_candidate
Define a library symbol object.
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:206
Schematic symbol object.
Definition: sch_component.h:88
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

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

Member Data Documentation

◆ m_cache_candidate

LIB_PART* RESCUE_CACHE_CANDIDATE::m_cache_candidate
private

◆ m_convert

◆ m_lib_candidate

◆ m_new_name

◆ m_requested_name

◆ m_unit


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