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, int aUnit=0, int aConvert=0)
 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...
 
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_PARTm_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_PART aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

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
aUnitThe unit of the rescued symbol.
aConvertThe 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_PART * 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 140 of file project_rescue.h.

140 { m_lib_candidate = NULL; }
LIB_PART * m_lib_candidate
#define NULL

References RESCUE_CANDIDATE::m_lib_candidate, and NULL.

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
aRescuer- the working RESCUER instance.
aCandidates- 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  // Remember the list of components is sorted by part name.
141  // So a search in libraries is made only once by group
142  LIB_PART* case_sensitive_match = nullptr;
143  std::vector<LIB_PART*> case_insensitive_matches;
144 
145  wxString last_part_name;
146 
147  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
148  {
149  wxString part_name = each_component->GetLibId().GetLibItemName();
150 
151  if( last_part_name != part_name )
152  {
153  // A new part name is found (a new group starts here).
154  // Search the symbol names candidates only once for this group:
155  last_part_name = part_name;
156  case_insensitive_matches.clear();
157 
158  LIB_ID id( wxEmptyString, part_name );
159 
160  case_sensitive_match = aRescuer.GetPrj()->SchLibs()->FindLibPart( id );
161 
162  if( !case_sensitive_match )
163  // the case sensitive match failed. Try a case insensitive match
164  aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches,
165  part_name );
166  }
167 
168  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
169  continue;
170 
171  RESCUE_CASE_CANDIDATE candidate( part_name, case_insensitive_matches[0]->GetName(),
172  case_insensitive_matches[0],
173  each_component->GetUnit(),
174  each_component->GetConvert() );
175 
176  candidate_map[part_name] = candidate;
177  }
178 
179  // Now, dump the map into aCandidates
180  for( const candidate_map_t::value_type& each_pair : candidate_map )
181  {
182  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
183  }
184 }
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.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Define a library symbol object.
Schematic symbol object.
Definition: sch_component.h:88
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
void clear()
Definition: utf8.h:113

References UTF8::clear(), RESCUER::GetComponents(), LIB_PART::GetLibId(), LIB_ID::GetLibItemName(), RESCUER::GetPrj(), 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 187 of file project_rescue.cpp.

188 {
189  wxString action;
190  action.Printf( _( "Rename to %s" ), m_new_name );
191  return action;
192 }
#define _(s)
Definition: 3d_actions.cpp:33

References _, and RESCUE_CANDIDATE::m_new_name.

◆ GetCacheCandidate()

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

92 { return NULL; }
#define NULL

References NULL.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

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

196 {
197  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
198  {
199  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
200  continue;
201 
202  LIB_ID libId;
203 
204  libId.SetLibItemName( m_new_name, false );
205  each_component->SetLibId( libId );
206  each_component->ClearFlags();
207  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
208  }
209 
210  return true;
211 }
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
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
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::GetComponents(), 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: