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 <html_messagebox.h>
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <listboxes.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 129 of file readwrite_dlgs.cpp.

References FP_LIB_TABLE::FootprintEnumerate(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TABLE::GetLogicalLibs(), LIB_ID::SetLibNickname(), and UTF8::size().

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

130 {
131  if( aFootprintId->GetLibNickname().size() )
132  return 0;
133 
134  wxString nick;
135  wxString fpname = aFootprintId->GetLibItemName();
136 
137  std::vector<wxString> nicks = aTbl->GetLogicalLibs();
138 
139  // Search each library going through libraries alphabetically.
140  for( unsigned libNdx = 0; libNdx<nicks.size(); ++libNdx )
141  {
142  wxArrayString fpnames;
143 
144  aTbl->FootprintEnumerate( fpnames, nicks[libNdx] );
145 
146  for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx )
147  {
148  if( fpname == fpnames[nameNdx] )
149  {
150  if( !nick )
151  nick = nicks[libNdx];
152  else
153  return 2; // duplicate, the guess would not be certain
154  }
155  }
156  }
157 
158  if( nick.size() )
159  {
160  aFootprintId->SetLibNickname( nick );
161  return 0;
162  }
163 
164  return 1;
165 }
std::string::size_type size() const
Definition: utf8.h:115
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
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
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:101
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...