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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29#ifndef GENDRILL_WRITER_BASE_H
30#define GENDRILL_WRITER_BASE_H
31
32// holes can have an attribute in Excellon drill files, similar to attributes
33// in Gerber X2 format
34// They are only comments for a better identification of holes (vias, pads...)
35// Set to 1 to add these comments and 0 to not use these comments
36#define USE_ATTRIB_FOR_HOLES 1
37
38#include <optional>
39#include <string>
40#include <vector>
41
42#include <layer_ids.h>
43#include <plotters/plotter.h>
44#include <padstack.h>
45
46
47class BOARD;
48class BOARD_ITEM;
49class OUTPUTFORMATTER;
50class PAGE_INFO;
51class REPORTER;
52
53// hole attribute, mainly to identify vias and pads and add this info as comment
54// in NC drill files
56{
57 HOLE_UNKNOWN, // uninitialized type
58 HOLE_VIA_THROUGH, // a via hole (always plated) from top to bottom
59 HOLE_VIA_BURIED, // a via hole (always plated) not through hole
60 HOLE_VIA_BACKDRILL, // a via hole created by a backdrill operation
61 HOLE_PAD, // a plated or not plated pad hole
62 HOLE_PAD_CASTELLATED, // a plated castelleted pad hole
63 HOLE_PAD_PRESSFIT, // a plated press-fit pad hole
64 HOLE_MECHANICAL // a mechanical pad (provided, not used)
65};
66
67// Via Protection features according to IPC-4761.
79
80// the DRILL_TOOL class handles tools used in the excellon drill file:
82{
83public:
84 int m_Diameter; // the diameter of the used tool
85 // (for oblong, the smaller size)
86 int m_TotalCount; // how many times it is used (round and oblong)
87 int m_OvalCount; // oblong count
88 bool m_Hole_NotPlated; // Is the hole plated or not plated
89 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
90 bool m_IsBackdrill; // True when drilling a backdrill span
91 bool m_HasPostMachining; // True if any hole for this tool has post-machining
92 std::optional<int> m_MinStubLength; // Minimum stub length for this tool (IU)
93 std::optional<int> m_MaxStubLength; // Maximum stub length for this tool (IU)
94
95public:
96 DRILL_TOOL( int aDiameter, bool a_NotPlated )
97 {
98 m_TotalCount = 0;
99 m_OvalCount = 0;
100 m_Diameter = aDiameter;
101 m_Hole_NotPlated = a_NotPlated;
103 m_IsBackdrill = false;
104 m_HasPostMachining = false;
105 }
106};
107
108
117{
118public:
150
151public:
152 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
153 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
154 // size y).
155 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
156 // must not be used).
157 VECTOR2I m_Hole_Size; // hole size for oblong holes
158 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
159 int m_Hole_Shape; // hole shape: round (0) or oval (1)
160 VECTOR2I m_Hole_Pos; // hole position
161 PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
162 PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
163 // m_Hole_Top_Layer < m_Hole_Bottom_Layer
164 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
165 // section.
166 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
167 // by type.
168 bool m_Hole_Filled; // True if the hole is filled
169 bool m_Hole_Capped; // True if the hole is capped
170 bool m_Hole_Top_Covered; // True if the hole is covered on the top layer
171 bool m_Hole_Bot_Covered; // True if the hole is covered on the bottom layer
172 bool m_Hole_Top_Plugged; // True if the hole is plugged on the top layer
173 bool m_Hole_Bot_Plugged; // True if the hole is plugged on the bottom layer
174 bool m_Hole_Top_Tented; // True if the hole is tented on the top layer
175 bool m_Hole_Bot_Tented; // True if the hole is tented on the bottom layer
176 bool m_IsBackdrill; // True if the hole is a backdrill
178 int m_FrontPostMachiningSize; // Post-machining size
179 int m_FrontPostMachiningDepth; // Post-machining depth
180 int m_FrontPostMachiningAngle; // Post-machining angle
182 int m_BackPostMachiningSize; // Post-machining size
183 int m_BackPostMachiningDepth; // Post-machining depth
184 int m_BackPostMachiningAngle; // Post-machining angle
185 PCB_LAYER_ID m_DrillStart; // Start layer for backdrills
186 PCB_LAYER_ID m_DrillEnd; // End layer for backdrills
187 std::optional<int> m_StubLength; // Stub length for backdrills
188
189
190};
191
192
193typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
194
195
197{
199 {
202 m_IsBackdrill = false;
203 m_IsNonPlatedFile = false;
204 }
205
206 DRILL_SPAN( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, bool aIsBackdrill,
207 bool aIsNonPlated )
208 {
209 m_StartLayer = aStartLayer;
210 m_EndLayer = aEndLayer;
211 m_IsBackdrill = aIsBackdrill;
212 m_IsNonPlatedFile = aIsNonPlated;
213 }
214
219
224
226 {
227 return m_StartLayer;
228 }
229
231 {
232 return m_EndLayer;
233 }
234
236 {
238 }
239
240 bool operator<( const DRILL_SPAN& aOther ) const
241 {
242 if( TopLayer() != aOther.TopLayer() )
243 return TopLayer() < aOther.TopLayer();
244
245 if( BottomLayer() != aOther.BottomLayer() )
246 return BottomLayer() < aOther.BottomLayer();
247
248 if( m_IsBackdrill != aOther.m_IsBackdrill )
249 return m_IsBackdrill && !aOther.m_IsBackdrill;
250
252 return m_IsNonPlatedFile && !aOther.m_IsNonPlatedFile;
253
254 if( m_StartLayer != aOther.m_StartLayer )
255 return m_StartLayer < aOther.m_StartLayer;
256
257 return m_EndLayer < aOther.m_EndLayer;
258 }
259
264};
265
266
271{
272public:
273 DRILL_PRECISION( int l = 2, int r = 4 )
274 {
275 m_Lhs = l; m_Rhs = r;
276 }
277
278
280 {
281 wxString text;
282
283 text << m_Lhs << wxT( ":" ) << m_Rhs;
284 return text;
285 }
286
287 int m_Lhs; // Left digit number (integer value of coordinates)
288 int m_Rhs; // Right digit number (decimal value of coordinates)
289};
290
291
298{
299public:
300 enum ZEROS_FMT { // Zero format in coordinates
301 DECIMAL_FORMAT, // Floating point coordinates
302 SUPPRESS_LEADING, // Suppress leading zeros
303 SUPPRESS_TRAILING, // Suppress trailing zeros
304 KEEP_ZEROS // keep zeros
305 };
306
307 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
308 PTH_FILE, // PTH only, this is the default also for blind/buried holes
309 NPTH_FILE, // NPTH only
310 MIXED_FILE // PHT+NPTH (mixed)
311 };
312
314 {
315 }
316
323 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
324
329
337 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
338
347 {
348 m_mapFileFmt = aMapFmt;
349 }
350
360 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
361
410 bool GenDrillReportFile( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
411
415 wxString GetDrillFileExt() const { return m_drillFileExtension; }
416
417protected:
429 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
430
443 void buildHolesList( const DRILL_SPAN& aSpan, bool aGenerateNPTH_list );
444
445 int getHolesCount() const { return m_holeListBuffer.size(); }
446
456 bool plotDrillMarks( PLOTTER* aPlotter );
457
459 std::vector<DRILL_SPAN> getUniqueLayerPairs() const;
460
467 unsigned printToolSummary( FILE* out, bool aSummaryNPTH ) const;
468
474 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
475
480 const std::string layerName( PCB_LAYER_ID aLayer ) const;
481
491 virtual const wxString getDrillFileName( const DRILL_SPAN& aSpan, bool aNPTH,
492 bool aMerge_PTH_NPTH ) const;
493
494
501 virtual const wxString getProtectionFileName( const DRILL_SPAN& aSpan,
502 IPC4761_FEATURES aFeature ) const;
503
504
516 const wxString BuildFileFunctionAttributeString( const DRILL_SPAN& aSpan,
517 TYPE_FILE aHoleType,
518 bool aCompatNCdrill = false ) const;
519
520
521protected:
522 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
524 {
525 m_pcb = aPcb;
526 m_conversionUnits = 1.0;
527 m_unitsMetric = true;
529 m_pageInfo = nullptr;
530 m_merge_PTH_NPTH = false;
532 }
533
535 wxString m_drillFileExtension; // .drl or .gbr, depending on format
536 bool m_unitsMetric; // true = mm, false = inches
537 ZEROS_FMT m_zeroFormat; // the zero format option for output file
538 DRILL_PRECISION m_precision; // The current coordinate precision (not
539 // used in decimal format).
540 double m_conversionUnits; // scaling factor to convert the board
541 // unites to Excellon/Gerber units (i.e
542 // inches or mm)
543 VECTOR2I m_offset; // Drill offset coordinates
544 bool m_merge_PTH_NPTH; // True to generate only one drill file
545 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
546 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
547
548 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
549 // if this map is needed
550 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
551 // If NULL, use a A4 page format
552};
553
554#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:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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.
std::vector< HOLE_INFO > m_holeListBuffer
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_SPAN > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
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
unsigned printToolSummary(FILE *out, bool aSummaryNPTH) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
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/.
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
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,...
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
PCB_LAYER_ID m_Hole_Bottom_Layer
std::optional< int > m_StubLength
PCB_LAYER_ID m_DrillEnd
PCB_LAYER_ID m_Hole_Top_Layer
HOLE_ATTRIBUTE m_HoleAttribute
PCB_LAYER_ID m_DrillStart
BOARD_ITEM * m_ItemParent
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
EDA_ANGLE m_Hole_Orient
An interface used to output 8 bit text in a convenient way.
Definition richio.h:295
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
Base plotter engine class.
Definition plotter.h:136
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static const bool FILLED
Definition gr_basic.cpp:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ B_Cu
Definition layer_ids.h:65
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:64
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:76
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
DRILL_LAYER_PAIR Pair() const
DRILL_SPAN(PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, bool aIsBackdrill, bool aIsNonPlated)
PCB_LAYER_ID DrillEndLayer() const
PCB_LAYER_ID m_EndLayer
PCB_LAYER_ID TopLayer() const
PCB_LAYER_ID DrillStartLayer() const
PCB_LAYER_ID BottomLayer() const
PCB_LAYER_ID m_StartLayer
bool operator<(const DRILL_SPAN &aOther) const
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695