KiCad PCB EDA Suite
gendrill_Excellon_writer.h
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 1992-2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
10  * Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #ifndef _GENDRILL_EXCELLON_WRITER_
31 #define _GENDRILL_EXCELLON_WRITER_
32 
33 #include <vector>
34 
35 
36 class BOARD;
37 class PLOTTER;
38 
39 
40 // the DRILL_TOOL class handles tools used in the excellon drill file:
42 {
43 public:
44  int m_Diameter; // the diameter of the used tool (for oblong, the smaller size)
45  int m_TotalCount; // how many times it is used (round and oblong)
46  int m_OvalCount; // oblong count
47  bool m_Hole_NotPlated; // Is the hole plated or not plated
48 
49 public:
50  DRILL_TOOL( int aDiameter, bool a_NotPlated )
51  {
52  m_TotalCount = 0;
53  m_OvalCount = 0;
54  m_Diameter = aDiameter;
55  m_Hole_NotPlated = a_NotPlated;
56  }
57 };
58 
59 
60 /* the HOLE_INFO class handle hole which must be drilled (diameter, position and layers)
61  * For buried or micro vias, the hole is not on all layers.
62  * So we must generate a drill file for each layer pair (adjacent layers)
63  * Not plated holes are always through holes, and must be output on a specific drill file
64  * because they are drilled after the Pcb process is finished.
65  */
66 class HOLE_INFO
67 {
68 public:
69  int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole size y)
70  int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0 must not be used)
71  wxSize m_Hole_Size; // hole size for oblong holes
72  double m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
73  int m_Hole_Shape; // hole shape: round (0) or oval (1)
74  wxPoint m_Hole_Pos; // hole position
75  LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
76  LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
77  // m_Hole_Top_Layer < m_Hole_Bottom_Layer
78  bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or section
79 
80 public:
82  {
83  m_Hole_NotPlated = false;
84  m_Hole_Diameter = 0;
85  m_Tool_Reference = 0;
86  m_Hole_Orient = 0.0;
87  m_Hole_Shape = 0;
88  m_Hole_Bottom_Layer = B_Cu;
89  m_Hole_Top_Layer = F_Cu;
90  }
91 };
92 
93 
94 /* the DRILL_PRECISION helper class to handle drill precision format in excellon files
95  */
97 {
98 public:
99  int m_lhs; // Left digit number (integer value of coordinates)
100  int m_rhs; // Right digit number (decimal value of coordinates)
101 
102 public:
103  DRILL_PRECISION( int l = 2, int r = 4 )
104  {
105  m_lhs = l; m_rhs = r;
106  }
107 
108 
110  {
111  wxString text;
112 
113  text << m_lhs << wxT( ":" ) << m_rhs;
114  return text;
115  }
116 };
117 
118 
119 typedef std::pair<LAYER_ID, LAYER_ID> DRILL_LAYER_PAIR;
120 class OUTPUTFORMATTER;
121 
127 {
128 public:
129  enum ZEROS_FMT { // Zero format in coordinates
130  DECIMAL_FORMAT, // Floating point coordinates
131  SUPPRESS_LEADING, // Suppress leading zeros
132  SUPPRESS_TRAILING, // Suppress trainling zeros
133  KEEP_ZEROS // keep zeros
134  };
135 
136  wxPoint m_Offset; // offset coordinates
137  bool m_ShortHeader; // true to generate the smallest header (strip comments)
138 
139 private:
140  FILE* m_file; // The output file
142  bool m_minimalHeader; // True to use minimal header
143  // in excellon file (strip comments)
144  bool m_unitsDecimal; // true = decimal, false = inches
145  ZEROS_FMT m_zeroFormat; // the zero format option for output file
146  DRILL_PRECISION m_precision; // The current coordinate precision (not used in decimal format)
147  double m_conversionUnits; // scaling factor to convert the board unites to Excellon units
148  // (i.e inches or mm)
149  bool m_mirror;
150  wxPoint m_offset; // Drill offset coordinates
151  bool m_merge_PTH_NPTH; // True to generate only one drill file
152  std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
153  std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
154 
155  PlotFormat m_mapFileFmt; // the format of the map drill file,
156  // if this map is needed
157  const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
158  // If NULL, use a A4 page format
159 
160 public:
161  EXCELLON_WRITER( BOARD* aPcb );
162 
164  {
165  }
166 
171  const wxPoint GetOffset() { return m_offset; }
172 
183  void SetFormat( bool aMetric, ZEROS_FMT aZerosFmt = DECIMAL_FORMAT,
184  int aLeftDigits = 0, int aRightDigits = 0 );
185 
191  void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
192 
201  void SetMapFileFormat( PlotFormat aMapFmt ) { m_mapFileFmt = aMapFmt; }
202 
203 
211  void SetOptions( bool aMirror, bool aMinimalHeader, wxPoint aOffset, bool aMerge_PTH_NPTH )
212  {
213  m_mirror = aMirror;
214  m_offset = aOffset;
215  m_minimalHeader = aMinimalHeader;
216  m_merge_PTH_NPTH = aMerge_PTH_NPTH;
217  }
218 
228  void CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
229  bool aGenDrill, bool aGenMap,
230  REPORTER * aReporter = NULL );
231 
284  bool GenDrillReportFile( const wxString& aFullFileName );
285 
295  bool GenDrillMapFile( const wxString& aFullFileName, PlotFormat aFormat );
296 
297 private:
304  int createDrillFile( FILE * aFile );
305 
319  void buildHolesList( DRILL_LAYER_PAIR aLayerPair,
320  bool aGenerateNPTH_list );
321 
322  int getHolesCount() const { return m_holeListBuffer.size(); }
323 
324  /* Print the DRILL file header. The full header is:
325  * M48
326  * ;DRILL file {PCBNEW (2007-11-29-b)} date 17/1/2008-21:02:35
327  * ;FORMAT={ <precision> / absolute / <units> / <numbers format>}
328  * FMAT,2
329  * INCH,TZ
330  */
331  void writeEXCELLONHeader();
332 
333  void writeEXCELLONEndOfFile();
334 
335  /* Created a line like:
336  * X48000Y19500
337  * According to the selected format
338  */
339  void writeCoordinates( char* aLine, double aCoordX, double aCoordY );
340 
349  bool plotDrillMarks( PLOTTER* aPlotter );
350 
352  std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
353 
360  unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
361 
362  const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
363 
364  const std::string layerName( LAYER_ID aLayer ) const;
365 
375  const wxString drillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
376  bool aMerge_PTH_NPTH ) const;
377 };
378 
379 #endif // #ifndef _GENDRILL_EXCELLON_WRITER_
std::vector< DRILL_TOOL > m_toolListBuffer
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plot_common.h:49
EXCELLON_WRITER is a class mainly used to create Excellon drill files However, this class is also use...
const wxString drillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
void buildHolesList(DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
Function BuildHolesList Create the list of holes and tools for a given board The list is sorted by in...
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void SetMapFileFormat(PlotFormat aMapFmt)
Function SetMapFileFormat Initialize the format for the drill map file.
std::pair< LAYER_ID, LAYER_ID > DRILL_LAYER_PAIR
unsigned printToolSummary(OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
Function printToolSummary prints m_toolListBuffer[] tools to aOut and returns total hole count...
const std::string layerName(LAYER_ID aLayer) const
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Function SetFormat Initialize internal parameters to match the given format.
LAYER_ID m_Hole_Bottom_Layer
int createDrillFile(FILE *aFile)
Function CreateDrillFile Creates an Excellon drill file.
void writeCoordinates(char *aLine, double aCoordX, double aCoordY)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
bool plotDrillMarks(PLOTTER *aPlotter)
Helper function.
const PAGE_INFO * m_pageInfo
void SetPageInfo(const PAGE_INFO *aPageInfo)
Sets the page info used to plot drill maps If NULL, a A4 page format will be used.
void CreateDrillandMapFilesSet(const wxString &aPlotDirectory, bool aGenDrill, bool aGenMap, REPORTER *aReporter=NULL)
Function CreateDrillandMapFilesSet Creates the full set of Excellon drill file for the board filename...
Base plotter engine class.
Definition: plot_common.h:86
DRILL_PRECISION m_precision
bool GenDrillMapFile(const wxString &aFullFileName, PlotFormat aFormat)
Function GenDrillMapFile Plot a map of drill marks for holes.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
std::vector< HOLE_INFO > m_holeListBuffer
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
bool GenDrillReportFile(const wxString &aFullFileName)
Function GenDrillReportFile Create a plain text report file giving a list of drill values and drill c...
DRILL_TOOL(int aDiameter, bool a_NotPlated)
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
const wxPoint GetOffset()
Return the plot offset (usually the position of the auxiliary axis.
void SetOptions(bool aMirror, bool aMinimalHeader, wxPoint aOffset, bool aMerge_PTH_NPTH)
Function SetOptions Initialize internal parameters to match drill options.
DRILL_PRECISION(int l=2, int r=4)