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_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aConvert=0)
 Create a RESCUE_CACHE_CANDIDATE. More...
 
 RESCUE_CACHE_CANDIDATE ()
 
virtual LIB_SYMBOLGetCacheCandidate () 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_SYMBOLGetLibCandidate () 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 objects into a vector. More...
 

Protected Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_SYMBOLm_lib_candidate
 
int m_unit
 
int m_convert
 

Private Attributes

LIB_SYMBOLm_cache_candidate
 

Detailed Description

Definition at line 149 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_SYMBOL aCacheCandidate,
LIB_SYMBOL aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

Create a RESCUE_CACHE_CANDIDATE.

Parameters
aRequestedNameis the name the schematic asks for.
aNewNameis the name we want to change it to.
aCacheCandidateis the part from the cache.
aLibCandidateis the part that would be loaded from the library.
aUnitis the unit of the rescued symbol.
aConvertis the body style of the rescued symbol.

Definition at line 218 of file project_rescue.cpp.

224 {
225  m_requested_name = aRequestedName;
226  m_new_name = aNewName;
227  m_cache_candidate = aCacheCandidate;
228  m_lib_candidate = aLibCandidate;
229  m_unit = aUnit;
230  m_convert = aConvert;
231 }
LIB_SYMBOL * m_cache_candidate
LIB_SYMBOL * 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 234 of file project_rescue.cpp.

235 {
236  m_cache_candidate = nullptr;
237  m_lib_candidate = nullptr;
238 }
LIB_SYMBOL * m_cache_candidate
LIB_SYMBOL * m_lib_candidate

References m_cache_candidate, and RESCUE_CANDIDATE::m_lib_candidate.

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 objects into a vector.

Parameters
aRescueris the working RESCUER instance.
aCandidatesis the vector the will hold the candidates.

Definition at line 241 of file project_rescue.cpp.

243 {
244  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
245  candidate_map_t candidate_map;
246 
247  // Remember the list of symbols is sorted by symbol name.
248  // So a search in libraries is made only once by group
249  LIB_SYMBOL* cache_match = nullptr;
250  LIB_SYMBOL* lib_match = nullptr;
251  wxString symbol_name;
252  wxString search_name;
253  wxString old_symbol_name;
254 
255  for( SCH_SYMBOL* eachSymbol : *( aRescuer.GetSymbols() ) )
256  {
257  symbol_name = eachSymbol->GetLibId().GetLibItemName();
258  search_name = LIB_ID::FixIllegalChars( symbol_name, false );
259 
260  if( old_symbol_name != symbol_name )
261  {
262  // A new symbol name is found (a new group starts here).
263  // Search the symbol names candidates only once for this group:
264  old_symbol_name = symbol_name;
265  cache_match = findSymbol( search_name, aRescuer.GetPrj()->SchLibs(), true );
266  lib_match = findSymbol( search_name, aRescuer.GetPrj()->SchLibs(), false );
267 
268  if( !cache_match && !lib_match )
269  continue;
270 
271  // Test whether there is a conflict or if the symbol can only be found in the cache
272  // and the symbol name does not have any illegal characters.
273  if( cache_match && lib_match &&
274  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
275  continue;
276 
277  if( !cache_match && lib_match )
278  continue;
279 
280  // Check if the symbol has already been rescued.
281  RESCUE_CACHE_CANDIDATE candidate( symbol_name, search_name, cache_match, lib_match,
282  eachSymbol->GetUnit(),
283  eachSymbol->GetConvert() );
284 
285  candidate_map[symbol_name] = candidate;
286  }
287  }
288 
289  // Now, dump the map into aCandidates
290  for( const candidate_map_t::value_type& each_pair : candidate_map )
291  {
292  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
293  }
294 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:189
Define a library symbol object.
Definition: lib_symbol.h:96
static LIB_SYMBOL * findSymbol(const wxString &aName, SYMBOL_LIBS *aLibs, bool aCached)
Search the libraries for the first symbol with a given name.
bool PinsConflictWith(const LIB_SYMBOL &aOtherSymbol, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength) const
Return true if this symbol's pins do not match another symbol's pins.
Definition: lib_symbol.cpp:738
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
Schematic symbol object.
Definition: sch_symbol.h:78
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.

References findSymbol(), LIB_ID::FixIllegalChars(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), RESCUER::GetPrj(), RESCUER::GetSymbols(), LIB_SYMBOL::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 297 of file project_rescue.cpp.

298 {
299  wxString action;
300 
302  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
303  "the cache." ), m_requested_name );
304  else if( m_cache_candidate && !m_lib_candidate )
305  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
307  else
308  action.Printf( _( "Rescue modified symbol %s to %s" ),
310 
311  return action;
312 }
LIB_SYMBOL * m_cache_candidate
#define _(s)
LIB_SYMBOL * m_lib_candidate
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_SYMBOL* 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 178 of file project_rescue.h.

178 { return m_cache_candidate; }
LIB_SYMBOL * m_cache_candidate

References m_cache_candidate.

◆ GetConvert()

int RESCUE_CANDIDATE::GetConvert ( ) const
inlineinherited

Definition at line 95 of file project_rescue.h.

95 { return m_convert; }

References RESCUE_CANDIDATE::m_convert.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetLibCandidate()

virtual LIB_SYMBOL* RESCUE_CANDIDATE::GetLibCandidate ( ) const
inlinevirtualinherited

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

Definition at line 91 of file project_rescue.h.

91 { return m_lib_candidate; }
LIB_SYMBOL * 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 79 of file project_rescue.h.

79 { 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 74 of file project_rescue.h.

74 { 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 93 of file project_rescue.h.

93 { 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 315 of file project_rescue.cpp.

316 {
318 
319  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
320 
321  std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->Flatten();
322  new_symbol->SetName( m_new_name );
323  aRescuer->AddSymbol( new_symbol.get() );
324 
325  for( SCH_SYMBOL* eachSymbol : *aRescuer->GetSymbols() )
326  {
327  if( eachSymbol->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
328  continue;
329 
330  LIB_ID libId;
331 
332  libId.SetLibItemName( m_new_name );
333  eachSymbol->SetLibId( libId );
334  eachSymbol->ClearFlags();
335  aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
336  }
337 
338  return true;
339 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
LIB_SYMBOL * m_cache_candidate
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Define a library symbol object.
Definition: lib_symbol.h:96
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:332
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:108
LIB_SYMBOL * m_lib_candidate
Schematic symbol object.
Definition: sch_symbol.h:78
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
void LogRescue(SCH_SYMBOL *aSymbol, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
wxString m_requested_name
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol)=0

References RESCUER::AddSymbol(), LIB_SYMBOL::Flatten(), RESCUER::GetSymbols(), 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_SYMBOL* 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: