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
a7f19392
Commit
a7f19392
authored
Mar 21, 2014
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify and fix the technique used to get the project fp-lib-table
parent
34dda6a1
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
158 additions
and
151 deletions
+158
-151
fp_lib_table.cpp
common/fp_lib_table.cpp
+15
-69
project.cpp
common/project.cpp
+43
-0
cfg.cpp
cvpcb/cfg.cpp
+2
-5
cvframe.cpp
cvpcb/cvframe.cpp
+20
-18
readwrite_dlgs.cpp
cvpcb/readwrite_dlgs.cpp
+10
-10
fp_lib_table.h
include/fp_lib_table.h
+12
-7
project.h
include/project.h
+7
-0
basepcbframe.cpp
pcbnew/basepcbframe.cpp
+4
-0
files.cpp
pcbnew/files.cpp
+11
-11
pcbnew.cpp
pcbnew/pcbnew.cpp
+3
-0
pcbnew_config.cpp
pcbnew/pcbnew_config.cpp
+31
-31
No files found.
common/fp_lib_table.cpp
View file @
a7f19392
...
...
@@ -24,6 +24,7 @@
*/
#include <fctsys.h>
#include <wx/config.h> // wxExpandEnvVars()
#include <wx/filename.h>
#include <wx/stdpaths.h>
...
...
@@ -45,19 +46,6 @@
using
namespace
FP_LIB_TABLE_T
;
/**
* Definition for enabling and disabling footprint library trace output. See the
* wxWidgets documentation on using the WXTRACE environment variable.
*/
static
const
wxString
traceFpLibTable
(
wxT
(
"KicadFpLibTable"
)
);
/// The footprint library table name used when no project file is passed to Pcbnew or CvPcb.
/// This is used temporarily to store the project specific library table until the project
/// file being edited is saved. It is then moved to the file fp-lib-table in the folder where
/// the project file is saved.
static
const
wxChar
templateProjectFileName
[]
=
wxT
(
"prj-fp-lib-table"
);
static
const
wxChar
global_tbl_name
[]
=
wxT
(
"fp-lib-table"
);
...
...
@@ -408,19 +396,6 @@ void FP_LIB_TABLE::ROW::Format( OUTPUTFORMATTER* out, int nestLevel ) const
);
}
void
FP_LIB_TABLE
::
Save
(
const
wxFileName
&
aPath
)
const
throw
(
IO_ERROR
)
{
wxFileName
fn
=
GetProjectTableFileName
(
aPath
.
GetFullPath
()
);
wxLogTrace
(
traceFpLibTable
,
wxT
(
"Saving footprint libary table <%s>."
),
GetChars
(
fn
.
GetFullPath
()
)
);
FILE_OUTPUTFORMATTER
sf
(
fn
.
GetFullPath
()
);
Format
(
&
sf
,
0
);
}
#define OPT_SEP '|' ///< options separator character
PROPERTIES
*
FP_LIB_TABLE
::
ParseOptions
(
const
std
::
string
&
aOptionsList
)
...
...
@@ -842,34 +817,6 @@ const wxString FP_LIB_TABLE::GlobalPathEnvVariableName()
}
wxString
FP_LIB_TABLE
::
GetProjectTableFileName
(
const
wxString
&
aProjectFullName
)
{
wxFileName
fn
=
aProjectFullName
;
wxString
path
=
fn
.
GetPath
();
// Set $KICAD_PRJ_PATH to user's configuration path if aPath is not set or does not exist.
if
(
!
fn
.
IsOk
()
||
!
wxFileName
::
IsDirReadable
(
path
)
)
{
fn
.
AssignDir
(
wxStandardPaths
::
Get
().
GetUserConfigDir
()
);
#if defined( __WINDOWS__ )
fn
.
AppendDir
(
wxT
(
"kicad"
)
);
#endif
fn
.
SetName
(
templateProjectFileName
);
}
else
{
fn
.
SetName
(
global_tbl_name
);
}
wxLogTrace
(
traceFpLibTable
,
wxT
(
"Project footprint lib table file '%s'."
),
GetChars
(
fn
.
GetFullPath
()
)
);
return
fn
.
GetFullPath
();
}
bool
FP_LIB_TABLE
::
LoadGlobalTable
(
FP_LIB_TABLE
&
aTable
)
throw
(
IO_ERROR
,
PARSE_ERROR
)
{
bool
tableExists
=
true
;
...
...
@@ -911,39 +858,38 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
{
wxFileName
fn
;
// This is possibly problematic with an uncertain wxApp title, which is now
// the case. We'll need a better technique soon.
fn
.
SetPath
(
wxStandardPaths
::
Get
().
GetUserConfigDir
()
);
#if defined( __WINDOWS__ )
fn
.
AppendDir
(
wxT
(
"kicad"
)
);
#endif
fn
.
SetName
(
GetFileName
()
);
wxLogTrace
(
traceFpLibTable
,
wxT
(
"Global footprint library table file '%s'."
),
GetChars
(
fn
.
GetFullPath
()
)
);
fn
.
SetName
(
global_tbl_name
);
return
fn
.
GetFullPath
();
}
// prefer wxString filename so it can be seen in a debugger easier than wxFileName.
const
wxString
FP_LIB_TABLE
::
GetFileName
()
{
return
global_tbl_name
;
}
void
FP_LIB_TABLE
::
Load
(
const
wxFileName
&
aFileName
,
FP_LIB_TABLE
*
aFallBackTable
)
void
FP_LIB_TABLE
::
Load
(
const
wxString
&
aFileName
)
throw
(
IO_ERROR
)
{
fallBack
=
aFallBackTable
;
// Empty footprint library tables are valid.
if
(
aFileName
.
IsOk
()
&&
aFileName
.
FileExists
(
)
)
if
(
wxFileName
::
IsFileReadable
(
aFileName
)
)
{
FILE_LINE_READER
reader
(
aFileName
.
GetFullPath
()
);
FILE_LINE_READER
reader
(
aFileName
);
FP_LIB_TABLE_LEXER
lexer
(
&
reader
);
Parse
(
&
lexer
);
}
}
void
FP_LIB_TABLE
::
Save
(
const
wxString
&
aFileName
)
const
throw
(
IO_ERROR
)
{
FILE_OUTPUTFORMATTER
sf
(
aFileName
);
Format
(
&
sf
,
0
);
}
common/project.cpp
View file @
a7f19392
...
...
@@ -82,6 +82,49 @@ const wxString PROJECT::GetProjectFullName() const
}
const
wxString
PROJECT
::
FootprintLibTblName
()
const
{
wxFileName
fn
=
GetProjectFullName
();
wxString
path
=
fn
.
GetPath
();
// DBG(printf( "path:'%s' fn:'%s'\n", TO_UTF8(path), TO_UTF8(fn.GetFullPath()) );)
// if there's no path to the project name, or the name as a whole is bogus or its not
// write-able then use a template file.
if
(
!
fn
.
GetDirCount
()
||
!
fn
.
IsOk
()
||
!
wxFileName
::
IsDirWritable
(
path
)
)
{
// return a template filename now.
// this next line is likely a problem now, since it relies on an
// application title which is no longer constant or known. This next line needs
// to be re-thought out.
fn
.
AssignDir
(
wxStandardPaths
::
Get
().
GetUserConfigDir
()
);
#if defined( __WINDOWS__ )
fn
.
AppendDir
(
wxT
(
"kicad"
)
);
#endif
/*
The footprint library table name used when no project file is passed
to Pcbnew or CvPcb. This is used temporarily to store the project
specific library table until the project file being edited is saved.
It is then moved to the file fp-lib-table in the folder where the
project file is saved.
*/
fn
.
SetName
(
wxT
(
"prj-fp-lib-table"
)
);
}
else
// normal path.
{
fn
.
SetName
(
wxT
(
"fp-lib-table"
)
);
}
fn
.
ClearExt
();
return
fn
.
GetFullPath
();
}
RETAINED_PATH
&
PROJECT
::
RPath
(
RETPATH_T
aIndex
)
{
unsigned
ndx
=
unsigned
(
aIndex
);
...
...
cvpcb/cfg.cpp
View file @
a7f19392
...
...
@@ -93,14 +93,11 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
prj.SetProjectFullName( fn.GetFullPath() );
*/
wx
FileName
projectFpLibTableFileName
=
FP_LIB_TABLE
::
GetProjectTableFileName
(
fn
.
GetFullPath
()
);
wx
String
projectFpLibTableFileName
=
prj
.
FootprintLibTblName
(
);
try
{
// Stack the project specific FP_LIB_TABLE overlay on top of the global table.
// ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
// stack this way, all using the same global fallback table.
FootprintLibs
()
->
Load
(
projectFpLibTableFileName
,
&
GFootprintTable
);
FootprintLibs
()
->
Load
(
projectFpLibTableFileName
);
}
catch
(
const
IO_ERROR
&
ioe
)
{
...
...
cvpcb/cvframe.cpp
View file @
a7f19392
...
...
@@ -210,6 +210,9 @@ FP_LIB_TABLE* CVPCB_MAINFRAME::FootprintLibs() const
if
(
!
tbl
)
{
// Stack the project specific FP_LIB_TABLE overlay on top of the global table.
// ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
// stack this way, all using the same global fallback table.
tbl
=
new
FP_LIB_TABLE
(
&
GFootprintTable
);
prj
.
Elem
(
PROJECT
::
FPTBL
,
tbl
);
}
...
...
@@ -504,41 +507,40 @@ void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
if
(
r
&
1
)
{
wxString
fileName
=
FP_LIB_TABLE
::
GetGlobalTableFileName
();
try
{
FILE_OUTPUTFORMATTER
sf
(
FP_LIB_TABLE
::
GetGlobalTableFileName
()
);
GFootprintTable
.
Format
(
&
sf
,
0
);
GFootprintTable
.
Save
(
fileName
);
tableChanged
=
true
;
}
catch
(
const
IO_ERROR
&
ioe
)
{
wxString
msg
=
wxString
::
Format
(
_
(
"Error occurred saving the global footprint library "
"table:
\n\n
%s"
),
GetChars
(
ioe
.
errorText
)
);
"Error occurred saving the global footprint library table:
\n
'%s'
\n
%s"
),
GetChars
(
fileName
),
GetChars
(
ioe
.
errorText
)
);
wxMessageBox
(
msg
,
_
(
"File Save Error"
),
wxOK
|
wxICON_ERROR
);
}
}
if
(
r
&
2
)
{
wxFileName
fn
=
m_NetlistFileName
;
fn
.
SetName
(
FP_LIB_TABLE
::
GetFileName
()
);
fn
.
SetExt
(
wxEmptyString
);
wxString
fileName
=
Prj
().
FootprintLibTblName
();
try
{
FILE_OUTPUTFORMATTER
sf
(
fn
.
GetFullPath
()
);
FootprintLibs
()
->
Format
(
&
sf
,
0
);
FootprintLibs
()
->
Save
(
fileName
);
tableChanged
=
true
;
}
catch
(
IO_ERROR
&
ioe
)
catch
(
const
IO_ERROR
&
ioe
)
{
wxString
msg
;
msg
.
Printf
(
_
(
"Error occurred saving the global footprint library "
"table:
\n\n
%s"
),
ioe
.
errorText
.
GetData
()
);
wxString
msg
=
wxString
::
Format
(
_
(
"Error occurred saving the project footprint library table:
\n
'%s'
\n
%s"
),
GetChars
(
fileName
),
GetChars
(
ioe
.
errorText
)
);
wxMessageBox
(
msg
,
_
(
"File Save Error"
),
wxOK
|
wxICON_ERROR
);
}
}
...
...
cvpcb/readwrite_dlgs.cpp
View file @
a7f19392
...
...
@@ -317,25 +317,25 @@ int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
// Save the project specific footprint library table.
if
(
!
FootprintLibs
()
->
IsEmpty
(
false
)
)
{
wxFileName
fpLibFileName
=
fn
;
fpLibFileName
.
ClearExt
();
fpLibFileName
.
SetName
(
FP_LIB_TABLE
::
GetFileName
()
);
wxString
fp_lib_tbl
=
Prj
().
FootprintLibTblName
();
if
(
fpLibFileName
.
FileExists
(
)
if
(
wxFileName
::
FileExists
(
fp_lib_tbl
)
&&
IsOK
(
this
,
_
(
"A footprint library table already exists in this path.
\n\n
Do "
"you want to overwrite it?"
)
)
)
{
try
{
FootprintLibs
()
->
Save
(
fp
LibFileName
);
FootprintLibs
()
->
Save
(
fp
_lib_tbl
);
}
catch
(
const
IO_ERROR
&
ioe
)
{
DisplayError
(
this
,
wxString
::
Format
(
_
(
"An error occurred attempting to save the "
"footprint library table <%s>
\n\n
%s"
),
GetChars
(
fpLibFileName
.
GetFullPath
()
),
GetChars
(
ioe
.
errorText
)
)
);
wxString
msg
=
wxString
::
Format
(
_
(
"An error occurred attempting to save the "
"footprint library table '%s'
\n\n
%s"
),
GetChars
(
fp_lib_tbl
),
GetChars
(
ioe
.
errorText
)
);
DisplayError
(
this
,
msg
);
}
}
}
...
...
include/fp_lib_table.h
View file @
a7f19392
...
...
@@ -357,8 +357,6 @@ public:
*/
void
Format
(
OUTPUTFORMATTER
*
out
,
int
nestLevel
)
const
throw
(
IO_ERROR
);
void
Save
(
const
wxFileName
&
aPath
)
const
throw
(
IO_ERROR
);
/**
* Function GetLogicalLibs
* returns the logical library names, all of them that are pertinent to
...
...
@@ -544,11 +542,13 @@ public:
*/
static
wxString
GetGlobalTableFileName
();
#if 0
/**
* Function GetFileName
* @return the footprint library file name.
*/
static const wxString GetFileName();
#endif
/**
* Function GlobalPathEnvVarVariableName
...
...
@@ -560,19 +560,24 @@ public:
*/
static
const
wxString
GlobalPathEnvVariableName
();
static
wxString
GetProjectTableFileName
(
const
wxString
&
aProjectFullName
);
/**
* Function Load
* loads the footprint library table using the path defined in \a aFileName with
* \a aFallBackTable.
*
* @param aFileName contains the
path and possible the file name and extension
.
*
@param aFallBackTable the fall back footprint library table which can be NULL.
* @param aFileName contains the
full path to the s-expression file
.
*
* @throw IO_ERROR if an error occurs attempting to load the footprint library
* table.
*/
void
Load
(
const
wxFileName
&
aFileName
,
FP_LIB_TABLE
*
aFallBackTable
)
throw
(
IO_ERROR
);
void
Load
(
const
wxString
&
aFileName
)
throw
(
IO_ERROR
);
/**
* Function Save
* writes this table to aFileName in s-expression form.
* @param aFileName is the name of the file to write to.
*/
void
Save
(
const
wxString
&
aFileName
)
const
throw
(
IO_ERROR
);
protected
:
...
...
include/project.h
View file @
a7f19392
...
...
@@ -82,6 +82,13 @@ public:
*/
VTBL_ENTRY
const
wxString
GetProjectFullName
()
const
;
/**
* Function FootprintLibTblName
* returns the path and filename of this project's fp-lib-table,
* i.e. the project specific one, not the global one.
*/
VTBL_ENTRY
const
wxString
FootprintLibTblName
()
const
;
/**
* Function ConfigSave
* saves the current "project" parameters into the wxConfigBase* derivative.
...
...
pcbnew/basepcbframe.cpp
View file @
a7f19392
...
...
@@ -181,7 +181,11 @@ FP_LIB_TABLE* PCB_BASE_FRAME::FootprintLibs() const
if
(
!
tbl
)
{
// Stack the project specific FP_LIB_TABLE overlay on top of the global table.
// ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
// stack this way, all using the same global fallback table.
tbl
=
new
FP_LIB_TABLE
(
&
GFootprintTable
);
prj
.
Elem
(
PROJECT
::
FPTBL
,
tbl
);
}
...
...
pcbnew/files.cpp
View file @
a7f19392
...
...
@@ -605,25 +605,25 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
// Save the project specific footprint library table.
if
(
!
FootprintLibs
()
->
IsEmpty
(
false
)
)
{
wxFileName
fn
=
pcbFileName
;
fn
.
ClearExt
();
fn
.
SetName
(
FP_LIB_TABLE
::
GetFileName
()
);
wxString
fp_lib_tbl
=
Prj
().
FootprintLibTblName
();
if
(
fn
.
FileExists
(
)
if
(
wxFileName
::
FileExists
(
fp_lib_tbl
)
&&
IsOK
(
this
,
_
(
"A footprint library table already exists in this path.
\n\n
Do "
"you want to overwrite it?"
)
)
)
{
try
{
FootprintLibs
()
->
Save
(
f
n
);
FootprintLibs
()
->
Save
(
f
p_lib_tbl
);
}
catch
(
IO_ERROR
&
ioe
)
catch
(
const
IO_ERROR
&
ioe
)
{
DisplayError
(
this
,
wxString
::
Format
(
_
(
"An error occurred attempting to save the "
wxString
msg
=
wxString
::
Format
(
_
(
"An error occurred attempting to save the "
"footprint library table '%s'
\n\n
%s"
),
GetChars
(
fn
.
GetFullPath
()
),
GetChars
(
ioe
.
errorText
)
)
);
GetChars
(
fp_lib_tbl
),
GetChars
(
ioe
.
errorText
)
);
DisplayError
(
this
,
msg
);
}
}
}
...
...
pcbnew/pcbnew.cpp
View file @
a7f19392
...
...
@@ -478,6 +478,9 @@ void IFACE::OnKifaceEnd()
// wxPython will do its own cleanup as part of that process.
// This should only be called if python was setup correctly.
/* bring this in, but without a linker error:
pcbnewFinishPythonScripting();
*/
#endif
}
pcbnew/pcbnew_config.cpp
View file @
a7f19392
...
...
@@ -108,7 +108,7 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
GFootprintTable
.
Format
(
&
sf
,
0
);
tableChanged
=
true
;
}
catch
(
IO_ERROR
&
ioe
)
catch
(
const
IO_ERROR
&
ioe
)
{
wxString
msg
=
wxString
::
Format
(
_
(
"Error occurred saving the global footprint library "
...
...
@@ -123,18 +123,20 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
// is kept in memory and created in the path when the new board is saved.
if
(
(
r
&
2
)
&&
!
GetBoard
()
->
GetFileName
().
IsEmpty
()
)
{
wx
FileName
fn
=
GetBoard
()
->
GetFile
Name
();
wx
String
tblName
=
Prj
().
FootprintLibTbl
Name
();
try
{
FootprintLibs
()
->
Save
(
fn
);
FootprintLibs
()
->
Save
(
tblName
);
tableChanged
=
true
;
}
catch
(
IO_ERROR
&
ioe
)
catch
(
const
IO_ERROR
&
ioe
)
{
wxString
msg
;
msg
.
Printf
(
_
(
"Error occurred saving project specific footprint library "
"table:
\n\n
%s"
),
ioe
.
errorText
.
GetData
()
);
wxString
msg
=
wxString
::
Format
(
_
(
"Error occurred saving project specific footprint library "
"table:
\n\n
%s"
),
GetChars
(
ioe
.
errorText
)
);
wxMessageBox
(
msg
,
_
(
"File Save Error"
),
wxOK
|
wxICON_ERROR
);
}
}
...
...
@@ -258,17 +260,15 @@ bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
SetElementVisibility( RATSNEST_VISIBLE, showRats );
#endif
fn
=
GetBoard
()
->
GetFileName
();
wxFileName
projectFpLibTableFileName
=
FP_LIB_TABLE
::
GetProjectTableFileName
(
fn
.
GetFullPath
()
);
wxString
projectFpLibTableFileName
=
Prj
().
FootprintLibTblName
();
FootprintLibs
()
->
Clear
();
try
{
FootprintLibs
()
->
Load
(
projectFpLibTableFileName
,
&
GFootprintTable
);
FootprintLibs
()
->
Load
(
projectFpLibTableFileName
);
}
catch
(
IO_ERROR
ioe
)
catch
(
const
IO_ERROR
&
ioe
)
{
DisplayError
(
this
,
ioe
.
errorText
);
}
...
...
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