|
|
|
@ -53,44 +53,7 @@ |
|
|
|
|
|
|
|
// static members (static to remember last state):
|
|
|
|
int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO; |
|
|
|
int DIALOG_PLOT_SCHEMATIC::m_HPGLPaperSizeSelect = PAGE_SIZE_AUTO; |
|
|
|
|
|
|
|
|
|
|
|
enum HPGL_PAGEZ_T { |
|
|
|
PAGE_DEFAULT = 0, |
|
|
|
HPGL_PAGE_SIZE_A5, |
|
|
|
HPGL_PAGE_SIZE_A4, |
|
|
|
HPGL_PAGE_SIZE_A3, |
|
|
|
HPGL_PAGE_SIZE_A2, |
|
|
|
HPGL_PAGE_SIZE_A1, |
|
|
|
HPGL_PAGE_SIZE_A0, |
|
|
|
HPGL_PAGE_SIZE_A, |
|
|
|
HPGL_PAGE_SIZE_B, |
|
|
|
HPGL_PAGE_SIZE_C, |
|
|
|
HPGL_PAGE_SIZE_D, |
|
|
|
HPGL_PAGE_SIZE_E, |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const wxChar* plot_sheet_list( int aSize ) |
|
|
|
{ |
|
|
|
switch( aSize ) |
|
|
|
{ |
|
|
|
default: |
|
|
|
case PAGE_DEFAULT: return nullptr; |
|
|
|
case HPGL_PAGE_SIZE_A5: return wxT( "A5" ); |
|
|
|
case HPGL_PAGE_SIZE_A4: return wxT( "A4" ); |
|
|
|
case HPGL_PAGE_SIZE_A3: return wxT( "A3" ); |
|
|
|
case HPGL_PAGE_SIZE_A2: return wxT( "A2" ); |
|
|
|
case HPGL_PAGE_SIZE_A1: return wxT( "A1" ); |
|
|
|
case HPGL_PAGE_SIZE_A0: return wxT( "A0" ); |
|
|
|
case HPGL_PAGE_SIZE_A: return wxT( "A" ); |
|
|
|
case HPGL_PAGE_SIZE_B: return wxT( "B" ); |
|
|
|
case HPGL_PAGE_SIZE_C: return wxT( "C" ); |
|
|
|
case HPGL_PAGE_SIZE_D: return wxT( "D" ); |
|
|
|
case HPGL_PAGE_SIZE_E: return wxT( "E" ); |
|
|
|
} |
|
|
|
} |
|
|
|
HPGL_PAGE_SIZE DIALOG_PLOT_SCHEMATIC::m_HPGLPaperSizeSelect = HPGL_PAGE_SIZE::DEFAULT; |
|
|
|
|
|
|
|
|
|
|
|
DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) |
|
|
|
@ -149,7 +112,7 @@ void DIALOG_PLOT_SCHEMATIC::initDlg() |
|
|
|
// HPGL plot origin and unit system configuration
|
|
|
|
m_plotOriginOpt->SetSelection( cfg->m_PlotPanel.hpgl_origin ); |
|
|
|
|
|
|
|
m_HPGLPaperSizeSelect = cfg->m_PlotPanel.hpgl_paper_size; |
|
|
|
m_HPGLPaperSizeSelect = static_cast<HPGL_PAGE_SIZE>( cfg->m_PlotPanel.hpgl_paper_size ); |
|
|
|
|
|
|
|
// HPGL Pen Size is stored in mm in config
|
|
|
|
m_HPGLPenSize = cfg->m_PlotPanel.hpgl_pen_size * schIUScale.IU_PER_MM; |
|
|
|
@ -258,7 +221,7 @@ PLOT_FORMAT DIALOG_PLOT_SCHEMATIC::GetPlotFileFormat() |
|
|
|
void DIALOG_PLOT_SCHEMATIC::OnPageSizeSelected( wxCommandEvent& event ) |
|
|
|
{ |
|
|
|
if( GetPlotFileFormat() == PLOT_FORMAT::HPGL ) |
|
|
|
m_HPGLPaperSizeSelect = m_paperSizeOption->GetSelection(); |
|
|
|
m_HPGLPaperSizeSelect = static_cast<HPGL_PAGE_SIZE>( m_paperSizeOption->GetSelection() ); |
|
|
|
else |
|
|
|
m_pageSizeSelect = m_paperSizeOption->GetSelection(); |
|
|
|
} |
|
|
|
@ -291,7 +254,7 @@ void DIALOG_PLOT_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event ) |
|
|
|
paperSizes.push_back( _( "D" ) ); |
|
|
|
paperSizes.push_back( _( "E" ) ); |
|
|
|
|
|
|
|
selection = m_HPGLPaperSizeSelect; |
|
|
|
selection = static_cast<int>( m_HPGLPaperSizeSelect ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -339,7 +302,7 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( RENDER_SETTINGS* aSettings ) |
|
|
|
cfg->m_PlotPanel.frame_reference = getPlotDrawingSheet(); |
|
|
|
cfg->m_PlotPanel.format = static_cast<int>( GetPlotFileFormat() ); |
|
|
|
cfg->m_PlotPanel.hpgl_origin = m_plotOriginOpt->GetSelection(); |
|
|
|
cfg->m_PlotPanel.hpgl_paper_size = m_HPGLPaperSizeSelect; |
|
|
|
cfg->m_PlotPanel.hpgl_paper_size = static_cast<int>( m_HPGLPaperSizeSelect ); |
|
|
|
cfg->m_PlotPanel.open_file_after_plot = getOpenFileAfterPlot(); |
|
|
|
|
|
|
|
// HPGL Pen Size is stored in mm in config
|
|
|
|
@ -398,202 +361,29 @@ void DIALOG_PLOT_SCHEMATIC::plotSchematic( bool aPlotAll ) |
|
|
|
|
|
|
|
getPlotOptions( &renderSettings ); |
|
|
|
|
|
|
|
switch( GetPlotFileFormat() ) |
|
|
|
{ |
|
|
|
default: |
|
|
|
case PLOT_FORMAT::POST: |
|
|
|
createPSFiles( aPlotAll, getPlotDrawingSheet(), &renderSettings ); |
|
|
|
break; |
|
|
|
case PLOT_FORMAT::DXF: |
|
|
|
createDXFFiles( aPlotAll, getPlotDrawingSheet(), &renderSettings ); |
|
|
|
break; |
|
|
|
case PLOT_FORMAT::PDF: |
|
|
|
createPDFFile( aPlotAll, getPlotDrawingSheet(), &renderSettings ); |
|
|
|
break; |
|
|
|
case PLOT_FORMAT::SVG: |
|
|
|
createSVGFiles( aPlotAll, getPlotDrawingSheet(), &renderSettings ); |
|
|
|
break; |
|
|
|
case PLOT_FORMAT::HPGL: |
|
|
|
createHPGLFiles( aPlotAll, getPlotDrawingSheet(), &renderSettings ); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( const wxString& aPlotFileName, |
|
|
|
const wxString& aExtension, |
|
|
|
REPORTER* aReporter ) |
|
|
|
{ |
|
|
|
wxFileName retv; |
|
|
|
wxFileName tmp; |
|
|
|
|
|
|
|
tmp.SetPath( getOutputPath() ); |
|
|
|
retv.SetPath( tmp.GetPath() ); |
|
|
|
|
|
|
|
if( !aPlotFileName.IsEmpty() ) |
|
|
|
retv.SetName( aPlotFileName ); |
|
|
|
else |
|
|
|
retv.SetName( _( "Schematic" ) ); |
|
|
|
|
|
|
|
retv.SetExt( aExtension ); |
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &tmp, retv.GetFullName(), aReporter ) || !tmp.IsDirWritable() ) |
|
|
|
{ |
|
|
|
wxString msg = wxString::Format( _( "Failed to write plot files to folder '%s'." ), |
|
|
|
tmp.GetPath() ); |
|
|
|
aReporter->Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
retv.Clear(); |
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS& settings = m_parent->Schematic().Settings(); |
|
|
|
settings.m_PlotDirectoryName.Clear(); |
|
|
|
|
|
|
|
m_configChanged = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
retv.SetPath( tmp.GetPath() ); |
|
|
|
} |
|
|
|
|
|
|
|
wxLogTrace( tracePathsAndFiles, "Writing plot file '%s'.", retv.GetFullPath() ); |
|
|
|
|
|
|
|
return retv; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::createDXFFiles( bool aPlotAll, bool aPlotDrawingSheet, |
|
|
|
RENDER_SETTINGS* aRenderSettings ) |
|
|
|
{ |
|
|
|
SCH_EDIT_FRAME* schframe = m_parent; |
|
|
|
SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); |
|
|
|
|
|
|
|
/* When printing all pages, the printed page is not the current page. In complex hierarchies,
|
|
|
|
* we must update symbol references and other parameters in the given printed SCH_SCREEN, |
|
|
|
* according to the sheet path because in complex hierarchies a SCH_SCREEN (a drawing ) is |
|
|
|
* shared between many sheets and symbol references depend on the actual sheet path used. |
|
|
|
*/ |
|
|
|
SCH_SHEET_LIST sheetList; |
|
|
|
|
|
|
|
if( aPlotAll ) |
|
|
|
{ |
|
|
|
sheetList.BuildSheetList( &schframe->Schematic().Root(), true ); |
|
|
|
sheetList.SortByPageNumbers(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sheetList.push_back( schframe->GetCurrentSheet() ); |
|
|
|
} |
|
|
|
|
|
|
|
REPORTER& reporter = m_MessagesBox->Reporter(); |
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ ) |
|
|
|
{ |
|
|
|
schframe->SetCurrentSheet( sheetList[i] ); |
|
|
|
schframe->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
schframe->SetSheetNumberAndCount(); |
|
|
|
|
|
|
|
SCH_SCREEN* screen = schframe->GetCurrentSheet().LastScreen(); |
|
|
|
wxPoint plot_offset; |
|
|
|
wxString msg; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
wxString fname = schframe->GetUniqueFilenameForCurrentSheet(); |
|
|
|
|
|
|
|
// The sub sheet can be in a sub_hierarchy, but we plot the file in the
|
|
|
|
// main project folder (or the folder specified by the caller),
|
|
|
|
// so replace separators to create a unique filename:
|
|
|
|
fname.Replace( "/", "_" ); |
|
|
|
fname.Replace( "\\", "_" ); |
|
|
|
wxString ext = DXF_PLOTTER::GetDefaultFileExtension(); |
|
|
|
wxFileName plotFileName = createPlotFileName( fname, ext, &reporter ); |
|
|
|
|
|
|
|
if( !plotFileName.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
if( plotOneSheetDXF( plotFileName.GetFullPath(), screen, aRenderSettings, |
|
|
|
plot_offset, 1.0, aPlotDrawingSheet ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ACTION ); |
|
|
|
} |
|
|
|
else // Error
|
|
|
|
{ |
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
} |
|
|
|
catch( IO_ERROR& e ) |
|
|
|
{ |
|
|
|
msg.Printf( wxT( "DXF Plotter exception: %s"), e.What() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
schframe->SetCurrentSheet( oldsheetpath ); |
|
|
|
schframe->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
schframe->SetSheetNumberAndCount(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reporter.ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); |
|
|
|
|
|
|
|
schframe->SetCurrentSheet( oldsheetpath ); |
|
|
|
schframe->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
schframe->SetSheetNumberAndCount(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetDXF( const wxString& aFileName, |
|
|
|
SCH_SCREEN* aScreen, |
|
|
|
RENDER_SETTINGS* aRenderSettings, |
|
|
|
const wxPoint& aPlotOffset, |
|
|
|
double aScale, |
|
|
|
bool aPlotFrameRef ) |
|
|
|
{ |
|
|
|
aRenderSettings->LoadColors( getColorSettings() ); |
|
|
|
aRenderSettings->SetDefaultPenWidth( 0 ); |
|
|
|
|
|
|
|
const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); |
|
|
|
DXF_PLOTTER* plotter = new DXF_PLOTTER(); |
|
|
|
std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( m_parent ); |
|
|
|
|
|
|
|
plotter->SetRenderSettings( aRenderSettings ); |
|
|
|
plotter->SetPageSettings( pageInfo ); |
|
|
|
plotter->SetColorMode( getModeColor() ); |
|
|
|
COLOR_SETTINGS* colors = getColorSettings(); |
|
|
|
|
|
|
|
// Currently, plot units are in decimil
|
|
|
|
plotter->SetViewport( aPlotOffset, schIUScale.IU_PER_MILS/10, aScale, false ); |
|
|
|
SCH_PLOT_SETTINGS plotSettings; |
|
|
|
plotSettings.m_plotDrawingSheet = getPlotDrawingSheet(); |
|
|
|
plotSettings.m_plotAll = aPlotAll; |
|
|
|
plotSettings.m_blackAndWhite = !getModeColor(); |
|
|
|
plotSettings.m_useBackgroundColor = m_plotBackgroundColor->GetValue(); |
|
|
|
plotSettings.m_theme = colors->GetFilename(); |
|
|
|
plotSettings.m_HPGLPenSize = m_HPGLPenSize; |
|
|
|
plotSettings.m_HPGLPaperSizeSelect = static_cast<HPGL_PAGE_SIZE>( m_HPGLPaperSizeSelect ); |
|
|
|
plotSettings.m_HPGLPlotOrigin = |
|
|
|
static_cast<HPGL_PLOT_ORIGIN_AND_UNITS>( m_plotOriginOpt->GetSelection() ); |
|
|
|
plotSettings.m_outputDirectory = getOutputPath(); |
|
|
|
plotSettings.m_pageSizeSelect = m_pageSizeSelect; |
|
|
|
|
|
|
|
// Init :
|
|
|
|
plotter->SetCreator( wxT( "Eeschema-DXF" ) ); |
|
|
|
|
|
|
|
if( ! plotter->OpenFile( aFileName ) ) |
|
|
|
{ |
|
|
|
delete plotter; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
LOCALE_IO toggle; |
|
|
|
schPlotter->Plot( GetPlotFileFormat(), plotSettings, &renderSettings, |
|
|
|
&m_MessagesBox->Reporter() ); |
|
|
|
|
|
|
|
plotter->StartPlot( m_parent->GetCurrentSheet().GetPageNumber() ); |
|
|
|
|
|
|
|
if( aPlotFrameRef ) |
|
|
|
{ |
|
|
|
wxString sheetName = m_parent->GetCurrentSheet().Last()->GetName(); |
|
|
|
wxString sheetPath = m_parent->GetCurrentSheet().PathHumanReadable(); |
|
|
|
COLOR4D color = plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); |
|
|
|
|
|
|
|
PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), pageInfo, |
|
|
|
aScreen->Schematic()->GetProperties(), aScreen->GetPageNumber(), |
|
|
|
aScreen->GetPageCount(), sheetName, sheetPath, aScreen->GetFileName(), |
|
|
|
plotter->GetColorMode() ? color : COLOR4D::BLACK, |
|
|
|
aScreen->GetVirtualPageNumber() == 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
aScreen->Plot( plotter ); |
|
|
|
|
|
|
|
// finish
|
|
|
|
plotter->EndPlot(); |
|
|
|
delete plotter; |
|
|
|
|
|
|
|
return true; |
|
|
|
if( GetPlotFileFormat() == PLOT_FORMAT::PDF && getOpenFileAfterPlot() ) |
|
|
|
wxLaunchDefaultApplication( schPlotter->GetLastOutputFilePath() ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -609,661 +399,6 @@ void DIALOG_PLOT_SCHEMATIC::setHpglPenWidth() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::createHPGLFiles( bool aPlotAll, bool aPlotFrameRef, |
|
|
|
RENDER_SETTINGS* aRenderSettings ) |
|
|
|
{ |
|
|
|
SCH_SCREEN* screen = m_parent->GetScreen(); |
|
|
|
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); |
|
|
|
|
|
|
|
/* When printing all pages, the printed page is not the current page. In complex hierarchies,
|
|
|
|
* we must update symbol references and other parameters in the given printed SCH_SCREEN, |
|
|
|
* according to the sheet path because in complex hierarchies a SCH_SCREEN (a drawing ) is |
|
|
|
* shared between many sheets and symbol references depend on the actual sheet path used. |
|
|
|
*/ |
|
|
|
SCH_SHEET_LIST sheetList; |
|
|
|
|
|
|
|
if( aPlotAll ) |
|
|
|
{ |
|
|
|
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true ); |
|
|
|
sheetList.SortByPageNumbers(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sheetList.push_back( m_parent->GetCurrentSheet() ); |
|
|
|
} |
|
|
|
|
|
|
|
REPORTER& reporter = m_MessagesBox->Reporter(); |
|
|
|
|
|
|
|
setHpglPenWidth(); |
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ ) |
|
|
|
{ |
|
|
|
m_parent->SetCurrentSheet( sheetList[i] ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
|
|
|
|
screen = m_parent->GetCurrentSheet().LastScreen(); |
|
|
|
|
|
|
|
if( !screen ) // LastScreen() may return NULL
|
|
|
|
screen = m_parent->GetScreen(); |
|
|
|
|
|
|
|
const PAGE_INFO& curPage = screen->GetPageSettings(); |
|
|
|
|
|
|
|
PAGE_INFO plotPage = curPage; |
|
|
|
|
|
|
|
// if plotting on a page size other than curPage
|
|
|
|
if( m_paperSizeOption->GetSelection() != PAGE_DEFAULT ) |
|
|
|
plotPage.SetType( plot_sheet_list( m_paperSizeOption->GetSelection() ) ); |
|
|
|
|
|
|
|
// Calculation of conversion scales.
|
|
|
|
double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils(); |
|
|
|
|
|
|
|
// Calculate offsets
|
|
|
|
wxPoint plotOffset; |
|
|
|
wxString msg; |
|
|
|
|
|
|
|
if( getPlotOriginAndUnits() == HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER ) |
|
|
|
{ |
|
|
|
plotOffset.x = plotPage.GetWidthIU( schIUScale.IU_PER_MILS ) / 2; |
|
|
|
plotOffset.y = -plotPage.GetHeightIU( schIUScale.IU_PER_MILS ) / 2; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); |
|
|
|
// The sub sheet can be in a sub_hierarchy, but we plot the file in the
|
|
|
|
// main project folder (or the folder specified by the caller),
|
|
|
|
// so replace separators to create a unique filename:
|
|
|
|
fname.Replace( "/", "_" ); |
|
|
|
fname.Replace( "\\", "_" ); |
|
|
|
wxString ext = HPGL_PLOTTER::GetDefaultFileExtension(); |
|
|
|
wxFileName plotFileName = createPlotFileName( fname, ext, &reporter ); |
|
|
|
|
|
|
|
if( !plotFileName.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
LOCALE_IO toggle; |
|
|
|
|
|
|
|
if( plotOneSheetHpgl( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings, |
|
|
|
plotOffset, plot_scale, aPlotFrameRef, getPlotOriginAndUnits() ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ACTION ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
} |
|
|
|
catch( IO_ERROR& e ) |
|
|
|
{ |
|
|
|
msg.Printf( wxT( "HPGL Plotter exception: %s"), e.What() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reporter.ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); |
|
|
|
|
|
|
|
m_parent->SetCurrentSheet( oldsheetpath ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetHpgl( const wxString& aFileName, |
|
|
|
SCH_SCREEN* aScreen, |
|
|
|
const PAGE_INFO& aPageInfo, |
|
|
|
RENDER_SETTINGS* aRenderSettings, |
|
|
|
const wxPoint& aPlot0ffset, |
|
|
|
double aScale, |
|
|
|
bool aPlotFrameRef, |
|
|
|
HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits ) |
|
|
|
{ |
|
|
|
HPGL_PLOTTER* plotter = new HPGL_PLOTTER(); |
|
|
|
// Currently, plot units are in decimil
|
|
|
|
|
|
|
|
plotter->SetPageSettings( aPageInfo ); |
|
|
|
plotter->SetRenderSettings( aRenderSettings ); |
|
|
|
plotter->RenderSettings()->LoadColors( getColorSettings() ); |
|
|
|
plotter->SetColorMode( getModeColor() ); |
|
|
|
plotter->SetViewport( aPlot0ffset, schIUScale.IU_PER_MILS/10, aScale, false ); |
|
|
|
|
|
|
|
// TODO this could be configurable
|
|
|
|
plotter->SetTargetChordLength( schIUScale.mmToIU( 0.6 ) ); |
|
|
|
|
|
|
|
switch( aOriginAndUnits ) |
|
|
|
{ |
|
|
|
case HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT: |
|
|
|
case HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER: |
|
|
|
default: |
|
|
|
plotter->SetUserCoords( false ); |
|
|
|
break; |
|
|
|
case HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE: |
|
|
|
plotter->SetUserCoords( true ); |
|
|
|
plotter->SetUserCoordsFit( false ); |
|
|
|
break; |
|
|
|
case HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT: |
|
|
|
plotter->SetUserCoords( true ); |
|
|
|
plotter->SetUserCoordsFit( true ); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// Init :
|
|
|
|
plotter->SetCreator( wxT( "Eeschema-HPGL" ) ); |
|
|
|
|
|
|
|
if( !plotter->OpenFile( aFileName ) ) |
|
|
|
{ |
|
|
|
delete plotter; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
LOCALE_IO toggle; |
|
|
|
|
|
|
|
// Pen num and pen speed are not initialized here.
|
|
|
|
// Default HPGL driver values are used
|
|
|
|
plotter->SetPenDiameter( m_HPGLPenSize ); |
|
|
|
plotter->StartPlot( m_parent->GetCurrentSheet().GetPageNumber() ); |
|
|
|
|
|
|
|
if( aPlotFrameRef ) |
|
|
|
{ |
|
|
|
wxString sheetName = m_parent->GetCurrentSheet().Last()->GetName(); |
|
|
|
wxString sheetPath = m_parent->GetCurrentSheet().PathHumanReadable(); |
|
|
|
|
|
|
|
PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo, |
|
|
|
aScreen->Schematic()->GetProperties(), aScreen->GetPageNumber(), |
|
|
|
aScreen->GetPageCount(), sheetName, sheetPath, aScreen->GetFileName(), |
|
|
|
COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
aScreen->Plot( plotter ); |
|
|
|
|
|
|
|
plotter->EndPlot(); |
|
|
|
delete plotter; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotDrawingSheet, |
|
|
|
RENDER_SETTINGS* aRenderSettings ) |
|
|
|
{ |
|
|
|
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
|
|
|
|
|
|
|
|
/* When printing all pages, the printed page is not the current page. In complex hierarchies,
|
|
|
|
* we must update symbol references and other parameters in the given printed SCH_SCREEN, |
|
|
|
* according to the sheet path because in complex hierarchies a SCH_SCREEN (a drawing ) is |
|
|
|
* shared between many sheets and symbol references depend on the actual sheet path used. |
|
|
|
*/ |
|
|
|
SCH_SHEET_LIST sheetList; |
|
|
|
|
|
|
|
if( aPlotAll ) |
|
|
|
{ |
|
|
|
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true ); |
|
|
|
sheetList.SortByPageNumbers(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sheetList.push_back( m_parent->GetCurrentSheet() ); |
|
|
|
} |
|
|
|
|
|
|
|
// Allocate the plotter and set the job level parameter
|
|
|
|
PDF_PLOTTER* plotter = new PDF_PLOTTER(); |
|
|
|
plotter->SetRenderSettings( aRenderSettings ); |
|
|
|
plotter->SetColorMode( getModeColor() ); |
|
|
|
plotter->SetCreator( wxT( "Eeschema-PDF" ) ); |
|
|
|
plotter->SetTitle( ExpandTextVars( m_parent->GetTitleBlock().GetTitle(), &m_parent->Prj() ) ); |
|
|
|
|
|
|
|
wxString msg; |
|
|
|
wxFileName plotFileName; |
|
|
|
REPORTER& reporter = m_MessagesBox->Reporter(); |
|
|
|
LOCALE_IO toggle; // Switch the locale to standard C
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ ) |
|
|
|
{ |
|
|
|
m_parent->SetCurrentSheet( sheetList[i] ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
SCH_SCREEN* screen = m_parent->GetCurrentSheet().LastScreen(); |
|
|
|
|
|
|
|
if( i == 0 ) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); |
|
|
|
|
|
|
|
// The sub sheet can be in a sub_hierarchy, but we plot the file in the main
|
|
|
|
// project folder (or the folder specified by the caller), so replace separators
|
|
|
|
// to create a unique filename:
|
|
|
|
fname.Replace( "/", "_" ); |
|
|
|
fname.Replace( "\\", "_" ); |
|
|
|
wxString ext = PDF_PLOTTER::GetDefaultFileExtension(); |
|
|
|
plotFileName = createPlotFileName( fname, ext, &reporter ); |
|
|
|
|
|
|
|
if( !plotFileName.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
if( !plotter->OpenFile( plotFileName.GetFullPath() ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
delete plotter; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Open the plotter and do the first page
|
|
|
|
setupPlotPagePDF( plotter, screen ); |
|
|
|
plotter->StartPlot( sheetList[i].GetPageNumber(), _("Root") ); |
|
|
|
} |
|
|
|
catch( const IO_ERROR& e ) |
|
|
|
{ |
|
|
|
// Cannot plot PDF file
|
|
|
|
msg.Printf( wxT( "PDF Plotter exception: %s" ), e.What() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
|
|
|
|
restoreEnvironment( plotter, oldsheetpath ); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/* For the following pages you need to close the (finished) page,
|
|
|
|
* reconfigure, and then start a new one */ |
|
|
|
plotter->ClosePage(); |
|
|
|
setupPlotPagePDF( plotter, screen ); |
|
|
|
plotter->StartPage( sheetList[i].GetPageNumber(), |
|
|
|
sheetList[i].Last()->GetFields()[SHEETNAME].GetShownText() ); |
|
|
|
} |
|
|
|
|
|
|
|
plotOneSheetPDF( plotter, screen, aPlotDrawingSheet ); |
|
|
|
} |
|
|
|
|
|
|
|
// Everything done, close the plot and restore the environment
|
|
|
|
msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ACTION ); |
|
|
|
reporter.ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); |
|
|
|
|
|
|
|
restoreEnvironment( plotter, oldsheetpath ); |
|
|
|
|
|
|
|
if( getOpenFileAfterPlot()) |
|
|
|
wxLaunchDefaultApplication( plotFileName.GetFullPath() ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::restoreEnvironment( PDF_PLOTTER* aPlotter, |
|
|
|
SCH_SHEET_PATH& aOldsheetpath ) |
|
|
|
{ |
|
|
|
aPlotter->EndPlot(); |
|
|
|
delete aPlotter; |
|
|
|
|
|
|
|
// Restore the previous sheet
|
|
|
|
m_parent->SetCurrentSheet( aOldsheetpath ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, |
|
|
|
bool aPlotDrawingSheet ) |
|
|
|
{ |
|
|
|
if( m_plotBackgroundColor->GetValue() && aPlotter->GetColorMode() ) |
|
|
|
{ |
|
|
|
aPlotter->SetColor( aPlotter->RenderSettings()->GetBackgroundColor() ); |
|
|
|
wxPoint end( aPlotter->PageSettings().GetWidthIU( schIUScale.IU_PER_MILS ), |
|
|
|
aPlotter->PageSettings().GetHeightIU( schIUScale.IU_PER_MILS ) ); |
|
|
|
aPlotter->Rect( wxPoint( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0 ); |
|
|
|
} |
|
|
|
|
|
|
|
if( aPlotDrawingSheet ) |
|
|
|
{ |
|
|
|
COLOR4D color = COLOR4D::BLACK; |
|
|
|
|
|
|
|
if( aPlotter->GetColorMode() ) |
|
|
|
color = aPlotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); |
|
|
|
|
|
|
|
wxString sheetName = m_parent->GetCurrentSheet().Last()->GetName(); |
|
|
|
wxString sheetPath = m_parent->GetCurrentSheet().PathHumanReadable(); |
|
|
|
|
|
|
|
PlotDrawingSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), |
|
|
|
m_parent->GetPageSettings(), aScreen->Schematic()->GetProperties(), |
|
|
|
aScreen->GetPageNumber(), aScreen->GetPageCount(), sheetName, sheetPath, |
|
|
|
aScreen->GetFileName(), color, aScreen->GetVirtualPageNumber() == 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
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
|
|
|
|
const 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 = std::min( scalex, scaley ); |
|
|
|
aPlotter->SetPageSettings( plotPage ); |
|
|
|
|
|
|
|
// Currently, plot units are in decimil
|
|
|
|
aPlotter->SetViewport( wxPoint( 0, 0 ), schIUScale.IU_PER_MILS/10, scale, false ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::createPSFiles( bool aPlotAll, bool aPlotFrameRef, |
|
|
|
RENDER_SETTINGS* aRenderSettings ) |
|
|
|
{ |
|
|
|
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
|
|
|
|
PAGE_INFO plotPage; // page size selected to plot
|
|
|
|
wxString msg; |
|
|
|
REPORTER& reporter = m_MessagesBox->Reporter(); |
|
|
|
|
|
|
|
/* When printing all pages, the printed page is not the current page.
|
|
|
|
* In complex hierarchies, we must update symbol references and other parameters in the |
|
|
|
* given printed SCH_SCREEN, accordant to the sheet path because in complex hierarchies |
|
|
|
* a SCH_SCREEN (a drawing ) is shared between many sheets and symbol references |
|
|
|
* depend on the actual sheet path used. |
|
|
|
*/ |
|
|
|
SCH_SHEET_LIST sheetList; |
|
|
|
|
|
|
|
if( aPlotAll ) |
|
|
|
{ |
|
|
|
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true ); |
|
|
|
sheetList.SortByPageNumbers(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sheetList.push_back( m_parent->GetCurrentSheet() ); |
|
|
|
} |
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ ) |
|
|
|
{ |
|
|
|
m_parent->SetCurrentSheet( sheetList[i] ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
|
|
|
|
SCH_SCREEN* screen = m_parent->GetCurrentSheet().LastScreen(); |
|
|
|
PAGE_INFO actualPage = screen->GetPageSettings(); |
|
|
|
|
|
|
|
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 = std::min( scalex, scaley ); |
|
|
|
wxPoint plot_offset; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); |
|
|
|
|
|
|
|
// The sub sheet can be in a sub_hierarchy, but we plot the file in the
|
|
|
|
// main project folder (or the folder specified by the caller),
|
|
|
|
// so replace separators to create a unique filename:
|
|
|
|
fname.Replace( "/", "_" ); |
|
|
|
fname.Replace ("\\", "_" ); |
|
|
|
wxString ext = PS_PLOTTER::GetDefaultFileExtension(); |
|
|
|
wxFileName plotFileName = createPlotFileName( fname, ext, &reporter ); |
|
|
|
|
|
|
|
if( !plotFileName.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
if( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage, |
|
|
|
plot_offset, scale, aPlotFrameRef ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ACTION ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// Error
|
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
catch( IO_ERROR& e ) |
|
|
|
{ |
|
|
|
msg.Printf( wxT( "PS Plotter exception: %s"), e.What() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reporter.ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); |
|
|
|
|
|
|
|
m_parent->SetCurrentSheet( oldsheetpath ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName, |
|
|
|
SCH_SCREEN* aScreen, |
|
|
|
RENDER_SETTINGS* aRenderSettings, |
|
|
|
const PAGE_INFO& aPageInfo, |
|
|
|
const wxPoint& aPlot0ffset, |
|
|
|
double aScale, |
|
|
|
bool aPlotFrameRef ) |
|
|
|
{ |
|
|
|
PS_PLOTTER* plotter = new PS_PLOTTER(); |
|
|
|
plotter->SetRenderSettings( aRenderSettings ); |
|
|
|
plotter->SetPageSettings( aPageInfo ); |
|
|
|
plotter->SetColorMode( getModeColor() ); |
|
|
|
|
|
|
|
// Currently, plot units are in decimil
|
|
|
|
plotter->SetViewport( aPlot0ffset, schIUScale.IU_PER_MILS/10, aScale, false ); |
|
|
|
|
|
|
|
// Init :
|
|
|
|
plotter->SetCreator( wxT( "Eeschema-PS" ) ); |
|
|
|
|
|
|
|
if( ! plotter->OpenFile( aFileName ) ) |
|
|
|
{ |
|
|
|
delete plotter; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
LOCALE_IO toggle; // Switch the locale to standard C
|
|
|
|
|
|
|
|
plotter->StartPlot( m_parent->GetCurrentSheet().GetPageNumber() ); |
|
|
|
|
|
|
|
if( m_plotBackgroundColor->GetValue() && plotter->GetColorMode() ) |
|
|
|
{ |
|
|
|
plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); |
|
|
|
wxPoint end( plotter->PageSettings().GetWidthIU( schIUScale.IU_PER_MILS ), |
|
|
|
plotter->PageSettings().GetHeightIU( schIUScale.IU_PER_MILS ) ); |
|
|
|
plotter->Rect( wxPoint( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0 ); |
|
|
|
} |
|
|
|
|
|
|
|
if( aPlotFrameRef ) |
|
|
|
{ |
|
|
|
wxString sheetName = m_parent->GetCurrentSheet().Last()->GetName(); |
|
|
|
wxString sheetPath = m_parent->GetCurrentSheet().PathHumanReadable(); |
|
|
|
COLOR4D color = plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); |
|
|
|
|
|
|
|
PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), |
|
|
|
aPageInfo, aScreen->Schematic()->GetProperties(), aScreen->GetPageNumber(), |
|
|
|
aScreen->GetPageCount(), sheetName, sheetPath, aScreen->GetFileName(), |
|
|
|
plotter->GetColorMode() ? color : COLOR4D::BLACK, |
|
|
|
aScreen->GetVirtualPageNumber() == 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
aScreen->Plot( plotter ); |
|
|
|
|
|
|
|
plotter->EndPlot(); |
|
|
|
delete plotter; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PLOT_SCHEMATIC::createSVGFiles( bool aPrintAll, bool aPrintFrameRef, |
|
|
|
RENDER_SETTINGS* aRenderSettings ) |
|
|
|
{ |
|
|
|
wxString msg; |
|
|
|
REPORTER& reporter = m_MessagesBox->Reporter(); |
|
|
|
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); |
|
|
|
SCH_SHEET_LIST sheetList; |
|
|
|
|
|
|
|
if( aPrintAll ) |
|
|
|
{ |
|
|
|
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true ); |
|
|
|
sheetList.SortByPageNumbers(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
sheetList.push_back( m_parent->GetCurrentSheet() ); |
|
|
|
} |
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ ) |
|
|
|
{ |
|
|
|
SCH_SCREEN* screen; |
|
|
|
m_parent->SetCurrentSheet( sheetList[i] ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
screen = m_parent->GetCurrentSheet().LastScreen(); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); |
|
|
|
|
|
|
|
// The sub sheet can be in a sub_hierarchy, but we plot the file in the
|
|
|
|
// main project folder (or the folder specified by the caller),
|
|
|
|
// so replace separators to create a unique filename:
|
|
|
|
fname.Replace( "/", "_" ); |
|
|
|
fname.Replace( "\\", "_" ); |
|
|
|
wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); |
|
|
|
wxFileName plotFileName = createPlotFileName( fname, ext, &reporter ); |
|
|
|
|
|
|
|
if( !plotFileName.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings, |
|
|
|
getModeColor() ? false : true, aPrintFrameRef ); |
|
|
|
|
|
|
|
if( !success ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
msg.Printf( _( "Plotted to '%s'." ), plotFileName.GetFullPath() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ACTION ); |
|
|
|
} |
|
|
|
} |
|
|
|
catch( const IO_ERROR& e ) |
|
|
|
{ |
|
|
|
// Cannot plot SVG file
|
|
|
|
msg.Printf( wxT( "SVG Plotter exception: %s" ), e.What() ); |
|
|
|
reporter.Report( msg, RPT_SEVERITY_ERROR ); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reporter.ReportTail( _( "Done" ), RPT_SEVERITY_INFO ); |
|
|
|
|
|
|
|
m_parent->SetCurrentSheet( oldsheetpath ); |
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences(); |
|
|
|
m_parent->SetSheetNumberAndCount(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( const wxString& aFileName, |
|
|
|
SCH_SCREEN* aScreen, |
|
|
|
RENDER_SETTINGS* aRenderSettings, |
|
|
|
bool aPlotBlackAndWhite, |
|
|
|
bool aPlotFrameRef ) |
|
|
|
{ |
|
|
|
const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); |
|
|
|
|
|
|
|
SVG_PLOTTER* plotter = new SVG_PLOTTER(); |
|
|
|
plotter->SetRenderSettings( aRenderSettings ); |
|
|
|
plotter->SetPageSettings( pageInfo ); |
|
|
|
plotter->SetColorMode( aPlotBlackAndWhite ? false : true ); |
|
|
|
wxPoint plot_offset; |
|
|
|
double scale = 1.0; |
|
|
|
|
|
|
|
// Currently, plot units are in decimil
|
|
|
|
plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS/10, scale, false ); |
|
|
|
|
|
|
|
// Init :
|
|
|
|
plotter->SetCreator( wxT( "Eeschema-SVG" ) ); |
|
|
|
|
|
|
|
if( ! plotter->OpenFile( aFileName ) ) |
|
|
|
{ |
|
|
|
delete plotter; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
LOCALE_IO toggle; |
|
|
|
|
|
|
|
plotter->StartPlot( m_parent->GetCurrentSheet().GetPageNumber() ); |
|
|
|
|
|
|
|
if( m_plotBackgroundColor->GetValue() && plotter->GetColorMode() ) |
|
|
|
{ |
|
|
|
plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); |
|
|
|
wxPoint end( plotter->PageSettings().GetWidthIU( schIUScale.IU_PER_MILS ), |
|
|
|
plotter->PageSettings().GetHeightIU( schIUScale.IU_PER_MILS ) ); |
|
|
|
plotter->Rect( wxPoint( 0, 0 ), end, FILL_T::FILLED_SHAPE, 1.0 ); |
|
|
|
} |
|
|
|
|
|
|
|
if( aPlotFrameRef ) |
|
|
|
{ |
|
|
|
wxString sheetName = m_parent->GetCurrentSheet().Last()->GetName(); |
|
|
|
wxString sheetPath = m_parent->GetCurrentSheet().PathHumanReadable(); |
|
|
|
COLOR4D color = plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); |
|
|
|
|
|
|
|
PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), |
|
|
|
pageInfo, aScreen->Schematic()->GetProperties(), aScreen->GetPageNumber(), |
|
|
|
aScreen->GetPageCount(), sheetName, sheetPath, aScreen->GetFileName(), |
|
|
|
plotter->GetColorMode() ? color : COLOR4D::BLACK, |
|
|
|
aScreen->GetVirtualPageNumber() == 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
aScreen->Plot( plotter ); |
|
|
|
|
|
|
|
plotter->EndPlot(); |
|
|
|
delete plotter; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wxString DIALOG_PLOT_SCHEMATIC::getOutputPath() |
|
|
|
{ |
|
|
|
wxString msg; |
|
|
|
|