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 "dialog_SVG_print_base.h"
|
|
|
|
|
|
|
|
#include "dcsvg.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-01-13 19:18:54 +00:00
|
|
|
#include "pcbplot.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
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
// Local variables:
|
|
|
|
static int s_PrintPenMinWidth = 1;
|
2009-01-11 19:12:18 +00:00
|
|
|
static bool s_Print_Frame_Ref = true;
|
|
|
|
static int s_PlotBlackAndWhite = 0;
|
|
|
|
static long s_SelectedLayers = CUIVRE_LAYER | CMP_LAYER |
|
|
|
|
SILKSCREEN_LAYER_CMP | SILKSCREEN_LAYER_CU;
|
|
|
|
|
|
|
|
class DIALOG_SVG_PRINT : public DIALOG_SVG_PRINT_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
WinEDA_BasePcbFrame* m_Parent;
|
|
|
|
int m_ImageXSize_mm;
|
|
|
|
wxConfig* m_Config;
|
|
|
|
long m_PrintMaskLayer;
|
|
|
|
wxCheckBox* m_BoxSelectLayer[32];
|
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_SVG_PRINT( WinEDA_DrawFrame* parent );
|
|
|
|
~DIALOG_SVG_PRINT() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnCloseWindow( wxCloseEvent& event );
|
|
|
|
void OnInitDialog( wxInitDialogEvent& event );
|
|
|
|
void OnButtonPrintSelectedClick( wxCommandEvent& event );
|
|
|
|
void OnButtonPrintBoardClick( wxCommandEvent& event );
|
|
|
|
void OnButtonCancelClick( wxCommandEvent& event );
|
|
|
|
void OnSetColorModeSelected( wxCommandEvent& event );
|
|
|
|
void SetPenWidth();
|
2009-01-13 19:18:54 +00:00
|
|
|
void PrintSVGDoc( bool aPrintAll, bool aPrint_Framet_Ref );
|
|
|
|
bool DrawPage( const wxString& FullFileName, BASE_SCREEN* screen, bool aPrint_Framet_Ref );
|
2009-01-11 19:12:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************/
|
|
|
|
void WinEDA_DrawFrame::SVG_Print( wxCommandEvent& event )
|
|
|
|
/*******************************************************/
|
|
|
|
|
|
|
|
/* Prepare les structures de donnees de gestion de l'impression
|
|
|
|
* et affiche la fenetre de dialogue de gestion de l'impression des feuilles
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
DIALOG_SVG_PRINT frame( this );
|
|
|
|
|
|
|
|
frame.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* DIALOG_SVG_PRINT functions
|
|
|
|
*/
|
|
|
|
DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( WinEDA_DrawFrame* parent ) :
|
|
|
|
DIALOG_SVG_PRINT_base( parent )
|
|
|
|
{
|
|
|
|
m_Parent = (WinEDA_BasePcbFrame*) parent;
|
|
|
|
m_Config = wxGetApp().m_EDA_Config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
void DIALOG_SVG_PRINT::OnInitDialog( wxInitDialogEvent& event )
|
|
|
|
/*************************************************************/
|
|
|
|
{
|
|
|
|
SetFocus(); // Make ESC key working
|
|
|
|
|
|
|
|
m_ImageXSize_mm = 270;
|
|
|
|
if( m_Config )
|
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
m_Config->Read( OPTKEY_PLOT_LINEWIDTH_VALUE, &s_PrintPenMinWidth );
|
2009-01-11 19:12:18 +00:00
|
|
|
m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_PlotBlackAndWhite );
|
|
|
|
}
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_TextPenWidth, g_UnitMetric );
|
|
|
|
m_DialogPenWidth->SetValue(
|
2009-01-13 19:18:54 +00:00
|
|
|
ReturnStringFromValue( g_UnitMetric, s_PrintPenMinWidth, m_Parent->m_InternalUnits ) );
|
|
|
|
|
|
|
|
m_Print_Frame_Ref_Ctrl->SetValue( s_Print_Frame_Ref );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
// Create layers list
|
|
|
|
BOARD* board = m_Parent->GetBoard();
|
|
|
|
int mask = 1;
|
|
|
|
for( int layer = 0; layer<NB_LAYERS; layer++, mask <<= 1 )
|
|
|
|
{
|
|
|
|
m_BoxSelectLayer[layer] = new wxCheckBox( this, -1, board->GetLayerName( layer ) );
|
|
|
|
|
|
|
|
if( mask & s_SelectedLayers )
|
|
|
|
m_BoxSelectLayer[layer]->SetValue( true );
|
|
|
|
|
|
|
|
if( layer < 16 )
|
|
|
|
m_CopperLayersBoxSizer->Add( m_BoxSelectLayer[layer], 0, wxGROW | wxALL, 1 );
|
|
|
|
else
|
|
|
|
m_TechnicalBoxSizer->Add( m_BoxSelectLayer[layer], 0, wxGROW | wxALL, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
wxString layerKey;
|
|
|
|
|
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
|
|
|
{
|
|
|
|
bool option;
|
|
|
|
|
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
|
|
|
|
if( m_Config->Read( layerKey, &option ) )
|
|
|
|
m_BoxSelectLayer[layer]->SetValue( option );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetSizer() )
|
|
|
|
{
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
/***********************************/
|
2009-01-11 19:12:18 +00:00
|
|
|
void DIALOG_SVG_PRINT::SetPenWidth()
|
2009-01-13 19:18:54 +00:00
|
|
|
/***********************************/
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
s_PrintPenMinWidth = ReturnValueFromTextCtrl( *m_DialogPenWidth, m_Parent->m_InternalUnits );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
if( s_PrintPenMinWidth > WIDTH_MAX_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
s_PrintPenMinWidth = WIDTH_MAX_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
if( s_PrintPenMinWidth < WIDTH_MIN_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
s_PrintPenMinWidth = WIDTH_MIN_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_DialogPenWidth->SetValue(
|
2009-01-13 19:18:54 +00:00
|
|
|
ReturnStringFromValue( g_UnitMetric, s_PrintPenMinWidth, m_Parent->m_InternalUnits ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2009-01-13 19:18:54 +00:00
|
|
|
void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Framet_Ref )
|
2009-01-11 19:12:18 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-01-11 19:12:18 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
SetPenWidth();
|
|
|
|
|
|
|
|
BASE_SCREEN* screen = m_Parent->GetBaseScreen();
|
|
|
|
|
|
|
|
if( aPrintAll )
|
|
|
|
m_PrintMaskLayer = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
for ( int layer = 0; layer<NB_LAYERS; layer++ )
|
|
|
|
{
|
|
|
|
if ( ! aPrintAll && ! m_BoxSelectLayer[layer]->GetValue( ) )
|
|
|
|
continue;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_FileNameCtrl->GetValue();
|
|
|
|
if( !fn.IsOk() )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = screen->m_FileName;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
if( aPrintAll )
|
2009-04-05 20:49:15 +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
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT("-") +
|
|
|
|
m_BoxSelectLayer[layer]->GetLabel( ) );
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
m_PrintMaskLayer = 1 << layer;
|
|
|
|
if ( m_PrintBoardEdgesCtrl->IsChecked() )
|
|
|
|
m_PrintMaskLayer |= EDGE_LAYER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-22 04:23:16 +00:00
|
|
|
fn.SetExt( wxT( "svg" ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
bool success = DrawPage( fn.GetFullPath(), screen, aPrint_Framet_Ref );
|
|
|
|
msg = _( "Create file " ) + fn.GetFullPath();
|
2009-01-11 19:12:18 +00:00
|
|
|
if( !success )
|
|
|
|
msg += _( " error" );
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
m_MessagesBox->AppendText( msg );
|
|
|
|
|
|
|
|
if ( aPrintAll )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-13 19:18:54 +00:00
|
|
|
/**********************************************************************************/
|
2009-01-11 19:12:18 +00:00
|
|
|
bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, BASE_SCREEN* screen,
|
2009-01-13 19:18:54 +00:00
|
|
|
bool aPrint_Framet_Ref )
|
|
|
|
/***********************************************************************************/
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine effective d'impression
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int tmpzoom;
|
|
|
|
wxPoint tmp_startvisu;
|
|
|
|
wxSize SheetSize; // Sheet size in internal units
|
|
|
|
wxPoint old_org;
|
|
|
|
float dpi;
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
/* modification des cadrages et reglages locaux */
|
|
|
|
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 );
|
2009-01-11 19:12:18 +00:00
|
|
|
dpi = (float) SheetSize.x * 25.4 / m_ImageXSize_mm;
|
|
|
|
|
|
|
|
WinEDA_DrawPanel* panel = m_Parent->DrawPanel;
|
|
|
|
|
|
|
|
wxSVGFileDC dc( FullFileName, SheetSize.x, SheetSize.y, dpi );
|
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
EDA_Rect tmp = panel->m_ClipBox;
|
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
s_PrintPenMinWidth = ReturnValueFromTextCtrl( *m_DialogPenWidth, m_Parent->m_InternalUnits );
|
|
|
|
SetPenMinWidth( s_PrintPenMinWidth );
|
|
|
|
GRForceBlackPen( m_ModeColorOption->GetSelection() == 0 ? FALSE : true );
|
|
|
|
|
|
|
|
|
|
|
|
panel->m_ClipBox.SetX( 0 ); panel->m_ClipBox.SetY( 0 );
|
|
|
|
panel->m_ClipBox.SetWidth( 0x7FFFFF0 ); panel->m_ClipBox.SetHeight( 0x7FFFFF0 );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = true;
|
|
|
|
SetLocaleTo_C_standard(); // Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
|
|
|
panel->PrintPage( &dc, aPrint_Framet_Ref, m_PrintMaskLayer, false );
|
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
|
|
|
screen->m_IsPrinting = false;
|
|
|
|
panel->m_ClipBox = tmp;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
GRForceBlackPen( FALSE );
|
|
|
|
SetPenMinWidth( 1 );
|
|
|
|
|
|
|
|
screen->m_StartVisu = tmp_startvisu;
|
|
|
|
screen->m_DrawOrg = old_org;
|
|
|
|
screen->SetZoom( tmpzoom );
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonPrintBoardClick( wxCommandEvent& event )
|
|
|
|
/********************************************************************/
|
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
s_Print_Frame_Ref = m_Print_Frame_Ref_Ctrl->IsChecked( );
|
|
|
|
PrintSVGDoc( true, s_Print_Frame_Ref );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonPrintSelectedClick( wxCommandEvent& event )
|
|
|
|
/********************************************************************/
|
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
s_Print_Frame_Ref = m_Print_Frame_Ref_Ctrl->IsChecked( );
|
|
|
|
PrintSVGDoc( false, s_Print_Frame_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();
|
|
|
|
s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
|
2009-01-11 19:12:18 +00:00
|
|
|
if( m_Config )
|
|
|
|
{
|
2009-01-13 19:18:54 +00:00
|
|
|
m_Config->Write( OPTKEY_PLOT_LINEWIDTH_VALUE, s_PrintPenMinWidth );
|
2009-01-11 19:12:18 +00:00
|
|
|
m_Config->Write( PLOTSVGMODECOLOR_KEY, s_PlotBlackAndWhite );
|
|
|
|
wxString layerKey;
|
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
|
|
|
{
|
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
m_Config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event )
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
/* called on radiobox color/black and white selection
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
|
|
|
|
}
|