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
f78497bf
Commit
f78497bf
authored
May 10, 2013
by
Wayne Stambaugh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple PLOT_CONTROLLER from UI dependencies.
parent
b5bb5642
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
275 additions
and
204 deletions
+275
-204
footprint_info.cpp
common/footprint_info.cpp
+3
-0
dialog_SVG_print.cpp
pcbnew/dialogs/dialog_SVG_print.cpp
+20
-8
dialog_plot.cpp
pcbnew/dialogs/dialog_plot.cpp
+134
-8
pcbframe.cpp
pcbnew/pcbframe.cpp
+7
-0
pcbplot.cpp
pcbnew/pcbplot.cpp
+50
-172
pcbplot.h
pcbnew/pcbplot.h
+19
-10
plotcontroller.h
pcbnew/plotcontroller.h
+42
-6
No files found.
common/footprint_info.cpp
View file @
f78497bf
...
@@ -72,6 +72,9 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
...
@@ -72,6 +72,9 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
}
}
}
}
wxLogDebug
(
wxT
(
"Path <%s> -> <%s>."
),
GetChars
(
aFootprintsLibNames
[
ii
]
),
GetChars
(
filename
.
GetFullPath
()
)
);
if
(
!
filename
.
FileExists
()
)
if
(
!
filename
.
FileExists
()
)
{
{
m_filesNotFound
<<
filename
.
GetFullName
()
<<
wxT
(
"
\n
"
);
m_filesNotFound
<<
filename
.
GetFullName
()
<<
wxT
(
"
\n
"
);
...
...
pcbnew/dialogs/dialog_SVG_print.cpp
View file @
f78497bf
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
#include <convert_from_iu.h>
#include <convert_from_iu.h>
#include <wildcards_and_files_ext.h>
#include <wildcards_and_files_ext.h>
#include <macros.h>
#include <macros.h>
#include <reporter.h>
#include <confirm.h>
#include <pcbnew.h>
#include <pcbnew.h>
#include <pcbplot.h>
#include <pcbplot.h>
...
@@ -49,7 +51,7 @@
...
@@ -49,7 +51,7 @@
#define PLOTSVGPAGESIZEOPT_KEY wxT( "PlotSVGPageOpt" )
#define PLOTSVGPAGESIZEOPT_KEY wxT( "PlotSVGPageOpt" )
#define PLOTSVGPLOT_BRD_EDGE_KEY wxT( "PlotSVGBrdEdge" )
#define PLOTSVGPLOT_BRD_EDGE_KEY wxT( "PlotSVGBrdEdge" )
// reason
n
able values for default pen width
// reasonable values for default pen width
#define WIDTH_MAX_VALUE (2 * IU_PER_MM)
#define WIDTH_MAX_VALUE (2 * IU_PER_MM)
#define WIDTH_MIN_VALUE (0.05 * IU_PER_MM)
#define WIDTH_MIN_VALUE (0.05 * IU_PER_MM)
...
@@ -164,6 +166,7 @@ void DIALOG_SVG_PRINT::initDialog()
...
@@ -164,6 +166,7 @@ void DIALOG_SVG_PRINT::initDialog()
}
}
}
}
void
DIALOG_SVG_PRINT
::
OnOutputDirectoryBrowseClicked
(
wxCommandEvent
&
event
)
void
DIALOG_SVG_PRINT
::
OnOutputDirectoryBrowseClicked
(
wxCommandEvent
&
event
)
{
{
// Build the absolute path of current output plot directory
// Build the absolute path of current output plot directory
...
@@ -192,8 +195,7 @@ void DIALOG_SVG_PRINT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
...
@@ -192,8 +195,7 @@ void DIALOG_SVG_PRINT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
wxString
boardFilePath
=
(
(
wxFileName
)
m_board
->
GetFileName
()
).
GetPath
();
wxString
boardFilePath
=
(
(
wxFileName
)
m_board
->
GetFileName
()
).
GetPath
();
if
(
!
dirName
.
MakeRelativeTo
(
boardFilePath
)
)
if
(
!
dirName
.
MakeRelativeTo
(
boardFilePath
)
)
wxMessageBox
(
_
(
wxMessageBox
(
_
(
"Cannot make path relative (target volume different from board file volume)!"
),
"Cannot make path relative (target volume different from board file volume)!"
),
_
(
"Plot Output Directory"
),
wxOK
|
wxICON_ERROR
);
_
(
"Plot Output Directory"
),
wxOK
|
wxICON_ERROR
);
}
}
...
@@ -201,6 +203,7 @@ void DIALOG_SVG_PRINT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
...
@@ -201,6 +203,7 @@ void DIALOG_SVG_PRINT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
m_outputDirectory
=
m_outputDirectoryName
->
GetValue
();
m_outputDirectory
=
m_outputDirectoryName
->
GetValue
();
}
}
void
DIALOG_SVG_PRINT
::
SetPenWidth
()
void
DIALOG_SVG_PRINT
::
SetPenWidth
()
{
{
int
pensize
=
ReturnValueFromTextCtrl
(
*
m_DialogDefaultPenSize
);
int
pensize
=
ReturnValueFromTextCtrl
(
*
m_DialogDefaultPenSize
);
...
@@ -219,6 +222,7 @@ void DIALOG_SVG_PRINT::SetPenWidth()
...
@@ -219,6 +222,7 @@ void DIALOG_SVG_PRINT::SetPenWidth()
m_DialogDefaultPenSize
->
SetValue
(
ReturnStringFromValue
(
g_UserUnit
,
pensize
)
);
m_DialogDefaultPenSize
->
SetValue
(
ReturnStringFromValue
(
g_UserUnit
,
pensize
)
);
}
}
void
DIALOG_SVG_PRINT
::
ExportSVGFile
(
bool
aOnlyOneFile
)
void
DIALOG_SVG_PRINT
::
ExportSVGFile
(
bool
aOnlyOneFile
)
{
{
m_outputDirectory
=
m_outputDirectoryName
->
GetValue
();
m_outputDirectory
=
m_outputDirectoryName
->
GetValue
();
...
@@ -227,9 +231,16 @@ void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
...
@@ -227,9 +231,16 @@ void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
// absolute form). Bail if it fails
// absolute form). Bail if it fails
wxFileName
outputDir
=
wxFileName
::
DirName
(
m_outputDirectory
);
wxFileName
outputDir
=
wxFileName
::
DirName
(
m_outputDirectory
);
wxString
boardFilename
=
m_board
->
GetFileName
();
wxString
boardFilename
=
m_board
->
GetFileName
();
WX_TEXT_CTRL_REPORTER
reporter
(
m_messagesBox
);
if
(
!
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
,
m_messagesBox
)
)
if
(
!
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
,
&
reporter
)
)
{
wxString
msg
;
msg
.
Printf
(
_
(
"Could not write plot files to folder
\"
%s
\"
."
),
GetChars
(
outputDir
.
GetPath
()
)
);
DisplayError
(
this
,
msg
);
return
;
return
;
}
m_printMirror
=
m_printMirrorOpt
->
GetValue
();
m_printMirror
=
m_printMirrorOpt
->
GetValue
();
m_printBW
=
m_ModeColorOption
->
GetSelection
();
m_printBW
=
m_ModeColorOption
->
GetSelection
();
...
@@ -245,9 +256,11 @@ void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
...
@@ -245,9 +256,11 @@ void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
}
}
wxString
msg
;
wxString
msg
;
for
(
LAYER_NUM
layer
=
FIRST_LAYER
;
layer
<
NB_PCB_LAYERS
;
++
layer
)
for
(
LAYER_NUM
layer
=
FIRST_LAYER
;
layer
<
NB_PCB_LAYERS
;
++
layer
)
{
{
LAYER_MSK
currlayer_mask
=
GetLayerMask
(
layer
);
LAYER_MSK
currlayer_mask
=
GetLayerMask
(
layer
);
if
(
(
printMaskLayer
&
currlayer_mask
)
==
0
)
if
(
(
printMaskLayer
&
currlayer_mask
)
==
0
)
continue
;
continue
;
...
@@ -387,6 +400,5 @@ void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event )
...
@@ -387,6 +400,5 @@ void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event )
m_parent
->
OnModify
();
m_parent
->
OnModify
();
}
}
EndModal
(
0
);
EndModal
(
0
);
}
}
pcbnew/dialogs/dialog_plot.cpp
View file @
f78497bf
...
@@ -31,14 +31,13 @@
...
@@ -31,14 +31,13 @@
#include <wxPcbStruct.h>
#include <wxPcbStruct.h>
#include <pcbplot.h>
#include <pcbplot.h>
#include <base_units.h>
#include <base_units.h>
#include <macros.h>
#include <reporter.h>
#include <class_board.h>
#include <class_board.h>
#include <plotcontroller.h>
#include <wx/ffile.h>
#include <wx/ffile.h>
#include <dialog_plot.h>
#include <dialog_plot.h>
/**
* Class DIALOG_PLOT
*/
DIALOG_PLOT
::
DIALOG_PLOT
(
PCB_EDIT_FRAME
*
aParent
)
:
DIALOG_PLOT
::
DIALOG_PLOT
(
PCB_EDIT_FRAME
*
aParent
)
:
DIALOG_PLOT_BASE
(
aParent
),
m_parent
(
aParent
),
DIALOG_PLOT_BASE
(
aParent
),
m_parent
(
aParent
),
...
@@ -102,7 +101,6 @@ void DIALOG_PLOT::Init_Dialog()
...
@@ -102,7 +101,6 @@ void DIALOG_PLOT::Init_Dialog()
msg
=
ReturnStringFromValue
(
g_UserUnit
,
m_brdSettings
.
m_SolderMaskMinWidth
,
true
);
msg
=
ReturnStringFromValue
(
g_UserUnit
,
m_brdSettings
.
m_SolderMaskMinWidth
,
true
);
m_SolderMaskMinWidthCurrValue
->
SetLabel
(
msg
);
m_SolderMaskMinWidthCurrValue
->
SetLabel
(
msg
);
// Set units and value for HPGL pen size (this param in in mils).
// Set units and value for HPGL pen size (this param in in mils).
AddUnitSymbol
(
*
m_textPenSize
,
g_UserUnit
);
AddUnitSymbol
(
*
m_textPenSize
,
g_UserUnit
);
msg
=
ReturnStringFromValue
(
g_UserUnit
,
msg
=
ReturnStringFromValue
(
g_UserUnit
,
...
@@ -224,12 +222,14 @@ void DIALOG_PLOT::OnClose( wxCloseEvent& event )
...
@@ -224,12 +222,14 @@ void DIALOG_PLOT::OnClose( wxCloseEvent& event )
EndModal
(
0
);
EndModal
(
0
);
}
}
// A helper function to show a popup menu, when the dialog is right clicked.
// A helper function to show a popup menu, when the dialog is right clicked.
void
DIALOG_PLOT
::
OnRightClick
(
wxMouseEvent
&
event
)
void
DIALOG_PLOT
::
OnRightClick
(
wxMouseEvent
&
event
)
{
{
PopupMenu
(
m_popMenu
);
PopupMenu
(
m_popMenu
);
}
}
// Select or deselect groups of layers in the layers list:
// Select or deselect groups of layers in the layers list:
#include <layers_id_colors_and_visibility.h>
#include <layers_id_colors_and_visibility.h>
void
DIALOG_PLOT
::
OnPopUpLayers
(
wxCommandEvent
&
event
)
void
DIALOG_PLOT
::
OnPopUpLayers
(
wxCommandEvent
&
event
)
...
@@ -283,6 +283,7 @@ void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
...
@@ -283,6 +283,7 @@ void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
}
}
}
}
void
DIALOG_PLOT
::
CreateDrillFile
(
wxCommandEvent
&
event
)
void
DIALOG_PLOT
::
CreateDrillFile
(
wxCommandEvent
&
event
)
{
{
m_parent
->
InstallDrillFrame
(
event
);
m_parent
->
InstallDrillFrame
(
event
);
...
@@ -329,8 +330,7 @@ void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
...
@@ -329,8 +330,7 @@ void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
wxString
boardFilePath
=
(
(
wxFileName
)
m_parent
->
GetBoard
()
->
GetFileName
()
).
GetPath
();
wxString
boardFilePath
=
(
(
wxFileName
)
m_parent
->
GetBoard
()
->
GetFileName
()
).
GetPath
();
if
(
!
dirName
.
MakeRelativeTo
(
boardFilePath
)
)
if
(
!
dirName
.
MakeRelativeTo
(
boardFilePath
)
)
wxMessageBox
(
_
(
wxMessageBox
(
_
(
"Cannot make path relative (target volume different from board file volume)!"
),
"Cannot make path relative (target volume different from board file volume)!"
),
_
(
"Plot Output Directory"
),
wxOK
|
wxICON_ERROR
);
_
(
"Plot Output Directory"
),
wxOK
|
wxICON_ERROR
);
}
}
...
@@ -354,6 +354,7 @@ PlotFormat DIALOG_PLOT::GetPlotFormat()
...
@@ -354,6 +354,7 @@ PlotFormat DIALOG_PLOT::GetPlotFormat()
return
plotFmt
[
m_plotFormatOpt
->
GetSelection
()
];
return
plotFmt
[
m_plotFormatOpt
->
GetSelection
()
];
}
}
// Enable or disable widgets according to the plot format selected
// Enable or disable widgets according to the plot format selected
// and clear also some optional values
// and clear also some optional values
void
DIALOG_PLOT
::
SetPlotFormat
(
wxCommandEvent
&
event
)
void
DIALOG_PLOT
::
SetPlotFormat
(
wxCommandEvent
&
event
)
...
@@ -533,6 +534,8 @@ static bool setDouble( double* aResult, double aValue, double aMin, double aMax
...
@@ -533,6 +534,8 @@ static bool setDouble( double* aResult, double aValue, double aMin, double aMax
*
aResult
=
aValue
;
*
aResult
=
aValue
;
return
true
;
return
true
;
}
}
static
bool
setInt
(
int
*
aResult
,
int
aValue
,
int
aMin
,
int
aMax
)
static
bool
setInt
(
int
*
aResult
,
int
aValue
,
int
aMin
,
int
aMax
)
{
{
if
(
aValue
<
aMin
)
if
(
aValue
<
aMin
)
...
@@ -691,3 +694,126 @@ void DIALOG_PLOT::applyPlotSettings()
...
@@ -691,3 +694,126 @@ void DIALOG_PLOT::applyPlotSettings()
m_parent
->
OnModify
();
m_parent
->
OnModify
();
}
}
}
}
void
DIALOG_PLOT
::
Plot
(
wxCommandEvent
&
event
)
{
applyPlotSettings
();
// Create output directory if it does not exist (also transform it in
// absolute form). Bail if it fails
wxFileName
outputDir
=
wxFileName
::
DirName
(
m_plotOpts
.
GetOutputDirectory
()
);
wxString
boardFilename
=
m_parent
->
GetBoard
()
->
GetFileName
();
WX_TEXT_CTRL_REPORTER
reporter
(
m_messagesBox
);
if
(
!
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
,
&
reporter
)
)
{
wxString
msg
;
msg
.
Printf
(
_
(
"Could not write plot files to folder
\"
%s
\"
."
),
GetChars
(
outputDir
.
GetPath
()
)
);
DisplayError
(
this
,
msg
);
return
;
}
m_plotOpts
.
SetAutoScale
(
false
);
m_plotOpts
.
SetScale
(
1
);
switch
(
m_plotOpts
.
GetScaleSelection
()
)
{
default
:
break
;
case
0
:
// Autoscale option
m_plotOpts
.
SetAutoScale
(
true
);
break
;
case
2
:
// 3:2 option
m_plotOpts
.
SetScale
(
1.5
);
break
;
case
3
:
// 2:1 option
m_plotOpts
.
SetScale
(
2
);
break
;
case
4
:
// 3:1 option
m_plotOpts
.
SetScale
(
3
);
break
;
}
/* If the scale factor edit controls are disabled or the scale value
* is 0, don't adjust the base scale factor. This fixes a bug when
* the default scale adjust is initialized to 0 and saved in program
* settings resulting in a divide by zero fault.
*/
if
(
m_fineAdjustXscaleOpt
->
IsEnabled
()
&&
m_XScaleAdjust
!=
0.0
)
m_plotOpts
.
SetFineScaleAdjustX
(
m_XScaleAdjust
);
if
(
m_fineAdjustYscaleOpt
->
IsEnabled
()
&&
m_YScaleAdjust
!=
0.0
)
m_plotOpts
.
SetFineScaleAdjustY
(
m_YScaleAdjust
);
if
(
m_PSFineAdjustWidthOpt
->
IsEnabled
()
)
m_plotOpts
.
SetWidthAdjust
(
m_PSWidthAdjust
);
wxString
file_ext
(
GetDefaultPlotExtension
(
m_plotOpts
.
GetFormat
()
)
);
// Test for a reasonable scale value
// XXX could this actually happen? isn't it constrained in the apply
// function?
if
(
m_plotOpts
.
GetScale
()
<
PLOT_MIN_SCALE
)
DisplayInfoMessage
(
this
,
_
(
"Warning: Scale option set to a very small value"
)
);
if
(
m_plotOpts
.
GetScale
()
>
PLOT_MAX_SCALE
)
DisplayInfoMessage
(
this
,
_
(
"Warning: Scale option set to a very large value"
)
);
// Save the current plot options in the board
m_parent
->
SetPlotSettings
(
m_plotOpts
);
for
(
LAYER_NUM
layer
=
FIRST_LAYER
;
layer
<
NB_PCB_LAYERS
;
++
layer
)
{
if
(
m_plotOpts
.
GetLayerSelection
()
&
GetLayerMask
(
layer
)
)
{
// Pick the basename from the board file
wxFileName
fn
(
boardFilename
);
// Use Gerber Extensions based on layer number
// (See http://en.wikipedia.org/wiki/Gerber_File)
if
(
(
m_plotOpts
.
GetFormat
()
==
PLOT_FORMAT_GERBER
)
&&
m_useGerberExtensions
->
GetValue
()
)
file_ext
=
GetGerberExtension
(
layer
);
// Create file name (from the English layer name for non copper layers).
BuildPlotFileName
(
&
fn
,
outputDir
.
GetPath
(),
m_board
->
GetStandardLayerName
(
layer
),
file_ext
);
LOCALE_IO
toggle
;
BOARD
*
board
=
m_parent
->
GetBoard
();
PLOTTER
*
plotter
=
StartPlotBoard
(
board
,
&
m_plotOpts
,
fn
.
GetFullPath
(),
wxEmptyString
);
// Print diags in messages box:
wxString
msg
;
if
(
plotter
)
{
PlotOneBoardLayer
(
board
,
plotter
,
layer
,
m_plotOpts
);
plotter
->
EndPlot
();
delete
plotter
;
msg
.
Printf
(
_
(
"Plot file <%s> created"
),
GetChars
(
fn
.
GetFullPath
()
)
);
}
else
msg
.
Printf
(
_
(
"Unable to create <%s>"
),
GetChars
(
fn
.
GetFullPath
()
)
);
msg
<<
wxT
(
"
\n
"
);
m_messagesBox
->
AppendText
(
msg
);
}
}
// If no layer selected, we have nothing plotted.
// Prompt user if it happens because he could think there is a bug in Pcbnew.
if
(
!
m_plotOpts
.
GetLayerSelection
()
)
DisplayError
(
this
,
_
(
"No layer selected"
)
);
}
pcbnew/pcbframe.cpp
View file @
f78497bf
...
@@ -53,6 +53,7 @@
...
@@ -53,6 +53,7 @@
#include <module_editor_frame.h>
#include <module_editor_frame.h>
#include <dialog_SVG_print.h>
#include <dialog_SVG_print.h>
#include <dialog_helpers.h>
#include <dialog_helpers.h>
#include <dialog_plot.h>
#include <convert_from_iu.h>
#include <convert_from_iu.h>
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
...
@@ -853,3 +854,9 @@ void PCB_EDIT_FRAME::OnSelectAutoPlaceMode( wxCommandEvent& aEvent )
...
@@ -853,3 +854,9 @@ void PCB_EDIT_FRAME::OnSelectAutoPlaceMode( wxCommandEvent& aEvent )
}
}
}
}
void
PCB_EDIT_FRAME
::
ToPlotter
(
wxCommandEvent
&
event
)
{
DIALOG_PLOT
dlg
(
this
);
dlg
.
ShowModal
();
}
pcbnew/pcbplot.cpp
View file @
f78497bf
/**
* @file pcbnew/pcbplot.cpp
*/
/*
/*
* This program source code file is part of KiCad, a free EDA CAD application.
* This program source code file is part of KiCad, a free EDA CAD application.
*
*
...
@@ -27,6 +23,10 @@
...
@@ -27,6 +23,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
*/
/**
* @file pcbnew/pcbplot.cpp
*/
#include <fctsys.h>
#include <fctsys.h>
#include <plot_common.h>
#include <plot_common.h>
#include <confirm.h>
#include <confirm.h>
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include <pcbplot.h>
#include <pcbplot.h>
#include <pcbstruct.h>
#include <pcbstruct.h>
#include <base_units.h>
#include <base_units.h>
#include <reporter.h>
#include <class_board.h>
#include <class_board.h>
#include <pcbnew.h>
#include <pcbnew.h>
#include <plotcontroller.h>
#include <plotcontroller.h>
...
@@ -43,9 +44,7 @@
...
@@ -43,9 +44,7 @@
#include <macros.h>
#include <macros.h>
/** Get the 'traditional' gerber extension depending on the layer
wxString
GetGerberExtension
(
LAYER_NUM
layer
)
*/
static
wxString
GetGerberExtension
(
LAYER_NUM
layer
)
/*{{{*/
{
{
switch
(
layer
)
switch
(
layer
)
{
{
...
@@ -107,14 +106,10 @@ static wxString GetGerberExtension( LAYER_NUM layer )/*{{{*/
...
@@ -107,14 +106,10 @@ static wxString GetGerberExtension( LAYER_NUM layer )/*{{{*/
default:
default:
return
wxString
(
wxT
(
"gbr"
)
);
return
wxString
(
wxT
(
"gbr"
)
);
}
}
}
/*}}}*/
}
/* Complete a plot filename: forces the output directory,
* add a suffix to the name and sets the specified extension
void
BuildPlotFileName
(
wxFileName
*
aFilename
,
* the suffix is usually the layer name
* replaces not allowed chars in suffix by '_'
*/
void
BuildPlotFileName
(
wxFileName
*
aFilename
,
const
wxString
&
aOutputDir
,
const
wxString
&
aOutputDir
,
const
wxString
&
aSuffix
,
const
wxString
&
aSuffix
,
const
wxString
&
aExtension
)
const
wxString
&
aExtension
)
...
@@ -141,190 +136,73 @@ void BuildPlotFileName( wxFileName *aFilename,
...
@@ -141,190 +136,73 @@ void BuildPlotFileName( wxFileName *aFilename,
aFilename
->
SetName
(
aFilename
->
GetName
()
+
wxT
(
"-"
)
+
suffix
);
aFilename
->
SetName
(
aFilename
->
GetName
()
+
wxT
(
"-"
)
+
suffix
);
}
}
/*
* Fix the output directory pathname to absolute and ensure it exists
bool
EnsureOutputDirectory
(
wxFileName
*
aOutputDir
,
* (Creates it if not exists)
*/
bool
EnsureOutputDirectory
(
wxFileName
*
aOutputDir
,
const
wxString
&
aBoardFilename
,
const
wxString
&
aBoardFilename
,
wxTextCtrl
*
aMessageBox
)
REPORTER
*
aReporter
)
{
{
wxString
msg
;
wxString
boardFilePath
=
wxFileName
(
aBoardFilename
).
GetPath
();
wxString
boardFilePath
=
wxFileName
(
aBoardFilename
).
GetPath
();
if
(
!
aOutputDir
->
MakeAbsolute
(
boardFilePath
)
)
if
(
!
aOutputDir
->
MakeAbsolute
(
boardFilePath
)
)
{
{
wxString
msg
;
if
(
aReporter
)
msg
.
Printf
(
_
(
"Cannot make <%s> absolute with respect to <%s>!"
),
{
msg
.
Printf
(
_
(
"*** Error: cannot make path <%s> absolute with respect to <%s>! ***"
),
GetChars
(
aOutputDir
->
GetPath
()
),
GetChars
(
aOutputDir
->
GetPath
()
),
GetChars
(
boardFilePath
)
);
GetChars
(
boardFilePath
)
);
wxMessageBox
(
msg
,
_
(
"Plot"
),
wxOK
|
wxICON_ERROR
);
aReporter
->
Report
(
msg
);
}
return
false
;
return
false
;
}
}
wxString
outputPath
(
aOutputDir
->
GetPath
()
);
wxString
outputPath
(
aOutputDir
->
GetPath
()
);
if
(
!
wxFileName
::
DirExists
(
outputPath
)
)
if
(
!
wxFileName
::
DirExists
(
outputPath
)
)
{
{
if
(
wxMkdir
(
outputPath
)
)
if
(
wxMkdir
(
outputPath
)
)
{
{
if
(
a
MessageBox
)
if
(
a
Reporter
)
{
{
wxString
msg
;
msg
.
Printf
(
_
(
"Output directory <%s> created.
\n
"
),
GetChars
(
outputPath
)
);
msg
.
Printf
(
_
(
"Directory <%s> created.
\n
"
),
GetChars
(
outputPath
)
);
aReporter
->
Report
(
msg
);
aMessageBox
->
AppendText
(
msg
);
return
true
;
return
true
;
}
}
}
}
else
else
{
{
if
(
aMessageBox
)
if
(
aReporter
)
wxMessageBox
(
_
(
"Cannot create output directory!"
),
_
(
"Plot"
),
wxOK
|
wxICON_ERROR
);
return
false
;
}
}
return
true
;
}
/*
* DIALOG_PLOT:Plot
* Actually creates the files
*/
void
DIALOG_PLOT
::
Plot
(
wxCommandEvent
&
event
)
{
applyPlotSettings
();
// Create output directory if it does not exist (also transform it in
// absolute form). Bail if it fails
wxFileName
outputDir
=
wxFileName
::
DirName
(
m_plotOpts
.
GetOutputDirectory
()
);
wxString
boardFilename
=
m_parent
->
GetBoard
()
->
GetFileName
();
if
(
!
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
,
m_messagesBox
)
)
return
;
m_plotOpts
.
SetAutoScale
(
false
);
m_plotOpts
.
SetScale
(
1
);
switch
(
m_plotOpts
.
GetScaleSelection
()
)
{
default
:
break
;
case
0
:
// Autoscale option
m_plotOpts
.
SetAutoScale
(
true
);
break
;
case
2
:
// 3:2 option
m_plotOpts
.
SetScale
(
1.5
);
break
;
case
3
:
// 2:1 option
m_plotOpts
.
SetScale
(
2
);
break
;
case
4
:
// 3:1 option
m_plotOpts
.
SetScale
(
3
);
break
;
}
/* If the scale factor edit controls are disabled or the scale value
* is 0, don't adjust the base scale factor. This fixes a bug when
* the default scale adjust is initialized to 0 and saved in program
* settings resulting in a divide by zero fault.
*/
if
(
m_fineAdjustXscaleOpt
->
IsEnabled
()
&&
m_XScaleAdjust
!=
0.0
)
m_plotOpts
.
SetFineScaleAdjustX
(
m_XScaleAdjust
);
if
(
m_fineAdjustYscaleOpt
->
IsEnabled
()
&&
m_YScaleAdjust
!=
0.0
)
m_plotOpts
.
SetFineScaleAdjustY
(
m_YScaleAdjust
);
if
(
m_PSFineAdjustWidthOpt
->
IsEnabled
()
)
m_plotOpts
.
SetWidthAdjust
(
m_PSWidthAdjust
);
wxString
file_ext
(
GetDefaultPlotExtension
(
m_plotOpts
.
GetFormat
()
)
);
// Test for a reasonable scale value
// XXX could this actually happen? isn't it constrained in the apply
// function?
if
(
m_plotOpts
.
GetScale
()
<
PLOT_MIN_SCALE
)
DisplayInfoMessage
(
this
,
_
(
"Warning: Scale option set to a very small value"
)
);
if
(
m_plotOpts
.
GetScale
()
>
PLOT_MAX_SCALE
)
DisplayInfoMessage
(
this
,
_
(
"Warning: Scale option set to a very large value"
)
);
// Save the current plot options in the board
m_parent
->
SetPlotSettings
(
m_plotOpts
);
for
(
LAYER_NUM
layer
=
FIRST_LAYER
;
layer
<
NB_PCB_LAYERS
;
++
layer
)
{
if
(
m_plotOpts
.
GetLayerSelection
()
&
GetLayerMask
(
layer
)
)
{
// Pick the basename from the board file
wxFileName
fn
(
boardFilename
);
// Use Gerber Extensions based on layer number
// (See http://en.wikipedia.org/wiki/Gerber_File)
if
(
(
m_plotOpts
.
GetFormat
()
==
PLOT_FORMAT_GERBER
)
&&
m_useGerberExtensions
->
GetValue
()
)
file_ext
=
GetGerberExtension
(
layer
);
// Create file name (from the English layer name for non copper layers).
BuildPlotFileName
(
&
fn
,
outputDir
.
GetPath
(),
m_board
->
GetStandardLayerName
(
layer
),
file_ext
);
LOCALE_IO
toggle
;
BOARD
*
board
=
m_parent
->
GetBoard
();
PLOTTER
*
plotter
=
StartPlotBoard
(
board
,
&
m_plotOpts
,
fn
.
GetFullPath
(),
wxEmptyString
);
// Print diags in messages box:
wxString
msg
;
if
(
plotter
)
{
{
PlotOneBoardLayer
(
board
,
plotter
,
layer
,
m_plotOpts
);
msg
.
Printf
(
_
(
"*** Error: cannot create output directory <%s>! ***
\n
"
),
plotter
->
EndPlot
();
GetChars
(
outputPath
)
);
delete
plotter
;
aReporter
->
Report
(
msg
);
msg
.
Printf
(
_
(
"Plot file <%s> created"
),
GetChars
(
fn
.
GetFullPath
()
)
);
}
}
else
msg
.
Printf
(
_
(
"Unable to create <%s>"
),
GetChars
(
fn
.
GetFullPath
()
)
);
msg
<<
wxT
(
"
\n
"
);
return
false
;
m_messagesBox
->
AppendText
(
msg
);
}
}
}
}
// If no layer selected, we have nothing plotted.
return
true
;
// Prompt user if it happens because he could think there is a bug in Pcbnew.
if
(
!
m_plotOpts
.
GetLayerSelection
()
)
DisplayError
(
this
,
_
(
"No layer selected"
)
);
}
}
void
PCB_EDIT_FRAME
::
ToPlotter
(
wxCommandEvent
&
event
)
{
DIALOG_PLOT
dlg
(
this
);
dlg
.
ShowModal
();
}
/** Batch plotter constructor, nothing interesting here */
PLOT_CONTROLLER
::
PLOT_CONTROLLER
(
BOARD
*
aBoard
)
PLOT_CONTROLLER
::
PLOT_CONTROLLER
(
BOARD
*
aBoard
)
:
m_plotter
(
NULL
),
m_board
(
aBoard
)
:
m_plotter
(
NULL
),
m_board
(
aBoard
)
{
{
}
}
/** Batch plotter destructor, ensures that the last plot is closed */
PLOT_CONTROLLER
::~
PLOT_CONTROLLER
()
PLOT_CONTROLLER
::~
PLOT_CONTROLLER
()
{
{
ClosePlot
();
ClosePlot
();
}
}
/* IMPORTANT THING TO KNOW: the locale during plots *MUST* be kept as
/* IMPORTANT THING TO KNOW: the locale during plots *MUST* be kept as
* C/POSIX using a LOCALE_IO object on the stack. This even when
* C/POSIX using a LOCALE_IO object on the stack. This even when
* opening/closing the plotfile, since some drivers do I/O even then */
* opening/closing the plotfile, since some drivers do I/O even then */
/** Close the current plot, nothing happens if it isn't open */
void
PLOT_CONTROLLER
::
ClosePlot
()
void
PLOT_CONTROLLER
::
ClosePlot
()
{
{
LOCALE_IO
toggle
;
LOCALE_IO
toggle
;
...
@@ -337,9 +215,8 @@ void PLOT_CONTROLLER::ClosePlot()
...
@@ -337,9 +215,8 @@ void PLOT_CONTROLLER::ClosePlot()
}
}
}
}
/** Open a new plotfile; works as a factory for plotter objects
*/
bool
PLOT_CONTROLLER
::
OpenPlotfile
(
const
wxString
&
aSuffix
,
bool
PLOT_CONTROLLER
::
OpenPlotfile
(
const
wxString
&
aSuffix
,
/*{{{*/
PlotFormat
aFormat
,
PlotFormat
aFormat
,
const
wxString
&
aSheetDesc
)
const
wxString
&
aSheetDesc
)
{
{
...
@@ -358,20 +235,20 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString &aSuffix, /*{{{*/
...
@@ -358,20 +235,20 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString &aSuffix, /*{{{*/
wxString
outputDirName
=
m_plotOpts
.
GetOutputDirectory
()
;
wxString
outputDirName
=
m_plotOpts
.
GetOutputDirectory
()
;
wxFileName
outputDir
=
wxFileName
::
DirName
(
outputDirName
);
wxFileName
outputDir
=
wxFileName
::
DirName
(
outputDirName
);
wxString
boardFilename
=
m_board
->
GetFileName
();
wxString
boardFilename
=
m_board
->
GetFileName
();
if
(
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
,
NULL
)
)
if
(
EnsureOutputDirectory
(
&
outputDir
,
boardFilename
)
)
{
{
wxFileName
fn
(
boardFilename
);
wxFileName
fn
(
boardFilename
);
BuildPlotFileName
(
&
fn
,
outputDirName
,
BuildPlotFileName
(
&
fn
,
outputDirName
,
aSuffix
,
GetDefaultPlotExtension
(
aFormat
)
);
aSuffix
,
GetDefaultPlotExtension
(
aFormat
)
);
m_plotter
=
StartPlotBoard
(
m_board
,
&
m_plotOpts
,
fn
.
GetFullPath
(),
m_plotter
=
StartPlotBoard
(
m_board
,
&
m_plotOpts
,
fn
.
GetFullPath
(),
aSheetDesc
);
aSheetDesc
);
}
}
return
(
m_plotter
!=
NULL
);
return
(
m_plotter
!=
NULL
);
}
/*}}}*/
}
/** Plot a single layer on the current plotfile */
bool
PLOT_CONTROLLER
::
PlotLayer
(
LAYER_NUM
aLayer
)
bool
PLOT_CONTROLLER
::
PlotLayer
(
LAYER_NUM
aLayer
)
/*{{{*/
{
{
LOCALE_IO
toggle
;
LOCALE_IO
toggle
;
...
@@ -383,7 +260,8 @@ bool PLOT_CONTROLLER::PlotLayer( LAYER_NUM aLayer )/*{{{*/
...
@@ -383,7 +260,8 @@ bool PLOT_CONTROLLER::PlotLayer( LAYER_NUM aLayer )/*{{{*/
PlotOneBoardLayer
(
m_board
,
m_plotter
,
aLayer
,
m_plotOpts
);
PlotOneBoardLayer
(
m_board
,
m_plotter
,
aLayer
,
m_plotOpts
);
return
true
;
return
true
;
}
/*}}}*/
}
void
PLOT_CONTROLLER
::
SetColorMode
(
bool
aColorMode
)
void
PLOT_CONTROLLER
::
SetColorMode
(
bool
aColorMode
)
{
{
...
@@ -393,6 +271,7 @@ void PLOT_CONTROLLER::SetColorMode( bool aColorMode )
...
@@ -393,6 +271,7 @@ void PLOT_CONTROLLER::SetColorMode( bool aColorMode )
m_plotter
->
SetColorMode
(
aColorMode
);
m_plotter
->
SetColorMode
(
aColorMode
);
}
}
bool
PLOT_CONTROLLER
::
GetColorMode
()
bool
PLOT_CONTROLLER
::
GetColorMode
()
{
{
if
(
!
m_plotter
)
if
(
!
m_plotter
)
...
@@ -400,4 +279,3 @@ bool PLOT_CONTROLLER::GetColorMode()
...
@@ -400,4 +279,3 @@ bool PLOT_CONTROLLER::GetColorMode()
return
m_plotter
->
GetColorMode
();
return
m_plotter
->
GetColorMode
();
}
}
pcbnew/pcbplot.h
View file @
f78497bf
...
@@ -44,6 +44,7 @@ class PCB_TARGET;
...
@@ -44,6 +44,7 @@ class PCB_TARGET;
class
TEXTE_MODULE
;
class
TEXTE_MODULE
;
class
ZONE_CONTAINER
;
class
ZONE_CONTAINER
;
class
BOARD
;
class
BOARD
;
class
REPORTER
;
// Shared Config keys for plot and print
// Shared Config keys for plot and print
#define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
#define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
...
@@ -218,16 +219,16 @@ void PlotSilkScreen( BOARD* aBoard, PLOTTER* aPlotter, LAYER_MSK aLayerMask,
...
@@ -218,16 +219,16 @@ void PlotSilkScreen( BOARD* aBoard, PLOTTER* aPlotter, LAYER_MSK aLayerMask,
/**
/**
* Function EnsureOutputDirectory (helper function)
* Function EnsureOutputDirectory (helper function)
*
Fix the output directory pathname to absolute and ensure it exists
*
make \a OutputDir absolute and creates the path if it doesn't exist.
*
(Creates it if not exists)
*
@param aOutputDir the wxFileName containing the full path and file name to modify. The path
*
@param aOutputDir = the wxFileName to modify
*
may be absolute or relative to \a aBoardFilename .
*
(contains the absolute or relative to the board path
*
@param aBoardFilename the board full path and filename.
* @param a
BoardFilename = the board full filename
* @param a
Reporter a point to a REPORTER object use to show messages (can be NULL)
* @
param aMessageBox = a wxMessageBox to show message (can be NULL)
* @
return true if \a aOutputDir already exists or was successfully created.
*/
*/
bool
EnsureOutputDirectory
(
wxFileName
*
aOutputDir
,
bool
EnsureOutputDirectory
(
wxFileName
*
aOutputDir
,
const
wxString
&
aBoardFilename
,
const
wxString
&
aBoardFilename
,
wxTextCtrl
*
aMessageBox
);
REPORTER
*
aReporter
=
NULL
);
/**
/**
* Function BuildPlotFileName (helper function)
* Function BuildPlotFileName (helper function)
...
@@ -236,7 +237,7 @@ bool EnsureOutputDirectory( wxFileName* aOutputDir,
...
@@ -236,7 +237,7 @@ bool EnsureOutputDirectory( wxFileName* aOutputDir,
* the suffix is usually the layer name
* the suffix is usually the layer name
* replaces not allowed chars in suffix by '_'
* replaces not allowed chars in suffix by '_'
* @param aFilename = the wxFileName to initialize
* @param aFilename = the wxFileName to initialize
* Cont
ia
ns the base filename
* Cont
ai
ns the base filename
* @param aOutputDir = the path
* @param aOutputDir = the path
* @param aSuffix = the suffix to add to the base filename
* @param aSuffix = the suffix to add to the base filename
* @param aExtension = the file extension
* @param aExtension = the file extension
...
@@ -246,6 +247,14 @@ void BuildPlotFileName( wxFileName* aFilename,
...
@@ -246,6 +247,14 @@ void BuildPlotFileName( wxFileName* aFilename,
const
wxString
&
aSuffix
,
const
wxString
&
aSuffix
,
const
wxString
&
aExtension
);
const
wxString
&
aExtension
);
/**
* Function GetGerberExtension
* @return the appropriate Gerber file extension for \a aLayer
*/
extern
wxString
GetGerberExtension
(
LAYER_NUM
aLayer
);
// PLOTGERB.CPP
// PLOTGERB.CPP
void
SelectD_CODE_For_LineDraw
(
PLOTTER
*
plotter
,
int
aSize
);
void
SelectD_CODE_For_LineDraw
(
PLOTTER
*
plotter
,
int
aSize
);
...
...
pcbnew/plotcontroller.h
View file @
f78497bf
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Lorenzo Marcantonio, <l.marcantonio@logossrl.com>
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
/**
* @file pcbnew/pcbplot.h
* @file pcbnew/pcbplot.h
*/
*/
...
@@ -10,6 +34,8 @@
...
@@ -10,6 +34,8 @@
class
PLOTTER
;
class
PLOTTER
;
class
BOARD
;
class
BOARD
;
class
REPORTER
;
/**
/**
* Batch plotter state object. Keeps the plot options and handles multiple
* Batch plotter state object. Keeps the plot options and handles multiple
...
@@ -18,14 +44,24 @@ class BOARD;
...
@@ -18,14 +44,24 @@ class BOARD;
class
PLOT_CONTROLLER
class
PLOT_CONTROLLER
{
{
public
:
public
:
/** Batch plotter constructor, nothing interesting here */
PLOT_CONTROLLER
(
BOARD
*
aBoard
);
PLOT_CONTROLLER
(
BOARD
*
aBoard
);
/** Batch plotter destructor, ensures that the last plot is closed */
~
PLOT_CONTROLLER
();
~
PLOT_CONTROLLER
();
PCB_PLOT_PARAMS
*
AccessPlotOpts
()
{
return
&
m_plotOpts
;
}
PCB_PLOT_PARAMS
*
AccessPlotOpts
()
{
return
&
m_plotOpts
;
}
bool
IsPlotOpen
()
const
{
return
m_plotter
!=
NULL
;
}
bool
IsPlotOpen
()
const
{
return
m_plotter
!=
NULL
;
}
/** Close the current plot, nothing happens if it isn't open */
void
ClosePlot
();
void
ClosePlot
();
/** Open a new plotfile; works as a factory for plotter objects
*/
bool
OpenPlotfile
(
const
wxString
&
aSuffix
,
PlotFormat
aFormat
,
bool
OpenPlotfile
(
const
wxString
&
aSuffix
,
PlotFormat
aFormat
,
const
wxString
&
aSheetDesc
);
const
wxString
&
aSheetDesc
);
/** Plot a single layer on the current plotfile */
bool
PlotLayer
(
LAYER_NUM
layer
);
bool
PlotLayer
(
LAYER_NUM
layer
);
void
SetColorMode
(
bool
aColorMode
);
void
SetColorMode
(
bool
aColorMode
);
...
@@ -36,8 +72,8 @@ private:
...
@@ -36,8 +72,8 @@ private:
PCB_PLOT_PARAMS
m_plotOpts
;
PCB_PLOT_PARAMS
m_plotOpts
;
/// This is the plotter object; it starts NULL and become instantiated
/// This is the plotter object; it starts NULL and become instantiated
// when a plotfile is requested
//
/
when a plotfile is requested
PLOTTER
*
m_plotter
;
PLOTTER
*
m_plotter
;
/// The board we're plotting
/// The board we're plotting
BOARD
*
m_board
;
BOARD
*
m_board
;
...
...
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