KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_file_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_FILE_WRITER_BASE_H
30#define GENDRILL_FILE_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 <vector>
39#include <string>
40
41#include <layer_ids.h>
42#include <plotters/plotter.h>
43
44
45class BOARD;
46class BOARD_ITEM;
47class OUTPUTFORMATTER;
48class PAGE_INFO;
49class REPORTER;
50
51// hole attribute, mainly to identify vias and pads and add this info as comment
52// in NC drill files
54{
55 HOLE_UNKNOWN, // uninitialized type
56 HOLE_VIA_THROUGH, // a via hole (always plated) from top to bottom
57 HOLE_VIA_BURIED, // a via hole (always plated) not through hole
58 HOLE_PAD, // a plated or not plated pad hole
59 HOLE_PAD_CASTELLATED, // a plated castelleted pad hole
60 HOLE_PAD_PRESSFIT, // a plated press-fit pad hole
61 HOLE_MECHANICAL // a mechanical pad (provided, not used)
62};
63
64// Via Protection features according to IPC-4761.
76
77// the DRILL_TOOL class handles tools used in the excellon drill file:
79{
80public:
81 int m_Diameter; // the diameter of the used tool
82 // (for oblong, the smaller size)
83 int m_TotalCount; // how many times it is used (round and oblong)
84 int m_OvalCount; // oblong count
85 bool m_Hole_NotPlated; // Is the hole plated or not plated
86 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
87
88public:
89 DRILL_TOOL( int aDiameter, bool a_NotPlated )
90 {
91 m_TotalCount = 0;
92 m_OvalCount = 0;
93 m_Diameter = aDiameter;
94 m_Hole_NotPlated = a_NotPlated;
96 }
97};
98
99
108{
109public:
111 {
112 m_ItemParent = nullptr;
113 m_Hole_NotPlated = false;
114 m_Hole_Diameter = 0;
117 m_Hole_Shape = 0;
121 m_Hole_Filled = false;
122 m_Hole_Capped = false;
123 m_Hole_Top_Covered = false;
124 m_Hole_Bot_Covered = false;
125 m_Hole_Top_Plugged = false;
126 m_Hole_Bot_Plugged = false;
127 m_Hole_Top_Tented = false;
128 m_Hole_Bot_Tented = false;
129 }
130
131public:
132 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
133 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
134 // size y).
135 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
136 // must not be used).
137 VECTOR2I m_Hole_Size; // hole size for oblong holes
138 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
139 int m_Hole_Shape; // hole shape: round (0) or oval (1)
140 VECTOR2I m_Hole_Pos; // hole position
141 PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
142 PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
143 // m_Hole_Top_Layer < m_Hole_Bottom_Layer
144 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
145 // section.
146 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
147 // by type.
148
149 bool m_Hole_Filled; // hole should be filled
150 bool m_Hole_Capped; // hole should be capped
151 bool m_Hole_Top_Covered; // hole should be covered on top
152 bool m_Hole_Bot_Covered; // hole should be covered on bottom
153 bool m_Hole_Top_Plugged; // hole should be plugged on top
154 bool m_Hole_Bot_Plugged; // hole should be plugged on bottom
155 bool m_Hole_Top_Tented; // hole should be tented on top
156 bool m_Hole_Bot_Tented; // hole should be tented on bottom
157};
158
159
164{
165public:
166 DRILL_PRECISION( int l = 2, int r = 4 )
167 {
168 m_Lhs = l; m_Rhs = r;
169 }
170
171
173 {
174 wxString text;
175
176 text << m_Lhs << wxT( ":" ) << m_Rhs;
177 return text;
178 }
179
180 int m_Lhs; // Left digit number (integer value of coordinates)
181 int m_Rhs; // Right digit number (decimal value of coordinates)
182};
183
184
185typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
186
193{
194public:
195 enum ZEROS_FMT { // Zero format in coordinates
196 DECIMAL_FORMAT, // Floating point coordinates
197 SUPPRESS_LEADING, // Suppress leading zeros
198 SUPPRESS_TRAILING, // Suppress trailing zeros
199 KEEP_ZEROS // keep zeros
200 };
201
202 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
203 PTH_FILE, // PTH only, this is the default also for blind/buried holes
204 NPTH_FILE, // NPTH only
205 MIXED_FILE // PHT+NPTH (mixed)
206 };
207
209 {
210 }
211
218 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
219
224
232 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
233
242 {
243 m_mapFileFmt = aMapFmt;
244 }
245
255 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
256
305 bool GenDrillReportFile( const wxString& aFullFileName );
306
310 wxString GetDrillFileExt() const { return m_drillFileExtension; }
311
312protected:
324 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
325
338 void buildHolesList( DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list );
339
340 int getHolesCount() const { return m_holeListBuffer.size(); }
341
351 bool plotDrillMarks( PLOTTER* aPlotter );
352
354 std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
355
362 unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
363
369 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
370
375 const std::string layerName( PCB_LAYER_ID aLayer ) const;
376
386 virtual const wxString getDrillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
387 bool aMerge_PTH_NPTH ) const;
388
389
396 virtual const wxString getProtectionFileName( DRILL_LAYER_PAIR aPair,
397 IPC4761_FEATURES aFeature ) const;
398
399
411 const wxString BuildFileFunctionAttributeString( DRILL_LAYER_PAIR aLayerPair,
412 TYPE_FILE aHoleType,
413 bool aCompatNCdrill = false ) const;
414
415
416protected:
417 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
419 {
420 m_pcb = aPcb;
421 m_conversionUnits = 1.0;
422 m_unitsMetric = true;
424 m_pageInfo = nullptr;
425 m_merge_PTH_NPTH = false;
427 }
428
430 wxString m_drillFileExtension; // .drl or .gbr, depending on format
431 bool m_unitsMetric; // true = mm, false = inches
432 ZEROS_FMT m_zeroFormat; // the zero format option for output file
433 DRILL_PRECISION m_precision; // The current coordinate precision (not
434 // used in decimal format).
435 double m_conversionUnits; // scaling factor to convert the board
436 // unites to Excellon/Gerber units (i.e
437 // inches or mm)
438 VECTOR2I m_offset; // Drill offset coordinates
439 bool m_merge_PTH_NPTH; // True to generate only one drill file
440 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
441 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
442
443 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
444 // if this map is needed
445 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
446 // If NULL, use a A4 page format
447};
448
449#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:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
Helper to handle drill precision format in excellon files.
DRILL_PRECISION(int l=2, int r=4)
HOLE_ATTRIBUTE m_HoleAttribute
DRILL_TOOL(int aDiameter, bool a_NotPlated)
wxString GetDrillFileExt() const
Returns the file extension of the drill writer format.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
void SetMapFileFormat(PLOT_FORMAT aMapFmt)
Initialize the format for the drill map file.
void buildHolesList(DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
const wxString BuildFileFunctionAttributeString(DRILL_LAYER_PAIR aLayerPair, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
unsigned printToolSummary(OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
virtual const wxString getProtectionFileName(DRILL_LAYER_PAIR aPair, IPC4761_FEATURES aFeature) const
std::vector< HOLE_INFO > m_holeListBuffer
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
bool GenDrillReportFile(const wxString &aFullFileName)
Create a plain text report file giving a list of drill values and drill count for through holes,...
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
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.
PCB_LAYER_ID m_Hole_Bottom_Layer
PCB_LAYER_ID m_Hole_Top_Layer
HOLE_ATTRIBUTE m_HoleAttribute
BOARD_ITEM * m_ItemParent
An interface used to output 8 bit text in a convenient way.
Definition richio.h:322
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:121
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
@ F_Cu
Definition layer_ids.h:64
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695