Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
0dc4d9c1
Commit
0dc4d9c1
authored
Oct 15, 2012
by
Dick Hollenbeck
Committed by
Wayne Stambaugh
Oct 15, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit Dick's changes to the FP_LIB_TABLE object.
parent
012fa536
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
93 deletions
+159
-93
fp_lib_table.cpp
common/fp_lib_table.cpp
+46
-51
fp_lib_table.h
include/fp_lib_table.h
+113
-42
No files found.
common/fp_lib_table.cpp
View file @
0dc4d9c1
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010
-12
SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
*
...
...
@@ -39,7 +39,7 @@ FP_LIB_TABLE::FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable ) :
fallBack
(
aFallBackTable
)
{
// not copying fall back, simply search aFallBackTable separately
// if "
logical
Name not found".
// if "
nick
Name not found".
}
...
...
@@ -68,9 +68,9 @@ void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR
in
->
NeedSYMBOLorNUMBER
();
std
::
auto_ptr
<
ROW
>
row
(
new
ROW
(
this
)
);
ROW
row
(
this
);
row
->
SetLogicalName
(
in
->
CurText
()
);
row
.
SetNickName
(
in
->
FromUTF8
()
);
in
->
NeedRIGHT
();
...
...
@@ -82,7 +82,7 @@ void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR
in
->
NeedSYMBOLorNUMBER
();
row
->
SetType
(
in
->
CurText
()
);
row
.
SetType
(
in
->
FromUTF8
()
);
in
->
NeedRIGHT
();
...
...
@@ -94,7 +94,7 @@ void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR
in
->
NeedSYMBOLorNUMBER
();
row
->
SetFullURI
(
in
->
CurText
()
);
row
.
SetFullURI
(
in
->
FromUTF8
()
);
in
->
NeedRIGHT
();
...
...
@@ -106,23 +106,21 @@ void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR
in
->
NeedSYMBOLorNUMBER
();
row
->
SetOptions
(
in
->
CurText
()
);
row
.
SetOptions
(
in
->
FromUTF8
()
);
in
->
NeedRIGHT
();
in
->
NeedRIGHT
();
// terminate the (lib..)
// all
logical
Names within this table fragment must be unique, so we do not
// all
nick
Names within this table fragment must be unique, so we do not
// use doReplace in InsertRow(). However a fallBack table can have a
// conflicting
logical
Name and ours will supercede that one since in
// conflicting
nick
Name and ours will supercede that one since in
// FindLib() we search this table before any fall back.
if
(
!
InsertRow
(
row
)
)
{
std
::
string
msg
;
msg
+=
'\''
;
msg
+=
row
->
logicalName
;
msg
+=
'\''
;
msg
+=
" is a duplicate logical footprint library name"
;
wxString
msg
=
wxString
::
Format
(
_
(
"'%s' is a duplicate footprint library nickName"
),
GetChars
(
row
.
nickName
)
);
THROW_IO_ERROR
(
msg
);
}
}
...
...
@@ -135,7 +133,7 @@ void FP_LIB_TABLE::Format( OUTPUTFORMATTER* out, int nestLevel ) const
out
->
Print
(
nestLevel
,
"(fp_lib_table
\n
"
);
for
(
ROWS_CITER
it
=
rows
.
begin
();
it
!=
rows
.
end
();
++
it
)
it
->
second
->
Format
(
out
,
nestLevel
+
1
);
it
->
Format
(
out
,
nestLevel
+
1
);
out
->
Print
(
nestLevel
,
")
\n
"
);
}
...
...
@@ -144,48 +142,50 @@ void FP_LIB_TABLE::Format( OUTPUTFORMATTER* out, int nestLevel ) const
void
FP_LIB_TABLE
::
ROW
::
Format
(
OUTPUTFORMATTER
*
out
,
int
nestLevel
)
const
throw
(
IO_ERROR
)
{
out
->
Print
(
nestLevel
,
"(lib (logical %s)(type %s)(full_uri %s)(options %s))
\n
"
,
out
->
Quotes
(
logicalName
).
c_str
(),
out
->
Quotes
(
type
).
c_str
(),
out
->
Quotes
(
uri
).
c_str
(),
out
->
Quotes
(
options
).
c_str
()
);
out
->
Print
(
nestLevel
,
"(lib (name %s)(type %s)(full_uri %s)(options %s))
\n
"
,
out
->
Quotew
(
nickName
).
c_str
(),
out
->
Quotew
(
type
).
c_str
(),
out
->
Quotew
(
uri
).
c_str
(),
out
->
Quotew
(
options
).
c_str
()
);
}
std
::
vector
<
std
::
s
tring
>
FP_LIB_TABLE
::
GetLogicalLibs
()
std
::
vector
<
wxS
tring
>
FP_LIB_TABLE
::
GetLogicalLibs
()
{
// Only return unique logical library names. Use std::set::insert() to
// quietly reject any duplicates, which can happen when encountering a duplicate
//
logical lib
name from one of the fall back table(s).
//
nick
name from one of the fall back table(s).
std
::
set
<
std
::
string
>
unique
;
std
::
vector
<
std
::
string
>
ret
;
const
FP_LIB_TABLE
*
cur
=
this
;
std
::
set
<
wxString
>
unique
;
std
::
vector
<
wxString
>
ret
;
const
FP_LIB_TABLE
*
cur
=
this
;
do
{
for
(
ROWS_CITER
it
=
cur
->
rows
.
begin
();
it
!=
cur
->
rows
.
end
();
++
it
)
{
unique
.
insert
(
it
->
second
->
logical
Name
);
unique
.
insert
(
it
->
nick
Name
);
}
}
while
(
(
cur
=
cur
->
fallBack
)
!=
0
);
// return a sorted, unique set of
logical lib name std::vector<std::s
tring> to caller
for
(
std
::
set
<
std
::
s
tring
>::
const_iterator
it
=
unique
.
begin
();
it
!=
unique
.
end
();
++
it
)
// return a sorted, unique set of
nicknames in a std::vector<wxS
tring> to caller
for
(
std
::
set
<
wxS
tring
>::
const_iterator
it
=
unique
.
begin
();
it
!=
unique
.
end
();
++
it
)
ret
.
push_back
(
*
it
);
return
ret
;
}
#if 0 // will need PLUGIN_RELEASER.
MODULE* FP_LIB_TABLE::LookupFootprint( const FP_LIB_ID& aFootprintId )
throw( IO_ERROR )
{
PLUGIN* plugin = lookupLib( aFootprintId );
return
plugin
->
FootprintLoad
(
wxString
(
aFootprintId
.
GetBaseName
().
c_str
()
),
wxString
(
aFootprintId
.
GetLogicalLib
().
c_str
()
)
);
return plugin->FootprintLoad(
FROM_UTF8
( aFootprintId.GetBaseName().c_str() ),
FROM_UTF8
( aFootprintId.GetLogicalLib().c_str() ) );
}
...
...
@@ -254,24 +254,22 @@ void FP_LIB_TABLE::loadLib( ROW* aRow ) throw( IO_ERROR )
THROW_IO_ERROR( msg );
}
}
#endif
FP_LIB_TABLE
::
ROW
*
FP_LIB_TABLE
::
FindRow
(
const
std
::
string
&
aLogical
Name
)
const
FP_LIB_TABLE
::
ROW
*
FP_LIB_TABLE
::
FindRow
(
const
wxString
&
aNick
Name
)
const
{
// this function must be *super* fast, so therefore should not instantiate
// anything which would require using the heap. This function is the reason
// ptr_map<> was used instead of ptr_set<>, which would have required
// instantiating a ROW just to find a ROW.
// anything which would require using the heap.
const
FP_LIB_TABLE
*
cur
=
this
;
do
{
ROWS_CITER
it
=
cur
->
rows
.
find
(
aLogical
Name
);
INDEX_CITER
it
=
cur
->
nickIndex
.
find
(
aNick
Name
);
if
(
it
!=
cur
->
rows
.
end
()
)
if
(
it
!=
cur
->
nickIndex
.
end
()
)
{
// reference: http://myitcorner.com/blog/?p=361
return
(
FP_LIB_TABLE
::
ROW
*
)
it
->
second
;
// found
return
(
FP_LIB_TABLE
::
ROW
*
)
&
cur
->
rows
[
it
->
second
];
// found
}
// not found, search fall back table(s), if any
...
...
@@ -281,29 +279,26 @@ FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const std::string& aLogicalName ) cons
}
bool
FP_LIB_TABLE
::
InsertRow
(
std
::
auto_ptr
<
ROW
>
&
aRow
,
bool
doReplace
)
bool
FP_LIB_TABLE
::
InsertRow
(
const
ROW
&
aRow
,
bool
doReplace
)
{
// this does not need to be super fast.
ROWS_CITER
it
=
rows
.
find
(
aRow
->
logical
Name
);
INDEX_CITER
it
=
nickIndex
.
find
(
aRow
.
nick
Name
);
if
(
it
==
rows
.
end
()
)
if
(
it
==
nickIndex
.
end
()
)
{
// be careful here, key is needed because aRow can be
// release()ed before logicalName is captured.
const
std
::
string
&
key
=
aRow
->
logicalName
;
rows
.
insert
(
key
,
aRow
);
rows
.
push_back
(
aRow
);
nickIndex
.
insert
(
INDEX_VALUE
(
aRow
.
nickName
,
rows
.
size
()
-
1
)
);
return
true
;
}
if
(
doReplace
)
{
rows
.
erase
(
aRow
->
logicalName
)
;
int
ndx
=
it
->
second
;
// be careful here, key is needed because aRow can be
// release()ed before logicalName is captured.
const
std
::
string
&
key
=
aRow
->
logicalName
;
rows
.
insert
(
key
,
aRow
);
rows
[
ndx
]
=
aRow
;
nickIndex
.
erase
(
aRow
.
nickName
);
nickIndex
.
insert
(
INDEX_VALUE
(
aRow
.
nickName
,
ndx
)
);
return
true
;
}
...
...
include/fp_lib_table.h
View file @
0dc4d9c1
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010
-12
SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
*
...
...
@@ -26,10 +26,13 @@
#ifndef _FP_LIB_TABLE_H_
#define _FP_LIB_TABLE_H_
#include <macros.h>
#include <fp_lib_id.h>
#include <vector>
#include <map>
#include <boost/ptr_container/ptr_map.hpp>
#include <wx/grid.h>
#include <fp_lib_id.h>
class
OUTPUTFORMATTER
;
...
...
@@ -78,7 +81,7 @@ class MODULE;
*
* @author Wayne Stambaugh
*/
class
FP_LIB_TABLE
class
FP_LIB_TABLE
:
public
wxGridTableBase
{
public
:
...
...
@@ -94,19 +97,19 @@ public:
public
:
/**
* Function Get
Logical
Name
* returns the
logical
name of this library table row.
* Function Get
Nick
Name
* returns the
short
name of this library table row.
*/
const
std
::
string
&
GetLogical
Name
()
const
const
wxString
&
GetNick
Name
()
const
{
return
logical
Name
;
return
nick
Name
;
}
/**
* Function GetType
* returns the type of LIB represented by this record.
*/
const
std
::
s
tring
&
GetType
()
const
const
wxS
tring
&
GetType
()
const
{
return
type
;
}
...
...
@@ -115,7 +118,7 @@ public:
* Function GetFullURI
* returns the full location specifying URI for the LIB.
*/
const
std
::
s
tring
&
GetFullURI
()
const
const
wxS
tring
&
GetFullURI
()
const
{
return
uri
;
}
...
...
@@ -125,14 +128,14 @@ public:
* returns the options string, which may hold a password or anything else needed to
* instantiate the underlying LIB_SOURCE.
*/
const
std
::
s
tring
&
GetOptions
()
const
const
wxS
tring
&
GetOptions
()
const
{
return
options
;
}
~
ROW
()
{
delete
lib
;
//
delete lib;
}
/**
...
...
@@ -149,24 +152,24 @@ public:
protected
:
ROW
(
FP_LIB_TABLE
*
aOwner
)
:
owner
(
aOwner
)
,
lib
(
0
)
owner
(
aOwner
)
//
lib( 0 )
{}
/**
* Function Set
Logical
Name
* Function Set
Nick
Name
* changes the logical name of this library, useful for an editor.
*/
void
Set
LogicalName
(
const
std
::
string
&
aLogical
Name
)
void
Set
NickName
(
const
wxString
&
aNick
Name
)
{
logicalName
=
aLogical
Name
;
nickName
=
aNick
Name
;
}
/**
* Function SetType
* changes the type represented by this record.
*/
void
SetType
(
const
std
::
s
tring
&
aType
)
void
SetType
(
const
wxS
tring
&
aType
)
{
type
=
aType
;
}
...
...
@@ -175,7 +178,7 @@ public:
* Function SetFullURI
* changes the full URI for the library, useful from a library table editor.
*/
void
SetFullURI
(
const
std
::
s
tring
&
aFullURI
)
void
SetFullURI
(
const
wxS
tring
&
aFullURI
)
{
uri
=
aFullURI
;
}
...
...
@@ -185,21 +188,24 @@ public:
* changes the options string for this record, and is useful from
* the library table editor.
*/
void
SetOptions
(
const
std
::
s
tring
&
aOptions
)
void
SetOptions
(
const
wxS
tring
&
aOptions
)
{
options
=
aOptions
;
}
private
:
FP_LIB_TABLE
*
owner
;
std
::
string
logicalName
;
std
::
string
type
;
std
::
string
uri
;
std
::
string
options
;
PLUGIN
*
lib
;
///< ownership of the loaded LIB is here
FP_LIB_TABLE
*
owner
;
wxString
nickName
;
wxString
type
;
wxString
uri
;
wxString
options
;
/*
PLUGIN* lib; ///< ownership of the loaded LIB is here
*/
};
/**
* Constructor FP_LIB_TABLE
* builds a library table by pre-pending this table fragment in front of
...
...
@@ -246,6 +252,7 @@ public:
*/
void
Format
(
OUTPUTFORMATTER
*
out
,
int
nestLevel
)
const
throw
(
IO_ERROR
);
#if 0
/**
* Function LookupPart
* finds and loads a MODULE, and parses it. As long as the part is
...
...
@@ -262,25 +269,76 @@ public:
* @throw IO_ERROR if any problem occurs or if the footprint cannot be found.
*/
MODULE* LookupFootprint( const FP_LIB_ID& aFootprintId ) throw( IO_ERROR );
#endif
/**
* Function GetLogicalLibs
* returns the logical library names, all of them that are pertinent to
* a lookup done on this FP_LIB_TABLE.
*/
std
::
vector
<
std
::
string
>
GetLogicalLibs
();
std
::
vector
<
wxString
>
GetLogicalLibs
();
//-----<wxGridTableBase overloads>-------------------------------------------
int
GetNumberRows
()
{
return
rows
.
size
();
}
int
GetNumberCols
()
{
return
4
;
}
wxString
GetValue
(
int
aRow
,
int
aCol
)
{
if
(
unsigned
(
aRow
)
<
rows
.
size
()
)
{
const
ROW
&
r
=
rows
[
aRow
];
switch
(
aCol
)
{
case
0
:
return
r
.
GetNickName
();
case
1
:
return
r
.
GetType
();
case
2
:
return
r
.
GetFullURI
();
case
3
:
return
r
.
GetOptions
();
default:
;
// fall thru to wxEmptyString
}
}
return
wxEmptyString
;
}
void
SetValue
(
int
aRow
,
int
aCol
,
const
wxString
&
aValue
)
{
if
(
aCol
==
0
)
{
// when the nickname is changed, there's careful work to do, including
// ensuring uniqueness of the nickname.
}
else
if
(
unsigned
(
aRow
)
<
rows
.
size
()
)
{
ROW
&
r
=
rows
[
aRow
];
switch
(
aCol
)
{
case
1
:
return
r
.
SetType
(
aValue
);
case
2
:
return
r
.
SetFullURI
(
aValue
);
case
3
:
return
r
.
SetOptions
(
aValue
);
}
}
}
//-----</wxGridTableBase overloads>------------------------------------------
//----<read accessors>----------------------------------------------------
// the returning of a const
std::s
tring* tells if not found, but might be too
// the returning of a const
wxS
tring* tells if not found, but might be too
// promiscuous?
/**
* Function GetURI
* returns the full library path from a logical library name.
* @param aLogicalLibraryName is the short name for the library of interest.
* @return const
std::s
tring* - or NULL if not found.
* @return const
wxS
tring* - or NULL if not found.
*/
const
std
::
string
*
GetURI
(
const
std
::
s
tring
&
aLogicalLibraryName
)
const
const
wxString
*
GetURI
(
const
wxS
tring
&
aLogicalLibraryName
)
const
{
const
ROW
*
row
=
FindRow
(
aLogicalLibraryName
);
return
row
?
&
row
->
uri
:
0
;
...
...
@@ -290,9 +348,9 @@ public:
* Function GetType
* returns the type of a logical library.
* @param aLogicalLibraryName is the short name for the library of interest.
* @return const
std::s
tring* - or NULL if not found.
* @return const
wxS
tring* - or NULL if not found.
*/
const
std
::
string
*
GetType
(
const
std
::
s
tring
&
aLogicalLibraryName
)
const
const
wxString
*
GetType
(
const
wxS
tring
&
aLogicalLibraryName
)
const
{
const
ROW
*
row
=
FindRow
(
aLogicalLibraryName
);
return
row
?
&
row
->
type
:
0
;
...
...
@@ -302,9 +360,9 @@ public:
* Function GetLibOptions
* returns the options string for \a aLogicalLibraryName.
* @param aLogicalLibraryName is the short name for the library of interest.
* @return const
std::s
tring* - or NULL if not found.
* @return const
wxS
tring* - or NULL if not found.
*/
const
std
::
string
*
GetLibOptions
(
const
std
::
s
tring
&
aLogicalLibraryName
)
const
const
wxString
*
GetLibOptions
(
const
wxS
tring
&
aLogicalLibraryName
)
const
{
const
ROW
*
row
=
FindRow
(
aLogicalLibraryName
);
return
row
?
&
row
->
options
:
0
;
...
...
@@ -324,23 +382,24 @@ protected: // only a table editor can use these
* Function InsertRow
* adds aRow if it does not already exist or if doReplace is true. If doReplace
* is not true and the key for aRow already exists, the function fails and returns false.
* The key for the table is the
logical
Name, and all in this table must be unique.
* The key for the table is the
nick
Name, and all in this table must be unique.
* @param aRow is the new row to insert, or to forcibly add if doReplace is true.
* @param doReplace if true, means insert regardless of whether aRow's key already
* exists. If false, then fail if the key already exists.
* @return bool - true if the operation succeeded.
*/
bool
InsertRow
(
std
::
auto_ptr
<
ROW
>
&
aRow
,
bool
doReplace
=
false
);
bool
InsertRow
(
const
ROW
&
aRow
,
bool
doReplace
=
false
);
/**
* Function FindRow
* returns a #ROW* if a
Logical
Name is found in this table or in any chained
* returns a #ROW* if a
Nick
Name is found in this table or in any chained
* fallBack table fragment, else NULL.
*/
ROW
*
FindRow
(
const
std
::
string
&
aLogical
Name
)
const
;
ROW
*
FindRow
(
const
wxString
&
aNick
Name
)
const
;
private
:
#if 0 // lets see what we need.
/**
* Function lookupLib
* finds or loads a LIB based on @a aLogicalPartID or @a aFallBackLib.
...
...
@@ -367,12 +426,24 @@ private:
* already loaded.
*/
void loadLib( ROW* aRow ) throw( IO_ERROR );
#endif
typedef
boost
::
ptr_map
<
std
::
string
,
ROW
>
ROWS
;
typedef
ROWS
::
iterator
ROWS_ITER
;
typedef
ROWS
::
const_iterator
ROWS_CITER
;
typedef
std
::
vector
<
ROW
>
ROWS
;
typedef
ROWS
::
iterator
ROWS_ITER
;
typedef
ROWS
::
const_iterator
ROWS_CITER
;
ROWS
rows
;
/// this is a non-owning index into the ROWS table
typedef
std
::
map
<
wxString
,
int
>
INDEX
;
// "int" is std::vector array index
typedef
INDEX
::
iterator
INDEX_ITER
;
typedef
INDEX
::
const_iterator
INDEX_CITER
;
typedef
INDEX
::
value_type
INDEX_VALUE
;
/// the particular key is the nickName within each row.
INDEX
nickIndex
;
FP_LIB_TABLE
*
fallBack
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment