2018-09-19 13:06:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-02-12 10:44:34 +00:00
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-09-19 13:06:29 +00:00
|
|
|
* Copyright (C) 2018 CERN
|
|
|
|
* Author: Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 <board_printout.h>
|
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <gal/gal_print.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2023-09-07 00:23:19 +00:00
|
|
|
#include <gal/painter.h>
|
2018-10-05 14:41:17 +00:00
|
|
|
#include <pcbplot.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/app_settings.h>
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2018-10-05 14:41:17 +00:00
|
|
|
|
|
|
|
BOARD_PRINTOUT_SETTINGS::BOARD_PRINTOUT_SETTINGS( const PAGE_INFO& aPageInfo )
|
|
|
|
: PRINTOUT_SETTINGS( aPageInfo )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
m_LayerSet.set();
|
|
|
|
m_Mirror = false;
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void BOARD_PRINTOUT_SETTINGS::Load( APP_SETTINGS_BASE* aConfig )
|
2018-10-05 14:41:17 +00:00
|
|
|
{
|
|
|
|
PRINTOUT_SETTINGS::Load( aConfig );
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
m_LayerSet.reset();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
for( int layer : aConfig->m_Printing.layers )
|
2020-11-16 11:16:44 +00:00
|
|
|
m_LayerSet.set( layer, true );
|
2018-10-05 14:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void BOARD_PRINTOUT_SETTINGS::Save( APP_SETTINGS_BASE* aConfig )
|
2018-10-05 14:41:17 +00:00
|
|
|
{
|
|
|
|
PRINTOUT_SETTINGS::Save( aConfig );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
aConfig->m_Printing.layers.clear();
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
for( unsigned layer = 0; layer < m_LayerSet.size(); ++layer )
|
|
|
|
if( m_LayerSet.test( layer ) )
|
2020-01-13 01:44:19 +00:00
|
|
|
aConfig->m_Printing.layers.push_back( layer );
|
2018-10-05 14:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-06 16:51:46 +00:00
|
|
|
BOARD_PRINTOUT::BOARD_PRINTOUT( const BOARD_PRINTOUT_SETTINGS& aParams,
|
2020-08-25 13:07:18 +00:00
|
|
|
const KIGFX::VIEW* aView, const wxString& aTitle ) :
|
|
|
|
wxPrintout( aTitle ),
|
|
|
|
m_settings( aParams )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
|
|
|
m_view = aView;
|
2022-02-12 10:44:34 +00:00
|
|
|
m_gerbviewPrint = false;
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT::GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo )
|
|
|
|
{
|
|
|
|
*minPage = 1;
|
|
|
|
*selPageFrom = 1;
|
|
|
|
|
2018-10-05 14:41:17 +00:00
|
|
|
*maxPage = m_settings.m_pageCount;
|
|
|
|
*selPageTo = m_settings.m_pageCount;
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT::DrawPage( const wxString& aLayerName, int aPageNum, int aPageCount )
|
|
|
|
{
|
2022-02-12 10:44:34 +00:00
|
|
|
wxDC* dc = GetDC();
|
2018-09-19 13:06:29 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS options;
|
2022-02-12 10:44:34 +00:00
|
|
|
std::unique_ptr<KIGFX::GAL_PRINT> galPrint = KIGFX::GAL_PRINT::Create( options, dc );
|
|
|
|
KIGFX::GAL* gal = galPrint->GetGAL();
|
|
|
|
KIGFX::PRINT_CONTEXT* printCtx = galPrint->GetPrintCtx();
|
|
|
|
std::unique_ptr<KIGFX::PAINTER> painter = getPainter( gal );
|
2018-09-19 13:06:29 +00:00
|
|
|
std::unique_ptr<KIGFX::VIEW> view( m_view->DataReference() );
|
|
|
|
|
2018-10-06 19:34:51 +00:00
|
|
|
// Target paper size
|
2021-06-25 09:35:17 +00:00
|
|
|
wxRect pageSizePx = GetLogicalPageRect();
|
2018-10-06 19:34:51 +00:00
|
|
|
const VECTOR2D pageSizeIn( (double) pageSizePx.width / dc->GetPPI().x,
|
2021-06-25 09:35:17 +00:00
|
|
|
(double) pageSizePx.height / dc->GetPPI().y );
|
2018-10-06 19:34:51 +00:00
|
|
|
const VECTOR2D pageSizeIU( milsToIU( pageSizeIn.x * 1000 ), milsToIU( pageSizeIn.y * 1000 ) );
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2021-06-25 09:35:17 +00:00
|
|
|
galPrint->SetSheetSize( pageSizeIn );
|
|
|
|
|
2018-09-19 13:06:29 +00:00
|
|
|
view->SetGAL( gal );
|
|
|
|
view->SetPainter( painter.get() );
|
|
|
|
view->SetScaleLimits( 10e9, 0.0001 );
|
|
|
|
view->SetScale( 1.0 );
|
|
|
|
|
2018-09-28 11:15:17 +00:00
|
|
|
|
|
|
|
// Set the color scheme
|
2021-02-02 15:36:45 +00:00
|
|
|
RENDER_SETTINGS* dstSettings = view->GetPainter()->GetSettings();
|
2020-05-16 17:15:43 +00:00
|
|
|
dstSettings->LoadColors( m_settings.m_colorSettings );
|
2018-09-28 11:15:17 +00:00
|
|
|
|
2018-10-05 14:41:17 +00:00
|
|
|
if( m_settings.m_blackWhite )
|
2018-09-28 11:15:17 +00:00
|
|
|
{
|
|
|
|
for( int i = 0; i < LAYER_ID_COUNT; ++i )
|
|
|
|
dstSettings->SetLayerColor( i, COLOR4D::BLACK );
|
2022-07-04 10:00:44 +00:00
|
|
|
|
|
|
|
// In B&W mode, draw the background only in wxhite, because any other color
|
|
|
|
// will be replaced by a black background
|
|
|
|
dstSettings->SetBackgroundColor( COLOR4D::WHITE );
|
2018-09-28 11:15:17 +00:00
|
|
|
}
|
|
|
|
else // color enabled
|
|
|
|
{
|
|
|
|
for( int i = 0; i < LAYER_ID_COUNT; ++i )
|
2018-12-22 12:44:49 +00:00
|
|
|
{
|
|
|
|
// Cairo does not support translucent colors on PostScript surfaces
|
|
|
|
// see 'Features support by the PostScript surface' on
|
2020-05-16 17:15:43 +00:00
|
|
|
// https://www.cairographics.org/documentation/using_the_postscript_surface/
|
|
|
|
dstSettings->SetLayerColor( i, dstSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
|
2018-12-22 12:44:49 +00:00
|
|
|
}
|
2018-09-28 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 15:36:45 +00:00
|
|
|
dstSettings->SetIsPrinting( true );
|
|
|
|
|
2020-01-17 11:56:07 +00:00
|
|
|
setupPainter( *painter );
|
2021-02-25 13:02:33 +00:00
|
|
|
setupViewLayers( *view, m_settings.m_LayerSet );
|
2022-06-19 10:57:29 +00:00
|
|
|
dstSettings->SetPrintLayers( m_settings.m_LayerSet );
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2022-06-10 13:09:22 +00:00
|
|
|
dstSettings->SetLayerName( aLayerName );
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
|
|
|
|
VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.x ),
|
|
|
|
milsToIU( sheetSizeMils.y ) );
|
2023-02-08 10:05:31 +00:00
|
|
|
BOX2I drawingAreaBBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
|
|
|
|
|
|
|
|
// When printing the board without worksheet items, move board center to the
|
|
|
|
// drawing area center.
|
|
|
|
if( !m_settings.PrintBorderAndTitleBlock() )
|
|
|
|
drawingAreaBBox = getBoundingBox();
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2022-12-09 17:51:11 +00:00
|
|
|
view->SetLayerVisible( LAYER_DRAWINGSHEET, m_settings.PrintBorderAndTitleBlock() );
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2023-02-08 10:05:31 +00:00
|
|
|
// Fit to page (drawingAreaBBox)
|
2018-10-05 14:41:17 +00:00
|
|
|
if( m_settings.m_scale <= 0.0 )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
2023-02-08 10:05:31 +00:00
|
|
|
if( drawingAreaBBox.GetWidth() == 0 || drawingAreaBBox.GetHeight() == 0 )
|
2018-10-03 07:50:05 +00:00
|
|
|
{
|
2023-02-08 10:05:31 +00:00
|
|
|
// Nothing to print (empty board and no worksheet)
|
2018-10-05 14:41:17 +00:00
|
|
|
m_settings.m_scale = 1.0;
|
2018-10-03 07:50:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-08 10:05:31 +00:00
|
|
|
double scaleX = (double) pageSizeIU.x / drawingAreaBBox.GetWidth();
|
|
|
|
double scaleY = (double) pageSizeIU.y / drawingAreaBBox.GetHeight();
|
2018-10-05 14:41:17 +00:00
|
|
|
m_settings.m_scale = std::min( scaleX, scaleY );
|
2018-10-03 07:50:05 +00:00
|
|
|
}
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 10:13:06 +00:00
|
|
|
setupGal( gal );
|
2018-10-02 13:47:59 +00:00
|
|
|
galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
|
2023-02-08 10:05:31 +00:00
|
|
|
gal->SetLookAtPoint( drawingAreaBBox.Centre() );
|
2018-10-05 14:41:17 +00:00
|
|
|
gal->SetZoomFactor( m_settings.m_scale );
|
2020-05-16 17:15:43 +00:00
|
|
|
gal->SetClearColor( dstSettings->GetBackgroundColor() );
|
|
|
|
gal->ClearScreen();
|
|
|
|
|
2022-02-12 10:44:34 +00:00
|
|
|
if( m_gerbviewPrint )
|
|
|
|
// Mandatory in Gerbview to use the same order for printing as for screen redraw
|
|
|
|
// due to negative objects that need a specific order
|
|
|
|
view->UseDrawPriority( true );
|
|
|
|
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
2021-06-25 09:35:17 +00:00
|
|
|
KIGFX::GAL_DRAWING_CONTEXT ctx( gal );
|
|
|
|
view->Redraw();
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 08:10:08 +00:00
|
|
|
|
|
|
|
|
2020-01-17 11:56:07 +00:00
|
|
|
void BOARD_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
|
2018-09-28 08:10:08 +00:00
|
|
|
{
|
2021-04-05 13:24:57 +00:00
|
|
|
// Disable all layers by default, let specific implementations enable required layers
|
2018-09-28 08:10:08 +00:00
|
|
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
|
|
|
|
{
|
2020-01-17 11:56:07 +00:00
|
|
|
aView.SetLayerVisible( i, false );
|
|
|
|
aView.SetTopLayer( i, false );
|
|
|
|
aView.SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
|
2018-09-28 08:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 11:15:17 +00:00
|
|
|
|
|
|
|
|
2020-01-17 11:56:07 +00:00
|
|
|
void BOARD_PRINTOUT::setupPainter( KIGFX::PAINTER& aPainter )
|
2018-09-28 11:15:17 +00:00
|
|
|
{
|
2020-05-16 17:15:43 +00:00
|
|
|
if( !m_settings.m_background )
|
2020-01-17 11:56:07 +00:00
|
|
|
aPainter.GetSettings()->SetBackgroundColor( COLOR4D::WHITE );
|
2018-09-28 11:15:17 +00:00
|
|
|
}
|
2018-10-05 14:41:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT::setupGal( KIGFX::GAL* aGal )
|
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
aGal->SetFlip( m_settings.m_Mirror, false );
|
2018-10-05 14:41:17 +00:00
|
|
|
}
|