2012-08-31 07:43:37 +00:00
|
|
|
/**
|
2012-09-12 17:28:55 +00:00
|
|
|
* @file pcbnew/dialogs/dialog_SVG_print.cpp
|
2012-08-31 07:43:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <dcsvg.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
#include <class_pcb_screen.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2012-09-20 18:58:41 +00:00
|
|
|
#include <convert_from_iu.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <pcbplot.h>
|
|
|
|
#include <printout_controler.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <dialog_SVG_print.h>
|
2010-11-17 21:47:27 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
// Keys for configuration
|
2012-09-20 18:58:41 +00:00
|
|
|
#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" )
|
|
|
|
#define PLOTSVGPAGESIZEOPT_KEY wxT( "PlotSVGPageOpt" )
|
|
|
|
#define PLOTSVGPLOT_BRD_EDGE_KEY wxT( "PlotSVGBrdEdge" )
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-08-31 07:43:37 +00:00
|
|
|
// reasonnable values for default pen width
|
2012-09-20 18:58:41 +00:00
|
|
|
#define WIDTH_MAX_VALUE (2 * IU_PER_MM)
|
|
|
|
#define WIDTH_MIN_VALUE (0.05 * IU_PER_MM)
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
// Local variables:
|
2012-08-31 07:43:37 +00:00
|
|
|
static long s_SelectedLayers = LAYER_BACK | LAYER_FRONT |
|
|
|
|
SILKSCREEN_LAYER_FRONT | SILKSCREEN_LAYER_BACK;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* DIALOG_SVG_PRINT functions
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( EDA_DRAW_FRAME* parent ) :
|
2009-01-11 19:12:18 +00:00
|
|
|
DIALOG_SVG_PRINT_base( parent )
|
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
m_Parent = (PCB_BASE_FRAME*) parent;
|
|
|
|
m_Config = wxGetApp().GetSettings();
|
2011-12-16 20:12:49 +00:00
|
|
|
initDialog();
|
2010-03-26 17:18:59 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
2012-09-20 18:58:41 +00:00
|
|
|
bool DIALOG_SVG_PRINT::m_printMirror = false;
|
|
|
|
bool DIALOG_SVG_PRINT::m_oneFileOnly = false;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
void DIALOG_SVG_PRINT::initDialog()
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
|
|
|
if( m_Config )
|
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
m_Config->Read( PLOTSVGMODECOLOR_KEY, &m_printBW, false );
|
2012-08-31 07:43:37 +00:00
|
|
|
long ltmp;
|
|
|
|
m_Config->Read( PLOTSVGPAGESIZEOPT_KEY, <mp, 0 );
|
|
|
|
m_rbSvgPageSizeOpt->SetSelection( ltmp );
|
|
|
|
m_Config->Read( PLOTSVGPLOT_BRD_EDGE_KEY, <mp, 1 );
|
2012-09-20 18:58:41 +00:00
|
|
|
m_PrintBoardEdgesCtrl->SetValue( ltmp );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( m_printBW )
|
2012-08-31 07:43:37 +00:00
|
|
|
m_ModeColorOption->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_ModeColorOption->SetSelection( 0 );
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
m_printMirrorOpt->SetValue( m_printMirror );
|
|
|
|
m_rbFileOpt->SetSelection( m_oneFileOnly ? 1 : 0 );
|
|
|
|
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
AddUnitSymbol( *m_TextPenWidth, g_UserUnit );
|
2012-08-31 07:43:37 +00:00
|
|
|
m_DialogDefaultPenSize->SetValue(
|
2012-09-20 18:58:41 +00:00
|
|
|
ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) );
|
2009-01-13 19:18:54 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
// Create layers list
|
2012-09-20 18:58:41 +00:00
|
|
|
BOARD* board = m_Parent->GetBoard();
|
|
|
|
int layer;
|
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
for( layer = 0; layer < NB_LAYERS; ++layer )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-03-26 17:18:59 +00:00
|
|
|
if( !board->IsLayerEnabled( layer ) )
|
|
|
|
m_BoxSelectLayer[layer] = NULL;
|
|
|
|
else
|
|
|
|
m_BoxSelectLayer[layer] =
|
|
|
|
new wxCheckBox( this, -1, board->GetLayerName( layer ) );
|
|
|
|
}
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
// Add wxCheckBoxes in layers lists dialog
|
2012-09-20 18:58:41 +00:00
|
|
|
// List layers in same order than in setup layers dialog
|
2010-03-26 17:18:59 +00:00
|
|
|
// (Front or Top to Back or Bottom)
|
2012-09-20 18:58:41 +00:00
|
|
|
DECLARE_LAYERS_ORDER_LIST( layersOrder );
|
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
for( int layer_idx = 0; layer_idx < NB_LAYERS; ++layer_idx )
|
|
|
|
{
|
|
|
|
layer = layersOrder[layer_idx];
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
wxASSERT( layer < NB_LAYERS );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
if( m_BoxSelectLayer[layer] == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
long mask = 1 << layer;
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
if( mask & s_SelectedLayers )
|
|
|
|
m_BoxSelectLayer[layer]->SetValue( true );
|
|
|
|
|
|
|
|
if( layer < 16 )
|
2009-11-14 22:15:22 +00:00
|
|
|
m_CopperLayersBoxSizer->Add( m_BoxSelectLayer[layer],
|
|
|
|
0,
|
|
|
|
wxGROW | wxALL,
|
|
|
|
1 );
|
2009-01-11 19:12:18 +00:00
|
|
|
else
|
2009-11-14 22:15:22 +00:00
|
|
|
m_TechnicalBoxSizer->Add( m_BoxSelectLayer[layer],
|
|
|
|
0,
|
|
|
|
wxGROW | wxALL,
|
|
|
|
1 );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
wxString layerKey;
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
|
|
|
bool option;
|
2012-09-20 18:58:41 +00:00
|
|
|
|
|
|
|
if( m_BoxSelectLayer[layer] == NULL )
|
2010-03-26 17:18:59 +00:00
|
|
|
continue;
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
|
|
|
|
if( m_Config->Read( layerKey, &option ) )
|
|
|
|
m_BoxSelectLayer[layer]->SetValue( option );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::SetPenWidth()
|
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
int pensize = ReturnValueFromTextCtrl( *m_DialogDefaultPenSize );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( pensize > WIDTH_MAX_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
pensize = WIDTH_MAX_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( pensize < WIDTH_MIN_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
pensize = WIDTH_MIN_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
g_DrawDefaultLineThickness = pensize;
|
|
|
|
m_DialogDefaultPenSize->SetValue( ReturnStringFromValue( g_UserUnit, pensize ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxString msg;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
m_printMirror = m_printMirrorOpt->GetValue();
|
|
|
|
m_printBW = m_ModeColorOption->GetSelection();
|
2009-01-11 19:12:18 +00:00
|
|
|
SetPenWidth();
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
// Build layers mask
|
|
|
|
int printMaskLayer = 0;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
for( int layer = 0; layer<NB_LAYERS; layer++ )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
if( m_BoxSelectLayer[layer] && m_BoxSelectLayer[layer]->GetValue() )
|
|
|
|
printMaskLayer |= 1 << layer;
|
|
|
|
}
|
2010-03-26 17:18:59 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
for( int layer = 0; layer<NB_LAYERS; layer++ )
|
|
|
|
{
|
|
|
|
int currlayer_mask = 1 << layer;
|
|
|
|
if( (printMaskLayer & currlayer_mask ) == 0 )
|
2009-01-11 19:12:18 +00:00
|
|
|
continue;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_FileNameCtrl->GetValue();
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !fn.IsOk() )
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = m_Parent->GetBoard()->GetFileName();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( aOnlyOneFile )
|
|
|
|
{
|
|
|
|
m_PrintMaskLayer = printMaskLayer;
|
2009-11-14 22:15:22 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-brd" ) );
|
2012-09-20 18:58:41 +00:00
|
|
|
}
|
2009-01-13 19:18:54 +00:00
|
|
|
else
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
m_PrintMaskLayer = currlayer_mask;
|
|
|
|
wxString suffix = m_Parent->GetBoard()->GetLayerName( layer, false );
|
|
|
|
suffix.Trim(); // remove leading and trailing spaces if any
|
|
|
|
suffix.Trim( false );
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + suffix );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 04:23:16 +00:00
|
|
|
fn.SetExt( wxT( "svg" ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( m_PrintBoardEdgesCtrl->IsChecked() )
|
|
|
|
m_PrintMaskLayer |= EDGE_LAYER;
|
|
|
|
|
|
|
|
if( CreateSVGFile( fn.GetFullPath() ) )
|
|
|
|
msg.Printf( _( "Plot: %s OK\n" ), GetChars( fn.GetFullPath() ) );
|
|
|
|
else // Error
|
|
|
|
msg.Printf( _( "** Unable to create %s **\n" ), GetChars( fn.GetFullPath() ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
m_MessagesBox->AppendText( msg );
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( aOnlyOneFile )
|
2009-01-11 19:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
// Actual SVG file export function.
|
2012-09-20 18:58:41 +00:00
|
|
|
bool DIALOG_SVG_PRINT::CreateSVGFile( const wxString& aFullFileName )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
BOARD* brd = m_Parent->GetBoard();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
PCB_PLOT_PARAMS m_plotOpts;
|
2012-04-16 23:31:29 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
m_plotOpts.SetPlotFrameRef( PrintPageRef() );
|
2012-09-24 06:39:59 +00:00
|
|
|
// Adding drill marks
|
2012-09-20 18:58:41 +00:00
|
|
|
m_plotOpts.SetDrillMarksType( PCB_PLOT_PARAMS::FULL_DRILL_SHAPE );
|
2012-09-24 06:39:59 +00:00
|
|
|
|
|
|
|
m_plotOpts.SetSkipPlotNPTH_Pads( false );
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
m_plotOpts.SetMirror( m_printMirror );
|
|
|
|
m_plotOpts.SetFormat( PLOT_FORMAT_SVG );
|
2012-09-22 11:19:37 +00:00
|
|
|
EDA_COLOR_T color = UNSPECIFIED_COLOR; // Used layer color to plot ref and value
|
2012-09-20 18:58:41 +00:00
|
|
|
m_plotOpts.SetReferenceColor( color );
|
|
|
|
m_plotOpts.SetValueColor( color );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
PAGE_INFO pageInfo = brd->GetPageSettings();
|
|
|
|
wxPoint axisorigin = brd->GetOriginAxisPosition();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-08-31 07:43:37 +00:00
|
|
|
if( PageIsBoardBoundarySize() )
|
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
EDA_RECT bbox = brd->ComputeBoundingBox();
|
|
|
|
PAGE_INFO currpageInfo = brd->GetPageSettings();
|
|
|
|
currpageInfo.SetWidthMils( bbox.GetWidth() / IU_PER_MILS );
|
|
|
|
currpageInfo.SetHeightMils( bbox.GetHeight() / IU_PER_MILS );
|
|
|
|
brd->SetPageSettings( currpageInfo );
|
|
|
|
m_plotOpts.SetUseAuxOrigin( true );
|
|
|
|
wxPoint origin = bbox.GetOrigin();
|
|
|
|
brd->SetOriginAxisPosition( origin );
|
2012-08-31 07:43:37 +00:00
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( brd,
|
|
|
|
&m_plotOpts, aFullFileName,
|
|
|
|
wxEmptyString );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( plotter )
|
|
|
|
{
|
|
|
|
plotter->SetColorMode( m_ModeColorOption->GetSelection() == 0 );
|
2012-09-24 06:39:59 +00:00
|
|
|
PlotStandardLayer( brd, plotter, m_PrintMaskLayer, m_plotOpts );
|
2012-09-20 18:58:41 +00:00
|
|
|
}
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
plotter->EndPlot();
|
|
|
|
delete plotter;
|
|
|
|
brd->SetOriginAxisPosition( axisorigin );
|
|
|
|
brd->SetPageSettings( pageInfo );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
return true;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
void DIALOG_SVG_PRINT::OnButtonPlot( wxCommandEvent& event )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
m_oneFileOnly = m_rbFileOpt->GetSelection() == 1;
|
|
|
|
ExportSVGFile( m_oneFileOnly );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event )
|
|
|
|
{
|
2009-01-17 17:32:20 +00:00
|
|
|
SetPenWidth();
|
2012-09-20 18:58:41 +00:00
|
|
|
m_printBW = m_ModeColorOption->GetSelection();
|
|
|
|
m_oneFileOnly = m_rbFileOpt->GetSelection() == 1;
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
if( m_Config )
|
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
m_Config->Write( PLOTSVGMODECOLOR_KEY, m_printBW );
|
2012-08-31 07:43:37 +00:00
|
|
|
m_Config->Write( PLOTSVGPAGESIZEOPT_KEY, m_rbSvgPageSizeOpt->GetSelection() );
|
|
|
|
m_Config->Write( PLOTSVGPLOT_BRD_EDGE_KEY, m_PrintBoardEdgesCtrl->GetValue() );
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
wxString layerKey;
|
2012-09-20 18:58:41 +00:00
|
|
|
|
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-03-26 17:18:59 +00:00
|
|
|
if( m_BoxSelectLayer[layer] == NULL )
|
|
|
|
continue;
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
m_Config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 18:58:41 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
EndModal( 0 );
|
|
|
|
}
|