32#include <wx/filename.h>
51 if(
scale == 0.0 ) selection = 0;
52 else if(
scale == 1.5 ) selection = 2;
53 else if(
scale == 2.0 ) selection = 3;
54 else if(
scale == 3.0 ) selection = 4;
69 const LSEQ& aCommonLayers,
bool aUseGerberFileExtensions,
70 bool aPlotAllLayersToSingleFile,
bool aForceAllLayersToSinglePage,
71 std::optional<wxString> aLayerName, std::optional<wxString> aSheetName,
72 std::optional<wxString> aSheetPath,
73 std::vector<wxString>* aOutputFiles )
75 std::function<bool( wxString* )> textResolver =
76 [&]( wxString* token ) ->
bool
79 return m_board->ResolveTextVar( token, 0 );
83 if( aLayersToPlot.size() < 1 )
94 VECTOR2I existingAuxOrigin =
m_board->GetDesignSettings().GetAuxOrigin();
98 BOX2I bbox =
m_board->ComputeBoundingBox(
false,
false );
102 if(
m_board->GetBoardPolygonOutlines( boardOutlines,
false ) && boardOutlines.
OutlineCount() > 0 )
103 bbox = boardOutlines.
BBox();
110 m_board->SetPageSettings( currPageInfo );
122 if( aPlotAllLayersToSingleFile && aForceAllLayersToSinglePage )
124 layersToPlot.push_back( aLayersToPlot[0] );
126 if( aLayersToPlot.size() > 1 )
127 commonLayers.insert( commonLayers.end(), aLayersToPlot.begin() + 1, aLayersToPlot.end() );
131 layersToPlot = aLayersToPlot;
132 commonLayers = aCommonLayers;
135 int finalPageCount = 0;
136 std::vector<std::pair<PCB_LAYER_ID, wxString>> layersToExport;
146 layersToExport.emplace_back( layer,
m_board->GetLayerName( layer ) );
149 std::unique_ptr<GERBER_JOBFILE_WRITER> jobfile_writer;
162 for(
size_t i = 0; i < layersToPlot.size(); i++ )
170 wxString layerName =
m_board->GetLayerName( layer );
173 if( aPlotAllLayersToSingleFile )
175 fn = wxFileName( aOutputPath );
179 wxFileName brdFn =
m_board->GetFileName();
180 fn.Assign( aOutputPath, brdFn.GetName(), fileExt );
197 wxString fullname = fn.GetFullName();
198 jobfile_writer->AddGbrFile( layer, fullname );
201 if( !aPlotAllLayersToSingleFile || pageNum == 1 )
203 wxString pageNumber = wxString::Format(
"%d", pageNum );
204 wxString pageName = layerName;
205 wxString sheetName = layerName;
207 if( aLayerName.has_value() )
209 layerName = aLayerName.value();
210 pageName = aLayerName.value();
213 if( aSheetName.has_value() )
214 sheetName = aSheetName.value();
216 if( aSheetPath.has_value() )
217 sheetPath = aSheetPath.value();
219 m_plotOpts.SetLayersToExport( layersToExport );
221 sheetName, sheetPath, pageName, pageNumber, finalPageCount );
231 msg = wxS(
"AUTHOR" );
233 if(
m_board->ResolveTextVar( &msg, 0 ) )
236 msg = wxS(
"SUBJECT" );
238 if(
m_board->ResolveTextVar( &msg, 0 ) )
257 && aPlotAllLayersToSingleFile && !aForceAllLayersToSinglePage && pageNum != finalPageCount )
259 wxString pageNumber = wxString::Format(
"%d", pageNum + 1 );
260 size_t nextI = i + 1;
266 nextLayer = layersToPlot[nextI];
269 layerName =
m_board->GetLayerName( nextLayer );
271 wxString pageName = layerName;
272 wxString sheetName = layerName;
275 static_cast<PDF_PLOTTER*
>( plotter )->StartPage( pageNumber, pageName );
277 sheetPath, pageNumber, finalPageCount );
280 if( !aPlotAllLayersToSingleFile || i == aLayersToPlot.size() - 1 || pageNum == finalPageCount )
297 m_reporter->Report( wxString::Format(
_(
"Plotted to '%s'." ), fn.GetFullPath() ),
302 aOutputFiles->push_back( fn.GetFullPath() );
309 m_reporter->Report( wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ),
321 if( jobfile_writer &&
m_plotOpts.GetCreateGerberJobFile() )
324 wxFileName fn(
m_board->GetFileName() );
328 jobfile_writer->CreateJobFile( fn.GetFullPath() );
331 aOutputFiles->push_back( fn.GetFullPath() );
340 m_board->SetPageSettings( existingPageInfo );
341 m_board->GetDesignSettings().SetAuxOrigin( existingAuxOrigin );
356 LSET shown = aChecked & aEnabledLayers;
366 const wxString& aSuffix,
const wxString& aExtension )
371 aFilename->SetPath( aOutputDir );
374 aFilename->SetExt( aExtension );
382 wxString suffix = aSuffix;
384 suffix.Trim(
false );
386 wxString badchars = wxFileName::GetForbiddenChars( wxPATH_DOS );
387 badchars.Append(
"%." );
389 for(
unsigned ii = 0; ii < badchars.Len(); ii++ )
390 suffix.Replace( badchars[ii], wxT(
"_" ) );
392 if( !suffix.IsEmpty() )
393 aFilename->SetName( aFilename->GetName() + wxT(
"-" ) + suffix );
402 plotSequence.push_back( aLayerToPlot );
407 if(
find( plotSequence.begin(), plotSequence.end(), layer ) != plotSequence.end() )
410 plotSequence.push_back( layer );
489 if( theme.IsEmpty() )
492 theme = pcbSettings->m_ColorTheme;
499 aReporter.
Report( wxString::Format(
_(
"Color theme '%s' not found, will use theme from PCB Editor.\n" ),
550 const std::map<wxString, wxString>* aVarOverrides,
PCB_PLOT_PARAMS& aPlotOpts,
551 const LSEQ& aLayersToPlot,
const LSEQ& aLayersOnAll,
const wxString& aFileName,
563 brd->GetProject()->ApplyTextVars( *aVarOverrides );
565 brd->SynchronizeProperties();
578 pad->SetLocalRatsnestVisible(
false );
579 pad->SetNetCode( 0 );
593 PCB_PLOTTER plotter( brd.get(), aReporter, aPlotOpts );
594 bool useGerberFileExtensions =
false;
595 bool singleFile =
true;
596 bool forceAllLayersToOnePage =
false;
598 return plotter.
Plot( aFileName, aLayersToPlot, aLayersOnAll, useGerberFileExtensions, singleFile,
599 forceAllLayersToOnePage, wxEmptyString, wxEmptyString, wxEmptyString );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static std::unique_ptr< BOARD > CreateEmptyBoard(PROJECT *aProject)
Information pertinent to a Pcbnew printed circuit board.
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
void SetFlags(EDA_ITEM_FLAGS aMask)
virtual void SetParent(EDA_ITEM *aParent)
bool m_plotGraphicItemsUsingContours
bool m_useProtelFileExtension
bool m_includeNetlistAttributes
bool m_disableApertureMacros
bool m_pdfFrontFPPropertyPopups
wxString m_pdfBackgroundColor
The background color specified in a hex string.
bool m_pdfBackFPPropertyPopups
bool m_sketchDNPFPsOnFabLayers
bool m_useDrillOrigin
Used by SVG/DXF/PDF/Gerbers.
bool m_plotFootprintValues
LSEQ m_plotOnAllLayersSequence
Layers to include on all individual layer prints.
bool m_sketchPadsOnFabLayers
DRILL_MARKS m_drillShapeOption
Used by SVG & PDF.
bool m_crossoutDNPFPsOnFabLayers
bool m_hideDNPFPsOnFabLayers
bool m_mirror
Common Options.
bool m_subtractSolderMaskFromSilk
bool m_useBackgroundColor
double m_trackWidthCorrection
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
wxString GetFilename() const
A color representation with 4 components: red, green, blue, alpha.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
LSEQ getPlotSequence(PCB_LAYER_ID aLayerToPlot, LSEQ aPlotWithAllLayersSeq)
Generates a final LSEQ for plotting by removing duplicates.
bool Plot(const wxString &aOutputPath, const LSEQ &aLayersToPlot, const LSEQ &aCommonLayers, bool aUseGerberFileExtensions, bool aPlotAllLayersToSingleFile, bool aForceAllLayersToSinglePage, std::optional< wxString > aLayerName=std::nullopt, std::optional< wxString > aSheetName=std::nullopt, std::optional< wxString > aSheetPath=std::nullopt, std::vector< wxString > *aOutputFiles=nullptr)
static void PlotJobToPlotOpts(PCB_PLOT_PARAMS &aOpts, JOB_EXPORT_PCB_PLOT *aJob, REPORTER &aReporter)
Translate a JOB to PCB_PLOT_PARAMS.
PCB_PLOTTER(BOARD *aBoard, REPORTER *aReporter, PCB_PLOT_PARAMS &aParams)
PCB_PLOT_PARAMS m_plotOpts
bool copperLayerShouldBeSkipped(PCB_LAYER_ID aLayerToPlot)
All copper layers that are disabled are actually selected This is due to wonkyness in automatically s...
static void BuildPlotFileName(wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
Complete a plot filename.
static LSET DialogLayerSelection(const LSET &aChecked, const LSET &aEnabledLayers, bool aForJob)
Return the layers a plot dialog stores when aChecked are ticked.
Parameters and options when plotting/printing a board.
void SetDrillMarksType(DRILL_MARKS aVal)
void SetSkipPlotNPTH_Pads(bool aSkip)
void SetLayerSelection(const LSET &aSelection)
void SetOutputDirectory(const wxString &aDir)
void SetPlotReference(bool aFlag)
void SetSketchPadsOnFabLayers(bool aFlag)
void SetUseGerberX2format(bool aUse)
void SetA4Output(int aForce)
void SetPlotOnAllLayersSequence(LSEQ aSeq)
void SetDXFPlotPolygonMode(bool aFlag)
void SetAutoScale(bool aFlag)
void SetPlotFrameRef(bool aFlag)
void SetSketchDNPFPsOnFabLayers(bool aFlag)
bool m_PDFMetadata
Generate PDF metadata for SUBJECT and AUTHOR.
void SetPlotPadNumbers(bool aFlag)
COLOR4D m_backgroundColor
Background color to use for PNG and PDF plotting.
bool m_PDFFrontFPPropertyPopups
Generate PDF property popup menus for footprints.
void SetScale(double aVal)
void SetDisableGerberMacros(bool aDisable)
void SetDXFMultiLayeredExportOption(bool aFlag)
void SetScaleSelection(int aSelection)
void SetFineScaleAdjustX(double aVal)
void SetMirror(bool aFlag)
void SetBlackAndWhite(bool blackAndWhite)
void SetGerberPrecision(int aPrecision)
void SetSubtractMaskFromSilk(bool aSubtract)
void SetHideDNPFPsOnFabLayers(bool aFlag)
void SetPlotValue(bool aFlag)
void SetUseGerberProtelExtensions(bool aUse)
void SetDXFPlotUnits(DXF_UNITS aUnit)
void SetPngAntialias(bool aFlag)
void SetColorSettings(COLOR_SETTINGS *aSettings)
void SetIncludeGerberNetlistInfo(bool aUse)
void SetCreateGerberJobFile(bool aCreate)
bool m_PDFSingle
Generate a single PDF file for all layers.
void SetNegative(bool aFlag)
bool GetBlackAndWhite() const
void SetUseAuxOrigin(bool aAux)
bool m_PDFBackFPPropertyPopups
on front and/or back of board
void SetDXFPlotMode(DXF_OUTLINE_MODE aPlotMode)
void SetTextMode(PLOT_TEXT_MODE aVal)
void SetSvgFitPageToBoard(int aSvgFitPageToBoard)
void SetSvgPrecision(unsigned aPrecision)
void SetCrossoutDNPFPsOnFabLayers(bool aFlag)
void SetFormat(PLOT_FORMAT aFormat)
void SetBackgroundColor(const COLOR4D &aColor)
void SetFineScaleAdjustY(double aVal)
void SetWidthAdjust(int aVal)
Base plotter engine class.
virtual void SetAuthor(const wxString &aAuthor)
void SetLayer(PCB_LAYER_ID aLayer)
Sets the ID of the current layer.
virtual void SetTitle(const wxString &aTitle)
RENDER_SETTINGS * RenderSettings()
virtual void SetSubject(const wxString &aSubject)
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Return the default plot extension for a format.
static constexpr EDA_ANGLE ANGLE_0
#define IS_NEW
New item, just created.
int RefreshGeneratedTables(BOARD &aBoard)
Bring every generated table on the board up to date and return how many were rebuilt.
Classes used to generate a Gerber job file in JSON.
static const std::string GerberJobFileExtension
@ LAYER_PCB_BACKGROUND
PCB background color.
PCB_LAYER_ID
A quick note on layer IDs:
static int scaleToSelection(double scale)
bool PlotFootprintToSVG(const FOOTPRINT &aFootprint, PROJECT &aProject, const std::map< wxString, wxString > *aVarOverrides, PCB_PLOT_PARAMS &aPlotOpts, const LSEQ &aLayersToPlot, const LSEQ &aLayersOnAll, const wxString &aFileName, REPORTER *aReporter)
Plot a footprint to an SVG file, with the footprint origin at the SVG origin and the page/viewBox siz...
const wxString GetGerberProtelExtension(int aLayer)
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aLayerName, const wxString &aFullFileName, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aPageName=wxT("1"), const wxString &aPageNumber=wxEmptyString, const int aPageCount=1)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...
void setupPlotterNewPDFPage(PLOTTER *aPlotter, BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts, const wxString &aLayerName, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aPageNumber, int aPageCount)
void PlotBoardLayers(BOARD *aBoard, PLOTTER *aPlotter, const LSEQ &aLayerSequence, const PCB_PLOT_PARAMS &aPlotOptions)
Plot a sequence of board layer IDs.
void PlotInteractiveLayer(BOARD *aBoard, PLOTTER *aPlotter, const PCB_PLOT_PARAMS &aPlotOpt)
Plot interactive items (hypertext links, properties, etc.) for the footprints the page drew.
PLOT_FORMAT
The set of supported output plot formats.
Plotting engines similar to ps (PostScript, Gerber, svg)
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetAppSettings(const char *aFilename)
VECTOR2< int32_t > VECTOR2I