KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_writer_base.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25#ifndef GENDRILL_WRITER_BASE_H
26#define GENDRILL_WRITER_BASE_H
27
28// holes can have an attribute in Excellon drill files, similar to attributes
29// in Gerber X2 format
30// They are only comments for a better identification of holes (vias, pads...)
31// Set to 1 to add these comments and 0 to not use these comments
32#define USE_ATTRIB_FOR_HOLES 1
33
34#include <optional>
35#include <string>
36#include <vector>
37
39#include <layer_ids.h>
40#include <plotters/plotter.h>
41#include <padstack.h>
42
43
44class BOARD;
45class BOARD_ITEM;
46class OUTPUTFORMATTER;
47class PAGE_INFO;
48class REPORTER;
49
50
51// Via Protection features according to IPC-4761.
63
64// the DRILL_TOOL class handles tools used in the excellon drill file:
66{
67public:
68 int m_Diameter; // the diameter of the used tool
69 // (for oblong, the smaller size)
70 int m_TotalCount; // how many times it is used (round and oblong)
71 int m_OvalCount; // oblong count
72 bool m_Hole_NotPlated; // Is the hole plated or not plated
73 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
74 bool m_IsBackdrill; // True when drilling a backdrill span
75 bool m_HasPostMachining; // True if any hole for this tool has post-machining
76 std::optional<int> m_MinStubLength; // Minimum stub length for this tool (IU)
77 std::optional<int> m_MaxStubLength; // Maximum stub length for this tool (IU)
78
79public:
80 DRILL_TOOL( int aDiameter, bool a_NotPlated )
81 {
82 m_TotalCount = 0;
83 m_OvalCount = 0;
84 m_Diameter = aDiameter;
85 m_Hole_NotPlated = a_NotPlated;
87 m_IsBackdrill = false;
88 m_HasPostMachining = false;
89 }
90};
91
92
97{
98public:
99 DRILL_PRECISION( int l = 2, int r = 4 )
100 {
101 m_Lhs = l; m_Rhs = r;
102 }
103
104
106 {
107 wxString text;
108
109 text << m_Lhs << wxT( ":" ) << m_Rhs;
110 return text;
111 }
112
113 int m_Lhs; // Left digit number (integer value of coordinates)
114 int m_Rhs; // Right digit number (decimal value of coordinates)
115};
116
117
124{
125public:
126 enum ZEROS_FMT { // Zero format in coordinates
127 DECIMAL_FORMAT, // Floating point coordinates
128 SUPPRESS_LEADING, // Suppress leading zeros
129 SUPPRESS_TRAILING, // Suppress trailing zeros
130 KEEP_ZEROS // keep zeros
131 };
132
133 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
134 PTH_FILE, // PTH only, this is the default also for blind/buried holes
135 NPTH_FILE, // NPTH only
136 MIXED_FILE // PHT+NPTH (mixed)
137 };
138
140 {
141 }
142
149 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
150
155
163 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
164
173 {
174 m_mapFileFmt = aMapFmt;
175 }
176
186 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
187
237 bool GenDrillReportFile( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
238
242 wxString GetDrillFileExt() const { return m_drillFileExtension; }
243
244 const std::vector<wxString>& GetCreatedFiles() const { return m_createdFiles; }
245
246protected:
258 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
259
272 void buildHolesList( const DRILL_SPAN& aSpan, bool aGenerateNPTH_list );
273
274 int getHolesCount() const { return m_holeListBuffer.size(); }
275
285 bool plotDrillMarks( PLOTTER* aPlotter );
286
294
301 unsigned printToolSummary( FILE* aOut, TOOL_SUMMARY aSummary ) const;
302
308 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
309
314 const std::string layerName( PCB_LAYER_ID aLayer ) const;
315
325 virtual const wxString getDrillFileName( const DRILL_SPAN& aSpan, bool aNPTH,
326 bool aMerge_PTH_NPTH ) const;
327
328
335 virtual const wxString getProtectionFileName( const DRILL_SPAN& aSpan,
336 IPC4761_FEATURES aFeature ) const;
337
338
351 const wxString BuildFileFunctionAttributeString( const DRILL_SPAN& aSpan,
352 TYPE_FILE aHoleType,
353 bool aCompatNCdrill = false ) const;
354
355
356protected:
357 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
359 {
360 m_pcb = aPcb;
361 m_conversionUnits = 1.0;
362 m_unitsMetric = true;
364 m_pageInfo = nullptr;
365 m_merge_PTH_NPTH = false;
367 }
368
369 void AddCreatedFile( const wxString& aPath ) { m_createdFiles.emplace_back( aPath ); }
370
372 wxString m_drillFileExtension; // .drl or .gbr, depending on format
373 bool m_unitsMetric; // true = mm, false = inches
374 ZEROS_FMT m_zeroFormat; // the zero format option for output file
375 DRILL_PRECISION m_precision; // The current coordinate precision (not
376 // used in decimal format).
377 double m_conversionUnits; // scaling factor to convert the board
378 // unites to Excellon/Gerber units (i.e
379 // inches or mm)
380 VECTOR2I m_offset; // Drill offset coordinates
381 bool m_merge_PTH_NPTH; // True to generate only one drill file
382 std::vector<DRILL_OPERATION> m_holeListBuffer;
383
384 // One-based tool numbers, indexed by the sorted operation list.
385 std::vector<int> m_holeToolReferences;
386 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
387
388 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
389 // if this map is needed
390 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
391 // If NULL, use a A4 page format
392 std::vector<wxString> m_createdFiles;
393};
394
395#endif // #define GENDRILL_FILE_WRITER_BASE_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
Helper to handle drill precision format in excellon files.
DRILL_PRECISION(int l=2, int r=4)
std::optional< int > m_MinStubLength
HOLE_ATTRIBUTE m_HoleAttribute
DRILL_TOOL(int aDiameter, bool a_NotPlated)
std::optional< int > m_MaxStubLength
wxString GetDrillFileExt() const
Returns the file extension of the drill writer format.
virtual const wxString getProtectionFileName(const DRILL_SPAN &aSpan, IPC4761_FEATURES aFeature) const
const PAGE_INFO * m_pageInfo
void SetMapFileFormat(PLOT_FORMAT aMapFmt)
Initialize the format for the drill map file.
unsigned printToolSummary(FILE *aOut, TOOL_SUMMARY aSummary) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
void AddCreatedFile(const wxString &aPath)
TOOL_SUMMARY
Selects which subset of m_toolListBuffer a summary covers.
@ UNPLATED
Non-plated holes, excluding backdrills.
@ BACKDRILL
Backdrills, which are non-plated by construction.
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
bool genDrillMapFile(const wxString &aFullFileName, PLOT_FORMAT aFormat)
Plot a map of drill marks for holes.
VECTOR2I GetOffset()
Return the plot offset (usually the position of the drill/place origin).
std::vector< DRILL_TOOL > m_toolListBuffer
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
bool CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=nullptr)
Create the full set of map files for the board, in PS, PDF ... format (use SetMapFileFormat() to sele...
void SetMergeOption(bool aMerge)
Set the option to make separate drill files for PTH and NPTH.
const std::string layerName(PCB_LAYER_ID aLayer) const
std::vector< wxString > m_createdFiles
std::vector< int > m_holeToolReferences
std::vector< DRILL_OPERATION > m_holeListBuffer
virtual const wxString getDrillFileName(const DRILL_SPAN &aSpan, bool aNPTH, bool aMerge_PTH_NPTH) const
bool plotDrillMarks(PLOTTER *aPlotter)
Write the drill marks in PDF, POSTSCRIPT or other supported formats/.
const std::vector< wxString > & GetCreatedFiles() const
void SetPageInfo(const PAGE_INFO *aPageInfo)
Set the page info used to plot drill maps.
const wxString BuildFileFunctionAttributeString(const DRILL_SPAN &aSpan, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
The standard X2 FileFunction for drill files is %TF.FileFunction,Plated[NonPlated],...
bool GenDrillReportFile(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Create a plain text report file giving a list of drill values and drill count for through holes,...
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
Base plotter engine class.
Definition plotter.h:136
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
HOLE_ATTRIBUTE
Definition drill_span.h:36
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Definition drill_span.h:49
static const bool FILLED
Definition gr_basic.cpp:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:63
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708