2009-01-11 19:12:18 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialog_svg_print.cpp
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Modified by:
|
|
|
|
// Licence: GPL
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <dcsvg.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
#include <class_pcb_screen.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <pcbplot.h>
|
|
|
|
#include <printout_controler.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_mire.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_zone.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
|
|
|
|
#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" )
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
// reasonnable values for default pen width (in 1/10000 inch)
|
|
|
|
#define WIDTH_MAX_VALUE 500
|
2009-01-11 19:12:18 +00:00
|
|
|
#define WIDTH_MIN_VALUE 1
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
// Local variables:
|
2010-02-22 19:56:32 +00:00
|
|
|
static PRINT_PARAMETERS s_Parameters;
|
2009-12-21 13:05:11 +00:00
|
|
|
static long s_SelectedLayers = LAYER_BACK | LAYER_FRONT |
|
2009-12-21 18:51:37 +00:00
|
|
|
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 )
|
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
m_Parent = (PCB_BASE_FRAME*) parent;
|
2011-12-16 20:12:49 +00:00
|
|
|
m_Config = wxGetApp().GetSettings();
|
|
|
|
initDialog();
|
2010-03-26 17:18:59 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
2011-03-14 15:17:18 +00:00
|
|
|
m_buttonBoard->SetDefault();
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
void DIALOG_SVG_PRINT::initDialog( )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
|
|
|
SetFocus(); // Make ESC key working
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_Parameters.m_Print_Black_and_White );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 15:33:03 +00:00
|
|
|
s_Parameters.m_PenDefaultSize = g_DrawDefaultLineThickness;
|
2010-07-12 14:07:09 +00:00
|
|
|
AddUnitSymbol( *m_TextPenWidth, g_UserUnit );
|
2009-01-11 19:12:18 +00:00
|
|
|
m_DialogPenWidth->SetValue(
|
2010-07-12 14:07:09 +00:00
|
|
|
ReturnStringFromValue( g_UserUnit, s_Parameters.m_PenDefaultSize,
|
2011-12-16 13:32:23 +00:00
|
|
|
m_Parent->GetInternalUnits() ) );
|
2009-01-13 19:18:54 +00:00
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
m_Print_Frame_Ref_Ctrl->SetValue( s_Parameters.m_Print_Sheet_Ref );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
// Create layers list
|
|
|
|
BOARD* board = m_Parent->GetBoard();
|
2010-03-26 17:18:59 +00:00
|
|
|
int layer;
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
// Add wxCheckBoxes in layers lists dialog
|
|
|
|
// List layers in same order than in setup layers dialog
|
|
|
|
// (Front or Top to Back or Bottom)
|
|
|
|
DECLARE_LAYERS_ORDER_LIST(layersOrder);
|
|
|
|
for( int layer_idx = 0; layer_idx < NB_LAYERS; ++layer_idx )
|
|
|
|
{
|
|
|
|
layer = layersOrder[layer_idx];
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
|
|
|
{
|
|
|
|
bool option;
|
2010-03-26 17:18:59 +00:00
|
|
|
if ( m_BoxSelectLayer[layer] == NULL )
|
|
|
|
continue;
|
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()
|
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_PenDefaultSize = ReturnValueFromTextCtrl( *m_DialogPenWidth,
|
2011-12-16 13:32:23 +00:00
|
|
|
m_Parent->GetInternalUnits() );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
if( s_Parameters.m_PenDefaultSize > WIDTH_MAX_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_PenDefaultSize = WIDTH_MAX_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
if( s_Parameters.m_PenDefaultSize < WIDTH_MIN_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_PenDefaultSize = WIDTH_MIN_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 15:33:03 +00:00
|
|
|
g_DrawDefaultLineThickness = s_Parameters.m_PenDefaultSize;
|
2009-01-11 19:12:18 +00:00
|
|
|
m_DialogPenWidth->SetValue(
|
2010-07-12 14:07:09 +00:00
|
|
|
ReturnStringFromValue( g_UserUnit, s_Parameters.m_PenDefaultSize,
|
2011-12-16 13:32:23 +00:00
|
|
|
m_Parent->GetInternalUnits() ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Frame_Ref )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-11-14 22:15:22 +00:00
|
|
|
wxString msg;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
SetPenWidth();
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
PCB_SCREEN* screen = m_Parent->GetScreen();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
if( aPrintAll )
|
|
|
|
m_PrintMaskLayer = 0xFFFFFFFF;
|
2010-03-26 17:18:59 +00:00
|
|
|
else
|
|
|
|
m_PrintMaskLayer = 0;
|
|
|
|
|
|
|
|
if( m_PrintBoardEdgesCtrl->IsChecked() )
|
|
|
|
m_PrintMaskLayer |= EDGE_LAYER;
|
|
|
|
else
|
|
|
|
m_PrintMaskLayer &= ~EDGE_LAYER;
|
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
|
|
|
{
|
2010-03-26 17:18:59 +00:00
|
|
|
if ( m_BoxSelectLayer[layer] == NULL )
|
|
|
|
continue;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( !aPrintAll && !m_BoxSelectLayer[layer]->GetValue() )
|
2009-01-11 19:12:18 +00:00
|
|
|
continue;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_FileNameCtrl->GetValue();
|
|
|
|
if( !fn.IsOk() )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = screen->GetFileName();
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
if( aPrintAll )
|
2009-11-14 22:15:22 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "-brd" ) );
|
2009-01-13 19:18:54 +00:00
|
|
|
else
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-09-24 16:36:20 +00:00
|
|
|
wxString extraname = m_BoxSelectLayer[layer]->GetLabel();
|
|
|
|
extraname.Trim(); // remove leading and trailing spaces if any
|
|
|
|
extraname.Trim(false);
|
|
|
|
fn.SetName( fn.GetName() + wxT( "-" ) + extraname );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
m_PrintMaskLayer = 1 << layer;
|
2009-11-14 22:15:22 +00:00
|
|
|
if( m_PrintBoardEdgesCtrl->IsChecked() )
|
2009-01-11 19:12:18 +00:00
|
|
|
m_PrintMaskLayer |= EDGE_LAYER;
|
|
|
|
}
|
|
|
|
|
2009-04-22 04:23:16 +00:00
|
|
|
fn.SetExt( wxT( "svg" ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
bool success = DrawPage( fn.GetFullPath(), screen, aPrint_Frame_Ref );
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Create file " ) + fn.GetFullPath();
|
2009-01-11 19:12:18 +00:00
|
|
|
if( !success )
|
|
|
|
msg += _( " error" );
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
m_MessagesBox->AppendText( msg );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( aPrintAll )
|
2009-01-11 19:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2010-04-20 11:23:59 +00:00
|
|
|
* Actual print function.
|
2009-01-11 19:12:18 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName,
|
|
|
|
BASE_SCREEN* screen,
|
2010-02-22 19:56:32 +00:00
|
|
|
bool aPrint_Frame_Ref )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
// const PAGE_INFO& pageInfo = m_Parent->GetPageSettings();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
int tmpzoom;
|
|
|
|
wxPoint tmp_startvisu;
|
|
|
|
wxPoint old_org;
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
// Change frames and local settings
|
2009-01-11 19:12:18 +00:00
|
|
|
tmp_startvisu = screen->m_StartVisu;
|
|
|
|
tmpzoom = screen->GetZoom();
|
|
|
|
old_org = screen->m_DrawOrg;
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
|
|
|
|
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
|
|
|
|
|
2009-01-31 10:05:16 +00:00
|
|
|
screen->SetScalingFactor( 1.0 );
|
2011-12-16 13:32:23 +00:00
|
|
|
float dpi = (float)m_Parent->GetInternalUnits();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
EDA_DRAW_PANEL* panel = m_Parent->GetCanvas();
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// paper pageSize is in internal units, either nanometers or deci-mils
|
|
|
|
wxSize pageSize = m_Parent->GetPageSizeIU();
|
|
|
|
|
2012-03-07 20:18:00 +00:00
|
|
|
KicadSVGFileDC dc( FullFileName, pageSize.x, pageSize.y, dpi );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
EDA_RECT tmp = *panel->GetClipBox();
|
2009-04-13 05:58:11 +00:00
|
|
|
GRResetPenAndBrush( &dc );
|
2010-03-26 17:18:59 +00:00
|
|
|
GRForceBlackPen( m_ModeColorOption->GetSelection() == 0 ? false : true );
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_DrillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE;
|
2009-04-13 05:58:11 +00:00
|
|
|
|
2011-01-17 18:37:58 +00:00
|
|
|
// Set clip box to the max size
|
|
|
|
#define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
|
|
|
|
// and that allows calculations without overflow
|
2011-12-29 20:11:42 +00:00
|
|
|
panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = true;
|
2010-04-20 11:23:59 +00:00
|
|
|
|
2010-04-20 15:56:47 +00:00
|
|
|
int bg_color = g_DrawBgColor;
|
2010-04-20 11:23:59 +00:00
|
|
|
g_DrawBgColor = WHITE;
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2011-01-17 18:37:58 +00:00
|
|
|
if( aPrint_Frame_Ref )
|
2011-01-30 22:22:38 +00:00
|
|
|
m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize );
|
2011-01-17 18:37:58 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters);
|
2010-04-20 15:56:47 +00:00
|
|
|
g_DrawBgColor = bg_color;
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = false;
|
2011-12-29 20:11:42 +00:00
|
|
|
panel->SetClipBox( tmp );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-03-26 17:18:59 +00:00
|
|
|
GRForceBlackPen( false );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
screen->m_StartVisu = tmp_startvisu;
|
|
|
|
screen->m_DrawOrg = old_org;
|
|
|
|
screen->SetZoom( tmpzoom );
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonPrintBoardClick( wxCommandEvent& event )
|
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_Print_Sheet_Ref = m_Print_Frame_Ref_Ctrl->IsChecked();
|
|
|
|
PrintSVGDoc( true, s_Parameters.m_Print_Sheet_Ref );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonPrintSelectedClick( wxCommandEvent& event )
|
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_Print_Sheet_Ref = m_Print_Frame_Ref_Ctrl->IsChecked();
|
|
|
|
PrintSVGDoc( false, s_Parameters.m_Print_Sheet_Ref );
|
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();
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
|
2009-01-11 19:12:18 +00:00
|
|
|
if( m_Config )
|
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
m_Config->Write( PLOTSVGMODECOLOR_KEY, s_Parameters.m_Print_Black_and_White );
|
2009-01-11 19:12:18 +00:00
|
|
|
wxString layerKey;
|
2010-03-26 17:18:59 +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;
|
2009-01-11 19:12:18 +00:00
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
m_Config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* called on radiobox color/black and white selection
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2010-02-22 19:56:32 +00:00
|
|
|
s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|