KiCad PCB EDA Suite
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 (C) 1992-2021 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 
40 class BOARD_ITEM;
41 
42 // hole attribute, mainly to identify vias and pads and add this info as comment
43 // in NC drill files
44 enum class HOLE_ATTRIBUTE
45 {
46  HOLE_UNKNOWN, // uninitialized type
47  HOLE_VIA_THROUGH, // a via hole (always plated) from top to bottom
48  HOLE_VIA_BURIED, // a via hole (always plated) not through hole
49  HOLE_PAD, // a plated or not plated pad hole
50  HOLE_MECHANICAL // a mechanical pad (provided, not used)
51 };
52 
53 
54 // the DRILL_TOOL class handles tools used in the excellon drill file:
56 {
57 public:
58  int m_Diameter; // the diameter of the used tool
59  // (for oblong, the smaller size)
60  int m_TotalCount; // how many times it is used (round and oblong)
61  int m_OvalCount; // oblong count
62  bool m_Hole_NotPlated; // Is the hole plated or not plated
63  HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
64 
65 public:
66  DRILL_TOOL( int aDiameter, bool a_NotPlated )
67  {
68  m_TotalCount = 0;
69  m_OvalCount = 0;
70  m_Diameter = aDiameter;
71  m_Hole_NotPlated = a_NotPlated;
73  }
74 };
75 
76 
84 class HOLE_INFO
85 {
86 public:
88  {
89  m_ItemParent = nullptr;
90  m_Hole_NotPlated = false;
91  m_Hole_Diameter = 0;
92  m_Tool_Reference = 0;
93  m_Hole_Orient = 0.0;
94  m_Hole_Shape = 0;
98  }
99 
100 public:
101  BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
102  int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
103  // size y).
104  int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
105  // must not be used).
106  wxSize m_Hole_Size; // hole size for oblong holes
107  double m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
108  int m_Hole_Shape; // hole shape: round (0) or oval (1)
109  wxPoint m_Hole_Pos; // hole position
110  PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
111  PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
112  // m_Hole_Top_Layer < m_Hole_Bottom_Layer
113  bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
114  // section.
115  HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
116  // by type.
117 };
118 
119 
124 {
125 public:
126  DRILL_PRECISION( int l = 2, int r = 4 )
127  {
128  m_Lhs = l; m_Rhs = r;
129  }
130 
131 
133  {
134  wxString text;
135 
136  text << m_Lhs << wxT( ":" ) << m_Rhs;
137  return text;
138  }
139 
140  int m_Lhs; // Left digit number (integer value of coordinates)
141  int m_Rhs; // Right digit number (decimal value of coordinates)
142 };
143 
144 
145 typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
146 
153 {
154 public:
155  enum ZEROS_FMT { // Zero format in coordinates
156  DECIMAL_FORMAT, // Floating point coordinates
157  SUPPRESS_LEADING, // Suppress leading zeros
158  SUPPRESS_TRAILING, // Suppress trailing zeros
159  KEEP_ZEROS // keep zeros
160  };
161 
162  enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
163  PTH_FILE, // PTH only, this is the default also for blind/buried holes
164  NPTH_FILE, // NPTH only
165  MIXED_FILE // PHT+NPTH (mixed)
166  };
167 
169  {
170  }
171 
178  void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
179 
183  wxPoint GetOffset() { return m_offset; }
184 
192  void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
193 
202  {
203  m_mapFileFmt = aMapFmt;
204  }
205 
215  void CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
216 
265  bool GenDrillReportFile( const wxString& aFullFileName );
266 
267 protected:
279  bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
280 
293  void buildHolesList( DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list );
294 
295  int getHolesCount() const { return m_holeListBuffer.size(); }
296 
306  bool plotDrillMarks( PLOTTER* aPlotter );
307 
309  std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
310 
317  unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
318 
324  const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
325 
330  const std::string layerName( PCB_LAYER_ID aLayer ) const;
331 
341  virtual const wxString getDrillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
342  bool aMerge_PTH_NPTH ) const;
343 
344 
356  const wxString BuildFileFunctionAttributeString( DRILL_LAYER_PAIR aLayerPair,
357  TYPE_FILE aHoleType,
358  bool aCompatNCdrill = false ) const;
359 
360 
361 protected:
362  // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
364  {
365  m_pcb = aPcb;
366  m_conversionUnits = 1.0;
367  m_unitsMetric = true;
369  m_pageInfo = nullptr;
370  m_merge_PTH_NPTH = false;
372  }
373 
375  wxString m_drillFileExtension; // .drl or .gbr, depending on format
376  bool m_unitsMetric; // true = mm, false = inches
377  ZEROS_FMT m_zeroFormat; // the zero format option for output file
378  DRILL_PRECISION m_precision; // The current coordinate precision (not
379  // used in decimal format).
380  double m_conversionUnits; // scaling factor to convert the board
381  // unites to Excellon/Gerber units (i.e
382  // inches or mm)
383  wxPoint m_offset; // Drill offset coordinates
384  bool m_merge_PTH_NPTH; // True to generate only one drill file
385  std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
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 };
393 
394 #endif // #define GENDRILL_FILE_WRITER_BASE_H
unsigned printToolSummary(OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
BOARD_ITEM * m_ItemParent
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=nullptr)
Create the full set of map files for the board, in PS, PDF ...
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:309
void SetMergeOption(bool aMerge)
Set the option to make separate drill files for PTH and NPTH.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
HOLE_ATTRIBUTE m_HoleAttribute
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
Helper to handle drill precision format in excellon files.
std::vector< DRILL_TOOL > m_toolListBuffer
void SetMapFileFormat(PLOT_FORMAT aMapFmt)
Initialize the format for the drill map file.
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
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:67
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
const wxString BuildFileFunctionAttributeString(DRILL_LAYER_PAIR aLayerPair, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
Handle hole which must be drilled (diameter, position and layers).
wxPoint GetOffset()
Return the plot offset (usually the position of the drill/place origin).
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
E_SERIE r
Definition: eserie.cpp:41
void buildHolesList(DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
PCB_LAYER_ID m_Hole_Bottom_Layer
HOLE_ATTRIBUTE m_HoleAttribute
PCB_LAYER_ID m_Hole_Top_Layer
Base plotter engine class.
Definition: plotter.h:121
const std::string layerName(PCB_LAYER_ID aLayer) const
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
bool genDrillMapFile(const wxString &aFullFileName, PLOT_FORMAT aFormat)
Plot a map of drill marks for holes.
DRILL_TOOL(int aDiameter, bool a_NotPlated)
bool plotDrillMarks(PLOTTER *aPlotter)
Write the drill marks in HPGL, POSTSCRIPT or other supported formats/.
void SetPageInfo(const PAGE_INFO *aPageInfo)
Set the page info used to plot drill maps.
std::vector< HOLE_INFO > m_holeListBuffer
DRILL_PRECISION(int l=2, int r=4)
Create drill maps and drill reports and drill files.