KiCad PCB EDA Suite
readwrite_dlgs.cpp File Reference
#include <fctsys.h>
#include <kiway.h>
#include <common.h>
#include <confirm.h>
#include <build_version.h>
#include <macros.h>
#include <lib_id.h>
#include <fp_lib_table.h>
#include <reporter.h>
#include <html_messagebox.h>
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <listview_classes.h>
#include <wildcards_and_files_ext.h>
#include <fp_conflict_assignment_selector.h>

Go to the source code of this file.

Functions

static int guessNickname (FP_LIB_TABLE *aTbl, LIB_ID *aFootprintId)
 Return true if the resultant LIB_ID has a certain nickname. More...
 

Function Documentation

static int guessNickname ( FP_LIB_TABLE aTbl,
LIB_ID aFootprintId 
)
static

Return true if the resultant LIB_ID has a certain nickname.

The guess is only made if this footprint resides in only one library.

Returns
int - 0 on success, 1 on not found, 2 on ambiguous i.e. multiple matches

Definition at line 140 of file readwrite_dlgs.cpp.

References FP_LIB_TABLE::FootprintEnumerate(), FROM_UTF8(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TABLE::GetLogicalLibs(), LIB_ID::SetLibNickname(), and TO_UTF8.

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

141 {
142  if( aFootprintId->GetLibNickname().size() )
143  return 0;
144 
145  wxString nick;
146  wxString fpname = FROM_UTF8( aFootprintId->GetLibItemName() );
147 
148  std::vector<wxString> nicks = aTbl->GetLogicalLibs();
149 
150  // Search each library going through libraries alphabetically.
151  for( unsigned libNdx = 0; libNdx<nicks.size(); ++libNdx )
152  {
153  wxArrayString fpnames;
154 
155  aTbl->FootprintEnumerate( fpnames, nicks[libNdx] );
156 
157  for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx )
158  {
159  if( fpname == fpnames[nameNdx] )
160  {
161  if( !nick )
162  nick = nicks[libNdx];
163  else
164  return 2; // duplicate, the guess would not be certain
165  }
166  }
167  }
168 
169  if( nick.size() )
170  {
171  aFootprintId->SetLibNickname( TO_UTF8( nick ) );
172  return 0;
173  }
174 
175  return 1;
176 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
int SetLibNickname(const UTF8 &aNickname)
Function SetLibNickname.
Definition: lib_id.cpp:219
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname)
Return a list of footprint names contained within the library given by aNickname. ...
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108
std::vector< wxString > GetLogicalLibs()
Function GetLogicalLibs.