KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gerber_to_png.cpp File Reference
#include "gerber_to_png.h"
#include "gerber_file_image.h"
#include "gerber_draw_item.h"
#include "dcode.h"
#include "excellon_image.h"
#include "excellon_defaults.h"
#include <convert_basic_shapes_to_polygon.h>
#include <jobs/job_gerber_export_png.h>
#include <plotters/plotter_png.h>
#include <geometry/shape_poly_set.h>
#include <base_units.h>
#include <cmath>
#include <wx/filename.h>

Go to the source code of this file.

Functions

bool IsExcellonFile (const wxString &aPath)
 Determine if a file is an Excellon drill file based on extension.
 
BOX2I CalculateGerberBoundingBox (GERBER_FILE_IMAGE *aImage)
 Calculate bounding box for all draw items in a gerber image.
 
std::unique_ptr< GERBER_FILE_IMAGELoadGerberOrExcellon (const wxString &aPath, wxString *aErrorMsg, wxArrayString *aMessages)
 Load a Gerber or Excellon file, auto-detecting by extension.
 
GERBER_PLOTTER_VIEWPORT CalculatePlotterViewport (const BOX2I &aBBox, int aDpi, int aWidth, int aHeight)
 Compute pixel dimensions and plotter scale from a bounding box and DPI/size settings.
 
bool RenderGerberToPng (const wxString &aInputPath, const wxString &aOutputPath, const GERBER_RENDER_OPTIONS &aOptions, wxString *aErrorMsg, wxArrayString *aMessages)
 Render a Gerber or Excellon file to PNG.
 
bool RenderGerberToPng (const wxString &aInputPath, const wxString &aOutputPath, const JOB_GERBER_EXPORT_PNG &aJob, wxString *aErrorMsg, wxArrayString *aMessages)
 Render a Gerber or Excellon file to PNG using job parameters.
 

Function Documentation

◆ CalculateGerberBoundingBox()

BOX2I CalculateGerberBoundingBox ( GERBER_FILE_IMAGE * aImage)

Calculate bounding box for all draw items in a gerber image.

Definition at line 43 of file gerber_to_png.cpp.

References GERBER_FILE_IMAGE::GetItems(), and BOX2< Vec >::Merge().

Referenced by GERBVIEW_JOBS_HANDLER::JobGerberInfo(), and RenderGerberToPng().

◆ CalculatePlotterViewport()

GERBER_PLOTTER_VIEWPORT CalculatePlotterViewport ( const BOX2I & aBBox,
int aDpi,
int aWidth,
int aHeight )

Compute pixel dimensions and plotter scale from a bounding box and DPI/size settings.

Parameters
aBBoxBounding box in gerber IU
aDpiDPI for auto-sizing
aWidthRequested width (0 = auto from DPI)
aHeightRequested height (0 = auto from DPI)

Definition at line 179 of file gerber_to_png.cpp.

References gerbIUScale, BOX2< Vec >::GetHeight(), BOX2< Vec >::GetOrigin(), BOX2< Vec >::GetWidth(), GERBER_PLOTTER_VIEWPORT::height, GERBER_PLOTTER_VIEWPORT::iuPerDecimil, MIN_PIXEL_SIZE, GERBER_PLOTTER_VIEWPORT::offset, GERBER_PLOTTER_VIEWPORT::plotScale, and GERBER_PLOTTER_VIEWPORT::width.

Referenced by RenderDiffToPng(), and RenderGerberToPng().

◆ IsExcellonFile()

bool IsExcellonFile ( const wxString & aPath)

Determine if a file is an Excellon drill file based on extension.

Definition at line 35 of file gerber_to_png.cpp.

Referenced by LoadGerberOrExcellon().

◆ LoadGerberOrExcellon()

std::unique_ptr< GERBER_FILE_IMAGE > LoadGerberOrExcellon ( const wxString & aPath,
wxString * aErrorMsg,
wxArrayString * aMessages = nullptr )

Load a Gerber or Excellon file, auto-detecting by extension.

Returns
Loaded image, or nullptr on failure

Definition at line 67 of file gerber_to_png.cpp.

References image, and IsExcellonFile().

Referenced by GERBVIEW_JOBS_HANDLER::JobGerberDiff(), GERBVIEW_JOBS_HANDLER::JobGerberInfo(), and RenderGerberToPng().

◆ RenderGerberToPng() [1/2]

bool RenderGerberToPng ( const wxString & aInputPath,
const wxString & aOutputPath,
const GERBER_RENDER_OPTIONS & aOptions,
wxString * aErrorMsg = nullptr,
wxArrayString * aMessages = nullptr )

Render a Gerber or Excellon file to PNG.

Loads the file, converts all draw items to polygons, and renders using PNG_PLOTTER with Cairo.

Parameters
aInputPathPath to the Gerber or Excellon file
aOutputPathPath for the output PNG file
aOptionsRendering options
aErrorMsgOptional pointer to receive error messages
aMessagesOptional pointer to receive parse messages
Returns
true on success, false on failure

Definition at line 222 of file gerber_to_png.cpp.

References KIGFX::COLOR4D::a, GERBER_RENDER_OPTIONS::antialias, GERBER_RENDER_OPTIONS::backgroundColor, CalculateGerberBoundingBox(), CalculatePlotterViewport(), GERBER_RENDER_OPTIONS::dpi, PNG_PLOTTER::EndPlot(), GERBER_RENDER_OPTIONS::foregroundColor, gerbIUScale, BOX2< Vec >::GetHeight(), BOX2< Vec >::GetWidth(), GERBER_RENDER_OPTIONS::HasViewportOverride(), GERBER_PLOTTER_VIEWPORT::height, GERBER_RENDER_OPTIONS::height, image, GERBER_PLOTTER_VIEWPORT::iuPerDecimil, LoadGerberOrExcellon(), GERBER_PLOTTER_VIEWPORT::offset, GERBER_RENDER_OPTIONS::originXMm, GERBER_RENDER_OPTIONS::originYMm, GERBER_PLOTTER_VIEWPORT::plotScale, PNG_PLOTTER::SaveFile(), PNG_PLOTTER::SetAntialias(), PNG_PLOTTER::SetBackgroundColor(), PNG_PLOTTER::SetClearCompositing(), PNG_PLOTTER::SetPixelSize(), PNG_PLOTTER::SetResolution(), PNG_PLOTTER::SetViewport(), PNG_PLOTTER::StartPlot(), GERBER_PLOTTER_VIEWPORT::width, GERBER_RENDER_OPTIONS::width, GERBER_RENDER_OPTIONS::windowHeightMm, and GERBER_RENDER_OPTIONS::windowWidthMm.

Referenced by GERBVIEW_JOBS_HANDLER::JobGerberExportPng(), and RenderGerberToPng().

◆ RenderGerberToPng() [2/2]

bool RenderGerberToPng ( const wxString & aInputPath,
const wxString & aOutputPath,
const JOB_GERBER_EXPORT_PNG & aJob,
wxString * aErrorMsg = nullptr,
wxArrayString * aMessages = nullptr )