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_SYMBOL *aLibCandidate, int aUnit=0, int aConvert=0)
 Create a 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_SYMBOLGetCacheCandidate () const
 Get the part that can be loaded from the project cache, if possible, or else NULL. 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_CASE_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
 

Detailed Description

Definition at line 118 of file project_rescue.h.

Constructor & Destructor Documentation

◆ RESCUE_CASE_CANDIDATE() [1/2]

RESCUE_CASE_CANDIDATE::RESCUE_CASE_CANDIDATE ( const wxString &  aRequestedName,
const wxString &  aNewName,
LIB_SYMBOL aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

Create a RESCUE_CANDIDATE.

Parameters
aRequestedNameus the name the schematic asks for.
aNewNameis the name we want to change it to.
aLibCandidateis the part that will give us.
aUnitis the unit of the rescued symbol.
aConvertis the body style of the rescued symbol.

Definition at line 121 of file project_rescue.cpp.

126 {
127  m_requested_name = aRequestedName;
128  m_new_name = aNewName;
129  m_lib_candidate = aLibCandidate;
130  m_unit = aUnit;
131  m_convert = aConvert;
132 }
LIB_SYMBOL * m_lib_candidate
wxString m_requested_name

References 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_CASE_CANDIDATE() [2/2]

RESCUE_CASE_CANDIDATE::RESCUE_CASE_CANDIDATE ( )
inline

Definition at line 141 of file project_rescue.h.

141 { m_lib_candidate = nullptr; }
LIB_SYMBOL * m_lib_candidate

References RESCUE_CANDIDATE::m_lib_candidate.

Referenced by FindRescues().

Member Function Documentation

◆ FindRescues()

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
aRescueris the working RESCUER instance.
aCandidatesis the vector the will hold the candidates.

Definition at line 135 of file project_rescue.cpp.

137 {
138  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
139  candidate_map_t candidate_map;
140 
141  // Remember the list of symbols is sorted by symbol name.
142  // So a search in libraries is made only once by group
143  LIB_SYMBOL* case_sensitive_match = nullptr;
144  std::vector<LIB_SYMBOL*> case_insensitive_matches;
145 
146  wxString symbol_name;
147  wxString search_name;
148  wxString last_symbol_name;
149 
150  for( SCH_SYMBOL* eachSymbol : *( aRescuer.GetSymbols() ) )
151  {
152  symbol_name = eachSymbol->GetLibId().GetLibItemName();
153  search_name = LIB_ID::FixIllegalChars( symbol_name, false );
154 
155  if( last_symbol_name != symbol_name )
156  {
157  // A new symbol name is found (a new group starts here).
158  // Search the symbol names candidates only once for this group:
159  last_symbol_name = symbol_name;
160  case_insensitive_matches.clear();
161 
162  LIB_ID id( wxEmptyString, search_name );
163 
164  case_sensitive_match = aRescuer.GetPrj()->SchLibs()->FindLibSymbol( id );
165 
166  // If the case sensitive match failed, try a case insensitive match.
167  if( !case_sensitive_match )
168  aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches,
169  search_name );
170  }
171 
172  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
173  continue;
174 
175  RESCUE_CASE_CANDIDATE candidate( symbol_name, case_insensitive_matches[0]->GetName(),
176  case_insensitive_matches[0],
177  eachSymbol->GetUnit(),
178  eachSymbol->GetConvert() );
179 
180  candidate_map[symbol_name] = candidate;
181  }
182 
183  // Now, dump the map into aCandidates
184  for( const candidate_map_t::value_type& each_pair : candidate_map )
185  {
186  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
187  }
188 }
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
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
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 LIB_ID::FixIllegalChars(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), RESCUER::GetPrj(), RESCUER::GetSymbols(), and RESCUE_CASE_CANDIDATE().

Referenced by LEGACY_RESCUER::FindCandidates().

◆ GetActionDescription()

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

192 {
193  wxString action;
194  action.Printf( _( "Rename %s to %s" ), m_requested_name, m_new_name );
195  return action;
196 }
#define _(s)
wxString m_requested_name

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

◆ GetCacheCandidate()

virtual LIB_SYMBOL* 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 85 of file project_rescue.h.

85 { return nullptr; }

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ 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_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 199 of file project_rescue.cpp.

200 {
201  for( SCH_SYMBOL* eachSymbol : *aRescuer->GetSymbols() )
202  {
203  if( eachSymbol->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
204  continue;
205 
206  LIB_ID libId;
207 
208  libId.SetLibItemName( m_new_name );
209  eachSymbol->SetLibId( libId );
210  eachSymbol->ClearFlags();
211  aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
212  }
213 
214  return true;
215 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:108
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

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

Member Data Documentation

◆ m_convert

◆ m_lib_candidate

◆ m_new_name

◆ m_requested_name

◆ m_unit


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