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-29 14:26:20 +00:00
|
|
|
#include "gr_basic.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 "program.h"
|
2009-01-13 19:18:54 +00:00
|
|
|
#include "general.h"
|
2010-03-28 14:46:49 +00:00
|
|
|
#include "libeditframe.h"
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
// Keys for configuration
|
|
|
|
#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" )
|
|
|
|
|
|
|
|
extern BASE_SCREEN* ActiveScreen;
|
|
|
|
#define WIDTH_MAX_VALUE 100
|
|
|
|
#define WIDTH_MIN_VALUE 1
|
|
|
|
|
|
|
|
// Variables locales
|
|
|
|
static bool s_Print_Frame_Ref = true;
|
|
|
|
static int s_PlotBlackAndWhite = 0;
|
|
|
|
|
|
|
|
class DIALOG_SVG_PRINT : public DIALOG_SVG_PRINT_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
WinEDA_DrawFrame * m_Parent;
|
|
|
|
wxConfig* m_Config;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_SVG_PRINT( WinEDA_DrawFrame* parent );
|
|
|
|
~DIALOG_SVG_PRINT( ) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnCloseWindow( wxCloseEvent& event );
|
|
|
|
void OnInitDialog( wxInitDialogEvent& event );
|
|
|
|
void OnButtonPlotCurrentClick( wxCommandEvent& event );
|
|
|
|
void OnButtonPlotAllClick( wxCommandEvent& event );
|
|
|
|
void OnButtonCancelClick( wxCommandEvent& event );
|
|
|
|
void OnSetColorModeSelected( wxCommandEvent& event );
|
|
|
|
void SetPenWidth();
|
|
|
|
void PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref );
|
2010-03-28 14:46:49 +00:00
|
|
|
public:
|
|
|
|
static bool DrawSVGPage( WinEDA_DrawFrame * frame,
|
|
|
|
const wxString& FullFileName, BASE_SCREEN* screen,
|
|
|
|
bool aPrintBlackAndWhite = false,
|
|
|
|
bool aPrint_Sheet_Ref = false);
|
2009-01-11 19:12:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Prepare the data structures of print management and display the dialog
|
|
|
|
* window for printing sheets.
|
2009-01-11 19:12:18 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_DrawFrame::SVG_Print( wxCommandEvent& event )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
|
|
|
DIALOG_SVG_PRINT frame( this );
|
|
|
|
|
|
|
|
frame.ShowModal();
|
|
|
|
}
|
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
/* Creates the SVG print file for the current edited component.
|
|
|
|
*/
|
|
|
|
void WinEDA_LibeditFrame::SVG_Print_Component( const wxString& FullFileName )
|
|
|
|
{
|
|
|
|
DIALOG_SVG_PRINT::DrawSVGPage( this, FullFileName, GetScreen() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* DIALOG_SVG_PRINT functions
|
|
|
|
*/
|
|
|
|
DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( WinEDA_DrawFrame* parent )
|
|
|
|
: DIALOG_SVG_PRINT_base( parent )
|
|
|
|
{
|
|
|
|
m_Parent = parent;
|
|
|
|
m_Config = wxGetApp().m_EDA_Config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnInitDialog( wxInitDialogEvent& event )
|
|
|
|
{
|
|
|
|
SetFocus(); // Make ESC key working
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_PlotBlackAndWhite );
|
|
|
|
}
|
|
|
|
|
2010-03-19 20:15:30 +00:00
|
|
|
m_ModeColorOption->SetSelection(s_PlotBlackAndWhite);
|
|
|
|
|
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, g_DrawDefaultLineThickness,
|
2009-12-02 21:44:03 +00:00
|
|
|
m_Parent->m_InternalUnits ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
m_Print_Sheet_Ref->SetValue( s_Print_Frame_Ref );
|
|
|
|
if (GetSizer())
|
|
|
|
{
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::SetPenWidth()
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
g_DrawDefaultLineThickness =
|
|
|
|
ReturnValueFromTextCtrl( *m_DialogPenWidth, m_Parent->m_InternalUnits );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-06-02 07:26:49 +00:00
|
|
|
if( g_DrawDefaultLineThickness > WIDTH_MAX_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-06-02 07:26:49 +00:00
|
|
|
g_DrawDefaultLineThickness = WIDTH_MAX_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 07:26:49 +00:00
|
|
|
if( g_DrawDefaultLineThickness < WIDTH_MIN_VALUE )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
2009-06-02 07:26:49 +00:00
|
|
|
g_DrawDefaultLineThickness = WIDTH_MIN_VALUE;
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_DialogPenWidth->SetValue(
|
2010-07-12 14:07:09 +00:00
|
|
|
ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness,
|
2009-12-02 21:44:03 +00:00
|
|
|
m_Parent->m_InternalUnits ) );
|
2009-01-11 19:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg;
|
|
|
|
wxFileName fn;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
SetPenWidth();
|
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
g_DrawDefaultLineThickness =
|
|
|
|
ReturnValueFromTextCtrl( *m_DialogPenWidth, m_Parent->m_InternalUnits );
|
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
BASE_SCREEN* screen = m_Parent->GetBaseScreen();
|
|
|
|
BASE_SCREEN* oldscreen = screen;
|
|
|
|
|
|
|
|
if( aPrintAll && m_Parent->m_Ident == SCHEMATIC_FRAME )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
WinEDA_SchematicFrame* schframe = (WinEDA_SchematicFrame*) m_Parent;
|
|
|
|
SCH_SHEET_PATH* sheetpath, *oldsheetpath = schframe->GetSheet();
|
|
|
|
SCH_SCREEN* schscreen = schframe->GetScreen();
|
2009-01-11 19:12:18 +00:00
|
|
|
oldscreen = schscreen;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList( NULL );
|
2009-01-11 19:12:18 +00:00
|
|
|
sheetpath = SheetList.GetFirst();
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH list;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
if( sheetpath == NULL )
|
|
|
|
break;
|
|
|
|
list.Clear();
|
|
|
|
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
|
|
|
|
{
|
|
|
|
schframe->m_CurrentSheet = &list;
|
|
|
|
schframe->m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
schframe->SetSheetNumberAndCount();
|
|
|
|
schscreen = schframe->m_CurrentSheet->LastScreen();
|
|
|
|
ActiveScreen = schscreen;
|
|
|
|
}
|
|
|
|
else // Should not happen
|
|
|
|
return;
|
|
|
|
sheetpath = SheetList.GetNext();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = schframe->GetUniqueFilenameForCurrentSheet( ) + wxT( ".svg" );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), schscreen,
|
|
|
|
m_ModeColorOption->GetSelection() == 0 ? false : true,
|
2009-04-05 20:49:15 +00:00
|
|
|
aPrint_Sheet_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 );
|
|
|
|
}
|
|
|
|
schframe->m_CurrentSheet = oldsheetpath;
|
|
|
|
schframe->m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
schframe->SetSheetNumberAndCount();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_FileNameCtrl->GetValue();
|
|
|
|
|
|
|
|
if( !fn.IsOk() )
|
|
|
|
fn = screen->m_FileName;
|
2009-08-29 10:20:48 +00:00
|
|
|
|
|
|
|
fn.SetExt( wxT( "svg" ) );
|
2010-03-28 14:46:49 +00:00
|
|
|
fn.MakeAbsolute( );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), screen,
|
|
|
|
m_ModeColorOption->GetSelection() == 0 ? false : true,
|
|
|
|
aPrint_Sheet_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" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
msg += wxT( "\n" );
|
|
|
|
m_MessagesBox->AppendText( msg );
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
ActiveScreen = oldscreen;
|
|
|
|
}
|
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
bool DIALOG_SVG_PRINT::DrawSVGPage( WinEDA_DrawFrame * frame,
|
|
|
|
const wxString& FullFileName,
|
2009-12-02 21:44:03 +00:00
|
|
|
BASE_SCREEN* screen,
|
2010-03-28 14:46:49 +00:00
|
|
|
bool aPrintBlackAndWhite,
|
2009-12-02 21:44:03 +00:00
|
|
|
bool aPrint_Sheet_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;
|
|
|
|
|
|
|
|
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;
|
2010-04-20 11:23:59 +00:00
|
|
|
SheetSize = screen->ReturnPageSize( ); // page size in 1/1000 inch, ie in internal units
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-01-31 10:05:16 +00:00
|
|
|
screen->SetScalingFactor( 1.0 );
|
2010-03-28 14:46:49 +00:00
|
|
|
WinEDA_DrawPanel* panel = frame->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)
|
|
|
|
|
|
|
|
float dpi = (float)frame->m_InternalUnits;
|
|
|
|
wxSVGFileDC dc( FullFileName, SheetSize.x, SheetSize.y, dpi );
|
2009-01-11 19:12:18 +00:00
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
EDA_Rect tmp = panel->m_ClipBox;
|
|
|
|
GRResetPenAndBrush( &dc );
|
2010-03-28 14:46:49 +00:00
|
|
|
GRForceBlackPen( aPrintBlackAndWhite );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
panel->m_ClipBox.SetX( -0x3FFFFF0 );
|
|
|
|
panel->m_ClipBox.SetY( -0x3FFFFF0 );
|
2009-12-02 21:44:03 +00:00
|
|
|
panel->m_ClipBox.SetWidth( 0x7FFFFF0 );
|
|
|
|
panel->m_ClipBox.SetHeight( 0x7FFFFF0 );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
|
|
|
screen->m_IsPrinting = true;
|
2010-03-28 14:46:49 +00:00
|
|
|
frame->PrintPage( &dc, aPrint_Sheet_Ref, 1, false );
|
2009-12-02 21:44:03 +00:00
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = false;
|
|
|
|
panel->m_ClipBox = tmp;
|
2009-01-11 19:12:18 +00:00
|
|
|
|
|
|
|
|
2010-03-28 14:46:49 +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::OnButtonPlotAllClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
PrintSVGDoc( true, m_Print_Sheet_Ref->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonPlotCurrentClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
PrintSVGDoc( false, m_Print_Sheet_Ref->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnButtonCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
Close( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event )
|
|
|
|
{
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
|
|
|
|
m_Config->Write( PLOTSVGMODECOLOR_KEY, s_PlotBlackAndWhite );
|
|
|
|
}
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-01-11 19:12:18 +00:00
|
|
|
/* called on radiobox color/black and white selection
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event )
|
2009-01-11 19:12:18 +00:00
|
|
|
{
|
|
|
|
s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
|
|
|
|
}
|