From 57d4347f000d7634af6555d7fd670a984136a654 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 17 May 2021 17:00:30 -0400 Subject: [PATCH] Eeschema: move schematic plot dialog code into dialog_plog_schematic.cpp. This makes it easier to find all of the dialog code, has less files to compile, and makes it easier to see the redundant code that could be refactored. --- eeschema/CMakeLists.txt | 5 - eeschema/dialogs/dialog_plot_schematic.cpp | 823 ++++++++++++++++++++- eeschema/dialogs/dialog_plot_schematic.h | 55 +- eeschema/plotters/plot_schematic_DXF.cpp | 166 ----- eeschema/plotters/plot_schematic_HPGL.cpp | 257 ------- eeschema/plotters/plot_schematic_PDF.cpp | 217 ------ eeschema/plotters/plot_schematic_PS.cpp | 193 ----- eeschema/plotters/plot_schematic_SVG.cpp | 167 ----- 8 files changed, 844 insertions(+), 1039 deletions(-) delete mode 100644 eeschema/plotters/plot_schematic_DXF.cpp delete mode 100644 eeschema/plotters/plot_schematic_HPGL.cpp delete mode 100644 eeschema/plotters/plot_schematic_PDF.cpp delete mode 100644 eeschema/plotters/plot_schematic_PS.cpp delete mode 100644 eeschema/plotters/plot_schematic_SVG.cpp diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 9a271d4bdf..1684c35a84 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -192,11 +192,6 @@ set( EESCHEMA_SRCS menubar.cpp pin_number.cpp pin_type.cpp - plotters/plot_schematic_DXF.cpp - plotters/plot_schematic_HPGL.cpp - plotters/plot_schematic_PDF.cpp - plotters/plot_schematic_PS.cpp - plotters/plot_schematic_SVG.cpp sch_draw_panel.cpp project_rescue.cpp sch_base_frame.cpp diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index 9166345a5e..b41f705663 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -4,7 +4,7 @@ * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 1992-2010 Lorenzo Marcantonio * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,11 +30,17 @@ #include #include #include +#include #include +#include +#include #include #include + +#include #include #include +#include #include #include @@ -44,6 +50,43 @@ 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" ); + } +} + + DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) : DIALOG_PLOT_SCHEMATIC_BASE( parent ), m_parent( parent ), @@ -324,17 +367,17 @@ COLOR_SETTINGS* DIALOG_PLOT_SCHEMATIC::getColorSettings() void DIALOG_PLOT_SCHEMATIC::OnPlotCurrent( wxCommandEvent& event ) { - PlotSchematic( false ); + plotSchematic( false ); } void DIALOG_PLOT_SCHEMATIC::OnPlotAll( wxCommandEvent& event ) { - PlotSchematic( true ); + plotSchematic( true ); } -void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll ) +void DIALOG_PLOT_SCHEMATIC::plotSchematic( bool aPlotAll ) { KIGFX::SCH_RENDER_SETTINGS renderSettings( *m_parent->GetRenderSettings() ); @@ -347,7 +390,7 @@ void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll ) createPSFile( aPlotAll, getPlotDrawingSheet(), &renderSettings ); break; case PLOT_FORMAT::DXF: - CreateDXFFile( aPlotAll, getPlotDrawingSheet(), &renderSettings ); + createDxfFile( aPlotAll, getPlotDrawingSheet(), &renderSettings ); break; case PLOT_FORMAT::PDF: createPDFFile( aPlotAll, getPlotDrawingSheet(), &renderSettings ); @@ -386,3 +429,773 @@ wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( const wxString& aPlotFileN fn.SetPath( outputDir.GetFullPath() ); return fn; } + + +void DIALOG_PLOT_SCHEMATIC::createDxfFile( 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 setup references and others parameters + * in the printed SCH_SCREEN + * because in complex hierarchies a SCH_SCREEN (a schematic drawings) + * is shared between many sheets + */ + 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( plotOneSheetDxf( plotFileName.GetFullPath(), screen, aRenderSettings, + plot_offset, 1.0, aPlotDrawingSheet ) ) + { + msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ACTION ); + } + else // Error + { + msg.Printf( _( "Unable to create file \"%s\".\n" ), 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; + } + } + + schframe->SetCurrentSheet( oldsheetpath ); + schframe->GetCurrentSheet().UpdateAllScreenReferences(); + schframe->SetSheetNumberAndCount(); +} + + +bool DIALOG_PLOT_SCHEMATIC::plotOneSheetDxf( const wxString& aFileName, + SCH_SCREEN* aScreen, + RENDER_SETTINGS* aRenderSettings, + wxPoint aPlotOffset, + double aScale, + bool aPlotFrameRef ) +{ + aRenderSettings->LoadColors( getColorSettings() ); + aRenderSettings->SetDefaultPenWidth( 0 ); + + const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); + DXF_PLOTTER* plotter = new DXF_PLOTTER(); + + plotter->SetRenderSettings( aRenderSettings ); + plotter->SetPageSettings( pageInfo ); + plotter->SetColorMode( getModeColor() ); + + // Currently, plot units are in decimil + plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false ); + + // Init : + plotter->SetCreator( wxT( "Eeschema-DXF" ) ); + + if( ! plotter->OpenFile( aFileName ) ) + { + delete plotter; + return false; + } + + LOCALE_IO toggle; + + plotter->StartPlot(); + + if( aPlotFrameRef ) + { + PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), pageInfo, + aScreen->GetPageNumber(), aScreen->GetPageCount(), + m_parent->GetScreenDesc(), aScreen->GetFileName(), + plotter->GetColorMode() ? + plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : + COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); + } + + aScreen->Plot( plotter ); + + // finish + plotter->EndPlot(); + delete plotter; + + return true; +} + + +void DIALOG_PLOT_SCHEMATIC::setHpglPenWidth() +{ + m_HPGLPenSize = m_penWidth.GetValue(); + + if( m_HPGLPenSize > Millimeter2iu( 2 ) ) + m_HPGLPenSize = Millimeter2iu( 2 ); + + if( m_HPGLPenSize < Millimeter2iu( 0.01 ) ) + m_HPGLPenSize = Millimeter2iu( 0.01 ); +} + + +void DIALOG_PLOT_SCHEMATIC::createHPGLFile( 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 setup references and other parameters + * in the printed SCH_SCREEN + * because in complex hierarchies a SCH_SCREEN (a schematic drawings) + * is shared between many sheets + */ + 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() / 2; + plotOffset.y = -plotPage.GetHeightIU() / 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 ); + + LOCALE_IO toggle; + + if( plotOneSheetHpgl( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings, + plotOffset, plot_scale, aPlotFrameRef, getPlotOriginAndUnits() ) ) + { + msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ACTION ); + } + else + { + msg.Printf( _( "Unable to create file \"%s\".\n" ), 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 ); + } + + } + + 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, + 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, IU_PER_MILS/10, aScale, false ); + + // TODO this could be configurable + plotter->SetTargetChordLength( Millimeter2iu( 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(); + + if( aPlotFrameRef ) + { + PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo, + aScreen->GetPageNumber(), aScreen->GetPageCount(), + m_parent->GetScreenDesc(), 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 component references and others + * 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 component 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( m_parent->GetTitleBlock().GetTitle() ); + + 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( !plotter->OpenFile( plotFileName.GetFullPath() ) ) + { + msg.Printf( _( "Unable to create file \"%s\".\n" ), + plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ERROR ); + delete plotter; + return; + } + + // Open the plotter and do the first page + setupPlotPagePDF( plotter, screen ); + plotter->StartPlot(); + } + 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(); + } + + plotOneSheetPDF( plotter, screen, aPlotDrawingSheet ); + } + + // Everything done, close the plot and restore the environment + msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ACTION ); + + restoreEnvironment( plotter, oldsheetpath ); +} + + +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->SetColor( aPlotter->RenderSettings()->GetBackgroundColor() ); + wxPoint end( aPlotter->PageSettings().GetWidthIU(), + aPlotter->PageSettings().GetHeightIU() ); + aPlotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); + } + + if( aPlotDrawingSheet ) + { + COLOR4D color = COLOR4D::BLACK; + + if( aPlotter->GetColorMode() ) + color = aPlotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); + + PlotDrawingSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), + m_parent->GetPageSettings(), aScreen->GetPageNumber(), + aScreen->GetPageCount(), m_parent->GetScreenDesc(), + 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 ), IU_PER_MILS/10, scale, false ); +} + + +void DIALOG_PLOT_SCHEMATIC::createPSFile( 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 + + /* When printing all pages, the printed page is not the current page. + * In complex hierarchies, we must update component references + * and others 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 component 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; + + wxString msg; + REPORTER& reporter = m_MessagesBox->Reporter(); + + 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( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage, + plot_offset, scale, aPlotFrameRef ) ) + { + msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ACTION ); + } + else + { + // Error + msg.Printf( _( "Unable to create file \"%s\".\n" ), 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 ); + } + } + + 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, + 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, 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(); + + if( m_plotBackgroundColor->GetValue() ) + { + plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); + wxPoint end( plotter->PageSettings().GetWidthIU(), + plotter->PageSettings().GetHeightIU() ); + plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); + } + + if( aPlotFrameRef ) + { + PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), + aPageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(), + m_parent->GetScreenDesc(), aScreen->GetFileName(), + plotter->GetColorMode() ? + plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : + COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); + } + + aScreen->Plot( plotter ); + + plotter->EndPlot(); + delete plotter; + + return true; +} + + +void DIALOG_PLOT_SCHEMATIC::createSVGFile( 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 ); + + bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings, + getModeColor() ? false : true, aPrintFrameRef ); + + if( !success ) + { + msg.Printf( _( "Cannot create file \"%s\".\n" ), plotFileName.GetFullPath() ); + reporter.Report( msg, RPT_SEVERITY_ERROR ); + } + else + { + msg.Printf( _( "Plot: \"%s\" OK.\n" ), 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; + } + } + + 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, 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(); + + if( m_plotBackgroundColor->GetValue() ) + { + plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); + wxPoint end( plotter->PageSettings().GetWidthIU(), + plotter->PageSettings().GetHeightIU() ); + plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); + } + + if( aPlotFrameRef ) + { + PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), + pageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(), + m_parent->GetScreenDesc(), aScreen->GetFileName(), + plotter->GetColorMode() ? + plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : + COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); + } + + aScreen->Plot( plotter ); + + plotter->EndPlot(); + delete plotter; + + return true; +} diff --git a/eeschema/dialogs/dialog_plot_schematic.h b/eeschema/dialogs/dialog_plot_schematic.h index 4196351eb7..95d276d1eb 100644 --- a/eeschema/dialogs/dialog_plot_schematic.h +++ b/eeschema/dialogs/dialog_plot_schematic.h @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 1992-2010 Lorenzo Marcantonio - * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 2011 Wayne Stambaugh * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -32,10 +32,7 @@ #define __DIALOG_PLOT_SCHEMATIC__ #include -#include -#include #include -#include #include enum PageFormatReq @@ -54,11 +51,15 @@ enum class HPGL_PLOT_ORIGIN_AND_UNITS }; class PDF_PLOTTER; +class SCH_REPORTER; +class SCH_EDIT_FRAME; +class SCH_SCREEN; +class SCH_SHEET_PATH; + class DIALOG_PLOT_SCHEMATIC : public DIALOG_PLOT_SCHEMATIC_BASE { public: - // / Constructors DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ); /** @@ -77,11 +78,9 @@ private: // common void getPlotOptions( RENDER_SETTINGS* aSettings ); - bool getModeColor() - { return m_ModeColorOption->GetSelection() == 0; } + bool getModeColor() { return m_ModeColorOption->GetSelection() == 0; } - void setModeColor( bool aColor ) - { m_ModeColorOption->SetSelection( aColor ? 0 : 1 ); } + void setModeColor( bool aColor ) { m_ModeColorOption->SetSelection( aColor ? 0 : 1 ); } COLOR_SETTINGS* getColorSettings(); @@ -95,42 +94,40 @@ private: bool getPlotDrawingSheet() { return m_plotDrawingSheet->GetValue(); } void setPlotDrawingSheet( bool aPlot) { m_plotDrawingSheet->SetValue( aPlot ); } - void PlotSchematic( bool aPlotAll ); + void plotSchematic( bool aPlotAll ); // PDF - void createPDFFile( bool aPlotAll, bool aPlotDrawingSheet, - RENDER_SETTINGS* aRenderSettings ); - void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotDrawingSheet); - void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen ); + void createPDFFile( bool aPlotAll, bool aPlotDrawingSheet, RENDER_SETTINGS* aRenderSettings ); + void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotDrawingSheet); + void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen ); /** * Everything done, close the plot and restore the environment * @param aPlotter the plotter to close and destroy * @param aOldsheetpath the stored old sheet path for the current sheet before the plot started */ - void restoreEnvironment( PDF_PLOTTER* aPlotter, SCH_SHEET_PATH& aOldsheetpath ); + void restoreEnvironment( PDF_PLOTTER* aPlotter, SCH_SHEET_PATH& aOldsheetpath ); // DXF - void CreateDXFFile( bool aPlotAll, bool aPlotDrawingSheet, - RENDER_SETTINGS* aRenderSettings ); - bool PlotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen, - RENDER_SETTINGS* aRenderSettings, wxPoint aPlotOffset, double aScale, - bool aPlotFrameRef ); + void createDxfFile( bool aPlotAll, bool aPlotDrawingSheet, RENDER_SETTINGS* aRenderSettings ); + bool plotOneSheetDxf( const wxString& aFileName, SCH_SCREEN* aScreen, + RENDER_SETTINGS* aRenderSettings, wxPoint aPlotOffset, double aScale, + bool aPlotFrameRef ); - // HPGL - HPGL_PLOT_ORIGIN_AND_UNITS GetPlotOriginAndUnits() + // HPGLGetPlotOriginAndUnits + HPGL_PLOT_ORIGIN_AND_UNITS getPlotOriginAndUnits() { switch( m_plotOriginOpt->GetSelection() ) { case 0: default: return HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT; - case 1: return HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER; - case 2: return HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE; - case 3: return HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT; + case 1: return HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER; + case 2: return HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE; + case 3: return HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT; } } - void SetPlotOriginAndUnits( HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits ) + void setPlotOriginAndUnits( HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits ) { switch( aOriginAndUnits ) { @@ -154,8 +151,8 @@ private: } void createHPGLFile( bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS* aRenderSettings ); - void SetHPGLPenWidth(); - bool Plot_1_Page_HPGL( const wxString& aFileName, SCH_SCREEN* aScreen, + void setHpglPenWidth(); + bool plotOneSheetHpgl( const wxString& aFileName, SCH_SCREEN* aScreen, const PAGE_INFO& aPageInfo, RENDER_SETTINGS* aRenderSettings, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef, HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits ); @@ -182,7 +179,7 @@ private: * @throw IO_ERROR on file I/O errors. */ wxFileName createPlotFileName( const wxString& aPlotFileName, const wxString& aExtension, - REPORTER* aReporter = NULL ); + REPORTER* aReporter = nullptr ); SCH_EDIT_FRAME* m_parent; bool m_configChanged; // true if a project config param has changed diff --git a/eeschema/plotters/plot_schematic_DXF.cpp b/eeschema/plotters/plot_schematic_DXF.cpp deleted file mode 100644 index 2a3f087c4e..0000000000 --- a/eeschema/plotters/plot_schematic_DXF.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/** @file plot_schematic_DXF.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 1992-2010 Lorenzo Marcantonio - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( 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 setup references and others parameters - * in the printed SCH_SCREEN - * because in complex hierarchies a SCH_SCREEN (a schematic drawings) - * is shared between many sheets - */ - 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( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, aRenderSettings, - plot_offset, 1.0, aPlotDrawingSheet ) ) - { - msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ACTION ); - } - else // Error - { - msg.Printf( _( "Unable to create file \"%s\".\n" ), 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; - } - } - - schframe->SetCurrentSheet( oldsheetpath ); - schframe->GetCurrentSheet().UpdateAllScreenReferences(); - schframe->SetSheetNumberAndCount(); -} - - -bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName, - SCH_SCREEN* aScreen, - RENDER_SETTINGS* aRenderSettings, - wxPoint aPlotOffset, - double aScale, - bool aPlotFrameRef ) -{ - aRenderSettings->LoadColors( getColorSettings() ); - aRenderSettings->SetDefaultPenWidth( 0 ); - - const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); - DXF_PLOTTER* plotter = new DXF_PLOTTER(); - - plotter->SetRenderSettings( aRenderSettings ); - plotter->SetPageSettings( pageInfo ); - plotter->SetColorMode( getModeColor() ); - // Currently, plot units are in decimil - plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false ); - - // Init : - plotter->SetCreator( wxT( "Eeschema-DXF" ) ); - - if( ! plotter->OpenFile( aFileName ) ) - { - delete plotter; - return false; - } - - LOCALE_IO toggle; - - plotter->StartPlot(); - - if( aPlotFrameRef ) - { - PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), pageInfo, - aScreen->GetPageNumber(), aScreen->GetPageCount(), - m_parent->GetScreenDesc(), aScreen->GetFileName(), - plotter->GetColorMode() ? - plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : - COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); - } - - aScreen->Plot( plotter ); - - // finish - plotter->EndPlot(); - delete plotter; - - return true; -} diff --git a/eeschema/plotters/plot_schematic_HPGL.cpp b/eeschema/plotters/plot_schematic_HPGL.cpp deleted file mode 100644 index 68b836887c..0000000000 --- a/eeschema/plotters/plot_schematic_HPGL.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/** @file plot_schematic_HPGL.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 1992-2010 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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" ); - } -} - - -void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth() -{ - m_HPGLPenSize = m_penWidth.GetValue(); - - if( m_HPGLPenSize > Millimeter2iu( 2 ) ) - m_HPGLPenSize = Millimeter2iu( 2 ); - - if( m_HPGLPenSize < Millimeter2iu( 0.01 ) ) - m_HPGLPenSize = Millimeter2iu( 0.01 ); -} - - -void DIALOG_PLOT_SCHEMATIC::createHPGLFile( 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 setup references and other parameters - * in the printed SCH_SCREEN - * because in complex hierarchies a SCH_SCREEN (a schematic drawings) - * is shared between many sheets - */ - 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() / 2; - plotOffset.y = -plotPage.GetHeightIU() / 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 ); - - LOCALE_IO toggle; - - if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings, - plotOffset, plot_scale, aPlotFrameRef, GetPlotOriginAndUnits() ) ) - { - msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ACTION ); - } - else - { - msg.Printf( _( "Unable to create file \"%s\".\n" ), 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 ); - } - - } - - m_parent->SetCurrentSheet( oldsheetpath ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); -} - - -bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName, - SCH_SCREEN* aScreen, - const PAGE_INFO& aPageInfo, - RENDER_SETTINGS* aRenderSettings, - 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, IU_PER_MILS/10, aScale, false ); - - // TODO this could be configurable - plotter->SetTargetChordLength( Millimeter2iu( 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(); - - if( aPlotFrameRef ) - { - PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo, - aScreen->GetPageNumber(), aScreen->GetPageCount(), - m_parent->GetScreenDesc(), aScreen->GetFileName(), COLOR4D::BLACK, - aScreen->GetVirtualPageNumber() == 1 ); - } - - aScreen->Plot( plotter ); - - plotter->EndPlot(); - delete plotter; - - return true; -} diff --git a/eeschema/plotters/plot_schematic_PDF.cpp b/eeschema/plotters/plot_schematic_PDF.cpp deleted file mode 100644 index 2ed11079ee..0000000000 --- a/eeschema/plotters/plot_schematic_PDF.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/** @file plot_schematic_PDF.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 1992-2010 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -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 component references and others - * 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 component 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( m_parent->GetTitleBlock().GetTitle() ); - - 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( !plotter->OpenFile( plotFileName.GetFullPath() ) ) - { - msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ERROR ); - delete plotter; - return; - } - - // Open the plotter and do the first page - setupPlotPagePDF( plotter, screen ); - plotter->StartPlot(); - } - 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(); - } - - plotOneSheetPDF( plotter, screen, aPlotDrawingSheet ); - } - - // Everything done, close the plot and restore the environment - msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ACTION ); - - restoreEnvironment( plotter, oldsheetpath ); -} - - -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->SetColor( aPlotter->RenderSettings()->GetBackgroundColor() ); - wxPoint end( aPlotter->PageSettings().GetWidthIU(), - aPlotter->PageSettings().GetHeightIU() ); - aPlotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); - } - - if( aPlotDrawingSheet ) - { - COLOR4D color = COLOR4D::BLACK; - - if( aPlotter->GetColorMode() ) - color = aPlotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ); - - PlotDrawingSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), - m_parent->GetPageSettings(), aScreen->GetPageNumber(), - aScreen->GetPageCount(), m_parent->GetScreenDesc(), - 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 ), IU_PER_MILS/10, scale, false ); -} - diff --git a/eeschema/plotters/plot_schematic_PS.cpp b/eeschema/plotters/plot_schematic_PS.cpp deleted file mode 100644 index 9ad3009964..0000000000 --- a/eeschema/plotters/plot_schematic_PS.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/** @file plot_schematic_PS.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -void DIALOG_PLOT_SCHEMATIC::createPSFile( 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 - - /* When printing all pages, the printed page is not the current page. - * In complex hierarchies, we must update component references - * and others 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 component 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; - - wxString msg; - REPORTER& reporter = m_MessagesBox->Reporter(); - - 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( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage, - plot_offset, scale, aPlotFrameRef ) ) - { - msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ACTION ); - } - else - { - // Error - msg.Printf( _( "Unable to create file \"%s\".\n" ), 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 ); - } - } - - 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, - 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, 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(); - - if( m_plotBackgroundColor->GetValue() ) - { - plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); - wxPoint end( plotter->PageSettings().GetWidthIU(), - plotter->PageSettings().GetHeightIU() ); - plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); - } - - if( aPlotFrameRef ) - { - PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), - aPageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(), - m_parent->GetScreenDesc(), aScreen->GetFileName(), - plotter->GetColorMode() ? - plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : - COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); - } - - aScreen->Plot( plotter ); - - plotter->EndPlot(); - delete plotter; - - return true; -} diff --git a/eeschema/plotters/plot_schematic_SVG.cpp b/eeschema/plotters/plot_schematic_SVG.cpp deleted file mode 100644 index fa802a1856..0000000000 --- a/eeschema/plotters/plot_schematic_SVG.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file plot_schematic_SVG.cpp - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "sch_painter.h" -#include - - -void DIALOG_PLOT_SCHEMATIC::createSVGFile( 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 ); - - bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings, - getModeColor() ? false : true, aPrintFrameRef ); - - if( !success ) - { - msg.Printf( _( "Cannot create file \"%s\".\n" ), plotFileName.GetFullPath() ); - reporter.Report( msg, RPT_SEVERITY_ERROR ); - } - else - { - msg.Printf( _( "Plot: \"%s\" OK.\n" ), 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; - } - } - - 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, 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(); - - if( m_plotBackgroundColor->GetValue() ) - { - plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); - wxPoint end( plotter->PageSettings().GetWidthIU(), - plotter->PageSettings().GetHeightIU() ); - plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); - } - - if( aPlotFrameRef ) - { - PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), - pageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(), - m_parent->GetScreenDesc(), aScreen->GetFileName(), - plotter->GetColorMode() ? - plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) : - COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); - } - - aScreen->Plot( plotter ); - - plotter->EndPlot(); - delete plotter; - - return true; -}