2009-01-11 19:12:18 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialog_svg_print.cpp
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Modified by:
|
|
|
|
// Licence: GPL
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-01-11 19:12:18 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
#include "dcsvg.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-01-13 19:18:54 +00:00
|
|
|
#include "pcbplot.h"
|
2010-02-22 19:56:32 +00:00
|
|
|
#include "printout_controler.h"
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-11-17 21:47:27 +00:00
|
|
|
#include "dialog_SVG_print.h"
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-02-24 15:33:03 +00:00
|
|
|
extern int g_DrawDefaultLineThickness;
|
|
|
|
|
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;
|
2009-01-11 19:12:18 +00:00
|
|
|
m_Config = wxGetApp().m_EDA_Config;
|
2010-03-26 17:18:59 +00:00
|
|
|
initDialog( );
|
|
|
|
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,
|
2009-11-14 22:15:22 +00:00
|
|
|
m_Parent->m_InternalUnits ) );
|
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,
|
2009-11-14 22:15:22 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
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,
|
2009-11-14 22:15:22 +00:00
|
|
|
m_Parent->m_InternalUnits ) );
|
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
|
|
|
{
|
|
|
|
int tmpzoom;
|
|
|
|
wxPoint tmp_startvisu;
|
|
|
|
wxSize SheetSize; // Sheet size in internal units
|
|
|
|
wxPoint old_org;
|
|
|
|
bool success = true;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* 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;
|
|
|
|
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
|
|
|
|
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
|
|
|
|
SheetSize = screen->m_CurrentSheetDesc->m_Size; // size in 1/1000 inch
|
|
|
|
SheetSize.x *= m_Parent->m_InternalUnits / 1000;
|
|
|
|
SheetSize.y *= m_Parent->m_InternalUnits / 1000; // size in pixels
|
|
|
|
|
2009-01-31 10:05:16 +00:00
|
|
|
screen->SetScalingFactor( 1.0 );
|
2010-04-20 11:23:59 +00:00
|
|
|
float dpi = (float)m_Parent->m_InternalUnits;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_PANEL* panel = m_Parent->DrawPanel;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-04-20 11:23:59 +00:00
|
|
|
SetLocaleTo_C_standard(); // Switch the locale to standard C (needed
|
|
|
|
// to print floating point numbers like 1.3)
|
2009-01-11 19:12:18 +00:00
|
|
|
wxSVGFileDC dc( FullFileName, SheetSize.x, SheetSize.y, dpi );
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT tmp = panel->m_ClipBox;
|
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
|
|
|
|
|
|
|
|
2010-04-20 15:56:47 +00:00
|
|
|
panel->m_ClipBox.SetX( 0 );
|
|
|
|
panel->m_ClipBox.SetY( 0 );
|
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
|
|
|
|
panel->m_ClipBox.SetWidth( MAX_VALUE );
|
|
|
|
panel->m_ClipBox.SetHeight( 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
|
|
|
|
|
|
|
m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters);
|
2010-04-20 15:56:47 +00:00
|
|
|
g_DrawBgColor = bg_color;
|
2011-01-17 18:37:58 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = false;
|
2009-11-14 22:15:22 +00:00
|
|
|
panel->m_ClipBox = 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
|
|
|
}
|