50#include <fmt/format.h>
85 hole_sets.emplace_back(
F_Cu,
B_Cu,
false,
true );
87 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
88 it != hole_sets.end(); ++it )
103 fn.SetPath( aPlotDirectory );
107 wxString fullFilename = fn.GetFullPath();
109 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
111 if( file ==
nullptr )
115 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
126 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
137 else if( doing_npth )
145 bool wroteDrillFile =
false;
150 wroteDrillFile =
true;
155 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" );
204 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,BackDrill\n" );
209 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
213 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
217 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
221 fmt::print(
m_file,
"{}",
"; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
225 fmt::print(
m_file,
"{}",
"; #@! TD\n" );
233 TYPE_FILE aHolesType,
bool aTagBackdrillHit )
241 int diam, holes_count;
242 int x0, y0, xf, yf, xc, yc;
255#if USE_ATTRIB_FOR_HOLES
264 auto formatStub = [&](
int aStubLength )
266 double stubMM =
pcbIUScale.IUTomm( aStubLength );
267 double stubInches = stubMM / 25.4;
268 wxString tmp = fmt::format(
"{:.3f}mm ({:.4f}\")", stubMM, stubInches );
272 wxString comment = wxT(
"; Backdrill" );
276 comment += wxT(
" stub " );
282 comment += wxT(
" to " );
288 comment += wxT(
", post-machining" );
290 comment += wxT(
"\n" );
295 fmt::print(
m_file,
"{}",
"; Post-machining\n" );
300 fmt::print(
m_file,
"{}",
"%\n" );
301 fmt::print(
m_file,
"{}",
"G90\n" );
302 fmt::print(
m_file,
"{}",
"G05\n" );
306 int tool_reference = -2;
318 fmt::print(
m_file,
"T{}\n", tool_reference );
332 fmt::print(
m_file,
"{}", line );
351 fmt::print(
m_file,
"T{}\n", tool_reference );
391 fmt::print(
m_file,
"{}",
"G00" );
399 for(
int kk = 0; line[kk] != 0; kk++ )
405 fmt::print(
m_file,
"{}", line );
406 fmt::print(
m_file,
"{}",
"G85" );
410 fmt::print(
m_file,
"{}", line );
411 fmt::print(
m_file,
"{}",
"M15\nG01" );
418 fmt::print(
m_file,
"{}",line );
421 fmt::print(
m_file,
"{}",
"M16\n" );
423 fmt::print(
m_file,
"{}",
"G05\n" );
447 if( aLeftDigits <= 0 )
450 if( aRightDigits <= 0 )
484 while( xs.Last() ==
'0' )
487 if( xs.Last() ==
'.' )
490 while( ys.Last() ==
'0' )
493 if( ys.Last() ==
'.' )
496 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
502 aCoordX *= 10; aCoordY *= 10;
505 std::snprintf( aLine, aLineSize,
"X%dY%d\n",
KiROUND( aCoordX ),
KiROUND( aCoordY ) );
522 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
523 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
525 size_t j = xs.Len() - 1;
527 while( xs[j] ==
'0' && j )
532 while( ys[j] ==
'0' && j )
535 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
542 aCoordX *= 10; aCoordY *= 10;
551 xs.Printf( wxT(
"%0*d" ), xpad,
KiROUND( aCoordX ) );
552 ys.Printf( wxT(
"%0*d" ), ypad,
KiROUND( aCoordY ) );
553 std::snprintf( aLine, aLineSize,
"X%sY%s\n",
TO_UTF8( xs ),
TO_UTF8( ys ) );
561 fmt::print(
m_file,
"{}",
"M48\n" );
569 fmt::print(
m_file,
"; DRILL file {} date {}\n",
571 msg = wxT(
"; FORMAT={" );
581 msg << wxT(
"/ absolute / " );
593 const wxString zero_fmt[4] =
596 wxT(
"suppress leading zeros" ),
597 wxT(
"suppress trailing zeros" ),
610 msg = wxT(
"; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
619 fmt::print(
m_file,
"{}",
"FMAT,2\n" );
627 fmt::print(
m_file,
"{}",
"\n" );
631 fmt::print(
m_file,
"{}",
",TZ\n" );
635 fmt::print(
m_file,
"{}",
",LZ\n" );
640 fmt::print(
m_file,
"{}",
"\n" );
649 fmt::print(
m_file,
"{}",
"M30\n" );
656 wxFileName fn =
m_pcb->GetFileName();
661 << wxT(
"-backdrill" );
663 fn.SetName( fn.GetName() + extend );
674 fn.SetPath( aPlotDirectory );
676 wxString fullFilename = fn.GetFullPath();
677 FILE* file = wxFopen( fullFilename, wxT(
"w" ) );
679 if( file ==
nullptr )
684 msg.Printf(
_(
"Failed to create file '%s'." ), fullFilename );
693 msg.Printf(
_(
"Created file '%s'" ), fullFilename );
708 msg.Printf(
_(
"Failed to write file '%s'." ), fullFilename );
723 fmt::print(
m_file,
"{}",
"; backdrill\n" );
736 int aSizeIU,
int aDepthIU,
int aAngleDeciDegree,
737 const wxString& aSideLabel )
746 comment << wxT(
"; Post-machining " ) << aSideLabel << wxT(
" " )
748 : wxT(
"counterbore" ) );
752 if( !sizeStr.IsEmpty() )
753 comment << wxT(
" dia " ) << sizeStr;
757 if( !depthStr.IsEmpty() )
758 comment << wxT(
" depth " ) << depthStr;
762 double angle = aAngleDeciDegree / 10.0;
765 if( ( aAngleDeciDegree % 10 ) == 0 )
766 angleStr = fmt::format(
"{:.0f}deg", angle );
768 angleStr = fmt::format(
"{:.1f}deg", angle );
770 comment << wxT(
" angle " ) << angleStr;
773 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.
void writeHoleComments(const DRILL_OPERATION &aHole, bool aTagBackdrillHit)
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()
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
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_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...
std::vector< int > m_holeToolReferences
int getHolesCount() const
std::vector< DRILL_OPERATION > m_holeListBuffer
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
The standard X2 FileFunction for drill files is %TF.FileFunction,Plated[NonPlated],...
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::vector< DRILL_SPAN > EnumerateDrillSpans(const BOARD &aBoard, bool aPadBackdrills)
Every drill span present on the board, through-holes first.
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
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
wxString GetISO8601CurrentDateTime()
One machining action, which is also one NC hit and one tool assignment.
DRILL_POST_MACHINING m_BackPostMachining
VECTOR2I m_SizeXY
Source axes, never normalized to (width, length).
DRILL_POST_MACHINING m_FrontPostMachining
PAD_DRILL_POST_MACHINING_MODE m_Mode
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.