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
65a585b5
Commit
65a585b5
authored
Jun 15, 2010
by
jean-pierre charras
Browse files
Options
Browse Files
Download
Plain Diff
bitmap2component: better user interface (using wxWidgets) and more bitmaps file format import
parents
6e859e26
5ecb22b5
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
2425 additions
and
63 deletions
+2425
-63
CMakeLists.txt
bitmap2component/CMakeLists.txt
+6
-1
bitmap2cmp_gui.cpp
bitmap2component/bitmap2cmp_gui.cpp
+344
-0
bitmap2cmp_gui_base.cpp
bitmap2component/bitmap2cmp_gui_base.cpp
+120
-0
bitmap2cmp_gui_base.fbp
bitmap2component/bitmap2cmp_gui_base.fbp
+738
-0
bitmap2cmp_gui_base.h
bitmap2component/bitmap2cmp_gui_base.h
+69
-0
bitmap2component.cpp
bitmap2component/bitmap2component.cpp
+26
-62
gui_bm2cmp.cpp
bitmap2component/gui_bm2cmp.cpp
+1122
-0
No files found.
bitmap2component/CMakeLists.txt
View file @
65a585b5
...
...
@@ -5,12 +5,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
set
(
BITMAP2COMPONENT_SRCS
bitmap2component.cpp
bitmap2cmp_gui_base
bitmap2cmp_gui
)
add_executable
(
bitmap2component WIN32 MACOSX_BUNDLE
${
BITMAP2COMPONENT_SRCS
}
${
BITMAP2COMPONENT_RESOURCES
}
)
target_link_libraries
(
bitmap2component potrace kbool
)
target_link_libraries
(
bitmap2component
${
wxWidgets_LIBRARIES
}
potrace
kbool
)
install
(
TARGETS bitmap2component
DESTINATION
${
KICAD_PLUGINS
}
...
...
bitmap2component/bitmap2cmp_gui.cpp
0 → 100644
View file @
65a585b5
This diff is collapsed.
Click to expand it.
bitmap2component/bitmap2cmp_gui_base.cpp
0 → 100644
View file @
65a585b5
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "bitmap2cmp_gui_base.h"
///////////////////////////////////////////////////////////////////////////
BM2CMP_FRAME_BASE
::
BM2CMP_FRAME_BASE
(
wxWindow
*
parent
,
wxWindowID
id
,
const
wxString
&
title
,
const
wxPoint
&
pos
,
const
wxSize
&
size
,
long
style
)
:
wxFrame
(
parent
,
id
,
title
,
pos
,
size
,
style
)
{
this
->
SetSizeHints
(
wxDefaultSize
,
wxDefaultSize
);
wxBoxSizer
*
bMainSizer
;
bMainSizer
=
new
wxBoxSizer
(
wxHORIZONTAL
);
m_notebook1
=
new
wxNotebook
(
this
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
0
);
m_InitialPicturePanel
=
new
wxScrolledWindow
(
m_notebook1
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
wxHSCROLL
|
wxVSCROLL
);
m_InitialPicturePanel
->
SetScrollRate
(
5
,
5
);
m_InitialPicturePanel
->
SetMinSize
(
wxSize
(
400
,
300
)
);
m_notebook1
->
AddPage
(
m_InitialPicturePanel
,
_
(
"Original Picture"
),
true
);
m_GreyscalePicturePanel
=
new
wxScrolledWindow
(
m_notebook1
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
wxHSCROLL
|
wxVSCROLL
);
m_GreyscalePicturePanel
->
SetScrollRate
(
5
,
5
);
m_GreyscalePicturePanel
->
SetMinSize
(
wxSize
(
400
,
300
)
);
m_notebook1
->
AddPage
(
m_GreyscalePicturePanel
,
_
(
"Greyscale Picture"
),
false
);
m_BNPicturePanel
=
new
wxScrolledWindow
(
m_notebook1
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
wxHSCROLL
|
wxVSCROLL
);
m_BNPicturePanel
->
SetScrollRate
(
5
,
5
);
m_notebook1
->
AddPage
(
m_BNPicturePanel
,
_
(
"Binary Picture"
),
false
);
bMainSizer
->
Add
(
m_notebook1
,
1
,
wxEXPAND
,
5
);
wxBoxSizer
*
brightSizer
;
brightSizer
=
new
wxBoxSizer
(
wxVERTICAL
);
m_gridInfo
=
new
wxGrid
(
this
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
0
);
// Grid
m_gridInfo
->
CreateGrid
(
3
,
1
);
m_gridInfo
->
EnableEditing
(
false
);
m_gridInfo
->
EnableGridLines
(
true
);
m_gridInfo
->
EnableDragGridSize
(
false
);
m_gridInfo
->
SetMargins
(
0
,
0
);
// Columns
m_gridInfo
->
SetColSize
(
0
,
80
);
m_gridInfo
->
EnableDragColMove
(
false
);
m_gridInfo
->
EnableDragColSize
(
true
);
m_gridInfo
->
SetColLabelSize
(
30
);
m_gridInfo
->
SetColLabelValue
(
0
,
_
(
"Value"
)
);
m_gridInfo
->
SetColLabelAlignment
(
wxALIGN_CENTRE
,
wxALIGN_CENTRE
);
// Rows
m_gridInfo
->
AutoSizeRows
();
m_gridInfo
->
EnableDragRowSize
(
true
);
m_gridInfo
->
SetRowLabelSize
(
80
);
m_gridInfo
->
SetRowLabelValue
(
0
,
_
(
"Size X"
)
);
m_gridInfo
->
SetRowLabelValue
(
1
,
_
(
"Size Y"
)
);
m_gridInfo
->
SetRowLabelValue
(
2
,
_
(
"BPP"
)
);
m_gridInfo
->
SetRowLabelAlignment
(
wxALIGN_RIGHT
,
wxALIGN_CENTRE
);
// Label Appearance
// Cell Defaults
m_gridInfo
->
SetDefaultCellAlignment
(
wxALIGN_LEFT
,
wxALIGN_TOP
);
brightSizer
->
Add
(
m_gridInfo
,
0
,
wxEXPAND
|
wxALIGN_CENTER_HORIZONTAL
,
5
);
m_buttonLoad
=
new
wxButton
(
this
,
wxID_ANY
,
_
(
"Load Bitmap"
),
wxDefaultPosition
,
wxDefaultSize
,
0
);
brightSizer
->
Add
(
m_buttonLoad
,
0
,
wxALL
|
wxEXPAND
|
wxALIGN_CENTER_HORIZONTAL
,
5
);
m_buttonExportEeschema
=
new
wxButton
(
this
,
wxID_ANY
,
_
(
"Export to eeschema"
),
wxDefaultPosition
,
wxDefaultSize
,
0
);
brightSizer
->
Add
(
m_buttonExportEeschema
,
0
,
wxALL
|
wxEXPAND
|
wxALIGN_CENTER_HORIZONTAL
,
5
);
m_buttonExportPcbnew
=
new
wxButton
(
this
,
wxID_ANY
,
_
(
"Export to Pcbnew"
),
wxDefaultPosition
,
wxDefaultSize
,
0
);
brightSizer
->
Add
(
m_buttonExportPcbnew
,
0
,
wxALL
|
wxEXPAND
|
wxALIGN_CENTER_HORIZONTAL
,
5
);
wxString
m_rbOptionsChoices
[]
=
{
_
(
"Normal"
),
_
(
"Negative"
)
};
int
m_rbOptionsNChoices
=
sizeof
(
m_rbOptionsChoices
)
/
sizeof
(
wxString
);
m_rbOptions
=
new
wxRadioBox
(
this
,
wxID_ANY
,
_
(
"Options"
),
wxDefaultPosition
,
wxDefaultSize
,
m_rbOptionsNChoices
,
m_rbOptionsChoices
,
1
,
wxRA_SPECIFY_COLS
);
m_rbOptions
->
SetSelection
(
0
);
brightSizer
->
Add
(
m_rbOptions
,
0
,
wxALL
|
wxEXPAND
,
5
);
m_ThresholdText
=
new
wxStaticText
(
this
,
wxID_ANY
,
_
(
"Threshold Value:"
),
wxDefaultPosition
,
wxDefaultSize
,
0
);
m_ThresholdText
->
Wrap
(
-
1
);
brightSizer
->
Add
(
m_ThresholdText
,
0
,
wxTOP
|
wxRIGHT
|
wxLEFT
,
5
);
m_sliderThreshold
=
new
wxSlider
(
this
,
wxID_ANY
,
5
,
0
,
10
,
wxDefaultPosition
,
wxDefaultSize
,
wxSL_AUTOTICKS
|
wxSL_HORIZONTAL
|
wxSL_LABELS
|
wxSL_TOP
);
brightSizer
->
Add
(
m_sliderThreshold
,
0
,
wxEXPAND
|
wxALIGN_CENTER_HORIZONTAL
|
wxBOTTOM
|
wxRIGHT
|
wxLEFT
,
5
);
bMainSizer
->
Add
(
brightSizer
,
0
,
wxEXPAND
,
5
);
this
->
SetSizer
(
bMainSizer
);
this
->
Layout
();
// Connect Events
m_InitialPicturePanel
->
Connect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_GreyscalePicturePanel
->
Connect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_BNPicturePanel
->
Connect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_buttonLoad
->
Connect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnLoadFile
),
NULL
,
this
);
m_buttonExportEeschema
->
Connect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnExportEeschema
),
NULL
,
this
);
m_buttonExportPcbnew
->
Connect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnExportPcbnew
),
NULL
,
this
);
m_rbOptions
->
Connect
(
wxEVT_COMMAND_RADIOBOX_SELECTED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnOptionsSelection
),
NULL
,
this
);
m_sliderThreshold
->
Connect
(
wxEVT_SCROLL_THUMBTRACK
,
wxScrollEventHandler
(
BM2CMP_FRAME_BASE
::
OnThresholdChange
),
NULL
,
this
);
}
BM2CMP_FRAME_BASE
::~
BM2CMP_FRAME_BASE
()
{
// Disconnect Events
m_InitialPicturePanel
->
Disconnect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_GreyscalePicturePanel
->
Disconnect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_BNPicturePanel
->
Disconnect
(
wxEVT_PAINT
,
wxPaintEventHandler
(
BM2CMP_FRAME_BASE
::
OnPaint
),
NULL
,
this
);
m_buttonLoad
->
Disconnect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnLoadFile
),
NULL
,
this
);
m_buttonExportEeschema
->
Disconnect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnExportEeschema
),
NULL
,
this
);
m_buttonExportPcbnew
->
Disconnect
(
wxEVT_COMMAND_BUTTON_CLICKED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnExportPcbnew
),
NULL
,
this
);
m_rbOptions
->
Disconnect
(
wxEVT_COMMAND_RADIOBOX_SELECTED
,
wxCommandEventHandler
(
BM2CMP_FRAME_BASE
::
OnOptionsSelection
),
NULL
,
this
);
m_sliderThreshold
->
Disconnect
(
wxEVT_SCROLL_THUMBTRACK
,
wxScrollEventHandler
(
BM2CMP_FRAME_BASE
::
OnThresholdChange
),
NULL
,
this
);
}
bitmap2component/bitmap2cmp_gui_base.fbp
0 → 100644
View file @
65a585b5
This diff is collapsed.
Click to expand it.
bitmap2component/bitmap2cmp_gui_base.h
0 → 100644
View file @
65a585b5
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __bitmap2cmp_gui_base__
#define __bitmap2cmp_gui_base__
#include <wx/intl.h>
#include <wx/scrolwin.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/notebook.h>
#include <wx/grid.h>
#include <wx/button.h>
#include <wx/radiobox.h>
#include <wx/stattext.h>
#include <wx/slider.h>
#include <wx/sizer.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class BM2CMP_FRAME_BASE
///////////////////////////////////////////////////////////////////////////////
class
BM2CMP_FRAME_BASE
:
public
wxFrame
{
private
:
protected
:
wxNotebook
*
m_notebook1
;
wxScrolledWindow
*
m_InitialPicturePanel
;
wxScrolledWindow
*
m_GreyscalePicturePanel
;
wxScrolledWindow
*
m_BNPicturePanel
;
wxGrid
*
m_gridInfo
;
wxButton
*
m_buttonLoad
;
wxButton
*
m_buttonExportEeschema
;
wxButton
*
m_buttonExportPcbnew
;
wxRadioBox
*
m_rbOptions
;
wxStaticText
*
m_ThresholdText
;
wxSlider
*
m_sliderThreshold
;
// Virtual event handlers, overide them in your derived class
virtual
void
OnPaint
(
wxPaintEvent
&
event
){
event
.
Skip
();
}
virtual
void
OnLoadFile
(
wxCommandEvent
&
event
){
event
.
Skip
();
}
virtual
void
OnExportEeschema
(
wxCommandEvent
&
event
){
event
.
Skip
();
}
virtual
void
OnExportPcbnew
(
wxCommandEvent
&
event
){
event
.
Skip
();
}
virtual
void
OnOptionsSelection
(
wxCommandEvent
&
event
){
event
.
Skip
();
}
virtual
void
OnThresholdChange
(
wxScrollEvent
&
event
){
event
.
Skip
();
}
public
:
BM2CMP_FRAME_BASE
(
wxWindow
*
parent
,
wxWindowID
id
=
wxID_ANY
,
const
wxString
&
title
=
_
(
"Bitmap to Component Converter"
),
const
wxPoint
&
pos
=
wxDefaultPosition
,
const
wxSize
&
size
=
wxSize
(
500
,
419
),
long
style
=
wxDEFAULT_FRAME_STYLE
|
wxTAB_TRAVERSAL
);
~
BM2CMP_FRAME_BASE
();
};
#endif //__bitmap2cmp_gui_base__
bitmap2component/bitmap2component.cpp
View file @
65a585b5
...
...
@@ -32,7 +32,7 @@
#include <vector>
#include "potracelib.h"
#include "bitmap_io.h"
//
#include "bitmap_io.h"
#include "auxiliary.h"
...
...
@@ -49,6 +49,13 @@ enum output_format {
PCBNEW_FMT
,
EESCHEMA_FMT
};
/* free a potrace bitmap */
static
void
bm_free
(
potrace_bitmap_t
*
bm
)
{
if
(
bm
!=
NULL
)
{
free
(
bm
->
map
);
}
free
(
bm
);
}
/* Helper class th handle useful info to convert a bitmpa to
...
...
@@ -185,53 +192,11 @@ void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
}
int
main
(
int
argc
,
char
*
argv
[]
)
int
bitmap2component
(
potrace_bitmap_t
*
aPotrace_bitmap
,
FILE
*
aOutfile
,
int
aFormat
)
{
potrace_bitmap_t
*
potrace_bitmap
=
NULL
;
potrace_param_t
*
param
;
potrace_state_t
*
st
;
int
error
;
int
fmt_option
=
'0'
;
FILE
*
infile
,
*
outfile
=
NULL
;
if
(
argc
<
4
)
{
printf
(
"Usage:
\n
bitmap2component <infile_bitmap.ext> <outfile.ext> <0,1,2>
\n
"
);
printf
(
" Allowed bitmap files formats are .bmp or .pgm
\n
"
);
printf
(
"output format:
\n
0 = pcbnew.emp, 1 = eeschema.lib, 2 = ps
\n
"
);
return
-
1
;
}
infile
=
fopen
(
argv
[
1
],
"r"
);
if
(
infile
==
NULL
)
{
printf
(
"File %s could not be opened
\n
"
,
argv
[
1
]
);
return
-
2
;
}
outfile
=
fopen
(
argv
[
2
],
"w"
);
if
(
outfile
==
NULL
)
{
printf
(
"File %s could not be opened
\n
"
,
argv
[
2
]
);
return
-
2
;
}
double
threshold
=
0.5
;
// = 0 to 1.0
error
=
bm_read
(
infile
,
threshold
,
&
potrace_bitmap
);
if
(
error
!=
0
)
{
printf
(
"Bitmap %s could not be read
\n
"
,
argv
[
1
]
);
return
-
2
;
}
if
(
!
potrace_bitmap
)
{
fprintf
(
stderr
,
"Error allocating bitmap: %s
\n
"
,
strerror
(
errno
)
);
return
1
;
}
/* set tracing parameters, starting from defaults */
param
=
potrace_param_default
();
...
...
@@ -243,7 +208,7 @@ int main( int argc, char* argv[] )
param
->
turdsize
=
0
;
/* convert the bitmap to curves */
st
=
potrace_trace
(
param
,
p
otrace_bitmap
);
st
=
potrace_trace
(
param
,
aP
otrace_bitmap
);
if
(
!
st
||
st
->
status
!=
POTRACE_STATUS_OK
)
{
fprintf
(
stderr
,
"Error tracing bitmap: %s
\n
"
,
strerror
(
errno
)
);
...
...
@@ -251,41 +216,40 @@ int main( int argc, char* argv[] )
}
BITMAPCONV_INFO
info
;
info
.
m_PixmapWidth
=
p
otrace_bitmap
->
w
;
info
.
m_PixmapHeight
=
p
otrace_bitmap
->
h
;
// the bitmap size in pixels
info
.
m_PixmapWidth
=
aP
otrace_bitmap
->
w
;
info
.
m_PixmapHeight
=
aP
otrace_bitmap
->
h
;
// the bitmap size in pixels
info
.
m_Paths
=
st
->
plist
;
info
.
m_Outfile
=
o
utfile
;
info
.
m_Outfile
=
aO
utfile
;
if
(
argc
>=
4
)
fmt_option
=
argv
[
3
][
0
];
switch
(
fmt_option
)
switch
(
aFormat
)
{
case
'2'
:
case
2
:
info
.
m_Format
=
POSTSCRIPT_FMT
;
info
.
m_ScaleX
=
info
.
m_ScaleY
=
1.0
;
// the conversion scale
/* output vector data, e.g. as a rudimentary EPS file */
CreateOutputFile
(
info
);
break
;
case
'1'
:
case
1
:
info
.
m_Format
=
EESCHEMA_FMT
;
info
.
m_ScaleX
=
info
.
m_ScaleY
=
1000.0
/
300
;
// the conversion scale
info
.
m_ScaleX
=
1000.0
/
300
;
// the conversion scale
info
.
m_ScaleY
=
-
info
.
m_ScaleX
;
// Y axis is bottom to Top for components in libs
CreateOutputFile
(
info
);
break
;
case
'0'
:
case
0
:
info
.
m_Format
=
PCBNEW_FMT
;
info
.
m_ScaleX
=
10000.0
/
300
;
// the conversion scale
info
.
m_ScaleY
=
-
info
.
m_ScaleX
;
// Y axis is top to bottom in modedit
info
.
m_ScaleY
=
info
.
m_ScaleX
;
// Y axis is top to bottom in modedit
CreateOutputFile
(
info
);
break
;
default
:
printf
(
"Unknown output format
\n
"
);
break
;
}
CreateOutputFile
(
info
);
bm_free
(
potrace_bitmap
);
bm_free
(
aPotrace_bitmap
);
potrace_state_free
(
st
);
potrace_param_free
(
param
);
...
...
bitmap2component/gui_bm2cmp.cpp
0 → 100644
View file @
65a585b5
This diff is collapsed.
Click to expand it.
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