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
51a83a7a
Commit
51a83a7a
authored
Apr 17, 2012
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cvpcb LEGACY_PLUGIN usage factoring
parent
3341669f
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
246 deletions
+119
-246
loadcmp.cpp
cvpcb/loadcmp.cpp
+26
-99
export_to_pcbnew.cpp
gerbview/export_to_pcbnew.cpp
+29
-83
class_board.h
pcbnew/class_board.h
+1
-1
legacy_plugin.cpp
pcbnew/legacy_plugin.cpp
+55
-57
legacy_plugin.h
pcbnew/legacy_plugin.h
+8
-6
No files found.
cvpcb/loadcmp.cpp
View file @
51a83a7a
...
...
@@ -17,8 +17,7 @@
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <class_DisplayFootprintsFrame.h>
#include <richio.h>
#include <filter_reader.h>
#include <io_mgr.h>
#include <wildcards_and_files_ext.h>
...
...
@@ -29,122 +28,50 @@
* @param CmpName - Module name
* @return - a pointer to the loaded module or NULL.
*/
MODULE
*
DISPLAY_FOOTPRINTS_FRAME
::
Get_Module
(
const
wxString
&
Cmp
Name
)
MODULE
*
DISPLAY_FOOTPRINTS_FRAME
::
Get_Module
(
const
wxString
&
aFootprint
Name
)
{
int
Found
=
0
;
unsigned
ii
;
char
*
Line
;
char
Name
[
255
];
wxString
tmp
,
msg
;
wxFileName
fn
;
MODULE
*
Module
=
NULL
;
CVPCB_MAINFRAME
*
parent
=
(
CVPCB_MAINFRAME
*
)
GetParent
();
for
(
ii
=
0
;
ii
<
parent
->
m_ModuleLibNames
.
GetCount
();
ii
++
)
try
{
fn
=
parent
->
m_ModuleLibNames
[
ii
];
fn
.
SetExt
(
FootprintLibFileExtension
);
tmp
=
wxGetApp
().
FindLibraryPath
(
fn
);
PLUGIN
::
RELEASER
pi
(
IO_MGR
::
PluginFind
(
IO_MGR
::
LEGACY
)
);
if
(
!
tmp
)
for
(
unsigned
i
=
0
;
i
<
parent
->
m_ModuleLibNames
.
GetCount
();
++
i
)
{
msg
.
Printf
(
_
(
"PCB foot print library file <%s> could not be \
found in the default search paths."
),
GetChars
(
fn
.
GetFullName
()
)
);
wxMessageBox
(
msg
,
titleLibLoadError
,
wxOK
|
wxICON_ERROR
,
this
);
continue
;
}
wxFileName
fn
=
parent
->
m_ModuleLibNames
[
i
];
FILE
*
file
=
wxFopen
(
tmp
,
wxT
(
"rt"
)
);
fn
.
SetExt
(
FootprintLibFileExtension
);
wxString
libPath
=
wxGetApp
().
FindLibraryPath
(
fn
);
if
(
file
==
NULL
)
if
(
!
libPath
)
{
msg
.
Printf
(
_
(
"Could not open PCB foot print library file <%s>."
),
GetChars
(
tmp
)
);
wxString
msg
=
wxString
::
Format
(
_
(
"PCB foot print library file <%s> could not be found in the default search paths."
),
fn
.
GetFullName
().
GetData
()
);
// @todo we should not be using wxMessageBox directly.
wxMessageBox
(
msg
,
titleLibLoadError
,
wxOK
|
wxICON_ERROR
,
this
);
continue
;
}
FILE_LINE_READER
fileReader
(
file
,
tmp
);
FILTER_READER
reader
(
fileReader
);
/* Read header. */
reader
.
ReadLine
();
Line
=
reader
.
Line
();
StrPurge
(
Line
);
MODULE
*
footprint
=
pi
->
FootprintLoad
(
libPath
,
aFootprintName
);
if
(
strnicmp
(
Line
,
FOOTPRINT_LIBRARY_HEADER
,
FOOTPRINT_LIBRARY_HEADER_CNT
)
!=
0
)
if
(
footprint
)
{
msg
.
Printf
(
_
(
"<%s> is not a valid KiCad PCB foot print library."
),
GetChars
(
tmp
)
);
wxMessageBox
(
msg
,
titleLibLoadError
,
wxOK
|
wxICON_ERROR
,
this
);
fclose
(
file
);
return
NULL
;
}
Found
=
0
;
while
(
!
Found
&&
reader
.
ReadLine
()
)
{
Line
=
reader
.
Line
();
if
(
strncmp
(
Line
,
"$MODULE"
,
6
)
==
0
)
break
;
if
(
strnicmp
(
Line
,
"$INDEX"
,
6
)
==
0
)
{
while
(
reader
.
ReadLine
()
)
{
Line
=
reader
.
Line
();
if
(
strnicmp
(
Line
,
"$EndINDEX"
,
9
)
==
0
)
break
;
StrPurge
(
Line
);
if
(
stricmp
(
Line
,
TO_UTF8
(
CmpName
)
)
==
0
)
{
Found
=
1
;
break
;
footprint
->
SetPosition
(
wxPoint
(
0
,
0
)
);
return
footprint
;
}
}
}
}
while
(
Found
&&
reader
.
ReadLine
()
)
catch
(
IO_ERROR
ioe
)
{
Line
=
reader
.
Line
();
if
(
Line
[
0
]
!=
'$'
)
continue
;
if
(
Line
[
1
]
!=
'M'
)
continue
;
if
(
strnicmp
(
Line
,
"$MODULE"
,
7
)
!=
0
)
continue
;
/* Read component name. */
sscanf
(
Line
+
7
,
" %s"
,
Name
);
if
(
stricmp
(
Name
,
TO_UTF8
(
CmpName
)
)
==
0
)
{
Module
=
new
MODULE
(
GetBoard
()
);
// Switch the locale to standard C (needed to print floating
// point numbers like 1.3)
SetLocaleTo_C_standard
();
Module
->
ReadDescr
(
&
reader
);
SetLocaleTo_Default
();
// revert to the current locale
Module
->
SetPosition
(
wxPoint
(
0
,
0
)
);
return
Module
;
}
}
file
=
NULL
;
DisplayError
(
this
,
ioe
.
errorText
);
return
NULL
;
}
msg
.
Printf
(
_
(
"Module %s not found"
),
Cmp
Name
.
GetData
()
);
wxString
msg
=
wxString
::
Format
(
_
(
"Footprint '%s' not found"
),
aFootprint
Name
.
GetData
()
);
DisplayError
(
this
,
msg
);
return
NULL
;
}
gerbview/export_to_pcbnew.cpp
View file @
51a83a7a
...
...
@@ -15,6 +15,7 @@
#include <../pcbnew/class_track.h>
#include <../pcbnew/class_drawsegment.h>
#include <io_mgr.h>
#include <gerbview.h>
#include <class_board_design_settings.h>
#include <class_gerber_draw_item.h>
...
...
@@ -26,32 +27,35 @@
*/
class
GBR_TO_PCB_EXPORTER
{
GERBVIEW_FRAME
*
m_gerbview_frame
;
// the maint gerber frame
FILE
*
m_file
;
// .brd file to write to
BOARD
*
m_pcb
;
// the board to populate and export
public
:
GBR_TO_PCB_EXPORTER
(
GERBVIEW_FRAME
*
aFrame
,
FILE
*
aFil
e
);
GBR_TO_PCB_EXPORTER
(
GERBVIEW_FRAME
*
aFrame
,
const
wxString
&
aFileNam
e
);
~
GBR_TO_PCB_EXPORTER
();
/**
* Function ExportPcb
* saves a board from a gerber load.
*/
bool
ExportPcb
(
int
*
LayerLookUpTable
);
BOARD
*
GetBoard
()
{
return
m_pcb
;
}
private
:
bool
WriteSetup
(
);
// Write the SETUP section data file
bool
WriteGeneralDescrPcb
(
);
void
export_non_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
);
void
export_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
);
void
export_flashed_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
);
void
export_segline_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
);
void
export_segarc_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
);
void
cleanBoard
();
GERBVIEW_FRAME
*
m_gerbview_frame
;
// the maint gerber frame
wxString
m_file_name
;
// BOARD file to write to
BOARD
*
m_pcb
;
// the board to populate and export
};
GBR_TO_PCB_EXPORTER
::
GBR_TO_PCB_EXPORTER
(
GERBVIEW_FRAME
*
aFrame
,
FILE
*
aFil
e
)
GBR_TO_PCB_EXPORTER
::
GBR_TO_PCB_EXPORTER
(
GERBVIEW_FRAME
*
aFrame
,
const
wxString
&
aFileNam
e
)
{
m_gerbview_frame
=
aFrame
;
m_file
=
aFil
e
;
m_file
_name
=
aFileNam
e
;
m_pcb
=
new
BOARD
();
}
...
...
@@ -84,12 +88,12 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
return
;
}
wxString
FullF
ileName
,
msg
;
wxString
f
ileName
,
msg
;
wxString
PcbExt
(
wxT
(
".brd"
)
);
msg
=
wxT
(
"*"
)
+
PcbExt
;
FullF
ileName
=
EDA_FileSelector
(
_
(
"Board file name:"
),
f
ileName
=
EDA_FileSelector
(
_
(
"Board file name:"
),
wxEmptyString
,
wxEmptyString
,
PcbExt
,
...
...
@@ -98,7 +102,7 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
wxFD_SAVE
,
false
);
if
(
FullF
ileName
==
wxEmptyString
)
if
(
f
ileName
==
wxEmptyString
)
return
;
/* Install a dialog frame to choose the mapping
...
...
@@ -111,24 +115,15 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
if
(
ok
!=
wxID_OK
)
return
;
if
(
wxFileExists
(
FullF
ileName
)
)
if
(
wxFileExists
(
f
ileName
)
)
{
if
(
!
IsOK
(
this
,
_
(
"Ok to change the existing file ?"
)
)
)
return
;
}
FILE
*
file
=
wxFopen
(
FullFileName
,
wxT
(
"wt"
)
);
if
(
file
==
NULL
)
{
msg
=
_
(
"Unable to create "
)
+
FullFileName
;
DisplayError
(
this
,
msg
);
return
;
}
GBR_TO_PCB_EXPORTER
gbr_exporter
(
this
,
fileName
);
GBR_TO_PCB_EXPORTER
gbr_exporter
(
this
,
file
);
gbr_exporter
.
ExportPcb
(
dlg
->
GetLayersLookUpTable
()
);
fclose
(
file
);
}
...
...
@@ -162,54 +157,6 @@ void GBR_TO_PCB_EXPORTER::cleanBoard()
}
bool
GBR_TO_PCB_EXPORTER
::
WriteSetup
(
)
{
fprintf
(
m_file
,
"$SETUP
\n
"
);
fprintf
(
m_file
,
"InternalUnit %f INCH
\n
"
,
1.0
/
PCB_INTERNAL_UNIT
);
fprintf
(
m_file
,
"Layers %d
\n
"
,
m_pcb
->
GetCopperLayerCount
()
);
fprintf
(
m_file
,
"$EndSETUP
\n\n
"
);
return
true
;
}
bool
GBR_TO_PCB_EXPORTER
::
WriteGeneralDescrPcb
(
)
{
int
nbLayers
;
// Print the copper layer count
nbLayers
=
m_pcb
->
GetCopperLayerCount
();
if
(
nbLayers
<=
1
)
// Minimal layers count in Pcbnew is 2
{
nbLayers
=
2
;
m_pcb
->
SetCopperLayerCount
(
2
);
}
fprintf
(
m_file
,
"$GENERAL
\n
"
);
fprintf
(
m_file
,
"encoding utf-8
\n
"
);
fprintf
(
m_file
,
"LayerCount %d
\n
"
,
nbLayers
);
// Compute and print the board bounding box
EDA_RECT
bbbox
=
m_pcb
->
ComputeBoundingBox
();
fprintf
(
m_file
,
"Di %d %d %d %d
\n
"
,
bbbox
.
GetX
(),
bbbox
.
GetY
(),
bbbox
.
GetRight
(),
bbbox
.
GetBottom
()
);
fprintf
(
m_file
,
"$EndGENERAL
\n\n
"
);
return
true
;
}
/* Routine to save the board
* @param frame = pointer to the main frame
* @param File = FILE * pointer to an already opened file
* @param LayerLookUpTable = look up table: Pcbnew layer for each gerber layer
* @return 1 if OK, 0 if fail
*/
bool
GBR_TO_PCB_EXPORTER
::
ExportPcb
(
int
*
LayerLookUpTable
)
{
BOARD
*
gerberPcb
=
m_gerbview_frame
->
GetBoard
();
...
...
@@ -235,22 +182,21 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable )
cleanBoard
();
m_pcb
->
SetCopperLayerCount
(
LayerLookUpTable
[
32
]
);
// Switch the locale to standard C (needed to print floating point numbers)
SetLocaleTo_C_standard
();
// write PCB header
fprintf
(
m_file
,
"PCBNEW-BOARD Version %d date %s
\n\n
"
,
LEGACY_BOARD_FILE_VERSION
,
TO_UTF8
(
DateAndTime
()
)
);
WriteGeneralDescrPcb
(
);
WriteSetup
(
);
// write items on file
m_pcb
->
Save
(
m_file
);
try
{
PLUGIN
::
RELEASER
pi
(
IO_MGR
::
PluginFind
(
IO_MGR
::
LEGACY
)
);
pi
->
Save
(
m_file_name
,
m_pcb
);
}
catch
(
IO_ERROR
ioe
)
{
DisplayError
(
m_gerbview_frame
,
ioe
.
errorText
);
return
false
;
}
SetLocaleTo_Default
();
// revert to the current locale
return
true
;
}
void
GBR_TO_PCB_EXPORTER
::
export_non_copper_item
(
GERBER_DRAW_ITEM
*
aGbrItem
,
int
aLayer
)
{
DRAWSEGMENT
*
drawitem
=
new
DRAWSEGMENT
(
m_pcb
,
PCB_LINE_T
);
...
...
pcbnew/class_board.h
View file @
51a83a7a
...
...
@@ -848,7 +848,7 @@ public:
* ( using the default netclass value or a preset value )
* the default netclass is always in m_TrackWidthList[0]
*/
int
GetCurrentTrackWidth
()
int
GetCurrentTrackWidth
()
const
{
return
m_TrackWidthList
[
m_TrackWidthSelector
];
}
...
...
pcbnew/legacy_plugin.cpp
View file @
51a83a7a
This diff is collapsed.
Click to expand it.
pcbnew/legacy_plugin.h
View file @
51a83a7a
...
...
@@ -40,6 +40,7 @@ class NETINFO;
class
TEXTE_PCB
;
class
TRACK
;
class
NETCLASS
;
class
NETCLASSES
;
class
ZONE_CONTAINER
;
class
DIMENSION
;
class
NETINFO_ITEM
;
...
...
@@ -114,6 +115,8 @@ public:
MODULE
*
LoadMODULE
();
void
SaveMODULE
(
const
MODULE
*
aModule
)
const
;
void
SaveModule3D
(
const
MODULE
*
aModule
)
const
;
void
SaveBOARD
(
const
BOARD
*
aBoard
)
const
;
protected
:
...
...
@@ -247,18 +250,17 @@ protected:
*/
std
::
string
fmtDEG
(
double
aAngle
)
const
;
void
saveAllSections
()
const
;
void
saveGENERAL
()
const
;
void
saveSHEET
()
const
;
void
saveSETUP
()
const
;
void
saveBOARD
()
const
;
void
saveGENERAL
(
const
BOARD
*
aBoard
)
const
;
void
saveSHEET
(
const
BOARD
*
aBoard
)
const
;
void
saveSETUP
(
const
BOARD
*
aBoard
)
const
;
void
saveBOARD_ITEMS
(
const
BOARD
*
aBoard
)
const
;
void
saveMODULE_TEXT
(
const
TEXTE_MODULE
*
aText
)
const
;
void
saveMODULE_EDGE
(
const
EDGE_MODULE
*
aGraphic
)
const
;
void
savePAD
(
const
D_PAD
*
aPad
)
const
;
void
saveNETINFO_ITEM
(
const
NETINFO_ITEM
*
aNet
)
const
;
void
saveNETCLASSES
()
const
;
void
saveNETCLASSES
(
const
NETCLASSES
*
aNetClasses
)
const
;
void
saveNETCLASS
(
const
NETCLASS
*
aNetclass
)
const
;
void
savePCB_TEXT
(
const
TEXTE_PCB
*
aText
)
const
;
...
...
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