KiCad PCB EDA Suite
EXCELLON_WRITER Class Reference

EXCELLON_WRITER is a class mainly used to create Excellon drill files However, this class is also used to create drill maps and drill report. More...

#include <gendrill_Excellon_writer.h>

Inheritance diagram for EXCELLON_WRITER:
GENDRILL_WRITER_BASE

Public Types

enum  ZEROS_FMT { DECIMAL_FORMAT, SUPPRESS_LEADING, SUPPRESS_TRAILING, KEEP_ZEROS }
 

Public Member Functions

 EXCELLON_WRITER (BOARD *aPcb)
 
virtual ~EXCELLON_WRITER ()
 
const wxPoint GetOffset ()
 Return the plot offset (usually the position of the auxiliary axis. More...
 
void SetRouteModeForOvalHoles (bool aUseRouteModeForOvalHoles)
 
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. More...
 
void SetOptions (bool aMirror, bool aMinimalHeader, wxPoint aOffset, bool aMerge_PTH_NPTH)
 Function SetOptions Initialize internal parameters to match drill options. More...
 
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 filenames are computed from the board name, and layers id. More...
 
void SetMergeOption (bool aMerge)
 set the option to make separate drill files for PTH and NPTH More...
 
void SetPageInfo (const PAGE_INFO *aPageInfo)
 Sets the page info used to plot drill maps If NULL, a A4 page format will be used. More...
 
void SetMapFileFormat (PlotFormat aMapFmt)
 Initialize the format for the drill map file. More...
 
void CreateMapFilesSet (const wxString &aPlotDirectory, REPORTER *aReporter=NULL)
 Function CreateMapFilesSet Creates the full set of map files for the board, in PS, PDF ... More...
 
bool GenDrillReportFile (const wxString &aFullFileName)
 Function GenDrillReportFile Create a plain text report file giving a list of drill values and drill count for through holes, oblong holes, and for buried vias, drill values and drill count per layer pair there is only one report for all drill files even when buried or blinds vias exist. More...
 

Protected Member Functions

bool genDrillMapFile (const wxString &aFullFileName, PlotFormat aFormat)
 Function GenDrillMapFile Plot a map of drill marks for holes. More...
 
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 increasing drill size. More...
 
int getHolesCount () const
 
bool plotDrillMarks (PLOTTER *aPlotter)
 Helper function. More...
 
std::vector< DRILL_LAYER_PAIRgetUniqueLayerPairs () const
 Get unique layer pairs by examining the micro and blind_buried vias. More...
 
unsigned printToolSummary (OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
 Function printToolSummary prints m_toolListBuffer[] tools to aOut and returns total hole count. More...
 
const std::string layerPairName (DRILL_LAYER_PAIR aPair) const
 minor helper function. More...
 
const std::string layerName (PCB_LAYER_ID aLayer) const
 minor helper function. More...
 
virtual const wxString getDrillFileName (DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
 
const wxString BuildFileFunctionAttributeString (DRILL_LAYER_PAIR aLayerPair, bool aIsNpth, bool aCompatNCdrill=false) const
 

Protected Attributes

BOARDm_pcb
 
wxString m_drillFileExtension
 
bool m_unitsMetric
 
ZEROS_FMT m_zeroFormat
 
DRILL_PRECISION m_precision
 
double m_conversionUnits
 
wxPoint m_offset
 
bool m_merge_PTH_NPTH
 
std::vector< HOLE_INFOm_holeListBuffer
 
std::vector< DRILL_TOOLm_toolListBuffer
 
PlotFormat m_mapFileFmt
 
const PAGE_INFOm_pageInfo
 

Private Member Functions

int createDrillFile (FILE *aFile, DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
 Function CreateDrillFile Creates an Excellon drill file. More...
 
void writeEXCELLONHeader (DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
 
void writeEXCELLONEndOfFile ()
 
void writeCoordinates (char *aLine, double aCoordX, double aCoordY)
 

Private Attributes

FILE * m_file
 
bool m_minimalHeader
 
bool m_mirror
 
bool m_useRouteModeForOval
 

Detailed Description

EXCELLON_WRITER is a class mainly used to create Excellon drill files However, this class is also used to create drill maps and drill report.

Definition at line 44 of file gendrill_Excellon_writer.h.

Member Enumeration Documentation

◆ ZEROS_FMT

Enumerator
DECIMAL_FORMAT 
SUPPRESS_LEADING 
SUPPRESS_TRAILING 
KEEP_ZEROS 

Definition at line 129 of file gendrill_file_writer_base.h.

129  { // 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  };

Constructor & Destructor Documentation

◆ EXCELLON_WRITER()

EXCELLON_WRITER::EXCELLON_WRITER ( BOARD aPcb)
See also
for EXCELLON format, see: http://www.excellon.com/manuals/program.htm and the CNC-7 manual.

Definition at line 65 of file gendrill_Excellon_writer.cpp.

References GENDRILL_WRITER_BASE::DECIMAL_FORMAT, DrillFileExtension, GENDRILL_WRITER_BASE::m_conversionUnits, GENDRILL_WRITER_BASE::m_drillFileExtension, m_file, GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, m_minimalHeader, m_mirror, m_useRouteModeForOval, and GENDRILL_WRITER_BASE::m_zeroFormat.

◆ ~EXCELLON_WRITER()

virtual EXCELLON_WRITER::~EXCELLON_WRITER ( )
inlinevirtual

Definition at line 57 of file gendrill_Excellon_writer.h.

58  {
59  }

Member Function Documentation

◆ BuildFileFunctionAttributeString()

const wxString GENDRILL_WRITER_BASE::BuildFileFunctionAttributeString ( DRILL_LAYER_PAIR  aLayerPair,
bool  aIsNpth,
bool  aCompatNCdrill = false 
) const
protectedinherited
Returns
a wxString containing the .FileFunction attribute. the standard X2 FileFunction for drill files is TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH][Blind][Buried],Drill[Route][Mixed]*% There is no X1 version, as the Gerber drill files uses only X2 format There is a compatible NC drill version.
Parameters
aLayerPairis the layer pair (Drill from rom first layer to second layer)
aIsNpthis true when generating NPTH drill file
aCompatNCdrillis true when generating NC (Excellon) compatible drill file

Definition at line 351 of file gendrill_file_writer_base.cpp.

353 {
354 // Build a wxString containing the .FileFunction attribute for drill files.
355 // %TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH][Blind][Buried],Drill[Route][Mixed]*%
356  wxString text;
357 
358  if( aCompatNCdrill )
359  text = "; #@! ";
360  else
361  text = "%";
362 
363  text << "TF.FileFunction,";
364 
365  if( aIsNpth )
366  text << "NonPlated,";
367  else
368  text << "Plated,";
369 
370  int layer1 = aLayerPair.first;
371  int layer2 = aLayerPair.second;
372  // In Gerber files, layers num are 1 to copper layer count instead of F_Cu to B_Cu
373  // (0 to copper layer count-1)
374  // Note also for a n copper layers board, gerber layers num are 1 ... n
375  layer1 += 1;
376 
377  if( layer2 == B_Cu )
378  layer2 = m_pcb->GetCopperLayerCount();
379  else
380  layer2 += 1;
381 
382  text << layer1 << ",";
383  text << layer2 << ",";
384 
385  // Now add PTH or NPTH or Blind or Buried attribute
386  int toplayer = 1;
387  int bottomlayer = m_pcb->GetCopperLayerCount();
388 
389  if( aIsNpth )
390  text << "NPTH";
391  else if( layer1 == toplayer && layer2 == bottomlayer )
392  text << "PTH";
393  else if( layer1 == toplayer || layer2 == bottomlayer )
394  text << "Blind";
395  else
396  text << "Buried";
397 
398  // In NC drill file, these previous parameters should be enough:
399  if( aCompatNCdrill )
400  return text;
401 
402 
403  // Now add Drill or Route or Mixed:
404  // file containing only round holes have Drill attribute
405  // file containing only oblong holes have Routed attribute
406  // file containing both holes have Mixed attribute
407  bool hasOblong = false;
408  bool hasDrill = false;
409 
410  for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
411  {
412  const HOLE_INFO& hole_descr = m_holeListBuffer[ii];
413 
414  if( hole_descr.m_Hole_Shape ) // m_Hole_Shape not 0 is an oblong hole)
415  hasOblong = true;
416  else
417  hasDrill = true;
418  }
419 
420  if( hasOblong && hasDrill )
421  text << ",Mixed";
422  else if( hasDrill )
423  text << ",Drill";
424  else if( hasOblong )
425  text << ",Route";
426 
427  // else: empty file.
428 
429  // End of .FileFunction attribute:
430  text << "*%";
431 
432  return text;
433 }
int GetCopperLayerCount() const
Function GetCopperLayerCount.
std::vector< HOLE_INFO > m_holeListBuffer

References B_Cu, BOARD::GetCopperLayerCount(), HOLE_INFO::m_Hole_Shape, GENDRILL_WRITER_BASE::m_holeListBuffer, and GENDRILL_WRITER_BASE::m_pcb.

Referenced by GERBER_WRITER::createDrillFile(), and writeEXCELLONHeader().

◆ buildHolesList()

void GENDRILL_WRITER_BASE::buildHolesList ( DRILL_LAYER_PAIR  aLayerPair,
bool  aGenerateNPTH_list 
)
protectedinherited

Function BuildHolesList Create the list of holes and tools for a given board The list is sorted by increasing drill size.

Only holes included within aLayerPair are listed. If aLayerPair identifies with [F_Cu, B_Cu], then pad holes are always included also.

Parameters
aLayerPairis an inclusive range of layers.
aGenerateNPTH_list: true to create NPTH only list (with no plated holes) false to created plated holes list (with no NPTH )

Definition at line 72 of file gendrill_file_writer_base.cpp.

74 {
75  HOLE_INFO new_hole;
76 
77  m_holeListBuffer.clear();
78  m_toolListBuffer.clear();
79 
80  wxASSERT( aLayerPair.first < aLayerPair.second ); // fix the caller
81 
82  // build hole list for vias
83  if( ! aGenerateNPTH_list ) // vias are always plated !
84  {
85  for( auto track : m_pcb->Tracks() )
86  {
87  if( track->Type() != PCB_VIA_T )
88  continue;
89 
90  auto via = static_cast<VIA*>( track );
91  int hole_sz = via->GetDrillValue();
92 
93  if( hole_sz == 0 ) // Should not occur.
94  continue;
95 
96  new_hole.m_ItemParent = via;
97  new_hole.m_Tool_Reference = -1; // Flag value for Not initialized
98  new_hole.m_Hole_Orient = 0;
99  new_hole.m_Hole_Diameter = hole_sz;
100  new_hole.m_Hole_NotPlated = false;
101  new_hole.m_Hole_Size.x = new_hole.m_Hole_Size.y = new_hole.m_Hole_Diameter;
102 
103  new_hole.m_Hole_Shape = 0; // hole shape: round
104  new_hole.m_Hole_Pos = via->GetStart();
105 
106  via->LayerPair( &new_hole.m_Hole_Top_Layer, &new_hole.m_Hole_Bottom_Layer );
107 
108  // LayerPair() returns params with m_Hole_Bottom_Layer > m_Hole_Top_Layer
109  // Remember: top layer = 0 and bottom layer = 31 for through hole vias
110  // Any captured via should be from aLayerPair.first to aLayerPair.second exactly.
111  if( new_hole.m_Hole_Top_Layer != aLayerPair.first ||
112  new_hole.m_Hole_Bottom_Layer != aLayerPair.second )
113  continue;
114 
115  m_holeListBuffer.push_back( new_hole );
116  }
117  }
118 
119  if( aLayerPair == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
120  {
121  // add holes for thru hole pads
122  for( auto module : m_pcb->Modules() )
123  {
124  for( auto& pad : module->Pads() )
125  {
126  if( !m_merge_PTH_NPTH )
127  {
128  if( !aGenerateNPTH_list && pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
129  continue;
130 
131  if( aGenerateNPTH_list && pad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
132  continue;
133  }
134 
135  if( pad->GetDrillSize().x == 0 )
136  continue;
137 
138  new_hole.m_ItemParent = pad;
139  new_hole.m_Hole_NotPlated = (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED);
140  new_hole.m_Tool_Reference = -1; // Flag is: Not initialized
141  new_hole.m_Hole_Orient = pad->GetOrientation();
142  new_hole.m_Hole_Shape = 0; // hole shape: round
143  new_hole.m_Hole_Diameter = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
144  new_hole.m_Hole_Size.x = new_hole.m_Hole_Size.y = new_hole.m_Hole_Diameter;
145 
146  if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
147  new_hole.m_Hole_Shape = 1; // oval flag set
148 
149  new_hole.m_Hole_Size = pad->GetDrillSize();
150  new_hole.m_Hole_Pos = pad->GetPosition(); // hole position
151  new_hole.m_Hole_Bottom_Layer = B_Cu;
152  new_hole.m_Hole_Top_Layer = F_Cu; // pad holes are through holes
153  m_holeListBuffer.push_back( new_hole );
154  }
155  }
156  }
157 
158  // Sort holes per increasing diameter value
159  sort( m_holeListBuffer.begin(), m_holeListBuffer.end(), CmpHoleSorting );
160 
161  // build the tool list
162  int last_hole = -1; // Set to not initialized (this is a value not used
163  // for m_holeListBuffer[ii].m_Hole_Diameter)
164  bool last_notplated_opt = false;
165 
166  DRILL_TOOL new_tool( 0, false );
167  unsigned jj;
168 
169  for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
170  {
171  if( m_holeListBuffer[ii].m_Hole_Diameter != last_hole ||
172  m_holeListBuffer[ii].m_Hole_NotPlated != last_notplated_opt )
173  {
174  new_tool.m_Diameter = m_holeListBuffer[ii].m_Hole_Diameter;
175  new_tool.m_Hole_NotPlated = m_holeListBuffer[ii].m_Hole_NotPlated;
176  m_toolListBuffer.push_back( new_tool );
177  last_hole = new_tool.m_Diameter;
178  last_notplated_opt = new_tool.m_Hole_NotPlated;
179  }
180 
181  jj = m_toolListBuffer.size();
182 
183  if( jj == 0 )
184  continue; // Should not occurs
185 
186  m_holeListBuffer[ii].m_Tool_Reference = jj; // Tool value Initialized (value >= 1)
187 
188  m_toolListBuffer.back().m_TotalCount++;
189 
190  if( m_holeListBuffer[ii].m_Hole_Shape )
191  m_toolListBuffer.back().m_OvalCount++;
192  }
193 }
BOARD_ITEM * m_ItemParent
static bool CmpHoleSorting(const HOLE_INFO &a, const HOLE_INFO &b)
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
std::vector< DRILL_TOOL > m_toolListBuffer
MODULES & Modules()
Definition: class_board.h:236
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
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
std::vector< HOLE_INFO > m_holeListBuffer
TRACKS & Tracks()
Definition: class_board.h:227
#define min(a, b)
Definition: auxiliary.h:85

References B_Cu, CmpHoleSorting(), F_Cu, DRILL_TOOL::m_Diameter, HOLE_INFO::m_Hole_Bottom_Layer, HOLE_INFO::m_Hole_Diameter, DRILL_TOOL::m_Hole_NotPlated, HOLE_INFO::m_Hole_NotPlated, HOLE_INFO::m_Hole_Orient, HOLE_INFO::m_Hole_Pos, HOLE_INFO::m_Hole_Shape, HOLE_INFO::m_Hole_Size, HOLE_INFO::m_Hole_Top_Layer, GENDRILL_WRITER_BASE::m_holeListBuffer, HOLE_INFO::m_ItemParent, GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, GENDRILL_WRITER_BASE::m_pcb, HOLE_INFO::m_Tool_Reference, GENDRILL_WRITER_BASE::m_toolListBuffer, min, BOARD::Modules(), PAD_ATTRIB_HOLE_NOT_PLATED, PAD_DRILL_SHAPE_CIRCLE, PCB_VIA_T, and BOARD::Tracks().

Referenced by GERBER_WRITER::CreateDrillandMapFilesSet(), CreateDrillandMapFilesSet(), GENDRILL_WRITER_BASE::CreateMapFilesSet(), and GENDRILL_WRITER_BASE::GenDrillReportFile().

◆ CreateDrillandMapFilesSet()

void EXCELLON_WRITER::CreateDrillandMapFilesSet ( const wxString &  aPlotDirectory,
bool  aGenDrill,
bool  aGenMap,
REPORTER aReporter = NULL 
)

Function CreateDrillandMapFilesSet Creates the full set of Excellon drill file for the board filenames are computed from the board name, and layers id.

Parameters
aPlotDirectory= the output folder
aGenDrill= true to generate the EXCELLON drill file
aGenMap= true to generate a drill map file
aReporter= a REPORTER to return activity or any message (can be NULL)

Definition at line 79 of file gendrill_Excellon_writer.cpp.

82 {
83  wxFileName fn;
84  wxString msg;
85 
86  std::vector<DRILL_LAYER_PAIR> hole_sets = getUniqueLayerPairs();
87 
88  // append a pair representing the NPTH set of holes, for separate drill files.
89  if( !m_merge_PTH_NPTH )
90  hole_sets.push_back( DRILL_LAYER_PAIR( F_Cu, B_Cu ) );
91 
92  for( std::vector<DRILL_LAYER_PAIR>::const_iterator it = hole_sets.begin();
93  it != hole_sets.end(); ++it )
94  {
95  DRILL_LAYER_PAIR pair = *it;
96  // For separate drill files, the last layer pair is the NPTH drill file.
97  bool doing_npth = m_merge_PTH_NPTH ? false : ( it == hole_sets.end() - 1 );
98 
99  buildHolesList( pair, doing_npth );
100 
101  // The file is created if it has holes, or if it is the non plated drill file
102  // to be sure the NPTH file is up to date in separate files mode.
103  if( getHolesCount() > 0 || doing_npth )
104  {
105  fn = getDrillFileName( pair, doing_npth, m_merge_PTH_NPTH );
106  fn.SetPath( aPlotDirectory );
107 
108  if( aGenDrill )
109  {
110  wxString fullFilename = fn.GetFullPath();
111 
112  FILE* file = wxFopen( fullFilename, wxT( "w" ) );
113 
114  if( file == NULL )
115  {
116  if( aReporter )
117  {
118  msg.Printf( _( "** Unable to create %s **\n" ), GetChars( fullFilename ) );
119  aReporter->Report( msg );
120  }
121  break;
122  }
123  else
124  {
125  if( aReporter )
126  {
127  msg.Printf( _( "Create file %s\n" ), GetChars( fullFilename ) );
128  aReporter->Report( msg );
129  }
130  }
131 
132  createDrillFile( file, pair, doing_npth );
133  }
134  }
135  }
136 
137  if( aGenMap )
138  CreateMapFilesSet( aPlotDirectory, aReporter );
139 }
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
int createDrillFile(FILE *aFile, DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
Function CreateDrillFile Creates an Excellon drill file.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
void CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=NULL)
Function CreateMapFilesSet Creates the full set of map files for the board, in PS,...
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
#define _(s)
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...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.

References _, B_Cu, GENDRILL_WRITER_BASE::buildHolesList(), createDrillFile(), GENDRILL_WRITER_BASE::CreateMapFilesSet(), F_Cu, GetChars(), GENDRILL_WRITER_BASE::getDrillFileName(), GENDRILL_WRITER_BASE::getHolesCount(), GENDRILL_WRITER_BASE::getUniqueLayerPairs(), GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, and REPORTER::Report().

Referenced by DIALOG_GENDRILL::GenDrillAndMapFiles().

◆ createDrillFile()

int EXCELLON_WRITER::createDrillFile ( FILE *  aFile,
DRILL_LAYER_PAIR  aLayerPair,
bool  aGenerateNPTH_list 
)
private

Function CreateDrillFile Creates an Excellon drill file.

Parameters
aFile= an opened file to write to will be closed by CreateDrillFile
Returns
hole count

Definition at line 142 of file gendrill_Excellon_writer.cpp.

144 {
145  m_file = aFile;
146 
147  int diam, holes_count;
148  int x0, y0, xf, yf, xc, yc;
149  double xt, yt;
150  char line[1024];
151 
152  LOCALE_IO dummy; // Use the standard notation for double numbers
153 
154  writeEXCELLONHeader( aLayerPair, aGenerateNPTH_list );
155 
156  holes_count = 0;
157 
158 #ifdef WRITE_PTH_NPTH_COMMENT
159  // if PTH_ and NPTH are merged write a comment in drill file at the
160  // beginning of NPTH section
161  bool writePTHcomment = m_merge_PTH_NPTH;
162  bool writeNPTHcomment = m_merge_PTH_NPTH;
163 #endif
164 
165  /* Write the tool list */
166  for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
167  {
168  DRILL_TOOL& tool_descr = m_toolListBuffer[ii];
169 
170 #ifdef WRITE_PTH_NPTH_COMMENT
171  if( writePTHcomment && !tool_descr.m_Hole_NotPlated )
172  {
173  writePTHcomment = false;
174  fprintf( m_file, ";TYPE=PLATED\n" );
175  }
176 
177  if( writeNPTHcomment && tool_descr.m_Hole_NotPlated )
178  {
179  writeNPTHcomment = false;
180  fprintf( m_file, ";TYPE=NON_PLATED\n" );
181  }
182 #endif
183 
184  if( m_unitsMetric ) // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
185  fprintf( m_file, "T%dC%.3f\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits );
186  else // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
187  fprintf( m_file, "T%dC%.4f\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits );
188  }
189 
190  fputs( "%\n", m_file ); // End of header info
191  fputs( "G90\n", m_file ); // Absolute mode
192  fputs( "G05\n", m_file ); // Drill mode
193 
194  /* Read the hole file and generate lines for normal holes (oblong
195  * holes will be created later) */
196  int tool_reference = -2;
197 
198  for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
199  {
200  HOLE_INFO& hole_descr = m_holeListBuffer[ii];
201 
202  if( hole_descr.m_Hole_Shape )
203  continue; // oblong holes will be created later
204 
205  if( tool_reference != hole_descr.m_Tool_Reference )
206  {
207  tool_reference = hole_descr.m_Tool_Reference;
208  fprintf( m_file, "T%d\n", tool_reference );
209  }
210 
211  x0 = hole_descr.m_Hole_Pos.x - m_offset.x;
212  y0 = hole_descr.m_Hole_Pos.y - m_offset.y;
213 
214  if( !m_mirror )
215  y0 *= -1;
216 
217  xt = x0 * m_conversionUnits;
218  yt = y0 * m_conversionUnits;
219  writeCoordinates( line, xt, yt );
220 
221  fputs( line, m_file );
222  holes_count++;
223  }
224 
225  /* Read the hole file and generate lines for normal holes (oblong holes
226  * will be created later) */
227  tool_reference = -2; // set to a value not used for
228  // m_holeListBuffer[ii].m_Tool_Reference
229  for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
230  {
231  HOLE_INFO& hole_descr = m_holeListBuffer[ii];
232 
233  if( hole_descr.m_Hole_Shape == 0 )
234  continue; // wait for oblong holes
235 
236  if( tool_reference != hole_descr.m_Tool_Reference )
237  {
238  tool_reference = hole_descr.m_Tool_Reference;
239  fprintf( m_file, "T%d\n", tool_reference );
240  }
241 
242  diam = std::min( hole_descr.m_Hole_Size.x, hole_descr.m_Hole_Size.y );
243 
244  if( diam == 0 )
245  continue;
246 
247  /* Compute the hole coordinates: */
248  xc = x0 = xf = hole_descr.m_Hole_Pos.x - m_offset.x;
249  yc = y0 = yf = hole_descr.m_Hole_Pos.y - m_offset.y;
250 
251  /* Compute the start and end coordinates for the shape */
252  if( hole_descr.m_Hole_Size.x < hole_descr.m_Hole_Size.y )
253  {
254  int delta = ( hole_descr.m_Hole_Size.y - hole_descr.m_Hole_Size.x ) / 2;
255  y0 -= delta;
256  yf += delta;
257  }
258  else
259  {
260  int delta = ( hole_descr.m_Hole_Size.x - hole_descr.m_Hole_Size.y ) / 2;
261  x0 -= delta;
262  xf += delta;
263  }
264 
265  RotatePoint( &x0, &y0, xc, yc, hole_descr.m_Hole_Orient );
266  RotatePoint( &xf, &yf, xc, yc, hole_descr.m_Hole_Orient );
267 
268  if( !m_mirror )
269  {
270  y0 *= -1;
271  yf *= -1;
272  }
273 
274  xt = x0 * m_conversionUnits;
275  yt = y0 * m_conversionUnits;
276 
278  fputs( "G00", m_file ); // Select the routing mode
279 
280  writeCoordinates( line, xt, yt );
281 
282  if( !m_useRouteModeForOval )
283  {
284  /* remove the '\n' from end of line, because we must add the "G85"
285  * command to the line: */
286  for( int kk = 0; line[kk] != 0; kk++ )
287  {
288  if( line[kk] < ' ' )
289  line[kk] = 0;
290  }
291 
292  fputs( line, m_file );
293  fputs( "G85", m_file ); // add the "G85" command
294  }
295  else
296  {
297  fputs( line, m_file );
298  fputs( "M15\nG01", m_file ); // tool down and linear routing from last coordinates
299  }
300 
301  xt = xf * m_conversionUnits;
302  yt = yf * m_conversionUnits;
303  writeCoordinates( line, xt, yt );
304 
305  fputs( line, m_file );
306 
308  fputs( "M16\n", m_file ); // Tool up (end routing)
309 
310  fputs( "G05\n", m_file ); // Select drill mode
311  holes_count++;
312  }
313 
315 
316  return holes_count;
317 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:175
void writeEXCELLONHeader(DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
std::vector< DRILL_TOOL > m_toolListBuffer
void writeCoordinates(char *aLine, double aCoordX, double aCoordY)
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
std::vector< HOLE_INFO > m_holeListBuffer
#define min(a, b)
Definition: auxiliary.h:85

References dummy(), GENDRILL_WRITER_BASE::m_conversionUnits, DRILL_TOOL::m_Diameter, m_file, DRILL_TOOL::m_Hole_NotPlated, HOLE_INFO::m_Hole_Orient, HOLE_INFO::m_Hole_Pos, HOLE_INFO::m_Hole_Shape, HOLE_INFO::m_Hole_Size, GENDRILL_WRITER_BASE::m_holeListBuffer, GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, m_mirror, GENDRILL_WRITER_BASE::m_offset, HOLE_INFO::m_Tool_Reference, GENDRILL_WRITER_BASE::m_toolListBuffer, GENDRILL_WRITER_BASE::m_unitsMetric, m_useRouteModeForOval, min, RotatePoint(), writeCoordinates(), writeEXCELLONEndOfFile(), and writeEXCELLONHeader().

Referenced by CreateDrillandMapFilesSet().

◆ CreateMapFilesSet()

void GENDRILL_WRITER_BASE::CreateMapFilesSet ( const wxString &  aPlotDirectory,
REPORTER aReporter = NULL 
)
inherited

Function CreateMapFilesSet Creates the full set of map files for the board, in PS, PDF ...

format (use SetMapFileFormat() to select the format) filenames are computed from the board name, and layers id

Parameters
aPlotDirectory= the output folder
aReporter= a REPORTER to return activity or any message (can be NULL)

Definition at line 294 of file gendrill_file_writer_base.cpp.

296 {
297  wxFileName fn;
298  wxString msg;
299 
300  std::vector<DRILL_LAYER_PAIR> hole_sets = getUniqueLayerPairs();
301 
302  // append a pair representing the NPTH set of holes, for separate drill files.
303  if( !m_merge_PTH_NPTH )
304  hole_sets.push_back( DRILL_LAYER_PAIR( F_Cu, B_Cu ) );
305 
306  for( std::vector<DRILL_LAYER_PAIR>::const_iterator it = hole_sets.begin();
307  it != hole_sets.end(); ++it )
308  {
309  DRILL_LAYER_PAIR pair = *it;
310  // For separate drill files, the last layer pair is the NPTH drill file.
311  bool doing_npth = m_merge_PTH_NPTH ? false : ( it == hole_sets.end() - 1 );
312 
313  buildHolesList( pair, doing_npth );
314 
315  // The file is created if it has holes, or if it is the non plated drill file
316  // to be sure the NPTH file is up to date in separate files mode.
317  if( getHolesCount() > 0 || doing_npth )
318  {
319  fn = getDrillFileName( pair, doing_npth, m_merge_PTH_NPTH );
320  fn.SetPath( aPlotDirectory );
321 
322  fn.SetExt( wxEmptyString ); // Will be added by GenDrillMap
323  wxString fullfilename = fn.GetFullPath() + wxT( "-drl_map" );
324  fullfilename << wxT(".") << GetDefaultPlotExtension( m_mapFileFmt );
325 
326  bool success = genDrillMapFile( fullfilename, m_mapFileFmt );
327 
328  if( ! success )
329  {
330  if( aReporter )
331  {
332  msg.Printf( _( "** Unable to create %s **\n" ), GetChars( fullfilename ) );
333  aReporter->Report( msg );
334  }
335 
336  return;
337  }
338  else
339  {
340  if( aReporter )
341  {
342  msg.Printf( _( "Create file %s\n" ), GetChars( fullfilename ) );
343  aReporter->Report( msg );
344  }
345  }
346  }
347  }
348 }
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
bool genDrillMapFile(const wxString &aFullFileName, PlotFormat aFormat)
Function GenDrillMapFile Plot a map of drill marks for holes.
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
#define _(s)
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...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.

References _, B_Cu, GENDRILL_WRITER_BASE::buildHolesList(), F_Cu, GENDRILL_WRITER_BASE::genDrillMapFile(), GetChars(), GetDefaultPlotExtension(), GENDRILL_WRITER_BASE::getDrillFileName(), GENDRILL_WRITER_BASE::getHolesCount(), GENDRILL_WRITER_BASE::getUniqueLayerPairs(), GENDRILL_WRITER_BASE::m_mapFileFmt, GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, and REPORTER::Report().

Referenced by GERBER_WRITER::CreateDrillandMapFilesSet(), and CreateDrillandMapFilesSet().

◆ genDrillMapFile()

bool GENDRILL_WRITER_BASE::genDrillMapFile ( const wxString &  aFullFileName,
PlotFormat  aFormat 
)
protectedinherited

Function GenDrillMapFile Plot a map of drill marks for holes.

Hole list must be created before calling this function, by buildHolesList() for the right holes set (PTH, NPTH, buried/blind vias ...) the paper sheet to use to plot the map is set in m_pageInfo ( calls SetPageInfo() to set it ) if NULL, A4 format will be used

Parameters
aFullFileName: the full filename of the map file to create,
aFormat: one of the supported plot formats (see enum PlotFormat )

Definition at line 58 of file gen_drill_report_files.cpp.

60 {
61  // Remark:
62  // Hole list must be created before calling this function, by buildHolesList(),
63  // for the right holes set (PTH, NPTH, buried/blind vias ...)
64 
65  double scale = 1.0;
66  wxPoint offset;
67  PLOTTER* plotter = NULL;
68  PAGE_INFO dummy( PAGE_INFO::A4, false );
69 
70  PCB_PLOT_PARAMS plot_opts; // starts plotting with default options
71 
72  LOCALE_IO toggle; // use standard C notation for float numbers
73 
74  const PAGE_INFO& page_info = m_pageInfo ? *m_pageInfo : dummy;
75 
76  // Calculate dimensions and center of PCB
78 
79  // Calculate the scale for the format type, scale 1 in HPGL, drawing on
80  // an A4 sheet in PS, + text description of symbols
81  switch( aFormat )
82  {
83  case PLOT_FORMAT_GERBER:
84  offset = GetOffset();
85  plotter = new GERBER_PLOTTER();
86  plotter->SetViewport( offset, IU_PER_MILS/10, scale, false );
87  plotter->SetGerberCoordinatesFormat( 5 ); // format x.5 unit = mm
88  break;
89 
90  case PLOT_FORMAT_HPGL: // Scale for HPGL format.
91  {
92  HPGL_PLOTTER* hpgl_plotter = new HPGL_PLOTTER;
93  plotter = hpgl_plotter;
94  hpgl_plotter->SetPenNumber( plot_opts.GetHPGLPenNum() );
95  hpgl_plotter->SetPenSpeed( plot_opts.GetHPGLPenSpeed() );
96  plotter->SetPageSettings( page_info );
97  plotter->SetViewport( offset, IU_PER_MILS/10, scale, false );
98  }
99  break;
100 
101 
102  default:
103  wxASSERT( false );
104  // fall through
105  case PLOT_FORMAT_PDF:
106  case PLOT_FORMAT_POST:
107  {
108  PAGE_INFO pageA4( wxT( "A4" ) );
109  wxSize pageSizeIU = pageA4.GetSizeIU();
110 
111  // Reserve a margin around the page.
112  int margin = KiROUND( 20 * IU_PER_MM );
113 
114  // Calculate a scaling factor to print the board on the sheet
115  double Xscale = double( pageSizeIU.x - ( 2 * margin ) ) / bbbox.GetWidth();
116 
117  // We should print the list of drill sizes, so reserve room for it
118  // 60% height for board 40% height for list
119  int ypagesize_for_board = KiROUND( pageSizeIU.y * 0.6 );
120  double Yscale = double( ypagesize_for_board - margin ) / bbbox.GetHeight();
121 
122  scale = std::min( Xscale, Yscale );
123 
124  // Experience shows the scale should not to large, because texts
125  // create problem (can be to big or too small).
126  // So the scale is clipped at 3.0;
127  scale = std::min( scale, 3.0 );
128 
129  offset.x = KiROUND( double( bbbox.Centre().x ) -
130  ( pageSizeIU.x / 2.0 ) / scale );
131  offset.y = KiROUND( double( bbbox.Centre().y ) -
132  ( ypagesize_for_board / 2.0 ) / scale );
133 
134  if( aFormat == PLOT_FORMAT_PDF )
135  plotter = new PDF_PLOTTER;
136  else
137  plotter = new PS_PLOTTER;
138 
139  plotter->SetPageSettings( pageA4 );
140  plotter->SetViewport( offset, IU_PER_MILS/10, scale, false );
141  }
142  break;
143 
144  case PLOT_FORMAT_DXF:
145  {
146  DXF_PLOTTER* dxf_plotter = new DXF_PLOTTER;
147 
148  if( m_unitsMetric )
150  else
151  dxf_plotter->SetUnits( DXF_PLOTTER::DXF_UNIT_INCHES );
152 
153  plotter = dxf_plotter;
154  plotter->SetPageSettings( page_info );
155  plotter->SetViewport( offset, IU_PER_MILS/10, scale, false );
156  }
157  break;
158 
159  case PLOT_FORMAT_SVG:
160  {
161  SVG_PLOTTER* svg_plotter = new SVG_PLOTTER;
162  plotter = svg_plotter;
163  plotter->SetPageSettings( page_info );
164  plotter->SetViewport( offset, IU_PER_MILS/10, scale, false );
165  }
166  break;
167  }
168 
169  plotter->SetCreator( wxT( "PCBNEW" ) );
170  plotter->SetDefaultLineWidth( 5 * IU_PER_MILS );
171  plotter->SetColorMode( false );
172 
173  if( ! plotter->OpenFile( aFullFileName ) )
174  {
175  delete plotter;
176  return false;
177  }
178 
179  plotter->StartPlot();
180 
181  // Draw items on edge layer (not all, only items useful for drill map
182  BRDITEMS_PLOTTER itemplotter( plotter, m_pcb, plot_opts );
183  itemplotter.SetLayerSet( Edge_Cuts );
184 
185  for( auto PtStruct : m_pcb->Drawings() )
186  {
187  switch( PtStruct->Type() )
188  {
189  case PCB_LINE_T:
190  itemplotter.PlotDrawSegment( (DRAWSEGMENT*) PtStruct );
191  break;
192 
193  case PCB_TEXT_T:
194  itemplotter.PlotTextePcb( (TEXTE_PCB*) PtStruct );
195  break;
196 
197  case PCB_DIMENSION_T:
198  case PCB_TARGET_T:
199  case PCB_MARKER_T: // do not draw
200  default:
201  break;
202  }
203  }
204 
205  int x, y;
206  int plotX, plotY, TextWidth;
207  int intervalle = 0;
208  char line[1024];
209  wxString msg;
210  int textmarginaftersymbol = KiROUND( 2 * IU_PER_MM );
211 
212  // Set Drill Symbols width
213  plotter->SetDefaultLineWidth( 0.2 * IU_PER_MM / scale );
214  plotter->SetCurrentLineWidth( -1 );
215 
216  // Plot board outlines and drill map
217  plotDrillMarks( plotter );
218 
219  // Print a list of symbols used.
220  int charSize = 3 * IU_PER_MM; // text size in IUs
221  double charScale = 1.0 / scale; // real scale will be 1/scale,
222  // because the global plot scale is scale
223  TextWidth = KiROUND( (charSize * charScale) / 10.0 ); // Set text width (thickness)
224  intervalle = KiROUND( charSize * charScale ) + TextWidth;
225 
226  // Trace information.
227  plotX = KiROUND( bbbox.GetX() + textmarginaftersymbol * charScale );
228  plotY = bbbox.GetBottom() + intervalle;
229 
230  // Plot title "Info"
231  wxString Text = wxT( "Drill Map:" );
232  plotter->Text( wxPoint( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, 0,
233  wxSize( KiROUND( charSize * charScale ),
234  KiROUND( charSize * charScale ) ),
236  TextWidth, false, false );
237 
238  for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
239  {
240  DRILL_TOOL& tool = m_toolListBuffer[ii];
241 
242  if( tool.m_TotalCount == 0 )
243  continue;
244 
245  plotY += intervalle;
246 
247  int plot_diam = KiROUND( tool.m_Diameter );
248  x = KiROUND( plotX - textmarginaftersymbol * charScale - plot_diam / 2.0 );
249  y = KiROUND( plotY + charSize * charScale );
250  plotter->Marker( wxPoint( x, y ), plot_diam, ii );
251 
252  // List the diameter of each drill in mm and inches.
253  sprintf( line, "%2.2fmm / %2.3f\" ",
254  diameter_in_mm( tool.m_Diameter ),
255  diameter_in_inches( tool.m_Diameter ) );
256 
257  msg = FROM_UTF8( line );
258 
259  // Now list how many holes and ovals are associated with each drill.
260  if( ( tool.m_TotalCount == 1 )
261  && ( tool.m_OvalCount == 0 ) )
262  sprintf( line, "(1 hole)" );
263  else if( tool.m_TotalCount == 1 ) // && ( toolm_OvalCount == 1 )
264  sprintf( line, "(1 slot)" );
265  else if( tool.m_OvalCount == 0 )
266  sprintf( line, "(%d holes)", tool.m_TotalCount );
267  else if( tool.m_OvalCount == 1 )
268  sprintf( line, "(%d holes + 1 slot)", tool.m_TotalCount - 1 );
269  else // if ( toolm_OvalCount > 1 )
270  sprintf( line, "(%d holes + %d slots)",
271  tool.m_TotalCount - tool.m_OvalCount,
272  tool.m_OvalCount );
273 
274  msg += FROM_UTF8( line );
275 
276  if( tool.m_Hole_NotPlated )
277  msg += wxT( " (not plated)" );
278 
279  plotter->Text( wxPoint( plotX, y ), COLOR4D::UNSPECIFIED, msg, 0,
280  wxSize( KiROUND( charSize * charScale ),
281  KiROUND( charSize * charScale ) ),
283  TextWidth, false, false );
284 
285  intervalle = KiROUND( ( ( charSize * charScale ) + TextWidth ) * 1.2 );
286 
287  if( intervalle < ( plot_diam + ( 1 * IU_PER_MM / scale ) + TextWidth ) )
288  intervalle = plot_diam + ( 1 * IU_PER_MM / scale ) + TextWidth;
289  }
290 
291  plotter->EndPlot();
292  delete plotter;
293 
294  return true;
295 }
double diameter_in_inches(double ius)
double diameter_in_mm(double ius)
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:161
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:175
virtual bool StartPlot()=0
int GetX() const
Definition: eda_rect.h:109
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:79
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:126
int GetWidth() const
Definition: eda_rect.h:117
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
int GetHPGLPenSpeed() const
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.cpp:537
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false)
Definition: plotter.h:436
int GetBottom() const
Definition: eda_rect.h:122
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:215
std::vector< DRILL_TOOL > m_toolListBuffer
virtual bool EndPlot()=0
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
virtual void SetPenSpeed(int speed)
Definition: plotter.h:609
static const wxChar A4[]
Definition: page_info.h:64
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:98
int GetHeight() const
Definition: eda_rect.h:118
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:99
void Marker(const wxPoint &position, int diametre, unsigned aShapeId)
Draw a pattern shape number aShapeId, to coord position.
Definition: plotter.cpp:281
virtual void SetDefaultLineWidth(int width)=0
Set the default line width.
int GetHPGLPenNum() const
Base plotter engine class.
Definition: plotter.h:97
const wxPoint GetOffset()
Return the plot offset (usually the position of the auxiliary axis.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:97
const int scale
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
virtual void SetPenNumber(int number)
Definition: plotter.h:614
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define IU_PER_MILS
Definition: plotter.cpp:134
wxPoint Centre() const
Definition: eda_rect.h:60
bool plotDrillMarks(PLOTTER *aPlotter)
Helper function.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
DRAWINGS & Drawings()
Definition: class_board.h:245
#define min(a, b)
Definition: auxiliary.h:85
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.

References PAGE_INFO::A4, EDA_RECT::Centre(), diameter_in_inches(), diameter_in_mm(), BOARD::Drawings(), dummy(), DXF_PLOTTER::DXF_UNIT_INCHES, DXF_PLOTTER::DXF_UNIT_MILLIMETERS, Edge_Cuts, PLOTTER::EndPlot(), FROM_UTF8(), BOARD::GetBoardEdgesBoundingBox(), EDA_RECT::GetBottom(), EDA_RECT::GetHeight(), PCB_PLOT_PARAMS::GetHPGLPenNum(), PCB_PLOT_PARAMS::GetHPGLPenSpeed(), GENDRILL_WRITER_BASE::GetOffset(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, IU_PER_MILS, KiROUND(), DRILL_TOOL::m_Diameter, DRILL_TOOL::m_Hole_NotPlated, DRILL_TOOL::m_OvalCount, GENDRILL_WRITER_BASE::m_pageInfo, GENDRILL_WRITER_BASE::m_pcb, GENDRILL_WRITER_BASE::m_toolListBuffer, DRILL_TOOL::m_TotalCount, GENDRILL_WRITER_BASE::m_unitsMetric, PLOTTER::Marker(), min, PLOTTER::OpenFile(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MARKER_T, PCB_TARGET_T, PCB_TEXT_T, PLOT_FORMAT_DXF, PLOT_FORMAT_GERBER, PLOT_FORMAT_HPGL, PLOT_FORMAT_PDF, PLOT_FORMAT_POST, PLOT_FORMAT_SVG, BRDITEMS_PLOTTER::PlotDrawSegment(), GENDRILL_WRITER_BASE::plotDrillMarks(), BRDITEMS_PLOTTER::PlotTextePcb(), scale, PLOTTER::SetColorMode(), PLOTTER::SetCreator(), PLOTTER::SetCurrentLineWidth(), PLOTTER::SetDefaultLineWidth(), PLOTTER::SetGerberCoordinatesFormat(), BRDITEMS_PLOTTER::SetLayerSet(), PLOTTER::SetPageSettings(), HPGL_PLOTTER::SetPenNumber(), HPGL_PLOTTER::SetPenSpeed(), DXF_PLOTTER::SetUnits(), PLOTTER::SetViewport(), PLOTTER::StartPlot(), and PLOTTER::Text().

Referenced by GENDRILL_WRITER_BASE::CreateMapFilesSet().

◆ GenDrillReportFile()

bool GENDRILL_WRITER_BASE::GenDrillReportFile ( const wxString &  aFullFileName)
inherited

Function GenDrillReportFile Create a plain text report file giving a list of drill values and drill count for through holes, oblong holes, and for buried vias, drill values and drill count per layer pair there is only one report for all drill files even when buried or blinds vias exist.

Here is a sample created by this function: Drill report for F:/tmp/interf_u/interf_u.brd Created on 04/10/2012 20:48:38 Selected Drill Unit: Imperial (inches)

Drill report for plated through holes : T1 0,025" 0,64mm (88 holes) T2 0,031" 0,79mm (120 holes) T3 0,032" 0,81mm (151 holes) (with 1 slot) T4 0,040" 1,02mm (43 holes) T5 0,079" 2,00mm (1 hole) (with 1 slot) T6 0,120" 3,05mm (1 hole) (with 1 slot)

Total plated holes count 404

Drill report for buried and blind vias :

Drill report for holes from layer Soudure to layer Interne1 :

Total plated holes count 0

Drill report for holes from layer Interne1 to layer Interne2 : T1 0,025" 0,64mm (3 holes)

Total plated holes count 3

Drill report for holes from layer Interne2 to layer Composant : T1 0,025" 0,64mm (1 hole)

Total plated holes count 1

Drill report for unplated through holes : T1 0,120" 3,05mm (1 hole) (with 1 slot)

Total unplated holes count 1

Parameters
aFullFileName: the name of the file to create
Returns
true if the file is created

Definition at line 298 of file gen_drill_report_files.cpp.

299 {
300  FILE_OUTPUTFORMATTER out( aFullFileName );
301 
302  static const char separator[] =
303  " =============================================================\n";
304 
305  wxASSERT( m_pcb );
306 
307  unsigned totalHoleCount;
308  wxString brdFilename = m_pcb->GetFileName();
309 
310  std::vector<DRILL_LAYER_PAIR> hole_sets = getUniqueLayerPairs();
311 
312  out.Print( 0, "Drill report for %s\n", TO_UTF8( brdFilename ) );
313  out.Print( 0, "Created on %s\n\n", TO_UTF8( DateAndTime() ) );
314 
315  // Output the cu layer stackup, so layer name references make sense.
316  out.Print( 0, "Copper Layer Stackup:\n" );
317  out.Print( 0, separator );
318 
320 
321  int conventional_layer_num = 1;
322 
323  for( LSEQ seq = cu.Seq(); seq; ++seq, ++conventional_layer_num )
324  {
325  out.Print( 0, " L%-2d: %-25s %s\n",
326  conventional_layer_num,
327  TO_UTF8( m_pcb->GetLayerName( *seq ) ),
328  layerName( *seq ).c_str() // generic layer name
329  );
330  }
331 
332  out.Print( 0, "\n\n" );
333 
334  /* output hole lists:
335  * 1 - through holes
336  * 2 - for partial holes only: by layer starting and ending pair
337  * 3 - Non Plated through holes
338  */
339 
340  bool buildNPTHlist = false; // First pass: build PTH list only
341 
342  // in this loop are plated only:
343  for( unsigned pair_ndx = 0; pair_ndx < hole_sets.size(); ++pair_ndx )
344  {
345  DRILL_LAYER_PAIR pair = hole_sets[pair_ndx];
346 
347  buildHolesList( pair, buildNPTHlist );
348 
349  if( pair == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
350  {
351  out.Print( 0, "Drill file '%s' contains\n",
352  TO_UTF8( getDrillFileName( pair, false, m_merge_PTH_NPTH ) ) );
353 
354  out.Print( 0, " plated through holes:\n" );
355  out.Print( 0, separator );
356  totalHoleCount = printToolSummary( out, false );
357  out.Print( 0, " Total plated holes count %u\n", totalHoleCount );
358  }
359  else // blind/buried
360  {
361  out.Print( 0, "Drill file '%s' contains\n",
362  TO_UTF8( getDrillFileName( pair, false, m_merge_PTH_NPTH ) ) );
363 
364  out.Print( 0, " holes connecting layer pair: '%s and %s' (%s vias):\n",
365  TO_UTF8( m_pcb->GetLayerName( ToLAYER_ID( pair.first ) ) ),
366  TO_UTF8( m_pcb->GetLayerName( ToLAYER_ID( pair.second ) ) ),
367  pair.first == F_Cu || pair.second == B_Cu ? "blind" : "buried"
368  );
369 
370  out.Print( 0, separator );
371  totalHoleCount = printToolSummary( out, false );
372  out.Print( 0, " Total plated holes count %u\n", totalHoleCount );
373  }
374 
375  out.Print( 0, "\n\n" );
376  }
377 
378  // NPTHoles. Generate the full list (pads+vias) if PTH and NPTH are merged,
379  // or only the NPTH list (which never has vias)
380  if( !m_merge_PTH_NPTH )
381  buildNPTHlist = true;
382 
383  buildHolesList( DRILL_LAYER_PAIR( F_Cu, B_Cu ), buildNPTHlist );
384 
385  // nothing wrong with an empty NPTH file in report.
386  if( m_merge_PTH_NPTH )
387  out.Print( 0, "Not plated through holes are merged with plated holes\n" );
388  else
389  out.Print( 0, "Drill file '%s' contains\n",
391  true, m_merge_PTH_NPTH ) ) );
392 
393  out.Print( 0, " unplated through holes:\n" );
394  out.Print( 0, separator );
395  totalHoleCount = printToolSummary( out, true );
396  out.Print( 0, " Total unplated holes count %u\n", totalHoleCount );
397 
398  return true;
399 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
unsigned printToolSummary(OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
Function printToolSummary prints m_toolListBuffer[] tools to aOut and returns total hole count.
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
#define cu(a)
Definition: auxiliary.h:88
const wxString & GetFileName() const
Definition: class_board.h:225
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
Class LSET is a set of PCB_LAYER_IDs.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
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...
const std::string layerName(PCB_LAYER_ID aLayer) const
minor helper function.
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
wxString DateAndTime()
Definition: string.cpp:333

References LSET::AllCuMask(), B_Cu, GENDRILL_WRITER_BASE::buildHolesList(), cu, DateAndTime(), F_Cu, GENDRILL_WRITER_BASE::getDrillFileName(), BOARD::GetEnabledLayers(), BOARD::GetFileName(), BOARD::GetLayerName(), GENDRILL_WRITER_BASE::getUniqueLayerPairs(), GENDRILL_WRITER_BASE::layerName(), GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, GENDRILL_WRITER_BASE::m_pcb, OUTPUTFORMATTER::Print(), GENDRILL_WRITER_BASE::printToolSummary(), TO_UTF8, and ToLAYER_ID().

Referenced by DIALOG_GENDRILL::OnGenReportFile().

◆ getDrillFileName()

const wxString GENDRILL_WRITER_BASE::getDrillFileName ( DRILL_LAYER_PAIR  aPair,
bool  aNPTH,
bool  aMerge_PTH_NPTH 
) const
protectedvirtualinherited
Returns
a filename which identify the drill file function. it is the board name with the layer pair names added, and for separate (PTH and NPTH) files, "-NPH" or "-NPTH" added
Parameters
aPair= the layer pair
aNPTH= true to generate the filename of NPTH holes
aMerge_PTH_NPTH= true to generate the filename of a file which containd both NPH and NPTH holes

Reimplemented in GERBER_WRITER.

Definition at line 263 of file gendrill_file_writer_base.cpp.

265 {
266  wxASSERT( m_pcb );
267 
268  wxString extend;
269 
270  if( aNPTH )
271  extend = "-NPTH";
272  else if( aPair == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
273  {
274  if( !aMerge_PTH_NPTH )
275  extend = "-PTH";
276  // if merged, extend with nothing
277  }
278  else
279  {
280  extend += '-';
281  extend += layerPairName( aPair );
282  }
283 
284  wxFileName fn = m_pcb->GetFileName();
285 
286  fn.SetName( fn.GetName() + extend );
287  fn.SetExt( m_drillFileExtension );
288 
289  wxString ret = fn.GetFullName();
290 
291  return ret;
292 }
const wxString & GetFileName() const
Definition: class_board.h:225
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
minor helper function.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR

References B_Cu, F_Cu, BOARD::GetFileName(), GENDRILL_WRITER_BASE::layerPairName(), GENDRILL_WRITER_BASE::m_drillFileExtension, and GENDRILL_WRITER_BASE::m_pcb.

Referenced by CreateDrillandMapFilesSet(), GENDRILL_WRITER_BASE::CreateMapFilesSet(), GENDRILL_WRITER_BASE::GenDrillReportFile(), and GERBER_WRITER::getDrillFileName().

◆ getHolesCount()

int GENDRILL_WRITER_BASE::getHolesCount ( ) const
inlineprotectedinherited

◆ GetOffset()

const wxPoint EXCELLON_WRITER::GetOffset ( )
inline

Return the plot offset (usually the position of the auxiliary axis.

Definition at line 65 of file gendrill_Excellon_writer.h.

65 { return m_offset; }

References GENDRILL_WRITER_BASE::m_offset.

◆ getUniqueLayerPairs()

std::vector< DRILL_LAYER_PAIR > GENDRILL_WRITER_BASE::getUniqueLayerPairs ( ) const
protectedinherited

Get unique layer pairs by examining the micro and blind_buried vias.

Definition at line 196 of file gendrill_file_writer_base.cpp.

197 {
198  wxASSERT( m_pcb );
199 
200  static const KICAD_T interesting_stuff_to_collect[] = {
201  PCB_VIA_T,
202  EOT
203  };
204 
205  PCB_TYPE_COLLECTOR vias;
206 
207  vias.Collect( m_pcb, interesting_stuff_to_collect );
208 
209  std::set< DRILL_LAYER_PAIR > unique;
210 
211  DRILL_LAYER_PAIR layer_pair;
212 
213  for( int i = 0; i < vias.GetCount(); ++i )
214  {
215  VIA* v = (VIA*) vias[i];
216 
217  v->LayerPair( &layer_pair.first, &layer_pair.second );
218 
219  // only make note of blind buried.
220  // thru hole is placed unconditionally as first in fetched list.
221  if( layer_pair != DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
222  {
223  unique.insert( layer_pair );
224  }
225  }
226 
227  std::vector<DRILL_LAYER_PAIR> ret;
228 
229  ret.push_back( DRILL_LAYER_PAIR( F_Cu, B_Cu ) ); // always first in returned list
230 
231  for( std::set< DRILL_LAYER_PAIR >::const_iterator it = unique.begin(); it != unique.end(); ++it )
232  ret.push_back( *it );
233 
234  return ret;
235 }
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
void Collect(BOARD_ITEM *aBoard, const KICAD_T aScanList[])
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
Definition: collectors.cpp:514
size_t i
Definition: json11.cpp:597
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:621

References B_Cu, PCB_TYPE_COLLECTOR::Collect(), EOT, F_Cu, COLLECTOR::GetCount(), i, VIA::LayerPair(), GENDRILL_WRITER_BASE::m_pcb, and PCB_VIA_T.

Referenced by GERBER_WRITER::CreateDrillandMapFilesSet(), CreateDrillandMapFilesSet(), GENDRILL_WRITER_BASE::CreateMapFilesSet(), and GENDRILL_WRITER_BASE::GenDrillReportFile().

◆ layerName()

const std::string GENDRILL_WRITER_BASE::layerName ( PCB_LAYER_ID  aLayer) const
protectedinherited

minor helper function.

Returns
a string from aLayer to identify the layer. string are "front" "back" or "in<aLayer>"

Definition at line 238 of file gendrill_file_writer_base.cpp.

239 {
240  // Generic names here.
241  switch( aLayer )
242  {
243  case F_Cu:
244  return "front";
245  case B_Cu:
246  return "back";
247  default:
248  return StrPrintf( "in%d", aLayer );
249  }
250 }
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74

References B_Cu, F_Cu, and numEval::StrPrintf().

Referenced by GENDRILL_WRITER_BASE::GenDrillReportFile(), and GENDRILL_WRITER_BASE::layerPairName().

◆ layerPairName()

const std::string GENDRILL_WRITER_BASE::layerPairName ( DRILL_LAYER_PAIR  aPair) const
protectedinherited

minor helper function.

Returns
a string from aPair to identify the layer layer pair. string is "<layer1Name>"-"<layer2Name>" used to generate a filename for drill files and drill maps

Definition at line 253 of file gendrill_file_writer_base.cpp.

254 {
255  std::string ret = layerName( aPair.first );
256  ret += '-';
257  ret += layerName( aPair.second );
258 
259  return ret;
260 }
const std::string layerName(PCB_LAYER_ID aLayer) const
minor helper function.

References GENDRILL_WRITER_BASE::layerName().

Referenced by GENDRILL_WRITER_BASE::getDrillFileName().

◆ plotDrillMarks()

bool GENDRILL_WRITER_BASE::plotDrillMarks ( PLOTTER aPlotter)
protectedinherited

Helper function.

Writes the drill marks in HPGL, POSTSCRIPT or other supported formats Each hole size has a symbol (circle, cross X, cross + ...) up to PLOTTER::MARKER_COUNT different values. If more than PLOTTER::MARKER_COUNT different values, these other values share the same mark shape

Parameters
aPlotter= a PLOTTER instance (HPGL, POSTSCRIPT ... plotter).

Definition at line 402 of file gen_drill_report_files.cpp.

403 {
404  // Plot the drill map:
405  wxPoint pos;
406 
407  for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
408  {
409  const HOLE_INFO& hole = m_holeListBuffer[ii];
410  pos = hole.m_Hole_Pos;
411 
412  // Always plot the drill symbol (for slots identifies the needed cutter!
413  aPlotter->Marker( pos, hole.m_Hole_Diameter, hole.m_Tool_Reference - 1 );
414 
415  if( hole.m_Hole_Shape != 0 )
416  {
417  wxSize oblong_size = hole.m_Hole_Size;
418  aPlotter->FlashPadOval( pos, oblong_size, hole.m_Hole_Orient, SKETCH, NULL );
419  }
420  }
421 
422  return true;
423 }
void Marker(const wxPoint &position, int diametre, unsigned aShapeId)
Draw a pattern shape number aShapeId, to coord position.
Definition: plotter.cpp:281
virtual void FlashPadOval(const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void *aData)=0
virtual function FlashPadOval
std::vector< HOLE_INFO > m_holeListBuffer

References PLOTTER::FlashPadOval(), HOLE_INFO::m_Hole_Diameter, HOLE_INFO::m_Hole_Orient, HOLE_INFO::m_Hole_Pos, HOLE_INFO::m_Hole_Shape, HOLE_INFO::m_Hole_Size, GENDRILL_WRITER_BASE::m_holeListBuffer, HOLE_INFO::m_Tool_Reference, PLOTTER::Marker(), and SKETCH.

Referenced by GENDRILL_WRITER_BASE::genDrillMapFile().

◆ printToolSummary()

unsigned GENDRILL_WRITER_BASE::printToolSummary ( OUTPUTFORMATTER aOut,
bool  aSummaryNPTH 
) const
protectedinherited

Function printToolSummary prints m_toolListBuffer[] tools to aOut and returns total hole count.

Parameters
aOut= the current OUTPUTFORMATTER to print summary
aSummaryNPTH= true to print summary for NPTH, false for PTH

Definition at line 426 of file gen_drill_report_files.cpp.

427 {
428  unsigned totalHoleCount = 0;
429 
430  for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
431  {
432  const DRILL_TOOL& tool = m_toolListBuffer[ii];
433 
434  if( aSummaryNPTH && !tool.m_Hole_NotPlated )
435  continue;
436 
437  if( !aSummaryNPTH && tool.m_Hole_NotPlated )
438  continue;
439 
440  // List the tool number assigned to each drill,
441  // in mm then in inches.
442  int tool_number = ii+1;
443  out.Print( 0, " T%d %2.2fmm %2.3f\" ", tool_number,
444  diameter_in_mm( tool.m_Diameter ),
445  diameter_in_inches( tool.m_Diameter ) );
446 
447  // Now list how many holes and ovals are associated with each drill.
448  if( ( tool.m_TotalCount == 1 ) && ( tool.m_OvalCount == 0 ) )
449  out.Print( 0, "(1 hole)\n" );
450  else if( tool.m_TotalCount == 1 )
451  out.Print( 0, "(1 hole) (with 1 slot)\n" );
452  else if( tool.m_OvalCount == 0 )
453  out.Print( 0, "(%d holes)\n", tool.m_TotalCount );
454  else if( tool.m_OvalCount == 1 )
455  out.Print( 0, "(%d holes) (with 1 slot)\n", tool.m_TotalCount );
456  else // tool.m_OvalCount > 1
457  out.Print( 0, "(%d holes) (with %d slots)\n",
458  tool.m_TotalCount, tool.m_OvalCount );
459 
460  totalHoleCount += tool.m_TotalCount;
461  }
462 
463  out.Print( 0, "\n" );
464 
465  return totalHoleCount;
466 }
double diameter_in_inches(double ius)
double diameter_in_mm(double ius)
std::vector< DRILL_TOOL > m_toolListBuffer

References diameter_in_inches(), diameter_in_mm(), DRILL_TOOL::m_Diameter, DRILL_TOOL::m_Hole_NotPlated, DRILL_TOOL::m_OvalCount, GENDRILL_WRITER_BASE::m_toolListBuffer, DRILL_TOOL::m_TotalCount, and OUTPUTFORMATTER::Print().

Referenced by GENDRILL_WRITER_BASE::GenDrillReportFile().

◆ SetFormat()

void EXCELLON_WRITER::SetFormat ( bool  aMetric,
ZEROS_FMT  aZerosFmt = DECIMAL_FORMAT,
int  aLeftDigits = 0,
int  aRightDigits = 0 
)

Function SetFormat Initialize internal parameters to match the given format.

Parameters
aMetric= true for metric coordinates, false for imperial units
aZerosFmt= DECIMAL_FORMAT, SUPPRESS_LEADING, SUPPRESS_TRAILING, KEEP_ZEROS
aLeftDigits= number of digits for integer part of coordinates if <= 0 (default), a suitable value will be used, depending on units
aRightDigits= number of digits for mantissa part of coordinates if <= 0 (default), a suitable value will be used, depending on units

Definition at line 320 of file gendrill_Excellon_writer.cpp.

324 {
325  m_unitsMetric = aMetric;
326  m_zeroFormat = aZerosFmt;
327 
328  /* Set conversion scale depending on drill file units */
329  if( m_unitsMetric )
330  m_conversionUnits = 1.0 / IU_PER_MM; // EXCELLON units = mm
331  else
332  m_conversionUnits = 0.001 / IU_PER_MILS; // EXCELLON units = INCHES
333 
334  // Set the zero counts. if aZerosFmt == DECIMAL_FORMAT, these values
335  // will be set, but not used.
336  if( aLeftDigits <= 0 )
337  aLeftDigits = m_unitsMetric ? 3 : 2;
338 
339  if( aRightDigits <= 0 )
340  aRightDigits = m_unitsMetric ? 3 : 4;
341 
342  m_precision.m_lhs = aLeftDigits;
343  m_precision.m_rhs = aRightDigits;
344 }
#define IU_PER_MILS
Definition: plotter.cpp:134

References IU_PER_MILS, GENDRILL_WRITER_BASE::m_conversionUnits, DRILL_PRECISION::m_lhs, GENDRILL_WRITER_BASE::m_precision, DRILL_PRECISION::m_rhs, GENDRILL_WRITER_BASE::m_unitsMetric, and GENDRILL_WRITER_BASE::m_zeroFormat.

Referenced by DIALOG_GENDRILL::GenDrillAndMapFiles().

◆ SetMapFileFormat()

void GENDRILL_WRITER_BASE::SetMapFileFormat ( PlotFormat  aMapFmt)
inlineinherited

Initialize the format for the drill map file.

Parameters
aMapFmt= a PlotFormat value (one of PLOT_FORMAT_HPGL, PLOT_FORMAT_POST, PLOT_FORMAT_GERBER, PLOT_FORMAT_DXF, PLOT_FORMAT_SVG, PLOT_FORMAT_PDF the most useful are PLOT_FORMAT_PDF and PLOT_FORMAT_POST

Definition at line 198 of file gendrill_file_writer_base.h.

198 { m_mapFileFmt = aMapFmt; }

References GENDRILL_WRITER_BASE::m_mapFileFmt.

Referenced by DIALOG_GENDRILL::GenDrillAndMapFiles().

◆ SetMergeOption()

void GENDRILL_WRITER_BASE::SetMergeOption ( bool  aMerge)
inlineinherited

set the option to make separate drill files for PTH and NPTH

Parameters
aMerge= true to make only one file containing PTH and NPTH = false to create 2 separate files

Definition at line 176 of file gendrill_file_writer_base.h.

References GENDRILL_WRITER_BASE::m_merge_PTH_NPTH.

Referenced by DIALOG_GENDRILL::OnGenReportFile().

◆ SetOptions()

void EXCELLON_WRITER::SetOptions ( bool  aMirror,
bool  aMinimalHeader,
wxPoint  aOffset,
bool  aMerge_PTH_NPTH 
)
inline

Function SetOptions Initialize internal parameters to match drill options.

Parameters
aMirror= true to create mirrored coordinates (Y coordinates negated)
aMinimalHeader= true to use a minimal header (no comments, no info)
aOffset= drill coordinates offset
aMerge_PTH_NPTH= true to create only one file containing PTH and NPTH false to create 2 separate files : one for PTH and one for NPTH

Definition at line 99 of file gendrill_Excellon_writer.h.

100  {
101  m_mirror = aMirror;
102  m_offset = aOffset;
103  m_minimalHeader = aMinimalHeader;
104  m_merge_PTH_NPTH = aMerge_PTH_NPTH;
105  }

References GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, m_minimalHeader, m_mirror, and GENDRILL_WRITER_BASE::m_offset.

Referenced by DIALOG_GENDRILL::GenDrillAndMapFiles().

◆ SetPageInfo()

void GENDRILL_WRITER_BASE::SetPageInfo ( const PAGE_INFO aPageInfo)
inlineinherited

Sets the page info used to plot drill maps If NULL, a A4 page format will be used.

Parameters
aPageInfo= a reference to the page info, usually used to plot/display the board

Definition at line 189 of file gendrill_file_writer_base.h.

189 { m_pageInfo = aPageInfo; }

References GENDRILL_WRITER_BASE::m_pageInfo.

◆ SetRouteModeForOvalHoles()

void EXCELLON_WRITER::SetRouteModeForOvalHoles ( bool  aUseRouteModeForOvalHoles)
inline

Definition at line 70 of file gendrill_Excellon_writer.h.

71  {
72  m_useRouteModeForOval = aUseRouteModeForOvalHoles;
73  }

References m_useRouteModeForOval.

Referenced by DIALOG_GENDRILL::GenDrillAndMapFiles().

◆ writeCoordinates()

void EXCELLON_WRITER::writeCoordinates ( char *  aLine,
double  aCoordX,
double  aCoordY 
)
private

Definition at line 347 of file gendrill_Excellon_writer.cpp.

348 {
349  wxString xs, ys;
350  int xpad = m_precision.m_lhs + m_precision.m_rhs;
351  int ypad = xpad;
352 
353  switch( m_zeroFormat )
354  {
355  default:
356  case DECIMAL_FORMAT:
357  /* In Excellon files, resolution is 1/1000 mm or 1/10000 inch (0.1 mil)
358  * Although in decimal format, Excellon specifications do not specify
359  * clearly the resolution. However it seems to be 1/1000mm or 0.1 mil
360  * like in non decimal formats, so we trunk coordinates to 3 or 4 digits in mantissa
361  * Decimal format just prohibit useless leading 0:
362  * 0.45 or .45 is right, but 00.54 is incorrect.
363  */
364  if( m_unitsMetric )
365  {
366  // resolution is 1/1000 mm
367  xs.Printf( wxT( "%.3f" ), aCoordX );
368  ys.Printf( wxT( "%.3f" ), aCoordY );
369  }
370  else
371  {
372  // resolution is 1/10000 inch
373  xs.Printf( wxT( "%.4f" ), aCoordX );
374  ys.Printf( wxT( "%.4f" ), aCoordY );
375  }
376 
377  //Remove useless trailing 0
378  while( xs.Last() == '0' )
379  xs.RemoveLast();
380 
381  if( xs.Last() == '.' ) // however keep a trailing 0 after the floating point separator
382  xs << '0';
383 
384  while( ys.Last() == '0' )
385  ys.RemoveLast();
386 
387  if( ys.Last() == '.' )
388  ys << '0';
389 
390  sprintf( aLine, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
391  break;
392 
393  case SUPPRESS_LEADING:
394  for( int i = 0; i< m_precision.m_rhs; i++ )
395  {
396  aCoordX *= 10; aCoordY *= 10;
397  }
398 
399  sprintf( aLine, "X%dY%d\n", KiROUND( aCoordX ), KiROUND( aCoordY ) );
400  break;
401 
402  case SUPPRESS_TRAILING:
403  {
404  for( int i = 0; i < m_precision.m_rhs; i++ )
405  {
406  aCoordX *= 10;
407  aCoordY *= 10;
408  }
409 
410  if( aCoordX < 0 )
411  xpad++;
412 
413  if( aCoordY < 0 )
414  ypad++;
415 
416  xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
417  ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
418 
419  size_t j = xs.Len() - 1;
420 
421  while( xs[j] == '0' && j )
422  xs.Truncate( j-- );
423 
424  j = ys.Len() - 1;
425 
426  while( ys[j] == '0' && j )
427  ys.Truncate( j-- );
428 
429  sprintf( aLine, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
430  break;
431  }
432 
433  case KEEP_ZEROS:
434  for( int i = 0; i< m_precision.m_rhs; i++ )
435  {
436  aCoordX *= 10; aCoordY *= 10;
437  }
438 
439  if( aCoordX < 0 )
440  xpad++;
441 
442  if( aCoordY < 0 )
443  ypad++;
444 
445  xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
446  ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
447  sprintf( aLine, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
448  break;
449  }
450 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
size_t i
Definition: json11.cpp:597

References GENDRILL_WRITER_BASE::DECIMAL_FORMAT, i, GENDRILL_WRITER_BASE::KEEP_ZEROS, KiROUND(), DRILL_PRECISION::m_lhs, GENDRILL_WRITER_BASE::m_precision, DRILL_PRECISION::m_rhs, GENDRILL_WRITER_BASE::m_unitsMetric, GENDRILL_WRITER_BASE::m_zeroFormat, GENDRILL_WRITER_BASE::SUPPRESS_LEADING, GENDRILL_WRITER_BASE::SUPPRESS_TRAILING, and TO_UTF8.

Referenced by createDrillFile().

◆ writeEXCELLONEndOfFile()

void EXCELLON_WRITER::writeEXCELLONEndOfFile ( )
private

Definition at line 544 of file gendrill_Excellon_writer.cpp.

545 {
546  //add if minimal here
547  fputs( "T0\nM30\n", m_file );
548  fclose( m_file );
549 }

References m_file.

Referenced by createDrillFile().

◆ writeEXCELLONHeader()

void EXCELLON_WRITER::writeEXCELLONHeader ( DRILL_LAYER_PAIR  aLayerPair,
bool  aGenerateNPTH_list 
)
private

Definition at line 453 of file gendrill_Excellon_writer.cpp.

455 {
456  fputs( "M48\n", m_file ); // The beginning of a header
457 
458  if( !m_minimalHeader )
459  {
460  // The next lines in EXCELLON files are comments:
461  wxString msg;
462  msg << "KiCad " << GetBuildVersion();
463 
464  fprintf( m_file, "; DRILL file {%s} date %s\n", TO_UTF8( msg ), TO_UTF8( DateAndTime() ) );
465  msg = "; FORMAT={";
466 
467  // Print precision:
468  // Note in decimal format the precision is not used.
469  // the floating point notation has higher priority than the precision.
472  else
473  msg << "-:-"; // in decimal format the precision is irrelevant
474 
475  msg << "/ absolute / ";
476  msg << ( m_unitsMetric ? "metric" : "inch" );
477 
478  /* Adding numbers notation format.
479  * this is same as m_Choice_Zeros_Format strings, but NOT translated
480  * because some EXCELLON parsers do not like non ASCII values
481  * so we use ONLY English (ASCII) strings.
482  * if new options are added in m_Choice_Zeros_Format, they must also
483  * be added here
484  */
485  msg << wxT( " / " );
486 
487  const wxString zero_fmt[4] =
488  {
489  "decimal",
490  "suppress leading zeros",
491  "suppress trailing zeros",
492  "keep zeros"
493  };
494 
495  msg << zero_fmt[m_zeroFormat] << "}\n";
496  fputs( TO_UTF8( msg ), m_file );
497 
498  // add the structured comment TF.CreationDate:
499  // The attribute value must conform to the full version of the ISO 8601
501  fputs( TO_UTF8( msg ), m_file );
502 
503  // Add the application name that created the drill file
504  msg = "; #@! TF.GenerationSoftware,Kicad,Pcbnew,";
505  msg << GetBuildVersion() << "\n";
506  fputs( TO_UTF8( msg ), m_file );
507 
508  if( !m_merge_PTH_NPTH )
509  {
510  // Add the standard X2 FileFunction for drill files
511  // TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH]
512  msg = BuildFileFunctionAttributeString( aLayerPair, aGenerateNPTH_list, true )
513  + "\n";
514  fputs( TO_UTF8( msg ), m_file );
515  }
516 
517  fputs( "FMAT,2\n", m_file ); // Use Format 2 commands (version used since 1979)
518  }
519 
520  fputs( m_unitsMetric ? "METRIC" : "INCH", m_file );
521 
522  switch( m_zeroFormat )
523  {
524  case DECIMAL_FORMAT:
525  fputs( "\n", m_file );
526  break;
527 
528  case SUPPRESS_LEADING:
529  fputs( ",TZ\n", m_file );
530  break;
531 
532  case SUPPRESS_TRAILING:
533  fputs( ",LZ\n", m_file );
534  break;
535 
536  case KEEP_ZEROS:
537  // write nothing, but TZ is acceptable when all zeros are kept
538  fputs( "\n", m_file );
539  break;
540  }
541 }
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString BuildFileFunctionAttributeString(DRILL_LAYER_PAIR aLayerPair, bool aIsNpth, bool aCompatNCdrill=false) const
wxString DateAndTime()
Definition: string.cpp:333

References GENDRILL_WRITER_BASE::BuildFileFunctionAttributeString(), DateAndTime(), GENDRILL_WRITER_BASE::DECIMAL_FORMAT, GBR_NC_STRING_FORMAT_NCDRILL, GbrMakeCreationDateAttributeString(), GetBuildVersion(), DRILL_PRECISION::GetPrecisionString(), GENDRILL_WRITER_BASE::KEEP_ZEROS, m_file, GENDRILL_WRITER_BASE::m_merge_PTH_NPTH, m_minimalHeader, GENDRILL_WRITER_BASE::m_precision, GENDRILL_WRITER_BASE::m_unitsMetric, GENDRILL_WRITER_BASE::m_zeroFormat, GENDRILL_WRITER_BASE::SUPPRESS_LEADING, GENDRILL_WRITER_BASE::SUPPRESS_TRAILING, and TO_UTF8.

Referenced by createDrillFile().

Member Data Documentation

◆ m_conversionUnits

double GENDRILL_WRITER_BASE::m_conversionUnits
protectedinherited

◆ m_drillFileExtension

wxString GENDRILL_WRITER_BASE::m_drillFileExtension
protectedinherited

◆ m_file

FILE* EXCELLON_WRITER::m_file
private

◆ m_holeListBuffer

◆ m_mapFileFmt

PlotFormat GENDRILL_WRITER_BASE::m_mapFileFmt
protectedinherited

◆ m_merge_PTH_NPTH

◆ m_minimalHeader

bool EXCELLON_WRITER::m_minimalHeader
private

Definition at line 48 of file gendrill_Excellon_writer.h.

Referenced by EXCELLON_WRITER(), SetOptions(), and writeEXCELLONHeader().

◆ m_mirror

bool EXCELLON_WRITER::m_mirror
private

Definition at line 49 of file gendrill_Excellon_writer.h.

Referenced by createDrillFile(), EXCELLON_WRITER(), and SetOptions().

◆ m_offset

wxPoint GENDRILL_WRITER_BASE::m_offset
protectedinherited

◆ m_pageInfo

const PAGE_INFO* GENDRILL_WRITER_BASE::m_pageInfo
protectedinherited

◆ m_pcb

◆ m_precision

DRILL_PRECISION GENDRILL_WRITER_BASE::m_precision
protectedinherited

◆ m_toolListBuffer

std::vector<DRILL_TOOL> GENDRILL_WRITER_BASE::m_toolListBuffer
protectedinherited

◆ m_unitsMetric

◆ m_useRouteModeForOval

bool EXCELLON_WRITER::m_useRouteModeForOval
private

◆ m_zeroFormat


The documentation for this class was generated from the following files: