34#include <wx/filename.h>
41 [](
JOB* job, wxWindow* aParent ) ->
bool
47 [](
JOB* job, wxWindow* aParent ) ->
bool
53 [](
JOB* job, wxWindow* aParent ) ->
bool
66 return wxS(
"Excellon Drill" );
68 return wxS(
"Gerber" );
76 if( aMessages.IsEmpty() )
79 for(
const wxString& msg : aMessages )
97 wxArrayString messages;
118 double lengthScale = 1.0;
119 double areaScale = 1.0;
120 wxString unitStr = wxS(
"mm" );
121 wxString areaUnitStr = wxS(
"mm²" );
128 unitStr = wxS(
"mm" );
129 areaUnitStr = wxS(
"mm²" );
133 lengthScale = 1.0 / 25.4;
134 areaScale = 1.0 / ( 25.4 * 25.4 );
135 unitStr = wxS(
"in" );
136 areaUnitStr = wxS(
"in²" );
140 lengthScale = 1000.0 / 25.4;
141 areaScale = 1000000.0 / ( 25.4 * 25.4 );
142 unitStr = wxS(
"mils" );
143 areaUnitStr = wxS(
"mils²" );
147 double originX =
static_cast<double>( bbox.
GetOrigin().x ) * iuToMm * lengthScale;
148 double originY =
static_cast<double>( bbox.
GetOrigin().y ) * iuToMm * lengthScale;
149 double width =
static_cast<double>( bbox.
GetWidth() ) * iuToMm * lengthScale;
150 double height =
static_cast<double>( bbox.
GetHeight() ) * iuToMm * lengthScale;
152 int apertureCount =
image->GetDcodesCount();
158 j[
"filename"] = fn.GetFullName().ToStdString();
159 j[
"type"] = GetFileTypeString(
image.get() ).ToStdString();
160 j[
"item_count"] =
image->GetItemsCount();
161 j[
"units"] = unitStr.ToStdString();
163 j[
"bounding_box"] = {
164 {
"origin_x", originX }, {
"origin_y", originY }, {
"width", width }, {
"height", height }
167 j[
"aperture_count"] = apertureCount;
171 double areaMm2 =
image->CalculateCopperArea();
172 j[
"copper_area"] = areaMm2 * areaScale;
182 out += wxString::Format( wxS(
"File: %s\n" ), fn.GetFullName() );
183 out += wxString::Format( wxS(
"Type: %s\n" ), GetFileTypeString(
image.get() ) );
184 out += wxString::Format( wxS(
"Item count: %d\n" ),
image->GetItemsCount() );
186 out += wxS(
"Bounding box:\n" );
187 out += wxString::Format( wxS(
" Origin: (%.3f, %.3f) %s\n" ), originX, originY, unitStr );
188 out += wxString::Format( wxS(
" Size: %.3f x %.3f %s\n" ), width, height, unitStr );
190 out += wxString::Format( wxS(
"\nApertures defined: %d\n" ), apertureCount );
194 double areaMm2 =
image->CalculateCopperArea();
195 out += wxString::Format( wxS(
"Copper area: %.3f %s\n" ), areaMm2 * areaScale, areaUnitStr );
214 wxArrayString messages;
245 wxArrayString messagesA;
246 wxArrayString messagesB;
285 polyB.
Move( alignOffset );
292 constexpr double DIFF_AREA_EPSILON_MM2 = 1e-9;
294 bool filesIdentical =
295 (
result.additionsArea < DIFF_AREA_EPSILON_MM2 &&
result.removalsArea < DIFF_AREA_EPSILON_MM2 );
305 auto writeTextToOutput = [&](
const wxString& aText ) ->
bool
309 if( !outputPath.IsEmpty() )
311 wxFile file( outputPath, wxFile::write );
313 if( !file.IsOpened() )
317 m_reporter->Report( wxString::Format( wxS(
"Failed to open output file: %s" ), outputPath ),
328 m_reporter->Report( wxString::Format( wxS(
"Output written to: %s" ), outputPath ),
346 if( !writeTextToOutput(
text ) )
356 if( !writeTextToOutput( wxString::FromUTF8( j.dump( 2 ) ) ) )
constexpr EDA_IU_SCALE gerbIUScale
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
constexpr const Vec & GetOrigin() const
Hold the image data and parameters for one gerber file and layer parameters.
int JobGerberExportPng(JOB *aJob)
int JobGerberDiff(JOB *aJob)
GERBVIEW_JOBS_HANDLER(KIWAY *aKiway)
int JobGerberInfo(JOB *aJob)
bool checkStrictMode(const wxArrayString &aMessages, bool aStrict)
void Register(const std::string &aJobTypeName, std::function< int(JOB *job)> aHandler, std::function< bool(JOB *job, wxWindow *aParent)> aConfigHandler)
JOB_DISPATCHER(KIWAY *aKiway)
Job to compare two Gerber files and highlight differences.
bool m_transparentBackground
OUTPUT_FORMAT m_outputFormat
Job to convert Gerber/Excellon files to PNG images.
Job to extract information from Gerber/Excellon files.
OUTPUT_FORMAT m_outputFormat
An simple container class that lets us dispatch output jobs to kifaces.
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
A color representation with 4 components: red, green, blue, alpha.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Represent a set of closed polygons.
void Move(const VECTOR2I &aVector) override
wxString FormatDiffResultText(const GERBER_DIFF_RESULT &aResult, const wxString &aFile1, const wxString &aFile2, DIFF_UNITS aUnits)
Format a diff result as human-readable text.
GERBER_DIFF_RESULT CalculateGerberDiff(const SHAPE_POLY_SET &aReference, const SHAPE_POLY_SET &aComparison)
Calculate the geometric differences between two poly sets.
VECTOR2I CalculateAlignment(const SHAPE_POLY_SET &aReference, const SHAPE_POLY_SET &aComparison)
Calculate the alignment offset to make a comparison poly set align with a reference.
nlohmann::json FormatDiffResultJson(const GERBER_DIFF_RESULT &aResult, const wxString &aFile1, const wxString &aFile2, DIFF_UNITS aUnits, double aMaxDiffPercent)
Format a diff result as JSON.
bool RenderDiffToPng(const GERBER_DIFF_RESULT &aResult, const wxString &aOutputPath, const DIFF_RENDER_OPTIONS &aOptions)
Render a diff result to PNG with colored regions.
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.
BOX2I CalculateGerberBoundingBox(GERBER_FILE_IMAGE *aImage)
Calculate bounding box for all draw items in a gerber image.
std::unique_ptr< GERBER_FILE_IMAGE > LoadGerberOrExcellon(const wxString &aPath, wxString *aErrorMsg, wxArrayString *aMessages)
Load a Gerber or Excellon file, auto-detecting by extension.
SHAPE_POLY_SET ConvertGerberToPolySet(GERBER_FILE_IMAGE *aImage, int aTolerance)
Convert a GERBER_FILE_IMAGE to a merged SHAPE_POLY_SET.
static const int ERR_RC_VIOLATIONS
Rules check violation count was greater than 0.
static const int ERR_INVALID_INPUT_FILE
static const int ERR_UNKNOWN
Options for diff PNG rendering.
KIGFX::COLOR4D colorBackground
White.
Result of a Gerber diff calculation containing the geometric differences and area statistics.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I