eeschema: plot functions: code cleaning.

SVG plotter: fix issues in draw arc and draw rectangle.
This commit is contained in:
jean-pierre charras 2012-09-18 16:50:30 +02:00
parent c3ecce2ec6
commit 5179ed926b
8 changed files with 261 additions and 259 deletions

View File

@ -71,7 +71,7 @@
*
* <polygon points="0,0 50,0 25,50" style="stroke:#660000; fill:#cc3333;"/>
*
* The <path> element is used to draw advanced shapes combined from lines and archs,
* The <path> element is used to draw advanced shapes combined from lines and arcs,
* with or without fill.
* It is probably the most advanced and versatile SVG shape of them all.
* It is probably also the hardest element to master.
@ -81,6 +81,14 @@
* M110,110
* L100,0"
* style="stroke:#660000; fill:none;"/>
*
* Draw an elliptic arc: it is one of basic path command:
* <path d="M(startx,starty) A(radiusx,radiusy)
* rotation-axe-x
* flag_arc_large,flag_sweep endx,endy">
* flag_arc_large: 0 = small arc > 180 deg, 1 = large arc > 180 deg
* flag_sweep : 0 = CCW, 1 = CW
* The center of ellipse is automatically calculated.
*/
#include <fctsys.h>
#include <trigo.h>
@ -152,7 +160,7 @@ void SVG_PLOTTER::setSVGPlotStyle()
break;
case FILLED_WITH_BG_BODYCOLOR:
fputs( "fill-opacity:0.3;\n", outputFile );
fputs( "fill-opacity:0.6;\n", outputFile );
break;
}
@ -246,17 +254,18 @@ void SVG_PLOTTER::SetDash( bool dashed )
void SVG_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
{
DPOINT p1_dev = userToDeviceCoordinates( p1 );
DPOINT p2_dev = userToDeviceCoordinates( p2 );
EDA_RECT rect( p1, wxSize( p2.x -p1.x, p2.y -p1.y ) );
rect.Normalize();
DPOINT pos_dev = userToDeviceCoordinates( rect.GetOrigin() );
DPOINT size_dev = userToDeviceSize( rect.GetSize() );
setFillMode( fill );
SetCurrentLineWidth( width );
fprintf( outputFile,
"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%d\" />\n",
(int) p1_dev.x, (int) p1_dev.y, // origin
(int) (p2_dev.x - p1_dev.x), (int) (p2_dev.y - p1_dev.y), // size
0 // radius of rounded corners
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n",
pos_dev.x, pos_dev.y, size_dev.x, size_dev.y,
0.0 // radius of rounded corners
);
}
@ -299,18 +308,21 @@ void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad
DPOINT centre_dev = userToDeviceCoordinates( centre );
double radius_dev = userToDeviceSize( radius );
if( plotMirror )
if( !plotMirror )
{
int tmp = StAngle;
StAngle = -EndAngle;
EndAngle = -tmp;
}
DPOINT start = centre_dev;
start.x += radius_dev;
DPOINT end = start;
DPOINT start;
start.x = radius_dev;
RotatePoint( &start.x, &start.y, StAngle );
DPOINT end;
end.x = radius_dev;
RotatePoint( &end.x, &end.y, EndAngle );
start += centre_dev;
end += centre_dev;
double theta1 = StAngle * M_PI / 1800.0;
@ -336,13 +348,11 @@ void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad
// params are start point, radius1, radius2, X axe rotation,
// flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg),
// sweep arc ( 0 = CCW, 1 = CW),
// end point,
// center point (optional, needed to draw a pie
fprintf( outputFile, "<path d=\"M%d %d A%d %d 0.0 %d %d %d %d \" /> \n",
(int) start.x, (int) start.y,
(int) radius_dev, (int) radius_dev,
// end point
fprintf( outputFile, "<path d=\"M%g %g A%g %g 0.0 %d %d %g %g \" />\n",
start.x, start.y, radius_dev, radius_dev,
flg_arc, flg_sweep,
(int) end.x, (int) end.y );
end.x, end.y );
}
@ -355,7 +365,17 @@ void SVG_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
setFillMode( aFill );
SetCurrentLineWidth( aWidth );
fprintf( outputFile, "<polygon style=\"fill-rule:evenodd;\"\n" );
switch( aFill )
{
case NO_FILL:
fprintf( outputFile, "<polyline fill=\"none;\"\n" );
break;
case FILLED_WITH_BG_BODYCOLOR:
case FILLED_SHAPE:
fprintf( outputFile, "<polyline style=\"fill-rule:evenodd;\"\n" );
break;
}
DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
fprintf( outputFile, "points=\"%d,%d\n", (int) pos.x, (int) pos.y );
@ -380,7 +400,7 @@ void SVG_PLOTTER::PlotImage( const wxImage& aImage, const wxPoint& aPos,
// in svg file we must insert a link to a png image file to plot an image
// the image itself is not included in the svg file.
// So we prefer skip the image, and just draw a rectangle,
// like othe plotter which do not support images
// like other plotters which do not support images
PLOTTER::PlotImage( aImage, aPos, aScaleFactor );

View File

@ -4,7 +4,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2012 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 1992-2012 Jean-Pierre Charras <jp.charras at wanadoo.fr
* Copyright (C) 1992-2010 Lorenzo Marcantonio
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
*
@ -42,13 +42,12 @@
#define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
#define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
#define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
#define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )
// static members (static to remember last state):
int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO;
int DIALOG_PLOT_SCHEMATIC::m_HPGLPaperSizeSelect = 0;
void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
{
@ -64,7 +63,6 @@ DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) :
m_parent = parent;
m_config = wxGetApp().GetSettings();
m_select_PlotAll = false;
initDlg();
GetSizer()->SetSizeHints( this );
@ -94,6 +92,9 @@ void DIALOG_PLOT_SCHEMATIC::initDlg()
m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
SetPlotOriginCenter( tmp );
m_config->Read( PLOT_HPGL_PAPERSIZE_KEY, &m_HPGLPaperSizeSelect, 0 );
m_HPGLPaperSizeOption->SetSelection( m_HPGLPaperSizeSelect );
// Switch to the last save plot format
long plotfmt;
m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
@ -164,6 +165,7 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
m_config->Write( PLOT_HPGL_ORIGIN_KEY, GetPlotOriginCenter() );
m_HPGLPaperSizeSelect = m_HPGLPaperSizeOption->GetSelection();
m_config->Write( PLOT_HPGL_PAPERSIZE_KEY, m_HPGLPaperSizeSelect );
m_pageSizeSelect = m_PaperSizeOption->GetSelection();
g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DefaultLineSizeCtrl );
@ -175,37 +177,38 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
{
switch( m_plotFormatOpt->GetSelection() )
switch( GetPlotFileFormat() )
{
case 0: // postscript
default:
case PLOT_FORMAT_POST:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show( m_PaperSizeOption );
m_PaperSizeOption->Enable( true );
m_DefaultLineSizeCtrl->Enable( true );
break;
case 1: // PDF
case PLOT_FORMAT_PDF:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( true );
m_DefaultLineSizeCtrl->Enable( true );
break;
case 2: // SVG
case PLOT_FORMAT_SVG:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( false );
m_DefaultLineSizeCtrl->Enable( true );
break;
case 3: // DXF
case PLOT_FORMAT_DXF:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( false );
m_DefaultLineSizeCtrl->Enable( false );
break;
case 4: //HPGL
case PLOT_FORMAT_HPGL:
m_paperOptionsSizer->Show( m_paperHPGLSizer );
m_paperOptionsSizer->Hide(m_PaperSizeOption);
m_DefaultLineSizeCtrl->Enable( false );
@ -217,75 +220,41 @@ void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
}
void DIALOG_PLOT_SCHEMATIC::setupPlotPage( PLOTTER * plotter, SCH_SCREEN* screen )
{
PAGE_INFO plotPage; // page size selected to plot
// Considerations on page size and scaling requests
PAGE_INFO actualPage = screen->GetPageSettings(); // page size selected in schematic
switch( m_pageSizeSelect )
{
case PAGE_SIZE_A:
plotPage.SetType( wxT( "A" ) );
plotPage.SetPortrait( actualPage.IsPortrait() );
break;
case PAGE_SIZE_A4:
plotPage.SetType( wxT( "A4" ) );
plotPage.SetPortrait( actualPage.IsPortrait() );
break;
case PAGE_SIZE_AUTO:
default:
plotPage = actualPage;
break;
}
double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
double scale = MIN( scalex, scaley );
plotter->SetPageSettings( plotPage );
plotter->SetViewport( wxPoint( 0, 0 ), IU_PER_DECIMILS, scale, false );
}
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotCurrentClick( wxCommandEvent& event )
{
m_select_PlotAll = false;
PlotSchematic();
PlotSchematic( true );
}
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
{
m_select_PlotAll = true;
PlotSchematic();
PlotSchematic( false );
}
void DIALOG_PLOT_SCHEMATIC::PlotSchematic()
void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll )
{
getPlotOptions();
switch( GetPlotFileFormat() )
{
case PLOT_FORMAT_HPGL:
createHPGLFile( m_select_PlotAll );
createHPGLFile( aPlotAll, getPlotFrameRef() );
break;
default:
case PLOT_FORMAT_POST:
createPSFile();
createPSFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_DXF:
CreateDXFFile();
CreateDXFFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_PDF:
createPDFFile();
createPDFFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_SVG:
createSVGFile( m_select_PlotAll, getPlotFrameRef() );
createSVGFile( aPlotAll, getPlotFrameRef() );
break;
}
m_MessagesBox->AppendText( wxT( "****\n" ) );

View File

@ -50,8 +50,7 @@ private:
static int m_pageSizeSelect; // Static to keep last option for some format:
// Static to keep last option:
// use default size or force A or A4 size
static int m_HPGLPaperSizeSelect; // for HPGL format only: last selected paper size
bool m_select_PlotAll; // Flaf to plot current page or the full hierarchy
int m_HPGLPaperSizeSelect; // for HPGL format only: last selected paper size
public:
// / Constructors
@ -67,6 +66,7 @@ private:
// common
void getPlotOptions();
bool getModeColor()
{ return m_ModeColorOption->GetSelection() == 0; }
@ -78,18 +78,17 @@ private:
bool getPlotFrameRef() { return m_PlotFrameRefOpt->GetValue(); }
void setPlotFrameRef( bool aPlot) {m_PlotFrameRefOpt->SetValue( aPlot ); }
void setupPlotPage( PLOTTER* plotter, SCH_SCREEN* screen );
void PlotSchematic();
void PlotSchematic( bool aPlotAll );
// PDF
void createPDFFile();
void plotOneSheetPDF( PLOTTER* plotter, SCH_SCREEN* screen);
void createPDFFile( bool aPlotAll, bool aPlotFrameRef );
void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotFrameRef);
void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen );
// DXF
void CreateDXFFile();
void PlotOneSheetDXF( const wxString& FileName, SCH_SCREEN* screen,
wxPoint plot_offset, double scale );
void CreateDXFFile( bool aPlotAll, bool aPlotFrameRef );
bool PlotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen,
wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );
// HPGL
bool GetPlotOriginCenter()
@ -100,24 +99,25 @@ private:
{
m_plotOriginOpt->SetSelection( aCenter ? 1 : 0 );
}
void createHPGLFile( bool aPlotAll );
void createHPGLFile( bool aPlotAll, bool aPlotFrameRef );
void SetHPGLPenWidth();
void Plot_1_Page_HPGL( const wxString& FileName, SCH_SCREEN* screen,
const PAGE_INFO& pageInfo,
wxPoint& offset, double plot_scale );
bool Plot_1_Page_HPGL( const wxString& aFileName, SCH_SCREEN* aScreen,
const PAGE_INFO& aPageInfo,
wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );
// PS
void createPSFile();
void plotOneSheetPS( const wxString& FileName, SCH_SCREEN* screen,
const PAGE_INFO& pageInfo,
wxPoint plot_offset, double scale );
void createPSFile( bool aPlotAll, bool aPlotFrameRef );
bool plotOneSheetPS( const wxString& aFileName, SCH_SCREEN* aScreen,
const PAGE_INFO& aPageInfo,
wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );
// SVG
void createSVGFile( bool aPrintAll, bool aPrint_Sheet_Ref );
void createSVGFile( bool aPlotAll, bool aPlotFrameRef );
public:
// This function is static because it is called by libedit
// outside a dialog.
static bool plotOneSheetSVG( EDA_DRAW_FRAME* frame, const wxString& FullFileName,
SCH_SCREEN* screen,
bool aPrintBlackAndWhite, bool aPrint_Sheet_Ref );
// outside a dialog. This is the reason we need aFrame as parameter
static bool plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, const wxString& aFileName,
SCH_SCREEN* aScreen,
bool aPlotBlackAndWhite, bool aPlotFrameRef );
};

View File

@ -34,14 +34,13 @@
#include <dialog_plot_schematic.h>
void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_parent;
SCH_SCREEN* screen = schframe->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
wxString plotFileName;
wxPoint plot_offset;
/* When printing all pages, the printed page is not the current page.
* In complex hierarchies, we must setup references and others parameters
@ -56,7 +55,7 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
while( true )
{
if( m_select_PlotAll )
if( aPlotAll )
{
if( sheetpath == NULL )
break;
@ -78,15 +77,21 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
sheetpath = SheetList.GetNext();
}
plot_offset.x = 0;
plot_offset.y = 0;
wxPoint plot_offset;
plotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT(".")
+ DXF_PLOTTER::GetDefaultFileExtension();
PlotOneSheetDXF( plotFileName, screen, plot_offset, 1 );
wxString msg;
if( !m_select_PlotAll )
if( PlotOneSheetDXF( plotFileName, screen, plot_offset, 1.0, aPlotFrameRef ) )
msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
else // Error
msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
if( !aPlotAll )
break;
}
@ -96,56 +101,46 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
}
void DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& FileName,
SCH_SCREEN* screen,
wxPoint plot_offset,
double scale )
bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
SCH_SCREEN* aScreen,
wxPoint aPlotOffset,
double aScale,
bool aPlotFrameRef )
{
wxString msg;
FILE* output_file = wxFopen( FileName, wxT( "wt" ) );
FILE* output_file = wxFopen( aFileName, wxT( "wt" ) );
if( output_file == NULL )
{
msg = wxT( "\n** " );
msg += _( "Unable to create " ) + FileName + wxT( " **\n" );
m_MessagesBox->AppendText( msg );
return;
}
msg.Printf( _( "Plot: %s " ), GetChars( FileName ) );
m_MessagesBox->AppendText( msg );
return false;
LOCALE_IO toggle;
DXF_PLOTTER* plotter = new DXF_PLOTTER();
const PAGE_INFO& pageInfo = screen->GetPageSettings();
const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
plotter->SetPageSettings( pageInfo );
plotter->SetColorMode( getModeColor() );
plotter->SetViewport( plot_offset, IU_PER_DECIMILS, scale, false );
plotter->SetViewport( aPlotOffset, IU_PER_DECIMILS, aScale, false );
// Init :
plotter->SetCreator( wxT( "Eeschema-DXF" ) );
plotter->SetFilename( FileName );
plotter->SetFilename( aFileName );
plotter->StartPlot( output_file );
if( getPlotFrameRef() )
if( aPlotFrameRef )
{
plotter->SetColor( BLACK );
PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
m_parent->GetPageSettings(),
screen->m_ScreenNumber, screen->m_NumberOfScreens,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(),
screen->GetFileName() );
aScreen->GetFileName() );
}
screen->Plot( plotter );
aScreen->Plot( plotter );
// finish
plotter->EndPlot();
delete plotter;
m_MessagesBox->AppendText( wxT( "Ok\n" ) );
return true;
}

View File

@ -108,7 +108,7 @@ void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
}
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
{
wxString plotFileName;
SCH_SCREEN* screen = m_parent->GetScreen();
@ -179,7 +179,14 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )
LOCALE_IO toggle;
Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset, plot_scale );
wxString msg;
if( Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset,
plot_scale, aPlotFrameRef ) )
msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
else // Error
msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
if( !aPlotAll )
break;
@ -191,37 +198,28 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )
}
void DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& FileName,
SCH_SCREEN* screen,
const PAGE_INFO& pageInfo,
wxPoint& offset,
double plot_scale )
bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
SCH_SCREEN* aScreen,
const PAGE_INFO& aPageInfo,
wxPoint aPlot0ffset,
double aScale,
bool aPlotFrameRef )
{
wxString msg;
FILE* output_file = wxFopen( FileName, wxT( "wt" ) );
FILE* output_file = wxFopen( aFileName, wxT( "wt" ) );
if( output_file == NULL )
{
msg = wxT( "\n** " );
msg += _( "Unable to create " ) + FileName + wxT( " **\n" );
m_MessagesBox->AppendText( msg );
return;
}
return false;
LOCALE_IO toggle;
msg.Printf( _( "Plot: %s " ), FileName.GetData() );
m_MessagesBox->AppendText( msg );
HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
plotter->SetPageSettings( pageInfo );
plotter->SetViewport( offset, IU_PER_DECIMILS, plot_scale, false );
plotter->SetPageSettings( aPageInfo );
plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, aScale, false );
// Init :
plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
plotter->SetFilename( FileName );
plotter->SetFilename( aFileName );
plotter->SetPenSpeed( g_HPGL_Pen_Descr.m_Pen_Speed );
plotter->SetPenNumber( g_HPGL_Pen_Descr.m_Pen_Num );
plotter->SetPenDiameter( g_HPGL_Pen_Descr.m_Pen_Diam );
@ -233,14 +231,14 @@ void DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& FileName,
if( getPlotFrameRef() )
PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
m_parent->GetPageSettings(),
screen->m_ScreenNumber, screen->m_NumberOfScreens,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(),
screen->GetFileName() );
aScreen->GetFileName() );
screen->Plot( plotter );
aScreen->Plot( plotter );
plotter->EndPlot();
delete plotter;
m_MessagesBox->AppendText( wxT( "Ok\n" ) );
return true;
}

View File

@ -34,7 +34,7 @@
#include <sch_sheet_path.h>
#include <dialog_plot_schematic.h>
void DIALOG_PLOT_SCHEMATIC::createPDFFile()
void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
@ -58,13 +58,15 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile()
plotter->SetColorMode( getModeColor() );
plotter->SetCreator( wxT( "Eeschema-PDF" ) );
wxString msg;
wxString plotFileName;
// First page handling is different
bool first_page = true;
do
{
// Step over the schematic hierarchy
if( m_select_PlotAll )
if( aPlotAll )
{
SCH_SHEET_PATH list;
@ -83,27 +85,22 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile()
if( first_page )
{
wxString msg;
wxString plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
+ PDF_PLOTTER::GetDefaultFileExtension();
msg.Printf( _( "Plot: %s " ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
+ PDF_PLOTTER::GetDefaultFileExtension();
FILE* output_file = wxFopen( plotFileName, wxT( "wb" ) );
if( output_file == NULL )
{
msg = wxT( "\n** " );
msg += _( "Unable to create " ) + plotFileName + wxT( " **\n" );
msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
wxBell();
return;
}
// Open the plotter and do the first page
SetLocaleTo_C_standard();
plotter->SetFilename( plotFileName );
setupPlotPage( plotter, screen );
setupPlotPagePDF( plotter, screen );
plotter->StartPlot( output_file );
first_page = false;
}
@ -112,12 +109,12 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile()
/* For the following pages you need to close the (finished) page,
* reconfigure, and then start a new one */
plotter->ClosePage();
setupPlotPage( plotter, screen );
setupPlotPagePDF( plotter, screen );
plotter->StartPage();
}
plotOneSheetPDF( plotter, screen );
} while( m_select_PlotAll && sheetpath );
plotOneSheetPDF( plotter, screen, aPlotFrameRef );
} while( aPlotAll && sheetpath );
// Everything done, close the plot and restore the environment
plotter->EndPlot();
@ -128,20 +125,58 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile()
m_parent->SetCurrentSheet( oldsheetpath );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
}
void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* plotter, SCH_SCREEN* screen )
void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter,
SCH_SCREEN* aScreen,
bool aPlotFrameRef )
{
if( getPlotFrameRef() )
if( aPlotFrameRef )
{
plotter->SetColor( BLACK );
PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
aPlotter->SetColor( BLACK );
PlotWorkSheet( aPlotter, m_parent->GetTitleBlock(),
m_parent->GetPageSettings(),
screen->m_ScreenNumber, screen->m_NumberOfScreens,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(),
screen->GetFileName() );
aScreen->GetFileName() );
}
screen->Plot( plotter );
aScreen->Plot( aPlotter );
}
void DIALOG_PLOT_SCHEMATIC::setupPlotPagePDF( PLOTTER * aPlotter, SCH_SCREEN* aScreen )
{
PAGE_INFO plotPage; // page size selected to plot
// Considerations on page size and scaling requests
PAGE_INFO actualPage = aScreen->GetPageSettings(); // page size selected in schematic
switch( m_pageSizeSelect )
{
case PAGE_SIZE_A:
plotPage.SetType( wxT( "A" ) );
plotPage.SetPortrait( actualPage.IsPortrait() );
break;
case PAGE_SIZE_A4:
plotPage.SetType( wxT( "A4" ) );
plotPage.SetPortrait( actualPage.IsPortrait() );
break;
case PAGE_SIZE_AUTO:
default:
plotPage = actualPage;
break;
}
double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
double scale = MIN( scalex, scaley );
aPlotter->SetPageSettings( plotPage );
aPlotter->SetViewport( wxPoint( 0, 0 ), IU_PER_DECIMILS, scale, false );
}

View File

@ -33,7 +33,7 @@
#include <dialog_plot_schematic.h>
void DIALOG_PLOT_SCHEMATIC::createPSFile()
void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
@ -55,7 +55,7 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile()
while( true )
{
if( m_select_PlotAll )
if( aPlotAll )
{
if( sheetpath == NULL )
break;
@ -104,9 +104,18 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile()
plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
+ PS_PLOTTER::GetDefaultFileExtension();
plotOneSheetPS( plotFileName, screen, plotPage, plot_offset, scale );
wxString msg;
if( !m_select_PlotAll )
if( plotOneSheetPS( plotFileName, screen, plotPage, plot_offset,
scale, aPlotFrameRef ) )
msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
else // Error
msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );
m_MessagesBox->AppendText( msg );
if( !aPlotAll )
break;
}
@ -116,54 +125,45 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile()
}
void DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& FileName,
SCH_SCREEN* screen,
const PAGE_INFO& pageInfo,
wxPoint plot_offset,
double scale )
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
SCH_SCREEN* aScreen,
const PAGE_INFO& aPageInfo,
wxPoint aPlot0ffset,
double aScale,
bool aPlotFrameRef )
{
wxString msg;
FILE* output_file = wxFopen( FileName, wxT( "wt" ) );
FILE* output_file = wxFopen( aFileName, wxT( "wt" ) );
if( output_file == NULL )
{
msg = wxT( "\n** " );
msg += _( "Unable to create " ) + FileName + wxT( " **\n" );
m_MessagesBox->AppendText( msg );
return;
}
msg.Printf( _( "Plot: %s " ), GetChars( FileName ) );
m_MessagesBox->AppendText( msg );
return false;
SetLocaleTo_C_standard();
PS_PLOTTER* plotter = new PS_PLOTTER();
plotter->SetPageSettings( pageInfo );
plotter->SetPageSettings( aPageInfo );
plotter->SetDefaultLineWidth( g_DrawDefaultLineThickness );
plotter->SetColorMode( getModeColor() );
plotter->SetViewport( plot_offset, IU_PER_DECIMILS, scale, false );
plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, aScale, false );
// Init :
plotter->SetCreator( wxT( "Eeschema-PS" ) );
plotter->SetFilename( FileName );
plotter->SetFilename( aFileName );
plotter->StartPlot( output_file );
if( getPlotFrameRef() )
if( aPlotFrameRef )
{
plotter->SetColor( BLACK );
PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
m_parent->GetPageSettings(),
screen->m_ScreenNumber, screen->m_NumberOfScreens,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(),
screen->GetFileName() );
aScreen->GetFileName() );
}
screen->Plot( plotter );
aScreen->Plot( plotter );
plotter->EndPlot();
delete plotter;
SetLocaleTo_Default();
m_MessagesBox->AppendText( wxT( "Ok\n" ) );
return true;
}

View File

@ -102,75 +102,60 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
bool success = plotOneSheetSVG( m_parent, fn.GetFullPath(), screen,
getModeColor() ? false : true,
aPrintFrameRef );
msg = _( "Create file " ) + fn.GetFullPath();
if( success )
msg.Printf( _( "Plot: %s OK\n" ),
GetChars( fn.GetFullPath() ) );
else // Error
msg.Printf( _( "** Unable to create %s **\n" ),
GetChars( fn.GetFullPath() ) );
if( !success )
msg += _( " error" );
msg += wxT( "\n" );
m_MessagesBox->AppendText( msg );
}
}
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* frame,
const wxString& FullFileName,
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* aFrame,
const wxString& aFileName,
SCH_SCREEN* aScreen,
bool aPrintBlackAndWhite,
bool aPrintFrameRef )
bool aPlotBlackAndWhite,
bool aPlotFrameRef )
{
int tmpzoom;
wxPoint tmp_startvisu;
wxSize sheetSize; // Sheet size in internal units
wxPoint old_org;
bool success = true;
FILE* output_file = wxFopen( aFileName, wxT( "wt" ) );
tmp_startvisu = aScreen->m_StartVisu;
tmpzoom = aScreen->GetZoom();
old_org = aScreen->m_DrawOrg;
aScreen->m_DrawOrg.x = aScreen->m_DrawOrg.y = 0;
aScreen->m_StartVisu.x = aScreen->m_StartVisu.y = 0;
if( output_file == NULL )
return false;
sheetSize = aScreen->GetPageSettings().GetSizeIU();
aScreen->SetScalingFactor( 1.0 );
EDA_DRAW_PANEL* panel = frame->GetCanvas();
LOCALE_IO toggle;
LOCALE_IO toggle;
SVG_PLOTTER* plotter = new SVG_PLOTTER();
double dpi = 1000.0 * IU_PER_MILS;
wxPoint origin;
KicadSVGFileDC dc( FullFileName, origin, sheetSize, dpi );
const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
plotter->SetPageSettings( pageInfo );
plotter->SetDefaultLineWidth( g_DrawDefaultLineThickness );
plotter->SetColorMode( aPlotBlackAndWhite ? false : true );
wxPoint plot_offset;
double scale = 1.0;
plotter->SetViewport( plot_offset, IU_PER_DECIMILS, scale, false );
EDA_RECT tmp = *panel->GetClipBox();
GRResetPenAndBrush( &dc );
GRForceBlackPen( aPrintBlackAndWhite );
// Init :
plotter->SetCreator( wxT( "Eeschema-SVG" ) );
plotter->SetFilename( aFileName );
plotter->StartPlot( output_file );
if( aPlotFrameRef )
{
plotter->SetColor( BLACK );
PlotWorkSheet( plotter, aFrame->GetTitleBlock(),
aFrame->GetPageSettings(),
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
aFrame->GetScreenDesc(),
aScreen->GetFileName() );
}
panel->SetClipBox( EDA_RECT( wxPoint( -0x3FFFFF0, -0x3FFFFF0 ),
wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
aScreen->Plot( plotter );
aScreen->m_IsPrinting = true;
plotter->EndPlot();
delete plotter;
if( frame->IsType( SCHEMATIC_FRAME_TYPE ) )
aScreen->Draw( panel, &dc, GR_COPY );
if( frame->IsType( LIBEDITOR_FRAME_TYPE ) )
( (LIB_EDIT_FRAME*) frame )->RedrawComponent( &dc,
wxPoint( sheetSize.x / 2,
sheetSize.y / 2 ) );
if( aPrintFrameRef )
frame->TraceWorkSheet( &dc, aScreen, g_DrawDefaultLineThickness,
IU_PER_MILS, frame->GetScreenDesc() );
aScreen->m_IsPrinting = false;
panel->SetClipBox( tmp );
GRForceBlackPen( false );
aScreen->m_StartVisu = tmp_startvisu;
aScreen->m_DrawOrg = old_org;
aScreen->SetZoom( tmpzoom );
return success;
return true;
}