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
38#include <drill/drill_span.h>
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
101{
102public:
134
135public:
136 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
137 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
138 // size y).
139 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
140 // must not be used).
141 VECTOR2I m_Hole_Size; // hole size for oblong holes
142 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
143 int m_Hole_Shape; // hole shape: round (0) or oval (1)
144 VECTOR2I m_Hole_Pos; // hole position
145 PCB_LAYER_ID m_Hole_Bottom_Layer; // physically lowest layer reached by the hole
146 PCB_LAYER_ID m_Hole_Top_Layer; // physically highest layer reached by the hole
147 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
148 // section.
149 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
150 // by type.
151 bool m_Hole_Filled; // True if the hole is filled
152 bool m_Hole_Capped; // True if the hole is capped
153 bool m_Hole_Top_Covered; // True if the hole is covered on the top layer
154 bool m_Hole_Bot_Covered; // True if the hole is covered on the bottom layer
155 bool m_Hole_Top_Plugged; // True if the hole is plugged on the top layer
156 bool m_Hole_Bot_Plugged; // True if the hole is plugged on the bottom layer
157 bool m_Hole_Top_Tented; // True if the hole is tented on the top layer
158 bool m_Hole_Bot_Tented; // True if the hole is tented on the bottom layer
159 bool m_IsBackdrill; // True if the hole is a backdrill
161 int m_FrontPostMachiningSize; // Post-machining size
162 int m_FrontPostMachiningDepth; // Post-machining depth
163 int m_FrontPostMachiningAngle; // Post-machining angle
165 int m_BackPostMachiningSize; // Post-machining size
166 int m_BackPostMachiningDepth; // Post-machining depth
167 int m_BackPostMachiningAngle; // Post-machining angle
168 PCB_LAYER_ID m_DrillStart; // Start layer for backdrills
169 PCB_LAYER_ID m_DrillEnd; // End layer for backdrills
170 std::optional<int> m_StubLength; // Stub length for backdrills
171
172
173};
174
175
180{
181public:
182 DRILL_PRECISION( int l = 2, int r = 4 )
183 {
184 m_Lhs = l; m_Rhs = r;
185 }
186
187
189 {
190 wxString text;
191
192 text << m_Lhs << wxT( ":" ) << m_Rhs;
193 return text;
194 }
195
196 int m_Lhs; // Left digit number (integer value of coordinates)
197 int m_Rhs; // Right digit number (decimal value of coordinates)
198};
199
200
207{
208public:
209 enum ZEROS_FMT { // Zero format in coordinates
210 DECIMAL_FORMAT, // Floating point coordinates
211 SUPPRESS_LEADING, // Suppress leading zeros
212 SUPPRESS_TRAILING, // Suppress trailing zeros
213 KEEP_ZEROS // keep zeros
214 };
215
216 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
217 PTH_FILE, // PTH only, this is the default also for blind/buried holes
218 NPTH_FILE, // NPTH only
219 MIXED_FILE // PHT+NPTH (mixed)
220 };
221
223 {
224 }
225
232 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
233
238
246 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
247
256 {
257 m_mapFileFmt = aMapFmt;
258 }
259
269 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
270
319 bool GenDrillReportFile( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
320
324 wxString GetDrillFileExt() const { return m_drillFileExtension; }
325
326 const std::vector<wxString>& GetCreatedFiles() const { return m_createdFiles; }
327
328protected:
340 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
341
354 void buildHolesList( const DRILL_SPAN& aSpan, bool aGenerateNPTH_list );
355
356 int getHolesCount() const { return m_holeListBuffer.size(); }
357
367 bool plotDrillMarks( PLOTTER* aPlotter );
368
370 std::vector<DRILL_SPAN> getUniqueLayerPairs() const;
371
379
386 unsigned printToolSummary( FILE* out, TOOL_SUMMARY aSummary ) const;
387
393 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
394
399 const std::string layerName( PCB_LAYER_ID aLayer ) const;
400
410 virtual const wxString getDrillFileName( const DRILL_SPAN& aSpan, bool aNPTH,
411 bool aMerge_PTH_NPTH ) const;
412
413
420 virtual const wxString getProtectionFileName( const DRILL_SPAN& aSpan,
421 IPC4761_FEATURES aFeature ) const;
422
423
435 const wxString BuildFileFunctionAttributeString( const DRILL_SPAN& aSpan,
436 TYPE_FILE aHoleType,
437 bool aCompatNCdrill = false ) const;
438
439
440protected:
441 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
443 {
444 m_pcb = aPcb;
445 m_conversionUnits = 1.0;
446 m_unitsMetric = true;
448 m_pageInfo = nullptr;
449 m_merge_PTH_NPTH = false;
451 }
452
453 void AddCreatedFile( const wxString& aPath ) { m_createdFiles.emplace_back( aPath ); }
454
456 wxString m_drillFileExtension; // .drl or .gbr, depending on format
457 bool m_unitsMetric; // true = mm, false = inches
458 ZEROS_FMT m_zeroFormat; // the zero format option for output file
459 DRILL_PRECISION m_precision; // The current coordinate precision (not
460 // used in decimal format).
461 double m_conversionUnits; // scaling factor to convert the board
462 // unites to Excellon/Gerber units (i.e
463 // inches or mm)
464 VECTOR2I m_offset; // Drill offset coordinates
465 bool m_merge_PTH_NPTH; // True to generate only one drill file
466 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
467 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
468
469 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
470 // if this map is needed
471 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
472 // If NULL, use a A4 page format
473 std::vector<wxString> m_createdFiles;
474};
475
476#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:409
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
unsigned printToolSummary(FILE *out, TOOL_SUMMARY aSummary) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
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.
void AddCreatedFile(const wxString &aPath)
std::vector< HOLE_INFO > m_holeListBuffer
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_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
std::vector< wxString > m_createdFiles
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
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: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 classification and drill span, shared by the drill model and the drill writers.
HOLE_ATTRIBUTE
Definition drill_span.h:36
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Definition drill_span.h:48
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:422
static const bool FILLED
Definition gr_basic.cpp:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:75
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:63
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683