53#include <fmt/format.h>
88 hole_sets.emplace_back(
F_Cu,
B_Cu,
false,
true );
90 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
91 it != hole_sets.end(); ++it )
106 fn.SetPath( aPlotDirectory );
110 wxString fullFilename = fn.GetFullPath();
112 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
114 if( file ==
nullptr )
118 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
129 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
140 else if( doing_npth )
148 bool wroteDrillFile =
false;
153 wroteDrillFile =
true;
158 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
195 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
199 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
203 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,BackDrill\n" );
208 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
212 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
216 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
220 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
224 fmt::print(
m_file,
"{}",
"; #@! TD\n" );
232 TYPE_FILE aHolesType,
bool aTagBackdrillHit )
240 int diam, holes_count;
241 int x0, y0, xf, yf, xc, yc;
254#if USE_ATTRIB_FOR_HOLES
263 auto formatStub = [&](
int aStubLength )
265 double stubMM =
pcbIUScale.IUTomm( aStubLength );
266 double stubInches = stubMM / 25.4;
267 wxString tmp = fmt::format(
"{:.3f}mm ({:.4f}\")", stubMM, stubInches );
271 wxString comment = wxT(
"; Backdrill" );
275 comment += wxT(
" stub " );
281 comment += wxT(
" to " );
287 comment += wxT(
", post-machining" );
289 comment += wxT(
"\n" );
294 fmt::print(
m_file,
"{}",
"; Post-machining\n" );
299 fmt::print(
m_file,
"{}",
"%\n" );
300 fmt::print(
m_file,
"{}",
"G90\n" );
301 fmt::print(
m_file,
"{}",
"G05\n" );
305 int tool_reference = -2;
317 fmt::print(
m_file,
"T{}\n", tool_reference );
331 fmt::print(
m_file,
"{}", line );
350 fmt::print(
m_file,
"T{}\n", tool_reference );
390 fmt::print(
m_file,
"{}",
"G00" );
398 for(
int kk = 0; line[kk] != 0; kk++ )
404 fmt::print(
m_file,
"{}", line );
405 fmt::print(
m_file,
"{}",
"G85" );
409 fmt::print(
m_file,
"{}", line );
410 fmt::print(
m_file,
"{}",
"M15\nG01" );
417 fmt::print(
m_file,
"{}",line );
420 fmt::print(
m_file,
"{}",
"M16\n" );
422 fmt::print(
m_file,
"{}",
"G05\n" );
446 if( aLeftDigits <= 0 )
449 if( aRightDigits <= 0 )
483 while( xs.Last() ==
'0' )
486 if( xs.Last() ==
'.' )
489 while( ys.Last() ==
'0' )
492 if( ys.Last() ==
'.' )
495 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
501 aCoordX *= 10; aCoordY *= 10;
504 std::snprintf( aLine, aLineSize,
"X%dY%d\n",
KiROUND( aCoordX ),
KiROUND( aCoordY ) );
521 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
522 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
524 size_t j = xs.Len() - 1;
526 while( xs[j] ==
'0' && j )
531 while( ys[j] ==
'0' && j )
534 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
541 aCoordX *= 10; aCoordY *= 10;
550 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
551 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
552 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
560 fmt::print(
m_file,
"{}",
"M48\n" );
568 fmt::print(
m_file,
"; DRILL file {} date {}\n",
570 msg = wxT(
"; FORMAT={" );
580 msg << wxT(
"/ absolute / " );
592 const wxString zero_fmt[4] =
595 wxT(
"suppress leading zeros" ),
596 wxT(
"suppress trailing zeros" ),
609 msg = wxT(
"; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
618 fmt::print(
m_file,
"{}",
"FMAT,2\n" );
626 fmt::print(
m_file,
"{}",
"\n" );
630 fmt::print(
m_file,
"{}",
",TZ\n" );
634 fmt::print(
m_file,
"{}",
",LZ\n" );
639 fmt::print(
m_file,
"{}",
"\n" );
648 fmt::print(
m_file,
"{}",
"M30\n" );
655 wxFileName fn =
m_pcb->GetFileName();
660 << wxT(
"-backdrill" );
662 fn.SetName( fn.GetName() + extend );
673 fn.SetPath( aPlotDirectory );
675 wxString fullFilename = fn.GetFullPath();
676 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
678 if( file ==
nullptr )
683 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
692 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
707 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
721 fmt::print(
m_file,
"{}",
"; backdrill\n" );
734 int aSizeIU,
int aDepthIU,
int aAngleDeciDegree,
735 const wxString& aSideLabel )
744 comment << wxT(
"; Post-machining " ) << aSideLabel << wxT(
" " )
746 : wxT(
"counterbore" ) );
750 if( !sizeStr.IsEmpty() )
751 comment << wxT(
" dia " ) << sizeStr;
755 if( !depthStr.IsEmpty() )
756 comment << wxT(
" depth " ) << depthStr;
760 double angle = aAngleDeciDegree / 10.0;
763 if( ( aAngleDeciDegree % 10 ) == 0 )
764 angleStr = fmt::format(
"{:.0f}deg", angle );
766 angleStr = fmt::format(
"{:.1f}deg", angle );
768 comment << wxT(
" angle " ) << angleStr;
771 comment << wxT(
"\n" );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Initialize internal parameters to match the given format.
bool m_useRouteModeForOval
void writeCoordinates(char *aLine, size_t aLineSize, double aCoordX, double aCoordY)
Create a line like according to the selected format.
int createDrillFile(FILE *aFile, const DRILL_SPAN &aSpan, TYPE_FILE aHolesType, bool aTagBackdrillHit=false)
Create an Excellon drill file.
void writePostMachiningComment(PAD_DRILL_POST_MACHINING_MODE aMode, int aSizeIU, int aDepthIU, int aAngleDeciDegree, const wxString &aSideLabel)
void writeHoleAttribute(HOLE_ATTRIBUTE aAttribute)
Write a comment string giving the hole attribute.
bool CreateDrillandMapFilesSet(const wxString &aPlotDirectory, bool aGenDrill, bool aGenMap, REPORTER *aReporter=nullptr)
Create the full set of Excellon drill file for the board.
EXCELLON_WRITER(BOARD *aPcb)
wxFileName getBackdrillLayerPairFileName(const DRILL_SPAN &aSpan) const
wxString formatLinearValue(int aValueIU) const
void writeEXCELLONEndOfFile()
void writeHoleComments(const HOLE_INFO &aHole, bool aTagBackdrillHit)
bool writeBackdrillLayerPairFile(const wxString &aPlotDirectory, REPORTER *aReporter, const DRILL_SPAN &aSpan)
void writeEXCELLONHeader(const DRILL_SPAN &aSpan, TYPE_FILE aHolesType)
Print the DRILL file header.
wxString m_drillFileExtension
std::vector< HOLE_INFO > m_holeListBuffer
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
DRILL_PRECISION m_precision
GENDRILL_WRITER_BASE(BOARD *aPcb)
std::vector< DRILL_SPAN > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
std::vector< DRILL_TOOL > m_toolListBuffer
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
bool CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=nullptr)
Create the full set of map files for the board, in PS, PDF ... format (use SetMapFileFormat() to sele...
int getHolesCount() const
virtual const wxString getDrillFileName(const DRILL_SPAN &aSpan, bool aNPTH, bool aMerge_PTH_NPTH) const
const wxString BuildFileFunctionAttributeString(const DRILL_SPAN &aSpan, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
Handle hole which must be drilled (diameter, position and layers).
int m_FrontPostMachiningDepth
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
int m_FrontPostMachiningAngle
int m_BackPostMachiningDepth
int m_BackPostMachiningSize
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
int m_FrontPostMachiningSize
int m_BackPostMachiningAngle
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
Classes used in drill files, map files and report files generation.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static const std::string DrillFileExtension
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
DRILL_LAYER_PAIR Pair() const
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition of file extensions used in Kicad.