49#include <fmt/format.h>
84 hole_sets.emplace_back(
F_Cu,
B_Cu,
false,
true );
86 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
87 it != hole_sets.end(); ++it )
102 fn.SetPath( aPlotDirectory );
106 wxString fullFilename = fn.GetFullPath();
108 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
110 if( file ==
nullptr )
114 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
125 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
136 else if( doing_npth )
144 bool wroteDrillFile =
false;
149 wroteDrillFile =
true;
154 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
194 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
198 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
202 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,BackDrill\n" );
207 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
211 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
215 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
219 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
223 fmt::print(
m_file,
"{}",
"; #@! TD\n" );
231 TYPE_FILE aHolesType,
bool aTagBackdrillHit )
239 int diam, holes_count;
240 int x0, y0, xf, yf, xc, yc;
253#if USE_ATTRIB_FOR_HOLES
262 auto formatStub = [&](
int aStubLength )
264 double stubMM =
pcbIUScale.IUTomm( aStubLength );
265 double stubInches = stubMM / 25.4;
266 wxString tmp = fmt::format(
"{:.3f}mm ({:.4f}\")", stubMM, stubInches );
270 wxString comment = wxT(
"; Backdrill" );
274 comment += wxT(
" stub " );
280 comment += wxT(
" to " );
286 comment += wxT(
", post-machining" );
288 comment += wxT(
"\n" );
293 fmt::print(
m_file,
"{}",
"; Post-machining\n" );
298 fmt::print(
m_file,
"{}",
"%\n" );
299 fmt::print(
m_file,
"{}",
"G90\n" );
300 fmt::print(
m_file,
"{}",
"G05\n" );
304 int tool_reference = -2;
316 fmt::print(
m_file,
"T{}\n", tool_reference );
330 fmt::print(
m_file,
"{}", line );
349 fmt::print(
m_file,
"T{}\n", tool_reference );
389 fmt::print(
m_file,
"{}",
"G00" );
397 for(
int kk = 0; line[kk] != 0; kk++ )
403 fmt::print(
m_file,
"{}", line );
404 fmt::print(
m_file,
"{}",
"G85" );
408 fmt::print(
m_file,
"{}", line );
409 fmt::print(
m_file,
"{}",
"M15\nG01" );
416 fmt::print(
m_file,
"{}",line );
419 fmt::print(
m_file,
"{}",
"M16\n" );
421 fmt::print(
m_file,
"{}",
"G05\n" );
445 if( aLeftDigits <= 0 )
448 if( aRightDigits <= 0 )
482 while( xs.Last() ==
'0' )
485 if( xs.Last() ==
'.' )
488 while( ys.Last() ==
'0' )
491 if( ys.Last() ==
'.' )
494 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
500 aCoordX *= 10; aCoordY *= 10;
503 std::snprintf( aLine, aLineSize,
"X%dY%d\n",
KiROUND( aCoordX ),
KiROUND( aCoordY ) );
520 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
521 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
523 size_t j = xs.Len() - 1;
525 while( xs[j] ==
'0' && j )
530 while( ys[j] ==
'0' && j )
533 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
540 aCoordX *= 10; aCoordY *= 10;
549 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
550 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
551 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
559 fmt::print(
m_file,
"{}",
"M48\n" );
567 fmt::print(
m_file,
"; DRILL file {} date {}\n",
569 msg = wxT(
"; FORMAT={" );
579 msg << wxT(
"/ absolute / " );
591 const wxString zero_fmt[4] =
594 wxT(
"suppress leading zeros" ),
595 wxT(
"suppress trailing zeros" ),
608 msg = wxT(
"; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
617 fmt::print(
m_file,
"{}",
"FMAT,2\n" );
625 fmt::print(
m_file,
"{}",
"\n" );
629 fmt::print(
m_file,
"{}",
",TZ\n" );
633 fmt::print(
m_file,
"{}",
",LZ\n" );
638 fmt::print(
m_file,
"{}",
"\n" );
647 fmt::print(
m_file,
"{}",
"M30\n" );
654 wxFileName fn =
m_pcb->GetFileName();
659 << wxT(
"-backdrill" );
661 fn.SetName( fn.GetName() + extend );
672 fn.SetPath( aPlotDirectory );
674 wxString fullFilename = fn.GetFullPath();
675 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
677 if( file ==
nullptr )
682 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
691 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
706 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.
void AddCreatedFile(const wxString &aPath)
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.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Classes used in drill files, map files and report files generation.
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.