diff --git a/common/jobs/job_fp_export_svg.cpp b/common/jobs/job_fp_export_svg.cpp index 60f0ee6e03..98450eed65 100644 --- a/common/jobs/job_fp_export_svg.cpp +++ b/common/jobs/job_fp_export_svg.cpp @@ -22,13 +22,13 @@ JOB_FP_EXPORT_SVG::JOB_FP_EXPORT_SVG() : - JOB( "fpsvg", true ), + JOB_EXPORT_PCB_PLOT( JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::SVG, "fpsvg", true ), m_libraryPath(), - m_footprint(), - m_blackAndWhite( false ), - m_sketchPadsOnFabLayers( false ), - m_hideDNPFPsOnFabLayers( false ), - m_sketchDNPFPsOnFabLayers( true ), - m_crossoutDNPFPsOnFabLayers( true ) + m_footprint() { + m_blackAndWhite = false; + m_sketchPadsOnFabLayers = false; + m_hideDNPFPsOnFabLayers = false; + m_sketchDNPFPsOnFabLayers = true; + m_crossoutDNPFPsOnFabLayers = true; } \ No newline at end of file diff --git a/common/jobs/job_fp_export_svg.h b/common/jobs/job_fp_export_svg.h index 23194cce93..dc83a37adc 100644 --- a/common/jobs/job_fp_export_svg.h +++ b/common/jobs/job_fp_export_svg.h @@ -25,27 +25,16 @@ #include <layer_ids.h> #include <lseq.h> #include <wx/string.h> +#include <jobs/job_export_pcb_plot.h> #include "job.h" -class KICOMMON_API JOB_FP_EXPORT_SVG : public JOB +class KICOMMON_API JOB_FP_EXPORT_SVG : public JOB_EXPORT_PCB_PLOT { public: JOB_FP_EXPORT_SVG(); wxString m_libraryPath; wxString m_footprint; - - wxString m_outputDirectory; - - wxString m_colorTheme; - - bool m_blackAndWhite; - bool m_sketchPadsOnFabLayers; - bool m_hideDNPFPsOnFabLayers; - bool m_sketchDNPFPsOnFabLayers; - bool m_crossoutDNPFPsOnFabLayers; - - LSEQ m_printMaskLayer; }; #endif \ No newline at end of file diff --git a/kicad/cli/command_fp_export_svg.cpp b/kicad/cli/command_fp_export_svg.cpp index 600e4eb0bf..abd261e629 100644 --- a/kicad/cli/command_fp_export_svg.cpp +++ b/kicad/cli/command_fp_export_svg.cpp @@ -81,7 +81,7 @@ int CLI::FP_EXPORT_SVG_COMMAND::doPerform( KIWAY& aKiway ) std::unique_ptr<JOB_FP_EXPORT_SVG> svgJob = std::make_unique<JOB_FP_EXPORT_SVG>(); svgJob->m_libraryPath = m_argInput; - svgJob->m_outputDirectory = m_argOutput; + svgJob->SetConfiguredOutputPath( m_argOutput ); svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE ); svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS ); svgJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS ); @@ -99,9 +99,9 @@ int CLI::FP_EXPORT_SVG_COMMAND::doPerform( KIWAY& aKiway ) svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() ); if( !m_selectedLayers.empty() ) - svgJob->m_printMaskLayer = m_selectedLayers; + svgJob->m_plotLayerSequence = m_selectedLayers; else - svgJob->m_printMaskLayer = LSET::AllLayersMask().SeqStackupForPlotting(); + svgJob->m_plotLayerSequence = LSET::AllLayersMask().SeqStackupForPlotting(); int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() ); diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bf9e1a8b20..bbc6f67a0e 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -232,7 +232,6 @@ set( PCBNEW_EXPORTERS exporters/export_gencad.cpp exporters/export_gencad_writer.cpp exporters/export_idf.cpp - exporters/export_svg.cpp exporters/step/exporter_step.cpp exporters/step/step_pcb_model.cpp exporters/step/KI_XCAFDoc_AssemblyGraph.cxx diff --git a/pcbnew/exporters/export_svg.cpp b/pcbnew/exporters/export_svg.cpp deleted file mode 100644 index a74044e09f..0000000000 --- a/pcbnew/exporters/export_svg.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 - * Copyright The 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 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/>. - */ - -#include "board.h" -#include "locale_io.h" -#include "export_svg.h" -#include "pcbplot.h" -#include "pgm_base.h" -#include "plotters/plotters_pslike.h" - - -bool EXPORT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions ) -{ - PCB_PLOT_PARAMS plot_opts; - wxString outputFile = aSvgPlotOptions.m_outputFile; - - plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame ); - - if( aSvgPlotOptions.m_sketchPadsOnFabLayers ) - { - plot_opts.SetSketchPadsOnFabLayers( true ); - plot_opts.SetPlotPadNumbers( true ); - } - - plot_opts.SetHideDNPFPsOnFabLayers( aSvgPlotOptions.m_hideDNPFPsOnFabLayers ); - plot_opts.SetSketchDNPFPsOnFabLayers( aSvgPlotOptions.m_sketchDNPFPsOnFabLayers ); - plot_opts.SetCrossoutDNPFPsOnFabLayers( aSvgPlotOptions.m_crossoutDNPFPsOnFabLayers ); - - // Adding drill marks, for copper layers - if( ( LSET( { aSvgPlotOptions.m_printMaskLayer } ) & LSET::AllCuMask() ).any() ) - { - switch( aSvgPlotOptions.m_drillShapeOption ) - { - 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; - } - } - else - { - plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); - } - - plot_opts.SetSkipPlotNPTH_Pads( false ); - - plot_opts.SetMirror( aSvgPlotOptions.m_mirror ); - plot_opts.SetNegative( aSvgPlotOptions.m_negative ); - plot_opts.SetFormat( PLOT_FORMAT::SVG ); - plot_opts.SetSvgPrecision( aSvgPlotOptions.m_precision ); - - PAGE_INFO savedPageInfo = aBoard->GetPageSettings(); - VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin(); - - if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size - { - BOX2I bbox = aBoard->ComputeBoundingBox( false ); - 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 ); - } - - if( outputFile.IsEmpty() ) - { - wxFileName fn = aBoard->GetFileName(); - fn.SetName( fn.GetName() ); - fn.SetExt( wxS( "svg" ) ); - - outputFile = fn.GetFullName(); - } - - SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - - plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) ); - - LOCALE_IO toggle; - PCB_LAYER_ID layer = UNDEFINED_LAYER; - wxString layerName; - //@todo allow controlling the sheet name and path that will be displayed in the title block - // Leave blank for now - 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 ); - - if( plotter ) - { - plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite ); - PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer, plot_opts ); - plotter->EndPlot(); - - delete plotter; - - // reset to the values saved earlier - aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin ); - aBoard->SetPageSettings( savedPageInfo ); - - return true; - } - else - { - return false; - } -} diff --git a/pcbnew/exporters/export_svg.h b/pcbnew/exporters/export_svg.h deleted file mode 100644 index 532981f316..0000000000 --- a/pcbnew/exporters/export_svg.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 - * Copyright The 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 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/>. - */ - -#ifndef PCB_PLOT_SVG_H -#define PCB_PLOT_SVG_H - -struct PCB_PLOT_SVG_OPTIONS -{ - wxString m_outputFile; - wxString m_colorTheme; - - bool m_mirror; - bool m_blackAndWhite; - bool m_plotFrame; - bool m_negative; - - int m_pageSizeMode; - - LSEQ m_printMaskLayer; - bool m_sketchPadsOnFabLayers; - bool m_hideDNPFPsOnFabLayers; - bool m_sketchDNPFPsOnFabLayers; - bool m_crossoutDNPFPsOnFabLayers; - - // How holes in pads/vias are plotted: - // 0 = no hole, 1 = small shape, 2 = actual shape - // Not used in some plotters (Gerber) - int m_drillShapeOption; - - // coord format: 4 digits in mantissa (units always in mm). This is a good choice. - unsigned int m_precision = 4; -}; - -class EXPORT_SVG -{ -public: - static bool Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions ); -}; - -#endif \ No newline at end of file diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index c5fdb158b0..c6a879a256 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -61,7 +61,6 @@ #include <pad.h> #include <pcb_marker.h> #include <project/project_file.h> -#include <exporters/export_svg.h> #include <exporters/export_gencad_writer.h> #include <exporters/export_d356.h> #include <kiface_ids.h> @@ -1668,9 +1667,12 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; } - if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) ) + wxString outPath = svgJob->GetFullOutputPath( nullptr ); + + if( !PATHS::EnsurePathExists( outPath, true ) ) { - wxFileName::Mkdir( svgJob->m_outputDirectory ); + m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR ); + return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; } int exitCode = CLI::EXIT_CODES::OK; @@ -1733,7 +1735,7 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR brd->Add( fp, ADD_MODE::INSERT, true ); wxFileName outputFile; - outputFile.SetPath( aSvgJob->m_outputDirectory ); + outputFile.SetPath( aSvgJob->GetFullOutputPath(nullptr) ); outputFile.SetName( aFootprint->GetFPID().GetLibItemName().wx_str() ); outputFile.SetExt( FILEEXT::SVGFileExtension ); @@ -1742,22 +1744,35 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR outputFile.GetFullPath() ), RPT_SEVERITY_ACTION ); + PCB_PLOT_PARAMS plotOpts; + PCB_PLOTTER::PlotJobToPlotOpts( plotOpts, aSvgJob, *m_reporter ); - PCB_PLOT_SVG_OPTIONS svgPlotOptions; - svgPlotOptions.m_blackAndWhite = aSvgJob->m_blackAndWhite; - svgPlotOptions.m_colorTheme = aSvgJob->m_colorTheme; - svgPlotOptions.m_outputFile = outputFile.GetFullPath(); - svgPlotOptions.m_mirror = false; - svgPlotOptions.m_pageSizeMode = 2; // board bounding box - svgPlotOptions.m_printMaskLayer = aSvgJob->m_printMaskLayer; - svgPlotOptions.m_sketchPadsOnFabLayers = aSvgJob->m_sketchPadsOnFabLayers; - svgPlotOptions.m_hideDNPFPsOnFabLayers = aSvgJob->m_hideDNPFPsOnFabLayers; - svgPlotOptions.m_sketchDNPFPsOnFabLayers = aSvgJob->m_sketchDNPFPsOnFabLayers; - svgPlotOptions.m_crossoutDNPFPsOnFabLayers = aSvgJob->m_crossoutDNPFPsOnFabLayers; - svgPlotOptions.m_plotFrame = false; + // always fixed for the svg plot + plotOpts.SetPlotFrameRef( false ); + plotOpts.SetSvgFitPageToBoard( true ); + plotOpts.SetMirror( false ); + plotOpts.SetSkipPlotNPTH_Pads( false ); - if( !EXPORT_SVG::Plot( brd.get(), svgPlotOptions ) ) + if( plotOpts.GetSketchPadsOnFabLayers() ) + { + plotOpts.SetPlotPadNumbers( true ); + } + + PCB_PLOTTER plotter( brd.get(), m_reporter, plotOpts ); + + LOCALE_IO dummy; + + if( !plotter.Plot( outputFile.GetFullPath(), + aSvgJob->m_plotLayerSequence, + aSvgJob->m_plotOnAllLayersSequence, + false, + true, + wxEmptyString, wxEmptyString, + wxEmptyString ) ) + { m_reporter->Report( _( "Error creating svg file" ) + wxS( "\n" ), RPT_SEVERITY_ERROR ); + return CLI::EXIT_CODES::ERR_UNKNOWN; + } return CLI::EXIT_CODES::OK; }