2022-10-04 01:53:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-08-05 16:18:18 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-10-04 01:53:37 +00:00
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-08-18 17:44:54 +00:00
|
|
|
#include "board.h"
|
|
|
|
#include "locale_io.h"
|
|
|
|
#include "pcb_plot_params.h"
|
|
|
|
#include "export_svg.h"
|
|
|
|
#include "pcbplot.h"
|
|
|
|
#include "pgm_base.h"
|
|
|
|
#include "plotters/plotters_pslike.h"
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
|
2023-08-18 17:44:54 +00:00
|
|
|
bool EXPORT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions )
|
2022-10-04 01:53:37 +00:00
|
|
|
{
|
|
|
|
PCB_PLOT_PARAMS plot_opts;
|
2022-10-25 23:53:18 +00:00
|
|
|
wxString outputFile = aSvgPlotOptions.m_outputFile;
|
2022-10-04 01:53:37 +00:00
|
|
|
|
2022-12-14 03:48:07 +00:00
|
|
|
plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
// Adding drill marks, for copper layers
|
2023-09-28 14:59:11 +00:00
|
|
|
if( ( LSET( aSvgPlotOptions.m_printMaskLayer ) & LSET::AllCuMask() ).any() )
|
2023-08-05 16:18:18 +00:00
|
|
|
{
|
|
|
|
switch( aSvgPlotOptions.m_drillShapeOption )
|
|
|
|
{
|
2024-05-13 18:21:20 +00:00
|
|
|
default:
|
|
|
|
case 0: plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); break;
|
|
|
|
case 1: plot_opts.SetDrillMarksType( DRILL_MARKS::SMALL_DRILL_SHAPE ); break;
|
|
|
|
case 2: plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
|
2023-08-05 16:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-04 01:53:37 +00:00
|
|
|
else
|
2023-08-18 17:44:54 +00:00
|
|
|
{
|
2022-11-12 07:48:25 +00:00
|
|
|
plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
|
2023-08-18 17:44:54 +00:00
|
|
|
}
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
plot_opts.SetSkipPlotNPTH_Pads( false );
|
|
|
|
|
|
|
|
plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
|
2023-06-03 18:44:03 +00:00
|
|
|
plot_opts.SetNegative( aSvgPlotOptions.m_negative );
|
2022-10-04 01:53:37 +00:00
|
|
|
plot_opts.SetFormat( PLOT_FORMAT::SVG );
|
|
|
|
// coord format: 4 digits in mantissa (units always in mm). This is a good choice.
|
|
|
|
plot_opts.SetSvgPrecision( 4 );
|
|
|
|
|
|
|
|
PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
|
|
|
|
VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
|
|
|
|
|
|
|
|
if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
|
|
|
|
{
|
2024-05-06 20:34:40 +00:00
|
|
|
BOX2I bbox = aBoard->ComputeBoundingBox( false, false );
|
2022-10-04 01:53:37 +00:00
|
|
|
PAGE_INFO currpageInfo = aBoard->GetPageSettings();
|
|
|
|
|
|
|
|
currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
|
|
|
|
currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
|
|
|
|
aBoard->SetPageSettings( currpageInfo );
|
|
|
|
plot_opts.SetUseAuxOrigin( true );
|
|
|
|
VECTOR2I origin = bbox.GetOrigin();
|
|
|
|
aBoard->GetDesignSettings().SetAuxOrigin( origin );
|
|
|
|
}
|
|
|
|
|
2022-10-25 23:53:18 +00:00
|
|
|
if( outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = aBoard->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
2024-05-13 18:21:20 +00:00
|
|
|
fn.SetExt( wxS( "svg" ) );
|
2022-10-25 23:53:18 +00:00
|
|
|
|
|
|
|
outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
2022-10-04 01:53:37 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
|
2023-01-25 03:57:28 +00:00
|
|
|
plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
PCB_LAYER_ID layer = UNDEFINED_LAYER;
|
|
|
|
wxString layerName;
|
2022-10-04 01:53:37 +00:00
|
|
|
//@todo allow controlling the sheet name and path that will be displayed in the title block
|
|
|
|
// Leave blank for now
|
2024-05-13 19:03:45 +00:00
|
|
|
wxString sheetName;
|
|
|
|
wxString sheetPath;
|
|
|
|
|
|
|
|
if( aSvgPlotOptions.m_printMaskLayer.size() == 1 )
|
|
|
|
{
|
|
|
|
layer = aSvgPlotOptions.m_printMaskLayer.front();
|
|
|
|
layerName = aBoard->GetLayerName( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, layer, layerName,
|
|
|
|
outputFile, sheetName, sheetPath );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
if( plotter )
|
|
|
|
{
|
|
|
|
plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
|
2024-05-13 18:21:20 +00:00
|
|
|
PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer, plot_opts );
|
2022-10-04 01:53:37 +00:00
|
|
|
plotter->EndPlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete plotter;
|
|
|
|
|
|
|
|
// reset to the values saved earlier
|
|
|
|
aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
|
|
|
|
aBoard->SetPageSettings( savedPageInfo );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|