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-2017 KiCad Developers, see change_log.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 #include <vector>
33 
34 class BOARD_ITEM;
35 
36 
37 // the DRILL_TOOL class handles tools used in the excellon drill file:
39 {
40 public:
41  int m_Diameter; // the diameter of the used tool (for oblong, the smaller size)
42  int m_TotalCount; // how many times it is used (round and oblong)
43  int m_OvalCount; // oblong count
44  bool m_Hole_NotPlated; // Is the hole plated or not plated
45 
46 public:
47  DRILL_TOOL( int aDiameter, bool a_NotPlated )
48  {
49  m_TotalCount = 0;
50  m_OvalCount = 0;
51  m_Diameter = aDiameter;
52  m_Hole_NotPlated = a_NotPlated;
53  }
54 };
55 
56 
57 /* the HOLE_INFO class handle hole which must be drilled (diameter, position and layers)
58  * For buried or micro vias, the hole is not on all layers.
59  * So we must generate a drill file for each layer pair (adjacent layers)
60  * Not plated holes are always through holes, and must be output on a specific drill file
61  * because they are drilled after the Pcb process is finished.
62  */
63 class HOLE_INFO
64 {
65 public:
66  BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
67  int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole size y)
68  int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0 must not be used)
69  wxSize m_Hole_Size; // hole size for oblong holes
70  double m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
71  int m_Hole_Shape; // hole shape: round (0) or oval (1)
72  wxPoint m_Hole_Pos; // hole position
73  PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
74  PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
75  // m_Hole_Top_Layer < m_Hole_Bottom_Layer
76  bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or section
77 
78 public:
80  {
81  m_ItemParent = nullptr;
82  m_Hole_NotPlated = false;
83  m_Hole_Diameter = 0;
84  m_Tool_Reference = 0;
85  m_Hole_Orient = 0.0;
86  m_Hole_Shape = 0;
87  m_Hole_Bottom_Layer = B_Cu;
88  m_Hole_Top_Layer = F_Cu;
89  }
90 };
91 
92 
93 /* the DRILL_PRECISION helper class to handle drill precision format in excellon files
94  */
96 {
97 public:
98  int m_lhs; // Left digit number (integer value of coordinates)
99  int m_rhs; // Right digit number (decimal value of coordinates)
100 
101 public:
102  DRILL_PRECISION( int l = 2, int r = 4 )
103  {
104  m_lhs = l; m_rhs = r;
105  }
106 
107 
109  {
110  wxString text;
111 
112  text << m_lhs << wxT( ":" ) << m_rhs;
113  return text;
114  }
115 };
116 
117 
118 typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
119 
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 protected:
138  wxString m_drillFileExtension; // .drl or .gbr, depending on format
139  bool m_unitsMetric; // true = mm, false = inches
140  ZEROS_FMT m_zeroFormat; // the zero format option for output file
141  DRILL_PRECISION m_precision; // The current coordinate precision (not used in decimal format)
142  double m_conversionUnits; // scaling factor to convert the board unites to
143  // Excellon/Gerber units (i.e inches or mm)
144  wxPoint m_offset; // Drill offset coordinates
145  bool m_merge_PTH_NPTH; // True to generate only one drill file
146  std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
147  std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
148 
149  PlotFormat m_mapFileFmt; // the format of the map drill file,
150  // if this map is needed
151  const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
152  // If NULL, use a A4 page format
153  // This Ctor is protected.
154  // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
156  {
157  m_pcb = aPcb;
158  m_conversionUnits = 1.0;
159  m_unitsMetric = true;
160  m_mapFileFmt = PLOT_FORMAT_PDF;
161  m_pageInfo = NULL;
162  m_merge_PTH_NPTH = false;
163  m_zeroFormat = DECIMAL_FORMAT;
164  }
165 
166 public:
168  {
169  }
170 
176  void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
177 
182  const wxPoint GetOffset() { return m_offset; }
183 
189  void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
190 
198  void SetMapFileFormat( PlotFormat aMapFmt ) { m_mapFileFmt = aMapFmt; }
199 
208  void CreateMapFilesSet( const wxString& aPlotDirectory,
209  REPORTER* aReporter = NULL );
210 
262  bool GenDrillReportFile( const wxString& aFullFileName );
263 
264 protected:
276  bool genDrillMapFile( const wxString& aFullFileName, PlotFormat aFormat );
277 
291  void buildHolesList( DRILL_LAYER_PAIR aLayerPair,
292  bool aGenerateNPTH_list );
293 
294  int getHolesCount() const { return m_holeListBuffer.size(); }
295 
304  bool plotDrillMarks( PLOTTER* aPlotter );
305 
307  std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
308 
315  unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
316 
323  const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
324 
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 
345 #endif // #define GENDRILL_FILE_WRITER_BASE_H
346 
BOARD_ITEM * m_ItemParent
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:50
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
void SetMergeOption(bool aMerge)
set the option to make separate drill files for PTH and NPTH
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
std::vector< DRILL_TOOL > m_toolListBuffer
PCB_LAYER_ID
A quick note on layer IDs:
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
PCB_LAYER_ID m_Hole_Bottom_Layer
PCB_LAYER_ID m_Hole_Top_Layer
Base plotter engine class.
Definition: plotter.h:97
const wxPoint GetOffset()
Return the plot offset (usually the position of the auxiliary axis.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
DRILL_TOOL(int aDiameter, bool a_NotPlated)
void SetPageInfo(const PAGE_INFO *aPageInfo)
Sets the page info used to plot drill maps If NULL, a A4 page format will be used.
std::vector< HOLE_INFO > m_holeListBuffer
DRILL_PRECISION(int l=2, int r=4)
GENDRILL_WRITER_BASE is a class to create drill maps and drill report, and a helper class to created ...
void SetMapFileFormat(PlotFormat aMapFmt)
Initialize the format for the drill map file.