2011-09-23 13:57:12 +00:00
|
|
|
/**
|
2012-10-05 12:25:12 +00:00
|
|
|
* @file gendrill_Excellon_writer.h
|
|
|
|
* @brief Classes used in drill files, map files and report files generation.
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
|
|
|
|
2010-11-26 11:55:34 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-11-26 11:55:34 +00:00
|
|
|
*
|
2015-04-29 15:37:37 +00:00
|
|
|
* Copyright (C) 1992-2015 Jean_Pierre Charras <jp.charras at wanadoo.fr>
|
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
|
2010-11-26 11:55:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
#ifndef _GENDRILL_EXCELLON_WRITER_
|
|
|
|
#define _GENDRILL_EXCELLON_WRITER_
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class PLOTTER;
|
|
|
|
|
|
|
|
|
2008-01-25 16:47:36 +00:00
|
|
|
/* the DRILL_TOOL class handles tools used in the excellon drill file */
|
2008-01-18 15:47:15 +00:00
|
|
|
class DRILL_TOOL
|
|
|
|
{
|
|
|
|
public:
|
2010-11-24 19:54:59 +00:00
|
|
|
int m_Diameter; // the diameter of the used tool (for oblong, the smaller size)
|
|
|
|
int m_TotalCount; // how many times it is used (round and oblong)
|
|
|
|
int m_OvalCount; // oblong count
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DRILL_TOOL( int diametre )
|
2008-01-18 15:47:15 +00:00
|
|
|
{
|
|
|
|
m_TotalCount = 0;
|
|
|
|
m_OvalCount = 0;
|
|
|
|
m_Diameter = diametre;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
/* the HOLE_INFO class handle hole which must be drilled (diameter, position and layers)
|
|
|
|
* For buried or micro vias, the hole is not on all layers.
|
|
|
|
* So we must generate a drill file for each layer pair (adjacent layers)
|
|
|
|
* Not plated holes are always through holes, and must be output on a specific drill file
|
|
|
|
* because they are drilled after the Pcb process is finished.
|
2014-03-06 18:38:39 +00:00
|
|
|
*/
|
2008-01-18 15:47:15 +00:00
|
|
|
class HOLE_INFO
|
|
|
|
{
|
|
|
|
public:
|
2014-06-24 16:17:18 +00:00
|
|
|
int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole size y)
|
|
|
|
int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0 must not be used)
|
|
|
|
wxSize m_Hole_Size; // hole size for oblong holes
|
|
|
|
double m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
|
|
|
|
int m_Hole_Shape; // hole shape: round (0) or oval (1)
|
|
|
|
wxPoint m_Hole_Pos; // hole position
|
2015-03-13 16:48:42 +00:00
|
|
|
LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
|
|
|
|
LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
|
|
|
|
// m_Hole_Top_Layer < m_Hole_Bottom_Layer
|
2014-06-24 16:17:18 +00:00
|
|
|
bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file
|
2014-03-06 18:38:39 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
public:
|
|
|
|
HOLE_INFO()
|
|
|
|
{
|
|
|
|
m_Hole_NotPlated = false;
|
2015-03-13 16:48:42 +00:00
|
|
|
m_Hole_Diameter = 0;
|
|
|
|
m_Tool_Reference = 0;
|
|
|
|
m_Hole_Orient = 0.0;
|
|
|
|
m_Hole_Shape = 0;
|
|
|
|
m_Hole_Bottom_Layer = B_Cu;
|
|
|
|
m_Hole_Top_Layer = F_Cu;
|
2011-08-19 13:08:24 +00:00
|
|
|
}
|
2008-01-18 15:47:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
/* the DRILL_PRECISION helper class to handle drill precision format in excellon files
|
2010-11-24 19:54:59 +00:00
|
|
|
*/
|
2010-11-24 15:10:33 +00:00
|
|
|
class DRILL_PRECISION
|
2008-01-18 15:47:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-11-24 15:10:33 +00:00
|
|
|
int m_lhs; // Left digit number (integer value of coordinates)
|
2014-03-06 18:38:39 +00:00
|
|
|
int m_rhs; // Right digit number (decimal value of coordinates)
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
public: DRILL_PRECISION( int l = 2, int r = 4 )
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
|
|
|
m_lhs = l; m_rhs = r;
|
|
|
|
}
|
2010-11-24 19:54:59 +00:00
|
|
|
|
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
wxString GetPrecisionString()
|
|
|
|
{
|
|
|
|
wxString text;
|
2010-11-24 19:54:59 +00:00
|
|
|
|
|
|
|
text << m_lhs << wxT( ":" ) << m_rhs;
|
2010-11-24 15:10:33 +00:00
|
|
|
return text;
|
|
|
|
}
|
2008-01-18 15:47:15 +00:00
|
|
|
};
|
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
|
2015-10-23 14:30:22 +00:00
|
|
|
typedef std::pair<LAYER_ID, LAYER_ID> LAYER_PAIR;
|
|
|
|
class OUTPUTFORMATTER;
|
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-11-24 19:54:59 +00:00
|
|
|
class EXCELLON_WRITER
|
|
|
|
{
|
|
|
|
public:
|
2015-04-29 15:37:37 +00:00
|
|
|
enum ZEROS_FMT { // Zero format in coordinates
|
|
|
|
DECIMAL_FORMAT, // Floating point coordinates
|
|
|
|
SUPPRESS_LEADING, // Suppress leading zeros
|
|
|
|
SUPPRESS_TRAILING, // Suppress trainling zeros
|
|
|
|
KEEP_ZEROS // keep zeros
|
2010-11-24 19:54:59 +00:00
|
|
|
};
|
2014-03-06 18:38:39 +00:00
|
|
|
|
|
|
|
wxPoint m_Offset; // offset coordinates
|
|
|
|
bool m_ShortHeader; // true to generate the smallest header (strip comments)
|
2010-11-24 19:54:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FILE* m_file; // The output file
|
|
|
|
BOARD* m_pcb;
|
2014-03-06 18:38:39 +00:00
|
|
|
bool m_minimalHeader; // True to use minimal header
|
2010-11-24 19:54:59 +00:00
|
|
|
// in excellon file (strip comments)
|
|
|
|
bool m_unitsDecimal; // true = decimal, false = inches
|
2015-04-29 15:37:37 +00:00
|
|
|
ZEROS_FMT m_zeroFormat; // the zero format option for output file
|
2014-03-06 18:38:39 +00:00
|
|
|
DRILL_PRECISION m_precision; // The current coordinate precision (not used in decimal format)
|
2010-11-24 19:54:59 +00:00
|
|
|
double m_conversionUnits; // scaling factor to convert the board unites to Excellon units
|
|
|
|
// (i.e inches or mm)
|
|
|
|
bool m_mirror;
|
2014-03-06 18:38:39 +00:00
|
|
|
wxPoint m_offset; // Drill offset coordinates
|
2012-10-05 12:25:12 +00:00
|
|
|
std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
|
|
|
|
std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
|
2010-11-24 19:54:59 +00:00
|
|
|
|
2015-04-29 15:37:37 +00:00
|
|
|
PlotFormat m_mapFileFmt; // the format of the map drill file,
|
|
|
|
// if this map is needed
|
|
|
|
const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
|
|
|
|
// If NULL, use a A4 page format
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2015-04-29 15:37:37 +00:00
|
|
|
public:
|
|
|
|
EXCELLON_WRITER( BOARD* aPcb );
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
~EXCELLON_WRITER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
/**
|
|
|
|
* Return the plot offset (usually the position
|
2014-03-06 18:38:39 +00:00
|
|
|
* of the auxiliary axis
|
2012-10-05 12:25:12 +00:00
|
|
|
*/
|
|
|
|
const wxPoint GetOffset() { return m_offset; }
|
2010-11-24 19:54:59 +00:00
|
|
|
|
|
|
|
/**
|
2010-12-28 11:24:42 +00:00
|
|
|
* Function SetFormat
|
2010-11-24 19:54:59 +00:00
|
|
|
* Initialize internal parameters to match the given format
|
|
|
|
* @param aMetric = true for metric coordinates, false for imperial units
|
|
|
|
* @param aZerosFmt = DECIMAL_FORMAT, SUPPRESS_LEADING, SUPPRESS_TRAILING, KEEP_ZEROS
|
|
|
|
* @param aLeftDigits = number of digits for integer part of coordinates
|
2015-04-29 15:37:37 +00:00
|
|
|
* if <= 0 (default), a suitable value will be used, depending on units
|
2010-11-24 19:54:59 +00:00
|
|
|
* @param aRightDigits = number of digits for mantissa part of coordinates
|
2015-04-29 15:37:37 +00:00
|
|
|
* if <= 0 (default), a suitable value will be used, depending on units
|
2010-11-24 19:54:59 +00:00
|
|
|
*/
|
2015-04-29 15:37:37 +00:00
|
|
|
void SetFormat( bool aMetric, ZEROS_FMT aZerosFmt = DECIMAL_FORMAT,
|
|
|
|
int aLeftDigits = 0, int aRightDigits = 0 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the page info used to plot drill maps
|
|
|
|
* If NULL, a A4 page format will be used
|
|
|
|
* @param aPageInfo = a reference to the page info, usually used to plot/display the board
|
|
|
|
*/
|
|
|
|
void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetMapFileFormat
|
|
|
|
* Initialize the format for the drill map file
|
|
|
|
* @param SetMapFileFormat = 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
|
|
|
|
*/
|
|
|
|
void SetMapFileFormat( PlotFormat aMapFmt ) { m_mapFileFmt = aMapFmt; }
|
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
|
|
|
|
/**
|
2010-12-28 11:24:42 +00:00
|
|
|
* Function SetOptions
|
2010-11-24 19:54:59 +00:00
|
|
|
* Initialize internal parameters to match drill options
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aMirror = true to create mirrored coordinates (Y coordinates negated)
|
|
|
|
* @param aMinimalHeader = true to use a minimal header (no comments, no info)
|
|
|
|
* @param aOffset = drill coordinates offset
|
2010-11-24 19:54:59 +00:00
|
|
|
*/
|
2015-10-26 07:43:30 +00:00
|
|
|
void SetOptions( bool aMirror, bool aMinimalHeader, wxPoint aOffset )
|
2010-11-24 19:54:59 +00:00
|
|
|
{
|
|
|
|
m_mirror = aMirror;
|
|
|
|
m_offset = aOffset;
|
|
|
|
m_minimalHeader = aMinimalHeader;
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
/**
|
|
|
|
* Function BuildHolesList
|
|
|
|
* Create the list of holes and tools for a given board
|
2015-10-23 14:30:22 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param aLayerPair is an inclusive range of layers.
|
2012-10-05 12:25:12 +00:00
|
|
|
* @param aGenerateNPTH_list :
|
|
|
|
* true to create NPTH only list (with no plated holes)
|
|
|
|
* false to created plated holes list (with no NPTH )
|
|
|
|
*/
|
2015-10-23 14:30:22 +00:00
|
|
|
void BuildHolesList( LAYER_PAIR aLayerPair,
|
2015-10-26 07:43:30 +00:00
|
|
|
bool aGenerateNPTH_list );
|
2012-10-05 12:25:12 +00:00
|
|
|
|
|
|
|
int GetHolesCount() const { return m_holeListBuffer.size(); }
|
2010-11-24 19:54:59 +00:00
|
|
|
|
2015-04-29 15:37:37 +00:00
|
|
|
/**
|
|
|
|
* Function CreateDrillandMapFilesSet
|
|
|
|
* Creates the full set of Excellon drill file for the board
|
|
|
|
* filenames are computed from the board name, and layers id
|
|
|
|
* @param aPlotDirectory = the output folder
|
|
|
|
* @param aGenDrill = true to generate the EXCELLON drill file
|
|
|
|
* @param aGenMap = true to generate a drill map file
|
|
|
|
* @param aReporter = a REPORTER to return activity or any message (can be NULL)
|
|
|
|
*/
|
|
|
|
void CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
|
|
|
|
bool aGenDrill, bool aGenMap,
|
|
|
|
REPORTER * aReporter = NULL );
|
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
/**
|
2010-12-28 11:24:42 +00:00
|
|
|
* Function CreateDrillFile
|
2010-11-24 19:54:59 +00:00
|
|
|
* Creates an Excellon drill file
|
2014-03-06 18:38:39 +00:00
|
|
|
* @param aFile = an opened file to write to will be closed by CreateDrillFile
|
2010-11-24 19:54:59 +00:00
|
|
|
* @return hole count
|
|
|
|
*/
|
2012-10-05 12:25:12 +00:00
|
|
|
int CreateDrillFile( FILE * aFile );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2014-03-06 18:38:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2012-10-05 12:25:12 +00:00
|
|
|
* @param aFullFileName : the name of the file to create
|
2015-04-29 15:37:37 +00:00
|
|
|
* m_unitsDecimal = false to use inches, true to use mm in report file
|
2012-10-05 12:25:12 +00:00
|
|
|
*
|
|
|
|
* @return success if the file is created
|
|
|
|
*/
|
|
|
|
bool GenDrillReportFile( const wxString& aFullFileName );
|
2010-11-24 19:54:59 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
/**
|
|
|
|
* Function GenDrillMapFile
|
|
|
|
* Plot a map of drill marks for holes.
|
2015-04-29 15:37:37 +00:00
|
|
|
* 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
|
|
|
|
* @param aFullFileName : the full filename of the map file to create,
|
2012-10-05 12:25:12 +00:00
|
|
|
* @param aFormat : one of the supported plot formats (see enum PlotFormat )
|
|
|
|
*/
|
2015-04-29 15:37:37 +00:00
|
|
|
bool GenDrillMapFile( const wxString& aFullFileName, PlotFormat aFormat );
|
|
|
|
|
2010-11-24 19:54:59 +00:00
|
|
|
private:
|
2014-03-06 18:38:39 +00:00
|
|
|
/* Print the DRILL file header. The full header is:
|
|
|
|
* M48
|
|
|
|
* ;DRILL file {PCBNEW (2007-11-29-b)} date 17/1/2008-21:02:35
|
|
|
|
* ;FORMAT={ <precision> / absolute / <units> / <numbers format>}
|
|
|
|
* FMAT,2
|
|
|
|
* INCH,TZ
|
|
|
|
*/
|
2012-10-05 12:25:12 +00:00
|
|
|
void WriteEXCELLONHeader();
|
2014-03-06 18:38:39 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
void WriteEXCELLONEndOfFile();
|
2014-03-06 18:38:39 +00:00
|
|
|
|
|
|
|
/* Created a line like:
|
|
|
|
* X48000Y19500
|
|
|
|
* According to the selected format
|
|
|
|
*/
|
2010-11-24 19:54:59 +00:00
|
|
|
void WriteCoordinates( char* aLine, double aCoordX, double aCoordY );
|
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
/** 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
|
|
|
|
* @param aPlotter = a PLOTTER instance (HPGL, POSTSCRIPT ... plotter).
|
|
|
|
*/
|
2012-12-18 13:54:44 +00:00
|
|
|
bool PlotDrillMarks( PLOTTER* aPlotter );
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2015-10-23 14:30:22 +00:00
|
|
|
/// Get unique layer pairs by examining the micro and blind_buried vias.
|
|
|
|
std::vector<LAYER_PAIR> getUniqueLayerPairs() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function printToolSummary
|
|
|
|
* prints m_toolListBuffer[] tools to aOut and returns total hole count.
|
|
|
|
*/
|
|
|
|
unsigned printToolSummary( OUTPUTFORMATTER& aOut ) const;
|
|
|
|
|
|
|
|
const std::string layerPairName( LAYER_PAIR aPair ) const;
|
|
|
|
|
|
|
|
const std::string layerName( LAYER_ID aLayer ) const;
|
|
|
|
|
|
|
|
const wxString drillFileName( LAYER_PAIR aPair, bool aNPTH ) const;
|
|
|
|
};
|
2008-01-18 15:47:15 +00:00
|
|
|
|
2012-10-05 12:25:12 +00:00
|
|
|
#endif // #ifndef _GENDRILL_EXCELLON_WRITER_
|