2018-09-19 13:06:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
* 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>
|
|
|
|
#include <painter.h>
|
2018-10-05 14:41:17 +00:00
|
|
|
#include <pcbplot.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
|
|
|
{
|
2018-10-05 14:41:17 +00:00
|
|
|
m_layerSet.set();
|
|
|
|
m_mirror = false;
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-05 14:41:17 +00:00
|
|
|
void BOARD_PRINTOUT_SETTINGS::Load( wxConfigBase* aConfig )
|
|
|
|
{
|
|
|
|
PRINTOUT_SETTINGS::Load( aConfig );
|
|
|
|
|
2018-10-06 22:37:24 +00:00
|
|
|
for( unsigned layer = 0; layer < m_layerSet.size(); ++layer )
|
2018-10-05 14:41:17 +00:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
wxString key = wxString::Format( OPTKEY_LAYERBASE, layer );
|
|
|
|
aConfig->Read( key, &tmp, 1 );
|
|
|
|
m_layerSet.set( layer, tmp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT_SETTINGS::Save( wxConfigBase* aConfig )
|
|
|
|
{
|
|
|
|
PRINTOUT_SETTINGS::Save( aConfig );
|
|
|
|
|
2018-10-06 22:37:24 +00:00
|
|
|
for( unsigned layer = 0; layer < m_layerSet.size(); ++layer )
|
2018-10-05 14:41:17 +00:00
|
|
|
{
|
|
|
|
wxString key = wxString::Format( OPTKEY_LAYERBASE, layer );
|
|
|
|
aConfig->Write( key, m_layerSet.test( layer ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-06 16:51:46 +00:00
|
|
|
BOARD_PRINTOUT::BOARD_PRINTOUT( const BOARD_PRINTOUT_SETTINGS& aParams,
|
|
|
|
const KIGFX::VIEW* aView, const wxString& aTitle ) :
|
2018-10-05 14:41:17 +00:00
|
|
|
wxPrintout( aTitle ), m_settings( aParams )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
|
|
|
m_view = aView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
auto dc = GetDC();
|
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS options;
|
|
|
|
auto galPrint = KIGFX::GAL_PRINT::Create( options, dc );
|
|
|
|
auto gal = galPrint->GetGAL();
|
|
|
|
auto printCtx = galPrint->GetPrintCtx();
|
|
|
|
auto painter = getPainter( gal );
|
|
|
|
std::unique_ptr<KIGFX::VIEW> view( m_view->DataReference() );
|
|
|
|
|
2018-10-06 19:34:51 +00:00
|
|
|
// Target paper size
|
2018-10-02 13:47:59 +00:00
|
|
|
wxRect pageSizePx = GetLogicalPageRect();
|
2018-10-06 19:34:51 +00:00
|
|
|
const VECTOR2D pageSizeIn( (double) pageSizePx.width / dc->GetPPI().x,
|
2018-10-02 13:47:59 +00:00
|
|
|
(double) pageSizePx.height / dc->GetPPI().y );
|
|
|
|
galPrint->SetSheetSize( pageSizeIn );
|
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
|
|
|
|
|
|
|
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
|
|
|
|
auto srcSettings = m_view->GetPainter()->GetSettings();
|
|
|
|
auto dstSettings = view->GetPainter()->GetSettings();
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
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
|
|
|
|
// ttps://www.cairographics.org/documentation/using_the_postscript_surface/
|
2018-10-09 10:21:37 +00:00
|
|
|
dstSettings->SetLayerColor( i, srcSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
|
2018-12-22 12:44:49 +00:00
|
|
|
}
|
2018-09-28 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-05 14:41:17 +00:00
|
|
|
setupViewLayers( view, m_settings.m_layerSet );
|
2018-09-28 11:15:17 +00:00
|
|
|
setupPainter( painter );
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2018-10-06 16:51:46 +00:00
|
|
|
auto sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
|
|
|
|
VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.GetWidth() ), milsToIU( sheetSizeMils.GetHeight() ) );
|
2018-10-06 19:34:51 +00:00
|
|
|
BOX2I bBox;
|
2018-09-19 13:06:29 +00:00
|
|
|
|
2018-10-06 19:34:51 +00:00
|
|
|
// Determine printout bounding box
|
2018-10-05 14:41:17 +00:00
|
|
|
if( m_settings.PrintBorderAndTitleBlock() )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
2018-10-06 16:51:46 +00:00
|
|
|
bBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
|
2018-09-19 13:06:29 +00:00
|
|
|
view->SetLayerVisible( LAYER_WORKSHEET, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EDA_RECT targetBbox = getBoundingBox();
|
|
|
|
bBox = BOX2I( targetBbox.GetOrigin(), targetBbox.GetSize() );
|
|
|
|
view->SetLayerVisible( LAYER_WORKSHEET, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-03 07:50:05 +00:00
|
|
|
// Fit to page
|
2018-10-05 14:41:17 +00:00
|
|
|
if( m_settings.m_scale <= 0.0 )
|
2018-09-19 13:06:29 +00:00
|
|
|
{
|
2018-10-03 07:50:05 +00:00
|
|
|
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
|
|
|
|
{
|
|
|
|
// Nothing to print
|
2018-10-05 14:41:17 +00:00
|
|
|
m_settings.m_scale = 1.0;
|
2018-10-03 07:50:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-06 19:34:51 +00:00
|
|
|
double scaleX = (double) pageSizeIU.x / bBox.GetWidth();
|
|
|
|
double scaleY = (double) pageSizeIU.y / bBox.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-12-22 12:44:49 +00:00
|
|
|
view->SetPrintMode( 1 );
|
|
|
|
|
2018-09-29 10:13:06 +00:00
|
|
|
setupGal( gal );
|
2018-10-02 13:47:59 +00:00
|
|
|
galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
|
2018-09-19 13:06:29 +00:00
|
|
|
gal->SetLookAtPoint( bBox.Centre() );
|
2018-10-05 14:41:17 +00:00
|
|
|
gal->SetZoomFactor( m_settings.m_scale );
|
2018-09-19 13:06:29 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
KIGFX::GAL_DRAWING_CONTEXT ctx( gal );
|
|
|
|
view->Redraw();
|
|
|
|
}
|
2018-12-22 12:44:49 +00:00
|
|
|
|
|
|
|
view->SetPrintMode( 0 );
|
2018-09-19 13:06:29 +00:00
|
|
|
}
|
2018-09-28 08:10:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
|
|
|
|
const LSET& aLayerSet )
|
|
|
|
{
|
|
|
|
// Disable all layers by default, let specific implementions enable required layers
|
|
|
|
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
|
|
|
|
{
|
|
|
|
aView->SetLayerVisible( i, false );
|
2018-09-28 21:45:48 +00:00
|
|
|
aView->SetTopLayer( i, false );
|
2018-09-28 08:10:08 +00:00
|
|
|
aView->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 11:15:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
void BOARD_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter )
|
|
|
|
{
|
2018-09-28 21:45:48 +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 )
|
|
|
|
{
|
|
|
|
aGal->SetFlip( m_settings.m_mirror, false );
|
|
|
|
}
|